update// implemented dump method to each datastoretype

This commit is contained in:
Strider
2020-05-17 14:12:27 +02:00
parent 4f584ac86e
commit d4bf7a83c8
14 changed files with 183 additions and 1 deletions

View File

@@ -32,6 +32,17 @@ ChatItem ChatDataStore::getData(QString key)
QString ChatDataStore::dump()
{
json chats;
chats["count"] = this->data.size();
json j = {};
for (auto &c: this->data)
{
j.push_back(c.second.toJson());
}
chats["chatitems"] = j;
std::string dump = chats.dump(4);
qDebug() << dump.c_str();
return "";
}

View File

@@ -0,0 +1,53 @@
// Copyright 2019-2020 The Hush developers
// GPLv3
#include "ContactDataStore.h"
#include <string>
ContactDataStore* ContactDataStore::getInstance()
{
if(!ContactDataStore::instanced)
{
ContactDataStore::instanced = true;
ContactDataStore::instance = new ContactDataStore();
}
return ContactDataStore::instance;
}
void ContactDataStore::clear()
{
this->data.clear();
}
void ContactDataStore::setData(QString key, ContactItem value)
{
this->data[key] = value;
}
ContactItem ContactDataStore::getData(QString key)
{
return this->data[key];
}
QString ContactDataStore::dump()
{
json contacts;
contacts["count"] = this->data.size();
json j = {};
for (auto &c: this->data)
{
qDebug() << c.second.toQTString();
c.second.toJson();
j.push_back(c.second.toJson());
}
contacts["contacts"] = j;
std::string dump = contacts.dump(4);
qDebug() << dump.c_str();
return "";
}
ContactDataStore* ContactDataStore::instance = nullptr;
bool ContactDataStore::instanced = false;

View File

@@ -0,0 +1,34 @@
#ifndef CONTACTDATASTORE_H
#define CONTACTDATASTORE_H
#include "../Model/ContactItem.h"
#include <string>
using json = nlohmann::json;
class ContactDataStore
{
private:
static bool instanced;
static ContactDataStore* instance;
std::map<QString, ContactItem> data;
ContactDataStore()
{
}
public:
static ContactDataStore* getInstance();
void clear();
void setData(QString key, ContactItem value);
ContactItem getData(QString key);
QString dump();
~ContactDataStore()
{
ContactDataStore::instanced = false;
ContactDataStore::instance = nullptr;
}
};
#endif

View File

@@ -8,4 +8,9 @@ SietchDataStore* DataStore::getSietchDataStore()
ChatDataStore* DataStore::getChatDataStore()
{
return ChatDataStore::getInstance();
}
ContactDataStore* DataStore::getContactDataStore()
{
return ContactDataStore::getInstance();
}

View File

@@ -3,12 +3,14 @@
#include "SietchDataStore.h"
#include "ChatDataStore.h"
#include "ContactDataStore.h"
class DataStore
{
public:
static SietchDataStore* getSietchDataStore();
static ChatDataStore* getChatDataStore();
static ContactDataStore* getContactDataStore();
};
#endif