From 1d822d3a0344bd1c9cac501af2bedd4d17146305 Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 10 Feb 2014 14:57:48 +0100 Subject: [PATCH] [Bookmarks] Importing bookmarks now works It will however need a complete rewrite, the code is really bad. HtmlImport: Supports importing bookmarks with full structure --- src/lib/bookmarks/bookmarkstoolbar.cpp | 1 + .../bookmarksimport/bookmarksimportdialog.cpp | 171 ++++-------------- .../bookmarksimport/bookmarksimportdialog.h | 27 ++- .../bookmarksimport/bookmarksimportdialog.ui | 104 ----------- .../bookmarksimporticonfetcher.cpp | 84 --------- .../bookmarksimporticonfetcher.h | 67 ------- src/lib/bookmarksimport/chromeimporter.cpp | 19 +- src/lib/bookmarksimport/chromeimporter.h | 5 +- src/lib/bookmarksimport/firefoximporter.cpp | 17 +- src/lib/bookmarksimport/firefoximporter.h | 4 +- src/lib/bookmarksimport/htmlimporter.cpp | 29 +-- src/lib/bookmarksimport/htmlimporter.h | 5 +- src/lib/bookmarksimport/ieimporter.cpp | 19 +- src/lib/bookmarksimport/ieimporter.h | 5 +- src/lib/bookmarksimport/operaimporter.cpp | 21 ++- src/lib/bookmarksimport/operaimporter.h | 2 +- src/lib/lib.pro | 2 - src/lib/other/browsinglibrary.cpp | 22 ++- src/lib/other/browsinglibrary.h | 3 + src/lib/other/browsinglibrary.ui | 7 + 20 files changed, 142 insertions(+), 472 deletions(-) delete mode 100644 src/lib/bookmarksimport/bookmarksimporticonfetcher.cpp delete mode 100644 src/lib/bookmarksimport/bookmarksimporticonfetcher.h diff --git a/src/lib/bookmarks/bookmarkstoolbar.cpp b/src/lib/bookmarks/bookmarkstoolbar.cpp index 22c448475..087a2f493 100644 --- a/src/lib/bookmarks/bookmarkstoolbar.cpp +++ b/src/lib/bookmarks/bookmarkstoolbar.cpp @@ -51,6 +51,7 @@ BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent) connect(m_bookmarks, SIGNAL(bookmarkAdded(BookmarkItem*)), this, SLOT(bookmarksChanged())); connect(m_bookmarks, SIGNAL(bookmarkRemoved(BookmarkItem*)), this, SLOT(bookmarksChanged())); connect(m_bookmarks, SIGNAL(bookmarkChanged(BookmarkItem*)), this, SLOT(bookmarksChanged())); + connect(m_bookmarks, SIGNAL(showOnlyIconsInToolbarChanged(bool)), this, SLOT(showOnlyIconsChanged(bool))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); refresh(); diff --git a/src/lib/bookmarksimport/bookmarksimportdialog.cpp b/src/lib/bookmarksimport/bookmarksimportdialog.cpp index 7d6977772..f77df332f 100644 --- a/src/lib/bookmarksimport/bookmarksimportdialog.cpp +++ b/src/lib/bookmarksimport/bookmarksimportdialog.cpp @@ -22,24 +22,19 @@ #include "operaimporter.h" #include "htmlimporter.h" #include "ieimporter.h" +#include "bookmarkitem.h" #include "mainapplication.h" -#include "bookmarksimporticonfetcher.h" #include "iconprovider.h" -#include "networkmanager.h" #include "qztools.h" -#include #include #include -#include BookmarksImportDialog::BookmarksImportDialog(QWidget* parent) : QDialog(parent) , ui(new Ui::BookmarksImportDialog) , m_currentPage(0) , m_browser(Firefox) - , m_fetcher(0) - , m_fetcherThread(0) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); @@ -53,7 +48,6 @@ BookmarksImportDialog::BookmarksImportDialog(QWidget* parent) connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(nextPage())); connect(ui->chooseFile, SIGNAL(clicked()), this, SLOT(setFile())); connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(close())); - connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stopDownloading())); } void BookmarksImportDialog::nextPage() @@ -85,121 +79,24 @@ void BookmarksImportDialog::nextPage() if (exportedOK()) { m_currentPage++; ui->stackedWidget->setCurrentIndex(m_currentPage); - - if (!ui->fetchIcons->isChecked()) { - addExportedBookmarks(); - close(); - return; - } - - startFetchingIcons(); + showExportedBookmarks(); } break; - case 2: - addExportedBookmarks(); - close(); - break; - default: + addExportedBookmarks(); + close(); break; } } -void BookmarksImportDialog::startFetchingIcons() -{ - ui->nextButton->setText(tr("Finish")); - ui->nextButton->setEnabled(false); - ui->progressBar->setValue(0); - ui->progressBar->setMaximum(m_exportedBookmarks.count()); - - m_fetcherThread = new QThread(); - m_fetcher = new BookmarksImportIconFetcher(); - m_fetcher->moveToThread(m_fetcherThread); - - QIcon defaultIcon = qIconProvider->emptyWebIcon(); - QIcon folderIcon = style()->standardIcon(QStyle::SP_DirIcon); - QHash hash; - - foreach (const Bookmark &b, m_exportedBookmarks) { - QTreeWidgetItem* item; - QTreeWidgetItem* findParent = hash[b.folder]; - if (findParent) { - item = new QTreeWidgetItem(findParent); - } - else { - QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->treeWidget); - newParent->setText(0, b.folder); - newParent->setIcon(0, folderIcon); - ui->treeWidget->addTopLevelItem(newParent); - hash[b.folder] = newParent; - - item = new QTreeWidgetItem(newParent); - } - - QVariant bookmarkVariant = QVariant::fromValue(b); - item->setText(0, b.title); - if (b.image.isNull()) { - item->setIcon(0, defaultIcon); - } - else { - item->setIcon(0, QIcon(QPixmap::fromImage(b.image))); - } - item->setText(1, b.url.toString()); - item->setData(0, Qt::UserRole + 10, bookmarkVariant); - - ui->treeWidget->addTopLevelItem(item); - - m_fetcher->addEntry(b.url, item); - } - - ui->treeWidget->expandAll(); - - connect(m_fetcher, SIGNAL(iconFetched(QImage,QTreeWidgetItem*)), this, SLOT(iconFetched(QImage,QTreeWidgetItem*))); - connect(m_fetcher, SIGNAL(oneFinished()), this, SLOT(loadFinished())); - - m_fetcherThread->start(); - m_fetcher->startFetching(); -} - -void BookmarksImportDialog::stopDownloading() -{ - ui->nextButton->setEnabled(true); - ui->stopButton->hide(); - ui->progressBar->setValue(ui->progressBar->maximum()); - ui->fetchingLabel->setText(tr("Please press Finish to complete importing process.")); -} - -void BookmarksImportDialog::loadFinished() -{ - ui->progressBar->setValue(ui->progressBar->value() + 1); - - if (ui->progressBar->value() == ui->progressBar->maximum()) { - ui->stopButton->hide(); - ui->nextButton->setEnabled(true); - ui->fetchingLabel->setText(tr("Please press Finish to complete importing process.")); - } -} - -void BookmarksImportDialog::iconFetched(const QImage &image, QTreeWidgetItem* item) -{ - item->setIcon(0, QIcon(QPixmap::fromImage(image))); - - Bookmark b = item->data(0, Qt::UserRole + 10).value(); - - int index = m_exportedBookmarks.indexOf(b); - if (index != -1) { - m_exportedBookmarks[index].image = image; - } -} - bool BookmarksImportDialog::exportedOK() { if (m_browser == Firefox) { FirefoxImporter firefox(this); firefox.setFile(ui->fileLine->text()); if (firefox.openDatabase()) { - m_exportedBookmarks = firefox.exportBookmarks(); + m_exportedFolder = firefox.exportBookmarks(); } if (firefox.error()) { @@ -211,7 +108,7 @@ bool BookmarksImportDialog::exportedOK() ChromeImporter chrome(this); chrome.setFile(ui->fileLine->text()); if (chrome.openFile()) { - m_exportedBookmarks = chrome.exportBookmarks(); + m_exportedFolder = chrome.exportBookmarks(); } if (chrome.error()) { @@ -223,7 +120,7 @@ bool BookmarksImportDialog::exportedOK() OperaImporter opera(this); opera.setFile(ui->fileLine->text()); if (opera.openFile()) { - m_exportedBookmarks = opera.exportBookmarks(); + m_exportedFolder = opera.exportBookmarks(); } if (opera.error()) { @@ -235,7 +132,7 @@ bool BookmarksImportDialog::exportedOK() HtmlImporter html(this); html.setFile(ui->fileLine->text()); if (html.openFile()) { - m_exportedBookmarks = html.exportBookmarks(); + m_exportedFolder = html.exportBookmarks(); } if (html.error()) { @@ -249,7 +146,7 @@ bool BookmarksImportDialog::exportedOK() ie.setFile(ui->fileLine->text()); if (ie.openFile()) { - m_exportedBookmarks = ie.exportBookmarks(); + m_exportedFolder = ie.exportBookmarks(); } if (ie.error()) { @@ -257,14 +154,38 @@ bool BookmarksImportDialog::exportedOK() } } #endif - if (m_exportedBookmarks.isEmpty()) { + + if (!m_exportedFolder || m_exportedFolder->children().isEmpty()) { QMessageBox::critical(this, tr("Error!"), tr("The file doesn't contain any bookmark.")); return false; } + Q_ASSERT(m_exportedFolder->isFolder()); return true; } +void BookmarksImportDialog::showExportedBookmarks() +{ + ui->nextButton->setText(tr("Finish")); + + QTreeWidgetItem* root = new QTreeWidgetItem(ui->treeWidget); + root->setText(0, m_exportedFolder->title()); + root->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); + ui->treeWidget->addTopLevelItem(root); + + foreach (BookmarkItem* b, m_exportedFolder->children()) { + // TODO: Multi-level bookmarks + if (b->isUrl()) { + QTreeWidgetItem* item = new QTreeWidgetItem(root); + item->setText(0, b->title()); + item->setIcon(0, _iconForUrl(b->url())); + item->setText(1, b->urlString()); + } + } + + ui->treeWidget->expandAll(); +} + void BookmarksImportDialog::setFile() { #ifdef Q_OS_WIN @@ -288,21 +209,7 @@ void BookmarksImportDialog::setFile() void BookmarksImportDialog::addExportedBookmarks() { -#if 0 - QApplication::setOverrideCursor(Qt::WaitCursor); - Bookmarks* model = mApp->bookmarks(); - - QSqlDatabase db = QSqlDatabase::database(); - db.transaction(); - - foreach (const Bookmark &b, m_exportedBookmarks) { - model->saveBookmark(b.url, b.title, qIconProvider->iconFromImage(b.image), b.folder); - } - - db.commit(); - - QApplication::restoreOverrideCursor(); -#endif + mApp->bookmarks()->addBookmark(mApp->bookmarks()->unsortedFolder(), m_exportedFolder); } void BookmarksImportDialog::setupBrowser(Browser browser) @@ -381,12 +288,4 @@ void BookmarksImportDialog::setupBrowser(Browser browser) BookmarksImportDialog::~BookmarksImportDialog() { delete ui; - - if (m_fetcherThread) { - m_fetcherThread->exit(); - m_fetcherThread->wait(); - - m_fetcherThread->deleteLater(); - m_fetcher->deleteLater(); - } } diff --git a/src/lib/bookmarksimport/bookmarksimportdialog.h b/src/lib/bookmarksimport/bookmarksimportdialog.h index 4660873ce..fbc79d19e 100644 --- a/src/lib/bookmarksimport/bookmarksimportdialog.h +++ b/src/lib/bookmarksimport/bookmarksimportdialog.h @@ -19,20 +19,15 @@ #define BOOKMARKSIMPORTDIALOG_H #include -#include #include "qz_namespace.h" -#include "bookmarks.h" namespace Ui { class BookmarksImportDialog; } -class QTreeWidgetItem; -class QThread; - -class BookmarksImportIconFetcher; +class BookmarkItem; class QT_QUPZILLA_EXPORT BookmarksImportDialog : public QDialog { @@ -46,16 +41,19 @@ private slots: void nextPage(); void setFile(); - void stopDownloading(); - void iconFetched(const QImage &image, QTreeWidgetItem* item); - void loadFinished(); - private: - enum Browser { Firefox = 0, Chrome = 1, Opera = 2, IE = 3, Html = 4}; + enum Browser { + Firefox = 0, + Chrome = 1, + Opera = 2, + IE = 3, + Html = 4 + }; void setupBrowser(Browser browser); bool exportedOK(); - void startFetchingIcons(); + + void showExportedBookmarks(); void addExportedBookmarks(); Ui::BookmarksImportDialog* ui; @@ -70,10 +68,7 @@ private: QPixmap m_browserPixmap; QString m_browserBookmarkFile; - QVector m_exportedBookmarks; - - BookmarksImportIconFetcher* m_fetcher; - QThread* m_fetcherThread; + BookmarkItem* m_exportedFolder; }; #endif // BOOKMARKSIMPORTDIALOG_H diff --git a/src/lib/bookmarksimport/bookmarksimportdialog.ui b/src/lib/bookmarksimport/bookmarksimportdialog.ui index 5014817ce..d145fffd6 100644 --- a/src/lib/bookmarksimport/bookmarksimportdialog.ui +++ b/src/lib/bookmarksimport/bookmarksimportdialog.ui @@ -217,110 +217,6 @@ - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Fetching icons, please wait... - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - 24 - - - - - - - - - - - :/icons/theme/stop.png:/icons/theme/stop.png - - - - 16 - 16 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - diff --git a/src/lib/bookmarksimport/bookmarksimporticonfetcher.cpp b/src/lib/bookmarksimport/bookmarksimporticonfetcher.cpp deleted file mode 100644 index 00b5bcbb3..000000000 --- a/src/lib/bookmarksimport/bookmarksimporticonfetcher.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* 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 . -* ============================================================ */ -#include "bookmarksimporticonfetcher.h" -#include "iconfetcher.h" - -#include -#include - -BookmarksImportIconFetcher::BookmarksImportIconFetcher(QObject* parent) - : QObject(parent) -{ -} - -void BookmarksImportIconFetcher::addEntry(const QUrl &url, QTreeWidgetItem* item) -{ - Pair pair; - pair.url = url; - pair.item = item; - - m_pairs.append(pair); -} - -void BookmarksImportIconFetcher::startFetching() -{ - QTimer::singleShot(0, this, SLOT(slotStartFetching())); -} - -void BookmarksImportIconFetcher::slotIconFetched(const QImage &image) -{ - IconFetcher* fetcher = qobject_cast(sender()); - if (!fetcher) { - return; - } - - QTreeWidgetItem* itemPointer = static_cast(fetcher->data().value()); - - emit iconFetched(image, itemPointer); -} - -void BookmarksImportIconFetcher::slotFetcherFinished() -{ - IconFetcher* fetcher = qobject_cast(sender()); - if (!fetcher) { - return; - } - - m_fetchers.removeOne(fetcher); - - emit oneFinished(); -} - -void BookmarksImportIconFetcher::slotStartFetching() -{ - QNetworkAccessManager* manager = new QNetworkAccessManager(this); - - foreach (const Pair &pair, m_pairs) { - QVariant itemPointer = QVariant::fromValue((void*) pair.item); - - IconFetcher* fetcher = new IconFetcher(this); - fetcher->setNetworkAccessManager(manager); - fetcher->setData(itemPointer); - fetcher->fetchIcon(pair.url); - - connect(fetcher, SIGNAL(iconFetched(QImage)), this, SLOT(slotIconFetched(QImage))); - connect(fetcher, SIGNAL(finished()), this, SLOT(slotFetcherFinished())); - - m_fetchers.append(fetcher); - } -} diff --git a/src/lib/bookmarksimport/bookmarksimporticonfetcher.h b/src/lib/bookmarksimport/bookmarksimporticonfetcher.h deleted file mode 100644 index 846182c89..000000000 --- a/src/lib/bookmarksimport/bookmarksimporticonfetcher.h +++ /dev/null @@ -1,67 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* 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 . -* ============================================================ */ -#ifndef BOOKMARKSIMPORTICONFETCHER_H -#define BOOKMARKSIMPORTICONFETCHER_H - -#include -#include -#include -#include - -#include "qz_namespace.h" - -class QNetworkAccessManager; -class QTreeWidgetItem; -class QImage; - -class IconFetcher; - -class QT_QUPZILLA_EXPORT BookmarksImportIconFetcher : public QObject -{ - Q_OBJECT -public: - struct Pair { - QUrl url; - QTreeWidgetItem* item; - }; - - explicit BookmarksImportIconFetcher(QObject* parent = 0); - - void addEntry(const QUrl &url, QTreeWidgetItem* item); - void startFetching(); - -signals: - void iconFetched(const QImage &image, QTreeWidgetItem* item); - void oneFinished(); - -private slots: - void slotStartFetching(); - - void slotIconFetched(const QImage &image); - void slotFetcherFinished(); - -private: - QVector m_pairs; - QList m_fetchers; - -}; - -// Hint to QVector to use std::realloc on item moving -Q_DECLARE_TYPEINFO(BookmarksImportIconFetcher::Pair, Q_MOVABLE_TYPE); - -#endif // BOOKMARKSIMPORTICONFETCHER_H diff --git a/src/lib/bookmarksimport/chromeimporter.cpp b/src/lib/bookmarksimport/chromeimporter.cpp index 710fbd098..20115ae66 100644 --- a/src/lib/bookmarksimport/chromeimporter.cpp +++ b/src/lib/bookmarksimport/chromeimporter.cpp @@ -18,6 +18,7 @@ #include "chromeimporter.h" #include "qztools.h" #include "bookmarksimportdialog.h" +#include "bookmarkitem.h" #include #include @@ -49,10 +50,8 @@ bool ChromeImporter::openFile() return true; } -QVector ChromeImporter::exportBookmarks() +BookmarkItem* ChromeImporter::exportBookmarks() { - QVector list; - QString bookmarks = QString::fromUtf8(m_file.readAll()); m_file.close(); @@ -66,6 +65,9 @@ QVector ChromeImporter::exportBookmarks() pos += rx.matchedLength(); } + BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder); + root->setTitle("Chrome Import"); + QScriptEngine* scriptEngine = new QScriptEngine(); foreach (QString parsedString, parsedBookmarks) { parsedString = "(" + parsedString + ")"; @@ -78,12 +80,9 @@ QVector ChromeImporter::exportBookmarks() continue; } - Bookmarks::Bookmark b; - b.folder = "Chrome Import"; - b.title = name; - b.url = url; - - list.append(b); + BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root); + b->setTitle(name); + b->setUrl(url); } else { m_error = true; @@ -91,6 +90,6 @@ QVector ChromeImporter::exportBookmarks() } } - return list; + return root; } diff --git a/src/lib/bookmarksimport/chromeimporter.h b/src/lib/bookmarksimport/chromeimporter.h index 1aba3b60c..c4f5dfb63 100644 --- a/src/lib/bookmarksimport/chromeimporter.h +++ b/src/lib/bookmarksimport/chromeimporter.h @@ -22,7 +22,8 @@ #include #include "qz_namespace.h" -#include "bookmarks.h" + +class BookmarkItem; class QT_QUPZILLA_EXPORT ChromeImporter : public QObject { @@ -32,7 +33,7 @@ public: void setFile(const QString &path); bool openFile(); - QVector exportBookmarks(); + BookmarkItem* exportBookmarks(); bool error() { return m_error; } QString errorString() { return m_errorString; } diff --git a/src/lib/bookmarksimport/firefoximporter.cpp b/src/lib/bookmarksimport/firefoximporter.cpp index ac469c4e1..3d3087a9a 100644 --- a/src/lib/bookmarksimport/firefoximporter.cpp +++ b/src/lib/bookmarksimport/firefoximporter.cpp @@ -17,6 +17,7 @@ * ============================================================ */ #include "firefoximporter.h" #include "bookmarksimportdialog.h" +#include "bookmarkitem.h" #include #include @@ -54,9 +55,10 @@ bool FirefoxImporter::openDatabase() return true; } -QVector FirefoxImporter::exportBookmarks() +BookmarkItem* FirefoxImporter::exportBookmarks() { - QVector list; + BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder); + root->setTitle("Firefox Import"); QSqlQuery query(db); query.exec("SELECT title, fk FROM moz_bookmarks WHERE title != ''"); @@ -78,12 +80,9 @@ QVector FirefoxImporter::exportBookmarks() continue; } - Bookmarks::Bookmark b; - b.folder = "Firefox Import"; - b.title = title; - b.url = url; - - list.append(b); + BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root); + b->setTitle(title); + b->setUrl(url); } if (query.lastError().isValid()) { @@ -91,5 +90,5 @@ QVector FirefoxImporter::exportBookmarks() m_errorString = query.lastError().text(); } - return list; + return root; } diff --git a/src/lib/bookmarksimport/firefoximporter.h b/src/lib/bookmarksimport/firefoximporter.h index 25183f79f..e519ba894 100644 --- a/src/lib/bookmarksimport/firefoximporter.h +++ b/src/lib/bookmarksimport/firefoximporter.h @@ -25,6 +25,8 @@ #include "qz_namespace.h" #include "bookmarks.h" +class BookmarkItem; + class QT_QUPZILLA_EXPORT FirefoxImporter : public QObject { public: @@ -33,7 +35,7 @@ public: void setFile(const QString &path); bool openDatabase(); - QVector exportBookmarks(); + BookmarkItem* exportBookmarks(); bool error() { return m_error; } QString errorString() { return m_errorString; } diff --git a/src/lib/bookmarksimport/htmlimporter.cpp b/src/lib/bookmarksimport/htmlimporter.cpp index 42fc664c3..b50ec7ae1 100644 --- a/src/lib/bookmarksimport/htmlimporter.cpp +++ b/src/lib/bookmarksimport/htmlimporter.cpp @@ -17,9 +17,11 @@ * ============================================================ */ #include "htmlimporter.h" #include "bookmarksimportdialog.h" - +#include "bookmarkitem.h" #include "qzregexp.h" +#include + HtmlImporter::HtmlImporter(QObject* parent) : QObject(parent) , m_error(false) @@ -59,10 +61,8 @@ int qzMin(int a, int b) } } -QVector HtmlImporter::exportBookmarks() +BookmarkItem* HtmlImporter::exportBookmarks() { - QVector list; - QString bookmarks = QString::fromUtf8(m_file.readAll()); m_file.close(); @@ -84,7 +84,11 @@ QVector HtmlImporter::exportBookmarks() bookmarks = bookmarks.left(bookmarks.lastIndexOf(QLatin1String("

"))); int start = bookmarks.indexOf(QLatin1String("

")); - QStringList folders("Html Import"); + BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder); + root->setTitle("HTML Import"); + + QList folders; + folders.append(root); while (start > 0) { QString string = bookmarks.mid(start); @@ -107,7 +111,9 @@ QVector HtmlImporter::exportBookmarks() // QString arguments = rx.cap(1); QString folderName = rx.cap(2).trimmed(); - folders.append(folderName); + BookmarkItem* folder = new BookmarkItem(BookmarkItem::Folder, folders.isEmpty() ? root : folders.last()); + folder->setTitle(folderName); + folders.append(folder); start += posOfFolder + rx.cap(0).size(); } @@ -141,14 +147,11 @@ QVector HtmlImporter::exportBookmarks() continue; } - Bookmarks::Bookmark b; - b.folder = folders.last(); - b.title = linkName; - b.url = url; - - list.append(b); + BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, folders.isEmpty() ? root : folders.last()); + b->setTitle(linkName); + b->setUrl(url); } } - return list; + return root; } diff --git a/src/lib/bookmarksimport/htmlimporter.h b/src/lib/bookmarksimport/htmlimporter.h index 5feac83c9..1b46b6ecb 100644 --- a/src/lib/bookmarksimport/htmlimporter.h +++ b/src/lib/bookmarksimport/htmlimporter.h @@ -22,7 +22,8 @@ #include #include "qz_namespace.h" -#include "bookmarks.h" + +class BookmarkItem; class QT_QUPZILLA_EXPORT HtmlImporter : public QObject { @@ -32,7 +33,7 @@ public: void setFile(const QString &path); bool openFile(); - QVector exportBookmarks(); + BookmarkItem* exportBookmarks(); bool error() { return m_error; } QString errorString() { return m_errorString; } diff --git a/src/lib/bookmarksimport/ieimporter.cpp b/src/lib/bookmarksimport/ieimporter.cpp index eb5d4efdf..794b0e650 100644 --- a/src/lib/bookmarksimport/ieimporter.cpp +++ b/src/lib/bookmarksimport/ieimporter.cpp @@ -16,10 +16,11 @@ * along with this program. If not, see . * ============================================================ */ #include "ieimporter.h" - #include "bookmarksimportdialog.h" +#include "bookmarkitem.h" #include +#include #include IeImporter::IeImporter(QObject* parent) @@ -57,22 +58,20 @@ bool IeImporter::openFile() return true; } -QVector IeImporter::exportBookmarks() +BookmarkItem* IeImporter::exportBookmarks() { - QVector bookmarks; + BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder); + root->setTitle("Internet Explorer Import"); foreach (QFileInfo file, urls) { QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat, this); QUrl url = urlFile.value("InternetShortcut/URL").toUrl(); - Bookmarks::Bookmark bookmark; - bookmark.folder = "Internet Explorer Import"; - bookmark.title = file.baseName(); - bookmark.url = url; - - bookmarks.append(bookmark); + BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root); + b->setTitle(file.baseName()); + b->setUrl(url); } - return bookmarks; + return root; } diff --git a/src/lib/bookmarksimport/ieimporter.h b/src/lib/bookmarksimport/ieimporter.h index 65afa4e93..a261bdd83 100644 --- a/src/lib/bookmarksimport/ieimporter.h +++ b/src/lib/bookmarksimport/ieimporter.h @@ -21,10 +21,11 @@ #include #include "qz_namespace.h" -#include "bookmarks.h" #include +class BookmarkItem; + class IeImporter : public QObject { Q_OBJECT @@ -34,7 +35,7 @@ public: void setFile(const QString &path); bool openFile(); - QVector exportBookmarks(); + BookmarkItem* exportBookmarks(); bool error() { return m_error; } QString errorString() { return m_errorString; } diff --git a/src/lib/bookmarksimport/operaimporter.cpp b/src/lib/bookmarksimport/operaimporter.cpp index bb60beb3c..a158be2c4 100644 --- a/src/lib/bookmarksimport/operaimporter.cpp +++ b/src/lib/bookmarksimport/operaimporter.cpp @@ -17,8 +17,11 @@ * ============================================================ */ #include "operaimporter.h" #include "bookmarksimportdialog.h" +#include "bookmarkitem.h" #include "qzregexp.h" +#include + OperaImporter::OperaImporter(QObject* parent) : QObject(parent) , m_error(false) @@ -44,16 +47,17 @@ bool OperaImporter::openFile() return true; } -QVector OperaImporter::exportBookmarks() +BookmarkItem* OperaImporter::exportBookmarks() { - QVector list; - QString bookmarks = QString::fromUtf8(m_file.readAll()); m_file.close(); QzRegExp rx("#URL(.*)CREATED", Qt::CaseSensitive); rx.setMinimal(true); + BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder); + root->setTitle("Opera Import"); + int pos = 0; while ((pos = rx.indexIn(bookmarks, pos)) != -1) { QString string = rx.cap(1); @@ -72,13 +76,10 @@ QVector OperaImporter::exportBookmarks() continue; } - Bookmarks::Bookmark b; - b.folder = "Opera Import"; - b.title = name; - b.url = url; - - list.append(b); + BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root); + b->setTitle(name); + b->setUrl(url); } - return list; + return root; } diff --git a/src/lib/bookmarksimport/operaimporter.h b/src/lib/bookmarksimport/operaimporter.h index cfc976861..1a48c5156 100644 --- a/src/lib/bookmarksimport/operaimporter.h +++ b/src/lib/bookmarksimport/operaimporter.h @@ -32,7 +32,7 @@ public: void setFile(const QString &path); bool openFile(); - QVector exportBookmarks(); + BookmarkItem* exportBookmarks(); bool error() { return m_error; } QString errorString() { return m_errorString; } diff --git a/src/lib/lib.pro b/src/lib/lib.pro index bfb644411..36b200662 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -196,7 +196,6 @@ SOURCES += \ preferences/pluginlistdelegate.cpp \ popupwindow/popupstatusbarmessage.cpp \ other/licenseviewer.cpp \ - bookmarksimport/bookmarksimporticonfetcher.cpp \ other/checkboxdialog.cpp \ tools/plaineditwithlines.cpp \ tools/focusselectlineedit.cpp \ @@ -388,7 +387,6 @@ HEADERS += \ preferences/pluginlistdelegate.h \ popupwindow/popupstatusbarmessage.h \ other/licenseviewer.h \ - bookmarksimport/bookmarksimporticonfetcher.h \ other/checkboxdialog.h \ tools/plaineditwithlines.h \ sidebar/sidebarinterface.h \ diff --git a/src/lib/other/browsinglibrary.cpp b/src/lib/other/browsinglibrary.cpp index 3fca1f8a0..d8aa057c9 100644 --- a/src/lib/other/browsinglibrary.cpp +++ b/src/lib/other/browsinglibrary.cpp @@ -21,11 +21,12 @@ #include "bookmarksmanager.h" #include "rssmanager.h" #include "mainapplication.h" -#include "downloaditem.h" #include "qztools.h" #include "settings.h" -#include "history.h" +#include "bookmarksimportdialog.h" + +#include #include BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget* parent) @@ -49,10 +50,14 @@ BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget* parent) ui->tabs->AddTab(m_historyManager, QIcon(":/icons/other/bighistory.png"), tr("History")); ui->tabs->AddTab(m_bookmarksManager, QIcon(":/icons/other/bigstar.png"), tr("Bookmarks")); ui->tabs->AddTab(m_rssManager, QIcon(":/icons/other/feed.png"), tr("RSS")); - ui->tabs->SetMode(FancyTabWidget::Mode_LargeSidebar); ui->tabs->setFocus(); + QMenu* m = new QMenu(this); + m->addAction(tr("Import Bookmarks..."), this, SLOT(importBookmarks())); + m->addAction(tr("Export Bookmarks to HTML..."), this, SLOT(exportBookmarks())); + ui->importExport->setMenu(m); + connect(ui->tabs, SIGNAL(CurrentChanged(int)), this, SLOT(currentIndexChanged(int))); connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(search())); @@ -95,6 +100,17 @@ void BrowsingLibrary::search() } } +void BrowsingLibrary::importBookmarks() +{ + BookmarksImportDialog* d = new BookmarksImportDialog(this); + d->show(); +} + +void BrowsingLibrary::exportBookmarks() +{ + +} + void BrowsingLibrary::showHistory(QupZilla* mainClass) { ui->tabs->SetCurrentIndex(0); diff --git a/src/lib/other/browsinglibrary.h b/src/lib/other/browsinglibrary.h index 5f2b48808..143712bb3 100644 --- a/src/lib/other/browsinglibrary.h +++ b/src/lib/other/browsinglibrary.h @@ -53,6 +53,9 @@ private slots: void currentIndexChanged(int index); void search(); + void importBookmarks(); + void exportBookmarks(); + private: void closeEvent(QCloseEvent* e); void keyPressEvent(QKeyEvent* e); diff --git a/src/lib/other/browsinglibrary.ui b/src/lib/other/browsinglibrary.ui index 8747b6c28..e380418eb 100644 --- a/src/lib/other/browsinglibrary.ui +++ b/src/lib/other/browsinglibrary.ui @@ -54,6 +54,13 @@ 0 + + + + Import / Export + + +