KIO

ksambasharedata.cpp
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#include "ksambasharedata.h"
8#include "ksambasharedata_p.h"
9
10#include "ksambashare.h"
11#include "ksambashare_p.h"
12
13// TODO: add support for this samba options
14// usershare allow guests=P_BOOL,FLAG_ADVANCED
15// usershare max shares=P_INTEGER,FLAG_ADVANCED
16// usershare owner only=P_BOOL,FLAG_ADVANCED
17// usershare path=P_STRING,FLAG_ADVANCED
18// usershare prefix allow list=P_LIST,FLAG_ADVANCED
19// usershare prefix deny list=P_LIST,FLAG_ADVANCED
20// usershare template share=P_STRING,FLAG_ADVANCED
21
22KSambaShareData::KSambaShareData()
23 : dd(new KSambaShareDataPrivate)
24{
25}
26
27KSambaShareData::KSambaShareData(const KSambaShareData &other)
28 : dd(other.dd)
29{
30}
31
32KSambaShareData::~KSambaShareData()
33{
34}
35
37{
38 return dd->name;
39}
40
42{
43 return dd->path;
44}
45
47{
48 return dd->comment;
49}
50
52{
53 return dd->acl;
54}
55
56KSambaShareData::GuestPermission KSambaShareData::guestPermission() const
57{
58 return (dd->guestPermission == QLatin1Char('n')) ? GuestsNotAllowed : GuestsAllowed;
59}
60
61KSambaShareData::UserShareError KSambaShareData::setName(const QString &name)
62{
63 if (!KSambaShare::instance()->d_func()->isShareNameValid(name)) {
64 return UserShareNameInvalid;
65 }
66
67 if (!KSambaShare::instance()->d_func()->isShareNameAvailable(name)) {
68 return UserShareNameInUse;
69 }
70
71 if (!dd->name.isEmpty()) {
72 dd.detach();
73 }
74
75 dd->name = name;
76
77 return UserShareNameOk;
78}
79
80KSambaShareData::UserShareError KSambaShareData::setPath(const QString &path)
81{
82 UserShareError result = KSambaShare::instance()->d_func()->isPathValid(path);
83 if (result == UserSharePathOk) {
84 dd->path = path;
85 }
86
87 return result;
88}
89
90KSambaShareData::UserShareError KSambaShareData::setComment(const QString &comment)
91{
92 dd->comment = comment;
93
94 return UserShareCommentOk;
95}
96
97KSambaShareData::UserShareError KSambaShareData::setAcl(const QString &acl)
98{
99 UserShareError result = KSambaShare::instance()->d_func()->isAclValid(acl);
100 if (result == UserShareAclOk) {
101 dd->acl = acl;
102 }
103
104 return result;
105}
106
107KSambaShareData::UserShareError KSambaShareData::setGuestPermission(const GuestPermission &permission)
108{
109 UserShareError result = KSambaShare::instance()->d_func()->guestsAllowed(permission);
110 if (result == UserShareGuestsOk) {
111 dd->guestPermission = (permission == GuestsNotAllowed) ? QStringLiteral("n") : QStringLiteral("y");
112 }
113
114 return result;
115}
116
117KSambaShareData::UserShareError KSambaShareData::save()
118{
119 if (dd->name.isEmpty()) {
120 return UserShareNameInvalid;
121 } else if (dd->path.isEmpty()) {
122 return UserSharePathInvalid;
123 } else {
124 return KSambaShare::instance()->d_func()->add(*this);
125 }
126}
127
128KSambaShareData::UserShareError KSambaShareData::remove()
129{
130 if (dd->name.isEmpty()) {
131 return UserShareNameInvalid;
132 } else {
133 return KSambaShare::instance()->d_func()->remove(*this);
134 }
135}
136
137KSambaShareData &KSambaShareData::operator=(const KSambaShareData &other)
138{
139 if (&other != this) {
140 dd = other.dd;
141 }
142
143 return *this;
144}
145
146bool KSambaShareData::operator==(const KSambaShareData &other) const
147{
148 return other.dd == dd;
149}
150
151bool KSambaShareData::operator!=(const KSambaShareData &other) const
152{
153 return !(&other == this);
154}
This class represents a Samba user share.
QString acl() const
Returns a containing a string describing the permission added to the users, such as "[DOMAIN\]usernam...
KSambaShareData::UserShareError setPath(const QString &path)
Set the path for the share.
KSambaShareData::UserShareError setAcl(const QString &acl)
Sets the acl to the share.
QString comment() const
KSambaShareData::UserShareError setGuestPermission(const GuestPermission &permission=KSambaShareData::GuestsNotAllowed)
Flags if guest is allowed or not to access the share.
KSambaShareData::GuestPermission guestPermission() const
KSambaShareData::UserShareError remove()
Unshare the folder held by the object.
KSambaShareData::UserShareError setComment(const QString &comment)
Sets the comment for the share.
KSambaShareData::UserShareError save()
Share the folder with the information that has been set.
QString path() const
QString name() const
KSambaShareData::UserShareError setName(const QString &name)
Sets the share name.
static KSambaShare * instance()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.