File samba-file-sharing.diff of Package kdelibs3
--- kio/kio/kfileshare.cpp.sav 2005-09-29 21:31:30.000000000 +0200
+++ kio/kio/kfileshare.cpp 2006-11-15 20:47:51.000000000 +0100
@@ -291,4 +291,24 @@ bool KFileShare::setShared( const QStrin
return ok;
}
+bool KFileShare::sambaActive()
+{
+ // rcsmb is not executable by users, try ourselves
+ int status = system( "/sbin/checkproc -p /var/run/samba/smbd.pid /usr/sbin/smbd" );
+ return status != -1 && WIFEXITED( status ) && WEXITSTATUS( status ) == 0;
+}
+
+bool KFileShare::nfsActive()
+{
+ // rcnfsserver is not executable by users, try ourselves
+ int status = system( "/sbin/checkproc /usr/sbin/rpc.mountd" );
+ if( status != -1 && WIFEXITED( status ) && WEXITSTATUS( status ) == 0 )
+ {
+ status = system( "/sbin/checkproc -n nfsd" );
+ if( status != -1 && WIFEXITED( status ) && WEXITSTATUS( status ) == 0 )
+ return true;
+ }
+ return false;
+}
+
#include "kfileshare.moc"
--- kio/kio/kfileshare.h.sav 2005-09-29 21:31:29.000000000 +0200
+++ kio/kio/kfileshare.h 2006-11-15 21:18:57.000000000 +0100
@@ -131,6 +131,18 @@ public:
* Returns whether NFS is enabled
*/
static bool nfsEnabled();
+
+ /**
+ * Returns whether Samba is active (service is running)
+ * @internal
+ */
+ static bool sambaActive();
+
+ /**
+ * Returns whether NFS is active (service is running)
+ * @internal
+ */
+ static bool nfsActive();
private:
static Authorization s_authorization;
--- kio/kfile/kfilesharedlg.cpp.sav 2005-09-29 21:31:31.000000000 +0200
+++ kio/kfile/kfilesharedlg.cpp 2006-11-15 22:04:55.000000000 +0100
@@ -47,6 +47,8 @@ public:
KProcess *m_configProc;
bool m_bAllShared;
bool m_bAllUnshared;
+ QLabel* m_sambaStatus;
+ QLabel* m_nfsStatus;
};
KFileSharePropsPlugin::KFileSharePropsPlugin( KPropertiesDialog *_props )
@@ -165,6 +167,25 @@ void KFileSharePropsPlugin::init()
m_pbConfig = new QPushButton( i18n("Configure File Sharing..."), m_widget );
connect( m_pbConfig, SIGNAL( clicked() ), SLOT( slotConfigureFileSharing() ) );
vbox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
+
+ sep = new KSeparator( m_widget );
+ vbox->addWidget( sep, 0 );
+ QGridLayout* grid = new QGridLayout( vbox, 2, 3 );
+ label = new QLabel( i18n( "Samba status:" ), m_widget );
+ grid->addWidget( label, 0, 0 );
+ d->m_sambaStatus = new QLabel( m_widget );
+ grid->addWidget( d->m_sambaStatus, 0, 1 );
+ QPushButton* cb = new QPushButton( i18n( "Configure..." ), m_widget );
+ connect( cb, SIGNAL( clicked()), SLOT( configureSamba()));
+ grid->addWidget( cb, 0, 2 );
+ label = new QLabel( i18n( "NFS status:" ), m_widget );
+ grid->addWidget( label, 1, 0 );
+ d->m_nfsStatus = new QLabel( m_widget );
+ grid->addWidget( d->m_nfsStatus, 1, 1 );
+ cb = new QPushButton( i18n( "Configure..." ), m_widget );
+ connect( cb, SIGNAL( clicked()), SLOT( configureNfs()));
+ grid->addWidget( cb, 1, 2 );
+ updateServiceStatus( NULL );
vbox->addStretch( 10 );
}
@@ -278,6 +299,31 @@ QWidget* KFileSharePropsPlugin::page() c
return d->m_vBox;
}
+void KFileSharePropsPlugin::configureSamba()
+{
+ KProcess* proc = new KProcess;
+ *proc << locate( "exe", "kdesu" ) << "--nonewdcop" << "/sbin/yast2" << "samba-server";
+ connect( proc, SIGNAL( processExited( KProcess* )), SLOT( updateServiceStatus( KProcess * )));
+ if( !proc->start( KProcess::NotifyOnExit ))
+ KMessageBox::error( m_widget->topLevelWidget(), i18n( "Cannot run Samba configuration module" ));
+}
+
+void KFileSharePropsPlugin::configureNfs()
+{
+ KProcess* proc = new KProcess;
+ *proc << locate( "exe", "kdesu" ) << "--nonewdcop" << "/sbin/yast2" << "nfs_server";
+ connect( proc, SIGNAL( processExited( KProcess* )), SLOT( updateServiceStatus( KProcess * )));
+ if( !proc->start( KProcess::NotifyOnExit ))
+ KMessageBox::error( m_widget->topLevelWidget(), i18n( "Cannot run NFS configuration module" ));
+}
+
+void KFileSharePropsPlugin::updateServiceStatus( KProcess* proc )
+{
+ delete proc;
+ d->m_sambaStatus->setText( KFileShare::sambaActive() ? i18n( "Running" ) : i18n( "Not running" ));
+ d->m_nfsStatus->setText( KFileShare::nfsActive() ? i18n( "Running" ) : i18n( "Not running" ));
+}
+
#include "kfilesharedlg.moc"
//TODO: do we need to monitor /etc/security/fileshare.conf ?
--- kio/kfile/kfilesharedlg.h.sav 2005-09-29 21:31:31.000000000 +0200
+++ kio/kfile/kfilesharedlg.h 2006-11-15 22:01:11.000000000 +0100
@@ -24,6 +24,7 @@
class QVBoxLayout;
class QRadioButton;
class QPushButton;
+class KProcess;
/**
* This plugin provides a page to KPropsDlg, showing the "file sharing" options
@@ -52,6 +53,11 @@ protected slots:
void slotConfigureFileSharing();
void slotConfigureFileSharingDone();
+private slots:
+ void configureSamba();
+ void configureNfs();
+ void updateServiceStatus( KProcess* proc );
+
private:
void init();
bool setShared( const QString&path, bool shared );