Move config file loading to config.c

This commit is contained in:
Sebastian Ramacher 2014-01-06 16:02:58 +01:00
parent 4350053956
commit 68b665a49d
4 changed files with 26 additions and 30 deletions

View File

@ -15,8 +15,12 @@
#include <girara/shortcuts.h>
#include <girara/config.h>
#include <girara/commands.h>
#include <girara/utils.h>
#include <glib/gi18n.h>
#define GLOBAL_RC "/etc/zathurarc"
#define ZATHURA_RC "zathurarc"
static void
cb_jumplist_change(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
@ -454,11 +458,25 @@ config_load_default(zathura_t* zathura)
}
void
config_load_file(zathura_t* zathura, const char* path)
config_load_files(zathura_t* zathura)
{
if (zathura == NULL || path == NULL) {
return;
/* load global configuration files */
char* config_path = girara_get_xdg_path(XDG_CONFIG_DIRS);
girara_list_t* config_dirs = girara_split_path_array(config_path);
ssize_t size = girara_list_size(config_dirs) - 1;
for (; size >= 0; --size) {
const char* dir = girara_list_nth(config_dirs, size);
char* file = g_build_filename(dir, ZATHURA_RC, NULL);
girara_config_parse(zathura->ui.session, file);
g_free(file);
}
girara_list_free(config_dirs);
g_free(config_path);
girara_config_parse(zathura->ui.session, path);
girara_config_parse(zathura->ui.session, GLOBAL_RC);
/* load local configuration files */
char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL);
girara_config_parse(zathura->ui.session, configuration_file);
g_free(configuration_file);
}

View File

@ -3,9 +3,6 @@
#ifndef CONFIG_H
#define CONFIG_H
#define GLOBAL_RC "/etc/zathurarc"
#define ZATHURA_RC "zathurarc"
#include "zathura.h"
/**
@ -21,6 +18,6 @@ void config_load_default(zathura_t* zathura);
* @param zathura The zathura session
* @param path Path to the configuration file
*/
void config_load_file(zathura_t* zathura, const char* path);
void config_load_files(zathura_t* zathura);
#endif // CONFIG_H

View File

@ -168,8 +168,8 @@ cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext*
static void
cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation),
GtkPrintContext* UNUSED(context), gint page_number, GtkPageSetup* setup,
zathura_t* zathura)
GtkPrintContext* UNUSED(context), gint page_number,
GtkPageSetup* setup, zathura_t* zathura)
{
if (zathura == NULL || zathura->document == NULL) {
return;

View File

@ -101,26 +101,7 @@ zathura_init(zathura_t* zathura)
/* configuration */
config_load_default(zathura);
/* load global configuration files */
char* config_path = girara_get_xdg_path(XDG_CONFIG_DIRS);
girara_list_t* config_dirs = girara_split_path_array(config_path);
ssize_t size = girara_list_size(config_dirs) - 1;
for (; size >= 0; --size) {
const char* dir = girara_list_nth(config_dirs, size);
char* file = g_build_filename(dir, ZATHURA_RC, NULL);
config_load_file(zathura, file);
g_free(file);
}
girara_list_free(config_dirs);
g_free(config_path);
config_load_file(zathura, GLOBAL_RC);
/* load local configuration files */
char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL);
config_load_file(zathura, configuration_file);
g_free(configuration_file);
config_load_files(zathura);
/* UI */
if (girara_session_init(zathura->ui.session, "zathura") == false) {