[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/plasma/applets/rssnow
From: Rob Scheepmaker <r.scheepmaker () student ! utwente ! nl>
Date: 2008-03-26 18:29:48
Message-ID: 1206556188.699632.4384.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 790386 by scheepmaker:
Improved the fuzzyDate function, by also showing minutes/hours ago, and using i18np for plurals.
Also fixed a crash when dropping rss feeds on the applet.
M +16 -19 news.cpp
M +1 -1 news.h
--- trunk/playground/base/plasma/applets/rssnow/news.cpp #790385:790386
@@ -249,6 +249,7 @@
foreach (KUrl feed, urls){
m_feeds.append(feed.prettyUrl());
}
+ updateScrollers();
connectToEngine();
}
}
@@ -279,8 +280,7 @@
if (timestamp != 0) {
QDateTime datetime;
datetime.setTime_t(timestamp);
- QDate date = datetime.date();
- data.extrainfo = fuzzyDate(date);
+ data.extrainfo = fuzzyDate(datetime);
}
if (!m_feedIcons.contains(icon)) {
@@ -311,26 +311,23 @@
m_timer->start();
}
-//TODO: probably move this functionality to a seperate class, because
-//seperate files are great.
-QString News::fuzzyDate(const QDate& date) {
- QDate now = QDate::currentDate();
+//TODO: hmm, we probably want to update the timestamps more often then the feeds
+//get updated... like, every minute
+QString News::fuzzyDate(const QDateTime& datetime) {
+ QDateTime now = QDateTime::currentDateTime();
+ QDate nowdate = now.date();
+ QDate date = datetime.date();
- if (now == date) {
- return i18n( "today" );
- } else if (now == (date.addDays(1))) {
+ if (now < (datetime.addSecs(3600))) {
+ return i18np( "%1 minute ago", "%1 mintutes ago", (datetime.secsTo(now)/60) );
+ } else if (nowdate == date.addDays(1)) {
return i18n( "yesterday" );
- } else if (now < (date.addDays(7))) {
- return i18n( "last %1", QDate::longDayName(date.dayOfWeek()));
+ } else if (now < (datetime.addDays(1))) {
+ return i18np( "%1 hour ago", "%1 hours ago", (datetime.secsTo(now)/3600) );
+ } else if (now < (datetime.addDays(7))) {
+ return i18np( "%1 day ago", "%1 days ago", datetime.daysTo(now));
} else {
- //TODO: this could probably be written nicer:
- QDate comp = date;
- int i = 0;
- while (comp < now) {
- i++;
- comp = comp.addDays(7);
- }
- return i18n( "%1 week ago", (i - 1));
+ return i18np( "%1 week ago", "%1 weeks ago", (datetime.daysTo(now)/7));
}
}
--- trunk/playground/base/plasma/applets/rssnow/news.h #790385:790386
@@ -80,7 +80,7 @@
void connectToEngine();
void updateScrollers();
- QString fuzzyDate(const QDate& date);
+ QString fuzzyDate(const QDateTime& date);
};
K_EXPORT_PLASMA_APPLET(rssnow, News)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic