00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kfilesharedlg.h"
00021
#include <qvbox.h>
00022
#include <qlabel.h>
00023
#include <qdir.h>
00024
#include <qradiobutton.h>
00025
#include <qbuttongroup.h>
00026
#include <qlayout.h>
00027
#include <kprocess.h>
00028
#include <kprocio.h>
00029
#include <klocale.h>
00030
#include <kglobalsettings.h>
00031
#include <kstandarddirs.h>
00032
#include <kdebug.h>
00033
#include <stdio.h>
00034
#include <stdlib.h>
00035
#include <errno.h>
00036
#include <kio/kfileshare.h>
00037
#include <kseparator.h>
00038
#include <qpushbutton.h>
00039
#include <kapplication.h>
00040
#include <ksimpleconfig.h>
00041
#include <kmessagebox.h>
00042
00043
class KFileSharePropsPlugin::Private
00044 {
00045
public:
00046
QVBox *m_vBox;
00047
00048 };
00049
00050 KFileSharePropsPlugin::KFileSharePropsPlugin(
KPropertiesDialog *_props )
00051 :
KPropsDlgPlugin( _props )
00052 {
00053 d =
new Private;
00054 d->m_vBox = _props->
addVBoxPage( i18n(
"&Share") );
00055 properties->setFileSharingPage(d->m_vBox);
00056 m_widget = 0L;
00057 init();
00058 }
00059
00060 KFileSharePropsPlugin::~KFileSharePropsPlugin()
00061 {
00062
delete d;
00063 }
00064
00065
bool KFileSharePropsPlugin::supports(
const KFileItemList& items )
00066 {
00067
00068
00069
if (
KFileShare::shareMode() == KFileShare::Advanced) {
00070
kdDebug() <<
"KFileSharePropsPlugin::supports: false because sharemode is advanced" <<
endl;
00071
return false;
00072 }
00073
00074
KFileItemListIterator it( items );
00075
for ( ; it.current(); ++it )
00076 {
00077
bool isLocal = ( *it )->isLocalFile();
00078
00079
if ( !(*it)->isDir() || !isLocal )
00080
return false;
00081
00082
if ( isLocal && (*it)->url().path( 1 ) ==
KGlobalSettings::trashPath() )
00083
return false;
00084 }
00085
return true;
00086 }
00087
00088
void KFileSharePropsPlugin::init()
00089 {
00090
00091
00092
00093
delete m_widget;
00094 m_rbShare = 0L;
00095 m_rbUnShare = 0L;
00096 m_widget =
new QWidget( d->m_vBox );
00097
QVBoxLayout * vbox =
new QVBoxLayout( m_widget );
00098
00099
switch (
KFileShare::authorization() ) {
00100
case KFileShare::Authorized:
00101 {
00102
00103
QString home = QDir::homeDirPath();
00104
if (
home[
home.length()-1] !=
'/' )
00105
home +=
'/';
00106
bool ok =
true;
00107
KFileItemList items =
properties->
items();
00108
00109
bool allShared =
true;
00110
bool allUnshared =
true;
00111
KFileItemListIterator it( items );
00112
for ( ; it.current() && ok; ++it ) {
00113
QString path = (*it)->url().path();
00114
if ( !path.startsWith( home ) )
00115 ok =
false;
00116
if (
KFileShare::isDirectoryShared( path ) )
00117 allUnshared =
false;
00118
else
00119 allShared =
false;
00120 }
00121
if ( !ok )
00122 {
00123 vbox->addWidget(
new QLabel( i18n(
"Only folders in your home folder can be shared."),
00124 m_widget ), 0 );
00125 }
00126
else
00127 {
00128
00129 vbox->setSpacing( KDialog::spacingHint() );
00130 vbox->setMargin( KDialog::marginHint() );
00131
00132
QButtonGroup *rbGroup =
new QButtonGroup( m_widget );
00133 rbGroup->hide();
00134 m_rbUnShare =
new QRadioButton( i18n(
"Not shared"), m_widget );
00135 connect( m_rbUnShare, SIGNAL( toggled(
bool) ), SIGNAL(
changed() ) );
00136 vbox->addWidget( m_rbUnShare, 0 );
00137 rbGroup->insert( m_rbUnShare );
00138
00139 m_rbShare =
new QRadioButton( i18n(
"Shared"), m_widget );
00140 connect( m_rbShare, SIGNAL( toggled(
bool) ), SIGNAL(
changed() ) );
00141 vbox->addWidget( m_rbShare, 0 );
00142 rbGroup->insert( m_rbShare );
00143
00144
00145
if ( allShared )
00146 m_rbShare->setChecked(
true);
00147
if ( allUnshared )
00148 m_rbUnShare->setChecked(
true);
00149
00150
00151
QLabel *
label =
new QLabel( i18n(
"Sharing this folder makes it available under Linux/UNIX (NFS) and Windows (Samba).") , m_widget );
00152
label->setAlignment( Qt::AlignAuto | Qt::AlignVCenter | Qt::WordBreak );
00153 vbox->addWidget( label, 0 );
00154
00155
KSeparator* sep=
new KSeparator(m_widget);
00156 vbox->addWidget( sep, 0 );
00157
label =
new QLabel( i18n(
"You can also reconfigure file sharing authorization.") , m_widget );
00158
label->setAlignment( Qt::AlignAuto | Qt::AlignVCenter | Qt::WordBreak );
00159 vbox->addWidget( label, 0 );
00160 m_pbConfig =
new QPushButton( i18n(
"Configure File Sharing..."), m_widget );
00161 connect( m_pbConfig, SIGNAL( clicked() ), SLOT( slotConfigureFileSharing() ) );
00162 vbox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
00163
00164 vbox->addStretch( 10 );
00165 }
00166 }
00167
break;
00168
case KFileShare::ErrorNotFound:
00169 vbox->addWidget(
new QLabel( i18n(
"Error running 'filesharelist'. Check if installed and in $PATH or /usr/sbin."),
00170 m_widget ), 0 );
00171
break;
00172
case KFileShare::UserNotAllowed:
00173 {
00174 vbox->setSpacing( 10 );
00175
if (
KFileShare::sharingEnabled()) {
00176 vbox->addWidget(
new QLabel( i18n(
"You need to be authorized to share folders."),
00177 m_widget ), 0 );
00178 }
else {
00179 vbox->addWidget(
new QLabel( i18n(
"File sharing is disabled."),
00180 m_widget ), 0 );
00181 }
00182
QHBoxLayout* hBox =
new QHBoxLayout( (
QWidget *)0L );
00183 vbox->addLayout( hBox, 0 );
00184 m_pbConfig =
new QPushButton( i18n(
"Configure File Sharing..."), m_widget );
00185 connect( m_pbConfig, SIGNAL( clicked() ), SLOT( slotConfigureFileSharing() ) );
00186 hBox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
00187 vbox->addStretch( 10 );
00188
break;
00189 }
00190
case KFileShare::NotInitialized:
00191
kdWarning() <<
"KFileShare Authorization still NotInitialized after calling authorization() - impossible" <<
endl;
00192
break;
00193 }
00194 }
00195
00196
void KFileSharePropsPlugin::slotConfigureFileSharing()
00197 {
00198
KProcess proc;
00199 proc <<
KStandardDirs::findExe(
"kdesu") <<
"kcmshell" <<
"fileshare";
00200 proc.
start( KProcess::DontCare );
00201 m_pbConfig->setEnabled(
false);
00202 }
00203
00204 void KFileSharePropsPlugin::applyChanges()
00205 {
00206
kdDebug() <<
"KFileSharePropsPlugin::applyChanges" <<
endl;
00207
if ( m_rbShare && m_rbUnShare )
00208 {
00209
bool share = m_rbShare->isChecked();
00210
KFileItemList items = properties->
items();
00211
KFileItemListIterator it( items );
00212
bool ok =
true;
00213
for ( ; it.current() && ok; ++it ) {
00214
QString path = (*it)->url().path();
00215 ok = setShared( path, share );
00216
if (!ok) {
00217
if (share)
00218
KMessageBox::detailedError(properties,
00219 i18n(
"Sharing folder '%1' failed.").arg(path),
00220 i18n(
"An error occurred while trying to share folder '%1'. "
00221
"Make sure that the Perl script 'fileshareset' is set suid root.")
00222 .arg(path));
00223
else
00224
KMessageBox::error(properties,
00225 i18n(
"Unsharing folder '%1' failed.").arg(path),
00226 i18n(
"An error occurred while trying to unshare folder '%1'. "
00227
"Make sure that the Perl script 'fileshareset' is set suid root.")
00228 .arg(path));
00229
00230 properties->
abortApplying();
00231
break;
00232 }
00233 }
00234
00235
00236
KFileShare::readShareList();
00237 }
00238 }
00239
00240
bool KFileSharePropsPlugin::setShared(
const QString& path,
bool shared )
00241 {
00242
kdDebug() <<
"KFileSharePropsPlugin::setShared " << path <<
"," << shared <<
endl;
00243
return KFileShare::setShared( path, shared );
00244 }
00245
00246
QWidget* KFileSharePropsPlugin::page()
const
00247
{
00248
return d->m_vBox;
00249 }
00250
00251
#include "kfilesharedlg.moc"
00252
00253
00254
00255
00256