1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Unified desktop notification preferences

This commit is contained in:
James Booth 2012-10-27 22:05:08 +01:00
parent 7ba66d7edb
commit c71259c322
6 changed files with 122 additions and 104 deletions

View File

@ -71,12 +71,10 @@ static gboolean _cmd_tiny(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_close(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_beep(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_notify(const char * const inp, struct cmd_help_t help);
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_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_history(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_vercheck(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);
@ -221,40 +219,26 @@ static struct cmd_t setting_commands[] =
{ "/notify",
_cmd_set_notify,
{ "/notify on|off", "Desktop notifications for new messages.",
{ "/notify on|off",
"--------------",
"Switch the message notifications on or off.",
"The notification will appear for all incoming messages.",
"The desktop environment must support desktop notifications.",
{ "/notify type value", "Control various desktop noficiations.",
{ "/notify type value",
"------------------",
"Settings for various desktop notifications where type is one of:",
"message : Notificaitons for messages.",
" : on|off",
"remind : Notification reminders of unread messages.",
" : where value is the reminder period in seconds,",
" : use 0 to disable.",
"typing : Notifications when contacts are typing.",
" : on|off",
"",
"Config file section : [ui]",
"Config file value : notify=true|false",
NULL } } },
{ "/typing",
_cmd_set_typing,
{ "/typing on|off", "Show when contacts typing.",
{ "/typing on|off",
"--------------",
"Switch typing notifications on or off for incoming messages",
"If desktop notifications are also enabled you will receive them",
"for when users are typing a message to you.",
"Example : /notify message on (enable message notifications)",
"Example : /notify remind 10 (remind every 10 seconds)",
"Example : /notify remind 0 (switch off reminders)",
"Example : /notify typing on (enable typing notifications)",
"",
"Config file section : [ui]",
"Config file value : typing=true|false",
NULL } } },
{ "/remind",
_cmd_set_remind,
{ "/remind seconds", "Desktop notification reminder of unread messages.",
{ "/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 section : [notifications]",
"Config file value : message=on|off",
"Config file value : typing=on|off",
"Config file value : remind=seconds",
NULL } } },
@ -847,15 +831,76 @@ _cmd_set_beep(const char * const inp, struct cmd_help_t help)
static gboolean
_cmd_set_notify(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/notify",
"Desktop notifications", prefs_set_notify);
}
char *kind = NULL;
char *value = NULL;
static gboolean
_cmd_set_typing(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/typing",
"Incoming typing notifications", prefs_set_typing);
// copy input
char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp);
// get kind
strtok(inp_cpy, " ");
kind = strtok(NULL, " ");
if ((kind != NULL) && (strlen(inp) > (8 + strlen(kind) + 1))) {
if ((strcmp(kind, "message") != 0) &&
(strcmp(kind, "typing") != 0) &&
(strcmp(kind, "remind") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
// get value
value = strndup(inp+8+strlen(kind)+1, strlen(inp)-(8+strlen(kind)+1));
if (value != NULL) {
// set message setting
if (strcmp(kind, "message") == 0) {
if (strcmp(inp, "/notify message on") == 0) {
cons_show("Message notifications enabled.");
prefs_set_notify_message(TRUE);
} else if (strcmp(inp, "/notify message off") == 0) {
cons_show("Message notifications disabled.");
prefs_set_notify_message(FALSE);
} else {
cons_show("Usage: /notify message on|off");
}
// set typing setting
} else if (strcmp(kind, "typing") == 0) {
if (strcmp(inp, "/notify typing on") == 0) {
cons_show("Typing notifications enabled.");
prefs_set_notify_typing(TRUE);
} else if (strcmp(inp, "/notify typing off") == 0) {
cons_show("Typing notifications disabled.");
prefs_set_notify_typing(FALSE);
} else {
cons_show("Usage: /notify typing on|off");
}
} else { // remind
gint period = atoi(value);
prefs_set_notify_remind(period);
if (period == 0) {
cons_show("Message reminders disabled.");
} else if (period == 1) {
cons_show("Message reminder period set to 1 second.");
} else {
cons_show("Message reminder period set to %d seconds.", period);
}
}
return TRUE;
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
}
}
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
}
}
static gboolean
@ -898,34 +943,6 @@ _cmd_set_history(const char * const inp, struct cmd_help_t help)
"Chat history", prefs_set_history);
}
static gboolean
_cmd_set_remind(const char * const inp, struct cmd_help_t help)
{
if ((strncmp(inp, "/remind ", 8) != 0) || (strlen(inp) < 9)) {
cons_show("Usage: %s", help.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);
if (period == 0) {
cons_show("Message reminders disabled.");
} else if (period == 1) {
cons_show("Message reminder period set to 1 second.");
} else {
cons_show("Message reminder period set to %d seconds.", period);
}
}
return TRUE;
}
static gboolean
_cmd_away(const char * const inp, struct cmd_help_t help)
{

View File

@ -290,7 +290,7 @@ _message_handler(xmpp_conn_t * const conn,
// if no message, check for chatstates
if (body == NULL) {
if (prefs_get_typing()) {
if (prefs_get_notify_typing()) {
if (xmpp_stanza_get_child_by_name(stanza, "active") != NULL) {
// active
} else if (xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) {

View File

@ -236,28 +236,41 @@ prefs_set_beep(gboolean value)
}
gboolean
prefs_get_notify(void)
prefs_get_notify_typing(void)
{
return g_key_file_get_boolean(prefs, "ui", "notify", NULL);
return g_key_file_get_boolean(prefs, "notifications", "typing", NULL);
}
void
prefs_set_notify(gboolean value)
prefs_set_notify_typing(gboolean value)
{
g_key_file_set_boolean(prefs, "ui", "notify", value);
g_key_file_set_boolean(prefs, "notifications", "typing", value);
_save_prefs();
}
gboolean
prefs_get_typing(void)
prefs_get_notify_message(void)
{
return g_key_file_get_boolean(prefs, "ui", "typing", NULL);
return g_key_file_get_boolean(prefs, "notifications", "message", NULL);
}
void
prefs_set_typing(gboolean value)
prefs_set_notify_message(gboolean value)
{
g_key_file_set_boolean(prefs, "ui", "typing", value);
g_key_file_set_boolean(prefs, "notifications", "message", value);
_save_prefs();
}
gint
prefs_get_notify_remind(void)
{
return g_key_file_get_integer(prefs, "notifications", "remind", NULL);
}
void
prefs_set_notify_remind(gint value)
{
g_key_file_set_integer(prefs, "notifications", "remind", value);
_save_prefs();
}
@ -313,19 +326,6 @@ prefs_set_history(gboolean value)
_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
prefs_add_login(const char *jid)
{

View File

@ -44,10 +44,6 @@ void prefs_reset_boolean_choice(void);
gboolean prefs_get_beep(void);
void prefs_set_beep(gboolean value);
gboolean prefs_get_notify(void);
void prefs_set_notify(gboolean value);
gboolean prefs_get_typing(void);
void prefs_set_typing(gboolean value);
gboolean prefs_get_flash(void);
void prefs_set_flash(gboolean value);
gboolean prefs_get_chlog(void);
@ -56,11 +52,16 @@ gboolean prefs_get_history(void);
void prefs_set_history(gboolean value);
gboolean prefs_get_showsplash(void);
void prefs_set_showsplash(gboolean value);
gint prefs_get_remind(void);
void prefs_set_remind(gint value);
gboolean prefs_get_vercheck(void);
void prefs_set_vercheck(gboolean value);
void prefs_set_notify_message(gboolean value);
gboolean prefs_get_notify_message(void);
void prefs_set_notify_typing(gboolean value);
gboolean prefs_get_notify_typing(void);
void prefs_set_notify_remind(gint period);
gint prefs_get_notify_remind(void);
void prefs_add_login(const char *jid);
NCURSES_COLOR_T prefs_get_bkgnd();

View File

@ -65,7 +65,7 @@ prof_run(const int disable_tls, char *log_level)
gdouble elapsed = g_timer_elapsed(timer, NULL);
gint remind_period = prefs_get_remind();
gint remind_period = prefs_get_notify_remind();
// 0 means to not remind
if (remind_period > 0 && elapsed >= remind_period) {

View File

@ -241,7 +241,7 @@ win_show_typing(const char * const from)
}
#ifdef HAVE_LIBNOTIFY
if (prefs_get_notify())
if (prefs_get_notify_typing())
_win_notify_typing(short_from);
#endif
}
@ -300,7 +300,7 @@ win_show_incomming_msg(const char * const from, const char * const message)
if (prefs_get_beep())
beep();
#ifdef HAVE_LIBNOTIFY
if (prefs_get_notify())
if (prefs_get_notify_message())
_win_notify_message(short_from);
#endif
}
@ -518,12 +518,12 @@ cons_prefs(void)
else
cons_show("Terminal flash : OFF");
if (prefs_get_notify())
if (prefs_get_notify_message())
cons_show("Message notifications : ON");
else
cons_show("Message notifications : OFF");
if (prefs_get_typing())
if (prefs_get_notify_typing())
cons_show("Typing notifications : ON");
else
cons_show("Typing notifications : OFF");
@ -548,7 +548,7 @@ cons_prefs(void)
else
cons_show("Version checking : OFF");
gint remind_period = prefs_get_remind();
gint remind_period = prefs_get_notify_remind();
if (remind_period == 0) {
cons_show("Message reminder period : OFF");
} else if (remind_period == 1) {