BluezQt

initobexmanagerjob.cpp
1 /*
2  * BluezQt - Asynchronous Bluez wrapper library
3  *
4  * SPDX-FileCopyrightText: 2014 David Rosca <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7  */
8 
9 #include "initobexmanagerjob.h"
10 #include "debug.h"
11 #include "obexmanager.h"
12 #include "obexmanager_p.h"
13 
14 namespace BluezQt
15 {
16 class InitObexManagerJobPrivate : public QObject
17 {
18 public:
19  explicit InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager);
20 
21  void doStart();
22  void initError(const QString &errorText);
23  void initFinished();
24 
25  InitObexManagerJob *q;
26  ObexManager *m_manager;
27 };
28 
29 InitObexManagerJobPrivate::InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager)
30  : QObject(q)
31  , q(q)
32  , m_manager(manager)
33 {
34 }
35 
36 void InitObexManagerJobPrivate::doStart()
37 {
38  if (m_manager->d->m_initialized) {
39  qCWarning(BLUEZQT) << "InitObexManagerJob: ObexManager already initialized!";
40  q->emitResult();
41  return;
42  }
43 
44  connect(m_manager->d, &ObexManagerPrivate::initError, this, &InitObexManagerJobPrivate::initError);
45  connect(m_manager->d, &ObexManagerPrivate::initFinished, this, &InitObexManagerJobPrivate::initFinished);
46 
47  m_manager->d->init();
48 }
49 
50 void InitObexManagerJobPrivate::initError(const QString &errorText)
51 {
52  qCWarning(BLUEZQT) << "InitObexManagerJob Error:" << errorText;
53 
55  q->setErrorText(errorText);
56  q->emitResult();
57 }
58 
59 void InitObexManagerJobPrivate::initFinished()
60 {
61  q->emitResult();
62 }
63 
64 InitObexManagerJob::InitObexManagerJob(ObexManager *manager)
65  : Job(manager)
66  , d(new InitObexManagerJobPrivate(this, manager))
67 {
68 }
69 
71 {
72  if (isRunning()) {
73  qCWarning(BLUEZQT) << "InitObexManagerJob Error: Job was deleted before finished!";
74 
76  setErrorText(QStringLiteral("Job was deleted before finished."));
77  emitResult();
78  }
79  delete d;
80 }
81 
82 ObexManager *InitObexManagerJob::manager() const
83 {
84  return d->m_manager;
85 }
86 
87 void InitObexManagerJob::doStart()
88 {
89  d->doStart();
90 }
91 
92 void InitObexManagerJob::doEmitResult()
93 {
94  Q_EMIT result(this);
95 }
96 
97 } // namespace BluezQt
bool isRunning() const
Returns whether the job is currently running.
Definition: job.cpp:83
~InitObexManagerJob() override
Destroys an InitObexManagerJob object.
void setErrorText(const QString &errorText)
Sets the error text.
Definition: job.cpp:98
Q_EMITQ_EMIT
@ UserDefinedError
Subclasses should define error codes starting at this value.
Definition: job.h:74
void setError(int errorCode)
Sets the error code.
Definition: job.cpp:93
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition: job.cpp:55
void result(InitObexManagerJob *job)
Indicates that the job have finished.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:19:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.