diff --git a/core/smb4kcustomoptions.cpp b/core/smb4kcustomoptions.cpp index 335805d..e89130c 100644 --- a/core/smb4kcustomoptions.cpp +++ b/core/smb4kcustomoptions.cpp @@ -1,982 +1,977 @@ /*************************************************************************** This class carries custom options ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kcustomoptions.h" #include "smb4ksettings.h" #if defined(Q_OS_LINUX) #include "smb4kmountsettings_linux.h" #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include "smb4kmountsettings_bsd.h" #endif // Qt includes #include #include // KDE includes #include #include class Smb4KCustomOptionsPrivate { public: QString workgroup; QUrl url; QHostAddress ip; NetworkItem type; Smb4KCustomOptions::Remount remount; bool useUser; KUser user; bool useGroup; KUserGroup group; bool useFileMode; QString fileMode; bool useDirectoryMode; QString directoryMode; #if defined(Q_OS_LINUX) bool cifsUnixExtensionsSupport; bool useFileSystemPort; int fileSystemPort; bool useSecurityMode; int securityMode; bool useWriteAccess; int writeAccess; #endif QString profile; bool useSmbPort; int smbPort; bool useKerberos; QString mac; bool wakeOnLanBeforeFirstScan; bool wakeOnLanBeforeMount; }; Smb4KCustomOptions::Smb4KCustomOptions(Smb4KHost *host) : d(new Smb4KCustomOptionsPrivate) { d->workgroup = host->workgroupName(); d->url = host->url(); d->type = Host; d->remount = UndefinedRemount; d->useUser = Smb4KMountSettings::useUserId(); d->user = KUser(Smb4KMountSettings::userId()); d->useGroup = Smb4KMountSettings::useGroupId(); d->group = KUserGroup(Smb4KMountSettings::groupId()); d->useFileMode = Smb4KMountSettings::useFileMode(); d->fileMode = Smb4KMountSettings::fileMode(); d->useDirectoryMode = Smb4KMountSettings::useDirectoryMode(); d->directoryMode = Smb4KMountSettings::directoryMode(); #if defined(Q_OS_LINUX) d->cifsUnixExtensionsSupport = Smb4KMountSettings::cifsUnixExtensionsSupport(); d->useFileSystemPort = Smb4KMountSettings::useRemoteFileSystemPort(); d->fileSystemPort = Smb4KMountSettings::remoteFileSystemPort(); d->useSecurityMode = Smb4KMountSettings::useSecurityMode(); d->securityMode = Smb4KMountSettings::securityMode(); d->useWriteAccess = Smb4KMountSettings::useWriteAccess(); d->writeAccess = Smb4KMountSettings::writeAccess(); #endif d->useSmbPort = Smb4KSettings::useRemoteSmbPort(); d->smbPort = host->port() != -1 ? host->port() : Smb4KSettings::remoteSmbPort(); d->useKerberos = Smb4KSettings::useKerberos(); d->ip.setAddress(host->ipAddress()); d->wakeOnLanBeforeFirstScan = false; d->wakeOnLanBeforeMount = false; } Smb4KCustomOptions::Smb4KCustomOptions(Smb4KShare *share) : d(new Smb4KCustomOptionsPrivate) { d->url = share->url(); d->workgroup = share->workgroupName(); d->type = Share; d->remount = UndefinedRemount; d->useUser = Smb4KMountSettings::useUserId(); d->user = share->user(); d->useGroup = Smb4KMountSettings::useGroupId(); d->group = share->group(); d->useFileMode = Smb4KMountSettings::useFileMode(); d->fileMode = Smb4KMountSettings::fileMode(); d->useDirectoryMode = Smb4KMountSettings::useDirectoryMode(); d->directoryMode = Smb4KMountSettings::directoryMode(); #if defined(Q_OS_LINUX) d->cifsUnixExtensionsSupport = Smb4KMountSettings::cifsUnixExtensionsSupport(); d->useFileSystemPort = Smb4KMountSettings::useRemoteFileSystemPort(); d->fileSystemPort = share->port() != -1 ? share->port() : Smb4KMountSettings::remoteFileSystemPort(); d->useSecurityMode = Smb4KMountSettings::useSecurityMode(); d->securityMode = Smb4KMountSettings::securityMode(); d->useWriteAccess = Smb4KMountSettings::useWriteAccess(); d->writeAccess = Smb4KMountSettings::writeAccess(); #endif d->useSmbPort = Smb4KSettings::useRemoteSmbPort(); d->smbPort = Smb4KSettings::remoteSmbPort(); d->useKerberos = Smb4KSettings::useKerberos(); d->ip.setAddress(share->hostIpAddress()); d->wakeOnLanBeforeFirstScan = false; d->wakeOnLanBeforeMount = false; } Smb4KCustomOptions::Smb4KCustomOptions(const Smb4KCustomOptions &o) : d(new Smb4KCustomOptionsPrivate) { *d = *o.d; } Smb4KCustomOptions::Smb4KCustomOptions() : d(new Smb4KCustomOptionsPrivate) { d->type = UnknownNetworkItem; d->remount = UndefinedRemount; d->useUser = Smb4KMountSettings::useUserId(); d->user = KUser(Smb4KMountSettings::userId()); d->useGroup = Smb4KMountSettings::useGroupId(); d->group = KUserGroup(Smb4KMountSettings::groupId()); d->useFileMode = Smb4KMountSettings::useFileMode(); d->fileMode = Smb4KMountSettings::fileMode(); d->useDirectoryMode = Smb4KMountSettings::useDirectoryMode(); d->directoryMode = Smb4KMountSettings::directoryMode(); #if defined(Q_OS_LINUX) d->cifsUnixExtensionsSupport = Smb4KMountSettings::cifsUnixExtensionsSupport(); d->useFileSystemPort = Smb4KMountSettings::useRemoteFileSystemPort(); d->fileSystemPort = Smb4KMountSettings::remoteFileSystemPort(); d->useSecurityMode = Smb4KMountSettings::useSecurityMode(); d->securityMode = Smb4KMountSettings::securityMode(); d->useWriteAccess = Smb4KMountSettings::useWriteAccess(); d->writeAccess = Smb4KMountSettings::writeAccess(); #endif d->useSmbPort = Smb4KSettings::useRemoteSmbPort(); d->smbPort = Smb4KSettings::remoteSmbPort(); d->useKerberos = Smb4KSettings::useKerberos(); d->wakeOnLanBeforeFirstScan = false; d->wakeOnLanBeforeMount = false; } Smb4KCustomOptions::~Smb4KCustomOptions() { } void Smb4KCustomOptions::setHost(Smb4KHost *host) { // // Set all variables that can be extracted from the host item // if (host) { switch (d->type) { case UnknownNetworkItem: { d->workgroup = host->workgroupName(); d->url = host->url(); d->type = Host; d->smbPort = host->port() != -1 ? host->port() : d->smbPort; d->ip.setAddress(host->ipAddress()); break; } default: { break; } } } } void Smb4KCustomOptions::setShare(Smb4KShare *share) { // // Set all variables that can be extracted from the share item // if (share) { switch (d->type) { case UnknownNetworkItem: { d->url = share->url(); d->workgroup = share->workgroupName(); d->type = Share; #if defined(Q_OS_LINUX) d->fileSystemPort = share->port() != -1 ? share->port() : d->fileSystemPort; #endif d->user = share->user(); d->group = share->group(); d->ip.setAddress(share->hostIpAddress()); break; } case Host: { if (QString::compare(d->url.toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::RemovePath), share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::RemovePath), Qt::CaseInsensitive) == 0) { d->url = share->url(); d->type = Share; #if defined(Q_OS_LINUX) d->fileSystemPort = share->port() != -1 ? share->port() : d->fileSystemPort; #endif d->user = share->user(); d->group = share->group(); d->ip.setAddress(share->hostIpAddress()); } break; } default: { break; } } } } Smb4KGlobal::NetworkItem Smb4KCustomOptions::type() const { return d->type; } void Smb4KCustomOptions::setWorkgroupName(const QString &workgroup) { d->workgroup = workgroup; } QString Smb4KCustomOptions::workgroupName() const { return d->workgroup; } void Smb4KCustomOptions::setUrl(const QUrl &url) { d->url = url; } QUrl Smb4KCustomOptions::url() const { return d->url; } QString Smb4KCustomOptions::hostName() const { return d->url.host().toUpper(); } QString Smb4KCustomOptions::shareName() const { if (d->url.path().startsWith('/')) { return d->url.path().remove(0, 1); } return d->url.path(); } void Smb4KCustomOptions::setIpAddress(const QString &ip) { d->ip.setAddress(ip); } QString Smb4KCustomOptions::ipAddress() const { return d->ip.toString(); } bool Smb4KCustomOptions::hasIpAddress() const { return !d->ip.isNull(); } QString Smb4KCustomOptions::displayString() const { QString string; switch (d->type) { case Host: { string = hostName(); break; } case Share: { string = i18n("%1 on %2", shareName(), hostName()); break; } default: { break; } } return string; } void Smb4KCustomOptions::setRemount(Smb4KCustomOptions::Remount remount) { switch (d->type) { case Share: { d->remount = remount; break; } default: { d->remount = UndefinedRemount; break; } } } Smb4KCustomOptions::Remount Smb4KCustomOptions::remount() const { return d->remount; } void Smb4KCustomOptions::setUseUser(bool use) { d->useUser = use; } bool Smb4KCustomOptions::useUser() const { return d->useUser; } void Smb4KCustomOptions::setUser(const KUser &user) { d->user = user; } KUser Smb4KCustomOptions::user() const { return d->user; } void Smb4KCustomOptions::setUseGroup(bool use) { d->useGroup = use; } bool Smb4KCustomOptions::useGroup() const { return d->useGroup; } void Smb4KCustomOptions::setGroup(const KUserGroup& group) { d->group = group; } KUserGroup Smb4KCustomOptions::group() const { return d->group; } void Smb4KCustomOptions::setUseFileMode(bool use) { d->useFileMode = use; } bool Smb4KCustomOptions::useFileMode() const { return d->useFileMode; } void Smb4KCustomOptions::setFileMode(const QString& mode) { d->fileMode = mode; } QString Smb4KCustomOptions::fileMode() const { return d->fileMode; } void Smb4KCustomOptions::setUseDirectoryMode(bool use) { d->useDirectoryMode = use; } bool Smb4KCustomOptions::useDirectoryMode() const { return d->useDirectoryMode; } void Smb4KCustomOptions::setDirectoryMode(const QString& mode) { d->directoryMode = mode; } QString Smb4KCustomOptions::directoryMode() const { return d->directoryMode; } #if defined(Q_OS_LINUX) void Smb4KCustomOptions::setCifsUnixExtensionsSupport(bool support) { d->cifsUnixExtensionsSupport = support; } bool Smb4KCustomOptions::cifsUnixExtensionsSupport() const { return d->cifsUnixExtensionsSupport; } void Smb4KCustomOptions::setUseFileSystemPort(bool use) { d->useFileSystemPort = use; } bool Smb4KCustomOptions::useFileSystemPort() const { return d->useFileSystemPort; } void Smb4KCustomOptions::setFileSystemPort(int port) { d->fileSystemPort = port; switch (d->type) { case Share: { d->url.setPort(port); break; } default: { break; } } } int Smb4KCustomOptions::fileSystemPort() const { return d->fileSystemPort; } void Smb4KCustomOptions::setUseSecurityMode(bool use) { d->useSecurityMode = use; } bool Smb4KCustomOptions::useSecurityMode() const { return d->useSecurityMode; } void Smb4KCustomOptions::setSecurityMode(int mode) { d->securityMode = mode; } int Smb4KCustomOptions::securityMode() const { return d->securityMode; } void Smb4KCustomOptions::setUseWriteAccess(bool use) { d->useWriteAccess = use; } bool Smb4KCustomOptions::useWriteAccess() const { return d->useWriteAccess; } void Smb4KCustomOptions::setWriteAccess(int access) { d->writeAccess = access; } int Smb4KCustomOptions::writeAccess() const { return d->writeAccess; } #endif void Smb4KCustomOptions::setProfile(const QString &profile) { d->profile = profile; } QString Smb4KCustomOptions::profile() const { return d->profile; } void Smb4KCustomOptions::setUseSmbPort(bool use) { d->useSmbPort = use; } bool Smb4KCustomOptions::useSmbPort() const { return d->useSmbPort; } void Smb4KCustomOptions::setSmbPort(int port) { d->smbPort = port; switch (d->type) { case Host: { d->url.setPort(port); break; } default: { break; } } } int Smb4KCustomOptions::smbPort() const { return d->smbPort; } void Smb4KCustomOptions::setUseKerberos(bool use) { d->useKerberos = use; } bool Smb4KCustomOptions::useKerberos() const { return d->useKerberos; } void Smb4KCustomOptions::setMACAddress(const QString &macAddress) { QRegExp exp("..\\:..\\:..\\:..\\:..\\:.."); if (exp.exactMatch(macAddress)) { d->mac = macAddress; } } QString Smb4KCustomOptions::macAddress() const { return d->mac; } void Smb4KCustomOptions::setWOLSendBeforeNetworkScan(bool send) { d->wakeOnLanBeforeFirstScan = send; } bool Smb4KCustomOptions::wolSendBeforeNetworkScan() const { return d->wakeOnLanBeforeFirstScan; } void Smb4KCustomOptions::setWOLSendBeforeMount(bool send) { d->wakeOnLanBeforeMount = send; } bool Smb4KCustomOptions::wolSendBeforeMount() const { return d->wakeOnLanBeforeMount; } QMap Smb4KCustomOptions::customOptions() const { QMap entries; switch (d->remount) { case RemountOnce: { entries.insert("remount", "once"); break; } case RemountAlways: { entries.insert("remount", "always"); break; } - case RemountNever: - { - entries.insert("remount", "never"); - break; - } case UndefinedRemount: { entries.insert("remount", QString()); break; } default: { break; } } entries.insert("use_user", d->useUser ? "true" : "false"); entries.insert("uid", QString("%1").arg(d->user.userId().toString())); entries.insert("owner", d->user.loginName()); entries.insert("use_group", d->useGroup ? "true" : "false"); entries.insert("gid", QString("%1").arg(d->group.groupId().toString())); entries.insert("group", d->group.name()); entries.insert("use_file_mode", d->useFileMode ? "true" : "false"); entries.insert("file_mode", d->fileMode); entries.insert("use_directory_mode", d->useDirectoryMode ? "true" : "false"); entries.insert("directory_mode", d->directoryMode); #if defined(Q_OS_LINUX) entries.insert("cifs_unix_extensions_support", d->cifsUnixExtensionsSupport ? "true" : "false"); entries.insert("use_filesystem_port", d->useFileSystemPort ? "true" : "false"); entries.insert("filesystem_port", QString("%1").arg(fileSystemPort())); entries.insert("use_security_mode", d->useSecurityMode ? "true" : "false"); switch (d->securityMode) { case Smb4KMountSettings::EnumSecurityMode::None: { entries.insert("security_mode", "none"); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5: { entries.insert("security_mode", "krb5"); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5i: { entries.insert("security_mode", "krb5i"); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlm: { entries.insert("security_mode", "ntlm"); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmi: { entries.insert("security_mode", "ntlmi"); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2: { entries.insert("security_mode", "ntlmv2"); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2i: { entries.insert("security_mode", "ntlmv2i"); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmssp: { entries.insert("security_mode", "ntlmssp"); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmsspi: { entries.insert("security_mode", "ntlmsspi"); break; } default: { break; } } entries.insert("use_write_access", d->useWriteAccess ? "true" : "false"); switch (d->writeAccess) { case Smb4KMountSettings::EnumWriteAccess::ReadWrite: { entries.insert("write_access", "true"); break; } case Smb4KMountSettings::EnumWriteAccess::ReadOnly: { entries.insert("write_access", "false"); break; } default: { break; } } #endif entries.insert("use_smb_port", d->useSmbPort ? "true" : "false"); entries.insert("smb_port", QString("%1").arg(smbPort())); entries.insert("kerberos", d->useKerberos ? "true" : "false"); entries.insert("mac_address", d->mac); entries.insert("wol_send_before_first_scan", d->wakeOnLanBeforeFirstScan ? "true" : "false"); entries.insert("wol_send_before_mount", d->wakeOnLanBeforeMount ? "true" : "false"); return entries; } bool Smb4KCustomOptions::hasOptions() const { // // NOTE: This function does not honor the workgroup, the url, // the ip address, the type and the profile, because these things // are not custom options. // // Perform remount if (d->remount != Smb4KCustomOptions::UndefinedRemount) { return true; } // Use user information if (d->useUser != Smb4KMountSettings::useUserId()) { return true; } // User information if (d->user.userId() != KUser(Smb4KMountSettings::userId()).userId()) { return true; } // Use group information if (d->useGroup != Smb4KMountSettings::useGroupId()) { return true; } // Group information if (d->group.groupId() != KUserGroup(Smb4KMountSettings::groupId()).groupId()) { return true; } // Use file mask if (d->useFileMode != Smb4KMountSettings::useFileMode()) { return true; } if (d->fileMode != Smb4KMountSettings::fileMode()) { return true; } if (d->useDirectoryMode != Smb4KMountSettings::useDirectoryMode()) { return true; } if (d->directoryMode != Smb4KMountSettings::directoryMode()) { return true; } #if defined(Q_OS_LINUX) // CIFS Unix extension support if (d->cifsUnixExtensionsSupport != Smb4KMountSettings::cifsUnixExtensionsSupport()) { return true; } // Use filesystem port if (d->useFileSystemPort != Smb4KMountSettings::useRemoteFileSystemPort()) { return true; } // File system port (used for mounting) if (d->fileSystemPort != Smb4KMountSettings::remoteFileSystemPort()) { return true; } // Use security mode if (d->useSecurityMode != Smb4KMountSettings::useSecurityMode()) { return true; } // Security mode if (d->securityMode != Smb4KMountSettings::securityMode()) { return true; } // Use write access if (d->useWriteAccess != Smb4KMountSettings::useWriteAccess()) { return true; } // Write access if (d->writeAccess != Smb4KMountSettings::writeAccess()) { return true; } #endif // Use SMB port if (d->useSmbPort != Smb4KSettings::useRemoteSmbPort()) { return true; } // SMB port if (d->smbPort != Smb4KSettings::remoteSmbPort()) { return true; } // Kerberos if (d->useKerberos != Smb4KSettings::useKerberos()) { return true; } // MAC address if (!d->mac.isEmpty()) { return true; } // Send WOL packages before first scan if (d->wakeOnLanBeforeFirstScan) { return true; } // Send WOL packages before mount if (d->wakeOnLanBeforeMount) { return true; } return false; } void Smb4KCustomOptions::update(Smb4KCustomOptions *options) { d->ip.setAddress(options->ipAddress()); d->remount = options->remount(); d->useUser = options->useUser(); d->user = options->user(); d->useGroup = options->useGroup(); d->group = options->group(); d->useFileMode = options->useFileMode(); d->fileMode = options->fileMode(); d->useDirectoryMode = options->useDirectoryMode(); d->directoryMode = options->directoryMode(); #if defined(Q_OS_LINUX) d->cifsUnixExtensionsSupport = options->cifsUnixExtensionsSupport(); d->useFileSystemPort = options->useFileSystemPort(); d->fileSystemPort = options->fileSystemPort(); d->useSecurityMode = options->useSecurityMode(); d->securityMode = options->securityMode(); d->useWriteAccess = options->useWriteAccess(); d->writeAccess = options->writeAccess(); #endif d->profile = options->profile(); d->useSmbPort = options->useSmbPort(); d->smbPort = options->smbPort(); d->useKerberos = options->useKerberos(); d->mac = options->macAddress(); d->wakeOnLanBeforeFirstScan = options->wolSendBeforeNetworkScan(); d->wakeOnLanBeforeMount = options->wolSendBeforeMount(); } diff --git a/core/smb4kcustomoptions.h b/core/smb4kcustomoptions.h index ce5e037..8cdcb7b 100644 --- a/core/smb4kcustomoptions.h +++ b/core/smb4kcustomoptions.h @@ -1,575 +1,574 @@ /*************************************************************************** This class carries custom options ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KCUSTOMOPTIONS_H #define SMB4KCUSTOMOPTIONS_H // application specific includes #include "smb4khost.h" #include "smb4kshare.h" #include "smb4kglobal.h" // Qt includes #include #include // KDE includes #include // forward declarations class Smb4KCustomOptionsPrivate; using namespace Smb4KGlobal; /** * This class stores the custom options defined for a certain host * or share. * * @author Alexander Reinholdt * @since 1.0.0 */ class Q_DECL_EXPORT Smb4KCustomOptions { friend class Smb4KCustomOptionsPrivate; public: /** * Constructor for a host */ explicit Smb4KCustomOptions(Smb4KHost *host); /** * Constructor for a share */ explicit Smb4KCustomOptions(Smb4KShare *share); /** * Copy constructor */ Smb4KCustomOptions(const Smb4KCustomOptions &options); /** * Empty constructor */ Smb4KCustomOptions(); /** * Destructor */ ~Smb4KCustomOptions(); /** * Sets the host object. If you already set a network item before, * this function will do nothing. * * @param host The host object */ void setHost(Smb4KHost *host); /** * Sets the share object. If you already set a host item before, * you can overwrite it with this function if the host names and * workgroup names match. This way you can propagate options that * were defined for a host to one of its shares. * * @param share The host object */ void setShare(Smb4KShare *share); /** * Returns the type of the network item for that the options * are defined * * @returns the type of the network item */ Smb4KGlobal::NetworkItem type() const; /** * Sets the workgroup name. * * @param workgroup The workgroup name */ void setWorkgroupName(const QString &workgroup); /** * Returns the workgroup name. * * @returns the workgroup name. */ QString workgroupName() const; /** * Sets the URL of the network item * * @param url The URL */ void setUrl(const QUrl &url); /** * Returns the URL of the network item * * @returns the URL */ QUrl url() const; /** * Returns the host name. * * @returns the host name. */ QString hostName() const; /** * Returns the share name, if appropriate, or an empty string. * * @returns the share name */ QString shareName() const; /** * Sets the IP address for the network item * * @param ip The IP address */ void setIpAddress(const QString &ip); /** * Returns the IP address of the network item * * @returns the IP address */ QString ipAddress() const; /** * Returns TRUE if the IP address is set and FALSE otherwise. * * @returns TRUE if the IP address is known. */ bool hasIpAddress() const; /** * Returns the display string. Prefer this over all other alternatives in your * GUI. * @returns the display string. */ QString displayString() const; /** * Remount enumeration * * @param RemountOnce Remount the share only next time the application * is started. * @param RemountAlways Remount the share every time the application is * started. * @param RemountNever Never remount the share. - * @param UndefinedRemount No remount option is defined. + * @param UndefinedRemount No remount behavior is undefined. */ enum Remount { RemountOnce, RemountAlways, - RemountNever, UndefinedRemount }; /** * If the network item is of type Share, set if it should be remounted. * If the network item is not of type Share, this function does nothing. * * @param remount One entry of the Remount enumeration */ void setRemount(Remount remount); /** * Returns if the network item should be remounted. * * @returns if the network item should be remounted. */ Remount remount() const; /** * Set if the information about the user that is to be owner of the share * should be used when mounting or not. * * @param usage Boolean that determines whether the uid should be * used. */ void setUseUser(bool use); /** * Use the information about the user that is to be owner of the share. * * @returns TRUE if the uid should be used when mounting. */ bool useUser() const; /** * Set the user who owns the share. * @param user The user */ void setUser(const KUser &user); /** * Returns the user who owns the share. * @returns the user */ KUser user() const; /** * Set if the information about the group that is to be owner of the share * should be used when mounting or not. * * @param use Boolean that determines whether the gid should be used. */ void setUseGroup(bool use); /** * Use the information about the group that is to be owner of the share. * * @returns TRUE if the gid should be used when mounting. */ bool useGroup() const; /** * Set the group that owns the share. * * @param group The group */ void setGroup(const KUserGroup &group); /** * Returns the group that owns the share. * * @returns the group */ KUserGroup group() const; /** * Set if the file mode should be used. * * @param use Boolean that determines whether the file mode should be used. */ void setUseFileMode(bool use); /** * Returns if the file mode should be used. * * @return TRUE if the file mode should be used */ bool useFileMode() const; /** * Set the file mode that should be used. The value must be defined in octal. * * @param mode The file mode */ void setFileMode(const QString &mode); /** * Returns the file mode that should be used. The value is returned in octal. * * @returns the file mode */ QString fileMode() const; /** * Set if the directory mode should be used. * * @param use Boolean that determines whether the directory mode should be used. */ void setUseDirectoryMode(bool use); /** * Returns if the directory mode should be used. * * @return TRUE if the file directory should be used */ bool useDirectoryMode() const; /** * Set the directory mode that should be used. The value must be defined in octal. * * @param mode The directory mode */ void setDirectoryMode(const QString &mode); /** * Returns the directory mode that should be used. The value is returned in octal. * * @returns the directory mode */ QString directoryMode() const; #if defined(Q_OS_LINUX) /** * Set if the server supports the CIFS Unix Extensions. If this setting is set, * the parameters that are not needed in the case of support are cleared. * * @param supports Boolean that determines if the server supports * the CIFS Unix extensions. */ void setCifsUnixExtensionsSupport(bool support); /** * The server supports the CIFS Unix extensions. * * @returns TRUE if the server supports the CIFS Unix Extensions. */ bool cifsUnixExtensionsSupport() const; /** * Set if the filesystem port should be used * * @param use Boolean that determines if the filesystem port should * be used */ void setUseFileSystemPort(bool use); /** * Returns if the filesystem port should be used. * * @returns TRUE if the filesystem port should be used */ bool useFileSystemPort() const; /** * Set the port that is to be used with mounting for a single share or all * shares of a host. * * @param port The file system port */ void setFileSystemPort(int port); /** * Returns the file system port. The default value is 445. * * @returns the file system port */ int fileSystemPort() const; /** * Set if the security mode should be used. * * @param use Boolean that determines if the security mode should * be used */ void setUseSecurityMode(bool use); /** * Returns if the security mode should be used * * @returns TRUE if the security mode should be used */ bool useSecurityMode() const; /** * Set the security mode for mounting. * * @param mode The security mode */ void setSecurityMode(int mode); /** * Returns the security mode for mounting a specific share. * * @returns the security mode */ int securityMode() const; /** * Set if the write access setting should be used. * * @param use Boolean that determines if the write access setting * should be used */ void setUseWriteAccess(bool use); /** * Returns if the write access setting should be used * * @returns TRUE if the write access setting should be used */ bool useWriteAccess() const; /** * Set the write access for either a single share or all shares of a host. * * @param access The write access */ void setWriteAccess(int access); /** * Returns the write access for the share. * * @returns the write access */ int writeAccess() const; #endif /** * Set the profile this custom options object belongs to. The profile is * meant to distinguish between several network environments, like home * and work. * * @param profile The profile name */ void setProfile(const QString &profile); /** * Returns the name of the profile this custom options object belongs to. * * @returns the profile name */ QString profile() const; /** * Set whether the SMB port should be used. * * @param use True, if the SMB port should be used */ void setUseSmbPort(bool use); /** * Returns whether the SMB port should be used. * * @returns TRUE if the SMB port should be used. */ bool useSmbPort() const; /** * Set the SMB port to use with this host or share. * * @param port The SMB port */ void setSmbPort(int port); /** * Returns the SMB port. The default value is 139. * * @returns the SMB port */ int smbPort() const; /** * Sets the useage of Kerberos for this network item. * * @param use Boolean that determines the useage of Kerberos */ void setUseKerberos(bool use); /** * Returns the usage of Kerberos for this network item. * * @returns the usage of Kerberos */ bool useKerberos() const; /** * This function sets the MAC address of a host. In case the options * represent a share this is the MAC address of the host that shares * the resource. * * @param macAddress The MAC address of the host */ void setMACAddress(const QString &macAddress); /** * This function returns the MAC address of the host or an empty string if * no MAC address was defined. * * @returns the MAC address of the host. */ QString macAddress() const; /** * Set whether a magic WOL package should be send to the host that this * network item represents or where this network item is located before scanning * the entire network. * * @param send Boolean that determines if a magic WOL package * is to be sent. */ void setWOLSendBeforeNetworkScan(bool send); /** * Send a magic WOL package to the host that this network item represents * or where this network item is located before scanning the entire network. * * @returns TRUE if a magic WOL package should be send on first network * scan. */ bool wolSendBeforeNetworkScan() const; /** * Set whether a magic WOL package should be send to the host that this * network item represents or where this network item is located before a * mount attempt. * * @param send Boolean that determines if a magic WOL package * is to be sent. */ void setWOLSendBeforeMount(bool send); /** * Send a magic WOL package to the host that this network item represents * or where this network item is located before a mount attempt. * * @returns TRUE if a magic WOL package should be send on first network * scan. */ bool wolSendBeforeMount() const; /** * This function returns all custom options in a sorted map. The URL, * workgroup and IP address must be retrieved separately if needed. * * Note that all entries that are set and valid are returned here. This * also comprises default values (e.g. the default SMB port). If you need * to check if a certain value is a custom option or not, you need to implement * this check. * * @returns all valid entries. */ QMap customOptions() const; /** * Check if there are options defined * * @returns TRUE if there are options defined and FALSE otherwise */ bool hasOptions() const; /** * Update this custom options object. You cannot change the workgroup, * URL and type with this function. * * @param options The options that are used to update this object */ void update(Smb4KCustomOptions *options); private: const QScopedPointer d; }; #endif diff --git a/core/smb4kcustomoptionsmanager.cpp b/core/smb4kcustomoptionsmanager.cpp index ac5a88f..715f37e 100644 --- a/core/smb4kcustomoptionsmanager.cpp +++ b/core/smb4kcustomoptionsmanager.cpp @@ -1,1164 +1,1186 @@ /*************************************************************************** Manage custom options ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kcustomoptionsmanager.h" #include "smb4kcustomoptionsmanager_p.h" #include "smb4kcustomoptions.h" #include "smb4khomesshareshandler.h" #include "smb4knotification.h" #include "smb4khost.h" #include "smb4kshare.h" #include "smb4ksettings.h" #include "smb4kglobal.h" #include "smb4kprofilemanager.h" #if defined(Q_OS_LINUX) #include "smb4kmountsettings_linux.h" #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include "smb4kmountsettings_bsd.h" #endif // Qt includes #include #include #include #include #include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include using namespace Smb4KGlobal; Q_GLOBAL_STATIC(Smb4KCustomOptionsManagerStatic, p); Smb4KCustomOptionsManager::Smb4KCustomOptionsManager(QObject *parent) : QObject(parent), d(new Smb4KCustomOptionsManagerPrivate) { // First we need the directory. QString path = dataLocation(); QDir dir; if (!dir.exists(path)) { dir.mkpath(path); } readCustomOptions(); // Connections connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit())); } Smb4KCustomOptionsManager::~Smb4KCustomOptionsManager() { } Smb4KCustomOptionsManager *Smb4KCustomOptionsManager::self() { return &p->instance; } void Smb4KCustomOptionsManager::addRemount(const SharePtr &share, bool always) { if (share) { + // + // Find the right custom options, if they exist + // OptionsPtr options = findOptions(share, true); if (options) { // If the options are already in the list, check if the share is // always to be remounted. If so, ignore the 'always' argument // and leave that option untouched. if (options->remount() != Smb4KCustomOptions::RemountAlways) { options->setRemount(always ? Smb4KCustomOptions::RemountAlways : Smb4KCustomOptions::RemountOnce); } } else { options = OptionsPtr(new Smb4KCustomOptions(share.data())); options->setProfile(Smb4KProfileManager::self()->activeProfile()); options->setRemount(always ? Smb4KCustomOptions::RemountAlways : Smb4KCustomOptions::RemountOnce); d->options << options; } + // + // Write the custom options + // writeCustomOptions(); } } void Smb4KCustomOptionsManager::removeRemount(const SharePtr &share, bool force) { if (share) { + // + // Get the remount + // OptionsPtr options = findOptions(share, true); + // + // Remove the remount flag and, if there are no more options defined, + // the options object itself. Save the modified list to the file afterwards. + // if (options) { if (options->remount() == Smb4KCustomOptions::RemountOnce) { - options->setRemount(Smb4KCustomOptions::RemountNever); + options->setRemount(Smb4KCustomOptions::UndefinedRemount); } else if (options->remount() == Smb4KCustomOptions::RemountAlways && force) { - options->setRemount(Smb4KCustomOptions::RemountNever); - } + options->setRemount(Smb4KCustomOptions::UndefinedRemount); + } + + if (!options->hasOptions()) + { + removeCustomOptions(options, false); + } } + // + // Write the options + // writeCustomOptions(); } } void Smb4KCustomOptionsManager::clearRemounts(bool force) { // - // List of relevant custom options + // Remove the remount flag and, if there are nomore options defined, + // also the options object. Write everything to the file afterwards. // - QList options = customOptions(false); - - // - // Remove the remount flags - // - for (const OptionsPtr &o : options) + for (const OptionsPtr &o : d->options) { if (o->type() == Share) { if (o->remount() == Smb4KCustomOptions::RemountOnce) { - o->setRemount(Smb4KCustomOptions::RemountNever); + o->setRemount(Smb4KCustomOptions::UndefinedRemount); } else if (o->remount() == Smb4KCustomOptions::RemountAlways && force) { - o->setRemount(Smb4KCustomOptions::RemountNever); + o->setRemount(Smb4KCustomOptions::UndefinedRemount); } } + + if (!o->hasOptions()) + { + removeCustomOptions(o, false); + } } // // Write the options // writeCustomOptions(); } QList Smb4KCustomOptionsManager::sharesToRemount() { // // List of relevant custom options // QList options = customOptions(false); // // List of remounts // QList remounts; // // Get the list of remounts // for (const OptionsPtr &o : options) { if (o->remount() == Smb4KCustomOptions::RemountOnce) { remounts << o; } else if (o->remount() == Smb4KCustomOptions::RemountAlways) { remounts << o; } } // // Return relevant options // return remounts; } OptionsPtr Smb4KCustomOptionsManager::findOptions(const NetworkItemPtr &networkItem, bool exactMatch) { // // The options that are to be returned // OptionsPtr options; // // Get the list of options // QList optionsList = customOptions(false); // // Only do something if the list of options is not empty. // if (!optionsList.isEmpty()) { for (const OptionsPtr &opt : optionsList) { // // If we want to have an exact match, skip all options that do not match // if (exactMatch) { if (networkItem->type() != opt->type() || QString::compare(networkItem->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash), opt->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash), Qt::CaseInsensitive) != 0) { continue; } } // // Now assign the options // if (networkItem->type() == Host && opt->type() == Host) { HostPtr host = networkItem.staticCast(); if (host) { if (QString::compare(host->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash), opt->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash), Qt::CaseInsensitive) == 0 || (host->url().isEmpty() && host->ipAddress() == opt->ipAddress())) { options = opt; break; } } } else if (networkItem->type() == Share) { SharePtr share = networkItem.staticCast(); if (share) { if (opt->type() == Share && QString::compare(share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash), opt->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash), Qt::CaseInsensitive) == 0) { // Since this is the exact match, break here options = opt; break; } else if (opt->type() == Host && QString::compare(share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::RemovePath|QUrl::StripTrailingSlash), opt->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::RemovePath|QUrl::StripTrailingSlash), Qt::CaseInsensitive) == 0) { // These options belong to the host. Do not break here, // because there might still be an exact match options = opt; } } } } } // // Return the options // return options; } OptionsPtr Smb4KCustomOptionsManager::findOptions(const QUrl &url) { // // The options that are to be returned // OptionsPtr options; // // Search the options for the given URL // if (url.isValid() && url.scheme() == "smb") { // // Get the relevant options // QList optionsList = customOptions(false); // // Get the options // for (const OptionsPtr &o : optionsList) { if (o->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash) == url.toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash)) { options = o; break; } } } // // Return the options // return options; } void Smb4KCustomOptionsManager::readCustomOptions() { // // Clear the list of options // while (!d->options.isEmpty()) { d->options.takeFirst().clear(); } // // Set the XML file // QFile xmlFile(dataLocation()+QDir::separator()+"custom_options.xml"); if (xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QXmlStreamReader xmlReader(&xmlFile); while (!xmlReader.atEnd()) { xmlReader.readNext(); if (xmlReader.isStartElement()) { if (xmlReader.name() == "custom_options" && (xmlReader.attributes().value("version") != "1.2" && xmlReader.attributes().value("version") != "2.0")) { xmlReader.raiseError(i18n("The format of %1 is not supported.", xmlFile.fileName())); break; } else { if (xmlReader.name() == "options") { OptionsPtr options = OptionsPtr(new Smb4KCustomOptions()); options->setProfile(xmlReader.attributes().value("profile").toString()); // // Initialize the options // if (QString::compare(xmlReader.attributes().value("type").toString(), "host", Qt::CaseInsensitive) == 0) { options->setHost(new Smb4KHost()); } else { options->setShare(new Smb4KShare()); } while (!(xmlReader.isEndElement() && xmlReader.name() == "options")) { xmlReader.readNext(); if (xmlReader.isStartElement()) { if (xmlReader.name() == "workgroup") { options->setWorkgroupName(xmlReader.readElementText()); } else if (xmlReader.name() == "url") { QUrl url(xmlReader.readElementText()); options->setUrl(url); } else if (xmlReader.name() == "unc") { QUrl url = QUrl::fromUserInput(xmlReader.readElementText()); url.setScheme("smb"); options->setUrl(url); } else if (xmlReader.name() == "ip") { options->setIpAddress(xmlReader.readElementText()); } else if (xmlReader.name() == "custom") { while (!(xmlReader.isEndElement() && xmlReader.name() == "custom")) { xmlReader.readNext(); if (xmlReader.isStartElement()) { if (xmlReader.name() == "smb_port") { bool ok = false; int portNumber = xmlReader.readElementText().toInt(&ok); if (ok) { options->setSmbPort(portNumber); } } else if (xmlReader.name() == "use_smb_port") { QString useSmbPort = xmlReader.readElementText(); if (useSmbPort == "true") { options->setUseSmbPort(true); } else { options->setUseSmbPort(false); } } else if (xmlReader.name() == "kerberos") { QString useKerberos = xmlReader.readElementText(); if (useKerberos == "true") { options->setUseKerberos(true); } else { options->setUseKerberos(false); } } else if (xmlReader.name() == "mac_address") { QString macAddress = xmlReader.readElementText(); QRegExp exp("..\\:..\\:..\\:..\\:..\\:.."); if (exp.exactMatch(macAddress)) { options->setMACAddress(macAddress); } } else if (xmlReader.name() == "wol_send_before_first_scan") { QString send = xmlReader.readElementText(); if (send == "true") { options->setWOLSendBeforeNetworkScan(true); } else { options->setWOLSendBeforeNetworkScan(false); } } else if (xmlReader.name() == "wol_send_before_mount") { QString send = xmlReader.readElementText(); if (send == "true") { options->setWOLSendBeforeMount(true); } else { options->setWOLSendBeforeMount(false); } } else if (xmlReader.name() == "remount") { QString remount = xmlReader.readElementText(); if (remount == "once") { options->setRemount(Smb4KCustomOptions::RemountOnce); } else if (remount == "always") { options->setRemount(Smb4KCustomOptions::RemountAlways); } - else if (remount == "never") - { - options->setRemount(Smb4KCustomOptions::RemountNever); - } else { options->setRemount(Smb4KCustomOptions::UndefinedRemount); } } else if (xmlReader.name() == "use_user") { QString useUser = xmlReader.readElementText(); if (useUser == "true") { options->setUseUser(true); } else { options->setUseUser(false); } } else if (xmlReader.name() == "uid") { KUser user((K_UID)xmlReader.readElementText().toInt()); if (user.isValid()) { options->setUser(user); } } else if (xmlReader.name() == "use_group") { QString useGroup = xmlReader.readElementText(); if (useGroup == "true") { options->setUseGroup(true); } else { options->setUseGroup(false); } } else if (xmlReader.name() == "gid") { KUserGroup group((K_GID)xmlReader.readElementText().toInt()); if (group.isValid()) { options->setGroup(group); } } else if (xmlReader.name() == "use_file_mode") { QString useFileMode = xmlReader.readElementText(); if (useFileMode == "true") { options->setUseFileMode(true); } else { options->setUseFileMode(false); } } else if (xmlReader.name() == "file_mode") { options->setFileMode(xmlReader.readElementText()); } else if (xmlReader.name() == "use_directory_mode") { QString useDirectoryMode = xmlReader.readElementText(); if (useDirectoryMode == "true") { options->setUseDirectoryMode(true); } else { options->setUseDirectoryMode(false); } } else if (xmlReader.name() == "directory_mode") { options->setDirectoryMode(xmlReader.readElementText()); } #if defined(Q_OS_LINUX) else if (xmlReader.name() == "cifs_unix_extensions_support") { QString support = xmlReader.readElementText(); if (support == "true") { options->setCifsUnixExtensionsSupport(true); } else { options->setCifsUnixExtensionsSupport(false); } } else if (xmlReader.name() == "use_filesystem_port") { QString useFilesystemPort = xmlReader.readElementText(); if (useFilesystemPort == "true") { options->setUseFileSystemPort(true); } else { options->setUseFileSystemPort(false); } } else if (xmlReader.name() == "filesystem_port") { bool ok = false; int portNumber = xmlReader.readElementText().toInt(&ok); if (ok) { options->setFileSystemPort(portNumber); } } else if (xmlReader.name() == "use_security_mode") { QString useSecurityMode = xmlReader.readElementText(); if (useSecurityMode == "true") { options->setUseSecurityMode(true); } else { options->setUseSecurityMode(false); } } else if (xmlReader.name() == "security_mode") { QString securityMode = xmlReader.readElementText(); if (securityMode == "none") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::None); } else if (securityMode == "krb5") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Krb5); } else if (securityMode == "krb5i") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Krb5i); } else if (securityMode == "ntlm") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlm); } else if (securityMode == "ntlmi") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmi); } else if (securityMode == "ntlmv2") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmv2); } else if (securityMode == "ntlmv2i") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i); } else if (securityMode == "ntlmssp") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmssp); } else if (securityMode == "ntlmsspi") { options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi); } } else if (xmlReader.name() == "use_write_access") { QString useWriteAccess = xmlReader.readElementText(); if (useWriteAccess == "true") { options->setUseWriteAccess(true); } else { options->setUseWriteAccess(false); } } else if (xmlReader.name() == "write_access") { QString writeAccess = xmlReader.readElementText(); if (writeAccess == "true") { options->setWriteAccess(Smb4KMountSettings::EnumWriteAccess::ReadWrite); } else if (writeAccess == "false") { options->setWriteAccess(Smb4KMountSettings::EnumWriteAccess::ReadWrite); } } #endif } } } continue; } else { continue; } } d->options << options; } } } } xmlFile.close(); if (xmlReader.hasError()) { Smb4KNotification::readingFileFailed(xmlFile, xmlReader.errorString()); } } else { if (xmlFile.exists()) { Smb4KNotification::openingFileFailed(xmlFile); } } } void Smb4KCustomOptionsManager::writeCustomOptions() { // // Set the XML file // QFile xmlFile(dataLocation()+QDir::separator()+"custom_options.xml"); // // Write the options to the file // if (!d->options.isEmpty()) { if (xmlFile.open(QIODevice::WriteOnly|QIODevice::Text)) { QXmlStreamWriter xmlWriter(&xmlFile); xmlWriter.setAutoFormatting(true); xmlWriter.writeStartDocument(); xmlWriter.writeStartElement("custom_options"); xmlWriter.writeAttribute("version", "2.0"); for (const OptionsPtr &options : d->options) { if (options->hasOptions() || options->remount() == Smb4KCustomOptions::RemountOnce) { xmlWriter.writeStartElement("options"); xmlWriter.writeAttribute("type", options->type() == Host ? "host" : "share"); xmlWriter.writeAttribute("profile", options->profile()); xmlWriter.writeTextElement("workgroup", options->workgroupName()); xmlWriter.writeTextElement("url", options->url().toDisplayString()); xmlWriter.writeTextElement("ip", options->ipAddress()); xmlWriter.writeStartElement("custom"); QMap map = options->customOptions(); QMapIterator it(map); while (it.hasNext()) { it.next(); if (!it.value().isEmpty()) { xmlWriter.writeTextElement(it.key(), it.value()); } } xmlWriter.writeEndElement(); xmlWriter.writeEndElement(); } } xmlWriter.writeEndDocument(); xmlFile.close(); } else { Smb4KNotification::openingFileFailed(xmlFile); } } else { xmlFile.remove(); } - - // FIXME: Flush the list of custom options and reload it? } QList Smb4KCustomOptionsManager::customOptions(bool optionsOnly) { // // Options list // QList options; // // Get this list of options // for (const OptionsPtr &o : d->options) { if (Smb4KSettings::useProfiles() && o->profile() != Smb4KProfileManager::self()->activeProfile()) { continue; } if (o->hasOptions() || (!optionsOnly && o->remount() == Smb4KCustomOptions::RemountOnce)) { options << o; } } // // Return the list of relevant options // return options; } void Smb4KCustomOptionsManager::replaceCustomOptions(const QList &optionsList) { // // Clear the list of options. Honor profiles. // QMutableListIterator it(d->options); while (it.hasNext()) { OptionsPtr options = it.next(); if (Smb4KSettings::useProfiles() && options->profile() != Smb4KProfileManager::self()->activeProfile()) { continue; } it.remove(); } // // Append the new list // if (!optionsList.isEmpty()) { for (const OptionsPtr &options : optionsList) { if (Smb4KSettings::useProfiles()) { options->setProfile(Smb4KProfileManager::self()->activeProfile()); } if (options->hasOptions() || options->remount() == Smb4KCustomOptions::RemountOnce) { d->options << options; } } } writeCustomOptions(); } void Smb4KCustomOptionsManager::openCustomOptionsDialog(const NetworkItemPtr &item) { if (item) { OptionsPtr options; switch (item->type()) { case Host: { HostPtr host = item.staticCast(); if (host) { options = findOptions(host); if (!options) { options = OptionsPtr(new Smb4KCustomOptions(host.data())); options->setProfile(Smb4KProfileManager::self()->activeProfile()); } } break; } case Share: { SharePtr share = item.staticCast(); if (share && !share->isPrinter()) { if (share->isHomesShare()) { if (!Smb4KHomesSharesHandler::self()->specifyUser(share, true)) { return; } } options = findOptions(share); if (!options) { options = OptionsPtr(new Smb4KCustomOptions(share.data())); options->setProfile(Smb4KProfileManager::self()->activeProfile()); // Get rid of the 'homes' share if (share->isHomesShare()) { options->setUrl(share->homeUrl()); } } else { // In case the custom options object for the host has been // returned, change its internal network item, otherwise we // will change the host's custom options... options->setShare(share.data()); } } break; } default: { break; } } if (options) { QPointer dlg = new Smb4KCustomOptionsDialog(options, QApplication::activeWindow()); if (dlg->exec() == QDialog::Accepted) { if (options->hasOptions()) { - addCustomOptions(options); + addCustomOptions(options, true); } else { - removeCustomOptions(options); + removeCustomOptions(options, true); } } else { resetCustomOptions(); } delete dlg; } } } -void Smb4KCustomOptionsManager::addCustomOptions(const OptionsPtr &options) +void Smb4KCustomOptionsManager::addCustomOptions(const OptionsPtr &options, bool write) { if (options) { // // Check if options for the URL already exist // OptionsPtr knownOptions = findOptions(options->url()); if (knownOptions) { // // Update the options // knownOptions->update(options.data()); } else { // // Add the options // if (options->profile().isEmpty()) { options->setProfile(Smb4KProfileManager::self()->activeProfile()); } d->options << options; } // // In case the options are defined for a host, propagate them // to the options of shares belonging to that host. Overwrite // the settings // if (options->type() == Host) { for (const OptionsPtr &o : d->options) { if (o->type() == Share && o->hostName() == options->hostName() && o->workgroupName() == options->workgroupName()) { o->setIpAddress(options->ipAddress()); o->setUseUser(options->useUser()); o->setUser(options->user()); o->setUseGroup(options->useGroup()); o->setGroup(options->group()); o->setUseFileMode(options->useFileMode()); o->setFileMode(options->fileMode()); o->setUseDirectoryMode(options->useDirectoryMode()); o->setDirectoryMode(options->directoryMode()); #if defined(Q_OS_LINUX) o->setCifsUnixExtensionsSupport(options->cifsUnixExtensionsSupport()); o->setUseFileSystemPort(options->useFileSystemPort()); o->setFileSystemPort(options->fileSystemPort()); o->setUseSecurityMode(options->useSecurityMode()); o->setSecurityMode(options->securityMode()); o->setUseWriteAccess(options->useWriteAccess()); o->setWriteAccess(options->writeAccess()); #endif o->setUseSmbPort(options->useSmbPort()); o->setSmbPort(options->smbPort()); o->setUseKerberos(options->useKerberos()); o->setMACAddress(options->macAddress()); o->setWOLSendBeforeNetworkScan(options->wolSendBeforeNetworkScan()); o->setWOLSendBeforeMount(options->wolSendBeforeMount()); } } } // - // Write the custom options to the file + // Write the custom options to the file, if desired // - writeCustomOptions(); + if (write) + { + writeCustomOptions(); + } } } -void Smb4KCustomOptionsManager::removeCustomOptions(const OptionsPtr &options) +void Smb4KCustomOptionsManager::removeCustomOptions(const OptionsPtr &options, bool write) { if (options) { // // Find the custom options and remove them // for (int i = 0; i < d->options.size(); ++i) { if ((!Smb4KSettings::useProfiles() || Smb4KProfileManager::self()->activeProfile() == d->options.at(i)->profile()) && d->options.at(i)->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash) == options->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash)) { d->options.takeAt(i).clear(); break; } } // - // Write the custom options to the file + // Write the custom options to the file, if desired // - writeCustomOptions(); + if (write) + { + writeCustomOptions(); + } } } QList Smb4KCustomOptionsManager::wakeOnLanEntries() const { QList list; // // Get the Wake-On-LAN entries // for (const OptionsPtr &options : d->options) { if (!options->macAddress().isEmpty() && (options->wolSendBeforeNetworkScan() || options->wolSendBeforeMount())) { list << options; } } // // Return them // return list; } void Smb4KCustomOptionsManager::resetCustomOptions() { readCustomOptions(); } void Smb4KCustomOptionsManager::migrateProfile(const QString& from, const QString& to) { // // Replace the old with the new profile // for (const OptionsPtr &options : d->options) { if (options->profile() == from) { options->setProfile(to); } } // // Write all custom options to the file. // writeCustomOptions(); } void Smb4KCustomOptionsManager::removeProfile(const QString& name) { // // Remove all entries belonging to the profile // QMutableListIterator it(d->options); while (it.hasNext()) { OptionsPtr options = it.next(); if (QString::compare(options->profile(), name, Qt::CaseSensitive) == 0) { it.remove(); } } // // Write all custom options to the file. // writeCustomOptions(); } ///////////////////////////////////////////////////////////////////////////// // SLOT IMPLEMENTATIONS ///////////////////////////////////////////////////////////////////////////// void Smb4KCustomOptionsManager::slotAboutToQuit() { writeCustomOptions(); } diff --git a/core/smb4kcustomoptionsmanager.h b/core/smb4kcustomoptionsmanager.h index 87174d3..a1da09a 100644 --- a/core/smb4kcustomoptionsmanager.h +++ b/core/smb4kcustomoptionsmanager.h @@ -1,250 +1,254 @@ /*************************************************************************** Manage custom options ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KCUSTOMOPTIONSMANAGER_H #define SMB4KCUSTOMOPTIONSMANAGER_H // application specific includes #include "smb4kglobal.h" // Qt includes #include #include // forward declarations class Smb4KCustomOptionsManagerPrivate; class Smb4KProfileManager; /** * This classes manages the custom options that were defined * for a certain share or host. * * @author Alexander Reinholdt * @since 1.0.0 */ class Q_DECL_EXPORT Smb4KCustomOptionsManager : public QObject { Q_OBJECT friend class Smb4KCustomOptionsManagerPrivate; friend class Smb4KProfileManager; public: /** * Constructor */ explicit Smb4KCustomOptionsManager(QObject *parent = 0); /** * Destructor */ ~Smb4KCustomOptionsManager(); /** * Returns a static pointer to this class * * @returns a static pointer to this class */ static Smb4KCustomOptionsManager *self(); /** * Add the share to the list of shares that are to be remounted * either only on next program start or always Smb4K is restarted. * * @param share The share object * * @param always If set to TRUE the share is always mounted * when Smb4K is restarted. */ void addRemount(const SharePtr &share, bool always = false); /** * Remove the share @p share from the list of shares that are to be * remounted. If @p force is set to TRUE, the share is removed even * if it should always be removed (option is set to * Smb4KCustomOptions::AlwaysRemount). Apart from that, the share is only * removed when the option is set to Smb4KCustomOptions::DoRemount. * * @param share The share object * * @param force If set to TRUE, the share is removed regardless of the * remount setting. */ void removeRemount(const SharePtr &share, bool force = false); /** * Removes all remounts from the list of custom options. If @p force * is set to TRUE, even those are removed that should always be remounted. * * @param force If set to TRUE, even those shares are removed that should * always be remounted. */ void clearRemounts(bool force); /** * Returns the list of shares that are to be remounted. * * @returns the list of shares that are to be remounted */ QList sharesToRemount(); /** * Find custom options for the network item @p networkItem. * * If the network item represents a share and custom options for it are not * defined, but for the host that provides the share, the options for the host * are returned. If neither is in the list, NULL is returned. * * If you set @p exactMatch to TRUE, NULL will be returned if the URL is not found. * Except in some special cases, you should not set @p exactMatch to true, * because options that are defined for all shares provided by a certain host and * stored in a host-type custom options object are ignored then. * * @param networkItem The network item * @param exaxtMatch If TRUE, only exact matches are returned * * @returns the custom options for the network item */ OptionsPtr findOptions(const NetworkItemPtr &networkItem, bool exactMatch = false); /** * Find custom options for the provided @p url. * * This function searches the list of custom options and compares the host entry * and, if applicable, the path (i.e. the share name). If an exact match was found, * the corresponding custom options are returned. * * @param url The network item's URL * * @returns the custom options */ OptionsPtr findOptions(const QUrl &url); /** * Get the list of custom options. By default, the list not only comprises of those * items that have custom options defined but also of those that are "only" to be * remounted. If @p optionsOnly is defined, only those entries are returned that have * custom options defined. Those that are only to be remounted won't be returned. * * @param optionsOnly Only return those entries that have custom options defined * * @returns the list of custom options objects. */ QList customOptions(bool optionsOnly = false); /** * Replace all previously defined custom options with a list of new ones. If you * just want to change certain custom options, use the findOptions() functions. * * @param optionsList The list of new or updated options */ void replaceCustomOptions(const QList &optionsList); /** * This function opens the custom options dialog. * * @param item The network item - either host or share * * @param parent The parent widget */ void openCustomOptionsDialog(const NetworkItemPtr &item); /** * This function adds custom options for a single network item to the list * of options. If there already are options defined for that network item, * they are updated. * * Please note that this function will store a copy of @p options and not * the original object. * * @param options The custom options + * + * @param write Write the options to the file */ - void addCustomOptions(const OptionsPtr &options); + void addCustomOptions(const OptionsPtr &options, bool write = false); /** * This function removes custom options for a single network item from the * list of options. * * @param options The custom options + * + * @param write Write the options to the file */ - void removeCustomOptions(const OptionsPtr &options); + void removeCustomOptions(const OptionsPtr &options, bool write = false); /** * This function returns a list of custom option objects that have * Wake-On-LAN features defined. * * @returns a list of custom options objects with WOL features defined. */ QList wakeOnLanEntries() const; /** * Reload custom options from the file. */ void resetCustomOptions(); protected Q_SLOTS: /** * Called when the application exits */ void slotAboutToQuit(); private: /** * Read custom options */ void readCustomOptions(); /** * This function writes the custom options to the disk. */ void writeCustomOptions(); /** * Migrates one profile to another. * * This function is meant to be used by the profile manager. * * @param from The name of the old profile. * @param to The name of the new profile. */ void migrateProfile(const QString &from, const QString &to); /** * Removes a profile from the list of profiles. * * This function is meant to be used by the profile manager. * * @param name The name of the profile. */ void removeProfile(const QString &name); /** * Pointer to Smb4KCustomOptionsManagerPrivate class */ const QScopedPointer d; }; #endif diff --git a/core/smb4kcustomoptionsmanager_p.cpp b/core/smb4kcustomoptionsmanager_p.cpp index b77db15..1f93ec6 100644 --- a/core/smb4kcustomoptionsmanager_p.cpp +++ b/core/smb4kcustomoptionsmanager_p.cpp @@ -1,2024 +1,2024 @@ /*************************************************************************** Private helper classes for Smb4KCustomOptionsManagerPrivate class ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kcustomoptionsmanager_p.h" #include "smb4ksettings.h" #if defined(Q_OS_LINUX) #include "smb4kmountsettings_linux.h" #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include "smb4kmountsettings_bsd.h" #endif // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include #include #include #include #include #include Smb4KCustomOptionsDialog::Smb4KCustomOptionsDialog(const OptionsPtr &options, QWidget *parent) : QDialog(parent), m_options(options) { // // Set the title // setWindowTitle(i18n("Custom Options")); // // Set up the layout // QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(5); setLayout(layout); // Header QWidget *header = new QWidget(this); QHBoxLayout *headerLayout = new QHBoxLayout(header); headerLayout->setSpacing(5); headerLayout->setMargin(0); QLabel *pixmap = new QLabel(header); QPixmap preferencesPixmap = KDE::icon("preferences-system-network").pixmap(KIconLoader::SizeHuge); pixmap->setPixmap(preferencesPixmap); pixmap->setAlignment(Qt::AlignCenter); QLabel *description = 0; switch (m_options->type()) { case Host: { description = new QLabel(i18n("

Define custom options for host %1 and all the shares it provides.

", m_options->displayString()), header); break; } case Share: { description = new QLabel(i18n("

Define custom options for share %1.

", m_options->displayString()), header); break; } default: { description = new QLabel(); break; } } description->setWordWrap(true); description->setAlignment(Qt::AlignVCenter); headerLayout->addWidget(pixmap, 0); headerLayout->addWidget(description, Qt::AlignVCenter); layout->addWidget(header, 0); // // Set up the operating system dependent stuff // setupView(); // // Finish the layout // QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this); QPushButton *restoreButton = buttonBox->addButton(QDialogButtonBox::RestoreDefaults); QPushButton *okButton = buttonBox->addButton(QDialogButtonBox::Ok); okButton->setShortcut(Qt::CTRL|Qt::Key_Return); okButton->setDefault(true); QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); cancelButton->setShortcut(Qt::Key_Escape); layout->addWidget(buttonBox, 0); // // Connections // connect(restoreButton, SIGNAL(clicked()), SLOT(slotSetDefaultValues())); connect(okButton, SIGNAL(clicked()), SLOT(slotOKClicked())); connect(cancelButton, SIGNAL(clicked()), SLOT(reject())); // // Set the dialog size // create(); KConfigGroup group(Smb4KSettings::self()->config(), "CustomOptionsDialog"); QSize dialogSize; if (group.exists()) { KWindowConfig::restoreWindowSize(windowHandle(), group); dialogSize = windowHandle()->size(); } else { dialogSize = sizeHint(); } resize(dialogSize); // workaround for QTBUG-40584 // // Enable/disable buttons // restoreButton->setEnabled(!checkDefaultValues()); } Smb4KCustomOptionsDialog::~Smb4KCustomOptionsDialog() { } #if defined(Q_OS_LINUX) // // Linux // void Smb4KCustomOptionsDialog::setupView() { // // Tab widget with settings // QTabWidget *tabWidget = new QTabWidget(this); QVBoxLayout *dialogLayout = qobject_cast(layout()); dialogLayout->addWidget(tabWidget, 0); // // Custom options for mounting // QWidget *mountingTab = new QWidget(tabWidget); QVBoxLayout *mountingTabLayout = new QVBoxLayout(mountingTab); mountingTabLayout->setSpacing(5); // // Common options // QGroupBox *commonBox = new QGroupBox(i18n("Common Options"), mountingTab); QGridLayout *commonBoxLayout = new QGridLayout(commonBox); commonBoxLayout->setSpacing(5); QCheckBox *remountAlways = new QCheckBox(i18n("Always remount this share"), commonBox); remountAlways->setObjectName("RemountAlways"); remountAlways->setEnabled(m_options->type() == Share); connect(remountAlways, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); commonBoxLayout->addWidget(remountAlways, 0, 0, 1, 2, 0); // Write access QCheckBox *useWriteAccess = new QCheckBox(Smb4KMountSettings::self()->useWriteAccessItem()->label(), commonBox); useWriteAccess->setObjectName("UseWriteAccess"); KComboBox *writeAccess = new KComboBox(commonBox); writeAccess->setObjectName("WriteAccess"); QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; writeAccess->addItem(readWriteText); writeAccess->addItem(readOnlyText); connect(useWriteAccess, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(writeAccess, SIGNAL(currentIndexChanged(int)), SLOT(slotCheckValues())); commonBoxLayout->addWidget(useWriteAccess, 1, 0, 0); commonBoxLayout->addWidget(writeAccess, 1, 1, 0); // Remote file system port QCheckBox *useFilesystemPort = new QCheckBox(Smb4KMountSettings::self()->useRemoteFileSystemPortItem()->label(), commonBox); useFilesystemPort->setObjectName("UseFilesystemPort"); QSpinBox *filesystemPort = new QSpinBox(commonBox); filesystemPort->setObjectName("FileSystemPort"); filesystemPort->setMinimum(Smb4KMountSettings::self()->remoteFileSystemPortItem()->minValue().toInt()); filesystemPort->setMaximum(Smb4KMountSettings::self()->remoteFileSystemPortItem()->maxValue().toInt()); // filesystemPort->setSliderEnabled(true); connect(useFilesystemPort, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(filesystemPort, SIGNAL(valueChanged(int)), SLOT(slotCheckValues())); commonBoxLayout->addWidget(useFilesystemPort, 2, 0, 0); commonBoxLayout->addWidget(filesystemPort, 2, 1, 0); mountingTabLayout->addWidget(commonBox, 0); // // CIFS Unix Extensions Support // QGroupBox *extensionsSupportBox = new QGroupBox(i18n("CIFS Unix Extensions Support"), mountingTab); QGridLayout *extensionsSupportBoxLayout = new QGridLayout(extensionsSupportBox); extensionsSupportBoxLayout->setSpacing(5); QCheckBox *cifsExtensionsSupport = new QCheckBox(i18n("This server supports the CIFS Unix extensions"), extensionsSupportBox); cifsExtensionsSupport->setObjectName("CifsExtensionsSupport"); connect(cifsExtensionsSupport, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(cifsExtensionsSupport, SIGNAL(toggled(bool)), SLOT(slotCifsExtensionsSupport(bool))); extensionsSupportBoxLayout->addWidget(cifsExtensionsSupport, 0, 0, 1, 4, 0); // User Id QCheckBox *useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), extensionsSupportBox); useUserId->setObjectName("UseUserId"); KComboBox *userId = new KComboBox(extensionsSupportBox); userId->setObjectName("UserId"); QList allUsers = KUser::allUsers(); for (const KUser &u : allUsers) { userId->addItem(QString("%1 (%2)").arg(u.loginName()).arg(u.userId().nativeId()), QVariant::fromValue(u.groupId().nativeId())); } connect(useUserId, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(userId, SIGNAL(currentIndexChanged(int)), SLOT(slotCheckValues())); extensionsSupportBoxLayout->addWidget(useUserId, 1, 0, 0); extensionsSupportBoxLayout->addWidget(userId, 1, 1, 0); // Group Id QCheckBox *useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), extensionsSupportBox); useGroupId->setObjectName("UseGroupId"); KComboBox *groupId = new KComboBox(extensionsSupportBox); groupId->setObjectName("GroupId"); QList allGroups = KUserGroup::allGroups(); for (const KUserGroup &g : allGroups) { groupId->addItem(QString("%1 (%2)").arg(g.name()).arg(g.groupId().nativeId()), QVariant::fromValue(g.groupId().nativeId())); } connect(useGroupId, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(groupId, SIGNAL(currentIndexChanged(int)), SLOT(slotCheckValues())); extensionsSupportBoxLayout->addWidget(useGroupId, 2, 0, 0); extensionsSupportBoxLayout->addWidget(groupId, 2, 1, 0); // File mode QCheckBox *useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), extensionsSupportBox); useFileMode->setObjectName("UseFileMode"); KLineEdit *fileMode = new KLineEdit(extensionsSupportBox); fileMode->setObjectName("FileMode"); fileMode->setClearButtonEnabled(true); fileMode->setAlignment(Qt::AlignRight); connect(useFileMode, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(fileMode, SIGNAL(textEdited(QString)), this, SLOT(slotCheckValues())); extensionsSupportBoxLayout->addWidget(useFileMode, 3, 0, 0); extensionsSupportBoxLayout->addWidget(fileMode, 3, 1, 0); // Directory mode QCheckBox *useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), extensionsSupportBox); useDirectoryMode->setObjectName("UseDirectoryMode"); KLineEdit *directoryMode = new KLineEdit(extensionsSupportBox); directoryMode->setObjectName("DirectoryMode"); directoryMode->setClearButtonEnabled(true); directoryMode->setAlignment(Qt::AlignRight); connect(useDirectoryMode, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(directoryMode, SIGNAL(textEdited(QString)), this, SLOT(slotCheckValues())); extensionsSupportBoxLayout->addWidget(useDirectoryMode, 4, 0, 0); extensionsSupportBoxLayout->addWidget(directoryMode, 4, 1, 0); mountingTabLayout->addWidget(extensionsSupportBox, 0); // // Advanced options // QGroupBox *advancedOptionsBox = new QGroupBox(i18n("Advanced Options"), mountingTab); QGridLayout *advancedOptionsBoxLayout = new QGridLayout(advancedOptionsBox); advancedOptionsBoxLayout->setSpacing(5); // Security mode QCheckBox *useSecurityMode = new QCheckBox(Smb4KMountSettings::self()->useSecurityModeItem()->label(), advancedOptionsBox); useSecurityMode->setObjectName("UseSecurityMode"); KComboBox *securityMode = new KComboBox(advancedOptionsBox); securityMode->setObjectName("SecurityMode"); QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; securityMode->addItem(noneText); securityMode->addItem(krb5Text); securityMode->addItem(krb5iText); securityMode->addItem(ntlmText); securityMode->addItem(ntlmiText); securityMode->addItem(ntlmv2Text); securityMode->addItem(ntlmv2iText); securityMode->addItem(ntlmsspText); connect(useSecurityMode, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(securityMode, SIGNAL(currentIndexChanged(int)), SLOT(slotCheckValues())); advancedOptionsBoxLayout->addWidget(useSecurityMode, 0, 0, 0); advancedOptionsBoxLayout->addWidget(securityMode, 0, 1, 0); mountingTabLayout->addWidget(advancedOptionsBox, 0); mountingTabLayout->addStretch(100); tabWidget->addTab(mountingTab, i18n("Mounting")); // // Custom options for Samba // QWidget *sambaTab = new QWidget(tabWidget); QVBoxLayout *sambaTabLayout = new QVBoxLayout(sambaTab); sambaTabLayout->setSpacing(5); // // Common Options // QGroupBox *commonSambaOptionsBox = new QGroupBox(i18n("Common Options"), sambaTab); QGridLayout *commonSambaOptionsBoxLayout = new QGridLayout(commonSambaOptionsBox); commonSambaOptionsBoxLayout->setSpacing(5); // SMB port QCheckBox *useSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), commonSambaOptionsBox); useSmbPort->setObjectName("UseSmbPort"); QSpinBox *smbPort = new QSpinBox(commonSambaOptionsBox); smbPort->setObjectName("SmbPort"); smbPort->setMinimum(Smb4KSettings::self()->remoteSmbPortItem()->minValue().toInt()); smbPort->setMaximum(Smb4KSettings::self()->remoteSmbPortItem()->maxValue().toInt()); // smbPort->setSliderEnabled(true); connect(useSmbPort, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(smbPort, SIGNAL(valueChanged(int)), this, SLOT(slotCheckValues())); commonSambaOptionsBoxLayout->addWidget(useSmbPort, 0, 0, 0); commonSambaOptionsBoxLayout->addWidget(smbPort, 0, 1, 0); sambaTabLayout->addWidget(commonSambaOptionsBox, 0); // // Authentication // QGroupBox *authenticationBox = new QGroupBox(i18n("Authentication"), sambaTab); QVBoxLayout *authenticationBoxLayout = new QVBoxLayout(authenticationBox); authenticationBoxLayout->setSpacing(5); // Kerberos QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), authenticationBox); useKerberos->setObjectName("UseKerberos"); connect(useKerberos, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); authenticationBoxLayout->addWidget(useKerberos, 0); sambaTabLayout->addWidget(authenticationBox, 0); sambaTabLayout->addStretch(100); tabWidget->addTab(sambaTab, i18n("Samba")); // // Custom options for Wake-On-LAN // // NOTE: If you change the texts here, also alter them in the respective // config page. // QWidget *wakeOnLanTab = new QWidget(tabWidget); QVBoxLayout *wakeOnLanTabLayout = new QVBoxLayout(wakeOnLanTab); wakeOnLanTabLayout->setSpacing(5); // // MAC address // QGroupBox *macAddressBox = new QGroupBox(i18n("MAC Address"), wakeOnLanTab); QGridLayout *macAddressBoxLayout = new QGridLayout(macAddressBox); macAddressBoxLayout->setSpacing(5); // MAC address QLabel *macAddressLabel = new QLabel(i18n("MAC Address:"), macAddressBox); KLineEdit *macAddress = new KLineEdit(macAddressBox); macAddress->setObjectName("MACAddress"); macAddress->setClearButtonEnabled(true); macAddress->setInputMask("HH:HH:HH:HH:HH:HH;_"); // MAC address, see QLineEdit doc macAddressLabel->setBuddy(macAddress); connect(macAddress, SIGNAL(textEdited(QString)), SLOT(slotCheckValues())); connect(macAddress, SIGNAL(textEdited(QString)), SLOT(slotEnableWOLFeatures(QString))); macAddressBoxLayout->addWidget(macAddressLabel, 0, 0, 0); macAddressBoxLayout->addWidget(macAddress, 0, 1, 0); wakeOnLanTabLayout->addWidget(macAddressBox, 0); // // Wake-On-LAN Actions // QGroupBox *wakeOnLANActionsBox = new QGroupBox(i18n("Actions"), wakeOnLanTab); QVBoxLayout *wakeOnLANActionsBoxLayout = new QVBoxLayout(wakeOnLANActionsBox); wakeOnLANActionsBoxLayout->setSpacing(5); // Send magic package before network scan QCheckBox *sendPackageBeforeScan = new QCheckBox(i18n("Send magic package before scanning the network neighborhood"), wakeOnLANActionsBox); sendPackageBeforeScan->setObjectName("SendPackageBeforeScan"); connect(sendPackageBeforeScan, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeScan, 0); // Send magic package before mount QCheckBox *sendPackageBeforeMount = new QCheckBox(i18n("Send magic package before mounting a share"), wakeOnLanTab); sendPackageBeforeMount->setObjectName("SendPackageBeforeMount"); connect(sendPackageBeforeMount, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeMount, 0); wakeOnLanTabLayout->addWidget(wakeOnLANActionsBox, 0); wakeOnLanTabLayout->addStretch(100); tabWidget->addTab(wakeOnLanTab, i18n("Wake-On-LAN")); // // Load settings // if (m_options->hasOptions()) { if (m_options->type() == Share) { remountAlways->setChecked((m_options->remount() == Smb4KCustomOptions::RemountAlways)); } // CIFS Unix extensions support cifsExtensionsSupport->setChecked(m_options->cifsUnixExtensionsSupport()); // User information useUserId->setChecked(m_options->useUser()); userId->setCurrentText(QString("%1 (%2)").arg(m_options->user().loginName()).arg(m_options->user().userId().nativeId())); // Group information useGroupId->setChecked(m_options->useGroup()); groupId->setCurrentText(QString("%1 (%2)").arg(m_options->group().name()).arg(m_options->group().groupId().nativeId())); // File mode useFileMode->setChecked(m_options->useFileMode()); fileMode->setText(m_options->fileMode()); // Directory mode useDirectoryMode->setChecked(m_options->useDirectoryMode()); directoryMode->setText(m_options->directoryMode()); // Remote file system port useFilesystemPort->setChecked(m_options->useFileSystemPort()); filesystemPort->setValue(m_options->fileSystemPort()); // Write access useWriteAccess->setChecked(m_options->useWriteAccess()); switch (m_options->writeAccess()) { case Smb4KMountSettings::EnumWriteAccess::ReadWrite: { writeAccess->setCurrentText(readWriteText); break; } case Smb4KMountSettings::EnumWriteAccess::ReadOnly: { writeAccess->setCurrentText(readOnlyText); break; } default: { break; } } // Security mode useSecurityMode->setChecked(m_options->useSecurityMode()); switch (m_options->securityMode()) { case Smb4KMountSettings::EnumSecurityMode::None: { securityMode->setCurrentText(noneText); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5: { securityMode->setCurrentText(krb5Text); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5i: { securityMode->setCurrentText(krb5iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlm: { securityMode->setCurrentText(ntlmText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmi: { securityMode->setCurrentText(ntlmiText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2: { securityMode->setCurrentText(ntlmv2Text); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2i: { securityMode->setCurrentText(ntlmv2iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmssp: { securityMode->setCurrentText(ntlmsspText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmsspi: { securityMode->setCurrentText(ntlmsspiText); break; } default: { break; } } // Remote SMB port useSmbPort->setChecked(m_options->useSmbPort()); smbPort->setValue(m_options->smbPort()); // Kerberos useKerberos->setChecked(m_options->useKerberos()); // MAC address macAddress->setText(m_options->macAddress()); // Send magic package before scan sendPackageBeforeScan->setChecked(m_options->wolSendBeforeNetworkScan()); // Send magic package before mount sendPackageBeforeMount->setChecked(m_options->wolSendBeforeMount()); } else { setDefaultValues(); } // // Enable/disable features // wakeOnLanTab->setEnabled((m_options->type() == Host && Smb4KSettings::enableWakeOnLAN())); slotEnableWOLFeatures(macAddress->text()); slotCifsExtensionsSupport(cifsExtensionsSupport->isChecked()); } #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) // // FreeBSD and NetBSD // void Smb4KCustomOptionsDialog::setupView() { // // Tab widget with settings // QTabWidget *tabWidget = new QTabWidget(this); QVBoxLayout *dialogLayout = qobject_cast(layout()); dialogLayout->addWidget(tabWidget, 0); // // Custom options for mounting // QWidget *mountingTab = new QWidget(tabWidget); QVBoxLayout *mountingTabLayout = new QVBoxLayout(mountingTab); mountingTabLayout->setSpacing(5); // // Common options // QGroupBox *commonBox = new QGroupBox(i18n("Common Options"), mountingTab); QGridLayout *commonBoxLayout = new QGridLayout(commonBox); commonBoxLayout->setSpacing(5); QCheckBox *remountAlways = new QCheckBox(i18n("Always remount this share"), commonBox); remountAlways->setObjectName("RemountAlways"); remountAlways->setEnabled(m_options->type() == Share); connect(remountAlways, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); commonBoxLayout->addWidget(remountAlways, 0, 0, 1, 2, 0); // User Id QCheckBox *useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), commonBox); useUserId->setObjectName("UseUserId"); KComboBox *userId = new KComboBox(commonBox); userId->setObjectName("UserId"); QList allUsers = KUser::allUsers(); for (const KUser &u : allUsers) { userId->addItem(QString("%1 (%2)").arg(u.loginName()).arg(u.userId().nativeId()), QVariant::fromValue(u.groupId().nativeId())); } connect(useUserId, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(userId, SIGNAL(currentIndexChanged(int)), SLOT(slotCheckValues())); commonBoxLayout->addWidget(useUserId, 1, 0, 0); commonBoxLayout->addWidget(userId, 1, 1, 0); // Group Id QCheckBox *useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), commonBox); useGroupId->setObjectName("UseGroupId"); KComboBox *groupId = new KComboBox(commonBox); groupId->setObjectName("GroupId"); QList allGroups = KUserGroup::allGroups(); for (const KUserGroup &g : allGroups) { groupId->addItem(QString("%1 (%2)").arg(g.name()).arg(g.groupId().nativeId()), QVariant::fromValue(g.groupId().nativeId())); } connect(useGroupId, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); connect(groupId, SIGNAL(currentIndexChanged(int)), SLOT(slotCheckValues())); commonBoxLayout->addWidget(useGroupId, 2, 0, 0); commonBoxLayout->addWidget(groupId, 2, 1, 0); // File mode QCheckBox *useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), commonBox); useFileMode->setObjectName("UseFileMode"); KLineEdit *fileMode = new KLineEdit(commonBox); fileMode->setObjectName("FileMode"); fileMode->setClearButtonEnabled(true); fileMode->setAlignment(Qt::AlignRight); connect(useFileMode, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(fileMode, SIGNAL(textEdited(QString)), this, SLOT(slotCheckValues())); commonBoxLayout->addWidget(useFileMode, 3, 0, 0); commonBoxLayout->addWidget(fileMode, 3, 1, 0); // Directory mode QCheckBox *useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), commonBox); useDirectoryMode->setObjectName("UseDirectoryMode"); KLineEdit *directoryMode = new KLineEdit(commonBox); directoryMode->setObjectName("DirectoryMode"); directoryMode->setClearButtonEnabled(true); directoryMode->setAlignment(Qt::AlignRight); connect(useDirectoryMode, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(directoryMode, SIGNAL(textEdited(QString)), this, SLOT(slotCheckValues())); commonBoxLayout->addWidget(useDirectoryMode, 4, 0, 0); commonBoxLayout->addWidget(directoryMode, 4, 1, 0); mountingTabLayout->addWidget(commonBox, 0); mountingTabLayout->addStretch(100); tabWidget->addTab(mountingTab, i18n("Mounting")); // // Custom options for Samba // QWidget *sambaTab = new QWidget(tabWidget); QVBoxLayout *sambaTabLayout = new QVBoxLayout(sambaTab); sambaTabLayout->setSpacing(5); // // Common Options // QGroupBox *commonSambaOptionsBox = new QGroupBox(i18n("Common Options"), sambaTab); QGridLayout *commonSambaOptionsBoxLayout = new QGridLayout(commonSambaOptionsBox); commonSambaOptionsBoxLayout->setSpacing(5); // SMB port QCheckBox *useSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), commonSambaOptionsBox); useSmbPort->setObjectName("UseSmbPort"); QSpinBox *smbPort = new QSpinBox(commonSambaOptionsBox); smbPort->setObjectName("SmbPort"); smbPort->setMinimum(Smb4KSettings::self()->remoteSmbPortItem()->minValue().toInt()); smbPort->setMaximum(Smb4KSettings::self()->remoteSmbPortItem()->maxValue().toInt()); // smbPort->setSliderEnabled(true); connect(useSmbPort, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(smbPort, SIGNAL(valueChanged(int)), this, SLOT(slotCheckValues())); commonSambaOptionsBoxLayout->addWidget(useSmbPort, 0, 0, 0); commonSambaOptionsBoxLayout->addWidget(smbPort, 0, 1, 0); sambaTabLayout->addWidget(commonSambaOptionsBox, 0); // // Authentication // QGroupBox *authenticationBox = new QGroupBox(i18n("Authentication"), sambaTab); QVBoxLayout *authenticationBoxLayout = new QVBoxLayout(authenticationBox); authenticationBoxLayout->setSpacing(5); // Kerberos QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), authenticationBox); useKerberos->setObjectName("UseKerberos"); connect(useKerberos, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); authenticationBoxLayout->addWidget(useKerberos, 0); sambaTabLayout->addWidget(authenticationBox, 0); sambaTabLayout->addStretch(100); tabWidget->addTab(sambaTab, i18n("Samba")); // // Custom options for Wake-On-LAN // // NOTE: If you change the texts here, also alter them in the respective // config page. // QWidget *wakeOnLanTab = new QWidget(tabWidget); QVBoxLayout *wakeOnLanTabLayout = new QVBoxLayout(wakeOnLanTab); wakeOnLanTabLayout->setSpacing(5); // // MAC address // QGroupBox *macAddressBox = new QGroupBox(i18n("MAC Address"), wakeOnLanTab); QGridLayout *macAddressBoxLayout = new QGridLayout(macAddressBox); macAddressBoxLayout->setSpacing(5); // MAC address QLabel *macAddressLabel = new QLabel(i18n("MAC Address:"), macAddressBox); KLineEdit *macAddress = new KLineEdit(macAddressBox); macAddress->setObjectName("MACAddress"); macAddress->setClearButtonEnabled(true); macAddress->setInputMask("HH:HH:HH:HH:HH:HH;_"); // MAC address, see QLineEdit doc macAddressLabel->setBuddy(macAddress); connect(macAddress, SIGNAL(textEdited(QString)), SLOT(slotCheckValues())); connect(macAddress, SIGNAL(textEdited(QString)), SLOT(slotEnableWOLFeatures(QString))); macAddressBoxLayout->addWidget(macAddressLabel, 0, 0, 0); macAddressBoxLayout->addWidget(macAddress, 0, 1, 0); wakeOnLanTabLayout->addWidget(macAddressBox, 0); // // Wake-On-LAN Actions // QGroupBox *wakeOnLANActionsBox = new QGroupBox(i18n("Actions"), wakeOnLanTab); QVBoxLayout *wakeOnLANActionsBoxLayout = new QVBoxLayout(wakeOnLANActionsBox); wakeOnLANActionsBoxLayout->setSpacing(5); // Send magic package before network scan QCheckBox *sendPackageBeforeScan = new QCheckBox(i18n("Send magic package before scanning the network neighborhood"), wakeOnLANActionsBox); sendPackageBeforeScan->setObjectName("SendPackageBeforeScan"); connect(sendPackageBeforeScan, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeScan, 0); // Send magic package before mount QCheckBox *sendPackageBeforeMount = new QCheckBox(i18n("Send magic package before mounting a share"), wakeOnLanTab); sendPackageBeforeMount->setObjectName("SendPackageBeforeMount"); connect(sendPackageBeforeMount, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeMount, 0); wakeOnLanTabLayout->addWidget(wakeOnLANActionsBox, 0); wakeOnLanTabLayout->addStretch(100); tabWidget->addTab(wakeOnLanTab, i18n("Wake-On-LAN")); // // Load settings // if (m_options->hasOptions()) { if (m_options->type() == Share) { remountAlways->setChecked((m_options->remount() == Smb4KCustomOptions::RemountAlways)); } // User information useUserId->setChecked(m_options->useUser()); userId->setCurrentText(QString("%1 (%2)").arg(m_options->user().loginName()).arg(m_options->user().userId().nativeId())); // Group information useGroupId->setChecked(m_options->useGroup()); groupId->setCurrentText(QString("%1 (%2)").arg(m_options->group().name()).arg(m_options->group().groupId().nativeId())); // File mode useFileMode->setChecked(m_options->useFileMode()); fileMode->setText(m_options->fileMode()); // Directory mode useDirectoryMode->setChecked(m_options->useDirectoryMode()); directoryMode->setText(m_options->directoryMode()); // Remote SMB port useSmbPort->setChecked(m_options->useSmbPort()); smbPort->setValue(m_options->smbPort()); // Kerberos useKerberos->setChecked(m_options->useKerberos()); // MAC address macAddress->setText(m_options->macAddress()); // Send magic package before scan sendPackageBeforeScan->setChecked(m_options->wolSendBeforeNetworkScan()); // Send magic package before mount sendPackageBeforeMount->setChecked(m_options->wolSendBeforeMount()); } else { setDefaultValues(); } // // Enable/disable features // wakeOnLanTab->setEnabled((m_options->type() == Host && Smb4KSettings::enableWakeOnLAN())); slotEnableWOLFeatures(macAddress->text()); } #else // // Generic (without mount options) // void Smb4KCustomOptionsDialog::setupView() { // // Tab widget with settings // QTabWidget *tabWidget = new QTabWidget(this); QVBoxLayout *dialogLayout = qobject_cast(layout()); dialogLayout->addWidget(tabWidget, 0); // // Custom options for Samba // QWidget *sambaTab = new QWidget(tabWidget); QVBoxLayout *sambaTabLayout = new QVBoxLayout(sambaTab); sambaTabLayout->setSpacing(5); // // Common Options // QGroupBox *commonSambaOptionsBox = new QGroupBox(i18n("Common Options"), sambaTab); QGridLayout *commonSambaOptionsBoxLayout = new QGridLayout(commonSambaOptionsBox); commonSambaOptionsBoxLayout->setSpacing(5); // SMB port QCheckBox *useSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), commonSambaOptionsBox); useSmbPort->setObjectName("UseSmbPort"); QSpinBox *smbPort = new QSpinBox(commonSambaOptionsBox); smbPort->setObjectName("SmbPort"); smbPort->setMinimum(Smb4KSettings::self()->remoteSmbPortItem()->minValue().toInt()); smbPort->setMaximum(Smb4KSettings::self()->remoteSmbPortItem()->maxValue().toInt()); // smbPort->setSliderEnabled(true); connect(useSmbPort, SIGNAL(toggled(bool)), this, SLOT(slotCheckValues())); connect(smbPort, SIGNAL(valueChanged(int)), this, SLOT(slotCheckValues())); commonSambaOptionsBoxLayout->addWidget(useSmbPort, 0, 0, 0); commonSambaOptionsBoxLayout->addWidget(smbPort, 0, 1, 0); sambaTabLayout->addWidget(commonSambaOptionsBox, 0); // // Authentication // QGroupBox *authenticationBox = new QGroupBox(i18n("Authentication"), sambaTab); QVBoxLayout *authenticationBoxLayout = new QVBoxLayout(authenticationBox); authenticationBoxLayout->setSpacing(5); // Kerberos QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), authenticationBox); useKerberos->setObjectName("UseKerberos"); connect(useKerberos, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); authenticationBoxLayout->addWidget(useKerberos, 0); sambaTabLayout->addWidget(authenticationBox, 0); sambaTabLayout->addStretch(100); tabWidget->addTab(sambaTab, i18n("Samba")); // // Custom options for Wake-On-LAN // // NOTE: If you change the texts here, also alter them in the respective // config page. // QWidget *wakeOnLanTab = new QWidget(tabWidget); QVBoxLayout *wakeOnLanTabLayout = new QVBoxLayout(wakeOnLanTab); wakeOnLanTabLayout->setSpacing(5); // // MAC address // QGroupBox *macAddressBox = new QGroupBox(i18n("MAC Address"), wakeOnLanTab); QGridLayout *macAddressBoxLayout = new QGridLayout(macAddressBox); macAddressBoxLayout->setSpacing(5); // MAC address QLabel *macAddressLabel = new QLabel(i18n("MAC Address:"), macAddressBox); KLineEdit *macAddress = new KLineEdit(macAddressBox); macAddress->setObjectName("MACAddress"); macAddress->setClearButtonEnabled(true); macAddress->setInputMask("HH:HH:HH:HH:HH:HH;_"); // MAC address, see QLineEdit doc macAddressLabel->setBuddy(macAddress); connect(macAddress, SIGNAL(textEdited(QString)), SLOT(slotCheckValues())); connect(macAddress, SIGNAL(textEdited(QString)), SLOT(slotEnableWOLFeatures(QString))); macAddressBoxLayout->addWidget(macAddressLabel, 0, 0, 0); macAddressBoxLayout->addWidget(macAddress, 0, 1, 0); wakeOnLanTabLayout->addWidget(macAddressBox, 0); // // Wake-On-LAN Actions // QGroupBox *wakeOnLANActionsBox = new QGroupBox(i18n("Actions"), wakeOnLanTab); QVBoxLayout *wakeOnLANActionsBoxLayout = new QVBoxLayout(wakeOnLANActionsBox); wakeOnLANActionsBoxLayout->setSpacing(5); // Send magic package before network scan QCheckBox *sendPackageBeforeScan = new QCheckBox(i18n("Send magic package before scanning the network neighborhood"), wakeOnLANActionsBox); sendPackageBeforeScan->setObjectName("SendPackageBeforeScan"); connect(sendPackageBeforeScan, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeScan, 0); // Send magic package before mount QCheckBox *sendPackageBeforeMount = new QCheckBox(i18n("Send magic package before mounting a share"), wakeOnLanTab); sendPackageBeforeMount->setObjectName("SendPackageBeforeMount"); connect(sendPackageBeforeMount, SIGNAL(toggled(bool)), SLOT(slotCheckValues())); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeMount, 0); wakeOnLanTabLayout->addWidget(wakeOnLANActionsBox, 0); wakeOnLanTabLayout->addStretch(100); tabWidget->addTab(wakeOnLanTab, i18n("Wake-On-LAN")); // // Load settings // if (m_options->hasOptions()) { // Remote SMB port useSmbPort->setChecked(m_options->useSmbPort()); smbPort->setValue(m_options->smbPort()); // Kerberos useKerberos->setChecked(m_options->useKerberos()); // MAC address macAddress->setText(m_options->macAddress()); // Send magic package before scan sendPackageBeforeScan->setChecked(m_options->wolSendBeforeNetworkScan()); // Send magic package before mount sendPackageBeforeMount->setChecked(m_options->wolSendBeforeMount()); } else { setDefaultValues(); } // // Enable/disable features // wakeOnLanTab->setEnabled((m_options->type() == Host && Smb4KSettings::enableWakeOnLAN())); slotEnableWOLFeatures(macAddress->text()); } #endif bool Smb4KCustomOptionsDialog::checkDefaultValues() { // // Always remount the share // if (m_options->type() == Share) { QCheckBox *remountAlways = findChild("RemountAlways"); if (remountAlways) { if (remountAlways->isChecked()) { return false; } } } // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { if (useUserId->isChecked() != Smb4KMountSettings::useUserId()) { return false; } } KComboBox *userId = findChild("UserId"); if (userId) { K_UID uid = (K_UID)userId->itemData(userId->currentIndex()).toInt(); if (uid != (K_UID)Smb4KMountSettings::userId().toInt()) { return false; } } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { if (useGroupId->isChecked() != Smb4KMountSettings::useGroupId()) { return false; } } KComboBox *groupId = findChild("GroupId"); if (groupId) { K_GID gid = (K_GID)groupId->itemData(groupId->currentIndex()).toInt(); if (gid != (K_GID)Smb4KMountSettings::groupId().toInt()) { return false; } } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { if (useFileMode->isChecked() != Smb4KMountSettings::useFileMode()) { return false; } } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { if (fileMode->text() != Smb4KMountSettings::fileMode()) { return false; } } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { if (useDirectoryMode->isChecked() != Smb4KMountSettings::useDirectoryMode()) { return false; } } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { if (directoryMode->text() != Smb4KMountSettings::directoryMode()) { return false; } } #if defined(Q_OS_LINUX) // // CIFS Unix extensions support // QCheckBox *cifsExtensionsSupport = findChild("CifsExtensionsSupport"); if (cifsExtensionsSupport) { if (cifsExtensionsSupport->isChecked() != Smb4KMountSettings::cifsUnixExtensionsSupport()) { return false; } } // // Filesystem port // QCheckBox *useFilesystemPort = findChild("UseFilesystemPort"); if (useFilesystemPort) { if (useFilesystemPort->isChecked() != Smb4KMountSettings::useRemoteFileSystemPort()) { return false; } } QSpinBox *filesystemPort = findChild("FileSystemPort"); if (filesystemPort) { if (filesystemPort->value() != Smb4KMountSettings::remoteFileSystemPort()) { return false; } } // // Write access // QCheckBox *useWriteAccess = findChild("UseWriteAccess"); if (useWriteAccess) { if (useWriteAccess->isChecked() != Smb4KMountSettings::useWriteAccess()) { return false; } } KComboBox *writeAccess = findChild("WriteAccess"); if (writeAccess) { if (writeAccess->currentText() != Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::self()->writeAccess()).label) { return false; } } // // Security mode // QCheckBox *useSecurityMode = findChild("UseSecurityMode"); if (useSecurityMode) { if (useSecurityMode->isChecked() != Smb4KMountSettings::useSecurityMode()) { return false; } } KComboBox *securityMode = findChild("SecurityMode"); if (securityMode) { if (securityMode->currentText() != Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::self()->securityMode()).label) { return false; } } #endif // // SMB port // QCheckBox *useSmbPort = findChild("UseSmbPort"); if (useSmbPort) { if (useSmbPort->isChecked() != Smb4KSettings::useRemoteSmbPort()) { return false; } } QSpinBox *smbPort = findChild("SmbPort"); if (smbPort) { if (smbPort->value() != Smb4KSettings::remoteSmbPort()) { return false; } } // // Kerberos // QCheckBox *useKerberos = findChild("UseKerberos"); if (useKerberos) { if (useKerberos->isChecked() != Smb4KSettings::useKerberos()) { return false; } } // // MAC address & Wake-On-LAN features // if (m_options->type() == Host && Smb4KSettings::enableWakeOnLAN()) { KLineEdit *macAddress = findChild("MACAddress"); if (macAddress) { QRegExp exp("..\\:..\\:..\\:..\\:..\\:.."); if (exp.exactMatch(macAddress->text())) { return false; } } QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { if (sendPackageBeforeScan->isChecked()) { return false; } } QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { if (sendPackageBeforeMount->isChecked()) { return false; } } } return true; } void Smb4KCustomOptionsDialog::setDefaultValues() { // // Always remount the share // if (m_options->type() == Share) { QCheckBox *remountAlways = findChild("RemountAlways"); if (remountAlways) { remountAlways->setChecked(false); } } // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { useUserId->setChecked(Smb4KMountSettings::useUserId()); } KComboBox *userId = findChild("UserId"); if (userId) { KUser user((K_UID)Smb4KMountSettings::userId().toInt()); userId->setCurrentText(QString("%1 (%2)").arg(user.loginName()).arg(user.userId().nativeId())); } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { useGroupId->setChecked(Smb4KMountSettings::useGroupId()); } KComboBox *groupId = findChild("GroupId"); if (groupId) { KUserGroup group((K_GID)Smb4KMountSettings::groupId().toInt()); groupId->setCurrentText(QString("%1 (%2)").arg(group.name()).arg(group.groupId().nativeId()));; } // // File mask // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { useFileMode->setChecked(Smb4KMountSettings::useFileMode()); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { fileMode->setText(Smb4KMountSettings::fileMode()); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { useDirectoryMode->setChecked(Smb4KMountSettings::useDirectoryMode()); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { directoryMode->setText(Smb4KMountSettings::directoryMode()); } #if defined(Q_OS_LINUX) // // CIFS Unix extensions support // QCheckBox *cifsExtensionsSupport = findChild("CifsExtensionsSupport"); if (cifsExtensionsSupport) { cifsExtensionsSupport->setChecked(Smb4KMountSettings::cifsUnixExtensionsSupport()); } // // Filesystem port // QCheckBox *useFilesystemPort = findChild("UseFilesystemPort"); if (useFilesystemPort) { useFilesystemPort->setChecked(Smb4KMountSettings::useRemoteFileSystemPort()); } QSpinBox *filesystemPort = findChild("FileSystemPort"); if (filesystemPort) { filesystemPort->setValue(Smb4KMountSettings::remoteFileSystemPort()); } // // Write access // QCheckBox *useWriteAccess = findChild("UseWriteAccess"); if (useWriteAccess) { useWriteAccess->setChecked(Smb4KMountSettings::useWriteAccess()); } KComboBox *writeAccess = findChild("WriteAccess"); if (writeAccess) { QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; switch (Smb4KMountSettings::writeAccess()) { case Smb4KMountSettings::EnumWriteAccess::ReadWrite: { writeAccess->setCurrentText(readWriteText); break; } case Smb4KMountSettings::EnumWriteAccess::ReadOnly: { writeAccess->setCurrentText(readOnlyText); break; } default: { break; } } } // // Security mode // QCheckBox *useSecurityMode = findChild("UseSecurityMode"); if (useSecurityMode) { useSecurityMode->setChecked(Smb4KMountSettings::useSecurityMode()); } KComboBox *securityMode = findChild("SecurityMode"); if (securityMode) { QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; switch (Smb4KMountSettings::securityMode()) { case Smb4KMountSettings::EnumSecurityMode::None: { securityMode->setCurrentText(noneText); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5: { securityMode->setCurrentText(krb5Text); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5i: { securityMode->setCurrentText(krb5iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlm: { securityMode->setCurrentText(ntlmText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmi: { securityMode->setCurrentText(ntlmiText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2: { securityMode->setCurrentText(ntlmv2Text); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2i: { securityMode->setCurrentText(ntlmv2iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmssp: { securityMode->setCurrentText(ntlmsspText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmsspi: { securityMode->setCurrentText(ntlmsspiText); break; } default: { break; } } } #endif // // SMB port // QCheckBox *useSmbPort = findChild("UseSmbPort"); if (useSmbPort) { useSmbPort->setChecked(Smb4KSettings::useRemoteSmbPort()); } QSpinBox *smbPort = findChild("SmbPort"); if (smbPort) { smbPort->setValue(Smb4KSettings::remoteSmbPort()); } // // Kerberos // QCheckBox *useKerberos = findChild("UseKerberos"); if (useKerberos) { useKerberos->setChecked(Smb4KSettings::useKerberos()); } // // MAC address & Wake-On-LAN features // if (m_options->type() == Host) { KLineEdit *macAddress = findChild("MACAddress"); if (macAddress) { macAddress->clear(); macAddress->setInputMask("HH:HH:HH:HH:HH:HH;_"); } QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { sendPackageBeforeScan->setChecked(false); } QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { sendPackageBeforeMount->setChecked(false); } } } void Smb4KCustomOptionsDialog::saveValues() { // // Always remount the share // if (m_options->type() == Share) { QCheckBox *remountAlways = findChild("RemountAlways"); if (remountAlways) { if (remountAlways->isChecked()) { m_options->setRemount(Smb4KCustomOptions::RemountAlways); } else { - m_options->setRemount(Smb4KCustomOptions::RemountNever); + m_options->setRemount(Smb4KCustomOptions::UndefinedRemount); } } } // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { m_options->setUseUser(useUserId->isChecked()); } KComboBox *userId = findChild("UserId"); if (userId) { m_options->setUser(KUser(userId->itemData(userId->currentIndex()).toInt())); } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { m_options->setUseGroup(useGroupId->isChecked()); } KComboBox *groupId = findChild("GroupId"); if (groupId) { m_options->setGroup(KUserGroup(groupId->itemData(groupId->currentIndex()).toInt())); } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { m_options->setUseFileMode(useFileMode->isChecked()); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { m_options->setFileMode(fileMode->text()); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { m_options->setUseDirectoryMode(useDirectoryMode->isChecked()); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { m_options->setDirectoryMode(directoryMode->text()); } #if defined(Q_OS_LINUX) // // CIFS Unix extensions support // QCheckBox *cifsExtensionsSupport = findChild("CifsExtensionsSupport"); if (cifsExtensionsSupport) { m_options->setCifsUnixExtensionsSupport(cifsExtensionsSupport->isChecked()); } // // Filesystem port // QCheckBox *useFilesystemPort = findChild("UseFilesystemPort"); if (useFilesystemPort) { m_options->setUseFileSystemPort(useFilesystemPort->isChecked()); } QSpinBox *filesystemPort = findChild("FileSystemPort"); if (filesystemPort) { m_options->setFileSystemPort(filesystemPort->value()); } // // Write access // QCheckBox *useWriteAccess = findChild("UseWriteAccess"); if (useWriteAccess) { m_options->setUseWriteAccess(useWriteAccess->isChecked()); } KComboBox *writeAccess = findChild("WriteAccess"); if (writeAccess) { QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; if (writeAccess->currentText() == readWriteText) { m_options->setWriteAccess(Smb4KMountSettings::EnumWriteAccess::ReadWrite); } else if (writeAccess->currentText() == readOnlyText) { m_options->setWriteAccess(Smb4KMountSettings::EnumWriteAccess::ReadOnly); } } // // Security mode // QCheckBox *useSecurityMode = findChild("UseSecurityMode"); if (useSecurityMode) { m_options->setUseSecurityMode(useSecurityMode->isChecked()); } KComboBox *securityMode = findChild("SecurityMode"); if (securityMode) { QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; if (securityMode->currentText() == noneText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::None); } else if (securityMode->currentText() == krb5Text) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Krb5); } else if (securityMode->currentText() == krb5iText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Krb5i); } else if (securityMode->currentText() == ntlmText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlm); } else if (securityMode->currentText() == ntlmiText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmi); } else if (securityMode->currentText() == ntlmv2Text) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmv2); } else if (securityMode->currentText() == ntlmv2iText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i); } else if (securityMode->currentText() == ntlmsspText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmssp); } else if (securityMode->currentText() == ntlmsspiText) { m_options->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi); } } #endif // // SMB port // QCheckBox *useSmbPort = findChild("UseSmbPort"); if (useSmbPort) { m_options->setUseSmbPort(useSmbPort->isChecked()); } QSpinBox *smbPort = findChild("SmbPort"); if (smbPort) { m_options->setSmbPort(smbPort->value()); } // Kerberos QCheckBox *useKerberos = findChild("UseKerberos"); if (useKerberos) { m_options->setUseKerberos(useKerberos->isChecked()); } // MAC address & Wake-On-LAN features if (m_options->type() == Host) { KLineEdit *macAddress = findChild("MACAddress"); if (macAddress) { m_options->setMACAddress(macAddress->text()); } QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { m_options->setWOLSendBeforeNetworkScan(sendPackageBeforeScan->isChecked()); } QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { m_options->setWOLSendBeforeMount(sendPackageBeforeMount->isChecked()); } } KConfigGroup group(Smb4KSettings::self()->config(), "CustomOptionsDialog"); KWindowConfig::saveWindowSize(windowHandle(), group); } void Smb4KCustomOptionsDialog::slotSetDefaultValues() { setDefaultValues(); } void Smb4KCustomOptionsDialog::slotCheckValues() { QDialogButtonBox *buttonBox = findChild(); if (buttonBox) { for (QAbstractButton *b : buttonBox->buttons()) { if (buttonBox->buttonRole(b) == QDialogButtonBox::ResetRole) { b->setEnabled(!checkDefaultValues()); break; } } } } void Smb4KCustomOptionsDialog::slotOKClicked() { saveValues(); accept(); } void Smb4KCustomOptionsDialog::slotEnableWOLFeatures(const QString &mac) { QRegExp exp("..\\:..\\:..\\:..\\:..\\:.."); QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { sendPackageBeforeScan->setEnabled(m_options->type() == Host && exp.exactMatch(mac)); } QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { sendPackageBeforeMount->setEnabled(m_options->type() == Host && exp.exactMatch(mac)); } } void Smb4KCustomOptionsDialog::slotCifsExtensionsSupport(bool support) { #if defined(Q_OS_LINUX) // // User id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { useUserId->setEnabled(!support); } KComboBox *userId = findChild("UserId"); if (userId) { userId->setEnabled(!support); } // // Group id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { useGroupId->setEnabled(!support); } KComboBox *groupId = findChild("GroupId"); if (groupId) { groupId->setEnabled(!support); } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { useFileMode->setEnabled(!support); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { fileMode->setEnabled(!support); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { useDirectoryMode->setEnabled(!support); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { directoryMode->setEnabled(!support); } #endif } diff --git a/smb4k/smb4kconfigpagecustomoptions.cpp b/smb4k/smb4kconfigpagecustomoptions.cpp index dd92130..a34065c 100644 --- a/smb4k/smb4kconfigpagecustomoptions.cpp +++ b/smb4k/smb4kconfigpagecustomoptions.cpp @@ -1,1919 +1,1919 @@ /*************************************************************************** The configuration page for the custom options ------------------- begin : Sa Jan 19 2013 copyright : (C) 2013-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ // application specific includes #include "smb4kconfigpagecustomoptions.h" #include "core/smb4ksettings.h" #include "core/smb4kcustomoptions.h" #include "core/smb4kglobal.h" #if defined(Q_OS_LINUX) #include "core/smb4kmountsettings_linux.h" #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include "core/smb4kmountsettings_bsd.h" #endif // Qt includes #include #include #include #include #include #include // KDE includes #include #include using namespace Smb4KGlobal; Smb4KConfigPageCustomOptions::Smb4KConfigPageCustomOptions(QWidget *parent) : QWidget(parent) { m_maybe_changed = false; // // Layout // QHBoxLayout *layout = new QHBoxLayout(this); layout->setSpacing(5); setLayout(layout); // // Set up the list widget // QListWidget *optionsListWidget = new QListWidget(this); optionsListWidget->setObjectName("OptionsListWidget"); optionsListWidget->setSelectionMode(QListWidget::SingleSelection); optionsListWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(optionsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(slotEditCustomItem(QListWidgetItem*))); connect(optionsListWidget, SIGNAL(itemSelectionChanged()), SLOT(slotItemSelectionChanged())); connect(optionsListWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(slotCustomContextMenuRequested(QPoint))); layout->addWidget(optionsListWidget, 0); QAction *editAction = new QAction(KDE::icon("edit-rename"), i18n("Edit"), optionsListWidget); editAction->setObjectName("edit_action"); editAction->setEnabled(false); QAction *removeAction = new QAction(KDE::icon("edit-delete"), i18n("Remove"), optionsListWidget); removeAction->setObjectName("remove_action"); removeAction->setEnabled(false); QAction *clearAction = new QAction(KDE::icon("edit-clear-list"), i18n("Clear List"), optionsListWidget); clearAction->setObjectName("clear_action"); clearAction->setEnabled(false); optionsListWidget->addAction(editAction); optionsListWidget->addAction(removeAction); optionsListWidget->addAction(clearAction); KActionMenu *actionMenu = new KActionMenu(optionsListWidget); actionMenu->setObjectName("ActionMenu"); actionMenu->addAction(editAction); actionMenu->addAction(removeAction); actionMenu->addAction(clearAction); connect(editAction, SIGNAL(triggered(bool)), SLOT(slotEditActionTriggered(bool))); connect(removeAction, SIGNAL(triggered(bool)), SLOT(slotRemoveActionTriggered(bool))); connect(clearAction, SIGNAL(triggered(bool)), SLOT(slotClearActionTriggered(bool))); // // Set up the tab widget // QTabWidget *tabWidget = new QTabWidget(this); tabWidget->setObjectName("TabWidget"); layout->addWidget(tabWidget, 0); // // Network item tab // QWidget *itemTab = new QWidget(tabWidget); QVBoxLayout *itemTabLayout = new QVBoxLayout(itemTab); itemTabLayout->setSpacing(5); // Identification QGroupBox *identificationBox = new QGroupBox(i18n("Identification"), itemTab); QGridLayout *identificationBoxLayout = new QGridLayout(identificationBox); identificationBoxLayout->setSpacing(5); QLabel *workgroupLabel = new QLabel(i18n("Workgroup:"), identificationBox); KLineEdit *workgroup = new KLineEdit(identificationBox); workgroup->setObjectName("Workgroup"); // workgroup->setClearButtonEnabled(true); workgroup->setReadOnly(true); workgroupLabel->setBuddy(workgroup); identificationBoxLayout->addWidget(workgroupLabel, 0, 0, 0); identificationBoxLayout->addWidget(workgroup, 0, 1, 0); QLabel *locationLabel = new QLabel(i18n("Location:"), identificationBox); KLineEdit *location = new KLineEdit(identificationBox); location->setObjectName("Location"); // location->setClearButtonEnabled(true); location->setReadOnly(true); locationLabel->setBuddy(location); identificationBoxLayout->addWidget(locationLabel, 1, 0, 0); identificationBoxLayout->addWidget(location, 1, 1, 0); QLabel *ipAddressLabel = new QLabel(i18n("IP Address:"), identificationBox); KLineEdit *ipAddress = new KLineEdit(identificationBox); ipAddress->setObjectName("IPAddress"); ipAddress->setClearButtonEnabled(true); ipAddressLabel->setBuddy(ipAddress); identificationBoxLayout->addWidget(ipAddressLabel, 2, 0, 0); identificationBoxLayout->addWidget(ipAddress, 2, 1, 0); itemTabLayout->addWidget(identificationBox, 0); itemTabLayout->addStretch(100); tabWidget->addTab(itemTab, i18n("Network Item")); // // Mounting tab // setupMountingTab(); // // Samba tab // QWidget *sambaTab = new QWidget(tabWidget); QVBoxLayout *sambaTabLayout = new QVBoxLayout(sambaTab); sambaTabLayout->setSpacing(5); // Common Options QGroupBox *commonSambaOptionsBox = new QGroupBox(i18n("Common Options"), sambaTab); QGridLayout *commonSambaOptionsBoxLayout = new QGridLayout(commonSambaOptionsBox); commonSambaOptionsBoxLayout->setSpacing(5); // SMB port QCheckBox *useSmbPort = new QCheckBox(Smb4KSettings::self()->useRemoteSmbPortItem()->label(), commonSambaOptionsBox); useSmbPort->setObjectName("UseSmbPort"); QSpinBox *smbPort = new QSpinBox(commonSambaOptionsBox); smbPort->setObjectName("SmbPort"); smbPort->setMinimum(Smb4KSettings::self()->remoteSmbPortItem()->minValue().toInt()); smbPort->setMaximum(Smb4KSettings::self()->remoteSmbPortItem()->maxValue().toInt()); // smbPort->setSliderEnabled(true); commonSambaOptionsBoxLayout->addWidget(useSmbPort, 0, 0, 0); commonSambaOptionsBoxLayout->addWidget(smbPort, 0, 1, 0); sambaTabLayout->addWidget(commonSambaOptionsBox, 0); // Authentication QGroupBox *authenticationBox = new QGroupBox(i18n("Authentication"), sambaTab); QVBoxLayout *authenticationBoxLayout = new QVBoxLayout(authenticationBox); authenticationBoxLayout->setSpacing(5); // Kerberos QCheckBox *useKerberos = new QCheckBox(Smb4KSettings::self()->useKerberosItem()->label(), authenticationBox); useKerberos->setObjectName("UseKerberos"); authenticationBoxLayout->addWidget(useKerberos, 0); sambaTabLayout->addWidget(authenticationBox, 0); sambaTabLayout->addStretch(100); tabWidget->addTab(sambaTab, i18n("Samba")); // // Wake-On-LAN tab // // NOTE: If you change the texts here, also alter them in the custom // options dialog // QWidget *wakeOnLanTab = new QWidget(tabWidget); QVBoxLayout *wakeOnLanTabLayout = new QVBoxLayout(wakeOnLanTab); wakeOnLanTabLayout->setSpacing(5); // MAC address QGroupBox *macAddressBox = new QGroupBox(i18n("MAC Address"), wakeOnLanTab); QGridLayout *macAddressBoxLayout = new QGridLayout(macAddressBox); macAddressBoxLayout->setSpacing(5); // MAC address QLabel *macAddressLabel = new QLabel(i18n("MAC Address:"), macAddressBox); KLineEdit *macAddress = new KLineEdit(macAddressBox); macAddress->setObjectName("MACAddress"); macAddress->setClearButtonEnabled(true); macAddress->setInputMask("HH:HH:HH:HH:HH:HH;_"); // MAC address, see QLineEdit doc macAddressLabel->setBuddy(macAddress); macAddressBoxLayout->addWidget(macAddressLabel, 0, 0, 0); macAddressBoxLayout->addWidget(macAddress, 0, 1, 0); wakeOnLanTabLayout->addWidget(macAddressBox, 0); // Wake-On-LAN Actions QGroupBox *wakeOnLANActionsBox = new QGroupBox(i18n("Actions"), wakeOnLanTab); QVBoxLayout *wakeOnLANActionsBoxLayout = new QVBoxLayout(wakeOnLANActionsBox); wakeOnLANActionsBoxLayout->setSpacing(5); // Send magic package before network scan QCheckBox *sendPackageBeforeScan = new QCheckBox(i18n("Send magic package before scanning the network neighborhood"), wakeOnLANActionsBox); sendPackageBeforeScan->setObjectName("SendPackageBeforeScan"); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeScan, 0); // Send magic package before mount QCheckBox *sendPackageBeforeMount = new QCheckBox(i18n("Send magic package before mounting a share"), wakeOnLanTab); sendPackageBeforeMount->setObjectName("SendPackageBeforeMount"); wakeOnLANActionsBoxLayout->addWidget(sendPackageBeforeMount, 0); wakeOnLanTabLayout->addWidget(wakeOnLANActionsBox, 0); wakeOnLanTabLayout->addStretch(100); tabWidget->addTab(wakeOnLanTab, i18n("Wake-On-LAN")); // // Clear the editor widgets, i.e. set them to the default empty values. // clearEditors(); } Smb4KConfigPageCustomOptions::~Smb4KConfigPageCustomOptions() { } #if defined(Q_OS_LINUX) // // Linux // void Smb4KConfigPageCustomOptions::setupMountingTab() { // // Get the tab widget // QTabWidget *tabWidget = findChild("TabWidget"); // // Custom options for mounting // QWidget *mountingTab = new QWidget(tabWidget); QVBoxLayout *mountingTabLayout = new QVBoxLayout(mountingTab); mountingTabLayout->setSpacing(5); // // Common options // QGroupBox *commonBox = new QGroupBox(i18n("Common Options"), mountingTab); QGridLayout *commonBoxLayout = new QGridLayout(commonBox); commonBoxLayout->setSpacing(5); QCheckBox *remountAlways = new QCheckBox(i18n("Always remount this share"), commonBox); remountAlways->setObjectName("RemountAlways"); remountAlways->setEnabled(false); commonBoxLayout->addWidget(remountAlways, 0, 0, 1, 2, 0); // Write access QCheckBox *useWriteAccess = new QCheckBox(Smb4KMountSettings::self()->useWriteAccessItem()->label(), commonBox); useWriteAccess->setObjectName("UseWriteAccess"); KComboBox *writeAccess = new KComboBox(commonBox); writeAccess->setObjectName("WriteAccess"); QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; writeAccess->addItem(readWriteText); writeAccess->addItem(readOnlyText); commonBoxLayout->addWidget(useWriteAccess, 1, 0, 0); commonBoxLayout->addWidget(writeAccess, 1, 1, 0); // Remote file system port QCheckBox *useFilesystemPort = new QCheckBox(Smb4KMountSettings::self()->useRemoteFileSystemPortItem()->label(), commonBox); useFilesystemPort->setObjectName("UseFilesystemPort"); QSpinBox *filesystemPort = new QSpinBox(commonBox); filesystemPort->setObjectName("FileSystemPort"); filesystemPort->setMinimum(Smb4KMountSettings::self()->remoteFileSystemPortItem()->minValue().toInt()); filesystemPort->setMaximum(Smb4KMountSettings::self()->remoteFileSystemPortItem()->maxValue().toInt()); // filesystemPort->setSliderEnabled(true); commonBoxLayout->addWidget(useFilesystemPort, 2, 0, 0); commonBoxLayout->addWidget(filesystemPort, 2, 1, 0); mountingTabLayout->addWidget(commonBox, 0); // // CIFS Unix Extensions Support // QGroupBox *extensionsSupportBox = new QGroupBox(i18n("CIFS Unix Extensions Support"), mountingTab); QGridLayout *extensionsSupportBoxLayout = new QGridLayout(extensionsSupportBox); extensionsSupportBoxLayout->setSpacing(5); QCheckBox *cifsExtensionsSupport = new QCheckBox(i18n("This server supports the CIFS Unix extensions"), extensionsSupportBox); cifsExtensionsSupport->setObjectName("CifsExtensionsSupport"); extensionsSupportBoxLayout->addWidget(cifsExtensionsSupport, 0, 0, 1, 2, 0); // User Id QCheckBox *useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), extensionsSupportBox); useUserId->setObjectName("UseUserId"); KComboBox *userId = new KComboBox(extensionsSupportBox); userId->setObjectName("UserId"); QList allUsers = KUser::allUsers(); for (const KUser &u : allUsers) { userId->addItem(QString("%1 (%2)").arg(u.loginName()).arg(u.userId().nativeId()), QVariant::fromValue(u.groupId().nativeId())); } extensionsSupportBoxLayout->addWidget(useUserId, 1, 0, 0); extensionsSupportBoxLayout->addWidget(userId, 1, 1, 0); // Group Id QCheckBox *useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), extensionsSupportBox); useGroupId->setObjectName("UseGroupId"); KComboBox *groupId = new KComboBox(extensionsSupportBox); groupId->setObjectName("GroupId"); QList allGroups = KUserGroup::allGroups(); for (const KUserGroup &g : allGroups) { groupId->addItem(QString("%1 (%2)").arg(g.name()).arg(g.groupId().nativeId()), QVariant::fromValue(g.groupId().nativeId())); } extensionsSupportBoxLayout->addWidget(useGroupId, 2, 0, 0); extensionsSupportBoxLayout->addWidget(groupId, 2, 1, 0); // File mode QCheckBox *useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), extensionsSupportBox); useFileMode->setObjectName("UseFileMode"); KLineEdit *fileMode = new KLineEdit(extensionsSupportBox); fileMode->setObjectName("FileMode"); fileMode->setClearButtonEnabled(true); fileMode->setAlignment(Qt::AlignRight); extensionsSupportBoxLayout->addWidget(useFileMode, 3, 0, 0); extensionsSupportBoxLayout->addWidget(fileMode, 3, 1, 0); // Directory mode QCheckBox *useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), extensionsSupportBox); useDirectoryMode->setObjectName("UseDirectoryMode"); KLineEdit *directoryMode = new KLineEdit(extensionsSupportBox); directoryMode->setObjectName("DirectoryMode"); directoryMode->setClearButtonEnabled(true); directoryMode->setAlignment(Qt::AlignRight); extensionsSupportBoxLayout->addWidget(useDirectoryMode, 4, 0, 0); extensionsSupportBoxLayout->addWidget(directoryMode, 4, 1, 0); mountingTabLayout->addWidget(extensionsSupportBox, 0); // // Advanced options // QGroupBox *advancedOptionsBox = new QGroupBox(i18n("Advanced Options"), mountingTab); QGridLayout *advancedOptionsBoxLayout = new QGridLayout(advancedOptionsBox); advancedOptionsBoxLayout->setSpacing(5); // Security mode QCheckBox *useSecurityMode = new QCheckBox(Smb4KMountSettings::self()->useSecurityModeItem()->label(), advancedOptionsBox); useSecurityMode->setObjectName("UseSecurityMode"); KComboBox *securityMode = new KComboBox(advancedOptionsBox); securityMode->setObjectName("SecurityMode"); QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; securityMode->addItem(noneText); securityMode->addItem(krb5Text); securityMode->addItem(krb5iText); securityMode->addItem(ntlmText); securityMode->addItem(ntlmiText); securityMode->addItem(ntlmv2Text); securityMode->addItem(ntlmv2iText); securityMode->addItem(ntlmsspText); advancedOptionsBoxLayout->addWidget(useSecurityMode, 0, 0, 0); advancedOptionsBoxLayout->addWidget(securityMode, 0, 1, 0); mountingTabLayout->addWidget(advancedOptionsBox, 0); mountingTabLayout->addStretch(100); tabWidget->addTab(mountingTab, i18n("Mounting")); } #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) // // FreeBSD and NetBSD // void Smb4KConfigPageCustomOptions::setupMountingTab() { // // Get the tab widget // QTabWidget *tabWidget = findChild("TabWidget"); // // Custom options for mounting // QWidget *mountingTab = new QWidget(tabWidget); QVBoxLayout *mountingTabLayout = new QVBoxLayout(mountingTab); mountingTabLayout->setSpacing(5); // // Common options // QGroupBox *commonBox = new QGroupBox(i18n("Common Options"), mountingTab); QGridLayout *commonBoxLayout = new QGridLayout(commonBox); commonBoxLayout->setSpacing(5); QCheckBox *remountAlways = new QCheckBox(i18n("Always remount this share"), commonBox); remountAlways->setObjectName("RemountAlways"); remountAlways->setEnabled(false); commonBoxLayout->addWidget(remountAlways, 0, 0, 1, 2, 0); // User Id QCheckBox *useUserId = new QCheckBox(Smb4KMountSettings::self()->useUserIdItem()->label(), commonBox); useUserId->setObjectName("UseUserId"); KComboBox *userId = new KComboBox(commonBox); userId->setObjectName("UserId"); QList allUsers = KUser::allUsers(); for (const KUser &u : allUsers) { userId->addItem(QString("%1 (%2)").arg(u.loginName()).arg(u.userId().nativeId()), QVariant::fromValue(u.groupId().nativeId())); } commonBoxLayout->addWidget(useUserId, 1, 0, 0); commonBoxLayout->addWidget(userId, 1, 1, 0); // Group Id QCheckBox *useGroupId = new QCheckBox(Smb4KMountSettings::self()->useGroupIdItem()->label(), commonBox); useGroupId->setObjectName("UseGroupId"); KComboBox *groupId = new KComboBox(commonBox); groupId->setObjectName("GroupId"); QList allGroups = KUserGroup::allGroups(); for (const KUserGroup &g : allGroups) { groupId->addItem(QString("%1 (%2)").arg(g.name()).arg(g.groupId().nativeId()), QVariant::fromValue(g.groupId().nativeId())); } commonBoxLayout->addWidget(useGroupId, 2, 0, 0); commonBoxLayout->addWidget(groupId, 2, 1, 0); // File mode QCheckBox *useFileMode = new QCheckBox(Smb4KMountSettings::self()->useFileModeItem()->label(), commonBox); useFileMode->setObjectName("UseFileMode"); KLineEdit *fileMode = new KLineEdit(commonBox); fileMode->setObjectName("FileMode"); fileMode->setClearButtonEnabled(true); fileMode->setAlignment(Qt::AlignRight); commonBoxLayout->addWidget(useFileMode, 3, 0, 0); commonBoxLayout->addWidget(fileMode, 3, 1, 0); // Directory mode QCheckBox *useDirectoryMode = new QCheckBox(Smb4KMountSettings::self()->useDirectoryModeItem()->label(), commonBox); useDirectoryMode->setObjectName("UseDirectoryMode"); KLineEdit *directoryMode = new KLineEdit(commonBox); directoryMode->setObjectName("DirectoryMode"); directoryMode->setClearButtonEnabled(true); directoryMode->setAlignment(Qt::AlignRight); commonBoxLayout->addWidget(useDirectoryMode, 4, 0, 0); commonBoxLayout->addWidget(directoryMode, 4, 1, 0); mountingTabLayout->addWidget(commonBox, 0); mountingTabLayout->addStretch(100); tabWidget->addTab(mountingTab, i18n("Mounting")); } #else // // Generic (without mount options) // void Smb4KConfigPageCustomOptions::setupMountingTab() { // The operating system is not support } #endif void Smb4KConfigPageCustomOptions::insertCustomOptions(const QList &list) { // // If the global list of options has not been loaded, set it here // if (m_optionsList.isEmpty()) { m_optionsList = list; } // // Get the list widget and display the new options // QListWidget *optionsListWidget = findChild("OptionsListWidget"); if (optionsListWidget) { // Clear the list widget while (optionsListWidget->count() != 0) { delete optionsListWidget->item(0); } // Display the new options for (const OptionsPtr &o : m_optionsList) { switch (o->type()) { case Host: { QListWidgetItem *item = new QListWidgetItem(KDE::icon("network-server"), o->displayString(), optionsListWidget, Host); item->setData(Qt::UserRole, o->url().toDisplayString()); break; } case Share: { QListWidgetItem *item = new QListWidgetItem(KDE::icon("folder-network"), o->displayString(), optionsListWidget, Share); item->setData(Qt::UserRole, o->url().toDisplayString()); break; } default: { break; } } } optionsListWidget->sortItems(Qt::AscendingOrder); } } const QList Smb4KConfigPageCustomOptions::getCustomOptions() { return m_optionsList; } void Smb4KConfigPageCustomOptions::clearEditors() { // // Clear current options // m_currentOptions.clear(); // // Workgroup // KLineEdit *workgroup = findChild("Workgroup"); if (workgroup) { workgroup->clear(); } // // Location // KLineEdit *location = findChild("Location"); if (location) { location->clear(); } // // IP address // KLineEdit *ipAddress = findChild("IPAddress"); if (ipAddress) { disconnect(ipAddress, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); ipAddress->clear(); } // // Remounting // QCheckBox *remountAlways = findChild("RemountAlways"); if (remountAlways) { disconnect(remountAlways, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); remountAlways->setChecked(false); } // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { disconnect(useUserId, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useUserId->setChecked(false); } KComboBox *userId = findChild("UserId"); if (userId) { disconnect(userId, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); KUser user((K_UID)Smb4KMountSettings::userId().toInt()); userId->setCurrentText(QString("%1 (%2)").arg(user.loginName()).arg(user.userId().nativeId())); } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { disconnect(useGroupId, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useGroupId->setChecked(false); } KComboBox *groupId = findChild("GroupId"); if (groupId) { disconnect(groupId, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); KUserGroup group((K_GID)Smb4KMountSettings::groupId().toInt()); groupId->setCurrentText(QString("%1 (%2)").arg(group.name()).arg(group.groupId().nativeId())); } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { disconnect(useFileMode, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useFileMode->setChecked(false); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { disconnect(fileMode, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); fileMode->setText(Smb4KMountSettings::fileMode()); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { disconnect(useDirectoryMode, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useDirectoryMode->setChecked(false); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { disconnect(directoryMode, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); directoryMode->setText(Smb4KMountSettings::fileMode()); } #if defined(Q_OS_LINUX) // // Write access // QCheckBox *useWriteAccess = findChild("UseWriteAccess"); if (useWriteAccess) { disconnect(useWriteAccess, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useWriteAccess->setChecked(false); } KComboBox *writeAccess = findChild("WriteAccess"); if (writeAccess) { disconnect(writeAccess, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; switch (Smb4KMountSettings::writeAccess()) { case Smb4KMountSettings::EnumWriteAccess::ReadWrite: { writeAccess->setCurrentText(readWriteText); break; } case Smb4KMountSettings::EnumWriteAccess::ReadOnly: { writeAccess->setCurrentText(readOnlyText); break; } default: { break; } } } // // File system port // QCheckBox *useFilesystemPort = findChild("UseFilesystemPort"); if (useFilesystemPort) { disconnect(useFilesystemPort, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useFilesystemPort->setChecked(false); } QSpinBox *filesystemPort = findChild("FileSystemPort"); if (filesystemPort) { disconnect(filesystemPort, SIGNAL(valueChanged(int)), this, SLOT(slotEntryChanged())); filesystemPort->setValue(Smb4KMountSettings::remoteFileSystemPort()); } // // CIFS Unix Extensions Support // QCheckBox *cifsExtensionsSupport = findChild("CifsExtensionsSupport"); if (cifsExtensionsSupport) { disconnect(cifsExtensionsSupport, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); disconnect(cifsExtensionsSupport, SIGNAL(toggled(bool)), this, SLOT(slotCifsUnixExtensionsSupport(bool))); cifsExtensionsSupport->setChecked(false); } // // Security mode // QCheckBox *useSecurityMode = findChild("UseSecurityMode"); if (useSecurityMode) { disconnect(useSecurityMode, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useSecurityMode->setChecked(false); } KComboBox *securityMode = findChild("SecurityMode"); if (securityMode) { disconnect(securityMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; switch (Smb4KMountSettings::securityMode()) { case Smb4KMountSettings::EnumSecurityMode::None: { securityMode->setCurrentText(noneText); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5: { securityMode->setCurrentText(krb5Text); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5i: { securityMode->setCurrentText(krb5iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlm: { securityMode->setCurrentText(ntlmText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmi: { securityMode->setCurrentText(ntlmiText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2: { securityMode->setCurrentText(ntlmv2Text); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2i: { securityMode->setCurrentText(ntlmv2iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmssp: { securityMode->setCurrentText(ntlmsspText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmsspi: { securityMode->setCurrentText(ntlmsspiText); break; } default: { break; } } } #endif // // SMB port // QCheckBox *useSmbPort = findChild("UseSmbPort"); if (useSmbPort) { disconnect(useSmbPort, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useSmbPort->setChecked(false); } QSpinBox *smbPort = findChild("SmbPort"); if (smbPort) { disconnect(smbPort, SIGNAL(valueChanged(int)), this, SLOT(slotEntryChanged())); smbPort->setValue(Smb4KSettings::remoteSmbPort()); } // // Kerberos // QCheckBox *useKerberos = findChild("UseKerberos"); if (useKerberos) { disconnect(useKerberos, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); useKerberos->setChecked(false); } // // MAC address // KLineEdit *macAddress = findChild("MACAddress"); if (macAddress) { disconnect(macAddress, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); disconnect(macAddress, SIGNAL(textEdited(QString)), this, SLOT(slotEnableWOLFeatures(QString))); macAddress->clear(); macAddress->setInputMask("HH:HH:HH:HH:HH:HH;_"); } // // Wake-On-Lan: send package before scan // QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { disconnect(sendPackageBeforeScan, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); sendPackageBeforeScan->setChecked(false); } // // Wake-On-Lan: Send package before mount // QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { disconnect(sendPackageBeforeMount, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); sendPackageBeforeMount->setChecked(false); } // // Disable widgets // QTabWidget *tabWidget = findChild("TabWidget"); if (tabWidget) { tabWidget->setEnabled(false); } } void Smb4KConfigPageCustomOptions::setCurrentOptions(const QString& url) { for (const OptionsPtr &o : m_optionsList) { if (url == o->url().toString()) { m_currentOptions = o; break; } } } void Smb4KConfigPageCustomOptions::populateEditors() { // // Workgroup // KLineEdit *workgroup = findChild("Workgroup"); if (workgroup) { workgroup->setText(m_currentOptions->workgroupName()); } // // Location // KLineEdit *location = findChild("Location"); if (location) { location->setText(m_currentOptions->displayString()); } // // IP address // KLineEdit *ipAddress = findChild("IPAddress"); if (ipAddress) { ipAddress->setText(m_currentOptions->ipAddress()); connect(ipAddress, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); } // // Remounting // QCheckBox *remountAlways = findChild("RemountAlways"); if (remountAlways) { remountAlways->setEnabled(m_currentOptions->type() == Share); if (m_currentOptions->remount() == Smb4KCustomOptions::RemountAlways) { remountAlways->setChecked(true); } else { remountAlways->setChecked(false); } connect(remountAlways, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { useUserId->setChecked(m_currentOptions->useUser()); connect(useUserId, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } KComboBox *userId = findChild("UserId"); if (userId) { userId->setCurrentText(QString("%1 (%2)").arg(m_currentOptions->user().loginName()).arg(m_currentOptions->user().userId().nativeId())); connect(userId, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { useGroupId->setChecked(m_currentOptions->useGroup()); connect(useGroupId, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } KComboBox *groupId = findChild("GroupId"); if (groupId) { groupId->setCurrentText(QString("%1 (%2)").arg(m_currentOptions->group().name()).arg(m_currentOptions->group().groupId().nativeId())); connect(groupId, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { useFileMode->setChecked(m_currentOptions->useFileMode()); connect(useFileMode, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { fileMode->setText(m_currentOptions->fileMode()); connect(fileMode, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { useDirectoryMode->setChecked(m_currentOptions->useFileMode()); connect(useDirectoryMode, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { directoryMode->setText(m_currentOptions->directoryMode()); connect(directoryMode, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); } #if defined(Q_OS_LINUX) // // Write access // QCheckBox *useWriteAccess = findChild("UseWriteAccess"); if (useWriteAccess) { useWriteAccess->setChecked(m_currentOptions->useWriteAccess()); connect(useWriteAccess, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } KComboBox *writeAccess = findChild("WriteAccess"); if (writeAccess) { QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; switch (m_currentOptions->writeAccess()) { case Smb4KMountSettings::EnumWriteAccess::ReadWrite: { writeAccess->setCurrentText(readWriteText); break; } case Smb4KMountSettings::EnumWriteAccess::ReadOnly: { writeAccess->setCurrentText(readOnlyText); break; } default: { break; } } connect(writeAccess, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); } // // File system port // QCheckBox *useFilesystemPort = findChild("UseFilesystemPort"); if (useFilesystemPort) { useFilesystemPort->setChecked(m_currentOptions->useFileSystemPort()); connect(useFilesystemPort, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } QSpinBox *filesystemPort = findChild("FileSystemPort"); if (filesystemPort) { filesystemPort->setValue(m_currentOptions->fileSystemPort()); connect(filesystemPort, SIGNAL(valueChanged(int)), this, SLOT(slotEntryChanged())); } // // CIFS Unix Extensions Support // QCheckBox *cifsExtensionsSupport = findChild("CifsExtensionsSupport"); if (cifsExtensionsSupport) { connect(cifsExtensionsSupport, SIGNAL(toggled(bool)), this, SLOT(slotCifsUnixExtensionsSupport(bool))); cifsExtensionsSupport->setChecked(m_currentOptions->cifsUnixExtensionsSupport()); connect(cifsExtensionsSupport, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } // // Security mode // QCheckBox *useSecurityMode = findChild("UseSecurityMode"); if (useSecurityMode) { useSecurityMode->setChecked(m_currentOptions->useSecurityMode()); connect(useSecurityMode, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } KComboBox *securityMode = findChild("SecurityMode"); if (securityMode) { QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; switch (m_currentOptions->securityMode()) { case Smb4KMountSettings::EnumSecurityMode::None: { securityMode->setCurrentText(noneText); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5: { securityMode->setCurrentText(krb5Text); break; } case Smb4KMountSettings::EnumSecurityMode::Krb5i: { securityMode->setCurrentText(krb5iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlm: { securityMode->setCurrentText(ntlmText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmi: { securityMode->setCurrentText(ntlmiText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2: { securityMode->setCurrentText(ntlmv2Text); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmv2i: { securityMode->setCurrentText(ntlmv2iText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmssp: { securityMode->setCurrentText(ntlmsspText); break; } case Smb4KMountSettings::EnumSecurityMode::Ntlmsspi: { securityMode->setCurrentText(ntlmsspiText); break; } default: { break; } } connect(securityMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotEntryChanged())); } slotCifsUnixExtensionsSupport(cifsExtensionsSupport->isChecked()); #endif // // SMB port // QCheckBox *useSmbPort = findChild("UseSmbPort"); if (useSmbPort) { useSmbPort->setChecked(m_currentOptions->useSmbPort()); connect(useSmbPort, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } QSpinBox *smbPort = findChild("SmbPort"); if (smbPort) { smbPort->setValue(m_currentOptions->smbPort()); connect(smbPort, SIGNAL(valueChanged(int)), this, SLOT(slotEntryChanged())); } // // Kerberos // QCheckBox *useKerberos = findChild("UseKerberos"); if (useKerberos) { useKerberos->setChecked(m_currentOptions->useKerberos()); connect(useKerberos, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } // // MAC address // KLineEdit *macAddress = findChild("MACAddress"); if (macAddress) { macAddress->setText(m_currentOptions->macAddress()); connect(macAddress, SIGNAL(textEdited(QString)), this, SLOT(slotEntryChanged())); connect(macAddress, SIGNAL(textEdited(QString)), this, SLOT(slotEnableWOLFeatures(QString))); slotEnableWOLFeatures(m_currentOptions->macAddress()); } // // Wake-On-Lan: Send package before scan // QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { sendPackageBeforeScan->setChecked(m_currentOptions->wolSendBeforeNetworkScan()); connect(sendPackageBeforeScan, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } // // Wake-On-Lan: Send package before mount // QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { sendPackageBeforeMount->setChecked(m_currentOptions->wolSendBeforeMount()); connect(sendPackageBeforeMount, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); } // // Enable widgets // QTabWidget *tabWidget = findChild("TabWidget"); if (tabWidget) { // Enable the tab widget tabWidget->setEnabled(true); // Enable the Wake-On-Lan page int wolTabIndex = tabWidget->count() - 1; tabWidget->widget(wolTabIndex)->setEnabled(Smb4KSettings::enableWakeOnLAN()); } } void Smb4KConfigPageCustomOptions::commitChanges() { // // IP address // KLineEdit *ipAddress = findChild("IPAddress"); if (ipAddress) { m_currentOptions->setIpAddress(ipAddress->text()); } // // Remounting // QCheckBox *remountAlways = findChild("RemountAlways"); if (remountAlways) { if (remountAlways->isChecked()) { m_currentOptions->setRemount(Smb4KCustomOptions::RemountAlways); } else { - m_currentOptions->setRemount(Smb4KCustomOptions::RemountNever); + m_currentOptions->setRemount(Smb4KCustomOptions::UndefinedRemount); } } // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { m_currentOptions->setUseUser(useUserId->isChecked()); } KComboBox *userId = findChild("UserId"); if (userId) { m_currentOptions->setUser(KUser(userId->itemData(userId->currentIndex()).toInt())); } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { m_currentOptions->setUseGroup(useGroupId->isChecked()); } KComboBox *groupId = findChild("GroupId"); if (groupId) { m_currentOptions->setGroup(KUserGroup(groupId->itemData(groupId->currentIndex()).toInt())); } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { m_currentOptions->setUseFileMode(useFileMode->isChecked()); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { m_currentOptions->setFileMode(fileMode->text()); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { m_currentOptions->setUseDirectoryMode(useDirectoryMode->isChecked()); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { m_currentOptions->setDirectoryMode(directoryMode->text()); } #if defined(Q_OS_LINUX) // // Write access // QCheckBox *useWriteAccess = findChild("UseWriteAccess"); if (useWriteAccess) { m_currentOptions->setUseWriteAccess(useWriteAccess->isChecked()); } KComboBox *writeAccess = findChild("WriteAccess"); if (writeAccess) { QString readWriteText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadWrite).label; QString readOnlyText = Smb4KMountSettings::self()->writeAccessItem()->choices().value(Smb4KMountSettings::EnumWriteAccess::ReadOnly).label; if (writeAccess->currentText() == readWriteText) { m_currentOptions->setWriteAccess(Smb4KMountSettings::EnumWriteAccess::ReadWrite); } else if (writeAccess->currentText() == readOnlyText) { m_currentOptions->setWriteAccess(Smb4KMountSettings::EnumWriteAccess::ReadOnly); } } // // File system port // QCheckBox *useFilesystemPort = findChild("UseFilesystemPort"); if (useFilesystemPort) { m_currentOptions->setUseFileSystemPort(useFilesystemPort->isChecked()); } QSpinBox *filesystemPort = findChild("FileSystemPort"); if (filesystemPort) { m_currentOptions->setFileSystemPort(filesystemPort->value()); } // // CIFS Unix Extensions Support // QCheckBox *cifsExtensionsSupport = findChild("CifsExtensionsSupport"); if (cifsExtensionsSupport) { m_currentOptions->setCifsUnixExtensionsSupport(cifsExtensionsSupport->isChecked()); } // // Security mode // QCheckBox *useSecurityMode = findChild("UseSecurityMode"); if (useSecurityMode) { m_currentOptions->setUseSecurityMode(useSecurityMode->isChecked()); } KComboBox *securityMode = findChild("SecurityMode"); if (securityMode) { QString noneText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::None).label; QString krb5Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5).label; QString krb5iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Krb5i).label; QString ntlmText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlm).label; QString ntlmiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmi).label; QString ntlmv2Text = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2).label; QString ntlmv2iText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i).label; QString ntlmsspText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmssp).label; QString ntlmsspiText = Smb4KMountSettings::self()->securityModeItem()->choices().value(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi).label; if (securityMode->currentText() == noneText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::None); } else if (securityMode->currentText() == krb5Text) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Krb5); } else if (securityMode->currentText() == krb5iText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Krb5i); } else if (securityMode->currentText() == ntlmText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlm); } else if (securityMode->currentText() == ntlmiText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmi); } else if (securityMode->currentText() == ntlmv2Text) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmv2); } else if (securityMode->currentText() == ntlmv2iText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmv2i); } else if (securityMode->currentText() == ntlmsspText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmssp); } else if (securityMode->currentText() == ntlmsspiText) { m_currentOptions->setSecurityMode(Smb4KMountSettings::EnumSecurityMode::Ntlmsspi); } } #endif // // SMB port // QCheckBox *useSmbPort = findChild("UseSmbPort"); if (useSmbPort) { m_currentOptions->setUseSmbPort(useSmbPort->isChecked()); } QSpinBox *smbPort = findChild("SmbPort"); if (smbPort) { m_currentOptions->setSmbPort(smbPort->value()); } // // Kerberos // QCheckBox *useKerberos = findChild("UseKerberos"); if (useKerberos) { m_currentOptions->setUseKerberos(useKerberos->isChecked()); } // // MAC address // KLineEdit *macAddress = findChild("MACAddress"); if (macAddress) { m_currentOptions->setMACAddress(macAddress->text()); } // // Wake-On-Lan: Send package before scan // QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { m_currentOptions->setWOLSendBeforeNetworkScan(sendPackageBeforeScan->isChecked()); } // // Wake-On-Lan: Send package before mount // QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { m_currentOptions->setWOLSendBeforeMount(sendPackageBeforeMount->isChecked()); } // // In case the options are defined for a host, propagate them // to the options of shares belonging to that host. Overwrite // the settings // if (m_currentOptions->type() == Host) { for (const OptionsPtr &o : m_optionsList) { if (o->type() == Share && o->hostName() == m_currentOptions->hostName() && o->workgroupName() == m_currentOptions->workgroupName()) { o->setIpAddress(m_currentOptions->ipAddress()); o->setUseUser(m_currentOptions->useUser()); o->setUser(m_currentOptions->user()); o->setUseGroup(m_currentOptions->useGroup()); o->setGroup(m_currentOptions->group()); o->setUseFileMode(m_currentOptions->useFileMode()); o->setFileMode(m_currentOptions->fileMode()); o->setUseDirectoryMode(m_currentOptions->useDirectoryMode()); o->setDirectoryMode(m_currentOptions->directoryMode()); #if defined(Q_OS_LINUX) o->setCifsUnixExtensionsSupport(m_currentOptions->cifsUnixExtensionsSupport()); o->setUseFileSystemPort(m_currentOptions->useFileSystemPort()); o->setFileSystemPort(m_currentOptions->fileSystemPort()); o->setUseSecurityMode(m_currentOptions->useSecurityMode()); o->setSecurityMode(m_currentOptions->securityMode()); o->setUseWriteAccess(m_currentOptions->useWriteAccess()); o->setWriteAccess(m_currentOptions->writeAccess()); #endif o->setUseSmbPort(m_currentOptions->useSmbPort()); o->setSmbPort(m_currentOptions->smbPort()); o->setUseKerberos(m_currentOptions->useKerberos()); o->setMACAddress(m_currentOptions->macAddress()); o->setWOLSendBeforeNetworkScan(m_currentOptions->wolSendBeforeNetworkScan()); o->setWOLSendBeforeMount(m_currentOptions->wolSendBeforeMount()); } } } m_maybe_changed = true; emit customSettingsModified(); } bool Smb4KConfigPageCustomOptions::eventFilter(QObject* obj, QEvent* e) { QListWidget *optionsListWidget = findChild("OptionsListWidget"); if (optionsListWidget) { if (obj == optionsListWidget->viewport()) { if (e->type() == QEvent::MouseButtonPress) { QMouseEvent *mev = static_cast(e); QPoint pos = optionsListWidget->viewport()->mapFromGlobal(mev->globalPos()); QListWidgetItem *item = optionsListWidget->itemAt(pos); if (!item) { clearEditors(); optionsListWidget->clearSelection(); } } } } return QObject::eventFilter(obj, e); } void Smb4KConfigPageCustomOptions::slotEditCustomItem(QListWidgetItem *item) { setCurrentOptions(item->data(Qt::UserRole).toString()); if (m_currentOptions) { populateEditors(); } else { clearEditors(); } } void Smb4KConfigPageCustomOptions::slotItemSelectionChanged() { clearEditors(); } void Smb4KConfigPageCustomOptions::slotCustomContextMenuRequested(const QPoint& pos) { QListWidget *optionsListWidget = findChild("OptionsListWidget"); if (optionsListWidget) { QListWidgetItem *item = optionsListWidget->itemAt(pos); for (QAction *a : optionsListWidget->actions()) { if (a->objectName() == "edit_action") { a->setEnabled(item != 0); } else if (a->objectName() == "remove_action") { a->setEnabled(item != 0); } else if (a->objectName() == "clear_action") { a->setEnabled(optionsListWidget->count() != 0); } } KActionMenu *actionMenu = optionsListWidget->findChild("ActionMenu"); if (actionMenu) { actionMenu->menu()->popup(optionsListWidget->viewport()->mapToGlobal(pos)); } } } void Smb4KConfigPageCustomOptions::slotEditActionTriggered(bool /*checked*/) { QListWidget *optionsListWidget = findChild("OptionsListWidget"); if (optionsListWidget) { slotEditCustomItem(optionsListWidget->currentItem()); } } void Smb4KConfigPageCustomOptions::slotRemoveActionTriggered(bool /*checked*/) { QListWidget *optionsListWidget = findChild("OptionsListWidget"); if (optionsListWidget) { QListWidgetItem *item = optionsListWidget->currentItem(); if (item) { setCurrentOptions(item->data(Qt::UserRole).toString()); int index = m_optionsList.indexOf(m_currentOptions); if (index != -1) { m_optionsList.takeAt(index).clear(); } KLineEdit *location = findChild("Location"); if (location) { if (item->text() == location->text()) { clearEditors(); } } delete item; m_currentOptions.clear(); m_maybe_changed = true; emit customSettingsModified(); } } } void Smb4KConfigPageCustomOptions::slotClearActionTriggered(bool /*checked*/) { clearEditors(); QListWidget *optionsListWidget = findChild("OptionsListWidget"); if (optionsListWidget) { while (optionsListWidget->count() != 0) { delete optionsListWidget->item(0); } } while (!m_optionsList.isEmpty()) { m_optionsList.takeFirst().clear(); } m_currentOptions.clear(); m_maybe_changed = true; emit customSettingsModified(); } void Smb4KConfigPageCustomOptions::slotEntryChanged() { commitChanges(); } void Smb4KConfigPageCustomOptions::slotEnableWOLFeatures(const QString &mac_address) { QRegExp exp("..\\:..\\:..\\:..\\:..\\:.."); // // Wake-On_lan: send package before scan // QCheckBox *sendPackageBeforeScan = findChild("SendPackageBeforeScan"); if (sendPackageBeforeScan) { sendPackageBeforeScan->setEnabled(exp.exactMatch(mac_address)); } // // Wake-On-Lan: send package before mount // QCheckBox *sendPackageBeforeMount = findChild("SendPackageBeforeMount"); if (sendPackageBeforeMount) { sendPackageBeforeMount->setEnabled(exp.exactMatch(mac_address)); } } void Smb4KConfigPageCustomOptions::slotCifsUnixExtensionsSupport(bool on) { // // User Id // QCheckBox *useUserId = findChild("UseUserId"); if (useUserId) { useUserId->setEnabled(!on); } KComboBox *userId = findChild("UserId"); if (userId) { userId->setEnabled(!on); } // // Group Id // QCheckBox *useGroupId = findChild("UseGroupId"); if (useGroupId) { useGroupId->setEnabled(!on); } KComboBox *groupId = findChild("GroupId"); if (groupId) { groupId->setEnabled(!on); } // // File mode // QCheckBox *useFileMode = findChild("UseFileMode"); if (useFileMode) { useFileMode->setEnabled(!on); } KLineEdit *fileMode = findChild("FileMode"); if (fileMode) { fileMode->setEnabled(!on); } // // Directory mode // QCheckBox *useDirectoryMode = findChild("UseDirectoryMode"); if (useDirectoryMode) { useDirectoryMode->setEnabled(!on); } KLineEdit *directoryMode = findChild("DirectoryMode"); if (directoryMode) { directoryMode->setEnabled(!on); } }