diff --git a/src/BookmarkHandler.cpp b/src/BookmarkHandler.cpp index 349e0c3f..1650898e 100644 --- a/src/BookmarkHandler.cpp +++ b/src/BookmarkHandler.cpp @@ -1,183 +1,182 @@ /* 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 "BookmarkMenu.h" #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); - _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr); + + BookmarkMenu *bookmarkMenu = new BookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr); + bookmarkMenu->setParent(this); } 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; } 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 {}; } 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; } diff --git a/src/BookmarkHandler.h b/src/BookmarkHandler.h index e9c27cb0..e60edc7d 100644 --- a/src/BookmarkHandler.h +++ b/src/BookmarkHandler.h @@ -1,132 +1,130 @@ /* 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 #include // Konsole #include "konsoleprivate_export.h" class QMenu; -class KBookmarkMenu; 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() Q_DECL_OVERRIDE; QUrl currentUrl() const Q_DECL_OVERRIDE; QString currentTitle() const Q_DECL_OVERRIDE; QString currentIcon() const Q_DECL_OVERRIDE; bool enableOption(BookmarkOption option) const Q_DECL_OVERRIDE; bool supportsTabs() const Q_DECL_OVERRIDE; QList currentBookmarkList() const Q_DECL_OVERRIDE; void openFolderinTabs(const KBookmarkGroup &group) Q_DECL_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) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(BookmarkHandler) QString titleForView(ViewProperties *view) const; QUrl urlForView(ViewProperties *view) const; QString iconForView(ViewProperties *view) const; QMenu *_menu; - KBookmarkMenu *_bookmarkMenu; QString _file; bool _toplevel; ViewProperties *_activeView; QList _views; }; } #endif // BOOKMARKHANDLER_H diff --git a/src/BookmarkMenu.cpp b/src/BookmarkMenu.cpp new file mode 100644 index 00000000..34c13c8e --- /dev/null +++ b/src/BookmarkMenu.cpp @@ -0,0 +1,54 @@ +/* This file was part of the KDE libraries + + Copyright 2019 by Tomaz Canabrava + Copyright 2019 by Martin Sandsmark + + 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. +*/ + +// Own +#include "BookmarkMenu.h" + +// KDE +#include + +// Qt +#include +#include +#include + +BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec) : + KBookmarkMenu (mgr, owner, parentMenu, collec) +{ + // We need to hijack the action + QAction *bookmarkAction = collec->action(QStringLiteral("add_bookmark")); + disconnect(bookmarkAction, nullptr, this, nullptr); + connect(bookmarkAction, &QAction::triggered, this, &BookmarkMenu::maybeAddBookmark); +} + +void BookmarkMenu::maybeAddBookmark() +{ + // Check for duplicates first + const KBookmarkGroup rootGroup = manager()->root(); + const QUrl currUrl = owner()->currentUrl(); + for (const QUrl &url : rootGroup.groupUrlList()) { + if (url == currUrl) { + return; + } + } + + slotAddBookmark(); +} diff --git a/src/BookmarkMenu.h b/src/BookmarkMenu.h new file mode 100644 index 00000000..a42eab23 --- /dev/null +++ b/src/BookmarkMenu.h @@ -0,0 +1,48 @@ +/* This file was part of the KDE libraries + + Copyright 2019 by Tomaz Canabrava + Copyright 2019 by Martin Sandsmark + + 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. +*/ + +#ifndef BOOKMARKMENU_H +#define BOOKMARKMENU_H + +// KDE +#include + +// Konsole +#include "konsoleprivate_export.h" + +/* Hackish hack to mitigate a broken behavior of KBookmarkMenu. + * slotAddBookmark accepts duplicates and it's fragile code, + * that thing really deserves a rewrite. + * the easiest way is to "hijack" it's protected method to public + * and just cast around. + */ +class KONSOLEPRIVATE_EXPORT BookmarkMenu : public KBookmarkMenu +{ + Q_OBJECT + +public: + BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec); + +private Q_SLOTS: + void maybeAddBookmark(); +}; + +#endif//BOOKMARKMENU_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bbdb6c07..7a910b49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,224 +1,225 @@ # cmake-options : -DCMAKE_DISABLE_FIND_PACKAGE_LibKonq=TRUE or FALSE; default is FALSE add_definitions(-DTRANSLATION_DOMAIN=\"konsole\") ### Handle DragonFlyBSD here instead of using __DragonFly__ IF(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") set(HAVE_OS_DRAGONFLYBSD 1) else() set(HAVE_OS_DRAGONFLYBSD 0) endif() IF(NOT (${KF5_VERSION} VERSION_LESS "5.60.0")) set(USE_TERMINALINTERFACEV2 1) endif() include(CheckIncludeFiles) include(ECMAddAppIcon) configure_file(config-konsole.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-konsole.h) ### Tests if(BUILD_TESTING) find_package(Qt5Test ${QT_MIN_VERSION} CONFIG REQUIRED) add_subdirectory(autotests) add_subdirectory(tests) endif() ### Security concerns about sendText and runCommand dbus methods being public option(REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS "Konsole: remove sendText and runCommand dbus methods" OFF) ### Development tools option(KONSOLE_BUILD_UNI2CHARACTERWIDTH "Konsole: build uni2characterwidth executable" OFF) ### Konsole source files shared between embedded terminal and main application # qdbuscpp2xml -m Session.h -o org.kde.konsole.Session.xml # qdbuscpp2xml -M -s ViewManager.h -o org.kde.konsole.Konsole.xml # Generate dbus .xml files; do not store .xml in source folder qt5_generate_dbus_interface(Session.h org.kde.konsole.Session.xml OPTIONS -m) qt5_generate_dbus_interface(ViewManager.h org.kde.konsole.Window.xml OPTIONS -m) qt5_add_dbus_adaptor(sessionadaptors_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml Session.h Konsole::Session) qt5_add_dbus_adaptor(windowadaptors_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml ViewManager.h Konsole::ViewManager) set(konsoleprivate_SRCS ${sessionadaptors_SRCS} ${windowadaptors_SRCS} hsluv.c BookmarkHandler.cpp + BookmarkMenu.cpp ColorScheme.cpp ColorSchemeManager.cpp ColorSchemeEditor.cpp CopyInputDialog.cpp EditProfileDialog.cpp FontDialog.cpp Emulation.cpp DetachableTabBar.cpp Filter.cpp History.cpp HistorySizeDialog.cpp HistorySizeWidget.cpp IncrementalSearchBar.cpp KeyBindingEditor.cpp KeyboardTranslator.cpp KeyboardTranslatorManager.cpp ProcessInfo.cpp Profile.cpp ProfileList.cpp ProfileReader.cpp ProfileWriter.cpp ProfileManager.cpp Pty.cpp RenameTabDialog.cpp RenameTabWidget.cpp SaveHistoryTask.cpp SearchHistoryTask.cpp Screen.cpp ScreenWindow.cpp ScrollState.cpp Session.cpp SessionController.cpp SessionManager.cpp SessionListModel.cpp SessionTask.cpp ShellCommand.cpp TabTitleFormatButton.cpp TerminalCharacterDecoder.cpp ExtendedCharTable.cpp TerminalDisplay.cpp TerminalDisplayAccessible.cpp TerminalHeaderBar.cpp LineBlockCharacters.cpp ViewContainer.cpp ViewManager.cpp ViewProperties.cpp ViewSplitter.cpp Vt102Emulation.cpp ZModemDialog.cpp PrintOptions.cpp WindowSystemInfo.cpp CharacterWidth.cpp ${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Window.xml ${CMAKE_CURRENT_BINARY_DIR}/org.kde.konsole.Session.xml) ecm_qt_declare_logging_category(konsoleprivate_SRCS HEADER konsoledebug.h IDENTIFIER KonsoleDebug CATEGORY_NAME org.kde.konsole) kconfig_add_kcfg_files(konsoleprivate_SRCS settings/KonsoleSettings.kcfgc) set(konsole_LIBS KF5::XmlGui Qt5::PrintSupport Qt5::Xml KF5::Notifications KF5::WindowSystem KF5::TextWidgets KF5::GuiAddons KF5::IconThemes KF5::Bookmarks KF5::I18n KF5::Pty KF5::KIOWidgets KF5::DBusAddons KF5::GlobalAccel KF5::NewStuff ) if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") #kinfo_getfile() is in libutil list(APPEND konsole_LIBS util) endif() ### Konsole Application ki18n_wrap_ui(konsoleprivate_SRCS ColorSchemeEditor.ui CopyInputDialog.ui EditProfileGeneralPage.ui EditProfileTabsPage.ui EditProfileAppearancePage.ui EditProfileScrollingPage.ui EditProfileKeyboardPage.ui EditProfileMousePage.ui EditProfileAdvancedPage.ui KeyBindingEditor.ui RenameTabDialog.ui RenameTabWidget.ui HistorySizeDialog.ui HistorySizeWidget.ui PrintOptions.ui settings/TemporaryFilesSettings.ui settings/GeneralSettings.ui settings/PartInfo.ui settings/ProfileSettings.ui settings/TabBarSettings.ui) # add the resource files for the ui files qt5_add_resources( konsoleprivate_SRCS ../desktop/konsole.qrc) add_library(konsoleprivate ${konsoleprivate_SRCS}) generate_export_header(konsoleprivate BASE_NAME konsoleprivate) target_link_libraries(konsoleprivate PUBLIC ${konsole_LIBS}) set_target_properties(konsoleprivate PROPERTIES VERSION ${KONSOLEPRIVATE_VERSION_STRING} SOVERSION ${KONSOLEPRIVATE_SOVERSION} ) install(TARGETS konsoleprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP) set(konsole_KDEINIT_SRCS Application.cpp MainWindow.cpp main.cpp settings/ConfigurationDialog.cpp settings/TemporaryFilesSettings.cpp settings/GeneralSettings.cpp settings/ProfileSettings.cpp settings/TabBarSettings.cpp) # Sets the icon on Windows and OSX file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/*.png") ecm_add_app_icon(kdeinit_konsole ICONS ${ICONS_SRCS}) kf5_add_kdeinit_executable(konsole ${konsole_KDEINIT_SRCS}) target_link_libraries(kdeinit_konsole konsoleprivate KF5::XmlGui KF5::WindowSystem KF5::Bookmarks KF5::I18n KF5::KIOWidgets KF5::NotifyConfig KF5::Crash ) if(APPLE) set_target_properties(konsole PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER "org.kde.konsole" MACOSX_BUNDLE_BUNDLE_NAME "Konsole" MACOSX_BUNDLE_DISPLAY_NAME "Konsole" MACOSX_BUNDLE_INFO_STRING "Konsole, the KDE terminal emulator" MACOSX_BUNDLE_LONG_VERSION_STRING "Konsole ${KDE_APPLICATIONS_VERSION}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}" MACOSX_BUNDLE_BUNDLE_VERSION "${KDE_APPLICATIONS_VERSION}" MACOSX_BUNDLE_COPYRIGHT "1997-2016 The Konsole Developers") endif() install(TARGETS kdeinit_konsole konsole ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) ### Embedded Konsole KPart set(konsolepart_PART_SRCS Part.cpp settings/PartInfo.cpp settings/ProfileSettings.cpp) add_library(konsolepart MODULE ${konsolepart_PART_SRCS}) generate_export_header(konsolepart BASE_NAME konsole) kcoreaddons_desktop_to_json(konsolepart ../desktop/konsolepart.desktop) set_target_properties(konsolepart PROPERTIES DEFINE_SYMBOL KONSOLE_PART) target_link_libraries(konsolepart KF5::Parts KF5::XmlGui konsoleprivate) install(TARGETS konsolepart DESTINATION ${KDE_INSTALL_PLUGINDIR})