1 /***************************************************************************
2     smb4knetworkoptions  -  The configuration page for the network
3     settings of Smb4K
4                              -------------------
5     begin                : Sa Nov 15 2003
6     copyright            : (C) 2003-2020 by Alexander Reinholdt
7     email                : alexander.reinholdt@kdemail.net
8  ***************************************************************************/
9 
10 /***************************************************************************
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  *   This program is distributed in the hope that it will be useful, but   *
17  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
19  *   General Public License for more details.                              *
20  *                                                                         *
21  *   You should have received a copy of the GNU General Public License     *
22  *   along with this program; if not, write to the                         *
23  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
24  *   MA 02110-1335, USA                                                    *
25  ***************************************************************************/
26 
27 // application specific includes
28 #include "smb4kconfigpagenetwork.h"
29 #include "core/smb4ksettings.h"
30 
31 // Qt includes
32 #include <QVBoxLayout>
33 #include <QGridLayout>
34 #include <QGroupBox>
35 #include <QLabel>
36 #include <QCheckBox>
37 #include <QSpinBox>
38 
39 // KDE includes
40 #include <KIconThemes/KIconLoader>
41 #include <KI18n/KLocalizedString>
42 #include <KCompletion/KLineEdit>
43 #include <KCompletion/KComboBox>
44 
45 
Smb4KConfigPageNetwork(QWidget * parent)46 Smb4KConfigPageNetwork::Smb4KConfigPageNetwork(QWidget *parent) : QTabWidget(parent)
47 {
48   //
49   // Basic Samba Settings
50   //
51   QWidget *basicTab = new QWidget(this);
52   QVBoxLayout *basicTabLayout = new QVBoxLayout(basicTab);
53 
54   //
55   // Browse Settings group box
56   //
57   QGroupBox *browseSettingsBox = new QGroupBox(i18n("Browse Settings"), basicTab);
58   QGridLayout *browseSettingsBoxLayout = new QGridLayout(browseSettingsBox);
59 
60 #ifdef USE_WS_DISCOVERY
61   // Use WS-Discovery
62   QCheckBox *useWsDiscovery = new QCheckBox(Smb4KSettings::self()->useWsDiscoveryItem()->label(), browseSettingsBox);
63   useWsDiscovery->setObjectName("kcfg_UseWsDiscovery");
64 #endif
65 
66   // Use DNS-SD
67   QCheckBox *useDnsServiceDiscovery = new QCheckBox(Smb4KSettings::self()->useDnsServiceDiscoveryItem()->label(), browseSettingsBox);
68   useDnsServiceDiscovery->setObjectName("kcfg_UseDnsServiceDiscovery");
69 
70 #ifdef USE_SMBC_PROTOCOL
71   // Force SMBv1 protocol for browsing
72   QCheckBox *forceSmb1Protocol = new QCheckBox(Smb4KSettings::self()->forceSmb1ProtocolItem()->label(), browseSettingsBox);
73   forceSmb1Protocol->setObjectName("kcfg_ForceSmb1Protocol");
74 
75   // Set client protocol versions
76   QCheckBox *useClientProtocolVersions = new QCheckBox(Smb4KSettings::self()->useClientProtocolVersionsItem()->label(), browseSettingsBox);
77   useClientProtocolVersions->setObjectName("kcfg_UseClientProtocolVersions");
78 
79   QLabel *minimalProtocolVersionLabel = new QLabel(Smb4KSettings::self()->minimalClientProtocolVersionItem()->label(), browseSettingsBox);
80   minimalProtocolVersionLabel->setIndent(25);
81   minimalProtocolVersionLabel->setObjectName("MinimalProtocolVersionLabel");
82 
83   KComboBox *minimalProtocolVersion = new KComboBox(browseSettingsBox);
84   minimalProtocolVersion->setObjectName("kcfg_MinimalClientProtocolVersion");
85 
86   QList<KCoreConfigSkeleton::ItemEnum::Choice> minimalProtocolVersionChoices = Smb4KSettings::self()->minimalClientProtocolVersionItem()->choices();
87 
88   for (const KCoreConfigSkeleton::ItemEnum::Choice &c : minimalProtocolVersionChoices)
89   {
90     minimalProtocolVersion->addItem(c.label);
91   }
92 
93   QLabel *maximalProtocolVersionLabel = new QLabel(Smb4KSettings::self()->maximalClientProtocolVersionItem()->label(), browseSettingsBox);
94   maximalProtocolVersionLabel->setIndent(25);
95   maximalProtocolVersionLabel->setObjectName("MaximalProtocolVersionLabel");
96 
97   KComboBox *maximalProtocolVersion = new KComboBox(browseSettingsBox);
98   maximalProtocolVersion->setObjectName("kcfg_MaximalClientProtocolVersion");
99 
100   QList<KCoreConfigSkeleton::ItemEnum::Choice> maximalProtocolVersionChoices = Smb4KSettings::self()->maximalClientProtocolVersionItem()->choices();
101 
102   for (const KCoreConfigSkeleton::ItemEnum::Choice &c : maximalProtocolVersionChoices)
103   {
104     maximalProtocolVersion->addItem(c.label);
105   }
106 
107   minimalProtocolVersionLabel->setBuddy(minimalProtocolVersion);
108   maximalProtocolVersionLabel->setBuddy(maximalProtocolVersion);
109 #endif
110 
111 #ifdef USE_WS_DISCOVERY
112   browseSettingsBoxLayout->addWidget(useWsDiscovery, 0, 0, 1, 2);
113   browseSettingsBoxLayout->addWidget(useDnsServiceDiscovery, 1, 0, 1, 2);
114 #ifdef USE_SMBC_PROTOCOL
115   browseSettingsBoxLayout->addWidget(forceSmb1Protocol, 2, 0, 1, 2);
116   browseSettingsBoxLayout->addWidget(useClientProtocolVersions, 3, 0, 1, 2);
117   browseSettingsBoxLayout->addWidget(minimalProtocolVersionLabel, 4, 0);
118   browseSettingsBoxLayout->addWidget(minimalProtocolVersion, 4, 1);
119   browseSettingsBoxLayout->addWidget(maximalProtocolVersionLabel, 5, 0);
120   browseSettingsBoxLayout->addWidget(maximalProtocolVersion, 5, 1);
121 #endif
122 #else
123   browseSettingsBoxLayout->addWidget(useDnsServiceDiscovery, 0, 0, 1, 2);
124 #ifdef USE_SMBC_PROTOCOL
125   browseSettingsBoxLayout->addWidget(forceSmb1Protocol, 1, 0, 1, 2);
126   browseSettingsBoxLayout->addWidget(useClientProtocolVersions, 2, 0, 1, 2);
127   browseSettingsBoxLayout->addWidget(minimalProtocolVersionLabel, 3, 0);
128   browseSettingsBoxLayout->addWidget(minimalProtocolVersion, 3, 1);
129   browseSettingsBoxLayout->addWidget(maximalProtocolVersionLabel, 4, 0);
130   browseSettingsBoxLayout->addWidget(maximalProtocolVersion, 4, 1);
131 #endif
132 #endif
133 
134   //
135   // Behavior group box
136   //
137   QGroupBox *behaviorBox = new QGroupBox(i18n("Behavior"), basicTab);
138   QGridLayout *behaviorBoxLayout = new QGridLayout(behaviorBox);
139 
140   QCheckBox *detectPrinters = new QCheckBox(Smb4KSettings::self()->detectPrinterSharesItem()->label(), behaviorBox);
141   detectPrinters->setObjectName("kcfg_DetectPrinterShares");
142 
143   QCheckBox *detectHiddenShares = new QCheckBox(Smb4KSettings::self()->detectHiddenSharesItem()->label(), behaviorBox);
144   detectHiddenShares->setObjectName("kcfg_DetectHiddenShares");
145 
146   QCheckBox *previewHiddenItems = new QCheckBox(Smb4KSettings::self()->previewHiddenItemsItem()->label(), behaviorBox);
147   previewHiddenItems->setObjectName("kcfg_PreviewHiddenItems");
148 
149   behaviorBoxLayout->addWidget(detectPrinters, 0, 0);
150   behaviorBoxLayout->addWidget(detectHiddenShares, 0, 1);
151   behaviorBoxLayout->addWidget(previewHiddenItems, 1, 0);
152 
153   basicTabLayout->addWidget(browseSettingsBox, 0);
154   basicTabLayout->addWidget(behaviorBox, 0);
155   basicTabLayout->addStretch(100);
156 
157   addTab(basicTab, i18n("Basic Settings"));
158 
159   //
160   // Samba Settings
161   //
162   QWidget *sambaTab = new QWidget(this);
163   QVBoxLayout *sambaTabLayout = new QVBoxLayout(sambaTab);
164 
165   //
166   // Basic Settings group box
167   //
168   QGroupBox *basicSettingsBox = new QGroupBox(i18n("Common Settings"), sambaTab);
169   QGridLayout *basicSettingsBoxLayout = new QGridLayout(basicSettingsBox);
170 
171   QLabel *nebiosNameLabel = new QLabel(Smb4KSettings::self()->netBIOSNameItem()->label(), basicSettingsBox);
172   KLineEdit *netbiosName = new KLineEdit(basicSettingsBox);
173   netbiosName->setObjectName("kcfg_NetBIOSName");
174   netbiosName->setClearButtonEnabled(true);
175   nebiosNameLabel->setBuddy(netbiosName);
176 
177   QLabel *domainLabel = new QLabel(Smb4KSettings::self()->domainNameItem()->label(), basicSettingsBox);
178   KLineEdit *domain = new KLineEdit(basicSettingsBox);
179   domain->setObjectName("kcfg_DomainName");
180   domain->setClearButtonEnabled(true);
181   domainLabel->setBuddy(domain);
182 
183   QCheckBox *useRemoteSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), basicSettingsBox);
184   useRemoteSmbPort->setObjectName("kcfg_UseRemoteSmbPort");
185 
186   QSpinBox *remoteSmbPort = new QSpinBox(basicSettingsBox);
187   remoteSmbPort->setObjectName("kcfg_RemoteSmbPort");
188 //   remoteSmbPort->setSliderEnabled(true);
189 
190   QCheckBox *largeNetworkNeighborhood = new QCheckBox(Smb4KSettings::self()->largeNetworkNeighborhoodItem()->label(), basicSettingsBox);
191   largeNetworkNeighborhood->setObjectName("kcfg_LargeNetworkNeighborhood");
192 
193   basicSettingsBoxLayout->addWidget(nebiosNameLabel, 0, 0);
194   basicSettingsBoxLayout->addWidget(netbiosName, 0, 1);
195   basicSettingsBoxLayout->addWidget(domainLabel, 1, 0);
196   basicSettingsBoxLayout->addWidget(domain, 1, 1);
197   basicSettingsBoxLayout->addWidget(useRemoteSmbPort, 2, 0);
198   basicSettingsBoxLayout->addWidget(remoteSmbPort, 2, 1);
199   basicSettingsBoxLayout->addWidget(largeNetworkNeighborhood, 3, 0, 1, 2);
200 
201   //
202   // Authentication group box
203   //
204   QGroupBox *authenticationBox = new QGroupBox(i18n("Authentication"), sambaTab);
205   QGridLayout *authenticationBoxLayout = new QGridLayout(authenticationBox);
206 
207   QCheckBox *masterBrowsersRequireAuth = new QCheckBox(Smb4KSettings::self()->masterBrowsersRequireAuthItem()->label(), authenticationBox);
208   masterBrowsersRequireAuth->setObjectName("kcfg_MasterBrowsersRequireAuth");
209 
210   QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), authenticationBox);
211   useKerberos->setObjectName("kcfg_UseKerberos");
212 
213   QCheckBox *useCCache = new QCheckBox(Smb4KSettings::self()->useWinbindCCacheItem()->label(), authenticationBox);
214   useCCache->setObjectName("kcfg_UseWinbindCCache");
215 
216   authenticationBoxLayout->addWidget(masterBrowsersRequireAuth, 0, 0);
217   authenticationBoxLayout->addWidget(useKerberos, 0, 1);
218   authenticationBoxLayout->addWidget(useCCache, 1, 0);
219 
220   //
221   // Security group box
222   //
223   QGroupBox *securityBox = new QGroupBox(i18n("Security"), sambaTab);
224   QGridLayout *securityBoxLayout = new QGridLayout(securityBox);
225 
226   // Encryption level
227   QCheckBox *useEncryptionLevel = new QCheckBox(Smb4KSettings::self()->useEncryptionLevelItem()->label(), securityBox);
228   useEncryptionLevel->setObjectName("kcfg_UseEncryptionLevel");
229 
230   KComboBox *encryptionLevel = new KComboBox(securityBox);
231   encryptionLevel->setObjectName("kcfg_EncryptionLevel");
232 
233   QList<KCoreConfigSkeleton::ItemEnum::Choice> encryptionLevelChoices = Smb4KSettings::self()->encryptionLevelItem()->choices();
234 
235   for (const KCoreConfigSkeleton::ItemEnum::Choice &c : encryptionLevelChoices)
236   {
237     encryptionLevel->addItem(c.label);
238   }
239 
240   securityBoxLayout->addWidget(useEncryptionLevel, 0, 0);
241   securityBoxLayout->addWidget(encryptionLevel, 0, 1);
242 
243   sambaTabLayout->addWidget(basicSettingsBox, 0);
244   sambaTabLayout->addWidget(authenticationBox, 0);
245   sambaTabLayout->addWidget(securityBox, 0);
246   sambaTabLayout->addStretch(100);
247 
248   addTab(sambaTab, i18n("Samba Settings"));
249 
250   //
251   // Wake-On-LAN tab
252   //
253   QWidget *wakeOnLanTab = new QWidget(this);
254   QVBoxLayout *wakeOnLanTabLayout = new QVBoxLayout(wakeOnLanTab);
255 
256   //
257   // Wake-On-LAN group box
258   //
259   QGroupBox *wakeOnLanBox = new QGroupBox(i18n("Wake-On-LAN"), wakeOnLanTab);
260   QGridLayout *wakeOnLanBoxLayout = new QGridLayout(wakeOnLanBox);
261 
262   QCheckBox *enableWakeOnLan = new QCheckBox(Smb4KSettings::self()->enableWakeOnLANItem()->label(), wakeOnLanBox);
263   enableWakeOnLan->setObjectName("kcfg_EnableWakeOnLAN");
264 
265   QLabel *wakeOnLanWaitingTimeLabel = new QLabel(Smb4KSettings::self()->wakeOnLANWaitingTimeItem()->label(), wakeOnLanBox);
266   wakeOnLanWaitingTimeLabel->setIndent(25);
267   wakeOnLanWaitingTimeLabel->setObjectName("WakeOnLanWaitingTimeLabel");
268 
269   QSpinBox *wakeOnLanWaitingTime = new QSpinBox(wakeOnLanBox);
270   wakeOnLanWaitingTime->setObjectName("kcfg_WakeOnLANWaitingTime");
271   wakeOnLanWaitingTime->setSuffix(i18n(" s"));
272   wakeOnLanWaitingTime->setSingleStep(1);
273 //   wakeOnLanWaitingTime->setSliderEnabled(true);
274 
275   wakeOnLanWaitingTimeLabel->setBuddy(wakeOnLanWaitingTime);
276 
277   QFrame *wakeOnLanNote = new QFrame(wakeOnLanBox);
278   QGridLayout *wakeOnLanNoteLayout = new QGridLayout(wakeOnLanNote);
279   wakeOnLanNoteLayout->setContentsMargins(5, 5, 5, 5);
280 
281   QLabel *importantPixmap = new QLabel(wakeOnLanNote);
282   importantPixmap->setPixmap(KIconLoader::global()->loadIcon("emblem-important", KIconLoader::Desktop, KIconLoader::SizeMedium));
283   importantPixmap->adjustSize();
284 
285   QLabel *message = new QLabel(wakeOnLanNote);
286   message->setText(i18n("<qt>Define the hosts that should be woken up via the custom options dialog.</qt>"));
287   message->setTextFormat(Qt::AutoText);
288   message->setWordWrap(true);
289   message->setAlignment(Qt::AlignJustify);
290 
291   wakeOnLanNoteLayout->addWidget(importantPixmap, 0, 0, Qt::AlignVCenter);
292   wakeOnLanNoteLayout->addWidget(message, 0, 1, Qt::AlignVCenter);
293   wakeOnLanNoteLayout->setColumnStretch(1, 1);
294 
295   wakeOnLanBoxLayout->addWidget(enableWakeOnLan, 0, 0, 1, 2);
296   wakeOnLanBoxLayout->addWidget(wakeOnLanWaitingTimeLabel, 1, 0);
297   wakeOnLanBoxLayout->addWidget(wakeOnLanWaitingTime, 1, 1);
298   wakeOnLanBoxLayout->addWidget(wakeOnLanNote, 2, 0, 1, 2);
299 
300   wakeOnLanTabLayout->addWidget(wakeOnLanBox, 0);
301   wakeOnLanTabLayout->addStretch(100);
302 
303   addTab(wakeOnLanTab, i18n("Wake-On-LAN Settings"));
304 
305   //
306   // Connections
307   //
308 #ifdef USE_SMBC_PROTOCOL
309   connect(useClientProtocolVersions, SIGNAL(toggled(bool)), this, SLOT(slotSetProtocolVersionsToggled(bool)));
310 #endif
311   connect(enableWakeOnLan, SIGNAL(toggled(bool)), this, SLOT(slotEnableWakeOnLanFeatureToggled(bool)));
312 
313   //
314   // Set the correct states to the widgets
315   //
316 #ifdef USE_SMBC_PROTOCOL
317   slotSetProtocolVersionsToggled(Smb4KSettings::useClientProtocolVersions());
318 #endif
319   slotEnableWakeOnLanFeatureToggled(Smb4KSettings::enableWakeOnLAN());
320 }
321 
322 
~Smb4KConfigPageNetwork()323 Smb4KConfigPageNetwork::~Smb4KConfigPageNetwork()
324 {
325 }
326 
327 
328 #ifdef USE_SMBC_PROTOCOL
slotSetProtocolVersionsToggled(bool on)329 void Smb4KConfigPageNetwork::slotSetProtocolVersionsToggled(bool on)
330 {
331   //
332   // Get the widgets
333   //
334   QLabel *minimalProtocolVersionLabel = findChild<QLabel *>("MinimalProtocolVersionLabel");
335   KComboBox *minimalProtocolVersion = findChild<KComboBox *>("kcfg_MinimalClientProtocolVersion");
336   QLabel *maximalProtocolVersionLabel = findChild<QLabel *>("MaximalProtocolVersionLabel");
337   KComboBox *maximalProtocolVersion = findChild<KComboBox *>("kcfg_MaximalClientProtocolVersion");
338 
339   //
340   // Enable / disable widgets
341   //
342   minimalProtocolVersionLabel->setEnabled(on);
343   minimalProtocolVersion->setEnabled(on);
344   maximalProtocolVersionLabel->setEnabled(on);
345   maximalProtocolVersion->setEnabled(on);
346 }
347 #endif
348 
349 
slotEnableWakeOnLanFeatureToggled(bool on)350 void Smb4KConfigPageNetwork::slotEnableWakeOnLanFeatureToggled(bool on)
351 {
352   //
353   // Get the widgets
354   //
355   QLabel *wakeOnLanWaitingTimeLabel = findChild<QLabel *>("WakeOnLanWaitingTimeLabel");
356   QSpinBox *wakeOnLanWaitingTime = findChild<QSpinBox *>("kcfg_WakeOnLANWaitingTime");
357 
358   //
359   // Enable / disable widgets
360   //
361   wakeOnLanWaitingTimeLabel->setEnabled(on);
362   wakeOnLanWaitingTime->setEnabled(on);
363 }
364 
365 
366 
367