mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
[Bookmarks] Importing bookmarks now works
It will however need a complete rewrite, the code is really bad. HtmlImport: Supports importing bookmarks with full structure
This commit is contained in:
parent
284e58ebca
commit
1d822d3a03
|
@ -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();
|
||||
|
|
|
@ -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 <QWebSettings>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QThread>
|
||||
|
||||
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<QString, QTreeWidgetItem*> 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<Bookmark>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,20 +19,15 @@
|
|||
#define BOOKMARKSIMPORTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPair>
|
||||
|
||||
#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<Bookmark> m_exportedBookmarks;
|
||||
|
||||
BookmarksImportIconFetcher* m_fetcher;
|
||||
QThread* m_fetcherThread;
|
||||
BookmarkItem* m_exportedFolder;
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSIMPORTDIALOG_H
|
||||
|
|
|
@ -217,110 +217,6 @@
|
|||
</widget>
|
||||
<widget class="QWidget" name="finalPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="fetchingLabel">
|
||||
<property name="text">
|
||||
<string>Fetching icons, please wait...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="stopButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/icons.qrc">
|
||||
<normaloff>:/icons/theme/stop.png</normaloff>:/icons/theme/stop.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<attribute name="headerMinimumSectionSize">
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-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 "bookmarksimporticonfetcher.h"
|
||||
#include "iconfetcher.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
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<IconFetcher*>(sender());
|
||||
if (!fetcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
QTreeWidgetItem* itemPointer = static_cast<QTreeWidgetItem*>(fetcher->data().value<void*>());
|
||||
|
||||
emit iconFetched(image, itemPointer);
|
||||
}
|
||||
|
||||
void BookmarksImportIconFetcher::slotFetcherFinished()
|
||||
{
|
||||
IconFetcher* fetcher = qobject_cast<IconFetcher*>(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);
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-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/>.
|
||||
* ============================================================ */
|
||||
#ifndef BOOKMARKSIMPORTICONFETCHER_H
|
||||
#define BOOKMARKSIMPORTICONFETCHER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
|
||||
#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<Pair> m_pairs;
|
||||
QList<IconFetcher*> m_fetchers;
|
||||
|
||||
};
|
||||
|
||||
// Hint to QVector to use std::realloc on item moving
|
||||
Q_DECLARE_TYPEINFO(BookmarksImportIconFetcher::Pair, Q_MOVABLE_TYPE);
|
||||
|
||||
#endif // BOOKMARKSIMPORTICONFETCHER_H
|
|
@ -18,6 +18,7 @@
|
|||
#include "chromeimporter.h"
|
||||
#include "qztools.h"
|
||||
#include "bookmarksimportdialog.h"
|
||||
#include "bookmarkitem.h"
|
||||
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValue>
|
||||
|
@ -49,10 +50,8 @@ bool ChromeImporter::openFile()
|
|||
return true;
|
||||
}
|
||||
|
||||
QVector<Bookmark> ChromeImporter::exportBookmarks()
|
||||
BookmarkItem* ChromeImporter::exportBookmarks()
|
||||
{
|
||||
QVector<Bookmark> list;
|
||||
|
||||
QString bookmarks = QString::fromUtf8(m_file.readAll());
|
||||
m_file.close();
|
||||
|
||||
|
@ -66,6 +65,9 @@ QVector<Bookmark> 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<Bookmark> 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<Bookmark> ChromeImporter::exportBookmarks()
|
|||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#include <QFile>
|
||||
|
||||
#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<Bookmark> exportBookmarks();
|
||||
BookmarkItem* exportBookmarks();
|
||||
|
||||
bool error() { return m_error; }
|
||||
QString errorString() { return m_errorString; }
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* ============================================================ */
|
||||
#include "firefoximporter.h"
|
||||
#include "bookmarksimportdialog.h"
|
||||
#include "bookmarkitem.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
|
@ -54,9 +55,10 @@ bool FirefoxImporter::openDatabase()
|
|||
return true;
|
||||
}
|
||||
|
||||
QVector<Bookmark> FirefoxImporter::exportBookmarks()
|
||||
BookmarkItem* FirefoxImporter::exportBookmarks()
|
||||
{
|
||||
QVector<Bookmark> 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<Bookmark> 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<Bookmark> FirefoxImporter::exportBookmarks()
|
|||
m_errorString = query.lastError().text();
|
||||
}
|
||||
|
||||
return list;
|
||||
return root;
|
||||
}
|
||||
|
|
|
@ -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<Bookmarks::Bookmark> exportBookmarks();
|
||||
BookmarkItem* exportBookmarks();
|
||||
|
||||
bool error() { return m_error; }
|
||||
QString errorString() { return m_errorString; }
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
* ============================================================ */
|
||||
#include "htmlimporter.h"
|
||||
#include "bookmarksimportdialog.h"
|
||||
|
||||
#include "bookmarkitem.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
HtmlImporter::HtmlImporter(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_error(false)
|
||||
|
@ -59,10 +61,8 @@ int qzMin(int a, int b)
|
|||
}
|
||||
}
|
||||
|
||||
QVector<Bookmark> HtmlImporter::exportBookmarks()
|
||||
BookmarkItem* HtmlImporter::exportBookmarks()
|
||||
{
|
||||
QVector<Bookmarks::Bookmark> list;
|
||||
|
||||
QString bookmarks = QString::fromUtf8(m_file.readAll());
|
||||
m_file.close();
|
||||
|
||||
|
@ -84,7 +84,11 @@ QVector<Bookmark> HtmlImporter::exportBookmarks()
|
|||
bookmarks = bookmarks.left(bookmarks.lastIndexOf(QLatin1String("</dl><p>")));
|
||||
int start = bookmarks.indexOf(QLatin1String("<dl><p>"));
|
||||
|
||||
QStringList folders("Html Import");
|
||||
BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder);
|
||||
root->setTitle("HTML Import");
|
||||
|
||||
QList<BookmarkItem*> folders;
|
||||
folders.append(root);
|
||||
|
||||
while (start > 0) {
|
||||
QString string = bookmarks.mid(start);
|
||||
|
@ -107,7 +111,9 @@ QVector<Bookmark> 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<Bookmark> 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;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#include <QFile>
|
||||
|
||||
#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<Bookmark> exportBookmarks();
|
||||
BookmarkItem* exportBookmarks();
|
||||
|
||||
bool error() { return m_error; }
|
||||
QString errorString() { return m_errorString; }
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "ieimporter.h"
|
||||
|
||||
#include "bookmarksimportdialog.h"
|
||||
#include "bookmarkitem.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QSettings>
|
||||
|
||||
IeImporter::IeImporter(QObject* parent)
|
||||
|
@ -57,22 +58,20 @@ bool IeImporter::openFile()
|
|||
return true;
|
||||
}
|
||||
|
||||
QVector<Bookmarks::Bookmark> IeImporter::exportBookmarks()
|
||||
BookmarkItem* IeImporter::exportBookmarks()
|
||||
{
|
||||
QVector<Bookmarks::Bookmark> 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;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
#include <QObject>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
#include "bookmarks.h"
|
||||
|
||||
#include <QFileInfoList>
|
||||
|
||||
class BookmarkItem;
|
||||
|
||||
class IeImporter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -34,7 +35,7 @@ public:
|
|||
void setFile(const QString &path);
|
||||
bool openFile();
|
||||
|
||||
QVector<Bookmarks::Bookmark> exportBookmarks();
|
||||
BookmarkItem* exportBookmarks();
|
||||
|
||||
bool error() { return m_error; }
|
||||
QString errorString() { return m_errorString; }
|
||||
|
|
|
@ -17,8 +17,11 @@
|
|||
* ============================================================ */
|
||||
#include "operaimporter.h"
|
||||
#include "bookmarksimportdialog.h"
|
||||
#include "bookmarkitem.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
OperaImporter::OperaImporter(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_error(false)
|
||||
|
@ -44,16 +47,17 @@ bool OperaImporter::openFile()
|
|||
return true;
|
||||
}
|
||||
|
||||
QVector<Bookmark> OperaImporter::exportBookmarks()
|
||||
BookmarkItem* OperaImporter::exportBookmarks()
|
||||
{
|
||||
QVector<Bookmark> 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<Bookmark> 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;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
void setFile(const QString &path);
|
||||
bool openFile();
|
||||
|
||||
QVector<Bookmarks::Bookmark> exportBookmarks();
|
||||
BookmarkItem* exportBookmarks();
|
||||
|
||||
bool error() { return m_error; }
|
||||
QString errorString() { return m_errorString; }
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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 <QMenu>
|
||||
#include <QCloseEvent>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -54,6 +54,13 @@
|
|||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="importExport">
|
||||
<property name="text">
|
||||
<string>Import / Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
Loading…
Reference in New Issue
Block a user