File indexing completed on 2024-04-28 05:01:56

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