QMap<QString, QString> parsePics(QXmlStreamReader& xml2);
void addElementDataToMap_Pics(QXmlStreamReader& xml2,
QMap<QString, QString>& map2) const;
void addPicsToUI(QList< QMap<QString,QString> >& root2);
void addToList_Pics(QList< QMap<QString,QString> >& root2);
QMap<QString, QString> parsePics(QXmlStreamReader& xml2);
void addElementDataToMap_Pics(QXmlStreamReader& xml2,
QMap<QString, QString>& map2) const;
void addPicsToUI(QList< QMap<QString,QString> >& root2);
void addToList_Pics(QList< QMap<QString,QString> >& root2);
QLabel *picture;
To copy to clipboard, switch view to plain text mode
QTimer::singleShot(0,
this,
SLOT(parseXML_Pics
()));
connect(timer, SIGNAL(timeout()), this, SLOT(doAddToList_Pics()));
timer->start(3000);
void mediazone::doAddToList_Pics()
{
QList< QMap<QString,QString> > root2;
addToList_Pics(root2);
}
void mediazone::parseXML_Pics() {
/* We'll parse the example.xml */
QFile* file2
= new QFile("/home/dev/ttm/moives/xml/strings.xml");
/* If we can't open it, let's show an error message. */
"QXSRimpl::parseXML",
"file2 Couldn't open strings.xml",
return;
}
/* QXmlStreamReader takes any QIODevice. */
QXmlStreamReader xml2(file2);
QList< QMap<QString,QString> > root2;
/* We'll parse the XML until we reach end of it.*/
while(!xml2.atEnd() &&
!xml2.hasError()) {
/* Read next element.*/
QXmlStreamReader::TokenType token2 = xml2.readNext();
/* If token is just StartDocument, we'll go to next.*/
if(token2 == QXmlStreamReader::StartDocument) {
continue;
}
/* If token is StartElement, we'll see if we can read it.*/
if(token2 == QXmlStreamReader::StartElement) {
/* If it's named root, we'll go to the next.*/
if(xml2.name() == "root") {
continue;
}
/* If it's named row, we'll dig the information from there.*/
if(xml2.name() == "row") {
root2.append(this->parsePics(xml2));
}
}
}
/* Error handling. */
if(xml2.hasError()) {
"xml2 has error",
xml2.errorString(),
}
/* Removes any device() or data from the reader
* and resets its internal state to the initial state. */
xml2.clear();
this->addToList_Pics(root2);
}
QMap<QString, QString> mediazone::parsePics(QXmlStreamReader& xml2) {
QMap<QString, QString> row2;
/* Let's check that we're really getting a row. */
if(xml2.tokenType() != QXmlStreamReader::StartElement &&
xml2.name() == "row") {
return row2;
}
/* Let's get the attributes for row */
QXmlStreamAttributes attributes2 = xml2.attributes();
/* Let's check that row has id attribute. */
if(attributes2.hasAttribute("id")) {
/* We'll add it to the map. */
row2["id"] = attributes2.value("id").toString();
}
/* Next element... */
xml2.readNext();
/*
* We're going to loop over the things because the order might change.
* We'll continue the loop until we hit an EndElement named row.
*/
while(!(xml2.tokenType() == QXmlStreamReader::EndElement &&
xml2.name() == "row")) {
if(xml2.tokenType() == QXmlStreamReader::StartElement) {
/* We've found Picture. */
if(xml2.name() == "zone2banner300x300") {
this->addElementDataToMap_Pics(xml2, row2);
emit doneParsePics();
}
}
/* ...and next... */
xml2.readNext();
}
return row2;
}
void mediazone::addElementDataToMap_Pics(QXmlStreamReader& xml2,
QMap<QString, QString>& map2) const {
/* We need a start element, like <foo> */
if(xml2.tokenType() != QXmlStreamReader::StartElement) {
return;
}
/* Let's read the name... */
QString elementName2
= xml2.
name().
toString();
/* ...go to the next. */
xml2.readNext();
/*
* This elements needs to contain Characters so we know it's
* actually data, if it's not we'll leave.
*/
if(xml2.tokenType() != QXmlStreamReader::Characters) {
return;
}
/* Now we can add it to the map.*/
map2.insert(elementName2, xml2.text().toString());
}
void mediazone::addToList_Pics(QList< QMap<QString,QString> >& root2)
{
while(!root2.isEmpty()) {
QMap<QString,QString> row2 = root2.takeFirst();
QMapIterator<QString,QString> Iter_Pics(row2);
while(Iter_Pics.hasNext())
{
Iter_Pics.next();
myPics = Iter_Pics.value();
vidpath_Pics = "/home/dev/ttm/images/" + myPics;
picture
->setGeometry
(QRect(781,
2,
475,
360));
picture->clear();
picture
->setPixmap
(QPixmap(vidpath_Pics
));
picture->showFullScreen();
picture->show();
}
}
}
QTimer::singleShot(0,this, SLOT(parseXML_Pics()));
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(doAddToList_Pics()));
timer->start(3000);
void mediazone::doAddToList_Pics()
{
QList< QMap<QString,QString> > root2;
addToList_Pics(root2);
}
void mediazone::parseXML_Pics() {
/* We'll parse the example.xml */
QFile* file2 = new QFile("/home/dev/ttm/moives/xml/strings.xml");
/* If we can't open it, let's show an error message. */
if (!file2->open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(this,
"QXSRimpl::parseXML",
"file2 Couldn't open strings.xml",
QMessageBox::Ok);
return;
}
/* QXmlStreamReader takes any QIODevice. */
QXmlStreamReader xml2(file2);
QList< QMap<QString,QString> > root2;
/* We'll parse the XML until we reach end of it.*/
while(!xml2.atEnd() &&
!xml2.hasError()) {
/* Read next element.*/
QXmlStreamReader::TokenType token2 = xml2.readNext();
/* If token is just StartDocument, we'll go to next.*/
if(token2 == QXmlStreamReader::StartDocument) {
continue;
}
/* If token is StartElement, we'll see if we can read it.*/
if(token2 == QXmlStreamReader::StartElement) {
/* If it's named root, we'll go to the next.*/
if(xml2.name() == "root") {
continue;
}
/* If it's named row, we'll dig the information from there.*/
if(xml2.name() == "row") {
root2.append(this->parsePics(xml2));
}
}
}
/* Error handling. */
if(xml2.hasError()) {
QMessageBox::critical(this,
"xml2 has error",
xml2.errorString(),
QMessageBox::Ok);
}
/* Removes any device() or data from the reader
* and resets its internal state to the initial state. */
xml2.clear();
this->addToList_Pics(root2);
}
QMap<QString, QString> mediazone::parsePics(QXmlStreamReader& xml2) {
QMap<QString, QString> row2;
/* Let's check that we're really getting a row. */
if(xml2.tokenType() != QXmlStreamReader::StartElement &&
xml2.name() == "row") {
return row2;
}
/* Let's get the attributes for row */
QXmlStreamAttributes attributes2 = xml2.attributes();
/* Let's check that row has id attribute. */
if(attributes2.hasAttribute("id")) {
/* We'll add it to the map. */
row2["id"] = attributes2.value("id").toString();
}
/* Next element... */
xml2.readNext();
/*
* We're going to loop over the things because the order might change.
* We'll continue the loop until we hit an EndElement named row.
*/
while(!(xml2.tokenType() == QXmlStreamReader::EndElement &&
xml2.name() == "row")) {
if(xml2.tokenType() == QXmlStreamReader::StartElement) {
/* We've found Picture. */
if(xml2.name() == "zone2banner300x300") {
this->addElementDataToMap_Pics(xml2, row2);
emit doneParsePics();
}
}
/* ...and next... */
xml2.readNext();
}
return row2;
}
void mediazone::addElementDataToMap_Pics(QXmlStreamReader& xml2,
QMap<QString, QString>& map2) const {
/* We need a start element, like <foo> */
if(xml2.tokenType() != QXmlStreamReader::StartElement) {
return;
}
/* Let's read the name... */
QString elementName2 = xml2.name().toString();
/* ...go to the next. */
xml2.readNext();
/*
* This elements needs to contain Characters so we know it's
* actually data, if it's not we'll leave.
*/
if(xml2.tokenType() != QXmlStreamReader::Characters) {
return;
}
/* Now we can add it to the map.*/
map2.insert(elementName2, xml2.text().toString());
}
void mediazone::addToList_Pics(QList< QMap<QString,QString> >& root2)
{
while(!root2.isEmpty()) {
QMap<QString,QString> row2 = root2.takeFirst();
QMapIterator<QString,QString> Iter_Pics(row2);
while(Iter_Pics.hasNext())
{
Iter_Pics.next();
QString myPics;
myPics = Iter_Pics.value();
QString vidpath_Pics = QApplication::applicationDirPath();
vidpath_Pics = "/home/dev/ttm/images/" + myPics;
picture = new QLabel(this);
picture->setGeometry(QRect(781,2,475,360));
picture->clear();
picture->setPixmap(QPixmap(vidpath_Pics));
picture->showFullScreen();
picture->show();
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks