From 8d760b11cdb95b95701e22dc7b79acbe532c54d9 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 19 May 2011 13:09:53 +0000 Subject: [PATCH] Added display of the date for addons (should we perhaps make the strftime format translatable?). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8645 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/addons/addon.cpp | 14 +++++++++++++- src/addons/addon.hpp | 11 +++++++++++ src/states_screens/addons_screen.cpp | 7 ++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/addons/addon.cpp b/src/addons/addon.cpp index 2fbbbae3d..816b2eee4 100644 --- a/src/addons/addon.cpp +++ b/src/addons/addon.cpp @@ -21,7 +21,7 @@ #include "addons/addon.hpp" #include -//#include +#include #include "io/file_manager.hpp" #include "io/xml_node.hpp" @@ -42,6 +42,7 @@ Addon::Addon(const XMLNode &xml) m_icon_basename = ""; m_icon_revision = 0; m_size = 0; + m_date = 0; m_icon_ready = false; m_type = xml.getName(); @@ -50,6 +51,7 @@ Addon::Addon(const XMLNode &xml) xml.get("id", &m_id ); xml.get("designer", &m_designer ); xml.get("status", &m_status ); + xml.get("date", &m_date ); xml.get("installed", &m_installed ); xml.get("installed-revision", &m_installed_revision); xml.get("revision", &m_revision ); @@ -78,6 +80,7 @@ void Addon::copyInstallData(const Addon &addon) m_icon_revision = addon.m_revision; m_designer = addon.m_designer; m_status = addon.m_status; + m_date = addon.m_date; } // copyInstallData // ---------------------------------------------------------------------------- @@ -92,6 +95,7 @@ void Addon::writeXML(std::ofstream *out_stream) << "\" id=\"" << m_id << "\" designer=\"" << m_designer << "\" status=\"" << m_status + << "\" date=\"" << m_date << "\" installed=\"" << (m_installed ? "true" : "false" ) << "\" installed-revision=\"" << m_installed_revision @@ -100,3 +104,11 @@ void Addon::writeXML(std::ofstream *out_stream) << "\"/>\n"; } // writeXML +// ---------------------------------------------------------------------------- +std::string Addon::getDateAsString() const +{ + const struct tm *t = gmtime((time_t*)&m_date); + char s[16]; + strftime(s, 128, "%d.%m.%Y", t); + return s; +} // getDateAsString \ No newline at end of file diff --git a/src/addons/addon.hpp b/src/addons/addon.hpp index ffa0a8a18..974820775 100644 --- a/src/addons/addon.hpp +++ b/src/addons/addon.hpp @@ -24,6 +24,8 @@ #include #include "io/file_manager.hpp" +#include "utils/time.hpp" + class XMLNode; class Addon @@ -56,6 +58,8 @@ public: int m_icon_revision; /** The status flags of this addon. */ int m_status; + /** Date when the addon was added. */ + Time::TimeType m_date; /** A description of this addon. */ std::string m_description; /** The URL of the icon (relative to the server) */ @@ -99,6 +103,13 @@ public: /** Returns the name of the addon. */ const std::string& getDescription() const { return m_description; } // ------------------------------------------------------------------------ + /** Returns the date (in seconds since epoch) when the addon was + * uploaded. */ + Time::TimeType getDate() const { return m_date; } + // ------------------------------------------------------------------------ + /** Returns a user readable date as a string. */ + std::string getDateAsString() const; + // ------------------------------------------------------------------------ /** Returns if the addon is installed. */ bool isInstalled() const { return m_installed; } // ------------------------------------------------------------------------ diff --git a/src/states_screens/addons_screen.cpp b/src/states_screens/addons_screen.cpp index 5aaf6b890..79bbfe1af 100644 --- a/src/states_screens/addons_screen.cpp +++ b/src/states_screens/addons_screen.cpp @@ -111,10 +111,11 @@ void AddonsScreen::loadList() core::stringw s; if(addon.getDesigner().size()==0) - s = addon.getName().c_str(); + s = (addon.getName()+"\t"+addon.getDateAsString()).c_str(); else - s = _("%s by %s", addon.getName().c_str(), - addon.getDesigner().c_str()); + s = _("%s by %s\t%d", addon.getName().c_str(), + addon.getDesigner().c_str(), + addon.getDateAsString().c_str()); w_list->addItem(addon.getId(), s.c_str(), icon); }