From dc0c3cc699c1b91fbf3c9724f5039f3bd1ed0d95 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 19 Feb 2016 23:59:14 +0100 Subject: Introduce Tray Icon for Profanity Add tray icon for profanity based on Gtk StatusIcon. Different icon is displayed in case the user has unread messages. --- src/main.c | 4 +++ src/proIcon.png | Bin 0 -> 102058 bytes src/proIconMsg.png | Bin 0 -> 56159 bytes src/profanity.c | 6 ++++ src/tray.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/tray.h | 41 +++++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 src/proIcon.png create mode 100644 src/proIconMsg.png create mode 100644 src/tray.c create mode 100644 src/tray.h (limited to 'src') diff --git a/src/main.c b/src/main.c index ec745ff5..b863db96 100644 --- a/src/main.c +++ b/src/main.c @@ -34,8 +34,10 @@ #include "config.h" +#include #include #include +#include #ifdef HAVE_GIT_VERSION #include "gitversion.h" @@ -127,6 +129,8 @@ main(int argc, char **argv) return 0; } + assert (gtk_init_check(&argc, &argv) == true); + gtk_init(&argc, &argv); prof_run(log, account_name); return 0; diff --git a/src/proIcon.png b/src/proIcon.png new file mode 100644 index 00000000..b02687a3 Binary files /dev/null and b/src/proIcon.png differ diff --git a/src/proIconMsg.png b/src/proIconMsg.png new file mode 100644 index 00000000..2a0d78cf Binary files /dev/null and b/src/proIconMsg.png differ diff --git a/src/profanity.c b/src/profanity.c index 212705a4..bb5a994a 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -37,6 +37,7 @@ #include "gitversion.h" #endif +#include #include #include #include @@ -71,6 +72,7 @@ #include "window_list.h" #include "event/client_events.h" #include "config/tlscerts.h" +#include "tray.h" static void _check_autoaway(void); static void _init(char *log_level); @@ -96,6 +98,7 @@ void prof_run(char *log_level, char *account_name) { _init(log_level); + gtk_main_iteration_do(false); _connect_default(account_name); ui_update(); @@ -126,6 +129,7 @@ prof_run(char *log_level, char *account_name) jabber_process_events(10); iq_autoping_check(); ui_update(); + gtk_main_iteration_do(false); } } @@ -318,6 +322,7 @@ _init(char *log_level) prefs_load(); log_init(prof_log_level); log_stderr_init(PROF_LEVEL_ERROR); + create_tray(); if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION log_info("Starting Profanity (%sdev.%s.%s)...", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); @@ -366,6 +371,7 @@ _shutdown(void) cl_ev_disconnect(); } + destroy_tray(); jabber_shutdown(); muc_close(); caps_close(); diff --git a/src/tray.c b/src/tray.c new file mode 100644 index 00000000..966119c3 --- /dev/null +++ b/src/tray.c @@ -0,0 +1,81 @@ +/* + * tray.c + * + * Copyright (C) 2012 - 2016 David Petroni + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include +#include +#include + +#include "tray.h" +#include "window_list.h" + +static GtkStatusIcon *prof_tray = NULL; +static gchar *icon_filename = "src/proIcon.png"; +static gchar *icon_msg_filename = "src/proIconMsg.png"; +static int unread_messages; +static bool shutting_down; +static guint timer; + +gboolean tray_change_icon(gpointer data) +{ + if (shutting_down) { + return false; + } + + unread_messages = wins_get_total_unread(); + + if (unread_messages) { + gtk_status_icon_set_from_file(prof_tray, icon_msg_filename); + } else { + gtk_status_icon_set_from_file(prof_tray, icon_filename); + } + + return true; +} + +void create_tray(void) +{ + prof_tray = gtk_status_icon_new_from_file(icon_filename); + shutting_down = false; + timer = g_timeout_add(5000, tray_change_icon, NULL); +} + +void destroy_tray(void) +{ + shutting_down = true; + g_source_remove(timer); + if (prof_tray) { + gtk_widget_destroy(GTK_WIDGET(prof_tray)); + prof_tray = NULL; + } +} diff --git a/src/tray.h b/src/tray.h new file mode 100644 index 00000000..f1973382 --- /dev/null +++ b/src/tray.h @@ -0,0 +1,41 @@ +/* + * tray.h + * + * Copyright (C) 2012 - 2016 David Petroni + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#ifndef PROFANITY_TRAY_H +#define PROFANITY_TRAY_H + +void create_tray(void); +void destroy_tray(void); + +#endif -- cgit 1.4.1-2-gfad0