sync to chat
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
// Copyright 2019-2020 The Hush developers
|
||||
// GPLv3
|
||||
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include "../Crypto/passwd.h"
|
||||
#include "addressbook.h"
|
||||
|
||||
FileSystem::FileSystem()
|
||||
{
|
||||
@@ -23,9 +19,9 @@ FileSystem* FileSystem::getInstance()
|
||||
return FileSystem::instance;
|
||||
}
|
||||
|
||||
QList<ContactItem> FileSystem::readContacts(QString file)
|
||||
/*QList<ContactItem> FileSystem::readContacts(QString file)
|
||||
{
|
||||
return this->readContactsOldFormat(file); //will be called if addresses are in the old dat-format
|
||||
//return this->readContactsOldFormat(file); //will be called if addresses are in the old dat-format
|
||||
|
||||
QFile _file(file);
|
||||
if (_file.exists())
|
||||
@@ -83,7 +79,7 @@ void FileSystem::writeContactsOldFormat(QString file, QList<ContactItem> contact
|
||||
c.push_back(item.getAvatar());
|
||||
_contacts.push_back(c);
|
||||
}
|
||||
out << QString("v2") << _contacts;
|
||||
out << QString("v0") << _contacts;
|
||||
_file.close();
|
||||
}
|
||||
|
||||
@@ -96,68 +92,20 @@ QList<ContactItem> FileSystem::readContactsOldFormat(QString file)
|
||||
contacts.clear();
|
||||
_file.open(QIODevice::ReadOnly);
|
||||
QDataStream in(&_file); // read the data serialized from the file
|
||||
if(in.status() == QDataStream::ReadCorruptData)
|
||||
QString version;
|
||||
in >> version;
|
||||
qDebug() << "Read " << version << " Hush contacts from disk...";
|
||||
qDebug() << "Detected old addressbook format";
|
||||
QList<QList<QString>> stuff;
|
||||
in >> stuff;
|
||||
//qDebug() << "Stuff: " << stuff;
|
||||
for (int i=0; i < stuff.size(); i++)
|
||||
{
|
||||
qDebug() << "Error reading contacts! ---> Your hush contacts from disk maybe corrupted";
|
||||
QFile::rename(file, file + QString(".corrupted"));
|
||||
QMessageBox::critical(
|
||||
nullptr,
|
||||
QObject::tr("Error reading contacts!"),
|
||||
QObject::tr("Your hush contacts from disk maybe corrupted"),
|
||||
QMessageBox::Ok
|
||||
);
|
||||
ContactItem contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]);
|
||||
contacts.push_back(contact);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QString version;
|
||||
in >> version;
|
||||
if(version == "v1")
|
||||
{
|
||||
qDebug() << "Detected old addressbook format";
|
||||
// Convert old addressbook format v1 to v2
|
||||
QList<QPair<QString,QString>> stuff;
|
||||
in >> stuff;
|
||||
qDebug() << "Stuff: " << stuff;
|
||||
for (int i=0; i < stuff.size(); i++)
|
||||
{
|
||||
ContactItem contact = ContactItem(stuff[i].first, stuff[i].second);
|
||||
contacts.push_back(contact);
|
||||
qDebug() << "contact=" << contact.toQTString();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Read " << version << " Hush contacts from disk...";
|
||||
QList<QList<QString>> stuff;
|
||||
in >> stuff;
|
||||
qDebug() << "Dataarray size: " << stuff.size();
|
||||
if(stuff.size() == 0)
|
||||
return contacts;
|
||||
|
||||
for (int i= 0; i < stuff.size(); i++)
|
||||
{
|
||||
qDebug() << stuff[i].size();
|
||||
ContactItem contact;
|
||||
if(stuff[i].size() == 4)
|
||||
{
|
||||
contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]);
|
||||
}
|
||||
|
||||
qDebug() << contact.toQTString();
|
||||
contacts.push_back(contact);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
qDebug() << "Hush contacts readed from disk...";
|
||||
}
|
||||
|
||||
|
||||
_file.close();
|
||||
}
|
||||
else
|
||||
@@ -173,7 +121,7 @@ FileSystem::~FileSystem()
|
||||
this->instance = nullptr;
|
||||
this->instanced = false;
|
||||
delete this->instance;
|
||||
}
|
||||
}*/
|
||||
|
||||
FileSystem *FileSystem::instance = nullptr;
|
||||
bool FileSystem::instanced = false;
|
||||
@@ -11,11 +11,11 @@ using json = nlohmann::json;
|
||||
class ContactItem
|
||||
{
|
||||
private:
|
||||
QString _myAddress = "";
|
||||
QString _partnerAddress = "";
|
||||
QString _name = "";
|
||||
QString _cid = "";
|
||||
QString _avatar = ":/icons/res/sdlogo.png";
|
||||
QString _myAddress;
|
||||
QString _partnerAddress;
|
||||
QString _name;
|
||||
QString _cid;
|
||||
QString _avatar;
|
||||
|
||||
public:
|
||||
ContactItem();
|
||||
|
||||
@@ -39,9 +39,7 @@ void AddressBookModel::loadData()
|
||||
parent->horizontalHeader()->restoreState(
|
||||
QSettings().value(
|
||||
"addresstablegeometry"
|
||||
).toByteArray()
|
||||
|
||||
|
||||
).toByteArray()
|
||||
);
|
||||
|
||||
}
|
||||
@@ -241,9 +239,14 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target)
|
||||
return;
|
||||
|
||||
|
||||
rpc->refresh(true);
|
||||
// rpc->refresh(true);
|
||||
model.updateUi();
|
||||
|
||||
rpc->refreshContacts(
|
||||
parent->ui->listContactWidget
|
||||
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
// AddressBook::getInstance()->addAddressLabel(newLabel, ab.addr->text(), cid);
|
||||
@@ -380,7 +383,7 @@ AddressBook::AddressBook()
|
||||
|
||||
void AddressBook::readFromStorage()
|
||||
{
|
||||
/*QFile file(AddressBook::writeableFile());
|
||||
QFile file(AddressBook::writeableFile());
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
@@ -394,40 +397,44 @@ void AddressBook::readFromStorage()
|
||||
QList<QList<QString>> stuff;
|
||||
in >> stuff;
|
||||
//qDebug() << "Stuff: " << stuff;
|
||||
|
||||
for (int i=0; i < stuff.size(); i++)
|
||||
{
|
||||
//qDebug() << "0:" << stuff[i][0];
|
||||
//qDebug() << "0:" << stuff[i][0];
|
||||
//qDebug() << "1:" << stuff[i][1];
|
||||
//qDebug() << "2:" << stuff[i][2];
|
||||
ContactItem contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]);
|
||||
//qDebug() << "contact=" << contact.toQTString();
|
||||
allLabels.push_back(contact);
|
||||
}
|
||||
|
||||
{
|
||||
qDebug() << "Read " << version << " Hush contacts from disk...";
|
||||
|
||||
|
||||
qDebug() << "Read " << version << " Hush contacts from disk...";
|
||||
file.close();
|
||||
}
|
||||
}else{
|
||||
{
|
||||
qDebug() << "No Hush contacts found on disk!";
|
||||
}
|
||||
}*/
|
||||
allLabels = FileSystem::getInstance()->readContacts(AddressBook::writeableFile());
|
||||
else
|
||||
{
|
||||
qDebug() << "No Hush contacts found on disk!";
|
||||
}
|
||||
|
||||
// test to see if the contact items in datastore are correctly dumped to json
|
||||
DataStore::getContactDataStore()->dump();
|
||||
// Special.
|
||||
// Add the default silentdragon donation address if it isn't already present
|
||||
// QList<QString> allAddresses;
|
||||
// std::transform(allLabels.begin(), allLabels.end(),
|
||||
// std::back_inserter(allAddresses), [=] (auto i) { return i.getPartnerAddress(); });
|
||||
// if (!allAddresses.contains(Settings::getDonationAddr(true))) {
|
||||
// allLabels.append(QPair<QString, QString>("silentdragon donation", Settings::getDonationAddr(true)));
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void AddressBook::writeToStorage()
|
||||
{
|
||||
//FileSystem::getInstance()->writeContacts(AddressBook::writeableFile(), DataStore::getContactDataStore()->dump());
|
||||
|
||||
FileSystem::getInstance()->writeContactsOldFormat(AddressBook::writeableFile(), allLabels);
|
||||
// FileSystem::getInstance()->writeContactsOldFormat(AddressBook::writeableFile(), allLabels);
|
||||
|
||||
|
||||
/*QFile file(AddressBook::writeableFile());
|
||||
QFile file(AddressBook::writeableFile());
|
||||
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
||||
QDataStream out(&file); // we will serialize the data into the file
|
||||
QList<QList<QString>> contacts;
|
||||
@@ -442,7 +449,7 @@ void AddressBook::writeToStorage()
|
||||
contacts.push_back(c);
|
||||
}
|
||||
out << QString("v1") << contacts;
|
||||
file.close();*/
|
||||
file.close();
|
||||
}
|
||||
|
||||
QString AddressBook::writeableFile()
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<activeon>:/icons/res/sdlogo.png</activeon>
|
||||
<activeon>:/icons/res/SDLogo.png</activeon>
|
||||
</iconset>
|
||||
</property>
|
||||
</item>
|
||||
|
||||
@@ -239,17 +239,15 @@ void MainWindow::renderContactRequest(){
|
||||
|
||||
qDebug()<<"Beginn kopiert" <<cid << addr << newLabel << myAddr;
|
||||
AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar);
|
||||
rpc->refreshContacts(
|
||||
ui->listContactWidget);
|
||||
|
||||
QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact");
|
||||
QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact");
|
||||
|
||||
});
|
||||
|
||||
dialog.exec();
|
||||
|
||||
rpc->refreshContacts(
|
||||
ui->listContactWidget
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
void ChatModel::addCid(QString tx, QString cid)
|
||||
@@ -776,7 +774,8 @@ void::MainWindow::addContact()
|
||||
request.setupUi(&dialog);
|
||||
Settings::saveRestore(&dialog);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
bool sapling = true;
|
||||
rpc->createNewZaddr(sapling, [=] (json reply) {
|
||||
QString myAddr = QString::fromStdString(reply.get<json::array_t>()[0]);
|
||||
@@ -786,11 +785,15 @@ void::MainWindow::addContact()
|
||||
ui->listReceiveAddresses->setCurrentIndex(0);
|
||||
qDebug() << "new generated myAddr add Contact" << myAddr;
|
||||
});
|
||||
|
||||
|
||||
}catch(...)
|
||||
{
|
||||
|
||||
|
||||
qDebug() << QString("Caught something nasty with myZaddr Contact");
|
||||
}
|
||||
|
||||
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
|
||||
|
||||
|
||||
|
||||
QObject::connect(request.sendRequestButton, &QPushButton::clicked, [&] () {
|
||||
|
||||
@@ -940,7 +943,10 @@ void MainWindow::ContactRequest() {
|
||||
delete d;
|
||||
|
||||
});
|
||||
QString addr = contactRequest.getReceiverAddress();
|
||||
|
||||
/////Add this contact after we sent the request
|
||||
|
||||
QString addr = contactRequest.getReceiverAddress();
|
||||
QString newLabel = contactRequest.getLabel();
|
||||
QString myAddr = contactRequest.getSenderAddress();
|
||||
QString cid = contactRequest.getCid();
|
||||
@@ -973,17 +979,22 @@ void MainWindow::ContactRequest() {
|
||||
|
||||
////// Success, so show it
|
||||
AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar);
|
||||
rpc->refreshContacts(
|
||||
ui->listContactWidget);
|
||||
QMessageBox::information(
|
||||
this,
|
||||
QObject::tr("Added Contact"),
|
||||
QObject::tr("successfully added your new contact").arg(newLabel),
|
||||
QMessageBox::Ok
|
||||
|
||||
);
|
||||
return;
|
||||
// Force a UI update so we get the unconfirmed Tx
|
||||
// rpc->refresh(true);
|
||||
ui->memoTxtChat->clear();
|
||||
rpc->refresh(true);
|
||||
rpc->refreshContacts(
|
||||
ui->listContactWidget);
|
||||
|
||||
},
|
||||
// Errored out
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<activeon>:/icons/res/sdlogo.png</activeon>
|
||||
<activeon>:/icons/res/SDLogo.png</activeon>
|
||||
</iconset>
|
||||
</property>
|
||||
</item>
|
||||
|
||||
@@ -922,8 +922,6 @@ void Controller::refreshTransactions() {
|
||||
isNotarized = false;
|
||||
}
|
||||
|
||||
qDebug()<<"Conf : " << confirmations;
|
||||
|
||||
ChatItem item = ChatItem(
|
||||
datetime,
|
||||
address,
|
||||
@@ -1078,7 +1076,6 @@ void Controller::refreshTransactions() {
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug()<<"get Lag" << getLag();
|
||||
|
||||
// Calculate the total unspent amount that's pending. This will need to be
|
||||
// shown in the UI so the user can keep track of pending funds
|
||||
@@ -1098,10 +1095,7 @@ void Controller::refreshTransactions() {
|
||||
// Update model data, which updates the table view
|
||||
transactionsTableModel->replaceData(txdata);
|
||||
chat->renderChatBox(ui, ui->listChat,ui->memoSizeChat);
|
||||
// refreshContacts(
|
||||
// ui->listContactWidget
|
||||
|
||||
// );
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<activeon>:/icons/res/sdlogo.png</activeon>
|
||||
<activeon>:/icons/res/SDLogo.png</activeon>
|
||||
</iconset>
|
||||
</property>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user