Falkon Develop
Cross-platform Qt-based web browser
bookmarksexportdialog.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19#include "ui_bookmarksexportdialog.h"
20#include "htmlexporter.h"
21#include "mainapplication.h"
22#include "bookmarks.h"
23
24#include <QMessageBox>
25
27 : QDialog(parent)
28 , ui(new Ui::BookmarksExportDialog)
29 , m_currentExporter(nullptr)
30{
31 setAttribute(Qt::WA_DeleteOnClose);
32 ui->setupUi(this);
33
34 init();
35
36 connect(ui->chooseOutput, &QAbstractButton::clicked, this, &BookmarksExportDialog::setPath);
37 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &BookmarksExportDialog::exportBookmarks);
38 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
39}
40
42{
43 delete ui;
44}
45
46void BookmarksExportDialog::setPath()
47{
48 Q_ASSERT(m_currentExporter);
49
50 ui->output->setText(m_currentExporter->getPath(this));
51}
52
53void BookmarksExportDialog::exportBookmarks()
54{
55 Q_ASSERT(m_currentExporter);
56
57 if (ui->output->text().isEmpty()) {
58 return;
59 }
60
61 bool ok = m_currentExporter->exportBookmarks(mApp->bookmarks()->rootItem());
62
63 if (!ok) {
64 QMessageBox::critical(this, tr("Error!"), m_currentExporter->errorString());
65 }
66 else {
67 close();
68 }
69}
70
71void BookmarksExportDialog::init()
72{
73 m_exporters.append(new HtmlExporter(this));
74
75 for (BookmarksExporter* exporter : std::as_const(m_exporters)) {
76 ui->format->addItem(exporter->name());
77 }
78
79 m_currentExporter = m_exporters.at(0);
80}
BookmarksExportDialog(QWidget *parent=nullptr)
virtual bool exportBookmarks(BookmarkItem *root)=0
virtual QString getPath(QWidget *parent)=0
QString errorString() const
#define mApp