5 #include <glib/gi18n-lib.h>
16 #define COMMENT_PREFIX "\"#"
19 cb_window_icon(girara_session_t* session,
const char*
UNUSED(name),
22 g_return_if_fail(session != NULL && value != NULL);
24 if (session->gtk.window != NULL) {
26 gtk_window_set_icon_from_file(GTK_WINDOW(session->gtk.window), (
const char*) value, &error);
28 girara_error(
"failed to load window icon: %s", error->message);
35 cb_font(girara_session_t* session,
const char*
UNUSED(name),
38 g_return_if_fail(session != NULL && value != NULL);
40 pango_font_description_free(session->style.font);
43 PangoFontDescription* font = pango_font_description_from_string(value);
44 session->style.font = font;
47 if (session->gtk.inputbar_entry != NULL) {
48 gtk_widget_override_font(GTK_WIDGET(session->gtk.inputbar_entry), font);
51 if (session->gtk.inputbar_dialog != NULL) {
52 gtk_widget_override_font(GTK_WIDGET(session->gtk.inputbar_dialog), font);
56 if (session->gtk.notification_text != NULL) {
57 gtk_widget_override_font(GTK_WIDGET(session->gtk.notification_text), font);
60 GIRARA_LIST_FOREACH(session->elements.statusbar_items, girara_statusbar_item_t *, iter, item)
62 gtk_widget_override_font(GTK_WIDGET(item->text), font);
68 cb_guioptions(girara_session_t* session,
const char*
UNUSED(name),
71 g_return_if_fail(session != NULL && value != NULL);
74 bool show_commandline =
false;
75 bool show_statusbar =
false;
78 char* input = (
char*) value;
79 int input_length = strlen(input);
81 for (
int i = 0; i < input_length; i++) {
85 show_commandline =
true;
89 show_statusbar =
true;
95 if (show_commandline ==
true) {
96 session->global.autohide_inputbar =
false;
97 gtk_widget_show(session->gtk.inputbar);
99 session->global.autohide_inputbar =
true;
100 gtk_widget_hide(session->gtk.inputbar);
103 if (show_statusbar ==
true) {
104 session->global.hide_statusbar =
false;
105 gtk_widget_show(session->gtk.statusbar);
107 session->global.hide_statusbar =
true;
108 gtk_widget_hide(session->gtk.statusbar);
113 cb_scrollbars(girara_session_t* session,
const char*
UNUSED(name),
116 g_return_if_fail(session != NULL && value != NULL);
118 if (*(
bool*) value ==
true) {
119 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(session->gtk.view),
120 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
122 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(session->gtk.view),
123 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
130 if (session == NULL) {
135 int window_width = 800;
136 int window_height = 600;
137 int n_completion_items = 15;
138 bool show_scrollbars =
false;
142 session->global.autohide_inputbar =
true;
152 girara_setting_add(session,
"completion-fg",
"#DDDDDD",
STRING, TRUE, _(
"Completion foreground color"), NULL, NULL);
153 girara_setting_add(session,
"completion-bg",
"#232323",
STRING, TRUE, _(
"Completion background color"), NULL, NULL);
154 girara_setting_add(session,
"completion-group-fg",
"#DEDEDE",
STRING, TRUE, _(
"Completion group foreground color"), NULL, NULL);
155 girara_setting_add(session,
"completion-group-bg",
"#000000",
STRING, TRUE, _(
"Completion group background color"), NULL, NULL);
156 girara_setting_add(session,
"completion-highlight-fg",
"#232323",
STRING, TRUE, _(
"Completion highlight foreground color"), NULL, NULL);
157 girara_setting_add(session,
"completion-highlight-bg",
"#9FBC00",
STRING, TRUE, _(
"Completion highlight background color"), NULL, NULL);
158 girara_setting_add(session,
"notification-error-fg",
"#FFFFFF",
STRING, TRUE, _(
"Error notification foreground color"), NULL, NULL);
159 girara_setting_add(session,
"notification-error-bg",
"#FF1212",
STRING, TRUE, _(
"Error notification background color"), NULL, NULL);
160 girara_setting_add(session,
"notification-warning-fg",
"#000000",
STRING, TRUE, _(
"Warning notification foreground color"), NULL, NULL);
161 girara_setting_add(session,
"notification-warning-bg",
"#F3F000",
STRING, TRUE, _(
"Warning notifaction background color"), NULL, NULL);
162 girara_setting_add(session,
"notification-fg",
"#000000",
STRING, TRUE, _(
"Notification foreground color"), NULL, NULL);
163 girara_setting_add(session,
"notification-bg",
"#FFFFFF",
STRING, TRUE, _(
"Notification background color"), NULL, NULL);
166 girara_setting_add(session,
"tabbar-focus-fg",
"#9FBC00",
STRING, TRUE, _(
"Tab bar foreground color (active)"), NULL, NULL);
167 girara_setting_add(session,
"tabbar-focus-bg",
"#000000",
STRING, TRUE, _(
"Tab bar background color (active)"), NULL, NULL);
169 girara_setting_add(session,
"window-width", &window_width,
INT, TRUE, _(
"Initial window width"), NULL, NULL);
170 girara_setting_add(session,
"window-height", &window_height,
INT, TRUE, _(
"Initial window height"), NULL, NULL);
171 girara_setting_add(session,
"n-completion-items", &n_completion_items,
INT, TRUE, _(
"Number of completion items"), NULL, NULL);
172 girara_setting_add(session,
"show-scrollbars", &show_scrollbars,
BOOLEAN, FALSE, _(
"Show scrollbars"), cb_scrollbars, NULL);
175 girara_setting_add(session,
"guioptions",
"s",
STRING, FALSE, _(
"Show or hide certain GUI elements"), cb_guioptions, NULL);
232 g_return_val_if_fail(session != NULL,
false);
233 g_return_val_if_fail(identifier != NULL,
false);
237 if (strcmp(data->identifier, identifier) == 0) {
238 data->handle = handle;
245 girara_config_handle_t* config_handle = g_slice_new(girara_config_handle_t);
247 config_handle->identifier = g_strdup(identifier);
248 config_handle->handle = handle;
257 if (handle == NULL) {
261 g_free(handle->identifier);
262 g_slice_free(girara_config_handle_t, handle);
266 config_parse(girara_session_t* session,
const char* path)
277 unsigned int line_number = 1;
280 if (strlen(line) == 0 || strchr(
COMMENT_PREFIX, line[0]) != NULL) {
289 if (argument_list == NULL) {
296 if (g_shell_parse_argv(line, &argc, &argv, NULL) != FALSE) {
297 for(
int i = 1; i < argc; i++) {
298 char* argument = g_strdup(argv[i]);
309 if (strcmp(argv[0],
"include") == 0) {
311 girara_warning(
"Could not process line %d in '%s': usage: include path.", line_number, path);
313 char* newpath = NULL;
314 if (g_path_is_absolute(argv[1]) == TRUE) {
315 newpath = g_strdup(argv[1]);
317 char* basename = g_path_get_dirname(path);
318 char* tmp = g_build_filename(basename, argv[1], NULL);
324 if (strcmp(newpath, path) == 0) {
325 girara_warning(
"Could not process line %d in '%s': trying to include itself.", line_number, path);
328 if (config_parse(session, newpath) == FALSE) {
329 girara_warning(
"Could not process line %d in '%s': failed to load '%s'.", line_number, path, newpath);
336 girara_config_handle_t* handle = NULL;
339 if (strcmp(handle->identifier, argv[0]) == 0) {
340 handle->handle(session, argument_list);
347 if (handle == NULL) {
348 girara_warning(
"Could not process line %d in '%s': Unknown handle '%s'", line_number, path, argv[0]);
365 config_parse(session, path);