mirror of
https://github.com/KDE/konsole.git
synced 2026-01-22 05:58:23 -05:00
* speeds up incremental builds as changes to a header will not always need the full mocs_compilation.cpp for all the target's headers rebuild, while having a moc file sourced into a source file only adds minor extra costs, due to small own code and the used headers usually already covered by the source file, being for the same class/struct * seems to not slow down clean builds, due to empty mocs_compilation.cpp resulting in those quickly processed, while the minor extra cost of the sourced moc files does not outweigh that in summary. Measured times actually improved by some percent points. (ideally CMake would just skip empty mocs_compilation.cpp & its object file one day) * enables compiler to see all methods of a class in same compilation unit to do some sanity checks * potentially more inlining in general, due to more in the compilation unit * allows to keep using more forward declarations in the header, as with the moc code being sourced into the cpp file there definitions can be ensured and often are already for the needs of the normal class methods
168 lines
4.1 KiB
C++
168 lines
4.1 KiB
C++
/* This file was part of the KDE libraries
|
|
|
|
SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org>
|
|
SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
// Born as kdelibs/kio/kfile/kfilebookmarkhandler.cpp
|
|
|
|
// Own
|
|
#include "BookmarkHandler.h"
|
|
|
|
// Qt
|
|
#include <QDir>
|
|
#include <QFileInfo>
|
|
#include <QStandardPaths>
|
|
|
|
// KDE
|
|
#include <KLocalizedString>
|
|
#include <KShell>
|
|
|
|
// Konsole
|
|
#include "BookmarkMenu.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<ViewProperties *>())
|
|
{
|
|
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);
|
|
|
|
// This constructor is only called with toplevel as true; regardless the
|
|
// fourth argument can not be nullptr as it will crash in BookmarkMenu
|
|
// TODO: remove the toplevel boolean argument in API
|
|
auto *bookmarkMenu = new BookmarkMenu(manager, this, _menu, collection);
|
|
bookmarkMenu->setParent(this);
|
|
}
|
|
|
|
BookmarkHandler::~BookmarkHandler() = default;
|
|
|
|
void BookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers)
|
|
{
|
|
Q_EMIT openUrl(bm.url());
|
|
}
|
|
|
|
void BookmarkHandler::openFolderinTabs(const KBookmarkGroup &group)
|
|
{
|
|
Q_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<KBookmarkOwner::FutureBookmark> BookmarkHandler::currentBookmarkList() const
|
|
{
|
|
QList<KBookmarkOwner::FutureBookmark> list;
|
|
list.reserve(_views.size());
|
|
|
|
const QList<ViewProperties *> 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<ViewProperties *> &views)
|
|
{
|
|
_views = views;
|
|
}
|
|
|
|
QList<ViewProperties *> BookmarkHandler::views() const
|
|
{
|
|
return _views;
|
|
}
|
|
|
|
void BookmarkHandler::setActiveView(ViewProperties *view)
|
|
{
|
|
_activeView = view;
|
|
}
|
|
|
|
ViewProperties *BookmarkHandler::activeView() const
|
|
{
|
|
return _activeView;
|
|
}
|
|
|
|
#include "moc_BookmarkHandler.cpp"
|