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
00041
class KFileSharePropsPlugin::Private
00042 {
00043
public:
00044
QVBox *m_vBox;
00045 };
00046
00047 KFileSharePropsPlugin::KFileSharePropsPlugin(
KPropertiesDialog *_props )
00048 :
KPropsDlgPlugin( _props )
00049 {
00050 d =
new Private;
00051 d->m_vBox = _props->
addVBoxPage( i18n(
"Local Net Sharing") );
00052 m_widget = 0L;
00053 init();
00054 }
00055
00056 KFileSharePropsPlugin::~KFileSharePropsPlugin()
00057 {
00058
delete d;
00059 }
00060
00061
bool KFileSharePropsPlugin::supports(
const KFileItemList& items )
00062 {
00063
KFileItemListIterator it( items );
00064
for ( ; it.current(); ++it )
00065 {
00066
bool isLocal = ( *it )->isLocalFile();
00067
00068
if ( !(*it)->isDir() || !isLocal )
00069
return false;
00070
00071
if ( isLocal && (*it)->url().path( 1 ) ==
KGlobalSettings::trashPath() )
00072
return false;
00073 }
00074
return true;
00075 }
00076
00077
void KFileSharePropsPlugin::init()
00078 {
00079
00080
00081
00082
delete m_widget;
00083 m_rbShare = 0L;
00084 m_rbUnShare = 0L;
00085 m_widget =
new QWidget( d->m_vBox );
00086
QVBoxLayout * vbox =
new QVBoxLayout( m_widget );
00087
00088
switch (
KFileShare::authorization() ) {
00089
case KFileShare::Authorized:
00090 {
00091
00092
QString home = QDir::homeDirPath();
00093
if (
home[
home.length()-1] !=
'/' )
00094
home +=
'/';
00095
bool ok =
true;
00096
KFileItemList items =
properties->
items();
00097
00098
bool allShared =
true;
00099
bool allUnshared =
true;
00100
KFileItemListIterator it( items );
00101
for ( ; it.current() && ok; ++it ) {
00102
QString path = (*it)->url().path();
00103
if ( !path.startsWith( home ) )
00104 ok =
false;
00105
if (
KFileShare::isDirectoryShared( path ) )
00106 allUnshared =
false;
00107
else
00108 allShared =
false;
00109 }
00110
if ( !ok )
00111 {
00112 vbox->addWidget(
new QLabel( i18n(
"Only directories in your home directory can be shared."),
00113 m_widget ), 0 );
00114 }
00115
else
00116 {
00117
00118 vbox->setSpacing( 20 );
00119 vbox->setMargin( 20 );
00120
00121
QButtonGroup *rbGroup =
new QButtonGroup( m_widget );
00122 rbGroup->hide();
00123 m_rbUnShare =
new QRadioButton( i18n(
"Not shared"), m_widget );
00124 connect( m_rbUnShare, SIGNAL( toggled(
bool) ), SIGNAL(
changed() ) );
00125 vbox->addWidget( m_rbUnShare, 0 );
00126 rbGroup->insert( m_rbUnShare );
00127
00128 m_rbShare =
new QRadioButton( i18n(
"Shared"), m_widget );
00129 connect( m_rbShare, SIGNAL( toggled(
bool) ), SIGNAL(
changed() ) );
00130 vbox->addWidget( m_rbShare, 0 );
00131 rbGroup->insert( m_rbShare );
00132
00133
00134
if ( allShared )
00135 m_rbShare->setChecked(
true);
00136
if ( allUnshared )
00137 m_rbUnShare->setChecked(
true);
00138
00139
00140
QLabel *
label =
new QLabel( i18n(
"Sharing this directory makes it available under Linux/UNIX (NFS) and Windows (Samba).") , m_widget );
00141
label->setAlignment( Qt::AlignAuto | Qt::AlignVCenter | Qt::WordBreak );
00142 vbox->addWidget( label, 0 );
00143
00144
KSeparator* sep=
new KSeparator(m_widget);
00145 vbox->addWidget( sep, 0 );
00146
label =
new QLabel( i18n(
"You can also reconfigure file sharing authorization.") , m_widget );
00147
label->setAlignment( Qt::AlignAuto | Qt::AlignVCenter | Qt::WordBreak );
00148 vbox->addWidget( label, 0 );
00149 m_pbConfig =
new QPushButton( i18n(
"Configure File Sharing..."), m_widget );
00150 connect( m_pbConfig, SIGNAL( clicked() ), SLOT( slotConfigureFileSharing() ) );
00151 vbox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
00152
00153 vbox->addStretch( 10 );
00154 }
00155 }
00156
break;
00157
case KFileShare::ErrorNotFound:
00158 vbox->addWidget(
new QLabel( i18n(
"Error running 'filesharelist'. Check if installed and in $PATH or /usr/sbin."),
00159 m_widget ), 0 );
00160
break;
00161
case KFileShare::UserNotAllowed:
00162 {
00163 vbox->setSpacing( 10 );
00164 vbox->addWidget(
new QLabel( i18n(
"You need to be authorized to share directories."),
00165 m_widget ), 0 );
00166
QHBoxLayout* hBox =
new QHBoxLayout( (QWidget *)0L );
00167 vbox->addLayout( hBox, 0 );
00168 m_pbConfig =
new QPushButton( i18n(
"Configure File Sharing..."), m_widget );
00169 connect( m_pbConfig, SIGNAL( clicked() ), SLOT( slotConfigureFileSharing() ) );
00170 hBox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
00171 vbox->addStretch( 10 );
00172
break;
00173 }
00174
case KFileShare::NotInitialized:
00175
kdWarning() <<
"KFileShare Authorization still NotInitialized after calling authorization() - impossible" <<
endl;
00176
break;
00177 }
00178 }
00179
00180
void KFileSharePropsPlugin::slotConfigureFileSharing()
00181 {
00182
00183
QString exe = KFileShare::findExe(
"diskdrake" );
00184
if (!exe.isEmpty())
00185 {
00186
KProcess proc;
00187 proc << exe;
00188 proc <<
"--fileshare";
00189 proc.
start( KProcess::DontCare );
00190 m_pbConfig->setEnabled(
false);
00191 }
00192
else
00193 {
00194
kdDebug()<<
"diskdrake no find\n";
00195 }
00196 }
00197
00198 void KFileSharePropsPlugin::applyChanges()
00199 {
00200
kdDebug() <<
"KFileSharePropsPlugin::applyChanges" <<
endl;
00201
if ( m_rbShare && m_rbUnShare )
00202 {
00203
if ( m_rbShare->isChecked() )
00204 {
00205
00206
KFileItemList items = properties->
items();
00207
KFileItemListIterator it( items );
00208
bool ok =
true;
00209
for ( ; it.current() && ok; ++it ) {
00210
QString path = (*it)->url().path();
00211 ok = setShared( path,
true );
00212 }
00213 }
00214
else if ( m_rbUnShare->isChecked() )
00215 {
00216
00217
KFileItemList items = properties->
items();
00218
KFileItemListIterator it( items );
00219
bool ok =
true;
00220
for ( ; it.current() && ok; ++it ) {
00221
QString path = (*it)->url().path();
00222 ok = setShared( path,
false );
00223 }
00224 }
00225
00226
KFileShare::readConfig();
00227 }
00228 }
00229
00230
bool KFileSharePropsPlugin::setShared(
const QString& path,
bool shared )
00231 {
00232
kdDebug() <<
"KFileSharePropsPlugin::setShared " << path <<
"," << shared <<
endl;
00233
return KFileShare::setShared( path, shared );
00234 }
00235
00236 QWidget* KFileSharePropsPlugin::page()
const
00237
{
00238
return d->m_vBox;
00239 }
00240
00241
#include "kfilesharedlg.moc"
00242
00243
00244
00245
00246