update// implemented dump method to each datastoretype
This commit is contained in:
35
.gdb_history
Normal file
35
.gdb_history
Normal file
@@ -0,0 +1,35 @@
|
||||
b ContactDataStore::dump()
|
||||
r
|
||||
n
|
||||
q
|
||||
b ContactDataStore::dump()
|
||||
r
|
||||
n
|
||||
c
|
||||
./build.sh
|
||||
$(./build.sh)
|
||||
$(./build.sh)
|
||||
q
|
||||
r
|
||||
q
|
||||
r
|
||||
b ContactDataStore::dump()
|
||||
r
|
||||
n
|
||||
b ContactItem::toJson()
|
||||
r
|
||||
c
|
||||
n
|
||||
q
|
||||
b ContactItem::toJson()
|
||||
r
|
||||
n
|
||||
c
|
||||
c
|
||||
c
|
||||
c
|
||||
c
|
||||
c
|
||||
c
|
||||
c
|
||||
q
|
||||
2
peda-session-SilentDragonLite.txt
Normal file
2
peda-session-SilentDragonLite.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
break ContactItem::toJson()
|
||||
|
||||
@@ -75,6 +75,7 @@ SOURCES += \
|
||||
src/DataStore/DataStore.cpp \
|
||||
src/DataStore/ChatDataStore.cpp \
|
||||
src/DataStore/SietchDataStore.cpp \
|
||||
src/DataStore/ContactDataStore.cpp \
|
||||
src/Model/ChatItem.cpp \
|
||||
src/Model/ContactRequestChatItem.cpp \
|
||||
src/Model/ContactItem.cpp \
|
||||
|
||||
@@ -12,7 +12,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view)
|
||||
// ui->lcdNumber->setStyleSheet("background-color: red");
|
||||
// ui->lcdNumber->setPalette(Qt::red);
|
||||
// ui->lcdNumber->display("1");
|
||||
|
||||
DataStore::getChatDataStore()->dump(); // test to see if the chat items in datastore are correctly dumped to json
|
||||
for (auto &p : AddressBook::getInstance()->getAllAddressLabels())
|
||||
{
|
||||
for (auto &c : DataStore::getChatDataStore()->getAllMemos())
|
||||
|
||||
@@ -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
|
||||
@@ -150,6 +150,22 @@ QString ChatItem::toChatLine()
|
||||
return line;
|
||||
}
|
||||
|
||||
json ChatItem::toJson()
|
||||
{
|
||||
json j;
|
||||
j["_timestamp"] = _timestamp;
|
||||
j["_address"] = _address.toStdString();
|
||||
j["_contact"] = _contact.toStdString();
|
||||
j["_memo"] = _memo.toStdString();
|
||||
j["_requestZaddr"] = _requestZaddr.toStdString();
|
||||
j["_type"] = _type.toStdString();
|
||||
j["_cid"] = _cid.toStdString();
|
||||
j["_txid"] = _txid.toStdString();
|
||||
j["_confirmations"] = _confirmations;
|
||||
j["_outgoing"] = _outgoing;
|
||||
return j;
|
||||
}
|
||||
|
||||
ChatItem::~ChatItem()
|
||||
{
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define CHATITEM_H
|
||||
|
||||
#include <QString>
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ChatItem
|
||||
{
|
||||
@@ -45,6 +46,7 @@ class ChatItem
|
||||
void setConfirmations(int confirmations);
|
||||
void toggleOutgo();
|
||||
QString toChatLine();
|
||||
json toJson();
|
||||
~ChatItem();
|
||||
};
|
||||
|
||||
|
||||
@@ -63,4 +63,15 @@ void ContactItem::setAvatar(QString avatar)
|
||||
QString ContactItem::toQTString()
|
||||
{
|
||||
return _name + "|" + _partnerAddress + "|" + _myAddress + "|" + _cid + "|" + _avatar;
|
||||
}
|
||||
|
||||
json ContactItem::toJson()
|
||||
{
|
||||
json j;
|
||||
j["_myAddress"] = _myAddress.toStdString();
|
||||
j["_partnerAddress"] = _partnerAddress.toStdString();
|
||||
j["_name"] = _name.toStdString();
|
||||
j["_cid"] = _cid.toStdString();
|
||||
j["_avatar"] = _avatar.toStdString();
|
||||
return j;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ContactItem
|
||||
{
|
||||
@@ -27,6 +28,7 @@ public:
|
||||
void setcid(QString cid);
|
||||
void setAvatar(QString avatar);
|
||||
QString toQTString();
|
||||
json toJson();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "settings.h"
|
||||
#include "mainwindow.h"
|
||||
#include "controller.h"
|
||||
#include "DataStore/DataStore.h"
|
||||
#include "FileSystem/FileSystem.h"
|
||||
|
||||
|
||||
@@ -398,6 +399,13 @@ void AddressBook::readFromStorage()
|
||||
}
|
||||
}*/
|
||||
allLabels = FileSystem::getInstance()->readContacts(AddressBook::writeableFile());
|
||||
|
||||
// test to see if the contact items in datastore are correctly dumped to json
|
||||
for(ContactItem item: allLabels)
|
||||
{
|
||||
DataStore::getContactDataStore()->setData(item.getCid(), item);
|
||||
}
|
||||
DataStore::getContactDataStore()->dump();
|
||||
}
|
||||
|
||||
void AddressBook::writeToStorage()
|
||||
|
||||
Reference in New Issue
Block a user