File indexing completed on 2024-05-05 17:01:33
0001 /*************************************************************************** 0002 This class derives from QObject and encapsulates the network items. 0003 It is for use with QtQuick. 0004 ------------------- 0005 begin : Fr Mär 02 2012 0006 copyright : (C) 2012-2019 by Alexander Reinholdt 0007 email : alexander.reinholdt@kdemail.net 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, but * 0017 * WITHOUT ANY WARRANTY; without even the implied warranty of * 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0019 * General Public License for more details. * 0020 * * 0021 * You should have received a copy of the GNU General Public License * 0022 * along with this program; if not, write to the * 0023 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* 0024 * MA 02110-1335, USA * 0025 ***************************************************************************/ 0026 0027 #ifndef SMB4KNETWORKOBJECT_H 0028 #define SMB4KNETWORKOBJECT_H 0029 0030 // application specific includes 0031 #include "core/smb4kworkgroup.h" 0032 #include "core/smb4khost.h" 0033 #include "core/smb4kshare.h" 0034 #include "core/smb4kglobal.h" 0035 0036 // Qt includes 0037 #include <QObject> 0038 #include <QString> 0039 #include <QScopedPointer> 0040 #include <QUrl> 0041 #include <QIcon> 0042 0043 // forward declaration 0044 class Smb4KNetworkObjectPrivate; 0045 0046 /** 0047 * This class derives from QObject and makes the main functions of the 0048 * network items Smb4KWorkgroup, Smb4KHost, and Smb4KShare available. Its 0049 * main purpose is to be used with QtQuick and Plasma. 0050 * 0051 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0052 * @since 1.1.0 0053 */ 0054 0055 0056 class Q_DECL_EXPORT Smb4KNetworkObject : public QObject 0057 { 0058 Q_OBJECT 0059 0060 Q_PROPERTY(NetworkItem type READ type WRITE setType NOTIFY changed) 0061 Q_PROPERTY(NetworkItem parentType READ parentType CONSTANT) 0062 Q_PROPERTY(QString workgroupName READ workgroupName WRITE setWorkgroupName NOTIFY changed) 0063 Q_PROPERTY(QString hostName READ hostName WRITE setHostName NOTIFY changed) 0064 Q_PROPERTY(QString shareName READ shareName WRITE setShareName NOTIFY changed) 0065 Q_PROPERTY(QString name READ name CONSTANT) 0066 Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY changed) 0067 Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY changed) 0068 Q_PROPERTY(QUrl parentUrl READ parentUrl CONSTANT) 0069 Q_PROPERTY(bool isMounted READ isMounted WRITE setMounted NOTIFY changed) 0070 Q_PROPERTY(bool isPrinter READ isPrinter WRITE setPrinter NOTIFY changed) 0071 Q_PROPERTY(QUrl mountpoint READ mountpoint WRITE setMountpoint NOTIFY changed) 0072 Q_PROPERTY(bool isMasterBrowser READ isMasterBrowser WRITE setMasterBrowser NOTIFY changed) 0073 Q_PROPERTY(bool isInaccessible READ isInaccessible WRITE setInaccessible NOTIFY changed) 0074 0075 friend class Smb4KNetworkObjectPrivate; 0076 0077 public: 0078 /** 0079 * NetworkItem enumeration. Used to make the property system happy. 0080 * Assigns the values of Smb4KGlobal::NetworkItem to its representatives. 0081 */ 0082 enum NetworkItem { 0083 Network = Smb4KGlobal::Network, 0084 Workgroup = Smb4KGlobal::Workgroup, 0085 Host = Smb4KGlobal::Host, 0086 Share = Smb4KGlobal::Share, 0087 Unknown = Smb4KGlobal::UnknownNetworkItem }; 0088 Q_ENUM(NetworkItem) 0089 0090 /** 0091 * Constructor for a workgroup. 0092 */ 0093 explicit Smb4KNetworkObject(Smb4KWorkgroup *workgroup, QObject *parent = 0); 0094 0095 /** 0096 * Constructor for a host. 0097 */ 0098 explicit Smb4KNetworkObject(Smb4KHost *host, QObject *parent = 0); 0099 0100 /** 0101 * Constructor for a share. 0102 */ 0103 explicit Smb4KNetworkObject(Smb4KShare *share, QObject *parent = 0); 0104 0105 /** 0106 * Empty constructor 0107 */ 0108 explicit Smb4KNetworkObject(QObject *parent = 0); 0109 0110 /** 0111 * Destructor 0112 */ 0113 ~Smb4KNetworkObject(); 0114 0115 /** 0116 * This function returns the type. 0117 * 0118 * @returns the type 0119 */ 0120 NetworkItem type() const; 0121 0122 /** 0123 * This function returns the type of the parent of this item. In case of 0124 * the type() function returning Unknown, this function will do the same, 0125 * otherwise the type of the level above is returned. 0126 * 0127 * @returns the parent's type 0128 */ 0129 NetworkItem parentType() const; 0130 0131 /** 0132 * Set the type of the network item. 0133 * 0134 * @param type The type 0135 */ 0136 void setType(NetworkItem type); 0137 0138 /** 0139 * Returns the workgroup name. 0140 * 0141 * @returns the workgroup name 0142 */ 0143 QString workgroupName() const; 0144 0145 /** 0146 * Set the workgroup name for this network item. 0147 * 0148 * @param name The workgroup name 0149 */ 0150 void setWorkgroupName(const QString &name); 0151 0152 /** 0153 * In case of a host or share, this function returns the name 0154 * of the host. In case of a workgroup the return value is an 0155 * empty string. 0156 * 0157 * @returns the host name or an empty string 0158 */ 0159 QString hostName() const; 0160 0161 /** 0162 * Set the host name for this network item. 0163 * 0164 * @param name The host name 0165 */ 0166 void setHostName(const QString &name); 0167 0168 /** 0169 * Returns TRUE if this network object represents a master browser 0170 * and FALSE otherwise. 0171 * @returns TRUE if the network object is a master browser 0172 */ 0173 bool isMasterBrowser() const; 0174 0175 /** 0176 * Set this network object to be a master browser. This function 0177 * only does something, if type() returns Host. 0178 * 0179 * @param master Set to TRUE, if the network item is a master 0180 * browser 0181 */ 0182 void setMasterBrowser(bool master); 0183 0184 /** 0185 * In case of a share, this function returns the name of the 0186 * share. In case of a workgroup or host the return value is an 0187 * empty string. 0188 * 0189 * @returns the share name or an empty string 0190 */ 0191 QString shareName() const; 0192 0193 /** 0194 * Set the share name for this network item. 0195 * 0196 * @param name The share name 0197 */ 0198 void setShareName(const QString &name); 0199 0200 /** 0201 * This is a convenience function that returns the name of the 0202 * item depending of its type. 0203 * 0204 * @returns the name depending of the type 0205 */ 0206 QString name() const; 0207 0208 /** 0209 * This function returns the comment of a network item or an 0210 * empty string if there is no comment defined. 0211 * 0212 * @returns the comment 0213 */ 0214 QString comment() const; 0215 0216 /** 0217 * Set the comment for this network item. 0218 * 0219 * @param comment The comment 0220 */ 0221 void setComment(const QString &comment); 0222 0223 /** 0224 * This function returns the UNC/URL of this item. 0225 * 0226 * Please note that a workgroup will have a UNC like smb://WORKGROUP, 0227 * so to discriminate it from a host, you need to check the type() 0228 * function as well. 0229 * 0230 * @returns the item's URL 0231 */ 0232 QUrl url() const; 0233 0234 /** 0235 * Return the URL of the parent item. 0236 * 0237 * @returns the item's parent URL 0238 */ 0239 QUrl parentUrl() const; 0240 0241 /** 0242 * Set the URL of this network item. 0243 * 0244 * @param url The URL 0245 */ 0246 void setUrl(const QUrl &url); 0247 0248 /** 0249 * This function returns TRUE if the network item is a share and it is 0250 * mounted. Otherwise it returns FALSE. 0251 * 0252 * @returns TRUE if the network item is mounted. 0253 */ 0254 bool isMounted() const; 0255 0256 /** 0257 * Mark this network item as mounted. This is only reasonable with a share. 0258 * 0259 * @param mounted Should be TRUE if the network item is mounted 0260 */ 0261 void setMounted(bool mounted); 0262 0263 /** 0264 * Updates the network item. 0265 * 0266 * @param networkItem The network item that needs to be updated 0267 */ 0268 void update(Smb4KBasicNetworkItem *networkItem); 0269 0270 /** 0271 * This function returns TRUE if the network item is a printer share. 0272 * Otherwise it returns FALSE, 0273 * 0274 * @returns TRUE if the network item is a printer. 0275 */ 0276 bool isPrinter() const; 0277 0278 /** 0279 * Mark this network item as printer. This is only reasonable with a share. 0280 * 0281 * @param printer Should be TRUE if the network item is a printer 0282 */ 0283 void setPrinter(bool printer); 0284 0285 /** 0286 * This function returns the mountpoint of a mounted share or an empty 0287 * string if the network item is not a share or the share is not mounted. 0288 * 0289 * @returns the mount point of a share. 0290 */ 0291 QUrl mountpoint() const; 0292 0293 /** 0294 * Set the mountpoint for this network item. This is only reasonable with a 0295 * share. 0296 * 0297 * @param mountpoint The mountpoint 0298 */ 0299 void setMountpoint(const QUrl &url); 0300 0301 /** 0302 * Returns TRUE if the network item is a share that is mounted and became 0303 * inaccessible. Otherwise this function returns FALSE. 0304 * @returns TRUE is the mounted share is inaccessible 0305 */ 0306 bool isInaccessible() const; 0307 0308 /** 0309 * Mark this network item as inaccessible. This is only reasonable with a 0310 * mounted share. 0311 * @param inaccessible Should be TRUE if the mounted share is inaccessible 0312 */ 0313 void setInaccessible(bool inaccessible); 0314 0315 Q_SIGNALS: 0316 /** 0317 * This signal is emitted when the network item changed. 0318 */ 0319 void changed(); 0320 0321 private: 0322 const QScopedPointer<Smb4KNetworkObjectPrivate> d; 0323 }; 0324 0325 #endif