From 73437f2efd4b7a2d70e70ebda1e010d20e472f6b Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Tue, 8 Apr 2014 00:45:57 +0300 Subject: [PATCH 1/4] Makefile.am: fixed spacing --- Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 13f2d591..9b17247a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -76,8 +76,8 @@ tests_sources = \ tests/test_preferences.c \ tests/test_server_events.c \ tests/test_muc.c \ - tests/test_cmd_roster.c \ - tests/test_cmd_win.c \ + tests/test_cmd_roster.c \ + tests/test_cmd_win.c \ tests/testsuite.c main_source = src/main.c From 3ceb9b0d1d0854021cacfa0ed354e1ce5b27fb58 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Tue, 8 Apr 2014 00:46:43 +0300 Subject: [PATCH 2/4] autotools: install themes during 'make install' Default path for themes is ${pkgdatadir}/themes that usualy equals to /usr/share/profanity/themes. This patch also introduces new option --with-themes[=PATH] that specifies installation path. This option can be used for cancel of installation at all: --without-themes. References: issue #323 --- Makefile.am | 14 ++++++++++++++ configure.ac | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Makefile.am b/Makefile.am index 9b17247a..f9d04fde 100644 --- a/Makefile.am +++ b/Makefile.am @@ -90,6 +90,16 @@ otr3_sources = \ otr4_sources = \ src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c +themes_sources = \ + themes/aqua \ + themes/boothj5 \ + themes/hacker \ + themes/headache \ + themes/original \ + themes/redsplash \ + themes/whiteness \ + themes/yellowsplash + if BUILD_OTR if BUILD_OTR3 core_sources += $(otr3_sources) @@ -103,6 +113,10 @@ endif bin_PROGRAMS = profanity profanity_SOURCES = $(core_sources) $(main_source) +if THEMES_INSTALL +profanity_themesdir = @THEMES_PATH@ +profanity_themes_DATA = $(themes_sources) +endif if INCLUDE_GIT_VERSION BUILT_SOURCES = $(git_include) endif diff --git a/configure.ac b/configure.ac index 706cc0b4..83bdc8cb 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,8 @@ AC_ARG_WITH([libxml2], [AS_HELP_STRING([--with-libxml2], [link with libxml2 instead of expat])]) AC_ARG_WITH([xscreensaver], [AS_HELP_STRING([--with-xscreensaver], [use libXScrnSaver to determine idle time])]) +AC_ARG_WITH([themes], + [AS_HELP_STRING([--with-themes[[=PATH]]], [install themes (default yes)])]) ### Select first existing xml library among expat and libxml2 PARSER="" @@ -192,6 +194,15 @@ elif test "x$enable_otr" = x; then [AC_MSG_NOTICE([libotr not found, otr encryption support not enabled])]) fi +AS_IF([test "x$with_themes" = xno], + [THEMES_INSTALL="false"], + [THEMES_INSTALL="true"]) +AS_IF([test "x$with_themes" = xno -o "x$with_themes" = xyes -o "x$with_themes" = x], + [THEMES_PATH='${pkgdatadir}/themes'], + [THEMES_PATH="$with_themes"]) +AC_SUBST(THEMES_PATH) +AM_CONDITIONAL([THEMES_INSTALL], "$THEMES_INSTALL") + ### 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], [], @@ -206,6 +217,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" +AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"$THEMES_PATH\"" LIBS="$LIBS $glib_LIBS $curl_LIBS $libnotify_LIBS" AC_SUBST(AM_CFLAGS) @@ -225,5 +237,7 @@ echo "AM_CFLAGS : $AM_CFLAGS" echo "AM_CPPFLAGS : $AM_CPPFLAGS" echo "LIBS : $LIBS" echo "XML Parser : $PARSER" +echo "Install themes : $THEMES_INSTALL" +echo "Themes path : $THEMES_PATH" echo "" echo "Now you can run \`make' to build profanity" From aa6e2284fcfdc75ef457f3e6266e896633ef3d34 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 9 Apr 2014 01:52:53 +0300 Subject: [PATCH 3/4] config/theme: search for system-wide themes Search for system-wide themes (usually /usr/share/profanity/themes) if not found in user's home directory. Not tested yet. --- configure.ac | 2 +- src/config/theme.c | 162 +++++++++++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 71 deletions(-) diff --git a/configure.ac b/configure.ac index 83bdc8cb..13f7699e 100644 --- a/configure.ac +++ b/configure.ac @@ -217,7 +217,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" -AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"$THEMES_PATH\"" +AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" LIBS="$LIBS $glib_LIBS $curl_LIBS $libnotify_LIBS" AC_SUBST(AM_CFLAGS) diff --git a/src/config/theme.c b/src/config/theme.c index 3b07e3d9..14e7260c 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -103,44 +103,14 @@ static void _set_colour(gchar *val, NCURSES_COLOR_T *pref, NCURSES_COLOR_T def); static void _load_colours(void); static gchar * _get_themes_dir(void); +void _theme_list_dir(const gchar * const dir, GSList **result); +static GString * _theme_find(const char * const theme_name); void theme_init(const char * const theme_name) { - log_info("Loading theme"); - theme = g_key_file_new(); - - if (theme_name != NULL) { - gchar *themes_dir = _get_themes_dir(); - theme_loc = g_string_new(themes_dir); - g_free(themes_dir); - g_string_append(theme_loc, "/"); - g_string_append(theme_loc, theme_name); - g_key_file_load_from_file(theme, theme_loc->str, G_KEY_FILE_KEEP_COMMENTS, - NULL); - } - - _load_colours(); -} - -GSList * -theme_list(void) -{ - GSList *result = NULL; - gchar *themes_dir = _get_themes_dir(); - GDir *themes = g_dir_open(themes_dir, 0, NULL); - if (themes != NULL) { - const gchar *theme = g_dir_read_name(themes); - while (theme != NULL) { - result = g_slist_append(result, strdup(theme)); - theme = g_dir_read_name(themes); - } - - g_dir_close(themes); - return result; - - } else { - return NULL; + if (!theme_load(theme_name) && !theme_load("default")) { + log_error("Theme initialisation failed"); } } @@ -148,45 +118,54 @@ gboolean theme_load(const char * const theme_name) { // use default theme - if (strcmp(theme_name, "default") == 0) { - g_key_file_free(theme); - theme = g_key_file_new(); - _load_colours(); - return TRUE; - } else { - gchar *themes_dir = _get_themes_dir(); - GString *new_theme_file = g_string_new(themes_dir); - g_free(themes_dir); - g_string_append(new_theme_file, "/"); - g_string_append(new_theme_file, theme_name); - - // no theme file found - if (!g_file_test(new_theme_file->str, G_FILE_TEST_EXISTS)) { - log_info("Theme does not exist \"%s\"", theme_name); - g_string_free(new_theme_file, TRUE); - return FALSE; - - // load from theme file - } else { - if (theme_loc != NULL) { - g_string_free(theme_loc, TRUE); - } - theme_loc = new_theme_file; - log_info("Changing theme to \"%s\"", theme_name); + if (theme_name == NULL || strcmp(theme_name, "default") == 0) { + if (theme != NULL) { g_key_file_free(theme); - theme = g_key_file_new(); - g_key_file_load_from_file(theme, theme_loc->str, G_KEY_FILE_KEEP_COMMENTS, - NULL); - _load_colours(); - return TRUE; } + theme = g_key_file_new(); + + // load theme from file + } else { + GString *new_theme_file = _theme_find(theme_name); + if (new_theme_file == NULL) { + log_info("Theme does not exist \"%s\"", theme_name); + return FALSE; + } + + if (theme_loc != NULL) { + g_string_free(theme_loc, TRUE); + } + theme_loc = new_theme_file; + log_info("Loading theme \"%s\"", theme_name); + if (theme != NULL) { + g_key_file_free(theme); + } + theme = g_key_file_new(); + g_key_file_load_from_file(theme, theme_loc->str, G_KEY_FILE_KEEP_COMMENTS, + NULL); } + + _load_colours(); + return TRUE; +} + +GSList * +theme_list(void) +{ + GSList *result = NULL; + _theme_list_dir(_get_themes_dir(), &result); +#ifdef THEMES_PATH + _theme_list_dir(THEMES_PATH, &result); +#endif + return result; } void theme_close(void) { - g_key_file_free(theme); + if (theme != NULL) { + g_key_file_free(theme); + } if (theme_loc != NULL) { g_string_free(theme_loc, TRUE); } @@ -434,10 +413,53 @@ _get_themes_dir(void) { gchar *xdg_config = xdg_get_config_home(); GString *themes_dir = g_string_new(xdg_config); - g_string_append(themes_dir, "/profanity/themes"); - gchar *result = strdup(themes_dir->str); g_free(xdg_config); - g_string_free(themes_dir, TRUE); - - return result; + g_string_append(themes_dir, "/profanity/themes"); + return g_string_free(themes_dir, FALSE); +} + +void +_theme_list_dir(const gchar * const dir, GSList **result) +{ + GDir *themes = g_dir_open(dir, 0, NULL); + if (themes != NULL) { + const gchar *theme = g_dir_read_name(themes); + while (theme != NULL) { + *result = g_slist_append(*result, strdup(theme)); + theme = g_dir_read_name(themes); + } + g_dir_close(themes); + } +} + +static GString * +_theme_find(const char * const theme_name) +{ + GString *path = NULL; + gchar *themes_dir = _get_themes_dir(); + + if (themes_dir != NULL) { + path = g_string_new(themes_dir); + g_free(themes_dir); + g_string_append(path, "/"); + g_string_append(path, theme_name); + if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) { + g_string_free(path, true); + path = NULL; + } + } + +#ifdef THEMES_PATH + if (path == NULL) { + path = g_string_new(THEMES_PATH); + g_string_append(path, "/"); + g_string_append(path, theme_name); + if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) { + g_string_free(path, true); + path = NULL; + } + } +#endif /* THEMES_PATH */ + + return path; } From 0c1092fd30984918e6c70ccdc3b6ba5f79b08f57 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Thu, 17 Apr 2014 12:35:09 +0300 Subject: [PATCH 4/4] autotools: added EXTRA_DIST Now sources can be distributed with `make dist-bzip2` command, so no need to make tarball manually. Current patch takes into account the status (release or development) and puts .git/HEAD, .git/index to tarball if necessary. Unfortunately, current scripts don't add any information about development status to the version string. Therefore, profanity-0.5.0.tar.bz2 is got regardless of development or release status. --- Makefile.am | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index f9d04fde..2db0ef1f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -90,15 +90,9 @@ otr3_sources = \ otr4_sources = \ src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c -themes_sources = \ - themes/aqua \ - themes/boothj5 \ - themes/hacker \ - themes/headache \ - themes/original \ - themes/redsplash \ - themes/whiteness \ - themes/yellowsplash +themes_sources = themes/* + +man_sources = docs/profanity.1 if BUILD_OTR if BUILD_OTR3 @@ -126,9 +120,13 @@ check_PROGRAMS = tests/testsuite tests_testsuite_SOURCES = $(tests_sources) tests_testsuite_LDADD = -lcmocka -man_MANS = docs/profanity.1 +man_MANS = $(man_sources) + +EXTRA_DIST = $(man_sources) $(themes_sources) if INCLUDE_GIT_VERSION +EXTRA_DIST += .git/HEAD .git/index + $(git_include).in: .git/HEAD .git/index rm -f $@ echo "#ifndef PROF_GIT_BRANCH" >> $@