Readd webpage
[browser-switch] / config-ui / browser-switchboard-cp.c
index 7096b5c..7d462f5 100644 (file)
@@ -43,6 +43,8 @@
 
 #include "configfile.h"
 
+#define CONTINUOUS_MODE_DEFAULT 0
+
 struct browser_entry {
        char *config;
        char *displayname;
@@ -57,7 +59,8 @@ struct browser_entry browsers[] = {
 };
 
 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;
@@ -71,10 +74,13 @@ GtkWidget *dialog;
  **********************************************************************/
 
 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) {
-       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) {
@@ -251,6 +257,16 @@ out:
        return;
 }
 
+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
+          die so that the config will be reloaded on next start otherwise */
+       system("kill -HUP `pidof browser-switchboard` > /dev/null 2>&1");
+}
+
+
 /**********************************************************************
  * Callbacks
  **********************************************************************/
@@ -265,47 +281,34 @@ static void default_browser_combo_callback(GtkWidget *widget, gpointer data) {
        }
 }
 
-static inline void close_dialog(void) {
-       gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_NONE);
-}
-
-static void ok_callback(GtkWidget *widget, gpointer data) {
-       save_config();
-       /* TODO: is there any cleanup necessary? */
-       close_dialog();
-}
-
-static void cancel_callback(GtkWidget *widget, gpointer data) {
-       /* TODO: is there any cleanup necessary? */
-       close_dialog();
-}
-
 
 /**********************************************************************
  * Interface
  **********************************************************************/
 
-static GtkDialog *swb_config_dialog(void) {
+static GtkDialog *swb_config_dialog(gpointer cp_window) {
        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();
-       /* 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);
+       dialog = gtk_dialog_new_with_buttons(
+               "Browser Switchboard",
+               GTK_WINDOW(cp_window),
+               GTK_DIALOG_MODAL,
+               GTK_STOCK_OK,
+               GTK_RESPONSE_OK,
+               GTK_STOCK_CANCEL,
+               GTK_RESPONSE_CANCEL,
+               NULL);
 
        dialog_vbox = GTK_DIALOG(dialog)->vbox;
 
        /* Config options */
        options_table = gtk_table_new(3, 2, FALSE);
-       gtk_table_set_row_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();
@@ -329,7 +332,6 @@ static GtkDialog *swb_config_dialog(void) {
                        0, 1,
                        GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND,
                        5, 0);
-       gtk_table_set_row_spacing(GTK_TABLE(options_table), 0, 5);
 
        cw.other_browser_cmd_entry = gtk_entry_new();
        cw.other_browser_cmd_entry_label = gtk_label_new("Command (%s for URI):");
@@ -348,27 +350,36 @@ static GtkDialog *swb_config_dialog(void) {
                        1, 2,
                        GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND,
                        5, 0);
-
-       cw.continuous_mode_check = gtk_check_button_new_with_label("Run browser launcher continuously in the background");
+       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),
-                       cw.continuous_mode_check,
+                       continuous_mode_label,
                        0, 2,
                        2, 3,
-                       0, GTK_FILL|GTK_EXPAND,
-                       5, 5);
-
-       /* Dialog buttons */
-       action_area = GTK_DIALOG(dialog)->action_area;
-
-       okbutton = gtk_button_new_from_stock(GTK_STOCK_OK);
-       g_signal_connect(G_OBJECT(okbutton), "clicked",
-                        G_CALLBACK(ok_callback), NULL);
-       gtk_box_pack_start(GTK_BOX(action_area), okbutton, FALSE, FALSE, 0);
+                       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,
+                       4, 5,
+                       GTK_FILL, GTK_FILL|GTK_EXPAND,
+                       20, 5);
+       gtk_table_set_row_spacing(GTK_TABLE(options_table), 3, 0);
 
-       cancelbutton = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
-       g_signal_connect(G_OBJECT(cancelbutton), "clicked",
-                        G_CALLBACK(cancel_callback), NULL);
-       gtk_box_pack_start(GTK_BOX(action_area), cancelbutton, FALSE, FALSE, 0);
 
        gtk_widget_show_all(dialog);
        return GTK_DIALOG(dialog);
@@ -385,16 +396,19 @@ static GtkDialog *swb_config_dialog(void) {
  */
 osso_return_t execute(osso_context_t *osso,
                      gpointer userdata, gboolean user_activated) {
-       HildonProgram *program;
        GtkDialog *dialog;
+       gint response;
 
-       program = HILDON_PROGRAM(hildon_program_get_instance());
        if (osso == NULL)
                return OSSO_ERROR;
 
-       dialog = GTK_DIALOG(swb_config_dialog());
+       dialog = GTK_DIALOG(swb_config_dialog(userdata));
        load_config();
-       gtk_dialog_run(dialog);
+
+       response = gtk_dialog_run(dialog);
+       if (response == GTK_RESPONSE_OK)
+               do_reconfig();
+
        gtk_widget_destroy(GTK_WIDGET(dialog));
 
        return OSSO_OK;
@@ -405,18 +419,25 @@ osso_return_t execute(osso_context_t *osso,
  */
 int main(int argc, char *argv[]) {
        GtkDialog *dialog;
+       gint response;
 #ifdef HILDON
        HildonProgram *program = NULL;
-       program = HILDON_PROGRAM(hildon_program_get_instance());
 #endif
 
        gtk_init(&argc, &argv);
+#ifdef HILDON
+       program = HILDON_PROGRAM(hildon_program_get_instance());
+#endif
 
        g_set_application_name("Browser Switchboard");
 
-       dialog = GTK_DIALOG(swb_config_dialog());
+       dialog = GTK_DIALOG(swb_config_dialog(NULL));
        load_config();
-       gtk_dialog_run(dialog);
+
+       response = gtk_dialog_run(dialog);
+       if (response == GTK_RESPONSE_OK)
+               do_reconfig();
+
        gtk_widget_destroy(GTK_WIDGET(dialog));
 
        exit(0);