diff --git a/src/BookmarkHandler.cpp b/src/BookmarkHandler.cpp index 968f2a0a..349e0c3f 100644 --- a/src/BookmarkHandler.cpp +++ b/src/BookmarkHandler.cpp @@ -1,192 +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 #include // Konsole #include "ViewProperties.h" using namespace Konsole; BookmarkHandler::BookmarkHandler(KActionCollection *collection, QMenu *menu, bool toplevel, QObject *parent) : QObject(parent), KBookmarkOwner(), _menu(menu), _bookmarkMenu(nullptr), _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); - - if (toplevel) { - _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, collection); - } else { - _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, nullptr); - } + _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr); } BookmarkHandler::~BookmarkHandler() { delete _bookmarkMenu; } 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; - } else { - return KBookmarkOwner::enableOption(option); } + return KBookmarkOwner::enableOption(option); } QUrl BookmarkHandler::currentUrl() const { return urlForView(_activeView); } QUrl BookmarkHandler::urlForView(ViewProperties *view) const { if (view != nullptr) { return view->url(); - } else { - return QUrl(); } + 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; - } else if (!url.host().isEmpty()) { + } + 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()); - } else { - return i18nc("@item:inmenu The host the user is connected to via ssh", "%1", - 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(); - } else { - return QString(); } + return {}; } bool BookmarkHandler::supportsTabs() const { return true; } QList BookmarkHandler::currentBookmarkList() const { QList list; list.reserve(_views.size()); foreach (ViewProperties *view, _views) { list << KBookmarkOwner::FutureBookmark(titleForView(view), urlForView(view), iconForView(view)); } return list; } 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; }