File indexing completed on 2024-12-22 04:45:58
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "importdatafinishpage.h" 0008 #include "importaccountjob.h" 0009 #include <KLocalizedString> 0010 #include <KMessageWidget> 0011 #include <QLabel> 0012 #include <QPlainTextEdit> 0013 #include <QUrl> 0014 #include <QVBoxLayout> 0015 0016 ImportDataFinishPage::ImportDataFinishPage(QWidget *parent) 0017 : QWizardPage(parent) 0018 , mInfos(new QLabel(this)) 0019 , mMessageWidget(new KMessageWidget(this)) 0020 , mDetails(new QPlainTextEdit(this)) 0021 { 0022 auto mainLayout = new QVBoxLayout(this); 0023 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0024 0025 mInfos->setObjectName(QStringLiteral("mInfos")); 0026 mainLayout->addWidget(mInfos); 0027 0028 mMessageWidget->setObjectName(QStringLiteral("mMessageWidget")); 0029 mMessageWidget->setVisible(false); 0030 mMessageWidget->setCloseButtonVisible(false); 0031 mMessageWidget->setMessageType(KMessageWidget::Information); 0032 mMessageWidget->setWordWrap(true); 0033 mMessageWidget->setText(i18n("Accounts imported.")); 0034 mainLayout->addWidget(mMessageWidget); 0035 0036 mDetails->setObjectName(QStringLiteral("mDetails")); 0037 mDetails->setReadOnly(true); 0038 mainLayout->addWidget(mDetails); 0039 } 0040 0041 ImportDataFinishPage::~ImportDataFinishPage() = default; 0042 0043 void ImportDataFinishPage::setZipFileUrl(const QUrl &url) 0044 { 0045 mImportDone = false; 0046 Q_EMIT completeChanged(); 0047 auto job = new ImportAccountJob(url.toLocalFile(), this); 0048 connect(job, &ImportAccountJob::importDone, this, &ImportDataFinishPage::slotImportDone); 0049 connect(job, &ImportAccountJob::importFailed, this, &ImportDataFinishPage::slotImportFailed); 0050 connect(job, &ImportAccountJob::importInfo, this, &ImportDataFinishPage::slotImportInfo); 0051 connect(job, &ImportAccountJob::finished, this, [this]() { 0052 mImportDone = true; 0053 Q_EMIT completeChanged(); 0054 }); 0055 job->start(); 0056 } 0057 0058 bool ImportDataFinishPage::isComplete() const 0059 { 0060 return mImportDone; 0061 } 0062 0063 void ImportDataFinishPage::slotImportDone() 0064 { 0065 mMessageWidget->animatedShow(); 0066 } 0067 0068 void ImportDataFinishPage::slotImportInfo(const QString &msg) 0069 { 0070 mDetails->appendPlainText(msg); 0071 } 0072 0073 void ImportDataFinishPage::slotImportFailed(const QString &msg) 0074 { 0075 QString currentText = mInfos->text(); 0076 if (!currentText.isEmpty()) { 0077 currentText += QLatin1Char('\n'); 0078 } 0079 mInfos->setText(currentText + msg); 0080 } 0081 0082 #include "moc_importdatafinishpage.cpp"