diff --git a/src/kbookmarkcontextmenu.cpp b/src/kbookmarkcontextmenu.cpp index 7c6ebfc..8a225d1 100644 --- a/src/kbookmarkcontextmenu.cpp +++ b/src/kbookmarkcontextmenu.cpp @@ -1,193 +1,193 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Torben Weis Copyright (C) 2006 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 as published by the Free Software Foundation; either version 2 of the License, 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. */ #include "kbookmarkcontextmenu.h" #include "kbookmarkowner.h" #include "kbookmarkmanager.h" #include "kbookmarkdialog.h" #include #include #include #include KBookmarkContextMenu::KBookmarkContextMenu(const KBookmark &bk, KBookmarkManager *manager, KBookmarkOwner *owner, QWidget *parent) : QMenu(parent), bm(bk), m_pManager(manager), m_pOwner(owner) { connect(this, &QMenu::aboutToShow, this, &KBookmarkContextMenu::slotAboutToShow); } void KBookmarkContextMenu::slotAboutToShow() { addActions(); } void KBookmarkContextMenu::addActions() { if (bm.isGroup()) { addOpenFolderInTabs(); addBookmark(); addFolderActions(); } else { addBookmark(); addBookmarkActions(); } } KBookmarkContextMenu::~KBookmarkContextMenu() { } void KBookmarkContextMenu::addBookmark() { if (m_pOwner && m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark)) { - addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), tr("Add Bookmark Here"), this, SLOT(slotInsert())); + addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), tr("Add Bookmark Here"), this, &KBookmarkContextMenu::slotInsert); } } void KBookmarkContextMenu::addFolderActions() { - addAction(tr("Open Folder in Bookmark Editor"), this, SLOT(slotEditAt())); + addAction(tr("Open Folder in Bookmark Editor"), this, &KBookmarkContextMenu::slotEditAt); addProperties(); addSeparator(); - addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete Folder"), this, SLOT(slotRemove())); + addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete Folder"), this, &KBookmarkContextMenu::slotRemove); } void KBookmarkContextMenu::addProperties() { - addAction(tr("Properties"), this, SLOT(slotProperties())); + addAction(tr("Properties"), this, &KBookmarkContextMenu::slotProperties); } void KBookmarkContextMenu::addBookmarkActions() { - addAction(tr("Copy Link Address"), this, SLOT(slotCopyLocation())); + addAction(tr("Copy Link Address"), this, &KBookmarkContextMenu::slotCopyLocation); addProperties(); addSeparator(); - addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete Bookmark"), this, SLOT(slotRemove())); + addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete Bookmark"), this, &KBookmarkContextMenu::slotRemove); } void KBookmarkContextMenu::addOpenFolderInTabs() { if (m_pOwner->supportsTabs()) { - addAction(QIcon::fromTheme(QStringLiteral("tab-new")), tr("Open Folder in Tabs"), this, SLOT(slotOpenFolderInTabs())); + addAction(QIcon::fromTheme(QStringLiteral("tab-new")), tr("Open Folder in Tabs"), this, &KBookmarkContextMenu::slotOpenFolderInTabs); } } void KBookmarkContextMenu::slotEditAt() { // qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotEditAt" << m_highlightedAddress; m_pManager->slotEditBookmarksAtAddress(bm.address()); } void KBookmarkContextMenu::slotProperties() { // qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotProperties" << m_highlightedAddress; KBookmarkDialog *dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow()); dlg->editBookmark(bm); delete dlg; } void KBookmarkContextMenu::slotInsert() { // qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotInsert" << m_highlightedAddress; QUrl url = m_pOwner->currentUrl(); if (url.isEmpty()) { QMessageBox::critical(QApplication::activeWindow(), QApplication::applicationName(), tr("Cannot add bookmark with empty URL.")); return; } QString title = m_pOwner->currentTitle(); if (title.isEmpty()) { title = url.toDisplayString(); } if (bm.isGroup()) { KBookmarkGroup parentBookmark = bm.toGroup(); Q_ASSERT(!parentBookmark.isNull()); parentBookmark.addBookmark(title, url, m_pOwner->currentIcon()); m_pManager->emitChanged(parentBookmark); } else { KBookmarkGroup parentBookmark = bm.parentGroup(); Q_ASSERT(!parentBookmark.isNull()); KBookmark newBookmark = parentBookmark.addBookmark(title, m_pOwner->currentUrl(), m_pOwner->currentIcon()); parentBookmark.moveBookmark(newBookmark, parentBookmark.previous(bm)); m_pManager->emitChanged(parentBookmark); } } void KBookmarkContextMenu::slotRemove() { // qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotRemove" << m_highlightedAddress; bool folder = bm.isGroup(); if (QMessageBox::warning( QApplication::activeWindow(), folder ? tr("Bookmark Folder Deletion") : tr("Bookmark Deletion"), folder ? tr("Are you sure you wish to remove the bookmark folder\n\"%1\"?").arg(bm.text()) : tr("Are you sure you wish to remove the bookmark\n\"%1\"?").arg(bm.text()), QMessageBox::Yes | QMessageBox::Cancel) != QMessageBox::Yes ) { return; } KBookmarkGroup parentBookmark = bm.parentGroup(); parentBookmark.deleteBookmark(bm); m_pManager->emitChanged(parentBookmark); } void KBookmarkContextMenu::slotCopyLocation() { // qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotCopyLocation" << m_highlightedAddress; if (!bm.isGroup()) { QMimeData *mimeData = new QMimeData; bm.populateMimeData(mimeData); QApplication::clipboard()->setMimeData(mimeData, QClipboard::Selection); mimeData = new QMimeData; bm.populateMimeData(mimeData); QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard); } } void KBookmarkContextMenu::slotOpenFolderInTabs() { owner()->openFolderinTabs(bookmark().toGroup()); } KBookmarkManager *KBookmarkContextMenu::manager() const { return m_pManager; } KBookmarkOwner *KBookmarkContextMenu::owner() const { return m_pOwner; } KBookmark KBookmarkContextMenu::bookmark() const { return bm; } diff --git a/src/kbookmarkdialog.cpp b/src/kbookmarkdialog.cpp index 5a9d446..ef5ba85 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 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, SIGNAL(accepted()), q, SLOT(accept())); + 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"))); 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())); setText(0, bk.fullText()); tree->expandItem(this); m_address = bk.address(); } KBookmarkTreeItem::~KBookmarkTreeItem() { } QString KBookmarkTreeItem::address() { return m_address; } diff --git a/src/kbookmarkmenu.cpp b/src/kbookmarkmenu.cpp index 5b8873e..36630e7 100644 --- a/src/kbookmarkmenu.cpp +++ b/src/kbookmarkmenu.cpp @@ -1,536 +1,536 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Torben Weis Copyright (C) 2006 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 as published by the Free Software Foundation; either version 2 of the License, 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. */ #include "kbookmarkmenu.h" #include "kbookmarkmenu_p.h" #include "kbookmarkaction.h" #include "kbookmarkactionmenu.h" #include "kbookmarkcontextmenu.h" #include "kbookmarkdialog.h" #include "kbookmarkowner.h" #include #include #include #include #include #include "kbookmarks_debug.h" #include #include #include /********************************************************************/ /********************************************************************/ /********************************************************************/ class KBookmarkMenuPrivate { public: KBookmarkMenuPrivate() : newBookmarkFolder(nullptr), addAddBookmark(nullptr), bookmarksToFolder(nullptr) { } QAction *newBookmarkFolder; QAction *addAddBookmark; QAction *bookmarksToFolder; }; KBookmarkMenu::KBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *_owner, QMenu *_parentMenu, KActionCollection *actionCollection) : QObject(), m_actionCollection(actionCollection), d(new KBookmarkMenuPrivate()), m_bIsRoot(true), m_pManager(mgr), m_pOwner(_owner), m_parentMenu(_parentMenu), m_parentAddress(QLatin1String("")) //TODO KBookmarkAdress::root { // TODO KDE5 find a QMenu equvalnet for this one //m_parentMenu->setKeyboardShortcutsEnabled( true ); // qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::KBookmarkMenu " << this << " address : " << m_parentAddress; connect(_parentMenu, &QMenu::aboutToShow, this, &KBookmarkMenu::slotAboutToShow); if (KBookmarkSettings::self()->m_contextmenu) { m_parentMenu->setContextMenuPolicy(Qt::CustomContextMenu); connect(m_parentMenu, &QWidget::customContextMenuRequested, this, &KBookmarkMenu::slotCustomContextMenu); } connect(m_pManager, &KBookmarkManager::changed, this, &KBookmarkMenu::slotBookmarksChanged); m_bDirty = true; addActions(); } void KBookmarkMenu::addActions() { if (m_bIsRoot) { addAddBookmark(); addAddBookmarksList(); addNewFolder(); addEditBookmarks(); } else { if (!m_parentMenu->actions().isEmpty()) { m_parentMenu->addSeparator(); } addOpenInTabs(); addAddBookmark(); addAddBookmarksList(); addNewFolder(); } } KBookmarkMenu::KBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *_owner, QMenu *_parentMenu, const QString &parentAddress) : QObject(), m_actionCollection(new KActionCollection(this)), d(new KBookmarkMenuPrivate()), m_bIsRoot(false), m_pManager(mgr), m_pOwner(_owner), m_parentMenu(_parentMenu), m_parentAddress(parentAddress) { // TODO KDE5 find a QMenu equvalnet for this one //m_parentMenu->setKeyboardShortcutsEnabled( true ); connect(_parentMenu, &QMenu::aboutToShow, this, &KBookmarkMenu::slotAboutToShow); if (KBookmarkSettings::self()->m_contextmenu) { m_parentMenu->setContextMenuPolicy(Qt::CustomContextMenu); connect(m_parentMenu, &QWidget::customContextMenuRequested, this, &KBookmarkMenu::slotCustomContextMenu); } m_bDirty = true; } KBookmarkMenu::~KBookmarkMenu() { qDeleteAll(m_lstSubMenus); qDeleteAll(m_actions); delete d; } void KBookmarkMenu::ensureUpToDate() { slotAboutToShow(); } void KBookmarkMenu::slotAboutToShow() { // Did the bookmarks change since the last time we showed them ? if (m_bDirty) { m_bDirty = false; clear(); refill(); m_parentMenu->adjustSize(); } } void KBookmarkMenu::slotCustomContextMenu(const QPoint &pos) { QAction *action = m_parentMenu->actionAt(pos); QMenu *menu = contextMenu(action); if (!menu) { return; } menu->setAttribute(Qt::WA_DeleteOnClose); menu->popup(m_parentMenu->mapToGlobal(pos)); } QMenu *KBookmarkMenu::contextMenu(QAction *action) { KBookmarkActionInterface *act = dynamic_cast(action); if (!act) { return nullptr; } return new KBookmarkContextMenu(act->bookmark(), m_pManager, m_pOwner); } bool KBookmarkMenu::isRoot() const { return m_bIsRoot; } bool KBookmarkMenu::isDirty() const { return m_bDirty; } QString KBookmarkMenu::parentAddress() const { return m_parentAddress; } KBookmarkManager *KBookmarkMenu::manager() const { return m_pManager; } KBookmarkOwner *KBookmarkMenu::owner() const { return m_pOwner; } QMenu *KBookmarkMenu::parentMenu() const { return m_parentMenu; } /********************************************************************/ /********************************************************************/ /********************************************************************/ /********************************************************************/ /********************************************************************/ /********************************************************************/ void KBookmarkMenu::slotBookmarksChanged(const QString &groupAddress) { qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotBookmarksChanged groupAddress: " << groupAddress; if (groupAddress == m_parentAddress) { //qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::slotBookmarksChanged -> setting m_bDirty on " << groupAddress; m_bDirty = true; } else { // Iterate recursively into child menus for (QList::iterator it = m_lstSubMenus.begin(), end = m_lstSubMenus.end(); it != end; ++it) { (*it)->slotBookmarksChanged(groupAddress); } } } void KBookmarkMenu::clear() { qDeleteAll(m_lstSubMenus); m_lstSubMenus.clear(); for (QList::iterator it = m_actions.begin(), end = m_actions.end(); it != end; ++it) { m_parentMenu->removeAction(*it); delete *it; } m_parentMenu->clear(); m_actions.clear(); } void KBookmarkMenu::refill() { //qCDebug(KBOOKMARKS_LOG) << "KBookmarkMenu::refill()"; if (m_bIsRoot) { addActions(); } fillBookmarks(); if (!m_bIsRoot) { addActions(); } } void KBookmarkMenu::addOpenInTabs() { if (!m_pOwner || !m_pOwner->supportsTabs() || !KAuthorized::authorizeAction(QStringLiteral("bookmarks"))) { return; } QString title = tr("Open Folder in Tabs"); QAction *paOpenFolderInTabs = new QAction(title, this); paOpenFolderInTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); paOpenFolderInTabs->setToolTip(tr("Open all bookmarks in this folder as a new tab.")); paOpenFolderInTabs->setStatusTip(paOpenFolderInTabs->toolTip()); connect(paOpenFolderInTabs, &QAction::triggered, this, &KBookmarkMenu::slotOpenFolderInTabs); m_parentMenu->addAction(paOpenFolderInTabs); m_actions.append(paOpenFolderInTabs); } void KBookmarkMenu::addAddBookmarksList() { if (!m_pOwner || !m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark) || !m_pOwner->supportsTabs() || !KAuthorized::authorizeAction(QStringLiteral("bookmarks"))) { return; } if (d->bookmarksToFolder == nullptr) { QString title = tr("Bookmark Tabs as Folder..."); d->bookmarksToFolder = new QAction(title, this); m_actionCollection->addAction(m_bIsRoot ? QStringLiteral("add_bookmarks_list") : QString(), d->bookmarksToFolder); d->bookmarksToFolder->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new-list"))); d->bookmarksToFolder->setToolTip(tr("Add a folder of bookmarks for all open tabs.")); d->bookmarksToFolder->setStatusTip(d->bookmarksToFolder->toolTip()); connect(d->bookmarksToFolder, &QAction::triggered, this, &KBookmarkMenu::slotAddBookmarksList); } m_parentMenu->addAction(d->bookmarksToFolder); } void KBookmarkMenu::addAddBookmark() { if (!m_pOwner || !m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark) || !KAuthorized::authorizeAction(QStringLiteral("bookmarks"))) { return; } if (d->addAddBookmark == nullptr) { d->addAddBookmark = m_actionCollection->addAction( KStandardAction::AddBookmark, m_bIsRoot ? QStringLiteral("add_bookmark") : QString(), this, SLOT(slotAddBookmark())); if (!m_bIsRoot) { d->addAddBookmark->setShortcut(QKeySequence()); } } m_parentMenu->addAction(d->addAddBookmark); } void KBookmarkMenu::addEditBookmarks() { if ((m_pOwner && !m_pOwner->enableOption(KBookmarkOwner::ShowEditBookmark)) || QStandardPaths::findExecutable(QStringLiteral(KEDITBOOKMARKS_BINARY)).isEmpty() || !KAuthorized::authorizeKAction(QStringLiteral("bookmarks"))) { return; } QAction *m_paEditBookmarks = m_actionCollection->addAction(KStandardAction::EditBookmarks, QStringLiteral("edit_bookmarks"), m_pManager, SLOT(slotEditBookmarks())); m_parentMenu->addAction(m_paEditBookmarks); m_paEditBookmarks->setToolTip(tr("Edit your bookmark collection in a separate window")); m_paEditBookmarks->setStatusTip(m_paEditBookmarks->toolTip()); } void KBookmarkMenu::addNewFolder() { if (!m_pOwner || !m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark) || !KAuthorized::authorizeAction(QStringLiteral("bookmarks"))) { return; } if (d->newBookmarkFolder == nullptr) { d->newBookmarkFolder = new QAction(tr("New Bookmark Folder..."), this); d->newBookmarkFolder->setIcon(QIcon::fromTheme(QStringLiteral("folder-new"))); d->newBookmarkFolder->setToolTip(tr("Create a new bookmark folder in this menu")); d->newBookmarkFolder->setStatusTip(d->newBookmarkFolder->toolTip()); connect(d->newBookmarkFolder, &QAction::triggered, this, &KBookmarkMenu::slotNewFolder); } m_parentMenu->addAction(d->newBookmarkFolder); } void KBookmarkMenu::fillBookmarks() { KBookmarkGroup parentBookmark = m_pManager->findByAddress(m_parentAddress).toGroup(); Q_ASSERT(!parentBookmark.isNull()); if (m_bIsRoot && !parentBookmark.first().isNull()) { // at least one bookmark m_parentMenu->addSeparator(); } for (KBookmark bm = parentBookmark.first(); !bm.isNull(); bm = parentBookmark.next(bm)) { m_parentMenu->addAction(actionForBookmark(bm)); } } QAction *KBookmarkMenu::actionForBookmark(const KBookmark &bm) { if (bm.isGroup()) { //qCDebug(KBOOKMARKS_LOG) << "Creating bookmark submenu named " << bm.text(); KActionMenu *actionMenu = new KBookmarkActionMenu(bm, this); m_actions.append(actionMenu); KBookmarkMenu *subMenu = new KBookmarkMenu(m_pManager, m_pOwner, actionMenu->menu(), bm.address()); m_lstSubMenus.append(subMenu); return actionMenu; } else if (bm.isSeparator()) { QAction *sa = new QAction(this); sa->setSeparator(true); m_actions.append(sa); return sa; } else { //qCDebug(KBOOKMARKS_LOG) << "Creating bookmark menu item for " << bm.text(); QAction *action = new KBookmarkAction(bm, m_pOwner, this); m_actions.append(action); return action; } } void KBookmarkMenu::slotAddBookmarksList() { if (!m_pOwner || !m_pOwner->supportsTabs()) { return; } KBookmarkGroup parentBookmark = m_pManager->findByAddress(m_parentAddress).toGroup(); KBookmarkDialog *dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow()); dlg->addBookmarks(m_pOwner->currentBookmarkList(), QLatin1String(""), parentBookmark); delete dlg; } void KBookmarkMenu::slotAddBookmark() { if (!m_pOwner) { return; } if (m_pOwner->currentTitle().isEmpty() && m_pOwner->currentUrl().isEmpty()) { return; } KBookmarkGroup parentBookmark = m_pManager->findByAddress(m_parentAddress).toGroup(); if (KBookmarkSettings::self()->m_advancedaddbookmark) { KBookmarkDialog *dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow()); dlg->addBookmark(m_pOwner->currentTitle(), m_pOwner->currentUrl(), m_pOwner->currentIcon(), parentBookmark); delete dlg; } else { parentBookmark.addBookmark(m_pOwner->currentTitle(), m_pOwner->currentUrl(), m_pOwner->currentIcon()); m_pManager->emitChanged(parentBookmark); } } void KBookmarkMenu::slotOpenFolderInTabs() { m_pOwner->openFolderinTabs(m_pManager->findByAddress(m_parentAddress).toGroup()); } void KBookmarkMenu::slotNewFolder() { if (!m_pOwner) { return; // this view doesn't handle bookmarks... } KBookmarkGroup parentBookmark = m_pManager->findByAddress(m_parentAddress).toGroup(); Q_ASSERT(!parentBookmark.isNull()); KBookmarkDialog *dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow()); dlg->createNewFolder(QLatin1String(""), parentBookmark); delete dlg; } void KImportedBookmarkMenu::slotNSLoad() { // qCDebug(KBOOKMARKS_LOG)<<"**** slotNSLoad ****"<disconnect(SIGNAL(aboutToShow())); + disconnect(parentMenu(), &QMenu::aboutToShow, nullptr, nullptr); // not NSImporter, but kept old name for BC reasons KBookmarkMenuImporter importer(manager(), this); importer.openBookmarks(m_location, m_type); } KImportedBookmarkMenu::KImportedBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, const QString &type, const QString &location) : KBookmarkMenu(mgr, owner, parentMenu, QString()), m_type(type), m_location(location) { connect(parentMenu, &QMenu::aboutToShow, this, &KImportedBookmarkMenu::slotNSLoad); } KImportedBookmarkMenu::KImportedBookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu) : KBookmarkMenu(mgr, owner, parentMenu, QString()), m_type(QString()), m_location(QString()) { } KImportedBookmarkMenu::~KImportedBookmarkMenu() { } void KImportedBookmarkMenu::refill() { } void KImportedBookmarkMenu::clear() { } /********************************************************************/ /********************************************************************/ /********************************************************************/ void KBookmarkMenuImporter::openBookmarks(const QString &location, const QString &type) { mstack.push(m_menu); KBookmarkImporterBase *importer = KBookmarkImporterBase::factory(type); if (!importer) { return; } importer->setFilename(location); connectToImporter(*importer); importer->parse(); delete importer; } void KBookmarkMenuImporter::connectToImporter(const QObject &importer) { connect(&importer, SIGNAL(newBookmark(QString,QString,QString)), SLOT(newBookmark(QString,QString,QString))); connect(&importer, SIGNAL(newFolder(QString,bool,QString)), SLOT(newFolder(QString,bool,QString))); connect(&importer, SIGNAL(newSeparator()), SLOT(newSeparator())); connect(&importer, SIGNAL(endFolder()), SLOT(endFolder())); } void KBookmarkMenuImporter::newBookmark(const QString &text, const QString &url, const QString &) { KBookmark bm = KBookmark::standaloneBookmark(text, QUrl(url), QStringLiteral("html")); QAction *action = new KBookmarkAction(bm, mstack.top()->owner(), this); mstack.top()->parentMenu()->addAction(action); mstack.top()->m_actions.append(action); } void KBookmarkMenuImporter::newFolder(const QString &text, bool, const QString &) { QString _text = KStringHandler::csqueeze(text).replace(QLatin1Char('&'), QLatin1String("&&")); KActionMenu *actionMenu = new KImportedBookmarkActionMenu(QIcon::fromTheme(QStringLiteral("folder")), _text, this); mstack.top()->parentMenu()->addAction(actionMenu); mstack.top()->m_actions.append(actionMenu); KImportedBookmarkMenu *subMenu = new KImportedBookmarkMenu(m_pManager, m_menu->owner(), actionMenu->menu()); mstack.top()->m_lstSubMenus.append(subMenu); mstack.push(subMenu); } void KBookmarkMenuImporter::newSeparator() { mstack.top()->parentMenu()->addSeparator(); } void KBookmarkMenuImporter::endFolder() { mstack.pop(); } #include "moc_kbookmarkmenu.cpp" #include "moc_kbookmarkmenu_p.cpp"