1 /***************************************************************************
2     The configuration dialog of Smb4K
3                              -------------------
4     begin                : Sa Apr 14 2007
5     copyright            : (C) 2004-2021 by Alexander Reinholdt
6     email                : alexander.reinholdt@kdemail.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful, but   *
16  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
18  *   General Public License for more details.                              *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program; if not, write to the                         *
22  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
23  *   MA 02110-1335, USA                                                    *
24  ***************************************************************************/
25 
26 // application specific includes
27 #include "smb4kconfigdialog.h"
28 #include "smb4kconfigpageauthentication.h"
29 #include "smb4kconfigpagecustomoptions.h"
30 #include "smb4kconfigpagemounting.h"
31 #include "smb4kconfigpagenetwork.h"
32 #include "smb4kconfigpageprofiles.h"
33 #include "smb4kconfigpagesynchronization.h"
34 #include "smb4kconfigpageuserinterface.h"
35 #include "core/smb4ksettings.h"
36 #include "core/smb4kglobal.h"
37 #include "core/smb4kauthinfo.h"
38 #include "core/smb4kwalletmanager.h"
39 #include "core/smb4kcustomoptions.h"
40 #include "core/smb4kcustomoptionsmanager.h"
41 #include "core/smb4kprofilemanager.h"
42 
43 #if defined(Q_OS_LINUX)
44 #include "smb4kmountsettings_linux.h"
45 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
46 #include "smb4kmountsettings_bsd.h"
47 #endif
48 
49 // Qt includes
50 #include <QPointer>
51 #include <QPair>
52 #include <QList>
53 #include <QSize>
54 #include <QStandardPaths>
55 #include <QRadioButton>
56 #include <QCheckBox>
57 #include <QTreeWidget>
58 #include <QScrollArea>
59 #include <QShowEvent>
60 #include <QWindow>
61 
62 // KDE includes
63 #include <KCoreAddons/KPluginFactory>
64 #include <KI18n/KLocalizedString>
65 #include <KConfigGui/KWindowConfig>
66 #include <KWidgetsAddons/KMessageBox>
67 #include <KWidgetsAddons/KPasswordDialog>
68 #include <KIOWidgets/KUrlRequester>
69 
70 using namespace Smb4KGlobal;
71 
K_PLUGIN_FACTORY(Smb4KConfigDialogFactory,registerPlugin<Smb4KConfigDialog> ();)72 K_PLUGIN_FACTORY(Smb4KConfigDialogFactory, registerPlugin<Smb4KConfigDialog>();)
73 
74 
75 Smb4KConfigDialog::Smb4KConfigDialog(QWidget *parent, const QList<QVariant> &/*args*/)
76 : KConfigDialog(parent, "ConfigDialog", Smb4KSettings::self())
77 {
78   setupDialog();
79 }
80 
81 
~Smb4KConfigDialog()82 Smb4KConfigDialog::~Smb4KConfigDialog()
83 {
84 }
85 
86 
setupDialog()87 void Smb4KConfigDialog::setupDialog()
88 {
89   // FIXME: I guess, normally we would not need to close destructively,
90   // but at the moment there are issues with the KURLRequester in file
91   // mode. To work around those, we are closing the dialog destructively.
92   // Maybe we can remove this if we moved to KDE4.
93   setAttribute(Qt::WA_DeleteOnClose, true);
94 
95   // Add the pages:
96   Smb4KConfigPageUserInterface *interface_options = new Smb4KConfigPageUserInterface(this);
97   QScrollArea *interface_area = new QScrollArea(this);
98   interface_area->setWidget(interface_options);
99   interface_area->setWidgetResizable(true);
100   interface_area->setFrameStyle(QFrame::NoFrame);
101 
102   Smb4KConfigPageNetwork *network_options = new Smb4KConfigPageNetwork(this);
103   QScrollArea *network_area = new QScrollArea(this);
104   network_area->setWidget(network_options);
105   network_area->setWidgetResizable(true);
106   network_area->setFrameStyle(QFrame::NoFrame);
107 
108   Smb4KConfigPageMounting *mount_options = new Smb4KConfigPageMounting(this);
109   QScrollArea *mount_area = new QScrollArea(this);
110   mount_area->setWidget(mount_options);
111   mount_area->setWidgetResizable(true);
112   mount_area->setFrameStyle(QFrame::NoFrame);
113 
114   Smb4KConfigPageAuthentication *auth_options = new Smb4KConfigPageAuthentication(this);
115   QScrollArea *auth_area = new QScrollArea(this);
116   auth_area->setWidget(auth_options);
117   auth_area->setWidgetResizable(true);
118   auth_area->setFrameStyle(QFrame::NoFrame);
119 
120   Smb4KConfigPageSynchronization *rsync_options = new Smb4KConfigPageSynchronization(this);
121   QScrollArea *rsync_area = new QScrollArea(this);
122   rsync_area->setWidget(rsync_options);
123   rsync_area->setWidgetResizable(true);
124   rsync_area->setFrameStyle(QFrame::NoFrame);
125 
126   rsync_options->setEnabled(!QStandardPaths::findExecutable("rsync").isEmpty());
127 
128   Smb4KConfigPageCustomOptions *custom_options = new Smb4KConfigPageCustomOptions(this);
129   QScrollArea *custom_area = new QScrollArea(this);
130   custom_area->setWidget(custom_options);
131   custom_area->setWidgetResizable(true);
132   custom_area->setFrameStyle(QFrame::NoFrame);
133 
134   Smb4KConfigPageProfiles *profiles_page = new Smb4KConfigPageProfiles(this);
135   QScrollArea *profiles_area = new QScrollArea(this);
136   profiles_area->setWidget(profiles_page);
137   profiles_area->setWidgetResizable(true);
138   profiles_area->setFrameStyle(QFrame::NoFrame);
139 
140   //
141   // Pages to the configuration dialog
142   //
143   m_user_interface  = addPage(interface_area, Smb4KSettings::self(), i18n("User Interface"), "preferences-desktop");
144   m_network         = addPage(network_area, Smb4KSettings::self(), i18n("Network"), "network-workgroup");
145   m_mounting        = addPage(mount_area, Smb4KMountSettings::self(), i18n("Mounting"), "media-mount");
146   m_authentication  = addPage(auth_area, Smb4KSettings::self(), i18n("Authentication"), "dialog-password");
147   m_synchronization = addPage(rsync_area, Smb4KSettings::self(),i18n("Synchronization"), "folder-sync");
148   m_custom_options  = addPage(custom_area, Smb4KSettings::self(), i18n("Custom Options"), "preferences-system-network");
149   m_profiles        = addPage(profiles_area, Smb4KSettings::self(), i18n("Profiles"), "format-list-unordered");
150 
151   //
152   // Connections
153   //
154   connect(custom_options, SIGNAL(customSettingsModified()), this, SLOT(slotEnableApplyButton()));
155 
156   connect(auth_options, SIGNAL(loadWalletEntries()), this, SLOT(slotLoadAuthenticationInformation()));
157   connect(auth_options, SIGNAL(saveWalletEntries()), this, SLOT(slotSaveAuthenticationInformation()));
158   connect(auth_options, SIGNAL(setDefaultLogin()), this, SLOT(slotSetDefaultLogin()));
159   connect(auth_options, SIGNAL(walletEntriesModified()), this, SLOT(slotEnableApplyButton()));
160 
161   connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotCheckPage(KPageWidgetItem*,KPageWidgetItem*)));
162 
163   //
164   // Dialog size
165   //
166   create();
167   windowHandle()->resize(QSize(800, 600));
168 
169   KConfigGroup group(Smb4KSettings::self()->config(), "ConfigDialog");
170   KWindowConfig::restoreWindowSize(windowHandle(), group);
171   resize(windowHandle()->size()); // workaround for QTBUG-40584
172 }
173 
174 
loadCustomOptions()175 void Smb4KConfigDialog::loadCustomOptions()
176 {
177   if (m_custom_options)
178   {
179     QList<OptionsPtr> optionsList = Smb4KCustomOptionsManager::self()->customOptions(true);
180     m_custom_options->widget()->findChild<Smb4KConfigPageCustomOptions *>()->insertCustomOptions(optionsList);
181   }
182 }
183 
184 
saveCustomOptions()185 void Smb4KConfigDialog::saveCustomOptions()
186 {
187   if (m_custom_options)
188   {
189     QList<OptionsPtr> optionsList = Smb4KCustomOptionsManager::self()->customOptions(true);
190     QList<OptionsPtr> editedOptionsList = m_custom_options->widget()->findChild<Smb4KConfigPageCustomOptions *>()->getCustomOptions();
191 
192     while (!optionsList.isEmpty())
193     {
194       OptionsPtr options = optionsList.takeFirst();
195       bool foundOptions = false;
196 
197       for (const OptionsPtr &editedOptions : qAsConst(editedOptionsList))
198       {
199         if (editedOptions->url().matches(options->url(), QUrl::RemoveUserInfo|QUrl::RemovePort))
200         {
201           // We do not need to update the custom options, because we are
202           // using QSharedPointers.
203           foundOptions = true;
204           break;
205         }
206       }
207 
208       if (!foundOptions)
209       {
210         Smb4KCustomOptionsManager::self()->removeCustomOptions(options);
211       }
212     }
213 
214     Smb4KCustomOptionsManager::self()->saveCustomOptions();
215   }
216 }
217 
218 
propagateProfilesChanges()219 void Smb4KConfigDialog::propagateProfilesChanges()
220 {
221   Smb4KConfigPageProfiles *profiles_page = m_profiles->widget()->findChild<Smb4KConfigPageProfiles *>();
222 
223   if (profiles_page)
224   {
225     // Remove the profiles.
226     QStringList removed_profiles = profiles_page->removedProfiles();
227 
228     if (!removed_profiles.isEmpty())
229     {
230       Smb4KProfileManager::self()->removeProfiles(removed_profiles);
231       profiles_page->clearRemovedProfiles();
232     }
233 
234     // Rename the profiles.
235     QList< QPair<QString,QString> > renamed_profiles = profiles_page->renamedProfiles();
236 
237     if (!renamed_profiles.isEmpty())
238     {
239       Smb4KProfileManager::self()->migrateProfiles(renamed_profiles);
240       profiles_page->clearRenamedProfiles();
241     }
242 
243     // Finally reload the custom options.
244     if (!removed_profiles.isEmpty() || !renamed_profiles.isEmpty())
245     {
246       loadCustomOptions();
247     }
248   }
249 }
250 
251 
checkNetworkPage()252 bool Smb4KConfigDialog::checkNetworkPage()
253 {
254   QRadioButton *query_custom_master = m_network->widget()->findChild<QRadioButton *>("kcfg_QueryCustomMaster");
255   KLineEdit *custom_master_input    = m_network->widget()->findChild<KLineEdit *>("kcfg_CustomMasterBrowser");
256 
257   QString msg = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
258 
259   if ((query_custom_master && query_custom_master->isChecked()) &&
260       (custom_master_input && custom_master_input->text().trimmed().isEmpty()))
261   {
262     KMessageBox::sorry(this, msg);
263     setCurrentPage(m_network);
264     custom_master_input->setFocus();
265     return false;
266   }
267 
268   QRadioButton *scan_bcast_areas = m_network->widget()->findChild<QRadioButton *>("kcfg_ScanBroadcastAreas");
269   KLineEdit *bcast_areas_input   = m_network->widget()->findChild<KLineEdit *>("kcfg_BroadcastAreas");
270 
271   if ((scan_bcast_areas && scan_bcast_areas->isChecked()) &&
272       (bcast_areas_input && bcast_areas_input->text().trimmed().isEmpty()))
273   {
274     KMessageBox::sorry(this, msg);
275     setCurrentPage(m_network);
276     bcast_areas_input->setFocus();
277     return false;
278   }
279 
280   return true;
281 }
282 
283 
checkMountingPage()284 bool Smb4KConfigDialog::checkMountingPage()
285 {
286   KUrlRequester *mount_prefix = m_mounting->widget()->findChild<KUrlRequester *>("kcfg_MountPrefix");
287 
288   QString msg = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
289 
290   if (mount_prefix && mount_prefix->url().path().trimmed().isEmpty())
291   {
292     KMessageBox::sorry(this, msg);
293     setCurrentPage(m_mounting);
294     mount_prefix->setFocus();
295     return false;
296   }
297 
298   KLineEdit *file_mask = m_mounting->widget()->findChild<KLineEdit *>("kcfg_FileMask");
299 
300   msg = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
301 
302   if (file_mask && file_mask->text().trimmed().isEmpty())
303   {
304     KMessageBox::sorry(this, msg);
305     setCurrentPage(m_mounting);
306     file_mask->setFocus();
307     return false;
308   }
309 
310   KLineEdit *directory_mask = m_mounting->widget()->findChild<KLineEdit *>("kcfg_DirectoryMask");
311 
312   if (directory_mask && directory_mask->text().trimmed().isEmpty())
313   {
314     KMessageBox::sorry(this, msg);
315     setCurrentPage(m_mounting);
316     directory_mask->setFocus();
317     return false;
318   }
319 
320   return true;
321 }
322 
323 
checkSynchronizationPage()324 bool Smb4KConfigDialog::checkSynchronizationPage()
325 {
326   //
327   // Get the config page
328   // Since the config page is embedded into a scroll area, use findChild() here.
329   //
330   Smb4KConfigPageSynchronization *configPage = m_synchronization->widget()->findChild<Smb4KConfigPageSynchronization *>();
331 
332   if (configPage)
333   {
334     //
335     // The error message
336     //
337     QString errorMessage = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
338 
339     // Find the tab number and the url requester
340     for (int i = 0; i < configPage->count(); i++)
341     {
342       // Synchronization prefix
343       KUrlRequester *syncPrefix = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_RsyncPrefix");
344 
345       if (syncPrefix && (!syncPrefix->url().isValid() || syncPrefix->url().path().trimmed().isEmpty()))
346       {
347         KMessageBox::sorry(this, errorMessage);
348         setCurrentPage(m_synchronization);
349         configPage->setCurrentIndex(i);
350         syncPrefix->setFocus();
351         return false;
352       }
353 
354       // Backups
355       QCheckBox *makeBackups = configPage->widget(i)->findChild<QCheckBox *>("kcfg_MakeBackups");
356       QCheckBox *useBackupSuffix = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseBackupSuffix");
357       KLineEdit *backupSuffix = configPage->widget(i)->findChild<KLineEdit *>("kcfg_BackupSuffix");
358       QCheckBox *useBackupDir = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseBackupDirectory");
359       KUrlRequester *backupDir = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_BackupDirectory");
360 
361       if (makeBackups && makeBackups->isChecked())
362       {
363         if (useBackupSuffix && useBackupSuffix->isChecked())
364         {
365           if (backupSuffix && backupSuffix->text().trimmed().isEmpty())
366           {
367             KMessageBox::sorry(this, errorMessage);
368             setCurrentPage(m_synchronization);
369             configPage->setCurrentIndex(i);
370             backupSuffix->setFocus();
371             return false;
372           }
373         }
374 
375         if (useBackupDir && useBackupDir->isChecked())
376         {
377           if (backupDir && (!backupDir->url().isValid() || backupDir->url().path().trimmed().isEmpty()))
378           {
379             KMessageBox::sorry(this, errorMessage);
380             setCurrentPage(m_synchronization);
381             configPage->setCurrentIndex(i);
382             backupDir->setFocus();
383             return false;
384           }
385         }
386       }
387 
388       // Minimal transfer size
389       QCheckBox *useMinTransferSize = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseMinimalTransferSize");
390       QSpinBox *minTransferSize = configPage->widget(i)->findChild<QSpinBox *>("kcfg_MinimalTransferSize");
391 
392       if (useMinTransferSize && useMinTransferSize->isChecked())
393       {
394         if (minTransferSize && minTransferSize->value() == 0)
395         {
396           KMessageBox::sorry(this, errorMessage);
397           setCurrentPage(m_synchronization);
398           configPage->setCurrentIndex(i);
399           minTransferSize->setFocus();
400           return false;
401         }
402       }
403 
404       // Maximal transfer size
405       QCheckBox *useMaxTransferSize = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseMaximalTransferSize");
406       QSpinBox *maxTransferSize = configPage->widget(i)->findChild<QSpinBox *>("kcfg_MaximalTransferSize");
407 
408       if (useMaxTransferSize && useMaxTransferSize->isChecked())
409       {
410         if (maxTransferSize && maxTransferSize->value() == 0)
411         {
412           KMessageBox::sorry(this, errorMessage);
413           setCurrentPage(m_synchronization);
414           configPage->setCurrentIndex(i);
415           maxTransferSize->setFocus();
416           return false;
417         }
418       }
419 
420       // Partial directory
421       QCheckBox *usePartialDirectory = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UsePartialDirectory");
422       KUrlRequester *partialDirectory = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_PartialDirectory");
423 
424       if (usePartialDirectory && usePartialDirectory->isChecked())
425       {
426         if (partialDirectory && (!partialDirectory->url().isValid() || partialDirectory->url().path().trimmed().isEmpty()))
427         {
428           KMessageBox::sorry(this, errorMessage);
429           setCurrentPage(m_synchronization);
430           configPage->setCurrentIndex(i);
431           partialDirectory->setFocus();
432           return false;
433         }
434       }
435 
436       // Exclude exclude
437       QCheckBox *useExcludePattern = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseExcludePattern");
438       KLineEdit *excludePattern = configPage->widget(i)->findChild<KLineEdit *>("kcfg_ExcludePattern");
439 
440       if (useExcludePattern && useExcludePattern->isChecked())
441       {
442         if (excludePattern && excludePattern->text().trimmed().isEmpty())
443         {
444           KMessageBox::sorry(this, errorMessage);
445           setCurrentPage(m_synchronization);
446           configPage->setCurrentIndex(i);
447           excludePattern->setFocus();
448           return false;
449         }
450       }
451 
452       // Read exclude pattern from file
453       QCheckBox *useExcludeFrom = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseExcludeFrom");
454       KUrlRequester *excludeFrom = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_ExcludeFrom");
455 
456       if (useExcludeFrom && useExcludeFrom->isChecked())
457       {
458         if (excludeFrom && (!excludeFrom->url().isValid() || excludeFrom->url().path().trimmed().isEmpty()))
459         {
460           KMessageBox::sorry(this, errorMessage);
461           setCurrentPage(m_synchronization);
462           configPage->setCurrentIndex(i);
463           excludeFrom->setFocus();
464           return false;
465         }
466       }
467 
468       // Exclude exclude
469       QCheckBox *useIncludePattern = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseIncludePattern");
470       KLineEdit *includePattern = configPage->widget(i)->findChild<KLineEdit *>("kcfg_IncludePattern");
471 
472       if (useIncludePattern && useIncludePattern->isChecked())
473       {
474         if (includePattern && includePattern->text().trimmed().isEmpty())
475         {
476           KMessageBox::sorry(this, errorMessage);
477           setCurrentPage(m_synchronization);
478           configPage->setCurrentIndex(i);
479           includePattern->setFocus();
480           return false;
481         }
482       }
483 
484       // Read exclude pattern from file
485       QCheckBox *useIncludeFrom = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseIncludeFrom");
486       KUrlRequester *includeFrom = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_IncludeFrom");
487 
488       if (useIncludeFrom && useIncludeFrom->isChecked())
489       {
490         if (includeFrom && (!includeFrom->url().isValid() || includeFrom->url().path().trimmed().isEmpty()))
491         {
492           KMessageBox::sorry(this, errorMessage);
493           setCurrentPage(m_synchronization);
494           configPage->setCurrentIndex(i);
495           includeFrom->setFocus();
496           return false;
497         }
498       }
499 
500       // Block size
501       QCheckBox *useFixedBlocksize = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseBlockSize");
502       QSpinBox *fixedBlocksize = configPage->widget(i)->findChild<QSpinBox *>("kcfg_BlockSize");
503 
504       if (useFixedBlocksize && useFixedBlocksize->isChecked())
505       {
506         if (fixedBlocksize && fixedBlocksize->value() == 0)
507         {
508           KMessageBox::sorry(this, errorMessage);
509           setCurrentPage(m_synchronization);
510           configPage->setCurrentIndex(i);
511           fixedBlocksize->setFocus();
512           return false;
513         }
514       }
515 
516       // NOTE: The is no need to check the following settings, because they may be empty or 0:
517       // - kcfg_UseCompressionLevel & kcfg_CompressionLevel
518       // - kcfg_UseSkipCompression & kcfg_SkipCompression
519       // - kcfg_UseBandwidthLimit & kcfg_BandwidthLimit
520       // - kcfg_UseMaximumDelete & kcfg_MaximumDeleteValue
521       // - kcfg_CustomFilteringRules
522       // - kcfg_UseChecksumSeed & kcfg_ChecksumSeed
523     }
524   }
525 
526   return true;
527 }
528 
529 
530 
checkSettings()531 bool Smb4KConfigDialog::checkSettings()
532 {
533   // Check Network page
534   if (!checkNetworkPage())
535   {
536     return false;
537   }
538 
539   // Check Mounting page
540   if (!checkMountingPage())
541   {
542     return false;
543   }
544 
545   // Check Synchronization page
546   if (!checkSynchronizationPage())
547   {
548     return false;
549   }
550 
551   return true;
552 }
553 
554 
555 /////////////////////////////////////////////////////////////////////////////
556 // SLOT IMPLEMENTATIONS
557 /////////////////////////////////////////////////////////////////////////////
558 
559 
updateSettings()560 void Smb4KConfigDialog::updateSettings()
561 {
562   saveCustomOptions();
563   slotSaveAuthenticationInformation();
564   propagateProfilesChanges();
565   (void)checkSettings();
566 
567   KConfigGroup group(Smb4KSettings::self()->config(), "ConfigDialog");
568   KWindowConfig::saveWindowSize(windowHandle(), group);
569 
570   KConfigDialog::updateSettings();
571 }
572 
573 
updateWidgets()574 void Smb4KConfigDialog::updateWidgets()
575 {
576   loadCustomOptions();
577 
578   KConfigDialog::updateWidgets();
579 }
580 
581 
reject()582 void Smb4KConfigDialog::reject()
583 {
584   Smb4KCustomOptionsManager::self()->resetCustomOptions();
585   QDialog::reject();
586 }
587 
588 
slotLoadAuthenticationInformation()589 void Smb4KConfigDialog::slotLoadAuthenticationInformation()
590 {
591   //
592   // Get the Authentication config page
593   //
594   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
595 
596   //
597   // Insert and display the wallet entries
598   //
599   authenticationPage->insertWalletEntries(Smb4KWalletManager::self()->walletEntries());
600 }
601 
602 
slotSaveAuthenticationInformation()603 void Smb4KConfigDialog::slotSaveAuthenticationInformation()
604 {
605   //
606   // Get the Authentication config page
607   //
608   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
609 
610   //
611   // Save the authentication information to the wallet
612   //
613   if (authenticationPage->walletEntriesDisplayed())
614   {
615     Smb4KWalletManager::self()->writeWalletEntries(authenticationPage->getWalletEntries());
616   }
617 }
618 
619 
slotSetDefaultLogin()620 void Smb4KConfigDialog::slotSetDefaultLogin()
621 {
622   //
623   // Get the Authentication config page
624   //
625   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
626 
627   //
628   // Create an authentication object for the default authentication information
629   //
630   Smb4KAuthInfo authInfo;
631 
632   //
633   // Read the default authentication information
634   //
635   Smb4KWalletManager::self()->readDefaultAuthInfo(&authInfo);
636 
637   //
638   // Show the password dialog to enter or modify the default authentication
639   // information.
640   //
641   QPointer<KPasswordDialog> dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine);
642   dlg->setPrompt(i18n("Enter the default login information."));
643   dlg->setUsername(authInfo.userName());
644   dlg->setPassword(authInfo.password());
645 
646   if (dlg->exec() == KPasswordDialog::Accepted)
647   {
648     //
649     // Save the authentication information to the wallet
650     //
651     authInfo.setUserName(dlg->username());
652     authInfo.setPassword(dlg->password());
653 
654     Smb4KWalletManager::self()->writeDefaultAuthInfo(&authInfo);
655 
656     //
657     // Reload the list of authentication information
658     //
659     if (authenticationPage->walletEntriesDisplayed())
660     {
661       slotLoadAuthenticationInformation();
662     }
663   }
664   else
665   {
666     //
667     // Discard the password dialog and reset the checkbox
668     //
669     authenticationPage->findChild<QCheckBox *>("kcfg_UseDefaultLogin")->setChecked(false);
670   }
671 
672   delete dlg;
673 }
674 
675 
slotEnableApplyButton()676 void Smb4KConfigDialog::slotEnableApplyButton()
677 {
678   //
679   // Check if we need to enable the Apply button
680   //
681   bool enable = false;
682 
683   //
684   // Check the wallet entries
685   //
686   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
687 
688   if (authenticationPage->walletEntriesMaybeChanged())
689   {
690     QList<Smb4KAuthInfo *> oldWalletEntries = Smb4KWalletManager::self()->walletEntries();
691     QList<Smb4KAuthInfo *> newWalletEntries = authenticationPage->getWalletEntries();
692 
693     for (Smb4KAuthInfo *oldEntry : oldWalletEntries)
694     {
695       for (Smb4KAuthInfo *newEntry : newWalletEntries)
696       {
697         if (QString::compare(oldEntry->url().toString(QUrl::RemovePort), newEntry->url().toString(QUrl::RemovePort), Qt::CaseInsensitive) == 0 /* leave the user info here */ &&
698             QString::compare(oldEntry->workgroupName(), newEntry->workgroupName(), Qt::CaseInsensitive) == 0)
699         {
700           enable = true;
701           break;
702         }
703       }
704 
705       if (enable)
706       {
707         break;
708       }
709     }
710   }
711 
712   //
713   // Check the custom options
714   //
715   Smb4KConfigPageCustomOptions *customOptionsPage = m_custom_options->widget()->findChild<Smb4KConfigPageCustomOptions *>();
716 
717   if (!enable && customOptionsPage && customOptionsPage->customSettingsMaybeChanged())
718   {
719     enable = true;
720   }
721 
722   QPushButton *applyButton = buttonBox()->button(QDialogButtonBox::Apply);
723 
724   if (applyButton)
725   {
726     applyButton->setEnabled(enable);
727   }
728 }
729 
730 
slotCheckPage(KPageWidgetItem *,KPageWidgetItem * before)731 void Smb4KConfigDialog::slotCheckPage(KPageWidgetItem* /*current*/, KPageWidgetItem* before)
732 {
733   if (before == m_network)
734   {
735     (void)checkNetworkPage();
736   }
737   else if (before == m_mounting)
738   {
739     (void)checkMountingPage();
740   }
741   else if (before == m_synchronization)
742   {
743     (void)checkSynchronizationPage();
744   }
745 }
746 
747 #include "smb4kconfigdialog.moc"
748