File indexing completed on 2024-10-06 04:35:38
0001 /* 0002 * Editor widget for the custom settings 0003 * 0004 * SPDX-FileCopyrightText: 2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 // application specific includes 0009 #include "smb4kcustomsettingseditorwidget.h" 0010 #include "smb4ksettings.h" 0011 #if defined(Q_OS_LINUX) 0012 #include "smb4kmountsettings_linux.h" 0013 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) 0014 #include "smb4kmountsettings_bsd.h" 0015 #endif 0016 0017 // Qt includes 0018 #include <QGridLayout> 0019 #include <QGroupBox> 0020 0021 // KDE includes 0022 #include <KLocalizedString> 0023 0024 using namespace Smb4KGlobal; 0025 0026 Smb4KCustomSettingsEditorWidget::Smb4KCustomSettingsEditorWidget(QWidget *parent) 0027 : QTabWidget(parent) 0028 { 0029 // FIXME: Implement mount point!? 0030 0031 // FIXME: Honor disabled widgets and unchecked check boxes!? 0032 m_haveCustomSettings = false; 0033 setupView(); 0034 } 0035 0036 Smb4KCustomSettingsEditorWidget::~Smb4KCustomSettingsEditorWidget() 0037 { 0038 } 0039 0040 #if defined(Q_OS_LINUX) 0041 void Smb4KCustomSettingsEditorWidget::setupView() 0042 { 0043 QGroupBox *tab1 = new QGroupBox(this); 0044 QGridLayout *tab1Layout = new QGridLayout(tab1); 0045 0046 m_alwaysRemountShare = new QCheckBox(i18n("Always remount this share"), tab1); 0047 m_alwaysRemountShare->setEnabled(false); 0048 0049 connect(m_alwaysRemountShare, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotAlwaysRemoutShareToggled); 0050 0051 m_useWriteAccess = new QCheckBox(Smb4KMountSettings::self()->useWriteAccessItem()->label(), tab1); 0052 m_writeAccess = new KComboBox(tab1); 0053 0054 QList<KCoreConfigSkeleton::ItemEnum::Choice> writeAccessChoices = Smb4KMountSettings::self()->writeAccessItem()->choices(); 0055 0056 for (const KCoreConfigSkeleton::ItemEnum::Choice &wa : qAsConst(writeAccessChoices)) { 0057 m_writeAccess->addItem(wa.label); 0058 } 0059 0060 connect(m_useWriteAccess, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseWriteAccessToggled); 0061 connect(m_writeAccess, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotWriteAccessChanged); 0062 0063 m_useFileSystemPort = new QCheckBox(Smb4KMountSettings::self()->useRemoteFileSystemPortItem()->label(), tab1); 0064 m_fileSystemPort = new QSpinBox(tab1); 0065 m_fileSystemPort->setMinimum(Smb4KMountSettings::self()->remoteFileSystemPortItem()->minValue().toInt()); 0066 m_fileSystemPort->setMaximum(Smb4KMountSettings::self()->remoteFileSystemPortItem()->maxValue().toInt()); 0067 0068 connect(m_useFileSystemPort, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseFileSystemPortToggled); 0069 connect(m_fileSystemPort, &QSpinBox::valueChanged, this, &Smb4KCustomSettingsEditorWidget::slotFileSystemPortChanged); 0070 0071 tab1Layout->addWidget(m_alwaysRemountShare, 0, 0, 1, 2); 0072 tab1Layout->addWidget(m_useWriteAccess, 1, 0); 0073 tab1Layout->addWidget(m_writeAccess, 1, 1); 0074 tab1Layout->addWidget(m_useFileSystemPort, 2, 0); 0075 tab1Layout->addWidget(m_fileSystemPort, 2, 1); 0076 tab1Layout->setRowStretch(3, 100); 0077 0078 addTab(tab1, i18n("Mounting: Common Settings")); 0079 0080 QGroupBox *tab2 = new QGroupBox(this); 0081 QGridLayout *tab2Layout = new QGridLayout(tab2); 0082 0083 m_cifsUnixExtensionSupport = new QCheckBox(i18n("This server supports the CIFS Unix extensions"), tab2); 0084 0085 connect(m_cifsUnixExtensionSupport, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotCifsUnixExtensionSupportToggled); 0086 0087 m_useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), tab2); 0088 m_userId = new KComboBox(tab2); 0089 0090 QList<KUser> allUsers = KUser::allUsers(); 0091 0092 for (const KUser &user : qAsConst(allUsers)) { 0093 m_userId->addItem(user.loginName() + QStringLiteral(" (") + user.userId().toString() + QStringLiteral(")"), user.userId().toString()); 0094 } 0095 0096 connect(m_useUserId, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseUserIdToggled); 0097 connect(m_userId, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotUserIdChanged); 0098 0099 m_useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), tab2); 0100 m_groupId = new KComboBox(tab2); 0101 0102 QList<KUserGroup> allGroups = KUserGroup::allGroups(); 0103 0104 for (const KUserGroup &group : qAsConst(allGroups)) { 0105 m_groupId->addItem(group.name() + QStringLiteral(" (") + group.groupId().toString() + QStringLiteral(")"), group.groupId().toString()); 0106 } 0107 0108 connect(m_useGroupId, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseGroupIdToggled); 0109 connect(m_groupId, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotGroupIdChanged); 0110 0111 m_useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), tab2); 0112 m_fileMode = new KLineEdit(tab2); 0113 m_fileMode->setClearButtonEnabled(true); 0114 m_fileMode->setAlignment(Qt::AlignRight); 0115 0116 connect(m_useFileMode, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseFileModeToggled); 0117 connect(m_fileMode, &KLineEdit::textChanged, this, &Smb4KCustomSettingsEditorWidget::slotFileModeChanged); 0118 0119 m_useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), tab2); 0120 m_directoryMode = new KLineEdit(tab2); 0121 m_directoryMode->setClearButtonEnabled(true); 0122 m_directoryMode->setAlignment(Qt::AlignRight); 0123 0124 connect(m_useDirectoryMode, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseDirectoryModeToggled); 0125 connect(m_directoryMode, &KLineEdit::textChanged, this, &Smb4KCustomSettingsEditorWidget::slotDirectoryModeChanged); 0126 0127 tab2Layout->addWidget(m_cifsUnixExtensionSupport, 0, 0, 1, 2); 0128 tab2Layout->addWidget(m_useUserId, 1, 0); 0129 tab2Layout->addWidget(m_userId, 1, 1); 0130 tab2Layout->addWidget(m_useGroupId, 2, 0); 0131 tab2Layout->addWidget(m_groupId, 2, 1); 0132 tab2Layout->addWidget(m_useFileMode, 3, 0); 0133 tab2Layout->addWidget(m_fileMode, 3, 1); 0134 tab2Layout->addWidget(m_useDirectoryMode, 4, 0); 0135 tab2Layout->addWidget(m_directoryMode, 4, 1); 0136 tab2Layout->setRowStretch(5, 100); 0137 0138 addTab(tab2, i18n("Mounting: CIFS Unix Extensions")); 0139 0140 QGroupBox *tab3 = new QGroupBox(this); 0141 QGridLayout *tab3Layout = new QGridLayout(tab3); 0142 0143 m_useSmbMountProtocolVersion = new QCheckBox(Smb4KMountSettings::self()->useSmbProtocolVersionItem()->label(), tab3); 0144 m_smbMountProtocolVersion = new KComboBox(tab3); 0145 0146 QList<KCoreConfigSkeleton::ItemEnum::Choice> smbProtocolChoices = Smb4KMountSettings::self()->smbProtocolVersionItem()->choices(); 0147 0148 for (int i = 0; i < smbProtocolChoices.size(); ++i) { 0149 m_smbMountProtocolVersion->addItem(smbProtocolChoices.at(i).label, i); 0150 } 0151 0152 connect(m_useSmbMountProtocolVersion, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseSmbMountProtocolVersionToggled); 0153 connect(m_smbMountProtocolVersion, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotSmbMountProtocolVersionChanged); 0154 0155 m_useSecurityMode = new QCheckBox(Smb4KMountSettings::self()->useSecurityModeItem()->label(), tab3); 0156 m_securityMode = new KComboBox(tab3); 0157 0158 QList<KConfigSkeleton::ItemEnum::Choice> securityModeChoices = Smb4KMountSettings::self()->securityModeItem()->choices(); 0159 0160 for (int i = 0; i < securityModeChoices.size(); ++i) { 0161 m_securityMode->addItem(securityModeChoices.at(i).label, i); 0162 } 0163 0164 connect(m_useSecurityMode, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseSecurityModeToggled); 0165 connect(m_securityMode, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotSecurityModeChanged); 0166 0167 tab3Layout->addWidget(m_useSmbMountProtocolVersion, 0, 0); 0168 tab3Layout->addWidget(m_smbMountProtocolVersion, 0, 1); 0169 tab3Layout->addWidget(m_useSecurityMode, 1, 0); 0170 tab3Layout->addWidget(m_securityMode, 1, 1); 0171 tab3Layout->setRowStretch(2, 100); 0172 0173 addTab(tab3, i18n("Mounting: Advanced Settings")); 0174 0175 QGroupBox *tab4 = new QGroupBox(this); 0176 QGridLayout *tab4Layout = new QGridLayout(tab4); 0177 0178 m_useClientProtocolVersions = new QCheckBox(Smb4KSettings::self()->useClientProtocolVersionsItem()->label(), tab4); 0179 0180 m_minimalClientProtocolVersionLabel = new QLabel(Smb4KSettings::self()->minimalClientProtocolVersionItem()->label(), tab4); 0181 m_minimalClientProtocolVersionLabel->setIndent(25); 0182 m_minimalClientProtocolVersionLabel->setEnabled(false); 0183 m_minimalClientProtocolVersion = new KComboBox(tab4); 0184 m_minimalClientProtocolVersion->setEnabled(false); 0185 m_minimalClientProtocolVersionLabel->setBuddy(m_minimalClientProtocolVersion); 0186 0187 QList<KCoreConfigSkeleton::ItemEnum::Choice> minimalClientProtocolVersionChoices = Smb4KSettings::self()->minimalClientProtocolVersionItem()->choices(); 0188 0189 for (int i = 0; i < minimalClientProtocolVersionChoices.size(); ++i) { 0190 m_minimalClientProtocolVersion->addItem(minimalClientProtocolVersionChoices.at(i).label, i); 0191 } 0192 0193 m_maximalClientProtocolVersionLabel = new QLabel(Smb4KSettings::self()->maximalClientProtocolVersionItem()->label(), tab4); 0194 m_maximalClientProtocolVersionLabel->setIndent(25); 0195 m_maximalClientProtocolVersionLabel->setEnabled(false); 0196 m_maximalClientProtocolVersion = new KComboBox(tab4); 0197 m_maximalClientProtocolVersion->setEnabled(false); 0198 m_maximalClientProtocolVersionLabel->setBuddy(m_maximalClientProtocolVersion); 0199 0200 QList<KCoreConfigSkeleton::ItemEnum::Choice> maximalClientProtocolVersionChoices = Smb4KSettings::self()->maximalClientProtocolVersionItem()->choices(); 0201 0202 for (int i = 0; i < maximalClientProtocolVersionChoices.size(); ++i) { 0203 m_maximalClientProtocolVersion->addItem(maximalClientProtocolVersionChoices.at(i).label, i); 0204 } 0205 0206 connect(m_useClientProtocolVersions, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseClientProtocolVersionsToggled); 0207 connect(m_minimalClientProtocolVersion, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotMinimalClientProtocolVersionChanged); 0208 connect(m_maximalClientProtocolVersion, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotMaximalClientProtocolVersionChanged); 0209 0210 m_useRemoteSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), tab4); 0211 m_remoteSmbPort = new QSpinBox(tab4); 0212 m_remoteSmbPort->setMinimum(Smb4KSettings::self()->remoteSmbPortItem()->minValue().toInt()); 0213 m_remoteSmbPort->setMaximum(Smb4KSettings::self()->remoteSmbPortItem()->maxValue().toInt()); 0214 0215 connect(m_useRemoteSmbPort, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseClientProtocolVersionsToggled); 0216 connect(m_remoteSmbPort, &QSpinBox::valueChanged, this, &Smb4KCustomSettingsEditorWidget::slotRemoteSmbPortChanged); 0217 0218 m_useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), tab4); 0219 0220 connect(m_useKerberos, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseKerberosToggled); 0221 0222 tab4Layout->addWidget(m_useClientProtocolVersions, 0, 0, 1, 2); 0223 tab4Layout->addWidget(m_minimalClientProtocolVersionLabel, 1, 0); 0224 tab4Layout->addWidget(m_minimalClientProtocolVersion, 1, 1); 0225 tab4Layout->addWidget(m_maximalClientProtocolVersionLabel, 2, 0); 0226 tab4Layout->addWidget(m_maximalClientProtocolVersion, 2, 1); 0227 tab4Layout->addWidget(m_useRemoteSmbPort, 3, 0); 0228 tab4Layout->addWidget(m_remoteSmbPort, 3, 1); 0229 tab4Layout->addWidget(m_useKerberos, 4, 0, 1, 2); 0230 tab4Layout->setRowStretch(5, 100); 0231 0232 addTab(tab4, i18n("Browsing")); 0233 0234 QGroupBox *tab5 = new QGroupBox(this); 0235 QGridLayout *tab5Layout = new QGridLayout(tab5); 0236 0237 m_macAddressLabel = new QLabel(i18n("MAC Address:"), tab5); 0238 m_macAddressLabel->setEnabled(false); 0239 m_macAddress = new KLineEdit(tab5); 0240 m_macAddress->setClearButtonEnabled(true); 0241 m_macAddress->setInputMask(QStringLiteral("HH:HH:HH:HH:HH:HH;_")); // MAC address, see QLineEdit doc 0242 m_macAddress->setEnabled(false); 0243 m_macAddressLabel->setBuddy(m_macAddress); 0244 0245 connect(m_macAddress, &KLineEdit::textChanged, this, &Smb4KCustomSettingsEditorWidget::slotMacAddressChanged); 0246 0247 m_sendPacketBeforeScan = new QCheckBox(i18n("Send magic packet before scanning the network neighborhood"), tab5); 0248 m_sendPacketBeforeScan->setEnabled(false); 0249 m_sendPacketBeforeMount = new QCheckBox(i18n("Send magic packet before mounting a share"), tab5); 0250 m_sendPacketBeforeMount->setEnabled(false); 0251 0252 connect(m_sendPacketBeforeScan, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotSendPacketBeforeScanToggled); 0253 connect(m_sendPacketBeforeMount, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotSendPacketBeforeMountToggled); 0254 0255 tab5Layout->addWidget(m_macAddressLabel, 0, 0); 0256 tab5Layout->addWidget(m_macAddress, 0, 1); 0257 tab5Layout->addWidget(m_sendPacketBeforeScan, 1, 0, 1, 2); 0258 tab5Layout->addWidget(m_sendPacketBeforeMount, 2, 0, 1, 2); 0259 tab5Layout->setRowStretch(3, 100); 0260 0261 addTab(tab5, i18n("Wake-On-LAN")); 0262 } 0263 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) 0264 void Smb4KCustomSettingsEditorWidget::setupView() 0265 { 0266 QGroupBox *tab1 = new QGroupBox(this); 0267 QGridLayout *tab1Layout = new QGridLayout(tab1); 0268 0269 m_alwaysRemountShare = new QCheckBox(i18n("Always remount this share"), tab1); 0270 m_alwaysRemountShare->setEnabled(false); 0271 0272 connect(m_alwaysRemountShare, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotAlwaysRemoutShareToggled); 0273 0274 m_useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), tab1); 0275 m_userId = new KComboBox(tab1); 0276 0277 QList<KUser> allUsers = KUser::allUsers(); 0278 0279 for (const KUser &user : qAsConst(allUsers)) { 0280 m_userId->addItem(user.loginName() + QStringLiteral(" (") + user.userId().toString() + QStringLiteral(")"), user.userId().toString()); 0281 } 0282 0283 connect(m_useUserId, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseUserIdToggled); 0284 connect(m_userId, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotUserIdChanged); 0285 0286 m_useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), tab1); 0287 m_groupId = new KComboBox(tab1); 0288 0289 QList<KUserGroup> allGroups = KUserGroup::allGroups(); 0290 0291 for (const KUserGroup &group : qAsConst(allGroups)) { 0292 m_groupId->addItem(group.name() + QStringLiteral(" (") + group.groupId().toString() + QStringLiteral(")"), group.groupId().toString()); 0293 } 0294 0295 connect(m_useGroupId, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseGroupIdToggled); 0296 connect(m_groupId, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotGroupIdChanged); 0297 0298 m_useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), tab1); 0299 m_fileMode = new KLineEdit(tab1); 0300 m_fileMode->setClearButtonEnabled(true); 0301 m_fileMode->setAlignment(Qt::AlignRight); 0302 0303 connect(m_useFileMode, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseFileModeToggled); 0304 connect(m_fileMode, &KLineEdit::textChanged, this, &Smb4KCustomSettingsEditorWidget::slotFileModeChanged); 0305 0306 m_useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), tab1); 0307 m_directoryMode = new KLineEdit(tab1); 0308 m_directoryMode->setClearButtonEnabled(true); 0309 m_directoryMode->setAlignment(Qt::AlignRight); 0310 0311 connect(m_useDirectoryMode, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseDirectoryModeToggled); 0312 connect(m_directoryMode, &KLineEdit::textChanged, this, &Smb4KCustomSettingsEditorWidget::slotDirectoryModeChanged); 0313 0314 tab1Layout->addWidget(m_alwaysRemountShare, 0, 0, 1, 2); 0315 tab1Layout->addWidget(m_useUserId, 1, 0); 0316 tab1Layout->addWidget(m_userId, 1, 1); 0317 tab1Layout->addWidget(m_useGroupId, 2, 0); 0318 tab1Layout->addWidget(m_groupId, 2, 1); 0319 tab1Layout->addWidget(m_useFileMode, 3, 0); 0320 tab1Layout->addWidget(m_fileMode, 3, 1); 0321 tab1Layout->addWidget(m_useDirectoryMode, 4, 0); 0322 tab1Layout->addWidget(m_directoryMode, 4, 1); 0323 tab1Layout->setRowStretch(5, 100); 0324 0325 addTab(tab1, i18n("Mounting")); 0326 0327 QGroupBox *tab2 = new QGroupBox(this); 0328 QGridLayout *tab2Layout = new QGridLayout(tab2); 0329 0330 m_useClientProtocolVersions = new QCheckBox(Smb4KSettings::self()->useClientProtocolVersionsItem()->label(), tab2); 0331 0332 m_minimalClientProtocolVersionLabel = new QLabel(Smb4KSettings::self()->minimalClientProtocolVersionItem()->label(), tab2); 0333 m_minimalClientProtocolVersionLabel->setIndent(25); 0334 m_minimalClientProtocolVersionLabel->setEnabled(false); 0335 m_minimalClientProtocolVersion = new KComboBox(tab2); 0336 m_minimalClientProtocolVersion->setEnabled(false); 0337 m_minimalClientProtocolVersionLabel->setBuddy(m_minimalClientProtocolVersion); 0338 0339 QList<KCoreConfigSkeleton::ItemEnum::Choice> minimalClientProtocolVersionChoices = Smb4KSettings::self()->minimalClientProtocolVersionItem()->choices(); 0340 0341 for (int i = 0; i < minimalClientProtocolVersionChoices.size(); ++i) { 0342 m_minimalClientProtocolVersion->addItem(minimalClientProtocolVersionChoices.at(i).label, i); 0343 } 0344 0345 m_maximalClientProtocolVersionLabel = new QLabel(Smb4KSettings::self()->maximalClientProtocolVersionItem()->label(), tab2); 0346 m_maximalClientProtocolVersionLabel->setIndent(25); 0347 m_maximalClientProtocolVersionLabel->setEnabled(false); 0348 m_maximalClientProtocolVersion = new KComboBox(tab2); 0349 m_maximalClientProtocolVersion->setEnabled(false); 0350 m_maximalClientProtocolVersionLabel->setBuddy(m_maximalClientProtocolVersion); 0351 0352 QList<KCoreConfigSkeleton::ItemEnum::Choice> maximalClientProtocolVersionChoices = Smb4KSettings::self()->maximalClientProtocolVersionItem()->choices(); 0353 0354 for (int i = 0; i < maximalClientProtocolVersionChoices.size(); ++i) { 0355 m_maximalClientProtocolVersion->addItem(maximalClientProtocolVersionChoices.at(i).label, i); 0356 } 0357 0358 connect(m_useClientProtocolVersions, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseClientProtocolVersionsToggled); 0359 connect(m_minimalClientProtocolVersion, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotMinimalClientProtocolVersionChanged); 0360 connect(m_maximalClientProtocolVersion, &KComboBox::currentIndexChanged, this, &Smb4KCustomSettingsEditorWidget::slotMaximalClientProtocolVersionChanged); 0361 0362 m_useRemoteSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), tab2); 0363 m_remoteSmbPort = new QSpinBox(tab2); 0364 m_remoteSmbPort->setMinimum(Smb4KSettings::self()->remoteSmbPortItem()->minValue().toInt()); 0365 m_remoteSmbPort->setMaximum(Smb4KSettings::self()->remoteSmbPortItem()->maxValue().toInt()); 0366 0367 connect(m_useRemoteSmbPort, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseClientProtocolVersionsToggled); 0368 connect(m_remoteSmbPort, &QSpinBox::valueChanged, this, &Smb4KCustomSettingsEditorWidget::slotRemoteSmbPortChanged); 0369 0370 m_useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), tab2); 0371 0372 connect(m_useKerberos, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotUseKerberosToggled); 0373 0374 tab2Layout->addWidget(m_useClientProtocolVersions, 0, 0, 1, 2); 0375 tab2Layout->addWidget(m_minimalClientProtocolVersionLabel, 1, 0); 0376 tab2Layout->addWidget(m_minimalClientProtocolVersion, 1, 1); 0377 tab2Layout->addWidget(m_maximalClientProtocolVersionLabel, 2, 0); 0378 tab2Layout->addWidget(m_maximalClientProtocolVersion, 2, 1); 0379 tab2Layout->addWidget(m_useRemoteSmbPort, 3, 0); 0380 tab2Layout->addWidget(m_remoteSmbPort, 3, 1); 0381 tab2Layout->addWidget(m_useKerberos, 4, 0, 1, 2); 0382 tab2Layout->setRowStretch(5, 100); 0383 0384 addTab(tab2, i18n("Browsing")); 0385 0386 QGroupBox *tab3 = new QGroupBox(this); 0387 QGridLayout *tab3Layout = new QGridLayout(tab3); 0388 0389 m_macAddressLabel = new QLabel(i18n("MAC Address:"), tab3); 0390 m_macAddressLabel->setEnabled(false); 0391 m_macAddress = new KLineEdit(tab3); 0392 m_macAddress->setClearButtonEnabled(true); 0393 m_macAddress->setInputMask(QStringLiteral("HH:HH:HH:HH:HH:HH;_")); // MAC address, see QLineEdit doc 0394 m_macAddress->setEnabled(false); 0395 m_macAddressLabel->setBuddy(m_macAddress); 0396 0397 connect(m_macAddress, &KLineEdit::textChanged, this, &Smb4KCustomSettingsEditorWidget::slotMacAddressChanged); 0398 0399 m_sendPacketBeforeScan = new QCheckBox(i18n("Send magic packet before scanning the network neighborhood"), tab3); 0400 m_sendPacketBeforeScan->setEnabled(false); 0401 m_sendPacketBeforeMount = new QCheckBox(i18n("Send magic packet before mounting a share"), tab3); 0402 m_sendPacketBeforeMount->setEnabled(false); 0403 0404 connect(m_sendPacketBeforeScan, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotSendPacketBeforeScanToggled); 0405 connect(m_sendPacketBeforeMount, &QCheckBox::toggled, this, &Smb4KCustomSettingsEditorWidget::slotSendPacketBeforeMountToggled); 0406 0407 tab3Layout->addWidget(m_macAddressLabel, 0, 0); 0408 tab3Layout->addWidget(m_macAddress, 0, 1); 0409 tab3Layout->addWidget(m_sendPacketBeforeScan, 1, 0, 1, 2); 0410 tab3Layout->addWidget(m_sendPacketBeforeMount, 2, 0, 1, 2); 0411 tab3Layout->setRowStretch(3, 100); 0412 0413 addTab(tab3, i18n("Wake-On-LAN")); 0414 } 0415 #else 0416 void Smb4KCustomSettingsEditorWidget::setupView() 0417 { 0418 } 0419 #endif 0420 0421 void Smb4KCustomSettingsEditorWidget::setCustomSettings(const Smb4KCustomSettings &settings) 0422 { 0423 if (settings.type() != Host) { 0424 m_alwaysRemountShare->setEnabled(true); 0425 m_alwaysRemountShare->setChecked(settings.remount() == Smb4KCustomSettings::RemountAlways); 0426 } 0427 0428 #ifdef Q_OS_LINUX 0429 m_useWriteAccess->setChecked(settings.useWriteAccess()); 0430 m_writeAccess->setCurrentIndex(settings.writeAccess()); 0431 0432 m_useFileSystemPort->setChecked(settings.useFileSystemPort()); 0433 m_fileSystemPort->setValue(settings.fileSystemPort()); 0434 0435 m_cifsUnixExtensionSupport->setChecked(settings.cifsUnixExtensionsSupport()); 0436 #endif 0437 0438 m_useUserId->setChecked(settings.useUser()); 0439 int userIndex = m_userId->findData(settings.user().userId().toString()); 0440 m_userId->setCurrentIndex(userIndex); 0441 0442 m_useGroupId->setChecked(settings.useGroup()); 0443 int groupIndex = m_groupId->findData(settings.group().groupId().toString()); 0444 m_groupId->setCurrentIndex(groupIndex); 0445 0446 m_useFileMode->setChecked(settings.useFileMode()); 0447 m_fileMode->setText(settings.fileMode()); 0448 0449 m_useDirectoryMode->setChecked(settings.useDirectoryMode()); 0450 m_directoryMode->setText(settings.directoryMode()); 0451 0452 #ifdef Q_OS_LINUX 0453 m_useSmbMountProtocolVersion->setChecked(settings.useMountProtocolVersion()); 0454 int mountProtocolVersionIndex = m_smbMountProtocolVersion->findData(settings.mountProtocolVersion()); 0455 m_smbMountProtocolVersion->setCurrentIndex(mountProtocolVersionIndex); 0456 0457 m_useSecurityMode->setChecked(settings.useSecurityMode()); 0458 int securityModeIndex = m_securityMode->findData(settings.securityMode()); 0459 m_securityMode->setCurrentIndex(securityModeIndex); 0460 #endif 0461 0462 m_useClientProtocolVersions->setChecked(settings.useClientProtocolVersions()); 0463 int minimalClientProtocolVersionIndex = m_minimalClientProtocolVersion->findData(settings.minimalClientProtocolVersion()); 0464 m_minimalClientProtocolVersion->setCurrentIndex(minimalClientProtocolVersionIndex); 0465 int maximalClientProtocolVersionIndex = m_maximalClientProtocolVersion->findData(settings.maximalClientProtocolVersion()); 0466 m_maximalClientProtocolVersion->setCurrentIndex(maximalClientProtocolVersionIndex); 0467 0468 m_useRemoteSmbPort->setChecked(settings.useSmbPort()); 0469 m_remoteSmbPort->setValue(settings.smbPort()); 0470 0471 m_useKerberos->setChecked(settings.useKerberos()); 0472 0473 if (settings.type() == Host) { 0474 m_macAddressLabel->setEnabled(Smb4KSettings::enableWakeOnLAN()); 0475 m_macAddress->setEnabled(Smb4KSettings::enableWakeOnLAN()); 0476 m_sendPacketBeforeScan->setEnabled(Smb4KSettings::enableWakeOnLAN()); 0477 m_sendPacketBeforeMount->setEnabled(Smb4KSettings::enableWakeOnLAN()); 0478 0479 m_macAddress->setText(settings.macAddress()); 0480 m_sendPacketBeforeScan->setChecked(settings.wakeOnLanSendBeforeNetworkScan()); 0481 m_sendPacketBeforeMount->setChecked(settings.wakeOnLanSendBeforeMount()); 0482 } 0483 0484 m_customSettings = settings; 0485 m_haveCustomSettings = true; 0486 } 0487 0488 Smb4KCustomSettings Smb4KCustomSettingsEditorWidget::getCustomSettings() const 0489 { 0490 if (m_customSettings.type() != Host) { 0491 m_customSettings.setRemount(m_alwaysRemountShare->isChecked() ? Smb4KCustomSettings::RemountAlways : Smb4KCustomSettings::UndefinedRemount); 0492 } 0493 0494 #ifdef Q_OS_LINUX 0495 m_customSettings.setUseWriteAccess(m_useWriteAccess->isChecked()); 0496 m_customSettings.setWriteAccess(m_writeAccess->currentIndex()); 0497 0498 m_customSettings.setUseFileSystemPort(m_useFileSystemPort->isChecked()); 0499 m_customSettings.setFileSystemPort(m_fileSystemPort->value()); 0500 0501 m_customSettings.setCifsUnixExtensionsSupport(m_cifsUnixExtensionSupport->isChecked()); 0502 #endif 0503 0504 m_customSettings.setUseUser(m_useUserId->isChecked()); 0505 m_customSettings.setUser(KUser(K_UID(m_userId->currentData().toInt()))); 0506 0507 m_customSettings.setUseGroup(m_useGroupId->isChecked()); 0508 m_customSettings.setGroup(KUserGroup(K_GID(m_groupId->currentData().toInt()))); 0509 0510 m_customSettings.setUseFileMode(m_useFileMode->isChecked()); 0511 m_customSettings.setFileMode(m_fileMode->text()); 0512 0513 m_customSettings.setUseDirectoryMode(m_useDirectoryMode->isChecked()); 0514 m_customSettings.setDirectoryMode(m_directoryMode->text()); 0515 0516 #ifdef Q_OS_LINUX 0517 m_customSettings.setUseMountProtocolVersion(m_useSmbMountProtocolVersion->isChecked()); 0518 m_customSettings.setMountProtocolVersion(m_smbMountProtocolVersion->currentData().toInt()); 0519 0520 m_customSettings.setUseSecurityMode(m_useSecurityMode->isChecked()); 0521 m_customSettings.setSecurityMode(m_securityMode->currentData().toInt()); 0522 #endif 0523 0524 m_customSettings.setUseClientProtocolVersions(m_useClientProtocolVersions->isChecked()); 0525 m_customSettings.setMinimalClientProtocolVersion(m_minimalClientProtocolVersion->currentData().toInt()); 0526 m_customSettings.setMaximalClientProtocolVersion(m_maximalClientProtocolVersion->currentData().toInt()); 0527 0528 m_customSettings.setUseSmbPort(m_useRemoteSmbPort->isChecked()); 0529 m_customSettings.setSmbPort(m_remoteSmbPort->value()); 0530 0531 m_customSettings.setUseKerberos(m_useKerberos->isChecked()); 0532 0533 if (m_macAddress->hasAcceptableInput()) { 0534 m_customSettings.setMACAddress(m_macAddress->text()); 0535 } else { 0536 m_customSettings.setMACAddress(QString()); 0537 } 0538 m_customSettings.setWakeOnLanSendBeforeNetworkScan(m_sendPacketBeforeScan->isChecked()); 0539 m_customSettings.setWakeOnLanSendBeforeMount(m_sendPacketBeforeMount->isChecked()); 0540 0541 return m_customSettings; 0542 } 0543 0544 void Smb4KCustomSettingsEditorWidget::clear() 0545 { 0546 m_customSettings = Smb4KCustomSettings(); 0547 m_haveCustomSettings = false; 0548 setCurrentIndex(0); 0549 0550 m_alwaysRemountShare->setChecked(false); 0551 m_alwaysRemountShare->setEnabled(false); 0552 0553 #ifdef Q_OS_LINUX 0554 m_useWriteAccess->setChecked(false); 0555 m_writeAccess->setCurrentIndex(0); 0556 0557 m_useFileSystemPort->setChecked(false); 0558 m_fileSystemPort->setValue(445); 0559 0560 m_cifsUnixExtensionSupport->setChecked(false); 0561 #endif 0562 0563 m_useUserId->setChecked(false); 0564 m_userId->setCurrentIndex(0); 0565 0566 m_useGroupId->setChecked(false); 0567 m_groupId->setCurrentIndex(0); 0568 0569 m_useFileMode->setChecked(false); 0570 m_fileMode->clear(); 0571 0572 m_useDirectoryMode->setChecked(false); 0573 m_directoryMode->clear(); 0574 0575 #ifdef Q_OS_LINUX 0576 m_useSmbMountProtocolVersion->setChecked(false); 0577 m_smbMountProtocolVersion->setCurrentIndex(0); 0578 0579 m_useSecurityMode->setChecked(false); 0580 m_securityMode->setCurrentIndex(0); 0581 #endif 0582 0583 m_useClientProtocolVersions->setChecked(false); 0584 m_minimalClientProtocolVersion->setCurrentIndex(0); 0585 m_maximalClientProtocolVersion->setCurrentIndex(0); 0586 0587 m_useRemoteSmbPort->setChecked(false); 0588 m_remoteSmbPort->setValue(139); 0589 0590 m_useKerberos->setChecked(false); 0591 0592 m_macAddress->clear(); 0593 m_macAddress->setEnabled(false); 0594 m_sendPacketBeforeScan->setChecked(false); 0595 m_sendPacketBeforeScan->setEnabled(false); 0596 m_sendPacketBeforeMount->setChecked(false); 0597 m_sendPacketBeforeMount->setChecked(false); 0598 } 0599 0600 void Smb4KCustomSettingsEditorWidget::checkValues() 0601 { 0602 if (!m_haveCustomSettings) { 0603 return; 0604 } 0605 0606 if (m_alwaysRemountShare->isChecked() != (m_customSettings.remount() == Smb4KCustomSettings::RemountAlways)) { 0607 Q_EMIT edited(true); 0608 return; 0609 } 0610 0611 #ifdef Q_OS_LINUX 0612 if (m_useWriteAccess->isChecked() != m_customSettings.useWriteAccess()) { 0613 Q_EMIT edited(true); 0614 return; 0615 } 0616 0617 if (m_writeAccess->currentIndex() != m_customSettings.writeAccess()) { 0618 Q_EMIT edited(true); 0619 return; 0620 } 0621 0622 if (m_useFileSystemPort->isChecked() != m_customSettings.useFileSystemPort()) { 0623 Q_EMIT edited(true); 0624 return; 0625 } 0626 0627 if (m_fileSystemPort->value() != m_customSettings.fileSystemPort()) { 0628 Q_EMIT edited(true); 0629 return; 0630 } 0631 0632 if (m_cifsUnixExtensionSupport->isChecked() != m_customSettings.cifsUnixExtensionsSupport()) { 0633 Q_EMIT edited(true); 0634 return; 0635 } 0636 #endif 0637 0638 if (m_useUserId->isChecked() != m_customSettings.useUser()) { 0639 Q_EMIT edited(true); 0640 return; 0641 } 0642 0643 if (m_userId->currentData().toString() != m_customSettings.user().userId().toString()) { 0644 Q_EMIT edited(true); 0645 return; 0646 } 0647 0648 if (m_useGroupId->isChecked() != m_customSettings.useGroup()) { 0649 Q_EMIT edited(true); 0650 return; 0651 } 0652 0653 if (m_groupId->currentData().toString() != m_customSettings.group().groupId().toString()) { 0654 Q_EMIT edited(true); 0655 return; 0656 } 0657 0658 if (m_useFileMode->isChecked() != m_customSettings.useFileMode()) { 0659 Q_EMIT edited(true); 0660 return; 0661 } 0662 0663 if (m_fileMode->text() != m_customSettings.fileMode()) { 0664 Q_EMIT edited(true); 0665 return; 0666 } 0667 0668 if (m_useDirectoryMode->isChecked() != m_customSettings.useDirectoryMode()) { 0669 Q_EMIT edited(true); 0670 return; 0671 } 0672 0673 if (m_directoryMode->text() != m_customSettings.directoryMode()) { 0674 Q_EMIT edited(true); 0675 return; 0676 } 0677 0678 #ifdef Q_OS_LINUX 0679 if (m_useSmbMountProtocolVersion->isChecked() != m_customSettings.useMountProtocolVersion()) { 0680 Q_EMIT edited(true); 0681 return; 0682 } 0683 0684 if (m_smbMountProtocolVersion->currentData().toInt() != m_customSettings.mountProtocolVersion()) { 0685 Q_EMIT edited(true); 0686 return; 0687 } 0688 0689 if (m_useSecurityMode->isChecked() != m_customSettings.useSecurityMode()) { 0690 Q_EMIT edited(true); 0691 return; 0692 } 0693 0694 if (m_securityMode->currentData().toInt() != m_customSettings.securityMode()) { 0695 Q_EMIT edited(true); 0696 return; 0697 } 0698 #endif 0699 0700 if (m_useClientProtocolVersions->isChecked() != m_customSettings.useClientProtocolVersions()) { 0701 Q_EMIT edited(true); 0702 return; 0703 } 0704 0705 if (m_minimalClientProtocolVersion->currentData().toInt() != m_customSettings.minimalClientProtocolVersion()) { 0706 Q_EMIT edited(true); 0707 return; 0708 } 0709 0710 if (m_maximalClientProtocolVersion->currentData().toInt() != m_customSettings.maximalClientProtocolVersion()) { 0711 Q_EMIT edited(true); 0712 return; 0713 } 0714 0715 if (m_useRemoteSmbPort->isChecked() != m_customSettings.useSmbPort()) { 0716 Q_EMIT edited(true); 0717 return; 0718 } 0719 0720 if (m_remoteSmbPort->value() != m_customSettings.smbPort()) { 0721 Q_EMIT edited(true); 0722 return; 0723 } 0724 0725 if (m_useKerberos->isChecked() != m_customSettings.useKerberos()) { 0726 Q_EMIT edited(true); 0727 return; 0728 } 0729 0730 if (m_macAddress->hasAcceptableInput() && m_macAddress->text() != m_customSettings.macAddress()) { 0731 Q_EMIT edited(true); 0732 return; 0733 } 0734 0735 if (m_sendPacketBeforeScan->isChecked() != m_customSettings.wakeOnLanSendBeforeNetworkScan()) { 0736 Q_EMIT edited(true); 0737 return; 0738 } 0739 0740 if (m_sendPacketBeforeMount->isChecked() != m_customSettings.wakeOnLanSendBeforeMount()) { 0741 Q_EMIT edited(true); 0742 return; 0743 } 0744 0745 Q_EMIT edited(false); 0746 } 0747 0748 void Smb4KCustomSettingsEditorWidget::slotAlwaysRemoutShareToggled(bool checked) 0749 { 0750 Q_UNUSED(checked); 0751 checkValues(); 0752 } 0753 0754 #ifdef Q_OS_LINUX 0755 void Smb4KCustomSettingsEditorWidget::slotUseWriteAccessToggled(bool checked) 0756 { 0757 Q_UNUSED(checked); 0758 checkValues(); 0759 } 0760 0761 void Smb4KCustomSettingsEditorWidget::slotWriteAccessChanged(int index) 0762 { 0763 Q_UNUSED(index); 0764 checkValues(); 0765 } 0766 0767 void Smb4KCustomSettingsEditorWidget::slotUseFileSystemPortToggled(bool checked) 0768 { 0769 Q_UNUSED(checked); 0770 checkValues(); 0771 } 0772 0773 void Smb4KCustomSettingsEditorWidget::slotFileSystemPortChanged(int port) 0774 { 0775 Q_UNUSED(port); 0776 checkValues(); 0777 } 0778 0779 void Smb4KCustomSettingsEditorWidget::slotCifsUnixExtensionSupportToggled(bool checked) 0780 { 0781 Q_UNUSED(checked); 0782 0783 m_useUserId->setEnabled(!checked); 0784 m_userId->setEnabled(!checked); 0785 m_useGroupId->setEnabled(!checked); 0786 m_groupId->setEnabled(!checked); 0787 m_useFileMode->setEnabled(!checked); 0788 m_fileMode->setEnabled(!checked); 0789 m_useDirectoryMode->setEnabled(!checked); 0790 m_directoryMode->setEnabled(!checked); 0791 0792 checkValues(); 0793 } 0794 #endif 0795 0796 void Smb4KCustomSettingsEditorWidget::slotUseUserIdToggled(bool checked) 0797 { 0798 Q_UNUSED(checked); 0799 checkValues(); 0800 } 0801 0802 void Smb4KCustomSettingsEditorWidget::slotUserIdChanged(int index) 0803 { 0804 Q_UNUSED(index); 0805 checkValues(); 0806 } 0807 0808 void Smb4KCustomSettingsEditorWidget::slotUseGroupIdToggled(bool checked) 0809 { 0810 Q_UNUSED(checked); 0811 checkValues(); 0812 } 0813 0814 void Smb4KCustomSettingsEditorWidget::slotGroupIdChanged(int index) 0815 { 0816 Q_UNUSED(index); 0817 checkValues(); 0818 } 0819 0820 void Smb4KCustomSettingsEditorWidget::slotUseFileModeToggled(bool checked) 0821 { 0822 Q_UNUSED(checked); 0823 checkValues(); 0824 } 0825 0826 void Smb4KCustomSettingsEditorWidget::slotFileModeChanged(const QString &text) 0827 { 0828 Q_UNUSED(text); 0829 checkValues(); 0830 } 0831 0832 void Smb4KCustomSettingsEditorWidget::slotUseDirectoryModeToggled(bool checked) 0833 { 0834 Q_UNUSED(checked); 0835 checkValues(); 0836 } 0837 0838 void Smb4KCustomSettingsEditorWidget::slotDirectoryModeChanged(const QString &text) 0839 { 0840 Q_UNUSED(text); 0841 checkValues(); 0842 } 0843 0844 #ifdef Q_OS_LINUX 0845 void Smb4KCustomSettingsEditorWidget::slotUseSmbMountProtocolVersionToggled(bool checked) 0846 { 0847 Q_UNUSED(checked); 0848 checkValues(); 0849 } 0850 0851 void Smb4KCustomSettingsEditorWidget::slotSmbMountProtocolVersionChanged(int index) 0852 { 0853 Q_UNUSED(index); 0854 checkValues(); 0855 } 0856 0857 void Smb4KCustomSettingsEditorWidget::slotUseSecurityModeToggled(bool checked) 0858 { 0859 Q_UNUSED(checked); 0860 checkValues(); 0861 } 0862 0863 void Smb4KCustomSettingsEditorWidget::slotSecurityModeChanged(int index) 0864 { 0865 Q_UNUSED(index); 0866 checkValues(); 0867 } 0868 #endif 0869 0870 void Smb4KCustomSettingsEditorWidget::slotUseClientProtocolVersionsToggled(bool checked) 0871 { 0872 Q_UNUSED(checked); 0873 0874 m_minimalClientProtocolVersionLabel->setEnabled(checked); 0875 m_minimalClientProtocolVersion->setEnabled(checked); 0876 m_maximalClientProtocolVersionLabel->setEnabled(checked); 0877 m_maximalClientProtocolVersion->setEnabled(checked); 0878 0879 checkValues(); 0880 } 0881 0882 void Smb4KCustomSettingsEditorWidget::slotMinimalClientProtocolVersionChanged(int index) 0883 { 0884 Q_UNUSED(index); 0885 checkValues(); 0886 } 0887 0888 void Smb4KCustomSettingsEditorWidget::slotMaximalClientProtocolVersionChanged(int index) 0889 { 0890 Q_UNUSED(index); 0891 checkValues(); 0892 } 0893 0894 void Smb4KCustomSettingsEditorWidget::slotUseRemoteSmbPortToggled(bool checked) 0895 { 0896 Q_UNUSED(checked); 0897 checkValues(); 0898 } 0899 0900 void Smb4KCustomSettingsEditorWidget::slotRemoteSmbPortChanged(int port) 0901 { 0902 Q_UNUSED(port); 0903 checkValues(); 0904 } 0905 0906 void Smb4KCustomSettingsEditorWidget::slotUseKerberosToggled(bool checked) 0907 { 0908 Q_UNUSED(checked); 0909 checkValues(); 0910 } 0911 0912 void Smb4KCustomSettingsEditorWidget::slotMacAddressChanged(const QString &text) 0913 { 0914 Q_UNUSED(text); 0915 0916 m_sendPacketBeforeScan->setEnabled(!text.isEmpty() && m_macAddress->hasAcceptableInput()); 0917 m_sendPacketBeforeMount->setEnabled(!text.isEmpty() && m_macAddress->hasAcceptableInput()); 0918 0919 checkValues(); 0920 } 0921 0922 void Smb4KCustomSettingsEditorWidget::slotSendPacketBeforeScanToggled(bool checked) 0923 { 0924 Q_UNUSED(checked); 0925 checkValues(); 0926 } 0927 0928 void Smb4KCustomSettingsEditorWidget::slotSendPacketBeforeMountToggled(bool checked) 0929 { 0930 Q_UNUSED(checked); 0931 checkValues(); 0932 }