|
|
@ -21,37 +21,30 @@ FileSystem* FileSystem::getInstance() |
|
|
|
|
|
|
|
QList<ContactItem> FileSystem::readContacts(QString file) |
|
|
|
{ |
|
|
|
QList<ContactItem> contacts; |
|
|
|
return this->readContactsOldFormat(file); //will be called if addresses are in the old dat-format
|
|
|
|
} |
|
|
|
|
|
|
|
void FileSystem::writeContacts(QString file, QString data) |
|
|
|
{ |
|
|
|
qDebug() << data; |
|
|
|
QFile _file(file); |
|
|
|
if (_file.exists()) |
|
|
|
{ |
|
|
|
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"; |
|
|
|
QList<QList<QString>> stuff; |
|
|
|
in >> stuff; |
|
|
|
//qDebug() << "Stuff: " << stuff;
|
|
|
|
for (int i=0; i < stuff.size(); i++) |
|
|
|
std::ofstream f(file.toStdString().c_str()); |
|
|
|
if(f.is_open()) |
|
|
|
{ |
|
|
|
ContactItem contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]); |
|
|
|
contacts.push_back(contact); |
|
|
|
f << data.toStdString(); |
|
|
|
} |
|
|
|
|
|
|
|
_file.close(); |
|
|
|
f.close(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
qDebug() << "No Hush contacts found on disk!"; |
|
|
|
qInfo() << file << "not exist"; |
|
|
|
} |
|
|
|
|
|
|
|
return contacts; |
|
|
|
} |
|
|
|
|
|
|
|
void FileSystem::writeContacts(QString file, QList<ContactItem> contacts) |
|
|
|
void FileSystem::writeContactsOldFormat(QString file, QList<ContactItem> contacts) |
|
|
|
{ |
|
|
|
QFile _file(file); |
|
|
|
_file.open(QIODevice::ReadWrite | QIODevice::Truncate); |
|
|
@ -71,6 +64,38 @@ void FileSystem::writeContacts(QString file, QList<ContactItem> contacts) |
|
|
|
_file.close(); |
|
|
|
} |
|
|
|
|
|
|
|
QList<ContactItem> FileSystem::readContactsOldFormat(QString file) |
|
|
|
{ |
|
|
|
QList<ContactItem> contacts; |
|
|
|
QFile _file(file); |
|
|
|
if (_file.exists()) |
|
|
|
{ |
|
|
|
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"; |
|
|
|
QList<QList<QString>> stuff; |
|
|
|
in >> stuff; |
|
|
|
//qDebug() << "Stuff: " << stuff;
|
|
|
|
for (int i=0; i < stuff.size(); i++) |
|
|
|
{ |
|
|
|
ContactItem contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]); |
|
|
|
contacts.push_back(contact); |
|
|
|
} |
|
|
|
|
|
|
|
_file.close(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
qDebug() << "No Hush contacts found on disk!"; |
|
|
|
} |
|
|
|
|
|
|
|
return contacts; |
|
|
|
} |
|
|
|
|
|
|
|
FileSystem::~FileSystem() |
|
|
|
{ |
|
|
|
this->instance = nullptr; |
|
|
|