KIO
ksambasharedata.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright 2010 Rodrigo Belem <rclbelem@gmail.com> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) version 3, or any 00008 * later version accepted by the membership of KDE e.V. (or its 00009 * successor approved by the membership of KDE e.V.), which shall 00010 * act as a proxy defined in Section 6 of version 3 of the license. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library. If not, see <http://www.gnu.org/licenses/> 00019 */ 00020 00021 #include <QtCore/QRegExp> 00022 #include <QtCore/QFileInfo> 00023 #include <QtCore/QStringList> 00024 00025 #include "ksambashare.h" 00026 #include "ksambashare_p.h" 00027 #include "ksambasharedata.h" 00028 #include "ksambasharedata_p.h" 00029 00030 //TODO: add support for this samba options 00031 // usershare allow guests=P_BOOL,FLAG_ADVANCED 00032 // usershare max shares=P_INTEGER,FLAG_ADVANCED 00033 // usershare owner only=P_BOOL,FLAG_ADVANCED 00034 // usershare path=P_STRING,FLAG_ADVANCED 00035 // usershare prefix allow list=P_LIST,FLAG_ADVANCED 00036 // usershare prefix deny list=P_LIST,FLAG_ADVANCED 00037 // usershare template share=P_STRING,FLAG_ADVANCED 00038 00039 KSambaShareData::KSambaShareData() 00040 : dd(new KSambaShareDataPrivate) 00041 { 00042 } 00043 00044 KSambaShareData::KSambaShareData(const KSambaShareData &other) 00045 : dd(other.dd) 00046 { 00047 } 00048 00049 KSambaShareData::~KSambaShareData() 00050 { 00051 } 00052 00053 QString KSambaShareData::name() const 00054 { 00055 return dd->name; 00056 } 00057 00058 QString KSambaShareData::path() const 00059 { 00060 return dd->path; 00061 } 00062 00063 QString KSambaShareData::comment() const 00064 { 00065 return dd->comment; 00066 } 00067 00068 QString KSambaShareData::acl() const 00069 { 00070 return dd->acl; 00071 } 00072 00073 KSambaShareData::GuestPermission KSambaShareData::guestPermission() const 00074 { 00075 return (dd->guestPermission == QLatin1String("n")) ? GuestsNotAllowed : GuestsAllowed; 00076 } 00077 00078 KSambaShareData::UserShareError KSambaShareData::setName(const QString &name) 00079 { 00080 if (!KSambaShare::instance()->d_func()->isShareNameValid(name)) { 00081 return UserShareNameInvalid; 00082 } 00083 00084 if (!KSambaShare::instance()->d_func()->isShareNameAvailable(name)) { 00085 return UserShareNameInUse; 00086 } 00087 00088 00089 if (!dd->name.isEmpty()) { 00090 dd.detach(); 00091 } 00092 00093 dd->name = name; 00094 00095 return UserShareNameOk; 00096 } 00097 00098 KSambaShareData::UserShareError KSambaShareData::setPath(const QString &path) 00099 { 00100 UserShareError result = KSambaShare::instance()->d_func()->isPathValid(path); 00101 if (result == UserSharePathOk) { 00102 dd->path = path; 00103 } 00104 00105 return result; 00106 } 00107 00108 KSambaShareData::UserShareError KSambaShareData::setComment(const QString &comment) 00109 { 00110 dd->comment = comment; 00111 00112 return UserShareCommentOk; 00113 } 00114 00115 KSambaShareData::UserShareError KSambaShareData::setAcl(const QString &acl) 00116 { 00117 UserShareError result = KSambaShare::instance()->d_func()->isAclValid(acl); 00118 if (result == UserShareAclOk) { 00119 dd->acl = acl; 00120 } 00121 00122 return result; 00123 } 00124 00125 KSambaShareData::UserShareError KSambaShareData::setGuestPermission(const GuestPermission &permission) 00126 { 00127 UserShareError result = KSambaShare::instance()->d_func()->guestsAllowed(permission); 00128 if (result == UserShareGuestsOk) { 00129 dd->guestPermission = (permission == GuestsNotAllowed) ? "n" : "y"; 00130 } 00131 00132 return result; 00133 } 00134 00135 KSambaShareData::UserShareError KSambaShareData::save() 00136 { 00137 if (dd->name.isEmpty()) { 00138 return UserShareNameInvalid; 00139 } else if (dd->path.isEmpty()) { 00140 return UserSharePathInvalid; 00141 } else { 00142 return KSambaShare::instance()->d_func()->add(*this); 00143 } 00144 } 00145 00146 KSambaShareData::UserShareError KSambaShareData::remove() 00147 { 00148 if (dd->name.isEmpty()) { 00149 return UserShareNameInvalid; 00150 } else { 00151 return KSambaShare::instance()->d_func()->remove(*this); 00152 } 00153 } 00154 00155 KSambaShareData &KSambaShareData::operator=(const KSambaShareData &other) 00156 { 00157 if (&other != this) { 00158 dd = other.dd; 00159 } 00160 00161 return *this; 00162 } 00163 00164 bool KSambaShareData::operator==(const KSambaShareData &other) const 00165 { 00166 return other.dd == dd; 00167 } 00168 00169 bool KSambaShareData::operator!=(const KSambaShareData &other) const 00170 { 00171 return !(&other == this); 00172 }
KDE 4.7 API Reference