File indexing completed on 2024-05-05 04:38:45

0001 /*
0002     SPDX-FileCopyrightText: 2015 Kevin Funk <kfunk@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "jobstatus.h"
0008 
0009 #include <KJob>
0010 #include <KLocalizedString>
0011 
0012 using namespace KDevelop;
0013 
0014 class KDevelop::JobStatusPrivate
0015 {
0016 public:
0017     QString m_statusName;
0018 };
0019 
0020 JobStatus::JobStatus(KJob* job, const QString& statusName, QObject* parent)
0021     : QObject(parent)
0022     , d_ptr(new JobStatusPrivate{statusName})
0023 {
0024     connect(job, &KJob::infoMessage, this, [this](KJob*, const QString& plain, const QString&) {
0025         emit showMessage(this, plain);
0026     });
0027     connect(job, &KJob::finished, this, [this, job]() {
0028         if (job->error() == KJob::KilledJobError) {
0029             emit showErrorMessage(i18n("Task aborted"));
0030         }
0031         emit hideProgress(this);
0032         deleteLater();
0033     });
0034     connect(job, &KJob::percentChanged, this, &JobStatus::slotPercent);
0035 }
0036 
0037 JobStatus::~JobStatus()
0038 {
0039 }
0040 
0041 QString JobStatus::statusName() const
0042 {
0043     Q_D(const JobStatus);
0044 
0045     return d->m_statusName;
0046 }
0047 
0048 void JobStatus::slotPercent(KJob* job, unsigned long percent)
0049 {
0050     Q_UNUSED(job)
0051     emit showProgress(this, 0, 100, percent);
0052 }
0053 
0054 #include "moc_jobstatus.cpp"