about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--configure.ac8
-rwxr-xr-xinstall-all.sh4
-rw-r--r--src/main.c4
-rw-r--r--src/proIcon.pngbin0 -> 102058 bytes
-rw-r--r--src/proIconMsg.pngbin0 -> 56159 bytes
-rw-r--r--src/profanity.c6
-rw-r--r--src/tray.c81
-rw-r--r--src/tray.h41
9 files changed, 142 insertions, 5 deletions
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 <gtk/gtk.h>
 #include <string.h>
 #include <glib.h>
+#include <assert.h>
 
 #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
--- /dev/null
+++ b/src/proIcon.png
Binary files differdiff --git a/src/proIconMsg.png b/src/proIconMsg.png
new file mode 100644
index 00000000..2a0d78cf
--- /dev/null
+++ b/src/proIconMsg.png
Binary files differdiff --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 <gtk/gtk.h>
 #include <locale.h>
 #include <signal.h>
 #include <stdlib.h>
@@ -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 <petrodavi@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * 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 <gtk/gtk.h>
+#include <glib.h>
+#include <string.h>
+
+#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 <petrodavi@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * 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