File indexing completed on 2024-04-21 05:01:40

0001 /*
0002     This class manages the profiles that were defined by the user.
0003 
0004     SPDX-FileCopyrightText: 2014-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SMB4KPROFILEMANAGER_H
0009 #define SMB4KPROFILEMANAGER_H
0010 
0011 // application specific includes
0012 #include "smb4kglobal.h"
0013 
0014 // Qt includes
0015 #include <QObject>
0016 #include <QPair>
0017 #include <QScopedPointer>
0018 #include <QString>
0019 #include <QStringList>
0020 
0021 // forward declarations
0022 class Smb4KProfileManagerPrivate;
0023 
0024 /**
0025  * This class "manages" the profiles defined by the user in such a
0026  * degree as it sends signals when the active profile changed, a
0027  * profile was renamed or removed. You can also actively initiate the
0028  * migration of or remove a profile.
0029  *
0030  * When using profiles, please use this class instead of the KConfig XT
0031  * class(es).
0032  *
0033  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0034  * @since 1.2.0
0035  */
0036 
0037 class Q_DECL_EXPORT Smb4KProfileManager : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     /**
0043      * Constructor
0044      */
0045     explicit Smb4KProfileManager(QObject *parent = nullptr);
0046 
0047     /**
0048      * Destructor
0049      */
0050     virtual ~Smb4KProfileManager();
0051 
0052     /**
0053      * Returns a static pointer to this class.
0054      *
0055      * @returns a static pointer to this class.
0056      */
0057     static Smb4KProfileManager *self();
0058 
0059     /**
0060      * Set the active profile if the use of profiles is enabled.
0061      * Otherwise the this function does nothing.
0062      *
0063      * @param name        Name of the active profile.
0064      *
0065      * @returns true if the active profile was changed.
0066      */
0067     void setActiveProfile(const QString &name);
0068 
0069     /**
0070      * Return the currently active profile or an empty string if
0071      * the use of profiles is disabled.
0072      *
0073      * @returns the active profile.
0074      */
0075     QString activeProfile() const;
0076 
0077     /**
0078      * Returns the list of profiles or an empty string list if the
0079      * the use of profiles is disabled.
0080      *
0081      * @returns the list of profiles.
0082      */
0083     QStringList profilesList() const;
0084 
0085     /**
0086      * Returns if profiles should be used or not. This is basically
0087      * a convenience function, since it just returns
0088      * Smb4KSettings::useProfiles().
0089      *
0090      * @returns true if profiles should be used.
0091      */
0092     bool useProfiles() const;
0093 
0094     /**
0095      * Migrate all entries of one profile to another. This function does
0096      * not honor the useProfiles() function, so you can migrate profiles
0097      * even if their usage is not enabled.
0098      *
0099      * @param oldName     The name of the old profile
0100      * @param newName     The name of the new profile
0101      */
0102     void migrateProfile(const QString &oldName, const QString &newName);
0103 
0104     /**
0105      * Remove a profile with all of its entries. This function does
0106      * not honor the useProfiles() function, so you can remove profiles
0107      * even if their usage is not enabled.
0108      *
0109      * @param name        The name of the profile
0110      */
0111     void removeProfile(const QString &name);
0112 
0113 Q_SIGNALS:
0114     /**
0115      * This signal is emitted when all entries of one profile was migrated
0116      * to another one. There are two special marker for profiles. If the
0117      * old name is '*', this means 'all profiles' and if the either the old
0118      * or the new name is an empty thing, this means 'default profile'.
0119      *
0120      * @param oldName     The name of the old profile
0121      * @param newName     The name of the new profile
0122      */
0123     void profileMigrated(const QString &oldName, const QString &newName);
0124 
0125     /**
0126      * This signal is emitted when a profile is to be removed.
0127      *
0128      * @param profile     The removed profile
0129      */
0130     void profileRemoved(const QString &profile);
0131 
0132     /**
0133      * This signal is emitted when the active profile is about
0134      * to be changed. You should connect to this signal, if you need
0135      * to save settings or the like to the OLD profile.
0136      */
0137     void aboutToChangeProfile();
0138 
0139     /**
0140      * This signal is emitted when the active profile changed.
0141      *
0142      * @param newProfile  The name of the new profile
0143      */
0144     void activeProfileChanged(const QString &newProfile);
0145 
0146     /**
0147      * This signal is emitted when the list of profiles changed.
0148      *
0149      * @param profiles    The list of profiles
0150      */
0151     void profilesListChanged(const QStringList &profiles);
0152 
0153     /**
0154      * This signal is emitted when the usage of profiles is switched
0155      * on or off.
0156      *
0157      * @param use           TRUE if profiles are used and FALSE otherwise
0158      */
0159     void profileUsageChanged(bool use);
0160 
0161 protected Q_SLOTS:
0162     /**
0163      * This slot is connected to the configChanged() signal of the
0164      * configuration object of the core.
0165      */
0166     void slotConfigChanged();
0167 
0168 private:
0169     /**
0170      * Pointer to Smb4KBookmarkHandlerPrivate class
0171      */
0172     const QScopedPointer<Smb4KProfileManagerPrivate> d;
0173 };
0174 
0175 #endif