File indexing completed on 2024-11-03 12:39:13
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de> 0004 SPDX-FileCopyrightText: 2010 Rodrigo Belem <rclbelem@gmail.com> 0005 SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-only 0008 */ 0009 0010 #ifndef ksambashare_h 0011 #define ksambashare_h 0012 0013 #include "kiocore_export.h" 0014 #include <QObject> 0015 0016 class KSambaShareData; 0017 class KSambaSharePrivate; 0018 0019 /** 0020 * @class KSambaShare ksambashare.h <KSambaShare> 0021 * 0022 * This class lists Samba user shares and monitors them for addition, update and removal. 0023 * Singleton class, call instance() to get an instance. 0024 */ 0025 class KIOCORE_EXPORT KSambaShare : public QObject 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 /** 0031 * @return the one and only instance of KSambaShare. 0032 */ 0033 static KSambaShare *instance(); 0034 0035 /** 0036 * Whether or not the given path is shared by Samba. 0037 * 0038 * @param path the path to check if it is shared by Samba. 0039 * 0040 * @return whether the given path is shared by Samba. 0041 */ 0042 bool isDirectoryShared(const QString &path) const; 0043 0044 /** 0045 * Returns a list of all directories shared by local users in Samba. 0046 * The resulting list is not sorted. 0047 * 0048 * @return a list of all directories shared by Samba. 0049 */ 0050 QStringList sharedDirectories() const; 0051 0052 /** 0053 * Tests that a share name is valid and does not conflict with system users names or shares. 0054 * 0055 * @param name the share name. 0056 * 0057 * @return whether the given name is already being used or not. 0058 * 0059 * @since 4.7 0060 */ 0061 bool isShareNameAvailable(const QString &name) const; 0062 0063 /** 0064 * Returns the list of available shares. 0065 * 0066 * @return @c a QStringList containing the user shares names. 0067 * @return @c an empty list if there aren't user shared directories. 0068 * 0069 * @since 4.7 0070 */ 0071 QStringList shareNames() const; 0072 0073 /** 0074 * Returns the KSambaShareData object of the share name. 0075 * 0076 * @param name the share name. 0077 * 0078 * @return @c the KSambaShareData object that matches the name. 0079 * @return @c an empty KSambaShareData object if there isn't match for the name. 0080 * 0081 * @since 4.7 0082 */ 0083 KSambaShareData getShareByName(const QString &name) const; 0084 0085 /** 0086 * Returns a list of KSambaShareData matching the path. 0087 * 0088 * @param path the path that wants to get KSambaShareData object. 0089 * 0090 * @return @c the QList of KSambaShareData objects that matches the path. 0091 * @return @c an empty QList if there aren't matches for the given path. 0092 * 0093 * @since 4.7 0094 */ 0095 QList<KSambaShareData> getSharesByPath(const QString &path) const; 0096 0097 ~KSambaShare() override; 0098 0099 #if KIOCORE_ENABLE_DEPRECATED_SINCE(4, 6) 0100 /** 0101 * Returns the path to the used smb.conf file 0102 * or empty string if no file was found 0103 * 0104 * @return @c the path to the smb.conf file 0105 * 0106 * @deprecated Since 4.6, the conf file is no longer used 0107 */ 0108 KIOCORE_DEPRECATED_VERSION(4, 6, "Conf file no longer used") 0109 QString smbConfPath() const; 0110 #endif 0111 0112 /** 0113 * Used to obtain UserShareSystemError error strings. This is usually the 0114 * verbatim stderr of internal helper commands and may contain newlines. 0115 * Do not use this to obtain error strings for other error types! 0116 * 0117 * @return QString containing the most relevant last stderr 0118 * @since 5.74 0119 */ 0120 QString lastSystemErrorString() const; 0121 0122 /** 0123 * Check whether usershares may enable guests. System-level configuration 0124 * may disable usershare guests and prevent saving KSambaShareData with 0125 * UserGuestPermission set. 0126 * 0127 * @return @c true when usershares may allow guest access 0128 * @since 5.74 0129 */ 0130 bool areGuestsAllowed() const; 0131 0132 Q_SIGNALS: 0133 /** 0134 * Emitted when a share is updated, added or removed 0135 */ 0136 void changed(); 0137 0138 private: 0139 KIOCORE_NO_EXPORT KSambaShare(); 0140 0141 KSambaSharePrivate *const d_ptr; 0142 Q_DECLARE_PRIVATE(KSambaShare) 0143 friend class KSambaShareData; 0144 friend class KSambaShareSingleton; 0145 }; 0146 0147 #endif