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/tray.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/tray.h (limited to 'src/tray.h') 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 From 520eee23a9ddea98ede89bc372f60c720f3ee725 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 12 Mar 2016 16:55:52 +0100 Subject: fixing leakings --- src/tray.c | 31 +++++++++++++++++++++++++++---- src/tray.h | 9 +++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'src/tray.h') 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 -- cgit 1.4.1-2-gfad0 From 1e60d17d7c32194aa090f8d2ba7d5be4bffc0a44 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 30 Mar 2016 22:18:45 +0200 Subject: libgtk is now optional Having the lib is no more needed. --- configure.ac | 9 +++++++-- src/main.c | 16 ++++++++++++---- src/profanity.c | 32 +++++++++++++++++--------------- src/profanity.h | 2 +- src/tray.c | 6 +++++- src/tray.h | 2 +- 6 files changed, 43 insertions(+), 24 deletions(-) (limited to 'src/tray.h') diff --git a/configure.ac b/configure.ac index 2894ddef..13112c9f 100644 --- a/configure.ac +++ b/configure.ac @@ -62,6 +62,8 @@ AC_ARG_WITH([xscreensaver], [AS_HELP_STRING([--with-xscreensaver], [use libXScrnSaver to determine idle time])]) AC_ARG_WITH([themes], [AS_HELP_STRING([--with-themes[[=PATH]]], [install themes (default yes)])]) +AC_ARG_ENABLE([icons], + [AS_HELP_STRING([--enable-icons], [enable icons])]) ### plugins @@ -153,8 +155,11 @@ PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) # Checks GTK+ 2.0 -PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.24.10], [], - [AC_MSG_ERROR([gtk+-2.0 or higher is required for profanity])]) +PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.24.10], + [AC_DEFINE([HAVE_GTK], [1], [libgtk module])], + [AS_IF([test "x$enable_icons" = xyes], + [AC_MSG_ERROR([gtk+-2.0 or higher is required for icons])], + [AC_MSG_NOTICE([gtk+-2.0 not found, icons not enabled])])]) AS_IF([test "x$PLATFORM" != xosx], [AC_CHECK_LIB([readline], [main], [], diff --git a/src/main.c b/src/main.c index f080e063..242bf127 100644 --- a/src/main.c +++ b/src/main.c @@ -34,7 +34,9 @@ #include "prof_config.h" +#ifdef PROF_HAVE_GTK #include +#endif #include #include #include @@ -50,7 +52,6 @@ static gboolean version = FALSE; static char *log = "INFO"; static char *account_name = NULL; -static gboolean use_gtk = FALSE; int main(int argc, char **argv) @@ -139,14 +140,21 @@ main(int argc, char **argv) g_print("Python plugins: Disabled\n"); #endif +#ifdef PROF_HAVE_GTK + g_print("GTK icons: Enabled\n"); +#else + g_print("GTK icons: Disabled\n"); +#endif + return 0; } - use_gtk = gtk_init_check(&argc, &argv); - if (use_gtk) { +#ifdef PROF_HAVE_GTK + if (gtk_init_check(&argc, &argv)) { gtk_init(&argc, &argv); } - prof_run(log, account_name, use_gtk); +#endif + prof_run(log, account_name); return 0; } diff --git a/src/profanity.c b/src/profanity.c index 50f564c7..d6c39f06 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -37,7 +37,9 @@ #include "gitversion.h" #endif +#ifdef PROF_HAVE_GTK #include +#endif #include #include #include @@ -73,7 +75,9 @@ #include "window_list.h" #include "event/client_events.h" #include "config/tlscerts.h" +#ifdef PROF_HAVE_GTK #include "tray.h" +#endif static void _check_autoaway(void); static void _init(char *log_level); @@ -94,17 +98,15 @@ char *saved_status; static gboolean cont = TRUE; static gboolean force_quit = FALSE; -static gboolean gtk_enabled = FALSE; void -prof_run(char *log_level, char *account_name, gboolean use_gtk) +prof_run(char *log_level, char *account_name) { - gtk_enabled = use_gtk; _init(log_level); plugins_on_start(); - if (gtk_enabled) { - gtk_main_iteration_do(false); - } +#ifdef PROF_HAVE_GTK + gtk_main_iteration_do(false); +#endif _connect_default(account_name); ui_update(); @@ -137,9 +139,9 @@ prof_run(char *log_level, char *account_name, gboolean use_gtk) jabber_process_events(10); iq_autoping_check(); ui_update(); - if (gtk_enabled) { - gtk_main_iteration_do(false); - } +#ifdef PROF_HAVE_GTK + gtk_main_iteration_do(false); +#endif } } @@ -362,9 +364,9 @@ _init(char *log_level) #endif atexit(_shutdown); plugins_init(); - if (gtk_enabled) { - create_tray(); - } +#ifdef PROF_HAVE_GTK + create_tray(); +#endif inp_nonblocking(TRUE); } @@ -383,9 +385,9 @@ _shutdown(void) if (conn_status == JABBER_CONNECTED) { cl_ev_disconnect(); } - if (gtk_enabled) { - destroy_tray(); - } +#ifdef PROF_HAVE_GTK + destroy_tray(); +#endif jabber_shutdown(); plugins_on_shutdown(); muc_close(); diff --git a/src/profanity.h b/src/profanity.h index b32bbf17..7e128dc8 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -38,7 +38,7 @@ #include "resource.h" #include "xmpp/xmpp.h" -void prof_run(char *log_level, char *account_name, gboolean use_gtk); +void prof_run(char *log_level, char *account_name); void prof_handle_idle(void); void prof_handle_activity(void); diff --git a/src/tray.c b/src/tray.c index e227b68a..8b078adf 100644 --- a/src/tray.c +++ b/src/tray.c @@ -1,7 +1,7 @@ /* * tray.c * - * Copyright (C) 2012 - 2016 David Petroni + * Copyright (C) 2012 - 2016 James Booth * * This file is part of Profanity. * @@ -32,6 +32,9 @@ * */ +#include "prof_config.h" + +#ifdef PROF_HAVE_GTK #include #include #include @@ -156,3 +159,4 @@ void destroy_tray(void) } /* }}} */ +#endif diff --git a/src/tray.h b/src/tray.h index 6d12329f..416ca7d2 100644 --- a/src/tray.h +++ b/src/tray.h @@ -1,7 +1,7 @@ /* * tray.h * - * Copyright (C) 2012 - 2016 David Petroni + * Copyright (C) 2012 - 2016 James Booth * * This file is part of Profanity. * -- cgit 1.4.1-2-gfad0