From 953d22536876884faf75beba49a090e522a45b10 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Tue, 4 Jun 2013 13:33:01 +0200 Subject: command: add the current local time as a property This adds a the property 'clock', which returns the current local time as the string hh:mm. Additionally the keybinding 'shift' + 'o' was added to displaying the clock as '[hh:mm]' . --- core/command.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core/command.c') diff --git a/core/command.c b/core/command.c index 416fbcd06a..c5c818e6b7 100644 --- a/core/command.c +++ b/core/command.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "config.h" #include "talloc.h" @@ -579,6 +580,18 @@ static int mp_property_cache(m_option_t *prop, int action, void *arg, return m_property_int_ro(prop, action, arg, cache); } +static int mp_property_clock(m_option_t *prop, int action, void *arg, + MPContext *mpctx) +{ + char outstr[6]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + + if ((tmp != NULL) && (strftime(outstr, sizeof(outstr), "%k:%M", tmp) == 5)) + return m_property_strdup_ro(prop, action, arg, outstr); + return M_PROPERTY_UNAVAILABLE; +} + /// Volume (RW) static int mp_property_volume(m_option_t *prop, int action, void *arg, MPContext *mpctx) @@ -1405,6 +1418,8 @@ static const m_option_t mp_properties[] = { { "cache", mp_property_cache, CONF_TYPE_INT }, M_OPTION_PROPERTY("pts-association-mode"), M_OPTION_PROPERTY("hr-seek"), + { "clock", mp_property_clock, CONF_TYPE_STRING, + 0, 0, 0, NULL }, // Audio { "volume", mp_property_volume, CONF_TYPE_FLOAT, @@ -1544,6 +1559,7 @@ static struct property_osd_display { { "pts-association-mode", "PTS association mode" }, { "hr-seek", "hr-seek" }, { "speed", _("Speed") }, + { "clock", _("Clock") }, // audio { "volume", _("Volume"), .osd_progbar = OSD_VOLUME }, { "mute", _("Mute") }, -- cgit v1.2.3