File indexing completed on 2024-12-08 07:35:49
0001 /* 0002 The configuration page for the network settings of Smb4K 0003 0004 SPDX-FileCopyrightText: 2003-2023 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 // Set client protocol versions 0058 QCheckBox *useClientProtocolVersions = new QCheckBox(Smb4KSettings::self()->useClientProtocolVersionsItem()->label(), browseSettingsBox); 0059 useClientProtocolVersions->setObjectName(QStringLiteral("kcfg_UseClientProtocolVersions")); 0060 0061 browseSettingsBoxLayout->addWidget(useClientProtocolVersions); 0062 0063 m_protocolVersionsWidget = new QWidget(browseSettingsBox); 0064 m_protocolVersionsWidget->setEnabled(false); 0065 QGridLayout *protocolVersionsWidgetLayout = new QGridLayout(m_protocolVersionsWidget); 0066 protocolVersionsWidgetLayout->setContentsMargins(0, 0, 0, 0); 0067 0068 QLabel *minimalProtocolVersionLabel = new QLabel(Smb4KSettings::self()->minimalClientProtocolVersionItem()->label(), m_protocolVersionsWidget); 0069 minimalProtocolVersionLabel->setIndent(25); 0070 0071 KComboBox *minimalProtocolVersion = new KComboBox(m_protocolVersionsWidget); 0072 minimalProtocolVersion->setObjectName(QStringLiteral("kcfg_MinimalClientProtocolVersion")); 0073 0074 QList<KCoreConfigSkeleton::ItemEnum::Choice> minimalProtocolVersionChoices = Smb4KSettings::self()->minimalClientProtocolVersionItem()->choices(); 0075 0076 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(minimalProtocolVersionChoices)) { 0077 minimalProtocolVersion->addItem(c.label); 0078 } 0079 0080 protocolVersionsWidgetLayout->addWidget(minimalProtocolVersionLabel, 0, 0); 0081 protocolVersionsWidgetLayout->addWidget(minimalProtocolVersion, 0, 1); 0082 0083 QLabel *maximalProtocolVersionLabel = new QLabel(Smb4KSettings::self()->maximalClientProtocolVersionItem()->label(), m_protocolVersionsWidget); 0084 maximalProtocolVersionLabel->setIndent(25); 0085 0086 KComboBox *maximalProtocolVersion = new KComboBox(m_protocolVersionsWidget); 0087 maximalProtocolVersion->setObjectName(QStringLiteral("kcfg_MaximalClientProtocolVersion")); 0088 0089 QList<KCoreConfigSkeleton::ItemEnum::Choice> maximalProtocolVersionChoices = Smb4KSettings::self()->maximalClientProtocolVersionItem()->choices(); 0090 0091 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(maximalProtocolVersionChoices)) { 0092 maximalProtocolVersion->addItem(c.label); 0093 } 0094 0095 protocolVersionsWidgetLayout->addWidget(maximalProtocolVersionLabel, 1, 0); 0096 protocolVersionsWidgetLayout->addWidget(maximalProtocolVersion, 1, 1); 0097 0098 browseSettingsBoxLayout->addWidget(m_protocolVersionsWidget); 0099 0100 basicTabLayout->addWidget(browseSettingsBox); 0101 0102 // 0103 // Behavior 0104 // 0105 QGroupBox *behaviorBox = new QGroupBox(i18n("Behavior"), basicTab); 0106 QGridLayout *behaviorBoxLayout = new QGridLayout(behaviorBox); 0107 0108 QCheckBox *detectPrinters = new QCheckBox(Smb4KSettings::self()->detectPrinterSharesItem()->label(), behaviorBox); 0109 detectPrinters->setObjectName(QStringLiteral("kcfg_DetectPrinterShares")); 0110 0111 behaviorBoxLayout->addWidget(detectPrinters, 0, 0); 0112 0113 QCheckBox *detectHiddenShares = new QCheckBox(Smb4KSettings::self()->detectHiddenSharesItem()->label(), behaviorBox); 0114 detectHiddenShares->setObjectName(QStringLiteral("kcfg_DetectHiddenShares")); 0115 0116 behaviorBoxLayout->addWidget(detectHiddenShares, 0, 1); 0117 0118 QCheckBox *previewHiddenItems = new QCheckBox(Smb4KSettings::self()->previewHiddenItemsItem()->label(), behaviorBox); 0119 previewHiddenItems->setObjectName(QStringLiteral("kcfg_PreviewHiddenItems")); 0120 0121 behaviorBoxLayout->addWidget(previewHiddenItems, 1, 0); 0122 0123 basicTabLayout->addWidget(behaviorBox); 0124 basicTabLayout->addStretch(100); 0125 0126 addTab(basicTab, i18n("Basic Settings")); 0127 0128 // 0129 // Advanced Settings 0130 // 0131 QWidget *advancedTab = new QWidget(this); 0132 QVBoxLayout *advancedTabLayout = new QVBoxLayout(advancedTab); 0133 0134 // 0135 // Samba 0136 // 0137 QGroupBox *sambaBox = new QGroupBox(i18n("Samba"), advancedTab); 0138 QGridLayout *sambaBoxLayout = new QGridLayout(sambaBox); 0139 0140 QCheckBox *useRemoteSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), sambaBox); 0141 useRemoteSmbPort->setObjectName(QStringLiteral("kcfg_UseRemoteSmbPort")); 0142 0143 sambaBoxLayout->addWidget(useRemoteSmbPort, 0, 0); 0144 0145 QSpinBox *remoteSmbPort = new QSpinBox(sambaBox); 0146 remoteSmbPort->setObjectName(QStringLiteral("kcfg_RemoteSmbPort")); 0147 // remoteSmbPort->setSliderEnabled(true); 0148 0149 sambaBoxLayout->addWidget(remoteSmbPort, 0, 1); 0150 0151 QCheckBox *useEncryptionLevel = new QCheckBox(Smb4KSettings::self()->useEncryptionLevelItem()->label(), sambaBox); 0152 useEncryptionLevel->setObjectName(QStringLiteral("kcfg_UseEncryptionLevel")); 0153 0154 sambaBoxLayout->addWidget(useEncryptionLevel, 1, 0); 0155 0156 KComboBox *encryptionLevel = new KComboBox(sambaBox); 0157 encryptionLevel->setObjectName(QStringLiteral("kcfg_EncryptionLevel")); 0158 0159 QList<KCoreConfigSkeleton::ItemEnum::Choice> encryptionLevelChoices = Smb4KSettings::self()->encryptionLevelItem()->choices(); 0160 0161 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(encryptionLevelChoices)) { 0162 encryptionLevel->addItem(c.label); 0163 } 0164 0165 sambaBoxLayout->addWidget(encryptionLevel, 1, 1); 0166 0167 QCheckBox *largeNetworkNeighborhood = new QCheckBox(Smb4KSettings::self()->largeNetworkNeighborhoodItem()->label(), sambaBox); 0168 largeNetworkNeighborhood->setObjectName(QStringLiteral("kcfg_LargeNetworkNeighborhood")); 0169 0170 sambaBoxLayout->addWidget(largeNetworkNeighborhood, 2, 0, 1, 2); 0171 0172 QCheckBox *masterBrowsersRequireAuth = new QCheckBox(Smb4KSettings::self()->masterBrowsersRequireAuthItem()->label(), sambaBox); 0173 masterBrowsersRequireAuth->setObjectName(QStringLiteral("kcfg_MasterBrowsersRequireAuth")); 0174 0175 sambaBoxLayout->addWidget(masterBrowsersRequireAuth, 3, 0, 1, 2); 0176 0177 QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), sambaBox); 0178 useKerberos->setObjectName(QStringLiteral("kcfg_UseKerberos")); 0179 0180 sambaBoxLayout->addWidget(useKerberos, 4, 0, 1, 2); 0181 0182 QCheckBox *useCCache = new QCheckBox(Smb4KSettings::self()->useWinbindCCacheItem()->label(), sambaBox); 0183 useCCache->setObjectName(QStringLiteral("kcfg_UseWinbindCCache")); 0184 0185 sambaBoxLayout->addWidget(useCCache, 5, 0, 1, 2); 0186 0187 advancedTabLayout->addWidget(sambaBox); 0188 0189 QGroupBox *wakeOnLanBox = new QGroupBox(i18n("Wake-On-LAN"), advancedTab); 0190 QVBoxLayout *wakeOnLanBoxLayout = new QVBoxLayout(wakeOnLanBox); 0191 0192 QCheckBox *enableWakeOnLan = new QCheckBox(Smb4KSettings::self()->enableWakeOnLANItem()->label(), wakeOnLanBox); 0193 enableWakeOnLan->setObjectName(QStringLiteral("kcfg_EnableWakeOnLAN")); 0194 0195 wakeOnLanBoxLayout->addWidget(enableWakeOnLan); 0196 0197 m_waitingTimeWidget = new QWidget(wakeOnLanBox); 0198 m_waitingTimeWidget->setEnabled(false); 0199 QHBoxLayout *waitingTimeWidgetLayout = new QHBoxLayout(m_waitingTimeWidget); 0200 waitingTimeWidgetLayout->setContentsMargins(0, 0, 0, 0); 0201 0202 QLabel *wakeOnLanWaitingTimeLabel = new QLabel(Smb4KSettings::self()->wakeOnLANWaitingTimeItem()->label(), m_waitingTimeWidget); 0203 wakeOnLanWaitingTimeLabel->setIndent(25); 0204 0205 waitingTimeWidgetLayout->addWidget(wakeOnLanWaitingTimeLabel); 0206 0207 QSpinBox *wakeOnLanWaitingTime = new QSpinBox(m_waitingTimeWidget); 0208 wakeOnLanWaitingTime->setObjectName(QStringLiteral("kcfg_WakeOnLANWaitingTime")); 0209 wakeOnLanWaitingTime->setSuffix(i18n(" s")); 0210 wakeOnLanWaitingTime->setSingleStep(1); 0211 // wakeOnLanWaitingTime->setSliderEnabled(true); 0212 0213 waitingTimeWidgetLayout->addWidget(wakeOnLanWaitingTime); 0214 0215 wakeOnLanBoxLayout->addWidget(m_waitingTimeWidget); 0216 0217 KMessageWidget *wakeOnLanNote = new KMessageWidget(wakeOnLanBox); 0218 wakeOnLanNote->setText(i18n("Define the hosts that should be woken up via the custom settings editor.")); 0219 wakeOnLanNote->setMessageType(KMessageWidget::Information); 0220 wakeOnLanNote->setCloseButtonVisible(false); 0221 wakeOnLanNote->setIcon(KDE::icon(QStringLiteral("emblem-information"))); 0222 0223 wakeOnLanBoxLayout->addWidget(wakeOnLanNote); 0224 0225 advancedTabLayout->addWidget(wakeOnLanBox); 0226 advancedTabLayout->addStretch(100); 0227 0228 addTab(advancedTab, i18n("Advanced Settings")); 0229 0230 connect(useClientProtocolVersions, &QCheckBox::toggled, this, &Smb4KConfigPageNetwork::slotSetProtocolVersionsToggled); 0231 connect(enableWakeOnLan, &QCheckBox::toggled, this, &Smb4KConfigPageNetwork::slotEnableWakeOnLanFeatureToggled); 0232 } 0233 0234 Smb4KConfigPageNetwork::~Smb4KConfigPageNetwork() 0235 { 0236 } 0237 0238 void Smb4KConfigPageNetwork::slotSetProtocolVersionsToggled(bool on) 0239 { 0240 m_protocolVersionsWidget->setEnabled(on); 0241 } 0242 0243 void Smb4KConfigPageNetwork::slotEnableWakeOnLanFeatureToggled(bool on) 0244 { 0245 m_waitingTimeWidget->setEnabled(on); 0246 }