1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
|
/***************************************************************************
smb4kconfigdialog - The configuration dialog of Smb4K
-------------------
begin : Sa Apr 14 2007
copyright : (C) 2007 by Alexander Reinholdt
email : dustpuppy@users.berlios.de
***************************************************************************/
/***************************************************************************
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301 USA *
***************************************************************************/
// Qt includes
#include <qradiobutton.h>
#include <qcheckbox.h>
// KDE includes
#include <klistview.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
#include <kurlrequester.h>
// system specific includes
#include <unistd.h>
#include <sys/types.h>
// application specific includes
#include "smb4kconfigdialog.h"
#include "smb4kuserinterfaceoptions.h"
#include "smb4knetworkoptions.h"
#include "smb4kshareoptions.h"
#include "smb4kauthoptions.h"
#include "smb4ksuperuseroptions.h"
#include "smb4ksambaoptions.h"
#include "smb4krsyncoptions.h"
#include "../core/smb4ksettings.h"
#include "../core/smb4kglobal.h"
#include "../core/smb4ksambaoptionsinfo.h"
#include "../core/smb4ksambaoptionshandler.h"
#include "../core/smb4kcore.h"
#include "../core/smb4kauthinfo.h"
#include "../core/smb4kpasswordhandler.h"
using namespace Smb4KGlobal;
KInstance *Smb4KConfigDialogFactory::m_instance = 0L;
KAboutData *Smb4KConfigDialogFactory::m_about = 0L;
// Variables we need to determine if super user entries
// have to be written to /etc/sudoers or /etc/super.tab
bool use_sudo = false;
bool use_super = false;
#ifdef __linux__
bool force_unmount = false;
#endif
bool always_use_su = false;
// Use this variable to determine if the dialog should be
// closed after Smb4KFileIO::finished() was emitted.
bool close_dialog = false;
Smb4KConfigDialog::Smb4KConfigDialog( Smb4KSettings *settings, QWidget *parent, const char *name )
: KConfigDialog( parent, name, settings )
{
// FIXME: I guess, normally we would not need to close destructively,
// but at the moment there are issues with the KURLRequester in file
// mode. To work around those, we are closing the dialog destructively.
// Maybe we can remove this if we moved to KDE4.
setWFlags( Qt::WDestructiveClose );
// Add the pages:
Smb4KUserInterfaceOptions *interface_options = new Smb4KUserInterfaceOptions( this, "UserInterfaceOptions" );
Smb4KNetworkOptions* network_options = new Smb4KNetworkOptions( this, "NetworkOptions" );
Smb4KShareOptions *share_options= new Smb4KShareOptions( this, "ShareOptions" );
Smb4KAuthOptions *auth_options = new Smb4KAuthOptions( this, "AuthenticationOptions" );
Smb4KSambaOptions *samba_options = new Smb4KSambaOptions( this, "SambaOptions" );
Smb4KRsyncOptions *rsync_options = new Smb4KRsyncOptions( this, "SynchronizationOptions" );
Smb4KSuperUserOptions *super_user_options = new Smb4KSuperUserOptions( this, "SuperUserOptions" );
// Disable widgets if the respective programs are not installed.
if ( Smb4KSettings::rsync().isEmpty() )
{
rsync_options->setEnabled( false );
}
if ( Smb4KSettings::sudo().isEmpty() && Smb4KSettings::super().isEmpty() )
{
super_user_options->setEnabled( false );
}
else
{
// The search for the programs and all related actions have been
// done by the core. We only need to disable widgets here.
if ( Smb4KSettings::sudo().isEmpty() )
{
QRadioButton *sudo = static_cast<QRadioButton *>( super_user_options->child( "SudoButton", "QRadioButton", true ) );
if ( sudo )
{
sudo->setEnabled( false );
}
}
else if ( Smb4KSettings::super().isEmpty() )
{
QRadioButton *super = static_cast<QRadioButton *>( super_user_options->child( "SuperButton", "QRadioButton", true ) );
if ( super )
{
super->setEnabled( false );
}
}
else
{
// Do nothing
}
}
// There are a few settings we need to the initial values of.
// Initialize them here:
switch ( Smb4KSettings::superUserProgram() )
{
case Smb4KSettings::EnumSuperUserProgram::Sudo:
{
use_sudo = true;
break;
}
case Smb4KSettings::EnumSuperUserProgram::Super:
{
use_super = true;
break;
}
default:
{
break;
}
}
#ifdef __linux__
force_unmount = Smb4KSettings::useForceUnmount();
#endif
always_use_su = Smb4KSettings::alwaysUseSuperUser();
// Now add the pages to the configuration dialog
addPage( interface_options, i18n( "User Interface" ), "view_choose" );
addPage( network_options, i18n( "Network" ), "network" );
addPage( share_options, i18n( "Shares" ), "hdd_mount" );
addPage( auth_options, i18n( "Authentication" ), "identity" );
addPage( samba_options, i18n( "Samba" ), "samba" );
addPage( rsync_options, i18n( "Synchronization" ), "bottom" );
addPage( super_user_options, i18n( "Super User" ), "penguin" );
// Stuff that's not managed by KConfig XT is loaded by
// Smb4KConfigDialog::showEvent()!
// Resize the dialog
setInitialSize( configDialogSize( *(Smb4KSettings::self()->config()), "ConfigDialog" ) );
// Connections
connect( samba_options, SIGNAL( customSettingsChanged() ),
this, SLOT( slotCustomSambaSettingsChanged() ) );
connect( super_user_options, SIGNAL( removeEntries() ),
this, SLOT( slotRemoveSuperUserEntries() ) );
connect( Smb4KCore::fileIO(), SIGNAL( failed() ),
this, SLOT( slotReceivedFileIOFailed() ) );
connect( Smb4KCore::fileIO(), SIGNAL( finished() ),
this, SLOT( slotReceivedFileIOFinished() ) );
}
Smb4KConfigDialog::~Smb4KConfigDialog()
{
}
void Smb4KConfigDialog::loadCustomSambaOptions()
{
// Get the list view:
KListView *custom_list = static_cast<KListView *>( child( "CustomOptionsList", "KListView", true ) );
if ( !custom_list )
{
return;
}
// First of all clear the list view:
custom_list->clear();
// Now get the default values:
QString default_filesystem, protocol_hint, default_uid, default_gid;
bool write_access = true;
switch( Smb4KSettings::filesystem() )
{
case Smb4KSettings::EnumFilesystem::CIFS:
{
default_filesystem = "cifs";
break;
}
case Smb4KSettings::EnumFilesystem::SMBFS:
{
default_filesystem = "smbfs";
break;
}
default:
{
// FIXME: Set default_filesystem to "cifs"?
break;
}
}
switch ( Smb4KSettings::protocolHint() )
{
case Smb4KSettings::EnumProtocolHint::Automatic:
{
// In this case the user leaves it to the net
// command to determine the right protocol.
protocol_hint = QString::null;
break;
}
case Smb4KSettings::EnumProtocolHint::RPC:
{
protocol_hint = "rpc";
break;
}
case Smb4KSettings::EnumProtocolHint::RAP:
{
protocol_hint = "rap";
break;
}
case Smb4KSettings::EnumProtocolHint::ADS:
{
protocol_hint = "ads";
break;
}
default:
{
protocol_hint = QString::null;
break;
}
}
switch( Smb4KSettings::writeAccess() )
{
case Smb4KSettings::EnumWriteAccess::ReadWrite:
{
write_access = true;
break;
}
case Smb4KSettings::EnumWriteAccess::ReadOnly:
{
write_access = false;
break;
}
default:
{
break;
}
}
const QValueList<Smb4KSambaOptionsInfo *> &list = optionsHandler()->customOptionsList();
for ( QValueList<Smb4KSambaOptionsInfo *>::ConstIterator it = list.begin();
it != list.end(); ++it )
{
// If the only modification is that the share is to be remounted,
// we will not put it into the list:
if ( (*it)->type() == Smb4KSambaOptionsInfo::Share &&
(*it)->remount() &&
(*it)->port() == Smb4KSettings::remotePort() &&
#ifndef __FreeBSD__
QString::compare( (*it)->filesystem(), default_filesystem ) == 0 &&
(*it)->writeAccess() == write_access &&
(*it)->kerberos() == Smb4KSettings::useKerberos() /* FreeBSD does not know Kerberos for mounting */ &&
#endif
((QString::compare( default_filesystem, "cifs" ) == 0 && (*it)->uid().toInt() == (int)getuid()) ||
(!(*it)->uid().isEmpty() && QString::compare( (*it)->uid(), Smb4KSettings::userID() ) == 0)) &&
((QString::compare( default_filesystem, "cifs" ) == 0 && (*it)->gid().toInt() == (int)getgid()) ||
(!(*it)->gid().isEmpty() && QString::compare( (*it)->gid(), Smb4KSettings::groupID() ) == 0)) )
{
continue;
}
// Now put the item in the list:
KListViewItem *item = new KListViewItem( custom_list );
item->setText( Smb4KSambaOptions::ItemName, (*it)->itemName() );
item->setText( Smb4KSambaOptions::Port, ((*it)->port() != -1 ?
QString( "%1" ).arg( (*it)->port() ) :
QString( "%1" ).arg( Smb4KSettings::remotePort() )) );
switch ( (*it)->type() )
{
case Smb4KSambaOptionsInfo::Host:
{
item->setText( Smb4KSambaOptions::Protocol, !(*it)->protocol().isEmpty() ?
(QString::compare( (*it)->protocol(), "auto" ) == 0 ? i18n( "auto" ) : (*it)->protocol().upper()) :
(protocol_hint.isEmpty() ? i18n( "auto" ) : protocol_hint.upper()) );
item->setText( Smb4KSambaOptions::Kerberos, (*it)->kerberos() ?
i18n( "yes" ) :
i18n( "no" ) );
#ifndef __FreeBSD__
item->setText( Smb4KSambaOptions::FileSystem, "-" );
item->setText( Smb4KSambaOptions::WriteAccess, "-" );
#endif
item->setText( Smb4KSambaOptions::UID, "-" );
item->setText( Smb4KSambaOptions::GID, "-" );
break;
}
case Smb4KSambaOptionsInfo::Share:
{
item->setText( Smb4KSambaOptions::Protocol, "-" );
#ifndef __FreeBSD__
item->setText( Smb4KSambaOptions::Kerberos, (*it)->kerberos() ?
i18n( "yes" ) :
i18n( "no" ) );
item->setText( Smb4KSambaOptions::FileSystem, !(*it)->filesystem().isEmpty() ?
(*it)->filesystem().upper() :
default_filesystem.upper() );
item->setText( Smb4KSambaOptions::WriteAccess, (*it)->writeAccess() ?
i18n( "read-write" ) :
i18n( "read-only" ) );
#else
// FreeBSD does not know Kerberos for mounting
item->setText( Smb4KSambaOptions::Kerberos, "-" );
#endif
item->setText( Smb4KSambaOptions::UID, !(*it)->uid().isEmpty() ?
(*it)->uid() :
Smb4KSettings::userID() );
item->setText( Smb4KSambaOptions::GID, !(*it)->gid().isEmpty() ?
(*it)->gid() :
Smb4KSettings::groupID() );
break;
}
default:
{
break;
}
}
}
Smb4KSambaOptions *samba_options = static_cast<Smb4KSambaOptions *>( child( "SambaOptions", "Smb4KSambaOptions", true ) );
if ( samba_options )
{
samba_options->resetCustomTab();
}
}
void Smb4KConfigDialog::saveCustomSambaOptions()
{
// Get the list view:
KListView *custom_list = static_cast<KListView *>( child( "CustomOptionsList", "KListView", true ) );
if ( !custom_list )
{
return;
}
if ( custom_list->childCount() != 0 )
{
// First remove all items that have been deleted in the
// configuration dialog:
QValueList<Smb4KSambaOptionsInfo *> list = optionsHandler()->customOptionsList();
for ( QValueList<Smb4KSambaOptionsInfo *>::Iterator it = list.begin(); it != list.end(); ++it )
{
if ( !custom_list->findItem( (*it)->itemName(), Smb4KSambaOptions::ItemName ) )
{
optionsHandler()->removeItem( (*it)->itemName(), false );
continue;
}
else
{
continue;
}
}
// Now updated the remaining items:
QListViewItemIterator it( custom_list );
while ( it.current() )
{
QListViewItem *item = it.current();
Smb4KSambaOptionsInfo *info = optionsHandler()->findItem( item->text( Smb4KSambaOptions::ItemName ) );
if ( info )
{
switch( info->type() )
{
case Smb4KSambaOptionsInfo::Host:
{
info->setProtocol( (QString::compare( item->text( Smb4KSambaOptions::Protocol ), "-" ) != 0 ?
item->text( Smb4KSambaOptions::Protocol ).lower() :
QString::null) );
info->setKerberos( (QString::compare( item->text( Smb4KSambaOptions::Kerberos ), i18n( "yes" ) ) == 0) );
info->setPort( item->text( Smb4KSambaOptions::Port ).toInt() );
break;
}
case Smb4KSambaOptionsInfo::Share:
{
#ifndef __FreeBSD__
// FreeBSD does not know Kerberos for mounting
info->setKerberos( (QString::compare( item->text( Smb4KSambaOptions::Kerberos ), i18n( "yes" ) ) == 0) );
info->setFilesystem( (QString::compare( item->text( Smb4KSambaOptions::FileSystem ), "-" ) != 0 ?
item->text( Smb4KSambaOptions::FileSystem ).lower() :
QString::null) );
info->setWriteAccess( (QString::compare( item->text( Smb4KSambaOptions::WriteAccess ),
i18n( "read-write" ) ) == 0) );
#endif
info->setUID( (QString::compare( item->text( Smb4KSambaOptions::UID ), i18n( "default" ) ) != 0 &&
QString::compare( item->text( Smb4KSambaOptions::UID ), "-" ) != 0) ?
item->text( Smb4KSambaOptions::UID ) :
QString::null );
info->setGID( (QString::compare( item->text( Smb4KSambaOptions::GID ), i18n( "default" ) ) != 0 &&
QString::compare( item->text( Smb4KSambaOptions::GID ), "-" ) != 0) ?
item->text( Smb4KSambaOptions::GID ) :
QString::null );
info->setPort( item->text( Smb4KSambaOptions::Port ).toInt() );
break;
}
default:
{
break;
}
}
}
else
{
// We do not have this case.
}
++it;
}
}
else
{
// Remove all items, if the list view is empty:
QValueList<Smb4KSambaOptionsInfo *> list = optionsHandler()->customOptionsList();
for ( QValueList<Smb4KSambaOptionsInfo *>::Iterator it = list.begin(); it != list.end(); ++it )
{
if ( !(*it)->remount() )
{
optionsHandler()->removeItem( (*it)->itemName(), false );
continue;
}
else
{
continue;
}
}
}
optionsHandler()->sync();
}
void Smb4KConfigDialog::loadAuthenticationData()
{
// Load the default login info and put it into the configuration
// page:
Smb4KAuthInfo auth( QString::null, QString::null, QString::null );
(void) passwordHandler()->readDefaultAuth( &auth );
KLineEdit *default_user = static_cast<KLineEdit *>( child( "DefaultUserName", "KLineEdit", true ) );
if ( default_user )
{
default_user->setText( auth.user() );
}
KLineEdit *default_pass = static_cast<KLineEdit *>( child( "DefaultPassword", "KLineEdit", true ) );
if ( default_pass )
{
default_pass->setText( auth.password() );
}
}
void Smb4KConfigDialog::saveAuthenticationData()
{
// Read the default login info from the configuration page
// and pass it to the password handler, but only if the wallet
// is open at this time. Otherwise we could end up with empty
// entries:
if ( passwordHandler()->walletIsOpen() )
{
Smb4KAuthInfo auth( QString::null, QString::null, QString::null );
KLineEdit *default_user = static_cast<KLineEdit *>( child( "DefaultUserName", "KLineEdit", true ) );
if ( default_user )
{
auth.setUser( default_user->text() );
}
KLineEdit *default_pass = static_cast<KLineEdit *>( child( "DefaultPassword", "KLineEdit", true ) );
if ( default_pass )
{
auth.setPassword( default_pass->text() );
}
passwordHandler()->writeDefaultAuth( &auth );
}
else
{
// Do nothing
}
}
bool Smb4KConfigDialog::writeSuperUserEntries()
{
QRadioButton *sudo = static_cast<QRadioButton *>( child( "SudoButton", "QRadioButton", true ) );
QRadioButton *super = static_cast<QRadioButton *>( child( "SuperButton", "QRadioButton", true ) );
#ifdef __linux__
QCheckBox *force = static_cast<QCheckBox *>( child( "kcfg_UseForceUnmount", "QCheckBox", true ) );
#endif
QCheckBox *full_use = static_cast<QCheckBox *>( child( "kcfg_AlwaysUseSuperUser", "QCheckBox", true ) );
// Check if we need to write anything at all:
Smb4KFileIO::Operation op = Smb4KFileIO::NoOperation;
bool success = true;
#ifdef __linux__
if ( sudo && super && force && full_use )
#else
if ( sudo && super && full_use )
#endif
{
if ( sudo->isChecked() )
{
#ifdef __linux__
if ( (!use_sudo && (force->isChecked() || full_use->isChecked())) ||
(use_sudo &&
((force->isChecked() && force_unmount != force->isChecked()) ||
(full_use->isChecked() && always_use_su != full_use->isChecked()))) )
#else
if ( (!use_sudo && full_use->isChecked()) ||
(use_sudo &&
(full_use->isChecked() && always_use_su != full_use->isChecked())) )
#endif
{
success = Smb4KCore::fileIO()->writeSudoers( (op = Smb4KFileIO::Insert) );
}
}
else if ( super->isChecked() )
{
#ifdef __linux__
if ( (!use_super && (force->isChecked() || full_use->isChecked())) ||
(use_super &&
((force->isChecked() && force_unmount != force->isChecked()) ||
(full_use->isChecked() && always_use_su != full_use->isChecked()))) )
#else
if ( (!use_super && full_use->isChecked()) ||
(use_super &&
(full_use->isChecked() && always_use_su != full_use->isChecked())) )
#endif
{
success = Smb4KCore::fileIO()->writeSuperTab( (op = Smb4KFileIO::Insert) );
}
}
else
{
// Do nothing
}
use_sudo = sudo->isChecked();
use_super = super->isChecked();
#ifdef __linux__
force_unmount = force->isChecked();
#endif
always_use_su = full_use->isChecked();
}
else
{
// Do nothing
}
return (!success || op == Smb4KFileIO::NoOperation) ? false : true;
}
void Smb4KConfigDialog::removeSuperUserEntries()
{
QRadioButton *sudo = static_cast<QRadioButton *>( child( "SudoButton", "QRadioButton", true ) );
QRadioButton *super = static_cast<QRadioButton *>( child( "SuperButton", "QRadioButton", true ) );
#ifdef __linux__
QCheckBox *force = static_cast<QCheckBox *>( child( "kcfg_UseForceUnmount", "QCheckBox", true ) );
#endif
QCheckBox *full_use = static_cast<QCheckBox *>( child( "kcfg_AlwaysUseSuperUser", "QCheckBox", true ) );
#ifdef __linux__
if ( sudo && super && force && full_use )
#else
if ( sudo && super && full_use )
#endif
{
if ( sudo->isChecked() )
{
Smb4KCore::fileIO()->writeSudoers( Smb4KFileIO::Remove );
}
else if ( super->isChecked() )
{
Smb4KCore::fileIO()->writeSuperTab( Smb4KFileIO::Remove );
}
else
{
// Do nothing
}
#ifdef __linux__
force->setChecked( false );
#endif
full_use->setChecked( false );
use_sudo = sudo->isChecked();
use_super = super->isChecked();
#ifdef __linux__
force_unmount = force->isChecked();
#endif
always_use_su = full_use->isChecked();
}
else
{
// Do nothing
}
}
bool Smb4KConfigDialog::checkSettings()
{
bool ok = true;
QString issues = QString::null;
int index = 0;
// If the user chose "Query custom master browser" in the
// "Network" tab, there must be a master browser present:
QRadioButton *query_custom_master = static_cast<QRadioButton *>( child( "CustomMasterBrowserLabel", "QRadioButton", true ) );
KLineEdit *custom_master_input = static_cast<KLineEdit *>( child( "kcfg_CustomMasterBrowser", "KLineEdit", true ) );
if ( query_custom_master && custom_master_input &&
query_custom_master->isChecked() &&
custom_master_input->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Network] The custom master browser has not been entered.\n" ) );
}
// If the user chose "Scan broadcast areas" in the
// "Network" tab, there must broadcast areas present:
QRadioButton *scan_bcast_areas = static_cast<QRadioButton *>( child( "BroadcastAreasLabel", "QRadioButton", true ) );
KLineEdit *bcast_areas_input = static_cast<KLineEdit *>( child( "kcfg_BroadcastAreas", "KLineEdit", true ) );
if ( scan_bcast_areas && bcast_areas_input &&
scan_bcast_areas->isChecked() &&
bcast_areas_input->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Network] The broadcast areas have not been entered.\n" ) );
}
// The mount prefix must not be empty:
KURLRequester *mount_prefix = static_cast<KURLRequester *>( child( "kcfg_MountPrefix", "KURLRequester", true ) );
if ( mount_prefix && mount_prefix->url().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Shares] The mount prefix is empty.\n" ) );
}
// If the user wants to use a default login, the user
// name must not be empty.
QCheckBox *use_default_login = static_cast<QCheckBox *>( child( "kcfg_UseDefaultLogin", "QCheckBox", true ) );
KLineEdit *default_user_name = static_cast<KLineEdit *>( child( "kcfg_DefaultUserName", "KLineEdit", true ) );
if ( use_default_login && default_user_name &&
use_default_login->isChecked() &&
default_user_name->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Authentication] The default user name has not been entered.\n" ) );
}
// The file mask must not be empty.
KLineEdit *file_mask = static_cast<KLineEdit *>( child( "kcfg_FileMask", "KLineEdit", true ) );
if ( file_mask && file_mask->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Samba] The file mask is empty.\n" ) );
}
// The directory mask must not be empty.
KLineEdit *directory_mask = static_cast<KLineEdit *>( child( "kcfg_DirectoryMask", "KLineEdit", true ) );
if ( directory_mask && directory_mask->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Samba] The directory mask is empty.\n" ) );
}
// The UID must not be empty.
KLineEdit *user_id = static_cast<KLineEdit *>( child( "kcfg_UserID", "KLineEdit", true ) );
if ( user_id && user_id->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Samba] The UID is empty.\n" ) );
}
// The GID must not be empty.
KLineEdit *group_id = static_cast<KLineEdit *>( child( "kcfg_GroupID", "KLineEdit", true ) );
if ( group_id && group_id->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Samba] The GID is empty.\n" ) );
}
// The rsync prefix must not be empty.
KURLRequester *rsync_prefix = static_cast<KURLRequester *>( child( "kcfg_RsyncPrefix", "KURLRequester", true ) );
if ( rsync_prefix && rsync_prefix->url().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The rsync prefix is empty.\n" ) );
}
// The path where to store partial files must not be empty.
QCheckBox *use_partical_directory = static_cast<QCheckBox *>( child( "kcfg_UsePartialDirectory", "QCheckBox", true ) );
KURLRequester *partial_directory = static_cast<KURLRequester *>( child( "kcfg_PartialDirectory", "KURLRequester", true ) );
if ( use_partical_directory && use_partical_directory->isChecked() &&
partial_directory && partial_directory->url().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The directory where partially transferred files should be stored is empty.\n" ) );
}
// The the exclude patterns must not be empty.
QCheckBox *use_exclude_pattern = static_cast<QCheckBox *>( child( "kcfg_UseExcludePattern", "QCheckBox", true ) );
KLineEdit *exclude_pattern = static_cast<KLineEdit *>( child( "kcfg_ExcludePattern", "KLineEdit", true ) );
if ( use_exclude_pattern && use_exclude_pattern->isChecked() &&
exclude_pattern && exclude_pattern->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The exclude patterns have not been entered.\n" ) );
}
// The the path of the exclude file must not be empty.
QCheckBox *use_exclude_file = static_cast<QCheckBox *>( child( "kcfg_UseExcludeFrom", "QCheckBox", true ) );
KURLRequester *exclude_file = static_cast<KURLRequester *>( child( "kcfg_ExcludeFrom", "KURLRequester", true ) );
if ( use_exclude_file && use_exclude_file->isChecked() &&
exclude_file && exclude_file->url().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The path of the exclude file is empty.\n" ) );
}
// The the include patterns must not be empty.
QCheckBox *use_include_pattern = static_cast<QCheckBox *>( child( "kcfg_UseIncludePattern", "QCheckBox", true ) );
KLineEdit *include_pattern = static_cast<KLineEdit *>( child( "kcfg_IncludePattern", "KLineEdit", true ) );
if ( use_include_pattern && use_include_pattern->isChecked() &&
include_pattern && include_pattern->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The include patterns have not been entered.\n" ) );
}
// The the path of the exclude file must not be empty.
QCheckBox *use_include_file = static_cast<QCheckBox *>( child( "kcfg_UseIncludeFrom", "QCheckBox", true ) );
KURLRequester *include_file = static_cast<KURLRequester *>( child( "kcfg_IncludeFrom", "KURLRequester", true ) );
if ( use_include_file && use_include_file->isChecked() &&
include_file && include_file->url().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The path of the include file is empty.\n" ) );
}
// If you make backups, check that the suffix and that the
// backup directory is not empty.
QCheckBox *make_backups = static_cast<QCheckBox *>( child( "kcfg_MakeBackups", "QCheckBox", true ) );
if ( make_backups && make_backups->isChecked() )
{
// The backup suffix must not be empty.
QCheckBox *use_backup_suffix = static_cast<QCheckBox *>( child( "kcfg_UseBackupSuffix", "QCheckBox", true ) );
KLineEdit *backup_suffix = static_cast<KLineEdit *>( child( "kcfg_BackupSuffix", "KLineEdit", true ) );
if ( use_backup_suffix && use_backup_suffix->isChecked() &&
backup_suffix && backup_suffix->text().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The backup suffix has not been defined.\n" ) );
}
// The the path for backups must not be empty.
QCheckBox *use_backup_dir = static_cast<QCheckBox *>( child( "kcfg_UseBackupDirectory", "QCheckBox", true ) );
KURLRequester *backup_dir = static_cast<KURLRequester *>( child( "kcfg_BackupDirectory", "KURLRequester", true ) );
if ( use_backup_dir && use_backup_dir->isChecked() &&
backup_dir && backup_dir->url().stripWhiteSpace().isEmpty() )
{
ok = false;
index++;
issues.append( "* "+i18n( "[Synchronization] The backup directory is empty.\n" ) );
}
}
if ( !ok )
{
if ( index == 1 )
{
KMessageBox::error( this, i18n( "The configuration could not be written, because one setting is incomplete:\n%1Please correct this issue." ).arg( issues ) );
}
else
{
KMessageBox::error( this, i18n( "The configuration could not be written, because %1 settings are incomplete:\n%1Please correct these issues." ).arg( index ).arg( issues ) );
}
}
return ok;
}
void Smb4KConfigDialog::showEvent( QShowEvent *e )
{
// Spontaneous show events come from outside the application.
// We do not want to react on them.
if ( !e->spontaneous() )
{
loadCustomSambaOptions();
loadAuthenticationData();
}
}
/////////////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATIONS
/////////////////////////////////////////////////////////////////////////////
void Smb4KConfigDialog::slotApply()
{
// If some settings are not complete, stop here and give
// the user the opportunity to fill in the needed string(s).
if ( !checkSettings() )
{
return;
}
saveCustomSambaOptions();
saveAuthenticationData();
if ( writeSuperUserEntries() )
{
// Disable this widget until Smb4KFileIO::finished()
// is received.
setEnabled( false );
}
// The 'Apply' button will be disabled by KConfigDialog, so we do not
// need to do it here.
KConfigDialog::slotApply();
}
void Smb4KConfigDialog::slotOk()
{
// If some settings are not complete, stop here and give
// the user the opportunity to fill in the needed string(s).
if ( !checkSettings() )
{
return;
}
saveCustomSambaOptions();
saveAuthenticationData();
saveDialogSize( *(Smb4KSettings::self()->config()), "ConfigDialog" );
// If the something needs to be written to either /etc/super.tab
// or /etc/sudoers, do not close the dialog but wait until the
// Smb4KFileIO::finished() signal is received.
if ( !writeSuperUserEntries() )
{
KConfigDialog::slotOk();
}
else
{
// Disable this widget until Smb4KFileIO::finished()
// is received.
setEnabled( false );
// Tell Smb4KConfigDialog::slotReceivedFileIOFinished()
// to close the dialog.
close_dialog = true;
}
}
void Smb4KConfigDialog::slotCancel()
{
// Reset the custom Samba options tab:
Smb4KSambaOptions *samba_options = static_cast<Smb4KSambaOptions *>( child( "SambaOptions", "Smb4KSambaOptions", true ) );
if ( samba_options )
{
samba_options->resetCustomTab();
}
KConfigDialog::slotCancel();
}
void Smb4KConfigDialog::slotCustomSambaSettingsChanged()
{
// Get the list view and all other input widgets:
KListView *view = static_cast<KListView *>( child( "CustomOptionsList", "KListView", true ) );
if ( !view )
{
return;
}
// Get the list of custom options:
QValueList<Smb4KSambaOptionsInfo *> list = optionsHandler()->customOptionsList();
bool changed = false;
// Loop through the list view items to see what changed and if
// we need to enable the 'Apply' button:
for ( QValueList<Smb4KSambaOptionsInfo *>::ConstIterator it = list.begin();
it != list.end(); ++it )
{
// Find the item in the list view:
QListViewItem *item = view->findItem( (*it)->itemName(), Smb4KSambaOptions::ItemName );
if ( item )
{
if ( (*it)->type() == Smb4KSambaOptionsInfo::Host )
{
// Check if the protocol changed.
if ( ((*it)->protocol().isEmpty() &&
QString::compare( item->text( Smb4KSambaOptions::Protocol ).lower(), i18n( "auto" ) ) != 0) ||
QString::compare( (*it)->protocol(), item->text( Smb4KSambaOptions::Protocol ).lower() ) != 0 )
{
changed = true;
break;
}
}
else if ( (*it)->type() == Smb4KSambaOptionsInfo::Share )
{
#ifndef __FreeBSD__
// Check if the file system changed.
if ( QString::compare( (*it)->filesystem(), item->text( Smb4KSambaOptions::FileSystem ).lower() ) != 0 )
{
changed = true;
break;
}
// Check if the write access changed.
QString write_access = (*it)->writeAccess() ?
i18n( "read-write" ) :
i18n( "read-only" );
if ( QString::compare( write_access, item->text( Smb4KSambaOptions::WriteAccess ) ) != 0 )
{
changed = true;
break;
}
#endif
// Check if the UID changed.
if ( ((*it)->uid().isEmpty() &&
QString::compare( i18n( "default" ), item->text( Smb4KSambaOptions::UID ) ) != 0) ||
QString::compare( (*it)->uid(), item->text( Smb4KSambaOptions::UID ) ) != 0 )
{
changed = true;
break;
}
// Check if the GID changed.
if ( ((*it)->gid().isEmpty() &&
QString::compare( i18n( "default" ), item->text( Smb4KSambaOptions::GID ) ) != 0) ||
QString::compare( (*it)->gid(), item->text( Smb4KSambaOptions::GID ) ) != 0 )
{
changed = true;
break;
}
}
else
{
// Something went wrong. Stop right here.
break;
}
// Check if the Kerberos entry changed.
QString kerberos = (*it)->kerberos() ?
i18n( "yes" ) :
i18n( "no" );
if ( QString::compare( kerberos, item->text( Smb4KSambaOptions::Kerberos ) ) != 0 )
{
changed = true;
break;
}
// Check if the port value changed.
if ( (*it)->port() != item->text( Smb4KSambaOptions::Port ).toInt() )
{
changed = true;
break;
}
}
else
{
break;
}
}
enableButtonApply( changed );
}
void Smb4KConfigDialog::slotRemoveSuperUserEntries()
{
// Disable this widget until Smb4KFileIO::finished()
// is received.
setEnabled( false );
removeSuperUserEntries();
}
void Smb4KConfigDialog::slotReceivedFileIOFailed()
{
#ifdef __linux__
QCheckBox *force = static_cast<QCheckBox *>( child( "kcfg_UseForceUnmount", "QCheckBox", true ) );
#endif
QCheckBox *full_use = static_cast<QCheckBox *>( child( "kcfg_AlwaysUseSuperUser", "QCheckBox", true ) );
#ifdef __linux__
if ( force && full_use )
{
force->setChecked( false );
#else
if ( full_use )
{
#endif
full_use->setChecked( false );
}
}
void Smb4KConfigDialog::slotReceivedFileIOFinished()
{
// Enable the widget again.
setEnabled( true );
if ( close_dialog )
{
KConfigDialog::slotOk();
}
}
/////////////////////////////////////////////////////////////////////////////
// FACTORY STUFF
/////////////////////////////////////////////////////////////////////////////
Smb4KConfigDialogFactory::Smb4KConfigDialogFactory()
: KLibFactory()
{
}
Smb4KConfigDialogFactory::~Smb4KConfigDialogFactory()
{
delete m_instance;
delete m_about;
m_instance = 0L;
}
KInstance *Smb4KConfigDialogFactory::instance()
{
if( !m_instance )
{
m_about = new KAboutData( "smb4kconfigdialog", I18N_NOOP( "Smb4KConfigDialog" ), "1.0" );
m_about->addAuthor("Alexander Reinholdt", 0, "dustpuppy@users.berlios.de");
m_about->setLicense( KAboutData::License_GPL );
m_instance = new KInstance( m_about );
}
return m_instance;
}
QObject *Smb4KConfigDialogFactory::createObject( QObject *parent, const char *name, const char *,
const QStringList & )
{
return static_cast<QObject *>( new Smb4KConfigDialog( Smb4KSettings::self(), static_cast<QWidget *>( parent ), name ) );
}
/////////////////////////////////////////////////////////////////////////////
// INIT
/////////////////////////////////////////////////////////////////////////////
extern "C"
{
void *init_libsmb4kconfigdialog()
{
KGlobal::locale()->insertCatalogue( "smb4k" );
return new Smb4KConfigDialogFactory;
}
}
#include "smb4kconfigdialog.moc"
|