File indexing completed on 2024-04-21 15:42:49
0001 /*************************************************************************** 0002 The core class that mounts the shares. 0003 ------------------- 0004 begin : Die Jun 10 2003 0005 copyright : (C) 2003-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 SMB4KMOUNTER_H 0027 #define SMB4KMOUNTER_H 0028 0029 // application specific includes 0030 #include "smb4kglobal.h" 0031 0032 // Qt includes 0033 #include <QObject> 0034 #include <QFile> 0035 #include <QString> 0036 #include <QStringList> 0037 #include <QScopedPointer> 0038 #include <QMap> 0039 #include <QVariant> 0040 0041 // KDE includes 0042 #include <KCoreAddons/KCompositeJob> 0043 0044 // forward declarations 0045 class Smb4KShare; 0046 class Smb4KAuthInfo; 0047 class Smb4KMountDialog; 0048 class Smb4KMountJob; 0049 class Smb4KUnmountJob; 0050 class Smb4KMounterPrivate; 0051 0052 /** 0053 * This is one of the core classes of Smb4K. It manages the mounting 0054 * and unmounting of remote Samba/Windows shares. Additionally it maintains a 0055 * list of all mounts with SMBFS and CIFS file system that are present 0056 * on the system. 0057 * 0058 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0059 */ 0060 0061 class Q_DECL_EXPORT Smb4KMounter : public KCompositeJob 0062 { 0063 Q_OBJECT 0064 0065 friend class Smb4KMounterPrivate; 0066 0067 public: 0068 /** 0069 * The constructor. 0070 */ 0071 explicit Smb4KMounter(QObject *parent = 0); 0072 0073 /** 0074 * The destructor. 0075 */ 0076 ~Smb4KMounter(); 0077 0078 /** 0079 * Returns a static pointer to this class. 0080 */ 0081 static Smb4KMounter *self(); 0082 0083 /** 0084 * Aborts all running processes. 0085 */ 0086 void abort(); 0087 0088 /** 0089 * This function attempts to mount a share. 0090 * 0091 * @param share The Smb4KShare object that is representing the share. 0092 */ 0093 void mountShare(const SharePtr &share); 0094 0095 /** 0096 * Mounts a list of shares at once. 0097 * 0098 * @param shares The list of shares 0099 */ 0100 void mountShares(const QList<SharePtr> &shares); 0101 0102 /** 0103 * This function attempts to unmount a share. With the parameter @p silent you 0104 * can suppress any error messages. 0105 * 0106 * @param share The share object that should be unmounted. 0107 * 0108 * @param silent Determines whether this function should emit an error code in 0109 * case of an error. The default value is FALSE. 0110 */ 0111 void unmountShare(const SharePtr &share, bool silent = false); 0112 0113 /** 0114 * This function attempts to unmount a list of shares. With the parameter @p silent 0115 * you can suppress any error messages. 0116 * 0117 * @param shares The list of shares that is to be unmounted 0118 * 0119 * @param silent Determines whether this function should emit an error code in 0120 * case of an error. The default value is FALSE. 0121 */ 0122 void unmountShares(const QList<SharePtr> &shares, bool silent = false); 0123 0124 /** 0125 * Unmounts all shares at once. This is a convenience function. It calls 0126 * unmountShares() to unmount all currently mounted shares. 0127 * 0128 * @param silent Determines whether this function should emit an error code in 0129 * case of an error. The default value is FALSE. 0130 */ 0131 void unmountAllShares(bool silent); 0132 0133 /** 0134 * Mount a share via a mount dialog. The mount dialog is opened and you have 0135 * to enter the UNC and optionally the workgroup and IP address. 0136 */ 0137 void openMountDialog(); 0138 0139 /** 0140 * This function reports if the mounter is running or not. 0141 * 0142 * @returns TRUE if the mounter is running and FALSE otherwise. 0143 */ 0144 bool isRunning(); 0145 0146 /** 0147 * This function starts the composite job 0148 */ 0149 void start() override; 0150 0151 Q_SIGNALS: 0152 /** 0153 * This signal is emitted whenever a share item was updated. 0154 * 0155 * @param share The share item that was just updated. 0156 */ 0157 void updated(const SharePtr &share); 0158 0159 /** 0160 * This signal is emitted when a share has successfully been mounted. 0161 * 0162 * @param share The share that was just mounted. 0163 */ 0164 void mounted(const SharePtr &share); 0165 0166 /** 0167 * This signal is emitted after a share has successfully been unmounted. 0168 * 0169 * @param share The share that was unmounted. 0170 */ 0171 void unmounted(const SharePtr &share); 0172 0173 /** 0174 * This signal is emitted when a process is about to start. 0175 * @param process The kind of process 0176 */ 0177 void aboutToStart(int process); 0178 0179 /** 0180 * This signal is emitted when a process finished. 0181 * @param process The kind of process 0182 */ 0183 void finished(int process); 0184 0185 /** 0186 * This signal is emitted every time a share was added to or removed 0187 * from the list of shares. In contrast to the mounted() and unmounted() 0188 * signals, this signal is emitted at the end of the modification of 0189 * the list (the unmount() signal is emitted before the share is actually 0190 * removed from the list). 0191 * 0192 * If you need to know if the contents of a specific share has been changed, 0193 * you need to connect to the updated() signal. 0194 */ 0195 void mountedSharesListChanged(); 0196 0197 protected: 0198 /** 0199 * Reimplemented from QObject to process the queue. 0200 * 0201 * @param event The QTimerEvent event 0202 */ 0203 void timerEvent(QTimerEvent *event) override; 0204 0205 protected Q_SLOTS: 0206 /** 0207 * Starts the composite job 0208 */ 0209 void slotStartJobs(); 0210 0211 /** 0212 * This slot is called by the QApplication::aboutToQuit() signal. 0213 * Is does everything that has to be done before the program 0214 * really exits. 0215 */ 0216 void slotAboutToQuit(); 0217 0218 /** 0219 * This slot is called when the online status changed. It is used 0220 * to initialize network actions when the network becomes available. 0221 * @param online TRUE if online otherwise FALSE 0222 */ 0223 void slotOnlineStateChanged(bool online); 0224 0225 /** 0226 * Called when a mounted share has been stat'ed. 0227 * 0228 * @param job The KIO::StatJob 0229 */ 0230 void slotStatResult(KJob *job); 0231 0232 /** 0233 * This slot is invoked when the active profile is about to be changed 0234 */ 0235 void slotAboutToChangeProfile(); 0236 0237 /** 0238 * This slot is called when the active profile changed. 0239 */ 0240 void slotActiveProfileChanged(const QString &newProfile); 0241 0242 /** 0243 * This slot is called when a profile was migrated. 0244 * 0245 * @param from The old profile 0246 * @param to The new profile 0247 */ 0248 void slotProfileMigrated(const QString &from, const QString &to); 0249 0250 /** 0251 * This slot is called whenever a network share is mounted or 0252 * unmounted. 0253 */ 0254 void slotTriggerImport(); 0255 0256 /** 0257 * This slot is called whenever the configuration changed. It is used 0258 * to trigger the importing of shares when certain settings changed. 0259 */ 0260 void slotConfigChanged(); 0261 0262 private: 0263 /** 0264 * Trigger the remounting of shares. If the parameter @p fill_list is 0265 * set to true, the internal list should be populated with the shares 0266 * that are scheduled for a remount. 0267 * 0268 * @param fill_list Fill the internal list with shares that are 0269 * to be remounted. 0270 */ 0271 void triggerRemounts(bool fill_list); 0272 0273 /** 0274 * Imports mounted shares. 0275 */ 0276 void import(bool checkInaccessible); 0277 0278 /** 0279 * Save all shares that need to be remounted. 0280 */ 0281 void saveSharesForRemount(); 0282 0283 /** 0284 * Fill the mount action arguments into a map. 0285 */ 0286 bool fillMountActionArgs(const SharePtr &share, QVariantMap &mountArgs); 0287 0288 /** 0289 * Fill the unmount action arguments into a map. 0290 */ 0291 bool fillUnmountActionArgs(const SharePtr &share, bool force, bool silent, QVariantMap &unmountArgs); 0292 0293 /** 0294 * Check the size, accessibility, ids, etc. of the share(s) 0295 */ 0296 void check(const SharePtr &share); 0297 0298 /** 0299 * Pointer to the Smb4KMounterPrivate class. 0300 */ 0301 const QScopedPointer<Smb4KMounterPrivate> d; 0302 }; 0303 0304 #endif