CommunityWelcomePageWidget::CommunityWelcomePageWidget(QWidget *parent) : QWidget(parent), m_rssFetcher(new RSSFetcher(7)), ui(new Ui::CommunityWelcomePageWidget) { ui->setupUi(this); ui->labsTitleLabel->setStyledText(tr("News From the OpenPilot Project")); ui->sitesTitleLabel->setStyledText(tr("OpenPilot Websites")); connect(ui->newsTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString))); connect(ui->sitesTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString))); connect(m_rssFetcher, SIGNAL(newsItemReady(QString, QString, QString)), ui->newsTreeWidget, SLOT(slotAddNewsItem(QString, QString, QString))); //: Add localized feed here only if one exists m_rssFetcher->fetch(QUrl(tr("http://forums.openpilot.org/blog/rss/4-openpilot-development-blog"))); QList<QPair<QString, QString> > sites; sites << qMakePair(tr("OpenPilot Home"), QString(QLatin1String("http://www.openpilot.org"))); sites << qMakePair(tr("OpenPilot Wiki"), QString(QLatin1String("http://wiki.openpilot.org"))); sites << qMakePair(tr("OpenPilot Store"), QString(QLatin1String("http://www.openpilot.org/store"))); sites << qMakePair(tr("OpenPilot Forums"), QString(QLatin1String("http://forums.openpilot.org"))); sites << qMakePair(tr("OpenPilot Bug Tracker"), QString(QLatin1String("http://bugs.openpilot.org"))); QListIterator<QPair<QString, QString> > it(sites); while (it.hasNext()) { QPair<QString, QString> pair = it.next(); ui->sitesTreeWidget->addItem(pair.first, pair.second, pair.second); } }
void RssFetcher::parseXml(QIODevice *device) { QXmlStreamReader xmlReader(device); TagElement currentTag = otherElement; RssItem item; while (!xmlReader.atEnd()) { switch (xmlReader.readNext()) { case QXmlStreamReader::StartElement: currentTag = tagElement(xmlReader.name(), currentTag); if (currentTag == itemElement) { item = RssItem(); } break; case QXmlStreamReader::EndElement: if (xmlReader.name() == QLatin1String("item")) { m_items++; if ((uint)m_items > (uint)m_maxItems) return; emit newsItemReady(item.title, item.description, item.url); emit rssItemReady(item); } break; case QXmlStreamReader::Characters: if (!xmlReader.isWhitespace()) { switch (currentTag) { case titleElement: item.title += xmlReader.text().toString(); break; case descriptionElement: item.description += xmlReader.text().toString(); break; case categoryElement: item.category += xmlReader.text().toString(); break; case linkElement: item.url += xmlReader.text().toString(); break; case imageLinkElement: item.imagePath += xmlReader.text().toString(); break; default: break; } } // !xmlReader.isWhitespace() break; default: break; } } if (xmlReader.error() && xmlReader.error() != QXmlStreamReader::PrematureEndOfDocumentError) { qWarning("Welcome::Internal::RSSFetcher: XML ERROR: %d: %s (%s)", int(xmlReader.lineNumber()), qPrintable(xmlReader.errorString()), qPrintable(item.title)); } }