1/*
2 SPDX-FileCopyrightText: 2010 Rodrigo Belem <rclbelem@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef ksambasharedata_h
8#define ksambasharedata_h
9
10#include "kiocore_export.h"
11#include <QExplicitlySharedDataPointer>
12
13class QString;
14class KSambaShare;
15class KSambaSharePrivate;
16class KSambaShareDataPrivate;
17
18/*!
19 * \class KSambaShareData
20 * \inmodule KIOCore
21 *
22 * \brief This class represents a Samba user share.
23 *
24 * It is possible to share a directory with one or more
25 * different names, update the share details or remove.
26 *
27 * \since 4.7
28 * \sa KSambaShare
29 */
30class KIOCORE_EXPORT KSambaShareData
31{
32public:
33 /*!
34 * \value GuestsNotAllowed
35 * \value GuestsAllowed
36 */
37 enum GuestPermission {
38 GuestsNotAllowed,
39 GuestsAllowed,
40 };
41
42 /*!
43 * \value UserShareOk
44 * \value UserShareExceedMaxShares
45 * \value UserShareNameOk
46 * \value UserShareNameInvalid
47 * \value UserShareNameInUse
48 * \value UserSharePathOk
49 * \value UserSharePathInvalid
50 * \value UserSharePathNotExists
51 * \value UserSharePathNotDirectory
52 * \value UserSharePathNotAbsolute
53 * \value UserSharePathNotAllowed
54 * \value UserShareAclOk
55 * \value UserShareAclInvalid
56 * \value UserShareAclUserNotValid
57 * \value UserShareCommentOk
58 * \value UserShareGuestsOk
59 * \value UserShareGuestsInvalid
60 * \value UserShareGuestsNotAllowed
61 * \value UserShareSystemError A system error occurred; check KSambaShare::lastSystemErrorString
62 */
63 enum UserShareError {
64 UserShareOk,
65 UserShareExceedMaxShares,
66 UserShareNameOk,
67 UserShareNameInvalid,
68 UserShareNameInUse,
69 UserSharePathOk,
70 UserSharePathInvalid,
71 UserSharePathNotExists,
72 UserSharePathNotDirectory,
73 UserSharePathNotAbsolute,
74 UserSharePathNotAllowed,
75 UserShareAclOk,
76 UserShareAclInvalid,
77 UserShareAclUserNotValid,
78 UserShareCommentOk,
79 UserShareGuestsOk,
80 UserShareGuestsInvalid,
81 UserShareGuestsNotAllowed,
82 UserShareSystemError,
83 };
84
85 KSambaShareData();
86 KSambaShareData(const KSambaShareData &other);
87
88 ~KSambaShareData();
89
90 /*!
91 * Returns the share name.
92 */
93 QString name() const;
94
95 /*!
96 * Returns the share path.
97 */
98 QString path() const;
99
100 /*!
101 * Returns the share comment.
102 */
103 QString comment() const;
104
105 /*!
106 * Containing a string describing the permission added to the users, such as
107 * "[DOMAIN\]username1:X,[DOMAIN\]username2:X,...". X stands for "F" (full control), "R"
108 * (read-only) and "D" (deny). By default the acl is Everyone:R.
109 *
110 * Returns the share acl.
111 */
112 QString acl() const;
113
114 /*!
115 * Returns whether guest access to the share is allowed or not.
116 */
117 KSambaShareData::GuestPermission guestPermission() const;
118
119 /*!
120 * Sets the share name. If the share name is changed and valid it will remove the existing
121 * share and will create a new share.
122 * The share name cannot use a name of a system user or containing the forbidden characters
123 * '%, <, >, *, ?, |, /, \, +, =, ;, :, ",,. To check if the name is available or valid use
124 * the method KSambaShare::isShareNameAvailable().
125 *
126 * \a name the name that will be given to the share.
127 *
128 * Returns UserShareNameOk if the name is valid, UserShareNameInvalid if the name contains invalid characters, UserShareNameInUse if the name is already in
129 * use by another shared folder or a by a system user.
130 */
131 KSambaShareData::UserShareError setName(const QString &name);
132
133 /*!
134 * Set the path for the share.
135 *
136 * \a path the path that will be given to the share.
137 *
138 * Returns UserSharePathOk if valid.
139 *
140 * Returns UserSharePathInvalid if the path is in invalid format.
141 *
142 * Returns UserSharePathNotExists if the path does not exists.
143 *
144 * Returns UserSharePathNotDirectory if the path points to file instead of a directory.
145 *
146 * Returns UserSharePathNotAbsolute if the path is not is absolute form.
147 *
148 * Returns UserSharePathNotAllowed if the path is not owner by the user.
149 */
150 KSambaShareData::UserShareError setPath(const QString &path);
151
152 /*!
153 * Sets the comment for the share.
154 *
155 * \a comment the comment that will be given to the share.
156 *
157 * Returns UserShareCommentOk always.
158 */
159 KSambaShareData::UserShareError setComment(const QString &comment);
160
161 /*!
162 * Sets the acl to the share.
163 *
164 * \a acl the acl that will be given to the share.
165 *
166 * Returns UserShareAclOk if the acl is valid.
167 *
168 * Returns UserShareAclInvalid if the acl has invalid format.
169 *
170 * Returns UserShareAclUserNotValid if one of the users in the acl is invalid.
171 */
172 KSambaShareData::UserShareError setAcl(const QString &acl);
173
174 /*!
175 * Flags if guest is allowed or not to access the share.
176 *
177 * \a permission the permission that will be given to the share.
178 *
179 * Returns UserShareGuestsOk if the permission was set.
180 *
181 * Returns UserShareGuestsNotAllowed if the system does not allow guest access to the
182 * shares.
183 */
184 KSambaShareData::UserShareError setGuestPermission(const GuestPermission &permission = KSambaShareData::GuestsNotAllowed);
185
186 /*!
187 * Share the folder with the information that has been set.
188 *
189 * Returns UserShareOk if the share was added or other errors as applicable. Also see UserShareSystemError.
190 */
191 KSambaShareData::UserShareError save();
192
193 /*!
194 * Unshare the folder held by the object.
195 *
196 * Returns UserShareOk if the share was removed or other errors as applicable. Also see UserShareSystemError.
197 */
198 KSambaShareData::UserShareError remove();
199
200 KSambaShareData &operator=(const KSambaShareData &other);
201 bool operator==(const KSambaShareData &other) const;
202 bool operator!=(const KSambaShareData &other) const;
203
204private:
205 QExplicitlySharedDataPointer<KSambaShareDataPrivate> dd;
206
207 friend class KSambaSharePrivate;
208};
209
210#endif
211

source code of kio/src/core/ksambasharedata.h