File indexing completed on 2024-04-14 15:05:30

0001 /***************************************************************************
0002     This class manages the profiles that were defined by the user.
0003                              -------------------
0004     begin                : Mi Aug 06 2014
0005     copyright            : (C) 2014-2019 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 #ifndef SMB4KPROFILEMANAGER_H
0027 #define SMB4KPROFILEMANAGER_H
0028 
0029 // Qt includes
0030 #include <QObject>
0031 #include <QScopedPointer>
0032 #include <QString>
0033 #include <QStringList>
0034 #include <QPair>
0035 
0036 // forward declarations
0037 class Smb4KProfileManagerPrivate;
0038 
0039 /**
0040  * This class "manages" the profiles defined by the user in such a 
0041  * degree as it sends signals when the active profile changed, a
0042  * profile was renamed or removed. You can also actively initiate the
0043  * migration of or remove a profile.
0044  * 
0045  * When using profiles, please use this class instead of the KConfig XT
0046  * class(es).
0047  * 
0048  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0049  * @since 1.2.0
0050  */
0051 
0052 
0053 class Q_DECL_EXPORT Smb4KProfileManager : public QObject
0054 {
0055   Q_OBJECT
0056   
0057   public:
0058     /**
0059      * Constructor
0060      */
0061     explicit Smb4KProfileManager(QObject *parent = 0);
0062     
0063     /**
0064      * Destructor
0065      */
0066     virtual ~Smb4KProfileManager();
0067     
0068     /**
0069      * Returns a static pointer to this class.
0070      * 
0071      * @returns a static pointer to this class.
0072      */
0073     static Smb4KProfileManager *self();
0074     
0075     /**
0076      * Set the active profile if the use of profiles is enabled.
0077      * Otherwise the this function does nothing.
0078      * 
0079      * @param name        Name of the active profile.
0080      * 
0081      * @returns true if the active profile was changed.
0082      */
0083     void setActiveProfile(const QString &name);
0084     
0085     /**
0086      * Return the currently active profile or an empty string if 
0087      * the use of profiles is disabled.
0088      * 
0089      * @returns the active profile.
0090      */
0091     QString activeProfile() const;
0092     
0093     /**
0094      * Returns the list of profiles or an empty string list if the 
0095      * the use of profiles is disabled.
0096      * 
0097      * @returns the list of profiles.
0098      */
0099     QStringList profilesList() const;
0100     
0101     /**
0102      * Returns if profiles should be used or not. This is basically 
0103      * a convenience function, since it just returns 
0104      * Smb4KSettings::useProfiles().
0105      * 
0106      * @returns true if profiles should be used.
0107      */
0108     bool useProfiles() const;
0109     
0110     /**
0111      * Migrate all entries of one profile to another.
0112      * 
0113      * @param from        The name of the old profile.
0114      * @param to          The name of the new profile.
0115      */
0116     void migrateProfile(const QString &from, const QString &to);
0117     
0118     /**
0119      * Migrate all entries of a list of profiles to other profiles.
0120      * 
0121      * @param list        The list of profile pairs. The first entry
0122      *                    is the "from" profile, the second one the 
0123      *                    "to" profile.
0124      */
0125     void migrateProfiles(const QList<QPair<QString,QString>> &list);
0126     
0127     /**
0128      * Remove a profile with all of its entries.
0129      * 
0130      * @param name        The name of the profile.
0131      */
0132     void removeProfile(const QString &name);
0133     
0134     /**
0135      * Remove a list of profiles with all of their entries.
0136      * 
0137      * @param list        The list of profile names.
0138      */
0139     void removeProfiles(const QStringList &list);
0140     
0141   Q_SIGNALS:
0142     /**
0143      * This signal is emitted when all entries of one profile was migrated
0144      * to another one.
0145      * 
0146      * @param from        The old profile
0147      * @param to          The new profile
0148      */
0149     void migratedProfile(const QString &from, const QString &to);
0150     
0151     /**
0152      * This signal is emitted when a profile was removed.
0153      * 
0154      * @param profile     The removed profile
0155      */
0156     void removedProfile(const QString &profile);
0157     
0158     /**
0159      * This signal is emitted when the active profile is about 
0160      * to be changed. You should connect to this signal, if you need 
0161      * to save settings or the like to the OLD profile.
0162      */
0163     void aboutToChangeProfile();
0164     
0165     /**
0166      * This signal is emitted when the active profile changed.
0167      * 
0168      * @param newProfile  The name of the new profile
0169      */
0170     void activeProfileChanged(const QString &newProfile);
0171     
0172     /**
0173      * This signal is emitted when the list of profiles changed.
0174      * 
0175      * @param profiles    The list of profiles
0176      */
0177     void profilesListChanged(const QStringList &profiles);
0178     
0179     /**
0180      * This signal is emitted when the usage of profiles is switched
0181      * on or off.
0182      * 
0183      * @param use           TRUE if profiles are used and FALSE otherwise
0184      */
0185     void profileUsageChanged(bool use);
0186     
0187   protected Q_SLOTS:
0188     /**
0189      * This slot is connected to the configChanged() signal of the
0190      * configuration object of the core.
0191      */
0192     void slotConfigChanged();
0193     
0194   private:
0195     /**
0196      * Pointer to Smb4KBookmarkHandlerPrivate class
0197      */
0198     const QScopedPointer<Smb4KProfileManagerPrivate> d;
0199 };
0200 
0201 #endif