From ebfe1e6f68e5e2b65693822f2b07ad6674dc0031 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sun, 15 May 2011 14:40:17 +0200 Subject: - Fix bookmark conflict between Rekonq and Konqueror - New way to copy rekonq default bookmarks so no problem with konqueror anymore BUG: 273134 --- src/bookmarks/bookmarkprovider.cpp | 63 ++++++++++++++++++++++++-------------- src/bookmarks/bookmarkprovider.h | 1 + 2 files changed, 41 insertions(+), 23 deletions(-) (limited to 'src') 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 *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; -- cgit v1.2.1