mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge remote-tracking branch 'pasis/iss323'
This commit is contained in:
commit
df345a2cfb
18
Makefile.am
18
Makefile.am
@ -79,8 +79,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
|
||||
@ -93,6 +93,10 @@ otr3_sources = \
|
||||
otr4_sources = \
|
||||
src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c
|
||||
|
||||
themes_sources = themes/*
|
||||
|
||||
man_sources = docs/profanity.1
|
||||
|
||||
if BUILD_OTR
|
||||
if BUILD_OTR3
|
||||
core_sources += $(otr3_sources)
|
||||
@ -106,6 +110,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
|
||||
@ -115,9 +123,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" >> $@
|
||||
|
14
configure.ac
14
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"
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user