Commit 45173d67 authored by Luca Giambonini's avatar Luca Giambonini

introduced a new function "statusToString" to retrieve the status as QString...

introduced a new function "statusToString" to retrieve the status as QString to improve the debug output
source: https://srikanthsombhatla.wordpress.com/2010/08/13/convert-enum-to-qstring/
parent 22db15b0
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
#include <QDBusMetaType> #include <QDBusMetaType>
#include <QMetaEnum>
#include <memory> #include <memory>
...@@ -214,12 +215,10 @@ void Backend::setStatus(Backend::Status s, QObject * cO, const char * cS) ...@@ -214,12 +215,10 @@ void Backend::setStatus(Backend::Status s, QObject * cO, const char * cS)
{ {
Q_D(Backend); Q_D(Backend);
qDebug() << "CALLED WITH" << s << d->status; akabeiDebug() << "Current status: " << Akabei::Backend::statusToString(d->status) << " next status: " << Akabei::Backend::statusToString(s);
if (s == d->status) if (s == d->status)
return; return;
qDebug() << "Now let's call this";
if (s == Backend::StatusOnTransaction && d->status != Akabei::Backend::StatusWaitingForLock) { if (s == Backend::StatusOnTransaction && d->status != Akabei::Backend::StatusWaitingForLock) {
d->callbackObject = cO; d->callbackObject = cO;
d->callbackSlot = cS; d->callbackSlot = cS;
...@@ -311,7 +310,7 @@ void Backend::setStatus(Backend::Status s, QObject * cO, const char * cS) ...@@ -311,7 +310,7 @@ void Backend::setStatus(Backend::Status s, QObject * cO, const char * cS)
} }
d->status = s; d->status = s;
qDebug() << "Status changed to" << s; qDebug() << "Status changed to " << Akabei::Backend::statusToString(s);
emit statusChanged(d->status); emit statusChanged(d->status);
} }
...@@ -593,6 +592,13 @@ Backend::Status Backend::status() const ...@@ -593,6 +592,13 @@ Backend::Status Backend::status() const
return d->status; return d->status;
} }
QString Backend::statusToString(Backend::Status status)
{
int index = metaObject()->indexOfEnumerator("Status");
QMetaEnum metaEnum = metaObject()->enumerator(index);
return metaEnum.valueToKey(status);
}
QUuid Backend::groups() QUuid Backend::groups()
{ {
QString sql = Queries::allGroups(); QString sql = Queries::allGroups();
......
...@@ -64,6 +64,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject ...@@ -64,6 +64,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(Backend) Q_DISABLE_COPY(Backend)
Q_DECLARE_PRIVATE(Backend) Q_DECLARE_PRIVATE(Backend)
Q_ENUMS(Status)
public: public:
/** /**
* \enum Status * \enum Status
...@@ -77,6 +78,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject ...@@ -77,6 +78,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
StatusOnTransaction = 4, StatusOnTransaction = 4,
StatusBroken = 5 StatusBroken = 5
}; };
/** /**
* @returns the backend singleton * @returns the backend singleton
*/ */
...@@ -103,6 +105,11 @@ class AKABEICORESHARED_EXPORT Backend : public QObject ...@@ -103,6 +105,11 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
*/ */
Status status() const; Status status() const;
/**
* @returns the status of the backend in the form of string
*/
QString statusToString(Backend::Status aElement);
/** /**
* @returns the local database, which is the database which contains all the installed packages. * @returns the local database, which is the database which contains all the installed packages.
* To check whether a package is installed on the system, one needs to query this database whether * To check whether a package is installed on the system, one needs to query this database whether
......
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