File indexing completed on 2023-12-03 11:58:23
0001 /* 0002 The configuration page for the mount options 0003 0004 SPDX-FileCopyrightText: 2015-2022 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 // application specific includes 0009 #include "smb4kconfigpagemounting.h" 0010 #include "core/smb4kglobal.h" 0011 0012 #if defined(Q_OS_LINUX) 0013 #include "core/smb4kmountsettings_linux.h" 0014 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) 0015 #include "core/smb4kmountsettings_bsd.h" 0016 #endif 0017 0018 // Qt includes 0019 #include <QCheckBox> 0020 #include <QGroupBox> 0021 #include <QInputDialog> 0022 #include <QLabel> 0023 #include <QMenu> 0024 #include <QSpinBox> 0025 #include <QToolButton> 0026 #include <QVBoxLayout> 0027 0028 // KDE includes 0029 #include <KComboBox> 0030 #include <KIconLoader> 0031 #include <KLineEdit> 0032 #include <KLocalizedString> 0033 #include <KMessageBox> 0034 #include <KUrlRequester> 0035 0036 using namespace Smb4KGlobal; 0037 0038 Smb4KConfigPageMounting::Smb4KConfigPageMounting(QWidget *parent) 0039 : QTabWidget(parent) 0040 { 0041 setupWidget(); 0042 } 0043 0044 Smb4KConfigPageMounting::~Smb4KConfigPageMounting() 0045 { 0046 } 0047 0048 bool Smb4KConfigPageMounting::checkSettings() 0049 { 0050 KUrlRequester *mountPrefix = findChild<KUrlRequester *>(QStringLiteral("kcfg_MountPrefix")); 0051 0052 if (mountPrefix) { 0053 if (!mountPrefix->url().isValid()) { 0054 mountPrefix->setFocus(); 0055 return false; 0056 } 0057 } 0058 0059 QCheckBox *useFileMode = findChild<QCheckBox *>(QStringLiteral("kcfg_UseFileMode")); 0060 KLineEdit *fileMode = findChild<KLineEdit *>(QStringLiteral("kcfg_FileMode")); 0061 0062 if (useFileMode && fileMode) { 0063 if (useFileMode->isChecked() && fileMode->text().trimmed().isEmpty()) { 0064 fileMode->setFocus(); 0065 return false; 0066 } 0067 } 0068 0069 QCheckBox *useDirectoryMode = findChild<QCheckBox *>(QStringLiteral("kcfg_UseDirectoryMode")); 0070 KLineEdit *directoryMode = findChild<KLineEdit *>(QStringLiteral("kcfg_DirectoryMode")); 0071 0072 if (useDirectoryMode && directoryMode) { 0073 if (useDirectoryMode->isChecked() && directoryMode->text().trimmed().isEmpty()) { 0074 directoryMode->setFocus(); 0075 return false; 0076 } 0077 } 0078 0079 return true; 0080 } 0081 0082 #if defined(Q_OS_LINUX) 0083 // 0084 // Linux 0085 // 0086 void Smb4KConfigPageMounting::setupWidget() 0087 { 0088 // 0089 // Basic Settings tab 0090 // 0091 QWidget *basicTab = new QWidget(this); 0092 QVBoxLayout *basicTabLayout = new QVBoxLayout(basicTab); 0093 0094 // 0095 // Directories 0096 // 0097 QGroupBox *directoryBox = new QGroupBox(i18n("Directories"), basicTab); 0098 QGridLayout *directoryBoxLayout = new QGridLayout(directoryBox); 0099 0100 QLabel *prefixLabel = new QLabel(Smb4KMountSettings::self()->mountPrefixItem()->label(), directoryBox); 0101 KUrlRequester *prefix = new KUrlRequester(directoryBox); 0102 prefix->setMode(KFile::Directory | KFile::LocalOnly); 0103 prefix->setObjectName(QStringLiteral("kcfg_MountPrefix")); 0104 0105 prefixLabel->setBuddy(prefix); 0106 0107 QCheckBox *lowercaseSubdirs = new QCheckBox(Smb4KMountSettings::self()->forceLowerCaseSubdirsItem()->label(), directoryBox); 0108 lowercaseSubdirs->setObjectName(QStringLiteral("kcfg_ForceLowerCaseSubdirs")); 0109 0110 directoryBoxLayout->addWidget(prefixLabel, 0, 0); 0111 directoryBoxLayout->addWidget(prefix, 0, 1); 0112 directoryBoxLayout->addWidget(lowercaseSubdirs, 1, 0, 1, 2); 0113 0114 basicTabLayout->addWidget(directoryBox, 0); 0115 0116 // 0117 // Behavior 0118 // 0119 QGroupBox *behaviorBox = new QGroupBox(i18n("Behavior"), this); 0120 QGridLayout *behaviorBoxLayout = new QGridLayout(behaviorBox); 0121 0122 QCheckBox *remountShares = new QCheckBox(Smb4KMountSettings::self()->remountSharesItem()->label(), behaviorBox); 0123 remountShares->setObjectName(QStringLiteral("kcfg_RemountShares")); 0124 0125 QLabel *remountAttemptsLabel = new QLabel(Smb4KMountSettings::self()->remountAttemptsItem()->label(), behaviorBox); 0126 remountAttemptsLabel->setObjectName(QStringLiteral("RemountAttemptsLabel")); 0127 remountAttemptsLabel->setIndent(25); 0128 0129 QSpinBox *remountAttempts = new QSpinBox(behaviorBox); 0130 remountAttempts->setObjectName(QStringLiteral("kcfg_RemountAttempts")); 0131 remountAttemptsLabel->setBuddy(remountAttempts); 0132 0133 QLabel *remountIntervalLabel = new QLabel(Smb4KMountSettings::self()->remountIntervalItem()->label(), behaviorBox); 0134 remountIntervalLabel->setObjectName(QStringLiteral("RemountIntervalLabel")); 0135 remountIntervalLabel->setIndent(25); 0136 0137 QSpinBox *remountInterval = new QSpinBox(behaviorBox); 0138 remountInterval->setObjectName(QStringLiteral("kcfg_RemountInterval")); 0139 remountInterval->setSuffix(i18n(" min")); 0140 remountIntervalLabel->setBuddy(remountInterval); 0141 0142 QCheckBox *unmountAllShares = new QCheckBox(Smb4KMountSettings::self()->unmountSharesOnExitItem()->label(), behaviorBox); 0143 unmountAllShares->setObjectName(QStringLiteral("kcfg_UnmountSharesOnExit")); 0144 0145 QCheckBox *unmountForeignShares = new QCheckBox(Smb4KMountSettings::self()->unmountForeignSharesItem()->label(), behaviorBox); 0146 unmountForeignShares->setObjectName(QStringLiteral("kcfg_UnmountForeignShares")); 0147 0148 QCheckBox *unmountInaccessibleShares = new QCheckBox(Smb4KMountSettings::self()->forceUnmountInaccessibleItem()->label(), behaviorBox); 0149 unmountInaccessibleShares->setObjectName(QStringLiteral("kcfg_ForceUnmountInaccessible")); 0150 0151 QCheckBox *detectAllShares = new QCheckBox(Smb4KMountSettings::self()->detectAllSharesItem()->label(), behaviorBox); 0152 detectAllShares->setObjectName(QStringLiteral("kcfg_DetectAllShares")); 0153 0154 behaviorBoxLayout->addWidget(remountShares, 0, 0, 1, 2); 0155 behaviorBoxLayout->addWidget(remountAttemptsLabel, 1, 0); 0156 behaviorBoxLayout->addWidget(remountAttempts, 1, 1); 0157 behaviorBoxLayout->addWidget(remountIntervalLabel, 2, 0); 0158 behaviorBoxLayout->addWidget(remountInterval, 2, 1); 0159 behaviorBoxLayout->addWidget(unmountAllShares, 3, 0, 1, 2); 0160 behaviorBoxLayout->addWidget(unmountInaccessibleShares, 4, 0, 1, 2); 0161 behaviorBoxLayout->addWidget(unmountForeignShares, 5, 0, 1, 2); 0162 behaviorBoxLayout->addWidget(detectAllShares, 6, 0, 1, 2); 0163 0164 basicTabLayout->addWidget(behaviorBox, 0); 0165 basicTabLayout->addStretch(100); 0166 0167 addTab(basicTab, i18n("Basic Settings")); 0168 0169 // 0170 // Common Mount Settings tab 0171 // 0172 QWidget *commonTab = new QWidget(this); 0173 QVBoxLayout *commonTabLayout = new QVBoxLayout(commonTab); 0174 0175 // 0176 // Common options group box 0177 // 0178 QGroupBox *commonOptions = new QGroupBox(i18n("Common Options"), commonTab); 0179 QGridLayout *commonOptionsLayout = new QGridLayout(commonOptions); 0180 0181 // Write access 0182 QCheckBox *useWriteAccess = new QCheckBox(Smb4KMountSettings::self()->useWriteAccessItem()->label(), commonOptions); 0183 useWriteAccess->setObjectName(QStringLiteral("kcfg_UseWriteAccess")); 0184 0185 KComboBox *writeAccess = new KComboBox(commonOptions); 0186 writeAccess->setObjectName(QStringLiteral("kcfg_WriteAccess")); 0187 0188 QList<KCoreConfigSkeleton::ItemEnum::Choice> writeAccessChoices = Smb4KMountSettings::self()->writeAccessItem()->choices(); 0189 0190 for (const KCoreConfigSkeleton::ItemEnum::Choice &wa : qAsConst(writeAccessChoices)) { 0191 writeAccess->addItem(wa.label); 0192 } 0193 0194 commonOptionsLayout->addWidget(useWriteAccess, 0, 0); 0195 commonOptionsLayout->addWidget(writeAccess, 0, 1); 0196 0197 // Character set 0198 QCheckBox *useCharacterSet = new QCheckBox(Smb4KMountSettings::self()->useClientCharsetItem()->label(), commonOptions); 0199 useCharacterSet->setObjectName(QStringLiteral("kcfg_UseClientCharset")); 0200 0201 KComboBox *characterSet = new KComboBox(commonOptions); 0202 characterSet->setObjectName(QStringLiteral("kcfg_ClientCharset")); 0203 0204 QList<KCoreConfigSkeleton::ItemEnum::Choice> charsetChoices = Smb4KMountSettings::self()->clientCharsetItem()->choices(); 0205 0206 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(charsetChoices)) { 0207 characterSet->addItem(c.label); 0208 } 0209 0210 commonOptionsLayout->addWidget(useCharacterSet, 1, 0); 0211 commonOptionsLayout->addWidget(characterSet, 1, 1); 0212 0213 // Remote filesystem port 0214 QCheckBox *useFilesystemPort = new QCheckBox(Smb4KMountSettings::self()->useRemoteFileSystemPortItem()->label(), commonOptions); 0215 useFilesystemPort->setObjectName(QStringLiteral("kcfg_UseRemoteFileSystemPort")); 0216 0217 QSpinBox *filesystemPort = new QSpinBox(commonOptions); 0218 filesystemPort->setObjectName(QStringLiteral("kcfg_RemoteFileSystemPort")); 0219 0220 commonOptionsLayout->addWidget(useFilesystemPort, 2, 0); 0221 commonOptionsLayout->addWidget(filesystemPort, 2, 1); 0222 0223 commonTabLayout->addWidget(commonOptions, 0); 0224 0225 // 0226 // CIFS Unix Extensions Support group box 0227 // 0228 QGroupBox *cifsExtensionSupportBox = new QGroupBox(i18n("CIFS Unix Extensions Support"), commonTab); 0229 QGridLayout *cifsExtensionSupportLayout = new QGridLayout(cifsExtensionSupportBox); 0230 0231 // CIFS Unix extensions support 0232 QCheckBox *cifsExtensionsSupport = new QCheckBox(Smb4KMountSettings::self()->cifsUnixExtensionsSupportItem()->label(), cifsExtensionSupportBox); 0233 cifsExtensionsSupport->setObjectName(QStringLiteral("kcfg_CifsUnixExtensionsSupport")); 0234 0235 cifsExtensionSupportLayout->addWidget(cifsExtensionsSupport, 0, 0, 1, 2); 0236 0237 // User information 0238 QCheckBox *useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), cifsExtensionSupportBox); 0239 useUserId->setObjectName(QStringLiteral("kcfg_UseUserId")); 0240 0241 QWidget *userIdInputWidget = new QWidget(cifsExtensionSupportBox); 0242 userIdInputWidget->setObjectName(QStringLiteral("UserIdInputWidget")); 0243 0244 QGridLayout *userLayout = new QGridLayout(userIdInputWidget); 0245 userLayout->setContentsMargins(0, 0, 0, 0); 0246 0247 KLineEdit *userId = new KLineEdit(userIdInputWidget); 0248 userId->setObjectName(QStringLiteral("kcfg_UserId")); 0249 userId->setAlignment(Qt::AlignRight); 0250 userId->setReadOnly(true); 0251 0252 QToolButton *userChooser = new QToolButton(userIdInputWidget); 0253 userChooser->setIcon(KDE::icon(QStringLiteral("edit-find-user"))); 0254 userChooser->setToolTip(i18n("Choose a different user")); 0255 userChooser->setPopupMode(QToolButton::InstantPopup); 0256 0257 QMenu *userMenu = new QMenu(userChooser); 0258 userChooser->setMenu(userMenu); 0259 0260 QList<KUser> allUsers = KUser::allUsers(); 0261 0262 for (const KUser &u : qAsConst(allUsers)) { 0263 QAction *userAction = userMenu->addAction(u.loginName() + QStringLiteral(" (") + u.userId().toString() + QStringLiteral(")")); 0264 userAction->setData(u.userId().nativeId()); 0265 } 0266 0267 userLayout->addWidget(userId, 0, 0); 0268 userLayout->addWidget(userChooser, 0, 1, Qt::AlignCenter); 0269 0270 cifsExtensionSupportLayout->addWidget(useUserId, 1, 0); 0271 cifsExtensionSupportLayout->addWidget(userIdInputWidget, 1, 1); 0272 0273 // Group information 0274 QCheckBox *useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), cifsExtensionSupportBox); 0275 useGroupId->setObjectName(QStringLiteral("kcfg_UseGroupId")); 0276 0277 QWidget *groupIdInputWidget = new QWidget(cifsExtensionSupportBox); 0278 groupIdInputWidget->setObjectName(QStringLiteral("GroupIdInputWidget")); 0279 0280 QGridLayout *groupLayout = new QGridLayout(groupIdInputWidget); 0281 groupLayout->setContentsMargins(0, 0, 0, 0); 0282 0283 KLineEdit *groupId = new KLineEdit(groupIdInputWidget); 0284 groupId->setObjectName(QStringLiteral("kcfg_GroupId")); 0285 groupId->setAlignment(Qt::AlignRight); 0286 groupId->setReadOnly(true); 0287 0288 QToolButton *groupChooser = new QToolButton(groupIdInputWidget); 0289 groupChooser->setIcon(KDE::icon(QStringLiteral("edit-find-user"))); 0290 groupChooser->setToolTip(i18n("Choose a different group")); 0291 groupChooser->setPopupMode(QToolButton::InstantPopup); 0292 0293 QMenu *groupMenu = new QMenu(groupChooser); 0294 groupChooser->setMenu(groupMenu); 0295 0296 QList<KUserGroup> groupList = KUserGroup::allGroups(); 0297 0298 for (const KUserGroup &g : qAsConst(groupList)) { 0299 QAction *groupAction = groupMenu->addAction(g.name() + QStringLiteral(" (") + g.groupId().toString() + QStringLiteral(")")); 0300 groupAction->setData(g.groupId().nativeId()); 0301 } 0302 0303 groupLayout->addWidget(groupId, 0, 0); 0304 groupLayout->addWidget(groupChooser, 0, 1, Qt::AlignCenter); 0305 0306 cifsExtensionSupportLayout->addWidget(useGroupId, 2, 0); 0307 cifsExtensionSupportLayout->addWidget(groupIdInputWidget, 2, 1); 0308 0309 // File mask 0310 QCheckBox *useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), cifsExtensionSupportBox); 0311 useFileMode->setObjectName(QStringLiteral("kcfg_UseFileMode")); 0312 0313 KLineEdit *fileMode = new KLineEdit(cifsExtensionSupportBox); 0314 fileMode->setObjectName(QStringLiteral("kcfg_FileMode")); 0315 fileMode->setClearButtonEnabled(true); 0316 fileMode->setAlignment(Qt::AlignRight); 0317 0318 cifsExtensionSupportLayout->addWidget(useFileMode, 3, 0); 0319 cifsExtensionSupportLayout->addWidget(fileMode, 3, 1); 0320 0321 // Directory mask 0322 QCheckBox *useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), cifsExtensionSupportBox); 0323 useDirectoryMode->setObjectName(QStringLiteral("kcfg_UseDirectoryMode")); 0324 0325 KLineEdit *directoryMode = new KLineEdit(cifsExtensionSupportBox); 0326 directoryMode->setObjectName(QStringLiteral("kcfg_DirectoryMode")); 0327 directoryMode->setClearButtonEnabled(true); 0328 directoryMode->setAlignment(Qt::AlignRight); 0329 0330 cifsExtensionSupportLayout->addWidget(useDirectoryMode, 4, 0); 0331 cifsExtensionSupportLayout->addWidget(directoryMode, 4, 1); 0332 0333 commonTabLayout->addWidget(cifsExtensionSupportBox, 1); 0334 commonTabLayout->addStretch(100); 0335 0336 addTab(commonTab, i18n("Common Mount Settings")); 0337 0338 // 0339 // Advanced Mount Settings tab 0340 // 0341 QWidget *advancedTab = new QWidget(this); 0342 QVBoxLayout *advancedTabLayout = new QVBoxLayout(advancedTab); 0343 0344 QGroupBox *advancedOptions = new QGroupBox(i18n("Advanced Options"), advancedTab); 0345 QGridLayout *advancedOptionsLayout = new QGridLayout(advancedOptions); 0346 0347 // Force Uid 0348 QCheckBox *forceUid = new QCheckBox(Smb4KMountSettings::self()->forceUIDItem()->label(), advancedOptions); 0349 forceUid->setObjectName(QStringLiteral("kcfg_ForceUID")); 0350 0351 advancedOptionsLayout->addWidget(forceUid, 0, 0); 0352 0353 // Force Gid 0354 QCheckBox *forceGid = new QCheckBox(Smb4KMountSettings::self()->forceGIDItem()->label(), advancedOptions); 0355 forceGid->setObjectName(QStringLiteral("kcfg_ForceGID")); 0356 0357 advancedOptionsLayout->addWidget(forceGid, 0, 1); 0358 0359 // Permission checks 0360 QCheckBox *permissionChecks = new QCheckBox(Smb4KMountSettings::self()->permissionChecksItem()->label(), advancedOptions); 0361 permissionChecks->setObjectName(QStringLiteral("kcfg_PermissionChecks")); 0362 0363 advancedOptionsLayout->addWidget(permissionChecks, 1, 0); 0364 0365 // Client controls Ids 0366 QCheckBox *clientControlsIds = new QCheckBox(Smb4KMountSettings::self()->clientControlsIDsItem()->label(), advancedOptions); 0367 clientControlsIds->setObjectName(QStringLiteral("kcfg_ClientControlsIDs")); 0368 0369 advancedOptionsLayout->addWidget(clientControlsIds, 1, 1); 0370 0371 // Use server inode numbers 0372 QCheckBox *useServerInodes = new QCheckBox(Smb4KMountSettings::self()->serverInodeNumbersItem()->label(), advancedOptions); 0373 useServerInodes->setObjectName(QStringLiteral("kcfg_ServerInodeNumbers")); 0374 0375 advancedOptionsLayout->addWidget(useServerInodes, 2, 0); 0376 0377 // Translate reserved characters 0378 QCheckBox *translateReservedCharacters = new QCheckBox(Smb4KMountSettings::self()->translateReservedCharsItem()->label(), advancedOptions); 0379 translateReservedCharacters->setObjectName(QStringLiteral("kcfg_TranslateReservedChars")); 0380 0381 advancedOptionsLayout->addWidget(translateReservedCharacters, 2, 1); 0382 0383 // No locking 0384 QCheckBox *no_locking = new QCheckBox(Smb4KMountSettings::self()->noLockingItem()->label(), advancedOptions); 0385 no_locking->setObjectName(QStringLiteral("kcfg_NoLocking")); 0386 0387 advancedOptionsLayout->addWidget(no_locking, 3, 0); 0388 0389 // Extra widget for the rest of the options 0390 QWidget *advancedOptionsExtraWidget = new QWidget(advancedOptions); 0391 QGridLayout *advancedOptionsExtraWidgetLayout = new QGridLayout(advancedOptionsExtraWidget); 0392 advancedOptionsExtraWidgetLayout->setContentsMargins(0, 0, 0, 0); 0393 0394 // SMB protocol version 0395 QCheckBox *useSmbProtocol = new QCheckBox(Smb4KMountSettings::self()->useSmbProtocolVersionItem()->label(), advancedOptionsExtraWidget); 0396 useSmbProtocol->setObjectName(QStringLiteral("kcfg_UseSmbProtocolVersion")); 0397 0398 KComboBox *smbProtocol = new KComboBox(advancedOptionsExtraWidget); 0399 smbProtocol->setObjectName(QStringLiteral("kcfg_SmbProtocolVersion")); 0400 0401 QList<KCoreConfigSkeleton::ItemEnum::Choice> smbProtocolChoices = Smb4KMountSettings::self()->smbProtocolVersionItem()->choices(); 0402 0403 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(smbProtocolChoices)) { 0404 smbProtocol->addItem(c.label); 0405 } 0406 0407 advancedOptionsExtraWidgetLayout->addWidget(useSmbProtocol, 0, 0); 0408 advancedOptionsExtraWidgetLayout->addWidget(smbProtocol, 0, 1); 0409 0410 // Cache mode 0411 QCheckBox *useCacheMode = new QCheckBox(Smb4KMountSettings::self()->useCacheModeItem()->label(), advancedOptionsExtraWidget); 0412 useCacheMode->setObjectName(QStringLiteral("kcfg_UseCacheMode")); 0413 0414 KComboBox *cacheMode = new KComboBox(advancedOptionsExtraWidget); 0415 cacheMode->setObjectName(QStringLiteral("kcfg_CacheMode")); 0416 0417 QList<KCoreConfigSkeleton::ItemEnum::Choice> cacheModeChoices = Smb4KMountSettings::self()->cacheModeItem()->choices(); 0418 0419 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : qAsConst(cacheModeChoices)) { 0420 cacheMode->addItem(c.label); 0421 } 0422 0423 advancedOptionsExtraWidgetLayout->addWidget(useCacheMode, 1, 0); 0424 advancedOptionsExtraWidgetLayout->addWidget(cacheMode, 1, 1); 0425 0426 // Security mode 0427 QCheckBox *useSecurityMode = new QCheckBox(Smb4KMountSettings::self()->useSecurityModeItem()->label(), advancedOptionsExtraWidget); 0428 useSecurityMode->setObjectName(QStringLiteral("kcfg_UseSecurityMode")); 0429 0430 KComboBox *securityMode = new KComboBox(advancedOptionsExtraWidget); 0431 securityMode->setObjectName(QStringLiteral("kcfg_SecurityMode")); 0432 0433 QList<KConfigSkeleton::ItemEnum::Choice> securityModeChoices = Smb4KMountSettings::self()->securityModeItem()->choices(); 0434 0435 for (const KConfigSkeleton::ItemEnum::Choice &c : qAsConst(securityModeChoices)) { 0436 securityMode->addItem(c.label); 0437 } 0438 0439 advancedOptionsExtraWidgetLayout->addWidget(useSecurityMode, 2, 0); 0440 advancedOptionsExtraWidgetLayout->addWidget(securityMode, 2, 1); 0441 0442 // Additional options 0443 QCheckBox *useAdditionalCifsOptions = new QCheckBox(Smb4KMountSettings::self()->useCustomCifsOptionsItem()->label(), advancedOptionsExtraWidget); 0444 useAdditionalCifsOptions->setObjectName(QStringLiteral("kcfg_UseCustomCifsOptions")); 0445 0446 QWidget *additionalOptionsWidget = new QWidget(advancedOptionsExtraWidget); 0447 QHBoxLayout *additionalOptionsWidgetLayout = new QHBoxLayout(additionalOptionsWidget); 0448 additionalOptionsWidgetLayout->setContentsMargins(0, 0, 0, 0); 0449 0450 KLineEdit *additionalOptions = new KLineEdit(additionalOptionsWidget); 0451 additionalOptions->setObjectName(QStringLiteral("kcfg_CustomCIFSOptions")); 0452 additionalOptions->setReadOnly(true); 0453 additionalOptions->setClearButtonEnabled(true); 0454 0455 QToolButton *additionalOptionsEdit = new QToolButton(advancedOptionsExtraWidget); 0456 additionalOptionsEdit->setIcon(KDE::icon(QStringLiteral("document-edit"))); 0457 additionalOptionsEdit->setToolTip(i18n("Edit the additional CIFS options.")); 0458 0459 additionalOptionsWidgetLayout->addWidget(additionalOptions, 0); 0460 additionalOptionsWidgetLayout->addWidget(additionalOptionsEdit, 0); 0461 0462 advancedOptionsExtraWidgetLayout->addWidget(useAdditionalCifsOptions, 3, 0); 0463 advancedOptionsExtraWidgetLayout->addWidget(additionalOptionsWidget, 3, 1); 0464 0465 advancedOptionsLayout->addWidget(advancedOptionsExtraWidget, 4, 0, 1, 2); 0466 0467 advancedTabLayout->addWidget(advancedOptions, 0); 0468 advancedTabLayout->addStretch(100); 0469 0470 addTab(advancedTab, i18n("Advanced Mount Settings")); 0471 0472 // 0473 // Adjust widgets 0474 // 0475 slotCIFSUnixExtensionsSupport(Smb4KMountSettings::cifsUnixExtensionsSupport()); 0476 slotRemountSharesToggled(Smb4KMountSettings::remountShares()); 0477 0478 // 0479 // Connections 0480 // 0481 connect(userMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotNewUserTriggered(QAction *))); 0482 connect(groupMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotNewGroupTriggered(QAction *))); 0483 connect(cifsExtensionsSupport, SIGNAL(toggled(bool)), this, SLOT(slotCIFSUnixExtensionsSupport(bool))); 0484 connect(additionalOptionsEdit, SIGNAL(clicked(bool)), this, SLOT(slotAdditionalCIFSOptions())); 0485 connect(remountShares, SIGNAL(toggled(bool)), this, SLOT(slotRemountSharesToggled(bool))); 0486 } 0487 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) 0488 // 0489 // FreeBSD and NetBSD 0490 // 0491 void Smb4KConfigPageMounting::setupWidget() 0492 { 0493 // 0494 // Basic Settings tab 0495 // 0496 QWidget *basicTab = new QWidget(this); 0497 QVBoxLayout *basicTabLayout = new QVBoxLayout(basicTab); 0498 0499 // 0500 // Directories 0501 // 0502 QGroupBox *directoryBox = new QGroupBox(i18n("Directories"), basicTab); 0503 QGridLayout *directoryBoxLayout = new QGridLayout(directoryBox); 0504 0505 QLabel *prefixLabel = new QLabel(Smb4KMountSettings::self()->mountPrefixItem()->label(), directoryBox); 0506 KUrlRequester *prefix = new KUrlRequester(directoryBox); 0507 prefix->setMode(KFile::Directory | KFile::LocalOnly); 0508 prefix->setObjectName(QStringLiteral("kcfg_MountPrefix")); 0509 0510 prefixLabel->setBuddy(prefix); 0511 0512 QCheckBox *lowercaseSubdirs = new QCheckBox(Smb4KMountSettings::self()->forceLowerCaseSubdirsItem()->label(), directoryBox); 0513 lowercaseSubdirs->setObjectName(QStringLiteral("kcfg_ForceLowerCaseSubdirs")); 0514 0515 directoryBoxLayout->addWidget(prefixLabel, 0, 0); 0516 directoryBoxLayout->addWidget(prefix, 0, 1); 0517 directoryBoxLayout->addWidget(lowercaseSubdirs, 1, 0, 1, 2); 0518 0519 basicTabLayout->addWidget(directoryBox, 0); 0520 0521 // 0522 // Behavior 0523 // 0524 QGroupBox *behaviorBox = new QGroupBox(i18n("Behavior"), basicTab); 0525 QGridLayout *behaviorBoxLayout = new QGridLayout(behaviorBox); 0526 0527 QCheckBox *remountShares = new QCheckBox(Smb4KMountSettings::self()->remountSharesItem()->label(), behaviorBox); 0528 remountShares->setObjectName(QStringLiteral("kcfg_RemountShares")); 0529 0530 QLabel *remountAttemptsLabel = new QLabel(Smb4KMountSettings::self()->remountAttemptsItem()->label(), behaviorBox); 0531 remountAttemptsLabel->setObjectName(QStringLiteral("RemountAttemptsLabel")); 0532 remountAttemptsLabel->setIndent(25); 0533 0534 QSpinBox *remountAttempts = new QSpinBox(behaviorBox); 0535 remountAttempts->setObjectName(QStringLiteral("kcfg_RemountAttempts")); 0536 remountAttemptsLabel->setBuddy(remountAttempts); 0537 0538 QLabel *remountIntervalLabel = new QLabel(Smb4KMountSettings::self()->remountIntervalItem()->label(), behaviorBox); 0539 remountIntervalLabel->setObjectName(QStringLiteral("RemountIntervalLabel")); 0540 remountIntervalLabel->setIndent(25); 0541 0542 QSpinBox *remountInterval = new QSpinBox(behaviorBox); 0543 remountInterval->setObjectName(QStringLiteral("kcfg_RemountInterval")); 0544 remountInterval->setSuffix(i18n(" min")); 0545 remountIntervalLabel->setBuddy(remountInterval); 0546 0547 QCheckBox *unmountAllShares = new QCheckBox(Smb4KMountSettings::self()->unmountSharesOnExitItem()->label(), behaviorBox); 0548 unmountAllShares->setObjectName(QStringLiteral("kcfg_UnmountSharesOnExit")); 0549 0550 QCheckBox *unmountForeignShares = new QCheckBox(Smb4KMountSettings::self()->unmountForeignSharesItem()->label(), behaviorBox); 0551 unmountForeignShares->setObjectName(QStringLiteral("kcfg_UnmountForeignShares")); 0552 0553 QCheckBox *detectAllShares = new QCheckBox(Smb4KMountSettings::self()->detectAllSharesItem()->label(), behaviorBox); 0554 detectAllShares->setObjectName(QStringLiteral("kcfg_DetectAllShares")); 0555 0556 behaviorBoxLayout->addWidget(remountShares, 0, 0, 1, 2); 0557 behaviorBoxLayout->addWidget(remountAttemptsLabel, 1, 0); 0558 behaviorBoxLayout->addWidget(remountAttempts, 1, 1); 0559 behaviorBoxLayout->addWidget(remountIntervalLabel, 2, 0); 0560 behaviorBoxLayout->addWidget(remountInterval, 2, 1); 0561 behaviorBoxLayout->addWidget(unmountAllShares, 3, 0, 1, 2); 0562 behaviorBoxLayout->addWidget(unmountForeignShares, 4, 0, 1, 2); 0563 behaviorBoxLayout->addWidget(detectAllShares, 5, 0, 1, 2); 0564 0565 basicTabLayout->addWidget(behaviorBox, 0); 0566 basicTabLayout->addStretch(100); 0567 0568 addTab(basicTab, i18n("Basic Settings")); 0569 0570 // 0571 // Mount Settings tab 0572 // 0573 QWidget *mountTab = new QWidget(this); 0574 QVBoxLayout *mountTabLayout = new QVBoxLayout(mountTab); 0575 0576 // 0577 // Common Options 0578 // 0579 QGroupBox *commonOptionsBox = new QGroupBox(i18n("Common Options"), mountTab); 0580 QGridLayout *commonOptionsBoxLayout = new QGridLayout(commonOptionsBox); 0581 0582 // User information 0583 QCheckBox *useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), commonOptionsBox); 0584 useUserId->setObjectName(QStringLiteral("kcfg_UseUserId")); 0585 0586 QWidget *userIdInputWidget = new QWidget(commonOptionsBox); 0587 userIdInputWidget->setObjectName(QStringLiteral("UserIdInputWidget")); 0588 0589 QGridLayout *userLayout = new QGridLayout(userIdInputWidget); 0590 userLayout->setContentsMargins(0, 0, 0, 0); 0591 0592 KLineEdit *userId = new KLineEdit(userIdInputWidget); 0593 userId->setObjectName(QStringLiteral("kcfg_UserId")); 0594 userId->setAlignment(Qt::AlignRight); 0595 userId->setReadOnly(true); 0596 0597 QToolButton *userChooser = new QToolButton(userIdInputWidget); 0598 userChooser->setIcon(KDE::icon(QStringLiteral("edit-find-user"))); 0599 userChooser->setToolTip(i18n("Choose a different user")); 0600 userChooser->setPopupMode(QToolButton::InstantPopup); 0601 0602 QMenu *userMenu = new QMenu(userChooser); 0603 userChooser->setMenu(userMenu); 0604 0605 QList<KUser> allUsers = KUser::allUsers(); 0606 0607 for (const KUser &u : allUsers) { 0608 QAction *userAction = userMenu->addAction(u.loginName() + QStringLiteral(" (") + u.userId().toString() + QStringLiteral(")")); 0609 userAction->setData(u.userId().nativeId()); 0610 } 0611 0612 userLayout->addWidget(userId, 0, 0); 0613 userLayout->addWidget(userChooser, 0, 1, Qt::AlignCenter); 0614 0615 commonOptionsBoxLayout->addWidget(useUserId, 0, 0); 0616 commonOptionsBoxLayout->addWidget(userIdInputWidget, 0, 1); 0617 0618 // Group information 0619 QCheckBox *useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), commonOptionsBox); 0620 useGroupId->setObjectName(QStringLiteral("kcfg_UseGroupId")); 0621 0622 QWidget *groupIdInputWidget = new QWidget(commonOptionsBox); 0623 groupIdInputWidget->setObjectName(QStringLiteral("GroupIdInputWidget")); 0624 0625 QGridLayout *groupLayout = new QGridLayout(groupIdInputWidget); 0626 groupLayout->setContentsMargins(0, 0, 0, 0); 0627 0628 KLineEdit *groupId = new KLineEdit(groupIdInputWidget); 0629 groupId->setObjectName(QStringLiteral("kcfg_GroupId")); 0630 groupId->setAlignment(Qt::AlignRight); 0631 groupId->setReadOnly(true); 0632 0633 QToolButton *groupChooser = new QToolButton(groupIdInputWidget); 0634 groupChooser->setIcon(KDE::icon(QStringLiteral("edit-find-user"))); 0635 groupChooser->setToolTip(i18n("Choose a different group")); 0636 groupChooser->setPopupMode(QToolButton::InstantPopup); 0637 0638 QMenu *groupMenu = new QMenu(groupChooser); 0639 groupChooser->setMenu(groupMenu); 0640 0641 QList<KUserGroup> groupList = KUserGroup::allGroups(); 0642 0643 for (const KUserGroup &g : groupList) { 0644 QAction *groupAction = groupMenu->addAction(g.name() + QStringLiteral(" (") + g.groupId().toString() + QStringLiteral(")")); 0645 groupAction->setData(g.groupId().nativeId()); 0646 } 0647 0648 groupLayout->addWidget(groupId, 0, 0); 0649 groupLayout->addWidget(groupChooser, 0, 1, Qt::AlignCenter); 0650 0651 commonOptionsBoxLayout->addWidget(useGroupId, 1, 0); 0652 commonOptionsBoxLayout->addWidget(groupIdInputWidget, 1, 1); 0653 0654 // File mask 0655 QCheckBox *useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), commonOptionsBox); 0656 useFileMode->setObjectName(QStringLiteral("kcfg_UseFileMode")); 0657 0658 KLineEdit *fileMode = new KLineEdit(commonOptionsBox); 0659 fileMode->setObjectName(QStringLiteral("kcfg_FileMode")); 0660 fileMode->setClearButtonEnabled(true); 0661 fileMode->setAlignment(Qt::AlignRight); 0662 0663 commonOptionsBoxLayout->addWidget(useFileMode, 2, 0); 0664 commonOptionsBoxLayout->addWidget(fileMode, 2, 1); 0665 0666 // Directory mask 0667 QCheckBox *useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), commonOptionsBox); 0668 useDirectoryMode->setObjectName(QStringLiteral("kcfg_UseDirectoryMode")); 0669 0670 KLineEdit *directoryMode = new KLineEdit(commonOptionsBox); 0671 directoryMode->setObjectName(QStringLiteral("kcfg_DirectoryMode")); 0672 directoryMode->setClearButtonEnabled(true); 0673 directoryMode->setAlignment(Qt::AlignRight); 0674 0675 commonOptionsBoxLayout->addWidget(useDirectoryMode, 3, 0); 0676 commonOptionsBoxLayout->addWidget(directoryMode, 3, 1); 0677 0678 // 0679 // Character sets 0680 // 0681 QGroupBox *characterSetsBox = new QGroupBox(i18n("Character Sets"), mountTab); 0682 QGridLayout *characterSetsBoxLayout = new QGridLayout(characterSetsBox); 0683 0684 // Client character set 0685 QCheckBox *useCharacterSets = new QCheckBox(Smb4KMountSettings::self()->useCharacterSetsItem()->label(), characterSetsBox); 0686 useCharacterSets->setObjectName(QStringLiteral("kcfg_UseCharacterSets")); 0687 0688 QLabel *clientCharacterSetLabel = new QLabel(Smb4KMountSettings::self()->clientCharsetItem()->label(), characterSetsBox); 0689 clientCharacterSetLabel->setIndent(25); 0690 clientCharacterSetLabel->setObjectName(QStringLiteral("ClientCharacterSetLabel")); 0691 0692 KComboBox *clientCharacterSet = new KComboBox(characterSetsBox); 0693 clientCharacterSet->setObjectName(QStringLiteral("kcfg_ClientCharset")); 0694 0695 QList<KCoreConfigSkeleton::ItemEnum::Choice> charsetChoices = Smb4KMountSettings::self()->clientCharsetItem()->choices(); 0696 0697 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : charsetChoices) { 0698 clientCharacterSet->addItem(c.label); 0699 } 0700 0701 clientCharacterSetLabel->setBuddy(clientCharacterSet); 0702 0703 // Server character set 0704 QLabel *serverCharacterSetLabel = new QLabel(Smb4KMountSettings::self()->serverCodepageItem()->label(), characterSetsBox); 0705 serverCharacterSetLabel->setIndent(25); 0706 serverCharacterSetLabel->setObjectName(QStringLiteral("ServerCodepageLabel")); 0707 0708 KComboBox *serverCharacterSet = new KComboBox(characterSetsBox); 0709 serverCharacterSet->setObjectName(QStringLiteral("kcfg_ServerCodepage")); 0710 0711 QList<KCoreConfigSkeleton::ItemEnum::Choice> codepageChoices = Smb4KMountSettings::self()->serverCodepageItem()->choices(); 0712 0713 for (const KCoreConfigSkeleton::ItemEnum::Choice &c : codepageChoices) { 0714 serverCharacterSet->addItem(c.label); 0715 } 0716 0717 serverCharacterSetLabel->setBuddy(serverCharacterSet); 0718 0719 characterSetsBoxLayout->addWidget(useCharacterSets, 0, 0, 1, 2); 0720 characterSetsBoxLayout->addWidget(clientCharacterSetLabel, 1, 0); 0721 characterSetsBoxLayout->addWidget(clientCharacterSet, 1, 1); 0722 characterSetsBoxLayout->addWidget(serverCharacterSetLabel, 2, 0); 0723 characterSetsBoxLayout->addWidget(serverCharacterSet, 2, 1); 0724 0725 mountTabLayout->addWidget(commonOptionsBox, 0); 0726 mountTabLayout->addWidget(characterSetsBox, 0); 0727 mountTabLayout->addStretch(100); 0728 0729 addTab(mountTab, i18n("Mount Settings")); 0730 0731 // 0732 // Connections 0733 // 0734 connect(userMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotNewUserTriggered(QAction *))); 0735 connect(groupMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotNewGroupTriggered(QAction *))); 0736 connect(useCharacterSets, SIGNAL(toggled(bool)), this, SLOT(slotCharacterSets(bool))); 0737 connect(remountShares, SIGNAL(toggled(bool)), this, SLOT(slotRemountSharesToggled(bool))); 0738 0739 // 0740 // Enable / disable widgets 0741 // 0742 slotCharacterSets(Smb4KMountSettings::useCharacterSets()); 0743 slotRemountSharesToggled(Smb4KMountSettings::remountShares()); 0744 } 0745 #else 0746 // 0747 // Dummy 0748 // 0749 void Smb4KConfigPageMounting::setupWidget() 0750 { 0751 } 0752 #endif 0753 0754 void Smb4KConfigPageMounting::slotNewUserTriggered(QAction *action) 0755 { 0756 KLineEdit *userId = findChild<KLineEdit *>(QStringLiteral("kcfg_UserId")); 0757 0758 if (userId) { 0759 userId->setText(action->data().toString()); 0760 } 0761 } 0762 0763 void Smb4KConfigPageMounting::slotNewGroupTriggered(QAction *action) 0764 { 0765 KLineEdit *groupId = findChild<KLineEdit *>(QStringLiteral("kcfg_GroupId")); 0766 0767 if (groupId) { 0768 groupId->setText(action->data().toString()); 0769 } 0770 } 0771 0772 void Smb4KConfigPageMounting::slotCIFSUnixExtensionsSupport(bool checked) 0773 { 0774 QCheckBox *useUserId = findChild<QCheckBox *>(QStringLiteral("kcfg_UseUserId")); 0775 0776 if (useUserId) { 0777 useUserId->setEnabled(!checked); 0778 } 0779 0780 QWidget *userIdInputWidget = findChild<QWidget *>(QStringLiteral("UserIdInputWidget")); 0781 0782 if (userIdInputWidget) { 0783 userIdInputWidget->setEnabled(!checked); 0784 } 0785 0786 QCheckBox *useGroupId = findChild<QCheckBox *>(QStringLiteral("kcfg_UseGroupId")); 0787 0788 if (useGroupId) { 0789 useGroupId->setEnabled(!checked); 0790 } 0791 0792 QWidget *groupIdInputWidget = findChild<QWidget *>(QStringLiteral("GroupIdInputWidget")); 0793 0794 if (groupIdInputWidget) { 0795 groupIdInputWidget->setEnabled(!checked); 0796 } 0797 0798 QCheckBox *useFileMode = findChild<QCheckBox *>(QStringLiteral("kcfg_UseFileMode")); 0799 0800 if (useFileMode) { 0801 useFileMode->setEnabled(!checked); 0802 } 0803 0804 KLineEdit *fileMode = findChild<KLineEdit *>(QStringLiteral("kcfg_FileMode")); 0805 0806 if (fileMode) { 0807 fileMode->setEnabled(!checked); 0808 } 0809 0810 QCheckBox *useDirectoryMode = findChild<QCheckBox *>(QStringLiteral("kcfg_UseDirectoryMode")); 0811 0812 if (useDirectoryMode) { 0813 useDirectoryMode->setEnabled(!checked); 0814 } 0815 0816 KLineEdit *directoryMode = findChild<KLineEdit *>(QStringLiteral("kcfg_DirectoryMode")); 0817 0818 if (directoryMode) { 0819 directoryMode->setEnabled(!checked); 0820 } 0821 } 0822 0823 void Smb4KConfigPageMounting::slotAdditionalCIFSOptions() 0824 { 0825 #if defined(Q_OS_LINUX) 0826 KLineEdit *cifsOptions = findChild<KLineEdit *>(QStringLiteral("kcfg_CustomCIFSOptions")); 0827 0828 if (cifsOptions) { 0829 QString options = cifsOptions->originalText(); 0830 0831 bool ok = false; 0832 options = QInputDialog::getText(this, 0833 i18n("Additional CIFS Options"), 0834 i18n("<qt>Enter the desired options as a comma separated list:</qt>"), 0835 QLineEdit::Normal, 0836 options, 0837 &ok); 0838 0839 if (ok) { 0840 if (!options.trimmed().isEmpty()) { 0841 // SECURITY: Only pass those arguments to mount.cifs that do not pose 0842 // a potential security risk and that have not already been defined. 0843 // 0844 // This is, among others, the proper fix to the security issue reported 0845 // by Heiner Markert (aka CVE-2014-2581). 0846 QStringList allowedArgs = allowedMountArguments(); 0847 QStringList deniedArgs; 0848 QStringList list = options.split(QStringLiteral(","), Qt::SkipEmptyParts); 0849 QMutableStringListIterator it(list); 0850 0851 while (it.hasNext()) { 0852 QString arg = it.next().section(QStringLiteral("="), 0, 0); 0853 0854 if (!allowedArgs.contains(arg)) { 0855 deniedArgs << arg; 0856 it.remove(); 0857 } 0858 } 0859 0860 if (!deniedArgs.isEmpty()) { 0861 QString msg = i18np( 0862 "<qt>The following entry is going to be removed from the additional options: %2. Please read the handbook for details.</qt>", 0863 "<qt>The following %1 entries are going to be removed from the additional options: %2. Please read the handbook for details.</qt>", 0864 deniedArgs.size(), 0865 deniedArgs.join(QStringLiteral(", "))); 0866 KMessageBox::information(this, msg); 0867 } 0868 0869 cifsOptions->setText(list.join(QStringLiteral(",")).trimmed()); 0870 } else { 0871 cifsOptions->clear(); 0872 } 0873 } 0874 } 0875 #endif 0876 } 0877 0878 void Smb4KConfigPageMounting::slotCharacterSets(bool on) 0879 { 0880 // 0881 // Client character set 0882 // 0883 QLabel *clientCharacterSetLabel = findChild<QLabel *>(QStringLiteral("ClientCharacterSetLabel")); 0884 0885 if (clientCharacterSetLabel) { 0886 clientCharacterSetLabel->setEnabled(on); 0887 } 0888 0889 KComboBox *clientCharacterSet = findChild<KComboBox *>(QStringLiteral("kcfg_ClientCharset")); 0890 0891 if (clientCharacterSet) { 0892 clientCharacterSet->setEnabled(on); 0893 } 0894 0895 // 0896 // Server character set 0897 // 0898 QLabel *serverCharacterSetLabel = findChild<QLabel *>(QStringLiteral("ServerCodepageLabel")); 0899 0900 if (serverCharacterSetLabel) { 0901 serverCharacterSetLabel->setEnabled(on); 0902 } 0903 0904 KComboBox *serverCharacterSet = findChild<KComboBox *>(QStringLiteral("kcfg_ServerCodepage")); 0905 0906 if (serverCharacterSet) { 0907 serverCharacterSet->setEnabled(on); 0908 } 0909 } 0910 0911 void Smb4KConfigPageMounting::slotRemountSharesToggled(bool on) 0912 { 0913 // 0914 // Get the widget 0915 // 0916 QLabel *remountAttemptsLabel = findChild<QLabel *>(QStringLiteral("RemountAttemptsLabel")); 0917 QSpinBox *remountAttempts = findChild<QSpinBox *>(QStringLiteral("kcfg_RemountAttempts")); 0918 QLabel *remountIntervalLabel = findChild<QLabel *>(QStringLiteral("RemountIntervalLabel")); 0919 QSpinBox *remountInterval = findChild<QSpinBox *>(QStringLiteral("kcfg_RemountInterval")); 0920 0921 // 0922 // Enable / disable the widgets 0923 // 0924 remountAttemptsLabel->setEnabled(on); 0925 remountAttempts->setEnabled(on); 0926 remountIntervalLabel->setEnabled(on); 0927 remountInterval->setEnabled(on); 0928 }