Verified Commit eadd942a authored by Linus Jahn's avatar Linus Jahn Committed by Jonah Brüchert

{Roster,Message}Db: Add static instance getters

parent 3179d34e
......@@ -40,13 +40,28 @@
#include <QSqlQuery>
#include <QSqlRecord>
MessageDb *MessageDb::s_instance = nullptr;
MessageDb::MessageDb(QObject *parent)
: QObject(parent)
{
Q_ASSERT(!MessageDb::s_instance);
s_instance = this;
connect(this, &MessageDb::fetchMessagesRequested,
this, &MessageDb::fetchMessages);
}
MessageDb::~MessageDb()
{
s_instance = nullptr;
}
MessageDb *MessageDb::instance()
{
return s_instance;
}
void MessageDb::parseMessagesFromQuery(QSqlQuery &query, QVector<Message> &msgs)
{
// get indexes of attributes
......
......@@ -51,6 +51,9 @@ class MessageDb : public QObject
public:
explicit MessageDb(QObject *parent = nullptr);
~MessageDb();
static MessageDb *instance();
/**
* Parses a list of messages from a SELECT query.
......@@ -133,6 +136,9 @@ public slots:
* Marks a message as delivered using an UPDATE query.
*/
void setMessageAsDelivered(const QString &msgId);
private:
static MessageDb *s_instance;
};
#endif // MESSAGEDB_H
......@@ -40,13 +40,28 @@
#include <QSqlQuery>
#include <QSqlRecord>
RosterDb *RosterDb::s_instance = nullptr;
RosterDb::RosterDb(Database *db, QObject *parent)
: QObject(parent),
m_db(db)
{
Q_ASSERT(!RosterDb::s_instance);
s_instance = this;
connect(this, &RosterDb::fetchItemsRequested, this, &RosterDb::fetchItems);
}
RosterDb::~RosterDb()
{
s_instance = nullptr;
}
RosterDb *RosterDb::instance()
{
return s_instance;
}
void RosterDb::parseItemsFromQuery(QSqlQuery &query, QVector<RosterItem> &items)
{
QSqlRecord rec = query.record();
......
......@@ -44,8 +44,12 @@ class Database;
class RosterDb : public QObject
{
Q_OBJECT
public:
RosterDb(Database *db, QObject *parent = nullptr);
~RosterDb();
static RosterDb *instance();
static void parseItemsFromQuery(QSqlQuery &query, QVector<RosterItem> &items);
......@@ -77,6 +81,8 @@ private slots:
private:
Database *m_db;
static RosterDb *s_instance;
};
#endif // ROSTERDB_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