X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fxmlreader.cpp;h=9c7766b03640d29e7f2cced3fdd6ad87a3b6e27a;hp=2bcc168bc6a8613aff6730b2d91abdc006b70fee;hb=04e7348e047307f792f88b7a3e198a008eef0e8b;hpb=a16a5f4ed3711ad28f85951c0d63e666b1f86c11 diff --git a/Client/xmlreader.cpp b/Client/xmlreader.cpp index 2bcc168..9c7766b 100644 --- a/Client/xmlreader.cpp +++ b/Client/xmlreader.cpp @@ -10,12 +10,14 @@ #include #include #include "xmlreader.h" +#include "profiledialog.h" /** *Constructor of this class. */ XmlReader::XmlReader() { + qDebug() << "__XmlReader"; myCategoryList = new CategoryList(); } @@ -24,18 +26,21 @@ XmlReader::XmlReader() */ XmlReader::~XmlReader() { + qDebug() << "__~XmlReader"; category = ""; unit = ""; position = ""; user = ""; value = ""; - delete myCategoryList; + + if(myCategoryList) + delete myCategoryList; } /** *This function is used to parse top 10 results of a certain category. */ -void XmlReader::xmlReadTop10Results(QNetworkReply *device) +void XmlReader::xmlReadTop10Results(QNetworkReply *device, QString userName) { qDebug() << "_xmlReadTop10Results"; @@ -64,22 +69,41 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device) { qDebug() << xmlreader.name(); } + if(xmlreader.name() == "result") { - qDebug() << "result"; + qDebug() << xmlreader.name(); attr = xmlreader.attributes(); user = attr.value("username").toString(); position = attr.value("position").toString(); date = attr.value("date").toString(); - unit = attr.value("unit").toString(); + //unit = attr.value("unit").toString(); + unit = "s"; value = attr.value("value").toString(); + if (userName.toUpper() == user.toUpper())//If user name match highlight result + { + myCategoryList->top10List.append("" + position + "" + + user + "" + + value + " " + + unit + "" + + date + ""); + } + else//If user name not match + { + myCategoryList->top10List.append("" + position + "" + + user + "" + + value + " " + + unit + "" + + date + ""); + } + /* Old way, no highlight myCategoryList->top10List.append(position + "\t" + user + "\t" + value + " " + unit + "\t" + - date + "\n"); + date + "\n");*/ qDebug() << position << user << value << unit << date; i++; @@ -95,6 +119,10 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device) } } +/** + * + * + */ void XmlReader::xmlReadCategories(QNetworkReply *device) //void XmlReader::xmlReadCategories(QIODevice *device) { @@ -109,9 +137,6 @@ void XmlReader::xmlReadCategories(QNetworkReply *device) xmlreader.addData(array); //xmlreader.addData(device->readAll()); - if(myCategoryList->sizeOfCategoryList() != 0) { - myCategoryList->clearCategoryList(); - } myCategoryList->clearCats(); //Go trough the xml document @@ -134,10 +159,8 @@ void XmlReader::xmlReadCategories(QNetworkReply *device) description = attr.value("description").toString(); unit = attr.value("unit").toString(); category = xmlreader.readElementText(); - myCategoryList->appendCategoryList(category); myCategoryList->appendCats(i, description, unit, category); - //qDebug() << "i=" << i << myCategoryList->itemOfCategoryList(i); - //qDebug() << "description: " << description << "unit: " << unit << "category: " << category; + qDebug() << "description: " << description << "unit: " << unit << "category: " << category; i++; receivedFlag = 1; } @@ -147,6 +170,7 @@ void XmlReader::xmlReadCategories(QNetworkReply *device) if(receivedFlag) { qDebug() << "receivedCategoryList() emitted"; + myCategoryList->realSizeOfCats = i; emit receivedCategoryList(); } } @@ -169,6 +193,73 @@ void XmlReader::xmlShow() //xmlReadTop10Results(&file); //xmlReadCategories(&file); + //xmlReadProfile(&file); file.close(); } +/** + * This function is used to read profile xml. + * @param QIODevice device: target of reading, here filename. + * @param ProfileDialog *profileDialog + */ +void XmlReader::xmlReadProfile(QIODevice *device, ProfileDialog *profileDialog) +{ + qDebug() << "_xmlReadProfile"; + + profile = profileDialog; + + xmlreader.clear(); + QByteArray array = device->readAll(); + + xmlreader.addData(array); + + QString login; + QString picture; + + // Go trough the xml document + while(!xmlreader.atEnd()) + { + // Read next node + xmlreader.readNext(); + + // Check if this element is starting element + if(xmlreader.isStartElement()) + { + if(xmlreader.name() == "profile") + { + qDebug() << xmlreader.name(); + attr = xmlreader.attributes(); + login = attr.value("login").toString(); + picture = attr.value("picture").toString(); + } + if(xmlreader.name() == "manufacturer") + { + qDebug() << xmlreader.name(); + profile->setManufacturer(xmlreader.readElementText()); + } + if(xmlreader.name() == "type") + { + qDebug() << xmlreader.name(); + profile->setType(xmlreader.readElementText()); + + } + if(xmlreader.name() == "model") + { + qDebug() << xmlreader.name(); + profile->setModel(xmlreader.readElementText()); + + } + if(xmlreader.name() == "description") + { + qDebug() << xmlreader.name(); + profile->setDescription(xmlreader.readElementText()); + } + if(xmlreader.name() == "picture" && picture == "yes") + { + qDebug() << xmlreader.name(); + profile->setPicture(xmlreader.readElementText()); + } + } + } + profile = NULL; +}