Commit 9f5880aa authored by Moritz Lipp's avatar Moritz Lipp

Merge branch 'release/0.2.4'

parents 711405b1 45f105d2
......@@ -14,5 +14,7 @@ css-definitions.c
*.gcda
gcov/
*.swp
doc/
.version-checks/
doc/doxygen
build
tests/build
Copyright (c) 2010-2014 pwmt.org
Copyright (c) 2010-2015 pwmt.org
This software is provided 'as-is', without any express or implied warranty. In
no event will the authors be held liable for any damages arising from the use of
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
GIRARA_VERSION_MAJOR = 0
GIRARA_VERSION_MINOR = 2
GIRARA_VERSION_REV = 3
GIRARA_VERSION_REV = 4
VERSION = ${GIRARA_VERSION_MAJOR}.${GIRARA_VERSION_MINOR}.${GIRARA_VERSION_REV}
# Rules for the SOMAJOR and SOMINOR.
......@@ -12,12 +12,18 @@ VERSION = ${GIRARA_VERSION_MAJOR}.${GIRARA_VERSION_MINOR}.${GIRARA_VERSION_REV}
# * If any of the exported datastructures have changed in a incompatible way
# bump SOMAJOR and set SOMINOR to 0.
# * If a function has been added bump SOMINOR.
SOMAJOR = 1
SOMINOR = 1
SOMAJOR = 2
SOMINOR = 0
SOVERSION = ${SOMAJOR}.${SOMINOR}
# pkg-config binary
PKG_CONFIG ?= pkg-config
# libnotify
WITH_LIBNOTIFY ?= $(shell (pkg-config libnotify && echo 1) || echo 0)
WITH_LIBNOTIFY ?= $(shell (${PKG_CONFIG} libnotify --atleast-version=0.7.0 && echo 1) || echo 0)
# libjson-c
WITH_JSON ?= $(shell (${PKG_CONFIG} json-c --exists && echo 1) || echo 0)
# paths
PREFIX ?= /usr
......@@ -27,6 +33,14 @@ INCLUDEDIR ?= ${PREFIX}/include
# locale directory
LOCALEDIR ?= ${PREFIX}/share/locale
# build directories
DEPENDDIR ?= .depend
BUILDDIR ?= build
BUILDDIR_RELEASE ?= ${BUILDDIR}/release
BUILDDIR_DEBUG ?= ${BUILDDIR}/debug
BUILDDIR_GCOV ?= ${BUILDDIR}/gcov
BINDIR ?= bin
# version checks
# If you want to disable any of the checks, set *_VERSION_CHECK to 0.
......@@ -40,16 +54,21 @@ GLIB_MIN_VERSION = 2.28
GLIB_PKG_CONFIG_NAME = glib-2.0
# libs
GTK_INC ?= $(shell pkg-config --cflags gtk+-3.0)
GTK_LIB ?= $(shell pkg-config --libs gtk+-3.0)
GTK_INC ?= $(shell ${PKG_CONFIG} --cflags gtk+-3.0)
GTK_LIB ?= $(shell ${PKG_CONFIG} --libs gtk+-3.0)
ifneq (${WITH_LIBNOTIFY},0)
LIBNOTIFY_INC ?= $(shell pkg-config --cflags libnotify)
LIBNOTIFY_LIB ?= $(shell pkg-config --libs libnotify)
LIBNOTIFY_INC ?= $(shell ${PKG_CONFIG} --cflags libnotify)
LIBNOTIFY_LIB ?= $(shell ${PKG_CONFIG} --libs libnotify)
endif
ifneq (${WITH_JSON},0)
JSON_INC ?= $(shell ${PKG_CONFIG} --cflags json-c)
JSON_LIB ?= $(shell ${PKG_CONFIG} --libs json-c)
endif
INCS = ${GTK_INC} ${LIBNOTIFY_INC}
LIBS = ${GTK_LIB} ${LIBNOTIFY_LIB} -lm
INCS = ${GTK_INC} ${LIBNOTIFY_INC} ${JSON_INC}
LIBS = ${GTK_LIB} ${LIBNOTIFY_LIB} ${JSON_LIB} -lm
# flags
CFLAGS += -std=c99 -pedantic -Wall -Wextra -fPIC $(INCS)
......@@ -63,9 +82,16 @@ DFLAGS = -O0 -g
# compiler
CC ?= gcc
# archiver
AR ?= ar
# strip
SFLAGS ?= -s
# soname
SONAME_FLAG ?= -soname
SHARED_FLAG ?= -shared
# set to something != 0 if you want verbose build output
VERBOSE ?= 0
......@@ -75,9 +101,18 @@ GETTEXT_PACKAGE ?= lib${PROJECT}-${SOMAJOR}
# msgfmt
MSGFMT ?= msgfmt
# gcov & lcov
GCOV_CFLAGS=-fprofile-arcs -ftest-coverage
GCOV_LDFLAGS=-fprofile-arcs
LCOV_OUTPUT=gcov
LCOV_EXEC=lcov
LCOV_FLAGS=--base-directory . --directory ${BUILDDIR_GCOV} --capture --rc \
lcov_branch_coverage=1 --output-file ${BUILDDIR_GCOV}/$(PROJECT).info
GENHTML_EXEC=genhtml
GENHTML_FLAGS=--rc lcov_branch_coverage=1 --output-directory ${LCOV_OUTPUT} ${BUILDDIR_GCOV}/$(PROJECT).info
# colors
COLOR ?= 1
# dist
TARFILE = ${PROJECTNV}-${VERSION}.tar.gz
TARDIR = ${PROJECTNV}-${VERSION}
......@@ -97,3 +97,14 @@
padding: @bottombox-padding1@px @bottombox-padding2@px @bottombox-padding3@px
@bottombox-padding4@px;
}
#@session@ GtkScrolledWindow .undershoot.top,
#@session@ GtkScrolledWindow .undershoot.top:backdrop,
#@session@ GtkScrolledWindow .undershoot.bottom,
#@session@ GtkScrolledWindow .undershoot.bottom:backdrop,
#@session@ GtkScrolledWindow .undershoot.left,
#@session@ GtkScrolledWindow .undershoot.left:backdrop,
#@session@ GtkScrolledWindow .undershoot.right,
#@session@ GtkScrolledWindow .undershoot.right:backdrop {
background-color: transparent;
}
......@@ -2,7 +2,7 @@
# General information
PROJECT_NAME = girara
OUTPUT_DIRECTORY = ./doc/
OUTPUT_DIRECTORY = build
OUTPUT_LANGUAGE = English
TAB_SIZE = 2
EXTRACT_ALL = YES
......@@ -16,9 +16,9 @@ WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
# Input files
INPUT =
EXCLUDE = ./tests
FILE_PATTERNS = *.h *.c
INPUT = ../
EXCLUDE = ../tests
FILE_PATTERNS = *.h
RECURSIVE = YES
# Output files
......@@ -28,3 +28,6 @@ GENERATE_RTF = NO
GENERATE_XML = NO
SOURCE_BROWSER = YES
# HTML settings
HTML_TIMESTAMP = NO
# See LICENSE file for license and copyright information
include ../config.mk
include ../common.mk
include ../colors.mk
include config.mk
DOXYGEN_SOURCES=$(wildcard ../*.h) Doxyfile
all: html
html: ${DOXYGEN_BUILDDIR}/html/index.html
clean:
$(call colorecho,RM,doc/${DOXYGEN_BUILDDIR})
$(QUIET)rm -rf ${DOXYGEN_BUILDDIR}
${DOXYGEN_BUILDDIR}/html/index.html:
$(call colorecho,DOC,"Build HTML documentation")
$(QUIET)${DOXYGEN_BIN} Doxyfile
.PHONY: clean html all
# See LICENSE file for license and copyright information
DOXYGEN_BIN ?= doxygen
DOXYGEN_BUILDDIR ?= build
......@@ -50,18 +50,8 @@ cb_font(girara_session_t* session, const char* UNUSED(name),
{
g_return_if_fail(session != NULL && value != NULL);
GIRARA_IGNORE_DEPRECATED
pango_font_description_free(session->style.font);
/* parse font */
PangoFontDescription* font = pango_font_description_from_string(value);
session->style.font = font;
char* fontname = pango_font_description_to_string(session->style.font);
girara_template_set_variable_value(session->private_data->csstemplate, "font",
fontname);
g_free(fontname);
GIRARA_UNIGNORE
value);
}
static void
......@@ -280,11 +270,14 @@ girara_config_load_default(girara_session_t* session)
girara_inputbar_shortcut_add(session, GDK_CONTROL_MASK, GDK_KEY_n, girara_isc_command_history, GIRARA_NEXT, NULL);
/* commands */
girara_inputbar_command_add(session, "exec", NULL, girara_cmd_exec, NULL, _("Execute a command"));
girara_inputbar_command_add(session, "map", "m", girara_cmd_map, NULL, _("Map a key sequence"));
girara_inputbar_command_add(session, "quit", "q", girara_cmd_quit, NULL, _("Quit the program"));
girara_inputbar_command_add(session, "set", "s", girara_cmd_set, girara_cc_set, _("Set an option"));
girara_inputbar_command_add(session, "unmap", NULL, girara_cmd_unmap, NULL, _("Unmap a key sequence"));
girara_inputbar_command_add(session, "exec", NULL, girara_cmd_exec, NULL, _("Execute a command"));
girara_inputbar_command_add(session, "map", "m", girara_cmd_map, NULL, _("Map a key sequence"));
girara_inputbar_command_add(session, "quit", "q", girara_cmd_quit, NULL, _("Quit the program"));
girara_inputbar_command_add(session, "set", "s", girara_cmd_set, girara_cc_set, _("Set an option"));
girara_inputbar_command_add(session, "unmap", NULL, girara_cmd_unmap, NULL, _("Unmap a key sequence"));
#ifdef WITH_JSON
girara_inputbar_command_add(session, "dump", NULL, girara_cmd_dump_config, NULL, _("Dump settings to a file"));
#endif
/* config handle */
girara_config_handle_add(session, "map", girara_cmd_map);
......@@ -352,30 +345,31 @@ config_parse(girara_session_t* session, const char* path)
while ((line = girara_file_read_line(file)) != NULL) {
/* skip empty lines and comments */
if (strlen(line) == 0 || strchr(COMMENT_PREFIX, line[0]) != NULL) {
free(line);
g_free(line);
continue;
}
gchar** argv = NULL;
gint argc = 0;
girara_list_t* argument_list = girara_list_new();
if (argument_list == NULL) {
free(line);
g_free(line);
fclose(file);
return false;
}
girara_list_set_free_function(argument_list, g_free);
gchar** argv = NULL;
gint argc = 0;
if (g_shell_parse_argv(line, &argc, &argv, NULL) != FALSE) {
for(int i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
char* argument = g_strdup(argv[i]);
girara_list_append(argument_list, (void*) argument);
}
} else {
girara_list_free(argument_list);
fclose(file);
free(line);
g_free(line);
return false;
}
......@@ -399,7 +393,7 @@ config_parse(girara_session_t* session, const char* path)
girara_warning("Could not process line %d in '%s': trying to include itself.", line_number, path);
} else {
girara_debug("Loading config file '%s'.", newpath);
if (config_parse(session, newpath) == FALSE) {
if (config_parse(session, newpath) == false) {
girara_warning("Could not process line %d in '%s': failed to load '%s'.", line_number, path, newpath);
}
}
......@@ -426,7 +420,7 @@ config_parse(girara_session_t* session, const char* path)
line_number++;
girara_list_free(argument_list);
g_strfreev(argv);
free(line);
g_free(line);
}
fclose(file);
......
......@@ -52,6 +52,8 @@ HIDDEN void update_state_by_keyval(int *state, int keyval);
HIDDEN void widget_add_class(GtkWidget* widget, const char* styleclass);
HIDDEN void widget_remove_class(GtkWidget* widget, const char* styleclass);
/**
* Default complection function for the settings
*
......@@ -107,7 +109,8 @@ HIDDEN bool girara_cmd_set(girara_session_t* session,
/**
* Execute an external command
* * @param session The used girara session
*
* @param session The used girara session
* @param argument_list List of passed arguments
* @return TRUE No error occured
* @return FALSE An error occured
......@@ -115,6 +118,19 @@ HIDDEN bool girara_cmd_set(girara_session_t* session,
HIDDEN bool girara_cmd_exec(girara_session_t* session,
girara_list_t* argument_list);
#ifdef WITH_JSON
/**
* Dump current settings to a JSON file
*
* @param session The used girara session
* @param argument_list List of passed arguments
* @return TRUE No error occured
* @return FALSE An error occured
*/
HIDDEN bool girara_cmd_dump_config(girara_session_t* session,
girara_list_t* argument_list);
#endif
/**
* Process argument as a sequence of keys that were typed by the user
*
......
......@@ -89,67 +89,52 @@ fill_template_with_values(girara_session_t* session)
char* font = NULL;
girara_setting_get(session, "font", &font);
if (font != NULL) {
GIRARA_IGNORE_DEPRECATED
pango_font_description_free(session->style.font);
session->style.font = pango_font_description_from_string(font);
GIRARA_UNIGNORE
girara_template_set_variable_value(csstemplate, "font", font);
g_free(font);
}
GIRARA_IGNORE_DEPRECATED
if (session->style.font == NULL) {
girara_template_set_variable_value(csstemplate, "font", "monospace normal 9");
} else {
char* fontname = pango_font_description_to_string(session->style.font);
girara_template_set_variable_value(csstemplate, "font", fontname);
g_free(fontname);
}
GIRARA_UNIGNORE
girara_template_set_variable_value(csstemplate, "font", "monospace normal 9");
};
/* parse color values */
typedef struct color_setting_mapping_s {
const char* identifier;
GdkRGBA *color;
} color_setting_mapping_t;
GIRARA_IGNORE_DEPRECATED
const color_setting_mapping_t color_setting_mappings[] = {
{"default-fg", &(session->style.default_foreground)},
{"default-bg", &(session->style.default_background)},
{"inputbar-fg", &(session->style.inputbar_foreground)},
{"inputbar-bg", &(session->style.inputbar_background)},
{"statusbar-fg", &(session->style.statusbar_foreground)},
{"statusbar-bg", &(session->style.statusbar_background)},
{"completion-fg", &(session->style.completion_foreground)},
{"completion-bg", &(session->style.completion_background)},
{"completion-group-fg", &(session->style.completion_group_foreground)},
{"completion-group-bg", &(session->style.completion_group_background)},
{"completion-highlight-fg", &(session->style.completion_highlight_foreground)},
{"completion-highlight-bg", &(session->style.completion_highlight_background)},
{"notification-error-fg", &(session->style.notification_error_foreground)},
{"notification-error-bg", &(session->style.notification_error_background)},
{"notification-warning-fg", &(session->style.notification_warning_foreground)},
{"notification-warning-bg", &(session->style.notification_warning_background)},
{"notification-fg", &(session->style.notification_default_foreground)},
{"notification-bg", &(session->style.notification_default_background)},
{"tabbar-fg", &(session->style.tabbar_foreground)},
{"tabbar-bg", &(session->style.tabbar_background)},
{"tabbar-focus-fg", &(session->style.tabbar_focus_foreground)},
{"tabbar-focus-bg", &(session->style.tabbar_focus_background)},
const char* color_settings[] = {
"default-fg",
"default-bg",
"inputbar-fg",
"inputbar-bg",
"statusbar-fg",
"statusbar-bg",
"completion-fg",
"completion-bg",
"completion-group-fg",
"completion-group-bg",
"completion-highlight-fg",
"completion-highlight-bg",
"notification-error-fg",
"notification-error-bg",
"notification-warning-fg",
"notification-warning-bg",
"notification-fg",
"notification-bg",
"tabbar-fg",
"tabbar-bg",
"tabbar-focus-fg",
"tabbar-focus-bg",
};
GIRARA_UNIGNORE
for (size_t i = 0; i < LENGTH(color_setting_mappings); i++) {
for (size_t i = 0; i < LENGTH(color_settings); i++) {
char* tmp_value = NULL;
girara_setting_get(session, color_setting_mappings[i].identifier, &tmp_value);
girara_setting_get(session, color_settings[i], &tmp_value);
GdkRGBA color = { 0, 0, 0, 0 };
if (tmp_value != NULL) {
gdk_rgba_parse(color_setting_mappings[i].color, tmp_value);
gdk_rgba_parse(&color, tmp_value);
g_free(tmp_value);
}
char* color = gdk_rgba_to_string(color_setting_mappings[i].color);
girara_template_set_variable_value(csstemplate,
color_setting_mappings[i].identifier, color);
g_free(color);
char* colorstr = gdk_rgba_to_string(&color);
girara_template_set_variable_value(csstemplate, color_settings[i],
colorstr);
g_free(colorstr);
}
/* we want inputbar_entry the same height as notification_text and statusbar,
......@@ -283,7 +268,7 @@ girara_session_create()
gtk_box_set_homogeneous(session->gtk.inputbar_box, TRUE);
session->gtk.view = gtk_scrolled_window_new(NULL, NULL);
session->gtk.viewport = gtk_viewport_new(NULL, NULL);
#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 4
#if GTK_CHECK_VERSION(3, 4, 0)
gtk_widget_add_events(session->gtk.viewport, GDK_SCROLL_MASK);
#endif
session->gtk.statusbar = gtk_event_box_new();
......@@ -294,12 +279,6 @@ girara_session_create()
session->gtk.inputbar = gtk_event_box_new();
session->gtk.tabs = GTK_NOTEBOOK(gtk_notebook_new());
/* deprecated members */
GIRARA_IGNORE_DEPRECATED
session->settings = session->private_data->settings;
session->global.command_history = girara_get_command_history(session);
GIRARA_UNIGNORE
return session;
}
......@@ -310,7 +289,7 @@ girara_session_init(girara_session_t* session, const char* sessionname)
return false;
}
#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 4
#if GTK_CHECK_VERSION(3, 4, 0)
bool smooth_scroll = false;
girara_setting_get(session, "smooth-scroll", &smooth_scroll);
if (smooth_scroll) {
......@@ -327,11 +306,15 @@ girara_session_init(girara_session_t* session, const char* sessionname)
G_CALLBACK(css_template_changed), session);
/* window */
#ifdef GDK_WINDOWING_X11
if (session->gtk.embed != 0) {
session->gtk.window = gtk_plug_new(session->gtk.embed);
} else {
#endif
session->gtk.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
#ifdef GDK_WINDOWING_X11
}
#endif
gtk_widget_set_name(GTK_WIDGET(session->gtk.window),
session->private_data->session_name);
......@@ -475,8 +458,6 @@ girara_session_init(girara_session_t* session, const char* sessionname)
/* notification area */
widget_add_class(session->gtk.notification_area, "notification");
widget_add_class(session->gtk.notification_text, "notification");
gtk_style_context_save(gtk_widget_get_style_context(session->gtk.notification_area));
gtk_style_context_save(gtk_widget_get_style_context(session->gtk.notification_text));
/* set window size */
int window_width = 0;
......@@ -545,13 +526,6 @@ girara_session_destroy(girara_session_t* session)
{
g_return_val_if_fail(session != NULL, FALSE);
/* clean up style */
GIRARA_IGNORE_DEPRECATED
if (session->style.font != NULL) {
pango_font_description_free(session->style.font);
}
GIRARA_UNIGNORE
/* clean up shortcuts */
girara_list_free(session->bindings.shortcuts);
session->bindings.shortcuts = NULL;
......@@ -611,9 +585,6 @@ girara_session_destroy(girara_session_t* session)
/* clean up private data */
girara_session_private_free(session->private_data);
session->private_data = NULL;
GIRARA_IGNORE_DEPRECATED
session->settings = NULL;
GIRARA_UNIGNORE
/* clean up session */
g_slice_free(girara_session_t, session);
......@@ -699,21 +670,15 @@ girara_notify(girara_session_t* session, int level, const char* format, ...)
return;
}
GtkStyleContext* area_context = gtk_widget_get_style_context(session->gtk.notification_area);
GtkStyleContext* text_context = gtk_widget_get_style_context(session->gtk.notification_text);
gtk_style_context_restore(area_context);
gtk_style_context_restore(text_context);
gtk_style_context_save(area_context);
gtk_style_context_save(text_context);
bool error_class = false;
bool warning_class = false;
const char* cssclass = NULL;
switch (level) {
case GIRARA_ERROR:
cssclass = "notification-error";
error_class = true;
break;
case GIRARA_WARNING:
cssclass = "notification-warning";
warning_class = true;
break;
case GIRARA_INFO:
break;
......@@ -721,9 +686,19 @@ girara_notify(girara_session_t* session, int level, const char* format, ...)
return;
}
if (cssclass != NULL) {
widget_add_class(session->gtk.notification_area, cssclass);
widget_add_class(session->gtk.notification_text, cssclass);
if (error_class == true) {
widget_add_class(session->gtk.notification_area, "notification-error");
widget_add_class(session->gtk.notification_text, "notification-error");
} else {
widget_remove_class(session->gtk.notification_area, "notification-error");
widget_remove_class(session->gtk.notification_text, "notification-error");
}
if (warning_class == true) {
widget_add_class(session->gtk.notification_area, "notification-warning");
widget_add_class(session->gtk.notification_text, "notification-warning");
} else {
widget_remove_class(session->gtk.notification_area, "notification-warning");
widget_remove_class(session->gtk.notification_text, "notification-warning");
}
/* prepare message */
......
......@@ -8,7 +8,9 @@
#include "callbacks.h"
#include <gtk/gtk.h>
#ifdef GDK_WINDOWING_X11
#include <gtk/gtkx.h>
#endif
#include <gdk/gdkkeysyms.h>
struct girara_session_s
......@@ -30,36 +32,11 @@ struct girara_session_s
GtkEntry *inputbar_entry; /**< Inputbar entry */
GtkNotebook *tabs; /**< The tabs notebook */
GtkBox *results; /**< Completion results */
#ifdef GDK_WINDOWING_X11
Window embed; /**< Embedded window */
#endif
} gtk;
struct
{
GdkRGBA default_foreground; /**< The default foreground color */
GdkRGBA default_background; /**< The default background color */
GdkRGBA inputbar_foreground; /**< The foreground color of the inputbar */
GdkRGBA inputbar_background; /**< The background color of the inputbar */
GdkRGBA statusbar_foreground; /**< The foreground color of the statusbar */
GdkRGBA statusbar_background; /**< The background color of the statusbar */
GdkRGBA completion_foreground; /**< The foreground color of a completion item */
GdkRGBA completion_background; /**< The background color of a completion item */
GdkRGBA completion_group_foreground; /**< The foreground color of a completion group entry */
GdkRGBA completion_group_background; /**< The background color of a completion group entry */
GdkRGBA completion_highlight_foreground; /**< The foreground color of a highlighted completion item */
GdkRGBA completion_highlight_background; /**< The background color of a highlighted completion item */
GdkRGBA notification_error_foreground; /**< The foreground color of an error notification */
GdkRGBA notification_error_background; /**< The background color of an error notification */
GdkRGBA notification_warning_foreground; /**< The foreground color of a warning notification */
GdkRGBA notification_warning_background; /**< The background color of a warning notification */
GdkRGBA notification_default_foreground; /**< The foreground color of a default notification */
GdkRGBA notification_default_background; /**< The background color of a default notification */
GdkRGBA tabbar_foreground; /**< The foreground color for a tab */
GdkRGBA tabbar_background; /**< The background color for a tab */
GdkRGBA tabbar_focus_foreground; /**< The foreground color for a focused tab */
GdkRGBA tabbar_focus_background; /**< The background color for a focused tab */
PangoFontDescription *font; /**< The used font */
} GIRARA_DEPRECATED(style);
struct
{
girara_list_t* mouse_events; /**< List of mouse events */
......@@ -74,11 +51,6 @@ struct girara_session_s
girara_list_t* statusbar_items; /**< List of statusbar items */
} elements;
/**
* List of settings (deprecated)
*/
girara_list_t* GIRARA_DEPRECATED(settings);
struct
{
int inputbar_activate; /**< Inputbar activation */
......@@ -104,7 +76,6 @@ struct girara_session_s
{
GString *buffer; /**< Buffer */
void* data; /**< User data */
girara_list_t* GIRARA_DEPRECATED(command_history); /**< Command history (deprecated) */
bool autohide_inputbar; /**< Auto-hide inputbar */
bool hide_statusbar; /**< Hide statusbar */
} global;
......
......@@ -2,13 +2,18 @@
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <string.h>
#ifdef WITH_JSON
#include <json.h>
#endif
#include "settings.h"
#include "datastructures.h"
#include "completion.h"
#include "session.h"
#include "internal.h"
#include "utils.h"
/**
* Structure of a settings entry
......@@ -222,3 +227,73 @@ girara_cc_set(girara_session_t* session, const char* input)
return completion;
}
#ifdef WITH_JSON
bool
girara_cmd_dump_config(girara_session_t* session, girara_list_t* argument_list)
{
if (session == NULL || argument_list == NULL) {
return false;
}
const size_t number_of_arguments = girara_list_size(argument_list);
if (number_of_arguments != 1) {
girara_warning("Invalid number of arguments passed: %zu instead of 1",
number_of_arguments);
girara_notify(session, GIRARA_ERROR,
_("Invalid number of arguments passed: %zu instead of 1"),
number_of_arguments);
return false;
return false;
}
json_object* json_config = json_object_new_object();
GIRARA_LIST_FOREACH(session->private_data->settings, girara_setting_t*, iter, setting)
json_object* json_setting = json_object_new_object();
json_object* json_value = NULL;
json_object* json_type = NULL;
switch(setting->type) {
case BOOLEAN:
json_value = json_object_new_boolean(setting->value.b);
json_type = json_object_new_string("boolean");
break;
case FLOAT:
json_value = json_object_new_double(setting->value.f);
json_type = json_object_new_string("float");
break;
case INT:
json_value = json_object_new_int(setting->value.i);
json_type = json_object_new_string("int");
break;
case STRING:
json_value = json_object_new_string(setting->value.s ? setting->value.s : "");
json_type = json_object_new_string("string");
break;
default:
girara_debug("Invalid setting: %s", setting->name);
}
if (json_value != NULL) {
json_object_object_add(json_setting, "value", json_value);
json_object_object_add(json_setting, "type", json_type);
}
if (setting->description != NULL) {
json_object_object_add(json_setting, "description",
json_object_new_string(setting->description));
}