~ubuntu-branches/ubuntu/utopic/smb4k/utopic-proposed

« back to all changes in this revision

Viewing changes to smb4k/dialogs/smb4kcustomoptionsdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20120519185434-kpqpdrg5i47zm7tl
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    smb4kcustomoptionsdialog  -  With this dialog the user can define
3
 
    custom Samba options for hosts or shares.
4
 
                             -------------------
5
 
    begin                : So Jun 25 2006
6
 
    copyright            : (C) 2006-2008 by Alexander Reinholdt
7
 
    email                : dustpuppy@users.berlios.de
8
 
 ***************************************************************************/
9
 
 
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.                                   *
15
 
 *                                                                         *
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.                              *
20
 
 *                                                                         *
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,   *
24
 
 *   MA  02111-1307 USA                                                    *
25
 
 ***************************************************************************/
26
 
 
27
 
// Qt includes
28
 
#include <QGridLayout>
29
 
#include <QLabel>
30
 
#include <QList>
31
 
 
32
 
// KDE includes
33
 
#include <klocale.h>
34
 
#include <kapplication.h>
35
 
#include <klineedit.h>
36
 
#include <kdebug.h>
37
 
#include <kstandardguiitem.h>
38
 
#include <kuser.h>
39
 
 
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>
50
 
 
51
 
using namespace Smb4KGlobal;
52
 
 
53
 
 
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();
60
 
#ifndef __FreeBSD__
61
 
static bool default_readwrite = true;
62
 
#endif
63
 
 
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();
69
 
#ifndef __FreeBSD__
70
 
static bool readwrite_value = true;
71
 
#endif
72
 
 
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;
78
 
#ifndef __FreeBSD__
79
 
static bool readwrite_changed_ok = false;
80
 
#endif
81
 
 
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;
87
 
#ifndef __FreeBSD__
88
 
static bool readwrite_changed_default = false;
89
 
#endif
90
 
 
91
 
 
92
 
Smb4KCustomOptionsDialog::Smb4KCustomOptionsDialog( Smb4KHost *host, QWidget *parent )
93
 
: KDialog( parent ), m_type( Host ), m_host( host ), m_share( NULL )
94
 
{
95
 
  setAttribute( Qt::WA_DeleteOnClose, true );
96
 
 
97
 
  setCaption( i18n( "Custom Options" ) );
98
 
  setButtons( User1|Ok|Cancel );
99
 
  setDefaultButton( Ok );
100
 
  setButtonGuiItem( User1, KStandardGuiItem::defaults() );
101
 
 
102
 
  m_initialized = true;
103
 
 
104
 
  setupDialog();
105
 
 
106
 
  setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
107
 
 
108
 
  KConfigGroup group( Smb4KSettings::self()->config(), "CustomOptionsDialog" );
109
 
  restoreDialogSize( group );
110
 
}
111
 
 
112
 
 
113
 
Smb4KCustomOptionsDialog::Smb4KCustomOptionsDialog( Smb4KShare *share, QWidget *parent )
114
 
: KDialog( parent ), m_type( Share ), m_host( NULL ), m_share( share )
115
 
{
116
 
  setAttribute( Qt::WA_DeleteOnClose, true );
117
 
 
118
 
  setCaption( i18n( "Custom Options" ) );
119
 
  setButtons( User1|Ok|Cancel );
120
 
  setDefaultButton( Ok );
121
 
  setButtonGuiItem( User1, KStandardGuiItem::defaults() );
122
 
 
123
 
  if ( QString::compare( m_share->name(), "homes" ) != 0 )
124
 
  {
125
 
    m_initialized = true;
126
 
  }
127
 
  else
128
 
  {
129
 
    // We do not use parent as parent for the "Specify User"
130
 
    // dialog, so that the behavior is uniform.
131
 
    QWidget *p = 0;
132
 
 
133
 
    if ( kapp )
134
 
    {
135
 
      p = kapp->activeWindow();
136
 
    }
137
 
 
138
 
    (void) Smb4KHomesSharesHandler::self()->specifyUser( m_share, p );
139
 
    m_initialized = (QString::compare( m_share->name(), "homes" ) != 0);
140
 
  }
141
 
 
142
 
  setupDialog();
143
 
 
144
 
  setMinimumSize( (sizeHint().width() > 350 ? sizeHint().width() : 350), sizeHint().height() );
145
 
 
146
 
  setInitialSize( QSize( minimumWidth(), minimumHeight() ) );
147
 
 
148
 
  KConfigGroup group( Smb4KSettings::self()->config(), "CustomOptionsDialog" );
149
 
  restoreDialogSize( group );
150
 
}
151
 
 
152
 
 
153
 
Smb4KCustomOptionsDialog::~Smb4KCustomOptionsDialog()
154
 
{
155
 
}
156
 
 
157
 
 
158
 
void Smb4KCustomOptionsDialog::setupDialog()
159
 
{
160
 
  // The Smb4KSambaOptionsInfo object:
161
 
  Smb4KSambaOptionsInfo *info = NULL;
162
 
 
163
 
  // We need this later to decide if the "Default"
164
 
  // button needs to be enabled:
165
 
  bool enable_default_button = false;
166
 
 
167
 
  // These are the input widgets we need below:
168
 
  m_port_input = NULL;
169
 
  m_kerberos = NULL;
170
 
  m_proto_input = NULL;
171
 
  m_uid_input = NULL;
172
 
  m_gid_input = NULL;
173
 
#ifndef __FreeBSD__
174
 
  m_rw_input = NULL;
175
 
#endif
176
 
 
177
 
  // Set up the widget:
178
 
  QWidget *main_widget = new QWidget( this );
179
 
  setMainWidget( main_widget );
180
 
 
181
 
  QGridLayout *layout = new QGridLayout( main_widget );
182
 
  layout->setSpacing( 5 );
183
 
  layout->setMargin( 0 );
184
 
 
185
 
  QLabel *location_label = new QLabel( m_type == Host ? i18n( "Host:" ) : i18n( "Share:" ), main_widget );
186
 
  KLineEdit *location    = new KLineEdit( m_type == Host ?
187
 
                           m_host->name() :
188
 
                           "//"+m_share->host()+"/"+m_share->name(),
189
 
                           main_widget );
190
 
  location->setReadOnly( true );
191
 
 
192
 
  // The widgets will be put into the layout below.
193
 
 
194
 
  // Here comes the item-dependent stuff:
195
 
  switch ( m_type )
196
 
  {
197
 
    case Host:
198
 
    {
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() );
204
 
 
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 );
208
 
 
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" );
214
 
 
215
 
      m_proto_input->insertItems( 0, protocol_items );
216
 
 
217
 
      m_kerberos = new QCheckBox( i18n( "Try to authenticate with Kerberos (Active Directory)" ), main_widget );
218
 
 
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 );
226
 
 
227
 
      info = Smb4KSambaOptionsHandler::self()->findItem( m_host->name() );
228
 
 
229
 
      // Get the default values from the config file:
230
 
      default_port = Smb4KSettings::remoteSMBPort();
231
 
      default_kerberos = Smb4KSettings::useKerberos();
232
 
 
233
 
      switch ( Smb4KSettings::protocolHint() )
234
 
      {
235
 
        case Smb4KSettings::EnumProtocolHint::Automatic:
236
 
        {
237
 
          // In this case the user leaves it to the net
238
 
          // command to determine the right protocol.
239
 
          default_protocol = "auto";
240
 
 
241
 
          break;
242
 
        }
243
 
        case Smb4KSettings::EnumProtocolHint::RPC:
244
 
        {
245
 
          default_protocol = "rpc";
246
 
 
247
 
          break;
248
 
        }
249
 
        case Smb4KSettings::EnumProtocolHint::RAP:
250
 
        {
251
 
          default_protocol = "rap";
252
 
 
253
 
          break;
254
 
        }
255
 
        case Smb4KSettings::EnumProtocolHint::ADS:
256
 
        {
257
 
          default_protocol = "ads";
258
 
 
259
 
          break;
260
 
        }
261
 
        default:
262
 
        {
263
 
          default_protocol = QString();
264
 
 
265
 
          break;
266
 
        }
267
 
      }
268
 
 
269
 
      // Define the values that have to be put into the widgets:
270
 
      port_value =     (info && info->port() != -1) ?
271
 
                       info->port() :
272
 
                       default_port;
273
 
 
274
 
      if ( info )
275
 
      {
276
 
        switch ( info->protocol() )
277
 
        {
278
 
          case Smb4KSambaOptionsInfo::Automatic:
279
 
          {
280
 
            protocol_value = "auto";
281
 
 
282
 
            break;
283
 
          }
284
 
          case Smb4KSambaOptionsInfo::RPC:
285
 
          {
286
 
            protocol_value = "rpc";
287
 
 
288
 
            break;
289
 
          }
290
 
          case Smb4KSambaOptionsInfo::RAP:
291
 
          {
292
 
            protocol_value = "rap";
293
 
 
294
 
            break;
295
 
          }
296
 
          case Smb4KSambaOptionsInfo::ADS:
297
 
          {
298
 
            protocol_value = "ads";
299
 
 
300
 
            break;
301
 
          }
302
 
          case Smb4KSambaOptionsInfo::UndefinedProtocol:
303
 
          {
304
 
            protocol_value = default_protocol;
305
 
 
306
 
            break;
307
 
          }
308
 
          default:
309
 
          {
310
 
            break;
311
 
          }
312
 
        }
313
 
      }
314
 
      else
315
 
      {
316
 
        protocol_value = default_protocol;
317
 
      }
318
 
 
319
 
      if ( info )
320
 
      {
321
 
        switch ( info->useKerberos() )
322
 
        {
323
 
          case Smb4KSambaOptionsInfo::UseKerberos:
324
 
          {
325
 
            kerberos_value = true;
326
 
 
327
 
            break;
328
 
          }
329
 
          case Smb4KSambaOptionsInfo::NoKerberos:
330
 
          {
331
 
            kerberos_value = false;
332
 
 
333
 
            break;
334
 
          }
335
 
          case Smb4KSambaOptionsInfo::UndefinedKerberos:
336
 
          {
337
 
            kerberos_value = default_kerberos;
338
 
 
339
 
            break;
340
 
          }
341
 
          default:
342
 
          {
343
 
            break;
344
 
          }
345
 
        }
346
 
      }
347
 
      else
348
 
      {
349
 
        kerberos_value = default_kerberos;
350
 
      }
351
 
 
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 );
356
 
 
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 )
361
 
      {
362
 
        enable_default_button = true;
363
 
      }
364
 
 
365
 
      // Connections:
366
 
      connect( m_port_input,  SIGNAL( valueChanged( int ) ),
367
 
               this,          SLOT( slotPortChanged( int ) ) );
368
 
 
369
 
      connect( m_kerberos,    SIGNAL( toggled( bool ) ),
370
 
               this,          SLOT( slotKerberosToggled( bool ) ) );
371
 
 
372
 
      connect( m_proto_input, SIGNAL( activated( const QString & ) ),
373
 
               this,          SLOT( slotProtocolChanged( const QString & ) ) );
374
 
 
375
 
      break;
376
 
    }
377
 
    case Share:
378
 
    {
379
 
#ifndef __FreeBSD__
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() );
385
 
 
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 );
389
 
 
390
 
      QStringList write_access_entries;
391
 
      write_access_entries.append( i18n( "read-write" ) );
392
 
      write_access_entries.append( i18n( "read-only" ) );
393
 
 
394
 
      m_rw_input->insertItems( 0, write_access_entries );
395
 
 
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 );
399
 
 
400
 
      QList<KUser> user_list = KUser::allUsers();
401
 
      QStringList uids;
402
 
 
403
 
      for ( int i = 0; i < user_list.size(); ++i )
404
 
      {
405
 
        uids.append( QString( "%1 (%2)" ).arg( user_list.at( i ).loginName() )
406
 
                                         .arg( user_list.at( i ).uid() ) );
407
 
      }
408
 
 
409
 
      uids.sort();
410
 
 
411
 
      m_uid_input->addItems( uids );
412
 
 
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 );
416
 
 
417
 
      QList<KUserGroup> group_list = KUserGroup::allGroups();
418
 
      QStringList gids;
419
 
 
420
 
      for ( int i = 0; i < group_list.size(); ++i )
421
 
      {
422
 
        gids.append( QString( "%1 (%2)" ).arg( group_list.at( i ).name() )
423
 
                                         .arg( group_list.at( i ).gid() ) );
424
 
      }
425
 
 
426
 
      gids.sort();
427
 
 
428
 
      m_gid_input->addItems( gids );
429
 
 
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 );
440
 
#else
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() );
446
 
 
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 );
450
 
 
451
 
      QList<KUser> user_list = KUser::allUsers();
452
 
      QStringList uids;
453
 
 
454
 
      for ( int i = 0; i < user_list.size(); ++i )
455
 
      {
456
 
        uids.append( QString( "%1 (%2)" ).arg( user_list.at( i ).loginName() )
457
 
                                         .arg( user_list.at( i ).uid() ) );
458
 
      }
459
 
 
460
 
      uids.sort();
461
 
 
462
 
      m_uid_input->addItems( uids );
463
 
 
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 );
467
 
 
468
 
      QList<KUserGroup> group_list = KUserGroup::allGroups();
469
 
      QStringList gids;
470
 
 
471
 
      for ( int i = 0; i < group_list.size(); ++i )
472
 
      {
473
 
        gids.append( QString( "%1 (%2)" ).arg( group_list.at( i ).name() )
474
 
                                         .arg( group_list.at( i ).gid() ) );
475
 
      }
476
 
 
477
 
      gids.sort();
478
 
 
479
 
      m_gid_input->addItems( gids );
480
 
 
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 );
489
 
#endif
490
 
 
491
 
      info = Smb4KSambaOptionsHandler::self()->findItem( QString( "//%1/%2" ).arg( m_share->host(), m_share->name() ) );
492
 
 
493
 
      // Get the default values from the config file:
494
 
#ifndef __FreeBSD__
495
 
      default_port = Smb4KSettings::remoteFileSystemPort();
496
 
#else
497
 
      default_port = Smb4KSettings::remoteSMBPort();
498
 
#endif
499
 
      default_uid = Smb4KSettings::userID();
500
 
      default_gid = Smb4KSettings::groupID();
501
 
#ifndef __FreeBSD__
502
 
      switch ( Smb4KSettings::writeAccess() )
503
 
      {
504
 
        case Smb4KSettings::EnumWriteAccess::ReadWrite:
505
 
        {
506
 
          default_readwrite = true;
507
 
 
508
 
          break;
509
 
        }
510
 
        case Smb4KSettings::EnumWriteAccess::ReadOnly:
511
 
        {
512
 
          default_readwrite = false;
513
 
 
514
 
          break;
515
 
        }
516
 
        default:
517
 
        {
518
 
          break;
519
 
        }
520
 
      }
521
 
#endif
522
 
 
523
 
      // Define the values that have to be put into the widgets:
524
 
      port_value = (info && info->port() != -1) ?
525
 
                   info->port() :
526
 
                   default_port;
527
 
 
528
 
      uid_value = (info && info->uidIsSet()) ?
529
 
                  QString( "%1" ).arg( info->uid() ) :
530
 
                  default_uid;
531
 
 
532
 
      gid_value = (info && info->gidIsSet()) ?
533
 
                  QString( "%1" ).arg( info->gid() ) :
534
 
                  default_gid;
535
 
#ifndef __FreeBSD__
536
 
      if ( info )
537
 
      {
538
 
        switch( info->writeAccess() )
539
 
        {
540
 
          case Smb4KSambaOptionsInfo::ReadWrite:
541
 
          {
542
 
            readwrite_value = true;
543
 
 
544
 
            break;
545
 
          }
546
 
          case Smb4KSambaOptionsInfo::ReadOnly:
547
 
          {
548
 
            readwrite_value = false;
549
 
 
550
 
            break;
551
 
          }
552
 
          case Smb4KSambaOptionsInfo::UndefinedWriteAccess:
553
 
          {
554
 
            readwrite_value = default_readwrite;
555
 
 
556
 
            break;
557
 
          }
558
 
          default:
559
 
          {
560
 
            break;
561
 
          }
562
 
        }
563
 
      }
564
 
      else
565
 
      {
566
 
        readwrite_value = default_readwrite;
567
 
      }
568
 
#endif
569
 
 
570
 
      // Put the values in the widgets:
571
 
      m_port_input->setValue( port_value );
572
 
 
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 );
577
 
 
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 );
582
 
#ifndef __FreeBSD__
583
 
      m_rw_input->setCurrentItem( (readwrite_value ?
584
 
                                  i18n( "read-write" ) :
585
 
                                  i18n( "read-only" )),
586
 
                                  false );
587
 
#endif
588
 
 
589
 
      // Does the 'Default' button need to be enabled?
590
 
      if ( default_port != port_value ||
591
 
#ifndef __FreeBSD__
592
 
           default_readwrite != readwrite_value ||
593
 
#endif
594
 
           QString::compare( default_uid, uid_value ) != 0 ||
595
 
           QString::compare( default_gid, gid_value ) != 0 )
596
 
      {
597
 
        enable_default_button = true;
598
 
      }
599
 
 
600
 
      // Connections:
601
 
      connect( m_port_input,  SIGNAL( valueChanged( int ) ),
602
 
               this,          SLOT( slotPortChanged( int ) ) );
603
 
 
604
 
      connect( m_uid_input,   SIGNAL( activated( const QString & ) ),
605
 
               this,          SLOT( slotUIDChanged( const QString & ) ) );
606
 
 
607
 
      connect( m_gid_input,   SIGNAL( activated( const QString & ) ),
608
 
               this,          SLOT( slotGIDChanged( const QString & ) ) );
609
 
 
610
 
#ifndef __FreeBSD__
611
 
      connect( m_rw_input,    SIGNAL( activated( const QString & ) ),
612
 
               this,          SLOT( slotWriteAccessChanged( const QString & ) ) );
613
 
#endif
614
 
 
615
 
      break;
616
 
    }
617
 
    default:
618
 
    {
619
 
      // This should not happen...
620
 
      break;
621
 
    }
622
 
  }
623
 
 
624
 
  // Enable the buttons:
625
 
  enableButton( Ok, false );
626
 
  enableButton( User1, enable_default_button );
627
 
 
628
 
  // Connect the buttons:
629
 
  connect( this,          SIGNAL( okClicked() ),
630
 
           this,          SLOT( slotOKButtonClicked() ) );
631
 
 
632
 
  connect( this,          SIGNAL( user1Clicked() ),
633
 
           this,          SLOT( slotDefaultButtonClicked() ) );
634
 
}
635
 
 
636
 
/////////////////////////////////////////////////////////////////////////////
637
 
// SLOT IMPLEMENTATIONS
638
 
/////////////////////////////////////////////////////////////////////////////
639
 
 
640
 
void Smb4KCustomOptionsDialog::slotPortChanged( int val )
641
 
{
642
 
  port_changed_ok = (port_value != val);
643
 
  port_changed_default = (default_port != val);
644
 
 
645
 
  switch ( m_type )
646
 
  {
647
 
    case Host:
648
 
    {
649
 
      enableButton( Ok, port_changed_ok ||
650
 
                        protocol_changed_ok ||
651
 
                        kerberos_changed_ok );
652
 
 
653
 
      enableButton( User1, port_changed_default ||
654
 
                           protocol_changed_default ||
655
 
                           kerberos_changed_default );
656
 
 
657
 
      break;
658
 
    }
659
 
    case Share:
660
 
    {
661
 
      enableButton( Ok, port_changed_ok ||
662
 
#ifndef __FreeBSD__
663
 
                        readwrite_changed_ok ||
664
 
#endif
665
 
                        uid_changed_ok ||
666
 
                        gid_changed_ok );
667
 
 
668
 
      enableButton( User1, port_changed_default ||
669
 
#ifndef __FreeBSD__
670
 
                           readwrite_changed_default ||
671
 
#endif
672
 
                           uid_changed_default ||
673
 
                           gid_changed_default );
674
 
 
675
 
      break;
676
 
    }
677
 
    default:
678
 
    {
679
 
      break;
680
 
    }
681
 
  }
682
 
}
683
 
 
684
 
 
685
 
void Smb4KCustomOptionsDialog::slotProtocolChanged( const QString &protocol )
686
 
{
687
 
  protocol_changed_ok = (QString::compare( protocol_value, protocol.toLower() ) != 0);
688
 
  protocol_changed_default = (QString::compare( default_protocol, protocol.toLower() ) != 0);
689
 
 
690
 
  switch ( m_type )
691
 
  {
692
 
    case Host:
693
 
    {
694
 
      enableButton( Ok, port_changed_ok ||
695
 
                        protocol_changed_ok ||
696
 
                        kerberos_changed_ok );
697
 
 
698
 
      enableButton( User1, port_changed_default ||
699
 
                           protocol_changed_default ||
700
 
                           kerberos_changed_default );
701
 
 
702
 
      break;
703
 
    }
704
 
    case Share:
705
 
    {
706
 
      enableButton( Ok, port_changed_ok ||
707
 
#ifndef __FreeBSD__
708
 
                        readwrite_changed_ok ||
709
 
#endif
710
 
                        uid_changed_ok ||
711
 
                        gid_changed_ok );
712
 
 
713
 
      enableButton( User1, port_changed_default ||
714
 
#ifndef __FreeBSD__
715
 
                           readwrite_changed_default ||
716
 
#endif
717
 
                           uid_changed_default ||
718
 
                           gid_changed_default );
719
 
 
720
 
      break;
721
 
    }
722
 
    default:
723
 
    {
724
 
      break;
725
 
    }
726
 
  }
727
 
}
728
 
 
729
 
 
730
 
void Smb4KCustomOptionsDialog::slotKerberosToggled( bool on )
731
 
{
732
 
  kerberos_changed_ok = (kerberos_value != on);
733
 
  kerberos_changed_default = (default_kerberos != on);
734
 
 
735
 
  switch ( m_type )
736
 
  {
737
 
    case Host:
738
 
    {
739
 
      enableButton( Ok, port_changed_ok ||
740
 
                        protocol_changed_ok ||
741
 
                        kerberos_changed_ok );
742
 
 
743
 
      enableButton( User1, port_changed_default ||
744
 
                           protocol_changed_default ||
745
 
                           kerberos_changed_default );
746
 
 
747
 
      break;
748
 
    }
749
 
    case Share:
750
 
    {
751
 
      enableButton( Ok, port_changed_ok ||
752
 
#ifndef __FreeBSD__
753
 
                        readwrite_changed_ok ||
754
 
#endif
755
 
                        uid_changed_ok ||
756
 
                        gid_changed_ok );
757
 
 
758
 
      enableButton( User1, port_changed_default ||
759
 
#ifndef __FreeBSD__
760
 
                           readwrite_changed_default ||
761
 
#endif
762
 
                           uid_changed_default ||
763
 
                           gid_changed_default );
764
 
 
765
 
      break;
766
 
    }
767
 
    default:
768
 
    {
769
 
      break;
770
 
    }
771
 
  }
772
 
}
773
 
 
774
 
 
775
 
void Smb4KCustomOptionsDialog::slotWriteAccessChanged( const QString &rw )
776
 
{
777
 
#ifndef __FreeBSD__
778
 
  bool readwrite = (QString::compare( rw, i18n( "read-write" ) ) == 0);
779
 
  readwrite_changed_ok = (readwrite_value != readwrite);
780
 
  readwrite_changed_default = (default_readwrite != readwrite);
781
 
 
782
 
  switch ( m_type )
783
 
  {
784
 
    case Host:
785
 
    {
786
 
      enableButton( Ok, port_changed_ok ||
787
 
                        protocol_changed_ok ||
788
 
                        kerberos_changed_ok );
789
 
 
790
 
      enableButton( User1, port_changed_default ||
791
 
                           protocol_changed_default ||
792
 
                           kerberos_changed_default );
793
 
 
794
 
      break;
795
 
    }
796
 
    case Share:
797
 
    {
798
 
      enableButton( Ok, port_changed_ok ||
799
 
                        readwrite_changed_ok ||
800
 
                        uid_changed_ok ||
801
 
                        gid_changed_ok );
802
 
 
803
 
      enableButton( User1, port_changed_default ||
804
 
                           readwrite_changed_default ||
805
 
                           uid_changed_default ||
806
 
                           gid_changed_default );
807
 
      break;
808
 
    }
809
 
    default:
810
 
    {
811
 
      break;
812
 
    }
813
 
  }
814
 
#endif
815
 
}
816
 
 
817
 
 
818
 
void Smb4KCustomOptionsDialog::slotUIDChanged( const QString &u )
819
 
{
820
 
  QString uid = u.section( "(", 1, 1 ).section( ")", 0, 0 );
821
 
 
822
 
  uid_changed_ok = (QString::compare( uid_value, uid ) != 0);
823
 
  uid_changed_default = (QString::compare( default_uid, uid ) != 0);
824
 
 
825
 
  switch ( m_type )
826
 
  {
827
 
    case Host:
828
 
    {
829
 
      enableButton( Ok, port_changed_ok ||
830
 
                        protocol_changed_ok ||
831
 
                        kerberos_changed_ok );
832
 
 
833
 
      enableButton( User1, port_changed_default ||
834
 
                           protocol_changed_default ||
835
 
                           kerberos_changed_default );
836
 
 
837
 
      break;
838
 
    }
839
 
    case Share:
840
 
    {
841
 
      enableButton( Ok, port_changed_ok ||
842
 
#ifndef __FreeBSD__
843
 
                        readwrite_changed_ok ||
844
 
#endif
845
 
                        uid_changed_ok ||
846
 
                        gid_changed_ok );
847
 
 
848
 
      enableButton( User1, port_changed_default ||
849
 
#ifndef __FreeBSD__
850
 
                           readwrite_changed_default ||
851
 
#endif
852
 
                           uid_changed_default ||
853
 
                           gid_changed_default );
854
 
 
855
 
      break;
856
 
    }
857
 
    default:
858
 
    {
859
 
      break;
860
 
    }
861
 
  }
862
 
}
863
 
 
864
 
 
865
 
void Smb4KCustomOptionsDialog::slotGIDChanged( const QString &g )
866
 
{
867
 
  QString gid = g.section( "(", 1, 1 ).arg( ")", 0, 0 );
868
 
 
869
 
  gid_changed_ok = (QString::compare( gid_value, gid ) != 0);
870
 
  gid_changed_default = (QString::compare( default_gid, gid ) != 0);
871
 
 
872
 
  switch ( m_type )
873
 
  {
874
 
    case Host:
875
 
    {
876
 
      enableButton( Ok, port_changed_ok ||
877
 
                        protocol_changed_ok ||
878
 
                        kerberos_changed_ok );
879
 
 
880
 
      enableButton( User1, port_changed_default ||
881
 
                           protocol_changed_default ||
882
 
                           kerberos_changed_default );
883
 
 
884
 
      break;
885
 
    }
886
 
    case Share:
887
 
    {
888
 
      enableButton( Ok, port_changed_ok ||
889
 
#ifndef __FreeBSD__
890
 
                        readwrite_changed_ok ||
891
 
#endif
892
 
                        uid_changed_ok ||
893
 
                        gid_changed_ok );
894
 
 
895
 
      enableButton( User1, port_changed_default ||
896
 
#ifndef __FreeBSD__
897
 
                           readwrite_changed_default ||
898
 
#endif
899
 
                           uid_changed_default ||
900
 
                           gid_changed_default );
901
 
 
902
 
      break;
903
 
    }
904
 
    default:
905
 
    {
906
 
      break;
907
 
    }
908
 
  }
909
 
}
910
 
 
911
 
 
912
 
void Smb4KCustomOptionsDialog::slotOKButtonClicked()
913
 
{
914
 
  Smb4KSambaOptionsInfo *info = NULL;
915
 
 
916
 
  switch ( m_type )
917
 
  {
918
 
    case Host:
919
 
    {
920
 
      QString item_name = m_host->name();
921
 
 
922
 
      // Check if we can remove the item:
923
 
      if ( !port_changed_default && !protocol_changed_default && !kerberos_changed_default )
924
 
      {
925
 
        Smb4KSambaOptionsHandler::self()->removeItem( item_name, true );
926
 
      }
927
 
      else
928
 
      {
929
 
        // First search for the item in the custom options list
930
 
        // and create a new one only if the info could not be
931
 
        // found:
932
 
        if ( !(info = Smb4KSambaOptionsHandler::self()->findItem( item_name, true )) )
933
 
        {
934
 
          info = new Smb4KSambaOptionsInfo();
935
 
        }
936
 
 
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() );
942
 
 
943
 
        if ( QString::compare( m_proto_input->currentText(), i18n( "automatic" ), Qt::CaseInsensitive ) == 0 )
944
 
        {
945
 
          info->setProtocol( Smb4KSambaOptionsInfo::Automatic );
946
 
        }
947
 
        else if ( QString::compare( m_proto_input->currentText(), "rpc", Qt::CaseInsensitive ) == 0 )
948
 
        {
949
 
          info->setProtocol( Smb4KSambaOptionsInfo::RPC );
950
 
        }
951
 
        else if ( QString::compare( m_proto_input->currentText(), "rap", Qt::CaseInsensitive ) == 0 )
952
 
        {
953
 
          info->setProtocol( Smb4KSambaOptionsInfo::RAP );
954
 
        }
955
 
        else if ( QString::compare( m_proto_input->currentText(), "ads", Qt::CaseInsensitive ) == 0 )
956
 
        {
957
 
          info->setProtocol( Smb4KSambaOptionsInfo::ADS );
958
 
        }
959
 
        else
960
 
        {
961
 
          info->setProtocol( Smb4KSambaOptionsInfo::UndefinedProtocol );
962
 
        }
963
 
 
964
 
        if ( m_kerberos->isChecked() )
965
 
        {
966
 
          info->setUseKerberos( Smb4KSambaOptionsInfo::UseKerberos );
967
 
        }
968
 
        else
969
 
        {
970
 
          info->setUseKerberos( Smb4KSambaOptionsInfo::NoKerberos );
971
 
        }
972
 
 
973
 
        // Add the new item.
974
 
        Smb4KSambaOptionsHandler::self()->addItem( info, true );
975
 
      }
976
 
 
977
 
      break;
978
 
    }
979
 
    case Share:
980
 
    {
981
 
      QString item_name = QString( "//%1/%2" ).arg( m_share->host(), m_share->name() );
982
 
 
983
 
#ifndef __FreeBSD__
984
 
      // Check if we can remove the item:
985
 
      if ( !port_changed_default && !readwrite_changed_default &&
986
 
           !uid_changed_default && !gid_changed_default )
987
 
      {
988
 
        Smb4KSambaOptionsHandler::self()->removeItem( item_name, true );
989
 
      }
990
 
      else
991
 
      {
992
 
        // First search for the item in the custom options list
993
 
        // and create a new one only if the info could not be
994
 
        // found:
995
 
        if ( !(info = Smb4KSambaOptionsHandler::self()->findItem( item_name, true )) )
996
 
        {
997
 
          info = new Smb4KSambaOptionsInfo();
998
 
        }
999
 
 
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() );
1005
 
 
1006
 
        if ( QString::compare( m_rw_input->currentText(), i18n( "read-write" ), Qt::CaseInsensitive ) == 0 )
1007
 
        {
1008
 
          info->setWriteAccess( Smb4KSambaOptionsInfo::ReadWrite );
1009
 
        }
1010
 
        else if ( QString::compare( m_rw_input->currentText(), i18n( "read-only" ), Qt::CaseInsensitive ) == 0 )
1011
 
        {
1012
 
          info->setWriteAccess( Smb4KSambaOptionsInfo::ReadOnly );
1013
 
        }
1014
 
        else
1015
 
        {
1016
 
          info->setWriteAccess( Smb4KSambaOptionsInfo::UndefinedWriteAccess );
1017
 
        }
1018
 
 
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() );
1021
 
 
1022
 
        // Add the new item.
1023
 
        Smb4KSambaOptionsHandler::self()->addItem( info, true );
1024
 
      }
1025
 
#else
1026
 
      // Check if we can remove the item:
1027
 
      if ( !port_changed_default && !uid_changed_default && !gid_changed_default )
1028
 
      {
1029
 
        Smb4KSambaOptionsHandler::self()->removeItem( item_name, true );
1030
 
      }
1031
 
      else
1032
 
      {
1033
 
        // First search for the item in the custom options list
1034
 
        // and create a new one only if the info could not be
1035
 
        // found:
1036
 
        if ( !(info = Smb4KSambaOptionsHandler::self()->findItem( item_name, true )) )
1037
 
        {
1038
 
          info = new Smb4KSambaOptionsInfo();
1039
 
        }
1040
 
 
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() );
1046
 
 
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() );
1049
 
 
1050
 
        // Add the new item.
1051
 
        Smb4KSambaOptionsHandler::self()->addItem( info, true );
1052
 
      }
1053
 
#endif
1054
 
 
1055
 
      break;
1056
 
    }
1057
 
    default:
1058
 
    {
1059
 
      break;
1060
 
    }
1061
 
  }
1062
 
 
1063
 
  KConfigGroup group( Smb4KSettings::self()->config(), "Dialogs" );
1064
 
  saveDialogSize( group, KConfigGroup::Normal );
1065
 
}
1066
 
 
1067
 
 
1068
 
void Smb4KCustomOptionsDialog::slotDefaultButtonClicked()
1069
 
{
1070
 
  // Here, we only reset the dialog and enable the OK button
1071
 
  // if necessary.
1072
 
 
1073
 
  switch ( m_type )
1074
 
  {
1075
 
    case Host:
1076
 
    {
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 );
1081
 
 
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 );
1086
 
 
1087
 
      break;
1088
 
    }
1089
 
    case Share:
1090
 
    {
1091
 
      m_port_input->setValue( default_port );
1092
 
 
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 );
1097
 
 
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 );
1102
 
#ifndef __FreeBSD__
1103
 
      QString write_access = (default_readwrite ? i18n( "read-write" ) : i18n( "read-only" ));
1104
 
      m_rw_input->setCurrentItem( write_access, false );
1105
 
#endif
1106
 
 
1107
 
      // Enable or disable the OK button:
1108
 
      enableButton( Ok, default_port != port_value ||
1109
 
#ifndef __FreeBSD__
1110
 
                        default_readwrite != readwrite_value ||
1111
 
#endif
1112
 
                        QString::compare( default_uid, uid_value ) != 0 ||
1113
 
                        QString::compare( default_gid, gid_value ) != 0 );
1114
 
 
1115
 
      break;
1116
 
    }
1117
 
    default:
1118
 
    {
1119
 
      break;
1120
 
    }
1121
 
  }
1122
 
 
1123
 
  // We just put the default values into the dialog.
1124
 
  // Disable the 'Default' button:
1125
 
  enableButton( User1, false );
1126
 
}
1127
 
 
1128
 
#include "smb4kcustomoptionsdialog.moc"