Skip to content

Commit

Permalink
Updater: Printing the latest update check time
Browse files Browse the repository at this point in the history
Improved the textual output for the latest update time. If the check
has been made recently, instead of a full time and date it will now
print, e.g., "X minutes ago".
  • Loading branch information
skyjake committed Aug 31, 2012
1 parent 49c69f9 commit 83c5021
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/updater.cpp
Expand Up @@ -572,7 +572,7 @@ void Updater_ShowSettings(void)

void Updater_PrintLastUpdated(void)
{
UpdaterSettings st;
Con_Message("Latest update check was made on %s.\n",
st.lastCheckTime().asText(de::Time::FriendlyFormat).toAscii().constData());
de::Time when = UpdaterSettings().lastCheckTime();
Con_Message("Latest update check was made %s.\n",
UpdaterSettings().lastCheckAgo().toAscii().constData());
}
27 changes: 27 additions & 0 deletions doomsday/engine/portable/src/updater/updatersettings.cpp
Expand Up @@ -147,3 +147,30 @@ de::String UpdaterSettings::defaultDownloadPath()
{
return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
}

de::String UpdaterSettings::lastCheckAgo() const
{
de::Time when = lastCheckTime();
de::Time::Delta delta = when.since();

int t;
if(delta < 60.0)
{
t = delta.asMilliSeconds() / 1000;
return de::String("%1 second%2 ago").arg(t).arg(t != 1? "s" : "");
}

t = delta.asMinutes();
if(t <= 60)
{
return de::String("%1 minute%2 ago").arg(t).arg(t != 1? "s" : "");
}

t = delta.asHours();
if(t <= 24)
{
return de::String("%1 hour%2 ago").arg(t).arg(t != 1? "s" : "");
}

return de::String("on " + when.asText(de::Time::FriendlyFormat));
}
6 changes: 6 additions & 0 deletions doomsday/engine/portable/src/updater/updatersettings.h
Expand Up @@ -62,6 +62,12 @@ class UpdaterSettings
de::String downloadPath() const;
de::String pathToDeleteAtStartup() const;

/**
* @return Human-readable description of when the latest update
* check was made.
*/
de::String lastCheckAgo() const;

void setFrequency(Frequency freq);
void setChannel(Channel channel);
void setLastCheckTime(const de::Time& time);
Expand Down
Expand Up @@ -113,8 +113,8 @@ struct UpdaterSettingsDialog::Instance
{
UpdaterSettings st;

lastChecked->setText(tr("<small>Last checked on %1.</small>")
.arg(st.lastCheckTime().asText(de::Time::FriendlyFormat)));
lastChecked->setText(tr("<small>Last checked %1.</small>")
.arg(st.lastCheckAgo()));

autoCheck->setChecked(!st.onlyCheckManually());
freqList->setEnabled(!st.onlyCheckManually());
Expand Down

0 comments on commit 83c5021

Please sign in to comment.