diff options
author | Yoann Laissus <yoann.laissus@gmail.com> | 2011-05-18 08:32:16 +0200 |
---|---|---|
committer | Yoann Laissus <yoann.laissus@gmail.com> | 2011-05-18 08:32:16 +0200 |
commit | eed882d9f51bafabf31d784abb0d098d3e8097bc (patch) | |
tree | c3efb8f68f071f984a0a9618ddee5fc92b1112d2 /src | |
parent | Merge branch 'bkFolder' (diff) | |
parent | - Fix bookmark conflict between Rekonq and Konqueror (diff) | |
download | rekonq-eed882d9f51bafabf31d784abb0d098d3e8097bc.tar.xz |
Merge branch 'rekonqKonquerorBkConflict'
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/bookmarkprovider.cpp | 63 | ||||
-rw-r--r-- | src/bookmarks/bookmarkprovider.h | 1 |
2 files changed, 41 insertions, 23 deletions
diff --git a/src/bookmarks/bookmarkprovider.cpp b/src/bookmarks/bookmarkprovider.cpp index cef6eaeb..fc351320 100644 --- a/src/bookmarks/bookmarkprovider.cpp +++ b/src/bookmarks/bookmarkprovider.cpp @@ -54,31 +54,20 @@ BookmarkProvider::BookmarkProvider(QObject *parent) , m_owner(0) , m_actionCollection(new KActionCollection(this)) { - // NOTE - // This hackish code is needed to continue sharing bookmarks with konqueror, - // until we can (hopefully) start using an akonadi resource. - // - // The cleanest code has a subdole bug inside does not allowing people to start - // using rekonq and then using konqueror. So if konqueror bk file has not just been created, - // bk are stored in rekonq dir and then they will be lost when you start using konqi - - KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks - if (!QFile::exists(bookfile.path())) + m_manager = KBookmarkManager::userBookmarksManager(); + const QString bookmarksFile = KStandardDirs::locateLocal("data", QString::fromLatin1("konqueror/bookmarks.xml")); + + if (!QFile::exists(bookmarksFile)) { - bookfile = KUrl("~/.kde4/share/apps/konqueror/bookmarks.xml"); - if (!QFile::exists(bookfile.path())) - { - QString bookmarksDefaultPath = KStandardDirs::locate("appdata" , "defaultbookmarks.xbel"); - QFile bkms(bookmarksDefaultPath); - QString bookmarksPath = KStandardDirs::locateLocal("appdata", "bookmarks.xml", true); - bookmarksPath.replace("rekonq", "konqueror"); - bkms.copy(bookmarksPath); - bookfile = KUrl(bookmarksPath); - } - } + kDebug() << "copying of defaultbookmarks.xbel ..."; + + QString bookmarksDefaultPath = KStandardDirs::locate("appdata" , "defaultbookmarks.xbel"); + KBookmarkManager *tempManager = KBookmarkManager::managerForExternalFile(bookmarksDefaultPath); - m_manager = KBookmarkManager::managerForFile(bookfile.path(), "rekonq"); - m_manager->setEditorOptions("", true); + copyBookmarkGroup(tempManager->root(), rootGroup()); + m_manager->emitChanged(); + delete tempManager; + } connect(m_manager, SIGNAL(changed(const QString &, const QString &)), this, SLOT(slotBookmarksChanged())); @@ -303,3 +292,31 @@ KBookmark BookmarkProvider::bookmarkForUrl(const KBookmark &bookmark, const KUrl return found; } + + +void BookmarkProvider::copyBookmarkGroup(const KBookmarkGroup &groupToCopy, KBookmarkGroup destGroup) +{ + KBookmark bookmark = groupToCopy.first(); + while (!bookmark.isNull()) + { + if (bookmark.isGroup()) + { + KBookmarkGroup newDestGroup = destGroup.createNewFolder(bookmark.text()); + if (bookmark.toGroup().isToolbarGroup()) + { + newDestGroup.internalElement().setAttribute("toolbar", "yes"); + newDestGroup.setIcon("bookmark-toolbar"); + } + copyBookmarkGroup(bookmark.toGroup(), newDestGroup); + } + else if (bookmark.isSeparator()) + { + destGroup.createNewSeparator(); + } + else + { + destGroup.addBookmark(bookmark.text(), bookmark.url()); + } + bookmark = groupToCopy.next(bookmark); + } +} diff --git a/src/bookmarks/bookmarkprovider.h b/src/bookmarks/bookmarkprovider.h index 4af97ef7..fe49eaee 100644 --- a/src/bookmarks/bookmarkprovider.h +++ b/src/bookmarks/bookmarkprovider.h @@ -144,6 +144,7 @@ Q_SIGNALS: private: void find(QList<KBookmark> *list, const KBookmark &bookmark, const QString &text); KBookmark bookmarkForUrl(const KBookmark &bookmark, const KUrl &url); + void copyBookmarkGroup(const KBookmarkGroup &groupToCopy, KBookmarkGroup destGroup); KBookmarkManager *m_manager; BookmarkOwner *m_owner; |