20 #include "tdefilesharedlg.h"
24 #include <tqradiobutton.h>
25 #include <tqbuttongroup.h>
27 #include <tqlineedit.h>
30 #include <tdelocale.h>
31 #include <tdeglobalsettings.h>
32 #include <kstandarddirs.h>
37 #include <tdeio/tdefileshare.h>
38 #include <kseparator.h>
39 #include <tqpushbutton.h>
40 #include <tdeapplication.h>
41 #include <ksimpleconfig.h>
42 #include <tdemessagebox.h>
44 class KFileSharePropsPlugin::Private
48 TDEProcess *m_configProc;
58 d->m_vBox = _props->addVBoxPage( i18n(
"&Share") );
60 properties->setFileSharingPage(d->m_vBox);
65 KFileSharePropsPlugin::~KFileSharePropsPlugin()
68 d->m_configProc->detach();
72 bool KFileSharePropsPlugin::supports(
const KFileItemList& items )
76 if (KFileShare::shareMode() == KFileShare::Advanced) {
77 kdDebug() <<
"KFileSharePropsPlugin::supports: false because sharemode is advanced" << endl;
81 KFileItemListIterator it( items );
82 for ( ; it.current(); ++it )
84 bool isLocal = ( *it )->isLocalFile();
86 if ( !(*it)->isDir() || !isLocal )
89 if ( isLocal && (*it)->url().path( 1 ) == TDEGlobalSettings::trashPath() )
95 void KFileSharePropsPlugin::init()
104 m_widget =
new TQWidget( d->m_vBox );
105 TQVBoxLayout * vbox =
new TQVBoxLayout( m_widget );
108 switch ( KFileShare::authorization() ) {
109 case KFileShare::Authorized:
112 TQString home = TQDir::homeDirPath();
113 if ( home[home.length()-1] !=
'/' )
118 d->m_bAllShared =
true;
119 d->m_bAllUnshared =
true;
120 d->m_bAllReadOnly =
true;
121 KFileItemListIterator it( items );
122 for ( ; it.current() && ok; ++it ) {
123 TQString path = (*it)->url().path();
127 int dirStatus = KFileShare::isDirectoryShared( path );
128 if ( !path.startsWith( home ) )
130 if ( dirStatus == 1 ) {
131 d->m_bAllUnshared =
false;
133 else if ( dirStatus == 3 ) {
134 d->m_bAllUnshared =
false;
135 d->m_bAllReadOnly =
false;
138 d->m_bAllReadOnly =
false;
143 vbox->addWidget(
new TQLabel( i18n(
"Only folders in your home folder can be shared."),
149 vbox->setSpacing( KDialog::spacingHint() );
150 vbox->setMargin( KDialog::marginHint() );
152 TQButtonGroup *rbGroup =
new TQButtonGroup( m_widget );
154 m_rbUnShare =
new TQRadioButton( i18n(
"Not shared"), m_widget );
155 connect( m_rbUnShare, TQT_SIGNAL( toggled(
bool) ), TQT_SIGNAL(
changed() ) );
156 vbox->addWidget( m_rbUnShare, 0 );
157 rbGroup->insert( m_rbUnShare );
159 m_rbShare =
new TQRadioButton( i18n(
"Shared - read only for others"), m_widget );
160 connect( m_rbShare, TQT_SIGNAL( toggled(
bool) ), TQT_SIGNAL(
changed() ) );
161 vbox->addWidget( m_rbShare, 0 );
162 rbGroup->insert( m_rbShare );
164 m_rbSharerw =
new TQRadioButton( i18n(
"Shared - writeable for others"), m_widget );
165 connect( m_rbSharerw, TQT_SIGNAL( toggled(
bool) ), TQT_SIGNAL(
changed() ) );
166 vbox->addWidget( m_rbSharerw, 0 );
167 rbGroup->insert( m_rbSharerw );
178 if ( d->m_bAllShared )
179 m_rbSharerw->setChecked(
true);
180 if ( d->m_bAllUnshared )
181 m_rbUnShare->setChecked(
true);
182 if ( d->m_bAllReadOnly )
183 m_rbShare->setChecked(
true);
186 TQLabel *label =
new TQLabel( i18n(
"Sharing this folder makes it available under Linux/UNIX (NFS) and Windows (Samba).") , m_widget );
187 label->setAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::WordBreak );
188 vbox->addWidget( label, 0 );
190 KSeparator* sep=
new KSeparator(m_widget);
191 vbox->addWidget( sep, 0 );
192 label =
new TQLabel( i18n(
"You can also reconfigure file sharing authorization.") , m_widget );
193 label->setAlignment( TQt::AlignAuto | TQt::AlignVCenter | TQt::WordBreak );
194 vbox->addWidget( label, 0 );
195 m_pbConfig =
new TQPushButton( i18n(
"Configure File Sharing..."), m_widget );
196 connect( m_pbConfig, TQT_SIGNAL( clicked() ), TQT_SLOT( slotConfigureFileSharing() ) );
197 vbox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
199 vbox->addStretch( 10 );
201 if( !KFileShare::sambaActive() && !KFileShare::nfsActive())
202 m_widget->setEnabled(
false );
206 case KFileShare::ErrorNotFound:
207 vbox->addWidget(
new TQLabel( i18n(
"Error running 'filesharelist'. Check if installed and in $PATH or /usr/sbin."),
210 case KFileShare::UserNotAllowed:
212 vbox->setSpacing( 10 );
213 if (KFileShare::sharingEnabled()) {
214 vbox->addWidget(
new TQLabel( i18n(
"You need to be authorized to share folders."),
217 vbox->addWidget(
new TQLabel( i18n(
"File sharing is disabled."),
220 TQHBoxLayout* hBox =
new TQHBoxLayout( (TQWidget *)0L );
221 vbox->addLayout( hBox, 0 );
222 m_pbConfig =
new TQPushButton( i18n(
"Configure File Sharing..."), m_widget );
223 connect( m_pbConfig, TQT_SIGNAL( clicked() ), TQT_SLOT( slotConfigureFileSharing() ) );
224 hBox->addWidget( m_pbConfig, 0, Qt::AlignHCenter );
225 vbox->addStretch( 10 );
228 case KFileShare::NotInitialized:
229 kdWarning() <<
"KFileShare Authorization still NotInitialized after calling authorization() - impossible" << endl;
235 void KFileSharePropsPlugin::slotConfigureFileSharing()
237 if (d->m_configProc)
return;
239 d->m_configProc =
new TDEProcess(
this);
240 (*d->m_configProc) << TDEStandardDirs::findExe(
"tdesu") << locate(
"exe",
"tdecmshell") <<
"fileshare";
241 if (!d->m_configProc->start( TDEProcess::NotifyOnExit ))
243 delete d->m_configProc;
247 connect(d->m_configProc, TQT_SIGNAL(processExited(TDEProcess *)),
248 this, TQT_SLOT(slotConfigureFileSharingDone()));
249 m_pbConfig->setEnabled(
false);
252 void KFileSharePropsPlugin::slotConfigureFileSharingDone()
254 delete d->m_configProc;
256 KFileShare::readConfig();
257 KFileShare::readShareList();
263 kdDebug() <<
"KFileSharePropsPlugin::applyChanges" << endl;
264 if ( m_rbShare && m_rbUnShare && m_rbSharerw )
266 bool share = m_rbShare->isChecked();
268 if (share && d->m_bAllShared)
270 if (!share && d->m_bAllUnshared)
274 KFileItemListIterator it( items );
276 for ( ; it.current() && ok; ++it ) {
277 TQString path = (*it)->url().path();
278 ok = SuSEsetShared( path, share, m_rbSharerw->isChecked() );
282 i18n(
"Sharing folder '%1' failed.").arg(path),
283 i18n(
"An error occurred while trying to share folder '%1'. "
284 "Make sure that the Perl script 'fileshareset' is set suid root.")
288 i18n(
"Unsharing folder '%1' failed.").arg(path),
289 i18n(
"An error occurred while trying to unshare folder '%1'. "
290 "Make sure that the Perl script 'fileshareset' is set suid root.")
299 KFileShare::readShareList();
303 bool KFileSharePropsPlugin::setShared(
const TQString& path,
bool shared )
305 return SuSEsetShared( path, shared,
true );
308 bool KFileSharePropsPlugin::SuSEsetShared(
const TQString& path,
bool shared,
bool readonly )
310 kdDebug() <<
"KFileSharePropsPlugin::setShared " << path <<
","
311 << shared << readonly << endl;
312 return KFileShare::SuSEsetShared( path, shared, readonly );
315 TQWidget* KFileSharePropsPlugin::page()
const
320 #include "tdefilesharedlg.moc"
virtual void applyChanges()
Apply all changes to the file.
KFileItemList items() const
void abortApplying()
To abort applying changes.
The main properties dialog class.
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.
KPropertiesDialog * properties
Pointer to the dialog.