diff --git a/plasmoid/package/contents/ui/BookmarkEditor.qml b/plasmoid/package/contents/ui/BookmarkEditor.qml deleted file mode 100644 index 327a1a4..0000000 --- a/plasmoid/package/contents/ui/BookmarkEditor.qml +++ /dev/null @@ -1,470 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2018 by A. Reinholdt * - * * - * 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, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -import QtQuick 2.3 -import QtQuick.Layouts 1.3 -import QtQuick.Controls 2.3 -import QtQml.Models 2.3 -import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.components 2.0 as PlasmaComponents -import org.kde.plasma.extras 2.0 as PlasmaExtras -import org.kde.smb4k.smb4kqmlplugin 2.0 - - -PlasmaComponents.CommonDialog { - titleText: i18n("Edit Bookmarks") - buttonTexts: {[i18n("OK"), i18n("Cancel")]} - visualParent: parent - - property int editorWidth: units.iconSizes.medium * 15 - property var bookmarkList: [] - property var bookmarkGroups: [] - - BookmarkObject { - id: newGroup - isGroup: true - } - - content: ColumnLayout { - // - // Tool bar - // - PlasmaComponents.ToolBar { - id: bookmarkEditorToolBar - - Layout.minimumWidth: editorWidth - Layout.alignment: Qt.AlignCenter - Layout.fillWidth: true - - tools: PlasmaComponents.ToolBarLayout { - PlasmaComponents.ToolButton { - id: clearButton - tooltip: i18n("Clear") - iconSource: "edit-clear" - width: minimumWidth - onClicked: { - // Clear the list of bookmark groups - bookmarkGroups.length = 0 - - // Clear the bookmarks list - bookmarkList.length = 0 - - // Clear the editor widget - clearEditor() - } - } - } - } - - // - // List view - // - PlasmaExtras.ScrollArea { - id: bookmarkEditorScrollArea - - Layout.minimumWidth: editorWidth - Layout.minimumHeight: editorWidth / 2 // Yes, that's correct. - Layout.alignment: Qt.AlignCenter - Layout.fillWidth: true - - ListView { - id: bookmarkEditorListView - model: bookmarkEditorItemDelegateModel - clip: true - focus: true - highlightRangeMode: ListView.StrictlyEnforceRange - highlightFollowsCurrentItem: true - } - } - - // - // Editor widgets - // - GridLayout { - id: bookmarkEditorInputWidgets - columns: 2 - - enabled: false - - // - // Text input for the label - // - PlasmaComponents.Label { - text: i18n("Label:") - } - PlasmaComponents.TextField { - id: bookmarkEditorLabelInput - - Layout.minimumWidth: editorWidth - Layout.alignment: Qt.AlignCenter - Layout.fillWidth: true - onEditingFinished: { - changeBookmark() - } - } - - // - // Text input for the login - // - PlasmaComponents.Label { - text: i18n("Login:"); - } - PlasmaComponents.TextField { - id: bookmarkEditorLoginInput - - Layout.minimumWidth: editorWidth - Layout.alignment: Qt.AlignCenter - Layout.fillWidth: true - onEditingFinished: { - changeBookmark() - } - } - - // - // Text input for the IP address - // - PlasmaComponents.Label { - text: i18n("IP Address:") - } - PlasmaComponents.TextField { - id: bookmarkEditorIPInput - - Layout.minimumWidth: editorWidth - Layout.alignment: Qt.AlignCenter - Layout.fillWidth: true - onEditingFinished: { - changeBookmark() - } - } - - // - // Input combo box for the group name - // - PlasmaComponents.Label { - text: i18n("Group Name:") - } - PlasmaComponents.ComboBox { - id: bookmarkEditorGroupInput - - Layout.minimumWidth: editorWidth - Layout.alignment: Qt.AlignCenter - Layout.fillWidth: true - - editable: true - model: ListModel {} - - onAccepted: { - changeBookmark() - } - onActivated: { - changeBookmark() - } - } - } - } - - onButtonClicked: { - switch(index) { - case 0: // OK - changeBookmark() - iface.replaceBookmarks(bookmarkList) - break - case 1: // Cancel - break - default: - break - } - } - - // - // Connections - // - Connections { - target: iface - onBookmarksListChanged: fillView() - } - - // - // Delegate Model (used for sorting) - // - DelegateModel { - id: bookmarkEditorItemDelegateModel - - function lessThan(left, right) { - var less = false - - if (left.isGroup && right.isGroup) { - less = (left.groupName < right.groupName) - } - else if (left.groupName == right.groupName) { - if (left.hostName == right.hostName) { - less = left.shareName < right.shareName - } - else { - less = (left.hostName < right.hostName && left.shareName < right.shareName) - } - } - else { - less = (left.groupName < right.groupName) - } - - return less - } - - function insertPosition(item) { - var lower = 0 - var upper = items.count - - while (lower < upper) { - var middle = Math.floor(lower + (upper - lower) / 2) - var result = lessThan(item.model.object, items.get(middle).model.object) - if (result) { - upper = middle - } - else { - lower = middle + 1 - } - } - return lower - } - - function sort() { - while (unsortedItems.count > 0) { - var item = unsortedItems.get(0) - var index = insertPosition(item) - - item.groups = "items" - items.move(item.itemsIndex, index) - } - } - - items.includeByDefault: false - - groups: [ - DelegateModelGroup { - id: unsortedItems - name: "unsorted" - - includeByDefault: true - - onChanged: { - bookmarkEditorItemDelegateModel.sort() - } - } - ] - - filterOnGroup: "items" - - model: ListModel {} - - delegate: BookmarkEditorItemDelegate { - id: bookmarkEditorItemDelegate - - onItemClicked: { - bookmarkEditorListView.currentIndex = DelegateModel.itemsIndex - bookmarkOrGroupClicked(object) - } - - onRemoveClicked: { - bookmarkEditorListView.currentIndex = DelegateModel.itemsIndex - removeBookmark(object) - } - } - } - - // - // Functions - // - function setup() { - // Get the lists - bookmarkList = iface.bookmarks - bookmarkGroups = iface.bookmarkGroups - - // Fill the view - fillView() - } - - - function fillView() { - // Clear the editor - clearEditor() - - // Insert groups and bookmarks - if (bookmarkGroups.length != 0) { - for (var i = 0; i < bookmarkGroups.length; i++) { - // Insert groups and bookmarks into the view - bookmarkEditorItemDelegateModel.model.append({"object": bookmarkGroups[i]}) - getBookmarks(bookmarkGroups[i].groupName) - // Insert groups into the group name combo box - bookmarkEditorGroupInput.model.append({"entry": bookmarkGroups[i].groupName}) - } - } - else { - // Insert toplevel bookmarks to the view - getBookmarks("") - // Insert an empty group into the combo box - bookmarkEditorGroupInput.model.append({"entry": ""}) - } - - // Set the empty group as default in the combo box - var defaultIndex = bookmarkEditorGroupInput.find("") - if (defaultIndex != -1) { - bookmarkEditorGroupInput.currentIndex = defaultIndex - } - else { - // Do nothing - } - - // Set the default index of the view to the first item - bookmarkEditorListView.currentIndex = 0 - } - - function getBookmarks(groupName) { - if (bookmarkList.length != 0) { - for (var i = 0; i < bookmarkList.length; i++) { - if (bookmarkList[i].groupName == groupName) { - bookmarkEditorItemDelegateModel.model.append({"object": bookmarkList[i]}) - } - else { - // Do nothing - } - } - } - else { - // Do nothing - } - } - - function bookmarkOrGroupClicked(object) { - // Enable editor widgets - bookmarkEditorInputWidgets.enabled = true - - // Set texts - bookmarkEditorLabelInput.text = object.label - bookmarkEditorLoginInput.text = object.login - bookmarkEditorIPInput.text = object.hostIP - var newIndex = bookmarkEditorGroupInput.find(object.groupName) - if (newIndex != -1) { - bookmarkEditorGroupInput.currentIndex = newIndex - } - else { - // Do nothing - } - } - - function changeBookmark() { - if (bookmarkEditorItemDelegateModel.model.count != 0) { - // Get the selected bookmark and modify it according to the changes - // made in the editor widgets - var object = bookmarkEditorItemDelegateModel.items.get(bookmarkEditorListView.currentIndex).model.object - if (object !== 0) { - object.label = bookmarkEditorLabelInput.text - object.login = bookmarkEditorLoginInput.text - object.hostIP = bookmarkEditorIPInput.text - object.groupName = bookmarkEditorGroupInput.currentText - } - else { - // Do nothing - } - - // Add the new group name, if needed - var groupIndex = bookmarkEditorGroupInput.find(object.groupName) - if (groupIndex == -1) { - newGroup.groupName = object.groupName - bookmarkGroups.push(newGroup) - } - else { - // Do nothing - } - } - else { - // Do nothing - } - - // Fill the view - fillView() - } - - function clearEditor() { - // Clear the list view - while (bookmarkEditorItemDelegateModel.model.count != 0) { - bookmarkEditorItemDelegateModel.model.remove(0) - } - - // Clear and disable the editor widgets - // Enable editor widgets - bookmarkEditorLabelInput.text = "" - bookmarkEditorLoginInput.text = "" - bookmarkEditorIPInput.text = "" - var newIndex = bookmarkEditorGroupInput.find("") - if (newIndex != -1) { - bookmarkEditorGroupInput.currentIndex = newIndex - } - else { - // Do nothing - } - bookmarkEditorInputWidgets.enabled = false - } - - function removeBookmark(object) { - // Create a new, temporal list without the object to be removed - var newBookmarkList = [] - var groupNames = [] - for (var i = 0; i < bookmarkList.length; i++) { - if (bookmarkList[i] !== object) { - newBookmarkList.push(bookmarkList[i]) - if (groupNames.indexOf(bookmarkList[i].groupName) == -1) { - groupNames.push(object.groupName) - } - else { - // Do nothing - } - } - else { - // Do nothing - } - } - - // Clear the list of bookmarks - bookmarkList.length = 0 - - // Assign the temporal list to the list property - bookmarkList = newBookmarkList - - // Create a temporal list of groups - var newGroupList = [] - for (var i = 0; i < bookmarkGroups.length; i++) { - if (groupNames.indexOf(bookmarkGroups[i].groupName) !== -1) { - newGroupList.push(bookmarkGroups[i]) - } - else { - // Do nothing - } - } - - // Clear the list of bookmark groups - bookmarkGroups.length = 0 - - // Assign the group list to the list property - bookmarkGroups = newGroupList - - // Fill the view - fillView() - } -} diff --git a/plasmoid/package/contents/ui/BookmarkEditorItemDelegate.qml b/plasmoid/package/contents/ui/BookmarkEditorItemDelegate.qml deleted file mode 100644 index 9577f83..0000000 --- a/plasmoid/package/contents/ui/BookmarkEditorItemDelegate.qml +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2018 by A. Reinholdt * - * * - * 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, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -import QtQuick 2.3 -import QtQuick.Layouts 1.3 -import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.plasmoid 2.0 -import org.kde.plasma.components 2.0 as PlasmaComponents -import org.kde.plasma.extras 2.0 as PlasmaExtras -import org.kde.smb4k.smb4kqmlplugin 2.0 - -PlasmaComponents.ListItem { - id: delegate - - signal itemClicked() - signal removeClicked() - - width: parent.width - implicitWidth: parent.implicitWidth - // FIXME: Use something like margin instead of the 3 * units.smallSpacing that was found - // by trial and error ... - height: Math.max(delegateItemIcon.paintedHeight + 3 * units.smallSpacing, delegateItemText.height + 3 * units.smallSpacing) - implicitHeight: Math.max(delegateItemIcon.paintedHeight + 3 * units.smallSpacing, delegateItemText.height + 3 * units.smallSpacing) - focus: true - enabled: !object.isMounted - sectionDelegate: object.isGroup - - MouseArea { - anchors.fill: parent - - onClicked: { - delegate.itemClicked() - } - - Row { - spacing: units.largeSpacing - Column { - anchors.verticalCenter: parent.verticalCenter - PlasmaCore.IconItem { - id: delegateItemIcon - source: (object.isGroup ? "folder-bookmark" : "folder-network-symbolic") - width: units.iconSizes.medium - height: units.iconSizes.medium - } - } - Column { - anchors.verticalCenter: parent.verticalCenter - PlasmaComponents.Label { - id: delegateItemText - elide: Text.ElideRight - text: { - if (!object.isGroup) { - object.shareName+(object.label.length != 0 ? " ("+object.label+")" : "")+ - "
"+i18n("on %1", object.hostName) - } - else { - if (object.groupName.length != 0) { - object.groupName - } - else { - i18n("Toplevel Bookmarks") - } - } - } - } - } - } - } - - PlasmaComponents.ButtonRow { - anchors { - verticalCenter: parent.verticalCenter - right: parent.right - } - exclusive: false - spacing: 0 - - PlasmaComponents.ToolButton { - id: deleteButton - iconSource: "entry-delete" - tooltip: i18n("Delete Bookmark") - flat: true - opacity: 0.2 - visible: !object.isGroup - enabled: !object.isGroup - MouseArea { - anchors.fill: parent - hoverEnabled: true - onEntered: { - parent.opacity = 1.0 - } - onExited: { - parent.opacity = 0.2 - } - onClicked: { - delegate.removeClicked() - } - } - } - } -} - diff --git a/plasmoid/package/contents/ui/BookmarksPage.qml b/plasmoid/package/contents/ui/BookmarksPage.qml index e6d6836..2819048 100644 --- a/plasmoid/package/contents/ui/BookmarksPage.qml +++ b/plasmoid/package/contents/ui/BookmarksPage.qml @@ -1,293 +1,289 @@ /*************************************************************************** - * Copyright (C) 2017-2018 by A. Reinholdt * + * Copyright (C) 2017-2019 by A. Reinholdt * * * * * * 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, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.3 import QtQuick.Layouts 1.3 import QtQml.Models 2.3 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras PlasmaComponents.Page { id: bookmarksPage - // - // Bookmark editor - // - BookmarkEditor { - id: editor - } - // // Tool bar // PlasmaComponents.ToolBar { id: bookmarksToolBar anchors { top: parent.top left: parent.left right: parent.right } tools: PlasmaComponents.ToolBarLayout { PlasmaComponents.ToolButton { id: backButton tooltip: i18n("Go back") iconSource: "go-previous" width: minimumWidth onClicked: { back() } } PlasmaComponents.ToolButton { id: editButton tooltip: i18n("Edit bookmarks") iconSource: "bookmarks-organize" width: minimumWidth onClicked: { iface.editBookmarks() } } } } // // Delegate Model (used for sorting) // DelegateModel { id: bookmarkItemDelegateModel function lessThan(left, right) { var less = false if (left.isGroup && right.isGroup) { less = (left.groupName < right.groupName) } else if (!left.isGroup && !right.isGroup) { if (left.hostName == right.hostName) { less = (left.shareName < right.shareName) } else { less = (left.shareName < right.shareName && left.hostName < right.hostName) } } else { // Do nothing } return less } function insertPosition(item) { var lower = 0 var upper = items.count while (lower < upper) { var middle = Math.floor(lower + (upper - lower) / 2) var result = lessThan(item.model.object, items.get(middle).model.object) if (result) { upper = middle } else { lower = middle + 1 } } return lower } function sort() { while (unsortedItems.count > 0) { var item = unsortedItems.get(0) var index = insertPosition(item) item.groups = "items" items.move(item.itemsIndex, index) } } items.includeByDefault: false groups: [ DelegateModelGroup { id: unsortedItems name: "unsorted" includeByDefault: true onChanged: { bookmarkItemDelegateModel.sort() } } ] filterOnGroup: "items" model: ListModel {} delegate: BookmarkItemDelegate { id: bookmarkItemDelegate onItemClicked: { bookmarksListView.currentIndex = DelegateModel.itemsIndex bookmarkOrGroupClicked(object) } } } // // List view // PlasmaExtras.ScrollArea { id: bookmarksScrollArea anchors { top: bookmarksToolBar.bottom left: parent.left right: parent.right bottom: parent.bottom } ListView { id: bookmarksListView model: bookmarkItemDelegateModel clip: true focus: true highlightRangeMode: ListView.StrictlyEnforceRange } } // // Connections // Connections { target: iface onMountedSharesChanged: shareMountedOrUnmounted() onBookmarksListChanged: fillView() } // // Initialization // Component.onCompleted: { fillView() } // // Functions // function back() { // Since the 'Back' button is only useful when you // are currently in a group subfolder and want to // go back to the toplevel, just run fillView() here. fillView() } function bookmarkOrGroupClicked(object) { if (object.isGroup) { while (bookmarkItemDelegateModel.model.count != 0) { bookmarkItemDelegateModel.model.remove(0) } getBookmarks(object.groupName) + + // Set the current item to 0 + bookmarksListView.currentIndex = 0 } else { iface.mount(object.url) } } function shareMountedOrUnmounted() { for (var i = 0; i < bookmarkItemDelegateModel.model.count; i++) { var object = bookmarkItemDelegateModel.model.get(i).object if (object !== null) { if (!object.isGroup) { var mountedShare = iface.findMountedShare(object.url, false) if (mountedShare !== null) { object.isMounted = mountedShare.isMounted } else { object.isMounted = false } bookmarkItemDelegateModel.model.set(i, {"object": object}) } else { // Do nothing } } else { // Do nothing } } } function fillView() { while (bookmarkItemDelegateModel.model.count != 0) { bookmarkItemDelegateModel.model.remove(0) } // Get groups if (iface.bookmarkGroups.length != 0) { for (var i = 0; i < iface.bookmarkGroups.length; i++) { if (iface.bookmarkGroups[i].groupName.length != 0) { bookmarkItemDelegateModel.model.append({"object": iface.bookmarkGroups[i]}) } else { // Do nothing } } } else { // Do nothing } // Get toplevel bookmarks getBookmarks("") // Set the current item to 0 bookmarksListView.currentIndex = 0 } function getBookmarks(groupName) { if (iface.bookmarks.length != 0) { for (var i = 0; i < iface.bookmarks.length; i++) { if (iface.bookmarks[i].groupName == groupName) { var bookmark = iface.bookmarks[i] var mountedShare = iface.findMountedShare(bookmark.url, false) if (mountedShare !== null) { bookmark.isMounted = mountedShare.isMounted } else { // Do nothing } bookmarkItemDelegateModel.model.append({"object": bookmark}) } else { // Do nothing } } } else { // Do nothing } } } diff --git a/plasmoid/plugin/smb4kdeclarative.cpp b/plasmoid/plugin/smb4kdeclarative.cpp index 35afaa2..48bc168 100644 --- a/plasmoid/plugin/smb4kdeclarative.cpp +++ b/plasmoid/plugin/smb4kdeclarative.cpp @@ -1,756 +1,758 @@ /*************************************************************************** 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 -using namespace Smb4KGlobal; - 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 Network: + case Smb4KNetworkObject::Network: { Smb4KClient::self()->lookupDomains(); break; } - case Workgroup: + case Smb4KNetworkObject::Workgroup: { // Check if the workgroup is known. - WorkgroupPtr workgroup = findWorkgroup(object->url().host().toUpper()); + WorkgroupPtr workgroup = Smb4KGlobal::findWorkgroup(object->url().host().toUpper()); if (workgroup) { Smb4KClient::self()->lookupDomainMembers(workgroup); } break; } - case Host: + case Smb4KNetworkObject::Host: { // Check if the host is known. - HostPtr host = findHost(object->url().host().toUpper()); + HostPtr host = Smb4KGlobal::findHost(object->url().host().toUpper()); if (host) { Smb4KClient::self()->lookupShares(host); } break; } - case Share: + 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 Workgroup: + case Smb4KNetworkObject::Workgroup: { for (Smb4KNetworkObject *obj : d->workgroupObjects) { if (url == obj->url()) { object = obj; break; } else { continue; } } break; } - case Host: + case Smb4KNetworkObject::Host: { for (Smb4KNetworkObject *obj : d->hostObjects) { if (url == obj->url()) { object = obj; break; } else { continue; } } break; } - case Share: + 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() == Share) + if (object && object->type() == Smb4KNetworkObject::Share) { QString shareName = object->url().path(); if (shareName.startsWith('/')) { shareName = shareName.mid(1, -1); } - SharePtr share = findShare(object->url(), object->workgroupName()); + 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 = findShareByPath(object->mountpoint().path()); + 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() == Share) + if (object && object->type() == Smb4KNetworkObject::Share) { - SharePtr printer = findShare("//"+object->hostName()+"/"+object->shareName(), object->workgroupName()); + 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 : sharesList()) + 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 : mountedSharesList()) + 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() == Share) + if (object && object->type() == Smb4KNetworkObject::Share) { - for (const SharePtr &share : mountedSharesList()) + 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 Host: + case Smb4KNetworkObject::Host: { - for (const HostPtr &host : hostsList()) + for (const HostPtr &host : Smb4KGlobal::hostsList()) { if (host->url() == object->url()) { Smb4KCustomOptionsManager::self()->openCustomOptionsDialog(host); break; } else { continue; } } break; } - case Share: + case Smb4KNetworkObject::Share: { - for (const SharePtr &share : sharesList()) + 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() == Share) + if (object->type() == Smb4KNetworkObject::Share) { - QString unc = object->url().toString(QUrl::RemoveScheme|QUrl::RemoveUserInfo|QUrl::RemovePort|QUrl::StripTrailingSlash); - SharePtr share = findShare(unc, object->workgroupName()); + SharePtr share = Smb4KGlobal::findShare(object->url(), object->workgroupName()); if (share) { Smb4KClient::self()->openPreviewDialog(share); } } } void Smb4KDeclarative::slotWorkgroupsListChanged() { // (Re)fill the list of workgroup objects. while (!d->workgroupObjects.isEmpty()) { delete d->workgroupObjects.takeFirst(); } - for (const WorkgroupPtr &workgroup : workgroupsList()) + 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 : hostsList()) + 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 : sharesList()) + 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 : mountedSharesList()) + 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/smb4knetworkobject.cpp b/plasmoid/plugin/smb4knetworkobject.cpp index 9cff7c3..34b945a 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() { } -NetworkItem Smb4KNetworkObject::type() const +Smb4KNetworkObject::NetworkItem Smb4KNetworkObject::type() const { - return static_cast(d->type); + return static_cast(d->type); } -NetworkItem Smb4KNetworkObject::parentType() const +Smb4KNetworkObject::NetworkItem Smb4KNetworkObject::parentType() const { - return static_cast(d->parentType); + 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 { // 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) { 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 a3c459d..19019a2 100644 --- a/plasmoid/plugin/smb4knetworkobject.h +++ b/plasmoid/plugin/smb4knetworkobject.h @@ -1,316 +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; -using namespace Smb4KGlobal; - /** * 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(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) - Q_ENUM(NetworkItem) - 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; /** * Set the URL of this network item. * * @param url The 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