[gcompris] core: now configuration dialog callback requires a boolean return value indicating if the entered da



commit 2de30e89a581a7ed9857940a6d7e832d39a61c8d
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Sun Aug 21 02:14:54 2011 +0200

    core: now configuration dialog callback requires a boolean return value indicating if the entered data are correct.
    
    Now when we click ok in the config dialog. If the callback returns FALSE then it is not closed.
    It is up to the dialog implementor to display a relevant error message.
    
    I found out that the radio_buttons API makes the pythontest config dialog crashing.
    Since it is not used elsewhere, I just commented it until we need it.
    
    In login.py and tuxpaint, reactivated the config button that was missing.

 src/boards/py-mod-gcompris.c                |   23 +++++++++--------
 src/gcompris/board_config.c                 |    5 ++-
 src/gcompris/board_config.h                 |   10 +++++--
 src/gletters-activity/gletters.c            |    6 ++--
 src/imageid-activity/imageid.c              |    8 +++---
 src/login-activity/login.py                 |   18 +++++++------
 src/missing_letter-activity/missingletter.c |    8 +++---
 src/pythontest-activity/pythontest.py       |   35 ++++++++++-----------------
 src/readingh-activity/reading.c             |    7 +++--
 src/scalesboard-activity/scale.c            |    9 ++++---
 src/smallnumbers-activity/smallnumbers.c    |    8 ++++--
 src/tuxpaint-activity/tuxpaint.py           |    3 +-
 src/wordsgame-activity/wordsgame.c          |    8 ++++--
 13 files changed, 77 insertions(+), 71 deletions(-)
---
diff --git a/src/boards/py-mod-gcompris.c b/src/boards/py-mod-gcompris.c
index 96f8f98..071fa34 100644
--- a/src/boards/py-mod-gcompris.c
+++ b/src/boards/py-mod-gcompris.c
@@ -1088,16 +1088,16 @@ py_gc_db_set_board_conf (PyObject* self, PyObject* args)
 }
 
 
-/* Some functions and variables needed to get the file selector working */
+/* Some functions and variables needed to get the config dialog working */
 static PyObject* pyGcomprisConfCallbackFunc = NULL;
 
-static void pyGcomprisConfCallback(GHashTable* table){
+static gboolean pyGcomprisConfCallback(GHashTable* table){
   PyObject* result;
 
   PyGILState_STATE gil;
+  gboolean retval = TRUE;
 
-
-  if(pyGcomprisConfCallbackFunc==NULL) return;
+  if(pyGcomprisConfCallbackFunc==NULL) return TRUE;
 
   gil = pyg_gil_state_ensure();
 
@@ -1106,17 +1106,18 @@ static void pyGcomprisConfCallback(GHashTable* table){
   else
     result = PyObject_CallFunction(pyGcomprisConfCallbackFunc, "O", Py_None);
 
-  // This callback can be called multiple time ? not now
-
-  Py_DECREF(pyGcomprisConfCallbackFunc);
-
   if(result==NULL){
     PyErr_Print();
   } else {
+    if (PyObject_IsTrue(result))
+      retval = TRUE;
+    else
+      retval = FALSE;
     Py_DECREF(result);
   }
 
   pyg_gil_state_release(gil);
+  return retval;
 
 }
 
@@ -1139,8 +1140,8 @@ py_gc_board_config_window_display(PyObject* self, PyObject* args){
       return NULL;
     }
 
-  //if (pyGcomprisConfCallbackFunc)
-  //  Py_DECREF(pyGcomprisConfCallbackFunc);
+  if (pyGcomprisConfCallbackFunc)
+    Py_DECREF(pyGcomprisConfCallbackFunc);
 
   pyGcomprisConfCallbackFunc = pyCallback;
 
@@ -1149,7 +1150,7 @@ py_gc_board_config_window_display(PyObject* self, PyObject* args){
 
   return gcompris_new_pyGcomprisBoardConfigObject(
 		  gc_board_config_window_display( label,
-			  (GcomprisConfCallback )pyGcomprisConfCallback));
+						  pyGcomprisConfCallback));
 
 }
 
diff --git a/src/gcompris/board_config.c b/src/gcompris/board_config.c
index a13347e..71c5ced 100644
--- a/src/gcompris/board_config.c
+++ b/src/gcompris/board_config.c
@@ -78,7 +78,6 @@ gc_board_conf_close (GtkDialog *dialog,
   }
   gc_bar_hide(FALSE);
   g_free(u);
-
 }
 
 void
@@ -92,7 +91,9 @@ _response_board_conf (GtkButton *button,
 
     switch (arg1){
     case GTK_RESPONSE_APPLY:
-      u->Confcallback(u->hash_conf);
+      /* Do not close the config dialog if the user returns FALSE */
+      if ( ! u->Confcallback(u->hash_conf) )
+	return;
       break;
     case GTK_RESPONSE_CANCEL:
       u->Confcallback(NULL);
diff --git a/src/gcompris/board_config.h b/src/gcompris/board_config.h
index 14ab2b3..14267c8 100644
--- a/src/gcompris/board_config.h
+++ b/src/gcompris/board_config.h
@@ -20,10 +20,14 @@
 #define BOARD_CONFIG_H
 #include "gcompris.h"
 
-/* the callback type */
-typedef void (*GcomprisConfCallback) (GHashTable *table);
+/**
+ * the callback type
+ * returns TRUE if the data is valid and the save succeeded
+ */
+
+typedef gboolean (*GcomprisConfCallback) (GHashTable *table);
 
-typedef struct 
+typedef struct
 {
 	GtkWindow *conf_window;
 	GtkVBox *main_conf_box;
diff --git a/src/gletters-activity/gletters.c b/src/gletters-activity/gletters.c
index e5db45c..d90fc66 100644
--- a/src/gletters-activity/gletters.c
+++ b/src/gletters-activity/gletters.c
@@ -784,12 +784,12 @@ static void save_table (gpointer key,
 
 /* a GcomprisConfCallback
  */
-static void conf_ok(GHashTable *table)
+static gboolean conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard)
       pause_board(FALSE);
-    return;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, save_table, NULL);
@@ -832,7 +832,7 @@ static void conf_ok(GHashTable *table)
 
   board_conf = NULL;
   profile_conf = NULL;
-
+  return TRUE;
 }
 
 static void
diff --git a/src/imageid-activity/imageid.c b/src/imageid-activity/imageid.c
index c7724aa..4d277ed 100644
--- a/src/imageid-activity/imageid.c
+++ b/src/imageid-activity/imageid.c
@@ -662,12 +662,12 @@ static void save_table (gpointer key,
 			    (gchar *) value);
 }
 
-static GcomprisConfCallback conf_ok(GHashTable *table)
+static gboolean conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard)
       pause_board(FALSE);
-    return NULL;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
@@ -696,7 +696,7 @@ static GcomprisConfCallback conf_ok(GHashTable *table)
   board_conf = NULL;
   profile_conf = NULL;
 
-  return NULL;
+  return TRUE;
 }
 
 static void
@@ -714,7 +714,7 @@ config_start(GcomprisBoard *agcomprisBoard,
 				 aProfile ? aProfile->name : "");
   GcomprisBoardConf *bconf;
   bconf = gc_board_config_window_display( label,
-				 (GcomprisConfCallback )conf_ok);
+				 conf_ok);
 
   g_free(label);
 
diff --git a/src/login-activity/login.py b/src/login-activity/login.py
index 6c0585b..57e1533 100644
--- a/src/login-activity/login.py
+++ b/src/login-activity/login.py
@@ -54,7 +54,7 @@ class Gcompris_login:
     self.gcomprisBoard.maxlevel=1
     self.gcomprisBoard.sublevel=1
     self.gcomprisBoard.number_of_sublevel=1
-    gcompris.bar_set(gcompris.BAR_REPEAT)
+    gcompris.bar_set(gcompris.BAR_REPEAT|gcompris.BAR_CONFIG)
 
     gcompris.bar_set_level(self.gcomprisBoard)
 
@@ -78,8 +78,9 @@ class Gcompris_login:
 
     # Get the user list
     users = []
-    for group_id in self.Prop.profile.group_ids:
-      users.extend( gcompris.admin.get_users_from_group(group_id))
+    if self.Prop.profile:
+      for group_id in self.Prop.profile.group_ids:
+        users.extend( gcompris.admin.get_users_from_group(group_id))
 
     self.users = self.check_unique_id(users)
 
@@ -98,7 +99,7 @@ class Gcompris_login:
     # Display the profile name
     x = gcompris.BOARD_WIDTH-100
     y = 20.0
-    text = _("Profile: ") + Prop.profile.name
+    text = _("Profile: ") + (Prop.profile.name if Prop.profile else "")
 
     # Profile name
     goocanvas.Text(
@@ -465,7 +466,7 @@ class Gcompris_login:
     # init with default values
     self.config_dict = self.init_config()
 
-    #get the configured values for that profile
+    # get the configured values for that profile
     self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
 
     # Init configuration window:
@@ -476,7 +477,8 @@ class Gcompris_login:
     #we can add what you want in it.
 
     bconf = gcompris.configuration_window ( \
-      _('<b>%s</b> configuration\n for profile <b>%s</b>') % ('Login', profile.name ),
+      _('<b>%s</b> configuration\n for profile <b>%s</b>')
+      % ('Login', ( profile.name if profile else "" ) ),
       self.ok_callback
       )
 
@@ -502,7 +504,7 @@ class Gcompris_login:
 
   def ok_callback(self, table):
     if(not table):
-      return
+      return True
     for key,value in table.iteritems():
       gcompris.set_board_conf(self.configuring_profile, self.gcomprisBoard, key, value)
-
+    return True
diff --git a/src/missing_letter-activity/missingletter.c b/src/missing_letter-activity/missingletter.c
index bc0c9a1..a8da762 100644
--- a/src/missing_letter-activity/missingletter.c
+++ b/src/missing_letter-activity/missingletter.c
@@ -717,13 +717,13 @@ static void save_table (gpointer key,
 			 (gchar *) value);
 }
 
-static GcomprisConfCallback
+static gboolean
 conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard_missing)
       pause_board(FALSE);
-    return NULL;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
@@ -763,7 +763,7 @@ conf_ok(GHashTable *table)
   profile_conf = NULL;
   pause_board(FALSE);
 
-  return NULL;
+  return TRUE;
 }
 
 static void
@@ -786,7 +786,7 @@ config_start(GcomprisBoard *agcomprisBoard,
 				 aProfile ? aProfile->name : "");
   GcomprisBoardConf *bconf;
   bconf = gc_board_config_window_display( label,
-				 (GcomprisConfCallback )conf_ok);
+				 conf_ok);
 
   g_free(label);
 
diff --git a/src/pythontest-activity/pythontest.py b/src/pythontest-activity/pythontest.py
index 935d4f3..a3058a3 100644
--- a/src/pythontest-activity/pythontest.py
+++ b/src/pythontest-activity/pythontest.py
@@ -301,10 +301,6 @@ class Gcompris_pythontest:
     print("Gcompris_pythontest repeat.")
 
 
-  def config(self):
-    print("Gcompris_pythontest config.")
-
-
   def key_press(self, keyval, commit_str, preedit_str):
     utf8char = gtk.gdk.keyval_to_unicode(keyval)
     strn = u'%c' % utf8char
@@ -451,7 +447,8 @@ class Gcompris_pythontest:
     #we can add what you want in it.
 
     bconf = gcompris.configuration_window ( \
-      _('<b>%s</b> configuration\n for profile <b>%s</b>') % ('Pythontest', profile.name ),
+      _('<b>%s</b> configuration\n for profile <b>%s</b>')
+      % ('Pythontest', (profile.name if profile else "") ),
       self.ok_callback
       )
 
@@ -491,11 +488,14 @@ class Gcompris_pythontest:
                  'rectangle': _('Use rectangles')
                  }
 
-    gcompris.radio_buttons(bconf, _('Choice of pattern'),
-                           'pattern',
-                           patterns,
-                           self.config_dict['pattern']
-                           )
+    # FIXME radio button makes the configuration unstable
+    #       the problem is perhaps in the C code but since
+    #       no one use it, let's forget it for now.
+    # gcompris.radio_buttons(bconf, _('Choice of pattern'),
+    #                        'pattern',
+    #                        patterns,
+    #                        self.config_dict['pattern']
+    #                        )
 
     print "List of locales shown in gcompris.combo_locale :"
     print gcompris.get_locales_list()
@@ -507,23 +507,13 @@ class Gcompris_pythontest:
     gcompris.separator(bconf)
 
     print "List of locales shown in gcompris.combo_locales_asset :"
-    locales_purple = gcompris.get_locales_asset_list( "gcompris colors", None, "audio/x-ogg", "purple.ogg")
+    locales_purple = gcompris.get_locales_asset_list( "purple.ogg" )
     print locales_purple
 
-    label = gtk.Label()
-    label.set_markup('<i>-- unused, but here for test --</i>')
-    label.props.visibility = goocanvas.ITEM_VISIBLE
-#    self.main_vbox.pack_start (label, False, False, 8)
-
     gcompris.combo_locales_asset(bconf, _("Select sound locale"),
                                  self.config_dict['locale_sound'],
                                  "voices/$LOCALE/colors/red.ogg" )
 
-    print gcompris.utils.get_asset_file ("gcompris colors", None, "audio/x-ogg", "purple.ogg")
-    print gcompris.utils.get_asset_file_locale ("gcompris colors", None, "audio/x-ogg", "purple.ogg", None)
-    for lang in locales_purple:
-      print gcompris.utils.get_asset_file_locale ("gcompris colors", None, "audio/x-ogg", "purple.ogg", lang)
-
   def color_disable(self, button):
     self.color_choice.set_sensitive(not button.get_active())
 
@@ -532,7 +522,7 @@ class Gcompris_pythontest:
   def ok_callback(self, table):
     if (table == None):
       print 'Configuration returns None'
-      return
+      return True
 
     print "Keys and values returned by PythonTest config window:"
 
@@ -543,6 +533,7 @@ class Gcompris_pythontest:
       print '%20s:%20s    ' % (key, value)
       gcompris.set_board_conf(self.configuring_profile, self.gcomprisBoard, key, value)
 
+    return True;
 
   def init_config(self):
     default_config = { 'disable_line'    : 'False',
diff --git a/src/readingh-activity/reading.c b/src/readingh-activity/reading.c
index b4457a5..8866a93 100644
--- a/src/readingh-activity/reading.c
+++ b/src/readingh-activity/reading.c
@@ -848,12 +848,13 @@ static void save_table (gpointer key,
 			    (gchar *) value);
 }
 
-static void conf_ok(GHashTable *table)
+static gboolean
+conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard)
       pause_board(FALSE);
-    return;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
@@ -887,7 +888,7 @@ static void conf_ok(GHashTable *table)
 
   board_conf = NULL;
   profile_conf = NULL;
-
+  return TRUE;
 }
 
 static void
diff --git a/src/scalesboard-activity/scale.c b/src/scalesboard-activity/scale.c
index 8a96b87..9bb1af8 100644
--- a/src/scalesboard-activity/scale.c
+++ b/src/scalesboard-activity/scale.c
@@ -1107,12 +1107,13 @@ static void save_table (gpointer key,
 			 (gchar *) value);
 }
 
-static void conf_ok(GHashTable *table)
+static gboolean
+conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard)
       pause_board(FALSE);
-    return;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
@@ -1144,7 +1145,7 @@ static void conf_ok(GHashTable *table)
 
   board_conf = NULL;
   profile_conf = NULL;
-
+  return TRUE;
 }
 
 static void
@@ -1163,7 +1164,7 @@ config_start(GcomprisBoard *agcomprisBoard,
 
   GcomprisBoardConf *bconf;
   bconf = gc_board_config_window_display( label,
-					  (GcomprisConfCallback )conf_ok);
+					  conf_ok);
 
   g_free(label);
 
diff --git a/src/smallnumbers-activity/smallnumbers.c b/src/smallnumbers-activity/smallnumbers.c
index 5cb1d56..d445a2a 100644
--- a/src/smallnumbers-activity/smallnumbers.c
+++ b/src/smallnumbers-activity/smallnumbers.c
@@ -529,12 +529,13 @@ static GHFunc save_table (gpointer key,
   return NULL;
 }
 
-static void conf_ok(GHashTable *table)
+static gboolean
+conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard)
       pause_board(FALSE);
-    return;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
@@ -571,6 +572,7 @@ static void conf_ok(GHashTable *table)
 
   board_conf = NULL;
   profile_conf = NULL;
+  return TRUE;
 }
 
 static void sound_control_box_toggled(GtkToggleButton *togglebutton,
@@ -596,7 +598,7 @@ smallnumber_config_start(GcomprisBoard *agcomprisBoard,
 			  agcomprisBoard->name, aProfile ? aProfile->name : "");
 
   GcomprisBoardConf *bconf;
-  bconf = gc_board_config_window_display(label, (GcomprisConfCallback )conf_ok);
+  bconf = gc_board_config_window_display(label, conf_ok);
 
   g_free(label);
 
diff --git a/src/tuxpaint-activity/tuxpaint.py b/src/tuxpaint-activity/tuxpaint.py
index 4821fa0..6722c2c 100644
--- a/src/tuxpaint-activity/tuxpaint.py
+++ b/src/tuxpaint-activity/tuxpaint.py
@@ -125,7 +125,7 @@ class Gcompris_tuxpaint:
 
     gobject.child_watch_add(pid, child_callback, data=self, priority=gobject.PRIORITY_HIGH)
 
-    gcompris.bar_set(0)
+    gcompris.bar_set(gcompris.BAR_CONFIG)
     gcompris.bar_hide(1)
 
     gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
@@ -216,6 +216,7 @@ class Gcompris_tuxpaint:
       for key,value in table.iteritems():
         gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard,
                               key, value)
+    return True
 
   def init_config(self):
     default_config_dict = { 'fullscreen'             : 'True',
diff --git a/src/wordsgame-activity/wordsgame.c b/src/wordsgame-activity/wordsgame.c
index d46c0d5..d74d3c3 100644
--- a/src/wordsgame-activity/wordsgame.c
+++ b/src/wordsgame-activity/wordsgame.c
@@ -809,12 +809,13 @@ static void save_table (gpointer key,
 			    (gchar *) value);
 }
 
-static void conf_ok(GHashTable *table)
+static gboolean
+conf_ok(GHashTable *table)
 {
   if (!table){
     if (gcomprisBoard)
       pause_board(FALSE);
-    return;
+    return TRUE;
   }
 
   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
@@ -848,6 +849,7 @@ static void conf_ok(GHashTable *table)
 
   board_conf = NULL;
   profile_conf = NULL;
+  return TRUE;
 }
 
 static void
@@ -866,7 +868,7 @@ wordsgame_config_start(GcomprisBoard *agcomprisBoard,
 				 aProfile? aProfile->name: "");
 
   conf = gc_board_config_window_display( label,
-				 (GcomprisConfCallback )conf_ok);
+					 conf_ok);
 
   g_free(label);
 



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