File indexing completed on 2024-04-14 04:56:24

0001 /*
0002     This is the global namespace for Smb4K.
0003 
0004     SPDX-FileCopyrightText: 2005-2024 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SMB4KGLOBAL_H
0009 #define SMB4KGLOBAL_H
0010 
0011 // application specific includes
0012 #include "smb4kbasicnetworkitem.h"
0013 #include "smb4kbookmark.h"
0014 #include "smb4kcustomsettings.h"
0015 #include "smb4kfile.h"
0016 #include "smb4khost.h"
0017 #include "smb4kshare.h"
0018 #include "smb4kworkgroup.h"
0019 
0020 // Qt includes
0021 #include <QEvent>
0022 #include <QList>
0023 #include <QMap>
0024 #include <QSharedPointer>
0025 #include <QString>
0026 #include <QStringList>
0027 
0028 // type definitions
0029 typedef QSharedPointer<Smb4KBasicNetworkItem> NetworkItemPtr;
0030 typedef QSharedPointer<Smb4KWorkgroup> WorkgroupPtr;
0031 typedef QSharedPointer<Smb4KHost> HostPtr;
0032 typedef QSharedPointer<Smb4KShare> SharePtr;
0033 typedef QSharedPointer<Smb4KFile> FilePtr;
0034 typedef QSharedPointer<Smb4KBookmark> BookmarkPtr;
0035 typedef QSharedPointer<Smb4KCustomSettings> CustomSettingsPtr;
0036 
0037 // Other definitions
0038 #ifndef SMB4K_DEPRECATED
0039 #define SMB4K_DEPRECATED __attribute__((__deprecated__))
0040 #endif
0041 
0042 /**
0043  * This is the global namespace. It provides access to the global lists
0044  * of workgroups, hosts and shares, to the global settings of the Samba
0045  * configuration and much more.
0046  *
0047  * @author    Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0048  */
0049 
0050 namespace Smb4KGlobal
0051 {
0052 /**
0053  * This function returns the global list of workgroups that were discovered by
0054  * Smb4K. Use this if you want to access and modify the list with your code.
0055  *
0056  * @returns the global list of known workgroups.
0057  */
0058 Q_DECL_EXPORT const QList<WorkgroupPtr> &workgroupsList();
0059 
0060 /**
0061  * This function returns the workgroup or domain that matches the name @p name or
0062  * NULL if there is no such workgroup.
0063  *
0064  * @returns a pointer to the workgroup with name @p name.
0065  */
0066 Q_DECL_EXPORT WorkgroupPtr findWorkgroup(const QString &name);
0067 
0068 /**
0069  * This function takes a workgroup @p workgroup, checks whether it is already
0070  * in the list of domains and adds it to the list if necessary. It returns TRUE
0071  * if the workgroup was added and FALSE otherwise.
0072  *
0073  * Please prefer this function over per class solutions.
0074  *
0075  * @param workgroup   The workgroup item
0076  *
0077  * @returns TRUE if the workgroup was added and FALSE otherwise.
0078  */
0079 Q_DECL_EXPORT bool addWorkgroup(WorkgroupPtr workgroup);
0080 
0081 /**
0082  * This function takes a workgroup @p workgroup, and updates the respective workgroup
0083  * in the global list, if it exists. It returns TRUE on success and FALSE otherwise.
0084  * If you want to add a workgroup to the global list, use @see addWorkgroup().
0085  *
0086  * Please prefer this function over per class solutions.
0087  *
0088  * @returns TRUE if the workgroup was updated and FALSE otherwise
0089  */
0090 Q_DECL_EXPORT bool updateWorkgroup(WorkgroupPtr workgroup);
0091 
0092 /**
0093  * This function removes a workgroup @p workgroup from the list of domains. The
0094  * pointer that is passed to this function will be deleted. You won't be able
0095  * to use it afterwards. This function returns TRUE if the workgroup was removed
0096  * and FALSE otherwise.
0097  *
0098  * Please prefer this function over per class solutions.
0099  *
0100  * @param workgroup   The workgroup item
0101  *
0102  * @returns TRUE if the workgroup was removed and FALSE otherwise.
0103  */
0104 Q_DECL_EXPORT bool removeWorkgroup(WorkgroupPtr workgroup);
0105 
0106 /**
0107  * This function clears the global list of workgroups.
0108  */
0109 Q_DECL_EXPORT void clearWorkgroupsList();
0110 
0111 /**
0112  * This function returns the global list of hosts that were discovered by
0113  * Smb4K. Use this if you want to access and modify the list with your code.
0114  *
0115  * @returns the global list of known hosts.
0116  */
0117 Q_DECL_EXPORT const QList<HostPtr> &hostsList();
0118 
0119 /**
0120  * This function returns the host matching the name @p name or NULL if there is no
0121  * such host. The name of the host is mandatory. The workgroup may be empty, but
0122  * should be given, because this will speed up the search process.
0123  *
0124  * @param name          The name of the host
0125  *
0126  * @param workgroup     The workgroup where the host is located
0127  *
0128  * @returns an Smb4KHost item of NULL if none was found that matches @p name.
0129  */
0130 Q_DECL_EXPORT HostPtr findHost(const QString &name, const QString &workgroup = QString());
0131 
0132 /**
0133  * This function takes a host @p host, checks whether it is already
0134  * in the list of hosts and adds it to the list if necessary. It returns TRUE
0135  * if the host was added and FALSE otherwise.
0136  *
0137  * Please prefer this function over per class solutions.
0138  *
0139  * @param host          The host item
0140  *
0141  * @returns TRUE if the host was added and FALSE otherwise.
0142  */
0143 Q_DECL_EXPORT bool addHost(HostPtr host);
0144 
0145 /**
0146  * This function takes an host @p host, and updates the respective host
0147  * in the global list, if it exists. It returns TRUE on success and FALSE otherwise.
0148  * If you want to add an host to the global list, use @see addHost().
0149  *
0150  * Please prefer this function over per class solutions.
0151  *
0152  * @returns TRUE if the host was updated and FALSE otherwise
0153  */
0154 Q_DECL_EXPORT bool updateHost(HostPtr host);
0155 
0156 /**
0157  * This function removes a host @p host from the list of hosts. The
0158  * pointer that is passed to this function will be deleted. You won't
0159  * be able to use it afterwards. This function returns TRUE if the host was removed
0160  * and FALSE otherwise.
0161  *
0162  * Please prefer this function over per class solutions.
0163  *
0164  * @param host          The host item
0165  *
0166  * @returns TRUE if the host was removed and FALSE otherwise.
0167  */
0168 Q_DECL_EXPORT bool removeHost(HostPtr host);
0169 
0170 /**
0171  * This function clears the global list of hosts.
0172  */
0173 Q_DECL_EXPORT void clearHostsList();
0174 
0175 /**
0176  * This function returns all hosts that belong to the workgroup or domain
0177  * @p workgroup.
0178  *
0179  * Please favor this function over per class solutions.
0180  *
0181  * @param workgroup   The workgroup for that the list should be returned.
0182  *
0183  * @returns the list of hosts belonging to the workgroup or domain @param workgroup.
0184  */
0185 Q_DECL_EXPORT QList<HostPtr> workgroupMembers(WorkgroupPtr workgroup);
0186 
0187 /**
0188  * This function returns the list of shares that were discovered by Smb4K.
0189  * Use this if you want to access and modify the list with your code.
0190  *
0191  * @returns the global list of known shares.
0192  */
0193 Q_DECL_EXPORT const QList<SharePtr> &sharesList();
0194 
0195 /**
0196  * This function returns the share with URL @p url located in the workgroup or
0197  * domain @p workgroup. If there is no such share, 0 is returned. The workgroup
0198  * entry may be empty.
0199  *
0200  * @param url           The URL of the share
0201  *
0202  * @param workgroup     The workgroup
0203  *
0204  * @returns the share that matches @p url and optionally @p workgroup or 0.
0205  */
0206 Q_DECL_EXPORT SharePtr findShare(const QUrl &url, const QString &workgroup = QString());
0207 
0208 /**
0209  * This function takes a share @p share, checks whether it is already
0210  * in the list of shares and adds it to the list if necessary. It returns TRUE
0211  * if the share was added and FALSE otherwise.
0212  *
0213  * Please prefer this function over per class solutions.
0214  *
0215  * @param share         The share item
0216  *
0217  * @returns TRUE if the share was added and FALSE otherwise.
0218  */
0219 Q_DECL_EXPORT bool addShare(SharePtr share);
0220 
0221 /**
0222  * This function takes a share @p share, and updates the respective share
0223  * in the global list, if it exists. It returns TRUE on success and FALSE otherwise.
0224  * If you want to add a share to the global list, use @see addShare().
0225  *
0226  * Please prefer this function over per class solutions.
0227  *
0228  * @returns TRUE if the share was updated and FALSE otherwise
0229  */
0230 Q_DECL_EXPORT bool updateShare(SharePtr share);
0231 
0232 /**
0233  * This function removes a share @p share from the list of shares. The
0234  * pointer that is passed to this function will be deleted. You won't
0235  * be able to use it afterwards. This function returns TRUE if the share was removed
0236  * and FALSE otherwise.
0237  *
0238  * Please prefer this function over per class solutions.
0239  *
0240  * @param share         The share item
0241  *
0242  * @returns TRUE if the share was removed and FALSE otherwise.
0243  */
0244 Q_DECL_EXPORT bool removeShare(SharePtr share);
0245 
0246 /**
0247  * This function clears the global list of shares.
0248  */
0249 Q_DECL_EXPORT void clearSharesList();
0250 
0251 /**
0252  * This function returns the list of shares that is provided by one specific host
0253  * @p host.
0254  *
0255  * Please favor this function over per class solutions.
0256  *
0257  * @param host          The host where the shares are located
0258  *
0259  * @returns the list of shares that are provided by the host @p host.
0260  */
0261 Q_DECL_EXPORT QList<SharePtr> sharedResources(HostPtr host);
0262 
0263 /**
0264  * This function returns the global list of mounted shares that were discovered by
0265  * Smb4K. Use this if you want to access and modify the list with your code.
0266  *
0267  * @returns the global list of known mounted shares.
0268  */
0269 Q_DECL_EXPORT const QList<SharePtr> &mountedSharesList();
0270 
0271 /**
0272  * Find a mounted share by its path (i.e. mount point).
0273  *
0274  * @returns the share that is mounted to @p path.
0275  */
0276 Q_DECL_EXPORT SharePtr findShareByPath(const QString &path);
0277 
0278 /**
0279  * Find all mounts of a particular share with URL @p url on the system.
0280  *
0281  * This function will compare the incoming URL with the URL of each
0282  * mounted share to find all shares with the same URL. For the comparison
0283  * the user info and the port will be stripped.
0284  *
0285  * @param url         The URL of the share
0286  *
0287  * @returns the complete list of mounts with the URL @p url.
0288  */
0289 Q_DECL_EXPORT QList<SharePtr> findShareByUrl(const QUrl &url);
0290 
0291 /**
0292  * This function returns the list of inaccessible shares.
0293  *
0294  * @returns the list of inaccessible shares.
0295  */
0296 Q_DECL_EXPORT QList<SharePtr> findInaccessibleShares();
0297 
0298 /**
0299  * This function takes a mounted share @p share, checks whether it is
0300  * already in the list of mounted shares and adds it to the list if
0301  * necessary. It returns TRUE if the share was added and FALSE otherwise.
0302  *
0303  * Please prefer this function over per class solutions.
0304  *
0305  * @param share       The share item
0306  *
0307  * @returns TRUE if the share was added and FALSE otherwise.
0308  */
0309 Q_DECL_EXPORT bool addMountedShare(SharePtr share);
0310 
0311 /**
0312  * This function takes a mounted share @p share and updates the share that
0313  * is already present in the internal list.
0314  *
0315  * @param share       The share item
0316  * @returns TRUE if a share was found and updated. Returns FALSE otherwise.
0317  */
0318 Q_DECL_EXPORT bool updateMountedShare(SharePtr share);
0319 
0320 /**
0321  * This function removes a mounted share @p share from the list of mounted
0322  * shares. The pointer that is passed to this function will be deleted.
0323  * You won't be able to use it afterwards. This function returns TRUE if
0324  * the share was removed and FALSE otherwise.
0325  *
0326  * Please prefer this function over per class solutions.
0327  *
0328  * @param share       The share item
0329  *
0330  * @returns TRUE if the share was removed and FALSE otherwise.
0331  */
0332 Q_DECL_EXPORT bool removeMountedShare(SharePtr share);
0333 
0334 /**
0335  * This function returns TRUE if only shares are present that are owned by
0336  * other users and FALSE otherwise.
0337  *
0338  * @returns TRUE if there are only shares that are owned by other users.
0339  */
0340 Q_DECL_EXPORT bool onlyForeignMountedShares();
0341 
0342 /**
0343  * This enumeration determines with which application the mount point
0344  * of the current mounted share is to be opened.
0345  */
0346 enum OpenWith { FileManager, Konsole };
0347 
0348 /**
0349  * Open the mount point of a share. Which application is used is determined by
0350  * the value of @p openWith and - maybe - by settings that were defined by the
0351  * user.
0352  *
0353  * @param share         The share that is to be opened.
0354  *
0355  * @param openWith      Integer of type Smb4KCore::OpenWith. Determines with which
0356  *                      application the share should be opened.
0357  */
0358 Q_DECL_EXPORT void openShare(SharePtr share, OpenWith openWith = FileManager);
0359 
0360 /**
0361  * Get the NetBIOS name of this computer.
0362  *
0363  * @returns the NetBIOS name
0364  */
0365 Q_DECL_EXPORT const QString machineNetbiosName();
0366 
0367 /**
0368  * Get the name of the workgroup or domain this computer is in.
0369  *
0370  * @returns the workgroup or domain
0371  */
0372 Q_DECL_EXPORT const QString machineWorkgroupName();
0373 
0374 /**
0375  * This function returns TRUE if the core classes should set a busy cursor when
0376  * they are doing something.
0377  *
0378  * @returns TRUE in case a busy cursor should be set.
0379  */
0380 Q_DECL_EXPORT bool modifyCursor();
0381 
0382 #if defined(Q_OS_LINUX)
0383 /**
0384  * This list contains all allowed arguments for the mount.cifs binary and
0385  * is only present under the Linux operating system.
0386  *
0387  * @returns the list of allowed mount arguments
0388  */
0389 Q_DECL_EXPORT QStringList allowedMountArguments();
0390 #endif
0391 
0392 /**
0393  * Find the mount executable on the system.
0394  *
0395  * @returns the path of the mount executable.
0396  */
0397 Q_DECL_EXPORT const QString findMountExecutable();
0398 
0399 /**
0400  * Find the umount executable on the system.
0401  *
0402  * @returns the path of the umount executable.
0403  */
0404 Q_DECL_EXPORT const QString findUmountExecutable();
0405 
0406 /**
0407  * This function returns the directory where data is to be placed.
0408  *
0409  * @returns the data location
0410  */
0411 Q_DECL_EXPORT const QString dataLocation();
0412 
0413 /**
0414  * Wait the given @p time until proceeding. This wait function is non-blocking.
0415  *
0416  * @param time          The waiting time in msec
0417  */
0418 Q_DECL_EXPORT void wait(int time);
0419 };
0420 
0421 #endif