Warning, file /utilities/keditbookmarks/src/actionsimpl.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // -*- indent-tabs-mode:nil -*-
0002 // vim: set ts=4 sts=4 sw=4 et:
0003 /* This file is part of the KDE project
0004    Copyright (C) 2000 David Faure <faure@kde.org>
0005    Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
0006 
0007    This program is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU General Public
0009    License version 2 as published by the Free Software Foundation.
0010 
0011    This program is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    General Public License for more details.
0015 
0016    You should have received a copy of the GNU General Public License
0017    along with this program; see the file COPYING.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "actionsimpl.h"
0023 #include "globalbookmarkmanager.h"
0024 
0025 #include "bookmarkinfowidget.h"
0026 #include "exporters.h"
0027 #include "favicons.h"
0028 #include "importers.h"
0029 #include "kbookmarkmodel/commandhistory.h"
0030 #include "kbookmarkmodel/commands.h"
0031 #include "kbookmarkmodel/model.h"
0032 #include "testlink.h"
0033 #include "toplevel.h" // for KEBApp
0034 
0035 #include <stdlib.h>
0036 
0037 #include "keditbookmarks_debug.h"
0038 
0039 #include <QApplication>
0040 #include <QClipboard>
0041 #include <QFileDialog>
0042 #include <QMimeData>
0043 
0044 #include <KActionCollection>
0045 #include <kio_version.h>
0046 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
0047 #include <KIO/JobUiDelegateFactory>
0048 #else
0049 #include <KIO/JobUiDelegate>
0050 #endif
0051 #include <KIO/OpenUrlJob>
0052 #include <KIconDialog>
0053 #include <KIconLoader>
0054 #include <KLocalizedString>
0055 #include <KStandardAction>
0056 #include <QIcon>
0057 
0058 #include <QInputDialog>
0059 
0060 #include <KBookmark>
0061 #include <KBookmarkManager>
0062 #include <kbookmarkimporter.h>
0063 
0064 #include <kbookmarkexporter.h>
0065 #include <kbookmarkimporter_ie.h>
0066 #include <kbookmarkimporter_ns.h>
0067 #include <kbookmarkimporter_opera.h>
0068 
0069 // decoupled from resetActions in toplevel.cpp
0070 // as resetActions simply uses the action groups
0071 // specified in the ui.rc file
0072 void KEBApp::createActions()
0073 {
0074     m_actionsImpl = new ActionsImpl(this, GlobalBookmarkManager::self()->model());
0075 
0076     connect(m_actionsImpl->testLinkHolder(), &BookmarkIteratorHolder::setCancelEnabled, this, &KEBApp::setCancelTestsEnabled);
0077     connect(m_actionsImpl->favIconHolder(), &BookmarkIteratorHolder::setCancelEnabled, this, &KEBApp::setCancelFavIconUpdatesEnabled);
0078 
0079     // save and quit should probably not be in the toplevel???
0080     (void)KStandardAction::quit(this, SLOT(close()), actionCollection());
0081 
0082     KStandardAction::keyBindings(guiFactory(), &KXMLGUIFactory::showConfigureShortcutsDialog, actionCollection());
0083 
0084     (void)KStandardAction::configureToolbars(this, SLOT(slotConfigureToolbars()), actionCollection());
0085 
0086     if (m_browser) {
0087         (void)KStandardAction::open(m_actionsImpl, SLOT(slotLoad()), actionCollection());
0088         (void)KStandardAction::saveAs(m_actionsImpl, SLOT(slotSaveAs()), actionCollection());
0089     }
0090 
0091     (void)KStandardAction::cut(m_actionsImpl, SLOT(slotCut()), actionCollection());
0092     (void)KStandardAction::copy(m_actionsImpl, SLOT(slotCopy()), actionCollection());
0093     (void)KStandardAction::paste(m_actionsImpl, SLOT(slotPaste()), actionCollection());
0094 
0095     // actions
0096     QAction *m_actionsImplDelete = actionCollection()->addAction(QStringLiteral("delete"));
0097     m_actionsImplDelete->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
0098     m_actionsImplDelete->setText(i18n("&Delete"));
0099     actionCollection()->setDefaultShortcut(m_actionsImplDelete, Qt::Key_Delete);
0100     connect(m_actionsImplDelete, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotDelete);
0101 
0102     QAction *m_actionsImplRename = actionCollection()->addAction(QStringLiteral("rename"));
0103     m_actionsImplRename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
0104     m_actionsImplRename->setText(i18n("Rename"));
0105     actionCollection()->setDefaultShortcut(m_actionsImplRename, Qt::Key_F2);
0106     connect(m_actionsImplRename, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotRename);
0107 
0108     QAction *m_actionsImplChangeURL = actionCollection()->addAction(QStringLiteral("changeurl"));
0109     m_actionsImplChangeURL->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
0110     m_actionsImplChangeURL->setText(i18n("C&hange Location"));
0111     actionCollection()->setDefaultShortcut(m_actionsImplChangeURL, Qt::Key_F3);
0112     connect(m_actionsImplChangeURL, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotChangeURL);
0113 
0114     QAction *m_actionsImplChangeComment = actionCollection()->addAction(QStringLiteral("changecomment"));
0115     m_actionsImplChangeComment->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
0116     m_actionsImplChangeComment->setText(i18n("C&hange Comment"));
0117     actionCollection()->setDefaultShortcut(m_actionsImplChangeComment, Qt::Key_F4);
0118     connect(m_actionsImplChangeComment, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotChangeComment);
0119 
0120     QAction *m_actionsImplChangeIcon = actionCollection()->addAction(QStringLiteral("changeicon"));
0121     m_actionsImplChangeIcon->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-icons")));
0122     m_actionsImplChangeIcon->setText(i18n("Chan&ge Icon..."));
0123     connect(m_actionsImplChangeIcon, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotChangeIcon);
0124 
0125     QAction *m_actionsImplUpdateFavIcon = actionCollection()->addAction(QStringLiteral("updatefavicon"));
0126     m_actionsImplUpdateFavIcon->setText(i18n("Update Favicon"));
0127     connect(m_actionsImplUpdateFavIcon, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotUpdateFavIcon);
0128 
0129     QAction *m_actionsImplRecursiveSort = actionCollection()->addAction(QStringLiteral("recursivesort"));
0130     m_actionsImplRecursiveSort->setText(i18n("Recursive Sort"));
0131     connect(m_actionsImplRecursiveSort, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotRecursiveSort);
0132 
0133     QAction *m_actionsImplNewFolder = actionCollection()->addAction(QStringLiteral("newfolder"));
0134     m_actionsImplNewFolder->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
0135     m_actionsImplNewFolder->setText(i18n("&New Folder..."));
0136     actionCollection()->setDefaultShortcut(m_actionsImplNewFolder, Qt::CTRL | Qt::Key_N);
0137     connect(m_actionsImplNewFolder, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotNewFolder);
0138 
0139     QAction *m_actionsImplNewBookmark = actionCollection()->addAction(QStringLiteral("newbookmark"));
0140     m_actionsImplNewBookmark->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
0141     m_actionsImplNewBookmark->setText(i18n("&New Bookmark"));
0142     connect(m_actionsImplNewBookmark, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotNewBookmark);
0143 
0144     QAction *m_actionsImplInsertSeparator = actionCollection()->addAction(QStringLiteral("insertseparator"));
0145     m_actionsImplInsertSeparator->setText(i18n("&Insert Separator"));
0146     actionCollection()->setDefaultShortcut(m_actionsImplInsertSeparator, Qt::CTRL | Qt::Key_I);
0147     connect(m_actionsImplInsertSeparator, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotInsertSeparator);
0148 
0149     QAction *m_actionsImplSort = actionCollection()->addAction(QStringLiteral("sort"));
0150     m_actionsImplSort->setText(i18n("&Sort Alphabetically"));
0151     connect(m_actionsImplSort, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotSort);
0152 
0153     QAction *m_actionsImplSetAsToolbar = actionCollection()->addAction(QStringLiteral("setastoolbar"));
0154     m_actionsImplSetAsToolbar->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-toolbar")));
0155     m_actionsImplSetAsToolbar->setText(i18n("Set as T&oolbar Folder"));
0156     connect(m_actionsImplSetAsToolbar, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotSetAsToolbar);
0157 
0158     QAction *m_actionsImplExpandAll = actionCollection()->addAction(QStringLiteral("expandall"));
0159     m_actionsImplExpandAll->setText(i18n("&Expand All Folders"));
0160     connect(m_actionsImplExpandAll, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotExpandAll);
0161 
0162     QAction *m_actionsImplCollapseAll = actionCollection()->addAction(QStringLiteral("collapseall"));
0163     m_actionsImplCollapseAll->setText(i18n("Collapse &All Folders"));
0164     connect(m_actionsImplCollapseAll, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotCollapseAll);
0165 
0166     QAction *m_actionsImplOpenLink = actionCollection()->addAction(QStringLiteral("openlink"));
0167     m_actionsImplOpenLink->setIcon(QIcon::fromTheme(QStringLiteral("internet-web-browser")));
0168     m_actionsImplOpenLink->setText(i18n("&Open in Browser"));
0169     connect(m_actionsImplOpenLink, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotOpenLink);
0170 
0171     QAction *m_actionsImplTestSelection = actionCollection()->addAction(QStringLiteral("testlink"));
0172     m_actionsImplTestSelection->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
0173     m_actionsImplTestSelection->setText(i18n("Check &Status"));
0174     connect(m_actionsImplTestSelection, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotTestSelection);
0175 
0176     QAction *m_actionsImplTestAll = actionCollection()->addAction(QStringLiteral("testall"));
0177     m_actionsImplTestAll->setText(i18n("Check Status: &All"));
0178     connect(m_actionsImplTestAll, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotTestAll);
0179 
0180     QAction *m_actionsImplUpdateAllFavIcons = actionCollection()->addAction(QStringLiteral("updateallfavicons"));
0181     m_actionsImplUpdateAllFavIcons->setText(i18n("Update All &Favicons"));
0182     connect(m_actionsImplUpdateAllFavIcons, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotUpdateAllFavIcons);
0183 
0184     QAction *m_actionsImplCancelAllTests = actionCollection()->addAction(QStringLiteral("canceltests"));
0185     m_actionsImplCancelAllTests->setText(i18n("Cancel &Checks"));
0186     connect(m_actionsImplCancelAllTests, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotCancelAllTests);
0187 
0188     QAction *m_actionsImplCancelFavIconUpdates = actionCollection()->addAction(QStringLiteral("cancelfaviconupdates"));
0189     m_actionsImplCancelFavIconUpdates->setText(i18n("Cancel &Favicon Updates"));
0190     connect(m_actionsImplCancelFavIconUpdates, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotCancelFavIconUpdates);
0191 
0192     QAction *m_actionsImplImportNS = actionCollection()->addAction(QStringLiteral("importNS"));
0193     m_actionsImplImportNS->setObjectName(QStringLiteral("NS"));
0194     m_actionsImplImportNS->setIcon(QIcon::fromTheme(QStringLiteral("netscape")));
0195     m_actionsImplImportNS->setText(i18n("Import &Netscape Bookmarks..."));
0196     connect(m_actionsImplImportNS, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0197 
0198     QAction *m_actionsImplImportOpera = actionCollection()->addAction(QStringLiteral("importOpera"));
0199     m_actionsImplImportOpera->setObjectName(QStringLiteral("Opera"));
0200     m_actionsImplImportOpera->setIcon(QIcon::fromTheme(QStringLiteral("opera")));
0201     m_actionsImplImportOpera->setText(i18n("Import &Opera Bookmarks..."));
0202     connect(m_actionsImplImportOpera, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0203     /*
0204         KAction* m_actionsImplImportCrashes = actionCollection()->addAction("importCrashes");
0205         m_actionsImplImportCrashes->setObjectName( QLatin1String("Crashes" ));
0206         m_actionsImplImportCrashes->setText(i18n("Import All &Crash Sessions as Bookmarks..."));
0207         connect(m_actionsImplImportCrashes, &KAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0208     */
0209     QAction *m_actionsImplImportGaleon = actionCollection()->addAction(QStringLiteral("importGaleon"));
0210     m_actionsImplImportGaleon->setObjectName(QStringLiteral("Galeon"));
0211     m_actionsImplImportGaleon->setText(i18n("Import &Galeon Bookmarks..."));
0212     connect(m_actionsImplImportGaleon, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0213 
0214     QAction *m_actionsImplImportKDE2 = actionCollection()->addAction(QStringLiteral("importKDE2"));
0215     m_actionsImplImportKDE2->setObjectName(QStringLiteral("KDE2"));
0216     m_actionsImplImportKDE2->setIcon(QIcon::fromTheme(QStringLiteral("kde")));
0217     m_actionsImplImportKDE2->setText(i18n("Import &KDE 2 or KDE 3 Bookmarks..."));
0218 
0219     connect(m_actionsImplImportKDE2, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0220 
0221     QAction *m_actionsImplImportIE = actionCollection()->addAction(QStringLiteral("importIE"));
0222     m_actionsImplImportIE->setObjectName(QStringLiteral("IE"));
0223     m_actionsImplImportIE->setText(i18n("Import &Internet Explorer Bookmarks..."));
0224     connect(m_actionsImplImportIE, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0225 
0226     QAction *m_actionsImplImportMoz = actionCollection()->addAction(QStringLiteral("importMoz"));
0227     m_actionsImplImportMoz->setObjectName(QStringLiteral("Moz"));
0228     m_actionsImplImportMoz->setIcon(QIcon::fromTheme(QStringLiteral("mozilla")));
0229     m_actionsImplImportMoz->setText(i18n("Import &Mozilla Bookmarks..."));
0230     connect(m_actionsImplImportMoz, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotImport);
0231 
0232     QAction *m_actionsImplExportNS = actionCollection()->addAction(QStringLiteral("exportNS"));
0233     m_actionsImplExportNS->setIcon(QIcon::fromTheme(QStringLiteral("netscape")));
0234     m_actionsImplExportNS->setText(i18n("Export &Netscape Bookmarks"));
0235     connect(m_actionsImplExportNS, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotExportNS);
0236 
0237     QAction *m_actionsImplExportOpera = actionCollection()->addAction(QStringLiteral("exportOpera"));
0238     m_actionsImplExportOpera->setIcon(QIcon::fromTheme(QStringLiteral("opera")));
0239     m_actionsImplExportOpera->setText(i18n("Export &Opera Bookmarks..."));
0240     connect(m_actionsImplExportOpera, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotExportOpera);
0241 
0242     QAction *m_actionsImplExportHTML = actionCollection()->addAction(QStringLiteral("exportHTML"));
0243     m_actionsImplExportHTML->setIcon(QIcon::fromTheme(QStringLiteral("text-html")));
0244     m_actionsImplExportHTML->setText(i18n("Export &HTML Bookmarks..."));
0245     connect(m_actionsImplExportHTML, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotExportHTML);
0246 
0247     QAction *m_actionsImplExportIE = actionCollection()->addAction(QStringLiteral("exportIE"));
0248     m_actionsImplExportIE->setText(i18n("Export &Internet Explorer Bookmarks..."));
0249     connect(m_actionsImplExportIE, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotExportIE);
0250 
0251     QAction *m_actionsImplExportMoz = actionCollection()->addAction(QStringLiteral("exportMoz"));
0252     m_actionsImplExportMoz->setIcon(QIcon::fromTheme(QStringLiteral("mozilla")));
0253     m_actionsImplExportMoz->setText(i18n("Export &Mozilla Bookmarks..."));
0254     connect(m_actionsImplExportMoz, &QAction::triggered, m_actionsImpl, &ActionsImpl::slotExportMoz);
0255 }
0256 
0257 ActionsImpl::ActionsImpl(QObject *parent, KBookmarkModel *model)
0258     : QObject(parent)
0259     , m_model(model)
0260     , m_testLinkHolder(new TestLinkItrHolder(this, model))
0261     , m_favIconHolder(new FavIconsItrHolder(this, model))
0262 {
0263     Q_ASSERT(m_model);
0264 }
0265 
0266 void ActionsImpl::slotLoad()
0267 {
0268     const QString bookmarksFile = QFileDialog::getOpenFileName(KEBApp::self(), QString(), QString(), QStringLiteral("KDE Bookmark Files (*.xml)"));
0269     if (bookmarksFile.isNull())
0270         return;
0271     KEBApp::self()->reset(QString(), bookmarksFile);
0272 }
0273 
0274 void ActionsImpl::slotSaveAs()
0275 {
0276     KEBApp::self()->bkInfo()->commitChanges();
0277     const QString saveFilename = QFileDialog::getSaveFileName(KEBApp::self(), QString(), QString(), QStringLiteral("KDE Bookmark Files (*.xml)"));
0278     if (!saveFilename.isEmpty())
0279         GlobalBookmarkManager::self()->saveAs(saveFilename);
0280 }
0281 
0282 void GlobalBookmarkManager::doExport(ExportType type, const QString &_path)
0283 {
0284     // it can be null when we use command line to export => there is not interface
0285     if (KEBApp::self() && KEBApp::self()->bkInfo())
0286         KEBApp::self()->bkInfo()->commitChanges();
0287     QString path(_path);
0288     // TODO - add a factory and make all this use the base class
0289     if (type == OperaExport) {
0290         if (path.isNull())
0291             path = KOperaBookmarkImporterImpl().findDefaultLocation(true);
0292         KOperaBookmarkExporterImpl exporter(mgr(), path);
0293         exporter.write(mgr()->root());
0294         return;
0295 
0296     } else if (type == HTMLExport) {
0297         if (path.isNull())
0298             path = QFileDialog::getSaveFileName(KEBApp::self(), QString(), QDir::homePath(), i18n("HTML Bookmark Listing (*.html)"));
0299         HTMLExporter exporter;
0300         exporter.write(mgr()->root(), path);
0301         return;
0302 
0303     } else if (type == IEExport) {
0304         if (path.isNull())
0305             path = KIEBookmarkImporterImpl().findDefaultLocation(true);
0306         KIEBookmarkExporterImpl exporter(mgr(), path);
0307         exporter.write(mgr()->root());
0308         return;
0309     }
0310 
0311     bool moz = (type == MozillaExport);
0312 
0313     if (path.isNull()) {
0314         if (moz) {
0315             KMozillaBookmarkImporterImpl importer;
0316             path = importer.findDefaultLocation(true);
0317         } else {
0318             KNSBookmarkImporterImpl importer;
0319             path = importer.findDefaultLocation(true);
0320         }
0321     }
0322 
0323     if (!path.isEmpty()) {
0324         KNSBookmarkExporterImpl exporter(mgr(), path);
0325         exporter.write(mgr()->root());
0326     }
0327 }
0328 
0329 void KEBApp::setCancelFavIconUpdatesEnabled(bool enabled)
0330 {
0331     actionCollection()->action(QStringLiteral("cancelfaviconupdates"))->setEnabled(enabled);
0332 }
0333 
0334 void KEBApp::setCancelTestsEnabled(bool enabled)
0335 {
0336     actionCollection()->action(QStringLiteral("canceltests"))->setEnabled(enabled);
0337 }
0338 
0339 void ActionsImpl::slotCut()
0340 {
0341     KEBApp::self()->bkInfo()->commitChanges();
0342     slotCopy();
0343     DeleteManyCommand *mcmd = new DeleteManyCommand(m_model, i18nc("(qtundo-format)", "Cut Items"), KEBApp::self()->selectedBookmarks());
0344     commandHistory()->addCommand(mcmd);
0345 }
0346 
0347 void ActionsImpl::slotCopy()
0348 {
0349     KEBApp::self()->bkInfo()->commitChanges();
0350     // this is not a command, because it can't be undone
0351     KBookmark::List bookmarks = KEBApp::self()->selectedBookmarksExpanded();
0352     QMimeData *mimeData = new QMimeData;
0353     bookmarks.populateMimeData(mimeData);
0354     QApplication::clipboard()->setMimeData(mimeData);
0355 }
0356 
0357 void ActionsImpl::slotPaste()
0358 {
0359     KEBApp::self()->bkInfo()->commitChanges();
0360 
0361     QString addr;
0362     KBookmark bk = KEBApp::self()->firstSelected();
0363     if (bk.isGroup())
0364         addr = bk.address() + QStringLiteral("/0"); // FIXME internal
0365     else
0366         addr = bk.address();
0367 
0368     QUndoCommand *mcmd = CmdGen::insertMimeSource(m_model, i18nc("(qtundo-format)", "Paste"), QApplication::clipboard()->mimeData(), addr);
0369     commandHistory()->addCommand(mcmd);
0370 }
0371 
0372 /* -------------------------------------- */
0373 
0374 void ActionsImpl::slotNewFolder()
0375 {
0376     KEBApp::self()->bkInfo()->commitChanges();
0377     bool ok;
0378     QString str =
0379         QInputDialog::getText(KEBApp::self(), i18n("New folder:"), i18nc("@title:window", "Create New Bookmark Folder"), QLineEdit::Normal, QString(), &ok);
0380     if (!ok)
0381         return;
0382 
0383     CreateCommand *cmd = new CreateCommand(m_model, KEBApp::self()->insertAddress(), str, QStringLiteral("bookmark_folder"), /*open*/ true);
0384     commandHistory()->addCommand(cmd);
0385 }
0386 
0387 void ActionsImpl::slotNewBookmark()
0388 {
0389     KEBApp::self()->bkInfo()->commitChanges();
0390     // TODO - make a setCurrentItem(Command *) which uses finaladdress interface
0391     CreateCommand *cmd = new CreateCommand(m_model, KEBApp::self()->insertAddress(), QString(), QStringLiteral("www"), QUrl(QStringLiteral("http://")));
0392     commandHistory()->addCommand(cmd);
0393 }
0394 
0395 void ActionsImpl::slotInsertSeparator()
0396 {
0397     KEBApp::self()->bkInfo()->commitChanges();
0398     CreateCommand *cmd = new CreateCommand(m_model, KEBApp::self()->insertAddress());
0399     commandHistory()->addCommand(cmd);
0400 }
0401 
0402 void ActionsImpl::slotImport()
0403 {
0404     KEBApp::self()->bkInfo()->commitChanges();
0405     qCDebug(KEDITBOOKMARKS_LOG) << "ActionsImpl::slotImport() where sender()->name() == " << sender()->objectName();
0406     ImportCommand *import = ImportCommand::performImport(m_model, sender()->objectName(), KEBApp::self());
0407     if (!import)
0408         return;
0409     commandHistory()->addCommand(import);
0410     // FIXME select import->groupAddress
0411 }
0412 
0413 // TODO - this is getting ugly and repetitive. cleanup!
0414 
0415 void ActionsImpl::slotExportOpera()
0416 {
0417     KEBApp::self()->bkInfo()->commitChanges();
0418     GlobalBookmarkManager::self()->doExport(GlobalBookmarkManager::OperaExport);
0419 }
0420 void ActionsImpl::slotExportHTML()
0421 {
0422     KEBApp::self()->bkInfo()->commitChanges();
0423     GlobalBookmarkManager::self()->doExport(GlobalBookmarkManager::HTMLExport);
0424 }
0425 void ActionsImpl::slotExportIE()
0426 {
0427     KEBApp::self()->bkInfo()->commitChanges();
0428     GlobalBookmarkManager::self()->doExport(GlobalBookmarkManager::IEExport);
0429 }
0430 void ActionsImpl::slotExportNS()
0431 {
0432     KEBApp::self()->bkInfo()->commitChanges();
0433     GlobalBookmarkManager::self()->doExport(GlobalBookmarkManager::NetscapeExport);
0434 }
0435 void ActionsImpl::slotExportMoz()
0436 {
0437     KEBApp::self()->bkInfo()->commitChanges();
0438     GlobalBookmarkManager::self()->doExport(GlobalBookmarkManager::MozillaExport);
0439 }
0440 
0441 /* -------------------------------------- */
0442 
0443 void ActionsImpl::slotCancelFavIconUpdates()
0444 {
0445     m_favIconHolder->cancelAllItrs();
0446 }
0447 
0448 void ActionsImpl::slotCancelAllTests()
0449 {
0450     m_testLinkHolder->cancelAllItrs();
0451 }
0452 
0453 void ActionsImpl::slotTestAll()
0454 {
0455     m_testLinkHolder->insertIterator(new TestLinkItr(m_testLinkHolder, KEBApp::self()->allBookmarks()));
0456 }
0457 
0458 void ActionsImpl::slotUpdateAllFavIcons()
0459 {
0460     m_favIconHolder->insertIterator(new FavIconsItr(m_favIconHolder, KEBApp::self()->allBookmarks()));
0461 }
0462 
0463 ActionsImpl::~ActionsImpl()
0464 {
0465     delete m_favIconHolder;
0466     delete m_testLinkHolder;
0467 }
0468 
0469 /* -------------------------------------- */
0470 
0471 void ActionsImpl::slotTestSelection()
0472 {
0473     KEBApp::self()->bkInfo()->commitChanges();
0474     m_testLinkHolder->insertIterator(new TestLinkItr(m_testLinkHolder, KEBApp::self()->selectedBookmarksExpanded()));
0475 }
0476 
0477 void ActionsImpl::slotUpdateFavIcon()
0478 {
0479     KEBApp::self()->bkInfo()->commitChanges();
0480     m_favIconHolder->insertIterator(new FavIconsItr(m_favIconHolder, KEBApp::self()->selectedBookmarksExpanded()));
0481 }
0482 
0483 /* -------------------------------------- */
0484 
0485 class KBookmarkGroupList : private KBookmarkGroupTraverser
0486 {
0487 public:
0488     KBookmarkGroupList(KBookmarkManager *);
0489     QList<KBookmark> getList(const KBookmarkGroup &);
0490 
0491 private:
0492     void visit(const KBookmark &) override
0493     {
0494     }
0495     void visitEnter(const KBookmarkGroup &) override;
0496     void visitLeave(const KBookmarkGroup &) override
0497     {
0498     }
0499 
0500 private:
0501     KBookmarkManager *m_manager;
0502     QList<KBookmark> m_list;
0503 };
0504 
0505 KBookmarkGroupList::KBookmarkGroupList(KBookmarkManager *manager)
0506 {
0507     m_manager = manager;
0508 }
0509 
0510 QList<KBookmark> KBookmarkGroupList::getList(const KBookmarkGroup &grp)
0511 {
0512     traverse(grp);
0513     return m_list;
0514 }
0515 
0516 void KBookmarkGroupList::visitEnter(const KBookmarkGroup &grp)
0517 {
0518     m_list << grp;
0519 }
0520 
0521 void ActionsImpl::slotRecursiveSort()
0522 {
0523     KEBApp::self()->bkInfo()->commitChanges();
0524     KBookmark bk = KEBApp::self()->firstSelected();
0525     Q_ASSERT(bk.isGroup());
0526     KEBMacroCommand *mcmd = new KEBMacroCommand(i18nc("(qtundo-format)", "Recursive Sort"));
0527     KBookmarkGroupList lister(GlobalBookmarkManager::self()->mgr());
0528     QList<KBookmark> bookmarks = lister.getList(bk.toGroup());
0529     bookmarks << bk.toGroup();
0530     for (QList<KBookmark>::ConstIterator it = bookmarks.constBegin(); it != bookmarks.constEnd(); ++it) {
0531         new SortCommand(m_model, QLatin1String(""), (*it).address(), mcmd);
0532     }
0533     commandHistory()->addCommand(mcmd);
0534 }
0535 
0536 void ActionsImpl::slotSort()
0537 {
0538     KEBApp::self()->bkInfo()->commitChanges();
0539     KBookmark bk = KEBApp::self()->firstSelected();
0540     Q_ASSERT(bk.isGroup());
0541     SortCommand *cmd = new SortCommand(m_model, i18nc("(qtundo-format)", "Sort Alphabetically"), bk.address());
0542     commandHistory()->addCommand(cmd);
0543 }
0544 
0545 /* -------------------------------------- */
0546 
0547 void ActionsImpl::slotDelete()
0548 {
0549     KEBApp::self()->bkInfo()->commitChanges();
0550     DeleteManyCommand *mcmd = new DeleteManyCommand(m_model, i18nc("(qtundo-format)", "Delete Items"), KEBApp::self()->selectedBookmarks());
0551     commandHistory()->addCommand(mcmd);
0552 }
0553 
0554 void ActionsImpl::slotOpenLink()
0555 {
0556     KEBApp::self()->bkInfo()->commitChanges();
0557     const QList<KBookmark> bookmarks = KEBApp::self()->selectedBookmarksExpanded();
0558     for (auto &bm : bookmarks) {
0559         if (bm.isGroup() || bm.isSeparator()) {
0560             continue;
0561         }
0562 
0563         auto *job = new KIO::OpenUrlJob(bm.url());
0564 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
0565         job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, KEBApp::self()));
0566 #else
0567         job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, KEBApp::self()));
0568 #endif
0569         job->start();
0570     }
0571 }
0572 
0573 /* -------------------------------------- */
0574 
0575 void ActionsImpl::slotRename()
0576 {
0577     KEBApp::self()->bkInfo()->commitChanges();
0578     KEBApp::self()->startEdit(KEBApp::NameColumn);
0579 }
0580 
0581 void ActionsImpl::slotChangeURL()
0582 {
0583     KEBApp::self()->bkInfo()->commitChanges();
0584     KEBApp::self()->startEdit(KEBApp::UrlColumn);
0585 }
0586 
0587 void ActionsImpl::slotChangeComment()
0588 {
0589     KEBApp::self()->bkInfo()->commitChanges();
0590     KEBApp::self()->startEdit(KEBApp::CommentColumn);
0591 }
0592 
0593 void ActionsImpl::slotSetAsToolbar()
0594 {
0595     KEBApp::self()->bkInfo()->commitChanges();
0596     KBookmark bk = KEBApp::self()->firstSelected();
0597     Q_ASSERT(bk.isGroup());
0598     QUndoCommand *mcmd = CmdGen::setAsToolbar(m_model, bk);
0599     commandHistory()->addCommand(mcmd);
0600 }
0601 
0602 void ActionsImpl::slotChangeIcon()
0603 {
0604     KEBApp::self()->bkInfo()->commitChanges();
0605     KBookmark bk = KEBApp::self()->firstSelected();
0606     const QString newIcon = KIconDialog::getIcon(KIconLoader::Small, KIconLoader::Place, false, 0, false, KEBApp::self());
0607     if (newIcon.isEmpty())
0608         return;
0609     EditCommand *cmd = new EditCommand(m_model, bk.address(), -1, newIcon);
0610 
0611     commandHistory()->addCommand(cmd);
0612 }
0613 
0614 void ActionsImpl::slotExpandAll()
0615 {
0616     KEBApp::self()->expandAll();
0617 }
0618 
0619 void ActionsImpl::slotCollapseAll()
0620 {
0621     KEBApp::self()->collapseAll();
0622 }
0623 
0624 CommandHistory *ActionsImpl::commandHistory()
0625 {
0626     return m_model->commandHistory();
0627 }