Try to create CONFIGFILE_DIR if it doesn't exist
[browser-switch] / config-ui / browser-switchboard-cp.c
index 66c9bdb..dad6b68 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <errno.h>
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
@@ -152,9 +153,19 @@ static void save_config(void) {
        int other_browser_cmd_seen = 0;
        struct swb_config_line line;
 
-       /* Put together the path to the new config file and the tempfile */
+       /* If CONFIGFILE_DIR doesn't exist already, try to create it */
        if (!(homedir = getenv("HOME")))
                homedir = DEFAULT_HOMEDIR;
+       len = strlen(homedir) + strlen(CONFIGFILE_DIR) + 1;
+       if (!(newfile = calloc(len, sizeof(char))))
+               return;
+       snprintf(newfile, len, "%s%s", homedir, CONFIGFILE_DIR);
+       if (access(newfile, F_OK) == -1 && errno == ENOENT) {
+               mkdir(newfile, 0750);
+       }
+       free(newfile);
+
+       /* Put together the path to the new config file and the tempfile */
        len = strlen(homedir) + strlen(CONFIGFILE_LOC) + 1;
        if (!(newfile = calloc(len, sizeof(char))))
                return;
@@ -285,7 +296,8 @@ static GtkDialog *swb_config_dialog(void) {
        GtkWidget *okbutton, *cancelbutton;
 
        dialog = gtk_dialog_new();
-       gtk_widget_set_size_request(GTK_WIDGET(dialog), 580, 240);
+       /* Doesn't seem to be necessary?
+          gtk_widget_set_size_request(GTK_WIDGET(dialog), 580, 180); */
        gtk_window_set_title (GTK_WINDOW(dialog), "Browser Switchboard");
        gtk_window_set_type_hint (GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);