summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2013-06-04 13:33:01 +0200
committerwm4 <wm4@nowhere>2013-06-04 23:41:15 +0200
commit953d22536876884faf75beba49a090e522a45b10 (patch)
tree9fc0c80ca6f20e4a50d8bfbbe84b0612c2aad011 /core
parent213ad5d6c41f32cf9086fa377cd6d6df1236bb76 (diff)
downloadmpv-953d22536876884faf75beba49a090e522a45b10.tar.bz2
mpv-953d22536876884faf75beba49a090e522a45b10.tar.xz
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]' .
Diffstat (limited to 'core')
-rw-r--r--core/command.c16
1 files changed, 16 insertions, 0 deletions
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 <string.h>
#include <stdbool.h>
#include <assert.h>
+#include <time.h>
#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") },