File indexing completed on 2024-04-21 15:42:47
0001 /*************************************************************************** 0002 This is the global namespace for Smb4K. 0003 ------------------- 0004 begin : Sa Apr 2 2005 0005 copyright : (C) 2005-2019 by Alexander Reinholdt 0006 email : alexander.reinholdt@kdemail.net 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * This program is free software; you can redistribute it and/or modify * 0011 * it under the terms of the GNU General Public License as published by * 0012 * the Free Software Foundation; either version 2 of the License, or * 0013 * (at your option) any later version. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, but * 0016 * WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0018 * General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program; if not, write to the * 0022 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* 0023 * MA 02110-1335, USA * 0024 ***************************************************************************/ 0025 0026 #ifndef SMB4KGLOBAL_H 0027 #define SMB4KGLOBAL_H 0028 0029 // Qt includes 0030 #include <QMap> 0031 #include <QString> 0032 #include <QList> 0033 #include <QEvent> 0034 #include <QStringList> 0035 #include <QSharedPointer> 0036 0037 // forward declarations 0038 class Smb4KBasicNetworkItem; 0039 class Smb4KWorkgroup; 0040 class Smb4KHost; 0041 class Smb4KShare; 0042 class Smb4KFile; 0043 class Smb4KBookmark; 0044 class Smb4KCustomOptions; 0045 0046 // type definitions 0047 typedef QSharedPointer<Smb4KBasicNetworkItem> NetworkItemPtr; 0048 typedef QSharedPointer<Smb4KWorkgroup> WorkgroupPtr; 0049 typedef QSharedPointer<Smb4KHost> HostPtr; 0050 typedef QSharedPointer<Smb4KShare> SharePtr; 0051 typedef QSharedPointer<Smb4KFile> FilePtr; 0052 typedef QSharedPointer<Smb4KBookmark> BookmarkPtr; 0053 typedef QSharedPointer<Smb4KCustomOptions> OptionsPtr; 0054 0055 // Other definitions 0056 #ifndef SMB4K_DEPRECATED 0057 #define SMB4K_DEPRECATED __attribute__ ((__deprecated__)) 0058 #endif 0059 0060 0061 /** 0062 * This is the global namespace. It provides access to the global lists 0063 * of workgroups, hosts and shares, to the global settings of the Samba 0064 * configuration and much more. 0065 * 0066 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0067 */ 0068 0069 namespace Smb4KGlobal 0070 { 0071 /** 0072 * The Process enumeration. 0073 * 0074 * @enum LookupDomains Look up domains 0075 * @enum LookupDomainMembers Look up those servers that belong to a domain/workgroup 0076 * @enum LookupShares Look up shares on a server 0077 * @enum LookupFiles Look up files and directories within a share 0078 * @enum WakeUp Send magic Wake-On-LAN packages 0079 * @enum PrintFile Print a file 0080 * @enum NetworkSearch Network search 0081 * @enum MountShare Mount a share 0082 * @enum UnmountShare Unmount a share 0083 * @enum NoProcess No process 0084 */ 0085 enum Process { 0086 LookupDomains, 0087 LookupDomainMembers, 0088 LookupShares, 0089 LookupFiles, 0090 WakeUp, 0091 PrintFile, 0092 NetworkSearch, 0093 MountShare, 0094 UnmountShare, 0095 NoProcess }; 0096 0097 /** 0098 * The enumeration to determine the type of a network item. 0099 * 0100 * @enum Network The network 0101 * @enum Workgroup A workgroup 0102 * @enum Host A host 0103 * @enum Share A share 0104 * @enum Directory A directory in a shared folder 0105 * @enum File A file in a shared folder 0106 * @enum UnknownNetworkItem An unknown network item 0107 */ 0108 enum NetworkItem { 0109 Network, 0110 Workgroup, 0111 Host, 0112 Share, 0113 Directory, 0114 File, 0115 UnknownNetworkItem }; 0116 0117 /** 0118 * The enumeration that determines the share type 0119 * 0120 * @enum FileShare a file share 0121 * @enum PrinterShare a printer share 0122 * @enum IpcShare an IPC share 0123 */ 0124 enum ShareType { 0125 FileShare, 0126 PrinterShare, 0127 IpcShare, 0128 }; 0129 0130 /** 0131 * Use this function to initialize the core classes. Besides starting several 0132 * core classes such as the scanner (for an initial browse list) and the mounter 0133 * (for the import of all externally mounted shares), it also sets some default 0134 * values for some of the settings used to browse the network. 0135 * 0136 * By setting the @p modifyCursor parameter to TRUE, you force the core classes 0137 * to set a busy cursor when they do something. Default is FALSE. 0138 * 0139 * Setting @p initClasses to FALSE will avoid starting the core classes. This 0140 * should only the used if you are starting the core classes in a different 0141 * way (e. g. if you are starting them in the plasmoid via the Smb4KDeclarative 0142 * class). 0143 * 0144 * You should execute this function before starting your main application. 0145 */ 0146 Q_DECL_EXPORT void initCore(bool modifyCursor = false, bool initClasses = true); 0147 0148 /** 0149 * Aborts all actions that are run by the core classes and that can be aborted. 0150 */ 0151 Q_DECL_EXPORT void abortCore(); 0152 0153 /** 0154 * Check if at least one of the core classes that use KJobs (scanner, mounter, etc.) 0155 * is running. 0156 * 0157 * @returns TRUE if at least one of the core classes is doing something. 0158 */ 0159 Q_DECL_EXPORT bool coreIsRunning(); 0160 0161 /** 0162 * Check if the core has been initialized through the initCore() function. 0163 * 0164 * @returns TRUE if the core has already been initialized. 0165 */ 0166 Q_DECL_EXPORT bool coreIsInitialized(); 0167 0168 /** 0169 * This function returns the global list of workgroups that were discovered by 0170 * Smb4K. Use this if you want to access and modify the list with your code. 0171 * 0172 * @returns the global list of known workgroups. 0173 */ 0174 Q_DECL_EXPORT const QList<WorkgroupPtr> &workgroupsList(); 0175 0176 /** 0177 * This function returns the workgroup or domain that matches the name @p name or 0178 * NULL if there is no such workgroup. 0179 * 0180 * @returns a pointer to the workgroup with name @p name. 0181 */ 0182 Q_DECL_EXPORT WorkgroupPtr findWorkgroup(const QString &name); 0183 0184 /** 0185 * This function takes a workgroup @p workgroup, checks whether it is already 0186 * in the list of domains and adds it to the list if necessary. It returns TRUE 0187 * if the workgroup was added and FALSE otherwise. 0188 * 0189 * Please prefer this function over per class solutions. 0190 * 0191 * @param workgroup The workgroup item 0192 * 0193 * @returns TRUE if the workgroup was added and FALSE otherwise. 0194 */ 0195 Q_DECL_EXPORT bool addWorkgroup(WorkgroupPtr workgroup); 0196 0197 /** 0198 * This function takes a workgroup @p workgroup, and updates the respective workgroup 0199 * in the global list, if it exists. It returns TRUE on success and FALSE otherwise. 0200 * If you want to add a workgroup to the global list, use @see addWorkgroup(). 0201 * 0202 * Please prefer this function over per class solutions. 0203 * 0204 * @returns TRUE if the workgroup was updated and FALSE otherwise 0205 */ 0206 Q_DECL_EXPORT bool updateWorkgroup(WorkgroupPtr workgroup); 0207 0208 /** 0209 * This function removes a workgroup @p workgroup from the list of domains. The 0210 * pointer that is passed to this function will be deleted. You won't be able 0211 * to use it afterwards. This function returns TRUE if the workgroup was removed 0212 * and FALSE otherwise. 0213 * 0214 * Please prefer this function over per class solutions. 0215 * 0216 * @param workgroup The workgroup item 0217 * 0218 * @returns TRUE if the workgroup was removed and FALSE otherwise. 0219 */ 0220 Q_DECL_EXPORT bool removeWorkgroup(WorkgroupPtr workgroup); 0221 0222 /** 0223 * This function clears the global list of workgroups. 0224 */ 0225 Q_DECL_EXPORT void clearWorkgroupsList(); 0226 0227 /** 0228 * This function returns the global list of hosts that were discovered by 0229 * Smb4K. Use this if you want to access and modify the list with your code. 0230 * 0231 * @returns the global list of known hosts. 0232 */ 0233 Q_DECL_EXPORT const QList<HostPtr> &hostsList(); 0234 0235 /** 0236 * This function returns the host matching the name @p name or NULL if there is no 0237 * such host. The name of the host is mandatory. The workgroup may be empty, but 0238 * should be given, because this will speed up the search process. 0239 * 0240 * @param name The name of the host 0241 * 0242 * @param workgroup The workgroup where the host is located 0243 * 0244 * @returns an Smb4KHost item of NULL if none was found that matches @p name. 0245 */ 0246 Q_DECL_EXPORT HostPtr findHost(const QString &name, const QString &workgroup = QString()); 0247 0248 /** 0249 * This function takes a host @p host, checks whether it is already 0250 * in the list of hosts and adds it to the list if necessary. It returns TRUE 0251 * if the host was added and FALSE otherwise. 0252 * 0253 * Please prefer this function over per class solutions. 0254 * 0255 * @param host The host item 0256 * 0257 * @returns TRUE if the host was added and FALSE otherwise. 0258 */ 0259 Q_DECL_EXPORT bool addHost(HostPtr host); 0260 0261 /** 0262 * This function takes an host @p host, and updates the respective host 0263 * in the global list, if it exists. It returns TRUE on success and FALSE otherwise. 0264 * If you want to add an host to the global list, use @see addHost(). 0265 * 0266 * Please prefer this function over per class solutions. 0267 * 0268 * @returns TRUE if the host was updated and FALSE otherwise 0269 */ 0270 Q_DECL_EXPORT bool updateHost(HostPtr host); 0271 0272 /** 0273 * This function removes a host @p host from the list of hosts. The 0274 * pointer that is passed to this function will be deleted. You won't 0275 * be able to use it afterwards. This function returns TRUE if the host was removed 0276 * and FALSE otherwise. 0277 * 0278 * Please prefer this function over per class solutions. 0279 * 0280 * @param host The host item 0281 * 0282 * @returns TRUE if the host was removed and FALSE otherwise. 0283 */ 0284 Q_DECL_EXPORT bool removeHost(HostPtr host); 0285 0286 /** 0287 * This function clears the global list of hosts. 0288 */ 0289 Q_DECL_EXPORT void clearHostsList(); 0290 0291 /** 0292 * This function returns all hosts that belong to the workgroup or domain 0293 * @p workgroup. 0294 * 0295 * Please favor this function over per class solutions. 0296 * 0297 * @param workgroup The workgroup for that the list should be returned. 0298 * 0299 * @returns the list of hosts belonging to the workgroup or domain @param workgroup. 0300 */ 0301 Q_DECL_EXPORT QList<HostPtr> workgroupMembers(WorkgroupPtr workgroup); 0302 0303 /** 0304 * This function returns the list of shares that were discovered by Smb4K. 0305 * Use this if you want to access and modify the list with your code. 0306 * 0307 * @returns the global list of known shares. 0308 */ 0309 Q_DECL_EXPORT const QList<SharePtr> &sharesList(); 0310 0311 /** 0312 * This function returns the share with URL @p url located in the workgroup or 0313 * domain @p workgroup. If there is no such share, 0 is returned. The workgroup 0314 * entry may be empty. 0315 * 0316 * @param url The URL of the share 0317 * 0318 * @param workgroup The workgroup 0319 * 0320 * @returns the share that matches @p url and optionally @p workgroup or 0. 0321 */ 0322 Q_DECL_EXPORT SharePtr findShare(const QUrl &url, const QString &workgroup = QString()); 0323 0324 /** 0325 * This function takes a share @p share, checks whether it is already 0326 * in the list of shares and adds it to the list if necessary. It returns TRUE 0327 * if the share was added and FALSE otherwise. 0328 * 0329 * Please prefer this function over per class solutions. 0330 * 0331 * @param share The share item 0332 * 0333 * @returns TRUE if the share was added and FALSE otherwise. 0334 */ 0335 Q_DECL_EXPORT bool addShare(SharePtr share); 0336 0337 /** 0338 * This function takes a share @p share, and updates the respective share 0339 * in the global list, if it exists. It returns TRUE on success and FALSE otherwise. 0340 * If you want to add a share to the global list, use @see addShare(). 0341 * 0342 * Please prefer this function over per class solutions. 0343 * 0344 * @returns TRUE if the share was updated and FALSE otherwise 0345 */ 0346 Q_DECL_EXPORT bool updateShare(SharePtr share); 0347 0348 /** 0349 * This function removes a share @p share from the list of shares. The 0350 * pointer that is passed to this function will be deleted. You won't 0351 * be able to use it afterwards. This function returns TRUE if the share was removed 0352 * and FALSE otherwise. 0353 * 0354 * Please prefer this function over per class solutions. 0355 * 0356 * @param share The share item 0357 * 0358 * @returns TRUE if the share was removed and FALSE otherwise. 0359 */ 0360 Q_DECL_EXPORT bool removeShare(SharePtr share); 0361 0362 /** 0363 * This function clears the global list of shares. 0364 */ 0365 Q_DECL_EXPORT void clearSharesList(); 0366 0367 /** 0368 * This function returns the list of shares that is provided by one specific host 0369 * @p host. 0370 * 0371 * Please favor this function over per class solutions. 0372 * 0373 * @param host The host where the shares are located 0374 * 0375 * @returns the list of shares that are provided by the host @p host. 0376 */ 0377 Q_DECL_EXPORT QList<SharePtr> sharedResources(HostPtr host); 0378 0379 /** 0380 * This function returns the global list of mounted shares that were discovered by 0381 * Smb4K. Use this if you want to access and modify the list with your code. 0382 * 0383 * @returns the global list of known mounted shares. 0384 */ 0385 Q_DECL_EXPORT const QList<SharePtr> &mountedSharesList(); 0386 0387 /** 0388 * Find a mounted share by its path (i.e. mount point). 0389 * 0390 * @returns the share that is mounted to @p path. 0391 */ 0392 Q_DECL_EXPORT SharePtr findShareByPath(const QString &path); 0393 0394 /** 0395 * Find all mounts of a particular share with URL @p url on the system. 0396 * 0397 * This function will compare the incoming URL with the URL of each 0398 * mounted share to find all shares with the same URL. For the comparison 0399 * the user info and the port will be stripped. 0400 * 0401 * @param url The URL of the share 0402 * 0403 * @returns the complete list of mounts with the URL @p url. 0404 */ 0405 Q_DECL_EXPORT QList<SharePtr> findShareByUrl(const QUrl &url); 0406 0407 /** 0408 * This function returns the list of inaccessible shares. 0409 * 0410 * @returns the list of inaccessible shares. 0411 */ 0412 Q_DECL_EXPORT QList<SharePtr> findInaccessibleShares(); 0413 0414 /** 0415 * This function takes a mounted share @p share, checks whether it is 0416 * already in the list of mounted shares and adds it to the list if 0417 * necessary. It returns TRUE if the share was added and FALSE otherwise. 0418 * 0419 * Please prefer this function over per class solutions. 0420 * 0421 * @param share The share item 0422 * 0423 * @returns TRUE if the share was added and FALSE otherwise. 0424 */ 0425 Q_DECL_EXPORT bool addMountedShare(SharePtr share); 0426 0427 /** 0428 * This function takes a mounted share @p share and updates the share that 0429 * is already present in the internal list. 0430 * 0431 * @param share The share item 0432 * @returns TRUE if a share was found and updated. Returns FALSE otherwise. 0433 */ 0434 Q_DECL_EXPORT bool updateMountedShare(SharePtr share); 0435 0436 /** 0437 * This function removes a mounted share @p share from the list of mounted 0438 * shares. The pointer that is passed to this function will be deleted. 0439 * You won't be able to use it afterwards. This function returns TRUE if 0440 * the share was removed and FALSE otherwise. 0441 * 0442 * Please prefer this function over per class solutions. 0443 * 0444 * @param share The share item 0445 * 0446 * @returns TRUE if the share was removed and FALSE otherwise. 0447 */ 0448 Q_DECL_EXPORT bool removeMountedShare(SharePtr share); 0449 0450 /** 0451 * This function returns TRUE if only shares are present that are owned by 0452 * other users and FALSE otherwise. 0453 * 0454 * @returns TRUE if there are only shares that are owned by other users. 0455 */ 0456 Q_DECL_EXPORT bool onlyForeignMountedShares(); 0457 0458 /** 0459 * This enumeration determines with which application the mount point 0460 * of the current mounted share is to be opened. 0461 */ 0462 enum OpenWith { FileManager, 0463 Konsole }; 0464 0465 /** 0466 * Open the mount point of a share. Which application is used is determined by 0467 * the value of @p openWith and - maybe - by settings that were defined by the 0468 * user. 0469 * 0470 * @param share The share that is to be opened. 0471 * 0472 * @param openWith Integer of type Smb4KCore::OpenWith. Determines with which 0473 * application the share should be opened. 0474 */ 0475 Q_DECL_EXPORT void openShare(SharePtr share, OpenWith openWith = FileManager); 0476 0477 /** 0478 * Get the entries of the [global] section of the smb.conf file. 0479 * 0480 * @returns the entries of the [global] section of the smb.conf file 0481 */ 0482 Q_DECL_EXPORT const QMap<QString,QString> &globalSambaOptions(); 0483 0484 /** 0485 * This function returns TRUE if the core classes should set a busy cursor when 0486 * they are doing something. 0487 * 0488 * @returns TRUE in case a busy cursor should be set. 0489 */ 0490 Q_DECL_EXPORT bool modifyCursor(); 0491 0492 #if defined(Q_OS_LINUX) 0493 /** 0494 * This list contains all whitelisted arguments for the mount.cifs binary and 0495 * is only present under the Linux operating system. 0496 */ 0497 Q_DECL_EXPORT QStringList whitelistedMountArguments(); 0498 #endif 0499 0500 /** 0501 * Find the mount executable on the system. 0502 * 0503 * @returns the path of the mount executable. 0504 */ 0505 Q_DECL_EXPORT const QString findMountExecutable(); 0506 0507 /** 0508 * Find the umount executable on the system. 0509 * 0510 * @returns the path of the umount executable. 0511 */ 0512 Q_DECL_EXPORT const QString findUmountExecutable(); 0513 0514 /** 0515 * This function returns the directory where data is to be placed. 0516 * @returns the data location 0517 */ 0518 Q_DECL_EXPORT const QString dataLocation(); 0519 }; 0520 0521 #endif