File indexing completed on 2024-04-21 15:42:48

0001 /***************************************************************************
0002     This class handles the homes shares
0003                              -------------------
0004     begin                : Do Aug 10 2006
0005     copyright            : (C) 2006-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 SMB4KHOMESSHARESHANDLER_H
0027 #define SMB4KHOMESSHARESHANDLER_H
0028 
0029 // application specific includes
0030 #include "smb4kglobal.h"
0031 
0032 // Qt includes
0033 #include <QObject>
0034 #include <QString>
0035 #include <QStringList>
0036 #include <QList>
0037 #include <QScopedPointer>
0038 #include <QDialog>
0039 
0040 
0041 // forward declarations
0042 class Smb4KAuthInfo;
0043 class Smb4KHomesUsers;
0044 class Smb4KHomesSharesHandlerPrivate;
0045 class Smb4KProfileManager;
0046 
0047 
0048 /**
0049  * This class belongs to the core of Smb4K and takes care of the
0050  * user names that are/were defined for a certain 'homes' share.
0051  *
0052  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0053  */
0054 
0055 class Q_DECL_EXPORT Smb4KHomesSharesHandler : public QObject
0056 {
0057   Q_OBJECT
0058 
0059   friend class Smb4KHomesSharesHandlerPrivate;
0060   friend class Smb4KProfileManager;
0061 
0062   public:
0063     /**
0064      * The constructor
0065      */
0066     explicit Smb4KHomesSharesHandler(QObject *parent = 0);
0067 
0068     /**
0069      * The destructor
0070      */
0071     ~Smb4KHomesSharesHandler();
0072     
0073     /**
0074      * Returns a static pointer to this class.
0075      */
0076     static Smb4KHomesSharesHandler *self();
0077 
0078     /**
0079      * This function will open a dialog where the user has to define a
0080      * user name to access a 'homes' share. You also can define if the 
0081      * user name should be overwritten in case one has already been set
0082      * (default is TRUE).
0083      *
0084      * In case that a new username is set by this function, the password
0085      * is cleared.
0086      *
0087      * @param share       The share that is representing the homes share
0088      * 
0089      * @param overwrite   Overwrite user name or not
0090      *
0091      * @returns TRUE if user has been chosen and FALSE otherwise.
0092      */
0093     bool specifyUser(const SharePtr &share, bool overwrite = true);
0094     
0095     /**
0096      * Return the list of users defined for a certain homes share.
0097      * 
0098      * @param share       The share
0099      * 
0100      * @returns a list of users
0101      */
0102     QStringList homesUsers(const SharePtr &share);
0103     
0104   protected Q_SLOTS:
0105     /**
0106      * Called when the application goes down
0107      */
0108     void slotAboutToQuit();
0109     
0110     /**
0111      * This slot is called if the active profile changed.
0112      * 
0113      * @param activeProfile   The name of the active profile
0114      */
0115     void slotActiveProfileChanged(const QString &activeProfile);
0116     
0117   private:
0118     /**
0119      * Load the host and user names into a map.
0120      */
0121     const QList<Smb4KHomesUsers *> readUserNames(bool readAll);
0122 
0123     /**
0124      * This function writes the homes user entries to the disk. If @p listOnly 
0125      * is set to TRUE, only the list that was passed will be written to the 
0126      * file replacing the existing homes user entries. If it is FALSE (the 
0127      * default), the list will be merged with the existing homes user entries. 
0128      *
0129      * @param list          The (new) list of homes user entries that is to be 
0130      *                      written.
0131      * @param listOnly      If TRUE only the passed list will be written to
0132      *                      the file.
0133      */
0134     void writeUserNames(const QList<Smb4KHomesUsers *> &list, bool listOnly = false);
0135     
0136     /**
0137      * Find the homes user for a specific share
0138      */
0139     const QStringList findHomesUsers(const SharePtr &share);
0140     
0141     /**
0142      * Add user to a homes share
0143      */
0144     void addHomesUsers(const SharePtr &share, const QStringList &users);
0145     
0146     /**
0147      * Migrates one profile to another.
0148      * 
0149      * This function is meant to be used by the profile manager.
0150      * 
0151      * @param from        The name of the old profile.
0152      * @param to          The name of the new profile.
0153      */
0154     void migrateProfile(const QString &from, const QString &to);
0155     
0156     /**
0157      * Removes a profile from the list of profiles.
0158      * 
0159      * This function is meant to be used by the profile manager.
0160      * 
0161      * @param name        The name of the profile.
0162      */
0163     void removeProfile(const QString &name);
0164 
0165     /**
0166      * Pointer to the Smb4KHomesSharesHandlerPrivate class
0167      */
0168     const QScopedPointer<Smb4KHomesSharesHandlerPrivate> d;
0169 };
0170 
0171 #endif