diff --git a/core/smb4kauthinfo.cpp b/core/smb4kauthinfo.cpp index a2bfd0e..eb29b99 100644 --- a/core/smb4kauthinfo.cpp +++ b/core/smb4kauthinfo.cpp @@ -1,352 +1,296 @@ /*************************************************************************** This class provides a container for the authentication data. ------------------- begin : Sa Feb 28 2004 - copyright : (C) 2004-2018 by Alexander Reinholdt + copyright : (C) 2004-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 "smb4kauthinfo.h" // Qt includes #include #include // KDE includes #include class Smb4KAuthInfoPrivate { public: QUrl url; QString workgroup; NetworkItem type; bool homesShare; QHostAddress ip; }; Smb4KAuthInfo::Smb4KAuthInfo(const Smb4KHost *host) : d(new Smb4KAuthInfoPrivate) { d->url = host->url(); d->type = Host; d->workgroup = host->workgroupName(); d->homesShare = false; d->ip.setAddress(host->ipAddress()); } Smb4KAuthInfo::Smb4KAuthInfo(const Smb4KShare *share) : d(new Smb4KAuthInfoPrivate) { if (!share->isHomesShare()) { d->url = share->url(); } else { d->url = share->homeUrl(); } d->type = Share; d->workgroup = share->workgroupName(); d->homesShare = share->isHomesShare(); d->ip.setAddress(share->hostIpAddress()); } Smb4KAuthInfo::Smb4KAuthInfo() : d(new Smb4KAuthInfoPrivate) { d->type = UnknownNetworkItem; d->homesShare = false; d->url.clear(); d->workgroup.clear(); d->ip.clear(); } Smb4KAuthInfo::Smb4KAuthInfo(const Smb4KAuthInfo &i) : d(new Smb4KAuthInfoPrivate) { *d = *i.d; } Smb4KAuthInfo::~Smb4KAuthInfo() { } void Smb4KAuthInfo::setHost(Smb4KHost *host) { Q_ASSERT(host); if (host) { d->url = host->url(); d->type = Host; d->workgroup = host->workgroupName(); d->homesShare = false; d->ip.setAddress(host->ipAddress()); } else { // Do nothing } } void Smb4KAuthInfo::setShare(Smb4KShare *share) { Q_ASSERT(share); if (share) { if (!share->isHomesShare()) { d->url = share->url(); } else { d->url = share->homeUrl(); } d->type = Share; d->workgroup = share->workgroupName(); d->homesShare = share->isHomesShare(); d->ip.setAddress(share->hostIpAddress()); } else { // Do nothing } } void Smb4KAuthInfo::setWorkgroupName(const QString &workgroup) { d->workgroup = workgroup; } QString Smb4KAuthInfo::workgroupName() const { return d->workgroup; } void Smb4KAuthInfo::setUrl(const QUrl &url) { d->url = url; d->url.setScheme("smb"); // Set the type. if (!d->url.path().isEmpty() && d->url.path().length() > 1 && !d->url.path().endsWith('/')) { d->type = Share; } else { d->type = Host; } // Determine whether this is a homes share. qDebug() << "Smb4KAuthInfo::setUrl(): Check if determination of homes share works"; d->homesShare = (QString::compare(d->url.path().remove(0, 1), "homes", Qt::CaseSensitive) == 0); } void Smb4KAuthInfo::setUrl(const QString &url) { d->url.setUrl(url, QUrl::TolerantMode); d->url.setScheme("smb"); // Set the type. if (!d->url.path().isEmpty() && d->url.path().length() > 1 && !d->url.path().endsWith('/')) { d->type = Share; } else { d->type = Host; } // Determine whether this is a homes share. qDebug() << "Smb4KAuthInfo::setUrl(): Check if determination of homes share works"; d->homesShare = (QString::compare(d->url.path().remove(0, 1), "homes", Qt::CaseSensitive) == 0); } QUrl Smb4KAuthInfo::url() const { return d->url; } QString Smb4KAuthInfo::hostName() const { return d->url.host().toUpper(); } QString Smb4KAuthInfo::shareName() const { if (d->url.path().startsWith('/')) { return d->url.path().remove(0, 1); } else { // Do nothing } return d->url.path(); } void Smb4KAuthInfo::setUserName(const QString &username) { d->url.setUserName(username); if (d->homesShare) { d->url.setPath(username); } else { // Do nothing } } QString Smb4KAuthInfo::userName() const { return d->url.userName(); } void Smb4KAuthInfo::setPassword(const QString &passwd) { d->url.setPassword(passwd); } QString Smb4KAuthInfo::password() const { return d->url.password(); } Smb4KGlobal::NetworkItem Smb4KAuthInfo::type() const { return d->type; } bool Smb4KAuthInfo::isHomesShare() const { return d->homesShare; } -bool Smb4KAuthInfo::equals(Smb4KAuthInfo *info) const -{ - // URL - if (d->url != info->url()) - { - return false; - } - else - { - // Do nothing - } - - // Type - if (d->type != info->type()) - { - return false; - } - else - { - // Do nothing - } - - // Workgroup - if (QString::compare(d->workgroup, info->workgroupName(), Qt::CaseInsensitive) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Homes share? - if (d->homesShare != info->isHomesShare()) - { - return false; - } - else - { - // Do nothing - } - - // IP address - if (QString::compare(d->ip.toString(), info->ipAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - return true; -} - - void Smb4KAuthInfo::setIpAddress(const QString &ip) { d->ip.setAddress(ip); } QString Smb4KAuthInfo::ipAddress() const { return d->ip.toString(); } QString Smb4KAuthInfo::displayString() const { return i18n("%1 on %2", shareName(), hostName()); } diff --git a/core/smb4kauthinfo.h b/core/smb4kauthinfo.h index 9c7f157..c6c19aa 100644 --- a/core/smb4kauthinfo.h +++ b/core/smb4kauthinfo.h @@ -1,249 +1,233 @@ /*************************************************************************** This class provides a container for the authentication data. ------------------- begin : Sa Feb 28 2004 - copyright : (C) 2004-2018 by Alexander Reinholdt + copyright : (C) 2004-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 SMB4KAUTHINFO_H #define SMB4KAUTHINFO_H // application specific includes #include "smb4khost.h" #include "smb4kshare.h" #include "smb4kglobal.h" // Qt includes #include #include #include // forward declarations class Smb4KAuthInfoPrivate; using namespace Smb4KGlobal; /** * This class provides a container for the authentication data. * * @author Alexander Reinholdt */ class Q_DECL_EXPORT Smb4KAuthInfo { friend class Smb4KAuthInfoPrivate; public: /** * Constructor for a host item. * * @param host The Smb4KHost item. */ explicit Smb4KAuthInfo(const Smb4KHost *host); /** * Constructor for a share item. * * In case the share is a 'homes' share, this constructor will automatically * use the Smb4KShare::homeUrl() function to set the URL. * * @param share The Smb4KShare item. */ explicit Smb4KAuthInfo(const Smb4KShare *share); /** * The empty constructor. */ Smb4KAuthInfo(); /** * The copy constructor. * * @param info The Smb4KAuthInfo object that will be copied. */ Smb4KAuthInfo(const Smb4KAuthInfo &info); /** * The destructor */ ~Smb4KAuthInfo(); /** * Set the host item. This overwrites all previous data that this object * might have carried including the password. * * @param host The Smb4KHost item */ void setHost(Smb4KHost *host); /** * Set the share item. This overwrites all previous data that this object * might have carried including the password. * * In case the share is a 'homes' share, this function will automatically * use the Smb4KShare::homeUrl() function to set the URL. * * @param share The Smb4KShare item */ void setShare(Smb4KShare *share); /** * Sets the workgroup name. This function should only be used if you neither can * use setHost() nor setShare(). * * @param workgroup The name of the workgroup */ void setWorkgroupName(const QString &workgroup); /** * Returns the name of the workgroup. * * @returns The workgroup of the server/share for which this * authentication data is for. */ QString workgroupName() const; /** * Returns the host name. * * @returns the host name. */ QString hostName() const; /** * Returns the share name. * * @returns the share name. */ QString shareName() const; /** * Sets the username. * * In case of a 'homes' share, this function will also set the share * name to @p username. * * @param username The login for the server/share */ void setUserName(const QString &username); /** * Returns the username. * * @returns The username */ QString userName() const; /** * Sets the password. * * @param passwd The password for the server/share */ void setPassword(const QString &passwd); /** * Returns the password. */ QString password() const; /** * Returns the type. * * @returns the type. */ Smb4KGlobal::NetworkItem type() const; /** * If the item is a homes share, this function returns TRUE. In * all other cases, this function returns FALSE. * * @returns TRUE if the item is a homes share. */ bool isHomesShare() const; - /** - * Compare another Smb4KAuthInfo object with this one an return TRUE if both carry - * the same data. - * - * @param info The Smb4KAuthInfo object that should be compared with this - * one. - * - * @returns TRUE if the data that was compared is the same. - */ - bool equals(Smb4KAuthInfo *info) const; - - /** - * Operator to check if two authentication information objects are equal. - */ - bool operator==(Smb4KAuthInfo info) const { return equals(&info); } - /** * Sets the URL of the share after some checks are passed. * * @param url The URL of the network item */ void setUrl(const QUrl &url); /** * Sets the URL of the share. * * @param url The URL of the network item */ void setUrl(const QString &url); /** * Returns the URL of the network item * * @returns the URL */ QUrl url() const; /** * Sets the IP address for this authentication information object * * @param ip The IP address */ void setIpAddress(const QString &ip); /** * Returns the IP address * * @returns the IP address */ QString ipAddress() const; /** * Returns the display string. Prefer this over all other alternatives in your * GUI. * @returns the display string. */ QString displayString() const; private: /** * Pointer to Smb4KAuthInfoPrivate class */ const QScopedPointer d; }; #endif diff --git a/core/smb4kbookmark.cpp b/core/smb4kbookmark.cpp index 0dac16e..7be3057 100644 --- a/core/smb4kbookmark.cpp +++ b/core/smb4kbookmark.cpp @@ -1,331 +1,253 @@ /*************************************************************************** This is the bookmark container for Smb4K (next generation). ------------------- begin : So Jun 8 2008 - copyright : (C) 2008-2018 by Alexander Reinholdt + copyright : (C) 2008-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 "smb4kbookmark.h" #include "smb4kshare.h" // Qt includes #include #include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include #include using namespace Smb4KGlobal; class Smb4KBookmarkPrivate { public: QUrl url; QString workgroup; QHostAddress ip; QString label; QString group; QString profile; QIcon icon; Smb4KGlobal::ShareType type; }; Smb4KBookmark::Smb4KBookmark(Smb4KShare *share, const QString &label) : d(new Smb4KBookmarkPrivate) { if (!share->isHomesShare()) { d->url = share->url(); } else { d->url = share->homeUrl(); } d->workgroup = share->workgroupName(); d->type = share->shareType(); d->label = label; d->icon = KDE::icon("folder-network"); d->ip.setAddress(share->hostIpAddress()); } Smb4KBookmark::Smb4KBookmark(const Smb4KBookmark &b) : d(new Smb4KBookmarkPrivate) { *d = *b.d; } Smb4KBookmark::Smb4KBookmark() : d(new Smb4KBookmarkPrivate) { d->type = FileShare; d->icon = KDE::icon("folder-network"); } Smb4KBookmark::~Smb4KBookmark() { } void Smb4KBookmark::setWorkgroupName( const QString &workgroup ) { d->workgroup = workgroup; } QString Smb4KBookmark::workgroupName() const { return d->workgroup; } void Smb4KBookmark::setHostName(const QString &host) { d->url.setHost(host); d->url.setScheme("smb"); } QString Smb4KBookmark::hostName() const { return d->url.host().toUpper(); } void Smb4KBookmark::setShareName(const QString &share) { d->url.setPath(share); } QString Smb4KBookmark::shareName() const { if (d->url.path().startsWith('/')) { return d->url.path().remove(0, 1); } else { // Do nothing } return d->url.path(); } void Smb4KBookmark::setHostIpAddress(const QString &ip) { d->ip.setAddress(ip); } QString Smb4KBookmark::hostIpAddress() const { return d->ip.toString(); } void Smb4KBookmark::setShareType(Smb4KGlobal::ShareType type) { d->type = type; } Smb4KGlobal::ShareType Smb4KBookmark::shareType() const { return d->type; } void Smb4KBookmark::setLabel(const QString &label) { d->label = label; } QString Smb4KBookmark::label() const { return d->label; } void Smb4KBookmark::setLogin(const QString &login) { d->url.setUserName(login); } QString Smb4KBookmark::login() const { return d->url.userName(); } void Smb4KBookmark::setUrl(const QUrl &url) { d->url = url; d->url.setScheme("smb"); } void Smb4KBookmark::setUrl(const QString &url) { d->url.setUrl(url, QUrl::TolerantMode); d->url.setScheme("smb"); } QUrl Smb4KBookmark::url() const { return d->url; } void Smb4KBookmark::setGroupName(const QString &name) { d->group = name; } QString Smb4KBookmark::groupName() const { return d->group; } void Smb4KBookmark::setProfile(const QString &profile) { d->profile = profile; } QString Smb4KBookmark::profile() const { return d->profile; } -bool Smb4KBookmark::equals(Smb4KBookmark *bookmark) const -{ - // URL - if (d->url != bookmark->url()) - { - return false; - } - else - { - // Do nothing - } - - // Workgroup - if (QString::compare(d->workgroup, bookmark->workgroupName(), Qt::CaseInsensitive) != 0) - { - return false; - } - else - { - // Do nothing - } - - // IP address - if (QString::compare(d->ip.toString(), bookmark->hostIpAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Share type - if (d->type != bookmark->shareType()) - { - return false; - } - else - { - // Do nothing - } - - // Label - if (QString::compare(d->label, bookmark->label()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Group - if (QString::compare(d->group, bookmark->groupName()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Profile - if (QString::compare(d->profile, bookmark->profile()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // The icon is not used here. - - return true; -} - - void Smb4KBookmark::setIcon(const QIcon &icon) { d->icon = icon; } QIcon Smb4KBookmark::icon() const { return d->icon; } QString Smb4KBookmark::displayString() const { return i18n("%1 on %2", shareName(), hostName()); } diff --git a/core/smb4kbookmark.h b/core/smb4kbookmark.h index ece0433..58b82d4 100644 --- a/core/smb4kbookmark.h +++ b/core/smb4kbookmark.h @@ -1,274 +1,258 @@ /*************************************************************************** This is the bookmark container for Smb4K (next generation). ------------------- begin : So Jun 8 2008 - copyright : (C) 2008-2018 by Alexander Reinholdt + copyright : (C) 2008-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 SMB4KBOOKMARK_H #define SMB4KBOOKMARK_H // application specific includes #include "smb4kglobal.h" // Qt includes #include #include #include #include // forward declarations class Smb4KShare; class Smb4KBookmarkPrivate; /** * This is the container class for bookmarks in Smb4K. It is a complete * rewrite of the previous class and comes with several improvements. * * @author Alexander Reinholdt */ class Q_DECL_EXPORT Smb4KBookmark { friend class Smb4KBookmarkPrivate; public: /** * The constructor. * * @param share The share for which the bookmark should * be created. * * @param label The optional bookmark label. */ explicit Smb4KBookmark(Smb4KShare *share, const QString &label = QString()); /** * The copy constructor. * * @param bookmark The bookmark that should be copied. */ Smb4KBookmark(const Smb4KBookmark &bookmark); /** * The empty constructor. */ Smb4KBookmark(); /** * The destructor */ ~Smb4KBookmark(); /** * Set the workgroup name. * * @param workgroup The workgroup where the share is located. */ void setWorkgroupName(const QString &workgroup); /** * Returns the workgroup/domain name. * * @returns the workgroup/domain name. */ QString workgroupName() const; /** * Set the host name. * * @param host The host where the share is located. */ void setHostName(const QString &host); /** * Returns the host name. * * @returns the host name. */ QString hostName() const; /** * Set the share name. * * @param share The share name */ void setShareName(const QString &share); /** * Returns the share name. * * @returns the share name. */ QString shareName() const; /** * Set the host's IP address. * * @param ip The host's IP address */ void setHostIpAddress(const QString &ip); /** * Returns the host's IP address. * * @returns the host's IP address. */ QString hostIpAddress() const; /** * Set the share's type. * * @param type The type of the share. */ void setShareType(Smb4KGlobal::ShareType type); /** * Returns the share's type. * * @returns the type of the share. */ Smb4KGlobal::ShareType shareType() const; /** * Set the (optional) bookmark label. * * @param label The bookmark's label */ void setLabel(const QString &label); /** * Returns the bookmark's label. * * @returns the bookmark's label. */ QString label() const; /** * Sets the login that is used to mount this share. * * @param login The login */ void setLogin(const QString &login); /** * Returns the login that is used to mount this share. * * @returns the login. */ QString login() const; /** * Sets the URL of the share after some checks are passed. * * @param url The URL of the network item */ void setUrl(const QUrl &url); /** * Sets the URL of the share. * * @param url The URL of the network item */ void setUrl(const QString &url); /** * Returns the URL of this bookmark. * * @returns the URL */ QUrl url() const; /** * Set the group this bookmark belongs to. * * @param name The group name */ void setGroupName(const QString &name); /** * Returns the group name of this bookmark. * * @returns the group name */ QString groupName() const; /** * Sets the profile this bookmark belongs to. The profile is meant * to distinguish between several network environments, like home * and work, and is not an alternative to the group functions. * * @param profile The profile name */ void setProfile(const QString &profile); /** * Returns the name of the profile this bookmark belongs to. * * @returns the profile name */ QString profile() const; - /** - * Compare another Smb4KBookmark object with this one an return TRUE if both carry - * the same data. - * - * @param bookmark The Smb4KBookmark object that should be compared with this - * one. - * - * @returns TRUE if the data that was compared is the same. - */ - bool equals(Smb4KBookmark *bookmark) const; - - /** - * Operator to check if two bookmark objects are equal. - */ - bool operator==(Smb4KBookmark bookmark) const { return equals(&bookmark); } - /** * This function sets the icon of the bookmark. * * @param icon The icon */ void setIcon(const QIcon &icon); /** * This function returns the icon of the network item. By default, it * is the null icon. You must set the appropriate icon either in * a class that inherits this one or from somewhere else. * * @returns the network item's icon. */ QIcon icon() const; /** * Returns the display string. Prefer this over all other alternatives in your * GUI. * @returns the display string. */ QString displayString() const; private: const QScopedPointer d; }; #endif diff --git a/core/smb4kcustomoptions.cpp b/core/smb4kcustomoptions.cpp index e186fd3..c43a49f 100644 --- a/core/smb4kcustomoptions.cpp +++ b/core/smb4kcustomoptions.cpp @@ -1,1394 +1,1108 @@ /*************************************************************************** This class carries custom options ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2018 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; #if !defined(SMB4K_UNSUPPORTED_PLATFORM) Smb4KCustomOptions::Remount remount; bool useUser; KUser user; bool useGroup; KUserGroup group; bool useFileMode; QString fileMode; bool useDirectoryMode; QString directoryMode; #endif #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; #if !defined(SMB4K_UNSUPPORTED_PLATFORM) 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(); #endif #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; #if !defined(SMB4K_UNSUPPORTED_PLATFORM) 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(); #endif #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; #if !defined(SMB4K_UNSUPPORTED_PLATFORM) 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(); #endif #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; } } } else { // Do nothing } } 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 #if !defined(SMB4K_UNSUPPORTED_PLATFORM) d->user = share->user(); d->group = share->group(); #endif d->ip.setAddress(share->hostIpAddress()); break; } case Host: { if (d->url.matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::RemovePath)) { d->url = share->url(); d->type = Share; #if defined(Q_OS_LINUX) d->fileSystemPort = share->port() != -1 ? share->port() : d->fileSystemPort; #endif #if !defined(SMB4K_UNSUPPORTED_PLATFORM) d->user = share->user(); d->group = share->group(); #endif d->ip.setAddress(share->hostIpAddress()); } else { // Do nothing } break; } default: { break; } } } else { // Do nothing } } 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); } else { // Do nothing } 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; } #if !defined(SMB4K_UNSUPPORTED_PLATFORM) 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; } #endif #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; } else { // Do nothing } } 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; #if !defined(SMB4K_UNSUPPORTED_PLATFORM) 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); #endif #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::equals(Smb4KCustomOptions *options, bool fullCheck) const -{ - // Type - if (d->type != options->type()) - { - return false; - } - else - { - // Do nothing - } - - // Profile - if (QString::compare(d->profile, options->profile()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Workgroup - if (QString::compare(d->workgroup, options->workgroupName(), Qt::CaseInsensitive) != 0) - { - return false; - } - else - { - // Do nothing - } - - // URL - if (!d->url.matches(options->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) - { - return false; - } - else - { - // Do nothing - } - - // Full check - if (fullCheck) - { - // IP address - if (QString::compare(d->ip.toString(), options->ipAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - -#if !defined(SMB4K_UNSUPPORTED_PLATFORM) - // Remounting - if (d->remount != options->remount()) - { - return false; - } - else - { - // Do nothing - } - - // Use user information - if (d->useUser != options->useUser()) - { - return false; - } - else - { - // Do nothing - } - - // UID - if (d->user.userId() != options->user().userId()) - { - return false; - } - else - { - // Do nothing - } - - // Use group information - if (d->useGroup != options->useGroup()) - { - return false; - } - else - { - // Do nothing - } - - // GID - if (d->group.groupId() != options->group().groupId()) - { - return false; - } - else - { - // Do nothing - } - - // Use file mask - if (d->useFileMode != options->useFileMode()) - { - return false; - } - else - { - // Do nothing - } - - // File mode - if (d->fileMode != options->fileMode()) - { - return false; - } - else - { - // Do nothing - } - - // Use directory mode - if (d->useDirectoryMode != options->useDirectoryMode()) - { - return false; - } - else - { - // Do nothing - } - - if (d->directoryMode != options->directoryMode()) - { - return false; - } - else - { - // Do nothing - } -#endif - -#if defined(Q_OS_LINUX) - // CIFS Unix Extension support - if (d->cifsUnixExtensionsSupport != options->cifsUnixExtensionsSupport()) - { - return false; - } - else - { - // Do nothing - } - - if (d->useFileSystemPort != options->useFileSystemPort()) - { - return false; - } - else - { - // Do nothing - } - - // File system port (used for mounting) - if (d->fileSystemPort != options->fileSystemPort()) - { - return false; - } - else - { - // Do nothing - } - - // Use security mode - if (d->useSecurityMode != options->useSecurityMode()) - { - return false; - } - else - { - // Do nothing - } - - // Security mode - if (d->securityMode != options->securityMode()) - { - return false; - } - else - { - // Do nothing - } - - // Use write access - if (d->useWriteAccess != options->useWriteAccess()) - { - return false; - } - else - { - // Do nothing - } - - // Write access - if (d->writeAccess != options->writeAccess()) - { - return false; - } - else - { - // Do nothing - } -#endif - - // Use SMB port - if (d->useSmbPort != options->useSmbPort()) - { - return false; - } - else - { - // Do nothing - } - - // SMB port - if (d->smbPort != options->smbPort()) - { - return false; - } - else - { - // Do nothing - } - - // Kerberos - if (d->useKerberos != options->useKerberos()) - { - return false; - } - else - { - // Do nothing - } - - // MAC address - if (QString::compare(d->mac, options->macAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Send WOL packages before first scan - if (d->wakeOnLanBeforeFirstScan != options->wolSendBeforeNetworkScan()) - { - return false; - } - else - { - // Do nothing - } - - // Send WOL packages before mount - if (d->wakeOnLanBeforeMount != options->wolSendBeforeMount()) - { - return false; - } - else - { - // Do nothing - } - } - else - { - // Do nothing - } - - return true; -} - - 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. // #if !defined(SMB4K_UNSUPPORTED_PLATFORM) // Perform remount if (d->remount != Smb4KCustomOptions::UndefinedRemount) { return true; } else { // Do nothing } // Use user information if (d->useUser != Smb4KMountSettings::useUserId()) { return true; } else { // Do nothing } // User information if (d->user.userId() != KUser(Smb4KMountSettings::userId()).userId()) { return true; } else { // Do nothing } // Use group information if (d->useGroup != Smb4KMountSettings::useGroupId()) { return true; } else { // Do nothing } // Group information if (d->group.groupId() != KUserGroup(Smb4KMountSettings::groupId()).groupId()) { return true; } else { // Do nothing } // Use file mask if (d->useFileMode != Smb4KMountSettings::useFileMode()) { return true; } else { // Do nothing } if (d->fileMode != Smb4KMountSettings::fileMode()) { return true; } else { // Do nothing } if (d->useDirectoryMode != Smb4KMountSettings::useDirectoryMode()) { return true; } else { // Do nothing } if (d->directoryMode != Smb4KMountSettings::directoryMode()) { return true; } else { // Do nothing } #endif #if defined(Q_OS_LINUX) // CIFS Unix extension support if (d->cifsUnixExtensionsSupport != Smb4KMountSettings::cifsUnixExtensionsSupport()) { return true; } else { // Do nothing } // Use filesystem port if (d->useFileSystemPort != Smb4KMountSettings::useRemoteFileSystemPort()) { return true; } else { // Do nothing } // File system port (used for mounting) if (d->fileSystemPort != Smb4KMountSettings::remoteFileSystemPort()) { return true; } else { // Do nothing } // Use security mode if (d->useSecurityMode != Smb4KMountSettings::useSecurityMode()) { return true; } else { // Do nothing } // Security mode if (d->securityMode != Smb4KMountSettings::securityMode()) { return true; } else { // Do nothing } // Use write access if (d->useWriteAccess != Smb4KMountSettings::useWriteAccess()) { return true; } else { // Do nothing } // Write access if (d->writeAccess != Smb4KMountSettings::writeAccess()) { return true; } else { // Do nothing } #endif // Use SMB port if (d->useSmbPort != Smb4KSettings::useRemoteSmbPort()) { return true; } else { // Do nothing } // SMB port if (d->smbPort != Smb4KSettings::remoteSmbPort()) { return true; } else { // Do nothing } // Kerberos if (d->useKerberos != Smb4KSettings::useKerberos()) { return true; } else { // Do nothing } // MAC address if (!d->mac.isEmpty()) { return true; } else { // Do nothing } // Send WOL packages before first scan if (d->wakeOnLanBeforeFirstScan) { return true; } else { // Do nothing } // Send WOL packages before mount if (d->wakeOnLanBeforeMount) { return true; } else { // Do nothing } return false; } void Smb4KCustomOptions::update(Smb4KCustomOptions *options) { d->ip.setAddress(options->ipAddress()); #if !defined(SMB4K_UNSUPPORTED_PLATFORM) 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(); #endif #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 ca8ef23..c5140a8 100644 --- a/core/smb4kcustomoptions.h +++ b/core/smb4kcustomoptions.h @@ -1,594 +1,577 @@ /*************************************************************************** This class carries custom options ------------------- begin : Fr 29 Apr 2011 copyright : (C) 2011-2018 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; #if !defined(SMB4K_UNSUPPORTED_PLATFORM) /** * 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. */ 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; #endif #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 the custom options @p options are equal to those defined here. If - * you just want to check if the options have the same URL and workgroup and - * belong to the same profile, set @p fullCheck to FALSE. - * - * @param options The options that are to be compared to the - * ones defined here - * @param fullCheck Set this to FALSE if you just want to check - * the profile, URL and workgroup. - */ - bool equals(Smb4KCustomOptions *options, bool fullCheck = true) const; - - /** - * Operator to check if two custom options objects are equal. - */ - bool operator==(Smb4KCustomOptions options) const { return equals(&options, true); } - /** * 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/smb4khost.cpp b/core/smb4khost.cpp index 0b28592..90d28f0 100644 --- a/core/smb4khost.cpp +++ b/core/smb4khost.cpp @@ -1,328 +1,238 @@ /*************************************************************************** Smb4K's container class for information about a host. ------------------- begin : Sa Jan 26 2008 copyright : (C) 2008-2017 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 "smb4khost.h" #include "smb4kauthinfo.h" // Qt includes #include #include #include // KDE includes #include class Smb4KHostPrivate { public: QString workgroup; QHostAddress ip; QString comment; bool isMaster; }; Smb4KHost::Smb4KHost(const QString &name) : Smb4KBasicNetworkItem(Host), d(new Smb4KHostPrivate) { d->isMaster = false; *pIcon = KDE::icon("network-server"); setHostName(name); } Smb4KHost::Smb4KHost(const Smb4KHost &h) : Smb4KBasicNetworkItem(Host), d(new Smb4KHostPrivate) { *d = *h.d; if (pIcon->isNull()) { *pIcon = KDE::icon("network-server"); } else { // Do nothing } } Smb4KHost::Smb4KHost() : Smb4KBasicNetworkItem(Host), d(new Smb4KHostPrivate) { d->isMaster = false; *pIcon = KDE::icon("network-server"); } Smb4KHost::~Smb4KHost() { } void Smb4KHost::setHostName(const QString &name) { pUrl->setHost(name); pUrl->setScheme("smb"); } QString Smb4KHost::hostName() const { return pUrl->host().toUpper(); } void Smb4KHost::setWorkgroupName(const QString &workgroup) { d->workgroup = workgroup.toUpper(); } QString Smb4KHost::workgroupName() const { return d->workgroup; } void Smb4KHost::setIpAddress(const QString &ip) { d->ip.setAddress(ip); } void Smb4KHost::setIpAddress(const QHostAddress& address) { if (!address.isNull() && address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol) { d->ip = address; } else { // Do nothing } } QString Smb4KHost::ipAddress() const { return d->ip.toString(); } bool Smb4KHost::hasIpAddress() const { return !d->ip.isNull(); } void Smb4KHost::setComment(const QString &comment) { d->comment = comment; } QString Smb4KHost::comment() const { return d->comment; } void Smb4KHost::setIsMasterBrowser(bool master) { d->isMaster = master; } bool Smb4KHost::isMasterBrowser() const { return d->isMaster; } -bool Smb4KHost::isEmpty() const -{ - if (!pUrl->isEmpty()) - { - return false; - } - else - { - // Do nothing - } - - if (!d->workgroup.isEmpty()) - { - return false; - } - else - { - // Do nothing - } - - if (!d->ip.isNull()) - { - return false; - } - else - { - // Do nothing - } - - if (!d->comment.isEmpty()) - { - return false; - } - else - { - // Do nothing - } - - // Do not include icon here. - - return true; -} - - void Smb4KHost::setLogin(const QString &login) { pUrl->setUserName(login); } QString Smb4KHost::login() const { return pUrl->userName(); } void Smb4KHost::setPassword(const QString &passwd) { pUrl->setPassword(passwd); } QString Smb4KHost::password() const { return pUrl->password(); } void Smb4KHost::setPort(int port) { pUrl->setPort(port); } int Smb4KHost::port() const { return pUrl->port(); } -bool Smb4KHost::equals(Smb4KHost *host) const -{ - Q_ASSERT(host); - - if (*pUrl != host->url()) - { - return false; - } - else - { - // Do nothing - } - - if (QString::compare(workgroupName(), host->workgroupName()) != 0) - { - return false; - } - else - { - // Do nothing - } - - if (QString::compare(ipAddress(), host->ipAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - if (QString::compare(comment(), host->comment()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Do not include icon here. - - return true; -} - - void Smb4KHost::setAuthInfo(Smb4KAuthInfo *authInfo) { pUrl->setUserName(authInfo->userName()); pUrl->setPassword(authInfo->password()); } void Smb4KHost::update(Smb4KHost* host) { if (QString::compare(workgroupName(), host->workgroupName()) == 0 && QString::compare(hostName(), host->hostName()) == 0) { *pUrl = host->url(); setComment(host->comment()); setIsMasterBrowser(host->isMasterBrowser()); // Do not kill the already discovered IP address if (!hasIpAddress() && host->hasIpAddress()) { setIpAddress(host->ipAddress()); } else { // Do nothing } } else { // Do nothing } } diff --git a/core/smb4khost.h b/core/smb4khost.h index f72ab98..5208522 100644 --- a/core/smb4khost.h +++ b/core/smb4khost.h @@ -1,260 +1,235 @@ /*************************************************************************** Smb4K's container class for information about a host. ------------------- begin : Sa Jan 26 2008 copyright : (C) 2008-2017 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 SMB4KHOST_H #define SMB4KHOST_H // application specific includes #include "smb4kbasicnetworkitem.h" // Qt includes #include #include #include // forward declarations class Smb4KAuthInfo; class Smb4KHostPrivate; /** * This class is a container that carries information about a host found in * the network neighborhood. It is part of the core classes of Smb4K. * * @author Alexander Reinholdt */ class Q_DECL_EXPORT Smb4KHost : public Smb4KBasicNetworkItem { friend class Smb4KHostPrivate; public: /** * The default constructor. It takes the name of the host as only argument. * You have to set all other information with the other functions provided * by this class. * * @param name The name of the host */ explicit Smb4KHost(const QString &name); /** * The copy constructor. This constructor takes a Smb4KHost item as argument * and copies its values. * * @param host The Smb4KHost object that is to be copied. */ Smb4KHost(const Smb4KHost &host); /** * The empty constructor. It does not take any argument and you have to set * all information by the other functions provided by this class. */ Smb4KHost(); /** * The destructor. */ ~Smb4KHost(); /** * Set the name of the host. * * @param name The name of the host */ void setHostName(const QString &name); /** * Returns the name of the host. * * @returns the host's name. */ QString hostName() const; /** * Set the workgroup where this host is located. * * @param workgroup The workgroup name */ void setWorkgroupName(const QString &workgroup); /** * Returns the name of the workgroup where this host is located. * * @returns the workgroup name. */ QString workgroupName() const; /** * Set the IP address of this host. @p ip will only be accepted * if it is compatible with either IPv4 or IPv6. * * @param ip The IP address of this host. */ void setIpAddress(const QString &ip); /** * Set the IP address of this host. @p ip will only be accepted * if it is compatible with either IPv4 or IPv6. * * @param ip The IP address of this host. */ void setIpAddress(const QHostAddress &address); /** * Returns the IP address of the host. If the IP address was not * compatible with IPv4 and IPv6 or if no IP address was supplied, * an empty string is returned. * * @returns the host's IP address or an empty string. */ QString ipAddress() const; /** * Returns TRUE if the host's IP address is set and FALSE otherwise. * * @returns TRUE if the host's IP address is known. */ bool hasIpAddress() const; /** * Set the comment that was defined for the host. * * @param comment The comment string */ void setComment(const QString &comment); /** * Returns the comment that was defined or an empty string if there * was no comment. * * @returns the comment or an empty string. */ QString comment() const; /** * Set this host to be a master browser. * * @param master Set this to TRUE if the host is a master * browser. */ void setIsMasterBrowser(bool master); /** * Returns TRUE if the host is a master browser and FALSE otherwise. * * @returns TRUE if the host is a master browser. */ bool isMasterBrowser() const; - /** - * Returns TRUE if the item is empty and FALSE otherwise. An item is not - * empty if at least one string (workgroup name, master name, etc.) has been - * set. A modified boolean will not be considered. - * - * @returns TRUE if the item is empty. - */ - bool isEmpty() const; - /** * Set the port for the use in the URL. * * @param port The port */ void setPort(int port); /** * Returns the port that is used in the URL. * * @returns the port. */ int port() const; - /** - * Compare another Smb4KHost object with this one an return TRUE if both carry - * the same data. - * - * @param host The Smb4KHost object that should be compared with this - * one. - * - * @returns TRUE if the data that was compared is the same. - */ - bool equals(Smb4KHost *host) const; - - /** - * Operator to check if two hosts are equal. - */ - bool operator==(Smb4KHost host) const { return equals(&host); } - /** * Set the authentication information for the host. This function will add * the authentication information to the URL of the host. Any previous * user information including the login will be overwritten. * * @param authInfo The authentication information */ void setAuthInfo(Smb4KAuthInfo *authInfo); /** * Set the login name for the host. * * @param login The login name */ void setLogin(const QString &login); /** * Returns the login name. * * @returns the login name. */ QString login() const; /** * Set the password used for authentication. * * @param passwd The password */ void setPassword(const QString &passwd); /** * Returns the password. * * @returns the password. */ QString password() const; /** * Updates the host item if the workgroup and host name of @p host and * of this item is equal. Otherwise it does nothing. * @param host The share object that is used to update * this object */ void update(Smb4KHost *host); private: const QScopedPointer d; }; #endif diff --git a/core/smb4kshare.cpp b/core/smb4kshare.cpp index f1268f4..b31ef2d 100644 --- a/core/smb4kshare.cpp +++ b/core/smb4kshare.cpp @@ -1,1212 +1,711 @@ /*************************************************************************** Smb4K's container class for information about a share. ------------------- begin : Mo Jan 28 2008 copyright : (C) 2008-2017 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 "smb4kshare.h" #include "smb4kauthinfo.h" // Qt include #include #include // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include #include #include #include class Smb4KSharePrivate { public: QString workgroup; QString comment; QHostAddress ip; QString path; bool inaccessible; bool foreign; KUser user; KUserGroup group; qulonglong totalSpace; qulonglong freeSpace; qulonglong usedSpace; bool mounted; QString filesystem; Smb4KGlobal::ShareType shareType; }; Smb4KShare::Smb4KShare(const QString &host, const QString &name) : Smb4KBasicNetworkItem(Share), d(new Smb4KSharePrivate) { d->inaccessible = false; d->foreign = false; d->filesystem = QString(); d->user = KUser(KUser::UseRealUserID); d->group = KUserGroup(KUser::UseRealUserID); d->totalSpace = -1; d->freeSpace = -1; d->usedSpace = -1; d->mounted = false; d->shareType = FileShare; setHostName(host); setShareName(name); setShareIcon(); } Smb4KShare::Smb4KShare(const QUrl &url) : Smb4KBasicNetworkItem(Share), d(new Smb4KSharePrivate) { // // Set the private variables // d->inaccessible = false; d->foreign = false; d->filesystem = QString(); d->user = KUser(KUser::UseRealUserID); d->group = KUserGroup(KUser::UseRealUserID); d->totalSpace = -1; d->freeSpace = -1; d->usedSpace = -1; d->mounted = false; d->shareType = FileShare; // // Set the URL // *pUrl = url; // // Set the icon // setShareIcon(); } Smb4KShare::Smb4KShare(const Smb4KShare &s) : Smb4KBasicNetworkItem(Share), d(new Smb4KSharePrivate) { // // Copy the private variables // *d = *s.d; // // Set the icon if necessary // if (pIcon->isNull()) { setShareIcon(); } else { // Do nothing } } Smb4KShare::Smb4KShare() : Smb4KBasicNetworkItem(Share), d(new Smb4KSharePrivate) { // // Set the private variables // d->inaccessible = false; d->foreign = false; d->filesystem = QString(); d->user = KUser(KUser::UseRealUserID); d->group = KUserGroup(KUser::UseRealUserID); d->totalSpace = -1; d->freeSpace = -1; d->usedSpace = -1; d->mounted = false; d->shareType = FileShare; // // Set the URL // pUrl->setScheme("smb"); // // Set the icon // setShareIcon(); } Smb4KShare::~Smb4KShare() { } void Smb4KShare::setShareName(const QString &name) { if (name.startsWith('/')) { pUrl->setPath(name.trimmed()); } else { pUrl->setPath('/'+name.trimmed()); } pUrl->setScheme("smb"); } QString Smb4KShare::shareName() const { return pUrl->path().remove('/'); } void Smb4KShare::setHostName(const QString &hostName) { pUrl->setHost(hostName.trimmed()); pUrl->setScheme("smb"); } QString Smb4KShare::hostName() const { return pUrl->host().toUpper(); } QUrl Smb4KShare::homeUrl() const { QUrl u; if (isHomesShare() && !pUrl->userName().isEmpty()) { u = *pUrl; u.setPath('/'+pUrl->userName(), QUrl::TolerantMode); } else { // Do nothing } return u; } QString Smb4KShare::displayString(bool showHomesShare) const { if (showHomesShare && isHomesShare()) { return i18n("%1 on %2", homeUrl().path().remove('/'), hostName()); } else { // Do nothing } return i18n("%1 on %2", shareName(), hostName()); } void Smb4KShare::setWorkgroupName(const QString &workgroup) { d->workgroup = workgroup; } QString Smb4KShare::workgroupName() const { return d->workgroup; } void Smb4KShare::setShareType(Smb4KGlobal::ShareType type) { d->shareType = type; setShareIcon(); } Smb4KGlobal::ShareType Smb4KShare::shareType() const { return d->shareType; } QString Smb4KShare::shareTypeString() const { QString typeString; switch (d->shareType) { case FileShare: { typeString = i18n("Disk"); break; } case PrinterShare: { typeString = i18n("Printer"); break; } case IpcShare: { typeString = i18n("IPC"); break; } default: { break; } } return typeString; } void Smb4KShare::setComment(const QString &comment) { d->comment = comment; } QString Smb4KShare::comment() const { return d->comment; } void Smb4KShare::setHostIpAddress(const QString &ip) { d->ip.setAddress(ip); } void Smb4KShare::setHostIpAddress(const QHostAddress& address) { if (!address.isNull() && address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol) { d->ip = address; } else { // Do nothing } } QString Smb4KShare::hostIpAddress() const { return d->ip.toString(); } bool Smb4KShare::hasHostIpAddress() const { return !d->ip.isNull(); } bool Smb4KShare::isHidden() const { return pUrl->path().endsWith('$'); } bool Smb4KShare::isPrinter() const { return (d->shareType == PrinterShare); } void Smb4KShare::setPath(const QString &mountpoint) { d->path = mountpoint; } QString Smb4KShare::path() const { return d->path; } QString Smb4KShare::canonicalPath() const { return (d->inaccessible ? d->path : QDir(d->path).canonicalPath()); } void Smb4KShare::setInaccessible(bool in) { d->inaccessible = in; setShareIcon(); } bool Smb4KShare::isInaccessible() const { return (d->mounted && d->inaccessible); } void Smb4KShare::setForeign(bool foreign) { d->foreign = foreign; setShareIcon(); } bool Smb4KShare::isForeign() const { return (d->mounted && d->foreign); } QString Smb4KShare::fileSystemString() const { if (!path().isEmpty() && d->filesystem.isEmpty()) { KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(path()); d->filesystem = mp->mountType().toUpper(); } else { // Do nothing } return d->filesystem; } void Smb4KShare::setUser(const KUser &user) { d->user = user; } KUser Smb4KShare::user() const { return d->user; } void Smb4KShare::setGroup(const KUserGroup &group) { d->group = group; } KUserGroup Smb4KShare::group() const { return d->group; } void Smb4KShare::setMounted(bool mounted) { if (!isPrinter()) { d->mounted = mounted; setShareIcon(); } else { // Do nothing } } bool Smb4KShare::isMounted() const { return d->mounted; } void Smb4KShare::setTotalDiskSpace(qulonglong size) { d->totalSpace = size; } qulonglong Smb4KShare::totalDiskSpace() const { return d->totalSpace; } QString Smb4KShare::totalDiskSpaceString() const { return KIO::convertSize(d->totalSpace); } void Smb4KShare::setFreeDiskSpace(qulonglong size) { d->freeSpace = size; } qulonglong Smb4KShare::freeDiskSpace() const { return d->freeSpace; } QString Smb4KShare::freeDiskSpaceString() const { return KIO::convertSize(d->freeSpace); } void Smb4KShare::setUsedDiskSpace(qulonglong size) { d->usedSpace = size; } qulonglong Smb4KShare::usedDiskSpace() const { return d->usedSpace; } QString Smb4KShare::usedDiskSpaceString() const { return KIO::convertSize(d->usedSpace); } qreal Smb4KShare::diskUsage() const { qreal used(usedDiskSpace()); qreal total(totalDiskSpace()); if (total > 0) { return used * 100 / total; } return 0; } QString Smb4KShare::diskUsageString() const { return QString("%1 %").arg(diskUsage(), 0, 'f', 1); } -bool Smb4KShare::equals(Smb4KShare *share, CheckFlags flag) const -{ - qDebug() << "Simplify Smb4KShare::equals()"; - - Q_ASSERT(share); - - switch (flag) - { - case Full: - { - // URL - if (!url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) - { - return false; - } - else - { - // Do nothing - } - - // Login - if (QString::compare(login(), share->login()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Workgroup name - if (QString::compare(workgroupName(), share->workgroupName(), Qt::CaseInsensitive) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Type - if (d->shareType != share->shareType()) - { - return false; - } - else - { - // Do nothing - } - - // Comment - if (QString::compare(comment(), share->comment()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // IP address - if (QString::compare(hostIpAddress(), share->hostIpAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Path - if (QString::compare(path(), share->path()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Accessibility? - if (isInaccessible() != share->isInaccessible()) - { - return false; - } - else - { - // Do nothing - } - - // Foreignness - if (isForeign() != share->isForeign()) - { - return false; - } - else - { - // Do nothing - } - - // UID - if (user().userId().nativeId() != share->user().userId().nativeId()) - { - return false; - } - else - { - // Do nothing - } - - // GID - if (group().groupId().nativeId() != share->group().groupId().nativeId()) - { - return false; - } - else - { - // Do nothing - } - - // Total space - if (totalDiskSpace() != share->totalDiskSpace()) - { - return false; - } - else - { - // Do nothing - } - - // Used space - if (usedDiskSpace() != share->usedDiskSpace()) - { - return false; - } - else - { - // Do nothing - } - - // Mounted - if (isMounted() != share->isMounted()) - { - return false; - } - else - { - // Do nothing - } - - break; - } - case NetworkOnly: - { - // URL - if (!url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) - { - return false; - } - else - { - // Do nothing - } - - // Login - if (QString::compare(login(), share->login()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Workgroup name - if (QString::compare(workgroupName(), share->workgroupName(), Qt::CaseInsensitive) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Type - if (d->shareType != share->shareType()) - { - return false; - } - else - { - // Do nothing - } - - // Comment - if (QString::compare(comment(), share->comment()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // IP address - if (QString::compare(hostIpAddress(), share->hostIpAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - break; - } - case MinimalNetworkOnly: - { - // URL - if (!url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) - { - return false; - } - else - { - // Do nothing - } - - // Workgroup name - if (QString::compare(workgroupName(), share->workgroupName(), Qt::CaseInsensitive) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Type - if (d->shareType != share->shareType()) - { - return false; - } - else - { - // Do nothing - } - - break; - } - case LocalOnly: - { - // URL - if (!url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) - { - return false; - } - else - { - // Do nothing - } - - // Login - if (QString::compare(login(), share->login()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Path - if (QString::compare(path(), share->path()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Accessibility? - if (isInaccessible() != share->isInaccessible()) - { - return false; - } - else - { - // Do nothing - } - - // Foreignness - if (isForeign() != share->isForeign()) - { - return false; - } - else - { - // Do nothing - } - - // UID - if (user().userId().nativeId() != share->user().userId().nativeId()) - { - return false; - } - else - { - // Do nothing - } - - // GID - if (group().groupId().nativeId() != share->group().groupId().nativeId()) - { - return false; - } - else - { - // Do nothing - } - - // Total space - if (totalDiskSpace() != share->totalDiskSpace()) - { - return false; - } - else - { - // Do nothing - } - - // Used space - if (usedDiskSpace() != share->usedDiskSpace()) - { - return false; - } - else - { - // Do nothing - } - - // Mounted - if (isMounted() != share->isMounted()) - { - return false; - } - else - { - // Do nothing - } - - break; - } - case MinimalLocalOnly: - { - // URL - if (!url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) - { - return false; - } - else - { - // Do nothing - } - - // Path - if (QString::compare(path(), share->path()) != 0) - { - return false; - } - else - { - // Do nothing - } - - break; - } - default: - { - break; - } - } - - return true; -} - - -bool Smb4KShare::isEmpty(CheckFlags flag) const -{ - switch (flag) - { - case Full: - { - if (!url().isEmpty()) - { - return false; - } - - if (!d->workgroup.isEmpty()) - { - return false; - } - - if (!d->comment.isEmpty()) - { - return false; - } - - if (!d->ip.isNull()) - { - return false; - } - - if (!d->path.isEmpty()) - { - return false; - } - - if (!d->filesystem.isEmpty()) - { - return false; - } - - if (d->totalSpace > 0) - { - return false; - } - - if (d->freeSpace > 0) - { - return false; - } - - if (d->usedSpace > 0) - { - return false; - } - - break; - } - case NetworkOnly: - { - if (!pUrl->isEmpty()) - { - return false; - } - - if (!d->workgroup.isEmpty()) - { - return false; - } - - if (!d->comment.isEmpty()) - { - return false; - } - - if (!d->ip.isNull()) - { - return false; - } - - break; - } - case LocalOnly: - { - if (!d->path.isEmpty()) - { - return false; - } - - if (!d->filesystem.isEmpty()) - { - return false; - } - - if (d->totalSpace > 0) - { - return false; - } - - if (d->freeSpace > 0) - { - return false; - } - - if (d->usedSpace > 0) - { - return false; - } - - break; - } - default: - { - break; - } - } - - return true; -} - - void Smb4KShare::setMountData(Smb4KShare *share) { Q_ASSERT(share); - if (equals(share, MinimalNetworkOnly)) + if (QString::compare(url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), + share->url().toString(QUrl::RemoveUserInfo|QUrl::RemovePort), + Qt::CaseInsensitive) == 0 && + QString::compare(workgroupName(), share->workgroupName(), Qt::CaseInsensitive) == 0) { d->path = share->path(); d->inaccessible = share->isInaccessible(); d->foreign = share->isForeign(); d->user = share->user(); d->group = share->group(); d->totalSpace = share->totalDiskSpace(); d->freeSpace = share->freeDiskSpace(); d->usedSpace = share->usedDiskSpace(); d->mounted = share->isMounted(); d->shareType = share->shareType(); setShareIcon(); } else { // Do nothing } } void Smb4KShare::resetMountData() { d->path.clear(); d->inaccessible = false; d->foreign = false; d->user = KUser(KUser::UseRealUserID); d->group = KUserGroup(KUser::UseRealUserID); d->totalSpace = -1; d->freeSpace = -1; d->usedSpace = -1; d->mounted = false; d->shareType = FileShare; setShareIcon(); } bool Smb4KShare::isHomesShare() const { return pUrl->path().endsWith(QLatin1String("homes")); } void Smb4KShare::setPort(int port) { pUrl->setPort(port); } int Smb4KShare::port() const { return pUrl->port(); } void Smb4KShare::setAuthInfo(Smb4KAuthInfo *authInfo) { // Avoid that the login is overwritten with an empty // string if we have a homes share. if (!isHomesShare() || !authInfo->userName().isEmpty()) { pUrl->setUserName(authInfo->userName()); pUrl->setPassword(authInfo->password()); } else { // Do nothing } } void Smb4KShare::setLogin(const QString &login) { // Avoid that the login is overwritten with an empty // string if we have a homes share. if (!isHomesShare() || !login.isEmpty()) { pUrl->setUserName(login); } else { // Do nothing } } QString Smb4KShare::login() const { return pUrl->userName(); } void Smb4KShare::setPassword(const QString &passwd) { // Avoid that the password is overwritten with an empty // string if we have a homes share. if (!isHomesShare() || !passwd.isEmpty()) { pUrl->setPassword(passwd); } else { // Do nothing } } QString Smb4KShare::password() const { return pUrl->password(); } void Smb4KShare::setShareIcon() { // // We have three base icons: // - remote folder // - locked folder // - printer // if (!isPrinter()) { // Overlays QStringList overlays; if (isMounted()) { overlays << "emblem-mounted"; } else { overlays << ""; } if (isForeign()) { overlays << "task-attention"; } else { // Do nothing } if (!isInaccessible()) { *pIcon = KDE::icon("folder-network", overlays); } else { *pIcon = KDE::icon("folder-locked", overlays); } } else { *pIcon = KDE::icon("printer"); } } void Smb4KShare::update(Smb4KShare* share) { if (QString::compare(workgroupName(), share->workgroupName()) == 0 && (url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort) || homeUrl().matches(share->homeUrl(), QUrl::RemoveUserInfo|QUrl::RemovePort))) { *pUrl = share->url(); setMountData(share); setShareType(share->shareType()); setComment(share->comment()); setHostIpAddress(share->hostIpAddress()); } else { // Do nothing } } diff --git a/core/smb4kshare.h b/core/smb4kshare.h index d630768..76beac2 100644 --- a/core/smb4kshare.h +++ b/core/smb4kshare.h @@ -1,588 +1,535 @@ /*************************************************************************** Smb4K's container class for information about a share. ------------------- begin : Mo Jan 28 2008 copyright : (C) 2008-2017 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 SMB4KSHARE_H #define SMB4KSHARE_H // application specific includes #include "smb4kbasicnetworkitem.h" // Qt includes #include #include #include #include #include // KDE includes #include // forward declarations class Smb4KAuthInfo; class Smb4KSharePrivate; class Q_DECL_EXPORT Smb4KShare : public Smb4KBasicNetworkItem { friend class Smb4KSharePrivate; public: /** * This constructor takes the host name @p hostName and the name of the * shared resource @p shareName. All other information has to be set by the * other functions this class provides. * * This constructor will also assemble the UNC from the provided arguments. * * @param hostName The name of the host where the share is * located. * * @param shareName The name of the share. */ Smb4KShare(const QString &hostName, const QString &shareName); /** * This constructor takes the URL @p url as only argument. All other * information has to be set by the other functions this class provides. * * @param url The URL */ explicit Smb4KShare(const QUrl &url); /** * This is the copy constructor. It takes another Smb4KShare item and copies all * its values. * * @param share The Smb4KShare item that is to be copied */ Smb4KShare(const Smb4KShare &share); /** * The empty constructor. You need to set all information by the functions that * are provided with this class. */ Smb4KShare(); /** * The destructor. */ ~Smb4KShare(); /** * Sets the name of the share (*not* the UNC). * * @param name The share name */ void setShareName(const QString &name); /** * Returns the name of the share, e.g. "Music", "Data", etc. * * @returns the name of the share. */ QString shareName() const; /** * Sets the name of the host where the share is located. * * @param hostName The host name */ void setHostName(const QString &hostName); /** * Returns the name of the host where the share is located. * * @returns the host name */ QString hostName() const; /** * In case of a 'homes' share, this function returns the URL of the user's * home repository. * * If the share is not a 'homes' share or no user name for the homes share * has been defined, this function returns an empty string. * * @returns the user's home repository's URL. */ QUrl homeUrl() const; /** * Returns the display string. Prefer this over all other alternatives in your * GUI. * * @param showHomesShare Show the name of the users home share instead of 'homes' * in case this is a homes share. Setting this argument on a * non-homes share does nothing. * * @returns the display string. */ QString displayString(bool showHomeShare = false) const; /** * Set the workgroup where the host is located that offers this share. * * @param workgroup The name of the workgroup */ void setWorkgroupName(const QString &workgroup); /** * Returns the name of the workgroup where the host is located that * offers this share. * * @returns the workgroup name */ QString workgroupName() const; /** * Set the type of the share as reported by the server. * * @param type The type of the string */ void setShareType(Smb4KGlobal::ShareType type); /** * Returns the type of the share as reported by the server. If you are * looking for a translated type string, then use the shareTypeString() * function. * * @returns the type of the share. */ Smb4KGlobal::ShareType shareType() const; /** * Returns the translated type string of the share. You can use this * in the GUI. * * @returns a translated type string. */ QString shareTypeString() const; /** * Sets the comment that was defined for the share. * * @param comment The comment for the share */ void setComment(const QString &comment); /** * Returns the comment that was defined for this share. * * @returns the comment. */ QString comment() const; /** * Set the IP address of the host where the share is located. @p ip will * only be accepted if it is compatible with either IPv4 or IPv6. * * @param ip The host's IP address */ void setHostIpAddress(const QString &ip); /** * Set the IP address of the host where the share is located. @p ip will only be accepted * if it is compatible with either IPv4 or IPv6. * * @param ip The host's IP address */ void setHostIpAddress(const QHostAddress &address); /** * Returns the IP address of the host. If the IP address was not compatible * with IPv4 and IPv6 or if no IP address was supplied, an empty string is * returned. * * @returns the IP address of the host or an empty string. */ QString hostIpAddress() const; /** * Returns TRUE if the host's IP address is set and FALSE otherwise. * * @returns TRUE if the host's IP address is set and FALSE otherwise. */ bool hasHostIpAddress() const; /** * If the share is a hidden one, i.e. it ends with a '$', this function returns * TRUE and FALSE otherwise. * * @returns TRUE if this is a hidden share. */ bool isHidden() const; /** * If the share is a printer this function returns TRUE and otherwise FALSE. * * @returns TRUE if the share is a printer. */ bool isPrinter() const; /** * Sets the path aka mount point of the share as gathered by the mounter. * * @param mountpoint The mount point of the share. */ void setPath(const QString &mountpoint); /** * Returns the path to the mounted share (aka the mount point) as it was gathered * by the mounter. It is a C-type string. * * @returns the path to the mounted share. */ QString path() const; /** * Returns the canonical path to the mounted share. In contrast to the path() * function it will return the absolute path without symlinks. However, should * the share be inaccessible (i.e. the isInaccessible() returns TRUE), only * the "normal" path is returned. * * @returns the canonical path to the mounted share. */ QString canonicalPath() const; /** * Set @p in to TRUE if the share cannot be accessed by the user. This may be * because if strict permissions or because the remote server went offline. By * default it is assumed that the share is accessible. * * @param in Tells if the share is inaccessible or not. */ void setInaccessible(bool in); /** * Returns TRUE if the share is mounted and not accessible by the user. * * @returns TRUE if the share is mounted and inaccessible. */ bool isInaccessible() const; /** * If the share was mounted by another user, @p foreign should be set to TRUE. * By default it is assumed that the share is not foreign but owned by the * user. * * @param foreign TRUE if the share is foreign and FALSE otherwise. */ void setForeign(bool foreign); /** * Returns TRUE if the share is mounted and is owned by another user. * * @returns TRUE if this is a foreign share. */ bool isForeign() const; /** * Returns the file system as string in capital letters. If no file system * was specified, an empty string is returned. * * @returns the file system string or an empty string. */ QString fileSystemString() const; /** * Sets the owner of this share. * @param user The UID of the owner */ void setUser(const KUser &user); /** * Returns the owner of this share or the current user, if * the owner was not set using @see setUser(). * @returns the owner. */ KUser user() const; /** * Set the group that owns this share. * @param group The owning GID */ void setGroup(const KUserGroup &group); /** * Returns the group that owns this share or the current group, if * the group was not set using @see setGroup(). * @returns the group. */ KUserGroup group() const; /** * Sets the value of the total disk space that is available on the share. If * the disk usage could not be determined, @p size has to be set to 0. * * @param total The total disk space that is available on the share */ void setTotalDiskSpace(qulonglong size); /** * Returns the total disk space that is available on the share or 0 if the * total disk space was not set or could not be determined. * * @returns the total disk space or 0. */ qulonglong totalDiskSpace() const; /** * Returns the total disk space in a human readable form with value and unit * (e.g. 10 KiB, 25 MiB, etc.) even if the total disk space was not set or could * not be determined. If the value is a valid one, you have to check by evaluating * the return value of the isInaccessible() function. * * @returns the total disk space in a human readable form. */ QString totalDiskSpaceString() const; /** * Sets the value of the free disk space that is available on the share. If * the free disk space could not be determined, @p size has to be set to 0. * * @param free The free disk space that is available on the share */ void setFreeDiskSpace(qulonglong size); /** * Returns the free disk space that is available on the share or 0 if the * free disk space was not set or could not be determined. * * @returns the free disk space or 0. */ qulonglong freeDiskSpace() const; /** * Returns the free disk space in a human readable form with value and unit * (e.g. 10 KiB, 25 MiB, etc.) even if the free disk space was not set or could * not be determined. If the value is a valid one, you have to check by evaluating * the return value of the isInaccessible() function. * * @returns the free disk space in a human readable form. */ QString freeDiskSpaceString() const; /** * Sets the value of the disk space that is used on the share. If the used * disk space could not be determined, @p size has to be set to 0. * * @param free The free disk space that is available on the share */ void setUsedDiskSpace(qulonglong size); /** * Returns the used disk space that is used on the share or 0 if the * used disk space was not set or could not be determined. * * @returns the used disk space or 0. */ qulonglong usedDiskSpace() const; /** * Returns the used disk space in a human readable form with value and unit * (e.g. 10 KiB, 25 MiB, etc.) even if the used disk space was not set or could * not be determined. If the value is a valid one, you have to check by evaluating * the return value of the isInaccessible() function. * * @returns the used disk space in a human readable form. */ QString usedDiskSpaceString() const; /** * Returns the disk usage in percent. * @returns the disk usage in percent. */ qreal diskUsage() const; /** * Returns the disk usage in a human readable form with value and unit, * for example 3.5 %, 67.0 % etc. If the usage was not set or could not * be determined, this function returns an empty string. * * @returns the disk usage in a human readable form or an empty string. */ QString diskUsageString() const; - /** - * Enumeration for the checks. - * - * @enum Full Full comparison - * @enum NetworkOnly Only the network related values are compared - * @enum MinimalNetworkOnly Only the absolutely necessary network related values - * are compared - * @enum LocalOnly Only those values are compared that are of local - * importance - * @enum MinimalLocalOnly Only those values are compared that have local importance - * and are absolutely necessary for a comparison - */ - enum CheckFlags{ Full, - NetworkOnly, - MinimalNetworkOnly, - LocalOnly, - MinimalLocalOnly }; - - /** - * Compare another Smb4KShare object with this one an return TRUE if both carry - * the same data. Depending on the value of @p flag either all data will be compared - * or only the one that is network related or the one that is of local importance. - * - * Please note, that the UNC won't be checked with the flag CheckFlags::NetworkOnly, - * but only with either CheckFlags::Full or CheckFlags::LocalOnly. - * - * @param share The Smb4KShare object that should be compared with this - * one. - * - * @param flag The flag that determines which values are compared. - * - * @returns TRUE if the data that was compared is the same. - */ - bool equals(Smb4KShare *share, CheckFlags flag) const; - - /** - * Operator to check if two shares are equal. This operator performs a full check. - */ - bool operator==(Smb4KShare share) const { return equals(&share, Full); } - - /** - * Returns TRUE if values that were checked according to @p flag are empty. - * Modified booleans are not considered. - * - * Please note, that the UNC won't be checked with the flag CheckFlags::NetworkOnly, - * but only with either CheckFlags::Full or CheckFlags::LocalOnly. - * - * @param flag The flag that determines which values are checked. - * - * @returns TRUE if the item is empty. - */ - bool isEmpty(CheckFlags flag = Full) const; - /** * If this share was mounted, set @p mounted to TRUE. This function will not * work with printer shares. * * @param mounted Should be set to TRUE if the share was mounted. */ void setMounted(bool mounted); /** * This function returns TRUE if the share has been mounted and FALSE * otherwise. * * @returns TRUE if this share was mounted. */ bool isMounted() const; /** * This convenience function sets the mount related data that is copied * from @p share. * * @param share The share object from where the mount related * data should be copied. */ void setMountData(Smb4KShare *share); /** * This convenience function resets the mount related data. */ void resetMountData(); /** * Returns TRUE if the share is or *was* a 'homes' share. That means that * this value is not changed when the share name is changed. * * @returns TRUE if this is or *was* a 'homes' share and FALSE otherwise. */ bool isHomesShare() const; /** * Set the port for the use in the UNC. * * @param port The port */ void setPort(int port); /** * Returns the port that is used in the UNC. * * @returns the port. */ int port() const; /** * Set the authentication information for the share. This function will add * the authentication information to the URL of the share. Any previous * user information including the login will be overwritten. * * @param authInfo The authentication information */ void setAuthInfo(Smb4KAuthInfo *authInfo); /** * Set the login for the share. This function will add the login name * to the URL of the share. * * @param login The login name */ void setLogin(const QString &login); /** * Returns the login. * * @returns the login. */ QString login() const; /** * Set the password used for authentication. * * @param passwd The password */ void setPassword(const QString &passwd); /** * Returns the password. * * @returns the password. */ QString password() const; /** * Updates the share item if the workgroup name and the UNC of @p share and * of this item is equal. Otherwise it does nothing. * @param share The share object that is used to update * this object */ void update(Smb4KShare *share); private: const QScopedPointer d; /** * Set up the shares icon. */ void setShareIcon(); }; #endif diff --git a/core/smb4kworkgroup.cpp b/core/smb4kworkgroup.cpp index f63537c..8a6ed6d 100644 --- a/core/smb4kworkgroup.cpp +++ b/core/smb4kworkgroup.cpp @@ -1,240 +1,178 @@ /*************************************************************************** Smb4K's container class for information about a workgroup. ------------------- begin : Sa Jan 26 2008 copyright : (C) 2008-2017 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 "smb4kworkgroup.h" #include "smb4kglobal.h" // Qt includes #include #include // KDE includes #include using namespace Smb4KGlobal; class Smb4KWorkgroupPrivate { public: QUrl masterURL; QHostAddress masterIP; }; Smb4KWorkgroup::Smb4KWorkgroup(const QString &name) : Smb4KBasicNetworkItem(Workgroup), d(new Smb4KWorkgroupPrivate) { // // Set the URL of the workgroup // pUrl->setScheme("smb"); pUrl->setHost(name); // // Set the icon // *pIcon = KDE::icon("network-workgroup"); } Smb4KWorkgroup::Smb4KWorkgroup(const Smb4KWorkgroup &w) : Smb4KBasicNetworkItem(Workgroup), d(new Smb4KWorkgroupPrivate) { // Copy the private variables // *d = *w.d; // // Set the icon if necessary // if (pIcon->isNull()) { *pIcon = KDE::icon("network-workgroup"); } else { // Do nothing } } Smb4KWorkgroup::Smb4KWorkgroup() : Smb4KBasicNetworkItem(Workgroup), d(new Smb4KWorkgroupPrivate) { // // Set the URL // pUrl->setScheme("smb"); // // Set the icon // *pIcon = KDE::icon("network-workgroup"); } Smb4KWorkgroup::~Smb4KWorkgroup() { } void Smb4KWorkgroup::setWorkgroupName(const QString &name) { pUrl->setHost(name); pUrl->setScheme("smb"); } QString Smb4KWorkgroup::workgroupName() const { return pUrl->host().toUpper(); } void Smb4KWorkgroup::setMasterBrowserName(const QString &name) { d->masterURL.setHost(name); d->masterURL.setScheme("smb"); } QString Smb4KWorkgroup::masterBrowserName() const { return d->masterURL.host().toUpper(); } void Smb4KWorkgroup::setMasterBrowserIpAddress(const QString &ip) { d->masterIP.setAddress(ip); } void Smb4KWorkgroup::setMasterBrowserIpAddress(const QHostAddress& address) { if (!address.isNull() && address.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol) { d->masterIP = address; } else { // Do nothing } } QString Smb4KWorkgroup::masterBrowserIpAddress() const { return d->masterIP.toString(); } bool Smb4KWorkgroup::hasMasterBrowserIpAddress() const { return !d->masterIP.isNull(); } -bool Smb4KWorkgroup::isEmpty() const -{ - // Ignore all booleans. - - if (!pUrl->host().isEmpty()) - { - return false; - } - - if (!d->masterURL.host().isEmpty()) - { - return false; - } - - if (!d->masterIP.isNull()) - { - return false; - } - - // Do not include the icon here. - - return true; -} - - -bool Smb4KWorkgroup::equals(Smb4KWorkgroup *workgroup) const -{ - Q_ASSERT(workgroup); - - if (QString::compare(workgroupName(), workgroup->workgroupName()) != 0) - { - return false; - } - else - { - // Do nothing - } - - if (QString::compare(masterBrowserName(), workgroup->masterBrowserName()) != 0) - { - return false; - } - else - { - // Do nothing - } - - if (QString::compare(masterBrowserIpAddress(), workgroup->masterBrowserIpAddress()) != 0) - { - return false; - } - else - { - // Do nothing - } - - // Do not include the icon here. - - return true; -} - - void Smb4KWorkgroup::update(Smb4KWorkgroup* workgroup) { if (QString::compare(workgroupName(), workgroup->workgroupName()) == 0) { setMasterBrowserName(workgroup->masterBrowserName()); setMasterBrowserIpAddress(workgroup->masterBrowserIpAddress()); } else { // Do nothing } } diff --git a/core/smb4kworkgroup.h b/core/smb4kworkgroup.h index 520fd1d..57be993 100644 --- a/core/smb4kworkgroup.h +++ b/core/smb4kworkgroup.h @@ -1,180 +1,155 @@ /*************************************************************************** Smb4K's container class for information about a workgroup. ------------------- begin : Sa Jan 26 2008 copyright : (C) 2008-2017 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 SMB4KWORKGROUP_H #define SMB4KWORKGROUP_H // application specific includes #include "smb4kbasicnetworkitem.h" // Qt includes #include #include #include // forward declarations class Smb4KWorkgroupPrivate; /** * This class is a container that carries information about a workgroup or * domain found in the network neighborhood. It is part of the core classes * of Smb4K. * * @author Alexander Reinholdt */ class Q_DECL_EXPORT Smb4KWorkgroup : public Smb4KBasicNetworkItem { friend class Smb4KWorkgroupPrivate; public: /** * The default constructor. It takes the name of the workgroup as only * argument. You have to set all other information by the other functions * provided by this class. * * @param name The name of the workgroup or domain. */ explicit Smb4KWorkgroup(const QString &name); /** * The copy constructor. This constructor takes another Smb4KWorkgroup item * as argument and copies its values. * * @param workgroup The Smb4KWorkgroup item that is to be copied. */ Smb4KWorkgroup(const Smb4KWorkgroup &workgroup); /** * The empty constructor. It does not take any argument and you have to * set all information by the other functions provided by this class. */ Smb4KWorkgroup(); /** * The destructor. */ ~Smb4KWorkgroup(); /** * Sets the name of the workgroup. * * @param name The name of the workgroup */ void setWorkgroupName(const QString &name); /** * This function returns the name of the workgroup. * * @returns the workgroup name. */ QString workgroupName() const; /** * Sets the name of the master browser of this workgroup or domain. * * @param masterName The name of the master browser */ void setMasterBrowserName(const QString &name); /** * Returns the name of the master browser of this workgroup or domain. * * @returns the name of the master browser. */ QString masterBrowserName() const; /** * Set the IP address of the master browser. @p ip will only be accepted * if it is compatible with either IPv4 or IPv6. * * @param ip The master browser's IP address */ void setMasterBrowserIpAddress(const QString &ip); /** * Set the IP address of the master browser. @p address will only be accepted * if it is compatible with either IPv4 or IPv6. * * @param address The master browser's IP address */ void setMasterBrowserIpAddress(const QHostAddress &address); /** * Returns the IP address of the master browser of this workgroup * or domain. If the IP address was not compatible with IPv4 and * IPv6 or if no IP address was supplied, an empty string is returned. * * @returns the IP address of the master browser or an empty string. */ QString masterBrowserIpAddress() const; /** * Returns TRUE if the workgroup/domain master browsers IP address is set and * FALSE otherwise. * * @returns TRUE if the master browsers IP address is known. */ bool hasMasterBrowserIpAddress() const; - /** - * Returns TRUE if the item is empty and FALSE otherwise. An item is not - * empty if at least one string (workgroup name, master name, etc.) has been - * set. A modified boolean will not be considered. - * - * @returns TRUE if the item is empty. - */ - bool isEmpty() const; - - /** - * Compare another Smb4KWorkgroup object with this one an return TRUE if both carry - * the same data. - * - * @param workgroup The Smb4KWorkgroup object that should be compared with this - * one. - * - * @returns TRUE if the data that was compared is the same. - */ - bool equals(Smb4KWorkgroup *workgroup) const; - - /** - * Operator to check if two items are equal. - */ - bool operator==(Smb4KWorkgroup workgroup) const { return equals(&workgroup); } - /** * Updates the workgroup item if the workgroup name of @p workgroup and * of this item is equal. Otherwise it does nothing. * @param workgroup The workgroup object that is used to update * this object */ void update(Smb4KWorkgroup *workgroup); private: const QScopedPointer d; }; #endif diff --git a/smb4k/smb4kconfigdialog.cpp b/smb4k/smb4kconfigdialog.cpp index 5b3ae9f..62ef713 100644 --- a/smb4k/smb4kconfigdialog.cpp +++ b/smb4k/smb4kconfigdialog.cpp @@ -1,942 +1,909 @@ /*************************************************************************** The configuration dialog of Smb4K ------------------- begin : Sa Apr 14 2007 copyright : (C) 2004-2018 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 "smb4kconfigdialog.h" #include "smb4kconfigpageauthentication.h" #include "smb4kconfigpagecustomoptions.h" #include "smb4kconfigpagemounting.h" #include "smb4kconfigpagenetwork.h" #include "smb4kconfigpageprofiles.h" #include "smb4kconfigpagesynchronization.h" #include "smb4kconfigpageuserinterface.h" #include "core/smb4ksettings.h" #include "core/smb4kglobal.h" #include "core/smb4kauthinfo.h" #include "core/smb4kwalletmanager.h" #include "core/smb4kcustomoptions.h" #include "core/smb4kcustomoptionsmanager.h" #include "core/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 #include #include #include #include #include #include // KDE includes #include #include #include #include #include #include using namespace Smb4KGlobal; K_PLUGIN_FACTORY(Smb4KConfigDialogFactory, registerPlugin();) Smb4KConfigDialog::Smb4KConfigDialog(QWidget *parent, const QList &/*args*/) : KConfigDialog(parent, "ConfigDialog", Smb4KSettings::self()) { setupDialog(); } Smb4KConfigDialog::~Smb4KConfigDialog() { } void Smb4KConfigDialog::setupDialog() { // FIXME: I guess, normally we would not need to close destructively, // but at the moment there are issues with the KURLRequester in file // mode. To work around those, we are closing the dialog destructively. // Maybe we can remove this if we moved to KDE4. setAttribute(Qt::WA_DeleteOnClose, true); // Add the pages: Smb4KConfigPageUserInterface *interface_options = new Smb4KConfigPageUserInterface(this); QScrollArea *interface_area = new QScrollArea(this); interface_area->setWidget(interface_options); interface_area->setWidgetResizable(true); interface_area->setFrameStyle(QFrame::NoFrame); Smb4KConfigPageNetwork *network_options = new Smb4KConfigPageNetwork(this); QScrollArea *network_area = new QScrollArea(this); network_area->setWidget(network_options); network_area->setWidgetResizable(true); network_area->setFrameStyle(QFrame::NoFrame); #if !defined(SMB4K_UNSUPPORTED_PLATFORM) Smb4KConfigPageMounting *mount_options = new Smb4KConfigPageMounting(this); QScrollArea *mount_area = new QScrollArea(this); mount_area->setWidget(mount_options); mount_area->setWidgetResizable(true); mount_area->setFrameStyle(QFrame::NoFrame); #endif Smb4KConfigPageAuthentication *auth_options = new Smb4KConfigPageAuthentication(this); QScrollArea *auth_area = new QScrollArea(this); auth_area->setWidget(auth_options); auth_area->setWidgetResizable(true); auth_area->setFrameStyle(QFrame::NoFrame); Smb4KConfigPageSynchronization *rsync_options = new Smb4KConfigPageSynchronization(this); QScrollArea *rsync_area = new QScrollArea(this); rsync_area->setWidget(rsync_options); rsync_area->setWidgetResizable(true); rsync_area->setFrameStyle(QFrame::NoFrame); rsync_options->setEnabled(!QStandardPaths::findExecutable("rsync").isEmpty()); Smb4KConfigPageCustomOptions *custom_options = new Smb4KConfigPageCustomOptions(this); QScrollArea *custom_area = new QScrollArea(this); custom_area->setWidget(custom_options); custom_area->setWidgetResizable(true); custom_area->setFrameStyle(QFrame::NoFrame); Smb4KConfigPageProfiles *profiles_page = new Smb4KConfigPageProfiles(this); QScrollArea *profiles_area = new QScrollArea(this); profiles_area->setWidget(profiles_page); profiles_area->setWidgetResizable(true); profiles_area->setFrameStyle(QFrame::NoFrame); // // Pages to the configuration dialog // m_user_interface = addPage(interface_area, Smb4KSettings::self(), i18n("User Interface"), "preferences-desktop"); m_network = addPage(network_area, Smb4KSettings::self(), i18n("Network Neighborhood"), "network-workgroup"); #if !defined(SMB4K_UNSUPPORTED_PLATFORM) m_mounting = addPage(mount_area, Smb4KMountSettings::self(), i18n("Mounting"), "system-run"); #endif m_authentication = addPage(auth_area, Smb4KSettings::self(), i18n("Authentication"), "dialog-password"); m_synchronization = addPage(rsync_area, Smb4KSettings::self(),i18n("Synchronization"), "folder-sync"); m_custom_options = addPage(custom_area, Smb4KSettings::self(), i18n("Custom Options"), "preferences-system-network"); m_profiles = addPage(profiles_area, Smb4KSettings::self(), i18n("Profiles"), "format-list-unordered"); // // Connections // connect(custom_options, SIGNAL(customSettingsModified()), this, SLOT(slotEnableApplyButton())); connect(auth_options, SIGNAL(loadWalletEntries()), this, SLOT(slotLoadAuthenticationInformation())); connect(auth_options, SIGNAL(saveWalletEntries()), this, SLOT(slotSaveAuthenticationInformation())); connect(auth_options, SIGNAL(setDefaultLogin()), this, SLOT(slotSetDefaultLogin())); connect(auth_options, SIGNAL(walletEntriesModified()), this, SLOT(slotEnableApplyButton())); connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotCheckPage(KPageWidgetItem*,KPageWidgetItem*))); // // Dialog size // create(); windowHandle()->resize(QSize(800, 600)); KConfigGroup group(Smb4KSettings::self()->config(), "ConfigDialog"); KWindowConfig::restoreWindowSize(windowHandle(), group); resize(windowHandle()->size()); // workaround for QTBUG-40584 } void Smb4KConfigDialog::loadCustomOptions() { if (m_custom_options) { QList options = Smb4KCustomOptionsManager::self()->customOptions(); m_custom_options->widget()->findChild()->insertCustomOptions(options); } else { // Do nothing } } void Smb4KConfigDialog::saveCustomOptions() { if (m_custom_options) { QList options = m_custom_options->widget()->findChild()->getCustomOptions(); Smb4KCustomOptionsManager::self()->replaceCustomOptions(options); } else { // Do nothing } } void Smb4KConfigDialog::propagateProfilesChanges() { Smb4KConfigPageProfiles *profiles_page = m_profiles->widget()->findChild(); if (profiles_page) { // Remove the profiles. QStringList removed_profiles = profiles_page->removedProfiles(); if (!removed_profiles.isEmpty()) { Smb4KProfileManager::self()->removeProfiles(removed_profiles, this); profiles_page->clearRemovedProfiles(); } else { // Do nothing } // Rename the profiles. QList< QPair > renamed_profiles = profiles_page->renamedProfiles(); if (!renamed_profiles.isEmpty()) { Smb4KProfileManager::self()->migrateProfiles(renamed_profiles); profiles_page->clearRenamedProfiles(); } else { // Do nothing } // Finally reload the custom options. if (!removed_profiles.isEmpty() || !renamed_profiles.isEmpty()) { loadCustomOptions(); } else { // Do nothing } } else { // Do nothing } } bool Smb4KConfigDialog::checkNetworkPage() { QRadioButton *query_custom_master = m_network->widget()->findChild("kcfg_QueryCustomMaster"); KLineEdit *custom_master_input = m_network->widget()->findChild("kcfg_CustomMasterBrowser"); QString msg = i18n("An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it."); if ((query_custom_master && query_custom_master->isChecked()) && (custom_master_input && custom_master_input->text().trimmed().isEmpty())) { KMessageBox::sorry(this, msg); setCurrentPage(m_network); custom_master_input->setFocus(); return false; } else { // Do nothing } QRadioButton *scan_bcast_areas = m_network->widget()->findChild("kcfg_ScanBroadcastAreas"); KLineEdit *bcast_areas_input = m_network->widget()->findChild("kcfg_BroadcastAreas"); if ((scan_bcast_areas && scan_bcast_areas->isChecked()) && (bcast_areas_input && bcast_areas_input->text().trimmed().isEmpty())) { KMessageBox::sorry(this, msg); setCurrentPage(m_network); bcast_areas_input->setFocus(); return false; } else { // Do nothing } return true; } bool Smb4KConfigDialog::checkMountingPage() { #if !defined(SMB4K_UNSUPPORTED_PLATFORM) KUrlRequester *mount_prefix = m_mounting->widget()->findChild("kcfg_MountPrefix"); QString msg = i18n("An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it."); if (mount_prefix && mount_prefix->url().path().trimmed().isEmpty()) { KMessageBox::sorry(this, msg); setCurrentPage(m_mounting); mount_prefix->setFocus(); return false; } else { // Do nothing } KLineEdit *file_mask = m_mounting->widget()->findChild("kcfg_FileMask"); msg = i18n("An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it."); if (file_mask && file_mask->text().trimmed().isEmpty()) { KMessageBox::sorry(this, msg); setCurrentPage(m_mounting); file_mask->setFocus(); return false; } else { // Do nothing } KLineEdit *directory_mask = m_mounting->widget()->findChild("kcfg_DirectoryMask"); if (directory_mask && directory_mask->text().trimmed().isEmpty()) { KMessageBox::sorry(this, msg); setCurrentPage(m_mounting); directory_mask->setFocus(); return false; } else { // Do nothing } #endif return true; } bool Smb4KConfigDialog::checkSynchronizationPage() { // // Get the config page // Since the config page is embedded into a scroll area, use findChild() here. // Smb4KConfigPageSynchronization *configPage = m_synchronization->widget()->findChild(); if (configPage) { // // The error message // QString errorMessage = i18n("An incorrect setting has been found. You are now taken to the corresponding configuration page to fix it."); // Find the tab number and the url requester for (int i = 0; i < configPage->count(); i++) { // Synchronization prefix KUrlRequester *syncPrefix = configPage->widget(i)->findChild("kcfg_RsyncPrefix"); if (syncPrefix && (!syncPrefix->url().isValid() || syncPrefix->url().path().trimmed().isEmpty())) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); syncPrefix->setFocus(); return false; } else { // Do nothing } // Backups QCheckBox *makeBackups = configPage->widget(i)->findChild("kcfg_MakeBackups"); QCheckBox *useBackupSuffix = configPage->widget(i)->findChild("kcfg_UseBackupSuffix"); KLineEdit *backupSuffix = configPage->widget(i)->findChild("kcfg_BackupSuffix"); QCheckBox *useBackupDir = configPage->widget(i)->findChild("kcfg_UseBackupDirectory"); KUrlRequester *backupDir = configPage->widget(i)->findChild("kcfg_BackupDirectory"); if (makeBackups && makeBackups->isChecked()) { if (useBackupSuffix && useBackupSuffix->isChecked()) { if (backupSuffix && backupSuffix->text().trimmed().isEmpty()) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); backupSuffix->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } if (useBackupDir && useBackupDir->isChecked()) { if (backupDir && (!backupDir->url().isValid() || backupDir->url().path().trimmed().isEmpty())) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); backupDir->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } } else { // Do nothing } // Minimal transfer size QCheckBox *useMinTransferSize = configPage->widget(i)->findChild("kcfg_UseMinimalTransferSize"); QSpinBox *minTransferSize = configPage->widget(i)->findChild("kcfg_MinimalTransferSize"); if (useMinTransferSize && useMinTransferSize->isChecked()) { if (minTransferSize && minTransferSize->value() == 0) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); minTransferSize->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Maximal transfer size QCheckBox *useMaxTransferSize = configPage->widget(i)->findChild("kcfg_UseMaximalTransferSize"); QSpinBox *maxTransferSize = configPage->widget(i)->findChild("kcfg_MaximalTransferSize"); if (useMaxTransferSize && useMaxTransferSize->isChecked()) { if (maxTransferSize && maxTransferSize->value() == 0) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); maxTransferSize->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Partial directory QCheckBox *usePartialDirectory = configPage->widget(i)->findChild("kcfg_UsePartialDirectory"); KUrlRequester *partialDirectory = configPage->widget(i)->findChild("kcfg_PartialDirectory"); if (usePartialDirectory && usePartialDirectory->isChecked()) { if (partialDirectory && (!partialDirectory->url().isValid() || partialDirectory->url().path().trimmed().isEmpty())) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); partialDirectory->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Exclude exclude QCheckBox *useExcludePattern = configPage->widget(i)->findChild("kcfg_UseExcludePattern"); KLineEdit *excludePattern = configPage->widget(i)->findChild("kcfg_ExcludePattern"); if (useExcludePattern && useExcludePattern->isChecked()) { if (excludePattern && excludePattern->text().trimmed().isEmpty()) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); excludePattern->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Read exclude pattern from file QCheckBox *useExcludeFrom = configPage->widget(i)->findChild("kcfg_UseExcludeFrom"); KUrlRequester *excludeFrom = configPage->widget(i)->findChild("kcfg_ExcludeFrom"); if (useExcludeFrom && useExcludeFrom->isChecked()) { if (excludeFrom && (!excludeFrom->url().isValid() || excludeFrom->url().path().trimmed().isEmpty())) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); excludeFrom->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Exclude exclude QCheckBox *useIncludePattern = configPage->widget(i)->findChild("kcfg_UseIncludePattern"); KLineEdit *includePattern = configPage->widget(i)->findChild("kcfg_IncludePattern"); if (useIncludePattern && useIncludePattern->isChecked()) { if (includePattern && includePattern->text().trimmed().isEmpty()) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); includePattern->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Read exclude pattern from file QCheckBox *useIncludeFrom = configPage->widget(i)->findChild("kcfg_UseIncludeFrom"); KUrlRequester *includeFrom = configPage->widget(i)->findChild("kcfg_IncludeFrom"); if (useIncludeFrom && useIncludeFrom->isChecked()) { if (includeFrom && (!includeFrom->url().isValid() || includeFrom->url().path().trimmed().isEmpty())) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); includeFrom->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // Block size QCheckBox *useFixedBlocksize = configPage->widget(i)->findChild("kcfg_UseBlockSize"); QSpinBox *fixedBlocksize = configPage->widget(i)->findChild("kcfg_BlockSize"); if (useFixedBlocksize && useFixedBlocksize->isChecked()) { if (fixedBlocksize && fixedBlocksize->value() == 0) { KMessageBox::sorry(this, errorMessage); setCurrentPage(m_synchronization); configPage->setCurrentIndex(i); fixedBlocksize->setFocus(); return false; } else { // Do nothing } } else { // Do nothing } // NOTE: The is no need to check the following settings, because they may be empty or 0: // - kcfg_UseCompressionLevel & kcfg_CompressionLevel // - kcfg_UseSkipCompression & kcfg_SkipCompression // - kcfg_UseBandwidthLimit & kcfg_BandwidthLimit // - kcfg_UseMaximumDelete & kcfg_MaximumDeleteValue // - kcfg_CustomFilteringRules // - kcfg_UseChecksumSeed & kcfg_ChecksumSeed } } else { // Do nothing } return true; } bool Smb4KConfigDialog::checkSettings() { // Check Network page if (!checkNetworkPage()) { return false; } else { // Do nothing } // Check Mounting page if (!checkMountingPage()) { return false; } else { // Do nothing } // Check Synchronization page if (!checkSynchronizationPage()) { return false; } else { // Do nothing } return true; } ///////////////////////////////////////////////////////////////////////////// // SLOT IMPLEMENTATIONS ///////////////////////////////////////////////////////////////////////////// void Smb4KConfigDialog::updateSettings() { saveCustomOptions(); slotSaveAuthenticationInformation(); propagateProfilesChanges(); (void)checkSettings(); KConfigGroup group(Smb4KSettings::self()->config(), "ConfigDialog"); KWindowConfig::saveWindowSize(windowHandle(), group); KConfigDialog::updateSettings(); } void Smb4KConfigDialog::updateWidgets() { loadCustomOptions(); KConfigDialog::updateWidgets(); } void Smb4KConfigDialog::reject() { Smb4KCustomOptionsManager::self()->resetCustomOptions(); QDialog::reject(); } void Smb4KConfigDialog::slotLoadAuthenticationInformation() { Smb4KConfigPageAuthentication *auth_options = m_authentication->widget()->findChild(); QList entries = Smb4KWalletManager::self()->walletEntries(); auth_options->insertWalletEntries(entries); auth_options->displayWalletEntries(); } void Smb4KConfigDialog::slotSaveAuthenticationInformation() { Smb4KConfigPageAuthentication *auth_options = m_authentication->widget()->findChild(); if (auth_options->walletEntriesDisplayed()) { QList entries = auth_options->getWalletEntries(); Smb4KWalletManager::self()->writeWalletEntries(entries); } else { // Do nothing } } void Smb4KConfigDialog::slotSetDefaultLogin() { Smb4KConfigPageAuthentication *auth_options = m_authentication->widget()->findChild(); if (!auth_options->undoRemoval()) { Smb4KAuthInfo authInfo; // We do not need to call useDefaultAuthInfo(), because // Smb4KWalletManager::readDefaultAuthInfo() will do this // for us. Smb4KWalletManager::self()->readDefaultAuthInfo(&authInfo); QPointer dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine); dlg->setPrompt(i18n("Enter the default login information.")); dlg->setUsername(authInfo.userName()); dlg->setPassword(authInfo.password()); if (dlg->exec() == KPasswordDialog::Accepted) { authInfo.setUserName(dlg->username()); authInfo.setPassword(dlg->password()); Smb4KWalletManager::self()->writeDefaultAuthInfo(&authInfo); if (auth_options->walletEntriesDisplayed()) { slotLoadAuthenticationInformation(); } else { // Do nothing } } else { // Reset the checkbox. auth_options->findChild("kcfg_UseDefaultLogin")->setChecked(false); } delete dlg; } else { // Do nothing } } void Smb4KConfigDialog::slotEnableApplyButton() { // // Check if we need to enable the Apply button // bool enable = false; // // Check the wallet entries // Smb4KConfigPageAuthentication *authenticationPage = m_authentication->widget()->findChild(); if (authenticationPage->walletEntriesMaybeChanged()) { QList oldWalletEntries = Smb4KWalletManager::self()->walletEntries(); QList newWalletEntries = authenticationPage->getWalletEntries(); for (Smb4KAuthInfo *oldEntry : oldWalletEntries) { for (Smb4KAuthInfo *newEntry : newWalletEntries) { if (oldEntry->url().matches(newEntry->url(), QUrl::RemovePort /* leave the user info here */) && oldEntry->workgroupName() == newEntry->workgroupName()) { enable = true; break; } else { // Do nothing } } if (enable) { break; } else { // Do nothing } } } else { // Do nothing } // // Check the custom options // Smb4KConfigPageCustomOptions *customOptionsPage = m_custom_options->widget()->findChild(); if (!enable && customOptionsPage && customOptionsPage->customSettingsMaybeChanged()) { - QList newOptionsList = customOptionsPage->getCustomOptions(); - QList oldOptionsList = Smb4KCustomOptionsManager::self()->customOptions(); - - if (newOptionsList.size() == oldOptionsList.size()) - { - for (const OptionsPtr &newOptions : newOptionsList) - { - for (const OptionsPtr &oldOptions : oldOptionsList) - { - if (!newOptions->equals(oldOptions.data())) - { - enable = true; - break; - } - else - { - // Do nothing - } - } - - if (enable) - { - break; - } - else - { - // Do nothing - } - } - } - else - { - enable = true; - } + enable = true; } else { // Do nothing } QPushButton *applyButton = buttonBox()->button(QDialogButtonBox::Apply); if (applyButton) { applyButton->setEnabled(enable); } else { // Do nothing } } void Smb4KConfigDialog::slotCheckPage(KPageWidgetItem* /*current*/, KPageWidgetItem* before) { if (before == m_user_interface) { // Nothing to do } else if (before == m_network) { (void)checkNetworkPage(); } #if !defined(SMB4K_UNSUPPORTED_PLATFORM) else if (before == m_mounting) { (void)checkMountingPage(); } #endif else if (before == m_authentication) { // Do nothing } else if (before == m_synchronization) { (void)checkSynchronizationPage(); } else if (before == m_custom_options) { // Do nothing } else if (before == m_profiles) { // Do nothing } else { // Do nothing } } #include "smb4kconfigdialog.moc"