Commit e130d1e3 authored by Igor Kushnir's avatar Igor Kushnir

Connect to KJob signals with functor-based connection syntax

KJob::percent(KJob *job, unsigned long percent) signal is public since
https://commits.kde.org/kcoreaddons/c0b312a41f7fcb42ac6251a2d194c7799dfac723
(since KF 5.46).

Simplify JobStatus implementation:
* move slotPercent() from JobStatusPrivate to JobStatus for simplicity;
* remove unused JobStatusPrivate::m_job data member.

ulong => unsigned long in PatchReviewToolView::testJobPercent() because
"ulong" is practically absent from KDevelop source code now.

GIT_SILENT
parent 5cc55cbc
Pipeline #36691 canceled with stage
......@@ -196,8 +196,7 @@ void ProjectSourcePage::checkoutVcsProject()
m_ui->get->setEnabled(false);
m_ui->creationProgress->setValue(m_ui->creationProgress->minimum());
connect(job, &VcsJob::result, this, &ProjectSourcePage::projectReceived);
// Can't use new signal-slot syntax, KJob::percent is private :/
connect(job, SIGNAL(percent(KJob*,ulong)), SLOT(progressChanged(KJob*,ulong)));
connect(job, QOverload<KJob*, unsigned long>::of(&KJob::percent), this, &ProjectSourcePage::progressChanged);
connect(job, &VcsJob::infoMessage, this, &ProjectSourcePage::infoMessage);
ICore::self()->runController()->registerJob(job);
}
......
......@@ -616,9 +616,7 @@ void KDevelop::RunController::registerJob(KJob * job)
connect( job, &KJob::finished, this, &RunController::finished );
connect( job, &KJob::destroyed, this, &RunController::jobDestroyed );
// FIXME percent is a private signal and thus we cannot use new connect syntax
connect(job, SIGNAL(percent(KJob*,ulong)), this, SLOT(jobPercentChanged()));
connect(job, QOverload<KJob*, unsigned long>::of(&KJob::percent), this, &RunController::jobPercentChanged);
IRunController::registerJob(job);
......
......@@ -82,7 +82,8 @@ bool ExecuteCompositeJob::addSubjob(KJob* job)
++d->m_jobCount;
connect(job, SIGNAL(percent(KJob*,ulong)), this, SLOT(slotPercent(KJob*,ulong)));
connect(job, QOverload<KJob*, unsigned long>::of(&KJob::percent),
this, &ExecuteCompositeJob::slotPercent);
return true;
}
......@@ -105,7 +106,8 @@ void ExecuteCompositeJob::slotResult(KJob* job)
{
Q_D(ExecuteCompositeJob);
disconnect(job, SIGNAL(percent(KJob*,ulong)), this, SLOT(slotPercent(KJob*,ulong)));
disconnect(job, QOverload<KJob*, unsigned long>::of(&KJob::percent),
this, &ExecuteCompositeJob::slotPercent);
// jobIndex + 1 because this job just finished
const float ratio = d->m_jobIndex != -1 ? (d->m_jobIndex + 1.0) / d->m_jobCount : 1.0;
......
......@@ -29,33 +29,13 @@ using namespace KDevelop;
class KDevelop::JobStatusPrivate
{
public:
explicit JobStatusPrivate(JobStatus* q) : q(q) {}
void slotPercent(KJob* job, unsigned long percent);
JobStatus* q;
KJob* m_job;
QString m_statusName;
};
void JobStatusPrivate::slotPercent(KJob* job, long unsigned int percent)
{
Q_UNUSED(job);
emit q->showProgress(q, 0, 100, percent);
}
JobStatus::JobStatus(KJob* job, const QString& statusName, QObject* parent)
: QObject(parent)
, d_ptr(new JobStatusPrivate(this))
, d_ptr(new JobStatusPrivate{statusName})
{
Q_D(JobStatus);
d->m_job = job;
d->m_statusName = statusName;
connect(job, &KJob::infoMessage, this, [this](KJob*, const QString& plain, const QString&) {
emit showMessage(this, plain);
});
......@@ -66,8 +46,7 @@ JobStatus::JobStatus(KJob* job, const QString& statusName, QObject* parent)
emit hideProgress(this);
deleteLater();
});
// no new-signal-slot syntax possible :(
connect(job, SIGNAL(percent(KJob*,ulong)), this, SLOT(slotPercent(KJob*,ulong)));
connect(job, QOverload<KJob*, unsigned long>::of(&KJob::percent), this, &JobStatus::slotPercent);
}
JobStatus::~JobStatus()
......@@ -81,4 +60,10 @@ QString JobStatus::statusName() const
return d->m_statusName;
}
void JobStatus::slotPercent(KJob* job, unsigned long percent)
{
Q_UNUSED(job)
emit showProgress(this, 0, 100, percent);
}
#include "moc_jobstatus.cpp"
......@@ -61,11 +61,12 @@ Q_SIGNALS:
void showMessage(KDevelop::IStatus*, const QString& message, int timeout = 0) override;
void showProgress(KDevelop::IStatus*, int minimum, int maximum, int value) override;
private Q_SLOTS:
void slotPercent(KJob* job, unsigned long percent);
private:
const QScopedPointer<class JobStatusPrivate> d_ptr;
Q_DECLARE_PRIVATE(JobStatus)
Q_PRIVATE_SLOT(d_func(), void slotPercent(KJob*, unsigned long))
};
}
......@@ -33,8 +33,8 @@ using namespace KDevelop;
struct JobSpy
{
explicit JobSpy(KJob* job)
: finished(job, SIGNAL(finished(KJob*)))
, result(job, SIGNAL(result(KJob*)))
: finished(job, &KJob::finished)
, result(job, &KJob::result)
{}
QSignalSpy finished;
QSignalSpy result;
......
......@@ -570,11 +570,11 @@ void PatchReviewToolView::runTests()
auto* job = new ProjectTestJob(project, this);
connect(job, &ProjectTestJob::finished, this, &PatchReviewToolView::testJobResult);
connect(job, SIGNAL(percent(KJob*,ulong)), this, SLOT(testJobPercent(KJob*,ulong)));
connect(job, QOverload<KJob*, unsigned long>::of(&KJob::percent), this, &PatchReviewToolView::testJobPercent);
ICore::self()->runController()->registerJob(job);
}
void PatchReviewToolView::testJobPercent(KJob* job, ulong percent)
void PatchReviewToolView::testJobPercent(KJob* job, unsigned long percent)
{
Q_UNUSED(job);
m_editPatch.testProgressBar->setValue(percent);
......
......@@ -103,7 +103,7 @@ public Q_SLOTS:
void documentActivated( KDevelop::IDocument* );
void customContextMenuRequested(const QPoint& p);
void testJobResult(KJob* job);
void testJobPercent(KJob* job, ulong percent);
void testJobPercent(KJob* job, unsigned long percent);
};
#endif // KDEVPLATFORM_PLUGIN_PATCHREVIEWTOOLVIEW_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment