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

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • bookmarks
kbookmarkmanager.cc
Go to the documentation of this file.
1 // -*- c-basic-offset:4; indent-tabs-mode:nil -*-
2 // vim: set ts=4 sts=4 sw=4 et:
3 /* This file is part of the KDE libraries
4  Copyright (C) 2000 David Faure <faure@kde.org>
5  Copyright (C) 2003 Alexander Kellett <lypanov@kde.org>
6  Copyright (C) 2008 Norbert Frese <nf2@scheinwelt.at>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License version 2 as published by the Free Software Foundation.
11 
12  This library 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 GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "kbookmarkmanager.h"
24 
25 #include <QtCore/QFile>
26 #include <QtCore/QFileInfo>
27 #include <QtCore/QProcess>
28 #include <QtCore/QRegExp>
29 #include <QtCore/QTextStream>
30 #include <QtDBus/QtDBus>
31 #include <QtGui/QApplication>
32 
33 #include <kconfiggroup.h>
34 #include <kdebug.h>
35 #include <kdirwatch.h>
36 #include <klocale.h>
37 #include <kmessagebox.h>
38 #include <ksavefile.h>
39 #include <kstandarddirs.h>
40 
41 #include "kbookmarkmenu.h"
42 #include "kbookmarkmenu_p.h"
43 #include "kbookmarkimporter.h"
44 #include "kbookmarkdialog.h"
45 #include "kbookmarkmanageradaptor_p.h"
46 
47 #define BOOKMARK_CHANGE_NOTIFY_INTERFACE "org.kde.KIO.KBookmarkManager"
48 
49 class KBookmarkManagerList : public QList<KBookmarkManager *>
50 {
51 public:
52  ~KBookmarkManagerList() {
53  qDeleteAll( begin() , end() ); // auto-delete functionality
54  }
55 
56  QReadWriteLock lock;
57 };
58 
59 K_GLOBAL_STATIC(KBookmarkManagerList, s_pSelf)
60 
61 class KBookmarkMap : private KBookmarkGroupTraverser {
62 public:
63  KBookmarkMap() : m_mapNeedsUpdate(true) {}
64  void setNeedsUpdate() { m_mapNeedsUpdate = true; }
65  void update(KBookmarkManager*);
66  QList<KBookmark> find( const QString &url ) const
67  { return m_bk_map.value(url); }
68 private:
69  virtual void visit(const KBookmark &);
70  virtual void visitEnter(const KBookmarkGroup &) { ; }
71  virtual void visitLeave(const KBookmarkGroup &) { ; }
72 private:
73  typedef QList<KBookmark> KBookmarkList;
74  QMap<QString, KBookmarkList> m_bk_map;
75  bool m_mapNeedsUpdate;
76 };
77 
78 void KBookmarkMap::update(KBookmarkManager *manager)
79 {
80  if (m_mapNeedsUpdate) {
81  m_mapNeedsUpdate = false;
82 
83  m_bk_map.clear();
84  KBookmarkGroup root = manager->root();
85  traverse(root);
86  }
87 }
88 
89 void KBookmarkMap::visit(const KBookmark &bk)
90 {
91  if (!bk.isSeparator()) {
92  // add bookmark to url map
93  m_bk_map[bk.internalElement().attribute("href")].append(bk);
94  }
95 }
96 
97 // #########################
98 // KBookmarkManager::Private
99 class KBookmarkManager::Private
100 {
101 public:
102  Private(bool bDocIsloaded, const QString &dbusObjectName = QString())
103  : m_doc("xbel")
104  , m_dbusObjectName(dbusObjectName)
105  , m_docIsLoaded(bDocIsloaded)
106  , m_update(false)
107  , m_dialogAllowed(true)
108  , m_dialogParent(0)
109  , m_browserEditor(false)
110  , m_typeExternal(false)
111  , m_kDirWatch(0)
112  {}
113 
114  ~Private() {
115  delete m_kDirWatch;
116  }
117 
118  mutable QDomDocument m_doc;
119  mutable QDomDocument m_toolbarDoc;
120  QString m_bookmarksFile;
121  QString m_dbusObjectName;
122  mutable bool m_docIsLoaded;
123  bool m_update;
124  bool m_dialogAllowed;
125  QWidget *m_dialogParent;
126 
127  bool m_browserEditor;
128  QString m_editorCaption;
129 
130  bool m_typeExternal;
131  KDirWatch * m_kDirWatch; // for external bookmark files
132 
133  KBookmarkMap m_map;
134 };
135 
136 // ################
137 // KBookmarkManager
138 
139 static KBookmarkManager* lookupExisting(const QString& bookmarksFile)
140 {
141  for ( KBookmarkManagerList::ConstIterator bmit = s_pSelf->constBegin(), bmend = s_pSelf->constEnd();
142  bmit != bmend; ++bmit ) {
143  if ( (*bmit)->path() == bookmarksFile )
144  return *bmit;
145  }
146  return 0;
147 }
148 
149 
150 KBookmarkManager* KBookmarkManager::managerForFile( const QString& bookmarksFile, const QString& dbusObjectName )
151 {
152  KBookmarkManager* mgr(0);
153  {
154  QReadLocker readLock(&s_pSelf->lock);
155  mgr = lookupExisting(bookmarksFile);
156  if (mgr) {
157  return mgr;
158  }
159  }
160 
161  QWriteLocker writeLock(&s_pSelf->lock);
162  mgr = lookupExisting(bookmarksFile);
163  if (mgr) {
164  return mgr;
165  }
166 
167  mgr = new KBookmarkManager( bookmarksFile, dbusObjectName );
168  s_pSelf->append( mgr );
169  return mgr;
170 }
171 
172 KBookmarkManager* KBookmarkManager::managerForExternalFile( const QString& bookmarksFile )
173 {
174  KBookmarkManager* mgr(0);
175  {
176  QReadLocker readLock(&s_pSelf->lock);
177  mgr = lookupExisting(bookmarksFile);
178  if (mgr) {
179  return mgr;
180  }
181  }
182 
183  QWriteLocker writeLock(&s_pSelf->lock);
184  mgr = lookupExisting(bookmarksFile);
185  if (mgr) {
186  return mgr;
187  }
188 
189  mgr = new KBookmarkManager( bookmarksFile );
190  s_pSelf->append( mgr );
191  return mgr;
192 }
193 
194 
195 // principally used for filtered toolbars
196 KBookmarkManager* KBookmarkManager::createTempManager()
197 {
198  KBookmarkManager* mgr = new KBookmarkManager();
199  s_pSelf->append( mgr );
200  return mgr;
201 }
202 
203 #define PI_DATA "version=\"1.0\" encoding=\"UTF-8\""
204 
205 static QDomElement createXbelTopLevelElement(QDomDocument & doc)
206 {
207  QDomElement topLevel = doc.createElement("xbel");
208  topLevel.setAttribute("xmlns:mime", "http://www.freedesktop.org/standards/shared-mime-info");
209  topLevel.setAttribute("xmlns:bookmark", "http://www.freedesktop.org/standards/desktop-bookmarks");
210  topLevel.setAttribute("xmlns:kdepriv", "http://www.kde.org/kdepriv");
211  doc.appendChild( topLevel );
212  doc.insertBefore( doc.createProcessingInstruction( "xml", PI_DATA), topLevel );
213  return topLevel;
214 }
215 
216 KBookmarkManager::KBookmarkManager( const QString & bookmarksFile, const QString & dbusObjectName)
217  : d(new Private(false, dbusObjectName))
218 {
219  if(dbusObjectName.isNull()) // get dbusObjectName from file
220  if ( QFile::exists(d->m_bookmarksFile) )
221  parse(); //sets d->m_dbusObjectName
222 
223  init( "/KBookmarkManager/"+d->m_dbusObjectName );
224 
225  d->m_update = true;
226 
227  Q_ASSERT( !bookmarksFile.isEmpty() );
228  d->m_bookmarksFile = bookmarksFile;
229 
230  if ( !QFile::exists(d->m_bookmarksFile) )
231  {
232  QDomElement topLevel = createXbelTopLevelElement(d->m_doc);
233  topLevel.setAttribute("dbusName", dbusObjectName);
234  d->m_docIsLoaded = true;
235  }
236 }
237 
238 KBookmarkManager::KBookmarkManager(const QString & bookmarksFile)
239  : d(new Private(false))
240 {
241  // use KDirWatch to monitor this bookmarks file
242  d->m_typeExternal = true;
243  d->m_update = true;
244 
245  Q_ASSERT( !bookmarksFile.isEmpty() );
246  d->m_bookmarksFile = bookmarksFile;
247 
248  if ( !QFile::exists(d->m_bookmarksFile) )
249  {
250  createXbelTopLevelElement(d->m_doc);
251  }
252  else
253  {
254  parse();
255  }
256  d->m_docIsLoaded = true;
257 
258  // start KDirWatch
259  d->m_kDirWatch = new KDirWatch;
260  d->m_kDirWatch->addFile(d->m_bookmarksFile);
261  QObject::connect( d->m_kDirWatch, SIGNAL(dirty(const QString&)),
262  this, SLOT(slotFileChanged(const QString&)));
263  QObject::connect( d->m_kDirWatch, SIGNAL(created(const QString&)),
264  this, SLOT(slotFileChanged(const QString&)));
265  QObject::connect( d->m_kDirWatch, SIGNAL(deleted(const QString&)),
266  this, SLOT(slotFileChanged(const QString&)));
267  kDebug(7043) << "starting KDirWatch for " << d->m_bookmarksFile;
268 }
269 
270 KBookmarkManager::KBookmarkManager( )
271  : d(new Private(true))
272 {
273  init( "/KBookmarkManager/generated" );
274  d->m_update = false; // TODO - make it read/write
275 
276  createXbelTopLevelElement(d->m_doc);
277 }
278 
279 void KBookmarkManager::init( const QString& dbusPath )
280 {
281  // A KBookmarkManager without a dbus name is a temporary one, like those used by importers;
282  // no need to register them to dbus
283  if ( dbusPath != "/KBookmarkManager/" && dbusPath != "/KBookmarkManager/generated")
284  {
285  new KBookmarkManagerAdaptor(this);
286  QDBusConnection::sessionBus().registerObject( dbusPath, this );
287 
288  QDBusConnection::sessionBus().connect(QString(), dbusPath, BOOKMARK_CHANGE_NOTIFY_INTERFACE,
289  "bookmarksChanged", this, SLOT(notifyChanged(QString,QDBusMessage)));
290  QDBusConnection::sessionBus().connect(QString(), dbusPath, BOOKMARK_CHANGE_NOTIFY_INTERFACE,
291  "bookmarkConfigChanged", this, SLOT(notifyConfigChanged()));
292  }
293 }
294 
295 void KBookmarkManager::slotFileChanged(const QString& path)
296 {
297  if (path == d->m_bookmarksFile)
298  {
299  kDebug(7043) << "file changed (KDirWatch) " << path ;
300  // Reparse
301  parse();
302  // Tell our GUI
303  // (emit where group is "" to directly mark the root menu as dirty)
304  emit changed( "", QString() );
305  }
306 }
307 
308 KBookmarkManager::~KBookmarkManager()
309 {
310  if (!s_pSelf.isDestroyed()) {
311  s_pSelf->removeAll(this);
312  }
313 
314  delete d;
315 }
316 
317 bool KBookmarkManager::autoErrorHandlingEnabled() const
318 {
319  return d->m_dialogAllowed;
320 }
321 
322 void KBookmarkManager::setAutoErrorHandlingEnabled( bool enable, QWidget *parent )
323 {
324  d->m_dialogAllowed = enable;
325  d->m_dialogParent = parent;
326 }
327 
328 void KBookmarkManager::setUpdate( bool update )
329 {
330  d->m_update = update;
331 }
332 
333 QDomDocument KBookmarkManager::internalDocument() const
334 {
335  if(!d->m_docIsLoaded)
336  {
337  parse();
338  d->m_toolbarDoc.clear();
339  }
340  return d->m_doc;
341 }
342 
343 
344 void KBookmarkManager::parse() const
345 {
346  d->m_docIsLoaded = true;
347  //kDebug(7043) << "KBookmarkManager::parse " << d->m_bookmarksFile;
348  QFile file( d->m_bookmarksFile );
349  if ( !file.open( QIODevice::ReadOnly ) )
350  {
351  kWarning() << "Can't open " << d->m_bookmarksFile;
352  return;
353  }
354  d->m_doc = QDomDocument("xbel");
355  d->m_doc.setContent( &file );
356 
357  if ( d->m_doc.documentElement().isNull() )
358  {
359  kWarning() << "KBookmarkManager::parse : main tag is missing, creating default " << d->m_bookmarksFile;
360  QDomElement element = d->m_doc.createElement("xbel");
361  d->m_doc.appendChild(element);
362  }
363 
364  QDomElement docElem = d->m_doc.documentElement();
365 
366  QString mainTag = docElem.tagName();
367  if ( mainTag != "xbel" )
368  kWarning() << "KBookmarkManager::parse : unknown main tag " << mainTag;
369 
370  if(d->m_dbusObjectName.isNull())
371  {
372  d->m_dbusObjectName = docElem.attribute("dbusName");
373  }
374  else if(docElem.attribute("dbusName") != d->m_dbusObjectName)
375  {
376  docElem.setAttribute("dbusName", d->m_dbusObjectName);
377  save();
378  }
379 
380  QDomNode n = d->m_doc.documentElement().previousSibling();
381  if ( n.isProcessingInstruction() )
382  {
383  QDomProcessingInstruction pi = n.toProcessingInstruction();
384  pi.parentNode().removeChild(pi);
385  }
386 
387  QDomProcessingInstruction pi;
388  pi = d->m_doc.createProcessingInstruction( "xml", PI_DATA );
389  d->m_doc.insertBefore( pi, docElem );
390 
391  file.close();
392 
393  d->m_map.setNeedsUpdate();
394 }
395 
396 bool KBookmarkManager::save( bool toolbarCache ) const
397 {
398  return saveAs( d->m_bookmarksFile, toolbarCache );
399 }
400 
401 bool KBookmarkManager::saveAs( const QString & filename, bool toolbarCache ) const
402 {
403  kDebug(7043) << "KBookmarkManager::save " << filename;
404 
405  // Save the bookmark toolbar folder for quick loading
406  // but only when it will actually make things quicker
407  const QString cacheFilename = filename + QLatin1String(".tbcache");
408  if(toolbarCache && !root().isToolbarGroup())
409  {
410  KSaveFile cacheFile( cacheFilename );
411  if ( cacheFile.open() )
412  {
413  QString str;
414  QTextStream stream(&str, QIODevice::WriteOnly);
415  stream << root().findToolbar();
416  const QByteArray cstr = str.toUtf8();
417  cacheFile.write( cstr.data(), cstr.length() );
418  cacheFile.finalize();
419  }
420  }
421  else // remove any (now) stale cache
422  {
423  QFile::remove( cacheFilename );
424  }
425 
426  KSaveFile file( filename );
427  if ( file.open() )
428  {
429  file.simpleBackupFile( file.fileName(), QString(), ".bak" );
430  QTextStream stream(&file);
431  stream.setCodec( QTextCodec::codecForName( "UTF-8" ) );
432  stream << internalDocument().toString();
433  stream.flush();
434  if ( file.finalize() )
435  {
436  return true;
437  }
438  }
439 
440  static int hadSaveError = false;
441  file.abort();
442  if ( !hadSaveError ) {
443  QString err = i18n("Unable to save bookmarks in %1. Reported error was: %2. "
444  "This error message will only be shown once. The cause "
445  "of the error needs to be fixed as quickly as possible, "
446  "which is most likely a full hard drive.",
447  filename, file.errorString());
448 
449  if (d->m_dialogAllowed && qApp->type() != QApplication::Tty && QThread::currentThread() == qApp->thread())
450  KMessageBox::error( QApplication::activeWindow(), err );
451 
452  kError() << QString("Unable to save bookmarks in %1. File reported the following error-code: %2.").arg(filename).arg(file.error());
453  emit const_cast<KBookmarkManager*>(this)->error(err);
454  }
455  hadSaveError = true;
456  return false;
457 }
458 
459 QString KBookmarkManager::path() const
460 {
461  return d->m_bookmarksFile;
462 }
463 
464 KBookmarkGroup KBookmarkManager::root() const
465 {
466  return KBookmarkGroup(internalDocument().documentElement());
467 }
468 
469 KBookmarkGroup KBookmarkManager::toolbar()
470 {
471  kDebug(7043) << "KBookmarkManager::toolbar begin";
472  // Only try to read from a toolbar cache if the full document isn't loaded
473  if(!d->m_docIsLoaded)
474  {
475  kDebug(7043) << "KBookmarkManager::toolbar trying cache";
476  const QString cacheFilename = d->m_bookmarksFile + QLatin1String(".tbcache");
477  QFileInfo bmInfo(d->m_bookmarksFile);
478  QFileInfo cacheInfo(cacheFilename);
479  if (d->m_toolbarDoc.isNull() &&
480  QFile::exists(cacheFilename) &&
481  bmInfo.lastModified() < cacheInfo.lastModified())
482  {
483  kDebug(7043) << "KBookmarkManager::toolbar reading file";
484  QFile file( cacheFilename );
485 
486  if ( file.open( QIODevice::ReadOnly ) )
487  {
488  d->m_toolbarDoc = QDomDocument("cache");
489  d->m_toolbarDoc.setContent( &file );
490  kDebug(7043) << "KBookmarkManager::toolbar opened";
491  }
492  }
493  if (!d->m_toolbarDoc.isNull())
494  {
495  kDebug(7043) << "KBookmarkManager::toolbar returning element";
496  QDomElement elem = d->m_toolbarDoc.firstChild().toElement();
497  return KBookmarkGroup(elem);
498  }
499  }
500 
501  // Fallback to the normal way if there is no cache or if the bookmark file
502  // is already loaded
503  QDomElement elem = root().findToolbar();
504  if (elem.isNull())
505  {
506  // Root is the bookmark toolbar if none has been set.
507  // Make it explicit to speed up invocations of findToolbar()
508  root().internalElement().setAttribute("toolbar", "yes");
509  return root();
510  }
511  else
512  return KBookmarkGroup(elem);
513 }
514 
515 KBookmark KBookmarkManager::findByAddress( const QString & address )
516 {
517  //kDebug(7043) << "KBookmarkManager::findByAddress " << address;
518  KBookmark result = root();
519  // The address is something like /5/10/2+
520  const QStringList addresses = address.split(QRegExp("[/+]"),QString::SkipEmptyParts);
521  // kWarning() << addresses.join(",");
522  for ( QStringList::const_iterator it = addresses.begin() ; it != addresses.end() ; )
523  {
524  bool append = ((*it) == "+");
525  uint number = (*it).toUInt();
526  Q_ASSERT(result.isGroup());
527  KBookmarkGroup group = result.toGroup();
528  KBookmark bk = group.first(), lbk = bk; // last non-null bookmark
529  for ( uint i = 0 ; ( (i<number) || append ) && !bk.isNull() ; ++i ) {
530  lbk = bk;
531  bk = group.next(bk);
532  //kWarning() << i;
533  }
534  it++;
535  //kWarning() << "found section";
536  result = bk;
537  }
538  if (result.isNull()) {
539  kWarning() << "KBookmarkManager::findByAddress: couldn't find item " << address;
540  }
541  //kWarning() << "found " << result.address();
542  return result;
543  }
544 
545 void KBookmarkManager::emitChanged()
546 {
547  emitChanged(root());
548 }
549 
550 
551 void KBookmarkManager::emitChanged( const KBookmarkGroup & group )
552 {
553  (void) save(); // KDE5 TODO: emitChanged should return a bool? Maybe rename it to saveAndEmitChanged?
554 
555  // Tell the other processes too
556  // kDebug(7043) << "KBookmarkManager::emitChanged : broadcasting change " << group.address();
557 
558  emit bookmarksChanged(group.address());
559 
560  // We do get our own broadcast, so no need for this anymore
561  //emit changed( group );
562 }
563 
564 void KBookmarkManager::emitConfigChanged()
565 {
566  emit bookmarkConfigChanged();
567 }
568 
569 void KBookmarkManager::notifyCompleteChange( const QString &caller ) // DBUS call
570 {
571  if (!d->m_update)
572  return;
573 
574  kDebug(7043) << "KBookmarkManager::notifyCompleteChange";
575  // The bk editor tells us we should reload everything
576  // Reparse
577  parse();
578  // Tell our GUI
579  // (emit where group is "" to directly mark the root menu as dirty)
580  emit changed( "", caller );
581 }
582 
583 void KBookmarkManager::notifyConfigChanged() // DBUS call
584 {
585  kDebug() << "reloaded bookmark config!";
586  KBookmarkSettings::self()->readSettings();
587  parse(); // reload, and thusly recreate the menus
588  emit configChanged();
589 }
590 
591 void KBookmarkManager::notifyChanged( const QString &groupAddress, const QDBusMessage &msg ) // DBUS call
592 {
593  kDebug() << "KBookmarkManager::notifyChanged ( "<<groupAddress<<")";
594  if (!d->m_update)
595  return;
596 
597  // Reparse (the whole file, no other choice)
598  // if someone else notified us
599  if (msg.service() != QDBusConnection::sessionBus().baseService())
600  parse();
601 
602  //kDebug(7043) << "KBookmarkManager::notifyChanged " << groupAddress;
603  //KBookmarkGroup group = findByAddress( groupAddress ).toGroup();
604  //Q_ASSERT(!group.isNull());
605  emit changed( groupAddress, QString() );
606 }
607 
608 void KBookmarkManager::setEditorOptions( const QString& caption, bool browser )
609 {
610  d->m_editorCaption = caption;
611  d->m_browserEditor = browser;
612 }
613 
614 void KBookmarkManager::slotEditBookmarks()
615 {
616  QStringList args;
617  if ( !d->m_editorCaption.isEmpty() )
618  args << QLatin1String("--customcaption") << d->m_editorCaption;
619  if ( !d->m_browserEditor )
620  args << QLatin1String("--nobrowser");
621  if( !d->m_dbusObjectName.isEmpty() )
622  args << QLatin1String("--dbusObjectName") << d->m_dbusObjectName;
623  args << d->m_bookmarksFile;
624  QProcess::startDetached("keditbookmarks", args);
625 }
626 
627 void KBookmarkManager::slotEditBookmarksAtAddress( const QString& address )
628 {
629  QStringList args;
630  if ( !d->m_editorCaption.isEmpty() )
631  args << QLatin1String("--customcaption") << d->m_editorCaption;
632  if ( !d->m_browserEditor )
633  args << QLatin1String("--nobrowser");
634  if( !d->m_dbusObjectName.isEmpty() )
635  args << QLatin1String("--dbusObjectName") << d->m_dbusObjectName;
636  args << QLatin1String("--address") << address
637  << d->m_bookmarksFile;
638  QProcess::startDetached("keditbookmarks", args);
639 }
640 
642 bool KBookmarkManager::updateAccessMetadata( const QString & url )
643 {
644  d->m_map.update(this);
645  QList<KBookmark> list = d->m_map.find(url);
646  if ( list.count() == 0 )
647  return false;
648 
649  for ( QList<KBookmark>::iterator it = list.begin();
650  it != list.end(); ++it )
651  (*it).updateAccessMetadata();
652 
653  return true;
654 }
655 
656 void KBookmarkManager::updateFavicon( const QString &url, const QString &/*faviconurl*/ )
657 {
658  d->m_map.update(this);
659  QList<KBookmark> list = d->m_map.find(url);
660  for ( QList<KBookmark>::iterator it = list.begin();
661  it != list.end(); ++it )
662  {
663  // TODO - update favicon data based on faviconurl
664  // but only when the previously used icon
665  // isn't a manually set one.
666  }
667 }
668 
669 KBookmarkManager* KBookmarkManager::userBookmarksManager()
670 {
671  const QString bookmarksFile = KStandardDirs::locateLocal("data", QString::fromLatin1("konqueror/bookmarks.xml"));
672  KBookmarkManager* bookmarkManager = KBookmarkManager::managerForFile( bookmarksFile, "konqueror" );
673  bookmarkManager->setEditorOptions(KGlobal::caption(), true);
674  return bookmarkManager;
675 }
676 
677 KBookmarkSettings* KBookmarkSettings::s_self = 0;
678 
679 void KBookmarkSettings::readSettings()
680 {
681  KConfig config("kbookmarkrc", KConfig::NoGlobals);
682  KConfigGroup cg(&config, "Bookmarks");
683 
684  // add bookmark dialog usage - no reparse
685  s_self->m_advancedaddbookmark = cg.readEntry("AdvancedAddBookmarkDialog", false);
686 
687  // this one alters the menu, therefore it needs a reparse
688  s_self->m_contextmenu = cg.readEntry("ContextMenuActions", true);
689 }
690 
691 KBookmarkSettings *KBookmarkSettings::self()
692 {
693  if (!s_self)
694  {
695  s_self = new KBookmarkSettings;
696  readSettings();
697  }
698  return s_self;
699 }
700 
702 
703 bool KBookmarkOwner::enableOption(BookmarkOption action) const
704 {
705  if(action == ShowAddBookmark)
706  return true;
707  if(action == ShowEditBookmark)
708  return true;
709  return false;
710 }
711 
712 KBookmarkDialog * KBookmarkOwner::bookmarkDialog(KBookmarkManager * mgr, QWidget * parent)
713 {
714  return new KBookmarkDialog(mgr, parent);
715 }
716 
717 void KBookmarkOwner::openFolderinTabs(const KBookmarkGroup &)
718 {
719 
720 }
721 
722 #include "kbookmarkmanager.moc"
KGlobal::caption
QString caption()
i18n
QString i18n(const char *text)
createXbelTopLevelElement
static QDomElement createXbelTopLevelElement(QDomDocument &doc)
Definition: kbookmarkmanager.cc:205
KBookmarkSettings::m_contextmenu
bool m_contextmenu
Definition: kbookmarkmenu_p.h:88
kbookmarkmanager.h
KBookmarkOwner::ShowAddBookmark
Definition: kbookmarkmanager.h:422
KSaveFile::error
QFile::FileError error() const
KBookmarkSettings::self
static KBookmarkSettings * self()
Definition: kbookmarkmanager.cc:691
kdebug.h
KDirWatch::addFile
void addFile(const QString &file)
KBookmark::internalElement
QDomElement internalElement() const
Definition: kbookmark.cc:496
KBookmarkManager::path
QString path() const
This will return the path that this manager is using to read the bookmarks.
Definition: kbookmarkmanager.cc:459
KBookmarkSettings::s_self
static KBookmarkSettings * s_self
Definition: kbookmarkmenu_p.h:89
KBookmarkManager::updateFavicon
void updateFavicon(const QString &url, const QString &faviconurl)
Definition: kbookmarkmanager.cc:656
group
KBookmarkManager::setAutoErrorHandlingEnabled
void setAutoErrorHandlingEnabled(bool enable, QWidget *parent)
Enable or disable auto error handling is enabled.
Definition: kbookmarkmanager.cc:322
kdirwatch.h
kbookmarkmanageradaptor_p.h
KBookmarkManager::emitConfigChanged
void emitConfigChanged()
Definition: kbookmarkmanager.cc:564
PI_DATA
#define PI_DATA
Definition: kbookmarkmanager.cc:203
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
ksavefile.h
QWidget
KSaveFile
KSaveFile::open
virtual bool open(OpenMode flags=QIODevice::ReadWrite)
KBookmarkOwner::enableOption
virtual bool enableOption(BookmarkOption option) const
Returns true if action should be shown in the menu The default is to show both a add and editBookmark...
Definition: kbookmarkmanager.cc:703
KBookmarkGroup::findToolbar
QDomElement findToolbar() const
Definition: kbookmark.cc:247
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KBookmark::toGroup
KBookmarkGroup toGroup() const
Convert this to a group - do this only if isGroup() returns true.
Definition: kbookmark.cc:465
KBookmarkManager::slotEditBookmarksAtAddress
void slotEditBookmarksAtAddress(const QString &address)
Definition: kbookmarkmanager.cc:627
KBookmarkManager
This class implements the reading/writing of bookmarks in XML.
Definition: kbookmarkmanager.h:65
QString
KSaveFile::abort
void abort()
KBookmarkManager::configChanged
void configChanged()
Signals that the config changed.
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KBookmark
Definition: kbookmark.h:34
KBookmarkManagerAdaptor
Definition: kbookmarkmanageradaptor_p.h:27
KBookmarkManager::managerForFile
static KBookmarkManager * managerForFile(const QString &bookmarksFile, const QString &dbusObjectName)
This static function will return an instance of the KBookmarkManager, responsible for the given bookm...
Definition: kbookmarkmanager.cc:150
config
KSharedConfigPtr config()
KBookmarkOwner::ShowEditBookmark
Definition: kbookmarkmanager.h:422
kbookmarkimporter.h
KBookmarkOwner::BookmarkOption
BookmarkOption
Definition: kbookmarkmanager.h:422
KSaveFile::fileName
QString fileName() const
KBookmarkManager::createTempManager
static KBookmarkManager * createTempManager()
only used for KBookmarkBar
Definition: kbookmarkmanager.cc:196
KSaveFile::errorString
QString errorString() const
KBookmarkSettings::readSettings
static void readSettings()
Definition: kbookmarkmanager.cc:679
KConfig::NoGlobals
KBookmarkManager::setEditorOptions
void setEditorOptions(const QString &caption, bool browser)
Set options with which slotEditBookmarks called keditbookmarks this can be used to change the appeara...
Definition: kbookmarkmanager.cc:608
KBookmarkManager::updateAccessMetadata
bool updateAccessMetadata(const QString &url)
Update access time stamps for a given url.
Definition: kbookmarkmanager.cc:642
KBookmarkManager::slotEditBookmarks
void slotEditBookmarks()
Definition: kbookmarkmanager.cc:614
KBookmarkManager::setUpdate
void setUpdate(bool update)
Set the update flag.
Definition: kbookmarkmanager.cc:328
QStringList
KBookmarkManager::notifyChanged
void notifyChanged(const QString &groupAddress, const QDBusMessage &msg)
Emit the changed signal for the group whose address is given.
Definition: kbookmarkmanager.cc:591
KBookmark::isGroup
bool isGroup() const
Whether the bookmark is a group or a normal bookmark.
Definition: kbookmark.cc:283
KBookmarkManager::error
void error(const QString &errorMessage)
Emitted when an error occurs.
KBookmarkManager::saveAs
bool saveAs(const QString &filename, bool toolbarCache=true) const
Save the bookmarks to the given XML file on disk.
Definition: kbookmarkmanager.cc:401
KBookmarkManager::managerForExternalFile
static KBookmarkManager * managerForExternalFile(const QString &bookmarksFile)
Returns a KBookmarkManager, which will use KDirWatch for change detection This is important when shar...
Definition: kbookmarkmanager.cc:172
KBookmarkSettings
Definition: kbookmarkmenu_p.h:84
KBookmarkManager::save
bool save(bool toolbarCache=true) const
Save the bookmarks to an XML file on disk.
Definition: kbookmarkmanager.cc:396
KBookmarkManager::autoErrorHandlingEnabled
bool autoErrorHandlingEnabled() const
Check whether auto error handling is enabled.
Definition: kbookmarkmanager.cc:317
KBookmarkGroup
A group of bookmarks.
Definition: kbookmark.h:347
KBookmarkManager::bookmarkConfigChanged
void bookmarkConfigChanged()
Signal send over DBUS.
KBookmarkManager::changed
void changed(const QString &groupAddress, const QString &caller)
Signals that the group (or any of its children) with the address groupAddress (e.g.
KBookmarkManager::toolbar
KBookmarkGroup toolbar()
This returns the root of the toolbar menu.
Definition: kbookmarkmanager.cc:469
KBookmarkOwner::bookmarkDialog
virtual KBookmarkDialog * bookmarkDialog(KBookmarkManager *mgr, QWidget *parent)
Definition: kbookmarkmanager.cc:712
KBookmarkManager::userBookmarksManager
static KBookmarkManager * userBookmarksManager()
Returns a pointer to the user's main (konqueror) bookmark collection.
Definition: kbookmarkmanager.cc:669
KBookmarkOwner::openFolderinTabs
virtual void openFolderinTabs(const KBookmarkGroup &bm)
Called if the user wants to open every bookmark in this folder in a new tab.
Definition: kbookmarkmanager.cc:717
KBookmarkManager::bookmarksChanged
void bookmarksChanged(QString groupAddress)
Signal send over DBUS.
find
static int find(const QByteArray &buf, int begin, const char c1)
returns the position of the first occurrence of any of the given characters c1 or comma ('...
Definition: dataprotocol.cpp:85
KSaveFile::finalize
bool finalize()
KConfigGroup
KBookmarkManager::findByAddress
KBookmark findByAddress(const QString &address)
Definition: kbookmarkmanager.cc:515
KConfig
KBookmarkManager::emitChanged
void emitChanged()
Saves the bookmark file and notifies everyone.
Definition: kbookmarkmanager.cc:545
kbookmarkmenu.h
KBookmarkManager::root
KBookmarkGroup root() const
This will return the root bookmark.
Definition: kbookmarkmanager.cc:464
KBookmark::isSeparator
bool isSeparator() const
Whether the bookmark is a separator.
Definition: kbookmark.cc:290
KStandardDirs::locateLocal
static QString locateLocal(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
KBookmarkManager::KBookmarkGroup
friend class KBookmarkGroup
Definition: kbookmarkmanager.h:358
kstandarddirs.h
KBookmarkManager::notifyCompleteChange
void notifyCompleteChange(const QString &caller)
Reparse the whole bookmarks file and notify about the change Doesn't send signal over DBUS to the oth...
Definition: kbookmarkmanager.cc:569
KBookmarkSettings::m_advancedaddbookmark
bool m_advancedaddbookmark
Definition: kbookmarkmenu_p.h:87
KBookmarkManager::~KBookmarkManager
~KBookmarkManager()
Destructor.
Definition: kbookmarkmanager.cc:308
BOOKMARK_CHANGE_NOTIFY_INTERFACE
#define BOOKMARK_CHANGE_NOTIFY_INTERFACE
Definition: kbookmarkmanager.cc:47
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KDirWatch
kmessagebox.h
kbookmarkmenu_p.h
lookupExisting
static KBookmarkManager * lookupExisting(const QString &bookmarksFile)
Definition: kbookmarkmanager.cc:139
kbookmarkdialog.h
KBookmark::isNull
bool isNull() const
Definition: kbookmark.cc:295
end
const KShortcut & end()
KBookmarkManager::notifyConfigChanged
void notifyConfigChanged()
Definition: kbookmarkmanager.cc:583
KSaveFile::simpleBackupFile
static bool simpleBackupFile(const QString &filename, const QString &backupDir=QString(), const QString &backupExtension=QLatin1String("~"))
parse
QList< Action > parse(QSettings &ini)
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KBookmarkDialog
This class provides a Dialog for editing properties, adding Bookmarks and creating new folders...
Definition: kbookmarkdialog.h:44
KBookmarkGroupTraverser
Definition: kbookmark.h:459
KBookmarkManager::internalDocument
QDomDocument internalDocument() const
Definition: kbookmarkmanager.cc:333
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
QMap
Definition: netaccess.h:36
kconfiggroup.h
KBookmark::address
QString address() const
Return the "address" of this bookmark in the whole tree.
Definition: kbookmark.cc:471
QList
KIO::number
QString number(KIO::filesize_t size)
Converts a size to a string representation Not unlike QString::number(...)
Definition: global.cpp:63
begin
const KShortcut & begin()
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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