Skip to content

Commit 204b4e6

Browse files
committed
removed pimpl macros and this-> where possible (core)
1 parent 4bb7a79 commit 204b4e6

File tree

5 files changed

+75
-97
lines changed

5 files changed

+75
-97
lines changed

src/autoupdatercore/simplescheduler.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ int SimpleScheduler::startSchedule(int msecs, bool repeated, const QVariant &par
1818
return 0;
1919
}
2020

21-
const auto id = this->startTimer(msecs, Qt::VeryCoarseTimer);
21+
const auto id = startTimer(msecs, Qt::VeryCoarseTimer);
2222
if(id != 0)
23-
this->timerHash.insert(id, {repeated, parameter});
23+
timerHash.insert(id, {repeated, parameter});
2424
return id;
2525
}
2626

@@ -31,21 +31,21 @@ int SimpleScheduler::startSchedule(const QDateTime &when, const QVariant &parame
3131
qCWarning(logQtAutoUpdater) << "Time interval to big, timepoint to far in the future.";
3232
return 0;
3333
} else
34-
return this->startSchedule((int)delta, false, parameter);
34+
return startSchedule((int)delta, false, parameter);
3535
}
3636

3737
void SimpleScheduler::cancelSchedule(int id)
3838
{
39-
this->killTimer(id);
40-
this->timerHash.remove(id);
39+
killTimer(id);
40+
timerHash.remove(id);
4141
}
4242

4343
void SimpleScheduler::timerEvent(QTimerEvent *event)
4444
{
4545
const auto id = event->timerId();
46-
const auto info = this->timerHash.value(id, {false, QVariant()});
46+
const auto info = timerHash.value(id, {false, QVariant()});
4747
if(!info.first)
48-
this->cancelSchedule(id);
48+
cancelSchedule(id);
4949
emit scheduleTriggered(info.second);
5050
event->accept();
5151
}

src/autoupdatercore/updater.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,55 @@ Updater::Updater(QObject *parent) :
1717

1818
Updater::Updater(const QString &maintenanceToolPath, QObject *parent) :
1919
QObject(parent),
20-
d_ptr(new UpdaterPrivate(this))
20+
d(new UpdaterPrivate(this))
2121
{
22-
Q_D(Updater);
2322
d->toolPath = UpdaterPrivate::toSystemExe(maintenanceToolPath);
2423
}
2524

2625
Updater::~Updater() {}
2726

2827
bool Updater::exitedNormally() const
2928
{
30-
const Q_D(Updater);
3129
return d->normalExit;
3230
}
3331

3432
int Updater::errorCode() const
3533
{
36-
const Q_D(Updater);
3734
return d->lastErrorCode;
3835
}
3936

4037
QByteArray Updater::errorLog() const
4138
{
42-
const Q_D(Updater);
4339
return d->lastErrorLog;
4440
}
4541

4642
bool Updater::willRunOnExit() const
4743
{
48-
const Q_D(Updater);
4944
return d->runOnExit;
5045
}
5146

5247
QString Updater::maintenanceToolPath() const
5348
{
54-
const Q_D(Updater);
5549
return d->toolPath;
5650
}
5751

5852
bool Updater::isRunning() const
5953
{
60-
const Q_D(Updater);
6154
return d->running;
6255
}
6356

6457
QList<Updater::UpdateInfo> Updater::updateInfo() const
6558
{
66-
const Q_D(Updater);
6759
return d->updateInfos;
6860
}
6961

7062
bool Updater::checkForUpdates()
7163
{
72-
Q_D(Updater);
7364
return d->startUpdateCheck();
7465
}
7566

7667
void Updater::abortUpdateCheck(int maxDelay, bool async)
7768
{
78-
Q_D(Updater);
7969
d->stopUpdateCheck(maxDelay, async);
8070
}
8171

@@ -85,33 +75,28 @@ int Updater::scheduleUpdate(int delaySeconds, bool repeated)
8575
qCWarning(logQtAutoUpdater) << "delaySeconds to big to be converted to msecs";
8676
return 0;
8777
}
88-
Q_D(Updater);
8978
return d->scheduler->startSchedule(delaySeconds * 1000, repeated);
9079
}
9180

9281
int Updater::scheduleUpdate(const QDateTime &when)
9382
{
94-
Q_D(Updater);
9583
return d->scheduler->startSchedule(when);
9684
}
9785

9886
void Updater::cancelScheduledUpdate(int taskId)
9987
{
100-
Q_D(Updater);
10188
d->scheduler->cancelSchedule(taskId);
10289
}
10390

10491
void Updater::runUpdaterOnExit(const QStringList &arguments, AdminAuthoriser *authoriser)
10592
{
106-
Q_D(Updater);
10793
d->runOnExit = true;
10894
d->runArguments = arguments;
10995
d->adminAuth.reset(authoriser);
11096
}
11197

11298
void Updater::cancelExitRun()
11399
{
114-
Q_D(Updater);
115100
d->runOnExit = false;
116101
d->adminAuth.reset();
117102
}

src/autoupdatercore/updater.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Q_SLOTS:
8686

8787
//! Runs the maintenancetool as updater on exit, using the given admin authorisation
8888
inline void runUpdaterOnExit(AdminAuthoriser *authoriser = nullptr) {
89-
this->runUpdaterOnExit({QStringLiteral("--updater")}, authoriser);
89+
runUpdaterOnExit({QStringLiteral("--updater")}, authoriser);
9090
}
9191
//! Runs the maintenancetool as updater on exit, using the given arguments and admin authorisation
9292
void runUpdaterOnExit(const QStringList &arguments, AdminAuthoriser *authoriser = nullptr);
@@ -103,8 +103,7 @@ public Q_SLOTS:
103103
void updateInfoChanged(QList<QtAutoUpdater::Updater::UpdateInfo> updateInfo);
104104

105105
private:
106-
QScopedPointer<UpdaterPrivate> d_ptr;
107-
Q_DECLARE_PRIVATE(Updater)
106+
QScopedPointer<UpdaterPrivate> d;
108107
};
109108

110109
}

src/autoupdatercore/updater_p.cpp

Lines changed: 64 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Q_LOGGING_CATEGORY(logQtAutoUpdater, "QtAutoUpdater")
1313

1414
UpdaterPrivate::UpdaterPrivate(Updater *q_ptr) :
1515
QObject(nullptr),
16-
q_ptr(q_ptr),
16+
q(q_ptr),
1717
toolPath(),
1818
updateInfos(),
1919
normalExit(true),
@@ -29,19 +29,19 @@ UpdaterPrivate::UpdaterPrivate(Updater *q_ptr) :
2929
connect(qApp, &QCoreApplication::aboutToQuit,
3030
this, &UpdaterPrivate::appAboutToExit,
3131
Qt::DirectConnection);
32-
connect(this->scheduler, &SimpleScheduler::scheduleTriggered,
32+
connect(scheduler, &SimpleScheduler::scheduleTriggered,
3333
this, &UpdaterPrivate::startUpdateCheck);
3434
}
3535

3636
UpdaterPrivate::~UpdaterPrivate()
3737
{
38-
if(this->runOnExit)
38+
if(runOnExit)
3939
qCWarning(logQtAutoUpdater) << "Updater destroyed with run on exit active before the application quit";
4040

41-
if(this->mainProcess &&
42-
this->mainProcess->state() != QProcess::NotRunning) {
43-
this->mainProcess->kill();
44-
this->mainProcess->waitForFinished(1000);
41+
if(mainProcess &&
42+
mainProcess->state() != QProcess::NotRunning) {
43+
mainProcess->kill();
44+
mainProcess->waitForFinished(1000);
4545
}
4646
}
4747

@@ -63,50 +63,49 @@ const QString UpdaterPrivate::toSystemExe(QString basePath)
6363

6464
bool UpdaterPrivate::startUpdateCheck()
6565
{
66-
if(this->running)
66+
if(running)
6767
return false;
6868
else {
69-
Q_Q(Updater);
70-
this->updateInfos.clear();
71-
this->normalExit = true;
72-
this->lastErrorCode = EXIT_SUCCESS;
73-
this->lastErrorLog.clear();
74-
75-
QFileInfo toolInfo(QCoreApplication::applicationDirPath(), this->toolPath);
76-
this->mainProcess = new QProcess(this);
77-
this->mainProcess->setProgram(toolInfo.absoluteFilePath());
78-
this->mainProcess->setArguments({QStringLiteral("--checkupdates")});
79-
80-
connect(this->mainProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
69+
updateInfos.clear();
70+
normalExit = true;
71+
lastErrorCode = EXIT_SUCCESS;
72+
lastErrorLog.clear();
73+
74+
QFileInfo toolInfo(QCoreApplication::applicationDirPath(), toolPath);
75+
mainProcess = new QProcess(this);
76+
mainProcess->setProgram(toolInfo.absoluteFilePath());
77+
mainProcess->setArguments({QStringLiteral("--checkupdates")});
78+
79+
connect(mainProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
8180
this, &UpdaterPrivate::updaterReady, Qt::QueuedConnection);
82-
connect(this->mainProcess, &QProcess::errorOccurred,
81+
connect(mainProcess, &QProcess::errorOccurred,
8382
this, &UpdaterPrivate::updaterError, Qt::QueuedConnection);
8483

85-
this->mainProcess->start(QIODevice::ReadOnly);
86-
this->running = true;
84+
mainProcess->start(QIODevice::ReadOnly);
85+
running = true;
8786

88-
emit q->updateInfoChanged(this->updateInfos);
87+
emit q->updateInfoChanged(updateInfos);
8988
emit q->runningChanged(true);
9089
return true;
9190
}
9291
}
9392

9493
void UpdaterPrivate::stopUpdateCheck(int delay, bool async)
9594
{
96-
if(this->mainProcess &&
97-
this->mainProcess->state() != QProcess::NotRunning) {
95+
if(mainProcess &&
96+
mainProcess->state() != QProcess::NotRunning) {
9897
if(delay > 0) {
99-
this->mainProcess->terminate();
98+
mainProcess->terminate();
10099
if(async){
101100
QTimer::singleShot(delay, this, [this](){
102-
this->stopUpdateCheck(0, false);
101+
stopUpdateCheck(0, false);
103102
});
104103
} else {
105-
if(!this->mainProcess->waitForFinished(delay))
106-
this->mainProcess->kill();
104+
if(!mainProcess->waitForFinished(delay))
105+
mainProcess->kill();
107106
}
108107
} else
109-
this->mainProcess->kill();
108+
mainProcess->kill();
110109
}
111110
}
112111

@@ -154,78 +153,74 @@ QList<Updater::UpdateInfo> UpdaterPrivate::parseResult(const QByteArray &output)
154153

155154
void UpdaterPrivate::updaterReady(int exitCode, QProcess::ExitStatus exitStatus)
156155
{
157-
if(this->mainProcess) {
156+
if(mainProcess) {
158157
if(exitStatus == QProcess::NormalExit) {
159-
this->normalExit = true;
160-
this->lastErrorCode = exitCode;
161-
this->lastErrorLog = this->mainProcess->readAllStandardError();
162-
const auto updateOut = this->mainProcess->readAllStandardOutput();
163-
this->mainProcess->deleteLater();
164-
this->mainProcess = nullptr;
165-
166-
Q_Q(Updater);
167-
if(this->lastErrorCode != EXIT_SUCCESS) {
168-
this->running = false;
158+
normalExit = true;
159+
lastErrorCode = exitCode;
160+
lastErrorLog = mainProcess->readAllStandardError();
161+
const auto updateOut = mainProcess->readAllStandardOutput();
162+
mainProcess->deleteLater();
163+
mainProcess = nullptr;
164+
165+
if(lastErrorCode != EXIT_SUCCESS) {
166+
running = false;
169167
emit q->runningChanged(false);
170168
emit q->checkUpdatesDone(false, true);
171169
} else {
172-
this->running = false;
170+
running = false;
173171
emit q->runningChanged(false);
174172
try {
175-
this->updateInfos = this->parseResult(updateOut);
176-
if(!this->updateInfos.isEmpty())
177-
emit q->updateInfoChanged(this->updateInfos);
178-
emit q->checkUpdatesDone(!this->updateInfos.isEmpty(), false);
173+
updateInfos = parseResult(updateOut);
174+
if(!updateInfos.isEmpty())
175+
emit q->updateInfoChanged(updateInfos);
176+
emit q->checkUpdatesDone(!updateInfos.isEmpty(), false);
179177
} catch (NoUpdatesXmlException &) {
180178
emit q->checkUpdatesDone(false, false);
181179
} catch (InvalidXmlException &exc) {
182-
this->lastErrorLog = exc.what();
180+
lastErrorLog = exc.what();
183181
emit q->checkUpdatesDone(false, true);
184182
}
185183
}
186184
} else
187-
this->updaterError(QProcess::Crashed);
185+
updaterError(QProcess::Crashed);
188186
}
189187
}
190188

191189
void UpdaterPrivate::updaterError(QProcess::ProcessError error)
192190
{
193-
if(this->mainProcess) {
194-
Q_Q(Updater);
195-
this->normalExit = false;
196-
this->lastErrorCode = error;
197-
this->lastErrorLog = this->mainProcess->errorString().toUtf8();
198-
this->mainProcess->deleteLater();
199-
this->mainProcess = nullptr;
200-
201-
this->running = false;
191+
if(mainProcess) {
192+
normalExit = false;
193+
lastErrorCode = error;
194+
lastErrorLog = mainProcess->errorString().toUtf8();
195+
mainProcess->deleteLater();
196+
mainProcess = nullptr;
197+
198+
running = false;
202199
emit q->runningChanged(false);
203200
emit q->checkUpdatesDone(false, true);
204201
}
205202
}
206203

207204
void UpdaterPrivate::appAboutToExit()
208205
{
209-
if(this->runOnExit) {
210-
QFileInfo toolInfo(QCoreApplication::applicationDirPath(), this->toolPath);
206+
if(runOnExit) {
207+
QFileInfo toolInfo(QCoreApplication::applicationDirPath(), toolPath);
211208
auto ok = false;
212-
if(this->adminAuth && !this->adminAuth->hasAdminRights()) {
213-
ok = this->adminAuth->executeAsAdmin(toolInfo.absoluteFilePath(),
214-
this->runArguments);
215-
216-
} else {
209+
if(adminAuth && !adminAuth->hasAdminRights())
210+
ok = adminAuth->executeAsAdmin(toolInfo.absoluteFilePath(), runArguments);
211+
else {
217212
ok = QProcess::startDetached(toolInfo.absoluteFilePath(),
218-
this->runArguments,
213+
runArguments,
219214
toolInfo.absolutePath());
220215
}
221216

222217
if(!ok) {
223218
qCWarning(logQtAutoUpdater) << "Unable to start" << toolInfo.absoluteFilePath()
224-
<< "with arguments" << this->runArguments
225-
<< "as" << (this->adminAuth ? "admin/root" : "current user");
219+
<< "with arguments" << runArguments
220+
<< "as" << (adminAuth ? "admin/root" : "current user");
226221
}
227222

228-
this->runOnExit = false;//prevent warning
223+
runOnExit = false;//prevent warning
229224
}
230225
}
231226

src/autoupdatercore/updater_p.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class Q_AUTOUPDATERCORE_EXPORT UpdaterPrivate : public QObject
3333
QException *clone() const override;
3434
};
3535

36-
Updater *q_ptr;
37-
Q_DECLARE_PUBLIC(Updater)
36+
Updater *q;
3837

3938
QString toolPath;
4039
QList<Updater::UpdateInfo> updateInfos;

0 commit comments

Comments
 (0)