File indexing completed on 2024-07-14 15:13:52

0001 /***************************************************************************
0002     The configuration dialog of Smb4K
0003                              -------------------
0004     begin                : Sa Apr 14 2007
0005     copyright            : (C) 2004-2019 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 #ifdef HAVE_CONFIG_H
0027 #include <config.h>
0028 #endif
0029 
0030 // application specific includes
0031 #include "smb4kconfigdialog.h"
0032 #include "smb4kconfigpageauthentication.h"
0033 #include "smb4kconfigpagecustomoptions.h"
0034 #include "smb4kconfigpagemounting.h"
0035 #include "smb4kconfigpagenetwork.h"
0036 #include "smb4kconfigpageprofiles.h"
0037 #include "smb4kconfigpagesynchronization.h"
0038 #include "smb4kconfigpageuserinterface.h"
0039 #include "core/smb4ksettings.h"
0040 #include "core/smb4kglobal.h"
0041 #include "core/smb4kauthinfo.h"
0042 #include "core/smb4kwalletmanager.h"
0043 #include "core/smb4kcustomoptions.h"
0044 #include "core/smb4kcustomoptionsmanager.h"
0045 #include "core/smb4kprofilemanager.h"
0046 
0047 #if defined(Q_OS_LINUX)
0048 #include "smb4kmountsettings_linux.h"
0049 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
0050 #include "smb4kmountsettings_bsd.h"
0051 #endif
0052 
0053 // Qt includes
0054 #include <QPointer>
0055 #include <QPair>
0056 #include <QList>
0057 #include <QSize>
0058 #include <QStandardPaths>
0059 #include <QRadioButton>
0060 #include <QCheckBox>
0061 #include <QTreeWidget>
0062 #include <QScrollArea>
0063 #include <QShowEvent>
0064 #include <QWindow>
0065 
0066 // KDE includes
0067 #include <KCoreAddons/KPluginFactory>
0068 #include <KI18n/KLocalizedString>
0069 #include <KConfigGui/KWindowConfig>
0070 #include <KWidgetsAddons/KMessageBox>
0071 #include <KWidgetsAddons/KPasswordDialog>
0072 #include <KIOWidgets/KUrlRequester>
0073 
0074 using namespace Smb4KGlobal;
0075 
0076 K_PLUGIN_FACTORY(Smb4KConfigDialogFactory, registerPlugin<Smb4KConfigDialog>();)
0077 
0078 
0079 Smb4KConfigDialog::Smb4KConfigDialog(QWidget *parent, const QList<QVariant> &/*args*/)
0080 : KConfigDialog(parent, "ConfigDialog", Smb4KSettings::self())
0081 {
0082   setupDialog();
0083 }
0084 
0085 
0086 Smb4KConfigDialog::~Smb4KConfigDialog()
0087 {
0088 }
0089 
0090 
0091 void Smb4KConfigDialog::setupDialog()
0092 {
0093   // FIXME: I guess, normally we would not need to close destructively,
0094   // but at the moment there are issues with the KURLRequester in file
0095   // mode. To work around those, we are closing the dialog destructively.
0096   // Maybe we can remove this if we moved to KDE4.
0097   setAttribute(Qt::WA_DeleteOnClose, true);
0098 
0099   // Add the pages:
0100   Smb4KConfigPageUserInterface *interface_options = new Smb4KConfigPageUserInterface(this);
0101   QScrollArea *interface_area = new QScrollArea(this);
0102   interface_area->setWidget(interface_options);
0103   interface_area->setWidgetResizable(true);
0104   interface_area->setFrameStyle(QFrame::NoFrame);
0105 
0106   Smb4KConfigPageNetwork *network_options = new Smb4KConfigPageNetwork(this);
0107   QScrollArea *network_area = new QScrollArea(this);
0108   network_area->setWidget(network_options);
0109   network_area->setWidgetResizable(true);
0110   network_area->setFrameStyle(QFrame::NoFrame);
0111   
0112   Smb4KConfigPageMounting *mount_options = new Smb4KConfigPageMounting(this);
0113   QScrollArea *mount_area = new QScrollArea(this);
0114   mount_area->setWidget(mount_options);
0115   mount_area->setWidgetResizable(true);
0116   mount_area->setFrameStyle(QFrame::NoFrame);
0117 
0118   Smb4KConfigPageAuthentication *auth_options = new Smb4KConfigPageAuthentication(this);
0119   QScrollArea *auth_area = new QScrollArea(this);
0120   auth_area->setWidget(auth_options);
0121   auth_area->setWidgetResizable(true);
0122   auth_area->setFrameStyle(QFrame::NoFrame);
0123 
0124   Smb4KConfigPageSynchronization *rsync_options = new Smb4KConfigPageSynchronization(this);
0125   QScrollArea *rsync_area = new QScrollArea(this);
0126   rsync_area->setWidget(rsync_options);
0127   rsync_area->setWidgetResizable(true);
0128   rsync_area->setFrameStyle(QFrame::NoFrame);
0129   
0130   rsync_options->setEnabled(!QStandardPaths::findExecutable("rsync").isEmpty());
0131 
0132   Smb4KConfigPageCustomOptions *custom_options = new Smb4KConfigPageCustomOptions(this);
0133   QScrollArea *custom_area = new QScrollArea(this);
0134   custom_area->setWidget(custom_options);
0135   custom_area->setWidgetResizable(true);
0136   custom_area->setFrameStyle(QFrame::NoFrame);
0137   
0138   Smb4KConfigPageProfiles *profiles_page = new Smb4KConfigPageProfiles(this);
0139   QScrollArea *profiles_area = new QScrollArea(this);
0140   profiles_area->setWidget(profiles_page);
0141   profiles_area->setWidgetResizable(true);
0142   profiles_area->setFrameStyle(QFrame::NoFrame);
0143 
0144   // 
0145   // Pages to the configuration dialog
0146   // 
0147   m_user_interface  = addPage(interface_area, Smb4KSettings::self(), i18n("User Interface"), "preferences-desktop");
0148   m_network         = addPage(network_area, Smb4KSettings::self(), i18n("Network"), "network-workgroup");
0149   m_mounting        = addPage(mount_area, Smb4KMountSettings::self(), i18n("Mounting"), "system-run");
0150   m_authentication  = addPage(auth_area, Smb4KSettings::self(), i18n("Authentication"), "dialog-password");
0151   m_synchronization = addPage(rsync_area, Smb4KSettings::self(),i18n("Synchronization"), "folder-sync");
0152   m_custom_options  = addPage(custom_area, Smb4KSettings::self(), i18n("Custom Options"), "preferences-system-network");
0153   m_profiles        = addPage(profiles_area, Smb4KSettings::self(), i18n("Profiles"), "format-list-unordered");
0154 
0155   // 
0156   // Connections
0157   // 
0158   connect(custom_options, SIGNAL(customSettingsModified()), this, SLOT(slotEnableApplyButton()));
0159 
0160   connect(auth_options, SIGNAL(loadWalletEntries()), this, SLOT(slotLoadAuthenticationInformation()));
0161   connect(auth_options, SIGNAL(saveWalletEntries()), this, SLOT(slotSaveAuthenticationInformation()));
0162   connect(auth_options, SIGNAL(setDefaultLogin()), this, SLOT(slotSetDefaultLogin()));
0163   connect(auth_options, SIGNAL(walletEntriesModified()), this, SLOT(slotEnableApplyButton()));
0164   
0165   connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotCheckPage(KPageWidgetItem*,KPageWidgetItem*)));
0166   
0167   //
0168   // Dialog size
0169   //
0170   create();
0171   windowHandle()->resize(QSize(800, 600));
0172 
0173   KConfigGroup group(Smb4KSettings::self()->config(), "ConfigDialog");
0174   KWindowConfig::restoreWindowSize(windowHandle(), group);
0175   resize(windowHandle()->size()); // workaround for QTBUG-40584
0176 }
0177 
0178 
0179 void Smb4KConfigDialog::loadCustomOptions()
0180 {
0181   if (m_custom_options)
0182   {
0183     QList<OptionsPtr> options = Smb4KCustomOptionsManager::self()->customOptions();
0184     m_custom_options->widget()->findChild<Smb4KConfigPageCustomOptions *>()->insertCustomOptions(options);
0185   }
0186 }
0187 
0188 
0189 void Smb4KConfigDialog::saveCustomOptions()
0190 {
0191   if (m_custom_options)
0192   {
0193     QList<OptionsPtr> options = m_custom_options->widget()->findChild<Smb4KConfigPageCustomOptions *>()->getCustomOptions();
0194     Smb4KCustomOptionsManager::self()->replaceCustomOptions(options);
0195   }
0196 }
0197 
0198 
0199 void Smb4KConfigDialog::propagateProfilesChanges()
0200 {
0201   Smb4KConfigPageProfiles *profiles_page = m_profiles->widget()->findChild<Smb4KConfigPageProfiles *>();
0202   
0203   if (profiles_page)
0204   {
0205     // Remove the profiles.
0206     QStringList removed_profiles = profiles_page->removedProfiles();
0207     
0208     if (!removed_profiles.isEmpty())
0209     {
0210       Smb4KProfileManager::self()->removeProfiles(removed_profiles);
0211       profiles_page->clearRemovedProfiles();
0212     }
0213     
0214     // Rename the profiles.
0215     QList< QPair<QString,QString> > renamed_profiles = profiles_page->renamedProfiles();
0216     
0217     if (!renamed_profiles.isEmpty())
0218     {
0219       Smb4KProfileManager::self()->migrateProfiles(renamed_profiles);
0220       profiles_page->clearRenamedProfiles();
0221     }
0222     
0223     // Finally reload the custom options.
0224     if (!removed_profiles.isEmpty() || !renamed_profiles.isEmpty())
0225     {
0226       loadCustomOptions();
0227     }
0228   }
0229 }
0230 
0231 
0232 bool Smb4KConfigDialog::checkNetworkPage()
0233 {
0234   QRadioButton *query_custom_master = m_network->widget()->findChild<QRadioButton *>("kcfg_QueryCustomMaster");
0235   KLineEdit *custom_master_input    = m_network->widget()->findChild<KLineEdit *>("kcfg_CustomMasterBrowser");
0236   
0237   QString msg = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
0238 
0239   if ((query_custom_master && query_custom_master->isChecked()) &&
0240       (custom_master_input && custom_master_input->text().trimmed().isEmpty()))
0241   {
0242     KMessageBox::sorry(this, msg);
0243     setCurrentPage(m_network);
0244     custom_master_input->setFocus();
0245     return false;
0246   }
0247   
0248   QRadioButton *scan_bcast_areas = m_network->widget()->findChild<QRadioButton *>("kcfg_ScanBroadcastAreas");
0249   KLineEdit *bcast_areas_input   = m_network->widget()->findChild<KLineEdit *>("kcfg_BroadcastAreas");
0250   
0251   if ((scan_bcast_areas && scan_bcast_areas->isChecked()) &&
0252       (bcast_areas_input && bcast_areas_input->text().trimmed().isEmpty()))
0253   {
0254     KMessageBox::sorry(this, msg);
0255     setCurrentPage(m_network);
0256     bcast_areas_input->setFocus();
0257     return false;
0258   }
0259   
0260   return true;
0261 }
0262 
0263 
0264 bool Smb4KConfigDialog::checkMountingPage()
0265 {
0266   KUrlRequester *mount_prefix = m_mounting->widget()->findChild<KUrlRequester *>("kcfg_MountPrefix");
0267   
0268   QString msg = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
0269   
0270   if (mount_prefix && mount_prefix->url().path().trimmed().isEmpty())
0271   {
0272     KMessageBox::sorry(this, msg);
0273     setCurrentPage(m_mounting);
0274     mount_prefix->setFocus();
0275     return false;
0276   }
0277   
0278   KLineEdit *file_mask = m_mounting->widget()->findChild<KLineEdit *>("kcfg_FileMask");
0279   
0280   msg = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
0281   
0282   if (file_mask && file_mask->text().trimmed().isEmpty())
0283   {
0284     KMessageBox::sorry(this, msg);
0285     setCurrentPage(m_mounting);
0286     file_mask->setFocus();
0287     return false;
0288   }
0289   
0290   KLineEdit *directory_mask = m_mounting->widget()->findChild<KLineEdit *>("kcfg_DirectoryMask");
0291   
0292   if (directory_mask && directory_mask->text().trimmed().isEmpty())
0293   {
0294     KMessageBox::sorry(this, msg);
0295     setCurrentPage(m_mounting);
0296     directory_mask->setFocus();
0297     return false;
0298   }
0299   
0300   return true;
0301 }
0302 
0303 
0304 bool Smb4KConfigDialog::checkSynchronizationPage()
0305 {
0306   //
0307   // Get the config page 
0308   // Since the config page is embedded into a scroll area, use findChild() here.
0309   // 
0310   Smb4KConfigPageSynchronization *configPage = m_synchronization->widget()->findChild<Smb4KConfigPageSynchronization *>();
0311   
0312   if (configPage)
0313   {
0314     //
0315     // The error message
0316     // 
0317     QString errorMessage = i18n("<qt>An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it.</qt>");
0318     
0319     // Find the tab number and the url requester
0320     for (int i = 0; i < configPage->count(); i++)
0321     {
0322       // Synchronization prefix
0323       KUrlRequester *syncPrefix = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_RsyncPrefix");
0324       
0325       if (syncPrefix && (!syncPrefix->url().isValid() || syncPrefix->url().path().trimmed().isEmpty()))
0326       {
0327         KMessageBox::sorry(this, errorMessage);
0328         setCurrentPage(m_synchronization);
0329         configPage->setCurrentIndex(i);
0330         syncPrefix->setFocus();
0331         return false;
0332       }
0333     
0334       // Backups
0335       QCheckBox *makeBackups = configPage->widget(i)->findChild<QCheckBox *>("kcfg_MakeBackups");
0336       QCheckBox *useBackupSuffix = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseBackupSuffix");
0337       KLineEdit *backupSuffix = configPage->widget(i)->findChild<KLineEdit *>("kcfg_BackupSuffix");
0338       QCheckBox *useBackupDir = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseBackupDirectory");
0339       KUrlRequester *backupDir = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_BackupDirectory");
0340       
0341       if (makeBackups && makeBackups->isChecked())
0342       {
0343         if (useBackupSuffix && useBackupSuffix->isChecked())
0344         {
0345           if (backupSuffix && backupSuffix->text().trimmed().isEmpty())
0346           {
0347             KMessageBox::sorry(this, errorMessage);
0348             setCurrentPage(m_synchronization);
0349             configPage->setCurrentIndex(i);
0350             backupSuffix->setFocus();
0351             return false;
0352           }
0353         }
0354         
0355         if (useBackupDir && useBackupDir->isChecked())
0356         {
0357           if (backupDir && (!backupDir->url().isValid() || backupDir->url().path().trimmed().isEmpty()))
0358           {
0359             KMessageBox::sorry(this, errorMessage);
0360             setCurrentPage(m_synchronization);
0361             configPage->setCurrentIndex(i);
0362             backupDir->setFocus();
0363             return false;
0364           }
0365         }
0366       }
0367       
0368       // Minimal transfer size
0369       QCheckBox *useMinTransferSize = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseMinimalTransferSize");
0370       QSpinBox *minTransferSize = configPage->widget(i)->findChild<QSpinBox *>("kcfg_MinimalTransferSize");
0371       
0372       if (useMinTransferSize && useMinTransferSize->isChecked())
0373       {
0374         if (minTransferSize && minTransferSize->value() == 0)
0375         {
0376           KMessageBox::sorry(this, errorMessage);
0377           setCurrentPage(m_synchronization);
0378           configPage->setCurrentIndex(i);
0379           minTransferSize->setFocus();
0380           return false;
0381         }
0382       }
0383 
0384       // Maximal transfer size
0385       QCheckBox *useMaxTransferSize = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseMaximalTransferSize");
0386       QSpinBox *maxTransferSize = configPage->widget(i)->findChild<QSpinBox *>("kcfg_MaximalTransferSize");
0387       
0388       if (useMaxTransferSize && useMaxTransferSize->isChecked())
0389       {
0390         if (maxTransferSize && maxTransferSize->value() == 0)
0391         {
0392           KMessageBox::sorry(this, errorMessage);
0393           setCurrentPage(m_synchronization);
0394           configPage->setCurrentIndex(i);
0395           maxTransferSize->setFocus();
0396           return false;
0397         }
0398       }
0399       
0400       // Partial directory
0401       QCheckBox *usePartialDirectory = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UsePartialDirectory");
0402       KUrlRequester *partialDirectory = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_PartialDirectory");
0403       
0404       if (usePartialDirectory && usePartialDirectory->isChecked())
0405       {
0406         if (partialDirectory && (!partialDirectory->url().isValid() || partialDirectory->url().path().trimmed().isEmpty()))
0407         {
0408           KMessageBox::sorry(this, errorMessage);
0409           setCurrentPage(m_synchronization);
0410           configPage->setCurrentIndex(i);
0411           partialDirectory->setFocus();
0412           return false;
0413         }
0414       }
0415       
0416       // Exclude exclude
0417       QCheckBox *useExcludePattern = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseExcludePattern");
0418       KLineEdit *excludePattern = configPage->widget(i)->findChild<KLineEdit *>("kcfg_ExcludePattern");
0419       
0420       if (useExcludePattern && useExcludePattern->isChecked())
0421       {
0422         if (excludePattern && excludePattern->text().trimmed().isEmpty())
0423         {
0424           KMessageBox::sorry(this, errorMessage);
0425           setCurrentPage(m_synchronization);
0426           configPage->setCurrentIndex(i);
0427           excludePattern->setFocus();
0428           return false;
0429         }
0430       }
0431       
0432       // Read exclude pattern from file
0433       QCheckBox *useExcludeFrom = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseExcludeFrom");
0434       KUrlRequester *excludeFrom = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_ExcludeFrom");
0435       
0436       if (useExcludeFrom && useExcludeFrom->isChecked())
0437       {
0438         if (excludeFrom && (!excludeFrom->url().isValid() || excludeFrom->url().path().trimmed().isEmpty()))
0439         {
0440           KMessageBox::sorry(this, errorMessage);
0441           setCurrentPage(m_synchronization);
0442           configPage->setCurrentIndex(i);
0443           excludeFrom->setFocus();
0444           return false;
0445         }
0446       }
0447       
0448       // Exclude exclude
0449       QCheckBox *useIncludePattern = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseIncludePattern");
0450       KLineEdit *includePattern = configPage->widget(i)->findChild<KLineEdit *>("kcfg_IncludePattern");
0451       
0452       if (useIncludePattern && useIncludePattern->isChecked())
0453       {
0454         if (includePattern && includePattern->text().trimmed().isEmpty())
0455         {
0456           KMessageBox::sorry(this, errorMessage);
0457           setCurrentPage(m_synchronization);
0458           configPage->setCurrentIndex(i);
0459           includePattern->setFocus();
0460           return false;
0461         }
0462       }
0463       
0464       // Read exclude pattern from file
0465       QCheckBox *useIncludeFrom = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseIncludeFrom");
0466       KUrlRequester *includeFrom = configPage->widget(i)->findChild<KUrlRequester *>("kcfg_IncludeFrom");
0467       
0468       if (useIncludeFrom && useIncludeFrom->isChecked())
0469       {
0470         if (includeFrom && (!includeFrom->url().isValid() || includeFrom->url().path().trimmed().isEmpty()))
0471         {
0472           KMessageBox::sorry(this, errorMessage);
0473           setCurrentPage(m_synchronization);
0474           configPage->setCurrentIndex(i);
0475           includeFrom->setFocus();
0476           return false;
0477         }
0478       }
0479       
0480       // Block size
0481       QCheckBox *useFixedBlocksize = configPage->widget(i)->findChild<QCheckBox *>("kcfg_UseBlockSize");
0482       QSpinBox *fixedBlocksize = configPage->widget(i)->findChild<QSpinBox *>("kcfg_BlockSize");
0483       
0484       if (useFixedBlocksize && useFixedBlocksize->isChecked())
0485       {
0486         if (fixedBlocksize && fixedBlocksize->value() == 0)
0487         {
0488           KMessageBox::sorry(this, errorMessage);
0489           setCurrentPage(m_synchronization);
0490           configPage->setCurrentIndex(i);
0491           fixedBlocksize->setFocus();
0492           return false;
0493         }
0494       }
0495       
0496       // NOTE: The is no need to check the following settings, because they may be empty or 0:
0497       // - kcfg_UseCompressionLevel & kcfg_CompressionLevel
0498       // - kcfg_UseSkipCompression & kcfg_SkipCompression
0499       // - kcfg_UseBandwidthLimit & kcfg_BandwidthLimit
0500       // - kcfg_UseMaximumDelete & kcfg_MaximumDeleteValue
0501       // - kcfg_CustomFilteringRules
0502       // - kcfg_UseChecksumSeed & kcfg_ChecksumSeed
0503     }
0504   }
0505 
0506   return true;
0507 }
0508 
0509 
0510 
0511 bool Smb4KConfigDialog::checkSettings()
0512 {
0513   // Check Network page
0514   if (!checkNetworkPage())
0515   {
0516     return false;
0517   }
0518   
0519   // Check Mounting page
0520   if (!checkMountingPage())
0521   {
0522     return false;
0523   }
0524   
0525   // Check Synchronization page
0526   if (!checkSynchronizationPage())
0527   {
0528     return false;
0529   }
0530   
0531   return true;
0532 }
0533 
0534 
0535 /////////////////////////////////////////////////////////////////////////////
0536 // SLOT IMPLEMENTATIONS
0537 /////////////////////////////////////////////////////////////////////////////
0538 
0539 
0540 void Smb4KConfigDialog::updateSettings()
0541 {
0542   saveCustomOptions();
0543   slotSaveAuthenticationInformation();
0544   propagateProfilesChanges();
0545   (void)checkSettings();
0546   
0547   KConfigGroup group(Smb4KSettings::self()->config(), "ConfigDialog");
0548   KWindowConfig::saveWindowSize(windowHandle(), group);
0549       
0550   KConfigDialog::updateSettings();
0551 }
0552 
0553 
0554 void Smb4KConfigDialog::updateWidgets()
0555 {
0556   loadCustomOptions();
0557   
0558   KConfigDialog::updateWidgets();
0559 }
0560 
0561 
0562 void Smb4KConfigDialog::reject()
0563 {
0564   Smb4KCustomOptionsManager::self()->resetCustomOptions();
0565   QDialog::reject();
0566 }
0567 
0568 
0569 void Smb4KConfigDialog::slotLoadAuthenticationInformation()
0570 {
0571   //
0572   // Get the Authentication config page
0573   // 
0574   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
0575   
0576   //
0577   // Insert and display the wallet entries
0578   // 
0579   authenticationPage->insertWalletEntries(Smb4KWalletManager::self()->walletEntries());
0580 }
0581 
0582 
0583 void Smb4KConfigDialog::slotSaveAuthenticationInformation()
0584 {
0585   //
0586   // Get the Authentication config page
0587   // 
0588   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
0589   
0590   //
0591   // Save the authentication information to the wallet
0592   // 
0593   if (authenticationPage->walletEntriesDisplayed())
0594   {
0595     Smb4KWalletManager::self()->writeWalletEntries(authenticationPage->getWalletEntries());
0596   }
0597 }
0598 
0599 
0600 void Smb4KConfigDialog::slotSetDefaultLogin()
0601 {
0602   //
0603   // Get the Authentication config page
0604   // 
0605   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
0606   
0607   //
0608   // Create an authentication object for the default authentication information
0609   // 
0610   Smb4KAuthInfo authInfo;
0611   
0612   //
0613   // Read the default authentication information
0614   // 
0615   Smb4KWalletManager::self()->readDefaultAuthInfo(&authInfo);
0616 
0617   //
0618   // Show the password dialog to enter or modify the default authentication
0619   // information.
0620   // 
0621   QPointer<KPasswordDialog> dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine);
0622   dlg->setPrompt(i18n("Enter the default login information."));
0623   dlg->setUsername(authInfo.userName());
0624   dlg->setPassword(authInfo.password());
0625     
0626   if (dlg->exec() == KPasswordDialog::Accepted)
0627   {
0628     //
0629     // Save the authentication information to the wallet
0630     // 
0631     authInfo.setUserName(dlg->username());
0632     authInfo.setPassword(dlg->password());
0633       
0634     Smb4KWalletManager::self()->writeDefaultAuthInfo(&authInfo);
0635       
0636     //
0637     // Reload the list of authentication information
0638     // 
0639     if (authenticationPage->walletEntriesDisplayed())
0640     {
0641       slotLoadAuthenticationInformation();
0642     }
0643   }
0644   else
0645   {
0646     // 
0647     // Discard the password dialog and reset the checkbox
0648     // 
0649     authenticationPage->findChild<QCheckBox *>("kcfg_UseDefaultLogin")->setChecked(false);
0650   }
0651     
0652   delete dlg;
0653 }
0654 
0655 
0656 void Smb4KConfigDialog::slotEnableApplyButton()
0657 {
0658   // 
0659   // Check if we need to enable the Apply button
0660   // 
0661   bool enable = false;
0662   
0663   // 
0664   // Check the wallet entries
0665   // 
0666   Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild<Smb4KConfigPageAuthentication *>();
0667 
0668   if (authenticationPage->walletEntriesMaybeChanged())
0669   {
0670     QList<Smb4KAuthInfo *> oldWalletEntries = Smb4KWalletManager::self()->walletEntries();
0671     QList<Smb4KAuthInfo *> newWalletEntries = authenticationPage->getWalletEntries();
0672     
0673     for (Smb4KAuthInfo *oldEntry : oldWalletEntries)
0674     {
0675       for (Smb4KAuthInfo *newEntry : newWalletEntries)
0676       {
0677         if (QString::compare(oldEntry->url().toString(QUrl::RemovePort), newEntry->url().toString(QUrl::RemovePort), Qt::CaseInsensitive) == 0 /* leave the user info here */ &&
0678             QString::compare(oldEntry->workgroupName(), newEntry->workgroupName(), Qt::CaseInsensitive) == 0)
0679         {
0680           enable = true;
0681           break;
0682         }
0683       }
0684       
0685       if (enable)
0686       {
0687         break;
0688       }
0689     }
0690   }
0691   
0692   // 
0693   // Check the custom options
0694   // 
0695   Smb4KConfigPageCustomOptions *customOptionsPage = m_custom_options->widget()->findChild<Smb4KConfigPageCustomOptions *>();
0696   
0697   if (!enable && customOptionsPage && customOptionsPage->customSettingsMaybeChanged())
0698   {
0699     enable = true;
0700   }
0701 
0702   QPushButton *applyButton = buttonBox()->button(QDialogButtonBox::Apply);
0703   
0704   if (applyButton)
0705   {
0706     applyButton->setEnabled(enable);
0707   }
0708 }
0709 
0710 
0711 void Smb4KConfigDialog::slotCheckPage(KPageWidgetItem* /*current*/, KPageWidgetItem* before)
0712 {
0713   if (before == m_network)
0714   {
0715     (void)checkNetworkPage();
0716   }
0717   else if (before == m_mounting)
0718   {
0719     (void)checkMountingPage();
0720   }
0721   else if (before == m_synchronization)
0722   {
0723     (void)checkSynchronizationPage();
0724   }
0725 }
0726 
0727 #include "smb4kconfigdialog.moc"