about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorDavid <petrodavi@gmail.com>2016-02-19 23:59:14 +0100
committerDavid <petrodavi@gmail.com>2016-03-06 19:10:46 +0100
commitdc0c3cc699c1b91fbf3c9724f5039f3bd1ed0d95 (patch)
treec082118bbedf79911802bb58d19c741df2c4a271 /src
parentae46e647bf67e82b85f8a894be3c558aedb65f06 (diff)
downloadprofani-tty-dc0c3cc699c1b91fbf3c9724f5039f3bd1ed0d95.tar.gz
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.
Diffstat (limited to 'src')
-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
6 files changed, 132 insertions, 0 deletions
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