update// implemented dump method to each datastoretype
This commit is contained in:
@@ -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 "";
|
||||
}
|
||||
|
||||
|
||||
53
src/DataStore/ContactDataStore.cpp
Normal file
53
src/DataStore/ContactDataStore.cpp
Normal 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;
|
||||
34
src/DataStore/ContactDataStore.h
Normal file
34
src/DataStore/ContactDataStore.h
Normal 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
|
||||
@@ -8,4 +8,9 @@ SietchDataStore* DataStore::getSietchDataStore()
|
||||
ChatDataStore* DataStore::getChatDataStore()
|
||||
{
|
||||
return ChatDataStore::getInstance();
|
||||
}
|
||||
|
||||
ContactDataStore* DataStore::getContactDataStore()
|
||||
{
|
||||
return ContactDataStore::getInstance();
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user