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