• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
tdefilesharedlg.cpp
1/* This file is part of the KDE project
2 Copyright (c) 2001 David Faure <david@mandrakesoft.com>
3 Copyright (c) 2001 Laurent Montel <lmontel@mandrakesoft.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "tdefilesharedlg.h"
21#include <tqvbox.h>
22#include <tqlabel.h>
23#include <tqdir.h>
24#include <tqradiobutton.h>
25#include <tqbuttongroup.h>
26#include <tqlayout.h>
27#include <tqlineedit.h>
28#include <tdeprocess.h>
29#include <tdeprocio.h>
30#include <tdelocale.h>
31#include <tdeglobalsettings.h>
32#include <tdestandarddirs.h>
33#include <kdebug.h>
34#include <stdio.h>
35#include <stdlib.h>
36#include <errno.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>
43
44class KFileSharePropsPlugin::Private
45{
46public:
47 TQVBox *m_vBox;
48 TDEProcess *m_configProc;
49 bool m_bAllShared;
50 bool m_bAllUnshared;
51 bool m_bAllReadOnly;
52};
53
54KFileSharePropsPlugin::KFileSharePropsPlugin( KPropertiesDialog *_props )
55 : KPropsDlgPlugin( _props )
56{
57 d = new Private;
58 d->m_vBox = _props->addVBoxPage( i18n("&Share") );
59 d->m_configProc = 0;
60 properties->setFileSharingPage(d->m_vBox);
61 m_widget = 0L;
62 init();
63}
64
65KFileSharePropsPlugin::~KFileSharePropsPlugin()
66{
67 if (d->m_configProc)
68 d->m_configProc->detach(); // Detach to prevent that we kill the process
69 delete d;
70}
71
72bool KFileSharePropsPlugin::supports( const KFileItemList& items )
73{
74 // Do not show dialog if in advanced mode,
75 // because the advanced dialog is shown already.
76 if (KFileShare::shareMode() == KFileShare::Advanced) {
77 kdDebug() << "KFileSharePropsPlugin::supports: false because sharemode is advanced" << endl;
78 return false;
79 }
80
81 KFileItemListIterator it( items );
82 for ( ; it.current(); ++it )
83 {
84 bool isLocal = ( *it )->isLocalFile();
85 // We only support local dirs
86 if ( !(*it)->isDir() || !isLocal )
87 return false;
88 // And sharing the trash doesn't make sense
89 if ( isLocal && (*it)->url().path( 1 ) == TDEGlobalSettings::trashPath() )
90 return false;
91 }
92 return true;
93}
94
95void KFileSharePropsPlugin::init()
96{
97 // We store the main widget, so that it's possible (later) to call init()
98 // more than once, to update the page if something changed (e.g. after
99 // the user has been authorized)
100 delete m_widget;
101 m_rbShare = 0L;
102 m_rbUnShare = 0L;
103 m_rbSharerw = 0L;
104 m_widget = new TQWidget( d->m_vBox );
105 TQVBoxLayout * vbox = new TQVBoxLayout( m_widget );
106 //TQHBoxLayout * hbox = new TQHBoxLayout( vbox );
107
108 switch ( KFileShare::authorization() ) {
109 case KFileShare::Authorized:
110 {
111 // Check if all selected dirs are in $HOME
112 TQString home = TQDir::homeDirPath();
113 if ( home[home.length()-1] != '/' )
114 home += '/';
115 bool ok = true;
116 KFileItemList items = properties->items();
117 // We have 3 possibilities: all shared, all unshared (ro,rw), or mixed.
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();
124 // 0 => not shared
125 // 1 => shared read only
126 // 3 => shared writeable
127 int dirStatus = KFileShare::isDirectoryShared( path );
128 if ( !path.startsWith( home ) )
129 ok = false;
130 if ( dirStatus == 1 ) {
131 d->m_bAllUnshared = false;
132 }
133 else if ( dirStatus == 3 ) {
134 d->m_bAllUnshared = false;
135 d->m_bAllReadOnly = false;
136 }
137 else {
138 d->m_bAllReadOnly = false;
139 }
140 }
141 if ( !ok )
142 {
143 vbox->addWidget( new TQLabel( i18n( "Only folders in your home folder can be shared."),
144 m_widget ), 0 );
145 }
146 else
147 {
148 // Everything ok, show the share/unshare GUI
149 vbox->setSpacing( KDialog::spacingHint() );
150 vbox->setMargin( KDialog::marginHint() );
151
152 TQButtonGroup *rbGroup = new TQButtonGroup( m_widget );
153 rbGroup->hide();
154 m_rbUnShare = new TQRadioButton( i18n("Not shared"), m_widget );
155 connect( m_rbUnShare, TQ_SIGNAL( toggled(bool) ), TQ_SIGNAL( changed() ) );
156 vbox->addWidget( m_rbUnShare, 0 );
157 rbGroup->insert( m_rbUnShare );
158
159 m_rbShare = new TQRadioButton( i18n("Shared - read only for others"), m_widget );
160 connect( m_rbShare, TQ_SIGNAL( toggled(bool) ), TQ_SIGNAL( changed() ) );
161 vbox->addWidget( m_rbShare, 0 );
162 rbGroup->insert( m_rbShare );
163
164 m_rbSharerw = new TQRadioButton( i18n("Shared - writeable for others"), m_widget );
165 connect( m_rbSharerw, TQ_SIGNAL( toggled(bool) ), TQ_SIGNAL( changed() ) );
166 vbox->addWidget( m_rbSharerw, 0 );
167 rbGroup->insert( m_rbSharerw );
168
169 //TQLabel *testlabel1 = new TQLabel(i18n("Enter Samba Share Name here"),m_widget);
170 //m_leSmbShareName = new TQLineEdit(m_widget);
171 //m_leSmbShareName->setMaxLength(12);
172
173 //hbox->addWidget( testlabel1, 0 );
174 //hbox->addWidget( m_leSmbShareName );
175 //vbox->addLayout( hbox );
176
177 // Activate depending on status
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);
184
185 // Some help text
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 );
189
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, TQ_SIGNAL( clicked() ), TQ_SLOT( slotConfigureFileSharing() ) );
197 vbox->addWidget( m_pbConfig, 0, TQt::AlignHCenter );
198
199 vbox->addStretch( 10 );
200
201 if( !KFileShare::sambaActive() && !KFileShare::nfsActive())
202 m_widget->setEnabled( false );
203 }
204 }
205 break;
206 case KFileShare::ErrorNotFound:
207 vbox->addWidget( new TQLabel( i18n("Error running 'filesharelist'. Check if installed and in $PATH or /usr/sbin."),
208 m_widget ), 0 );
209 break;
210 case KFileShare::UserNotAllowed:
211 {
212 vbox->setSpacing( 10 );
213 if (KFileShare::sharingEnabled()) {
214 vbox->addWidget( new TQLabel( i18n("You need to be authorized to share folders."),
215 m_widget ), 0 );
216 } else {
217 vbox->addWidget( new TQLabel( i18n("File sharing is disabled."),
218 m_widget ), 0 );
219 }
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, TQ_SIGNAL( clicked() ), TQ_SLOT( slotConfigureFileSharing() ) );
224 hBox->addWidget( m_pbConfig, 0, TQt::AlignHCenter );
225 vbox->addStretch( 10 ); // align items on top
226 break;
227 }
228 case KFileShare::NotInitialized:
229 kdWarning() << "KFileShare Authorization still NotInitialized after calling authorization() - impossible" << endl;
230 break;
231 }
232 m_widget->show(); // In case the dialog was shown already.
233}
234
235void KFileSharePropsPlugin::slotConfigureFileSharing()
236{
237 if (d->m_configProc) return;
238
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 ))
242 {
243 delete d->m_configProc;
244 d->m_configProc = 0;
245 return;
246 }
247 connect(d->m_configProc, TQ_SIGNAL(processExited(TDEProcess *)),
248 this, TQ_SLOT(slotConfigureFileSharingDone()));
249 m_pbConfig->setEnabled(false);
250}
251
252void KFileSharePropsPlugin::slotConfigureFileSharingDone()
253{
254 delete d->m_configProc;
255 d->m_configProc = 0;
256 KFileShare::readConfig();
257 KFileShare::readShareList();
258 init();
259}
260
261void KFileSharePropsPlugin::applyChanges()
262{
263 kdDebug() << "KFileSharePropsPlugin::applyChanges" << endl;
264 if ( m_rbShare && m_rbUnShare && m_rbSharerw )
265 {
266 bool share = m_rbShare->isChecked();
267
268 if (share && d->m_bAllShared)
269 return; // Nothing to do
270 if (!share && d->m_bAllUnshared)
271 return; // Nothing to do
272
273 KFileItemList items = properties->items();
274 KFileItemListIterator it( items );
275 bool ok = true;
276 for ( ; it.current() && ok; ++it ) {
277 TQString path = (*it)->url().path();
278 ok = SuSEsetShared( path, share, m_rbSharerw->isChecked() );
279 if (!ok) {
280 if (share)
281 KMessageBox::detailedError(properties,
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.")
285 .arg(path));
286 else
287 KMessageBox::error(properties,
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.")
291 .arg(path));
292
293 properties->abortApplying();
294 break;
295 }
296 }
297
298 // Get the change back into our cached info
299 KFileShare::readShareList();
300 }
301}
302
303bool KFileSharePropsPlugin::setShared( const TQString& path, bool shared )
304{
305 return SuSEsetShared( path, shared, true );
306}
307
308bool KFileSharePropsPlugin::SuSEsetShared( const TQString& path, bool shared, bool readonly )
309{
310 kdDebug() << "KFileSharePropsPlugin::setShared " << path << ","
311 << shared << readonly << endl;
312 return KFileShare::SuSEsetShared( path, shared, readonly );
313}
314
315TQWidget* KFileSharePropsPlugin::page() const
316{
317 return d->m_vBox;
318}
319
320#include "tdefilesharedlg.moc"
321
322//TODO: do we need to monitor /etc/security/fileshare.conf ?
323// if the user is added to the 'fileshare' group, we wouldn't be notified
324// Of course the config module can notify us.
325// TODO: listen to such notifications ;)
KFileSharePropsPlugin::applyChanges
virtual void applyChanges()
Apply all changes to the file.
Definition: tdefilesharedlg.cpp:261
KPropertiesDialog
The main properties dialog class.
Definition: kpropertiesdialog.h:71
KPropertiesDialog::items
KFileItemList items() const
Definition: kpropertiesdialog.h:267
KPropertiesDialog::abortApplying
void abortApplying()
To abort applying changes.
Definition: kpropertiesdialog.cpp:588
KPropertiesDialog::setFileSharingPage
void setFileSharingPage(TQWidget *page)
Sets the file sharing page.
Definition: kpropertiesdialog.cpp:344
KPropsDlgPlugin
A Plugin in the Properties dialog This is an abstract class.
Definition: kpropertiesdialog.h:438
KPropsDlgPlugin::changed
void changed()
Emit this signal when the user changed anything in the plugin's tabs.
KPropsDlgPlugin::properties
KPropertiesDialog * properties
Pointer to the dialog.
Definition: kpropertiesdialog.h:480

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.4
This website is maintained by Timothy Pearson.