1 /*************************************************************************** 2 This class manages the profiles that were defined by the user. 3 ------------------- 4 begin : Mi Aug 06 2014 5 copyright : (C) 2014-2019 by Alexander Reinholdt 6 email : alexander.reinholdt@kdemail.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * This program is free software; you can redistribute it and/or modify * 11 * it under the terms of the GNU General Public License as published by * 12 * the Free Software Foundation; either version 2 of the License, or * 13 * (at your option) any later version. * 14 * * 15 * This program is distributed in the hope that it will be useful, but * 16 * WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 18 * General Public License for more details. * 19 * * 20 * You should have received a copy of the GNU General Public License * 21 * along with this program; if not, write to the * 22 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* 23 * MA 02110-1335, USA * 24 ***************************************************************************/ 25 26 #ifndef SMB4KPROFILEMANAGER_H 27 #define SMB4KPROFILEMANAGER_H 28 29 // Qt includes 30 #include <QObject> 31 #include <QScopedPointer> 32 #include <QString> 33 #include <QStringList> 34 #include <QPair> 35 36 // forward declarations 37 class Smb4KProfileManagerPrivate; 38 39 /** 40 * This class "manages" the profiles defined by the user in such a 41 * degree as it sends signals when the active profile changed, a 42 * profile was renamed or removed. You can also actively initiate the 43 * migration of or remove a profile. 44 * 45 * When using profiles, please use this class instead of the KConfig XT 46 * class(es). 47 * 48 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 49 * @since 1.2.0 50 */ 51 52 53 class Q_DECL_EXPORT Smb4KProfileManager : public QObject 54 { 55 Q_OBJECT 56 57 public: 58 /** 59 * Constructor 60 */ 61 explicit Smb4KProfileManager(QObject *parent = 0); 62 63 /** 64 * Destructor 65 */ 66 virtual ~Smb4KProfileManager(); 67 68 /** 69 * Returns a static pointer to this class. 70 * 71 * @returns a static pointer to this class. 72 */ 73 static Smb4KProfileManager *self(); 74 75 /** 76 * Set the active profile if the use of profiles is enabled. 77 * Otherwise the this function does nothing. 78 * 79 * @param name Name of the active profile. 80 * 81 * @returns true if the active profile was changed. 82 */ 83 void setActiveProfile(const QString &name); 84 85 /** 86 * Return the currently active profile or an empty string if 87 * the use of profiles is disabled. 88 * 89 * @returns the active profile. 90 */ 91 QString activeProfile() const; 92 93 /** 94 * Returns the list of profiles or an empty string list if the 95 * the use of profiles is disabled. 96 * 97 * @returns the list of profiles. 98 */ 99 QStringList profilesList() const; 100 101 /** 102 * Returns if profiles should be used or not. This is basically 103 * a convenience function, since it just returns 104 * Smb4KSettings::useProfiles(). 105 * 106 * @returns true if profiles should be used. 107 */ 108 bool useProfiles() const; 109 110 /** 111 * Migrate all entries of one profile to another. 112 * 113 * @param from The name of the old profile. 114 * @param to The name of the new profile. 115 */ 116 void migrateProfile(const QString &from, const QString &to); 117 118 /** 119 * Migrate all entries of a list of profiles to other profiles. 120 * 121 * @param list The list of profile pairs. The first entry 122 * is the "from" profile, the second one the 123 * "to" profile. 124 */ 125 void migrateProfiles(const QList<QPair<QString,QString>> &list); 126 127 /** 128 * Remove a profile with all of its entries. 129 * 130 * @param name The name of the profile. 131 */ 132 void removeProfile(const QString &name); 133 134 /** 135 * Remove a list of profiles with all of their entries. 136 * 137 * @param list The list of profile names. 138 */ 139 void removeProfiles(const QStringList &list); 140 141 Q_SIGNALS: 142 /** 143 * This signal is emitted when all entries of one profile was migrated 144 * to another one. 145 * 146 * @param from The old profile 147 * @param to The new profile 148 */ 149 void migratedProfile(const QString &from, const QString &to); 150 151 /** 152 * This signal is emitted when a profile was removed. 153 * 154 * @param profile The removed profile 155 */ 156 void removedProfile(const QString &profile); 157 158 /** 159 * This signal is emitted when the active profile is about 160 * to be changed. You should connect to this signal, if you need 161 * to save settings or the like to the OLD profile. 162 */ 163 void aboutToChangeProfile(); 164 165 /** 166 * This signal is emitted when the active profile changed. 167 * 168 * @param newProfile The name of the new profile 169 */ 170 void activeProfileChanged(const QString &newProfile); 171 172 /** 173 * This signal is emitted when the list of profiles changed. 174 * 175 * @param profiles The list of profiles 176 */ 177 void profilesListChanged(const QStringList &profiles); 178 179 /** 180 * This signal is emitted when the usage of profiles is switched 181 * on or off. 182 * 183 * @param use TRUE if profiles are used and FALSE otherwise 184 */ 185 void profileUsageChanged(bool use); 186 187 protected Q_SLOTS: 188 /** 189 * This slot is connected to the configChanged() signal of the 190 * configuration object of the core. 191 */ 192 void slotConfigChanged(); 193 194 private: 195 /** 196 * Pointer to Smb4KBookmarkHandlerPrivate class 197 */ 198 const QScopedPointer<Smb4KProfileManagerPrivate> d; 199 }; 200 201 #endif 202