mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
[Bookmarks] Automatically migrate bookmarks from SQLite to JSON
This commit is contained in:
parent
ad615316c8
commit
75f3460a27
|
@ -18,6 +18,7 @@
|
|||
#include "bookmarks.h"
|
||||
#include "bookmarkitem.h"
|
||||
#include "bookmarksmodel.h"
|
||||
#include "bookmarkstools.h"
|
||||
#include "mainapplication.h"
|
||||
#include "qztools.h"
|
||||
#include "webview.h"
|
||||
|
@ -263,6 +264,16 @@ void Bookmarks::init()
|
|||
m_folderUnsorted->setTitle(tr("Unsorted Bookmarks"));
|
||||
m_folderUnsorted->setDescription(tr("All other bookmarks"));
|
||||
|
||||
if (!BookmarksTools::migrateBookmarksIfNecessary(this)) {
|
||||
loadBookmarks();
|
||||
}
|
||||
|
||||
m_lastFolder = m_folderUnsorted;
|
||||
m_model = new BookmarksModel(this, this);
|
||||
}
|
||||
|
||||
void Bookmarks::loadBookmarks()
|
||||
{
|
||||
const QString bookmarksFile = mApp->currentProfilePath() + QLatin1String("/bookmarks.json");
|
||||
const QString backupFile = bookmarksFile + QLatin1String(".old");
|
||||
|
||||
|
@ -293,9 +304,6 @@ void Bookmarks::init()
|
|||
else {
|
||||
loadBookmarksFromMap(res.toMap().value("roots").toMap());
|
||||
}
|
||||
|
||||
m_lastFolder = m_folderUnsorted;
|
||||
m_model = new BookmarksModel(this, this);
|
||||
}
|
||||
|
||||
void Bookmarks::saveBookmarks()
|
||||
|
|
|
@ -78,6 +78,7 @@ signals:
|
|||
|
||||
private:
|
||||
void init();
|
||||
void loadBookmarks();
|
||||
void saveBookmarks();
|
||||
|
||||
void loadBookmarksFromMap(const QVariantMap &map);
|
||||
|
|
|
@ -39,7 +39,7 @@ void BookmarksItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem
|
|||
opt.frameShape = QFrame::HLine;
|
||||
opt.rect = option.rect;
|
||||
|
||||
// We need to fake continous line over 2 columns
|
||||
// We need to fake continuous line over 2 columns
|
||||
if (m_tree->viewType() == BookmarksTreeView::BookmarksManagerViewType) {
|
||||
if (index.column() == 1) {
|
||||
opt.rect = m_lastRect;
|
||||
|
|
|
@ -300,8 +300,15 @@ void BookmarksManager::addBookmark(BookmarkItem* item)
|
|||
|
||||
m_bookmarks->addBookmark(parent, item);
|
||||
|
||||
// Select newly added bookmark
|
||||
ui->tree->selectBookmark(item);
|
||||
ui->tree->ensureBookmarkVisible(item);
|
||||
|
||||
// Start editing title
|
||||
if (!item->isSeparator()) {
|
||||
ui->title->setFocus();
|
||||
ui->title->selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
BookmarkItem* BookmarksManager::parentForNewBookmark() const
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
QSize minimumSizeHint() const;
|
||||
|
||||
private slots:
|
||||
void bookmarkRemoved(BookmarkItem* bookmark);
|
||||
void createMenu();
|
||||
|
||||
void menuMiddleClicked(Menu* menu);
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "qzsettings.h"
|
||||
#include "qupzilla.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QSqlQuery>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QBoxLayout>
|
||||
#include <QLabel>
|
||||
|
@ -339,3 +341,54 @@ void BookmarksTools::addSeparatorToMenu(Menu* menu, BookmarkItem* separator)
|
|||
|
||||
menu->addSeparator();
|
||||
}
|
||||
|
||||
bool BookmarksTools::migrateBookmarksIfNecessary(Bookmarks* bookmarks)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.exec("SELECT name FROM sqlite_master WHERE type='table' AND name='folders'");
|
||||
|
||||
if (!query.next()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Bookmarks: Migrating your bookmarks from SQLite to JSON..." << std::endl;
|
||||
|
||||
QHash<QString, BookmarkItem*> folders;
|
||||
folders.insert("bookmarksToolbar", bookmarks->toolbarFolder());
|
||||
folders.insert("bookmarksMenu", bookmarks->menuFolder());
|
||||
folders.insert("unsorted", bookmarks->unsortedFolder());
|
||||
|
||||
query.exec("SELECT name, subfolder FROM folders");
|
||||
while (query.next()) {
|
||||
const QString title = query.value(0).toString();
|
||||
bool subfolder = query.value(1).toString() == QLatin1String("yes");
|
||||
|
||||
BookmarkItem* folder = new BookmarkItem(BookmarkItem::Folder, subfolder ? bookmarks->toolbarFolder() : 0);
|
||||
folder->setTitle(title);
|
||||
folders.insert(folder->title(), folder);
|
||||
}
|
||||
|
||||
query.exec("SELECT title, folder, url FROM bookmarks ORDER BY position ASC");
|
||||
while (query.next()) {
|
||||
const QString title = query.value(0).toString();
|
||||
const QString folder = query.value(1).toString();
|
||||
const QUrl url = query.value(2).toUrl();
|
||||
|
||||
BookmarkItem* parent = folders.value(folder);
|
||||
if (folder.isEmpty()) {
|
||||
parent = bookmarks->unsortedFolder();
|
||||
}
|
||||
Q_ASSERT(parent);
|
||||
|
||||
BookmarkItem* bookmark = new BookmarkItem(BookmarkItem::Url, parent);
|
||||
bookmark->setTitle(title);
|
||||
bookmark->setUrl(url);
|
||||
}
|
||||
|
||||
query.exec("DROP TABLE folders");
|
||||
query.exec("DROP TABLE bookmarks");
|
||||
query.exec("VACUUM");
|
||||
|
||||
std::cout << "Bookmarks: Bookmarks successfully migrated!" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class Bookmarks;
|
||||
class BookmarkItem;
|
||||
|
||||
class QT_QUPZILLA_EXPORT BookmarksFoldersMenu : public QMenu
|
||||
|
@ -92,6 +93,9 @@ public:
|
|||
static void addFolderToMenu(QObject* receiver, Menu* menu, BookmarkItem* folder);
|
||||
static void addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* bookmark);
|
||||
static void addSeparatorToMenu(Menu* menu, BookmarkItem* separator);
|
||||
|
||||
// Migration from Sql Bookmarks (returns true if bookmarks migrated)
|
||||
static bool migrateBookmarksIfNecessary(Bookmarks* bookmarks);
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSTOOLS_H
|
||||
|
|
|
@ -70,7 +70,7 @@ void IconProvider::saveIcon(WebView* view)
|
|||
|
||||
QImage IconProvider::iconForUrl(const QUrl &url)
|
||||
{
|
||||
if (url.isEmpty()) {
|
||||
if (url.path().isEmpty()) {
|
||||
return IconProvider::emptyWebImage();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user