1
/***************************************************************************
2
smb4kcustomoptionsdialog - With this dialog the user can define
3
custom Samba options for hosts or shares.
6
copyright : (C) 2006-2008 by Alexander Reinholdt
7
email : dustpuppy@users.berlios.de
8
***************************************************************************/
10
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
* This program is distributed in the hope that it will be useful, but *
17
* WITHOUT ANY WARRANTY; without even the implied warranty of *
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19
* General Public License for more details. *
21
* You should have received a copy of the GNU General Public License *
22
* along with this program; if not, write to the *
23
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
25
***************************************************************************/
28
#include <QGridLayout>
34
#include <kapplication.h>
35
#include <klineedit.h>
37
#include <kstandardguiitem.h>
40
// application specific includes
41
#include "smb4kcustomoptionsdialog.h"
42
#include <core/smb4kglobal.h>
43
#include <core/smb4kcore.h>
44
#include <core/smb4ksambaoptionsinfo.h>
45
#include <core/smb4ksambaoptionshandler.h>
46
#include <core/smb4ksettings.h>
47
#include <core/smb4khost.h>
48
#include <core/smb4kshare.h>
49
#include <core/smb4khomesshareshandler.h>
51
using namespace Smb4KGlobal;
54
// FIXME: Maybe introduce a private class here?
55
static int default_port = -1;
56
static QString default_protocol = QString();
57
static bool default_kerberos = false;
58
static QString default_uid = QString();
59
static QString default_gid = QString();
61
static bool default_readwrite = true;
64
static int port_value = -1;
65
static QString protocol_value = QString();
66
static bool kerberos_value = false;
67
static QString uid_value = QString();
68
static QString gid_value = QString();
70
static bool readwrite_value = true;
73
static bool port_changed_ok = false;
74
static bool protocol_changed_ok = false;
75
static bool kerberos_changed_ok = false;
76
static bool uid_changed_ok = false;
77
static bool gid_changed_ok = false;
79
static bool readwrite_changed_ok = false;
82
static bool port_changed_default = false;
83
static bool protocol_changed_default = false;
84
static bool kerberos_changed_default = false;
85
static bool uid_changed_default = false;
86
static bool gid_changed_default = false;
88
static bool readwrite_changed_default = false;
92
Smb4KCustomOptionsDialog::Smb4KCustomOptionsDialog( Smb4KHost *host, QWidget *parent )
93
: KDialog( parent ), m_type( Host ), m_host( host ), m_share( NULL )
95
setAttribute( Qt::WA_DeleteOnClose, true );
97
setCaption( i18n( "Custom Options" ) );
98
setButtons( User1|Ok|Cancel );
99
setDefaultButton( Ok );
100
setButtonGuiItem( User1, KStandardGuiItem::defaults() );
102
m_initialized = true;
106
setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
108
KConfigGroup group( Smb4KSettings::self()->config(), "CustomOptionsDialog" );
109
restoreDialogSize( group );
113
Smb4KCustomOptionsDialog::Smb4KCustomOptionsDialog( Smb4KShare *share, QWidget *parent )
114
: KDialog( parent ), m_type( Share ), m_host( NULL ), m_share( share )
116
setAttribute( Qt::WA_DeleteOnClose, true );
118
setCaption( i18n( "Custom Options" ) );
119
setButtons( User1|Ok|Cancel );
120
setDefaultButton( Ok );
121
setButtonGuiItem( User1, KStandardGuiItem::defaults() );
123
if ( QString::compare( m_share->name(), "homes" ) != 0 )
125
m_initialized = true;
129
// We do not use parent as parent for the "Specify User"
130
// dialog, so that the behavior is uniform.
135
p = kapp->activeWindow();
138
(void) Smb4KHomesSharesHandler::self()->specifyUser( m_share, p );
139
m_initialized = (QString::compare( m_share->name(), "homes" ) != 0);
144
setMinimumSize( (sizeHint().width() > 350 ? sizeHint().width() : 350), sizeHint().height() );
146
setInitialSize( QSize( minimumWidth(), minimumHeight() ) );
148
KConfigGroup group( Smb4KSettings::self()->config(), "CustomOptionsDialog" );
149
restoreDialogSize( group );
153
Smb4KCustomOptionsDialog::~Smb4KCustomOptionsDialog()
158
void Smb4KCustomOptionsDialog::setupDialog()
160
// The Smb4KSambaOptionsInfo object:
161
Smb4KSambaOptionsInfo *info = NULL;
163
// We need this later to decide if the "Default"
164
// button needs to be enabled:
165
bool enable_default_button = false;
167
// These are the input widgets we need below:
170
m_proto_input = NULL;
177
// Set up the widget:
178
QWidget *main_widget = new QWidget( this );
179
setMainWidget( main_widget );
181
QGridLayout *layout = new QGridLayout( main_widget );
182
layout->setSpacing( 5 );
183
layout->setMargin( 0 );
185
QLabel *location_label = new QLabel( m_type == Host ? i18n( "Host:" ) : i18n( "Share:" ), main_widget );
186
KLineEdit *location = new KLineEdit( m_type == Host ?
188
"//"+m_share->host()+"/"+m_share->name(),
190
location->setReadOnly( true );
192
// The widgets will be put into the layout below.
194
// Here comes the item-dependent stuff:
199
QLabel *port_label = new QLabel( Smb4KSettings::self()->remoteSMBPortItem()->label(), main_widget );
200
m_port_input = new KIntNumInput( -1, main_widget );
201
m_port_input->setMinimumWidth( 200 );
202
m_port_input->setMinimum( Smb4KSettings::self()->remoteSMBPortItem()->minValue().toInt() );
203
m_port_input->setMaximum( Smb4KSettings::self()->remoteSMBPortItem()->maxValue().toInt() );
205
QLabel *protocol_label = new QLabel( i18n( "Protocol:" ), main_widget );
206
m_proto_input = new KComboBox( false, main_widget );
207
m_proto_input->setMinimumWidth( 200 );
209
QStringList protocol_items;
210
protocol_items.append( i18n( "automatic" ) );
211
protocol_items.append( "RPC" );
212
protocol_items.append( "RAP" );
213
protocol_items.append( "ADS" );
215
m_proto_input->insertItems( 0, protocol_items );
217
m_kerberos = new QCheckBox( i18n( "Try to authenticate with Kerberos (Active Directory)" ), main_widget );
219
layout->addWidget( location_label, 0, 0, 0 );
220
layout->addWidget( location, 0, 1, 0 );
221
layout->addWidget( port_label, 1, 0, 0 );
222
layout->addWidget( m_port_input, 1, 1, 0 );
223
layout->addWidget( protocol_label, 2, 0, 0 );
224
layout->addWidget( m_proto_input, 2, 1, 0 );
225
layout->addWidget( m_kerberos, 3, 0, 1, 2, 0 );
227
info = Smb4KSambaOptionsHandler::self()->findItem( m_host->name() );
229
// Get the default values from the config file:
230
default_port = Smb4KSettings::remoteSMBPort();
231
default_kerberos = Smb4KSettings::useKerberos();
233
switch ( Smb4KSettings::protocolHint() )
235
case Smb4KSettings::EnumProtocolHint::Automatic:
237
// In this case the user leaves it to the net
238
// command to determine the right protocol.
239
default_protocol = "auto";
243
case Smb4KSettings::EnumProtocolHint::RPC:
245
default_protocol = "rpc";
249
case Smb4KSettings::EnumProtocolHint::RAP:
251
default_protocol = "rap";
255
case Smb4KSettings::EnumProtocolHint::ADS:
257
default_protocol = "ads";
263
default_protocol = QString();
269
// Define the values that have to be put into the widgets:
270
port_value = (info && info->port() != -1) ?
276
switch ( info->protocol() )
278
case Smb4KSambaOptionsInfo::Automatic:
280
protocol_value = "auto";
284
case Smb4KSambaOptionsInfo::RPC:
286
protocol_value = "rpc";
290
case Smb4KSambaOptionsInfo::RAP:
292
protocol_value = "rap";
296
case Smb4KSambaOptionsInfo::ADS:
298
protocol_value = "ads";
302
case Smb4KSambaOptionsInfo::UndefinedProtocol:
304
protocol_value = default_protocol;
316
protocol_value = default_protocol;
321
switch ( info->useKerberos() )
323
case Smb4KSambaOptionsInfo::UseKerberos:
325
kerberos_value = true;
329
case Smb4KSambaOptionsInfo::NoKerberos:
331
kerberos_value = false;
335
case Smb4KSambaOptionsInfo::UndefinedKerberos:
337
kerberos_value = default_kerberos;
349
kerberos_value = default_kerberos;
352
// Put the values in the widgets:
353
m_port_input->setValue( port_value );
354
m_proto_input->setCurrentItem( (QString::compare( protocol_value, "auto" ) == 0 ? i18n( "automatic" ) : protocol_value.toUpper()), false );
355
m_kerberos->setChecked( kerberos_value );
357
// Does the 'Default' button need to be enabled?
358
if ( default_port != port_value ||
359
QString::compare( default_protocol, protocol_value ) != 0 ||
360
default_kerberos != kerberos_value )
362
enable_default_button = true;
366
connect( m_port_input, SIGNAL( valueChanged( int ) ),
367
this, SLOT( slotPortChanged( int ) ) );
369
connect( m_kerberos, SIGNAL( toggled( bool ) ),
370
this, SLOT( slotKerberosToggled( bool ) ) );
372
connect( m_proto_input, SIGNAL( activated( const QString & ) ),
373
this, SLOT( slotProtocolChanged( const QString & ) ) );
380
QLabel *port_label = new QLabel( Smb4KSettings::self()->remoteFileSystemPortItem()->label(), main_widget );
381
m_port_input = new KIntNumInput( -1, main_widget );
382
m_port_input->setMinimumWidth( 200 );
383
m_port_input->setMinimum( Smb4KSettings::self()->remoteFileSystemPortItem()->minValue().toInt() );
384
m_port_input->setMaximum( Smb4KSettings::self()->remoteFileSystemPortItem()->maxValue().toInt() );
386
QLabel *permission_label = new QLabel( i18n( "Write access:" ), main_widget );
387
m_rw_input = new KComboBox( false, main_widget );
388
m_rw_input->setMinimumWidth( 200 );
390
QStringList write_access_entries;
391
write_access_entries.append( i18n( "read-write" ) );
392
write_access_entries.append( i18n( "read-only" ) );
394
m_rw_input->insertItems( 0, write_access_entries );
396
QLabel *uid_label = new QLabel( i18n( "User ID:" ), main_widget );
397
m_uid_input = new KComboBox( main_widget );
398
m_uid_input->setMinimumWidth( 200 );
400
QList<KUser> user_list = KUser::allUsers();
403
for ( int i = 0; i < user_list.size(); ++i )
405
uids.append( QString( "%1 (%2)" ).arg( user_list.at( i ).loginName() )
406
.arg( user_list.at( i ).uid() ) );
411
m_uid_input->addItems( uids );
413
QLabel *gid_label = new QLabel( i18n( "Group ID:" ), main_widget );
414
m_gid_input = new KComboBox( main_widget );
415
m_gid_input->setMinimumWidth( 200 );
417
QList<KUserGroup> group_list = KUserGroup::allGroups();
420
for ( int i = 0; i < group_list.size(); ++i )
422
gids.append( QString( "%1 (%2)" ).arg( group_list.at( i ).name() )
423
.arg( group_list.at( i ).gid() ) );
428
m_gid_input->addItems( gids );
430
layout->addWidget( location_label, 0, 0, 0 );
431
layout->addWidget( location, 0, 1, 0 );
432
layout->addWidget( port_label, 1, 0, 0 );
433
layout->addWidget( m_port_input, 1, 1, 0 );
434
layout->addWidget( uid_label, 2, 0, 0 );
435
layout->addWidget( m_uid_input, 2, 1, 0 );
436
layout->addWidget( gid_label, 3, 0, 0 );
437
layout->addWidget( m_gid_input, 3, 1, 0 );
438
layout->addWidget( permission_label, 4, 0, 0 );
439
layout->addWidget( m_rw_input, 4, 1, 0 );
441
QLabel *port_label = new QLabel( Smb4KSettings::self()->remoteSMBPortItem()->label(), main_widget );
442
m_port_input = new KIntNumInput( -1, main_widget );
443
m_port_input->setMinimumWidth( 200 );
444
m_port_input->setMinimum( Smb4KSettings::self()->remoteSMBPortItem()->minValue().toInt() );
445
m_port_input->setMaximum( Smb4KSettings::self()->remoteSMBPortItem()->maxValue().toInt() );
447
QLabel *uid_label = new QLabel( i18n( "User ID:" ), main_widget );
448
m_uid_input = new KComboBox( main_widget );
449
m_uid_input->setMinimumWidth( 200 );
451
QList<KUser> user_list = KUser::allUsers();
454
for ( int i = 0; i < user_list.size(); ++i )
456
uids.append( QString( "%1 (%2)" ).arg( user_list.at( i ).loginName() )
457
.arg( user_list.at( i ).uid() ) );
462
m_uid_input->addItems( uids );
464
QLabel *gid_label = new QLabel( i18n( "Group ID:" ), main_widget );
465
m_gid_input = new KComboBox( main_widget );
466
m_gid_input->setMinimumWidth( 200 );
468
QList<KUserGroup> group_list = KUserGroup::allGroups();
471
for ( int i = 0; i < group_list.size(); ++i )
473
gids.append( QString( "%1 (%2)" ).arg( group_list.at( i ).name() )
474
.arg( group_list.at( i ).gid() ) );
479
m_gid_input->addItems( gids );
481
layout->addWidget( location_label, 0, 0, 0 );
482
layout->addWidget( location, 0, 1, 0 );
483
layout->addWidget( port_label, 1, 0, 0 );
484
layout->addWidget( m_port_input, 1, 1, 0 );
485
layout->addWidget( uid_label, 2, 0, 0 );
486
layout->addWidget( m_uid_input, 2, 1, 0 );
487
layout->addWidget( gid_label, 3, 0, 0 );
488
layout->addWidget( m_gid_input, 3, 1, 0 );
491
info = Smb4KSambaOptionsHandler::self()->findItem( QString( "//%1/%2" ).arg( m_share->host(), m_share->name() ) );
493
// Get the default values from the config file:
495
default_port = Smb4KSettings::remoteFileSystemPort();
497
default_port = Smb4KSettings::remoteSMBPort();
499
default_uid = Smb4KSettings::userID();
500
default_gid = Smb4KSettings::groupID();
502
switch ( Smb4KSettings::writeAccess() )
504
case Smb4KSettings::EnumWriteAccess::ReadWrite:
506
default_readwrite = true;
510
case Smb4KSettings::EnumWriteAccess::ReadOnly:
512
default_readwrite = false;
523
// Define the values that have to be put into the widgets:
524
port_value = (info && info->port() != -1) ?
528
uid_value = (info && info->uidIsSet()) ?
529
QString( "%1" ).arg( info->uid() ) :
532
gid_value = (info && info->gidIsSet()) ?
533
QString( "%1" ).arg( info->gid() ) :
538
switch( info->writeAccess() )
540
case Smb4KSambaOptionsInfo::ReadWrite:
542
readwrite_value = true;
546
case Smb4KSambaOptionsInfo::ReadOnly:
548
readwrite_value = false;
552
case Smb4KSambaOptionsInfo::UndefinedWriteAccess:
554
readwrite_value = default_readwrite;
566
readwrite_value = default_readwrite;
570
// Put the values in the widgets:
571
m_port_input->setValue( port_value );
573
KUser user( (K_UID)uid_value.toInt() );
574
QString user_text = QString( "%1 (%2)" ).arg( user.loginName() ).arg( user.uid() );
575
int user_index = m_uid_input->findText( user_text );
576
m_uid_input->setCurrentIndex( user_index );
578
KUserGroup group( (K_GID)gid_value.toInt() );
579
QString group_text = QString( "%1 (%2)" ).arg( group.name() ).arg( group.gid() );
580
int group_index = m_gid_input->findText( group_text );
581
m_gid_input->setCurrentIndex( group_index );
583
m_rw_input->setCurrentItem( (readwrite_value ?
584
i18n( "read-write" ) :
585
i18n( "read-only" )),
589
// Does the 'Default' button need to be enabled?
590
if ( default_port != port_value ||
592
default_readwrite != readwrite_value ||
594
QString::compare( default_uid, uid_value ) != 0 ||
595
QString::compare( default_gid, gid_value ) != 0 )
597
enable_default_button = true;
601
connect( m_port_input, SIGNAL( valueChanged( int ) ),
602
this, SLOT( slotPortChanged( int ) ) );
604
connect( m_uid_input, SIGNAL( activated( const QString & ) ),
605
this, SLOT( slotUIDChanged( const QString & ) ) );
607
connect( m_gid_input, SIGNAL( activated( const QString & ) ),
608
this, SLOT( slotGIDChanged( const QString & ) ) );
611
connect( m_rw_input, SIGNAL( activated( const QString & ) ),
612
this, SLOT( slotWriteAccessChanged( const QString & ) ) );
619
// This should not happen...
624
// Enable the buttons:
625
enableButton( Ok, false );
626
enableButton( User1, enable_default_button );
628
// Connect the buttons:
629
connect( this, SIGNAL( okClicked() ),
630
this, SLOT( slotOKButtonClicked() ) );
632
connect( this, SIGNAL( user1Clicked() ),
633
this, SLOT( slotDefaultButtonClicked() ) );
636
/////////////////////////////////////////////////////////////////////////////
637
// SLOT IMPLEMENTATIONS
638
/////////////////////////////////////////////////////////////////////////////
640
void Smb4KCustomOptionsDialog::slotPortChanged( int val )
642
port_changed_ok = (port_value != val);
643
port_changed_default = (default_port != val);
649
enableButton( Ok, port_changed_ok ||
650
protocol_changed_ok ||
651
kerberos_changed_ok );
653
enableButton( User1, port_changed_default ||
654
protocol_changed_default ||
655
kerberos_changed_default );
661
enableButton( Ok, port_changed_ok ||
663
readwrite_changed_ok ||
668
enableButton( User1, port_changed_default ||
670
readwrite_changed_default ||
672
uid_changed_default ||
673
gid_changed_default );
685
void Smb4KCustomOptionsDialog::slotProtocolChanged( const QString &protocol )
687
protocol_changed_ok = (QString::compare( protocol_value, protocol.toLower() ) != 0);
688
protocol_changed_default = (QString::compare( default_protocol, protocol.toLower() ) != 0);
694
enableButton( Ok, port_changed_ok ||
695
protocol_changed_ok ||
696
kerberos_changed_ok );
698
enableButton( User1, port_changed_default ||
699
protocol_changed_default ||
700
kerberos_changed_default );
706
enableButton( Ok, port_changed_ok ||
708
readwrite_changed_ok ||
713
enableButton( User1, port_changed_default ||
715
readwrite_changed_default ||
717
uid_changed_default ||
718
gid_changed_default );
730
void Smb4KCustomOptionsDialog::slotKerberosToggled( bool on )
732
kerberos_changed_ok = (kerberos_value != on);
733
kerberos_changed_default = (default_kerberos != on);
739
enableButton( Ok, port_changed_ok ||
740
protocol_changed_ok ||
741
kerberos_changed_ok );
743
enableButton( User1, port_changed_default ||
744
protocol_changed_default ||
745
kerberos_changed_default );
751
enableButton( Ok, port_changed_ok ||
753
readwrite_changed_ok ||
758
enableButton( User1, port_changed_default ||
760
readwrite_changed_default ||
762
uid_changed_default ||
763
gid_changed_default );
775
void Smb4KCustomOptionsDialog::slotWriteAccessChanged( const QString &rw )
778
bool readwrite = (QString::compare( rw, i18n( "read-write" ) ) == 0);
779
readwrite_changed_ok = (readwrite_value != readwrite);
780
readwrite_changed_default = (default_readwrite != readwrite);
786
enableButton( Ok, port_changed_ok ||
787
protocol_changed_ok ||
788
kerberos_changed_ok );
790
enableButton( User1, port_changed_default ||
791
protocol_changed_default ||
792
kerberos_changed_default );
798
enableButton( Ok, port_changed_ok ||
799
readwrite_changed_ok ||
803
enableButton( User1, port_changed_default ||
804
readwrite_changed_default ||
805
uid_changed_default ||
806
gid_changed_default );
818
void Smb4KCustomOptionsDialog::slotUIDChanged( const QString &u )
820
QString uid = u.section( "(", 1, 1 ).section( ")", 0, 0 );
822
uid_changed_ok = (QString::compare( uid_value, uid ) != 0);
823
uid_changed_default = (QString::compare( default_uid, uid ) != 0);
829
enableButton( Ok, port_changed_ok ||
830
protocol_changed_ok ||
831
kerberos_changed_ok );
833
enableButton( User1, port_changed_default ||
834
protocol_changed_default ||
835
kerberos_changed_default );
841
enableButton( Ok, port_changed_ok ||
843
readwrite_changed_ok ||
848
enableButton( User1, port_changed_default ||
850
readwrite_changed_default ||
852
uid_changed_default ||
853
gid_changed_default );
865
void Smb4KCustomOptionsDialog::slotGIDChanged( const QString &g )
867
QString gid = g.section( "(", 1, 1 ).arg( ")", 0, 0 );
869
gid_changed_ok = (QString::compare( gid_value, gid ) != 0);
870
gid_changed_default = (QString::compare( default_gid, gid ) != 0);
876
enableButton( Ok, port_changed_ok ||
877
protocol_changed_ok ||
878
kerberos_changed_ok );
880
enableButton( User1, port_changed_default ||
881
protocol_changed_default ||
882
kerberos_changed_default );
888
enableButton( Ok, port_changed_ok ||
890
readwrite_changed_ok ||
895
enableButton( User1, port_changed_default ||
897
readwrite_changed_default ||
899
uid_changed_default ||
900
gid_changed_default );
912
void Smb4KCustomOptionsDialog::slotOKButtonClicked()
914
Smb4KSambaOptionsInfo *info = NULL;
920
QString item_name = m_host->name();
922
// Check if we can remove the item:
923
if ( !port_changed_default && !protocol_changed_default && !kerberos_changed_default )
925
Smb4KSambaOptionsHandler::self()->removeItem( item_name, true );
929
// First search for the item in the custom options list
930
// and create a new one only if the info could not be
932
if ( !(info = Smb4KSambaOptionsHandler::self()->findItem( item_name, true )) )
934
info = new Smb4KSambaOptionsInfo();
937
// Put in the needed information:
938
info->setUNC( item_name );
939
info->setPort( m_port_input->value() );
940
info->setWorkgroup( m_host->workgroup() );
941
info->setIP( m_host->ip() );
943
if ( QString::compare( m_proto_input->currentText(), i18n( "automatic" ), Qt::CaseInsensitive ) == 0 )
945
info->setProtocol( Smb4KSambaOptionsInfo::Automatic );
947
else if ( QString::compare( m_proto_input->currentText(), "rpc", Qt::CaseInsensitive ) == 0 )
949
info->setProtocol( Smb4KSambaOptionsInfo::RPC );
951
else if ( QString::compare( m_proto_input->currentText(), "rap", Qt::CaseInsensitive ) == 0 )
953
info->setProtocol( Smb4KSambaOptionsInfo::RAP );
955
else if ( QString::compare( m_proto_input->currentText(), "ads", Qt::CaseInsensitive ) == 0 )
957
info->setProtocol( Smb4KSambaOptionsInfo::ADS );
961
info->setProtocol( Smb4KSambaOptionsInfo::UndefinedProtocol );
964
if ( m_kerberos->isChecked() )
966
info->setUseKerberos( Smb4KSambaOptionsInfo::UseKerberos );
970
info->setUseKerberos( Smb4KSambaOptionsInfo::NoKerberos );
974
Smb4KSambaOptionsHandler::self()->addItem( info, true );
981
QString item_name = QString( "//%1/%2" ).arg( m_share->host(), m_share->name() );
984
// Check if we can remove the item:
985
if ( !port_changed_default && !readwrite_changed_default &&
986
!uid_changed_default && !gid_changed_default )
988
Smb4KSambaOptionsHandler::self()->removeItem( item_name, true );
992
// First search for the item in the custom options list
993
// and create a new one only if the info could not be
995
if ( !(info = Smb4KSambaOptionsHandler::self()->findItem( item_name, true )) )
997
info = new Smb4KSambaOptionsInfo();
1000
// Put in the needed information:
1001
info->setUNC( item_name );
1002
info->setPort( m_port_input->value() );
1003
info->setWorkgroup( m_share->workgroup() );
1004
info->setIP( m_share->hostIP() );
1006
if ( QString::compare( m_rw_input->currentText(), i18n( "read-write" ), Qt::CaseInsensitive ) == 0 )
1008
info->setWriteAccess( Smb4KSambaOptionsInfo::ReadWrite );
1010
else if ( QString::compare( m_rw_input->currentText(), i18n( "read-only" ), Qt::CaseInsensitive ) == 0 )
1012
info->setWriteAccess( Smb4KSambaOptionsInfo::ReadOnly );
1016
info->setWriteAccess( Smb4KSambaOptionsInfo::UndefinedWriteAccess );
1019
info->setUID( (uid_t)m_uid_input->currentText().section( "(", 1, 1 ).section( ")", 0, 0 ).toInt() );
1020
info->setGID( (gid_t)m_gid_input->currentText().section( "(", 1, 1 ).section( ")", 0, 0 ).toInt() );
1022
// Add the new item.
1023
Smb4KSambaOptionsHandler::self()->addItem( info, true );
1026
// Check if we can remove the item:
1027
if ( !port_changed_default && !uid_changed_default && !gid_changed_default )
1029
Smb4KSambaOptionsHandler::self()->removeItem( item_name, true );
1033
// First search for the item in the custom options list
1034
// and create a new one only if the info could not be
1036
if ( !(info = Smb4KSambaOptionsHandler::self()->findItem( item_name, true )) )
1038
info = new Smb4KSambaOptionsInfo();
1041
// Put in the needed information:
1042
info->setUNC( item_name );
1043
info->setWorkgroup( m_share->workgroup() );
1044
info->setIP( m_share->hostIP() );
1045
info->setPort( m_port_input->value() );
1047
info->setUID( (uid_t)m_uid_input->currentText().section( "(", 1, 1 ).section( ")", 0, 0 ).toInt() );
1048
info->setGID( (gid_t)m_gid_input->currentText().section( "(", 1, 1 ).section( ")", 0, 0 ).toInt() );
1050
// Add the new item.
1051
Smb4KSambaOptionsHandler::self()->addItem( info, true );
1063
KConfigGroup group( Smb4KSettings::self()->config(), "Dialogs" );
1064
saveDialogSize( group, KConfigGroup::Normal );
1068
void Smb4KCustomOptionsDialog::slotDefaultButtonClicked()
1070
// Here, we only reset the dialog and enable the OK button
1077
m_port_input->setValue( default_port );
1078
m_kerberos->setChecked( default_kerberos );
1079
QString protocol = (QString::compare( default_protocol, "auto" ) == 0 ? i18n( "automatic" ) : protocol_value.toUpper());
1080
m_proto_input->setCurrentItem( protocol, false );
1082
// Enable or disable the OK button:
1083
enableButton( Ok, default_port != port_value ||
1084
default_kerberos != kerberos_value ||
1085
QString::compare( default_protocol, protocol_value ) != 0 );
1091
m_port_input->setValue( default_port );
1093
KUser user( (K_UID)default_uid.toInt() );
1094
QString user_text = QString( "%1 (%2)" ).arg( user.loginName() ).arg( user.uid() );
1095
int user_index = m_uid_input->findText( user_text );
1096
m_uid_input->setCurrentIndex( user_index );
1098
KUserGroup group( (K_GID)default_gid.toInt() );
1099
QString group_text = QString( "%1 (%2)" ).arg( group.name() ).arg( group.gid() );
1100
int group_index = m_gid_input->findText( group_text );
1101
m_gid_input->setCurrentIndex( group_index );
1103
QString write_access = (default_readwrite ? i18n( "read-write" ) : i18n( "read-only" ));
1104
m_rw_input->setCurrentItem( write_access, false );
1107
// Enable or disable the OK button:
1108
enableButton( Ok, default_port != port_value ||
1110
default_readwrite != readwrite_value ||
1112
QString::compare( default_uid, uid_value ) != 0 ||
1113
QString::compare( default_gid, gid_value ) != 0 );
1123
// We just put the default values into the dialog.
1124
// Disable the 'Default' button:
1125
enableButton( User1, false );
1128
#include "smb4kcustomoptionsdialog.moc"