Make "Web" menu entry and /usr/bin/browser open the default browser
[browser-switch] / config-ui / browser-switchboard-cp.c
index 1846a46..c34778b 100644 (file)
@@ -2,7 +2,8 @@
  * browser-switchboard-cp.c -- a hildon-control-panel applet for
  * selecting the default browser for Browser Switchboard
  * 
- * Copyright (C) 2009 Steven Luo
+ * Copyright (C) 2009-2010 Steven Luo
+ * Copyright (C) 2009-2010 Faheem Pervez
  * 
  * Derived from services-cp.c from maemo-control-services
  * Copyright (c) 2008 Janne Kataja <janne.kataja@iki.fi>
@@ -71,6 +72,8 @@ struct browser_entry browsers[] = {
        { NULL, NULL },
 };
 
+char *logger_name = NULL;
+
 struct config_widgets {
 #if defined(HILDON) && defined(FREMANTLE)
        GtkWidget *continuous_mode_selector;
@@ -168,20 +171,25 @@ static void load_config(void) {
                                        set_continuous_mode(atoi(line.value));
                                        continuous_mode_seen = 1;
                                }
+                               free(line.value);
                        } else if (!strcmp(line.key, "default_browser")) {
                                if (!default_browser_seen) {
                                        set_default_browser(line.value);
                                        default_browser_seen = 1;
                                }
+                               free(line.value);
                        } else if (!strcmp(line.key, "other_browser_cmd")) {
                                if (!other_browser_cmd_seen) {
                                        set_other_browser_cmd(line.value);
                                        other_browser_cmd_seen = 1;
                                }
+                               free(line.value);
+                       } else if (!strcmp(line.key, "logging")) {
+                               if (!logger_name)
+                                       logger_name = line.value;
                        }
                }
                free(line.key);
-               free(line.value);
        }
        parse_config_file_end();
 
@@ -260,6 +268,15 @@ static void save_config(void) {
                                                        get_other_browser_cmd());
                                                other_browser_cmd_seen = 1;
                                        }
+                               } else if (!strcmp(line.key,
+                                                       "logging")) {
+                                       if (logger_name) {
+                                               fprintf(tmpfp, "%s = \"%s\"\n",
+                                                       line.key,
+                                                       logger_name);
+                                               free(logger_name);
+                                               logger_name = NULL;
+                                       }
                                }
                        } else {
                                /* Just copy the old line over */
@@ -281,6 +298,9 @@ static void save_config(void) {
        if (!other_browser_cmd_seen && strlen(get_other_browser_cmd()) > 0)
                fprintf(tmpfp, "%s = \"%s\"\n",
                        "other_browser_cmd", get_other_browser_cmd());
+       if (logger_name)
+               fprintf(tmpfp, "%s = \"%s\"\n",
+                       "logging", logger_name);
 
        /* Replace the old config file with the new one */
        fclose(tmpfp);
@@ -301,7 +321,7 @@ static void do_reconfig(void) {
        save_config();
 
        /* Try to send SIGHUP to any running browser-switchboard process
-          This causes it to reread config files if in continuous_mode, and
+          This causes it to reread config files if in continuous_mode, or
           die so that the config will be reloaded on next start otherwise */
        system("kill -HUP `pidof browser-switchboard` > /dev/null 2>&1");
 }
@@ -374,9 +394,10 @@ static GtkDialog *swb_config_dialog(gpointer cp_window) {
                           default_browser_selector_button, FALSE, FALSE, 0);
 
        cw.other_browser_cmd_entry = hildon_entry_new(_HILDON_SIZE_DEFAULT);
+       /* Disable autocapitalization and dictionary features for the entry */
        input_mode = hildon_gtk_entry_get_input_mode(GTK_ENTRY(cw.other_browser_cmd_entry));
-       input_mode &= ~HILDON_GTK_INPUT_MODE_AUTOCAP;
-       input_mode &= ~HILDON_GTK_INPUT_MODE_DICTIONARY;
+       input_mode &= ~(HILDON_GTK_INPUT_MODE_AUTOCAP |
+                       HILDON_GTK_INPUT_MODE_DICTIONARY);
        hildon_gtk_entry_set_input_mode(GTK_ENTRY(cw.other_browser_cmd_entry), input_mode);
 
        cw.other_browser_cmd_entry_label = hildon_caption_new(NULL,
@@ -418,6 +439,9 @@ static GtkDialog *swb_config_dialog(gpointer cp_window) {
        GtkWidget *default_browser_combo_label;
        GtkWidget *continuous_mode_label;
        int i;
+#ifdef HILDON
+       HildonGtkInputMode input_mode;
+#endif
 
        dialog = gtk_dialog_new_with_buttons(
                "Browser Switchboard",
@@ -459,6 +483,13 @@ static GtkDialog *swb_config_dialog(gpointer cp_window) {
                        5, 0);
 
        cw.other_browser_cmd_entry = gtk_entry_new();
+#ifdef HILDON
+       /* Disable autocapitalization and dictionary features for the entry */
+       input_mode = hildon_gtk_entry_get_input_mode(GTK_ENTRY(cw.other_browser_cmd_entry));
+       input_mode &= ~(HILDON_GTK_INPUT_MODE_AUTOCAP |
+                       HILDON_GTK_INPUT_MODE_DICTIONARY);
+       hildon_gtk_entry_set_input_mode(GTK_ENTRY(cw.other_browser_cmd_entry), input_mode);
+#endif
        cw.other_browser_cmd_entry_label = gtk_label_new("Command (%s for URI):");
        gtk_misc_set_alignment(GTK_MISC(cw.other_browser_cmd_entry_label), 1, 0.5);
        gtk_widget_set_sensitive(cw.other_browser_cmd_entry, FALSE);