X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fxmlreader.cpp;h=2bcc168bc6a8613aff6730b2d91abdc006b70fee;hp=c3a439c39ac865819e7fe6f4e61f50c46338fd57;hb=b8104711348ebb86e8c93b23067af8f699870626;hpb=762e24bbb530f14ecfd444d0235627d0ca61663b diff --git a/Client/xmlreader.cpp b/Client/xmlreader.cpp index c3a439c..2bcc168 100644 --- a/Client/xmlreader.cpp +++ b/Client/xmlreader.cpp @@ -1,11 +1,11 @@ -/** - * Parse xml file - * - * @author Toni Jussila - * @author Tiina Kivilinna-Korhola - * @copyright (c) 2010 Speed Freak team - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - */ +/* + * Parse xml file + * + * @author Toni Jussila + * @author Tiina Kivilinna-Korhola + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ #include #include @@ -16,7 +16,7 @@ */ XmlReader::XmlReader() { - xmlShow(); + myCategoryList = new CategoryList(); } /** @@ -26,20 +26,31 @@ XmlReader::~XmlReader() { category = ""; unit = ""; - description = ""; position = ""; user = ""; value = ""; + delete myCategoryList; } /** - *This function is used to parsing xml file. + *This function is used to parse top 10 results of a certain category. */ -void XmlReader::xmlRead(QIODevice *device) +void XmlReader::xmlReadTop10Results(QNetworkReply *device) { - qDebug() << "_xmlRead"; + qDebug() << "_xmlReadTop10Results"; + + int i = 0; + int receivedFlag = 0; + + xmlreader.clear(); + QByteArray array = device->readAll(); + qDebug() << "array: " << array; + xmlreader.addData(array); + //xmlreader.addData(device->readAll()); - xmlreader.addData(device->readAll()); + if(!(myCategoryList->top10List.isEmpty())) { + myCategoryList->top10List.clear(); + } //Go trough the xml document while(!xmlreader.atEnd()) @@ -52,55 +63,92 @@ void XmlReader::xmlRead(QIODevice *device) if(xmlreader.name() == "results") { qDebug() << xmlreader.name(); - attr = xmlreader.attributes(); - - category = attr.value("category").toString(); - unit = attr.value("unit").toString(); - description = attr.value("description").toString(); - - top10List << category; - qDebug() << top10List << unit << description; } - if(xmlreader.name() == "result") { qDebug() << "result"; attr = xmlreader.attributes(); + user = attr.value("username").toString(); position = attr.value("position").toString(); - user = attr.value("user").toString(); + date = attr.value("date").toString(); + unit = attr.value("unit").toString(); value = attr.value("value").toString(); - if (category == "acceleration-0-100") - { - top10AccelerationList.append(position + "\t" + + myCategoryList->top10List.append(position + "\t" + user + "\t" + - value + + value + " " + unit + "\t" + - description + "\n"); - } - - if(category == "top10speed") - { - top10SpeedList.append(position + "\t" + - user + "\t" + - value + - unit + "\t" + - description + "\n"); - } - - if(category == "top10gforce") - { - top10GforceList.append(position + "\t" + - user + "\t" + - value + - unit + "\t" + - description + "\n"); - } - qDebug() << position << user << value << unit; + date + "\n"); + + qDebug() << position << user << value << unit << date; + i++; + receivedFlag = 1; + } + } + } + //Only change labelTopList if a new top10List has been received + if(receivedFlag) + { + qDebug() << "receivedTop10List() emitted"; + emit receivedTop10List(); + } +} + +void XmlReader::xmlReadCategories(QNetworkReply *device) +//void XmlReader::xmlReadCategories(QIODevice *device) +{ + qDebug() << "_xmlReadCategories"; + + int i = 0; + int receivedFlag = 0; + + xmlreader.clear(); + QByteArray array = device->readAll(); + qDebug() << "array: " << array; + xmlreader.addData(array); + //xmlreader.addData(device->readAll()); + + if(myCategoryList->sizeOfCategoryList() != 0) { + myCategoryList->clearCategoryList(); + } + myCategoryList->clearCats(); + + //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() == "categories") + { + qDebug() << xmlreader.name(); + } + if(xmlreader.name() == "category") + { + qDebug() << xmlreader.name(); + attr = xmlreader.attributes(); + 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; + i++; + receivedFlag = 1; } } } + //Only change comboBoxTopCategory if a new list has been received + if(receivedFlag) + { + qDebug() << "receivedCategoryList() emitted"; + emit receivedCategoryList(); + } } /** @@ -109,7 +157,8 @@ void XmlReader::xmlRead(QIODevice *device) */ void XmlReader::xmlShow() { - QString filename = "results.xml"; + //QString filename = "results.xml"; + QString filename = "xmlcategoryfile.xml"; QFile file(filename); if (!file.open(QFile::ReadOnly)) @@ -118,43 +167,8 @@ void XmlReader::xmlShow() return; } - xmlRead(&file); + //xmlReadTop10Results(&file); + //xmlReadCategories(&file); file.close(); } -/** - *This is return function. - *@todo Read real top 10 category list - *@return QStringList top10List - */ -QStringList XmlReader::getTop10List() -{ - return top10List; -} - -/** - *This is return function. - *@return QString top10AccelerationList - */ -QString XmlReader::getTop10AccelerationList() -{ - return top10AccelerationList; -} - -/** - *This is return function. - *@return QString top10SpeedList - */ -QString XmlReader::getTop10SpeedList() -{ - return top10SpeedList; -} - -/** - *This is return function. - *@return QString top10GforceList - */ -QString XmlReader::getTop10GforceList() -{ - return top10GforceList; -}