Merge pull request #62 from strider-paff-shell/chat
update// added backwarts compat on addresses
This commit is contained in:
@@ -54,3 +54,8 @@ r
|
||||
s
|
||||
n
|
||||
q
|
||||
b FileSystem::readContactsOldFormat
|
||||
r
|
||||
n
|
||||
c
|
||||
q
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
break FileEncryption::encrypt
|
||||
break FileSystem::readContactsOldFormat
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ void FileSystem::writeContactsOldFormat(QString file, QList<ContactItem> contact
|
||||
c.push_back(item.getAvatar());
|
||||
_contacts.push_back(c);
|
||||
}
|
||||
out << QString("v1") << _contacts;
|
||||
out << QString("v2") << _contacts;
|
||||
_file.close();
|
||||
}
|
||||
|
||||
@@ -96,35 +96,68 @@ QList<ContactItem> FileSystem::readContactsOldFormat(QString file)
|
||||
contacts.clear();
|
||||
_file.open(QIODevice::ReadOnly);
|
||||
QDataStream in(&_file); // read the data serialized from the file
|
||||
QString version;
|
||||
in >> version;
|
||||
qDebug() << "Read " << version << " Hush contacts from disk...";
|
||||
qDebug() << "Detected old addressbook format";
|
||||
if(in.status() == QDataStream::ReadCorruptData)
|
||||
{
|
||||
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
|
||||
);
|
||||
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
|
||||
);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
qDebug() << "Read " << version << " Hush contacts from disk...";
|
||||
QList<QList<QString>> stuff;
|
||||
in >> stuff;
|
||||
for (int i=0; i < stuff.size(); i++)
|
||||
QString version;
|
||||
in >> version;
|
||||
if(version == "v1")
|
||||
{
|
||||
ContactItem contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]);
|
||||
contacts.push_back(contact);
|
||||
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
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
|
||||
ContactItem::ContactItem() {}
|
||||
|
||||
ContactItem::ContactItem(QString name, QString partnerAddress)
|
||||
{
|
||||
_name = name;
|
||||
_partnerAddress = partnerAddress;
|
||||
}
|
||||
|
||||
ContactItem::ContactItem(QString name, QString partnerAddress, QString myAddress, QString cid)
|
||||
{
|
||||
_name = name;
|
||||
_myAddress = myAddress;
|
||||
_partnerAddress = partnerAddress;
|
||||
_cid = cid;
|
||||
}
|
||||
|
||||
ContactItem::ContactItem(QString name, QString partnerAddress, QString myAddress, QString cid, QString avatar)
|
||||
{
|
||||
_name = name;
|
||||
|
||||
@@ -11,14 +11,16 @@ using json = nlohmann::json;
|
||||
class ContactItem
|
||||
{
|
||||
private:
|
||||
QString _myAddress;
|
||||
QString _partnerAddress;
|
||||
QString _name;
|
||||
QString _cid;
|
||||
QString _avatar;
|
||||
QString _myAddress = "";
|
||||
QString _partnerAddress = "";
|
||||
QString _name = "";
|
||||
QString _cid = "";
|
||||
QString _avatar = ":/icons/res/sdlogo.png";
|
||||
|
||||
public:
|
||||
ContactItem();
|
||||
ContactItem(QString name, QString partnerAddress);
|
||||
ContactItem(QString name, QString partnerAddress, QString myAddress, QString cid);
|
||||
ContactItem(QString name, QString partnerAddress, QString myAddress, QString cid, QString avatar);
|
||||
QString getName() const;
|
||||
QString getMyAddress() const;
|
||||
|
||||
@@ -417,12 +417,7 @@ 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();
|
||||
AddressBook::writeToStorage();
|
||||
}
|
||||
|
||||
void AddressBook::writeToStorage()
|
||||
|
||||
Reference in New Issue
Block a user