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

0001 /*
0002     This class provides the basic network item for the core library of
0003     Smb4K.
0004 
0005     SPDX-FileCopyrightText: 2009-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef SMB4KBASICNETWORKITEM_H
0010 #define SMB4KBASICNETWORKITEM_H
0011 
0012 // application specific includes
0013 #include "smb4kglobalenums.h"
0014 
0015 // Qt includes
0016 #include <QIcon>
0017 #include <QMetaType>
0018 #include <QScopedPointer>
0019 #include <QString>
0020 #include <QUrl>
0021 
0022 // forward declarations
0023 class Smb4KBasicNetworkItemPrivate;
0024 
0025 /**
0026  * This is the basic class from which all other network item classes
0027  * are derived.
0028  *
0029  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0030  * @since 1.0.0
0031  */
0032 
0033 class Q_DECL_EXPORT Smb4KBasicNetworkItem
0034 {
0035 public:
0036     /**
0037      * The constructor
0038      */
0039     explicit Smb4KBasicNetworkItem(Smb4KGlobal::NetworkItem type = Smb4KGlobal::UnknownNetworkItem);
0040 
0041     /**
0042      * The copy constructor
0043      */
0044     Smb4KBasicNetworkItem(const Smb4KBasicNetworkItem &item);
0045 
0046     /**
0047      * The destructor
0048      */
0049     virtual ~Smb4KBasicNetworkItem();
0050 
0051     /**
0052      * This function sets the type of the basic network item.
0053      *
0054      * @param type          The type of the network item
0055      */
0056     void setType(Smb4KGlobal::NetworkItem type) const;
0057 
0058     /**
0059      * This function returns the type of the basic network
0060      * item.
0061      *
0062      * @returns the type.
0063      */
0064     Smb4KGlobal::NetworkItem type() const;
0065 
0066     /**
0067      * This function sets the icon of the network item.
0068      *
0069      * @param icon          The icon
0070      */
0071     void setIcon(const QIcon &icon) const;
0072 
0073     /**
0074      * This function returns the icon of the network item. By default, it
0075      * is the null icon. You must set the appropriate icon either in
0076      * a class that inherits this one or from somewhere else.
0077      *
0078      * @returns the network item's icon.
0079      */
0080     QIcon icon() const;
0081 
0082     /**
0083      * Set the URL for this network item.
0084      *
0085      * @param url           The URL
0086      */
0087     void setUrl(const QUrl &url) const;
0088 
0089     /**
0090      * Return the URL for this network item.
0091      *
0092      * @returns the URL
0093      */
0094     QUrl url() const;
0095 
0096     /**
0097      * Set @p discovered to TRUE if this network item was discovered using
0098      * the DNS-SD service.
0099      *
0100      * @param discovered    Set this to TRUE if the network item was discovered
0101      *                      using the DNS-SD service
0102      */
0103     void setDnsDiscovered(bool discovered) const;
0104 
0105     /**
0106      * Return TRUE if the network item was discovered using the DNS-SD
0107      * service and FALSE otherwise.
0108      *
0109      * @return TRUE if discovered by DNS-SD.
0110      */
0111     bool dnsDiscovered() const;
0112 
0113     /**
0114      * Set the comment for this network item.
0115      *
0116      * @param comment       The comment
0117      */
0118     void setComment(const QString &comment) const;
0119 
0120     /**
0121      * Return the comment for this network item.
0122      *
0123      * @returns the comment
0124      */
0125     QString comment() const;
0126 
0127     /**
0128      * Returms true, if the URL carries user information
0129      */
0130     bool hasUserInfo() const;
0131 
0132     /**
0133      * Copy assignment operator
0134      */
0135     Smb4KBasicNetworkItem &operator=(const Smb4KBasicNetworkItem &other);
0136 
0137 protected:
0138     /**
0139      * Expose a pointer to the private URL variable.
0140      */
0141     QUrl *pUrl;
0142 
0143     /**
0144      * Expose a pointer to the private icon variable.
0145      */
0146     QIcon *pIcon;
0147 
0148     /**
0149      * Expose a pointer to the private comment variable.
0150      */
0151     QString *pComment;
0152 
0153     /**
0154      * Export a pointer to the private type variable
0155      */
0156     Smb4KGlobal::NetworkItem *pType;
0157 
0158 private:
0159     const QScopedPointer<Smb4KBasicNetworkItemPrivate> d;
0160 };
0161 
0162 Q_DECLARE_METATYPE(Smb4KBasicNetworkItem)
0163 
0164 #endif