diff --git a/plasmoid/plugin/smb4kdeclarative.cpp b/plasmoid/plugin/smb4kdeclarative.cpp index 48bc168..a5936fc 100644 --- a/plasmoid/plugin/smb4kdeclarative.cpp +++ b/plasmoid/plugin/smb4kdeclarative.cpp @@ -1,758 +1,792 @@ /*************************************************************************** This class provides the interface for Plasma and QtQuick ------------------- begin : Mo 02 Sep 2013 copyright : (C) 2013-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kdeclarative.h" #include "smb4kdeclarative_p.h" #include "smb4kbookmarkobject.h" #include "smb4knetworkobject.h" #include "smb4kprofileobject.h" #include "core/smb4kmounter.h" #include "core/smb4kglobal.h" #include "core/smb4kworkgroup.h" #include "core/smb4khost.h" #include "core/smb4kshare.h" #include "core/smb4kbasicnetworkitem.h" #include "core/smb4kbookmarkhandler.h" #include "core/smb4kbookmark.h" #include "core/smb4kcustomoptionsmanager.h" #include "core/smb4kprofilemanager.h" #include "core/smb4ksynchronizer.h" #include "core/smb4kclient.h" // Qt includes #include #include +// KDE includes +#include +#include +#include + Smb4KDeclarative::Smb4KDeclarative(QObject* parent) : QObject(parent), d(new Smb4KDeclarativePrivate) { // // Initialize the core // Smb4KGlobal::initCore(true, false); // // Connections // connect(Smb4KClient::self(), SIGNAL(workgroups()), this, SLOT(slotWorkgroupsListChanged())); connect(Smb4KClient::self(), SIGNAL(hosts(WorkgroupPtr)), this, SLOT(slotHostsListChanged())); connect(Smb4KClient::self(), SIGNAL(shares(HostPtr)), this, SLOT(slotSharesListChanged())); connect(Smb4KClient::self(), SIGNAL(aboutToStart(NetworkItemPtr,int)), this, SIGNAL(busy())); connect(Smb4KClient::self(), SIGNAL(finished(NetworkItemPtr,int)), this, SIGNAL(idle())); connect(Smb4KMounter::self(), SIGNAL(mountedSharesListChanged()), this, SLOT(slotMountedSharesListChanged())); connect(Smb4KMounter::self(), SIGNAL(aboutToStart(int)), this, SIGNAL(busy())); connect(Smb4KMounter::self(), SIGNAL(finished(int)), this, SIGNAL(idle())); connect(Smb4KBookmarkHandler::self(), SIGNAL(updated()), this, SLOT(slotBookmarksListChanged())); connect(Smb4KProfileManager::self(), SIGNAL(profilesListChanged(QStringList)), this, SLOT(slotProfilesListChanged(QStringList))); connect(Smb4KProfileManager::self(), SIGNAL(activeProfileChanged(QString)), this, SLOT(slotActiveProfileChanged(QString))); connect(Smb4KProfileManager::self(), SIGNAL(profileUsageChanged(bool)), this, SLOT(slotProfileUsageChanged(bool))); // // Do the initial loading of items // slotBookmarksListChanged(); slotProfilesListChanged(Smb4KProfileManager::self()->profilesList()); slotActiveProfileChanged(Smb4KProfileManager::self()->activeProfile()); slotProfileUsageChanged(Smb4KProfileManager::self()->useProfiles()); } Smb4KDeclarative::~Smb4KDeclarative() { while (!d->workgroupObjects.isEmpty()) { delete d->workgroupObjects.takeFirst(); } while (!d->hostObjects.isEmpty()) { delete d->hostObjects.takeFirst(); } while (!d->shareObjects.isEmpty()) { delete d->shareObjects.takeFirst(); } while (!d->mountedObjects.isEmpty()) { delete d->mountedObjects.takeFirst(); } while (!d->bookmarkObjects.isEmpty()) { delete d->bookmarkObjects.takeFirst(); } while (!d->bookmarkGroupObjects.isEmpty()) { delete d->bookmarkGroupObjects.takeFirst(); } while (!d->profileObjects.isEmpty()) { delete d->profileObjects.takeFirst(); } } QQmlListProperty Smb4KDeclarative::workgroups() { return QQmlListProperty(this, d->workgroupObjects); } QQmlListProperty Smb4KDeclarative::hosts() { return QQmlListProperty(this, d->hostObjects); } QQmlListProperty Smb4KDeclarative::shares() { return QQmlListProperty(this, d->shareObjects); } QQmlListProperty Smb4KDeclarative::mountedShares() { return QQmlListProperty(this, d->mountedObjects); } QQmlListProperty Smb4KDeclarative::bookmarks() { return QQmlListProperty(this, d->bookmarkObjects); } QQmlListProperty Smb4KDeclarative::bookmarkGroups() { return QQmlListProperty(this, d->bookmarkGroupObjects); } QQmlListProperty Smb4KDeclarative::profiles() { return QQmlListProperty(this, d->profileObjects); } void Smb4KDeclarative::lookup(Smb4KNetworkObject *object) { if (object) { switch (object->type()) { case Smb4KNetworkObject::Network: { Smb4KClient::self()->lookupDomains(); break; } case Smb4KNetworkObject::Workgroup: { // Check if the workgroup is known. WorkgroupPtr workgroup = Smb4KGlobal::findWorkgroup(object->url().host().toUpper()); if (workgroup) { Smb4KClient::self()->lookupDomainMembers(workgroup); } break; } case Smb4KNetworkObject::Host: { // Check if the host is known. HostPtr host = Smb4KGlobal::findHost(object->url().host().toUpper()); if (host) { Smb4KClient::self()->lookupShares(host); } break; } case Smb4KNetworkObject::Share: { break; } default: { // Shares are ignored break; } } } else { // If the object is 0, scan the whole network. Smb4KClient::self()->lookupDomains(); } } Smb4KNetworkObject *Smb4KDeclarative::findNetworkItem(const QUrl &url, int type) { Smb4KNetworkObject *object = 0; if (url.isValid()) { switch (type) { case Smb4KNetworkObject::Workgroup: { for (Smb4KNetworkObject *obj : d->workgroupObjects) { if (url == obj->url()) { object = obj; break; } else { continue; } } break; } case Smb4KNetworkObject::Host: { for (Smb4KNetworkObject *obj : d->hostObjects) { if (url == obj->url()) { object = obj; break; } else { continue; } } break; } case Smb4KNetworkObject::Share: { for (Smb4KNetworkObject *obj : d->shareObjects) { if (url == obj->url()) { object = obj; break; } else { continue; } } break; } default: { break; } } } return object; } void Smb4KDeclarative::openMountDialog() { Smb4KMounter::self()->openMountDialog(); } void Smb4KDeclarative::mount(Smb4KNetworkObject *object) { if (object && object->type() == Smb4KNetworkObject::Share) { QString shareName = object->url().path(); if (shareName.startsWith('/')) { shareName = shareName.mid(1, -1); } SharePtr share = Smb4KGlobal::findShare(object->url(), object->workgroupName()); if (share) { Smb4KMounter::self()->mountShare(share); } else { // If the share is not in the global list of shares, // try the list of bookmarks. BookmarkPtr bookmark = Smb4KBookmarkHandler::self()->findBookmarkByUrl(object->url()); share = SharePtr(new Smb4KShare()); share->setUrl(object->url()); share->setWorkgroupName(bookmark->workgroupName()); share->setHostIpAddress(bookmark->hostIpAddress()); Smb4KMounter::self()->mountShare(share); while (Smb4KMounter::self()->isRunning()) { QTest::qWait(50); } share.clear(); } } } void Smb4KDeclarative::unmount(Smb4KNetworkObject *object) { if (object && object->type()) { if (object->mountpoint().isValid()) { SharePtr share = Smb4KGlobal::findShareByPath(object->mountpoint().path()); if (share) { Smb4KMounter::self()->unmountShare(share); } } } } void Smb4KDeclarative::unmountAll() { Smb4KMounter::self()->unmountAllShares(false); } Smb4KNetworkObject* Smb4KDeclarative::findMountedShare(const QUrl& url, bool exactMatch) { Smb4KNetworkObject *object = 0; if (url.isValid()) { for (Smb4KNetworkObject *obj : d->mountedObjects) { if (url.matches(obj->url(), QUrl::None)) { object = obj; break; } else if (!exactMatch && url.matches(obj->url(), QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash)) { object = obj; continue; } else { continue; } } } return object; } void Smb4KDeclarative::print(Smb4KNetworkObject* object) { if (object && object->type() == Smb4KNetworkObject::Share) { SharePtr printer = Smb4KGlobal::findShare(object->url(), object->workgroupName()); if (printer) { Smb4KClient::self()->openPrintDialog(printer); } } } void Smb4KDeclarative::addBookmark(Smb4KNetworkObject* object) { if (object) { QList shares; // First, search the list of shares gathered by the scanner. for (const SharePtr &share : Smb4KGlobal::sharesList()) { if (share->url() == object->url()) { shares << share; break; } else { continue; } } // Second, if the list is still empty, try the list of mounted shares. if (shares.isEmpty()) { for (const SharePtr &mountedShare : Smb4KGlobal::mountedSharesList()) { if (mountedShare->url() == object->url()) { shares << mountedShare; break; } else { continue; } } } // Now add the share. if (!shares.isEmpty()) { for (const SharePtr &p : shares) { qDebug() << p->url(); } Smb4KBookmarkHandler::self()->addBookmarks(shares); } } } void Smb4KDeclarative::removeBookmark(Smb4KBookmarkObject* object) { if (object) { // // Find the bookmark in the list and remove it. // BookmarkPtr bookmark = Smb4KBookmarkHandler::self()->findBookmarkByUrl(object->url()); if (bookmark) { Smb4KBookmarkHandler::self()->removeBookmark(bookmark); } } } void Smb4KDeclarative::editBookmarks() { Smb4KBookmarkHandler::self()->editBookmarks(); } void Smb4KDeclarative::synchronize(Smb4KNetworkObject* object) { if (object && object->type() == Smb4KNetworkObject::Share) { for (const SharePtr &share : Smb4KGlobal::mountedSharesList()) { if (share->url() == object->url()) { Smb4KSynchronizer::self()->synchronize(share); } } } } void Smb4KDeclarative::openCustomOptionsDialog(Smb4KNetworkObject *object) { if (object) { switch (object->type()) { case Smb4KNetworkObject::Host: { for (const HostPtr &host : Smb4KGlobal::hostsList()) { if (host->url() == object->url()) { Smb4KCustomOptionsManager::self()->openCustomOptionsDialog(host); break; } else { continue; } } break; } case Smb4KNetworkObject::Share: { for (const SharePtr &share : Smb4KGlobal::sharesList()) { if (share->url() == object->url()) { Smb4KCustomOptionsManager::self()->openCustomOptionsDialog(share); break; } else { continue; } } break; } default: { break; } } } } void Smb4KDeclarative::startClient() { Smb4KClient::self()->start(); } void Smb4KDeclarative::abortClient() { Smb4KClient::self()->abort(); } void Smb4KDeclarative::startMounter() { Smb4KMounter::self()->start(); } void Smb4KDeclarative::abortMounter() { Smb4KMounter::self()->abort(); } QString Smb4KDeclarative::activeProfile() const { QString activeProfile; for (Smb4KProfileObject *profile : d->profileObjects) { if (profile->isActiveProfile()) { activeProfile = profile->profileName(); break; } else { continue; } } return activeProfile; } void Smb4KDeclarative::setActiveProfile(const QString& profile) { Smb4KProfileManager::self()->setActiveProfile(profile); } bool Smb4KDeclarative::profileUsage() const { return Smb4KProfileManager::self()->useProfiles(); } void Smb4KDeclarative::preview(Smb4KNetworkObject* object) { if (object->type() == Smb4KNetworkObject::Share) { SharePtr share = Smb4KGlobal::findShare(object->url(), object->workgroupName()); if (share) { Smb4KClient::self()->openPreviewDialog(share); } } } +void Smb4KDeclarative::openConfigurationDialog() +{ + // + // Check if the configuration dialog exists and try to show it. + // + if (KConfigDialog::exists("Smb4KConfigDialog")) + { + KConfigDialog::showDialog("Smb4KConfigDialog"); + return; + } + + // + // If the dialog does not exist, load and show it: + // + KPluginLoader loader("smb4kconfigdialog", this); + KPluginFactory *configFactory = loader.factory(); + + if (configFactory) + { + KConfigDialog *dlg = configFactory->create(); + + if (dlg) + { + dlg->setObjectName("Smb4KConfigDialog"); + dlg->show(); + } + } +} + void Smb4KDeclarative::slotWorkgroupsListChanged() { // (Re)fill the list of workgroup objects. while (!d->workgroupObjects.isEmpty()) { delete d->workgroupObjects.takeFirst(); } for (const WorkgroupPtr &workgroup : Smb4KGlobal::workgroupsList()) { d->workgroupObjects << new Smb4KNetworkObject(workgroup.data()); } emit workgroupsListChanged(); } void Smb4KDeclarative::slotHostsListChanged() { // (Re)fill the list of host object. while (!d->hostObjects.isEmpty()) { delete d->hostObjects.takeFirst(); } for (const HostPtr &host : Smb4KGlobal::hostsList()) { d->hostObjects << new Smb4KNetworkObject(host.data()); } emit hostsListChanged(); } void Smb4KDeclarative::slotSharesListChanged() { // (Re)fill the list of share objects. while (!d->shareObjects.isEmpty()) { delete d->shareObjects.takeFirst(); } for (const SharePtr &share : Smb4KGlobal::sharesList()) { d->shareObjects << new Smb4KNetworkObject(share.data()); } emit sharesListChanged(); } void Smb4KDeclarative::slotMountedSharesListChanged() { // (Re)fill the list of share objects. while (!d->mountedObjects.isEmpty()) { delete d->mountedObjects.takeFirst(); } for (const SharePtr &mountedShare : Smb4KGlobal::mountedSharesList()) { d->mountedObjects << new Smb4KNetworkObject(mountedShare.data()); } emit mountedSharesListChanged(); } void Smb4KDeclarative::slotBookmarksListChanged() { // (Re)fill the list of bookmark and group objects. while (!d->bookmarkObjects.isEmpty()) { delete d->bookmarkObjects.takeFirst(); } while (!d->bookmarkGroupObjects.isEmpty()) { delete d->bookmarkGroupObjects.takeFirst(); } for (const BookmarkPtr &bookmark : Smb4KBookmarkHandler::self()->bookmarksList()) { d->bookmarkObjects << new Smb4KBookmarkObject(bookmark.data()); } for (const QString &group : Smb4KBookmarkHandler::self()->groupsList()) { d->bookmarkGroupObjects << new Smb4KBookmarkObject(group); } emit bookmarksListChanged(); } void Smb4KDeclarative::slotProfilesListChanged(const QStringList& profiles) { while (!d->profileObjects.isEmpty()) { delete d->profileObjects.takeFirst(); } for (const QString &p : profiles) { Smb4KProfileObject *profile = new Smb4KProfileObject(); profile->setProfileName(p); if (QString::compare(p, Smb4KProfileManager::self()->activeProfile()) == 0) { profile->setActiveProfile(true); } else { profile->setActiveProfile(false); } d->profileObjects << profile; } emit profilesListChanged(); } void Smb4KDeclarative::slotActiveProfileChanged(const QString& activeProfile) { for (Smb4KProfileObject *profile : d->profileObjects) { if (QString::compare(profile->profileName(), activeProfile) == 0) { profile->setActiveProfile(true); } else { profile->setActiveProfile(false); } } emit activeProfileChanged(); } void Smb4KDeclarative::slotProfileUsageChanged(bool /*use*/) { emit profileUsageChanged(); } diff --git a/plasmoid/plugin/smb4kdeclarative.h b/plasmoid/plugin/smb4kdeclarative.h index 1a73de7..476bb13 100644 --- a/plasmoid/plugin/smb4kdeclarative.h +++ b/plasmoid/plugin/smb4kdeclarative.h @@ -1,420 +1,425 @@ /*************************************************************************** This class provides the interface for Plasma and QtQuick ------------------- begin : Mo 02 Sep 2013 copyright : (C) 2013-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KDECLARATIVE_H #define SMB4KDECLARATIVE_H // Qt includes #include #include #include #include // forward declarations class Smb4KDeclarativePrivate; class Smb4KNetworkObject; class Smb4KBookmarkObject; class Smb4KProfileObject; /** * This class provides the interface for programs written in QML to the core * classes of Smb4K. * * @author Alexander Reinholdt * @since 1.1.0 */ class Q_DECL_EXPORT Smb4KDeclarative : public QObject { Q_OBJECT Q_PROPERTY(QQmlListProperty workgroups READ workgroups NOTIFY workgroupsListChanged) Q_PROPERTY(QQmlListProperty hosts READ hosts NOTIFY hostsListChanged) Q_PROPERTY(QQmlListProperty shares READ shares NOTIFY sharesListChanged) Q_PROPERTY(QQmlListProperty mountedShares READ mountedShares NOTIFY mountedSharesListChanged) Q_PROPERTY(QQmlListProperty bookmarks READ bookmarks NOTIFY bookmarksListChanged) Q_PROPERTY(QQmlListProperty bookmarkGroups READ bookmarkGroups NOTIFY bookmarksListChanged) Q_PROPERTY(QQmlListProperty profiles READ profiles NOTIFY profilesListChanged) Q_PROPERTY(QString activeProfile READ activeProfile WRITE setActiveProfile NOTIFY activeProfileChanged) Q_PROPERTY(bool profileUsage READ profileUsage NOTIFY profileUsageChanged); friend class Smb4KDeclarativePrivate; public: /** * Constructor */ explicit Smb4KDeclarative(QObject *parent = 0); /** * Destructor */ virtual ~Smb4KDeclarative(); /** * This function returns the list of workgroups. Basically, this is the * Smb4KGlobal::workgroupsList() list converted into a list of Smb4KNetworkItem * objects. * * @returns the list of discovered workgroups. */ QQmlListProperty workgroups(); /** * This function returns the list of hosts. Basically, this is the * Smb4KGlobal::hostsList() list converted into a list of Smb4KNetworkItem * objects. * * @returns the list of discovered hosts. */ QQmlListProperty hosts(); /** * This function returns the list of shares. Basically, this is the * Smb4KGlobal::sharesList() list converted into a list of Smb4KNetworkItem * objects. * * @returns the list of discovered shares. */ QQmlListProperty shares(); /** * This function returns the list of mounted shares. Basically, this is the * Smb4KGlobal::mountedSharesList() list converted into a list of Smb4KNetworkItem * objects. * * @returns the list of the mounted shares. */ QQmlListProperty mountedShares(); /** * This function returns the list of bookmarks. Basically, this is the * the list returned by Smb4KBookmarkHandler::bookmarksList() function * converted into a list of Smb4KBookmarkObject objects. * * @returns the list of bookmarks */ QQmlListProperty bookmarks(); /** * This function returns the list of bookmark groups. Basically, this is the * the list returned by the Smb4KBookmarkHandler::groupsList() function * converted into a list of Smb4KBookmarkObject objects. * * @returns the list of bookmarks */ QQmlListProperty bookmarkGroups(); /** * This function returns the list of profiles. Basically, this is the list * returned by the Smb4KProfileManager::profilesList() converted into a list * of Smb4KProfileObject objects. * * @returns the list of profiles */ QQmlListProperty profiles(); /** * This function takes a Smb4KNetworkObject object and initiates a network * scan. If you pass a NULL pointer, a network scan will be performed. * * Please note that this function only works with network objects that are * already known. All others will be ignored. * * @param object The network object */ Q_INVOKABLE void lookup(Smb4KNetworkObject *object = 0); /** * This function takes a QUrl object, looks up the respective network object * and returns it. If there is not such an object, NULL is returned. * * Please note that this function only works with network objects that are * already known. All others will be ignored. * * @param url The URL of the network item * * @param type The type of the network item * * @returns The network item or NULL if it was not found. */ Q_INVOKABLE Smb4KNetworkObject *findNetworkItem(const QUrl &url, int type); /** * Open the mount dialog to mount a share. */ Q_INVOKABLE void openMountDialog(); /** * This function takes a network object and initiates the mounting of * the remote share. * * Please note that this function only works with network objects that * represent a share and that are already known, i.e. it must either be * a share that was already looked up during program run or one that was * bookmarked. * * @param object The network object */ Q_INVOKABLE void mount(Smb4KNetworkObject *object); /** * This function takes a network object and initiates the unmounting of * the mounted share. * * Please note that this function only works with network objects that * represent a share and that are already known. * * @param object The network object */ Q_INVOKABLE void unmount(Smb4KNetworkObject *object); /** * This function is a convenience function. It unmounts all currently mounted * shares by invoking @see unmountAllShares(0). */ Q_INVOKABLE void unmountAll(); /** * This function takes a QUrl object, looks up the respective mounted share * and returns it. If there is not such a share, NULL is returned. * * @param url The URL of the mounted share * * @param exactMatch Determines if the function should only search for the * exact match or if it may also except matches where the * user info and port may differ. * * @returns The mounted share or NULL if it was not found. */ Q_INVOKABLE Smb4KNetworkObject *findMountedShare(const QUrl &url, bool exactMatch = true); /** * This function takes a network object representing a remote printer and * initiates the printing of a file. * * Please note that this function only works with share objects that are * already known. All others will be ignored. * * @param object The network object representing a remote printer */ Q_INVOKABLE void print(Smb4KNetworkObject *object); /** * This function adds a new bookmark. * * @param object The network object that is to be bookmarked */ Q_INVOKABLE void addBookmark(Smb4KNetworkObject *object); /** * This function removes a bookmark. * * @param url The bookmark object that is to be removed */ Q_INVOKABLE void removeBookmark(Smb4KBookmarkObject *object); /** * This function opens the bookmark editor. */ Q_INVOKABLE void editBookmarks(); /** * This function starts the synchronization of a local and a * remote folder. */ Q_INVOKABLE void synchronize(Smb4KNetworkObject *object); /** * This function opens the custom options dialog. * * @param object The network object */ Q_INVOKABLE void openCustomOptionsDialog(Smb4KNetworkObject *object); /** * This function starts the client */ Q_INVOKABLE void startClient(); /** - * This function aborts the client + * This function stops the client */ Q_INVOKABLE void abortClient(); /** * This function starts the mounter. */ Q_INVOKABLE void startMounter(); /** - * This function aborts any action of the mounter. + * This function stops any action of the mounter. */ Q_INVOKABLE void abortMounter(); /** * Return the currently active profile or an empty string if * the use of profiles is disabled. * * @returns the active profile. */ QString activeProfile() const; /** * Set the active profile. * @param profile The name of the active profile */ void setActiveProfile(const QString &profile); /** * Return the current setting of the profile usage. * * @returns the profile usage. */ bool profileUsage() const; /** * Open the preview dialog with the contents of the passed network * item. * @param object The network object */ Q_INVOKABLE void preview(Smb4KNetworkObject *object); + + /** + * Open the configuration dialog of the main application + */ + Q_INVOKABLE void openConfigurationDialog(); Q_SIGNALS: /** * This signal is emitted when the list of workgroups changed. */ void workgroupsListChanged(); /** * This signal is emitted when the list of hosts changed. */ void hostsListChanged(); /** * This signal is emitted when the list of shares changed. */ void sharesListChanged(); /** * This signal is emitted when the list of mounted shares changed. */ void mountedSharesListChanged(); /** * This signal is emitted when the list of bookmarks changed. */ void bookmarksListChanged(); /** * This signal is emitted when the list of profiles changed. */ void profilesListChanged(); /** * This signal is emitted when the active profile changed. */ void activeProfileChanged(); /** * This signal is emitted when the profile usage changed. */ void profileUsageChanged(); /** * This signal is emitted, when one of the core classes becomes * busy. */ void busy(); /** * This signal is emitted, when one of the core signals becomes * idle. */ void idle(); protected Q_SLOTS: /** * This slot is invoked, when the list of workgroups was changed by * the scanner. It rebuilds the workgroups() list and emits the * worgroupsListChanged() signal. */ void slotWorkgroupsListChanged(); /** * This slot is invoked, when the list of hosts was changed by the * scanner. It rebuilds the hosts() list and emits the hostsListChanged() * signal. */ void slotHostsListChanged(); /** * This slot is invoked, when the list of shares was changed by the * scanner. It rebuilds the shares() list and emits the sharesListChanged() * signal. */ void slotSharesListChanged(); /** * This slot is invoked, when the list of mounted shares was changed * by the mounter. It rebuilds the mountedShares() list and emits the * mountedSharesListChanged() signal. */ void slotMountedSharesListChanged(); /** * This slot is invoked when the list of bookmarks was changed. It * rebuilds the bookmarks and bookmark groups lists and emits the * bookmarksListChanged() signal. */ void slotBookmarksListChanged(); /** * This slot is invoked when the list of profiles changed. It rebuils * the list of profiles and emits the profilesListChanged() signal. */ void slotProfilesListChanged(const QStringList &profiles); /** * This slot is invoked when the active profile changed. It resets * the value for the active profile and emits the activeProfileChanged() * signal. */ void slotActiveProfileChanged(const QString &activeProfile); /** * This slot is invoked when the profile usage changed. It resets * the value for the profile usage and emits the profileUsageChanged() * signal. */ void slotProfileUsageChanged(bool use); private: const QScopedPointer d; }; #endif diff --git a/plasmoid/plugin/smb4knetworkobject.cpp b/plasmoid/plugin/smb4knetworkobject.cpp index 34b945a..ccba476 100644 --- a/plasmoid/plugin/smb4knetworkobject.cpp +++ b/plasmoid/plugin/smb4knetworkobject.cpp @@ -1,434 +1,434 @@ /*************************************************************************** This class derives from QObject and encapsulates the network items. It is for use with QtQuick. ------------------- begin : Fr Mär 02 2012 copyright : (C) 2012-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 "smb4knetworkobject.h" #include "core/smb4kglobal.h" // Qt includes #include using namespace Smb4KGlobal; class Smb4KNetworkObjectPrivate { public: QString workgroup; QUrl url; int type; int parentType; QString comment; bool mounted; QUrl mountpoint; bool printer; bool isMaster; bool inaccessible; }; Smb4KNetworkObject::Smb4KNetworkObject(Smb4KWorkgroup *workgroup, QObject *parent) : QObject(parent), d(new Smb4KNetworkObjectPrivate) { d->workgroup = workgroup->workgroupName(); d->url = workgroup->url(); d->mounted = false; d->inaccessible = false; d->printer = false; d->isMaster = false; setType(Workgroup); } Smb4KNetworkObject::Smb4KNetworkObject(Smb4KHost *host, QObject *parent) : QObject(parent), d(new Smb4KNetworkObjectPrivate) { d->workgroup = host->workgroupName(); d->url = host->url(); d->comment = host->comment(); d->mounted = false; d->inaccessible = false; d->printer = false; d->isMaster = host->isMasterBrowser(); setType(Host); } Smb4KNetworkObject::Smb4KNetworkObject(Smb4KShare *share, QObject *parent) : QObject(parent), d(new Smb4KNetworkObjectPrivate) { d->workgroup = share->workgroupName(); d->url = share->url(); d->comment = share->comment(); d->mounted = share->isMounted(); d->inaccessible = share->isInaccessible(); d->printer = share->isPrinter(); d->isMaster = false; d->mountpoint = QUrl::fromLocalFile(share->path()); setType(Share); } Smb4KNetworkObject::Smb4KNetworkObject(QObject *parent) : QObject(parent), d(new Smb4KNetworkObjectPrivate) { d->url.setUrl("smb://", QUrl::TolerantMode); d->mounted = false; d->inaccessible = false; d->printer = false; d->isMaster = false; setType(Network); } Smb4KNetworkObject::~Smb4KNetworkObject() { } Smb4KNetworkObject::NetworkItem Smb4KNetworkObject::type() const { return static_cast(d->type); } Smb4KNetworkObject::NetworkItem Smb4KNetworkObject::parentType() const { return static_cast(d->parentType); } void Smb4KNetworkObject::setType(NetworkItem type) { d->type = type; switch (type) { case Host: { d->parentType = Workgroup; break; } case Share: { d->parentType = Host; break; } default: { d->parentType = Network; break; } } emit changed(); } QString Smb4KNetworkObject::workgroupName() const { return d->workgroup; } void Smb4KNetworkObject::setWorkgroupName(const QString& name) { d->workgroup = name; emit changed(); } QString Smb4KNetworkObject::hostName() const { return d->url.host().toUpper(); } void Smb4KNetworkObject::setHostName(const QString& name) { d->url.setHost(name); emit changed(); } bool Smb4KNetworkObject::isMasterBrowser() const { return d->isMaster; } void Smb4KNetworkObject::setMasterBrowser(bool master) { if (type() == Host) { d->isMaster = master; emit changed(); } } QString Smb4KNetworkObject::shareName() const { // Since users might come up with very weird share names, // we are careful and do not use QString::remove("/"), but // only remove preceding and trailing slashes. QString share_name = d->url.path(); if (share_name.startsWith('/')) { share_name = share_name.remove(0, 1); } if (share_name.endsWith('/')) { share_name = share_name.remove(share_name.size() - 1, 1); } return share_name; } void Smb4KNetworkObject::setShareName(const QString& name) { d->url.setPath(name); emit changed(); } QString Smb4KNetworkObject::name() const { QString name; switch (d->type) { case Workgroup: { name = workgroupName(); break; } case Host: { name = hostName(); break; } case Share: { name = shareName(); break; } default: { break; } } return name; } QString Smb4KNetworkObject::comment() const { return d->comment; } void Smb4KNetworkObject::setComment(const QString& comment) { d->comment = comment; emit changed(); } QUrl Smb4KNetworkObject::url() const { return d->url; } -QUrl Smb4KNetworkObject::parentURL() const +QUrl Smb4KNetworkObject::parentUrl() const { // Do not use QUrl::upUrl() here, because it produces // an URL like this: smb://HOST/Share/../ and we do not // want that. QUrl parent_url; parent_url.setUrl("smb://"); switch (d->type) { case Host: { parent_url.setHost(d->workgroup); break; } case Share: { parent_url.setHost(d->url.host()); break; } default: { break; } } return parent_url; } -void Smb4KNetworkObject::setURL(const QUrl& url) +void Smb4KNetworkObject::setUrl(const QUrl& url) { d->url = url; emit changed(); } bool Smb4KNetworkObject::isMounted() const { return d->mounted; } void Smb4KNetworkObject::setMounted(bool mounted) { d->mounted = mounted; emit changed(); } void Smb4KNetworkObject::update(Smb4KBasicNetworkItem *networkItem) { if (d->type == Workgroup && networkItem->type() == Smb4KGlobal::Workgroup) { Smb4KWorkgroup *workgroup = static_cast(networkItem); if (workgroup) { // Check that we update with the correct item. if (QString::compare(workgroupName(), workgroup->workgroupName(), Qt::CaseInsensitive) == 0) { d->workgroup = workgroup->workgroupName(); d->url = workgroup->url(); d->type = Workgroup; d->mounted = false; d->inaccessible = false; d->printer = false; } } } else if (d->type == Host && networkItem->type() == Smb4KGlobal::Host) { Smb4KHost *host = static_cast(networkItem); if (host) { // Check that we update with the correct item. if (QString::compare(workgroupName(), host->workgroupName(), Qt::CaseInsensitive) == 0 && QString::compare(hostName(), host->hostName(), Qt::CaseInsensitive) == 0) { d->workgroup = host->workgroupName(); d->url = host->url(); d->comment = host->comment(); d->type = Host; d->mounted = false; d->inaccessible = false; d->printer = false; } } } else if (d->type == Share && networkItem->type() == Smb4KGlobal::Share) { Smb4KShare *share = static_cast(networkItem); if (share) { // Check that we update with the correct item. if (QString::compare(workgroupName(), share->workgroupName(), Qt::CaseInsensitive) == 0 && QString::compare(hostName(), share->hostName(), Qt::CaseInsensitive) == 0 && QString::compare(shareName(), share->shareName(), Qt::CaseInsensitive) == 0) { d->workgroup = share->workgroupName(); d->url = share->url(); d->comment = share->comment(); d->type = Share; d->mounted = share->isMounted(); d->inaccessible = share->isInaccessible(); d->printer = share->isPrinter(); d->mountpoint.setUrl(share->path(), QUrl::TolerantMode); d->mountpoint.setScheme("file"); } } } else { d->type = Network; } emit changed(); } bool Smb4KNetworkObject::isPrinter() const { return d->printer; } void Smb4KNetworkObject::setPrinter(bool printer) { d->printer = printer; emit changed(); } QUrl Smb4KNetworkObject::mountpoint() const { return d->mountpoint; } void Smb4KNetworkObject::setMountpoint(const QUrl &mountpoint) { d->mountpoint = mountpoint; emit changed(); } bool Smb4KNetworkObject::isInaccessible() const { return (d->mounted && d->inaccessible); } void Smb4KNetworkObject::setInaccessible(bool inaccessible) { d->inaccessible = inaccessible; } diff --git a/plasmoid/plugin/smb4knetworkobject.h b/plasmoid/plugin/smb4knetworkobject.h index 19019a2..35614bd 100644 --- a/plasmoid/plugin/smb4knetworkobject.h +++ b/plasmoid/plugin/smb4knetworkobject.h @@ -1,325 +1,325 @@ /*************************************************************************** This class derives from QObject and encapsulates the network items. It is for use with QtQuick. ------------------- begin : Fr Mär 02 2012 copyright : (C) 2012-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 SMB4KNETWORKOBJECT_H #define SMB4KNETWORKOBJECT_H // application specific includes #include "core/smb4kworkgroup.h" #include "core/smb4khost.h" #include "core/smb4kshare.h" #include "core/smb4kglobal.h" // Qt includes #include #include #include #include #include // forward declaration class Smb4KNetworkObjectPrivate; /** * This class derives from QObject and makes the main functions of the * network items Smb4KWorkgroup, Smb4KHost, and Smb4KShare available. Its * main purpose is to be used with QtQuick and Plasma. * * @author Alexander Reinholdt * @since 1.1.0 */ class Q_DECL_EXPORT Smb4KNetworkObject : public QObject { Q_OBJECT Q_PROPERTY(NetworkItem type READ type WRITE setType NOTIFY changed) Q_PROPERTY(NetworkItem parentType READ parentType CONSTANT) Q_PROPERTY(QString workgroupName READ workgroupName WRITE setWorkgroupName NOTIFY changed) Q_PROPERTY(QString hostName READ hostName WRITE setHostName NOTIFY changed) Q_PROPERTY(QString shareName READ shareName WRITE setShareName NOTIFY changed) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY changed) - Q_PROPERTY(QUrl url READ url WRITE setURL NOTIFY changed) - Q_PROPERTY(QUrl parentURL READ parentURL CONSTANT) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY changed) + Q_PROPERTY(QUrl parentUrl READ parentUrl CONSTANT) Q_PROPERTY(bool isMounted READ isMounted WRITE setMounted NOTIFY changed) Q_PROPERTY(bool isPrinter READ isPrinter WRITE setPrinter NOTIFY changed) Q_PROPERTY(QUrl mountpoint READ mountpoint WRITE setMountpoint NOTIFY changed) Q_PROPERTY(bool isMasterBrowser READ isMasterBrowser WRITE setMasterBrowser NOTIFY changed) Q_PROPERTY(bool isInaccessible READ isInaccessible WRITE setInaccessible NOTIFY changed) friend class Smb4KNetworkObjectPrivate; public: /** * NetworkItem enumeration. Used to make the property system happy. * Assigns the values of Smb4KGlobal::NetworkItem to its representatives. */ enum NetworkItem { Network = Smb4KGlobal::Network, Workgroup = Smb4KGlobal::Workgroup, Host = Smb4KGlobal::Host, Share = Smb4KGlobal::Share, Unknown = Smb4KGlobal::UnknownNetworkItem }; Q_ENUM(NetworkItem) /** * Constructor for a workgroup. */ explicit Smb4KNetworkObject(Smb4KWorkgroup *workgroup, QObject *parent = 0); /** * Constructor for a host. */ explicit Smb4KNetworkObject(Smb4KHost *host, QObject *parent = 0); /** * Constructor for a share. */ explicit Smb4KNetworkObject(Smb4KShare *share, QObject *parent = 0); /** * Empty constructor */ explicit Smb4KNetworkObject(QObject *parent = 0); /** * Destructor */ ~Smb4KNetworkObject(); /** * This function returns the type. * * @returns the type */ NetworkItem type() const; /** * This function returns the type of the parent of this item. In case of * the type() function returning Unknown, this function will do the same, * otherwise the type of the level above is returned. * * @returns the parent's type */ NetworkItem parentType() const; /** * Set the type of the network item. * * @param type The type */ void setType(NetworkItem type); /** * Returns the workgroup name. * * @returns the workgroup name */ QString workgroupName() const; /** * Set the workgroup name for this network item. * * @param name The workgroup name */ void setWorkgroupName(const QString &name); /** * In case of a host or share, this function returns the name * of the host. In case of a workgroup the return value is an * empty string. * * @returns the host name or an empty string */ QString hostName() const; /** * Set the host name for this network item. * * @param name The host name */ void setHostName(const QString &name); /** * Returns TRUE if this network object represents a master browser * and FALSE otherwise. * @returns TRUE if the network object is a master browser */ bool isMasterBrowser() const; /** * Set this network object to be a master browser. This function * only does something, if type() returns Host. * * @param master Set to TRUE, if the network item is a master * browser */ void setMasterBrowser(bool master); /** * In case of a share, this function returns the name of the * share. In case of a workgroup or host the return value is an * empty string. * * @returns the share name or an empty string */ QString shareName() const; /** * Set the share name for this network item. * * @param name The share name */ void setShareName(const QString &name); /** * This is a convenience function that returns the name of the * item depending of its type. * * @returns the name depending of the type */ QString name() const; /** * This function returns the comment of a network item or an * empty string if there is no comment defined. * * @returns the comment */ QString comment() const; /** * Set the comment for this network item. * * @param comment The comment */ void setComment(const QString &comment); /** * This function returns the UNC/URL of this item. * * Please note that a workgroup will have a UNC like smb://WORKGROUP, * so to discriminate it from a host, you need to check the type() * function as well. * * @returns the item's URL */ QUrl url() const; /** * Return the URL of the parent item. * * @returns the item's parent URL */ - QUrl parentURL() const; + QUrl parentUrl() const; /** * Set the URL of this network item. * * @param url The URL */ - void setURL(const QUrl &url); + void setUrl(const QUrl &url); /** * This function returns TRUE if the network item is a share and it is * mounted. Otherwise it returns FALSE. * * @returns TRUE if the network item is mounted. */ bool isMounted() const; /** * Mark this network item as mounted. This is only reasonable with a share. * * @param mounted Should be TRUE if the network item is mounted */ void setMounted(bool mounted); /** * Updates the network item. * * @param networkItem The network item that needs to be updated */ void update(Smb4KBasicNetworkItem *networkItem); /** * This function returns TRUE if the network item is a printer share. * Otherwise it returns FALSE, * * @returns TRUE if the network item is a printer. */ bool isPrinter() const; /** * Mark this network item as printer. This is only reasonable with a share. * * @param printer Should be TRUE if the network item is a printer */ void setPrinter(bool printer); /** * This function returns the mountpoint of a mounted share or an empty * string if the network item is not a share or the share is not mounted. * * @returns the mount point of a share. */ QUrl mountpoint() const; /** * Set the mountpoint for this network item. This is only reasonable with a * share. * * @param mountpoint The mountpoint */ void setMountpoint(const QUrl &url); /** * Returns TRUE if the network item is a share that is mounted and became * inaccessible. Otherwise this function returns FALSE. * @returns TRUE is the mounted share is inaccessible */ bool isInaccessible() const; /** * Mark this network item as inaccessible. This is only reasonable with a * mounted share. * @param inaccessible Should be TRUE if the mounted share is inaccessible */ void setInaccessible(bool inaccessible); Q_SIGNALS: /** * This signal is emitted when the network item changed. */ void changed(); private: const QScopedPointer d; }; #endif