1 /****************************************************************************
3 ** Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
5 ** This file is part of KDE.
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
22 ****************************************************************************/
24 #include "bookmarkmanager.h"
26 #include "mainwindow.h"
28 #include <KBookmarkMenu>
29 #include <KStandardDirs>
32 BookmarkManager::BookmarkManager(KActionCollection
*collection
, KMenu
*menu
, MainWindow
*parent
)
39 const QString file
= KStandardDirs::locateLocal("data", "krdc/bookmarks.xml");
41 m_manager
= KBookmarkManager::managerForFile(file
, "krdc");
43 m_manager
->setUpdate(true);
45 m_bookmarkMenu
= new KBookmarkMenu(m_manager
, this, m_menu
, collection
);
47 KBookmarkGroup root
= m_manager
->root();
48 KBookmark bm
= root
.first();
49 while (!bm
.isNull()) {
50 if (bm
.metaDataItem("krdc-history") == "historyfolder") // get it also when user renamed it
56 kDebug(5010) << "History folder not found. Create it.";
57 bm
= m_manager
->root().createNewFolder(i18n("History"));
58 bm
.setMetaDataItem("krdc-history", "historyfolder");
59 m_manager
->emitChanged();
62 m_historyGroup
= bm
.toGroup();
65 BookmarkManager::~BookmarkManager()
67 delete m_bookmarkMenu
;
70 void BookmarkManager::addHistoryBookmark()
72 kDebug(5010) << "addHistoryBookmark";
74 KBookmark bm
= m_historyGroup
.first();
75 while (!bm
.isNull()) {
76 if (bm
.url() == KUrl(currentUrl())) {
77 kDebug(5010) << "Found URL. Move it at the history start.";
78 m_historyGroup
.moveBookmark(bm
, KBookmark());
79 m_manager
->emitChanged();
82 bm
= m_historyGroup
.next(bm
);
86 kDebug(5010) << "Add new history bookmark.";
87 m_historyGroup
.moveBookmark(m_historyGroup
.addBookmark(currentTitle(), currentUrl()), KBookmark());
88 m_manager
->emitChanged();
92 void BookmarkManager::openBookmark(const KBookmark
&bm
, Qt::MouseButtons
, Qt::KeyboardModifiers
)
94 emit
openUrl(bm
.url());
97 void BookmarkManager::openFolderinTabs(const KBookmarkGroup
&bookmarkGroup
)
99 KBookmark bm
= bookmarkGroup
.first();
100 while (!bm
.isNull()) {
101 emit
openUrl(bm
.url());
102 bm
= bookmarkGroup
.next(bm
);
106 bool BookmarkManager::addBookmarkEntry() const
111 bool BookmarkManager::editBookmarkEntry() const
116 QString
BookmarkManager::currentUrl() const
118 if (m_mainWindow
->currentRemoteView() >= 0)
119 return m_mainWindow
->remoteViewList().at(m_mainWindow
->currentRemoteView())
120 ->url().prettyUrl(KUrl::RemoveTrailingSlash
);
125 QString
BookmarkManager::currentTitle() const
130 bool BookmarkManager::supportsTabs() const
135 QList
<QPair
<QString
, QString
> > BookmarkManager::currentBookmarkList() const
137 QList
<QPair
<QString
, QString
> > list
;
139 QListIterator
<RemoteView
*> iter(m_mainWindow
->remoteViewList());
141 while (iter
.hasNext()) {
142 RemoteView
*next
= iter
.next();
143 const QString url
= next
->url().prettyUrl(KUrl::RemoveTrailingSlash
);
144 list
<< QPair
<QString
, QString
>(url
, url
);
150 #include "bookmarkmanager.moc"