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

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2016-05-15 01:45:25 +01:00
commit 085cf5694f
7 changed files with 150 additions and 16 deletions

View File

@ -124,6 +124,7 @@ static char* _close_autocomplete(ProfWin *window, const char *const input);
static char* _plugins_autocomplete(ProfWin *window, const char *const input); static char* _plugins_autocomplete(ProfWin *window, const char *const input);
static char* _sendfile_autocomplete(ProfWin *window, const char *const input); static char* _sendfile_autocomplete(ProfWin *window, const char *const input);
static char* _blocked_autocomplete(ProfWin *window, const char *const input); static char* _blocked_autocomplete(ProfWin *window, const char *const input);
static char *_tray_autocomplete(ProfWin *window, const char *const input);
GHashTable *commands = NULL; GHashTable *commands = NULL;
@ -1412,17 +1413,21 @@ static struct cmd_t command_defs[] =
}, },
{ "/tray", { "/tray",
parse_args, 1, 1, &cons_tray_setting, parse_args, 1, 2, &cons_tray_setting,
CMD_NOSUBFUNCS CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_tray) CMD_MAINFUNC(cmd_tray)
CMD_TAGS( CMD_TAGS(
CMD_TAG_UI) CMD_TAG_UI)
CMD_SYN( CMD_SYN(
"/tray on|off") "/tray on|off",
"/tray read on|off",
"/tray timer <seconds>")
CMD_DESC( CMD_DESC(
"Display an icon in the tray that will indicate new messages.") "Display an icon in the tray that will indicate new messages.")
CMD_ARGS( CMD_ARGS(
{ "on|off", "Enable or disable tray icon." }) { "on|off", "Show tray icon." },
{ "read on|off", "Show tray icon when no unread messages." },
{ "timer <seconds>", "Set tray icon timer, seconds must be between 1-10" })
CMD_NOEXAMPLES CMD_NOEXAMPLES
}, },
@ -2299,6 +2304,7 @@ static Autocomplete plugins_ac;
static Autocomplete plugins_load_ac; static Autocomplete plugins_load_ac;
static Autocomplete sendfile_ac; static Autocomplete sendfile_ac;
static Autocomplete blocked_ac; static Autocomplete blocked_ac;
static Autocomplete tray_ac;
/* /*
* Initialise command autocompleter and history * Initialise command autocompleter and history
@ -2859,6 +2865,12 @@ cmd_init(void)
blocked_ac = autocomplete_new(); blocked_ac = autocomplete_new();
autocomplete_add(blocked_ac, "add"); autocomplete_add(blocked_ac, "add");
autocomplete_add(blocked_ac, "remove"); autocomplete_add(blocked_ac, "remove");
tray_ac = autocomplete_new();
autocomplete_add(tray_ac, "on");
autocomplete_add(tray_ac, "off");
autocomplete_add(tray_ac, "read");
autocomplete_add(tray_ac, "timer");
} }
void void
@ -2950,6 +2962,7 @@ cmd_uninit(void)
autocomplete_free(plugins_load_ac); autocomplete_free(plugins_load_ac);
autocomplete_free(sendfile_ac); autocomplete_free(sendfile_ac);
autocomplete_free(blocked_ac); autocomplete_free(blocked_ac);
autocomplete_free(tray_ac);
} }
gboolean gboolean
@ -3180,6 +3193,7 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(autoping_ac); autocomplete_reset(autoping_ac);
autocomplete_reset(plugins_ac); autocomplete_reset(plugins_ac);
autocomplete_reset(blocked_ac); autocomplete_reset(blocked_ac);
autocomplete_reset(tray_ac);
autocomplete_reset(script_ac); autocomplete_reset(script_ac);
if (script_show_ac) { if (script_show_ac) {
autocomplete_free(script_show_ac); autocomplete_free(script_show_ac);
@ -3358,7 +3372,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
// autocomplete boolean settings // autocomplete boolean settings
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog",
"/history", "/vercheck", "/privileges", "/presence", "/wrap", "/winstidy", "/carbons", "/encwarn", "/history", "/vercheck", "/privileges", "/presence", "/wrap", "/winstidy", "/carbons", "/encwarn",
"/lastactivity", "/tray" }; "/lastactivity" };
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice);
@ -3475,6 +3489,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
g_hash_table_insert(ac_funcs, "/plugins", _plugins_autocomplete); g_hash_table_insert(ac_funcs, "/plugins", _plugins_autocomplete);
g_hash_table_insert(ac_funcs, "/sendfile", _sendfile_autocomplete); g_hash_table_insert(ac_funcs, "/sendfile", _sendfile_autocomplete);
g_hash_table_insert(ac_funcs, "/blocked", _blocked_autocomplete); g_hash_table_insert(ac_funcs, "/blocked", _blocked_autocomplete);
g_hash_table_insert(ac_funcs, "/tray", _tray_autocomplete);
int len = strlen(input); int len = strlen(input);
char parsed[len+1]; char parsed[len+1];
@ -3534,6 +3549,23 @@ _sub_autocomplete(ProfWin *window, const char *const input)
return NULL; return NULL;
} }
static char*
_tray_autocomplete(ProfWin *window, const char *const input)
{
char *result = NULL;
result = autocomplete_param_with_func(input, "/tray read", prefs_autocomplete_boolean_choice);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/tray", tray_ac, FALSE);
if (result) {
return result;
}
return NULL;
}
static char* static char*
_who_autocomplete(ProfWin *window, const char *const input) _who_autocomplete(ProfWin *window, const char *const input)
{ {

View File

@ -5865,6 +5865,47 @@ gboolean
cmd_tray(ProfWin *window, const char *const command, gchar **args) cmd_tray(ProfWin *window, const char *const command, gchar **args)
{ {
#ifdef HAVE_GTK #ifdef HAVE_GTK
if (g_strcmp0(args[0], "timer") == 0) {
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
return TRUE;
}
if (prefs_get_boolean(PREF_TRAY) == FALSE) {
cons_show("Tray icon not currently enabled, see /help tray");
return TRUE;
}
int intval = 0;
char *err_msg = NULL;
gboolean res = strtoi_range(args[1], &intval, 1, 10, &err_msg);
if (res) {
cons_show("Tray timer set to %d seconds.", intval);
prefs_set_tray_timer(intval);
if (prefs_get_boolean(PREF_TRAY)) {
tray_set_timer(intval);
}
} else {
cons_show(err_msg);
free(err_msg);
}
return TRUE;
} else if (g_strcmp0(args[0], "read") == 0) {
if (prefs_get_boolean(PREF_TRAY) == FALSE) {
cons_show("Tray icon not currently enabled, see /help tray");
} else if (g_strcmp0(args[1], "on") == 0) {
prefs_set_boolean(PREF_TRAY_READ, TRUE);
cons_show("Tray icon enabled when no unread messages.");
} else if (g_strcmp0(args[1], "off") == 0) {
prefs_set_boolean(PREF_TRAY_READ, FALSE);
cons_show("Tray icon disabled when no unread messages.");
} else {
cons_bad_cmd_usage(command);
}
return TRUE;
} else {
gboolean old = prefs_get_boolean(PREF_TRAY); gboolean old = prefs_get_boolean(PREF_TRAY);
_cmd_set_boolean_preference(args[0], command, "Tray icon", PREF_TRAY); _cmd_set_boolean_preference(args[0], command, "Tray icon", PREF_TRAY);
gboolean new = prefs_get_boolean(PREF_TRAY); gboolean new = prefs_get_boolean(PREF_TRAY);
@ -5875,7 +5916,9 @@ cmd_tray(ProfWin *window, const char *const command, gchar **args)
tray_disable(); tray_disable();
} }
} }
return TRUE; return TRUE;
}
#else #else
cons_show("This version of Profanity has not been built with GTK Tray Icon support enabled"); cons_show("This version of Profanity has not been built with GTK Tray Icon support enabled");
return TRUE; return TRUE;

View File

@ -591,6 +591,25 @@ prefs_set_autoxa_time(gint value)
_save_prefs(); _save_prefs();
} }
void
prefs_set_tray_timer(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "tray.timer", value);
_save_prefs();
}
gint
prefs_get_tray_timer(void)
{
gint result = g_key_file_get_integer(prefs, PREF_GROUP_NOTIFICATIONS, "tray.timer", NULL);
if (result == 0) {
return 5;
} else {
return result;
}
}
gchar** gchar**
prefs_get_plugins(void) prefs_get_plugins(void)
{ {
@ -1242,6 +1261,7 @@ _get_group(preference_t pref)
case PREF_NOTIFY_MENTION_CASE_SENSITIVE: case PREF_NOTIFY_MENTION_CASE_SENSITIVE:
case PREF_NOTIFY_MENTION_WHOLE_WORD: case PREF_NOTIFY_MENTION_WHOLE_WORD:
case PREF_TRAY: case PREF_TRAY:
case PREF_TRAY_READ:
return PREF_GROUP_NOTIFICATIONS; return PREF_GROUP_NOTIFICATIONS;
case PREF_CHLOG: case PREF_CHLOG:
case PREF_GRLOG: case PREF_GRLOG:
@ -1294,6 +1314,8 @@ _get_key(preference_t pref)
return "flash"; return "flash";
case PREF_TRAY: case PREF_TRAY:
return "tray"; return "tray";
case PREF_TRAY_READ:
return "tray.read";
case PREF_INTYPE: case PREF_INTYPE:
return "intype"; return "intype";
case PREF_HISTORY: case PREF_HISTORY:
@ -1507,6 +1529,7 @@ _get_default_boolean(preference_t pref)
case PREF_TLS_SHOW: case PREF_TLS_SHOW:
case PREF_LASTACTIVITY: case PREF_LASTACTIVITY:
case PREF_NOTIFY_MENTION_WHOLE_WORD: case PREF_NOTIFY_MENTION_WHOLE_WORD:
case PREF_TRAY_READ:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

View File

@ -53,6 +53,7 @@ typedef enum {
PREF_TITLEBAR_GOODBYE, PREF_TITLEBAR_GOODBYE,
PREF_FLASH, PREF_FLASH,
PREF_TRAY, PREF_TRAY,
PREF_TRAY_READ,
PREF_INTYPE, PREF_INTYPE,
PREF_HISTORY, PREF_HISTORY,
PREF_CARBONS, PREF_CARBONS,
@ -223,6 +224,9 @@ void prefs_set_roster_presence_indent(gint value);
void prefs_add_login(const char *jid); void prefs_add_login(const char *jid);
void prefs_set_tray_timer(gint value);
gint prefs_get_tray_timer(void);
gboolean prefs_add_alias(const char *const name, const char *const value); gboolean prefs_add_alias(const char *const name, const char *const value);
gboolean prefs_remove_alias(const char *const name); gboolean prefs_remove_alias(const char *const name);
char* prefs_get_alias(const char *const name); char* prefs_get_alias(const char *const name);

View File

@ -131,10 +131,23 @@ _tray_change_icon(gpointer data)
unread_messages = wins_get_total_unread(); unread_messages = wins_get_total_unread();
if (unread_messages) { if (unread_messages) {
if (!prof_tray) {
prof_tray = gtk_status_icon_new_from_file(icon_msg_filename->str);
} else {
gtk_status_icon_set_from_file(prof_tray, icon_msg_filename->str); gtk_status_icon_set_from_file(prof_tray, icon_msg_filename->str);
}
} else {
if (prefs_get_boolean(PREF_TRAY_READ)) {
if (!prof_tray) {
prof_tray = gtk_status_icon_new_from_file(icon_filename->str);
} else { } else {
gtk_status_icon_set_from_file(prof_tray, icon_filename->str); gtk_status_icon_set_from_file(prof_tray, icon_filename->str);
} }
} else {
g_clear_object(&prof_tray);
prof_tray = NULL;
}
}
return TRUE; return TRUE;
} }
@ -179,13 +192,22 @@ tray_shutdown(void)
g_string_free(icon_msg_filename, TRUE); g_string_free(icon_msg_filename, TRUE);
} }
void
tray_set_timer(int interval)
{
g_source_remove(timer);
_tray_change_icon(NULL);
timer = g_timeout_add(interval * 1000, _tray_change_icon, NULL);
}
void void
tray_enable(void) tray_enable(void)
{ {
prof_tray = gtk_status_icon_new_from_file(icon_filename->str); prof_tray = gtk_status_icon_new_from_file(icon_filename->str);
shutting_down = FALSE; shutting_down = FALSE;
_tray_change_icon(NULL); _tray_change_icon(NULL);
timer = g_timeout_add(5000, _tray_change_icon, NULL); int interval = prefs_get_tray_timer() * 1000;
timer = g_timeout_add(interval, _tray_change_icon, NULL);
} }
void void

View File

@ -51,4 +51,6 @@ void tray_enable(void);
*/ */
void tray_disable(void); void tray_disable(void);
void tray_set_timer(int interval);
#endif #endif

View File

@ -1188,6 +1188,14 @@ cons_tray_setting(void)
cons_show("Tray icon (/tray) : ON"); cons_show("Tray icon (/tray) : ON");
else else
cons_show("Tray icon (/tray) : OFF"); cons_show("Tray icon (/tray) : OFF");
if (prefs_get_boolean(PREF_TRAY_READ))
cons_show("Tray icon read (/tray) : ON");
else
cons_show("Tray icon read (/tray) : OFF");
int seconds = prefs_get_tray_timer();
cons_show("Tray timer (/tray) : %d seconds", seconds);
} }
void void