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]' .
This commit is contained in:
Jan-Marek Glogowski 2013-06-04 13:33:01 +02:00 committed by wm4
parent 213ad5d6c4
commit 953d225368
1 changed files with 16 additions and 0 deletions

View File

@ -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") },