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
* Free Software Foundation, 51 Franklin Street, Suite 500, Boston, *
24
* MA 02110-1335, USA *
24
25
***************************************************************************/
29
#include <QHBoxLayout>
30
#include <QVBoxLayout>
31
#include <QGridLayout>
37
#include <kdiskfreespaceinfo.h>
39
#include <kstandarddirs.h>
40
#include <kmountpoint.h>
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>
52
using namespace Smb4KGlobal;
55
Smb4KMountJob::Smb4KMountJob( QObject *parent ) : KJob( parent ),
56
m_started( false ), m_parent_widget( NULL ), m_processed( 0 )
58
setCapabilities( KJob::Killable );
62
Smb4KMountJob::~Smb4KMountJob()
67
void Smb4KMountJob::start()
70
QTimer::singleShot( 0, this, SLOT( slotStartMount() ) );
74
void Smb4KMountJob::setupMount( Smb4KShare *share, QWidget *parent )
78
m_parent_widget = parent;
82
void Smb4KMountJob::setupMount( const QList<Smb4KShare*> &shares, QWidget *parent )
84
QListIterator<Smb4KShare *> it( shares );
86
while ( it.hasNext() )
88
Smb4KShare *share = it.next();
93
m_parent_widget = parent;
97
bool Smb4KMountJob::createMountAction( Smb4KShare *share, Action *action )
102
// Find the mount program.
108
paths << "/usr/sbin";
109
paths << "/usr/local/bin";
110
paths << "/usr/local/sbin";
112
for ( int i = 0; i < paths.size(); ++i )
115
mount = KGlobal::dirs()->findExe( "mount.cifs", paths.at( i ) );
117
mount = KGlobal::dirs()->findExe( "mount_smbfs", paths.at( i ) );
120
if ( !mount.isEmpty() )
130
if ( mount.isEmpty() )
132
Smb4KNotification *notification = new Smb4KNotification();
133
notification->commandNotFound( mount );
141
// Assemble the mount point and create it.
143
mountpoint += Smb4KSettings::mountPrefix().path();
144
mountpoint += QDir::separator();
145
mountpoint += (Smb4KSettings::forceLowerCaseSubdirs() ? share->hostName().toLower() : share->hostName());
146
mountpoint += QDir::separator();
148
if ( !share->isHomesShare() )
150
mountpoint += (Smb4KSettings::forceLowerCaseSubdirs() ? share->shareName().toLower() : share->shareName());
154
mountpoint += (Smb4KSettings::forceLowerCaseSubdirs() ? share->login().toLower() : share->login());
157
QDir dir( QDir::cleanPath( mountpoint ) );
159
if ( !dir.mkpath( dir.path() ) )
161
Smb4KNotification *notification = new Smb4KNotification();
162
notification->mkdirFailed( dir );
167
share->setPath( dir.path() );
170
// Set the file system
172
share->setFileSystem( Smb4KShare::CIFS );
174
share->setFileSystem( Smb4KShare::SMBFS );
177
QStringList arguments;
178
QMap<QString, QString> global_options = globalSambaOptions();
179
Smb4KCustomOptions *options = Smb4KCustomOptionsManager::self()->findOptions( share );
182
// Set the port before passing the full UNC.
185
share->setPort( options->fileSystemPort() != Smb4KSettings::remoteFileSystemPort() ?
186
options->fileSystemPort() : Smb4KSettings::remoteFileSystemPort() );
190
share->setPort( Smb4KSettings::remoteFileSystemPort() );
193
QStringList args_list;
196
if ( !share->workgroupName().trimmed().isEmpty() )
198
args_list << QString( "domain=%1" ).arg( KShell::quoteArg( share->workgroupName() ) );
206
if ( !share->hostIP().trimmed().isEmpty() )
208
args_list << QString( "ip=%1" ).arg( share->hostIP() );
216
if ( !share->login().isEmpty() )
218
args_list << QString( "user=%1" ).arg( share->login() );
222
args_list << "guest";
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) )
230
// The client's NetBIOS name.
231
if ( !Smb4KSettings::netBIOSName().isEmpty() )
233
args_list << QString( "netbiosname=%1" ).arg( KShell::quoteArg( Smb4KSettings::netBIOSName() ) );
237
if ( !global_options["netbios name"].isEmpty() )
239
args_list << QString( "netbiosname=%1" ).arg( KShell::quoteArg( global_options["netbios name"] ) );
247
// The server's NetBIOS name.
248
args_list << QString( "servern=%1" ).arg( KShell::quoteArg( share->hostName() ) );
256
args_list << QString( "uid=%1" ).arg( options ? options->uid() : (uid_t)Smb4KSettings::userID().toInt() );
259
args_list << QString( "gid=%1" ).arg( options ? options->gid() : (gid_t)Smb4KSettings::groupID().toInt() );
261
// Client character set
262
switch ( Smb4KSettings::clientCharset() )
264
case Smb4KSettings::EnumClientCharset::default_charset:
266
if ( !global_options["unix charset"].isEmpty() )
268
args_list << QString( "iocharset=%1" ).arg( global_options["unix charset"].toLower() );
278
args_list << QString( "iocharset=%1" )
279
.arg( Smb4KSettings::self()->clientCharsetItem()->choices().value( Smb4KSettings::clientCharset() ).label );
285
args_list << QString( "port=%1" )
286
.arg( (options && options->fileSystemPort() != Smb4KSettings::remoteFileSystemPort()) ?
287
options->fileSystemPort() : Smb4KSettings::remoteFileSystemPort() );
292
switch ( options->writeAccess() )
294
case Smb4KCustomOptions::ReadWrite:
299
case Smb4KCustomOptions::ReadOnly:
306
switch ( Smb4KSettings::writeAccess() )
308
case Smb4KSettings::EnumWriteAccess::ReadWrite:
313
case Smb4KSettings::EnumWriteAccess::ReadOnly:
329
switch ( Smb4KSettings::writeAccess() )
331
case Smb4KSettings::EnumWriteAccess::ReadWrite:
336
case Smb4KSettings::EnumWriteAccess::ReadOnly:
349
if ( !Smb4KSettings::fileMask().isEmpty() )
351
args_list << QString( "file_mode=%1" ).arg( Smb4KSettings::fileMask() );
359
if ( !Smb4KSettings::directoryMask().isEmpty() )
361
args_list << QString( "dir_mode=%1" ).arg( Smb4KSettings::directoryMask() );
369
if ( Smb4KSettings::permissionChecks() )
375
args_list << "noperm";
378
// Client controls IDs
379
if ( Smb4KSettings::clientControlsIDs() )
381
args_list << "setuids";
385
args_list << "nosetuids";
388
// Server inode numbers
389
if ( Smb4KSettings::serverInodeNumbers() )
391
args_list << "serverino";
395
args_list << "noserverino";
398
// Inode data caching
399
if ( Smb4KSettings::noInodeDataCaching() )
401
args_list << "directio";
408
// Translate reserved characters
409
if ( Smb4KSettings::translateReservedChars() )
411
args_list << "mapchars";
415
args_list << "nomapchars";
419
if ( Smb4KSettings::noLocking() )
421
args_list << "nolock";
429
switch ( Smb4KSettings::securityMode() )
431
case Smb4KSettings::EnumSecurityMode::None:
433
args_list << "sec=none";
436
case Smb4KSettings::EnumSecurityMode::Krb5:
438
args_list << "sec=krb5";
441
case Smb4KSettings::EnumSecurityMode::Krb5i:
443
args_list << "sec=krb5i";
446
case Smb4KSettings::EnumSecurityMode::Ntlm:
448
args_list << "sec=ntlm";
451
case Smb4KSettings::EnumSecurityMode::Ntlmi:
453
args_list << "sec=ntlmi";
456
case Smb4KSettings::EnumSecurityMode::Ntlmv2:
458
args_list << "sec=ntlmv2";
461
case Smb4KSettings::EnumSecurityMode::Ntlmv2i:
463
args_list << "sec=ntlmv2i";
468
// Smb4KSettings::EnumSecurityMode::Default,
473
// Global custom options provided by the user
474
if ( !Smb4KSettings::customCIFSOptions().isEmpty() )
476
args_list += Smb4KSettings::customCIFSOptions().split( ",", QString::SkipEmptyParts );
484
arguments << args_list.join( "," );
488
share->setPort( options->smbPort() != Smb4KSettings::remoteSMBPort() ?
489
options->smbPort() : Smb4KSettings::remoteSMBPort() );
493
share->setPort( Smb4KSettings::remoteSMBPort() );
497
if ( !share->workgroupName().isEmpty() )
500
arguments << KShell::quoteArg( share->workgroupName() );
508
if ( !share->hostIP().isEmpty() )
511
arguments << share->hostIP();
518
// Do not ask for a password. Use ~/.nsmbrc instead.
519
// arguments << "-N";
525
arguments << QString( "%1" ).arg( options->uid() );
530
arguments << QString( "%1" ).arg( (K_UID)Smb4KSettings::userID().toInt() );
537
arguments << QString( "%1" ).arg( options->gid() );
542
arguments << QString( "%1" ).arg( (K_GID)Smb4KSettings::groupID().toInt() );
545
// Client character set and server codepage
546
QString charset, codepage;
548
switch ( Smb4KSettings::clientCharset() )
550
case Smb4KSettings::EnumClientCharset::default_charset:
552
charset = global_options["unix charset"].toLower(); // maybe empty
557
charset = Smb4KSettings::self()->clientCharsetItem()->choices().value( Smb4KSettings::clientCharset() ).label;
562
switch ( Smb4KSettings::serverCodepage() )
564
case Smb4KSettings::EnumServerCodepage::default_codepage:
566
codepage = global_options["dos charset"].toLower(); // maybe empty
571
codepage = Smb4KSettings::self()->serverCodepageItem()->choices().value( Smb4KSettings::serverCodepage() ).label;
576
if ( !charset.isEmpty() && !codepage.isEmpty() )
579
arguments << QString( "%1:%2" ).arg( charset, codepage );
587
if ( !Smb4KSettings::fileMask().isEmpty() )
590
arguments << Smb4KSettings::fileMask();
598
if ( !Smb4KSettings::directoryMask().isEmpty() )
601
arguments << Smb4KSettings::directoryMask();
608
if ( !share->login().isEmpty() )
611
arguments << share->login();
619
// Compile the mount command.
620
QStringList mount_command;
621
mount_command << mount;
623
if ( !share->isHomesShare() )
625
mount_command << share->unc();
629
mount_command << share->homeUNC();
632
mount_command << share->canonicalPath();
633
mount_command += arguments;
635
mount_command += arguments;
637
if ( !share->isHomesShare() )
639
mount_command << share->unc();
643
mount_command << share->homeUNC();
646
mount_command << share->canonicalPath();
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() );
654
if ( !share->isHomesShare() )
656
action->addArgument( "share_url", share->url() );
660
action->addArgument( "share_url", share->homeURL() );
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() );
672
bool Smb4KMountJob::doKill()
674
Action( "de.berlios.smb4k.mounthelper.mount" ).stop();
675
return KJob::doKill();
679
void Smb4KMountJob::slotStartMount()
681
QList<Action> actions;
682
QMutableListIterator<Smb4KShare> it( m_shares );
684
while ( it.hasNext() )
686
Smb4KShare *share = &it.next();
689
if ( createMountAction( share, &mountAction ) )
691
connect( mountAction.watcher(), SIGNAL( actionPerformed( ActionReply ) ),
692
this, SLOT( slotActionFinished( ActionReply ) ) );
694
actions << mountAction;
702
if ( !actions.isEmpty() )
704
emit aboutToStart( m_shares );
705
Action::executeActions( actions, NULL, "de.berlios.smb4k.mounthelper" );
709
// No aboutToStart() signal should have been emitted,
710
// so there is no need to emit a finished() signal.
716
void Smb4KMountJob::slotActionFinished( ActionReply reply )
718
// Count the processed actions.
721
if ( reply.succeeded() )
723
QMutableListIterator<Smb4KShare> it( m_shares );
725
while( it.hasNext() )
727
Smb4KShare *share = &it.next();
729
// Check if the mount process reported an error
730
QString stderr( reply.data()["stderr"].toString() );
732
if ( share->canonicalPath() == reply.data()["share_mountpoint"].toByteArray() && !stderr.isEmpty() )
735
if ( stderr.contains( "mount error 13", Qt::CaseSensitive ) || stderr.contains( "mount error(13)" )
736
/* authentication error */ )
738
m_auth_errors << *share;
739
emit authError( this );
741
else if ( (stderr.contains( "mount error 6" ) || stderr.contains( "mount error(6)" )) /* bad share name */ &&
742
share->shareName().contains( "_", Qt::CaseSensitive ) )
744
QString share_name = share->shareName();
745
share->setShareName( share_name.replace( "_", " " ) );
749
else if ( stderr.contains( "mount error 101" ) || stderr.contains( "mount error(101)" ) /* network unreachable */ )
751
qDebug() << "Network unreachable ..." << endl;
754
if ( stderr.contains( "Authentication error" ) )
756
m_auth_errors << *share;
757
emit authError( this );
762
Smb4KNotification *notification = new Smb4KNotification();
763
notification->mountingFailed( share, stderr );
774
// The auth action failed. Report this.
775
Smb4KNotification *notification = new Smb4KNotification();
777
if ( reply.type() == ActionReply::KAuthError )
779
notification->actionFailed( reply.errorCode() );
783
notification->actionFailed();
787
if ( m_processed == m_shares.size() )
789
// Give the operating system some time to process the mounts
790
// before we invoke KMountPoint::currentMountPoints().
791
QTimer::singleShot( 100, this, SLOT( slotFinishJob() ) );
796
void Smb4KMountJob::slotFinishJob()
798
QMutableListIterator<Smb4KShare> it( m_shares );
799
Smb4KShare *share = NULL;
801
while ( it.hasNext() )
805
// Check which share has been mounted and emit the mounted() signal
807
if ( !share->isMounted() )
809
KMountPoint::List mount_points = KMountPoint::currentMountPoints( KMountPoint::BasicInfoNeeded|KMountPoint::NeedMountOptions );
811
for ( int i = 0; i < mount_points.size(); ++i )
813
if ( QString::compare( mount_points.at( i )->mountPoint(), share->path() ) == 0 ||
814
QString::compare( mount_points.at( i )->mountPoint(), share->canonicalPath() ) == 0 )
816
share->setIsMounted( true );
817
emit mounted( share );
832
// Emit result() signal and tell the job to finish.
834
emit finished( m_shares );
838
Smb4KUnmountJob::Smb4KUnmountJob( QObject *parent ) : KJob( parent ),
839
m_started( false ), m_parent_widget( NULL ), m_processed( 0 )
841
setCapabilities( KJob::Killable );
845
Smb4KUnmountJob::~Smb4KUnmountJob()
850
void Smb4KUnmountJob::start()
853
QTimer::singleShot( 0, this, SLOT( slotStartUnmount() ) );
857
void Smb4KUnmountJob::setupUnmount( Smb4KShare *share, bool force, bool silent, QWidget *parent )
863
m_parent_widget = parent;
867
void Smb4KUnmountJob::setupUnmount( const QList<Smb4KShare *> &shares, bool force, bool silent, QWidget* parent )
869
QListIterator<Smb4KShare *> it( shares );
871
while ( it.hasNext() )
873
Smb4KShare *share = it.next();
880
m_parent_widget = parent;
884
bool Smb4KUnmountJob::createUnmountAction( Smb4KShare *share, bool force, bool silent, Action *action )
889
// Find the umount program.
895
paths << "/usr/sbin";
896
paths << "/usr/local/bin";
897
paths << "/usr/local/sbin";
899
for ( int i = 0; i < paths.size(); ++i )
901
umount = KGlobal::dirs()->findExe( "umount", paths.at( i ) );
903
if ( !umount.isEmpty() )
913
if ( umount.isEmpty() && !silent )
915
Smb4KNotification *notification = new Smb4KNotification();
916
notification->commandNotFound( umount );
924
// Compile the command
925
QStringList unmount_command;
926
unmount_command << umount;
931
unmount_command << "-l"; // lazy unmount
939
unmount_command << share->canonicalPath();
941
action->setName( "de.berlios.smb4k.mounthelper.unmount" );
942
action->setHelperID( "de.berlios.smb4k.mounthelper" );
943
action->addArgument( "umount_command", unmount_command );
945
// Now add everything we need.
946
action->addArgument( "share_url", share->url() );
947
action->addArgument( "share_mountpoint", share->canonicalPath() );
953
bool Smb4KUnmountJob::doKill()
955
Action( "de.berlios.smb4k.mounthelper.unmount" ).stop();
956
return KJob::doKill();
960
void Smb4KUnmountJob::slotStartUnmount()
962
QList<Action> actions;
963
QMutableListIterator<Smb4KShare> it( m_shares );
965
while ( it.hasNext() )
967
Smb4KShare *share = &it.next();
968
Action unmountAction;
970
if ( createUnmountAction( share, m_force, m_silent, &unmountAction ) )
972
connect( unmountAction.watcher(), SIGNAL( actionPerformed( ActionReply ) ),
973
this, SLOT( slotActionFinished( ActionReply ) ) );
975
actions << unmountAction;
983
if ( !actions.isEmpty() )
985
emit aboutToStart( m_shares );
986
Action::executeActions( actions, NULL, "de.berlios.smb4k.mounthelper" );
990
// No aboutToStart() signal should have been emitted,
991
// so there is no need to emit a finished() signal.
997
void Smb4KUnmountJob::slotActionFinished( ActionReply reply )
1001
if ( reply.succeeded() )
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 );
1009
while( it.hasNext() )
1011
Smb4KShare *share = &it.next();
1013
// Check if the unmount process reported an error
1014
QString stderr( reply.data()["stderr"].toString() );
1016
if ( share->canonicalPath() == reply.data()["share_mountpoint"].toByteArray() && !stderr.isEmpty() )
1018
// Check if an error occurred.
1019
QString stderr( reply.data().value( "stderr" ).toString() );
1021
if ( !stderr.isEmpty() )
1023
Smb4KNotification *notification = new Smb4KNotification();
1024
notification->unmountingFailed( share, stderr );
1040
// The auth action failed. Report this.
1041
Smb4KNotification *notification = new Smb4KNotification();
1043
if ( reply.type() == ActionReply::KAuthError )
1045
notification->actionFailed( reply.errorCode() );
1049
notification->actionFailed();
1053
if ( m_processed == m_shares.size() )
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() ) );
1064
void Smb4KUnmountJob::slotFinishJob()
1066
QMutableListIterator<Smb4KShare> it( m_shares );
1067
Smb4KShare *share = NULL;
1069
while ( it.hasNext() )
1073
// Check if the share has been unmounted and emit the unmounted()
1074
// signal if appropriate.
1075
if ( share->isMounted() )
1077
KMountPoint::List mount_points = KMountPoint::currentMountPoints( KMountPoint::BasicInfoNeeded|KMountPoint::NeedMountOptions );
1078
bool mountpoint_found = false;
1080
for ( int i = 0; i < mount_points.size(); ++i )
1082
if ( QString::compare( mount_points.at( i )->mountPoint(), share->path() ) == 0 ||
1083
QString::compare( mount_points.at( i )->mountPoint(), share->canonicalPath() ) == 0 )
1085
mountpoint_found = true;
1094
if ( !mountpoint_found )
1096
share->setIsMounted( false );
1097
emit unmounted( share );
1110
// Emit result() signal and tell the job to finish.
1112
emit finished( m_shares );
1117
Smb4KMountDialog::Smb4KMountDialog( Smb4KShare *share, QWidget *parent )
1118
: KDialog( parent ), m_share( share ), m_valid( true )
1120
setCaption( i18n( "Mount Share" ) );
1121
setButtons( Ok | Cancel );
1122
setDefaultButton( Ok );
1126
connect( this, SIGNAL( okClicked() ), SLOT( slotOkClicked() ) );
1127
connect( this, SIGNAL( cancelClicked() ), SLOT( slotCancelClicked() ) );
1129
setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
1131
KConfigGroup group( Smb4KSettings::self()->config(), "MountDialog" );
1132
restoreDialogSize( group );
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() ) );
1140
Smb4KMountDialog::~Smb4KMountDialog()
1145
void Smb4KMountDialog::setupView()
1147
QWidget *main_widget = new QWidget( this );
1148
setMainWidget( main_widget );
1150
QVBoxLayout *layout = new QVBoxLayout( main_widget );
1151
layout->setSpacing( 5 );
1152
layout->setMargin( 0 );
1154
QWidget *description = new QWidget( main_widget );
1156
QHBoxLayout *desc_layout = new QHBoxLayout( description );
1157
desc_layout->setSpacing( 5 );
1158
desc_layout->setMargin( 0 );
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 );
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 );
1170
desc_layout->addWidget( pixmap, 0 );
1171
desc_layout->addWidget( label, Qt::AlignBottom );
1173
QWidget *edit_widget = new QWidget( main_widget );
1175
QGridLayout *edit_layout = new QGridLayout( edit_widget );
1176
layout->setSpacing( 5 );
1177
layout->setMargin( 0 );
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();
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 );
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 );
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 );
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" ) );
1222
layout->addWidget( description, Qt::AlignBottom );
1223
layout->addWidget( edit_widget, 0 );
1224
layout->addWidget( m_bookmark, 0 );
1226
slotChangeInputValue( m_share_input->text() );
1229
connect( m_share_input, SIGNAL( textChanged ( const QString & ) ) ,
1230
this, SLOT( slotChangeInputValue( const QString & ) ) );
1232
connect( m_share_input, SIGNAL( editingFinished() ),
1233
this, SLOT( slotShareNameEntered() ) );
1235
connect( m_ip_input, SIGNAL( editingFinished() ),
1236
this, SLOT( slotIPEntered() ) );
1238
connect( m_workgroup_input, SIGNAL( editingFinished() ),
1239
this, SLOT( slotWorkgroupEntered() ) );
1243
/////////////////////////////////////////////////////////////////////////////
1244
// SLOT IMPLEMENTATIONS
1245
/////////////////////////////////////////////////////////////////////////////
1247
void Smb4KMountDialog::slotChangeInputValue( const QString& _test)
1249
enableButtonOk( !_test.isEmpty() );
1253
void Smb4KMountDialog::slotOkClicked()
1255
if ( !m_share_input->text().trimmed().isEmpty() )
1259
// Take care of Windows-like UNC addresses:
1260
if ( m_share_input->text().trimmed().startsWith( "\\" ) )
1262
QString unc = m_share_input->text();
1263
unc.replace( "\\", "/" );
1268
url = QUrl( m_share_input->text().trimmed() );
1271
url.setScheme( "smb" );
1273
if ( url.isValid() && !url.host().isEmpty() /* no invalid host name */ &&
1274
url.path().length() > 1 /* share name length */ && !url.path().endsWith( "/" ) )
1276
m_share->setURL( url );
1277
m_share->setWorkgroupName( m_workgroup_input->text().trimmed() );
1278
m_share->setHostIP( m_ip_input->text().trimmed() );
1282
Smb4KNotification *notification = new Smb4KNotification();
1283
notification->invalidURLPassed();
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() );
1300
void Smb4KMountDialog::slotCancelClicked()
1302
Smb4KMounter::self()->abort( m_share );
1306
void Smb4KMountDialog::slotShareNameEntered()
1308
KCompletion *completion = m_share_input->completionObject();
1309
QUrl url( m_share_input->userText() );
1310
url.setScheme( "smb" );
1312
if ( url.isValid() && !url.isEmpty() )
1314
completion->addItem( m_share_input->userText() );
1323
void Smb4KMountDialog::slotIPEntered()
1325
KCompletion *completion = m_ip_input->completionObject();
1327
if ( !m_ip_input->userText().isEmpty() )
1329
completion->addItem( m_ip_input->userText() );
1338
void Smb4KMountDialog::slotWorkgroupEntered()
1340
KCompletion *completion = m_workgroup_input->completionObject();
1342
if ( !m_workgroup_input->userText().isEmpty() )
1344
completion->addItem( m_workgroup_input->userText() );
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 )