• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krdc

  • sources
  • kde-4.12
  • kdenetwork
  • krdc
bookmarkmanager.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
4 **
5 ** This file is part of KDE.
6 **
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.
11 **
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.
16 **
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.
21 **
22 ****************************************************************************/
23 
24 #include "bookmarkmanager.h"
25 
26 #include "mainwindow.h"
27 
28 #include <KBookmarkMenu>
29 #include <KStandardDirs>
30 #include <KDebug>
31 
32 BookmarkManager::BookmarkManager(KActionCollection *collection, KMenu *menu, MainWindow *parent)
33  : QObject(parent),
34  KBookmarkOwner(),
35  m_mainWindow(parent)
36 {
37  const QString file = KStandardDirs::locateLocal("data", "krdc/bookmarks.xml");
38 
39  m_manager = KBookmarkManager::managerForFile(file, "krdc");
40  m_manager->setUpdate(true);
41  m_bookmarkMenu = new KBookmarkMenu(m_manager, this, menu, collection);
42 
43  KBookmarkGroup root = m_manager->root();
44  KBookmark bm = root.first();
45  while (!bm.isNull()) {
46  if (bm.metaDataItem("krdc-history") == "historyfolder") // get it also when user renamed it
47  break;
48  bm = root.next(bm);
49  }
50 
51  if (bm.isNull()) {
52  kDebug(5010) << "History folder not found. Create it.";
53  bm = m_manager->root().createNewFolder(i18n("History"));
54  bm.setMetaDataItem("krdc-history", "historyfolder");
55  m_manager->emitChanged();
56  }
57 
58  m_historyGroup = bm.toGroup();
59 }
60 
61 BookmarkManager::~BookmarkManager()
62 {
63  delete m_bookmarkMenu;
64 }
65 
66 void BookmarkManager::addHistoryBookmark(RemoteView *view)
67 {
68  KBookmark bm = m_historyGroup.first();
69  const QString urlString = urlForView(view);
70  const KUrl url = KUrl(urlString);
71  while (!bm.isNull()) {
72  if (bm.url() == url) {
73  kDebug(5010) << "Found URL. Move it at the history start.";
74  m_historyGroup.moveBookmark(bm, KBookmark());
75  bm.updateAccessMetadata();
76  m_manager->emitChanged(m_historyGroup);
77  return;
78  }
79  bm = m_historyGroup.next(bm);
80  }
81 
82  if (bm.isNull()) {
83  kDebug(5010) << "Add new history bookmark.";
84  bm = m_historyGroup.addBookmark(titleForUrl(urlString), urlString);
85  bm.updateAccessMetadata();
86  m_historyGroup.moveBookmark(bm, KBookmark());
87  m_manager->emitChanged(m_historyGroup);
88  }
89 }
90 
91 void BookmarkManager::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers)
92 {
93  emit openUrl(bm.url());
94 }
95 
96 void BookmarkManager::openFolderinTabs(const KBookmarkGroup &bookmarkGroup)
97 {
98  KBookmark bm = bookmarkGroup.first();
99  while (!bm.isNull()) {
100  emit openUrl(bm.url());
101  bm = bookmarkGroup.next(bm);
102  }
103 }
104 
105 bool BookmarkManager::addBookmarkEntry() const
106 {
107  return true;
108 }
109 
110 bool BookmarkManager::editBookmarkEntry() const
111 {
112  return true;
113 }
114 
115 QString BookmarkManager::currentUrl() const
116 {
117  RemoteView *view = m_mainWindow->currentRemoteView();
118  if (view)
119  return urlForView(view);
120  else
121  return QString();
122 }
123 
124 QString BookmarkManager::urlForView(RemoteView *view) const
125 {
126  return view->url().prettyUrl(KUrl::RemoveTrailingSlash);
127 
128 }
129 
130 QString BookmarkManager::currentTitle() const
131 {
132  return titleForUrl(currentUrl());
133 }
134 
135 QString BookmarkManager::titleForUrl(const QString &url) const
136 {
137  return QUrl::fromPercentEncoding(url.toUtf8());
138 
139 }
140 
141 bool BookmarkManager::supportsTabs() const
142 {
143  return true;
144 }
145 
146 QList<QPair<QString, QString> > BookmarkManager::currentBookmarkList() const
147 {
148  QList<QPair<QString, QString> > list;
149 
150  QMapIterator<QWidget *, RemoteView *> iter(m_mainWindow->remoteViewList());
151 
152  while (iter.hasNext()) {
153  RemoteView *next = iter.next().value();
154  const QString url = next->url().prettyUrl(KUrl::RemoveTrailingSlash);
155  list << QPair<QString, QString>(url, url);
156  }
157 
158  return list;
159 }
160 
161 void BookmarkManager::addManualBookmark(const QString &url, const QString &text)
162 {
163  m_manager->root().addBookmark(url, text);
164  emit m_manager->emitChanged();
165 }
166 
167 KBookmarkManager* BookmarkManager::getManager()
168 {
169  return m_manager;
170 }
171 
172 const QStringList BookmarkManager::findBookmarkAddresses(const KBookmarkGroup &group, const QString &url)
173 {
174  QStringList bookmarkAddresses = QStringList();
175  KBookmark bm = group.first();
176  while (!bm.isNull()) {
177  if (bm.isGroup()) {
178  bookmarkAddresses.append(findBookmarkAddresses(bm.toGroup(), url));
179  }
180 
181  if (bm.url() == url) {
182  bookmarkAddresses.append(bm.address());
183  }
184  bm = group.next(bm);
185  }
186  return bookmarkAddresses;
187 }
188 
189 void BookmarkManager::removeByUrl(KBookmarkManager *manager, const QString &url, bool ignoreHistory, const QString updateTitle)
190 {
191  foreach(const QString &address, findBookmarkAddresses(manager->root(), url)) {
192  KBookmark bm = manager->findByAddress(address);
193  if (ignoreHistory && bm.parentGroup().metaDataItem("krdc-history") == "historyfolder") {
194  if (!updateTitle.isEmpty()) {
195  kDebug(5010) << "Update" << bm.fullText();
196  bm.setFullText(updateTitle);
197  }
198  } else {
199  if (!bm.isGroup()) { // please don't delete groups... happened in testing
200  kDebug(5010) << "Delete" << bm.fullText();
201  bm.parentGroup().deleteBookmark(bm);
202  }
203  }
204  }
205 
206  manager->emitChanged();
207 }
208 
209 void BookmarkManager::updateTitle(KBookmarkManager *manager, const QString &url, const QString &title)
210 {
211  foreach(const QString &address, findBookmarkAddresses(manager->root(), url)) {
212  KBookmark bm = manager->findByAddress(address);
213  bm.setFullText(title);
214  kDebug(5010) << "Update" << bm.fullText();
215  }
216  manager->emitChanged();
217 }
218 
219 #include "bookmarkmanager.moc"
BookmarkManager::~BookmarkManager
~BookmarkManager()
Definition: bookmarkmanager.cpp:61
BookmarkManager::currentUrl
virtual QString currentUrl() const
Definition: bookmarkmanager.cpp:115
bookmarkmanager.h
BookmarkManager::getManager
KBookmarkManager * getManager()
Definition: bookmarkmanager.cpp:167
QObject
MainWindow::currentRemoteView
RemoteView * currentRemoteView() const
Definition: mainwindow.cpp:1172
RemoteView
Generic widget that displays a remote framebuffer.
Definition: remoteview.h:59
BookmarkManager::editBookmarkEntry
virtual bool editBookmarkEntry() const
Definition: bookmarkmanager.cpp:110
mainwindow.h
BookmarkManager::currentTitle
virtual QString currentTitle() const
Definition: bookmarkmanager.cpp:130
BookmarkManager::updateTitle
static void updateTitle(KBookmarkManager *manager, const QString &url, const QString &title)
Definition: bookmarkmanager.cpp:209
KBookmarkOwner
BookmarkManager::supportsTabs
virtual bool supportsTabs() const
Definition: bookmarkmanager.cpp:141
RemoteView::url
KUrl url()
Definition: remoteview.cpp:193
BookmarkManager::addManualBookmark
void addManualBookmark(const QString &url, const QString &text)
Definition: bookmarkmanager.cpp:161
BookmarkManager::BookmarkManager
BookmarkManager(KActionCollection *collection, KMenu *menu, MainWindow *parent)
Definition: bookmarkmanager.cpp:32
BookmarkManager::currentBookmarkList
virtual QList< QPair< QString, QString > > currentBookmarkList() const
Definition: bookmarkmanager.cpp:146
BookmarkManager::removeByUrl
static void removeByUrl(KBookmarkManager *manager, const QString &url, bool ignoreHistory=false, const QString updateTitle=QString())
Definition: bookmarkmanager.cpp:189
BookmarkManager::addBookmarkEntry
virtual bool addBookmarkEntry() const
Definition: bookmarkmanager.cpp:105
BookmarkManager::addHistoryBookmark
void addHistoryBookmark(RemoteView *view)
Definition: bookmarkmanager.cpp:66
BookmarkManager::findBookmarkAddresses
static const QStringList findBookmarkAddresses(const KBookmarkGroup &group, const QString &url)
Definition: bookmarkmanager.cpp:172
BookmarkManager::openUrl
void openUrl(const KUrl &url)
MainWindow
Definition: mainwindow.h:55
MainWindow::remoteViewList
QMap< QWidget *, RemoteView * > remoteViewList() const
Definition: mainwindow.cpp:1162
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krdc

Skip menu "krdc"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal