Replace the continuous_mode checkbox with a radiobutton group
[browser-switch] / config-ui / browser-switchboard-cp.c
index 06e97aa..616d7b3 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <errno.h>
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
@@ -42,6 +43,8 @@
 
 #include "configfile.h"
 
 
 #include "configfile.h"
 
+#define CONTINUOUS_MODE_DEFAULT 0
+
 struct browser_entry {
        char *config;
        char *displayname;
 struct browser_entry {
        char *config;
        char *displayname;
@@ -56,7 +59,8 @@ struct browser_entry browsers[] = {
 };
 
 struct config_widgets {
 };
 
 struct config_widgets {
-       GtkWidget *continuous_mode_check;
+       GtkWidget *continuous_mode_off_radio;
+       GtkWidget *continuous_mode_on_radio;
        GtkWidget *default_browser_combo;
        GtkWidget *other_browser_cmd_entry;
        GtkWidget *other_browser_cmd_entry_label;
        GtkWidget *default_browser_combo;
        GtkWidget *other_browser_cmd_entry;
        GtkWidget *other_browser_cmd_entry_label;
@@ -70,13 +74,16 @@ GtkWidget *dialog;
  **********************************************************************/
 
 static inline int get_continuous_mode(void) {
  **********************************************************************/
 
 static inline int get_continuous_mode(void) {
-       return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw.continuous_mode_check));
+       return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw.continuous_mode_on_radio));
 }
 static inline void set_continuous_mode(int state) {
 }
 static inline void set_continuous_mode(int state) {
-       return gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cw.continuous_mode_check), (gboolean)state);
+       if (state)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cw.continuous_mode_on_radio), TRUE);
+       else
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cw.continuous_mode_off_radio), TRUE);
 }
 
 }
 
-static inline char * get_default_browser(void) {
+static inline char *get_default_browser(void) {
        return browsers[gtk_combo_box_get_active(GTK_COMBO_BOX(cw.default_browser_combo))].config;
 }
 static void set_default_browser(char *browser) {
        return browsers[gtk_combo_box_get_active(GTK_COMBO_BOX(cw.default_browser_combo))].config;
 }
 static void set_default_browser(char *browser) {
@@ -93,7 +100,7 @@ static void set_default_browser(char *browser) {
        gtk_combo_box_set_active(GTK_COMBO_BOX(cw.default_browser_combo), i);
 }
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(cw.default_browser_combo), i);
 }
 
-static inline char * get_other_browser_cmd(void) {
+static inline char *get_other_browser_cmd(void) {
        return (char *)gtk_entry_get_text(GTK_ENTRY(cw.other_browser_cmd_entry));
 }
 static inline void set_other_browser_cmd(char *cmd) {
        return (char *)gtk_entry_get_text(GTK_ENTRY(cw.other_browser_cmd_entry));
 }
 static inline void set_other_browser_cmd(char *cmd) {
@@ -152,9 +159,19 @@ static void save_config(void) {
        int other_browser_cmd_seen = 0;
        struct swb_config_line line;
 
        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;
        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;
        len = strlen(homedir) + strlen(CONFIGFILE_LOC) + 1;
        if (!(newfile = calloc(len, sizeof(char))))
                return;
@@ -274,18 +291,20 @@ static void cancel_callback(GtkWidget *widget, gpointer data) {
  * Interface
  **********************************************************************/
 
  * Interface
  **********************************************************************/
 
-static GtkDialog * swb_config_dialog(void) {
+static GtkDialog *swb_config_dialog(void) {
        GtkWidget *dialog_vbox;
 
        GtkWidget *options_table;
        GtkWidget *default_browser_combo_label;
        GtkWidget *dialog_vbox;
 
        GtkWidget *options_table;
        GtkWidget *default_browser_combo_label;
+       GtkWidget *continuous_mode_label;
        int i;
 
        GtkWidget *action_area;
        GtkWidget *okbutton, *cancelbutton;
 
        dialog = gtk_dialog_new();
        int i;
 
        GtkWidget *action_area;
        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);
 
        gtk_window_set_title (GTK_WINDOW(dialog), "Browser Switchboard");
        gtk_window_set_type_hint (GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
 
@@ -293,8 +312,7 @@ static GtkDialog * swb_config_dialog(void) {
 
        /* Config options */
        options_table = gtk_table_new(3, 2, FALSE);
 
        /* Config options */
        options_table = gtk_table_new(3, 2, FALSE);
-       gtk_table_set_row_spacings(GTK_TABLE(options_table), 10);
-       gtk_table_set_col_spacings(GTK_TABLE(options_table), 10);
+       gtk_table_set_row_spacings(GTK_TABLE(options_table), 5);
        gtk_box_pack_start(GTK_BOX(dialog_vbox), options_table, FALSE, FALSE, 0);
 
        cw.default_browser_combo = gtk_combo_box_new_text();
        gtk_box_pack_start(GTK_BOX(dialog_vbox), options_table, FALSE, FALSE, 0);
 
        cw.default_browser_combo = gtk_combo_box_new_text();
@@ -303,7 +321,7 @@ static GtkDialog * swb_config_dialog(void) {
                                          browsers[i].displayname);
        gtk_combo_box_set_active(GTK_COMBO_BOX(cw.default_browser_combo), 0);
        default_browser_combo_label = gtk_label_new("Default browser:");
                                          browsers[i].displayname);
        gtk_combo_box_set_active(GTK_COMBO_BOX(cw.default_browser_combo), 0);
        default_browser_combo_label = gtk_label_new("Default browser:");
-       gtk_misc_set_alignment(GTK_MISC(default_browser_combo_label), 0, 0.5);
+       gtk_misc_set_alignment(GTK_MISC(default_browser_combo_label), 1, 0.5);
        g_signal_connect(G_OBJECT(cw.default_browser_combo), "changed",
                         G_CALLBACK(default_browser_combo_callback), NULL);
        gtk_table_attach(GTK_TABLE(options_table),
        g_signal_connect(G_OBJECT(cw.default_browser_combo), "changed",
                         G_CALLBACK(default_browser_combo_callback), NULL);
        gtk_table_attach(GTK_TABLE(options_table),
@@ -311,34 +329,60 @@ static GtkDialog * swb_config_dialog(void) {
                        0, 1,
                        0, 1,
                        GTK_FILL, GTK_FILL|GTK_EXPAND,
                        0, 1,
                        0, 1,
                        GTK_FILL, GTK_FILL|GTK_EXPAND,
-                       0, 0);
-       gtk_table_attach_defaults(GTK_TABLE(options_table),
+                       5, 0);
+       gtk_table_attach(GTK_TABLE(options_table),
                        cw.default_browser_combo,
                        1, 2,
                        cw.default_browser_combo,
                        1, 2,
-                       0, 1);
-       gtk_table_set_row_spacing(GTK_TABLE(options_table), 0, 5);
+                       0, 1,
+                       GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND,
+                       5, 0);
 
        cw.other_browser_cmd_entry = gtk_entry_new();
        cw.other_browser_cmd_entry_label = gtk_label_new("Command (%s for URI):");
 
        cw.other_browser_cmd_entry = gtk_entry_new();
        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), 0, 0.5);
+       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);
        gtk_widget_set_sensitive(cw.other_browser_cmd_entry_label, FALSE);
        gtk_table_attach(GTK_TABLE(options_table),
                        cw.other_browser_cmd_entry_label,
                        0, 1,
                        1, 2,
        gtk_widget_set_sensitive(cw.other_browser_cmd_entry, FALSE);
        gtk_widget_set_sensitive(cw.other_browser_cmd_entry_label, FALSE);
        gtk_table_attach(GTK_TABLE(options_table),
                        cw.other_browser_cmd_entry_label,
                        0, 1,
                        1, 2,
-                       0, GTK_FILL|GTK_EXPAND,
-                       0, 0);
-       gtk_table_attach_defaults(GTK_TABLE(options_table),
+                       GTK_FILL, GTK_FILL|GTK_EXPAND,
+                       5, 0);
+       gtk_table_attach(GTK_TABLE(options_table),
                        cw.other_browser_cmd_entry,
                        1, 2,
                        cw.other_browser_cmd_entry,
                        1, 2,
-                       1, 2);
-
-       cw.continuous_mode_check = gtk_check_button_new_with_label("Run browser launcher continuously in the background");
-       gtk_table_attach_defaults(GTK_TABLE(options_table),
-                       cw.continuous_mode_check,
+                       1, 2,
+                       GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND,
+                       5, 0);
+       gtk_table_set_row_spacing(GTK_TABLE(options_table), 1, 15);
+
+       continuous_mode_label = gtk_label_new("Optimize Browser Switchboard for:");
+       gtk_misc_set_alignment(GTK_MISC(continuous_mode_label), 0, 0.5);
+       cw.continuous_mode_off_radio = gtk_radio_button_new_with_label(NULL,
+                       "Lower memory usage");
+       cw.continuous_mode_on_radio = gtk_radio_button_new_with_label_from_widget(
+                       GTK_RADIO_BUTTON(cw.continuous_mode_off_radio),
+                       "Faster browser startup time");
+       set_continuous_mode(CONTINUOUS_MODE_DEFAULT);
+       gtk_table_attach(GTK_TABLE(options_table),
+                       continuous_mode_label,
+                       0, 2,
+                       2, 3,
+                       GTK_FILL, GTK_FILL|GTK_EXPAND,
+                       5, 0);
+       gtk_table_attach(GTK_TABLE(options_table),
+                       cw.continuous_mode_off_radio,
+                       0, 2,
+                       3, 4,
+                       GTK_FILL, GTK_FILL|GTK_EXPAND,
+                       20, 0);
+       gtk_table_attach(GTK_TABLE(options_table),
+                       cw.continuous_mode_on_radio,
                        0, 2,
                        0, 2,
-                       2, 3);
+                       4, 5,
+                       GTK_FILL, GTK_FILL|GTK_EXPAND,
+                       20, 5);
+       gtk_table_set_row_spacing(GTK_TABLE(options_table), 3, 0);
 
 
        /* Dialog buttons */
 
 
        /* Dialog buttons */
@@ -367,20 +411,17 @@ static GtkDialog * swb_config_dialog(void) {
 /*
  * Application was started from control panel.
  */
 /*
  * Application was started from control panel.
  */
-osso_return_t execute(osso_context_t * osso,
-                     gpointer userdata, gboolean user_activated)
-{
+osso_return_t execute(osso_context_t *osso,
+                     gpointer userdata, gboolean user_activated) {
        HildonProgram *program;
        HildonProgram *program;
+       GtkDialog *dialog;
+
        program = HILDON_PROGRAM(hildon_program_get_instance());
        program = HILDON_PROGRAM(hildon_program_get_instance());
-       
        if (osso == NULL)
                return OSSO_ERROR;
 
        if (osso == NULL)
                return OSSO_ERROR;
 
-       /* enable help system on dialog */
-       GtkDialog * dialog = GTK_DIALOG(swb_config_dialog());
-
+       dialog = GTK_DIALOG(swb_config_dialog());
        load_config();
        load_config();
-
        gtk_dialog_run(dialog);
        gtk_widget_destroy(GTK_WIDGET(dialog));
 
        gtk_dialog_run(dialog);
        gtk_widget_destroy(GTK_WIDGET(dialog));
 
@@ -390,8 +431,7 @@ osso_return_t execute(osso_context_t * osso,
 /*
  * Application was started from command line.
  */
 /*
  * Application was started from command line.
  */
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
        GtkDialog *dialog;
 #ifdef HILDON
        HildonProgram *program = NULL;
        GtkDialog *dialog;
 #ifdef HILDON
        HildonProgram *program = NULL;