[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#395052: Please provide the GTK frontend with a better handler for BOOLEAN questions



Frans Pop wrote:
On Tuesday 24 October 2006 17:47, Attilio Fiandrotti wrote:

Many users complained about poor "checkbox" handler provided in the GTK
frontend to handle BOOLEAN questions.
A "yes/no" widget based handler would do better for this purpose, ATM
i'm thinking about implementing this with a combobox [1] widget.


I don't agree that this would be a better solution as it would not be obvious to users which options are available and having to always open the combobox to select a different choice is very user unfriendly.

The optimal solution would be to have yes and no buttons, just like in the newt frontend.

An IMHO somewhat acceptable alternative solution is possibly to use radio buttons:
http://developer.gnome.org/doc/API/2.0/gtk/GtkRadioButton.html

I've experimented with the combobox and i must admit having a popdown menu is not optimal for many reasons: anyway patch is attached, so that anyone can evaluate by himself.
Let's try with a radiobutton, now.

Attilio
Index: gtk.c
===================================================================
--- gtk.c	(revisione 42179)
+++ gtk.c	(copia locale)
@@ -124,9 +124,9 @@
     return TRUE;
 }
 
-static void bool_setter(void *check, struct question *q)
+static void bool_setter(void *combobox, struct question *q)
 {
-    question_setvalue(q, (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check)) ? "true" : "false"));
+    question_setvalue(q, (gtk_combo_box_get_active(GTK_CHECK_BOX(combobox)) ? "true" : "false"));
 }
 
 static void entry_setter(void *entry, struct question *q)
@@ -374,32 +374,16 @@
     gtk_main_quit();
 }
 
-void check_toggled_callback (GtkWidget *toggle, gpointer data)
+void combobox_changed_callback (GtkWidget *combobox, gpointer data)
 {
     struct question *q = (struct question*)data;
-    gboolean value;
 
-    /* INFO(INFO_DEBUG, "GTK_DI - check_toggled_callback() called"); */
-    value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(toggle));
-    bool_setter (toggle, q);
+    if ( gtk_combo_box_get_active ( GTK_COMBO_BOX(combobox) ) == 1 )
+        question_setvalue(q, "true");
+    else
+        question_setvalue(q, "false");
 }
 
-void boolean_single_callback(GtkWidget *button, struct frontend_question_data* data )
-{
-    struct frontend *obj = data->obj;
-    struct question *q = data->q;
-    char *ret;
-
-    /* INFO(INFO_DEBUG, "GTK_DI - boolean_single_callback() called"); */
-    ret = (char*) gtk_object_get_user_data(GTK_OBJECT(button));
-    question_setvalue(q, ret);
-    free(ret);
-
-    ((struct frontend_data*)obj->data)->button_val = DC_OK;;
-
-    gtk_main_quit();
-}
-
 void multiselect_single_callback(GtkCellRendererToggle *cell, const gchar *path_string, struct question_treemodel_data* data)
 {
     int i, count;
@@ -613,7 +597,7 @@
     }
 
     /* here is created the question's description, unless question is BOOLEAN */
-    if( strcmp(q->template->type, "boolean") != 0 ) {
+//    if( strcmp(q->template->type, "boolean") != 0 ) {
         description_view = gtk_text_view_new ();
         description_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (description_view));
         gtk_text_buffer_set_text (description_buffer, q_get_description(q), -1);
@@ -628,7 +612,7 @@
         gtk_text_buffer_get_end_iter  (description_buffer, &end);
         gtk_text_buffer_apply_tag_by_name (description_buffer, "italic", &start, &end);
         gtk_widget_modify_base(GTK_WIDGET(description_view), GTK_STATE_NORMAL, bg_color);
-    }
+//    }
 
     gtk_container_set_focus_chain(GTK_CONTAINER(description_box), NULL);
 
@@ -642,7 +626,7 @@
     {
         if (strlen (q_get_extended_description(q)) > 0)
             gtk_box_pack_start(GTK_BOX (description_box), ext_description_view, FALSE, FALSE, 2);
-        if( strcmp(q->template->type, "boolean") != 0 )
+//        if( strcmp(q->template->type, "boolean") != 0 )
             gtk_box_pack_start(GTK_BOX (description_box), description_view, FALSE, FALSE, 3);
     }
 
@@ -665,7 +649,7 @@
 
 static int gtkhandler_boolean(struct frontend *obj, struct question *q, GtkWidget *qbox)
 {
-    GtkWidget *description_box, *check, *hpadbox, *vpadbox;
+    GtkWidget *description_box, *combobox, *hpadbox, *vpadbox;
     struct frontend_question_data *data;
     const char *defval = question_getvalue(q, "");
 
@@ -675,30 +659,35 @@
     data->obj = obj;
     data->q = q;
 
-    check = gtk_check_button_new_with_label(q_get_description(q));
+    combobox = gtk_combo_box_new_text( );
+    gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), question_get_text(obj, "debconf/no", "No") );
+    gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), question_get_text(obj, "debconf/yes", "Yes") );
+
     if (strcmp(defval, "true") == 0)
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
+        gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), 1);
     else
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), FALSE);
+        gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), 0);
 
-    if (q->next == NULL && q->prev == NULL)
-        g_signal_connect (G_OBJECT(check), "toggled", G_CALLBACK(check_toggled_callback), q);
-    else
-        register_setter(bool_setter, check, q, obj);
+    free(defval);
 
-    g_signal_connect (G_OBJECT(check), "destroy", G_CALLBACK (free_description_data), data);
+    //if (q->next == NULL && q->prev == NULL)
+        g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(combobox_changed_callback), q);
+    //else
+    //    register_setter(bool_setter, combobox, q, obj);
 
+    g_signal_connect (G_OBJECT(combobox), "destroy", G_CALLBACK (free_description_data), data);
+
     description_box = display_descriptions(q, obj);
 
     vpadbox = gtk_vbox_new (FALSE, DEFAULT_PADDING);
     gtk_box_pack_start (GTK_BOX(vpadbox), description_box, FALSE, FALSE, 0);
-    gtk_box_pack_start (GTK_BOX(vpadbox), check, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(vpadbox), combobox, FALSE, FALSE, 0);
     hpadbox = gtk_hbox_new (FALSE, DEFAULT_PADDING);
     gtk_box_pack_start (GTK_BOX(hpadbox), vpadbox, TRUE, TRUE, QUESTIONBOX_HPADDING);
     gtk_box_pack_start(GTK_BOX(qbox), hpadbox, FALSE, FALSE, QUESTIONBOX_VPADDING);
 
     if (is_first_question(q))
-        gtk_widget_grab_focus(check);
+        gtk_widget_grab_focus(combobox);
 
     return DC_OK;
 }

Reply to: