2
Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>
3
Copyright (c) 2011 Rodrigo Belem <rclbelem@gmail.com>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include <QStringList>
23
#include <QStandardItemModel>
28
#include <ksambashare.h>
29
#include <ksambasharedata.h>
30
#include <kmessagebox.h>
31
#include <KDE/KPluginFactory>
32
#include <KDE/KPluginLoader>
34
#include "propsdlgshareplugin.h"
38
K_PLUGIN_FACTORY(SambaUserSharePluginFactory, registerPlugin<SambaUserSharePlugin>();)
39
K_EXPORT_PLUGIN(SambaUserSharePluginFactory("fileshare_propsdlgplugin"))
41
SambaUserSharePlugin::SambaUserSharePlugin(QObject *parent, const QList<QVariant> &args)
42
: KPropertiesDialogPlugin(qobject_cast<KPropertiesDialog *>(parent))
46
url = properties->kurl().path(KUrl::RemoveTrailingSlash);
51
QFileInfo pathInfo(url);
52
if (!pathInfo.permission(QFile::ReadUser | QFile::WriteUser)) {
56
KGlobal::locale()->insertCatalog("kfileshare");
58
KVBox *vbox = new KVBox();
59
properties->addPage(vbox, i18n("&Share"));
60
properties->setFileSharingPage(vbox);
62
QWidget *widget = new QWidget(vbox);
63
propertiesUi.setupUi(widget);
65
QList<KSambaShareData> shareList = KSambaShare::instance()->getSharesByPath(url);
67
if (!shareList.isEmpty()) {
68
shareData = shareList.at(0); // FIXME: using just the first in the list for a while
75
connect(propertiesUi.sambaChk, SIGNAL(toggled(bool)), this, SLOT(toggleShareStatus(bool)));
76
connect(propertiesUi.sambaChk, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
77
connect(propertiesUi.sambaNameEdit, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
78
connect(propertiesUi.sambaAllowGuestChk, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
79
connect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SIGNAL(changed()));
81
for (int i = 0; i < model->rowCount(); ++i) {
82
propertiesUi.tableView->openPersistentEditor(model->index(i, 1, QModelIndex()));
86
SambaUserSharePlugin::~SambaUserSharePlugin()
90
void SambaUserSharePlugin::setupModel()
92
model = new UserPermissionModel(shareData, this);
95
void SambaUserSharePlugin::setupViews()
98
propertiesUi.tableView->setModel(model);
99
propertiesUi.tableView->setSelectionMode(QAbstractItemView::NoSelection);
100
propertiesUi.tableView->setItemDelegate(new UserPermissionDelegate(this));
103
void SambaUserSharePlugin::load()
105
bool guestAllowed = false;
106
bool sambaShared = KSambaShare::instance()->isDirectoryShared(url);
108
propertiesUi.sambaChk->setChecked(sambaShared);
110
guestAllowed = (bool) shareData.guestPermission();
112
propertiesUi.sambaAllowGuestChk->setChecked(guestAllowed);
114
propertiesUi.sambaNameEdit->setText(shareData.name());
117
void SambaUserSharePlugin::applyChanges()
119
KSambaShareData::UserShareError result;
121
if (propertiesUi.sambaChk->isChecked()) {
122
if (!propertiesUi.sambaNameEdit->text().isEmpty()
123
&& (shareData.name() != propertiesUi.sambaNameEdit->text())) {
124
shareData.setName(propertiesUi.sambaNameEdit->text());
127
shareData.setPath(url);
129
KSambaShareData::GuestPermission guestOk(shareData.guestPermission());
131
guestOk = (propertiesUi.sambaAllowGuestChk->isChecked() == false)
132
? KSambaShareData::GuestsNotAllowed : KSambaShareData::GuestsAllowed;
134
shareData.setGuestPermission(guestOk);
136
if (shareData.setAcl(model->getAcl()) != KSambaShareData::UserShareAclOk) {
140
result = shareData.save();
141
} else if (KSambaShare::instance()->isDirectoryShared(url)) {
142
result = shareData.remove();
146
void SambaUserSharePlugin::toggleShareStatus(bool checked)
148
if (propertiesUi.sambaNameEdit->text().isEmpty()) {
149
propertiesUi.sambaNameEdit->setText(getNewSambaName());
153
bool SambaUserSharePlugin::updateSambaShare()
155
kDebug() << "SambaUserSharePlugin::updateSambaShare: url" << url;
157
if (propertiesUi.sambaNameEdit->text().isEmpty()) {
158
//KMessageBox::sorry(this, i18n("You have to enter a name for the Samba share."));
159
propertiesUi.sambaNameEdit->setFocus();
163
if (propertiesUi.sambaNameEdit->text() != shareData.name()) {
164
if (!KSambaShare::instance()->isShareNameAvailable(propertiesUi.sambaNameEdit->text())) {
165
// There is another Share with the same name
166
//KMessageBox::sorry(this, i18n("<qt>There is already a share with the name <strong>%1</strong>.<br /> Please choose another name.</qt>", sambaNameEdit->text()));
167
propertiesUi.sambaNameEdit->selectAll();
168
propertiesUi.sambaNameEdit->setFocus();
172
shareData.setName(propertiesUi.sambaNameEdit->text());
178
QString SambaUserSharePlugin::getNewSambaName()
180
QString shareName = KUrl(url).fileName();
182
if (!propertiesUi.sambaNameEdit->text().isEmpty()) {
183
shareName = propertiesUi.sambaNameEdit->text();
186
// Windows could have problems with longer names
187
shareName = shareName.left(12);
192
#include "moc_propsdlgshareplugin.cpp"