File indexing completed on 2024-04-14 04:56:26
0001 /* 0002 Smb4K's container class for information about a share. 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 SMB4KSHARE_H 0009 #define SMB4KSHARE_H 0010 0011 // application specific includes 0012 #include "smb4kbasicnetworkitem.h" 0013 0014 // Qt includes 0015 #include <QHostAddress> 0016 #include <QScopedPointer> 0017 #include <QString> 0018 #include <QStringList> 0019 #include <QtGlobal> 0020 0021 // KDE includes 0022 #include <KUser> 0023 0024 // forward declarations 0025 class Smb4KAuthInfo; 0026 class Smb4KSharePrivate; 0027 0028 class Q_DECL_EXPORT Smb4KShare : public Smb4KBasicNetworkItem 0029 { 0030 friend class Smb4KSharePrivate; 0031 0032 public: 0033 /** 0034 * This constructor takes the URL @p url as argument. 0035 * 0036 * @param url The URL 0037 */ 0038 explicit Smb4KShare(const QUrl &url); 0039 0040 /** 0041 * This is the copy constructor. 0042 * 0043 * @param share The Smb4KShare item that is to be copied 0044 */ 0045 Smb4KShare(const Smb4KShare &share); 0046 0047 /** 0048 * The empty constructor. 0049 */ 0050 Smb4KShare(); 0051 0052 /** 0053 * The destructor. 0054 */ 0055 ~Smb4KShare(); 0056 0057 /** 0058 * Sets the name of the share (*not* the UNC). 0059 * 0060 * @param name The share name 0061 */ 0062 void setShareName(const QString &name); 0063 0064 /** 0065 * Returns the name of the share, e.g. "Music", "Data", etc. 0066 * 0067 * @returns the name of the share. 0068 */ 0069 QString shareName() const; 0070 0071 /** 0072 * Sets the name of the host where the share is located. 0073 * 0074 * @param hostName The host name 0075 */ 0076 void setHostName(const QString &hostName); 0077 0078 /** 0079 * Returns the name of the host where the share is located. 0080 * 0081 * @returns the host name 0082 */ 0083 QString hostName() const; 0084 0085 /** 0086 * In case of a 'homes' share, this function returns the URL of the user's 0087 * home repository. 0088 * 0089 * If the share is not a 'homes' share or no user name for the homes share 0090 * has been defined, this function returns an empty string. 0091 * 0092 * @returns the user's home repository's URL. 0093 */ 0094 QUrl homeUrl() const; 0095 0096 /** 0097 * Returns the display string. Prefer this over all other alternatives in your 0098 * GUI. 0099 * 0100 * @param showHomesShare Show the name of the users home share instead of 'homes' 0101 * in case this is a homes share. Setting this argument on a 0102 * non-homes share does nothing. 0103 * 0104 * @returns the display string. 0105 */ 0106 QString displayString(bool showHomeShare = false) const; 0107 0108 /** 0109 * Set the workgroup where the host is located that offers this share. 0110 * 0111 * @param workgroup The name of the workgroup 0112 */ 0113 void setWorkgroupName(const QString &workgroup); 0114 0115 /** 0116 * Returns the name of the workgroup where the host is located that 0117 * offers this share. 0118 * 0119 * @returns the workgroup name 0120 */ 0121 QString workgroupName() const; 0122 0123 /** 0124 * Set the type of the share as reported by the server. 0125 * 0126 * @param type The type of the string 0127 */ 0128 void setShareType(Smb4KGlobal::ShareType type); 0129 0130 /** 0131 * Returns the type of the share as reported by the server. If you are 0132 * looking for a translated type string, then use the shareTypeString() 0133 * function. 0134 * 0135 * @returns the type of the share. 0136 */ 0137 Smb4KGlobal::ShareType shareType() const; 0138 0139 /** 0140 * Returns the translated type string of the share. You can use this 0141 * in the GUI. 0142 * 0143 * @returns a translated type string. 0144 */ 0145 QString shareTypeString() const; 0146 0147 /** 0148 * Set the IP address of the host where the share is located. @p ip will 0149 * only be accepted if it is compatible with either IPv4 or IPv6. 0150 * 0151 * @param ip The host's IP address 0152 */ 0153 void setHostIpAddress(const QString &ip); 0154 0155 /** 0156 * Set the IP address of the host where the share is located. @p ip will only be accepted 0157 * if it is compatible with either IPv4 or IPv6. 0158 * 0159 * @param ip The host's IP address 0160 */ 0161 void setHostIpAddress(const QHostAddress &address); 0162 0163 /** 0164 * Returns the IP address of the host. If the IP address was not compatible 0165 * with IPv4 and IPv6 or if no IP address was supplied, an empty string is 0166 * returned. 0167 * 0168 * @returns the IP address of the host or an empty string. 0169 */ 0170 QString hostIpAddress() const; 0171 0172 /** 0173 * Returns TRUE if the host's IP address is set and FALSE otherwise. 0174 * 0175 * @returns TRUE if the host's IP address is set and FALSE otherwise. 0176 */ 0177 bool hasHostIpAddress() const; 0178 0179 /** 0180 * If the share is a hidden one, i.e. it ends with a '$', this function returns 0181 * TRUE and FALSE otherwise. 0182 * 0183 * @returns TRUE if this is a hidden share. 0184 */ 0185 bool isHidden() const; 0186 0187 /** 0188 * If the share is a printer this function returns TRUE and otherwise FALSE. 0189 * 0190 * @returns TRUE if the share is a printer. 0191 */ 0192 bool isPrinter() const; 0193 0194 /** 0195 * Sets the path aka mount point of the share as gathered by the mounter. 0196 * 0197 * @param mountpoint The mount point of the share. 0198 */ 0199 void setPath(const QString &mountpoint); 0200 0201 /** 0202 * Returns the path to the mounted share (aka the mount point) as it was gathered 0203 * by the mounter. It is a C-type string. 0204 * 0205 * @returns the path to the mounted share. 0206 */ 0207 QString path() const; 0208 0209 /** 0210 * Returns the canonical path to the mounted share. In contrast to the path() 0211 * function it will return the absolute path without symlinks. However, should 0212 * the share be inaccessible (i.e. the isInaccessible() returns TRUE), only 0213 * the "normal" path is returned. 0214 * 0215 * @returns the canonical path to the mounted share. 0216 */ 0217 QString canonicalPath() const; 0218 0219 /** 0220 * Set @p in to TRUE if the share cannot be accessed by the user. This may be 0221 * because if strict permissions or because the remote server went offline. By 0222 * default it is assumed that the share is accessible. 0223 * 0224 * @param in Tells if the share is inaccessible or not. 0225 */ 0226 void setInaccessible(bool in); 0227 0228 /** 0229 * Returns TRUE if the share is mounted and not accessible by the user. 0230 * 0231 * @returns TRUE if the share is mounted and inaccessible. 0232 */ 0233 bool isInaccessible() const; 0234 0235 /** 0236 * If the share was mounted by another user, @p foreign should be set to TRUE. 0237 * By default it is assumed that the share is not foreign but owned by the 0238 * user. 0239 * 0240 * @param foreign TRUE if the share is foreign and FALSE otherwise. 0241 */ 0242 void setForeign(bool foreign); 0243 0244 /** 0245 * Returns TRUE if the share is mounted and is owned by another user. 0246 * 0247 * @returns TRUE if this is a foreign share. 0248 */ 0249 bool isForeign() const; 0250 0251 /** 0252 * Returns the file system as string in capital letters. If no file system 0253 * was specified, an empty string is returned. 0254 * 0255 * @returns the file system string or an empty string. 0256 */ 0257 QString fileSystemString() const; 0258 0259 /** 0260 * Sets the owner of this share. 0261 * @param user The UID of the owner 0262 */ 0263 void setUser(const KUser &user); 0264 0265 /** 0266 * Returns the owner of this share or the current user, if 0267 * the owner was not set using @see setUser(). 0268 * @returns the owner. 0269 */ 0270 KUser user() const; 0271 0272 /** 0273 * Set the group that owns this share. 0274 * @param group The owning GID 0275 */ 0276 void setGroup(const KUserGroup &group); 0277 0278 /** 0279 * Returns the group that owns this share or the current group, if 0280 * the group was not set using @see setGroup(). 0281 * @returns the group. 0282 */ 0283 KUserGroup group() const; 0284 0285 /** 0286 * Sets the value of the total disk space that is available on the share. If 0287 * the disk usage could not be determined, @p size has to be set to 0. 0288 * 0289 * @param size The total disk space 0290 */ 0291 void setTotalDiskSpace(qint64 size); 0292 0293 /** 0294 * Returns the total disk space that is available on the share or 0 if the 0295 * total disk space was not set or could not be determined. 0296 * 0297 * @returns the total disk space or 0. 0298 */ 0299 qint64 totalDiskSpace() const; 0300 0301 /** 0302 * Returns the total disk space in a human readable form with value and unit 0303 * (e.g. 10 KiB, 25 MiB, etc.) even if the total disk space was not set or could 0304 * not be determined. If the value is a valid one, you have to check by evaluating 0305 * the return value of the isInaccessible() function. 0306 * 0307 * @returns the total disk space in a human readable form. 0308 */ 0309 QString totalDiskSpaceString() const; 0310 0311 /** 0312 * Sets the value of the free disk space that is available on the share. If 0313 * the free disk space could not be determined, @p size has to be set to 0. 0314 * 0315 * @param size The free disk space 0316 */ 0317 void setFreeDiskSpace(qint64 size); 0318 0319 /** 0320 * Returns the free disk space that is available on the share or 0 if the 0321 * free disk space was not set or could not be determined. 0322 * 0323 * @returns the free disk space or 0. 0324 */ 0325 qint64 freeDiskSpace() const; 0326 0327 /** 0328 * Returns the free disk space in a human readable form with value and unit 0329 * (e.g. 10 KiB, 25 MiB, etc.) even if the free disk space was not set or could 0330 * not be determined. If the value is a valid one, you have to check by evaluating 0331 * the return value of the isInaccessible() function. 0332 * 0333 * @returns the free disk space in a human readable form. 0334 */ 0335 QString freeDiskSpaceString() const; 0336 0337 /** 0338 * Returns the used disk space that is used on the share or 0 if the 0339 * used disk space was not set or could not be determined. 0340 * 0341 * @returns the used disk space or 0. 0342 */ 0343 qint64 usedDiskSpace() const; 0344 0345 /** 0346 * Returns the used disk space in a human readable form with value and unit 0347 * (e.g. 10 KiB, 25 MiB, etc.) even if the used disk space was not set or could 0348 * not be determined. If the value is a valid one, you have to check by evaluating 0349 * the return value of the isInaccessible() function. 0350 * 0351 * @returns the used disk space in a human readable form. 0352 */ 0353 QString usedDiskSpaceString() const; 0354 0355 /** 0356 * Returns the disk usage in percent. 0357 0358 * @returns the disk usage in percent. 0359 */ 0360 qreal diskUsage() const; 0361 0362 /** 0363 * Returns the disk usage in a human readable form with value and unit, 0364 * for example 3.5 %, 67.0 % etc. If the usage was not set or could not 0365 * be determined, this function returns an empty string. 0366 * 0367 * @returns the disk usage in a human readable form or an empty string. 0368 */ 0369 QString diskUsageString() const; 0370 0371 /** 0372 * If this share was mounted, set @p mounted to TRUE. This function will not 0373 * work with printer shares. 0374 * 0375 * @param mounted Should be set to TRUE if the share was mounted. 0376 */ 0377 void setMounted(bool mounted); 0378 0379 /** 0380 * This function returns TRUE if the share has been mounted and FALSE 0381 * otherwise. 0382 * 0383 * @returns TRUE if this share was mounted. 0384 */ 0385 bool isMounted() const; 0386 0387 /** 0388 * This convenience function sets the mount related data that is copied 0389 * from @p share. 0390 * 0391 * @param share The share object from where the mount related 0392 * data should be copied. 0393 */ 0394 void setMountData(Smb4KShare *share); 0395 0396 /** 0397 * This convenience function resets the mount related data. 0398 */ 0399 void resetMountData(); 0400 0401 /** 0402 * Returns TRUE if the share is or *was* a 'homes' share. That means that 0403 * this value is not changed when the share name is changed. 0404 * 0405 * @returns TRUE if this is or *was* a 'homes' share and FALSE otherwise. 0406 */ 0407 bool isHomesShare() const; 0408 0409 /** 0410 * Set the port for the use in the UNC. 0411 * 0412 * @param port The port 0413 */ 0414 void setPort(int port); 0415 0416 /** 0417 * Returns the port that is used in the UNC. 0418 * 0419 * @returns the port. 0420 */ 0421 int port() const; 0422 0423 /** 0424 * Set the user name for the share. 0425 * 0426 * @param name The user name 0427 */ 0428 void setUserName(const QString &name); 0429 0430 /** 0431 * Returns the user name. 0432 * 0433 * @returns the user name. 0434 */ 0435 QString userName() const; 0436 0437 /** 0438 * Set the password used for authentication. 0439 * 0440 * @param passwd The password 0441 */ 0442 void setPassword(const QString &passwd); 0443 0444 /** 0445 * Returns the password. 0446 * 0447 * @returns the password. 0448 */ 0449 QString password() const; 0450 0451 /** 0452 * Updates the share item if the workgroup name and the UNC of @p share and 0453 * of this item is equal. Otherwise it does nothing. 0454 * @param share The share object that is used to update 0455 * this object 0456 */ 0457 void update(Smb4KShare *share); 0458 0459 /** 0460 * Copy assignment operator 0461 */ 0462 Smb4KShare &operator=(const Smb4KShare &other); 0463 0464 private: 0465 const QScopedPointer<Smb4KSharePrivate> d; 0466 0467 /** 0468 * Set up the shares icon. 0469 */ 0470 void setShareIcon(); 0471 }; 0472 0473 Q_DECLARE_METATYPE(Smb4KShare) 0474 0475 #endif