File indexing completed on 2024-12-22 04:45:57
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "exportdatafinishpage.h" 0008 #include "exportaccountjob.h" 0009 #include <KLocalizedString> 0010 #include <KMessageWidget> 0011 #include <QDateTime> 0012 #include <QDir> 0013 #include <QLabel> 0014 #include <QPlainTextEdit> 0015 #include <QVBoxLayout> 0016 0017 ExportDataFinishPage::ExportDataFinishPage(QWidget *parent) 0018 : QWizardPage(parent) 0019 , mInfos(new QLabel(this)) 0020 , mMessageWidget(new KMessageWidget(this)) 0021 , mDetails(new QPlainTextEdit(this)) 0022 { 0023 auto mainLayout = new QVBoxLayout(this); 0024 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0025 0026 mInfos->setObjectName(QStringLiteral("mInfos")); 0027 mainLayout->addWidget(mInfos); 0028 0029 mDetails->setObjectName(QStringLiteral("mDetails")); 0030 mDetails->setReadOnly(true); 0031 0032 mMessageWidget->setObjectName(QStringLiteral("mMessageWidget")); 0033 mMessageWidget->setVisible(false); 0034 mMessageWidget->setCloseButtonVisible(false); 0035 mMessageWidget->setMessageType(KMessageWidget::Information); 0036 mMessageWidget->setWordWrap(true); 0037 mMessageWidget->setText(i18n("Accounts Exported.")); 0038 mainLayout->addWidget(mMessageWidget); 0039 0040 mainLayout->addWidget(mDetails); 0041 } 0042 0043 ExportDataFinishPage::~ExportDataFinishPage() = default; 0044 0045 bool ExportDataFinishPage::isComplete() const 0046 { 0047 return mExportDone; 0048 } 0049 0050 QString ExportDataFinishPage::generateExportZipFileName() const 0051 { 0052 return QDir::homePath() + QLatin1Char('/') + QStringLiteral("ruqola-accountdata-%1.zip").arg(QDateTime::currentDateTime().toString()); 0053 } 0054 0055 void ExportDataFinishPage::setListAccounts(const QVector<ImportExportUtils::AccountImportExportInfo> &newListAccounts) 0056 { 0057 // We will export => it's not done yet 0058 mExportDone = false; 0059 Q_EMIT completeChanged(); 0060 mListAccounts = newListAccounts; 0061 } 0062 0063 void ExportDataFinishPage::exportAccounts() 0064 { 0065 auto job = new ExportAccountJob(generateExportZipFileName(), this); 0066 connect(job, &ExportAccountJob::exportDone, this, &ExportDataFinishPage::slotExportDone); 0067 connect(job, &ExportAccountJob::exportFailed, this, &ExportDataFinishPage::slotExportFailed); 0068 connect(job, &ExportAccountJob::exportInfo, this, &ExportDataFinishPage::slotExportInfo); 0069 connect(job, &ExportAccountJob::finished, this, [this]() { 0070 mExportDone = true; 0071 Q_EMIT completeChanged(); 0072 }); 0073 job->setListAccounts(mListAccounts); 0074 job->start(); 0075 } 0076 0077 void ExportDataFinishPage::slotExportDone() 0078 { 0079 mMessageWidget->animatedShow(); 0080 } 0081 0082 void ExportDataFinishPage::slotExportFailed(const QString &msg) 0083 { 0084 QString currentText = mInfos->text(); 0085 if (!currentText.isEmpty()) { 0086 currentText += QLatin1Char('\n'); 0087 } 0088 mInfos->setText(currentText + msg); 0089 } 0090 0091 void ExportDataFinishPage::slotExportInfo(const QString &msg) 0092 { 0093 mDetails->appendPlainText(msg); 0094 } 0095 0096 #include "moc_exportdatafinishpage.cpp"