show an error when the rc config file cannot be parsed, and refuse to load
authorDana Jansens <danakj@orodu.net>
Sat, 2 Feb 2008 15:36:09 +0000 (10:36 -0500)
committerDana Jansens <danakj@orodu.net>
Sat, 2 Feb 2008 15:37:54 +0000 (10:37 -0500)
src/main.c
src/main.h
src/tree.c

index 2a42d3a..7083730 100644 (file)
@@ -46,7 +46,7 @@ gchar *obc_config_file = NULL;
 static gchar *obc_theme_install = NULL;
 static gchar *obc_theme_archive = NULL;
 
-void obconf_error(gchar *msg)
+void obconf_error(gchar *msg, gboolean modal)
 {
     GtkWidget *d;
 
@@ -55,10 +55,15 @@ void obconf_error(gchar *msg)
                                GTK_MESSAGE_ERROR,
                                GTK_BUTTONS_CLOSE,
                                "%s", msg);
-    g_signal_connect_swapped(GTK_OBJECT(d), "response",
-                             G_CALLBACK(gtk_widget_destroy),
-                             GTK_OBJECT(d));
-    gtk_widget_show(d);
+    gtk_window_set_title(GTK_WINDOW(d), "ObConf Error");
+    if (modal)
+        gtk_dialog_run(GTK_DIALOG(d));
+    else {
+        g_signal_connect_swapped(GTK_OBJECT(d), "response",
+                                 G_CALLBACK(gtk_widget_destroy),
+                                 GTK_OBJECT(d));
+        gtk_widget_show(d);
+    }
 }
 
 static void print_version()
@@ -186,6 +191,7 @@ static gboolean prop_get_string_utf8(Window win, Atom prop, gchar **ret)
 int main(int argc, char **argv)
 {
     gchar *p;
+    gboolean exit_with_error = FALSE;
 
     bindtextdomain(PACKAGE_NAME, LOCALEDIR);
     bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
@@ -204,9 +210,8 @@ int main(int argc, char **argv)
     g_free(p);
 
     if (!glade) {
-        obconf_error("Failed to load the obconf.glade interface file. You "
-                     "have probably failed to install ObConf properly.");
-        return 1;
+        obconf_error(_("Failed to load the obconf.glade interface file. You have probably failed to install ObConf properly."), TRUE);
+        exit_with_error = TRUE;
     }
 
     parse_paths_startup();
@@ -226,48 +231,63 @@ int main(int argc, char **argv)
 
     xmlIndentTreeOutput = 1;
     if (!parse_load_rc(obc_config_file, &doc, &root)) {
-        obconf_error("Failed to load an rc.xml. You have probably failed to "
-                     "install Openbox properly.");
-        return 1;
+        obconf_error(_("Failed to load an rc.xml. You have probably failed to install Openbox properly."), TRUE);
+        exit_with_error = TRUE;
     }
 
-    glade_xml_signal_autoconnect(glade);
-
+    /* look for parsing errors */
     {
-        gchar *s = g_strdup_printf
-            ("<span weight=\"bold\" size=\"xx-large\">ObConf %s</span>",
-             PACKAGE_VERSION);
-        gtk_label_set_markup(GTK_LABEL
-                             (glade_xml_get_widget(glade, "title_label")), s);
-        g_free(s);
+        xmlErrorPtr e = xmlGetLastError();
+        if (e) {
+            char *a = g_strdup_printf
+                (_("Error while parsing the Openbox configuration file.  Your configuration file is not valid XML.\n\nMessage: %s"),
+                 e->message);
+            obconf_error(a, TRUE);
+            g_free(a);
+            exit_with_error = TRUE;
+        }
     }
 
-    theme_setup_tab();
-    appearance_setup_tab();
-    windows_setup_tab();
-    moveresize_setup_tab();
-    mouse_setup_tab();
-    desktops_setup_tab();
-    margins_setup_tab();
-    dock_setup_tab();
-
-    mainwin = get_widget("main_window");
-
-    if (obc_theme_install)
-        theme_install(obc_theme_install);
-    else
-        theme_load_all();
-
-    /* the main window is not shown here ! it is shown when the theme previews
-       are completed */
-    gtk_main();
-
-    preview_update_set_active_font(NULL);
-    preview_update_set_inactive_font(NULL);
-    preview_update_set_menu_header_font(NULL);
-    preview_update_set_menu_item_font(NULL);
-    preview_update_set_osd_font(NULL);
-    preview_update_set_title_layout(NULL);
+    if (!exit_with_error) {
+        glade_xml_signal_autoconnect(glade);
+
+        {
+            gchar *s = g_strdup_printf
+                ("<span weight=\"bold\" size=\"xx-large\">ObConf %s</span>",
+                 PACKAGE_VERSION);
+            gtk_label_set_markup(GTK_LABEL
+                                 (glade_xml_get_widget(glade, "title_label")),
+                                 s);
+            g_free(s);
+        }
+
+        theme_setup_tab();
+        appearance_setup_tab();
+        windows_setup_tab();
+        moveresize_setup_tab();
+        mouse_setup_tab();
+        desktops_setup_tab();
+        margins_setup_tab();
+        dock_setup_tab();
+
+        mainwin = get_widget("main_window");
+
+        if (obc_theme_install)
+            theme_install(obc_theme_install);
+        else
+            theme_load_all();
+
+        /* the main window is not shown here ! it is shown when the theme
+           previews are completed */
+        gtk_main();
+
+        preview_update_set_active_font(NULL);
+        preview_update_set_inactive_font(NULL);
+        preview_update_set_menu_header_font(NULL);
+        preview_update_set_menu_item_font(NULL);
+        preview_update_set_osd_font(NULL);
+        preview_update_set_title_layout(NULL);
+    }
 
     RrInstanceFree(rrinst);
     parse_paths_shutdown();
index 91c5342..7d6303c 100644 (file)
@@ -35,7 +35,7 @@ extern gchar *obc_config_file;
 
 #define get_widget(s) glade_xml_get_widget(glade, s)
 
-void obconf_error(gchar *msg);
+void obconf_error(gchar *msg, gboolean model);
 void obconf_show_main();
 
 #endif
index 14214a9..2c0f2dc 100644 (file)
@@ -96,7 +96,7 @@ void tree_apply()
         gchar *s;
         s = g_strdup_printf("An error occured while saving the "
                             "config file '%s'", p);
-        obconf_error(s);
+        obconf_error(s, FALSE);
         g_free(s);
     }
     g_free(p);