1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

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.
This commit is contained in:
David 2016-02-19 23:59:14 +01:00
parent ae46e647bf
commit dc0c3cc699
9 changed files with 142 additions and 5 deletions

View File

@ -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 \

View File

@ -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)

View File

@ -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()

View File

@ -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;

BIN
src/proIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

BIN
src/proIconMsg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View File

@ -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();

81
src/tray.c Normal file
View File

@ -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;
}
}

41
src/tray.h Normal file
View File

@ -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