• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/bookmarks
 

kio/bookmarks

  • kio
  • bookmarks
kbookmarkmanager.cc
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 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "kbookmarkmanager.h"
23 #include "kbookmarkmenu.h"
24 #include "kbookmarkmenu_p.h"
25 #include "kbookmarkimporter.h"
26 #include <kdebug.h>
27 #include <krun.h>
28 #include <kstandarddirs.h>
29 #include <ksavefile.h>
30 #include <dcopref.h>
31 #include <tqregexp.h>
32 #include <kmessagebox.h>
33 #include <kprocess.h>
34 #include <klocale.h>
35 #include <kapplication.h>
36 #include <dcopclient.h>
37 #include <tqfile.h>
38 #include <tqfileinfo.h>
39 #include <tqtextstream.h>
40 #include <kstaticdeleter.h>
41 #include <tqptrstack.h>
42 
43 #include "dptrtemplate.h"
44 
45 class KBookmarkManagerPrivate : public dPtrTemplate<KBookmarkManager, KBookmarkManagerPrivate> {
46 public:
47  KBookmarkManagerPrivate()
48  { m_browserEditor = true; }
49  TQString m_editorCaption;
50  bool m_browserEditor;
51 };
52 template<> TQPtrDict<KBookmarkManagerPrivate>* dPtrTemplate<KBookmarkManager, KBookmarkManagerPrivate>::d_ptr = 0;
53 
54 KBookmarkManagerPrivate* KBookmarkManager::dptr() const {
55  return KBookmarkManagerPrivate::d( this );
56 }
57 
58 // TODO - clean this stuff up by just using the above dptrtemplate?
59 TQPtrList<KBookmarkManager>* KBookmarkManager::s_pSelf;
60 static KStaticDeleter<TQPtrList<KBookmarkManager> > sdbm;
61 
62 class KBookmarkMap : private KBookmarkGroupTraverser {
63 public:
64  KBookmarkMap( KBookmarkManager * );
65  void update();
66  TQValueList<KBookmark> find( const TQString &url ) const
67  { return m_bk_map[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 TQValueList<KBookmark> KBookmarkList;
74  TQMap<TQString, KBookmarkList> m_bk_map;
75  KBookmarkManager *m_manager;
76 };
77 
78 static KBookmarkMap *s_bk_map = 0;
79 
80 KBookmarkMap::KBookmarkMap( KBookmarkManager *manager ) {
81  m_manager = manager;
82 }
83 
84 void KBookmarkMap::update()
85 {
86  m_bk_map.clear();
87  KBookmarkGroup root = m_manager->root();
88  traverse(root);
89 }
90 
91 void KBookmarkMap::visit(const KBookmark &bk)
92 {
93  if (!bk.isSeparator()) {
94  // add bookmark to url map
95  m_bk_map[bk.internalElement().attribute("href")].append(bk);
96  }
97 }
98 
99 
100 KBookmarkManager* KBookmarkManager::managerForFile( const TQString& bookmarksFile, bool bImportDesktopFiles )
101 {
102  if ( !s_pSelf ) {
103  sdbm.setObject( s_pSelf, new TQPtrList<KBookmarkManager> );
104  s_pSelf->setAutoDelete( true );
105  }
106  TQPtrListIterator<KBookmarkManager> it ( *s_pSelf );
107  for ( ; it.current() ; ++it )
108  if ( it.current()->path() == bookmarksFile )
109  return it.current();
110 
111  KBookmarkManager* mgr = new KBookmarkManager( bookmarksFile, bImportDesktopFiles );
112  s_pSelf->append( mgr );
113  return mgr;
114 }
115 
116 // principally used for filtered toolbars
117 KBookmarkManager* KBookmarkManager::createTempManager()
118 {
119  if ( !s_pSelf ) {
120  sdbm.setObject( s_pSelf, new TQPtrList<KBookmarkManager> );
121  s_pSelf->setAutoDelete( true );
122  }
123  KBookmarkManager* mgr = new KBookmarkManager();
124  s_pSelf->append( mgr );
125  return mgr;
126 }
127 
128 #define PI_DATA "version=\"1.0\" encoding=\"UTF-8\""
129 
130 KBookmarkManager::KBookmarkManager( const TQString & bookmarksFile, bool bImportDesktopFiles )
131  : DCOPObject(TQCString("KBookmarkManager-")+bookmarksFile.utf8()), m_doc("xbel"), m_docIsLoaded(false)
132 {
133  m_toolbarDoc.clear();
134 
135  m_update = true;
136  m_showNSBookmarks = true;
137 
138  Q_ASSERT( !bookmarksFile.isEmpty() );
139  m_bookmarksFile = bookmarksFile;
140 
141  if ( !TQFile::exists(m_bookmarksFile) )
142  {
143  TQDomElement topLevel = m_doc.createElement("xbel");
144  m_doc.appendChild( topLevel );
145  m_doc.insertBefore( m_doc.createProcessingInstruction( "xml", PI_DATA), topLevel );
146  if ( bImportDesktopFiles )
147  importDesktopFiles();
148  m_docIsLoaded = true;
149  }
150 
151  connectDCOPSignal(0, objId(), "bookmarksChanged(TQString)", "notifyChanged(TQString)", false);
152  connectDCOPSignal(0, objId(), "bookmarkConfigChanged()", "notifyConfigChanged()", false);
153 }
154 
155 KBookmarkManager::KBookmarkManager( )
156  : DCOPObject(TQCString("KBookmarkManager-generated")), m_doc("xbel"), m_docIsLoaded(true)
157 {
158  m_toolbarDoc.clear(); // strange ;-)
159 
160  m_update = false; // TODO - make it read/write
161  m_showNSBookmarks = true;
162 
163  m_bookmarksFile = TQString::null; // AK - check all codepaths for this one
164 
165  TQDomElement topLevel = m_doc.createElement("xbel");
166  m_doc.appendChild( topLevel );
167  m_doc.insertBefore( m_doc.createProcessingInstruction( "xml", PI_DATA), topLevel );
168 
169  // TODO - enable this via some sort of api and fix the above DCOPObject script somehow
170 #if 0
171  connectDCOPSignal(0, objId(), "bookmarksChanged(TQString)", "notifyChanged(TQString)", false);
172  connectDCOPSignal(0, objId(), "bookmarkConfigChanged()", "notifyConfigChanged()", false);
173 #endif
174 }
175 
176 KBookmarkManager::~KBookmarkManager()
177 {
178  if ( s_pSelf )
179  s_pSelf->removeRef( this );
180 }
181 
182 void KBookmarkManager::setUpdate( bool update )
183 {
184  m_update = update;
185 }
186 
187 const TQDomDocument &KBookmarkManager::internalDocument() const
188 {
189  if(!m_docIsLoaded)
190  {
191  parse();
192  m_toolbarDoc.clear();
193  }
194  return m_doc;
195 }
196 
197 
198 void KBookmarkManager::parse() const
199 {
200  m_docIsLoaded = true;
201  //kdDebug(7043) << "KBookmarkManager::parse " << m_bookmarksFile << endl;
202  TQFile file( m_bookmarksFile );
203  if ( !file.open( IO_ReadOnly ) )
204  {
205  kdWarning() << "Can't open " << m_bookmarksFile << endl;
206  return;
207  }
208  m_doc = TQDomDocument("xbel");
209  m_doc.setContent( &file );
210 
211  TQDomElement docElem = m_doc.documentElement();
212  if ( docElem.isNull() )
213  kdWarning() << "KBookmarkManager::parse : can't parse " << m_bookmarksFile << endl;
214  else
215  {
216  TQString mainTag = docElem.tagName();
217  if ( mainTag == "BOOKMARKS" )
218  {
219  kdWarning() << "Old style bookmarks found. Calling convertToXBEL." << endl;
220  docElem.setTagName("xbel");
221  if ( docElem.hasAttribute( "HIDE_NSBK" ) && m_showNSBookmarks ) // non standard either, but we need it
222  {
223  docElem.setAttribute( "hide_nsbk", docElem.attribute( "HIDE_NSBK" ) == "1" ? "yes" : "no" );
224  docElem.removeAttribute( "HIDE_NSBK" );
225  }
226 
227  convertToXBEL( docElem );
228  save();
229  }
230  else if ( mainTag != "xbel" )
231  kdWarning() << "KBookmarkManager::parse : unknown main tag " << mainTag << endl;
232 
233  TQDomNode n = m_doc.documentElement().previousSibling();
234  if ( n.isProcessingInstruction() )
235  {
236  TQDomProcessingInstruction pi = n.toProcessingInstruction();
237  pi.parentNode().removeChild(pi);
238  }
239 
240  TQDomProcessingInstruction pi;
241  pi = m_doc.createProcessingInstruction( "xml", PI_DATA );
242  m_doc.insertBefore( pi, docElem );
243  }
244 
245  file.close();
246  if ( !s_bk_map )
247  s_bk_map = new KBookmarkMap( const_cast<KBookmarkManager*>( this ) );
248  s_bk_map->update();
249 }
250 
251 void KBookmarkManager::convertToXBEL( TQDomElement & group )
252 {
253  TQDomNode n = group.firstChild();
254  while( !n.isNull() )
255  {
256  TQDomElement e = n.toElement();
257  if ( !e.isNull() )
258  {
259  if ( e.tagName() == "TEXT" )
260  {
261  e.setTagName("title");
262  }
263  else if ( e.tagName() == "SEPARATOR" )
264  {
265  e.setTagName("separator"); // so close...
266  }
267  else if ( e.tagName() == "GROUP" )
268  {
269  e.setTagName("folder");
270  convertAttribute(e, "ICON","icon"); // non standard, but we need it
271  if ( e.hasAttribute( "TOOLBAR" ) ) // non standard either, but we need it
272  {
273  e.setAttribute( "toolbar", e.attribute( "TOOLBAR" ) == "1" ? "yes" : "no" );
274  e.removeAttribute( "TOOLBAR" );
275  }
276 
277  convertAttribute(e, "NETSCAPEINFO","netscapeinfo"); // idem
278  bool open = (e.attribute("OPEN") == "1");
279  e.removeAttribute("OPEN");
280  e.setAttribute("folded", open ? "no" : "yes");
281  convertToXBEL( e );
282  }
283  else
284  {
285  if ( e.tagName() == "BOOKMARK" )
286  {
287  e.setTagName("bookmark"); // so much difference :-)
288  convertAttribute(e, "ICON","icon"); // non standard, but we need it
289  convertAttribute(e, "NETSCAPEINFO","netscapeinfo"); // idem
290  convertAttribute(e, "URL","href");
291  TQString text = e.text();
292  while ( !e.firstChild().isNull() ) // clean up the old contained text
293  e.removeChild(e.firstChild());
294  TQDomElement titleElem = e.ownerDocument().createElement("title");
295  e.appendChild( titleElem ); // should be the only child anyway
296  titleElem.appendChild( e.ownerDocument().createTextNode( text ) );
297  }
298  else
299  {
300  kdWarning(7043) << "Unknown tag " << e.tagName() << endl;
301  }
302  }
303  }
304  n = n.nextSibling();
305  }
306 }
307 
308 void KBookmarkManager::convertAttribute( TQDomElement elem, const TQString & oldName, const TQString & newName )
309 {
310  if ( elem.hasAttribute( oldName ) )
311  {
312  elem.setAttribute( newName, elem.attribute( oldName ) );
313  elem.removeAttribute( oldName );
314  }
315 }
316 
317 void KBookmarkManager::importDesktopFiles()
318 {
319  KBookmarkImporter importer( const_cast<TQDomDocument *>(&internalDocument()) );
320  TQString path(KGlobal::dirs()->saveLocation("data", "kfm/bookmarks", true));
321  importer.import( path );
322  //kdDebug(7043) << internalDocument().toCString() << endl;
323 
324  save();
325 }
326 
327 bool KBookmarkManager::save( bool toolbarCache ) const
328 {
329  return saveAs( m_bookmarksFile, toolbarCache );
330 }
331 
332 bool KBookmarkManager::saveAs( const TQString & filename, bool toolbarCache ) const
333 {
334  kdDebug(7043) << "KBookmarkManager::save " << filename << endl;
335 
336  // Save the bookmark toolbar folder for quick loading
337  // but only when it will actually make things quicker
338  const TQString cacheFilename = filename + TQString::fromLatin1(".tbcache");
339  if(toolbarCache && !root().isToolbarGroup())
340  {
341  KSaveFile cacheFile( cacheFilename );
342  if ( cacheFile.status() == 0 )
343  {
344  TQString str;
345  TQTextStream stream(&str, IO_WriteOnly);
346  stream << root().findToolbar();
347  TQCString cstr = str.utf8();
348  cacheFile.file()->writeBlock( cstr.data(), cstr.length() );
349  cacheFile.close();
350  }
351  }
352  else // remove any (now) stale cache
353  {
354  TQFile::remove( cacheFilename );
355  }
356 
357  KSaveFile file( filename );
358  if ( file.status() == 0 )
359  {
360  file.backupFile( file.name(), TQString::null, ".bak" );
361  TQCString cstr;
362  cstr = internalDocument().toCString(); // is in UTF8
363  file.file()->writeBlock( cstr.data(), cstr.length() );
364  if ( file.close() )
365  return true;
366  }
367 
368  static int hadSaveError = false;
369  file.abort();
370  if ( !hadSaveError ) {
371  TQString error = i18n("Unable to save bookmarks in %1. Reported error was: %2. "
372  "This error message will only be shown once. The cause "
373  "of the error needs to be fixed as quickly as possible, "
374  "which is most likely a full hard drive.")
375  .arg(filename).arg(TQString::fromLocal8Bit(strerror(file.status())));
376  if (tqApp->type() != TQApplication::Tty)
377  KMessageBox::error( 0L, error );
378  else
379  kdError() << error << endl;
380  }
381  hadSaveError = true;
382  return false;
383 }
384 
385 KBookmarkGroup KBookmarkManager::root() const
386 {
387  return KBookmarkGroup(internalDocument().documentElement());
388 }
389 
390 KBookmarkGroup KBookmarkManager::toolbar()
391 {
392  kdDebug(7043) << "KBookmarkManager::toolbar begin" << endl;
393  // Only try to read from a toolbar cache if the full document isn't loaded
394  if(!m_docIsLoaded)
395  {
396  kdDebug(7043) << "KBookmarkManager::toolbar trying cache" << endl;
397  const TQString cacheFilename = m_bookmarksFile + TQString::fromLatin1(".tbcache");
398  TQFileInfo bmInfo(m_bookmarksFile);
399  TQFileInfo cacheInfo(cacheFilename);
400  if (m_toolbarDoc.isNull() &&
401  TQFile::exists(cacheFilename) &&
402  bmInfo.lastModified() < cacheInfo.lastModified())
403  {
404  kdDebug(7043) << "KBookmarkManager::toolbar reading file" << endl;
405  TQFile file( cacheFilename );
406 
407  if ( file.open( IO_ReadOnly ) )
408  {
409  m_toolbarDoc = TQDomDocument("cache");
410  m_toolbarDoc.setContent( &file );
411  kdDebug(7043) << "KBookmarkManager::toolbar opened" << endl;
412  }
413  }
414  if (!m_toolbarDoc.isNull())
415  {
416  kdDebug(7043) << "KBookmarkManager::toolbar returning element" << endl;
417  TQDomElement elem = m_toolbarDoc.firstChild().toElement();
418  return KBookmarkGroup(elem);
419  }
420  }
421 
422  // Fallback to the normal way if there is no cache or if the bookmark file
423  // is already loaded
424  TQDomElement elem = root().findToolbar();
425  if (elem.isNull())
426  return root(); // Root is the bookmark toolbar if none has been set.
427  else
428  return KBookmarkGroup(root().findToolbar());
429 }
430 
431 KBookmark KBookmarkManager::findByAddress( const TQString & address, bool tolerant )
432 {
433  //kdDebug(7043) << "KBookmarkManager::findByAddress " << address << endl;
434  KBookmark result = root();
435  // The address is something like /5/10/2+
436  TQStringList addresses = TQStringList::split(TQRegExp("[/+]"),address);
437  // kdWarning() << addresses.join(",") << endl;
438  for ( TQStringList::Iterator it = addresses.begin() ; it != addresses.end() ; )
439  {
440  bool append = ((*it) == "+");
441  uint number = (*it).toUInt();
442  Q_ASSERT(result.isGroup());
443  KBookmarkGroup group = result.toGroup();
444  KBookmark bk = group.first(), lbk = bk; // last non-null bookmark
445  for ( uint i = 0 ; ( (i<number) || append ) && !bk.isNull() ; ++i ) {
446  lbk = bk;
447  bk = group.next(bk);
448  //kdWarning() << i << endl;
449  }
450  it++;
451  int shouldBeGroup = !bk.isGroup() && (it != addresses.end());
452  if ( tolerant && ( bk.isNull() || shouldBeGroup ) ) {
453  if (!lbk.isNull()) result = lbk;
454  //kdWarning() << "break" << endl;
455  break;
456  }
457  //kdWarning() << "found section" << endl;
458  result = bk;
459  }
460  if (result.isNull()) {
461  kdWarning() << "KBookmarkManager::findByAddress: couldn't find item " << address << endl;
462  Q_ASSERT(!tolerant);
463  }
464  //kdWarning() << "found " << result.address() << endl;
465  return result;
466  }
467 
468 static TQString pickUnusedTitle( KBookmarkGroup parentBookmark,
469  const TQString &title, const TQString &url
470 ) {
471  // If this title is already used, we'll try to find something unused.
472  KBookmark ch = parentBookmark.first();
473  int count = 1;
474  TQString uniqueTitle = title;
475  do
476  {
477  while ( !ch.isNull() )
478  {
479  if ( uniqueTitle == ch.text() )
480  {
481  // Title already used !
482  if ( url != ch.url().url() )
483  {
484  uniqueTitle = title + TQString(" (%1)").arg(++count);
485  // New title -> restart search from the beginning
486  ch = parentBookmark.first();
487  break;
488  }
489  else
490  {
491  // this exact URL already exists
492  return TQString::null;
493  }
494  }
495  ch = parentBookmark.next( ch );
496  }
497  } while ( !ch.isNull() );
498 
499  return uniqueTitle;
500 }
501 
502 KBookmarkGroup KBookmarkManager::addBookmarkDialog(
503  const TQString & _url, const TQString & _title,
504  const TQString & _parentBookmarkAddress
505 ) {
506  TQString url = _url;
507  TQString title = _title;
508  TQString parentBookmarkAddress = _parentBookmarkAddress;
509 
510  if ( url.isEmpty() )
511  {
512  KMessageBox::error( 0L, i18n("Cannot add bookmark with empty URL."));
513  return KBookmarkGroup();
514  }
515 
516  if ( title.isEmpty() )
517  title = url;
518 
519  if ( KBookmarkSettings::self()->m_advancedaddbookmark)
520  {
521  KBookmarkEditDialog dlg( title, url, this, KBookmarkEditDialog::InsertionMode, parentBookmarkAddress );
522  if ( dlg.exec() != KDialogBase::Accepted )
523  return KBookmarkGroup();
524  title = dlg.finalTitle();
525  url = dlg.finalUrl();
526  parentBookmarkAddress = dlg.finalAddress();
527  }
528 
529  KBookmarkGroup parentBookmark;
530  parentBookmark = findByAddress( parentBookmarkAddress ).toGroup();
531  Q_ASSERT( !parentBookmark.isNull() );
532 
533  TQString uniqueTitle = pickUnusedTitle( parentBookmark, title, url );
534  if ( !uniqueTitle.isNull() )
535  parentBookmark.addBookmark( this, uniqueTitle, KURL( url ));
536 
537  return parentBookmark;
538 }
539 
540 
541 void KBookmarkManager::emitChanged( /*KDE4 const*/ KBookmarkGroup & group )
542 {
543  save();
544 
545  // Tell the other processes too
546  // kdDebug(7043) << "KBookmarkManager::emitChanged : broadcasting change " << group.address() << endl;
547 
548  TQByteArray data;
549  TQDataStream ds( data, IO_WriteOnly );
550  ds << group.address();
551 
552  emitDCOPSignal("bookmarksChanged(TQString)", data);
553 
554  // We do get our own broadcast, so no need for this anymore
555  //emit changed( group );
556 }
557 
558 void KBookmarkManager::emitConfigChanged()
559 {
560  emitDCOPSignal("bookmarkConfigChanged()", TQByteArray());
561 }
562 
563 void KBookmarkManager::notifyCompleteChange( TQString caller ) // DCOP call
564 {
565  if (!m_update) return;
566 
567  //kdDebug(7043) << "KBookmarkManager::notifyCompleteChange" << endl;
568  // The bk editor tells us we should reload everything
569  // Reparse
570  parse();
571  // Tell our GUI
572  // (emit where group is "" to directly mark the root menu as dirty)
573  emit changed( "", caller );
574 }
575 
576 void KBookmarkManager::notifyConfigChanged() // DCOP call
577 {
578  kdDebug() << "reloaded bookmark config!" << endl;
579  KBookmarkSettings::self()->readSettings();
580  parse(); // reload, and thusly recreate the menus
581 }
582 
583 void KBookmarkManager::notifyChanged( TQString groupAddress ) // DCOP call
584 {
585  if (!m_update) return;
586 
587  // Reparse (the whole file, no other choice)
588  // if someone else notified us
589  if (callingDcopClient()->senderId() != DCOPClient::mainClient()->appId())
590  parse();
591 
592  //kdDebug(7043) << "KBookmarkManager::notifyChanged " << groupAddress << endl;
593  //KBookmarkGroup group = findByAddress( groupAddress ).toGroup();
594  //Q_ASSERT(!group.isNull());
595  emit changed( groupAddress, TQString::null );
596 }
597 
598 bool KBookmarkManager::showNSBookmarks() const
599 {
600  return KBookmarkMenu::showDynamicBookmarks("netscape").show;
601 }
602 
603 void KBookmarkManager::setShowNSBookmarks( bool show )
604 {
605  m_showNSBookmarks = show;
606  if (this->path() != userBookmarksFile())
607  return;
608  KBookmarkMenu::DynMenuInfo info
609  = KBookmarkMenu::showDynamicBookmarks("netscape");
610  info.show = show;
611  KBookmarkMenu::setDynamicBookmarks("netscape", info);
612 }
613 
614 void KBookmarkManager::setEditorOptions( const TQString& caption, bool browser )
615 {
616  dptr()->m_editorCaption = caption;
617  dptr()->m_browserEditor = browser;
618 }
619 
620 void KBookmarkManager::slotEditBookmarks()
621 {
622  KProcess proc;
623  proc << TQString::fromLatin1("keditbookmarks");
624  if (!dptr()->m_editorCaption.isNull())
625  proc << TQString::fromLatin1("--customcaption") << dptr()->m_editorCaption;
626  if (!dptr()->m_browserEditor)
627  proc << TQString::fromLatin1("--nobrowser");
628  proc << m_bookmarksFile;
629  proc.start(KProcess::DontCare);
630 }
631 
632 void KBookmarkManager::slotEditBookmarksAtAddress( const TQString& address )
633 {
634  KProcess proc;
635  proc << TQString::fromLatin1("keditbookmarks")
636  << TQString::fromLatin1("--address") << address
637  << m_bookmarksFile;
638  proc.start(KProcess::DontCare);
639 }
640 
642 
643 void KBookmarkOwner::openBookmarkURL( const TQString& url )
644 {
645  (void) new KRun(KURL( url ));
646 }
647 
648 void KBookmarkOwner::virtual_hook( int, void* )
649 { /*BASE::virtual_hook( id, data );*/ }
650 
651 bool KBookmarkManager::updateAccessMetadata( const TQString & url, bool emitSignal )
652 {
653  if (!s_bk_map) {
654  s_bk_map = new KBookmarkMap(this);
655  s_bk_map->update();
656  }
657 
658  TQValueList<KBookmark> list = s_bk_map->find(url);
659  if ( list.count() == 0 )
660  return false;
661 
662  for ( TQValueList<KBookmark>::iterator it = list.begin();
663  it != list.end(); ++it )
664  (*it).updateAccessMetadata();
665 
666  if (emitSignal)
667  emit notifier().updatedAccessMetadata( path(), url );
668 
669  return true;
670 }
671 
672 void KBookmarkManager::updateFavicon( const TQString &url, const TQString &faviconurl, bool emitSignal )
673 {
674  Q_UNUSED(faviconurl);
675 
676  if (!s_bk_map) {
677  s_bk_map = new KBookmarkMap(this);
678  s_bk_map->update();
679  }
680 
681  TQValueList<KBookmark> list = s_bk_map->find(url);
682  for ( TQValueList<KBookmark>::iterator it = list.begin();
683  it != list.end(); ++it )
684  {
685  // TODO - update favicon data based on faviconurl
686  // but only when the previously used icon
687  // isn't a manually set one.
688  }
689 
690  if (emitSignal)
691  {
692  // TODO
693  // emit notifier().updatedFavicon( path(), url, faviconurl );
694  }
695 }
696 
697 TQString KBookmarkManager::userBookmarksFile()
698 {
699  return locateLocal("data", TQString::fromLatin1("konqueror/bookmarks.xml"));
700 }
701 
702 KBookmarkManager* KBookmarkManager::userBookmarksManager()
703 {
704  return KBookmarkManager::managerForFile( userBookmarksFile() );
705 }
706 
707 KBookmarkSettings* KBookmarkSettings::s_self = 0;
708 
709 void KBookmarkSettings::readSettings()
710 {
711  KConfig config("kbookmarkrc", false, false);
712  config.setGroup("Bookmarks");
713 
714  // add bookmark dialog usage - no reparse
715  s_self->m_advancedaddbookmark = config.readBoolEntry("AdvancedAddBookmarkDialog", false);
716 
717  // these three alter the menu, therefore all need a reparse
718  s_self->m_contextmenu = config.readBoolEntry("ContextMenuActions", true);
719  s_self->m_quickactions = config.readBoolEntry("QuickActionSubmenu", false);
720  s_self->m_filteredtoolbar = config.readBoolEntry("FilteredToolbar", false);
721 }
722 
723 KBookmarkSettings *KBookmarkSettings::self()
724 {
725  if (!s_self)
726  {
727  s_self = new KBookmarkSettings;
728  readSettings();
729  }
730  return s_self;
731 }
732 
733 #include "kbookmarkmanager.moc"
KBookmarkGroupTraverser
Definition: kbookmark.h:318
KBookmarkGroup
A group of bookmarks.
Definition: kbookmark.h:200
KBookmarkGroup::next
KBookmark next(const KBookmark &current) const
Return the next sibling of a child bookmark of this group.
Definition: kbookmark.cc:83
KBookmarkGroup::first
KBookmark first() const
Return the first child bookmark of this group.
Definition: kbookmark.cc:73
KBookmarkGroup::addBookmark
KBookmark addBookmark(KBookmarkManager *mgr, const KBookmark &bm, bool emitSignal=true)
Create a new bookmark, as the last child of this group Don't forget to use KBookmarkManager::self()->...
Definition: kbookmark.cc:178
KBookmarkImporter
A class for importing the previous bookmarks (desktop files) Separated from KBookmarkManager to save ...
Definition: kbookmarkimporter_kde1.h:35
KBookmarkManager
This class implements the reading/writing of bookmarks in XML.
Definition: kbookmarkmanager.h:54
KBookmarkManager::emitChanged
void emitChanged(KBookmarkGroup &group)
Saves the bookmark file and notifies everyone.
Definition: kbookmarkmanager.cc:541
KBookmarkManager::path
TQString path()
This will return the path that this manager is using to read the bookmarks.
Definition: kbookmarkmanager.h:134
KBookmarkManager::findByAddress
KBookmark findByAddress(const TQString &address, bool tolerate=false)
Definition: kbookmarkmanager.cc:431
KBookmarkManager::notifyChanged
ASYNC notifyChanged(TQString groupAddress)
Emit the changed signal for the group whose address is given.
Definition: kbookmarkmanager.cc:583
KBookmarkManager::toolbar
KBookmarkGroup toolbar()
This returns the root of the toolbar menu.
Definition: kbookmarkmanager.cc:390
KBookmarkManager::saveAs
bool saveAs(const TQString &filename, bool toolbarCache=true) const
Save the bookmarks to the given XML file on disk.
Definition: kbookmarkmanager.cc:332
KBookmarkManager::setEditorOptions
void setEditorOptions(const TQString &caption, bool browser)
Set options with which slotEditBookmarks called keditbookmarks this can be used to change the appeara...
Definition: kbookmarkmanager.cc:614
KBookmarkManager::setUpdate
void setUpdate(bool update)
Set the update flag.
Definition: kbookmarkmanager.cc:182
KBookmarkManager::notifier
KBookmarkNotifier & notifier()
Access to bookmark notifier, for emitting signals.
Definition: kbookmarkmanager.h:237
KBookmarkManager::addBookmarkDialog
KBookmarkGroup addBookmarkDialog(const TQString &_url, const TQString &_title, const TQString &_parentBookmarkAddress=TQString::null)
Definition: kbookmarkmanager.cc:502
KBookmarkManager::userBookmarksManager
static KBookmarkManager * userBookmarksManager()
Returns a pointer to the users main bookmark collection.
Definition: kbookmarkmanager.cc:702
KBookmarkManager::save
bool save(bool toolbarCache=true) const
Save the bookmarks to the default konqueror XML file on disk.
Definition: kbookmarkmanager.cc:327
KBookmarkManager::root
KBookmarkGroup root() const
This will return the root bookmark.
Definition: kbookmarkmanager.cc:385
KBookmarkManager::showNSBookmarks
bool showNSBookmarks() const
Definition: kbookmarkmanager.cc:598
KBookmarkManager::changed
void changed(const TQString &groupAddress, const TQString &caller)
Signals that the group (or any of its children) with the address groupAddress (e.g.
KBookmarkManager::~KBookmarkManager
~KBookmarkManager()
Destructor.
Definition: kbookmarkmanager.cc:176
KBookmarkManager::notifyCompleteChange
ASYNC notifyCompleteChange(TQString caller)
Reparse the whole bookmarks file and notify about the change (Called by the bookmark editor)
Definition: kbookmarkmanager.cc:563
KBookmarkManager::managerForFile
static KBookmarkManager * managerForFile(const TQString &bookmarksFile, bool bImportDesktopFiles=true)
This static function will return an instance of the KBookmarkManager, responsible for the given bookm...
Definition: kbookmarkmanager.cc:100
KBookmarkManager::KBookmarkManager
KBookmarkManager()
Definition: kbookmarkmanager.cc:155
KBookmarkManager::userBookmarksFile
static TQString userBookmarksFile()
Returns the path to the user's main bookmark collection file.
Definition: kbookmarkmanager.cc:697
KBookmarkManager::setShowNSBookmarks
void setShowNSBookmarks(bool show)
Shows an extra menu for NS bookmarks.
Definition: kbookmarkmanager.cc:603
KBookmarkManager::updateAccessMetadata
bool updateAccessMetadata(const TQString &url, bool emitSignal=true)
Update access time stamps for a given url.
Definition: kbookmarkmanager.cc:651
KBookmarkMenu::showDynamicBookmarks
static DynMenuInfo showDynamicBookmarks(const TQString &id)
Definition: kbookmarkmenu.cc:1100
KBookmarkMenu::setDynamicBookmarks
static void setDynamicBookmarks(const TQString &id, const DynMenuInfo &info)
Shows an extra menu for the given bookmarks file and type.
Definition: kbookmarkmenu.cc:1146
KBookmarkOwner::openBookmarkURL
virtual void openBookmarkURL(const TQString &_url)
This function is called if the user selects a bookmark.
Definition: kbookmarkmanager.cc:643
KBookmarkMenu::DynMenuInfo
Structure used for storing information about the dynamic menu setting.
Definition: kbookmarkmenu.h:130

kio/bookmarks

Skip menu "kio/bookmarks"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kio/bookmarks

Skip menu "kio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/bookmarks by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |