Open (and create) key file

This commit is contained in:
Moritz Lipp 2010-01-31 11:44:33 +01:00
parent 31672cd0ba
commit f3858ac26e

View file

@ -209,6 +209,11 @@ struct
int last;
} Marker;
struct
{
GKeyFile *file;
} Bookmarks;
struct
{
PopplerDocument *document;
@ -307,9 +312,28 @@ gboolean cb_inputbar_activate(GtkEntry*, gpointer);
void
init_directories()
{
/* create zathura directory */
gchar *base_directory = g_build_filename(g_get_home_dir(), ZATHURA_DIR, NULL);
g_mkdir_with_parents(base_directory, 0771);
g_free(base_directory);
/* create or open existing bookmark file */
Zathura.Bookmarks.file = g_key_file_new();
char* bookmarks = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, BOOKMARK_FILE);
if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
{
/* file does not exist */
g_file_set_contents(bookmarks, "# Zathura bookmarks", -1, NULL);
}
GError* error = NULL;
if(!g_key_file_load_from_file(Zathura.Bookmarks.file, bookmarks, G_KEY_FILE_KEEP_TRANSLATIONS, &error))
{
notify(ERROR, g_strdup_printf("Could not load bookmark file: %s", error->message));
}
g_free(bookmarks);
}
void