[gnome-games/gnome-2-28] aisleriot: maemo5: Fix game choice dialogue



commit a5c81f1fd2fe111913f6ee54fbf4203885c6ff97
Author: Christian Persch <chpe gnome org>
Date:   Fri Nov 27 18:28:41 2009 +0100

    aisleriot: maemo5: Fix game choice dialogue
    
    On maemo5, the treeview in a pannable area never has any row selected,
    so we failed to get the selected game type on response. Instead, the
    row-activated signal is emitted when the user selects an item; so we
    store the selected path in its handler and use that on response. [Found
    the problem thanks to this thread on maemo-developers ML:
    [http://lists.maemo.org/pipermail/maemo-developers/2009-May/019174.html
    ].
    
    Bug #591847.
    (cherry picked from commit 84b4a16b7a21f52bae35aceaf6d3185807f8efac)

 aisleriot/window.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/aisleriot/window.c b/aisleriot/window.c
index d578e2c..f3f2941 100644
--- a/aisleriot/window.c
+++ b/aisleriot/window.c
@@ -195,12 +195,30 @@ enum {
   COL_GAME_FILE
 };
 
+#define SELECTED_PATH_DATA_KEY "selected-path"
+
 static void
 select_game_row_activated_cb (GtkWidget *widget,
                               GtkTreePath *path,
                               GtkTreeViewColumn *column,
                               GtkDialog *dialog)
 {
+  g_assert (path != NULL);
+
+#ifdef HAVE_MAEMO_5
+  /* On maemo5 with a treeview in a pannable area, the selection
+   * handling is special. There _never_ is any row selected!
+   * Instead, we get a row-activated signal (which normally is only
+   * emitted when double-clicking a row) when the user selects a row.
+   *
+   * Since we can't use the selection, we need to store the activated
+   * row somewhere else.
+   */
+  g_object_set_data_full (G_OBJECT (dialog), SELECTED_PATH_DATA_KEY,
+                          gtk_tree_path_copy (path),
+                          (GDestroyNotify) gtk_tree_path_free);
+#endif /* HAVE_MAEMO_5 */
+
   /* Handle a double click by faking a click on the OK button. */
   gtk_dialog_response (dialog, GTK_RESPONSE_OK);
 }
@@ -214,9 +232,21 @@ select_game_response_cb (GtkWidget *dialog,
   GtkTreeModel *model;
   GtkTreeIter iter;
   char *game_file = NULL;
+#ifdef HAVE_MAEMO_5
+  GtkTreePath *path;
+#endif
+
+  if (response != GTK_RESPONSE_OK)
+    goto done;
 
-  if (response == GTK_RESPONSE_OK &&
-      gtk_tree_selection_get_selected (priv->game_choice_selection, &model, &iter)) {
+#ifdef HAVE_MAEMO_5
+  /* See the comment in select_game_row_activated_cb() above. */
+  if ((path = g_object_get_data (G_OBJECT (dialog), SELECTED_PATH_DATA_KEY)) != NULL &&
+      gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->game_choice_store), &iter, path)) {
+    model = GTK_TREE_MODEL (priv->game_choice_store);
+#else
+  if (gtk_tree_selection_get_selected (priv->game_choice_selection, &model, &iter)) {
+#endif
     gtk_tree_model_get (model, &iter,
                         COL_GAME_FILE, &game_file,
                         -1);
@@ -229,6 +259,7 @@ select_game_response_cb (GtkWidget *dialog,
     g_free (game_file);
   }
 
+done:
   gtk_widget_destroy (dialog);
 }
 



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