1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Made periodic message reminders a user option

This commit is contained in:
James Booth 2012-09-23 22:24:31 +01:00
parent 294ea2d1be
commit f488200408
5 changed files with 74 additions and 16 deletions

View File

@ -73,6 +73,7 @@ static gboolean _cmd_set_typing(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_chlog(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_chlog(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_remind(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_away(const char * const inp, struct cmd_help_t help); static gboolean _cmd_away(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_online(const char * const inp, struct cmd_help_t help); static gboolean _cmd_online(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help); static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help);
@ -204,10 +205,10 @@ static struct cmd_t setting_commands[] =
{ "/notify", { "/notify",
_cmd_set_notify, _cmd_set_notify,
{ "/notify on|off", "Enable/disable desktop notifications.", { "/notify on|off", "Enable/disable message notifications.",
{ "/notify on|off", { "/notify on|off",
"--------------", "--------------",
"Switch the desktop notifications on or off.", "Switch the message notifications on or off.",
"The notification will appear for all incoming messages.", "The notification will appear for all incoming messages.",
"The desktop environment must support desktop notifications.", "The desktop environment must support desktop notifications.",
"", "",
@ -228,6 +229,19 @@ static struct cmd_t setting_commands[] =
"Config file value : typing=true|false", "Config file value : typing=true|false",
NULL } } }, NULL } } },
{ "/remind",
_cmd_set_remind,
{ "/remind seconds", "Set message reminder period in seconds.",
{ "/remind seconds",
"--------------",
"Set the period for new message reminders as desktop notifications.",
"The value is in seconds, a setting of 0 will disable the feature.",
"The desktop environment must support desktop notifications.",
"",
"Config file section : [ui]",
"Config file value : remind=seconds",
NULL } } },
{ "/flash", { "/flash",
_cmd_set_flash, _cmd_set_flash,
{ "/flash on|off", "Enable/disable screen flash notifications.", { "/flash on|off", "Enable/disable screen flash notifications.",
@ -701,6 +715,29 @@ _cmd_set_chlog(const char * const inp, struct cmd_help_t help)
"Chat logging", prefs_set_chlog); "Chat logging", prefs_set_chlog);
} }
static gboolean
_cmd_set_remind(const char * const inp, struct cmd_help_t help)
{
if ((strncmp(inp, "/remind ", 8) != 0) || (strlen(inp) < 9)) {
char usage[strlen(help.usage + 8)];
sprintf(usage, "Usage: %s", help.usage);
cons_show(usage);
} else {
// copy input
char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp);
// get period
strtok(inp_cpy, " ");
char *period_str = strtok(NULL, " ");
gint period = atoi(period_str);
prefs_set_remind(period);
}
return TRUE;
}
static gboolean static gboolean
_cmd_away(const char * const inp, struct cmd_help_t help) _cmd_away(const char * const inp, struct cmd_help_t help)
{ {

View File

@ -269,6 +269,19 @@ prefs_set_chlog(gboolean value)
_save_prefs(); _save_prefs();
} }
gint
prefs_get_remind(void)
{
return g_key_file_get_integer(prefs, "ui", "remind", NULL);
}
void
prefs_set_remind(gint value)
{
g_key_file_set_integer(prefs, "ui", "remind", value);
_save_prefs();
}
void void
prefs_add_login(const char *jid) prefs_add_login(const char *jid)
{ {

View File

@ -52,6 +52,8 @@ gboolean prefs_get_chlog(void);
void prefs_set_chlog(gboolean value); void prefs_set_chlog(gboolean value);
gboolean prefs_get_showsplash(void); gboolean prefs_get_showsplash(void);
void prefs_set_showsplash(gboolean value); void prefs_set_showsplash(gboolean value);
gint prefs_get_remind(void);
void prefs_set_remind(gint value);
void prefs_add_login(const char *jid); void prefs_add_login(const char *jid);

View File

@ -41,8 +41,6 @@ static log_level_t _get_log_level(char *log_level);
gboolean _process_input(char *inp); gboolean _process_input(char *inp);
static void _create_config_directory(); static void _create_config_directory();
static gdouble remind_period = 10;
void void
profanity_run(void) profanity_run(void)
{ {
@ -62,6 +60,8 @@ profanity_run(void)
while(ch != '\n') { while(ch != '\n') {
gdouble elapsed = g_timer_elapsed(timer, NULL); gdouble elapsed = g_timer_elapsed(timer, NULL);
gint remind_period = prefs_get_remind();
// 0 means to not remind // 0 means to not remind
if (remind_period > 0 && elapsed >= remind_period) { if (remind_period > 0 && elapsed >= remind_period) {

View File

@ -472,34 +472,40 @@ cons_prefs(void)
cons_show(""); cons_show("");
if (prefs_get_beep()) if (prefs_get_beep())
cons_show("Terminal beep : ON"); cons_show("Terminal beep : ON");
else else
cons_show("Terminal beep : OFF"); cons_show("Terminal beep : OFF");
if (prefs_get_flash()) if (prefs_get_flash())
cons_show("Terminal flash : ON"); cons_show("Terminal flash : ON");
else else
cons_show("Terminal flash : OFF"); cons_show("Terminal flash : OFF");
if (prefs_get_notify()) if (prefs_get_notify())
cons_show("Desktop notifications : ON"); cons_show("Message notifications : ON");
else else
cons_show("Desktop notifications : OFF"); cons_show("Message notifications : OFF");
if (prefs_get_typing()) if (prefs_get_typing())
cons_show("Typing notifications : ON"); cons_show("Typing notifications : ON");
else else
cons_show("Typing notifications : OFF"); cons_show("Typing notifications : OFF");
if (prefs_get_showsplash()) if (prefs_get_showsplash())
cons_show("Splash screen : ON"); cons_show("Splash screen : ON");
else else
cons_show("Splash screen : OFF"); cons_show("Splash screen : OFF");
if (prefs_get_chlog()) if (prefs_get_chlog())
cons_show("Chat logging : ON"); cons_show("Chat logging : ON");
else else
cons_show("Chat logging : OFF"); cons_show("Chat logging : OFF");
char remind_period[50];
sprintf(remind_period,
"Message reminder period : %d seconds", prefs_get_remind());
cons_show(remind_period);
cons_show(""); cons_show("");