From 718a708b93102827dfe04ecb63b2331a6a949406 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 7 Mar 2016 22:25:30 +0100 Subject: [PATCH] Use a folder to add icons NOTE: it is not working in this release, I have to get how to retrieve icons from folder. --- Makefile.am | 6 +++++- configure.ac | 6 +++++- {src => icons}/proIcon.png | Bin {src => icons}/proIconMsg.png | Bin src/profanity.c | 6 ++++++ src/tray.c | 28 +++++++++++++++++++++++----- 6 files changed, 39 insertions(+), 7 deletions(-) rename {src => icons}/proIcon.png (100%) rename {src => icons}/proIconMsg.png (100%) diff --git a/Makefile.am b/Makefile.am index e737eafa..5cbc77f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -140,6 +140,8 @@ otr_unittest_sources = \ themes_sources = themes/* +icons_sources = icons/* + script_sources = bootstrap.sh configure-debug install-all.sh man_sources = docs/profanity.1 @@ -168,6 +170,8 @@ endif if INCLUDE_GIT_VERSION BUILT_SOURCES = $(git_include) endif +profanity_iconsdir = @ICONS_PATH@ +profanity_icons_DATA = $(icons_sources) TESTS = tests/unittests/unittests check_PROGRAMS = tests/unittests/unittests @@ -187,7 +191,7 @@ endif man_MANS = $(man_sources) -EXTRA_DIST = $(man_sources) $(themes_sources) $(script_sources) profrc.example LICENSE.txt +EXTRA_DIST = $(man_sources) $(icons_sources) $(themes_sources) $(script_sources) profrc.example LICENSE.txt if INCLUDE_GIT_VERSION EXTRA_DIST += .git/HEAD .git/index diff --git a/configure.ac b/configure.ac index 68e83918..ee4a4707 100644 --- a/configure.ac +++ b/configure.ac @@ -192,6 +192,9 @@ AS_IF([test "x$with_themes" = xno -o "x$with_themes" = xyes -o "x$with_themes" = AC_SUBST(THEMES_PATH) AM_CONDITIONAL([THEMES_INSTALL], "$THEMES_INSTALL") +ICONS_PATH='${pkgdatadir}/icons' +AC_SUBST(ICONS_PATH) + ### cmocka is required only for tests, profanity shouldn't be linked with it ### TODO: pass cmocka_CFLAGS and cmocka_LIBS to Makefile.am PKG_CHECK_MODULES([cmocka], [cmocka], [], @@ -213,7 +216,7 @@ 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 ${GTK_CFLAGS}" -AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" +AM_CPPFLAGS="$AM_CPPFLAGS -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\" -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS ${GTK_LIBS}" AC_SUBST(AM_CFLAGS) @@ -234,5 +237,6 @@ echo "LIBS : $LIBS" echo "XML Parser : $PARSER" echo "Install themes : $THEMES_INSTALL" echo "Themes path : $THEMES_PATH" +echo "Icons path : $ICONS_PATH" echo "" echo "Now you can run \`make' to build profanity" diff --git a/src/proIcon.png b/icons/proIcon.png similarity index 100% rename from src/proIcon.png rename to icons/proIcon.png diff --git a/src/proIconMsg.png b/icons/proIconMsg.png similarity index 100% rename from src/proIconMsg.png rename to icons/proIconMsg.png diff --git a/src/profanity.c b/src/profanity.c index bb5a994a..528e40a9 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -403,6 +403,8 @@ _create_directories(void) GString *themes_dir = g_string_new(xdg_config); g_string_append(themes_dir, "/profanity/themes"); + GString *icons_dir = g_string_new(xdg_config); + g_string_append(icons_dir, "/profanity/icons"); GString *chatlogs_dir = g_string_new(xdg_data); g_string_append(chatlogs_dir, "/profanity/chatlogs"); GString *logs_dir = g_string_new(xdg_data); @@ -411,6 +413,9 @@ _create_directories(void) if (!mkdir_recursive(themes_dir->str)) { log_error("Error while creating directory %s", themes_dir->str); } + if (!mkdir_recursive(icons_dir->str)) { + log_error("Error while creating directory %s", icons_dir->str); + } if (!mkdir_recursive(chatlogs_dir->str)) { log_error("Error while creating directory %s", chatlogs_dir->str); } @@ -419,6 +424,7 @@ _create_directories(void) } g_string_free(themes_dir, TRUE); + g_string_free(icons_dir, TRUE); g_string_free(chatlogs_dir, TRUE); g_string_free(logs_dir, TRUE); diff --git a/src/tray.c b/src/tray.c index 966119c3..c02b3dc7 100644 --- a/src/tray.c +++ b/src/tray.c @@ -40,12 +40,22 @@ #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 GString *icon_filename = NULL; +static GString *icon_msg_filename = NULL; static int unread_messages; static bool shutting_down; static guint timer; +static gchar* +_get_icons_dir(void) +{ + gchar *xdg_config = xdg_get_config_home(); + GString *icons_dir = g_string_new(xdg_config); + g_free(xdg_config); + g_string_append(icons_dir, "/profanity/icons"); + return g_string_free(icons_dir, true); +} + gboolean tray_change_icon(gpointer data) { if (shutting_down) { @@ -55,9 +65,9 @@ gboolean tray_change_icon(gpointer data) unread_messages = wins_get_total_unread(); if (unread_messages) { - gtk_status_icon_set_from_file(prof_tray, icon_msg_filename); + gtk_status_icon_set_from_file(prof_tray, icon_msg_filename->str); } else { - gtk_status_icon_set_from_file(prof_tray, icon_filename); + gtk_status_icon_set_from_file(prof_tray, icon_filename->str); } return true; @@ -65,9 +75,15 @@ gboolean tray_change_icon(gpointer data) void create_tray(void) { - prof_tray = gtk_status_icon_new_from_file(icon_filename); + gchar *icons_dir = _get_icons_dir(); + icon_filename = g_string_new(icons_dir); + icon_msg_filename = g_string_new(icons_dir); + g_string_append(icon_filename, "/proIcon.png"); + g_string_append(icon_msg_filename, "/proIconMsg.png"); + prof_tray = gtk_status_icon_new_from_file(icon_filename->str); shutting_down = false; timer = g_timeout_add(5000, tray_change_icon, NULL); + g_free(icons_dir); } void destroy_tray(void) @@ -78,4 +94,6 @@ void destroy_tray(void) gtk_widget_destroy(GTK_WIDGET(prof_tray)); prof_tray = NULL; } + g_string_free(icon_filename, false); + g_string_free(icon_msg_filename, false); }