File indexing completed on 2024-04-21 05:01:42
0001 /* 0002 This class derives from QObject and encapsulates the network items. 0003 It is for use with QtQuick. 0004 0005 SPDX-FileCopyrightText: 2012-2022 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef SMB4KNETWORKOBJECT_H 0010 #define SMB4KNETWORKOBJECT_H 0011 0012 // application specific includes 0013 #include "core/smb4kbasicnetworkitem.h" 0014 #include "core/smb4kglobal.h" 0015 0016 // Qt includes 0017 #include <QIcon> 0018 #include <QObject> 0019 #include <QScopedPointer> 0020 #include <QString> 0021 #include <QUrl> 0022 0023 // forward declaration 0024 class Smb4KNetworkObjectPrivate; 0025 0026 /** 0027 * This class derives from QObject and makes the main functions of the 0028 * network items Smb4KWorkgroup, Smb4KHost, and Smb4KShare available. Its 0029 * main purpose is to be used with QtQuick and Plasma. 0030 * 0031 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0032 * @since 1.1.0 0033 */ 0034 0035 class Q_DECL_EXPORT Smb4KNetworkObject : public QObject 0036 { 0037 Q_OBJECT 0038 0039 Q_PROPERTY(NetworkItem type READ type WRITE setType NOTIFY changed) 0040 Q_PROPERTY(NetworkItem parentType READ parentType CONSTANT) 0041 Q_PROPERTY(QString workgroupName READ workgroupName WRITE setWorkgroupName NOTIFY changed) 0042 Q_PROPERTY(QString hostName READ hostName CONSTANT) 0043 Q_PROPERTY(QString shareName READ shareName CONSTANT) 0044 Q_PROPERTY(QString name READ name CONSTANT) 0045 Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY changed) 0046 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY changed) 0047 Q_PROPERTY(QUrl parentUrl READ parentUrl CONSTANT) 0048 Q_PROPERTY(bool isMounted READ isMounted WRITE setMounted NOTIFY changed) 0049 Q_PROPERTY(bool isPrinter READ isPrinter WRITE setPrinter NOTIFY changed) 0050 Q_PROPERTY(QUrl mountpoint READ mountpoint WRITE setMountpoint NOTIFY changed) 0051 Q_PROPERTY(bool isMasterBrowser READ isMasterBrowser WRITE setMasterBrowser NOTIFY changed) 0052 Q_PROPERTY(bool isInaccessible READ isInaccessible WRITE setInaccessible NOTIFY changed) 0053 0054 friend class Smb4KNetworkObjectPrivate; 0055 0056 public: 0057 /** 0058 * NetworkItem enumeration. Used to make the property system happy. 0059 * Assigns the values of Smb4KGlobal::NetworkItem to its representatives. 0060 */ 0061 enum NetworkItem { 0062 Network = Smb4KGlobal::Network, 0063 Workgroup = Smb4KGlobal::Workgroup, 0064 Host = Smb4KGlobal::Host, 0065 Share = Smb4KGlobal::Share, 0066 Unknown = Smb4KGlobal::UnknownNetworkItem 0067 }; 0068 Q_ENUM(NetworkItem) 0069 0070 /** 0071 * Constructor with a network item. 0072 */ 0073 explicit Smb4KNetworkObject(Smb4KBasicNetworkItem *networkItem, QObject *parent = nullptr); 0074 0075 /** 0076 * Empty constructor 0077 */ 0078 explicit Smb4KNetworkObject(QObject *parent = nullptr); 0079 0080 /** 0081 * Destructor 0082 */ 0083 ~Smb4KNetworkObject(); 0084 0085 /** 0086 * This function returns the type. 0087 * 0088 * @returns the type 0089 */ 0090 NetworkItem type() const; 0091 0092 /** 0093 * This function returns the type of the parent of this item. In case of 0094 * the type() function returning Unknown, this function will do the same, 0095 * otherwise the type of the level above is returned. 0096 * 0097 * @returns the parent's type 0098 */ 0099 NetworkItem parentType() const; 0100 0101 /** 0102 * Set the type of the network item. 0103 * 0104 * @param type The type 0105 */ 0106 void setType(NetworkItem type); 0107 0108 /** 0109 * Returns the workgroup name. 0110 * 0111 * @returns the workgroup name 0112 */ 0113 QString workgroupName() const; 0114 0115 /** 0116 * Set the workgroup name for this network item. 0117 * 0118 * @param name The workgroup name 0119 */ 0120 void setWorkgroupName(const QString &name); 0121 0122 /** 0123 * In case of a host or share, this function returns the name 0124 * of the host. In case of a workgroup the return value is an 0125 * empty string. 0126 * 0127 * @returns the host name or an empty string 0128 */ 0129 QString hostName() const; 0130 0131 /** 0132 * Returns TRUE if this network object represents a master browser 0133 * and FALSE otherwise. 0134 * @returns TRUE if the network object is a master browser 0135 */ 0136 bool isMasterBrowser() const; 0137 0138 /** 0139 * Set this network object to be a master browser. This function 0140 * only does something, if type() returns Host. 0141 * 0142 * @param master Set to TRUE, if the network item is a master 0143 * browser 0144 */ 0145 void setMasterBrowser(bool master); 0146 0147 /** 0148 * In case of a share, this function returns the name of the 0149 * share. In case of a workgroup or host the return value is an 0150 * empty string. 0151 * 0152 * @returns the share name or an empty string 0153 */ 0154 QString shareName() const; 0155 0156 /** 0157 * This is a convenience function that returns the name of the 0158 * item depending of its type. 0159 * 0160 * @returns the name depending of the type 0161 */ 0162 QString name() const; 0163 0164 /** 0165 * This function returns the comment of a network item or an 0166 * empty string if there is no comment defined. 0167 * 0168 * @returns the comment 0169 */ 0170 QString comment() const; 0171 0172 /** 0173 * Set the comment for this network item. 0174 * 0175 * @param comment The comment 0176 */ 0177 void setComment(const QString &comment); 0178 0179 /** 0180 * This function returns the UNC/URL of this item. 0181 * 0182 * Please note that a workgroup will have a UNC like smb://WORKGROUP, 0183 * so to discriminate it from a host, you need to check the type() 0184 * function as well. 0185 * 0186 * @returns the item's URL 0187 */ 0188 QUrl url() const; 0189 0190 /** 0191 * Return the URL of the parent item. 0192 * 0193 * @returns the item's parent URL 0194 */ 0195 QUrl parentUrl() const; 0196 0197 /** 0198 * Set the URL of this network item. 0199 * 0200 * @param url The URL 0201 */ 0202 void setUrl(const QUrl &url); 0203 0204 /** 0205 * This function returns TRUE if the network item is a share and it is 0206 * mounted. Otherwise it returns FALSE. 0207 * 0208 * @returns TRUE if the network item is mounted. 0209 */ 0210 bool isMounted() const; 0211 0212 /** 0213 * Mark this network item as mounted. This is only reasonable with a share. 0214 * 0215 * @param mounted Should be TRUE if the network item is mounted 0216 */ 0217 void setMounted(bool mounted); 0218 0219 /** 0220 * Updates the network item. 0221 * 0222 * @param networkItem The network item that needs to be updated 0223 */ 0224 void update(Smb4KBasicNetworkItem *networkItem); 0225 0226 /** 0227 * This function returns TRUE if the network item is a printer share. 0228 * Otherwise it returns FALSE, 0229 * 0230 * @returns TRUE if the network item is a printer. 0231 */ 0232 bool isPrinter() const; 0233 0234 /** 0235 * Mark this network item as printer. This is only reasonable with a share. 0236 * 0237 * @param printer Should be TRUE if the network item is a printer 0238 */ 0239 void setPrinter(bool printer); 0240 0241 /** 0242 * This function returns the mountpoint of a mounted share or an empty 0243 * string if the network item is not a share or the share is not mounted. 0244 * 0245 * @returns the mount point of a share. 0246 */ 0247 QUrl mountpoint() const; 0248 0249 /** 0250 * Set the mountpoint for this network item. This is only reasonable with a 0251 * share. 0252 * 0253 * @param mountpoint The mountpoint 0254 */ 0255 void setMountpoint(const QUrl &url); 0256 0257 /** 0258 * Returns TRUE if the network item is a share that is mounted and became 0259 * inaccessible. Otherwise this function returns FALSE. 0260 * @returns TRUE is the mounted share is inaccessible 0261 */ 0262 bool isInaccessible() const; 0263 0264 /** 0265 * Mark this network item as inaccessible. This is only reasonable with a 0266 * mounted share. 0267 * @param inaccessible Should be TRUE if the mounted share is inaccessible 0268 */ 0269 void setInaccessible(bool inaccessible); 0270 0271 Q_SIGNALS: 0272 /** 0273 * This signal is emitted when the network item changed. 0274 */ 0275 void changed(); 0276 0277 private: 0278 const QScopedPointer<Smb4KNetworkObjectPrivate> d; 0279 }; 0280 0281 #endif