mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
[Bookmarks] Added option to export bookmarks to HTML file.
This commit is contained in:
parent
4265b90643
commit
b1da23ca72
@ -37,6 +37,7 @@
|
||||
#include <QShortcut>
|
||||
#include <QMenu>
|
||||
#include <QSqlQuery>
|
||||
#include <QLabel>
|
||||
|
||||
BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
@ -70,7 +71,11 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
|
||||
connect(m_bookmarksModel, SIGNAL(folderParentChanged(QString,bool)), this, SLOT(changeFolderParent(QString,bool)));
|
||||
connect(m_bookmarksModel, SIGNAL(bookmarkParentChanged(QString,QByteArray,int,QUrl,QString,QString)), this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
||||
|
||||
connect(ui->importBookmarks, SIGNAL(clicked(QPoint)), this, SLOT(importBookmarks()));
|
||||
QMenu* menu = new QMenu;
|
||||
menu->addAction(tr("Import Bookmarks..."), this, SLOT(importBookmarks()));
|
||||
menu->addAction(tr("Export Bookmarks to HTML..."), this, SLOT(exportBookmarks()));
|
||||
|
||||
ui->importExport->setMenu(menu);
|
||||
|
||||
QShortcut* deleteAction = new QShortcut(QKeySequence("Del"), ui->bookmarksTree);
|
||||
connect(deleteAction, SIGNAL(activated()), this, SLOT(deleteItem()));
|
||||
@ -85,6 +90,15 @@ void BookmarksManager::importBookmarks()
|
||||
b->show();
|
||||
}
|
||||
|
||||
void BookmarksManager::exportBookmarks()
|
||||
{
|
||||
QString file = QzTools::getSaveFileName("BookmarksManager-Export", this, tr("Export to HTML..."), QDir::homePath() + "/bookmarks.html");
|
||||
|
||||
if (!file.isEmpty()) {
|
||||
m_bookmarksModel->exportToHtml(file);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksManager::search(const QString &string)
|
||||
{
|
||||
ui->bookmarksTree->filterString(string);
|
||||
|
@ -64,7 +64,9 @@ private slots:
|
||||
void moveBookmark();
|
||||
void renameBookmark();
|
||||
void changeIcon();
|
||||
|
||||
void importBookmarks();
|
||||
void exportBookmarks();
|
||||
|
||||
void addFolder(const QString &name);
|
||||
void addSubfolder(const QString &name);
|
||||
|
@ -14,16 +14,17 @@
|
||||
<string>Bookmarks</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="7">
|
||||
<widget class="ClickableLabel" name="importBookmarks">
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QPushButton" name="addFolder">
|
||||
<property name="text">
|
||||
<string>Import Bookmarks</string>
|
||||
<string>Add Folder</string>
|
||||
</property>
|
||||
<property name="html-link-look" stdset="0">
|
||||
<bool>true</bool>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<widget class="QPushButton" name="collapseAll">
|
||||
<property name="text">
|
||||
<string>Collapse All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -40,14 +41,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QPushButton" name="addFolder">
|
||||
<property name="text">
|
||||
<string>Add Folder</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="9">
|
||||
<item row="0" column="0" colspan="8">
|
||||
<widget class="BookmarksTree" name="bookmarksTree">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
@ -83,21 +77,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<widget class="QPushButton" name="collapseAll">
|
||||
<item row="1" column="7">
|
||||
<widget class="QToolButton" name="importExport">
|
||||
<property name="text">
|
||||
<string>Collapse All</string>
|
||||
<string>Import and Export</string>
|
||||
</property>
|
||||
<property name="popupMode">
|
||||
<enum>QToolButton::InstantPopup</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ClickableLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>clickablelabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BookmarksTree</class>
|
||||
<extends>QTreeWidget</extends>
|
||||
|
@ -22,7 +22,10 @@
|
||||
#include "mainapplication.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
// SQLite DB -> table bookmarks + folders
|
||||
// Unique in bookmarks table is id
|
||||
@ -447,6 +450,84 @@ bool BookmarksModel::renameFolder(const QString &before, const QString &after)
|
||||
return true;
|
||||
}
|
||||
|
||||
void BookmarksModel::exportToHtml(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
qWarning() << "BookmarksModel::exportHtml Cannot open file for writing!" << file.errorString();
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
|
||||
out << "<!DOCTYPE NETSCAPE-Bookmark-file-1>" << endl;
|
||||
out << "<!-- This is an automatically generated file." << endl;
|
||||
out << " It will be read and overwritten." << endl;
|
||||
out << " DO NOT EDIT! -->" << endl;
|
||||
out << "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">" << endl;
|
||||
out << "<TITLE>Bookmarks</TITLE>" << endl;
|
||||
out << "<H1>Bookmarks</H1>" << endl;
|
||||
|
||||
out << "<DL><p>" << endl;
|
||||
|
||||
QString indent = " ";
|
||||
QList<QPair<QString, bool> > allFolders;
|
||||
|
||||
QPair<QString, bool> menu;
|
||||
menu.first = "bookmarksMenu";
|
||||
menu.second = false;
|
||||
|
||||
QPair<QString, bool> toolbar;
|
||||
toolbar.first = "bookmarksToolbar";
|
||||
toolbar.second = false;
|
||||
|
||||
allFolders.append(menu);
|
||||
allFolders.append(toolbar);
|
||||
|
||||
QSqlQuery query;
|
||||
query.exec("SELECT name, subfolder FROM folders");
|
||||
|
||||
while (query.next()) {
|
||||
QPair<QString, bool> pair;
|
||||
pair.first = query.value(0).toString();
|
||||
pair.second = query.value(1).toString() == QLatin1String("yes");
|
||||
|
||||
allFolders.append(pair);
|
||||
}
|
||||
|
||||
for (int i = 0; i < allFolders.size(); ++i) {
|
||||
QPair<QString, bool> pair = allFolders.at(i);
|
||||
|
||||
out << indent << "<DT><H3 TOOLBAR_SUBFOLDER=\"" << (pair.second ? "yes" : "no") << "\">" << pair.first << "</H3>" << endl;
|
||||
out << indent << "<DL><p>" << endl;
|
||||
|
||||
QSqlQuery q;
|
||||
q.prepare("SELECT title, url FROM bookmarks WHERE folder = ?");
|
||||
q.addBindValue(pair.first);
|
||||
q.exec();
|
||||
|
||||
while (q.next()) {
|
||||
QString title = q.value(0).toString();
|
||||
QString url = q.value(1).toString();
|
||||
|
||||
out << indent << indent << "<DT><A HREF=\"" << url << "\">" << title << "</A>" << endl;
|
||||
}
|
||||
|
||||
out << indent << "</DL><p>" << endl;
|
||||
}
|
||||
|
||||
query.exec("SELECT title, url FROM bookmarks WHERE folder='' OR folder='unsorted'");
|
||||
|
||||
while (query.next()) {
|
||||
QString title = query.value(0).toString();
|
||||
QString url = query.value(1).toString();
|
||||
|
||||
out << indent << "<DT><A HREF=\"" << url << "\">" << title << "</A>" << endl;
|
||||
}
|
||||
|
||||
out << "</DL><p>" << endl;
|
||||
}
|
||||
|
||||
QVector<Bookmark> BookmarksModel::folderBookmarks(const QString &name)
|
||||
{
|
||||
QVector<Bookmark> list;
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
|
||||
bool renameFolder(const QString &before, const QString &after);
|
||||
|
||||
void exportToHtml(const QString &fileName);
|
||||
|
||||
static bool bookmarksEqual(const Bookmark &one, const Bookmark &two);
|
||||
static QString toTranslatedFolder(const QString &name);
|
||||
static QString fromTranslatedFolder(const QString &name);
|
||||
|
Loading…
Reference in New Issue
Block a user