23 #include <QtGui/QLabel>
24 #include <QtCore/QDir>
25 #include <QtGui/QRadioButton>
26 #include <QtGui/QButtonGroup>
27 #include <QtGui/QLayout>
33 #include <QtGui/QPushButton>
36 class KFileSharePropsPlugin::Private
44 QRadioButton *m_rbShare;
45 QRadioButton *m_rbUnShare;
52 d->m_vBox =
new KVBox();
53 _props->addPage( d->m_vBox,
i18n(
"&Share") );
64 d->m_configProc->detach();
73 kDebug() <<
"KFileSharePropsPlugin::supports: false because sharemode is advanced";
77 KFileItemList::const_iterator kit = items.begin();
78 const KFileItemList::const_iterator kend = items.end();
79 for ( ; kit != kend; ++kit )
81 bool isLocal = (*kit).isLocalFile();
83 if ( !(*kit).isDir() || !isLocal )
89 void KFileSharePropsPlugin::init()
97 d->m_widget =
new QWidget( d->m_vBox );
98 QVBoxLayout * vbox =
new QVBoxLayout( d->m_widget );
105 if ( home[home.length()-1] !=
'/' )
110 d->m_bAllShared =
true;
111 d->m_bAllUnshared =
true;
112 KFileItemList::const_iterator kit = items.begin();
113 const KFileItemList::const_iterator kend = items.end();
114 for ( ; kit != kend && ok; ++kit )
117 const QString path = (*kit).url().toLocalFile();
118 if ( !path.startsWith( home ) )
121 d->m_bAllUnshared =
false;
123 d->m_bAllShared =
false;
127 vbox->addWidget(
new QLabel(
i18n(
"Only folders in your home folder can be shared."),
133 QButtonGroup *rbGroup =
new QButtonGroup( d->m_widget );
134 d->m_rbUnShare =
new QRadioButton(
i18n(
"Not shared"), d->m_widget );
135 connect( d->m_rbUnShare, SIGNAL(toggled(
bool)), SIGNAL(
changed()) );
136 vbox->addWidget( d->m_rbUnShare, 0 );
137 rbGroup->addButton( d->m_rbUnShare );
139 d->m_rbShare =
new QRadioButton(
i18n(
"Shared"), d->m_widget );
140 connect( d->m_rbShare, SIGNAL(toggled(
bool)), SIGNAL(
changed()) );
141 vbox->addWidget( d->m_rbShare, 0 );
142 rbGroup->addButton( d->m_rbShare );
145 if ( d->m_bAllShared )
146 d->m_rbShare->setChecked(
true);
147 if ( d->m_bAllUnshared )
148 d->m_rbUnShare->setChecked(
true);
151 QLabel *
label =
new QLabel(
i18n(
"Sharing this folder makes it available under Linux/UNIX (NFS) and Windows (Samba).") , d->m_widget );
152 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter);
153 label->setWordWrap(
true);
154 vbox->addWidget( label, 0 );
157 vbox->addWidget( sep, 0 );
158 label =
new QLabel(
i18n(
"You can also reconfigure file sharing authorization.") , d->m_widget );
159 label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter);
160 label->setWordWrap(
true);
161 vbox->addWidget( label, 0 );
162 d->m_pbConfig =
new QPushButton(
i18n(
"Configure File Sharing..."), d->m_widget );
164 vbox->addWidget( d->m_pbConfig, 0, Qt::AlignHCenter );
166 vbox->addStretch( 10 );
171 vbox->addWidget(
new QLabel(
i18n(
"Error running 'filesharelist'. Check if installed and in $PATH or /usr/sbin."),
176 vbox->setSpacing( 10 );
178 vbox->addWidget(
new QLabel(
i18n(
"You need to be authorized to share folders."),
181 vbox->addWidget(
new QLabel(
i18n(
"File sharing is disabled."),
184 QHBoxLayout* hBox =
new QHBoxLayout( (
QWidget *)0L );
185 vbox->addLayout( hBox, 0 );
186 d->m_pbConfig =
new QPushButton(
i18n(
"Configure File Sharing..."), d->m_widget );
188 hBox->addWidget( d->m_pbConfig, 0, Qt::AlignHCenter );
189 vbox->addStretch( 10 );
193 kWarning() <<
"KFileShare Authorization still NotInitialized after calling authorization() - impossible";
201 if (d->m_configProc)
return;
205 if (!d->m_configProc->start())
207 delete d->m_configProc;
211 connect(d->m_configProc, SIGNAL(processExited()),
213 d->m_pbConfig->setEnabled(
false);
218 delete d->m_configProc;
227 kDebug() <<
"KFileSharePropsPlugin::applyChanges";
228 if ( d->m_rbShare && d->m_rbUnShare )
230 bool share = d->m_rbShare->isChecked();
232 if (share && d->m_bAllShared)
234 if (!share && d->m_bAllUnshared)
239 KFileItemList::const_iterator kit = items.begin();
240 const KFileItemList::const_iterator kend = items.end();
241 for ( ; kit != kend && ok; ++kit )
243 const QString path = (*kit).url().toLocalFile();
244 ok = setShared( path, share );
248 i18n(
"Sharing folder '%1' failed.", path),
249 i18n(
"An error occurred while trying to share folder '%1'. "
250 "Make sure that the Perl script 'fileshareset' is set suid root.",
254 i18n(
"Unsharing folder '%1' failed.", path),
255 i18n(
"An error occurred while trying to unshare folder '%1'. "
256 "Make sure that the Perl script 'fileshareset' is set suid root.",
269 bool KFileSharePropsPlugin::setShared(
const QString& path,
bool shared )
271 kDebug() <<
"KFileSharePropsPlugin::setShared " << path <<
"," << shared;
280 #include "kfilesharedialog.moc"
QString i18n(const char *text)
virtual void applyChanges()
Apply all changes to the file.
static bool supports(const KFileItemList &items)
void readShareList()
Reads the list of shared folders.
KFileItemList items() const
bool sharingEnabled()
Returns whether sharing is enabled If this is false, file sharing is disabled and nobody can share fi...
QString label(StandardShortcut id)
static void detailedError(QWidget *parent, const QString &text, const QString &details, const QString &caption=QString(), Options options=Notify)
void abortApplying()
To abort applying changes.
KFileSharePropsPlugin(KPropertiesDialog *_props)
bool isDirectoryShared(const QString &path)
Call this to know if a directory is currently shared.
KPropertiesDialog * properties
Pointer to the dialog.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
bool setShared(const QString &path, bool shared)
Uses a suid perl script to share the given path with NFS and Samba.
ShareMode shareMode()
Returns the configured share mode.
void changed()
Emit this signal when the user changed anything in the plugin's tabs.
A Plugin in the Properties dialog This is an abstract class.
void slotConfigureFileSharingDone()
List of KFileItems, which adds a few helper methods to QList.
KAction * home(const QObject *recvr, const char *slot, QObject *parent)
Authorization authorization()
Call this to know if the current user is authorized to share directories.
The main properties dialog class.
void readConfig()
Reads the file share configuration file.
void slotConfigureFileSharing()
static QString findExe(const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)
void setFileSharingPage(QWidget *page)
Sets the file sharing page.
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
virtual ~KFileSharePropsPlugin()
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)