2014-02-08 23:01:01 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "bookmarkstools.h"
|
|
|
|
#include "bookmarkitem.h"
|
|
|
|
#include "bookmarks.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "iconprovider.h"
|
2014-02-10 11:54:58 +01:00
|
|
|
#include "enhancedmenu.h"
|
2014-02-08 23:01:01 +01:00
|
|
|
#include "tabwidget.h"
|
2014-02-09 11:02:51 +01:00
|
|
|
#include "qzsettings.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2014-02-08 23:01:01 +01:00
|
|
|
|
2014-02-10 16:58:05 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <QSqlQuery>
|
2014-02-08 23:01:01 +01:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QBoxLayout>
|
2016-02-09 14:16:50 +01:00
|
|
|
#include <QFormLayout>
|
2014-02-08 23:01:01 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
2016-02-09 14:16:50 +01:00
|
|
|
#include <QPlainTextEdit>
|
2014-02-08 23:01:01 +01:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QDialog>
|
|
|
|
|
|
|
|
// BookmarksFoldersMenu
|
|
|
|
BookmarksFoldersMenu::BookmarksFoldersMenu(QWidget* parent)
|
|
|
|
: QMenu(parent)
|
|
|
|
, m_selectedFolder(0)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarkItem* BookmarksFoldersMenu::selectedFolder() const
|
|
|
|
{
|
|
|
|
return m_selectedFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksFoldersMenu::folderChoosed()
|
|
|
|
{
|
|
|
|
if (QAction* act = qobject_cast<QAction*>(sender())) {
|
|
|
|
BookmarkItem* folder = static_cast<BookmarkItem*>(act->data().value<void*>());
|
|
|
|
emit folderSelected(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksFoldersMenu::init()
|
|
|
|
{
|
|
|
|
#define ADD_MENU(name) \
|
|
|
|
BookmarkItem* f_##name = mApp->bookmarks()->name(); \
|
2014-02-10 16:03:29 +01:00
|
|
|
QMenu* m_##name = addMenu(f_##name->icon(), f_##name->title()); \
|
2014-02-08 23:01:01 +01:00
|
|
|
createMenu(m_##name, f_##name);
|
|
|
|
|
|
|
|
ADD_MENU(toolbarFolder)
|
|
|
|
ADD_MENU(menuFolder)
|
|
|
|
ADD_MENU(unsortedFolder)
|
|
|
|
#undef ADD_MENU
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksFoldersMenu::createMenu(QMenu* menu, BookmarkItem* parent)
|
|
|
|
{
|
|
|
|
QAction* act = menu->addAction(tr("Choose %1").arg(parent->title()));
|
|
|
|
act->setData(QVariant::fromValue<void*>(static_cast<void*>(parent)));
|
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(folderChoosed()));
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
foreach (BookmarkItem* child, parent->children()) {
|
|
|
|
if (child->isFolder()) {
|
2014-02-10 16:03:29 +01:00
|
|
|
QMenu* m = menu->addMenu(child->icon(), child->title());
|
2014-02-08 23:01:01 +01:00
|
|
|
createMenu(m, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// BookmarksFoldersButton
|
|
|
|
BookmarksFoldersButton::BookmarksFoldersButton(QWidget* parent, BookmarkItem* folder)
|
|
|
|
: QPushButton(parent)
|
|
|
|
, m_menu(new BookmarksFoldersMenu(this))
|
2014-02-09 12:43:06 +01:00
|
|
|
, m_selectedFolder(folder ? folder : mApp->bookmarks()->lastUsedFolder())
|
2014-02-08 23:01:01 +01:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
|
|
|
connect(m_menu, SIGNAL(folderSelected(BookmarkItem*)), this, SLOT(setSelectedFolder(BookmarkItem*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarkItem* BookmarksFoldersButton::selectedFolder() const
|
|
|
|
{
|
|
|
|
return m_selectedFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksFoldersButton::setSelectedFolder(BookmarkItem* folder)
|
|
|
|
{
|
|
|
|
Q_ASSERT(folder);
|
|
|
|
Q_ASSERT(folder->isFolder());
|
|
|
|
|
|
|
|
m_selectedFolder = folder;
|
|
|
|
setText(folder->title());
|
2014-02-10 16:03:29 +01:00
|
|
|
setIcon(folder->icon());
|
2014-02-09 12:18:52 +01:00
|
|
|
|
|
|
|
if (sender()) {
|
|
|
|
emit selectedFolderChanged(folder);
|
|
|
|
}
|
2014-02-08 23:01:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksFoldersButton::init()
|
|
|
|
{
|
|
|
|
setMenu(m_menu);
|
|
|
|
setSelectedFolder(m_selectedFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// BookmarksTools
|
|
|
|
bool BookmarksTools::addBookmarkDialog(QWidget* parent, const QUrl &url, const QString &title, BookmarkItem* folder)
|
|
|
|
{
|
|
|
|
if (url.isEmpty() || title.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog* dialog = new QDialog(parent);
|
|
|
|
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLineEdit* edit = new QLineEdit(dialog);
|
|
|
|
BookmarksFoldersButton* folderButton = new BookmarksFoldersButton(dialog, folder);
|
|
|
|
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
QObject::connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
QObject::connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addWidget(edit);
|
|
|
|
layout->addWidget(folderButton);
|
|
|
|
layout->addWidget(box);
|
|
|
|
|
|
|
|
label->setText(Bookmarks::tr("Choose name and location of this bookmark."));
|
|
|
|
edit->setText(title);
|
|
|
|
edit->setCursorPosition(0);
|
2014-03-07 18:03:42 +01:00
|
|
|
dialog->setWindowIcon(IconProvider::iconForUrl(url));
|
2014-02-08 23:01:01 +01:00
|
|
|
dialog->setWindowTitle(Bookmarks::tr("Add New Bookmark"));
|
|
|
|
|
|
|
|
QSize size = dialog->size();
|
|
|
|
size.setWidth(350);
|
|
|
|
dialog->resize(size);
|
|
|
|
dialog->exec();
|
|
|
|
|
|
|
|
if (dialog->result() == QDialog::Rejected || edit->text().isEmpty()) {
|
|
|
|
delete dialog;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BookmarkItem* bookmark = new BookmarkItem(BookmarkItem::Url);
|
|
|
|
bookmark->setTitle(edit->text());
|
|
|
|
bookmark->setUrl(url);
|
|
|
|
mApp->bookmarks()->addBookmark(folderButton->selectedFolder(), bookmark);
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BookmarksTools::bookmarkAllTabsDialog(QWidget* parent, TabWidget* tabWidget, BookmarkItem* folder)
|
|
|
|
{
|
|
|
|
Q_ASSERT(tabWidget);
|
|
|
|
|
|
|
|
QDialog* dialog = new QDialog(parent);
|
|
|
|
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
BookmarksFoldersButton* folderButton = new BookmarksFoldersButton(dialog, folder);
|
|
|
|
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
QObject::connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
QObject::connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addWidget(folderButton);
|
|
|
|
layout->addWidget(box);
|
|
|
|
|
|
|
|
label->setText(Bookmarks::tr("Choose folder for bookmarks:"));
|
|
|
|
dialog->setWindowTitle(Bookmarks::tr("Bookmark All Tabs"));
|
|
|
|
|
|
|
|
QSize size = dialog->size();
|
|
|
|
size.setWidth(350);
|
|
|
|
dialog->resize(size);
|
|
|
|
dialog->exec();
|
|
|
|
|
|
|
|
if (dialog->result() == QDialog::Rejected) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (WebTab* tab, tabWidget->allTabs(false)) {
|
|
|
|
if (!tab->url().isEmpty()) {
|
|
|
|
BookmarkItem* bookmark = new BookmarkItem(BookmarkItem::Url);
|
|
|
|
bookmark->setTitle(tab->title());
|
|
|
|
bookmark->setUrl(tab->url());
|
|
|
|
mApp->bookmarks()->addBookmark(folderButton->selectedFolder(), bookmark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-09 11:02:51 +01:00
|
|
|
|
2016-02-09 14:16:50 +01:00
|
|
|
bool BookmarksTools::editBookmarkDialog(QWidget* parent, BookmarkItem *item)
|
|
|
|
{
|
|
|
|
QDialog* dialog = new QDialog(parent);
|
|
|
|
QFormLayout* layout = new QFormLayout(dialog);
|
|
|
|
|
|
|
|
QLineEdit* title = new QLineEdit;
|
|
|
|
QLineEdit* address = new QLineEdit;
|
|
|
|
QLineEdit* keyword = new QLineEdit;
|
|
|
|
QPlainTextEdit* description = new QPlainTextEdit;
|
|
|
|
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
QObject::connect(box, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
|
|
|
QObject::connect(box, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
|
|
|
|
|
|
|
layout->addRow(Bookmarks::tr("Title:"), title);
|
|
|
|
title->setText(item->title());
|
|
|
|
if (!item->isFolder()) {
|
|
|
|
layout->addRow(Bookmarks::tr("Address:"), address);
|
|
|
|
address->setText(item->urlString());
|
|
|
|
layout->addRow(Bookmarks::tr("Keyword:"), keyword);
|
|
|
|
keyword->setText(item->keyword());
|
|
|
|
}
|
|
|
|
layout->addRow(Bookmarks::tr("Description:"), description);
|
|
|
|
description->document()->setPlainText(item->description());
|
|
|
|
layout->addWidget(box);
|
|
|
|
|
|
|
|
dialog->setWindowIcon(item->icon());
|
|
|
|
dialog->setWindowTitle(Bookmarks::tr("Edit Bookmark"));
|
|
|
|
|
|
|
|
dialog->exec();
|
|
|
|
|
|
|
|
if (dialog->result() == QDialog::Rejected) {
|
|
|
|
delete dialog;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->setTitle(title->text());
|
|
|
|
if (!item->isFolder()) {
|
|
|
|
item->setUrl(QUrl::fromEncoded(address->text().toUtf8()));
|
|
|
|
item->setKeyword(keyword->text());
|
|
|
|
}
|
|
|
|
item->setDescription(description->toPlainText());
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BookmarksTools::openBookmark(BrowserWindow* window, BookmarkItem* item)
|
2014-02-09 11:02:51 +01:00
|
|
|
{
|
|
|
|
Q_ASSERT(window);
|
|
|
|
|
|
|
|
if (!item || !item->isUrl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-09 15:07:19 +01:00
|
|
|
if (item->isFolder()) {
|
|
|
|
openFolderInTabs(window, item);
|
|
|
|
}
|
|
|
|
else if (item->isUrl()) {
|
2014-03-01 13:02:57 +01:00
|
|
|
item->updateVisitCount();
|
2014-02-09 15:07:19 +01:00
|
|
|
window->loadAddress(item->url());
|
|
|
|
}
|
2014-02-09 11:02:51 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BookmarksTools::openBookmarkInNewTab(BrowserWindow* window, BookmarkItem* item)
|
2014-02-09 11:02:51 +01:00
|
|
|
{
|
|
|
|
Q_ASSERT(window);
|
|
|
|
|
2014-02-09 15:07:19 +01:00
|
|
|
if (!item) {
|
2014-02-09 11:02:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-09 15:07:19 +01:00
|
|
|
if (item->isFolder()) {
|
|
|
|
openFolderInTabs(window, item);
|
|
|
|
}
|
|
|
|
else if (item->isUrl()) {
|
2014-03-01 13:02:57 +01:00
|
|
|
item->updateVisitCount();
|
2014-02-09 15:07:19 +01:00
|
|
|
window->tabWidget()->addView(item->url(), item->title(), qzSettings->newTabPosition);
|
|
|
|
}
|
2014-02-09 11:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksTools::openBookmarkInNewWindow(BookmarkItem* item)
|
|
|
|
{
|
2014-02-09 17:27:55 +01:00
|
|
|
if (!item->isUrl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-01 13:02:57 +01:00
|
|
|
item->updateVisitCount();
|
2014-03-10 00:47:07 +01:00
|
|
|
mApp->createWindow(Qz::BW_NewWindow, item->url());
|
2014-02-09 11:02:51 +01:00
|
|
|
}
|
2014-02-09 15:07:19 +01:00
|
|
|
|
2014-02-22 15:20:54 +01:00
|
|
|
void BookmarksTools::openBookmarkInNewPrivateWindow(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
if (!item->isUrl()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-01 13:02:57 +01:00
|
|
|
item->updateVisitCount();
|
2014-02-22 15:20:54 +01:00
|
|
|
mApp->startPrivateBrowsing(item->url());
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BookmarksTools::openFolderInTabs(BrowserWindow* window, BookmarkItem* folder)
|
2014-02-09 15:07:19 +01:00
|
|
|
{
|
|
|
|
Q_ASSERT(window);
|
|
|
|
Q_ASSERT(folder->isFolder());
|
|
|
|
|
|
|
|
foreach (BookmarkItem* child, folder->children()) {
|
|
|
|
if (child->isUrl()) {
|
|
|
|
openBookmarkInNewTab(window, child);
|
|
|
|
}
|
|
|
|
else if (child->isFolder()) {
|
|
|
|
openFolderInTabs(window, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 11:54:58 +01:00
|
|
|
|
|
|
|
void BookmarksTools::addActionToMenu(QObject* receiver, Menu* menu, BookmarkItem* item)
|
|
|
|
{
|
|
|
|
Q_ASSERT(menu);
|
|
|
|
Q_ASSERT(item);
|
|
|
|
|
|
|
|
switch (item->type()) {
|
|
|
|
case BookmarkItem::Url:
|
|
|
|
addUrlToMenu(receiver, menu, item);
|
|
|
|
break;
|
|
|
|
case BookmarkItem::Folder:
|
|
|
|
addFolderToMenu(receiver, menu, item);
|
|
|
|
break;
|
|
|
|
case BookmarkItem::Separator:
|
|
|
|
addSeparatorToMenu(menu, item);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksTools::addFolderToMenu(QObject* receiver, Menu* menu, BookmarkItem* folder)
|
|
|
|
{
|
|
|
|
Q_ASSERT(menu);
|
|
|
|
Q_ASSERT(folder);
|
|
|
|
Q_ASSERT(folder->isFolder());
|
|
|
|
|
2014-06-08 15:20:21 +02:00
|
|
|
Menu* m = new Menu(menu);
|
|
|
|
QString title = QFontMetrics(m->font()).elidedText(folder->title(), Qt::ElideRight, 250);
|
|
|
|
m->setTitle(title);
|
2014-02-10 16:03:29 +01:00
|
|
|
m->setIcon(folder->icon());
|
2014-02-10 11:54:58 +01:00
|
|
|
QObject::connect(m, SIGNAL(menuMiddleClicked(Menu*)), receiver, SLOT(menuMiddleClicked(Menu*)));
|
|
|
|
|
|
|
|
QAction* act = menu->addMenu(m);
|
|
|
|
act->setData(QVariant::fromValue<void*>(static_cast<void*>(folder)));
|
2014-02-20 16:55:30 +01:00
|
|
|
act->setIconVisibleInMenu(true);
|
2014-02-10 11:54:58 +01:00
|
|
|
|
|
|
|
foreach (BookmarkItem* child, folder->children()) {
|
|
|
|
addActionToMenu(receiver, m, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m->isEmpty()) {
|
|
|
|
m->addAction(Bookmarks::tr("Empty"))->setDisabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksTools::addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* bookmark)
|
|
|
|
{
|
|
|
|
Q_ASSERT(menu);
|
|
|
|
Q_ASSERT(bookmark);
|
|
|
|
Q_ASSERT(bookmark->isUrl());
|
|
|
|
|
2014-06-08 15:20:21 +02:00
|
|
|
Action* act = new Action(menu);
|
|
|
|
QString title = QFontMetrics(act->font()).elidedText(bookmark->title(), Qt::ElideRight, 250);
|
|
|
|
act->setText(title);
|
|
|
|
act->setIcon(bookmark->icon());
|
|
|
|
|
2014-02-10 11:54:58 +01:00
|
|
|
act->setData(QVariant::fromValue<void*>(static_cast<void*>(bookmark)));
|
2014-02-20 16:55:30 +01:00
|
|
|
act->setIconVisibleInMenu(true);
|
2014-02-10 11:54:58 +01:00
|
|
|
|
|
|
|
QObject::connect(act, SIGNAL(triggered()), receiver, SLOT(bookmarkActivated()));
|
|
|
|
QObject::connect(act, SIGNAL(ctrlTriggered()), receiver, SLOT(bookmarkCtrlActivated()));
|
|
|
|
QObject::connect(act, SIGNAL(shiftTriggered()), receiver, SLOT(bookmarkShiftActivated()));
|
|
|
|
|
|
|
|
menu->addAction(act);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksTools::addSeparatorToMenu(Menu* menu, BookmarkItem* separator)
|
|
|
|
{
|
2014-02-10 12:58:34 +01:00
|
|
|
Q_UNUSED(separator)
|
|
|
|
|
2014-02-10 11:54:58 +01:00
|
|
|
Q_ASSERT(menu);
|
|
|
|
Q_ASSERT(separator->isSeparator());
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
}
|
2014-02-10 16:58:05 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2014-02-10 21:12:08 +01:00
|
|
|
BookmarkItem* parent = subfolder ? bookmarks->toolbarFolder() : bookmarks->unsortedFolder();
|
|
|
|
BookmarkItem* folder = new BookmarkItem(BookmarkItem::Folder, parent);
|
2014-02-10 16:58:05 +01:00
|
|
|
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);
|
2014-02-13 16:35:52 +01:00
|
|
|
if (!parent) {
|
2014-02-10 16:58:05 +01:00
|
|
|
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;
|
|
|
|
}
|