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

« back to all changes in this revision

Viewing changes to core/smb4kmounter_p.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
1
/***************************************************************************
2
 
    smb4kmounter_p  -  This is a private helper class for Smb4KMounter.
 
2
    smb4kmounter_p  -  This file contains private helper classes for the
 
3
    Smb4KMounter class.
3
4
                             -------------------
4
5
    begin                : Do Jul 19 2007
5
 
    copyright            : (C) 2007 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
 
6
    copyright            : (C) 2007-2011 by Alexander Reinholdt
 
7
    email                : alexander.reinholdt@kdemail.net
7
8
 ***************************************************************************/
8
9
 
9
10
/***************************************************************************
19
20
 *                                                                         *
20
21
 *   You should have received a copy of the GNU General Public License     *
21
22
 *   along with this program; if not, write to the                         *
22
 
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
23
 
 *   MA  02111-1307 USA                                                    *
 
23
 *   Free Software Foundation, 51 Franklin Street, Suite 500, Boston,      *
 
24
 *   MA 02110-1335, USA                                                    *
24
25
 ***************************************************************************/
25
26
 
 
27
// Qt includes
 
28
#include <QFileInfo>
 
29
#include <QHBoxLayout>
 
30
#include <QVBoxLayout>
 
31
#include <QGridLayout>
 
32
#include <QLabel>
 
33
#include <QTimer>
 
34
#include <QDir>
 
35
 
 
36
// KDE includes
 
37
#include <kdiskfreespaceinfo.h>
 
38
#include <klocale.h>
 
39
#include <kstandarddirs.h>
 
40
#include <kmountpoint.h>
 
41
#include <kshell.h>
 
42
 
26
43
// application specific includes
27
 
#include "smb4kmounter_p.h"
 
44
#include <smb4kmounter_p.h>
 
45
#include <smb4ksettings.h>
 
46
#include <smb4knotification.h>
 
47
#include <smb4khomesshareshandler.h>
 
48
#include <smb4kglobal.h>
 
49
#include <smb4kcustomoptionsmanager.h>
 
50
#include <smb4kcustomoptions.h>
 
51
 
 
52
using namespace Smb4KGlobal;
 
53
 
 
54
 
 
55
Smb4KMountJob::Smb4KMountJob( QObject *parent ) : KJob( parent ),
 
56
  m_started( false ), m_parent_widget( NULL ), m_processed( 0 )
 
57
{
 
58
  setCapabilities( KJob::Killable );
 
59
}
 
60
 
 
61
 
 
62
Smb4KMountJob::~Smb4KMountJob()
 
63
{
 
64
}
 
65
 
 
66
 
 
67
void Smb4KMountJob::start()
 
68
{
 
69
  m_started = true;
 
70
  QTimer::singleShot( 0, this, SLOT( slotStartMount() ) );
 
71
}
 
72
 
 
73
 
 
74
void Smb4KMountJob::setupMount( Smb4KShare *share, QWidget *parent )
 
75
{
 
76
  Q_ASSERT( share );
 
77
  m_shares << *share;
 
78
  m_parent_widget = parent;
 
79
}
 
80
 
 
81
 
 
82
void Smb4KMountJob::setupMount( const QList<Smb4KShare*> &shares, QWidget *parent )
 
83
{
 
84
  QListIterator<Smb4KShare *> it( shares );
 
85
 
 
86
  while ( it.hasNext() )
 
87
  {
 
88
    Smb4KShare *share = it.next();
 
89
    Q_ASSERT( share );
 
90
    m_shares << *share;
 
91
  }
 
92
 
 
93
  m_parent_widget = parent;
 
94
}
 
95
 
 
96
 
 
97
bool Smb4KMountJob::createMountAction( Smb4KShare *share, Action *action )
 
98
{
 
99
  Q_ASSERT( share );
 
100
  Q_ASSERT( action );
 
101
 
 
102
  // Find the mount program.
 
103
  QString mount;
 
104
  QStringList paths;
 
105
  paths << "/bin";
 
106
  paths << "/sbin";
 
107
  paths << "/usr/bin";
 
108
  paths << "/usr/sbin";
 
109
  paths << "/usr/local/bin";
 
110
  paths << "/usr/local/sbin";
 
111
 
 
112
  for ( int i = 0; i < paths.size(); ++i )
 
113
  {
 
114
#ifndef Q_OS_FREEBSD
 
115
    mount = KGlobal::dirs()->findExe( "mount.cifs", paths.at( i ) );
 
116
#else
 
117
    mount = KGlobal::dirs()->findExe( "mount_smbfs", paths.at( i ) );
 
118
#endif
 
119
 
 
120
    if ( !mount.isEmpty() )
 
121
    {
 
122
      break;
 
123
    }
 
124
    else
 
125
    {
 
126
      continue;
 
127
    }
 
128
  }
 
129
 
 
130
  if ( mount.isEmpty() )
 
131
  {
 
132
    Smb4KNotification *notification = new Smb4KNotification();
 
133
    notification->commandNotFound( mount );
 
134
    return false;
 
135
  }
 
136
  else
 
137
  {
 
138
    // Do nothing
 
139
  }
 
140
 
 
141
  // Assemble the mount point and create it.
 
142
  QString mountpoint;
 
143
  mountpoint += Smb4KSettings::mountPrefix().path();
 
144
  mountpoint += QDir::separator();
 
145
  mountpoint += (Smb4KSettings::forceLowerCaseSubdirs() ? share->hostName().toLower() : share->hostName());
 
146
  mountpoint += QDir::separator();
 
147
 
 
148
  if ( !share->isHomesShare() )
 
149
  {
 
150
    mountpoint += (Smb4KSettings::forceLowerCaseSubdirs() ? share->shareName().toLower() : share->shareName());
 
151
  }
 
152
  else
 
153
  {
 
154
    mountpoint += (Smb4KSettings::forceLowerCaseSubdirs() ? share->login().toLower() : share->login());
 
155
  }
 
156
 
 
157
  QDir dir( QDir::cleanPath( mountpoint ) );
 
158
 
 
159
  if ( !dir.mkpath( dir.path() ) )
 
160
  {
 
161
    Smb4KNotification *notification = new Smb4KNotification();
 
162
    notification->mkdirFailed( dir );
 
163
    return false;
 
164
  }
 
165
  else
 
166
  {
 
167
    share->setPath( dir.path() );
 
168
  }
 
169
 
 
170
  // Set the file system
 
171
#ifndef Q_OS_FREEBSD
 
172
  share->setFileSystem( Smb4KShare::CIFS );
 
173
#else
 
174
  share->setFileSystem( Smb4KShare::SMBFS );
 
175
#endif
 
176
 
 
177
  QStringList arguments;
 
178
  QMap<QString, QString> global_options = globalSambaOptions();
 
179
  Smb4KCustomOptions *options  = Smb4KCustomOptionsManager::self()->findOptions( share );
 
180
 
 
181
#ifndef Q_OS_FREEBSD
 
182
  // Set the port before passing the full UNC.
 
183
  if ( options )
 
184
  {
 
185
    share->setPort( options->fileSystemPort() != Smb4KSettings::remoteFileSystemPort() ?
 
186
                    options->fileSystemPort() : Smb4KSettings::remoteFileSystemPort() );
 
187
  }
 
188
  else
 
189
  {
 
190
    share->setPort( Smb4KSettings::remoteFileSystemPort() );
 
191
  }
 
192
 
 
193
  QStringList args_list;
 
194
 
 
195
  // Workgroup
 
196
  if ( !share->workgroupName().trimmed().isEmpty() )
 
197
  {
 
198
    args_list << QString( "domain=%1" ).arg( KShell::quoteArg( share->workgroupName() ) );
 
199
  }
 
200
  else
 
201
  {
 
202
    // Do nothing
 
203
  }
 
204
 
 
205
  // Host IP
 
206
  if ( !share->hostIP().trimmed().isEmpty() )
 
207
  {
 
208
    args_list << QString( "ip=%1" ).arg( share->hostIP() );
 
209
  }
 
210
  else
 
211
  {
 
212
    // Do nothing
 
213
  }
 
214
 
 
215
  // User
 
216
  if ( !share->login().isEmpty() )
 
217
  {
 
218
    args_list << QString( "user=%1" ).arg( share->login() );
 
219
  }
 
220
  else
 
221
  {
 
222
    args_list << "guest";
 
223
  }
 
224
 
 
225
  // Client's and server's NetBIOS name
 
226
  // According to the manual page, this is only needed when port 139
 
227
  // is used. So, we only pass the NetBIOS name in that case.
 
228
  if ( Smb4KSettings::remoteFileSystemPort() == 139 || (options && options->fileSystemPort() == 139) )
 
229
  {
 
230
    // The client's NetBIOS name.
 
231
    if ( !Smb4KSettings::netBIOSName().isEmpty() )
 
232
    {
 
233
      args_list << QString( "netbiosname=%1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
 
234
    }
 
235
    else
 
236
    {
 
237
      if ( !global_options["netbios name"].isEmpty() )
 
238
      {
 
239
        args_list << QString( "netbiosname=%1" ).arg( KShell::quoteArg( global_options["netbios name"] ) );
 
240
      }
 
241
      else
 
242
      {
 
243
        // Do nothing
 
244
      }
 
245
    }
 
246
 
 
247
    // The server's NetBIOS name.
 
248
    args_list << QString( "servern=%1" ).arg( KShell::quoteArg( share->hostName() ) );
 
249
  }
 
250
  else
 
251
  {
 
252
    // Do nothing
 
253
  }
 
254
 
 
255
  // UID
 
256
  args_list << QString( "uid=%1" ).arg( options ? options->uid() : (uid_t)Smb4KSettings::userID().toInt() );
 
257
 
 
258
  // GID
 
259
  args_list << QString( "gid=%1" ).arg( options ? options->gid() : (gid_t)Smb4KSettings::groupID().toInt() );
 
260
 
 
261
  // Client character set
 
262
  switch ( Smb4KSettings::clientCharset() )
 
263
  {
 
264
    case Smb4KSettings::EnumClientCharset::default_charset:
 
265
    {
 
266
      if ( !global_options["unix charset"].isEmpty() )
 
267
      {
 
268
        args_list << QString( "iocharset=%1" ).arg( global_options["unix charset"].toLower() );
 
269
      }
 
270
      else
 
271
      {
 
272
        // Do nothing
 
273
      }
 
274
      break;
 
275
    }
 
276
    default:
 
277
    {
 
278
      args_list << QString( "iocharset=%1" )
 
279
                   .arg( Smb4KSettings::self()->clientCharsetItem()->choices().value( Smb4KSettings::clientCharset() ).label );
 
280
      break;
 
281
    }
 
282
  }
 
283
 
 
284
  // Port
 
285
  args_list << QString( "port=%1" )
 
286
               .arg( (options && options->fileSystemPort() != Smb4KSettings::remoteFileSystemPort()) ?
 
287
                     options->fileSystemPort() : Smb4KSettings::remoteFileSystemPort() );
 
288
 
 
289
  // Write access
 
290
  if ( options )
 
291
  {
 
292
    switch ( options->writeAccess() )
 
293
    {
 
294
      case Smb4KCustomOptions::ReadWrite:
 
295
      {
 
296
        args_list << "rw";
 
297
        break;
 
298
      }
 
299
      case Smb4KCustomOptions::ReadOnly:
 
300
      {
 
301
        args_list << "ro";
 
302
        break;
 
303
      }
 
304
      default:
 
305
      {
 
306
        switch ( Smb4KSettings::writeAccess() )
 
307
        {
 
308
          case Smb4KSettings::EnumWriteAccess::ReadWrite:
 
309
          {
 
310
            args_list << "rw";
 
311
            break;
 
312
          }
 
313
          case Smb4KSettings::EnumWriteAccess::ReadOnly:
 
314
          {
 
315
            args_list << "ro";
 
316
            break;
 
317
          }
 
318
          default:
 
319
          {
 
320
            break;
 
321
          }
 
322
        }
 
323
        break;
 
324
      }
 
325
    }
 
326
  }
 
327
  else
 
328
  {
 
329
    switch ( Smb4KSettings::writeAccess() )
 
330
    {
 
331
      case Smb4KSettings::EnumWriteAccess::ReadWrite:
 
332
      {
 
333
        args_list << "rw";
 
334
        break;
 
335
      }
 
336
      case Smb4KSettings::EnumWriteAccess::ReadOnly:
 
337
      {
 
338
        args_list << "ro";
 
339
        break;
 
340
      }
 
341
      default:
 
342
      {
 
343
        break;
 
344
       }
 
345
    }
 
346
  }
 
347
 
 
348
  // File mask
 
349
  if ( !Smb4KSettings::fileMask().isEmpty() )
 
350
  {
 
351
    args_list << QString( "file_mode=%1" ).arg( Smb4KSettings::fileMask() );
 
352
  }
 
353
  else
 
354
  {
 
355
    // Do nothing
 
356
  }
 
357
 
 
358
  // Directory mask
 
359
  if ( !Smb4KSettings::directoryMask().isEmpty() )
 
360
  {
 
361
    args_list << QString( "dir_mode=%1" ).arg( Smb4KSettings::directoryMask() );
 
362
  }
 
363
  else
 
364
  {
 
365
    // Do nothing
 
366
  }
 
367
 
 
368
  // Permission checks
 
369
  if ( Smb4KSettings::permissionChecks() )
 
370
  {
 
371
    args_list << "perm";
 
372
  }
 
373
  else
 
374
  {
 
375
    args_list << "noperm";
 
376
  }
 
377
 
 
378
  // Client controls IDs
 
379
  if ( Smb4KSettings::clientControlsIDs() )
 
380
  {
 
381
    args_list << "setuids";
 
382
  }
 
383
  else
 
384
  {
 
385
    args_list << "nosetuids";
 
386
  }
 
387
 
 
388
  // Server inode numbers
 
389
  if ( Smb4KSettings::serverInodeNumbers() )
 
390
  {
 
391
    args_list << "serverino";
 
392
  }
 
393
  else
 
394
  {
 
395
    args_list << "noserverino";
 
396
  }
 
397
 
 
398
  // Inode data caching
 
399
  if ( Smb4KSettings::noInodeDataCaching() )
 
400
  {
 
401
    args_list << "directio";
 
402
  }
 
403
  else
 
404
  {
 
405
    // Do nothing
 
406
  }
 
407
 
 
408
  // Translate reserved characters
 
409
  if ( Smb4KSettings::translateReservedChars() )
 
410
  {
 
411
    args_list << "mapchars";
 
412
  }
 
413
  else
 
414
  {
 
415
    args_list << "nomapchars";
 
416
  }
 
417
 
 
418
  // Locking
 
419
  if ( Smb4KSettings::noLocking() )
 
420
  {
 
421
    args_list << "nolock";
 
422
  }
 
423
  else
 
424
  {
 
425
    // Do nothing
 
426
  }
 
427
 
 
428
  // Security mode
 
429
  switch ( Smb4KSettings::securityMode() )
 
430
  {
 
431
    case Smb4KSettings::EnumSecurityMode::None:
 
432
    {
 
433
      args_list << "sec=none";
 
434
      break;
 
435
    }
 
436
    case Smb4KSettings::EnumSecurityMode::Krb5:
 
437
    {
 
438
      args_list << "sec=krb5";
 
439
      break;
 
440
    }
 
441
    case Smb4KSettings::EnumSecurityMode::Krb5i:
 
442
    {
 
443
      args_list << "sec=krb5i";
 
444
      break;
 
445
    }
 
446
    case Smb4KSettings::EnumSecurityMode::Ntlm:
 
447
    {
 
448
      args_list << "sec=ntlm";
 
449
      break;
 
450
    }
 
451
    case Smb4KSettings::EnumSecurityMode::Ntlmi:
 
452
    {
 
453
      args_list << "sec=ntlmi";
 
454
      break;
 
455
    }
 
456
    case Smb4KSettings::EnumSecurityMode::Ntlmv2:
 
457
    {
 
458
      args_list << "sec=ntlmv2";
 
459
      break;
 
460
    }
 
461
    case Smb4KSettings::EnumSecurityMode::Ntlmv2i:
 
462
    {
 
463
      args_list << "sec=ntlmv2i";
 
464
      break;
 
465
    }
 
466
    default:
 
467
    {
 
468
      // Smb4KSettings::EnumSecurityMode::Default,
 
469
      break;
 
470
    }
 
471
  }
 
472
 
 
473
  // Global custom options provided by the user
 
474
  if ( !Smb4KSettings::customCIFSOptions().isEmpty() )
 
475
  {
 
476
    args_list += Smb4KSettings::customCIFSOptions().split( ",", QString::SkipEmptyParts );
 
477
  }
 
478
  else
 
479
  {
 
480
    // Do nothing
 
481
  }
 
482
 
 
483
  arguments << "-o";
 
484
  arguments << args_list.join( "," );
 
485
#else
 
486
  if ( options )
 
487
  {
 
488
    share->setPort( options->smbPort() != Smb4KSettings::remoteSMBPort() ?
 
489
                    options->smbPort() : Smb4KSettings::remoteSMBPort() );
 
490
  }
 
491
  else
 
492
  {
 
493
    share->setPort( Smb4KSettings::remoteSMBPort() );
 
494
  }
 
495
 
 
496
  // Workgroup
 
497
  if ( !share->workgroupName().isEmpty() )
 
498
  {
 
499
    arguments << "-W";
 
500
    arguments << KShell::quoteArg( share->workgroupName() );
 
501
  }
 
502
  else
 
503
  {
 
504
    // Do nothing
 
505
  }
 
506
 
 
507
  // Host IP
 
508
  if ( !share->hostIP().isEmpty() )
 
509
  {
 
510
    arguments << "-I";
 
511
    arguments << share->hostIP();
 
512
  }
 
513
  else
 
514
  {
 
515
    // Do nothing
 
516
  }
 
517
 
 
518
  // Do not ask for a password. Use ~/.nsmbrc instead.
 
519
//   arguments << "-N";
 
520
 
 
521
  // UID
 
522
  if ( options )
 
523
  {
 
524
    arguments << "-u";
 
525
    arguments << QString( "%1" ).arg( options->uid() );
 
526
  }
 
527
  else
 
528
  {
 
529
    arguments << "-u";
 
530
    arguments << QString( "%1" ).arg( (K_UID)Smb4KSettings::userID().toInt() );
 
531
  }
 
532
 
 
533
  // GID
 
534
  if ( options )
 
535
  {
 
536
    arguments << "-g";
 
537
    arguments << QString( "%1" ).arg( options->gid() );
 
538
  }
 
539
  else
 
540
  {
 
541
    arguments << "-g";
 
542
    arguments << QString( "%1" ).arg( (K_GID)Smb4KSettings::groupID().toInt() );
 
543
  }
 
544
 
 
545
  // Client character set and server codepage
 
546
  QString charset, codepage;
 
547
 
 
548
  switch ( Smb4KSettings::clientCharset() )
 
549
  {
 
550
    case Smb4KSettings::EnumClientCharset::default_charset:
 
551
    {
 
552
      charset = global_options["unix charset"].toLower(); // maybe empty
 
553
      break;
 
554
    }
 
555
    default:
 
556
    {
 
557
      charset = Smb4KSettings::self()->clientCharsetItem()->choices().value( Smb4KSettings::clientCharset() ).label;
 
558
      break;
 
559
    }
 
560
  }
 
561
 
 
562
  switch ( Smb4KSettings::serverCodepage() )
 
563
  {
 
564
    case Smb4KSettings::EnumServerCodepage::default_codepage:
 
565
    {
 
566
      codepage = global_options["dos charset"].toLower(); // maybe empty
 
567
      break;
 
568
    }
 
569
    default:
 
570
    {
 
571
      codepage = Smb4KSettings::self()->serverCodepageItem()->choices().value( Smb4KSettings::serverCodepage() ).label;
 
572
      break;
 
573
    }
 
574
  }
 
575
 
 
576
  if ( !charset.isEmpty() && !codepage.isEmpty() )
 
577
  {
 
578
    arguments << "-E";
 
579
    arguments << QString( "%1:%2" ).arg( charset, codepage );
 
580
  }
 
581
  else
 
582
  {
 
583
    // Do nothing
 
584
  }
 
585
 
 
586
  // File mask
 
587
  if ( !Smb4KSettings::fileMask().isEmpty() )
 
588
  {
 
589
    arguments << "-f";
 
590
    arguments << Smb4KSettings::fileMask();
 
591
  }
 
592
  else
 
593
  {
 
594
    // Do nothing
 
595
  }
 
596
 
 
597
  // Directory mask
 
598
  if ( !Smb4KSettings::directoryMask().isEmpty() )
 
599
  {
 
600
    arguments << "-d";
 
601
    arguments << Smb4KSettings::directoryMask();
 
602
  }
 
603
  else
 
604
  {
 
605
    // Do nothing
 
606
  }
 
607
 
 
608
  if ( !share->login().isEmpty() )
 
609
  {
 
610
    arguments << "-U";
 
611
    arguments << share->login();
 
612
  }
 
613
  else
 
614
  {
 
615
    arguments << "-N";
 
616
  }
 
617
#endif
 
618
 
 
619
  // Compile the mount command.
 
620
  QStringList mount_command;
 
621
  mount_command << mount;
 
622
#ifndef Q_OS_FREEBSD
 
623
  if ( !share->isHomesShare() )
 
624
  {
 
625
    mount_command << share->unc();
 
626
  }
 
627
  else
 
628
  {
 
629
    mount_command << share->homeUNC();
 
630
  }
 
631
 
 
632
  mount_command << share->canonicalPath();
 
633
  mount_command += arguments;
 
634
#else
 
635
  mount_command += arguments;
 
636
 
 
637
  if ( !share->isHomesShare() )
 
638
  {
 
639
    mount_command << share->unc();
 
640
  }
 
641
  else
 
642
  {
 
643
    mount_command << share->homeUNC();
 
644
  }
 
645
 
 
646
  mount_command << share->canonicalPath();
 
647
#endif
 
648
 
 
649
  action->setName( "de.berlios.smb4k.mounthelper.mount" );
 
650
  action->setHelperID( "de.berlios.smb4k.mounthelper" );
 
651
  action->addArgument( "mount_command", mount_command );
 
652
  action->addArgument( "home_dir", QDir::homePath() );
 
653
 
 
654
  if ( !share->isHomesShare() )
 
655
  {
 
656
    action->addArgument( "share_url", share->url() );
 
657
  }
 
658
  else
 
659
  {
 
660
    action->addArgument( "share_url", share->homeURL() );
 
661
  }
 
662
 
 
663
  action->addArgument( "share_workgroup", share->workgroupName() );
 
664
  action->addArgument( "share_comment", share->comment() );
 
665
  action->addArgument( "share_ip", share->hostIP() );
 
666
  action->addArgument( "share_mountpoint", share->canonicalPath() );
 
667
 
 
668
  return true;
 
669
}
 
670
 
 
671
 
 
672
bool Smb4KMountJob::doKill()
 
673
{
 
674
  Action( "de.berlios.smb4k.mounthelper.mount" ).stop();
 
675
  return KJob::doKill();
 
676
}
 
677
 
 
678
 
 
679
void Smb4KMountJob::slotStartMount()
 
680
{
 
681
  QList<Action> actions;
 
682
  QMutableListIterator<Smb4KShare> it( m_shares );
 
683
 
 
684
  while ( it.hasNext() )
 
685
  {
 
686
    Smb4KShare *share = &it.next();
 
687
    Action mountAction;
 
688
 
 
689
    if ( createMountAction( share, &mountAction ) )
 
690
    {
 
691
      connect( mountAction.watcher(), SIGNAL( actionPerformed( ActionReply ) ),
 
692
               this, SLOT( slotActionFinished( ActionReply ) ) );
 
693
 
 
694
      actions << mountAction;
 
695
    }
 
696
    else
 
697
    {
 
698
      // Do nothing
 
699
    }
 
700
  }
 
701
 
 
702
  if ( !actions.isEmpty() )
 
703
  {
 
704
    emit aboutToStart( m_shares );
 
705
    Action::executeActions( actions, NULL, "de.berlios.smb4k.mounthelper" );
 
706
  }
 
707
  else
 
708
  {
 
709
    // No aboutToStart() signal should have been emitted,
 
710
    // so there is no need to emit a finished() signal.
 
711
    emitResult();
 
712
  }
 
713
}
 
714
 
 
715
 
 
716
void Smb4KMountJob::slotActionFinished( ActionReply reply )
 
717
{
 
718
  // Count the processed actions.
 
719
  m_processed++;
 
720
 
 
721
  if ( reply.succeeded() )
 
722
  {
 
723
    QMutableListIterator<Smb4KShare> it( m_shares );
 
724
 
 
725
    while( it.hasNext() )
 
726
    {
 
727
      Smb4KShare *share = &it.next();
 
728
 
 
729
      // Check if the mount process reported an error
 
730
      QString stderr( reply.data()["stderr"].toString() );
 
731
 
 
732
      if ( share->canonicalPath() == reply.data()["share_mountpoint"].toByteArray() && !stderr.isEmpty() )
 
733
      {
 
734
#ifndef Q_OS_FREEBSD
 
735
        if ( stderr.contains( "mount error 13", Qt::CaseSensitive ) || stderr.contains( "mount error(13)" )
 
736
            /* authentication error */ )
 
737
        {
 
738
          m_auth_errors << *share;
 
739
          emit authError( this );
 
740
        }
 
741
        else if ( (stderr.contains( "mount error 6" ) || stderr.contains( "mount error(6)" )) /* bad share name */ &&
 
742
                  share->shareName().contains( "_", Qt::CaseSensitive ) )
 
743
        {
 
744
          QString share_name = share->shareName();
 
745
          share->setShareName( share_name.replace( "_", " " ) );
 
746
          m_retries << *share;
 
747
          emit retry( this );
 
748
        }
 
749
        else if ( stderr.contains( "mount error 101" ) || stderr.contains( "mount error(101)" ) /* network unreachable */ )
 
750
        {
 
751
          qDebug() << "Network unreachable ..." << endl;
 
752
        }
 
753
#else
 
754
        if ( stderr.contains( "Authentication error" ) )
 
755
        {
 
756
          m_auth_errors << *share;
 
757
          emit authError( this );
 
758
        }
 
759
#endif
 
760
        else
 
761
        {
 
762
          Smb4KNotification *notification = new Smb4KNotification();
 
763
          notification->mountingFailed( share, stderr );
 
764
        }
 
765
      }
 
766
      else
 
767
      {
 
768
        // Do nothing
 
769
      }
 
770
    }
 
771
  }
 
772
  else
 
773
  {
 
774
    // The auth action failed. Report this.
 
775
    Smb4KNotification *notification = new Smb4KNotification();
 
776
 
 
777
    if ( reply.type() == ActionReply::KAuthError )
 
778
    {
 
779
      notification->actionFailed( reply.errorCode() );
 
780
    }
 
781
    else
 
782
    {
 
783
      notification->actionFailed();
 
784
    }
 
785
  }
 
786
 
 
787
  if ( m_processed == m_shares.size() )
 
788
  {
 
789
    // Give the operating system some time to process the mounts
 
790
    // before we invoke KMountPoint::currentMountPoints().
 
791
    QTimer::singleShot( 100, this, SLOT( slotFinishJob() ) );
 
792
  }
 
793
}
 
794
 
 
795
 
 
796
void Smb4KMountJob::slotFinishJob()
 
797
{
 
798
  QMutableListIterator<Smb4KShare> it( m_shares );
 
799
  Smb4KShare *share = NULL;
 
800
 
 
801
  while ( it.hasNext() )
 
802
  {
 
803
    share = &it.next();
 
804
 
 
805
    // Check which share has been mounted and emit the mounted() signal
 
806
    // if appropriate.
 
807
    if ( !share->isMounted() )
 
808
    {
 
809
      KMountPoint::List mount_points = KMountPoint::currentMountPoints( KMountPoint::BasicInfoNeeded|KMountPoint::NeedMountOptions );
 
810
 
 
811
      for ( int i = 0; i < mount_points.size(); ++i )
 
812
      {
 
813
        if ( QString::compare( mount_points.at( i )->mountPoint(), share->path() ) == 0 ||
 
814
             QString::compare( mount_points.at( i )->mountPoint(), share->canonicalPath() ) == 0 )
 
815
        {
 
816
          share->setIsMounted( true );
 
817
          emit mounted( share );
 
818
          break;
 
819
        }
 
820
        else
 
821
        {
 
822
          continue;
 
823
        }
 
824
      }
 
825
    }
 
826
    else
 
827
    {
 
828
      // Do nothing
 
829
    }
 
830
  }
 
831
 
 
832
  // Emit result() signal and tell the job to finish.
 
833
  emitResult();
 
834
  emit finished( m_shares );
 
835
}
 
836
 
 
837
 
 
838
Smb4KUnmountJob::Smb4KUnmountJob( QObject *parent ) : KJob( parent ),
 
839
  m_started( false ), m_parent_widget( NULL ), m_processed( 0 )
 
840
{
 
841
  setCapabilities( KJob::Killable );
 
842
}
 
843
 
 
844
 
 
845
Smb4KUnmountJob::~Smb4KUnmountJob()
 
846
{
 
847
}
 
848
 
 
849
 
 
850
void Smb4KUnmountJob::start()
 
851
{
 
852
  m_started = true;
 
853
  QTimer::singleShot( 0, this, SLOT( slotStartUnmount() ) );
 
854
}
 
855
 
 
856
 
 
857
void Smb4KUnmountJob::setupUnmount( Smb4KShare *share, bool force, bool silent, QWidget *parent )
 
858
{
 
859
  Q_ASSERT( share );
 
860
  m_shares << *share;
 
861
  m_force = force;
 
862
  m_silent = silent;
 
863
  m_parent_widget = parent;
 
864
}
 
865
 
 
866
 
 
867
void Smb4KUnmountJob::setupUnmount( const QList<Smb4KShare *> &shares, bool force, bool silent, QWidget* parent )
 
868
{
 
869
  QListIterator<Smb4KShare *> it( shares );
 
870
 
 
871
  while ( it.hasNext() )
 
872
  {
 
873
    Smb4KShare *share = it.next();
 
874
    Q_ASSERT( share );
 
875
    m_shares << *share;
 
876
  }
 
877
 
 
878
  m_force = force;
 
879
  m_silent = silent;
 
880
  m_parent_widget = parent;
 
881
}
 
882
 
 
883
 
 
884
bool Smb4KUnmountJob::createUnmountAction( Smb4KShare *share, bool force, bool silent, Action *action )
 
885
{
 
886
  Q_ASSERT( share );
 
887
  Q_ASSERT( action );
 
888
 
 
889
  // Find the umount program.
 
890
  QString umount;
 
891
  QStringList paths;
 
892
  paths << "/bin";
 
893
  paths << "/sbin";
 
894
  paths << "/usr/bin";
 
895
  paths << "/usr/sbin";
 
896
  paths << "/usr/local/bin";
 
897
  paths << "/usr/local/sbin";
 
898
 
 
899
  for ( int i = 0; i < paths.size(); ++i )
 
900
  {
 
901
    umount = KGlobal::dirs()->findExe( "umount", paths.at( i ) );
 
902
 
 
903
    if ( !umount.isEmpty() )
 
904
    {
 
905
      break;
 
906
    }
 
907
    else
 
908
    {
 
909
      continue;
 
910
    }
 
911
  }
 
912
 
 
913
  if ( umount.isEmpty() && !silent )
 
914
  {
 
915
    Smb4KNotification *notification = new Smb4KNotification();
 
916
    notification->commandNotFound( umount );
 
917
    return false;
 
918
  }
 
919
  else
 
920
  {
 
921
    // Do nothing
 
922
  }
 
923
 
 
924
  // Compile the command
 
925
  QStringList unmount_command;
 
926
  unmount_command << umount;
 
927
 
 
928
#ifdef Q_OS_LINUX
 
929
  if ( force )
 
930
  {
 
931
    unmount_command << "-l"; // lazy unmount
 
932
  }
 
933
  else
 
934
  {
 
935
    // Do nothing
 
936
  }
 
937
#endif
 
938
 
 
939
  unmount_command << share->canonicalPath();
 
940
 
 
941
  action->setName( "de.berlios.smb4k.mounthelper.unmount" );
 
942
  action->setHelperID( "de.berlios.smb4k.mounthelper" );
 
943
  action->addArgument( "umount_command", unmount_command );
 
944
 
 
945
  // Now add everything we need.
 
946
  action->addArgument( "share_url", share->url() );
 
947
  action->addArgument( "share_mountpoint", share->canonicalPath() );
 
948
 
 
949
  return true;
 
950
}
 
951
 
 
952
 
 
953
bool Smb4KUnmountJob::doKill()
 
954
{
 
955
  Action( "de.berlios.smb4k.mounthelper.unmount" ).stop();
 
956
  return KJob::doKill();
 
957
}
 
958
 
 
959
 
 
960
void Smb4KUnmountJob::slotStartUnmount()
 
961
{
 
962
  QList<Action> actions;
 
963
  QMutableListIterator<Smb4KShare> it( m_shares );
 
964
 
 
965
  while ( it.hasNext() )
 
966
  {
 
967
    Smb4KShare *share = &it.next();
 
968
    Action unmountAction;
 
969
 
 
970
    if ( createUnmountAction( share, m_force, m_silent, &unmountAction ) )
 
971
    {
 
972
      connect( unmountAction.watcher(), SIGNAL( actionPerformed( ActionReply ) ),
 
973
               this, SLOT( slotActionFinished( ActionReply ) ) );
 
974
 
 
975
      actions << unmountAction;
 
976
    }
 
977
    else
 
978
    {
 
979
      // Do nothing
 
980
    }
 
981
  }
 
982
 
 
983
  if ( !actions.isEmpty() )
 
984
  {
 
985
    emit aboutToStart( m_shares );
 
986
    Action::executeActions( actions, NULL, "de.berlios.smb4k.mounthelper" );
 
987
  }
 
988
  else
 
989
  {
 
990
    // No aboutToStart() signal should have been emitted,
 
991
    // so there is no need to emit a finished() signal.
 
992
    emitResult();
 
993
  }
 
994
}
 
995
 
 
996
 
 
997
void Smb4KUnmountJob::slotActionFinished( ActionReply reply )
 
998
{
 
999
  m_processed++;
 
1000
 
 
1001
  if ( reply.succeeded() )
 
1002
  {
 
1003
    // Although theoretically the ActionReply object should
 
1004
    // return the right url, it seems that this is not the
 
1005
    // case with bulk operations. So, we just check which of
 
1006
    // the shares has been mounted and emit the mounted signal.
 
1007
    QMutableListIterator<Smb4KShare> it( m_shares );
 
1008
 
 
1009
    while( it.hasNext() )
 
1010
    {
 
1011
      Smb4KShare *share = &it.next();
 
1012
 
 
1013
      // Check if the unmount process reported an error
 
1014
      QString stderr( reply.data()["stderr"].toString() );
 
1015
 
 
1016
      if ( share->canonicalPath() == reply.data()["share_mountpoint"].toByteArray() && !stderr.isEmpty() )
 
1017
      {
 
1018
        // Check if an error occurred.
 
1019
        QString stderr( reply.data().value( "stderr" ).toString() );
 
1020
 
 
1021
        if ( !stderr.isEmpty() )
 
1022
        {
 
1023
          Smb4KNotification *notification = new Smb4KNotification();
 
1024
          notification->unmountingFailed( share, stderr );
 
1025
        }
 
1026
        else
 
1027
        {
 
1028
          // Do nothing
 
1029
        }
 
1030
      }
 
1031
      else
 
1032
      {
 
1033
        // Do nothing
 
1034
      }
 
1035
    }
 
1036
 
 
1037
  }
 
1038
  else
 
1039
  {
 
1040
    // The auth action failed. Report this.
 
1041
    Smb4KNotification *notification = new Smb4KNotification();
 
1042
 
 
1043
    if ( reply.type() == ActionReply::KAuthError )
 
1044
    {
 
1045
      notification->actionFailed( reply.errorCode() );
 
1046
    }
 
1047
    else
 
1048
    {
 
1049
      notification->actionFailed();
 
1050
    }
 
1051
  }
 
1052
 
 
1053
  if ( m_processed == m_shares.size() )
 
1054
  {
 
1055
    // Give the operating system some time to process the unmounts
 
1056
    // before we invoke KMountPoint::currentMountPoints(). It seems
 
1057
    // that we need at least 500 ms, so that even slow systems have
 
1058
    // the opportunity to unregister the mounts.
 
1059
    QTimer::singleShot( 500, this, SLOT( slotFinishJob() ) );
 
1060
  }
 
1061
}
 
1062
 
 
1063
 
 
1064
void Smb4KUnmountJob::slotFinishJob()
 
1065
{
 
1066
  QMutableListIterator<Smb4KShare> it( m_shares );
 
1067
  Smb4KShare *share = NULL;
 
1068
 
 
1069
  while ( it.hasNext() )
 
1070
  {
 
1071
    share = &it.next();
 
1072
 
 
1073
    // Check if the share has been unmounted and emit the unmounted()
 
1074
    // signal if appropriate.
 
1075
    if ( share->isMounted() )
 
1076
    {
 
1077
      KMountPoint::List mount_points = KMountPoint::currentMountPoints( KMountPoint::BasicInfoNeeded|KMountPoint::NeedMountOptions );
 
1078
      bool mountpoint_found = false;
 
1079
 
 
1080
      for ( int i = 0; i < mount_points.size(); ++i )
 
1081
      {
 
1082
        if ( QString::compare( mount_points.at( i )->mountPoint(), share->path() ) == 0 ||
 
1083
             QString::compare( mount_points.at( i )->mountPoint(), share->canonicalPath() ) == 0 )
 
1084
        {
 
1085
          mountpoint_found = true;
 
1086
          break;
 
1087
        }
 
1088
        else
 
1089
        {
 
1090
          continue;
 
1091
        }
 
1092
      }
 
1093
 
 
1094
      if ( !mountpoint_found )
 
1095
      {
 
1096
        share->setIsMounted( false );
 
1097
        emit unmounted( share );
 
1098
      }
 
1099
      else
 
1100
      {
 
1101
        // Do nothing
 
1102
      }
 
1103
    }
 
1104
    else
 
1105
    {
 
1106
      // Do nothing
 
1107
    }
 
1108
  }
 
1109
 
 
1110
  // Emit result() signal and tell the job to finish.
 
1111
  emitResult();
 
1112
  emit finished( m_shares );
 
1113
}
 
1114
 
 
1115
 
 
1116
 
 
1117
Smb4KMountDialog::Smb4KMountDialog( Smb4KShare *share, QWidget *parent )
 
1118
: KDialog( parent ), m_share( share ), m_valid( true )
 
1119
{
 
1120
  setCaption( i18n( "Mount Share" ) );
 
1121
  setButtons( Ok | Cancel );
 
1122
  setDefaultButton( Ok );
 
1123
 
 
1124
  setupView();
 
1125
 
 
1126
  connect( this, SIGNAL( okClicked() ), SLOT( slotOkClicked() ) );
 
1127
  connect( this, SIGNAL( cancelClicked() ), SLOT( slotCancelClicked() ) );
 
1128
 
 
1129
  setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
 
1130
 
 
1131
  KConfigGroup group( Smb4KSettings::self()->config(), "MountDialog" );
 
1132
  restoreDialogSize( group );
 
1133
 
 
1134
  m_share_input->completionObject()->setItems( group.readEntry( "ShareNameCompletion", QStringList() ) );
 
1135
  m_ip_input->completionObject()->setItems( group.readEntry( "IPAddressCompletion", QStringList() ) );
 
1136
  m_workgroup_input->completionObject()->setItems( group.readEntry( "WorkgroupCompletion", QStringList() ) );
 
1137
}
 
1138
 
 
1139
 
 
1140
Smb4KMountDialog::~Smb4KMountDialog()
 
1141
{
 
1142
}
 
1143
 
 
1144
 
 
1145
void Smb4KMountDialog::setupView()
 
1146
{
 
1147
  QWidget *main_widget = new QWidget( this );
 
1148
  setMainWidget( main_widget );
 
1149
 
 
1150
  QVBoxLayout *layout = new QVBoxLayout( main_widget );
 
1151
  layout->setSpacing( 5 );
 
1152
  layout->setMargin( 0 );
 
1153
 
 
1154
  QWidget *description = new QWidget( main_widget );
 
1155
 
 
1156
  QHBoxLayout *desc_layout = new QHBoxLayout( description );
 
1157
  desc_layout->setSpacing( 5 );
 
1158
  desc_layout->setMargin( 0 );
 
1159
 
 
1160
  QLabel *pixmap = new QLabel( description );
 
1161
  QPixmap mount_pix = KIcon( "view-form", KIconLoader::global(), QStringList( "emblem-mounted" ) ).pixmap( KIconLoader::SizeHuge );
 
1162
  pixmap->setPixmap( mount_pix );
 
1163
  pixmap->setAlignment( Qt::AlignBottom );
 
1164
 
 
1165
  QLabel *label = new QLabel( i18n( "Enter the location (UNC address) and optionally the IP address and "
 
1166
                                    "workgroup to mount a share." ), description );
 
1167
  label->setWordWrap( true );
 
1168
  label->setAlignment( Qt::AlignBottom );
 
1169
 
 
1170
  desc_layout->addWidget( pixmap, 0 );
 
1171
  desc_layout->addWidget( label, Qt::AlignBottom );
 
1172
 
 
1173
  QWidget *edit_widget = new QWidget( main_widget );
 
1174
 
 
1175
  QGridLayout *edit_layout = new QGridLayout( edit_widget );
 
1176
  layout->setSpacing( 5 );
 
1177
  layout->setMargin( 0 );
 
1178
 
 
1179
  QLabel *shareLabel = new QLabel( i18n( "UNC Address:" ), edit_widget );
 
1180
  m_share_input = new KLineEdit( edit_widget );
 
1181
  m_share_input->setWhatsThis( i18n( "The Uniform Naming Convention (UNC) address "
 
1182
    "describes the location of the share. It has the following syntax: "
 
1183
    "//[USER@]HOST/SHARE. The username is optional." ) );
 
1184
//   m_share_input->setToolTip( i18n( "The UNC address of the share" ) );
 
1185
  m_share_input->setCompletionMode( KGlobalSettings::CompletionPopupAuto );
 
1186
  m_share_input->setClearButtonShown( true );
 
1187
  m_share_input->setMinimumWidth( 200 );
 
1188
  m_share_input->setFocus();
 
1189
 
 
1190
  QLabel *addressLabel = new QLabel( i18n( "IP Address:" ), edit_widget );
 
1191
  m_ip_input = new KLineEdit( edit_widget);
 
1192
  m_ip_input->setWhatsThis( i18n( "The Internet Protocol (IP) address identifies the "
 
1193
    "host in the network and indicates where it is. It has two valid formats, the one "
 
1194
    "known as IP version 4 (e.g. 192.168.2.11) and the version 6 format "
 
1195
    "(e.g. 2001:0db8:85a3:08d3:1319:8a2e:0370:7334)." ) );
 
1196
//   m_ip_input->setToolTip( i18n( "The IP address of the host where the share is located" ) );
 
1197
  m_ip_input->setCompletionMode( KGlobalSettings::CompletionPopupAuto );
 
1198
  m_ip_input->setClearButtonShown( true );
 
1199
  m_ip_input->setMinimumWidth( 200 );
 
1200
 
 
1201
  QLabel *workgroupLabel = new QLabel( i18n( "Workgroup:" ), edit_widget );
 
1202
  m_workgroup_input = new KLineEdit( edit_widget );
 
1203
  m_workgroup_input->setWhatsThis( i18n( "The workgroup or domain identifies the "
 
1204
    "peer-to-peer computer network the host is located in." ) );
 
1205
//   m_workgroup_input->setToolTip( i18n( "The workgroup where the host is located" ) );
 
1206
  m_workgroup_input->setCompletionMode( KGlobalSettings::CompletionPopupAuto );
 
1207
  m_workgroup_input->setClearButtonShown( true );
 
1208
  m_workgroup_input->setMinimumWidth( 200 );
 
1209
 
 
1210
  edit_layout->addWidget( shareLabel, 0, 0, 0 );
 
1211
  edit_layout->addWidget( m_share_input, 0, 1, 0 );
 
1212
  edit_layout->addWidget( addressLabel, 1, 0, 0 );
 
1213
  edit_layout->addWidget( m_ip_input, 1, 1, 0 );
 
1214
  edit_layout->addWidget( workgroupLabel, 2, 0, 0 );
 
1215
  edit_layout->addWidget( m_workgroup_input, 2, 1, 0 );
 
1216
 
 
1217
  m_bookmark = new QCheckBox( i18n( "Add this share to the bookmarks" ), main_widget );
 
1218
  m_bookmark->setWhatsThis( i18n( "If you tick this checkbox, the share will be bookmarked "
 
1219
    "and you can access it e.g. through the \"Bookmarks\" menu entry in the main window." ) );
 
1220
//   m_bookmark->setToolTip( i18n( "Add this share to the bookmarks" ) );
 
1221
 
 
1222
  layout->addWidget( description, Qt::AlignBottom );
 
1223
  layout->addWidget( edit_widget, 0 );
 
1224
  layout->addWidget( m_bookmark, 0 );
 
1225
 
 
1226
  slotChangeInputValue( m_share_input->text() );
 
1227
 
 
1228
  // Connections
 
1229
  connect( m_share_input,     SIGNAL( textChanged ( const QString & ) ) ,
 
1230
           this,              SLOT( slotChangeInputValue( const QString & ) ) );
 
1231
 
 
1232
  connect( m_share_input,     SIGNAL( editingFinished() ),
 
1233
           this,              SLOT( slotShareNameEntered() ) );
 
1234
 
 
1235
  connect( m_ip_input,        SIGNAL( editingFinished() ),
 
1236
           this,              SLOT( slotIPEntered() ) );
 
1237
 
 
1238
  connect( m_workgroup_input, SIGNAL( editingFinished() ),
 
1239
           this,              SLOT( slotWorkgroupEntered() ) );
 
1240
}
 
1241
 
 
1242
 
 
1243
/////////////////////////////////////////////////////////////////////////////
 
1244
//  SLOT IMPLEMENTATIONS
 
1245
/////////////////////////////////////////////////////////////////////////////
 
1246
 
 
1247
void Smb4KMountDialog::slotChangeInputValue( const QString& _test)
 
1248
{
 
1249
  enableButtonOk( !_test.isEmpty() );
 
1250
}
 
1251
 
 
1252
 
 
1253
void Smb4KMountDialog::slotOkClicked()
 
1254
{
 
1255
  if ( !m_share_input->text().trimmed().isEmpty() )
 
1256
  {
 
1257
    QUrl url;
 
1258
    
 
1259
    // Take care of Windows-like UNC addresses:
 
1260
    if ( m_share_input->text().trimmed().startsWith( "\\" ) )
 
1261
    {
 
1262
      QString unc = m_share_input->text();
 
1263
      unc.replace( "\\", "/" );
 
1264
      url = QUrl( unc );
 
1265
    }
 
1266
    else
 
1267
    {
 
1268
      url = QUrl( m_share_input->text().trimmed() );
 
1269
    }
 
1270
    
 
1271
    url.setScheme( "smb" );
 
1272
 
 
1273
    if ( url.isValid() && !url.host().isEmpty() /* no invalid host name */ &&
 
1274
         url.path().length() > 1 /* share name length */ && !url.path().endsWith( "/" ) )
 
1275
    {
 
1276
      m_share->setURL( url );
 
1277
      m_share->setWorkgroupName( m_workgroup_input->text().trimmed() );
 
1278
      m_share->setHostIP( m_ip_input->text().trimmed() );
 
1279
    }
 
1280
    else
 
1281
    {
 
1282
      Smb4KNotification *notification = new Smb4KNotification();
 
1283
      notification->invalidURLPassed();
 
1284
      m_valid = false;
 
1285
    }
 
1286
  }
 
1287
  else
 
1288
  {
 
1289
    // Do nothing
 
1290
  }
 
1291
 
 
1292
  KConfigGroup group( Smb4KSettings::self()->config(), "MountDialog" );
 
1293
  saveDialogSize( group, KConfigGroup::Normal );
 
1294
  group.writeEntry( "ShareNameCompletion", m_share_input->completionObject()->items() );
 
1295
  group.writeEntry( "IPAddressCompletion", m_ip_input->completionObject()->items() );
 
1296
  group.writeEntry( "WorkgroupCompletion", m_workgroup_input->completionObject()->items() );
 
1297
}
 
1298
 
 
1299
 
 
1300
void Smb4KMountDialog::slotCancelClicked()
 
1301
{
 
1302
  Smb4KMounter::self()->abort( m_share );
 
1303
}
 
1304
 
 
1305
 
 
1306
void Smb4KMountDialog::slotShareNameEntered()
 
1307
{
 
1308
  KCompletion *completion = m_share_input->completionObject();
 
1309
  QUrl url( m_share_input->userText() );
 
1310
  url.setScheme( "smb" );
 
1311
 
 
1312
  if ( url.isValid() && !url.isEmpty() )
 
1313
  {
 
1314
    completion->addItem( m_share_input->userText() );
 
1315
  }
 
1316
  else
 
1317
  {
 
1318
    // Do nothing
 
1319
  }
 
1320
}
 
1321
 
 
1322
 
 
1323
void Smb4KMountDialog::slotIPEntered()
 
1324
{
 
1325
  KCompletion *completion = m_ip_input->completionObject();
 
1326
 
 
1327
  if ( !m_ip_input->userText().isEmpty() )
 
1328
  {
 
1329
    completion->addItem( m_ip_input->userText() );
 
1330
  }
 
1331
  else
 
1332
  {
 
1333
    // Do nothing
 
1334
  }
 
1335
}
 
1336
 
 
1337
 
 
1338
void Smb4KMountDialog::slotWorkgroupEntered()
 
1339
{
 
1340
  KCompletion *completion = m_workgroup_input->completionObject();
 
1341
 
 
1342
  if ( !m_workgroup_input->userText().isEmpty() )
 
1343
  {
 
1344
    completion->addItem( m_workgroup_input->userText() );
 
1345
  }
 
1346
  else
 
1347
  {
 
1348
    // Do nothing
 
1349
  }
 
1350
}
 
1351
 
28
1352
 
29
1353
Smb4KMounterPrivate::Smb4KMounterPrivate()
 
1354
: m_quit( false ), m_hardware( false ), m_pending_unmounts( 0 ), m_initial_unmounts( 0 ),
 
1355
  m_pending_mounts( 0 ), m_initial_mounts( 0 )
30
1356
{
31
 
  timerTicks = 0;
32
 
  clearData();
33
1357
}
34
1358
 
35
1359
 
38
1362
}
39
1363
 
40
1364
 
41
 
void Smb4KMounterPrivate::clearData()
42
 
{
43
 
  m_share = Smb4KShare();
44
 
}
45
 
 
46
 
 
47
 
void Smb4KMounterPrivate::setShare( const Smb4KShare &share )
48
 
{
49
 
  m_share = share;
50
 
}
51
 
 
52
 
 
53
 
Smb4KMounterQueueContainer::Smb4KMounterQueueContainer( int todo, const Smb4KShare &share )
54
 
: m_todo( todo ), m_share( share ), m_force( false ), m_no_message( false )
55
 
{
56
 
}
57
 
 
58
 
 
59
 
Smb4KMounterQueueContainer::Smb4KMounterQueueContainer( int todo, const Smb4KShare &share, bool force, bool no_msg )
60
 
: m_todo( todo ), m_share( share ), m_force( force ), m_no_message( no_msg )
61
 
{
62
 
}
63
 
 
64
 
 
65
 
Smb4KMounterQueueContainer::Smb4KMounterQueueContainer( int todo )
66
 
: m_todo( todo ), m_share( Smb4KShare() ), m_force( false ), m_no_message( false )
67
 
{
68
 
}
69
 
 
70
 
 
71
 
Smb4KMounterQueueContainer::~Smb4KMounterQueueContainer()
72
 
{
73
 
}
 
1365
void Smb4KMounterPrivate::setAboutToQuit()
 
1366
{
 
1367
  m_quit = true;
 
1368
}
 
1369
 
 
1370
 
 
1371
void Smb4KMounterPrivate::setHardwareReason( bool hardware )
 
1372
{
 
1373
  m_hardware = hardware;
 
1374
}
 
1375
 
 
1376
 
 
1377
void Smb4KMounterPrivate::addUnmount()
 
1378
{
 
1379
  m_initial_unmounts++;
 
1380
  m_pending_unmounts++;
 
1381
}
 
1382
 
 
1383
 
 
1384
void Smb4KMounterPrivate::removeUnmount()
 
1385
{
 
1386
  m_pending_unmounts--;
 
1387
}
 
1388
 
 
1389
 
 
1390
void Smb4KMounterPrivate::clearUnmounts()
 
1391
{
 
1392
  m_initial_unmounts = 0;
 
1393
  m_pending_unmounts = 0;
 
1394
}
 
1395
 
 
1396
 
 
1397
void Smb4KMounterPrivate::addMount()
 
1398
{
 
1399
  m_initial_mounts++;
 
1400
  m_pending_mounts++;
 
1401
}
 
1402
 
 
1403
 
 
1404
void Smb4KMounterPrivate::removeMount()
 
1405
{
 
1406
  m_pending_mounts--;
 
1407
}
 
1408
 
 
1409
 
 
1410
void Smb4KMounterPrivate::clearMounts()
 
1411
{
 
1412
  m_initial_mounts = 0;
 
1413
  m_pending_mounts = 0;
 
1414
}
 
1415
 
 
1416
#include "smb4kmounter_p.moc"