From 2bf28d3b9de3ae3af076c569ffaccb66e13857f1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 26 Nov 2017 20:02:53 +0100 Subject: Use config file for image store pathname --- src/colloquium.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 4 deletions(-) (limited to 'src/colloquium.c') diff --git a/src/colloquium.c b/src/colloquium.c index 18f3b00..c5716d9 100644 --- a/src/colloquium.c +++ b/src/colloquium.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ struct _colloquium GtkApplication parent_instance; char *mydir; int first_run; + char *imagestore; }; @@ -56,7 +58,7 @@ static void colloquium_activate(GApplication *papp) Colloquium *app = COLLOQUIUM(papp); if ( !app->first_run ) { struct presentation *p; - p = new_presentation(); + p = new_presentation(app->imagestore); narrative_window_new(p, papp); } } @@ -116,17 +118,18 @@ GActionEntry app_entries[] = { }; -static void colloquium_open(GApplication *app, GFile **files, gint n_files, +static void colloquium_open(GApplication *papp, GFile **files, gint n_files, const gchar *hint) { int i; + Colloquium *app = COLLOQUIUM(papp); for ( i = 0; iimagestore); if ( load_presentation(p, uri) == 0 ) { - narrative_window_new(p, app); + narrative_window_new(p, papp); } else { fprintf(stderr, "Failed to load '%s'\n", uri); } @@ -141,11 +144,75 @@ static void colloquium_finalize(GObject *object) } +static void create_config(const char *filename) +{ + + FILE *fh; + fh = fopen(filename, "w"); + if ( fh == NULL ) { + fprintf(stderr, "Failed to create config\n"); + return; + } + + fprintf(fh, "imagestore: %s\n", + g_get_user_special_dir(G_USER_DIRECTORY_PICTURES)); + + fclose(fh); +} + + +static void chomp(char *s) +{ + size_t i; + + if ( !s ) return; + + for ( i=0; iimagestore = strdup(line+12); + } + + fclose(fh); +} + + +const char *colloquium_get_imagestore(Colloquium *app) +{ + return app->imagestore; +} + + static void colloquium_startup(GApplication *papp) { Colloquium *app = COLLOQUIUM(papp); GtkBuilder *builder; const char *configdir; + char *tmp; G_APPLICATION_CLASS(colloquium_parent_class)->startup(papp); @@ -324,6 +391,23 @@ static void colloquium_startup(GApplication *papp) fprintf(stderr, "Failed to create folder\n"); } } + + /* Read config file */ + tmp = malloc(strlen(app->mydir)+32); + if ( tmp != NULL ) { + + tmp[0] = '\0'; + strcat(tmp, app->mydir); + strcat(tmp, "/config"); + + /* Create default config file if it doesn't exist */ + if ( !g_file_test(tmp, G_FILE_TEST_EXISTS) ) { + create_config(tmp); + } + + read_config(tmp, app); + free(tmp); + } } -- cgit v1.2.3