File indexing completed on 2024-04-21 15:42:45
0001 /*************************************************************************** 0002 This class carries 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 SMB4KCUSTOMOPTIONS_H 0027 #define SMB4KCUSTOMOPTIONS_H 0028 0029 // application specific includes 0030 #include "smb4khost.h" 0031 #include "smb4kshare.h" 0032 #include "smb4kglobal.h" 0033 0034 // Qt includes 0035 #include <QScopedPointer> 0036 #include <QUrl> 0037 0038 // KDE includes 0039 #include <KCoreAddons/KUser> 0040 0041 // forward declarations 0042 class Smb4KCustomOptionsPrivate; 0043 0044 using namespace Smb4KGlobal; 0045 0046 /** 0047 * This class stores the custom options defined for a certain host 0048 * or share. 0049 * 0050 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0051 * @since 1.0.0 0052 */ 0053 0054 class Q_DECL_EXPORT Smb4KCustomOptions 0055 { 0056 friend class Smb4KCustomOptionsPrivate; 0057 0058 public: 0059 /** 0060 * Constructor for a host 0061 */ 0062 explicit Smb4KCustomOptions(Smb4KHost *host); 0063 0064 /** 0065 * Constructor for a share 0066 */ 0067 explicit Smb4KCustomOptions(Smb4KShare *share); 0068 0069 /** 0070 * Copy constructor 0071 */ 0072 Smb4KCustomOptions(const Smb4KCustomOptions &options); 0073 0074 /** 0075 * Empty constructor 0076 */ 0077 Smb4KCustomOptions(); 0078 0079 /** 0080 * Destructor 0081 */ 0082 ~Smb4KCustomOptions(); 0083 0084 /** 0085 * Sets the host object. If you already set a network item before, 0086 * this function will do nothing. 0087 * 0088 * @param host The host object 0089 */ 0090 void setHost(Smb4KHost *host); 0091 0092 /** 0093 * Sets the share object. If you already set a host item before, 0094 * you can overwrite it with this function if the host names and 0095 * workgroup names match. This way you can propagate options that 0096 * were defined for a host to one of its shares. 0097 * 0098 * @param share The host object 0099 */ 0100 void setShare(Smb4KShare *share); 0101 0102 /** 0103 * Returns the type of the network item for that the options 0104 * are defined 0105 * 0106 * @returns the type of the network item 0107 */ 0108 Smb4KGlobal::NetworkItem type() const; 0109 0110 /** 0111 * Sets the workgroup name. 0112 * 0113 * @param workgroup The workgroup name 0114 */ 0115 void setWorkgroupName(const QString &workgroup); 0116 0117 /** 0118 * Returns the workgroup name. 0119 * 0120 * @returns the workgroup name. 0121 */ 0122 QString workgroupName() const; 0123 0124 /** 0125 * Sets the URL of the network item 0126 * 0127 * @param url The URL 0128 */ 0129 void setUrl(const QUrl &url); 0130 0131 /** 0132 * Returns the URL of the network item 0133 * 0134 * @returns the URL 0135 */ 0136 QUrl url() const; 0137 0138 /** 0139 * Returns the host name. 0140 * 0141 * @returns the host name. 0142 */ 0143 QString hostName() const; 0144 0145 /** 0146 * Returns the share name, if appropriate, or an empty string. 0147 * 0148 * @returns the share name 0149 */ 0150 QString shareName() const; 0151 0152 /** 0153 * Sets the IP address for the network item 0154 * 0155 * @param ip The IP address 0156 */ 0157 void setIpAddress(const QString &ip); 0158 0159 /** 0160 * Returns the IP address of the network item 0161 * 0162 * @returns the IP address 0163 */ 0164 QString ipAddress() const; 0165 0166 /** 0167 * Returns TRUE if the IP address is set and FALSE otherwise. 0168 * 0169 * @returns TRUE if the IP address is known. 0170 */ 0171 bool hasIpAddress() const; 0172 0173 /** 0174 * Returns the display string. Prefer this over all other alternatives in your 0175 * GUI. 0176 * @returns the display string. 0177 */ 0178 QString displayString() const; 0179 0180 /** 0181 * Remount enumeration 0182 * 0183 * @param RemountOnce Remount the share only next time the application 0184 * is started. 0185 * @param RemountAlways Remount the share every time the application is 0186 * started. 0187 * @param RemountNever Never remount the share. 0188 * @param UndefinedRemount No remount behavior is undefined. 0189 */ 0190 enum Remount { RemountOnce, 0191 RemountAlways, 0192 UndefinedRemount }; 0193 0194 /** 0195 * If the network item is of type Share, set if it should be remounted. 0196 * If the network item is not of type Share, this function does nothing. 0197 * 0198 * @param remount One entry of the Remount enumeration 0199 */ 0200 void setRemount(Remount remount); 0201 0202 /** 0203 * Returns if the network item should be remounted. 0204 * 0205 * @returns if the network item should be remounted. 0206 */ 0207 Remount remount() const; 0208 0209 /** 0210 * Set if the information about the user that is to be owner of the share 0211 * should be used when mounting or not. 0212 * 0213 * @param usage Boolean that determines whether the uid should be 0214 * used. 0215 */ 0216 void setUseUser(bool use); 0217 0218 /** 0219 * Use the information about the user that is to be owner of the share. 0220 * 0221 * @returns TRUE if the uid should be used when mounting. 0222 */ 0223 bool useUser() const; 0224 0225 /** 0226 * Set the user who owns the share. 0227 * @param user The user 0228 */ 0229 void setUser(const KUser &user); 0230 0231 /** 0232 * Returns the user who owns the share. 0233 * @returns the user 0234 */ 0235 KUser user() const; 0236 0237 /** 0238 * Set if the information about the group that is to be owner of the share 0239 * should be used when mounting or not. 0240 * 0241 * @param use Boolean that determines whether the gid should be used. 0242 */ 0243 void setUseGroup(bool use); 0244 0245 /** 0246 * Use the information about the group that is to be owner of the share. 0247 * 0248 * @returns TRUE if the gid should be used when mounting. 0249 */ 0250 bool useGroup() const; 0251 0252 /** 0253 * Set the group that owns the share. 0254 * 0255 * @param group The group 0256 */ 0257 void setGroup(const KUserGroup &group); 0258 0259 /** 0260 * Returns the group that owns the share. 0261 * 0262 * @returns the group 0263 */ 0264 KUserGroup group() const; 0265 0266 /** 0267 * Set if the file mode should be used. 0268 * 0269 * @param use Boolean that determines whether the file mode should be used. 0270 */ 0271 void setUseFileMode(bool use); 0272 0273 /** 0274 * Returns if the file mode should be used. 0275 * 0276 * @return TRUE if the file mode should be used 0277 */ 0278 bool useFileMode() const; 0279 0280 /** 0281 * Set the file mode that should be used. The value must be defined in octal. 0282 * 0283 * @param mode The file mode 0284 */ 0285 void setFileMode(const QString &mode); 0286 0287 /** 0288 * Returns the file mode that should be used. The value is returned in octal. 0289 * 0290 * @returns the file mode 0291 */ 0292 QString fileMode() const; 0293 0294 /** 0295 * Set if the directory mode should be used. 0296 * 0297 * @param use Boolean that determines whether the directory mode should be used. 0298 */ 0299 void setUseDirectoryMode(bool use); 0300 0301 /** 0302 * Returns if the directory mode should be used. 0303 * 0304 * @return TRUE if the file directory should be used 0305 */ 0306 bool useDirectoryMode() const; 0307 0308 /** 0309 * Set the directory mode that should be used. The value must be defined in octal. 0310 * 0311 * @param mode The directory mode 0312 */ 0313 void setDirectoryMode(const QString &mode); 0314 0315 /** 0316 * Returns the directory mode that should be used. The value is returned in octal. 0317 * 0318 * @returns the directory mode 0319 */ 0320 QString directoryMode() const; 0321 0322 #if defined(Q_OS_LINUX) 0323 /** 0324 * Set if the server supports the CIFS Unix Extensions. If this setting is set, 0325 * the parameters that are not needed in the case of support are cleared. 0326 * 0327 * @param supports Boolean that determines if the server supports 0328 * the CIFS Unix extensions. 0329 */ 0330 void setCifsUnixExtensionsSupport(bool support); 0331 0332 /** 0333 * The server supports the CIFS Unix extensions. 0334 * 0335 * @returns TRUE if the server supports the CIFS Unix Extensions. 0336 */ 0337 bool cifsUnixExtensionsSupport() const; 0338 0339 /** 0340 * Set if the filesystem port should be used 0341 * 0342 * @param use Boolean that determines if the filesystem port should 0343 * be used 0344 */ 0345 void setUseFileSystemPort(bool use); 0346 0347 /** 0348 * Returns if the filesystem port should be used. 0349 * 0350 * @returns TRUE if the filesystem port should be used 0351 */ 0352 bool useFileSystemPort() const; 0353 0354 /** 0355 * Set the port that is to be used with mounting for a single share or all 0356 * shares of a host. 0357 * 0358 * @param port The file system port 0359 */ 0360 void setFileSystemPort(int port); 0361 0362 /** 0363 * Returns the file system port. The default value is 445. 0364 * 0365 * @returns the file system port 0366 */ 0367 int fileSystemPort() const; 0368 0369 /** 0370 * Set if the security mode should be used. 0371 * 0372 * @param use Boolean that determines if the security mode should 0373 * be used 0374 */ 0375 void setUseSecurityMode(bool use); 0376 0377 /** 0378 * Returns if the security mode should be used 0379 * 0380 * @returns TRUE if the security mode should be used 0381 */ 0382 bool useSecurityMode() const; 0383 0384 /** 0385 * Set the security mode for mounting. 0386 * 0387 * @param mode The security mode 0388 */ 0389 void setSecurityMode(int mode); 0390 0391 /** 0392 * Returns the security mode for mounting a specific share. 0393 * 0394 * @returns the security mode 0395 */ 0396 int securityMode() const; 0397 0398 /** 0399 * Set if the write access setting should be used. 0400 * 0401 * @param use Boolean that determines if the write access setting 0402 * should be used 0403 */ 0404 void setUseWriteAccess(bool use); 0405 0406 /** 0407 * Returns if the write access setting should be used 0408 * 0409 * @returns TRUE if the write access setting should be used 0410 */ 0411 bool useWriteAccess() const; 0412 0413 /** 0414 * Set the write access for either a single share or all shares of a host. 0415 * 0416 * @param access The write access 0417 */ 0418 void setWriteAccess(int access); 0419 0420 /** 0421 * Returns the write access for the share. 0422 * 0423 * @returns the write access 0424 */ 0425 int writeAccess() const; 0426 #endif 0427 0428 /** 0429 * Set the profile this custom options object belongs to. The profile is 0430 * meant to distinguish between several network environments, like home 0431 * and work. 0432 * 0433 * @param profile The profile name 0434 */ 0435 void setProfile(const QString &profile); 0436 0437 /** 0438 * Returns the name of the profile this custom options object belongs to. 0439 * 0440 * @returns the profile name 0441 */ 0442 QString profile() const; 0443 0444 /** 0445 * Set whether the SMB port should be used. 0446 * 0447 * @param use True, if the SMB port should be used 0448 */ 0449 void setUseSmbPort(bool use); 0450 0451 /** 0452 * Returns whether the SMB port should be used. 0453 * 0454 * @returns TRUE if the SMB port should be used. 0455 */ 0456 bool useSmbPort() const; 0457 0458 /** 0459 * Set the SMB port to use with this host or share. 0460 * 0461 * @param port The SMB port 0462 */ 0463 void setSmbPort(int port); 0464 0465 /** 0466 * Returns the SMB port. The default value is 139. 0467 * 0468 * @returns the SMB port 0469 */ 0470 int smbPort() const; 0471 0472 /** 0473 * Sets the useage of Kerberos for this network item. 0474 * 0475 * @param use Boolean that determines the useage of Kerberos 0476 */ 0477 void setUseKerberos(bool use); 0478 0479 /** 0480 * Returns the usage of Kerberos for this network item. 0481 * 0482 * @returns the usage of Kerberos 0483 */ 0484 bool useKerberos() const; 0485 0486 /** 0487 * This function sets the MAC address of a host. In case the options 0488 * represent a share this is the MAC address of the host that shares 0489 * the resource. 0490 * 0491 * @param macAddress The MAC address of the host 0492 */ 0493 void setMACAddress(const QString &macAddress); 0494 0495 /** 0496 * This function returns the MAC address of the host or an empty string if 0497 * no MAC address was defined. 0498 * 0499 * @returns the MAC address of the host. 0500 */ 0501 QString macAddress() const; 0502 0503 /** 0504 * Set whether a magic WOL package should be send to the host that this 0505 * network item represents or where this network item is located before scanning 0506 * the entire network. 0507 * 0508 * @param send Boolean that determines if a magic WOL package 0509 * is to be sent. 0510 */ 0511 void setWOLSendBeforeNetworkScan(bool send); 0512 0513 /** 0514 * Send a magic WOL package to the host that this network item represents 0515 * or where this network item is located before scanning the entire network. 0516 * 0517 * @returns TRUE if a magic WOL package should be send on first network 0518 * scan. 0519 */ 0520 bool wolSendBeforeNetworkScan() const; 0521 0522 /** 0523 * Set whether a magic WOL package should be send to the host that this 0524 * network item represents or where this network item is located before a 0525 * mount attempt. 0526 * 0527 * @param send Boolean that determines if a magic WOL package 0528 * is to be sent. 0529 */ 0530 void setWOLSendBeforeMount(bool send); 0531 0532 /** 0533 * Send a magic WOL package to the host that this network item represents 0534 * or where this network item is located before a mount attempt. 0535 * 0536 * @returns TRUE if a magic WOL package should be send on first network 0537 * scan. 0538 */ 0539 bool wolSendBeforeMount() const; 0540 0541 /** 0542 * This function returns all custom options in a sorted map. The URL, 0543 * workgroup and IP address must be retrieved separately if needed. 0544 * 0545 * Note that all entries that are set and valid are returned here. This 0546 * also comprises default values (e.g. the default SMB port). If you need 0547 * to check if a certain value is a custom option or not, you need to implement 0548 * this check. 0549 * 0550 * @returns all valid entries. 0551 */ 0552 QMap<QString,QString> customOptions() const; 0553 0554 /** 0555 * Check if there are options defined 0556 * 0557 * @returns TRUE if there are options defined and FALSE otherwise 0558 */ 0559 bool hasOptions() const; 0560 0561 /** 0562 * Update this custom options object. You cannot change the workgroup, 0563 * URL and type with this function. 0564 * 0565 * @param options The options that are used to update this object 0566 */ 0567 void update(Smb4KCustomOptions *options); 0568 0569 private: 0570 const QScopedPointer<Smb4KCustomOptionsPrivate> d; 0571 }; 0572 0573 #endif 0574