1 /***************************************************************************
2 * Copyright (C) 2019 by David Hallas <david@davidhallas.dk> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinbookmarkhandler.h"
21 #include "dolphinmainwindow.h"
22 #include "dolphinviewcontainer.h"
24 #include <KBookmarkMenu>
28 #include <QStandardPaths>
30 DolphinBookmarkHandler::DolphinBookmarkHandler(DolphinMainWindow
*mainWindow
,
31 KActionCollection
* collection
,
35 m_mainWindow(mainWindow
)
37 QString bookmarksFile
= QStandardPaths::locate(QStandardPaths::GenericDataLocation
,
38 QStringLiteral("kfile/bookmarks.xml"));
39 if (bookmarksFile
.isEmpty()) {
40 QString genericDataLocation
= QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation
);
41 if (genericDataLocation
.isEmpty()) {
42 qWarning() << "GenericDataLocation is empty! Bookmarks will not be saved correctly.";
44 bookmarksFile
= QStringLiteral("%1/dolphin").arg(genericDataLocation
);
45 QDir().mkpath(bookmarksFile
);
46 bookmarksFile
+= QLatin1String("/bookmarks.xml");
48 m_bookmarkManager
= KBookmarkManager::managerForFile(bookmarksFile
, QStringLiteral("dolphin"));
49 m_bookmarkManager
->setUpdate(true);
50 m_bookmarkMenu
.reset(new KBookmarkMenu(m_bookmarkManager
, this, menu
, collection
));
53 DolphinBookmarkHandler::~DolphinBookmarkHandler()
57 QString
DolphinBookmarkHandler::currentTitle() const
59 return title(m_mainWindow
->activeViewContainer());
62 QUrl
DolphinBookmarkHandler::currentUrl() const
64 return url(m_mainWindow
->activeViewContainer());
67 QString
DolphinBookmarkHandler::currentIcon() const
69 return icon(m_mainWindow
->activeViewContainer());
72 bool DolphinBookmarkHandler::supportsTabs() const
77 QList
<KBookmarkOwner::FutureBookmark
> DolphinBookmarkHandler::currentBookmarkList() const
79 const auto viewContainers
= m_mainWindow
->viewContainers();
80 QList
<FutureBookmark
> bookmarks
;
81 bookmarks
.reserve(viewContainers
.size());
82 for (const auto viewContainer
: viewContainers
) {
83 bookmarks
<< FutureBookmark(title(viewContainer
), url(viewContainer
), icon(viewContainer
));
88 bool DolphinBookmarkHandler::enableOption(KBookmarkOwner::BookmarkOption option
) const
91 case BookmarkOption::ShowAddBookmark
: return true;
92 case BookmarkOption::ShowEditBookmark
: return true;
97 void DolphinBookmarkHandler::openBookmark(const KBookmark
& bookmark
, Qt::MouseButtons
, Qt::KeyboardModifiers
)
99 m_mainWindow
->changeUrl(bookmark
.url());
102 void DolphinBookmarkHandler::openFolderinTabs(const KBookmarkGroup
& bookmarkGroup
)
104 m_mainWindow
->openDirectories(bookmarkGroup
.groupUrlList(), false);
107 void DolphinBookmarkHandler::openInNewTab(const KBookmark
& bookmark
)
109 m_mainWindow
->openNewTabAfterCurrentTab(bookmark
.url());
112 void DolphinBookmarkHandler::openInNewWindow(const KBookmark
& bookmark
)
114 Dolphin::openNewWindow({bookmark
.url()}, m_mainWindow
);
117 QString
DolphinBookmarkHandler::title(DolphinViewContainer
* viewContainer
)
119 return viewContainer
->caption();
122 QUrl
DolphinBookmarkHandler::url(DolphinViewContainer
* viewContainer
)
124 return viewContainer
->url();
127 QString
DolphinBookmarkHandler::icon(DolphinViewContainer
* viewContainer
)
129 return KIO::iconNameForUrl(viewContainer
->url());