KIO
kbookmarkmanager.cc
Go to the documentation of this file.
00001 // -*- c-basic-offset:4; indent-tabs-mode:nil -*- 00002 // vim: set ts=4 sts=4 sw=4 et: 00003 /* This file is part of the KDE libraries 00004 Copyright (C) 2000 David Faure <faure@kde.org> 00005 Copyright (C) 2003 Alexander Kellett <lypanov@kde.org> 00006 Copyright (C) 2008 Norbert Frese <nf2@scheinwelt.at> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License version 2 as published by the Free Software Foundation. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "kbookmarkmanager.h" 00024 00025 #include <QtCore/QFile> 00026 #include <QtCore/QFileInfo> 00027 #include <QtCore/QProcess> 00028 #include <QtCore/QRegExp> 00029 #include <QtCore/QTextStream> 00030 #include <QtDBus/QtDBus> 00031 #include <QtGui/QApplication> 00032 00033 #include <kconfiggroup.h> 00034 #include <kdebug.h> 00035 #include <kdirwatch.h> 00036 #include <klocale.h> 00037 #include <kmessagebox.h> 00038 #include <ksavefile.h> 00039 #include <kstandarddirs.h> 00040 00041 #include "kbookmarkmenu.h" 00042 #include "kbookmarkmenu_p.h" 00043 #include "kbookmarkimporter.h" 00044 #include "kbookmarkdialog.h" 00045 #include "kbookmarkmanageradaptor_p.h" 00046 00047 #define BOOKMARK_CHANGE_NOTIFY_INTERFACE "org.kde.KIO.KBookmarkManager" 00048 00049 class KBookmarkManagerList : public QList<KBookmarkManager *> 00050 { 00051 public: 00052 ~KBookmarkManagerList() { 00053 qDeleteAll( begin() , end() ); // auto-delete functionality 00054 } 00055 00056 QReadWriteLock lock; 00057 }; 00058 00059 K_GLOBAL_STATIC(KBookmarkManagerList, s_pSelf) 00060 00061 class KBookmarkMap : private KBookmarkGroupTraverser { 00062 public: 00063 KBookmarkMap() : m_mapNeedsUpdate(true) {} 00064 void setNeedsUpdate() { m_mapNeedsUpdate = true; } 00065 void update(KBookmarkManager*); 00066 QList<KBookmark> find( const QString &url ) const 00067 { return m_bk_map.value(url); } 00068 private: 00069 virtual void visit(const KBookmark &); 00070 virtual void visitEnter(const KBookmarkGroup &) { ; } 00071 virtual void visitLeave(const KBookmarkGroup &) { ; } 00072 private: 00073 typedef QList<KBookmark> KBookmarkList; 00074 QMap<QString, KBookmarkList> m_bk_map; 00075 bool m_mapNeedsUpdate; 00076 }; 00077 00078 void KBookmarkMap::update(KBookmarkManager *manager) 00079 { 00080 if (m_mapNeedsUpdate) { 00081 m_mapNeedsUpdate = false; 00082 00083 m_bk_map.clear(); 00084 KBookmarkGroup root = manager->root(); 00085 traverse(root); 00086 } 00087 } 00088 00089 void KBookmarkMap::visit(const KBookmark &bk) 00090 { 00091 if (!bk.isSeparator()) { 00092 // add bookmark to url map 00093 m_bk_map[bk.internalElement().attribute("href")].append(bk); 00094 } 00095 } 00096 00097 // ######################### 00098 // KBookmarkManager::Private 00099 class KBookmarkManager::Private 00100 { 00101 public: 00102 Private(bool bDocIsloaded, const QString &dbusObjectName = QString()) 00103 : m_doc("xbel") 00104 , m_dbusObjectName(dbusObjectName) 00105 , m_docIsLoaded(bDocIsloaded) 00106 , m_update(false) 00107 , m_dialogAllowed(true) 00108 , m_dialogParent(0) 00109 , m_browserEditor(false) 00110 , m_typeExternal(false) 00111 , m_kDirWatch(0) 00112 {} 00113 00114 ~Private() { 00115 delete m_kDirWatch; 00116 } 00117 00118 mutable QDomDocument m_doc; 00119 mutable QDomDocument m_toolbarDoc; 00120 QString m_bookmarksFile; 00121 QString m_dbusObjectName; 00122 mutable bool m_docIsLoaded; 00123 bool m_update; 00124 bool m_dialogAllowed; 00125 QWidget *m_dialogParent; 00126 00127 bool m_browserEditor; 00128 QString m_editorCaption; 00129 00130 bool m_typeExternal; 00131 KDirWatch * m_kDirWatch; // for external bookmark files 00132 00133 KBookmarkMap m_map; 00134 }; 00135 00136 // ################ 00137 // KBookmarkManager 00138 00139 static KBookmarkManager* lookupExisting(const QString& bookmarksFile) 00140 { 00141 for ( KBookmarkManagerList::ConstIterator bmit = s_pSelf->constBegin(), bmend = s_pSelf->constEnd(); 00142 bmit != bmend; ++bmit ) { 00143 if ( (*bmit)->path() == bookmarksFile ) 00144 return *bmit; 00145 } 00146 return 0; 00147 } 00148 00149 00150 KBookmarkManager* KBookmarkManager::managerForFile( const QString& bookmarksFile, const QString& dbusObjectName ) 00151 { 00152 KBookmarkManager* mgr(0); 00153 { 00154 QReadLocker readLock(&s_pSelf->lock); 00155 mgr = lookupExisting(bookmarksFile); 00156 if (mgr) { 00157 return mgr; 00158 } 00159 } 00160 00161 QWriteLocker writeLock(&s_pSelf->lock); 00162 mgr = lookupExisting(bookmarksFile); 00163 if (mgr) { 00164 return mgr; 00165 } 00166 00167 mgr = new KBookmarkManager( bookmarksFile, dbusObjectName ); 00168 s_pSelf->append( mgr ); 00169 return mgr; 00170 } 00171 00172 KBookmarkManager* KBookmarkManager::managerForExternalFile( const QString& bookmarksFile ) 00173 { 00174 KBookmarkManager* mgr(0); 00175 { 00176 QReadLocker readLock(&s_pSelf->lock); 00177 mgr = lookupExisting(bookmarksFile); 00178 if (mgr) { 00179 return mgr; 00180 } 00181 } 00182 00183 QWriteLocker writeLock(&s_pSelf->lock); 00184 mgr = lookupExisting(bookmarksFile); 00185 if (mgr) { 00186 return mgr; 00187 } 00188 00189 mgr = new KBookmarkManager( bookmarksFile ); 00190 s_pSelf->append( mgr ); 00191 return mgr; 00192 } 00193 00194 00195 // principally used for filtered toolbars 00196 KBookmarkManager* KBookmarkManager::createTempManager() 00197 { 00198 KBookmarkManager* mgr = new KBookmarkManager(); 00199 s_pSelf->append( mgr ); 00200 return mgr; 00201 } 00202 00203 #define PI_DATA "version=\"1.0\" encoding=\"UTF-8\"" 00204 00205 static QDomElement createXbelTopLevelElement(QDomDocument & doc) 00206 { 00207 QDomElement topLevel = doc.createElement("xbel"); 00208 topLevel.setAttribute("xmlns:mime", "http://www.freedesktop.org/standards/shared-mime-info"); 00209 topLevel.setAttribute("xmlns:bookmark", "http://www.freedesktop.org/standards/desktop-bookmarks"); 00210 topLevel.setAttribute("xmlns:kdepriv", "http://www.kde.org/kdepriv"); 00211 doc.appendChild( topLevel ); 00212 doc.insertBefore( doc.createProcessingInstruction( "xml", PI_DATA), topLevel ); 00213 return topLevel; 00214 } 00215 00216 KBookmarkManager::KBookmarkManager( const QString & bookmarksFile, const QString & dbusObjectName) 00217 : d(new Private(false, dbusObjectName)) 00218 { 00219 if(dbusObjectName.isNull()) // get dbusObjectName from file 00220 if ( QFile::exists(d->m_bookmarksFile) ) 00221 parse(); //sets d->m_dbusObjectName 00222 00223 init( "/KBookmarkManager/"+d->m_dbusObjectName ); 00224 00225 d->m_update = true; 00226 00227 Q_ASSERT( !bookmarksFile.isEmpty() ); 00228 d->m_bookmarksFile = bookmarksFile; 00229 00230 if ( !QFile::exists(d->m_bookmarksFile) ) 00231 { 00232 QDomElement topLevel = createXbelTopLevelElement(d->m_doc); 00233 topLevel.setAttribute("dbusName", dbusObjectName); 00234 d->m_docIsLoaded = true; 00235 } 00236 } 00237 00238 KBookmarkManager::KBookmarkManager(const QString & bookmarksFile) 00239 : d(new Private(false)) 00240 { 00241 // use KDirWatch to monitor this bookmarks file 00242 d->m_typeExternal = true; 00243 d->m_update = true; 00244 00245 Q_ASSERT( !bookmarksFile.isEmpty() ); 00246 d->m_bookmarksFile = bookmarksFile; 00247 00248 if ( !QFile::exists(d->m_bookmarksFile) ) 00249 { 00250 createXbelTopLevelElement(d->m_doc); 00251 } 00252 else 00253 { 00254 parse(); 00255 } 00256 d->m_docIsLoaded = true; 00257 00258 // start KDirWatch 00259 d->m_kDirWatch = new KDirWatch; 00260 d->m_kDirWatch->addFile(d->m_bookmarksFile); 00261 QObject::connect( d->m_kDirWatch, SIGNAL(dirty(const QString&)), 00262 this, SLOT(slotFileChanged(const QString&))); 00263 QObject::connect( d->m_kDirWatch, SIGNAL(created(const QString&)), 00264 this, SLOT(slotFileChanged(const QString&))); 00265 QObject::connect( d->m_kDirWatch, SIGNAL(deleted(const QString&)), 00266 this, SLOT(slotFileChanged(const QString&))); 00267 kDebug(7043) << "starting KDirWatch for " << d->m_bookmarksFile; 00268 } 00269 00270 KBookmarkManager::KBookmarkManager( ) 00271 : d(new Private(true)) 00272 { 00273 init( "/KBookmarkManager/generated" ); 00274 d->m_update = false; // TODO - make it read/write 00275 00276 createXbelTopLevelElement(d->m_doc); 00277 } 00278 00279 void KBookmarkManager::init( const QString& dbusPath ) 00280 { 00281 // A KBookmarkManager without a dbus name is a temporary one, like those used by importers; 00282 // no need to register them to dbus 00283 if ( dbusPath != "/KBookmarkManager/" && dbusPath != "/KBookmarkManager/generated") 00284 { 00285 new KBookmarkManagerAdaptor(this); 00286 QDBusConnection::sessionBus().registerObject( dbusPath, this ); 00287 00288 QDBusConnection::sessionBus().connect(QString(), dbusPath, BOOKMARK_CHANGE_NOTIFY_INTERFACE, 00289 "bookmarksChanged", this, SLOT(notifyChanged(QString,QDBusMessage))); 00290 QDBusConnection::sessionBus().connect(QString(), dbusPath, BOOKMARK_CHANGE_NOTIFY_INTERFACE, 00291 "bookmarkConfigChanged", this, SLOT(notifyConfigChanged())); 00292 } 00293 } 00294 00295 void KBookmarkManager::slotFileChanged(const QString& path) 00296 { 00297 if (path == d->m_bookmarksFile) 00298 { 00299 kDebug(7043) << "file changed (KDirWatch) " << path ; 00300 // Reparse 00301 parse(); 00302 // Tell our GUI 00303 // (emit where group is "" to directly mark the root menu as dirty) 00304 emit changed( "", QString() ); 00305 } 00306 } 00307 00308 KBookmarkManager::~KBookmarkManager() 00309 { 00310 if (!s_pSelf.isDestroyed()) { 00311 s_pSelf->removeAll(this); 00312 } 00313 00314 delete d; 00315 } 00316 00317 bool KBookmarkManager::autoErrorHandlingEnabled() const 00318 { 00319 return d->m_dialogAllowed; 00320 } 00321 00322 void KBookmarkManager::setAutoErrorHandlingEnabled( bool enable, QWidget *parent ) 00323 { 00324 d->m_dialogAllowed = enable; 00325 d->m_dialogParent = parent; 00326 } 00327 00328 void KBookmarkManager::setUpdate( bool update ) 00329 { 00330 d->m_update = update; 00331 } 00332 00333 QDomDocument KBookmarkManager::internalDocument() const 00334 { 00335 if(!d->m_docIsLoaded) 00336 { 00337 parse(); 00338 d->m_toolbarDoc.clear(); 00339 } 00340 return d->m_doc; 00341 } 00342 00343 00344 void KBookmarkManager::parse() const 00345 { 00346 d->m_docIsLoaded = true; 00347 //kDebug(7043) << "KBookmarkManager::parse " << d->m_bookmarksFile; 00348 QFile file( d->m_bookmarksFile ); 00349 if ( !file.open( QIODevice::ReadOnly ) ) 00350 { 00351 kWarning() << "Can't open " << d->m_bookmarksFile; 00352 return; 00353 } 00354 d->m_doc = QDomDocument("xbel"); 00355 d->m_doc.setContent( &file ); 00356 00357 if ( d->m_doc.documentElement().isNull() ) 00358 { 00359 kWarning() << "KBookmarkManager::parse : main tag is missing, creating default " << d->m_bookmarksFile; 00360 QDomElement element = d->m_doc.createElement("xbel"); 00361 d->m_doc.appendChild(element); 00362 } 00363 00364 QDomElement docElem = d->m_doc.documentElement(); 00365 00366 QString mainTag = docElem.tagName(); 00367 if ( mainTag != "xbel" ) 00368 kWarning() << "KBookmarkManager::parse : unknown main tag " << mainTag; 00369 00370 if(d->m_dbusObjectName.isNull()) 00371 { 00372 d->m_dbusObjectName = docElem.attribute("dbusName"); 00373 } 00374 else if(docElem.attribute("dbusName") != d->m_dbusObjectName) 00375 { 00376 docElem.setAttribute("dbusName", d->m_dbusObjectName); 00377 save(); 00378 } 00379 00380 QDomNode n = d->m_doc.documentElement().previousSibling(); 00381 if ( n.isProcessingInstruction() ) 00382 { 00383 QDomProcessingInstruction pi = n.toProcessingInstruction(); 00384 pi.parentNode().removeChild(pi); 00385 } 00386 00387 QDomProcessingInstruction pi; 00388 pi = d->m_doc.createProcessingInstruction( "xml", PI_DATA ); 00389 d->m_doc.insertBefore( pi, docElem ); 00390 00391 file.close(); 00392 00393 d->m_map.setNeedsUpdate(); 00394 } 00395 00396 bool KBookmarkManager::save( bool toolbarCache ) const 00397 { 00398 return saveAs( d->m_bookmarksFile, toolbarCache ); 00399 } 00400 00401 bool KBookmarkManager::saveAs( const QString & filename, bool toolbarCache ) const 00402 { 00403 kDebug(7043) << "KBookmarkManager::save " << filename; 00404 00405 // Save the bookmark toolbar folder for quick loading 00406 // but only when it will actually make things quicker 00407 const QString cacheFilename = filename + QLatin1String(".tbcache"); 00408 if(toolbarCache && !root().isToolbarGroup()) 00409 { 00410 KSaveFile cacheFile( cacheFilename ); 00411 if ( cacheFile.open() ) 00412 { 00413 QString str; 00414 QTextStream stream(&str, QIODevice::WriteOnly); 00415 stream << root().findToolbar(); 00416 const QByteArray cstr = str.toUtf8(); 00417 cacheFile.write( cstr.data(), cstr.length() ); 00418 cacheFile.finalize(); 00419 } 00420 } 00421 else // remove any (now) stale cache 00422 { 00423 QFile::remove( cacheFilename ); 00424 } 00425 00426 KSaveFile file( filename ); 00427 if ( file.open() ) 00428 { 00429 file.simpleBackupFile( file.fileName(), QString(), ".bak" ); 00430 QTextStream stream(&file); 00431 stream.setCodec( QTextCodec::codecForName( "UTF-8" ) ); 00432 stream << internalDocument().toString(); 00433 stream.flush(); 00434 if ( file.finalize() ) 00435 { 00436 return true; 00437 } 00438 } 00439 00440 static int hadSaveError = false; 00441 file.abort(); 00442 if ( !hadSaveError ) { 00443 QString err = i18n("Unable to save bookmarks in %1. Reported error was: %2. " 00444 "This error message will only be shown once. The cause " 00445 "of the error needs to be fixed as quickly as possible, " 00446 "which is most likely a full hard drive.", 00447 filename, file.errorString()); 00448 00449 if (d->m_dialogAllowed && qApp->type() != QApplication::Tty && QThread::currentThread() == qApp->thread()) 00450 KMessageBox::error( QApplication::activeWindow(), err ); 00451 00452 kError() << QString("Unable to save bookmarks in %1. File reported the following error-code: %2.").arg(filename).arg(file.error()); 00453 emit const_cast<KBookmarkManager*>(this)->error(err); 00454 } 00455 hadSaveError = true; 00456 return false; 00457 } 00458 00459 QString KBookmarkManager::path() const 00460 { 00461 return d->m_bookmarksFile; 00462 } 00463 00464 KBookmarkGroup KBookmarkManager::root() const 00465 { 00466 return KBookmarkGroup(internalDocument().documentElement()); 00467 } 00468 00469 KBookmarkGroup KBookmarkManager::toolbar() 00470 { 00471 kDebug(7043) << "KBookmarkManager::toolbar begin"; 00472 // Only try to read from a toolbar cache if the full document isn't loaded 00473 if(!d->m_docIsLoaded) 00474 { 00475 kDebug(7043) << "KBookmarkManager::toolbar trying cache"; 00476 const QString cacheFilename = d->m_bookmarksFile + QLatin1String(".tbcache"); 00477 QFileInfo bmInfo(d->m_bookmarksFile); 00478 QFileInfo cacheInfo(cacheFilename); 00479 if (d->m_toolbarDoc.isNull() && 00480 QFile::exists(cacheFilename) && 00481 bmInfo.lastModified() < cacheInfo.lastModified()) 00482 { 00483 kDebug(7043) << "KBookmarkManager::toolbar reading file"; 00484 QFile file( cacheFilename ); 00485 00486 if ( file.open( QIODevice::ReadOnly ) ) 00487 { 00488 d->m_toolbarDoc = QDomDocument("cache"); 00489 d->m_toolbarDoc.setContent( &file ); 00490 kDebug(7043) << "KBookmarkManager::toolbar opened"; 00491 } 00492 } 00493 if (!d->m_toolbarDoc.isNull()) 00494 { 00495 kDebug(7043) << "KBookmarkManager::toolbar returning element"; 00496 QDomElement elem = d->m_toolbarDoc.firstChild().toElement(); 00497 return KBookmarkGroup(elem); 00498 } 00499 } 00500 00501 // Fallback to the normal way if there is no cache or if the bookmark file 00502 // is already loaded 00503 QDomElement elem = root().findToolbar(); 00504 if (elem.isNull()) 00505 return root(); // Root is the bookmark toolbar if none has been set. 00506 else 00507 return KBookmarkGroup(root().findToolbar()); 00508 } 00509 00510 KBookmark KBookmarkManager::findByAddress( const QString & address ) 00511 { 00512 //kDebug(7043) << "KBookmarkManager::findByAddress " << address; 00513 KBookmark result = root(); 00514 // The address is something like /5/10/2+ 00515 const QStringList addresses = address.split(QRegExp("[/+]"),QString::SkipEmptyParts); 00516 // kWarning() << addresses.join(","); 00517 for ( QStringList::const_iterator it = addresses.begin() ; it != addresses.end() ; ) 00518 { 00519 bool append = ((*it) == "+"); 00520 uint number = (*it).toUInt(); 00521 Q_ASSERT(result.isGroup()); 00522 KBookmarkGroup group = result.toGroup(); 00523 KBookmark bk = group.first(), lbk = bk; // last non-null bookmark 00524 for ( uint i = 0 ; ( (i<number) || append ) && !bk.isNull() ; ++i ) { 00525 lbk = bk; 00526 bk = group.next(bk); 00527 //kWarning() << i; 00528 } 00529 it++; 00530 //kWarning() << "found section"; 00531 result = bk; 00532 } 00533 if (result.isNull()) { 00534 kWarning() << "KBookmarkManager::findByAddress: couldn't find item " << address; 00535 } 00536 //kWarning() << "found " << result.address(); 00537 return result; 00538 } 00539 00540 void KBookmarkManager::emitChanged() 00541 { 00542 emitChanged(root()); 00543 } 00544 00545 00546 void KBookmarkManager::emitChanged( const KBookmarkGroup & group ) 00547 { 00548 (void) save(); // KDE5 TODO: emitChanged should return a bool? Maybe rename it to saveAndEmitChanged? 00549 00550 // Tell the other processes too 00551 // kDebug(7043) << "KBookmarkManager::emitChanged : broadcasting change " << group.address(); 00552 00553 emit bookmarksChanged(group.address()); 00554 00555 // We do get our own broadcast, so no need for this anymore 00556 //emit changed( group ); 00557 } 00558 00559 void KBookmarkManager::emitConfigChanged() 00560 { 00561 emit bookmarkConfigChanged(); 00562 } 00563 00564 void KBookmarkManager::notifyCompleteChange( const QString &caller ) // DBUS call 00565 { 00566 if (!d->m_update) 00567 return; 00568 00569 kDebug(7043) << "KBookmarkManager::notifyCompleteChange"; 00570 // The bk editor tells us we should reload everything 00571 // Reparse 00572 parse(); 00573 // Tell our GUI 00574 // (emit where group is "" to directly mark the root menu as dirty) 00575 emit changed( "", caller ); 00576 } 00577 00578 void KBookmarkManager::notifyConfigChanged() // DBUS call 00579 { 00580 kDebug() << "reloaded bookmark config!"; 00581 KBookmarkSettings::self()->readSettings(); 00582 parse(); // reload, and thusly recreate the menus 00583 emit configChanged(); 00584 } 00585 00586 void KBookmarkManager::notifyChanged( const QString &groupAddress, const QDBusMessage &msg ) // DBUS call 00587 { 00588 kDebug() << "KBookmarkManager::notifyChanged ( "<<groupAddress<<")"; 00589 if (!d->m_update) 00590 return; 00591 00592 // Reparse (the whole file, no other choice) 00593 // if someone else notified us 00594 if (msg.service() != QDBusConnection::sessionBus().baseService()) 00595 parse(); 00596 00597 //kDebug(7043) << "KBookmarkManager::notifyChanged " << groupAddress; 00598 //KBookmarkGroup group = findByAddress( groupAddress ).toGroup(); 00599 //Q_ASSERT(!group.isNull()); 00600 emit changed( groupAddress, QString() ); 00601 } 00602 00603 void KBookmarkManager::setEditorOptions( const QString& caption, bool browser ) 00604 { 00605 d->m_editorCaption = caption; 00606 d->m_browserEditor = browser; 00607 } 00608 00609 void KBookmarkManager::slotEditBookmarks() 00610 { 00611 QStringList args; 00612 if ( !d->m_editorCaption.isEmpty() ) 00613 args << QLatin1String("--customcaption") << d->m_editorCaption; 00614 if ( !d->m_browserEditor ) 00615 args << QLatin1String("--nobrowser"); 00616 if( !d->m_dbusObjectName.isEmpty() ) 00617 args << QLatin1String("--dbusObjectName") << d->m_dbusObjectName; 00618 args << d->m_bookmarksFile; 00619 QProcess::startDetached("keditbookmarks", args); 00620 } 00621 00622 void KBookmarkManager::slotEditBookmarksAtAddress( const QString& address ) 00623 { 00624 QStringList args; 00625 if ( !d->m_editorCaption.isEmpty() ) 00626 args << QLatin1String("--customcaption") << d->m_editorCaption; 00627 if ( !d->m_browserEditor ) 00628 args << QLatin1String("--nobrowser"); 00629 if( !d->m_dbusObjectName.isEmpty() ) 00630 args << QLatin1String("--dbusObjectName") << d->m_dbusObjectName; 00631 args << QLatin1String("--address") << address 00632 << d->m_bookmarksFile; 00633 QProcess::startDetached("keditbookmarks", args); 00634 } 00635 00637 bool KBookmarkManager::updateAccessMetadata( const QString & url ) 00638 { 00639 d->m_map.update(this); 00640 QList<KBookmark> list = d->m_map.find(url); 00641 if ( list.count() == 0 ) 00642 return false; 00643 00644 for ( QList<KBookmark>::iterator it = list.begin(); 00645 it != list.end(); ++it ) 00646 (*it).updateAccessMetadata(); 00647 00648 return true; 00649 } 00650 00651 void KBookmarkManager::updateFavicon( const QString &url, const QString &faviconurl ) 00652 { 00653 d->m_map.update(this); 00654 QList<KBookmark> list = d->m_map.find(url); 00655 for ( QList<KBookmark>::iterator it = list.begin(); 00656 it != list.end(); ++it ) 00657 { 00658 // TODO - update favicon data based on faviconurl 00659 // but only when the previously used icon 00660 // isn't a manually set one. 00661 } 00662 } 00663 00664 KBookmarkManager* KBookmarkManager::userBookmarksManager() 00665 { 00666 const QString bookmarksFile = KStandardDirs::locateLocal("data", QString::fromLatin1("konqueror/bookmarks.xml")); 00667 KBookmarkManager* bookmarkManager = KBookmarkManager::managerForFile( bookmarksFile, "konqueror" ); 00668 bookmarkManager->setEditorOptions(KGlobal::caption(), true); 00669 return bookmarkManager; 00670 } 00671 00672 KBookmarkSettings* KBookmarkSettings::s_self = 0; 00673 00674 void KBookmarkSettings::readSettings() 00675 { 00676 KConfig config("kbookmarkrc", KConfig::NoGlobals); 00677 KConfigGroup cg(&config, "Bookmarks"); 00678 00679 // add bookmark dialog usage - no reparse 00680 s_self->m_advancedaddbookmark = cg.readEntry("AdvancedAddBookmarkDialog", false); 00681 00682 // this one alters the menu, therefore it needs a reparse 00683 s_self->m_contextmenu = cg.readEntry("ContextMenuActions", true); 00684 } 00685 00686 KBookmarkSettings *KBookmarkSettings::self() 00687 { 00688 if (!s_self) 00689 { 00690 s_self = new KBookmarkSettings; 00691 readSettings(); 00692 } 00693 return s_self; 00694 } 00695 00697 00698 bool KBookmarkOwner::enableOption(BookmarkOption action) const 00699 { 00700 if(action == ShowAddBookmark) 00701 return true; 00702 if(action == ShowEditBookmark) 00703 return true; 00704 return false; 00705 } 00706 00707 KBookmarkDialog * KBookmarkOwner::bookmarkDialog(KBookmarkManager * mgr, QWidget * parent) 00708 { 00709 return new KBookmarkDialog(mgr, parent); 00710 } 00711 00712 void KBookmarkOwner::openFolderinTabs(const KBookmarkGroup &) 00713 { 00714 00715 } 00716 00717 #include "kbookmarkmanager.moc"
KDE 4.6 API Reference