From d1f1298b4b3a4c4e0195581e7b15a3bacd49bc33 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Tue, 25 Oct 2011 20:57:13 +0200 Subject: [PATCH] Make parsing of pubDate a little more flexible. --- larss/feedpoller.cpp | 21 +++++++++++++++++---- larss/main.cpp | 12 +++++++----- larss/mainwindow.cpp | 16 +++++++++++++--- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/larss/feedpoller.cpp b/larss/feedpoller.cpp index b8d6ce8..4628f13 100644 --- a/larss/feedpoller.cpp +++ b/larss/feedpoller.cpp @@ -159,16 +159,22 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply) uint pubDate; QString guid; QString pubDateTimeContent; + + // Check if we have Guid, in RSS 1.0 was not present. if (element.elementsByTagName("guid").length() != 0) - { guid = element.elementsByTagName("guid").item(0).firstChild().nodeValue(); + else + guid = link; + + // Check if we have pubDate + if (element.elementsByTagName("pubDate").length() != 0) + { pubDateTimeContent = element.elementsByTagName("pubDate").item(0).firstChild().nodeValue(); pubDate = pubDateToDateTime(pubDateTimeContent).toTime_t(); } else { - guid = link; - pubDate = QDateTime::currentDateTime().toTime_t(); + pubDate = QDateTime::currentDateTimeUtc().toTime_t(); } if (!links.contains(link)) @@ -219,10 +225,17 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply) QDateTime FeedPoller::pubDateToDateTime (QString pubDate) { + QString pubDateToParse; + // If the Day is not present in pubDate set a fake + // Day on top of it to make parsing working. + if (!pubDate.contains(",")) + pubDateToParse = QString("Sun, %1").arg(pubDate); + else + pubDateToParse = pubDate; // Parsing the data, take Sun, 12 Oct 2011 15:21:12 GMT // pieces[0] is Sun --- pieces[1] is 12 --- pieces[2] is Oct // pieces[3] is 2011 --- pieces[4] is 15:21:12 --- pieces[6] is GMT - QStringList pieces = pubDate.split(" "); + QStringList pieces = pubDateToParse.split(" "); QDateTime date; int month, year, day; diff --git a/larss/main.cpp b/larss/main.cpp index cd678d6..a6a4662 100644 --- a/larss/main.cpp +++ b/larss/main.cpp @@ -3,13 +3,15 @@ int main(int argc, char *argv[]) { - // Set some default values for our application - QCoreApplication::setApplicationName("Larss"); - QCoreApplication::setOrganizationName("PHC"); - QCoreApplication::setOrganizationDomain("phc.unipi.it"); - // Create the application and its main_window. QApplication larss_application(argc, argv); + + // Set some default values for our application + larss_application.setApplicationName("Larss"); + larss_application.setOrganizationName("PHC"); + larss_application.setOrganizationDomain("phc.unipi.it"); + + // Create the MainWindow object Larss::MainWindow main_window; // Show the main window diff --git a/larss/mainwindow.cpp b/larss/mainwindow.cpp index 9c2ee14..1766f1b 100644 --- a/larss/mainwindow.cpp +++ b/larss/mainwindow.cpp @@ -14,11 +14,11 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); - // Open the database + // Open the database, and create the directories for the data + // storage if they are not yet present in the filesystem. QString location = QDesktopServices::storageLocation(QDesktopServices::DataLocation); if (!QFile::exists(location)) QDir().mkpath(location); - qDebug() << "Data location: " << location; db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(location + "/larss.db"); db.open(); @@ -62,6 +62,15 @@ MainWindow::MainWindow(QWidget *parent) : resize (settings.value("width").toInt(), settings.value("height").toInt()); } + + // Expand all the categories. This is will be like this until we do + // not implement a decent method to store open/close categories on close. + QStandardItem *rootItem = feedModel->invisibleRootItem(); + for(qint32 i = 0; i < rootItem->rowCount(); i++) + { + QModelIndex index = rootItem->child(i, 0)->index(); + ui->feedTreeView->expand(index); + } } MainWindow::~MainWindow() @@ -78,6 +87,7 @@ MainWindow::loadingFeedStart(QString feedName) void MainWindow::closeEvent(QCloseEvent *event) { + Q_UNUSED(event); do_exit(); } @@ -156,7 +166,7 @@ bool Larss::MainWindow::eventFilter(QObject *object, QEvent *event) if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast(event); - if (loadedNews != "") + if (mouseEvent->button() == Qt::LeftButton && loadedNews != "") { ui->webView->load(QUrl(loadedNews)); } -- 2.1.4