Date are handled in the right way, now.
Leonardo Robol [2011-10-24 10:42]
Date are handled in the right way, now.
diff --git a/Larss.pro b/Larss.pro
index 006626b..483e055 100644
--- a/Larss.pro
+++ b/Larss.pro
@@ -22,3 +22,5 @@ HEADERS += include/mainwindow.h \
include/feedpoller.h
FORMS += ui/mainwindow.ui
+
+INCLUDEPATH += ./include
diff --git a/include/feedpoller.h b/include/feedpoller.h
index 4494249..1072dab 100644
--- a/include/feedpoller.h
+++ b/include/feedpoller.h
@@ -68,6 +68,8 @@ namespace Larss {
*/
void run();
+ QDateTime pubDateToDateTime (QString pubDate);
+
};
}
diff --git a/larss/feedpoller.cpp b/larss/feedpoller.cpp
index 11a6834..592d934 100644
--- a/larss/feedpoller.cpp
+++ b/larss/feedpoller.cpp
@@ -53,6 +53,8 @@ FeedPoller::poll()
return true;
}
}
+
+ return false;
}
void
@@ -111,15 +113,28 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
QString description = element.elementsByTagName("description").item(0).firstChild().nodeValue();
QString content = element.elementsByTagName("content:encoded").item(0).firstChild().nodeValue();
- // We should enable this for RSS 2.0
- // QString guid = element.elementsByTagName("guid").item(0).firstChild().nodeValue();
- // QString pubDate = element.elementsByTagName("pubDate").item(0).firstChild().nodeValue();
+ // Check if this is RSS2 or not
+ uint pubDate;
+ QString guid;
+ QString pubDateTimeContent;
+ if (element.elementsByTagName("guid").length() != 0)
+ {
+ guid = element.elementsByTagName("guid").item(0).firstChild().nodeValue();
+ pubDateTimeContent = element.elementsByTagName("pubDate").item(0).firstChild().nodeValue();
+ pubDate = pubDateToDateTime(pubDateTimeContent).toTime_t();
+ }
+ else
+ {
+ qDebug() << "Rss 1.0";
+ guid = link;
+ pubDate = QDateTime::currentDateTime().toTime_t();
+ }
if (!links.contains(link))
{
// That means that no results were found, so let's insert this one.
QSqlRecord record = parser->record();
- record.setValue("time", 0);
+ record.setValue("time", pubDate);
record.setValue("read", 0);
record.setValue("title", title);
record.setValue("link", link);
@@ -149,3 +164,54 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
manager->get(QNetworkRequest(QUrl(model->getUrl(next_item))));
}
}
+
+QDateTime
+FeedPoller::pubDateToDateTime (QString 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(" ");
+ QDateTime date;
+
+ int month, year, day;
+
+ // Set the day
+ day = pieces.at(1).toInt();
+
+ // Set the month
+ if (pieces.at(2) == "Jan")
+ month = 1;
+ else if (pieces.at(2) == "Feb")
+ month = 2;
+ else if (pieces.at(2) == "Mar")
+ month = 3;
+ else if (pieces.at(2) == "Apr")
+ month = 4;
+ else if (pieces.at(2) == "May")
+ month = 5;
+ else if (pieces.at(2) == "Jun")
+ month = 6;
+ else if (pieces.at(2) == "Jul")
+ month = 7;
+ else if (pieces.at(2) == "Aug")
+ month = 8;
+ else if (pieces.at(2) == "Sep")
+ month = 9;
+ else if (pieces.at(2) == "Oct")
+ month = 10;
+ else if (pieces.at(2) == "Nov")
+ month = 11;
+ else if (pieces.at(2) == "Dec")
+ month = 12;
+
+ // Set the year
+ year = pieces.at(3).toInt();
+
+ date.setDate(QDate (year, month, day));
+
+ // Set the hour
+ date.setTime(QTime::fromString(pieces[4], "hh:mm:ss"));
+
+ return date;
+}
diff --git a/larss/mainwindow.cpp b/larss/mainwindow.cpp
index 626ec1a..3c9bf8d 100644
--- a/larss/mainwindow.cpp
+++ b/larss/mainwindow.cpp
@@ -30,13 +30,13 @@ MainWindow::MainWindow(QWidget *parent) :
ui->newsTableView->setColumnHidden(3, true); // Link
ui->newsTableView->setColumnHidden(4, true); // Description
ui->newsTableView->setColumnHidden(5, true); // Content
- ui->newsTableView->setColumnHidden(6, true); // Time
+ // ui->newsTableView->setColumnHidden(6, true); // Time
ui->newsTableView->setColumnHidden(7, true); // Read state
ui->newsTableView->setEditTriggers(QTableView::NoEditTriggers);
ui->newsTableView->verticalHeader()->setHidden(true);
- ui->newsTableView->horizontalHeader()->setHidden(true);
ui->newsTableView->horizontalHeader()->setStretchLastSection(false);
ui->newsTableView->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
+ ui->newsTableView->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
// Show only unread elements
rssParser->setFilter("read=0");
diff --git a/larss/rssparser.cpp b/larss/rssparser.cpp
index 03e1ac1..44eb20b 100644
--- a/larss/rssparser.cpp
+++ b/larss/rssparser.cpp
@@ -27,6 +27,9 @@ Larss::RssParser::RssParser(QSqlDatabase db, FeedModel *model, QObject *parent)
// Select manual submit so user cannot modify content directly
setEditStrategy(QSqlTableModel::OnManualSubmit);
this->model = model;
+
+ // Make this sorted in different time
+ this->sort(6, Qt::DescendingOrder);
select();
}
@@ -58,7 +61,7 @@ Larss::RssParser::headerData(int section, Qt::Orientation orientation, int role)
return tr("Content");
break;
case 6:
- return tr("Time");
+ return tr("Date");
break;
case 7:
return tr("Read");
@@ -87,6 +90,13 @@ Larss::RssParser::data(const QModelIndex &idx, int role) const
default_font.setBold(true);
return default_font;
}
+
+ // Manage a nice rendering of Time
+ if (role == Qt::DisplayRole && idx.column() == 6)
+ {
+ return (QDateTime::fromTime_t(QSqlTableModel::data(idx, role).toInt()).toString());
+ }
+
// Call the default implementaton in almost every case
return QSqlTableModel::data(idx, role);
}
diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui
index f297349..83d5de3 100644
--- a/ui/mainwindow.ui
+++ b/ui/mainwindow.ui
@@ -36,7 +36,7 @@
<bool>false</bool>
</attribute>
</widget>
- <widget class="QWidget" name="">
+ <widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="webViewTitleLabel">