diff --git a/src/tray.c b/src/tray.c index f934d836..9bd45cf0 100644 --- a/src/tray.c +++ b/src/tray.c @@ -43,9 +43,19 @@ static GtkStatusIcon *prof_tray = NULL; static GString *icon_filename = NULL; static GString *icon_msg_filename = NULL; static gint unread_messages; -static bool shutting_down; +static gboolean shutting_down; static guint timer; +/* {{{ Privates */ + +/* + * Get icons from installation share folder or (if defined) .locale user's folder + * + * As implementation, looking through all the entries in the .locale folder is chosen. + * While useless as now, it might be useful in case an association name-icon is created. + * As now, with 2 icons only, this is pretty useless, but it is not harming ;) + * + */ static void _get_icons(void) { GString *icons_dir = NULL; @@ -74,26 +84,34 @@ static void _get_icons(void) GString *name = g_string_new(g_dir_read_name(dir)); while (name->len) { if (g_strcmp0("proIcon.png", name->str) == 0) { + g_string_free(icon_filename, true); icon_filename = g_string_new(icons_dir->str); g_string_append(icon_filename, "/proIcon.png"); } else if (g_strcmp0("proIconMsg.png", name->str) == 0){ + g_string_free(icon_msg_filename, true); icon_msg_filename = g_string_new(icons_dir->str); g_string_append(icon_msg_filename, "/proIconMsg.png"); } g_string_free(name, true); name = g_string_new(g_dir_read_name(dir)); } + g_string_free(name, true); } else { fprintf (stderr, "Unable to open dir: %s\n", err->message); g_error_free(err); } g_dir_close(dir); - g_free(err); g_string_free(icons_dir, true); } -gboolean tray_change_icon(gpointer data) +/* + * Callback for the timer + * + * This is the callback that the timer is calling in order to check if messages are there. + * + */ +gboolean _tray_change_icon(gpointer data) { if (shutting_down) { return false; @@ -110,12 +128,15 @@ gboolean tray_change_icon(gpointer data) return true; } +/* }}} */ +/* {{{ Public */ + void create_tray(void) { _get_icons(); prof_tray = gtk_status_icon_new_from_file(icon_filename->str); shutting_down = false; - timer = g_timeout_add(5000, tray_change_icon, NULL); + timer = g_timeout_add(5000, _tray_change_icon, NULL); } void destroy_tray(void) @@ -129,3 +150,5 @@ void destroy_tray(void) g_string_free(icon_filename, true); g_string_free(icon_msg_filename, true); } + +/* }}} */ diff --git a/src/tray.h b/src/tray.h index f1973382..6d12329f 100644 --- a/src/tray.h +++ b/src/tray.h @@ -35,7 +35,16 @@ #ifndef PROFANITY_TRAY_H #define PROFANITY_TRAY_H +/* + * Create tray icon + * + * This will initialize the timer that will be called in order to change the icons + * and will search the icons in the defaults paths + */ void create_tray(void); +/* + * Destroy tray icon + */ void destroy_tray(void); #endif