• 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  if ( e.tagName() == "TEXT" )
259  {
260  e.setTagName("title");
261  }
262  else if ( e.tagName() == "SEPARATOR" )
263  {
264  e.setTagName("separator"); // so close...
265  }
266  else if ( e.tagName() == "GROUP" )
267  {
268  e.setTagName("folder");
269  convertAttribute(e, "ICON","icon"); // non standard, but we need it
270  if ( e.hasAttribute( "TOOLBAR" ) ) // non standard either, but we need it
271  {
272  e.setAttribute( "toolbar", e.attribute( "TOOLBAR" ) == "1" ? "yes" : "no" );
273  e.removeAttribute( "TOOLBAR" );
274  }
275 
276  convertAttribute(e, "NETSCAPEINFO","netscapeinfo"); // idem
277  bool open = (e.attribute("OPEN") == "1");
278  e.removeAttribute("OPEN");
279  e.setAttribute("folded", open ? "no" : "yes");
280  convertToXBEL( e );
281  }
282  else
283  if ( e.tagName() == "BOOKMARK" )
284  {
285  e.setTagName("bookmark"); // so much difference :-)
286  convertAttribute(e, "ICON","icon"); // non standard, but we need it
287  convertAttribute(e, "NETSCAPEINFO","netscapeinfo"); // idem
288  convertAttribute(e, "URL","href");
289  TQString text = e.text();
290  while ( !e.firstChild().isNull() ) // clean up the old contained text
291  e.removeChild(e.firstChild());
292  TQDomElement titleElem = e.ownerDocument().createElement("title");
293  e.appendChild( titleElem ); // should be the only child anyway
294  titleElem.appendChild( e.ownerDocument().createTextNode( text ) );
295  }
296  else
297  kdWarning(7043) << "Unknown tag " << e.tagName() << endl;
298  n = n.nextSibling();
299  }
300 }
301 
302 void KBookmarkManager::convertAttribute( TQDomElement elem, const TQString & oldName, const TQString & newName )
303 {
304  if ( elem.hasAttribute( oldName ) )
305  {
306  elem.setAttribute( newName, elem.attribute( oldName ) );
307  elem.removeAttribute( oldName );
308  }
309 }
310 
311 void KBookmarkManager::importDesktopFiles()
312 {
313  KBookmarkImporter importer( const_cast<TQDomDocument *>(&internalDocument()) );
314  TQString path(KGlobal::dirs()->saveLocation("data", "kfm/bookmarks", true));
315  importer.import( path );
316  //kdDebug(7043) << internalDocument().toCString() << endl;
317 
318  save();
319 }
320 
321 bool KBookmarkManager::save( bool toolbarCache ) const
322 {
323  return saveAs( m_bookmarksFile, toolbarCache );
324 }
325 
326 bool KBookmarkManager::saveAs( const TQString & filename, bool toolbarCache ) const
327 {
328  kdDebug(7043) << "KBookmarkManager::save " << filename << endl;
329 
330  // Save the bookmark toolbar folder for quick loading
331  // but only when it will actually make things quicker
332  const TQString cacheFilename = filename + TQString::fromLatin1(".tbcache");
333  if(toolbarCache && !root().isToolbarGroup())
334  {
335  KSaveFile cacheFile( cacheFilename );
336  if ( cacheFile.status() == 0 )
337  {
338  TQString str;
339  TQTextStream stream(&str, IO_WriteOnly);
340  stream << root().findToolbar();
341  TQCString cstr = str.utf8();
342  cacheFile.file()->writeBlock( cstr.data(), cstr.length() );
343  cacheFile.close();
344  }
345  }
346  else // remove any (now) stale cache
347  {
348  TQFile::remove( cacheFilename );
349  }
350 
351  KSaveFile file( filename );
352  if ( file.status() == 0 )
353  {
354  file.backupFile( file.name(), TQString::null, ".bak" );
355  TQCString cstr;
356  cstr = internalDocument().toCString(); // is in UTF8
357  file.file()->writeBlock( cstr.data(), cstr.length() );
358  if ( file.close() )
359  return true;
360  }
361 
362  static int hadSaveError = false;
363  file.abort();
364  if ( !hadSaveError ) {
365  TQString error = i18n("Unable to save bookmarks in %1. Reported error was: %2. "
366  "This error message will only be shown once. The cause "
367  "of the error needs to be fixed as quickly as possible, "
368  "which is most likely a full hard drive.")
369  .arg(filename).arg(TQString::fromLocal8Bit(strerror(file.status())));
370  if (tqApp->type() != TQApplication::Tty)
371  KMessageBox::error( 0L, error );
372  else
373  kdError() << error << endl;
374  }
375  hadSaveError = true;
376  return false;
377 }
378 
379 KBookmarkGroup KBookmarkManager::root() const
380 {
381  return KBookmarkGroup(internalDocument().documentElement());
382 }
383 
384 KBookmarkGroup KBookmarkManager::toolbar()
385 {
386  kdDebug(7043) << "KBookmarkManager::toolbar begin" << endl;
387  // Only try to read from a toolbar cache if the full document isn't loaded
388  if(!m_docIsLoaded)
389  {
390  kdDebug(7043) << "KBookmarkManager::toolbar trying cache" << endl;
391  const TQString cacheFilename = m_bookmarksFile + TQString::fromLatin1(".tbcache");
392  TQFileInfo bmInfo(m_bookmarksFile);
393  TQFileInfo cacheInfo(cacheFilename);
394  if (m_toolbarDoc.isNull() &&
395  TQFile::exists(cacheFilename) &&
396  bmInfo.lastModified() < cacheInfo.lastModified())
397  {
398  kdDebug(7043) << "KBookmarkManager::toolbar reading file" << endl;
399  TQFile file( cacheFilename );
400 
401  if ( file.open( IO_ReadOnly ) )
402  {
403  m_toolbarDoc = TQDomDocument("cache");
404  m_toolbarDoc.setContent( &file );
405  kdDebug(7043) << "KBookmarkManager::toolbar opened" << endl;
406  }
407  }
408  if (!m_toolbarDoc.isNull())
409  {
410  kdDebug(7043) << "KBookmarkManager::toolbar returning element" << endl;
411  TQDomElement elem = m_toolbarDoc.firstChild().toElement();
412  return KBookmarkGroup(elem);
413  }
414  }
415 
416  // Fallback to the normal way if there is no cache or if the bookmark file
417  // is already loaded
418  TQDomElement elem = root().findToolbar();
419  if (elem.isNull())
420  return root(); // Root is the bookmark toolbar if none has been set.
421  else
422  return KBookmarkGroup(root().findToolbar());
423 }
424 
425 KBookmark KBookmarkManager::findByAddress( const TQString & address, bool tolerant )
426 {
427  //kdDebug(7043) << "KBookmarkManager::findByAddress " << address << endl;
428  KBookmark result = root();
429  // The address is something like /5/10/2+
430  TQStringList addresses = TQStringList::split(TQRegExp("[/+]"),address);
431  // kdWarning() << addresses.join(",") << endl;
432  for ( TQStringList::Iterator it = addresses.begin() ; it != addresses.end() ; )
433  {
434  bool append = ((*it) == "+");
435  uint number = (*it).toUInt();
436  Q_ASSERT(result.isGroup());
437  KBookmarkGroup group = result.toGroup();
438  KBookmark bk = group.first(), lbk = bk; // last non-null bookmark
439  for ( uint i = 0 ; ( (i<number) || append ) && !bk.isNull() ; ++i ) {
440  lbk = bk;
441  bk = group.next(bk);
442  //kdWarning() << i << endl;
443  }
444  it++;
445  int shouldBeGroup = !bk.isGroup() && (it != addresses.end());
446  if ( tolerant && ( bk.isNull() || shouldBeGroup ) ) {
447  if (!lbk.isNull()) result = lbk;
448  //kdWarning() << "break" << endl;
449  break;
450  }
451  //kdWarning() << "found section" << endl;
452  result = bk;
453  }
454  if (result.isNull()) {
455  kdWarning() << "KBookmarkManager::findByAddress: couldn't find item " << address << endl;
456  Q_ASSERT(!tolerant);
457  }
458  //kdWarning() << "found " << result.address() << endl;
459  return result;
460  }
461 
462 static TQString pickUnusedTitle( KBookmarkGroup parentBookmark,
463  const TQString &title, const TQString &url
464 ) {
465  // If this title is already used, we'll try to find something unused.
466  KBookmark ch = parentBookmark.first();
467  int count = 1;
468  TQString uniqueTitle = title;
469  do
470  {
471  while ( !ch.isNull() )
472  {
473  if ( uniqueTitle == ch.text() )
474  {
475  // Title already used !
476  if ( url != ch.url().url() )
477  {
478  uniqueTitle = title + TQString(" (%1)").arg(++count);
479  // New title -> restart search from the beginning
480  ch = parentBookmark.first();
481  break;
482  }
483  else
484  {
485  // this exact URL already exists
486  return TQString::null;
487  }
488  }
489  ch = parentBookmark.next( ch );
490  }
491  } while ( !ch.isNull() );
492 
493  return uniqueTitle;
494 }
495 
496 KBookmarkGroup KBookmarkManager::addBookmarkDialog(
497  const TQString & _url, const TQString & _title,
498  const TQString & _parentBookmarkAddress
499 ) {
500  TQString url = _url;
501  TQString title = _title;
502  TQString parentBookmarkAddress = _parentBookmarkAddress;
503 
504  if ( url.isEmpty() )
505  {
506  KMessageBox::error( 0L, i18n("Cannot add bookmark with empty URL."));
507  return KBookmarkGroup();
508  }
509 
510  if ( title.isEmpty() )
511  title = url;
512 
513  if ( KBookmarkSettings::self()->m_advancedaddbookmark)
514  {
515  KBookmarkEditDialog dlg( title, url, this, KBookmarkEditDialog::InsertionMode, parentBookmarkAddress );
516  if ( dlg.exec() != KDialogBase::Accepted )
517  return KBookmarkGroup();
518  title = dlg.finalTitle();
519  url = dlg.finalUrl();
520  parentBookmarkAddress = dlg.finalAddress();
521  }
522 
523  KBookmarkGroup parentBookmark;
524  parentBookmark = findByAddress( parentBookmarkAddress ).toGroup();
525  Q_ASSERT( !parentBookmark.isNull() );
526 
527  TQString uniqueTitle = pickUnusedTitle( parentBookmark, title, url );
528  if ( !uniqueTitle.isNull() )
529  parentBookmark.addBookmark( this, uniqueTitle, KURL( url ));
530 
531  return parentBookmark;
532 }
533 
534 
535 void KBookmarkManager::emitChanged( /*KDE4 const*/ KBookmarkGroup & group )
536 {
537  save();
538 
539  // Tell the other processes too
540  // kdDebug(7043) << "KBookmarkManager::emitChanged : broadcasting change " << group.address() << endl;
541 
542  TQByteArray data;
543  TQDataStream ds( data, IO_WriteOnly );
544  ds << group.address();
545 
546  emitDCOPSignal("bookmarksChanged(TQString)", data);
547 
548  // We do get our own broadcast, so no need for this anymore
549  //emit changed( group );
550 }
551 
552 void KBookmarkManager::emitConfigChanged()
553 {
554  emitDCOPSignal("bookmarkConfigChanged()", TQByteArray());
555 }
556 
557 void KBookmarkManager::notifyCompleteChange( TQString caller ) // DCOP call
558 {
559  if (!m_update) return;
560 
561  //kdDebug(7043) << "KBookmarkManager::notifyCompleteChange" << endl;
562  // The bk editor tells us we should reload everything
563  // Reparse
564  parse();
565  // Tell our GUI
566  // (emit where group is "" to directly mark the root menu as dirty)
567  emit changed( "", caller );
568 }
569 
570 void KBookmarkManager::notifyConfigChanged() // DCOP call
571 {
572  kdDebug() << "reloaded bookmark config!" << endl;
573  KBookmarkSettings::self()->readSettings();
574  parse(); // reload, and thusly recreate the menus
575 }
576 
577 void KBookmarkManager::notifyChanged( TQString groupAddress ) // DCOP call
578 {
579  if (!m_update) return;
580 
581  // Reparse (the whole file, no other choice)
582  // if someone else notified us
583  if (callingDcopClient()->senderId() != DCOPClient::mainClient()->appId())
584  parse();
585 
586  //kdDebug(7043) << "KBookmarkManager::notifyChanged " << groupAddress << endl;
587  //KBookmarkGroup group = findByAddress( groupAddress ).toGroup();
588  //Q_ASSERT(!group.isNull());
589  emit changed( groupAddress, TQString::null );
590 }
591 
592 bool KBookmarkManager::showNSBookmarks() const
593 {
594  return KBookmarkMenu::showDynamicBookmarks("netscape").show;
595 }
596 
597 void KBookmarkManager::setShowNSBookmarks( bool show )
598 {
599  m_showNSBookmarks = show;
600  if (this->path() != userBookmarksFile())
601  return;
602  KBookmarkMenu::DynMenuInfo info
603  = KBookmarkMenu::showDynamicBookmarks("netscape");
604  info.show = show;
605  KBookmarkMenu::setDynamicBookmarks("netscape", info);
606 }
607 
608 void KBookmarkManager::setEditorOptions( const TQString& caption, bool browser )
609 {
610  dptr()->m_editorCaption = caption;
611  dptr()->m_browserEditor = browser;
612 }
613 
614 void KBookmarkManager::slotEditBookmarks()
615 {
616  KProcess proc;
617  proc << TQString::fromLatin1("keditbookmarks");
618  if (!dptr()->m_editorCaption.isNull())
619  proc << TQString::fromLatin1("--customcaption") << dptr()->m_editorCaption;
620  if (!dptr()->m_browserEditor)
621  proc << TQString::fromLatin1("--nobrowser");
622  proc << m_bookmarksFile;
623  proc.start(KProcess::DontCare);
624 }
625 
626 void KBookmarkManager::slotEditBookmarksAtAddress( const TQString& address )
627 {
628  KProcess proc;
629  proc << TQString::fromLatin1("keditbookmarks")
630  << TQString::fromLatin1("--address") << address
631  << m_bookmarksFile;
632  proc.start(KProcess::DontCare);
633 }
634 
636 
637 void KBookmarkOwner::openBookmarkURL( const TQString& url )
638 {
639  (void) new KRun(KURL( url ));
640 }
641 
642 void KBookmarkOwner::virtual_hook( int, void* )
643 { /*BASE::virtual_hook( id, data );*/ }
644 
645 bool KBookmarkManager::updateAccessMetadata( const TQString & url, bool emitSignal )
646 {
647  if (!s_bk_map) {
648  s_bk_map = new KBookmarkMap(this);
649  s_bk_map->update();
650  }
651 
652  TQValueList<KBookmark> list = s_bk_map->find(url);
653  if ( list.count() == 0 )
654  return false;
655 
656  for ( TQValueList<KBookmark>::iterator it = list.begin();
657  it != list.end(); ++it )
658  (*it).updateAccessMetadata();
659 
660  if (emitSignal)
661  emit notifier().updatedAccessMetadata( path(), url );
662 
663  return true;
664 }
665 
666 void KBookmarkManager::updateFavicon( const TQString &url, const TQString &faviconurl, bool emitSignal )
667 {
668  Q_UNUSED(faviconurl);
669 
670  if (!s_bk_map) {
671  s_bk_map = new KBookmarkMap(this);
672  s_bk_map->update();
673  }
674 
675  TQValueList<KBookmark> list = s_bk_map->find(url);
676  for ( TQValueList<KBookmark>::iterator it = list.begin();
677  it != list.end(); ++it )
678  {
679  // TODO - update favicon data based on faviconurl
680  // but only when the previously used icon
681  // isn't a manually set one.
682  }
683 
684  if (emitSignal)
685  {
686  // TODO
687  // emit notifier().updatedFavicon( path(), url, faviconurl );
688  }
689 }
690 
691 TQString KBookmarkManager::userBookmarksFile()
692 {
693  return locateLocal("data", TQString::fromLatin1("konqueror/bookmarks.xml"));
694 }
695 
696 KBookmarkManager* KBookmarkManager::userBookmarksManager()
697 {
698  return KBookmarkManager::managerForFile( userBookmarksFile() );
699 }
700 
701 KBookmarkSettings* KBookmarkSettings::s_self = 0;
702 
703 void KBookmarkSettings::readSettings()
704 {
705  KConfig config("kbookmarkrc", false, false);
706  config.setGroup("Bookmarks");
707 
708  // add bookmark dialog usage - no reparse
709  s_self->m_advancedaddbookmark = config.readBoolEntry("AdvancedAddBookmarkDialog", false);
710 
711  // these three alter the menu, therefore all need a reparse
712  s_self->m_contextmenu = config.readBoolEntry("ContextMenuActions", true);
713  s_self->m_quickactions = config.readBoolEntry("QuickActionSubmenu", false);
714  s_self->m_filteredtoolbar = config.readBoolEntry("FilteredToolbar", false);
715 }
716 
717 KBookmarkSettings *KBookmarkSettings::self()
718 {
719  if (!s_self)
720  {
721  s_self = new KBookmarkSettings;
722  readSettings();
723  }
724  return s_self;
725 }
726 
727 #include "kbookmarkmanager.moc"

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.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |