1
/***************************************************************************
2
smb4kcustomoptionsmanager_p - Private helper classes for
3
Smb4KCustomOptionsManager class
6
copyright : (C) 2011 by Alexander Reinholdt
7
email : alexander.reinholdt@kdemail.net
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, 51 Franklin Street, Suite 500, Boston, *
24
* MA 02110-1335, USA *
25
***************************************************************************/
28
#include <QVBoxLayout>
29
#include <QHBoxLayout>
31
#include <QCoreApplication>
35
#include <kstandardguiitem.h>
38
// application specific includes
39
#include <smb4kcustomoptionsmanager_p.h>
40
#include <smb4ksettings.h>
43
Smb4KCustomOptionsDialog::Smb4KCustomOptionsDialog( Smb4KCustomOptions *options, QWidget *parent )
44
: KDialog( parent ), m_options( options )
46
setCaption( i18n( "Custom Options" ) );
47
setButtons( User1|Ok|Cancel );
48
setDefaultButton( Ok );
49
setButtonGuiItem( User1, KStandardGuiItem::defaults() );
53
connect( this, SIGNAL( user1Clicked() ), SLOT( slotSetDefaultValues() ) );
54
connect( this, SIGNAL( okClicked() ), SLOT( slotOKClicked() ) );
56
KConfigGroup group( Smb4KSettings::self()->config(), "CustomOptionsDialog" );
57
restoreDialogSize( group );
61
Smb4KCustomOptionsDialog::~Smb4KCustomOptionsDialog()
66
void Smb4KCustomOptionsDialog::setupView()
68
QWidget *main_widget = new QWidget( this );
69
setMainWidget( main_widget );
71
QVBoxLayout *layout = new QVBoxLayout( main_widget );
72
layout->setSpacing( 5 );
73
layout->setMargin( 0 );
75
QWidget *description = new QWidget( main_widget );
77
QHBoxLayout *desc_layout = new QHBoxLayout( description );
78
desc_layout->setSpacing( 5 );
79
desc_layout->setMargin( 0 );
81
QLabel *pixmap = new QLabel( description );
82
QPixmap mount_pix = KIcon( "preferences-system-network" ).pixmap( KIconLoader::SizeHuge );
83
pixmap->setPixmap( mount_pix );
84
pixmap->setAlignment( Qt::AlignBottom );
88
switch ( m_options->type() )
90
case Smb4KCustomOptions::Host:
92
label = new QLabel( i18n( "<p>Define custom options for host <b>%1</b> and all the shares it provides.</p>",
93
m_options->host()->hostName() ), description );
96
case Smb4KCustomOptions::Share:
98
label = new QLabel( i18n( "<p>Define custom options for share <b>%1</b> at host <b>%2</b>.</p>",
99
m_options->share()->shareName(), m_options->share()->hostName() ),
105
label = new QLabel();
110
label->setWordWrap( true );
111
label->setAlignment( Qt::AlignBottom );
113
desc_layout->addWidget( pixmap, 0 );
114
desc_layout->addWidget( label, Qt::AlignBottom );
116
QWidget *editors = new QWidget( main_widget );
118
QGridLayout *editors_layout = new QGridLayout( editors );
119
editors_layout->setSpacing( 5 );
120
editors_layout->setMargin( 0 );
122
QLabel *unc_label = new QLabel( i18n( "UNC Address:" ), editors );
123
KLineEdit *unc = NULL;
125
switch ( m_options->type() )
127
case Smb4KCustomOptions::Host:
129
unc = new KLineEdit( m_options->host()->unc(), editors );
132
case Smb4KCustomOptions::Share:
134
unc = new KLineEdit( m_options->share()->unc(), editors );
142
unc->setReadOnly( true );
144
QLabel *smb_label = new QLabel( i18n( "SMB Port:" ), editors );
145
m_smb_port = new KIntNumInput( (m_options->smbPort() != Smb4KSettings::remoteSMBPort() ?
146
m_options->smbPort() : Smb4KSettings::remoteSMBPort()), editors );
147
m_smb_port->setRange( Smb4KSettings::self()->remoteSMBPortItem()->minValue().toInt(),
148
Smb4KSettings::self()->remoteSMBPortItem()->maxValue().toInt() );
149
m_smb_port->setSliderEnabled( true );
152
QLabel *fs_label = new QLabel( i18n( "Filesystem Port:" ), editors );
153
m_fs_port = new KIntNumInput( (m_options->fileSystemPort() != Smb4KSettings::remoteFileSystemPort() ?
154
m_options->fileSystemPort() : Smb4KSettings::remoteFileSystemPort()), editors );
155
m_fs_port->setRange( Smb4KSettings::self()->remoteFileSystemPortItem()->minValue().toInt(),
156
Smb4KSettings::self()->remoteFileSystemPortItem()->maxValue().toInt() );
157
m_fs_port->setSliderEnabled( true );
159
QLabel *rw_label = new QLabel( i18n( "Write Access:" ), editors );
160
m_write_access = new KComboBox( editors );
161
m_write_access->insertItem( 0, Smb4KSettings::self()->writeAccessItem()->choices()
162
.value( Smb4KSettings::EnumWriteAccess::ReadWrite ).label,
163
QVariant::fromValue<int>( Smb4KCustomOptions::ReadWrite ) );
164
m_write_access->insertItem( 1, Smb4KSettings::self()->writeAccessItem()->choices()
165
.value( Smb4KSettings::EnumWriteAccess::ReadOnly ).label,
166
QVariant::fromValue<int>( Smb4KCustomOptions::ReadOnly ) );
168
if ( m_options->writeAccess() == Smb4KCustomOptions::UndefinedWriteAccess )
170
switch ( Smb4KSettings::writeAccess() )
172
case Smb4KSettings::EnumWriteAccess::ReadWrite:
174
m_write_access->setCurrentIndex( 0 );
177
case Smb4KSettings::EnumWriteAccess::ReadOnly:
179
m_write_access->setCurrentIndex( 1 );
190
switch ( m_options->writeAccess() )
192
case Smb4KCustomOptions::ReadWrite:
194
m_write_access->setCurrentIndex( 0 );
197
case Smb4KCustomOptions::ReadOnly:
199
m_write_access->setCurrentIndex( 1 );
210
QLabel *protocol_label = new QLabel( i18n( "Protocol Hint:" ), editors );
211
m_protocol_hint = new KComboBox( editors );
212
m_protocol_hint->insertItem( 0, Smb4KSettings::self()->protocolHintItem()->choices()
213
.value( Smb4KSettings::EnumProtocolHint::Automatic ).label,
214
QVariant::fromValue<int>( Smb4KCustomOptions::Automatic ) );
215
m_protocol_hint->insertItem( 1, Smb4KSettings::self()->protocolHintItem()->choices()
216
.value( Smb4KSettings::EnumProtocolHint::RPC ).label,
217
QVariant::fromValue<int>( Smb4KCustomOptions::RPC ) );
218
m_protocol_hint->insertItem( 2, Smb4KSettings::self()->protocolHintItem()->choices()
219
.value( Smb4KSettings::EnumProtocolHint::RAP ).label,
220
QVariant::fromValue<int>( Smb4KCustomOptions::RAP ) );
221
m_protocol_hint->insertItem( 3, Smb4KSettings::self()->protocolHintItem()->choices()
222
.value( Smb4KSettings::EnumProtocolHint::ADS ).label,
223
QVariant::fromValue<int>( Smb4KCustomOptions::ADS ) );
225
if ( m_options->protocolHint() == Smb4KCustomOptions::UndefinedProtocolHint )
227
switch ( Smb4KSettings::protocolHint() )
229
case Smb4KSettings::EnumProtocolHint::Automatic:
231
m_protocol_hint->setCurrentIndex( 0 );
234
case Smb4KSettings::EnumProtocolHint::RPC:
236
m_protocol_hint->setCurrentIndex( 1 );
239
case Smb4KSettings::EnumProtocolHint::RAP:
241
m_protocol_hint->setCurrentIndex( 2 );
244
case Smb4KSettings::EnumProtocolHint::ADS:
246
m_protocol_hint->setCurrentIndex( 3 );
257
switch ( m_options->protocolHint() )
259
case Smb4KCustomOptions::Automatic:
261
m_protocol_hint->setCurrentIndex( 0 );
264
case Smb4KCustomOptions::RPC:
266
m_protocol_hint->setCurrentIndex( 1 );
269
case Smb4KCustomOptions::RAP:
271
m_protocol_hint->setCurrentIndex( 2 );
274
case Smb4KCustomOptions::ADS:
276
m_protocol_hint->setCurrentIndex( 3 );
286
QLabel *uid_label = new QLabel( i18n( "User ID:" ), editors );
287
m_user_id = new KComboBox( editors );
289
for ( int i = 0; i < KUser::allUsers().size(); ++i )
291
KUser user = KUser::allUsers().at( i );
292
m_user_id->insertItem( i, QString( "%1 (%2)" ).arg( user.loginName() ).arg( user.uid() ),
293
QVariant::fromValue<K_UID>( user.uid() ) );
295
if ( m_options->uid() == user.uid() )
297
m_user_id->setCurrentIndex( i );
305
QLabel *gid_label = new QLabel( i18n( "Group ID:" ), editors );
306
m_group_id = new KComboBox( editors );
308
for ( int i = 0; i < KUserGroup::allGroups().size(); ++i )
310
KUserGroup group = KUserGroup::allGroups().at( i );
311
m_group_id->insertItem( i, QString( "%1 (%2)" ).arg( group.name() ).arg( group.gid() ),
312
QVariant::fromValue<K_UID>( group.gid() ) );
314
if ( m_options->gid() == group.gid() )
316
m_group_id->setCurrentIndex( i );
324
m_kerberos = new QCheckBox( Smb4KSettings::self()->useKerberosItem()->label(), editors );
326
if ( m_options->useKerberos() == Smb4KCustomOptions::UndefinedKerberos )
328
m_kerberos->setChecked( Smb4KSettings::useKerberos() );
332
switch ( m_options->useKerberos() )
334
case Smb4KCustomOptions::UseKerberos:
336
m_kerberos->setChecked( true );
339
case Smb4KCustomOptions::NoKerberos:
341
m_kerberos->setChecked( false );
351
editors_layout->addWidget( unc_label, 0, 0, 0 );
352
editors_layout->addWidget( unc, 0, 1, 0 );
353
editors_layout->addWidget( smb_label, 1, 0, 0 );
354
editors_layout->addWidget( m_smb_port, 1, 1, 0 );
356
editors_layout->addWidget( fs_label, 2, 0, 0 );
357
editors_layout->addWidget( m_fs_port, 2, 1, 0 );
358
editors_layout->addWidget( rw_label, 3, 0, 0 );
359
editors_layout->addWidget( m_write_access, 3, 1, 0 );
360
editors_layout->addWidget( protocol_label, 4, 0, 0 );
361
editors_layout->addWidget( m_protocol_hint, 4, 1, 0 );
362
editors_layout->addWidget( uid_label, 5, 0, 0 );
363
editors_layout->addWidget( m_user_id, 5, 1, 0 );
364
editors_layout->addWidget( gid_label, 6, 0, 0 );
365
editors_layout->addWidget( m_group_id, 6, 1, 0 );
366
editors_layout->addWidget( m_kerberos, 7, 0, 1, 2, 0 );
368
editors_layout->addWidget( protocol_label, 2, 0, 0 );
369
editors_layout->addWidget( m_protocol_hint, 2, 1, 0 );
370
editors_layout->addWidget( uid_label, 3, 0, 0 );
371
editors_layout->addWidget( m_user_id, 3, 1, 0 );
372
editors_layout->addWidget( gid_label, 4, 0, 0 );
373
editors_layout->addWidget( m_group_id, 4, 1, 0 );
374
editors_layout->addWidget( m_kerberos, 5, 0, 1, 2, 0 );
377
layout->addWidget( description );
378
layout->addWidget( editors );
380
connect( m_smb_port, SIGNAL( valueChanged( int ) ), SLOT( slotCheckValues() ) );
382
connect( m_fs_port, SIGNAL( valueChanged(int) ), SLOT( slotCheckValues() ) );
383
connect( m_write_access, SIGNAL( currentIndexChanged( int ) ), SLOT( slotCheckValues() ) );
385
connect( m_protocol_hint, SIGNAL( currentIndexChanged( int ) ), SLOT( slotCheckValues() ) );
386
connect( m_user_id, SIGNAL( currentIndexChanged( int ) ), SLOT( slotCheckValues() ) );
387
connect( m_group_id, SIGNAL( currentIndexChanged( int ) ), SLOT( slotCheckValues() ) );
388
connect( m_kerberos, SIGNAL( toggled( bool ) ), SLOT( slotCheckValues() ) );
390
enableButton( User1, !defaultValues() );
394
bool Smb4KCustomOptionsDialog::defaultValues()
396
if ( m_smb_port->value() != Smb4KSettings::remoteSMBPort() )
407
if ( m_fs_port->value() != Smb4KSettings::remoteFileSystemPort() )
416
if ( QString::compare( m_write_access->currentText(),
417
Smb4KSettings::self()->writeAccessItem()->choices().value( Smb4KSettings::self()->writeAccess() ).label,
418
Qt::CaseInsensitive ) != 0 )
428
if ( QString::compare( m_protocol_hint->currentText(),
429
Smb4KSettings::self()->protocolHintItem()->choices().value( Smb4KSettings::self()->protocolHint() ).label,
430
Qt::CaseInsensitive ) != 0 )
439
K_UID uid = (K_UID)m_user_id->itemData( m_user_id->currentIndex() ).toInt();
441
if ( uid != (K_UID)Smb4KSettings::userID().toInt() )
450
K_GID gid = (K_GID)m_group_id->itemData( m_group_id->currentIndex() ).toInt();
452
if ( gid != (K_GID)Smb4KSettings::groupID().toInt() )
461
if ( m_kerberos->isChecked() != Smb4KSettings::useKerberos() )
474
void Smb4KCustomOptionsDialog::slotSetDefaultValues()
476
m_smb_port->setValue( Smb4KSettings::remoteSMBPort() );
478
m_fs_port->setValue( Smb4KSettings::remoteFileSystemPort() );
480
switch ( Smb4KSettings::writeAccess() )
482
case Smb4KSettings::EnumWriteAccess::ReadWrite:
484
m_write_access->setCurrentIndex( 0 );
487
case Smb4KSettings::EnumWriteAccess::ReadOnly:
489
m_write_access->setCurrentIndex( 1 );
499
switch ( Smb4KSettings::protocolHint() )
501
case Smb4KSettings::EnumProtocolHint::Automatic:
503
m_protocol_hint->setCurrentIndex( 0 );
506
case Smb4KSettings::EnumProtocolHint::RPC:
508
m_protocol_hint->setCurrentIndex( 1 );
511
case Smb4KSettings::EnumProtocolHint::RAP:
513
m_protocol_hint->setCurrentIndex( 2 );
516
case Smb4KSettings::EnumProtocolHint::ADS:
518
m_protocol_hint->setCurrentIndex( 3 );
527
for ( int i = 0; i < m_user_id->count(); ++i )
529
if ( m_user_id->itemData( i ).toInt() == Smb4KSettings::userID().toInt() )
531
m_user_id->setCurrentIndex( i );
540
for ( int i = 0; i < m_group_id->count(); ++i )
542
if ( m_group_id->itemData( i ).toInt() == Smb4KSettings::groupID().toInt() )
544
m_group_id->setCurrentIndex( i );
553
m_kerberos->setChecked( Smb4KSettings::self()->useKerberos() );
557
void Smb4KCustomOptionsDialog::slotCheckValues()
559
enableButton( User1, !defaultValues() );
563
void Smb4KCustomOptionsDialog::slotOKClicked()
565
m_options->setSMBPort( m_smb_port->value() );
567
m_options->setFileSystemPort( m_fs_port->value() );
568
m_options->setWriteAccess( (Smb4KCustomOptions::WriteAccess)m_write_access->itemData( m_write_access->currentIndex() ).toInt() );
570
m_options->setProtocolHint( (Smb4KCustomOptions::ProtocolHint)m_protocol_hint->itemData( m_protocol_hint->currentIndex() ).toInt() );
571
m_options->setUID( m_user_id->itemData( m_user_id->currentIndex() ).toInt() );
572
m_options->setGID( m_group_id->itemData( m_group_id->currentIndex() ).toInt() );
574
if ( m_kerberos->isChecked() )
576
m_options->setUseKerberos( Smb4KCustomOptions::UseKerberos );
580
m_options->setUseKerberos( Smb4KCustomOptions::NoKerberos );
583
KConfigGroup group( Smb4KSettings::self()->config(), "CustomOptionsDialog" );
584
saveDialogSize( group, KConfigGroup::Normal );
589
Smb4KCustomOptionsManagerPrivate::Smb4KCustomOptionsManagerPrivate()
594
Smb4KCustomOptionsManagerPrivate::~Smb4KCustomOptionsManagerPrivate()
598
#include "smb4kcustomoptionsmanager_p.moc"