File indexing completed on 2024-04-28 12:45:27

0001 /*
0002     Smb4K's container class for information about a host.
0003 
0004     SPDX-FileCopyrightText: 2008-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SMB4KHOST_H
0009 #define SMB4KHOST_H
0010 
0011 // application specific includes
0012 #include "smb4kbasicnetworkitem.h"
0013 
0014 // Qt includes
0015 #include <QHostAddress>
0016 #include <QScopedPointer>
0017 #include <QString>
0018 
0019 // forward declarations
0020 class Smb4KAuthInfo;
0021 class Smb4KHostPrivate;
0022 
0023 /**
0024  * This class is a container that carries information about a host found in
0025  * the network neighborhood. It is part of the core classes of Smb4K.
0026  *
0027  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0028  */
0029 
0030 class Q_DECL_EXPORT Smb4KHost : public Smb4KBasicNetworkItem
0031 {
0032     friend class Smb4KHostPrivate;
0033 
0034 public:
0035     /**
0036      * This constructor takes the URL @p url as argument.
0037      *
0038      * @param url           The URL
0039      */
0040     explicit Smb4KHost(const QUrl &url);
0041 
0042     /**
0043      * The copy constructor.
0044      *
0045      * @param host                The Smb4KHost object that is to be copied.
0046      */
0047     Smb4KHost(const Smb4KHost &host);
0048 
0049     /**
0050      * The empty constructor.
0051      */
0052     Smb4KHost();
0053 
0054     /**
0055      * The destructor.
0056      */
0057     ~Smb4KHost();
0058 
0059     /**
0060      * Set the name of the host.
0061      *
0062      * @param name                The name of the host
0063      */
0064     void setHostName(const QString &name);
0065 
0066     /**
0067      * Returns the name of the host.
0068      *
0069      * @returns the host's name.
0070      */
0071     QString hostName() const;
0072 
0073     /**
0074      * Set the workgroup where this host is located.
0075      *
0076      * @param workgroup           The workgroup name
0077      */
0078     void setWorkgroupName(const QString &workgroup);
0079 
0080     /**
0081      * Returns the name of the workgroup where this host is located.
0082      *
0083      * @returns the workgroup name.
0084      */
0085     QString workgroupName() const;
0086 
0087     /**
0088      * Set the IP address of this host. @p ip will only be accepted
0089      * if it is compatible with either IPv4 or IPv6.
0090      *
0091      * @param ip                  The IP address of this host.
0092      */
0093     void setIpAddress(const QString &ip);
0094 
0095     /**
0096      * Set the IP address of this host. @p ip will only be accepted
0097      * if it is compatible with either IPv4 or IPv6.
0098      *
0099      * @param ip                  The IP address of this host.
0100      */
0101     void setIpAddress(const QHostAddress &address);
0102 
0103     /**
0104      * Returns the IP address of the host. If the IP address was not
0105      * compatible with IPv4 and IPv6 or if no IP address was supplied,
0106      * an empty string is returned.
0107      *
0108      * @returns the host's IP address or an empty string.
0109      */
0110     QString ipAddress() const;
0111 
0112     /**
0113      * Returns TRUE if the host's IP address is set and FALSE otherwise.
0114      *
0115      * @returns TRUE if the host's IP address is known.
0116      */
0117     bool hasIpAddress() const;
0118 
0119     /**
0120      * Set this host to be a master browser.
0121      *
0122      * @param master              Set this to TRUE if the host is a master
0123      *                            browser.
0124      */
0125     void setIsMasterBrowser(bool master);
0126 
0127     /**
0128      * Returns TRUE if the host is a master browser and FALSE otherwise.
0129      *
0130      * @returns TRUE if the host is a master browser.
0131      */
0132     bool isMasterBrowser() const;
0133 
0134     /**
0135      * Set the port for the use in the URL.
0136      *
0137      * @param port            The port
0138      */
0139     void setPort(int port);
0140 
0141     /**
0142      * Returns the port that is used in the URL.
0143      *
0144      * @returns the port.
0145      */
0146     int port() const;
0147 
0148     /**
0149      * Set the user name for the host.
0150      *
0151      * @param name          The login name
0152      */
0153     void setUserName(const QString &name);
0154 
0155     /**
0156      * Returns the user name.
0157      *
0158      * @returns the user name.
0159      */
0160     QString userName() const;
0161 
0162     /**
0163      * Set the password used for authentication.
0164      *
0165      * @param passwd              The password
0166      */
0167     void setPassword(const QString &passwd);
0168 
0169     /**
0170      * Returns the password.
0171      *
0172      * @returns the password.
0173      */
0174     QString password() const;
0175 
0176     /**
0177      * Updates the host item if the workgroup and host name of @p host and
0178      * of this item is equal. Otherwise it does nothing.
0179      * @param host            The share object that is used to update
0180      *                        this object
0181      */
0182     void update(Smb4KHost *host);
0183 
0184     /**
0185      * Copy assignment operator
0186      */
0187     Smb4KHost &operator=(const Smb4KHost &other);
0188 
0189 private:
0190     const QScopedPointer<Smb4KHostPrivate> d;
0191 };
0192 
0193 Q_DECLARE_METATYPE(Smb4KHost)
0194 
0195 #endif