Load configuration files

This commit is contained in:
Moritz Lipp 2011-04-01 09:55:37 +02:00
parent fdeb73436a
commit 3335e71ed8
3 changed files with 37 additions and 1 deletions

View File

@ -4,6 +4,7 @@
#include "completion.h"
#include "shortcuts.h"
#include "zathura.h"
#include "config.h"
void
config_load_default(void)
@ -11,15 +12,19 @@ config_load_default(void)
if (!Zathura.UI.session)
return;
int int_value = 0;
int int_value = 0;
char* string_value = NULL;
/* general settings */
girara_mode_set(Zathura.UI.session, NORMAL);
/* zathura settings */
string_value = CONFIG_DIR;
girara_setting_add(Zathura.UI.session, "config-dir", string_value, STRING, true, "Configuration directory", NULL);
int_value = 10;
girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL);
/* define default shortcuts */
girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL);
girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL);
@ -91,3 +96,13 @@ config_load_default(void)
girara_inputbar_command_add(Zathura.UI.session, "print", NULL, cmd_print, cc_print, "Print document");
girara_inputbar_command_add(Zathura.UI.session, "save", NULL, cmd_save, NULL, "Save document");
}
void
config_load_file(char* path)
{
if (Zathura.UI.session == NULL) {
return;
}
girara_config_parse(Zathura.UI.session, path);
}

View File

@ -3,9 +3,20 @@
#ifndef CONFIG_H
#define CONFIG_H
#define GLOBAL_RC "/etc/zathurarc"
#define ZATHURA_RC "zathurarc"
#define CONFIG_DIR "~/.config/zathura"
/**
* This function loads the default values of the configuration
*/
void config_load_default(void);
/**
* Loads and evaluates a configuration file
*
* @param path Path to the configuration file
*/
void config_load_file(char* path);
#endif // CONFIG_H

View File

@ -70,6 +70,16 @@ init_zathura()
/* configuration */
config_load_default();
/* load global configuration files */
config_load_file(GLOBAL_RC);
/* load local configuration files */
char* config_dir = girara_setting_get(Zathura.UI.session, "config-dir");
char* configuration_file = g_build_filename(config_dir ? config_dir : CONFIG_DIR, ZATHURA_RC, NULL);
config_load_file(configuration_file);
free(config_dir);
free(configuration_file);
return true;
error_free: