Commit d27de806 authored by Rishab Arora's avatar Rishab Arora

Added migration for users from old format

parent c978e45d
......@@ -67,6 +67,7 @@ bool KSUserDB::FirstRun() {
return false;
ImportFlags();
ImportUsers();
return true;
}
......@@ -645,3 +646,63 @@ bool KSUserDB::ImportFlags() {
}
return true;
}
bool KSUserDB::ImportUsers() {
QString usersfilename = KStandardDirs::locateLocal("appdata", "observerlist.xml");
QFile usersfile(usersfilename);
if (!usersfile.exists()) {
return false; // No upgrade needed. Flags file doesn't exist.
}
if( ! usersfile.open( QIODevice::ReadOnly ) )
return false;
QXmlStreamReader *reader = new QXmlStreamReader(&usersfile);
while( ! reader->atEnd() ) {
reader->readNext();
if( reader->isEndElement() )
break;
if( reader->isStartElement() ) {
if (reader->name() != "observers")
continue;
//Read all observers
while( ! reader->atEnd() ) {
reader->readNext();
if( reader->isEndElement() )
break;
if( reader->isStartElement() ) {
// Read single observer
if( reader->name() == "observer" ) {
QString name, surname, contact;
while( ! reader->atEnd() ) {
reader->readNext();
if( reader->isEndElement() )
break;
if( reader->isStartElement() ) {
if( reader->name() == "name" ) {
name = reader->readElementText();
} else if( reader->name() == "surname" ) {
surname = reader->readElementText();
} else if( reader->name() == "contact" ) {
contact = reader->readElementText();
}
}
}
AddObserver(name, surname, contact);
}
}
}
}
}
usersfile.close();
return true;
}
......@@ -228,6 +228,12 @@ class KSUserDB {
* @return bool
**/
bool ImportFlags();
/**
* @brief Imports users from previous format
*
* @return bool
**/
bool ImportUsers();
/**
* @brief Linked to the user database _once_.
**/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment