diff --git a/src/BookmarkHandler.cpp b/src/BookmarkHandler.cpp index 4a98c9bf..be337fec 100644 --- a/src/BookmarkHandler.cpp +++ b/src/BookmarkHandler.cpp @@ -1,170 +1,183 @@ /* This file was part of the KDE libraries Copyright 2002 Carsten Pfeiffer Copyright 2007-2008 Robert Knight library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation, version 2 or ( at your option ), any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Born as kdelibs/kio/kfile/kfilebookmarkhandler.cpp // Own #include "BookmarkHandler.h" // Qt #include #include #include // KDE #include #include #include // Konsole #include "BookmarkMenu.h" #include "ViewProperties.h" using namespace Konsole; BookmarkHandler::BookmarkHandler(KActionCollection *collection, QMenu *menu, bool toplevel, QObject *parent) : QObject(parent), KBookmarkOwner(), _menu(menu), _file(QString()), _toplevel(toplevel), _activeView(nullptr), _views(QList()) { setObjectName(QStringLiteral("BookmarkHandler")); _file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/bookmarks.xml")); if (_file.isEmpty()) { _file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/konsole"); QDir().mkpath(_file); _file += QStringLiteral("/bookmarks.xml"); } KBookmarkManager *manager = KBookmarkManager::managerForFile(_file, QStringLiteral("konsole")); manager->setUpdate(true); BookmarkMenu *bookmarkMenu = new BookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr); bookmarkMenu->setParent(this); } BookmarkHandler::~BookmarkHandler() { } void BookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) { emit openUrl(bm.url()); } void BookmarkHandler::openFolderinTabs(const KBookmarkGroup &group) { emit openUrls(group.groupUrlList()); } bool BookmarkHandler::enableOption(BookmarkOption option) const { if (option == ShowAddBookmark || option == ShowEditBookmark) { return _toplevel; } return KBookmarkOwner::enableOption(option); } QUrl BookmarkHandler::currentUrl() const { return urlForView(_activeView); } QUrl BookmarkHandler::urlForView(ViewProperties *view) const { if (view != nullptr) { return view->url(); } return {}; } QString BookmarkHandler::currentTitle() const { return titleForView(_activeView); } QString BookmarkHandler::titleForView(ViewProperties *view) const { const QUrl &url = view != nullptr ? view->url() : QUrl(); if (url.isLocalFile()) { QString path = url.path(); path = KShell::tildeExpand(path); path = QFileInfo(path).completeBaseName(); return path; } if (!url.host().isEmpty()) { if (!url.userName().isEmpty()) { return i18nc("@item:inmenu The user's name and host they are connected to via ssh", "%1 on %2", url.userName(), url.host()); } return i18nc("@item:inmenu The host the user is connected to via ssh", "%1", url.host()); } return url.toDisplayString(); } QString BookmarkHandler::currentIcon() const { return iconForView(_activeView); } QString BookmarkHandler::iconForView(ViewProperties *view) const { if (view != nullptr) { return view->icon().name(); } return {}; } +QList BookmarkHandler::currentBookmarkList() const +{ + QList list; + list.reserve(_views.size()); + + const QList views = _views; + for (ViewProperties* view : views) { + list << KBookmarkOwner::FutureBookmark(titleForView(view), urlForView(view), iconForView(view)); + } + + return list; +} + bool BookmarkHandler::supportsTabs() const { return true; } void BookmarkHandler::setViews(const QList &views) { _views = views; } QList BookmarkHandler::views() const { return _views; } void BookmarkHandler::setActiveView(ViewProperties *view) { _activeView = view; } ViewProperties *BookmarkHandler::activeView() const { return _activeView; } diff --git a/src/BookmarkHandler.h b/src/BookmarkHandler.h index b3659c6b..c2fe0ccf 100644 --- a/src/BookmarkHandler.h +++ b/src/BookmarkHandler.h @@ -1,128 +1,129 @@ /* This file was part of the KDE libraries Copyright 2002 Carsten Pfeiffer Copyright 2007-2008 Robert Knight library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation, version 2 or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Born as kdelibs/kio/kfile/kfilebookmarkhandler.h #ifndef BOOKMARKHANDLER_H #define BOOKMARKHANDLER_H // KDE #include // Konsole #include "konsoleprivate_export.h" class QMenu; class QUrl; class KActionCollection; namespace Konsole { class ViewProperties; /** * This class handles the communication between the bookmark menu and the active session, * providing a suggested title and URL when the user clicks the "Add Bookmark" item in * the bookmarks menu. * * The bookmark handler is associated with a session controller, which is used to * determine the working URL of the current session. When the user changes the active * view, the bookmark handler's controller should be changed using setController() * * When the user selects a bookmark, the openUrl() signal is emitted. */ class KONSOLEPRIVATE_EXPORT BookmarkHandler : public QObject, public KBookmarkOwner { Q_OBJECT public: /** * Constructs a new bookmark handler for Konsole bookmarks. * * @param collection The collection which the bookmark menu's actions should be added to * @param menu The menu which the bookmark actions should be added to * @param toplevel TODO: Document me * @param parent The parent object */ BookmarkHandler(KActionCollection *collection, QMenu *menu, bool toplevel, QObject *parent); ~BookmarkHandler() override; QUrl currentUrl() const override; QString currentTitle() const override; QString currentIcon() const override; bool enableOption(BookmarkOption option) const override; bool supportsTabs() const override; + QList currentBookmarkList() const override; void openFolderinTabs(const KBookmarkGroup &group) override; /** * Returns the menu which this bookmark handler inserts its actions into. */ QMenu *menu() const { return _menu; } QList views() const; ViewProperties *activeView() const; public Q_SLOTS: /** * */ void setViews(const QList &views); void setActiveView(ViewProperties *view); Q_SIGNALS: /** * Emitted when the user selects a bookmark from the bookmark menu. * * @param url The url of the bookmark which was selected by the user. */ void openUrl(const QUrl &url); /** * Emitted when the user selects 'Open Folder in Tabs' * from the bookmark menu. * * @param urls The urls of the bookmarks in the folder whose * 'Open Folder in Tabs' action was triggered */ void openUrls(const QList &urls); private Q_SLOTS: void openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) override; private: Q_DISABLE_COPY(BookmarkHandler) QString titleForView(ViewProperties *view) const; QUrl urlForView(ViewProperties *view) const; QString iconForView(ViewProperties *view) const; QMenu *_menu; QString _file; bool _toplevel; ViewProperties *_activeView; QList _views; }; } #endif // BOOKMARKHANDLER_H