diff --git a/Makefile.am b/Makefile.am index c61315f8..e737eafa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,7 +41,8 @@ core_sources = \ src/config/account.c src/config/account.h \ src/config/preferences.c src/config/preferences.h \ src/config/theme.c src/config/theme.h \ - src/config/scripts.c src/config/scripts.h + src/config/scripts.c src/config/scripts.h \ + src/tray.h src/tray.c unittest_sources = \ src/contact.c src/contact.h src/common.c \ diff --git a/configure.ac b/configure.ac index 6e63a480..68e83918 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,10 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], 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])]) + AS_IF([test "x$PLATFORM" != xosx], [AC_CHECK_LIB([readline], [main], [], [AC_MSG_ERROR([libreadline is required for profanity])])], @@ -208,9 +212,9 @@ AC_CHECK_HEADERS([ncurses.h], [], []) AM_CFLAGS="-Wall -Wno-deprecated-declarations" AS_IF([test "x$PACKAGE_STATUS" = xdevelopment], [AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"]) -AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS" +AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS ${GTK_CFLAGS}" AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" -LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS" +LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS ${GTK_LIBS}" AC_SUBST(AM_CFLAGS) AC_SUBST(AM_CPPFLAGS) diff --git a/install-all.sh b/install-all.sh index 0ea0817d..ac01a8d7 100755 --- a/install-all.sh +++ b/install-all.sh @@ -24,7 +24,7 @@ debian_prepare() echo echo Profanity installer... installing dependencies echo - sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libreadline-dev libtool libgpgme11-dev + sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libreadline-dev libtool libgpgme11-dev libgtk2.0-dev } @@ -34,7 +34,7 @@ fedora_prepare() echo Profanity installer... installing dependencies echo - sudo dnf -y install gcc git autoconf automake openssl-devel expat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr3-devel readline-devel libtool gpgme-devel + sudo dnf -y install gcc git autoconf automake openssl-devel expat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr3-devel readline-devel libtool gpgme-devel gtk2-devel } opensuse_prepare() 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