File indexing completed on 2024-04-21 15:42:46
0001 /*************************************************************************** 0002 Manage custom options 0003 ------------------- 0004 begin : Fr 29 Apr 2011 0005 copyright : (C) 2011-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 SMB4KCUSTOMOPTIONSMANAGER_H 0027 #define SMB4KCUSTOMOPTIONSMANAGER_H 0028 0029 // application specific includes 0030 #include "smb4kglobal.h" 0031 0032 // Qt includes 0033 #include <QObject> 0034 #include <QScopedPointer> 0035 0036 // forward declarations 0037 class Smb4KCustomOptionsManagerPrivate; 0038 class Smb4KProfileManager; 0039 0040 /** 0041 * This classes manages the custom options that were defined 0042 * for a certain share or host. 0043 * 0044 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0045 * @since 1.0.0 0046 */ 0047 0048 class Q_DECL_EXPORT Smb4KCustomOptionsManager : public QObject 0049 { 0050 Q_OBJECT 0051 0052 friend class Smb4KCustomOptionsManagerPrivate; 0053 friend class Smb4KProfileManager; 0054 0055 public: 0056 /** 0057 * Constructor 0058 */ 0059 explicit Smb4KCustomOptionsManager(QObject *parent = 0); 0060 0061 /** 0062 * Destructor 0063 */ 0064 ~Smb4KCustomOptionsManager(); 0065 0066 /** 0067 * Returns a static pointer to this class 0068 * 0069 * @returns a static pointer to this class 0070 */ 0071 static Smb4KCustomOptionsManager *self(); 0072 0073 /** 0074 * Add the share to the list of shares that are to be remounted 0075 * either only on next program start or always Smb4K is restarted. 0076 * 0077 * @param share The share object 0078 * 0079 * @param always If set to TRUE the share is always mounted 0080 * when Smb4K is restarted. 0081 */ 0082 void addRemount(const SharePtr &share, bool always = false); 0083 0084 /** 0085 * Remove the share @p share from the list of shares that are to be 0086 * remounted. If @p force is set to TRUE, the share is removed even 0087 * if it should always be removed (option is set to 0088 * Smb4KCustomOptions::AlwaysRemount). Apart from that, the share is only 0089 * removed when the option is set to Smb4KCustomOptions::DoRemount. 0090 * 0091 * @param share The share object 0092 * 0093 * @param force If set to TRUE, the share is removed regardless of the 0094 * remount setting. 0095 */ 0096 void removeRemount(const SharePtr &share, bool force = false); 0097 0098 /** 0099 * Removes all remounts from the list of custom options. If @p force 0100 * is set to TRUE, even those are removed that should always be remounted. 0101 * 0102 * @param force If set to TRUE, even those shares are removed that should 0103 * always be remounted. 0104 */ 0105 void clearRemounts(bool force); 0106 0107 /** 0108 * Returns the list of shares that are to be remounted. 0109 * 0110 * @returns the list of shares that are to be remounted 0111 */ 0112 QList<OptionsPtr> sharesToRemount(); 0113 0114 /** 0115 * Find custom options for the network item @p networkItem. 0116 * 0117 * If the network item represents a share and custom options for it are not 0118 * defined, but for the host that provides the share, the options for the host 0119 * are returned. If neither is in the list, NULL is returned. 0120 * 0121 * If you set @p exactMatch to TRUE, NULL will be returned if the URL is not found. 0122 * Except in some special cases, you should not set @p exactMatch to true, 0123 * because options that are defined for all shares provided by a certain host and 0124 * stored in a host-type custom options object are ignored then. 0125 * 0126 * @param networkItem The network item 0127 * @param exaxtMatch If TRUE, only exact matches are returned 0128 * 0129 * @returns the custom options for the network item 0130 */ 0131 OptionsPtr findOptions(const NetworkItemPtr &networkItem, bool exactMatch = false); 0132 0133 /** 0134 * Find custom options for the provided @p url. 0135 * 0136 * This function searches the list of custom options and compares the host entry 0137 * and, if applicable, the path (i.e. the share name). If an exact match was found, 0138 * the corresponding custom options are returned. 0139 * 0140 * @param url The network item's URL 0141 * 0142 * @returns the custom options 0143 */ 0144 OptionsPtr findOptions(const QUrl &url); 0145 0146 /** 0147 * Get the list of custom options. By default, the list not only comprises of those 0148 * items that have custom options defined but also of those that are "only" to be 0149 * remounted. If @p optionsOnly is defined, only those entries are returned that have 0150 * custom options defined. Those that are only to be remounted won't be returned. 0151 * 0152 * @param optionsOnly Only return those entries that have custom options defined 0153 * 0154 * @returns the list of custom options objects. 0155 */ 0156 QList<OptionsPtr> customOptions(bool optionsOnly = false); 0157 0158 /** 0159 * Replace all previously defined custom options with a list of new ones. If you 0160 * just want to change certain custom options, use the findOptions() functions. 0161 * 0162 * @param optionsList The list of new or updated options 0163 */ 0164 void replaceCustomOptions(const QList<OptionsPtr> &optionsList); 0165 0166 /** 0167 * This function opens the custom options dialog. 0168 * 0169 * @param item The network item - either host or share 0170 * 0171 * @param parent The parent widget 0172 */ 0173 void openCustomOptionsDialog(const NetworkItemPtr &item); 0174 0175 /** 0176 * This function adds custom options for a single network item to the list 0177 * of options. If there already are options defined for that network item, 0178 * they are updated. 0179 * 0180 * Please note that this function will store a copy of @p options and not 0181 * the original object. 0182 * 0183 * @param options The custom options 0184 * 0185 * @param write Write the options to the file 0186 */ 0187 void addCustomOptions(const OptionsPtr &options, bool write = false); 0188 0189 /** 0190 * This function removes custom options for a single network item from the 0191 * list of options. 0192 * 0193 * @param options The custom options 0194 * 0195 * @param write Write the options to the file 0196 */ 0197 void removeCustomOptions(const OptionsPtr &options, bool write = false); 0198 0199 /** 0200 * This function returns a list of custom option objects that have 0201 * Wake-On-LAN features defined. 0202 * 0203 * @returns a list of custom options objects with WOL features defined. 0204 */ 0205 QList<OptionsPtr> wakeOnLanEntries() const; 0206 0207 /** 0208 * Reload custom options from the file. 0209 */ 0210 void resetCustomOptions(); 0211 0212 protected Q_SLOTS: 0213 /** 0214 * Called when the application exits 0215 */ 0216 void slotAboutToQuit(); 0217 0218 private: 0219 /** 0220 * Read custom options 0221 */ 0222 void readCustomOptions(); 0223 0224 /** 0225 * This function writes the custom options to the disk. 0226 */ 0227 void writeCustomOptions(); 0228 0229 /** 0230 * Migrates one profile to another. 0231 * 0232 * This function is meant to be used by the profile manager. 0233 * 0234 * @param from The name of the old profile. 0235 * @param to The name of the new profile. 0236 */ 0237 void migrateProfile(const QString &from, const QString &to); 0238 0239 /** 0240 * Removes a profile from the list of profiles. 0241 * 0242 * This function is meant to be used by the profile manager. 0243 * 0244 * @param name The name of the profile. 0245 */ 0246 void removeProfile(const QString &name); 0247 0248 /** 0249 * Pointer to Smb4KCustomOptionsManagerPrivate class 0250 */ 0251 const QScopedPointer<Smb4KCustomOptionsManagerPrivate> d; 0252 }; 0253 0254 #endif