Commit fb4ff3cf authored by Sebastian Ramacher's avatar Sebastian Ramacher

Move config to private data

Signed-off-by: default avatarSebastian Ramacher <sebastian@ramacher.at>
parent f4bee430
......@@ -317,16 +317,18 @@ girara_cmd_map_unmap(girara_session_t* session, girara_list_t* argument_list,
}
}
girara_session_private_t* session_private = session->private_data;
/* Check for passed shortcut command */
if (unmap == false) {
bool found_mapping = false;
GIRARA_LIST_FOREACH(session->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, mapping)
GIRARA_LIST_FOREACH(session_private->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, mapping)
if (!g_strcmp0(tmp, mapping->identifier)) {
shortcut_function = mapping->function;
found_mapping = true;
break;
}
GIRARA_LIST_FOREACH_END(session->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, mapping);
GIRARA_LIST_FOREACH_END(session_private->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, mapping);
if (found_mapping == false) {
girara_warning("Not a valid shortcut function: %s", tmp);
......@@ -343,12 +345,12 @@ girara_cmd_map_unmap(girara_session_t* session, girara_list_t* argument_list,
if (++current_command < number_of_arguments) {
tmp = (char*) girara_list_nth(argument_list, current_command);
GIRARA_LIST_FOREACH(session->config.argument_mappings, girara_argument_mapping_t*, iter, mapping)
GIRARA_LIST_FOREACH(session_private->config.argument_mappings, girara_argument_mapping_t*, iter, mapping)
if (!g_strcmp0(tmp, mapping->identifier)) {
shortcut_argument_n = mapping->value;
break;
}
GIRARA_LIST_FOREACH_END(session->config.argument_mappings, girara_argument_mapping_t*, iter, mapping);
GIRARA_LIST_FOREACH_END(session_private->config.argument_mappings, girara_argument_mapping_t*, iter, mapping);
/* If no known argument is passed we save it in the data field */
if (shortcut_argument_n == 0) {
......
......@@ -283,21 +283,22 @@ girara_config_handle_add(girara_session_t* session, const char* identifier, gira
g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(identifier != NULL, false);
girara_session_private_t* session_private = session->private_data;
/* search for existing config handle */
GIRARA_LIST_FOREACH(session->config.handles, girara_config_handle_t*, iter, data)
GIRARA_LIST_FOREACH(session_private->config.handles, girara_config_handle_t*, iter, data)
if (strcmp(data->identifier, identifier) == 0) {
data->handle = handle;
girara_list_iterator_free(iter);
return true;
}
GIRARA_LIST_FOREACH_END(session->config.handles, girara_config_handle_t*, iter, data);
GIRARA_LIST_FOREACH_END(session_private->config.handles, girara_config_handle_t*, iter, data);
/* add new config handle */
girara_config_handle_t* config_handle = g_slice_new(girara_config_handle_t);
config_handle->identifier = g_strdup(identifier);
config_handle->handle = handle;
girara_list_append(session->config.handles, config_handle);
girara_list_append(session_private->config.handles, config_handle);
return true;
}
......@@ -385,8 +386,9 @@ config_parse(girara_session_t* session, const char* path)
}
} else {
/* search for config handle */
girara_session_private_t* session_private = session->private_data;
girara_config_handle_t* handle = NULL;
GIRARA_LIST_FOREACH(session->config.handles, girara_config_handle_t*, iter, tmp)
GIRARA_LIST_FOREACH(session_private->config.handles, girara_config_handle_t*, iter, tmp)
handle = tmp;
if (strcmp(handle->identifier, argv[0]) == 0) {
handle->handle(session, argument_list);
......@@ -394,7 +396,7 @@ config_parse(girara_session_t* session, const char* path)
} else {
handle = NULL;
}
GIRARA_LIST_FOREACH_END(session->config.handles, girara_config_handle_t*, iter, tmp);
GIRARA_LIST_FOREACH_END(session_private->config.handles, girara_config_handle_t*, iter, tmp);
if (handle == NULL) {
girara_warning("Could not process line %d in '%s': Unknown handle '%s'", line_number, path, argv[0]);
......
......@@ -289,6 +289,13 @@ struct girara_session_private_s
int n; /**< Numeric buffer */
GString *command; /**< Command in buffer */
} buffer;
struct
{
girara_list_t* handles;
girara_list_t* shortcut_mappings;
girara_list_t* argument_mappings;
} config;
};
#endif
......@@ -294,6 +294,8 @@ girara_session_create()
girara_session_t* session = g_slice_alloc0(sizeof(girara_session_t));
session->private_data = g_slice_alloc0(sizeof(girara_session_private_t));
girara_session_private_t* session_private = session->private_data;
/* init values */
session->bindings.mouse_events = girara_list_new2(
(girara_free_function_t) girara_mouse_event_free);
......@@ -306,11 +308,11 @@ girara_session_create()
session->bindings.inputbar_shortcuts = girara_list_new2(
(girara_free_function_t) girara_inputbar_shortcut_free);
session->private_data->elements.statusbar_items = girara_list_new2(
session_private->elements.statusbar_items = girara_list_new2(
(girara_free_function_t) girara_statusbar_item_free);
/* settings */
session->private_data->settings = girara_sorted_list_new2(
session_private->settings = girara_sorted_list_new2(
(girara_compare_function_t) cb_sort_settings,
(girara_free_function_t) girara_setting_free);
......@@ -323,12 +325,12 @@ girara_session_create()
css_data = g_resource_lookup_data(css_resource, "/org/pwmt/girara/CSS/girara-pre-3.20.css_t", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
}
if (css_data != NULL) {
session->private_data->csstemplate = girara_template_new(g_bytes_get_data(css_data, NULL));
session_private->csstemplate = girara_template_new(g_bytes_get_data(css_data, NULL));
g_bytes_unref(css_data);
}
session->private_data->gtk.cssprovider = NULL;
init_template_engine(session->private_data->csstemplate);
session_private->gtk.cssprovider = NULL;
init_template_engine(session_private->csstemplate);
/* init modes */
session->modes.identifiers = girara_list_new2(
......@@ -340,11 +342,11 @@ girara_session_create()
session->modes.inputbar = inputbar_mode;
/* config handles */
session->config.handles = girara_list_new2(
session_private->config.handles = girara_list_new2(
(girara_free_function_t) girara_config_handle_free);
session->config.shortcut_mappings = girara_list_new2(
session_private->config.shortcut_mappings = girara_list_new2(
(girara_free_function_t) girara_shortcut_mapping_free);
session->config.argument_mappings = girara_list_new2(
session_private->config.argument_mappings = girara_list_new2(
(girara_free_function_t) girara_argument_mapping_free);
/* command history */
......@@ -355,8 +357,8 @@ girara_session_create()
/* create widgets */
session->gtk.box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
session->private_data->gtk.overlay = gtk_overlay_new();
session->private_data->gtk.bottom_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
session_private->gtk.overlay = gtk_overlay_new();
session_private->gtk.bottom_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
session->gtk.statusbar_entries = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
session->gtk.inputbar_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
gtk_box_set_homogeneous(session->gtk.inputbar_box, TRUE);
......@@ -581,6 +583,18 @@ girara_session_private_free(girara_session_private_t* session)
g_free(session->session_name);
}
/* clean up config handles */
girara_list_free(session->config.handles);
session->config.handles = NULL;
/* clean up shortcut mappings */
girara_list_free(session->config.shortcut_mappings);
session->config.shortcut_mappings = NULL;
/* clean up argument mappings */
girara_list_free(session->config.argument_mappings);
session->config.argument_mappings = NULL;
/* clean up buffer */
if (session->buffer.command) {
g_string_free(session->buffer.command, TRUE);
......@@ -630,18 +644,6 @@ girara_session_destroy(girara_session_t* session)
/* clean up input histry */
g_clear_object(&session->command_history);
/* clean up config handles */
girara_list_free(session->config.handles);
session->config.handles = NULL;
/* clean up shortcut mappings */
girara_list_free(session->config.shortcut_mappings);
session->config.shortcut_mappings = NULL;
/* clean up argument mappings */
girara_list_free(session->config.argument_mappings);
session->config.argument_mappings = NULL;
/* clean up modes */
girara_list_free(session->modes.identifiers);
session->modes.identifiers = NULL;
......
......@@ -83,13 +83,6 @@ struct girara_session_s
girara_mode_t inputbar; /**< The inputbar mode */
} modes;
struct
{
girara_list_t* handles;
girara_list_t* shortcut_mappings;
girara_list_t* argument_mappings;
} config;
GiraraInputHistory* command_history; /**< Command history */
girara_session_private_t* private_data; /**< Private data of a girara session */
};
......
......@@ -587,20 +587,21 @@ girara_shortcut_mapping_add(girara_session_t* session, const char* identifier, g
return false;
}
GIRARA_LIST_FOREACH(session->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, data)
girara_session_private_t* session_private = session->private_data;
GIRARA_LIST_FOREACH(session_private->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, data)
if (strcmp(data->identifier, identifier) == 0) {
data->function = function;
girara_list_iterator_free(iter);
return true;
}
GIRARA_LIST_FOREACH_END(session->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, data);
GIRARA_LIST_FOREACH_END(session_private->config.shortcut_mappings, girara_shortcut_mapping_t*, iter, data);
/* add new config handle */
girara_shortcut_mapping_t* mapping = g_slice_new(girara_shortcut_mapping_t);
mapping->identifier = g_strdup(identifier);
mapping->function = function;
girara_list_append(session->config.shortcut_mappings, mapping);
girara_list_append(session_private->config.shortcut_mappings, mapping);
return true;
}
......@@ -625,20 +626,21 @@ girara_argument_mapping_add(girara_session_t* session, const char* identifier, i
return false;
}
GIRARA_LIST_FOREACH(session->config.argument_mappings, girara_argument_mapping_t*, iter, mapping);
girara_session_private_t* session_private = session->private_data;
GIRARA_LIST_FOREACH(session_private->config.argument_mappings, girara_argument_mapping_t*, iter, mapping);
if (g_strcmp0(mapping->identifier, identifier) == 0) {
mapping->value = value;
girara_list_iterator_free(iter);
return true;
}
GIRARA_LIST_FOREACH_END(session->config.argument_mappings, girara_argument_mapping_t*, iter, mapping);
GIRARA_LIST_FOREACH_END(session_private->config.argument_mappings, girara_argument_mapping_t*, iter, mapping);
/* add new config handle */
girara_argument_mapping_t* mapping = g_slice_new(girara_argument_mapping_t);
mapping->identifier = g_strdup(identifier);
mapping->value = value;
girara_list_append(session->config.argument_mappings, mapping);
girara_list_append(session_private->config.argument_mappings, mapping);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment