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