File indexing completed on 2024-05-26 05:00:26

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "bookmarksexportdialog.h"
0019 #include "ui_bookmarksexportdialog.h"
0020 #include "htmlexporter.h"
0021 #include "mainapplication.h"
0022 #include "bookmarks.h"
0023 
0024 #include <QMessageBox>
0025 
0026 BookmarksExportDialog::BookmarksExportDialog(QWidget* parent)
0027     : QDialog(parent)
0028     , ui(new Ui::BookmarksExportDialog)
0029     , m_currentExporter(nullptr)
0030 {
0031     setAttribute(Qt::WA_DeleteOnClose);
0032     ui->setupUi(this);
0033 
0034     init();
0035 
0036     connect(ui->chooseOutput, &QAbstractButton::clicked, this, &BookmarksExportDialog::setPath);
0037     connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &BookmarksExportDialog::exportBookmarks);
0038     connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
0039 }
0040 
0041 BookmarksExportDialog::~BookmarksExportDialog()
0042 {
0043     delete ui;
0044 }
0045 
0046 void BookmarksExportDialog::setPath()
0047 {
0048     Q_ASSERT(m_currentExporter);
0049 
0050     ui->output->setText(m_currentExporter->getPath(this));
0051 }
0052 
0053 void BookmarksExportDialog::exportBookmarks()
0054 {
0055     Q_ASSERT(m_currentExporter);
0056 
0057     if (ui->output->text().isEmpty()) {
0058         return;
0059     }
0060 
0061     bool ok = m_currentExporter->exportBookmarks(mApp->bookmarks()->rootItem());
0062 
0063     if (!ok) {
0064         QMessageBox::critical(this, tr("Error!"), m_currentExporter->errorString());
0065     }
0066     else {
0067         close();
0068     }
0069 }
0070 
0071 void BookmarksExportDialog::init()
0072 {
0073     m_exporters.append(new HtmlExporter(this));
0074 
0075     for (BookmarksExporter* exporter : std::as_const(m_exporters)) {
0076         ui->format->addItem(exporter->name());
0077     }
0078 
0079     m_currentExporter = m_exporters.at(0);
0080 }