File indexing completed on 2023-12-03 11:58:23

0001 /*
0002     The configuration page for the network settings of Smb4K
0003 
0004     SPDX-FileCopyrightText: 2003-2022 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 // application specific includes
0009 #include "smb4kconfigpagenetwork.h"
0010 #include "core/smb4ksettings.h"
0011 
0012 // Qt includes
0013 #include <QCheckBox>
0014 #include <QGridLayout>
0015 #include <QGroupBox>
0016 #include <QHBoxLayout>
0017 #include <QLabel>
0018 #include <QSpinBox>
0019 #include <QVBoxLayout>
0020 
0021 // KDE includes
0022 #include <KComboBox>
0023 #include <KIconLoader>
0024 #include <KLineEdit>
0025 #include <KLocalizedString>
0026 #include <KMessageWidget>
0027 
0028 Smb4KConfigPageNetwork::Smb4KConfigPageNetwork(QWidget *parent)
0029     : QTabWidget(parent)
0030 {
0031     //
0032     // Basic Settings
0033     //
0034     QWidget *basicTab = new QWidget(this);
0035     QVBoxLayout *basicTabLayout = new QVBoxLayout(basicTab);
0036 
0037     //
0038     // Browse Settings
0039     //
0040     QGroupBox *browseSettingsBox = new QGroupBox(i18n("Browse Settings"), basicTab);
0041     QVBoxLayout *browseSettingsBoxLayout = new QVBoxLayout(browseSettingsBox);
0042 
0043 #ifdef USE_WS_DISCOVERY
0044     // Use WS-Discovery
0045     QCheckBox *useWsDiscovery = new QCheckBox(Smb4KSettings::self()->useWsDiscoveryItem()->label(), browseSettingsBox);
0046     useWsDiscovery->setObjectName(QStringLiteral("kcfg_UseWsDiscovery"));
0047 
0048     browseSettingsBoxLayout->addWidget(useWsDiscovery);
0049 #endif
0050 
0051     // Use DNS-SD
0052     QCheckBox *useDnsServiceDiscovery = new QCheckBox(Smb4KSettings::self()->useDnsServiceDiscoveryItem()->label(), browseSettingsBox);
0053     useDnsServiceDiscovery->setObjectName(QStringLiteral("kcfg_UseDnsServiceDiscovery"));
0054 
0055     browseSettingsBoxLayout->addWidget(useDnsServiceDiscovery);
0056 
0057     // Force SMBv1 protocol for browsing
0058     QCheckBox *forceSmb1Protocol = new QCheckBox(Smb4KSettings::self()->forceSmb1ProtocolItem()->label(), browseSettingsBox);
0059     forceSmb1Protocol->setObjectName(QStringLiteral("kcfg_ForceSmb1Protocol"));
0060 
0061     browseSettingsBoxLayout->addWidget(forceSmb1Protocol);
0062 
0063     // Set client protocol versions
0064     QCheckBox *useClientProtocolVersions = new QCheckBox(Smb4KSettings::self()->useClientProtocolVersionsItem()->label(), browseSettingsBox);
0065     useClientProtocolVersions->setObjectName(QStringLiteral("kcfg_UseClientProtocolVersions"));
0066 
0067     browseSettingsBoxLayout->addWidget(useClientProtocolVersions);
0068 
0069     QWidget *versionsWidget = new QWidget(browseSettingsBox);
0070     QGridLayout *versionsLayout = new QGridLayout(versionsWidget);
0071     versionsLayout->setContentsMargins(0, 0, 0, 0);
0072 
0073     QLabel *minimalProtocolVersionLabel = new QLabel(Smb4KSettings::self()->minimalClientProtocolVersionItem()->label(), versionsWidget);
0074     minimalProtocolVersionLabel->setIndent(25);
0075     minimalProtocolVersionLabel->setObjectName(QStringLiteral("MinimalProtocolVersionLabel"));
0076 
0077     KComboBox *minimalProtocolVersion = new KComboBox(versionsWidget);
0078     minimalProtocolVersion->setObjectName(QStringLiteral("kcfg_MinimalClientProtocolVersion"));
0079 
0080     QList<KCoreConfigSkeleton::ItemEnum::Choice> minimalProtocolVersionChoices = Smb4KSettings::self()->minimalClientProtocolVersionItem()->choices();
0081 
0082     for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(minimalProtocolVersionChoices)) {
0083         minimalProtocolVersion->addItem(c.label);
0084     }
0085 
0086     versionsLayout->addWidget(minimalProtocolVersionLabel, 0, 0);
0087     versionsLayout->addWidget(minimalProtocolVersion, 0, 1);
0088 
0089     QLabel *maximalProtocolVersionLabel = new QLabel(Smb4KSettings::self()->maximalClientProtocolVersionItem()->label(), versionsWidget);
0090     maximalProtocolVersionLabel->setIndent(25);
0091     maximalProtocolVersionLabel->setObjectName(QStringLiteral("MaximalProtocolVersionLabel"));
0092 
0093     KComboBox *maximalProtocolVersion = new KComboBox(versionsWidget);
0094     maximalProtocolVersion->setObjectName(QStringLiteral("kcfg_MaximalClientProtocolVersion"));
0095 
0096     QList<KCoreConfigSkeleton::ItemEnum::Choice> maximalProtocolVersionChoices = Smb4KSettings::self()->maximalClientProtocolVersionItem()->choices();
0097 
0098     for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(maximalProtocolVersionChoices)) {
0099         maximalProtocolVersion->addItem(c.label);
0100     }
0101 
0102     versionsLayout->addWidget(maximalProtocolVersionLabel, 1, 0);
0103     versionsLayout->addWidget(maximalProtocolVersion, 1, 1);
0104 
0105     browseSettingsBoxLayout->addWidget(versionsWidget);
0106 
0107     basicTabLayout->addWidget(browseSettingsBox);
0108 
0109     //
0110     // Behavior
0111     //
0112     QGroupBox *behaviorBox = new QGroupBox(i18n("Behavior"), basicTab);
0113     QGridLayout *behaviorBoxLayout = new QGridLayout(behaviorBox);
0114 
0115     QCheckBox *detectPrinters = new QCheckBox(Smb4KSettings::self()->detectPrinterSharesItem()->label(), behaviorBox);
0116     detectPrinters->setObjectName(QStringLiteral("kcfg_DetectPrinterShares"));
0117 
0118     behaviorBoxLayout->addWidget(detectPrinters, 0, 0);
0119 
0120     QCheckBox *detectHiddenShares = new QCheckBox(Smb4KSettings::self()->detectHiddenSharesItem()->label(), behaviorBox);
0121     detectHiddenShares->setObjectName(QStringLiteral("kcfg_DetectHiddenShares"));
0122 
0123     behaviorBoxLayout->addWidget(detectHiddenShares, 0, 1);
0124 
0125     QCheckBox *previewHiddenItems = new QCheckBox(Smb4KSettings::self()->previewHiddenItemsItem()->label(), behaviorBox);
0126     previewHiddenItems->setObjectName(QStringLiteral("kcfg_PreviewHiddenItems"));
0127 
0128     behaviorBoxLayout->addWidget(previewHiddenItems, 1, 0);
0129 
0130     basicTabLayout->addWidget(behaviorBox);
0131     basicTabLayout->addStretch(100);
0132 
0133     addTab(basicTab, i18n("Basic Settings"));
0134 
0135     //
0136     // Advanced Settings
0137     //
0138     QWidget *advancedTab = new QWidget(this);
0139     QVBoxLayout *advancedTabLayout = new QVBoxLayout(advancedTab);
0140 
0141     //
0142     // Samba
0143     //
0144     QGroupBox *sambaBox = new QGroupBox(i18n("Samba"), advancedTab);
0145     QGridLayout *sambaBoxLayout = new QGridLayout(sambaBox);
0146 
0147     QCheckBox *useRemoteSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), sambaBox);
0148     useRemoteSmbPort->setObjectName(QStringLiteral("kcfg_UseRemoteSmbPort"));
0149 
0150     sambaBoxLayout->addWidget(useRemoteSmbPort, 0, 0);
0151 
0152     QSpinBox *remoteSmbPort = new QSpinBox(sambaBox);
0153     remoteSmbPort->setObjectName(QStringLiteral("kcfg_RemoteSmbPort"));
0154     //   remoteSmbPort->setSliderEnabled(true);
0155 
0156     sambaBoxLayout->addWidget(remoteSmbPort, 0, 1);
0157 
0158     QCheckBox *useEncryptionLevel = new QCheckBox(Smb4KSettings::self()->useEncryptionLevelItem()->label(), sambaBox);
0159     useEncryptionLevel->setObjectName(QStringLiteral("kcfg_UseEncryptionLevel"));
0160 
0161     sambaBoxLayout->addWidget(useEncryptionLevel, 1, 0);
0162 
0163     KComboBox *encryptionLevel = new KComboBox(sambaBox);
0164     encryptionLevel->setObjectName(QStringLiteral("kcfg_EncryptionLevel"));
0165 
0166     QList<KCoreConfigSkeleton::ItemEnum::Choice> encryptionLevelChoices = Smb4KSettings::self()->encryptionLevelItem()->choices();
0167 
0168     for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(encryptionLevelChoices)) {
0169         encryptionLevel->addItem(c.label);
0170     }
0171 
0172     sambaBoxLayout->addWidget(encryptionLevel, 1, 1);
0173 
0174     QCheckBox *largeNetworkNeighborhood = new QCheckBox(Smb4KSettings::self()->largeNetworkNeighborhoodItem()->label(), sambaBox);
0175     largeNetworkNeighborhood->setObjectName(QStringLiteral("kcfg_LargeNetworkNeighborhood"));
0176 
0177     sambaBoxLayout->addWidget(largeNetworkNeighborhood, 2, 0, 1, 2);
0178 
0179     QCheckBox *masterBrowsersRequireAuth = new QCheckBox(Smb4KSettings::self()->masterBrowsersRequireAuthItem()->label(), sambaBox);
0180     masterBrowsersRequireAuth->setObjectName(QStringLiteral("kcfg_MasterBrowsersRequireAuth"));
0181 
0182     sambaBoxLayout->addWidget(masterBrowsersRequireAuth, 3, 0, 1, 2);
0183 
0184     QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), sambaBox);
0185     useKerberos->setObjectName(QStringLiteral("kcfg_UseKerberos"));
0186 
0187     sambaBoxLayout->addWidget(useKerberos, 4, 0, 1, 2);
0188 
0189     QCheckBox *useCCache = new QCheckBox(Smb4KSettings::self()->useWinbindCCacheItem()->label(), sambaBox);
0190     useCCache->setObjectName(QStringLiteral("kcfg_UseWinbindCCache"));
0191 
0192     sambaBoxLayout->addWidget(useCCache, 5, 0, 1, 2);
0193 
0194     advancedTabLayout->addWidget(sambaBox);
0195 
0196     QGroupBox *wakeOnLanBox = new QGroupBox(i18n("Wake-On-LAN"), advancedTab);
0197     QVBoxLayout *wakeOnLanBoxLayout = new QVBoxLayout(wakeOnLanBox);
0198 
0199     QCheckBox *enableWakeOnLan = new QCheckBox(Smb4KSettings::self()->enableWakeOnLANItem()->label(), wakeOnLanBox);
0200     enableWakeOnLan->setObjectName(QStringLiteral("kcfg_EnableWakeOnLAN"));
0201 
0202     wakeOnLanBoxLayout->addWidget(enableWakeOnLan);
0203 
0204     QWidget *waitingTimeWidget = new QWidget(wakeOnLanBox);
0205     QHBoxLayout *waitingTimeWidgetLayout = new QHBoxLayout(waitingTimeWidget);
0206     waitingTimeWidgetLayout->setContentsMargins(0, 0, 0, 0);
0207 
0208     QLabel *wakeOnLanWaitingTimeLabel = new QLabel(Smb4KSettings::self()->wakeOnLANWaitingTimeItem()->label(), waitingTimeWidget);
0209     wakeOnLanWaitingTimeLabel->setIndent(25);
0210     wakeOnLanWaitingTimeLabel->setObjectName(QStringLiteral("WakeOnLanWaitingTimeLabel"));
0211 
0212     waitingTimeWidgetLayout->addWidget(wakeOnLanWaitingTimeLabel);
0213 
0214     QSpinBox *wakeOnLanWaitingTime = new QSpinBox(waitingTimeWidget);
0215     wakeOnLanWaitingTime->setObjectName(QStringLiteral("kcfg_WakeOnLANWaitingTime"));
0216     wakeOnLanWaitingTime->setSuffix(i18n(" s"));
0217     wakeOnLanWaitingTime->setSingleStep(1);
0218     //   wakeOnLanWaitingTime->setSliderEnabled(true);
0219 
0220     waitingTimeWidgetLayout->addWidget(wakeOnLanWaitingTime);
0221 
0222     wakeOnLanBoxLayout->addWidget(waitingTimeWidget);
0223 
0224     KMessageWidget *wakeOnLanNote = new KMessageWidget(wakeOnLanBox);
0225     wakeOnLanNote->setText(i18n("Define the hosts that should be woken up via the custom settings editor."));
0226     wakeOnLanNote->setMessageType(KMessageWidget::Information);
0227     wakeOnLanNote->setCloseButtonVisible(false);
0228     wakeOnLanNote->setIcon(KDE::icon(QStringLiteral("emblem-information")));
0229 
0230     wakeOnLanBoxLayout->addWidget(wakeOnLanNote);
0231 
0232     advancedTabLayout->addWidget(wakeOnLanBox);
0233     advancedTabLayout->addStretch(100);
0234 
0235     addTab(advancedTab, i18n("Advanced Settings"));
0236 
0237     //
0238     // Connections
0239     //
0240     connect(useClientProtocolVersions, SIGNAL(toggled(bool)), this, SLOT(slotSetProtocolVersionsToggled(bool)));
0241     connect(enableWakeOnLan, SIGNAL(toggled(bool)), this, SLOT(slotEnableWakeOnLanFeatureToggled(bool)));
0242 
0243     //
0244     // Set the correct states to the widgets
0245     //
0246     slotSetProtocolVersionsToggled(Smb4KSettings::useClientProtocolVersions());
0247     slotEnableWakeOnLanFeatureToggled(Smb4KSettings::enableWakeOnLAN());
0248 }
0249 
0250 Smb4KConfigPageNetwork::~Smb4KConfigPageNetwork()
0251 {
0252 }
0253 
0254 void Smb4KConfigPageNetwork::slotSetProtocolVersionsToggled(bool on)
0255 {
0256     //
0257     // Get the widgets
0258     //
0259     QLabel *minimalProtocolVersionLabel = findChild<QLabel *>(QStringLiteral("MinimalProtocolVersionLabel"));
0260     KComboBox *minimalProtocolVersion = findChild<KComboBox *>(QStringLiteral("kcfg_MinimalClientProtocolVersion"));
0261     QLabel *maximalProtocolVersionLabel = findChild<QLabel *>(QStringLiteral("MaximalProtocolVersionLabel"));
0262     KComboBox *maximalProtocolVersion = findChild<KComboBox *>(QStringLiteral("kcfg_MaximalClientProtocolVersion"));
0263 
0264     //
0265     // Enable / disable widgets
0266     //
0267     minimalProtocolVersionLabel->setEnabled(on);
0268     minimalProtocolVersion->setEnabled(on);
0269     maximalProtocolVersionLabel->setEnabled(on);
0270     maximalProtocolVersion->setEnabled(on);
0271 }
0272 
0273 void Smb4KConfigPageNetwork::slotEnableWakeOnLanFeatureToggled(bool on)
0274 {
0275     //
0276     // Get the widgets
0277     //
0278     QLabel *wakeOnLanWaitingTimeLabel = findChild<QLabel *>(QStringLiteral("WakeOnLanWaitingTimeLabel"));
0279     QSpinBox *wakeOnLanWaitingTime = findChild<QSpinBox *>(QStringLiteral("kcfg_WakeOnLANWaitingTime"));
0280 
0281     //
0282     // Enable / disable widgets
0283     //
0284     wakeOnLanWaitingTimeLabel->setEnabled(on);
0285     wakeOnLanWaitingTime->setEnabled(on);
0286 }