diff --git a/CMakeLists.txt b/CMakeLists.txt index f0d790d..5b16193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,102 +1,101 @@ cmake_minimum_required(VERSION 3.5) set(KF5_VERSION "5.56.0") # handled by release scripts set(KF5_DEP_VERSION "5.55.0") # handled by release scripts project(KBookmarks VERSION ${KF5_VERSION}) include(FeatureSummary) find_package(ECM 5.55.0 NO_MODULE) set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://projects.kde.org/projects/kdesupport/extra-cmake-modules") feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMQtDeclareLoggingCategory) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMAddQch) include(ECMPoQmTools) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") ecm_setup_version(PROJECT VARIABLE_PREFIX KBOOKMARKS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kbookmarks_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5BookmarksConfigVersion.cmake" SOVERSION 5) # Dependencies set(REQUIRED_QT_VERSION 5.10.0) find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Widgets Xml) if (NOT ANDROID) find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED DBus) endif() find_package(KF5Config ${KF5_DEP_VERSION} REQUIRED) find_package(KF5CoreAddons ${KF5_DEP_VERSION} REQUIRED) find_package(KF5Codecs ${KF5_DEP_VERSION} REQUIRED) find_package(KF5ConfigWidgets ${KF5_DEP_VERSION} REQUIRED) -find_package(KF5IconThemes ${KF5_DEP_VERSION} REQUIRED) find_package(KF5WidgetsAddons ${KF5_DEP_VERSION} REQUIRED) find_package(KF5XmlGui ${KF5_DEP_VERSION} REQUIRED) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(tests) add_subdirectory(autotests) endif() # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Bookmarks") if (BUILD_QCH) ecm_install_qch_export( TARGETS KF5Bookmarks_QCH FILE KF5BookmarksQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5BookmarksQchTargets.cmake\")") endif() include(CMakePackageConfigHelpers) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5BookmarksConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5BookmarksConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5BookmarksConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5BookmarksConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5BookmarksTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5BookmarksTargets.cmake NAMESPACE KF5:: ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kbookmarks_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) # contains list of debug categories, for kdebugsettings install(FILES kbookmarks.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 05ca449..49ddc32 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,113 +1,112 @@ ecm_create_qm_loader(kbookmarks_QM_LOADER kbookmarks5_qt) set(kbookmarks_SRCS kbookmark.cpp kbookmarkaction.cpp kbookmarkactioninterface.cpp kbookmarkactionmenu.cpp kbookmarkcontextmenu.cpp kbookmarkimporter.cpp kbookmarkmanager.cpp kbookmarkmenu.cpp kbookmarkowner.cpp konqbookmarkmenu.cpp kbookmarkimporter_opera.cpp kbookmarkimporter_ie.cpp kbookmarkimporter_ns.cpp kbookmarkdombuilder.cpp kbookmarkdialog.cpp ${kbookmarks_QM_LOADER} ) if (TARGET Qt5::DBus) list(APPEND kbookmarks_SRCS kbookmarkmanageradaptor.cpp) endif() ecm_qt_declare_logging_category(kbookmarks_SRCS HEADER kbookmarks_debug.h IDENTIFIER KBOOKMARKS_LOG CATEGORY_NAME kf5.kbookmarks) add_library(KF5Bookmarks ${kbookmarks_SRCS}) generate_export_header(KF5Bookmarks BASE_NAME KBookmarks) add_library(KF5::Bookmarks ALIAS KF5Bookmarks) target_include_directories(KF5Bookmarks INTERFACE "$") target_link_libraries(KF5Bookmarks PUBLIC Qt5::Widgets Qt5::Xml KF5::WidgetsAddons) target_link_libraries(KF5Bookmarks PRIVATE KF5::CoreAddons # for KStringHandler KF5::Codecs # for KCharsets KF5::ConfigCore # for KConfigGroup KF5::ConfigWidgets # for KStandardAction KF5::XmlGui # for KActionCollection - KF5::IconThemes # for SmallIcon ) if (TARGET Qt5::DBus) target_link_libraries(KF5Bookmarks PRIVATE Qt5::DBus) # dbus usage in kbookmarkmanager.cpp else() target_compile_definitions(KF5Bookmarks PUBLIC -DKBOOKMARKS_NO_DBUS) endif() set_target_properties(KF5Bookmarks PROPERTIES VERSION ${KBOOKMARKS_VERSION_STRING} SOVERSION ${KBOOKMARKS_SOVERSION} EXPORT_NAME Bookmarks ) ecm_generate_headers(KBookmarks_HEADERS HEADER_NAMES KBookmark KBookmarkAction KBookmarkActionInterface KBookmarkActionMenu KBookmarkContextMenu KBookmarkManager KBookmarkMenu KBookmarkOwner KBookmarkDomBuilder KBookmarkDialog KonqBookmarkMenu REQUIRED_HEADERS KBookmarks_HEADERS ) # These classes have weirdly named classes, no forwarding headers. set(KBookmarks_HEADERS ${KBookmarks_HEADERS} kbookmarkexporter.h kbookmarkimporter.h kbookmarkimporter_opera.h kbookmarkimporter_ie.h kbookmarkimporter_ns.h ) install(TARGETS KF5Bookmarks EXPORT KF5BookmarksTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kbookmarks_export.h ${KBookmarks_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KBookmarks COMPONENT Devel ) if(BUILD_QCH) ecm_add_qch( KF5Bookmarks_QCH NAME KBookmarks BASE_NAME KF5Bookmarks VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${KBookmarks_HEADERS} MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" LINK_QCHS Qt5Widgets_QCH Qt5Xml_QCH KF5WidgetsAddons_QCH BLANK_MACROS KCOREADDONS_EXPORT KCOREADDONS_DEPRECATED KCOREADDONS_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KBookmarks LIB_NAME KF5Bookmarks DEPS "widgets xml" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KBookmarks) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/kbookmarkdialog.cpp b/src/kbookmarkdialog.cpp index ef5ba85..9be5fb1 100644 --- a/src/kbookmarkdialog.cpp +++ b/src/kbookmarkdialog.cpp @@ -1,409 +1,409 @@ // -*- c-basic-offset:4; indent-tabs-mode:nil -*- /* This file is part of the KDE libraries Copyright 2007 Daniel Teske This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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. */ #include "kbookmarkdialog.h" #include "kbookmarkdialog_p.h" #include "kbookmarkmanager.h" #include "kbookmarkmenu.h" #include "kbookmarkmenu_p.h" #include #include #include #include #include #include #include #include -#include +#include #include KBookmarkDialogPrivate::KBookmarkDialogPrivate(KBookmarkDialog *q) : q(q) , folderTree(nullptr) , layout(false) { } KBookmarkDialogPrivate::~KBookmarkDialogPrivate() { } void KBookmarkDialogPrivate::initLayout() { QBoxLayout *vbox = new QVBoxLayout; QFormLayout *form = new QFormLayout(); vbox->addLayout(form); form->addRow(titleLabel, title); form->addRow(urlLabel, url); form->addRow(commentLabel, comment); vbox->addWidget(folderTree); vbox->addWidget(buttonBox); q->setLayout(vbox); } void KBookmarkDialogPrivate::initLayoutPrivate() { title = new QLineEdit(q); title->setMinimumWidth(300); titleLabel = new QLabel(KBookmarkDialog::tr("Name:", "@label:textbox"), q); titleLabel->setBuddy(title); url = new QLineEdit(q); url->setMinimumWidth(300); urlLabel = new QLabel(KBookmarkDialog::tr("Location:", "@label:textbox"), q); urlLabel->setBuddy(url); comment = new QLineEdit(q); comment->setMinimumWidth(300); commentLabel = new QLabel(KBookmarkDialog::tr("Comment:", "@label:textbox"), q); commentLabel->setBuddy(comment); folderTree = new QTreeWidget(q); folderTree->setColumnCount(1); folderTree->header()->hide(); folderTree->setSortingEnabled(false); folderTree->setSelectionMode(QTreeWidget::SingleSelection); folderTree->setSelectionBehavior(QTreeWidget::SelectRows); folderTree->setMinimumSize(60, 100); QTreeWidgetItem *root = new KBookmarkTreeItem(folderTree); fillGroup(root, mgr->root()); buttonBox = new QDialogButtonBox(q); buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); q->connect(buttonBox, &QDialogButtonBox::accepted, q, &KBookmarkDialog::accept); q->connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject); initLayout(); layout = true; } void KBookmarkDialogPrivate::fillGroup(QTreeWidgetItem *parentItem, const KBookmarkGroup &group, const KBookmarkGroup &selectGroup) { for (KBookmark bk = group.first(); !bk.isNull(); bk = group.next(bk)) { if (bk.isGroup()) { const KBookmarkGroup bkGroup = bk.toGroup(); QTreeWidgetItem* item = new KBookmarkTreeItem(parentItem, folderTree, bkGroup); if (selectGroup == bkGroup) { folderTree->setCurrentItem(item); } fillGroup(item, bkGroup, selectGroup); } } } void KBookmarkDialogPrivate::setParentBookmark(const KBookmark &bm) { QString address = bm.address(); KBookmarkTreeItem *item = static_cast(folderTree->topLevelItem(0)); while (true) { if (item->address() == bm.address()) { folderTree->setCurrentItem(item); return; } for (int i = 0; i < item->childCount(); ++i) { KBookmarkTreeItem *child = static_cast(item->child(i)); if (KBookmark::commonParent(child->address(), address) == child->address()) { item = child; break; } } } } KBookmarkGroup KBookmarkDialogPrivate::parentBookmark() { KBookmarkTreeItem *item = dynamic_cast(folderTree->currentItem()); if (!item) { return mgr->root(); } const QString &address = item->address(); return mgr->findByAddress(address).toGroup(); } void KBookmarkDialog::accept() { if (d->mode == KBookmarkDialogPrivate::NewFolder) { KBookmarkGroup parent = d->parentBookmark(); if (d->title->text().isEmpty()) { d->title->setText(QStringLiteral("New Folder")); } d->bm = parent.createNewFolder(d->title->text()); d->bm.setDescription(d->comment->text()); d->mgr->emitChanged(parent); } else if (d->mode == KBookmarkDialogPrivate::NewBookmark) { KBookmarkGroup parent = d->parentBookmark(); if (d->title->text().isEmpty()) { d->title->setText(QStringLiteral("New Bookmark")); } d->bm = parent.addBookmark(d->title->text(), QUrl(d->url->text()), d->icon); d->bm.setDescription(d->comment->text()); d->mgr->emitChanged(parent); } else if (d->mode == KBookmarkDialogPrivate::NewMultipleBookmarks) { KBookmarkGroup parent = d->parentBookmark(); if (d->title->text().isEmpty()) { d->title->setText(QStringLiteral("New Folder")); } d->bm = parent.createNewFolder(d->title->text()); d->bm.setDescription(d->comment->text()); foreach (const KBookmarkOwner::FutureBookmark &fb, d->list) { d->bm.toGroup().addBookmark(fb.title(), fb.url(), fb.icon()); } d->mgr->emitChanged(parent); } else if (d->mode == KBookmarkDialogPrivate::EditBookmark) { d->bm.setFullText(d->title->text()); d->bm.setUrl(QUrl(d->url->text())); d->bm.setDescription(d->comment->text()); d->mgr->emitChanged(d->bm.parentGroup()); } else if (d->mode == d->SelectFolder) { d->bm = d->parentBookmark(); } QDialog::accept(); } KBookmark KBookmarkDialog::editBookmark(const KBookmark &bm) { if (!d->layout) { d->initLayoutPrivate(); } KGuiItem::assign(d->buttonBox->button(QDialogButtonBox::Ok), KGuiItem(tr("Update", "@action:button"))); setWindowTitle(tr("Bookmark Properties", "@title:window")); d->url->setVisible(!bm.isGroup()); d->urlLabel->setVisible(!bm.isGroup()); d->bm = bm; d->title->setText(bm.fullText()); d->url->setText(bm.url().toString()); d->comment->setVisible(true); d->commentLabel->setVisible(true); d->comment->setText(bm.description()); d->folderTree->setVisible(false); d->mode = KBookmarkDialogPrivate::EditBookmark; if (exec() == QDialog::Accepted) { return d->bm; } else { return KBookmark(); } } KBookmark KBookmarkDialog::addBookmark(const QString &title, const QUrl &url, const QString &icon, KBookmark parent) { if (!d->layout) { d->initLayoutPrivate(); } if (parent.isNull()) { parent = d->mgr->root(); } QPushButton *newButton = new QPushButton; KGuiItem::assign(newButton, KGuiItem(tr("&New Folder...", "@action:button"), QStringLiteral("folder-new"))); d->buttonBox->addButton(newButton, QDialogButtonBox::ActionRole); connect(newButton, &QAbstractButton::clicked, this, &KBookmarkDialog::newFolderButton); KGuiItem::assign(d->buttonBox->button(QDialogButtonBox::Ok), KGuiItem(tr("Add", "@action:button"), QStringLiteral("bookmark-new"))); setWindowTitle(tr("Add Bookmark", "@title:window")); d->url->setVisible(true); d->urlLabel->setVisible(true); d->title->setText(title); d->url->setText(url.toString()); d->comment->setText(QString()); d->comment->setVisible(true); d->commentLabel->setVisible(true); d->setParentBookmark(parent); d->folderTree->setVisible(true); d->icon = icon; d->mode = KBookmarkDialogPrivate::NewBookmark; if (exec() == QDialog::Accepted) { return d->bm; } else { return KBookmark(); } } KBookmarkGroup KBookmarkDialog::addBookmarks(const QList &list, const QString &name, KBookmarkGroup parent) { if (!d->layout) { d->initLayoutPrivate(); } if (parent.isNull()) { parent = d->mgr->root(); } d->list = list; QPushButton *newButton = new QPushButton; KGuiItem::assign(newButton, KGuiItem(tr("&New Folder...", "@action:button"), QStringLiteral("folder-new"))); d->buttonBox->addButton(newButton, QDialogButtonBox::ActionRole); connect(newButton, &QAbstractButton::clicked, this, &KBookmarkDialog::newFolderButton); KGuiItem::assign(d->buttonBox->button(QDialogButtonBox::Ok), KGuiItem(tr("Add", "@action:button"), QStringLiteral("bookmark-new"))); setWindowTitle(tr("Add Bookmarks", "@title:window")); d->url->setVisible(false); d->urlLabel->setVisible(false); d->title->setText(name); d->comment->setVisible(true); d->commentLabel->setVisible(true); d->comment->setText(QString()); d->setParentBookmark(parent); d->folderTree->setVisible(true); d->mode = KBookmarkDialogPrivate::NewMultipleBookmarks; if (exec() == QDialog::Accepted) { return d->bm.toGroup(); } else { return KBookmarkGroup(); } } KBookmarkGroup KBookmarkDialog::selectFolder(KBookmark parent) { if (!d->layout) { d->initLayoutPrivate(); } if (parent.isNull()) { parent = d->mgr->root(); } QPushButton *newButton = new QPushButton; KGuiItem::assign(newButton, KGuiItem(tr("&New Folder...", "@action:button"), QStringLiteral("folder-new"))); d->buttonBox->addButton(newButton, QDialogButtonBox::ActionRole); connect(newButton, &QAbstractButton::clicked, this, &KBookmarkDialog::newFolderButton); setWindowTitle(tr("Select Folder", "@title:window")); d->url->setVisible(false); d->urlLabel->setVisible(false); d->title->setVisible(false); d->titleLabel->setVisible(false); d->comment->setVisible(false); d->commentLabel->setVisible(false); d->setParentBookmark(parent); d->folderTree->setVisible(true); d->mode = d->SelectFolder; if (exec() == QDialog::Accepted) { return d->bm.toGroup(); } else { return KBookmarkGroup(); } } KBookmarkGroup KBookmarkDialog::createNewFolder(const QString &name, KBookmark parent) { if (!d->layout) { d->initLayoutPrivate(); } if (parent.isNull()) { parent = d->mgr->root(); } setWindowTitle(tr("New Folder", "@title:window")); d->url->setVisible(false); d->urlLabel->setVisible(false); d->comment->setVisible(true); d->commentLabel->setVisible(true); d->comment->setText(QString()); d->title->setText(name); d->setParentBookmark(parent); d->folderTree->setVisible(true); d->mode = KBookmarkDialogPrivate::NewFolder; if (exec() == QDialog::Accepted) { return d->bm.toGroup(); } else { return KBookmarkGroup(); } } KBookmarkDialog::KBookmarkDialog(KBookmarkManager *mgr, QWidget *parent) : QDialog(parent) , d(new KBookmarkDialogPrivate(this)) { d->mgr = mgr; } KBookmarkDialog::~KBookmarkDialog() { delete d; } void KBookmarkDialog::newFolderButton() { QString caption = d->parentBookmark().fullText().isEmpty() ? tr("Create New Bookmark Folder", "@title:window") : tr("Create New Bookmark Folder in %1", "@title:window").arg(d->parentBookmark().text()); bool ok; QString text = QInputDialog::getText(this, caption, tr("New folder:", "@label:textbox"), QLineEdit::Normal, QString(), &ok); if (!ok) { return; } KBookmarkGroup group = d->parentBookmark().createNewFolder(text); if (!group.isNull()) { KBookmarkGroup parentGroup = group.parentGroup(); d->mgr->emitChanged(parentGroup); d->folderTree->clear(); QTreeWidgetItem *root = new KBookmarkTreeItem(d->folderTree); d->fillGroup(root, d->mgr->root(), group); } } /********************************************************************/ KBookmarkTreeItem::KBookmarkTreeItem(QTreeWidget *tree) : QTreeWidgetItem(tree), m_address(QLatin1String("")) { setText(0, KBookmarkDialog::tr("Bookmarks", "name of the container of all browser bookmarks")); - setIcon(0, SmallIcon(QStringLiteral("bookmarks"))); + setIcon(0, QIcon::fromTheme(QStringLiteral("bookmarks"))); tree->expandItem(this); tree->setCurrentItem(this); tree->setItemSelected(this, true); } KBookmarkTreeItem::KBookmarkTreeItem(QTreeWidgetItem *parent, QTreeWidget *tree, const KBookmarkGroup &bk) : QTreeWidgetItem(parent) { - setIcon(0, SmallIcon(bk.icon())); + setIcon(0, QIcon::fromTheme(bk.icon())); setText(0, bk.fullText()); tree->expandItem(this); m_address = bk.address(); } KBookmarkTreeItem::~KBookmarkTreeItem() { } QString KBookmarkTreeItem::address() { return m_address; }