File indexing completed on 2024-05-19 05:01:19

0001 // /* This file is part of the KDE project
0002 //     SPDX-FileCopyrightText: 2023 Stefano Crocco <stefano.crocco@alice.it>
0003 // 
0004 //     SPDX-License-Identifier: LGPL-2.0-or-later
0005 // */
0006 
0007 #include "choosepagesaveformatdlg.h"
0008 #include "ui_choosepagesaveformatdlg.h"
0009 
0010 #include <QButtonGroup>
0011 
0012 ChoosePageSaveFormatDlg::ChoosePageSaveFormatDlg(QWidget* parent)
0013     : QDialog(parent), m_ui(new Ui::ChoosePageSaveFormatDlg), m_choicesGroup(new QButtonGroup(this))
0014 {
0015     m_ui->setupUi(this);
0016     m_choicesGroup->addButton(m_ui->m_singleHTMLPage, QWebEngineDownloadRequest::SavePageFormat::SingleHtmlSaveFormat);
0017     m_choicesGroup->addButton(m_ui->m_asDirectory, QWebEngineDownloadRequest::SavePageFormat::CompleteHtmlSaveFormat);
0018     m_choicesGroup->addButton(m_ui->m_asMHTMLPage, QWebEngineDownloadRequest::SavePageFormat::MimeHtmlSaveFormat);
0019     connect(m_choicesGroup, &QButtonGroup::idClicked, this, &ChoosePageSaveFormatDlg::updateInfoText);
0020     updateInfoText(m_choicesGroup->checkedId());
0021 }
0022 
0023 ChoosePageSaveFormatDlg::~ChoosePageSaveFormatDlg()
0024 {
0025 }
0026 
0027 QWebEngineDownloadRequest::SavePageFormat ChoosePageSaveFormatDlg::choosenFormat() const
0028 {
0029     return static_cast<QWebEngineDownloadRequest::SavePageFormat>(m_choicesGroup->checkedId());
0030 }
0031 
0032 void ChoosePageSaveFormatDlg::updateInfoText(int id)
0033 {
0034     QString info;
0035     switch (id) {
0036         case QWebEngineDownloadRequest::SingleHtmlSaveFormat:
0037             info = i18n("The page will be saved as a single HTML file. Only the text of the page will be saved. External resources such as images won't be saved");
0038             break;
0039         case QWebEngineDownloadRequest::CompleteHtmlSaveFormat:
0040             info = i18n("The page will be saved as an HTML file. Any external resources the page requires, such as images, will be saved inside an apposite directory");
0041             break;
0042         case QWebEngineDownloadRequest::MimeHtmlSaveFormat:
0043             info = i18n("The page will be saved as a MTHML file which contains both the text of the page and any external resources it requires, such as images. <br><strong>Note</strong>: not all browsers are able to display this kind of files");
0044             break;
0045         case QWebEngineDownloadRequest::UnknownSaveFormat: //This should never happen
0046             info = QString();
0047             break;
0048     }
0049     m_ui->m_info->setText(info);
0050 }