[rhythmbox] convert limit-value to a GVariant



commit f980b500c0262d73673e07ef023cb05d5a99e3a1
Author: Jonathan Matthew <jonathan d14n org>
Date:   Thu Jul 4 20:45:41 2013 +1000

    convert limit-value to a GVariant

 rhythmdb/rhythmdb-query-model.c   |   35 +++++----
 shell/rb-playlist-manager.c       |    8 +-
 sources/rb-auto-playlist-source.c |   71 +++++-------------
 sources/rb-auto-playlist-source.h |    4 +-
 tests/test-widgets.c              |  147 ++++---------------------------------
 widgets/rb-query-creator.c        |   25 +++----
 widgets/rb-query-creator.h        |    4 +-
 7 files changed, 72 insertions(+), 222 deletions(-)
---
diff --git a/rhythmdb/rhythmdb-query-model.c b/rhythmdb/rhythmdb-query-model.c
index 193fa13..19f5f27 100644
--- a/rhythmdb/rhythmdb-query-model.c
+++ b/rhythmdb/rhythmdb-query-model.c
@@ -224,7 +224,7 @@ struct _RhythmDBQueryModelPrivate
        guint stamp;
 
        RhythmDBQueryModelLimitType limit_type;
-       GArray *limit_value;
+       GVariant *limit_value;
 
        glong total_duration;
        guint64 total_size;
@@ -366,11 +366,12 @@ rhythmdb_query_model_class_init (RhythmDBQueryModelClass *klass)
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_LIMIT_VALUE,
-                                        g_param_spec_boxed ("limit-value",
-                                                            "limit-value",
-                                                            "value of limit",
-                                                            G_TYPE_ARRAY,
-                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+                                        g_param_spec_variant ("limit-value",
+                                                              "limit-value",
+                                                              "value of limit",
+                                                              G_VARIANT_TYPE_UINT64,
+                                                              NULL,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (object_class,
                                         PROP_SHOW_HIDDEN,
                                         g_param_spec_boolean ("show-hidden",
@@ -600,8 +601,8 @@ rhythmdb_query_model_set_property (GObject *object,
                break;
        case PROP_LIMIT_VALUE:
                if (model->priv->limit_value)
-                       g_array_unref (model->priv->limit_value);
-               model->priv->limit_value = (GArray*)g_value_dup_boxed (value);
+                       g_variant_unref (model->priv->limit_value);
+               model->priv->limit_value = g_value_dup_variant (value);
                break;
        case PROP_SHOW_HIDDEN:
                model->priv->show_hidden = g_value_get_boolean (value);
@@ -647,7 +648,7 @@ rhythmdb_query_model_get_property (GObject *object,
                g_value_set_enum (value, model->priv->limit_type);
                break;
        case PROP_LIMIT_VALUE:
-               g_value_set_boxed (value, model->priv->limit_value);
+               g_value_set_variant (value, model->priv->limit_value);
                break;
        case PROP_SHOW_HIDDEN:
                g_value_set_boolean (value, model->priv->show_hidden);
@@ -794,7 +795,7 @@ rhythmdb_query_model_finalize (GObject *object)
                model->priv->sort_data_destroy (model->priv->sort_data);
 
        if (model->priv->limit_value)
-               g_array_unref (model->priv->limit_value);
+               g_variant_unref (model->priv->limit_value);
 
        G_OBJECT_CLASS (rhythmdb_query_model_parent_class)->finalize (object);
 }
@@ -3317,10 +3318,10 @@ rhythmdb_query_model_within_limit (RhythmDBQueryModel *model,
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
                {
-                       gulong limit_count;
-                       gulong current_count;
+                       guint64 limit_count;
+                       guint64 current_count;
 
-                       limit_count = g_value_get_ulong (&g_array_index (model->priv->limit_value, GValue, 
0));
+                       limit_count = g_variant_get_uint64 (model->priv->limit_value);
                        current_count = g_hash_table_size (model->priv->reverse_map);
 
                        if (entry)
@@ -3335,7 +3336,7 @@ rhythmdb_query_model_within_limit (RhythmDBQueryModel *model,
                        guint64 limit_size;
                        guint64 current_size;
 
-                       limit_size = g_value_get_uint64 (&g_array_index (model->priv->limit_value, GValue, 
0));
+                       limit_size = g_variant_get_uint64 (model->priv->limit_value);
                        current_size = model->priv->total_size;
 
                        if (entry)
@@ -3348,10 +3349,10 @@ rhythmdb_query_model_within_limit (RhythmDBQueryModel *model,
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
                {
-                       gulong limit_time;
-                       gulong current_time;
+                       guint64 limit_time;
+                       guint64 current_time;
 
-                       limit_time = g_value_get_ulong (&g_array_index (model->priv->limit_value, GValue, 0));
+                       limit_time = g_variant_get_uint64 (model->priv->limit_value);
                        current_time = model->priv->total_duration;
 
                        if (entry)
diff --git a/shell/rb-playlist-manager.c b/shell/rb-playlist-manager.c
index 84c9271..2c6608e 100644
--- a/shell/rb-playlist-manager.c
+++ b/shell/rb-playlist-manager.c
@@ -823,7 +823,7 @@ rb_playlist_manager_set_automatic_playlist (RBPlaylistManager *mgr,
                                            RBQueryCreator *creator)
 {
        RhythmDBQueryModelLimitType limit_type;
-       GArray *limit_value = NULL;
+       GVariant *limit_value = NULL;
        const char *sort_key;
        gint sort_direction;
        GPtrArray *query;
@@ -842,7 +842,7 @@ rb_playlist_manager_set_automatic_playlist (RBPlaylistManager *mgr,
                                           sort_direction);
        rhythmdb_query_free (query);
        if (limit_value != NULL) {
-               g_array_unref (limit_value);
+               g_variant_unref (limit_value);
        }
 }
 
@@ -931,7 +931,7 @@ edit_auto_playlist_action_cb (GSimpleAction *action, GVariant *parameter, gpoint
        creator = g_object_get_data (G_OBJECT (playlist), "rhythmbox-playlist-editor");
        if (creator == NULL) {
                RhythmDBQueryModelLimitType limit_type;
-               GArray *limit_value = NULL;
+               GVariant *limit_value = NULL;
                GPtrArray *query;
                char *sort_key;
                gint sort_direction;
@@ -952,7 +952,7 @@ edit_auto_playlist_action_cb (GSimpleAction *action, GVariant *parameter, gpoint
                                                                             sort_key,
                                                                             sort_direction));
                if (limit_value != NULL) {
-                       g_array_unref (limit_value);
+                       g_variant_unref (limit_value);
                }
                rhythmdb_query_free (query);
                g_free (sort_key);
diff --git a/sources/rb-auto-playlist-source.c b/sources/rb-auto-playlist-source.c
index acd59e7..b7b51f5 100644
--- a/sources/rb-auto-playlist-source.c
+++ b/sources/rb-auto-playlist-source.c
@@ -113,7 +113,7 @@ struct _RBAutoPlaylistSourcePrivate
        GPtrArray *query;
        gboolean query_resetting;
        RhythmDBQueryModelLimitType limit_type;
-       GArray *limit_value;
+       GVariant *limit_value;
 
        gboolean query_active;
        gboolean search_on_completion;
@@ -193,7 +193,7 @@ rb_auto_playlist_source_finalize (GObject *object)
        }
 
        if (priv->limit_value) {
-               g_array_unref (priv->limit_value);
+               g_variant_unref (priv->limit_value);
        }
 
        G_OBJECT_CLASS (rb_auto_playlist_source_parent_class)->finalize (object);
@@ -383,10 +383,9 @@ rb_auto_playlist_source_new_from_xml (RBShell *shell, xmlNodePtr node)
        xmlChar *tmp;
        GPtrArray *query;
        RhythmDBQueryModelLimitType limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_NONE;
-       GArray *limit_value = NULL;
+       GVariant *limit_value = NULL;
        gchar *sort_key = NULL;
        gint sort_direction = 0;
-       GValue val = {0,};
 
        child = node->children;
        while (xmlNodeIsText (child))
@@ -395,21 +394,14 @@ rb_auto_playlist_source_new_from_xml (RBShell *shell, xmlNodePtr node)
        query = rhythmdb_query_deserialize (rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source)),
                                            child);
 
-       limit_value = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (limit_value, (GDestroyNotify) g_value_unset);
        tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_COUNT);
        if (!tmp) /* Backwards compatibility */
                tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT);
        if (tmp) {
-               gulong l = strtoul ((char *)tmp, NULL, 0);
+               guint64 l = g_ascii_strtoull ((char *)tmp, NULL, 0);
                if (l > 0) {
                        limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_COUNT;
-
-                       g_value_init (&val, G_TYPE_ULONG);
-                       g_value_set_ulong (&val, l);
-                       g_array_append_val (limit_value, val);
-                       g_free (tmp);
-                       g_value_unset (&val);
+                       limit_value = g_variant_new_uint64 (l);
                }
        }
 
@@ -419,12 +411,7 @@ rb_auto_playlist_source_new_from_xml (RBShell *shell, xmlNodePtr node)
                        guint64 l = g_ascii_strtoull ((char *)tmp, NULL, 0);
                        if (l > 0) {
                                limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_SIZE;
-
-                               g_value_init (&val, G_TYPE_UINT64);
-                               g_value_set_uint64 (&val, l);
-                               g_array_append_val (limit_value, val);
-                               g_free (tmp);
-                               g_value_unset (&val);
+                               limit_value = g_variant_new_uint64 (l);
                        }
                }
        }
@@ -432,15 +419,10 @@ rb_auto_playlist_source_new_from_xml (RBShell *shell, xmlNodePtr node)
        if (limit_type == RHYTHMDB_QUERY_MODEL_LIMIT_NONE) {
                tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_TIME);
                if (tmp) {
-                       gulong l = strtoul ((char *)tmp, NULL, 0);
+                       guint64 l = g_ascii_strtoull ((char *)tmp, NULL, 0);
                        if (l > 0) {
                                limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_TIME;
-
-                               g_value_init (&val, G_TYPE_ULONG);
-                               g_value_set_ulong (&val, l);
-                               g_array_append_val (limit_value, val);
-                               g_free (tmp);
-                               g_value_unset (&val);
+                               limit_value = g_variant_new_uint64 (l);
                        }
                }
        }
@@ -464,7 +446,8 @@ rb_auto_playlist_source_new_from_xml (RBShell *shell, xmlNodePtr node)
                                           sort_key,
                                           sort_direction);
        g_free (sort_key);
-       g_array_unref (limit_value);
+       if (limit_value)
+               g_variant_unref (limit_value);
        rhythmdb_query_free (query);
 
        return RB_SOURCE (source);
@@ -627,24 +610,12 @@ impl_receive_drag (RBDisplayPage *page, GtkSelectionData *data)
 }
 
 static void
-_save_write_ulong (xmlNodePtr node, GArray *limit_value, const xmlChar *key)
-{
-       gulong l;
-       gchar *str;
-
-       l = g_value_get_ulong (&g_array_index (limit_value, GValue, 0));
-       str = g_strdup_printf ("%u", (guint)l);
-       xmlSetProp (node, key, BAD_CAST str);
-       g_free (str);
-}
-
-static void
-_save_write_uint64 (xmlNodePtr node, GArray *limit_value, const xmlChar *key)
+_save_write_uint64 (xmlNodePtr node, GVariant *limit_value, const xmlChar *key)
 {
        guint64 l;
        gchar *str;
 
-       l = g_value_get_uint64 (&g_array_index (limit_value, GValue, 0));
+       l = g_variant_get_uint64 (limit_value);
        str = g_strdup_printf ("%" G_GUINT64_FORMAT, l);
        xmlSetProp (node, key, BAD_CAST str);
        g_free (str);
@@ -656,7 +627,7 @@ impl_save_contents_to_xml (RBPlaylistSource *psource,
 {
        GPtrArray *query;
        RhythmDBQueryModelLimitType limit_type;
-       GArray *limit_value = NULL;
+       GVariant *limit_value = NULL;
        char *sort_key;
        gint sort_direction;
        RBAutoPlaylistSource *source = RB_AUTO_PLAYLIST_SOURCE (psource);
@@ -676,7 +647,7 @@ impl_save_contents_to_xml (RBPlaylistSource *psource,
                break;
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
-               _save_write_ulong (node, limit_value, RB_PLAYLIST_LIMIT_COUNT);
+               _save_write_uint64 (node, limit_value, RB_PLAYLIST_LIMIT_COUNT);
                break;
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_SIZE:
@@ -684,7 +655,7 @@ impl_save_contents_to_xml (RBPlaylistSource *psource,
                break;
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
-               _save_write_ulong (node, limit_value, RB_PLAYLIST_LIMIT_TIME);
+               _save_write_uint64 (node, limit_value, RB_PLAYLIST_LIMIT_TIME);
                break;
 
        default:
@@ -705,7 +676,7 @@ impl_save_contents_to_xml (RBPlaylistSource *psource,
        rhythmdb_query_free (query);
 
        if (limit_value != NULL) {
-               g_array_unref (limit_value);
+               g_variant_unref (limit_value);
        }
        g_free (sort_key);
 }
@@ -799,7 +770,7 @@ void
 rb_auto_playlist_source_set_query (RBAutoPlaylistSource *source,
                                   GPtrArray *query,
                                   RhythmDBQueryModelLimitType limit_type,
-                                  GArray *limit_value,
+                                  GVariant *limit_value,
                                   const char *sort_key,
                                   gint sort_order)
 {
@@ -817,7 +788,7 @@ rb_auto_playlist_source_set_query (RBAutoPlaylistSource *source,
        }
 
        if (priv->limit_value) {
-               g_array_unref (priv->limit_value);
+               g_variant_unref (priv->limit_value);
        }
 
        /* playlists that aren't limited, with a particular sort order, are user-orderable */
@@ -826,7 +797,7 @@ rb_auto_playlist_source_set_query (RBAutoPlaylistSource *source,
 
        priv->query = rhythmdb_query_copy (query);
        priv->limit_type = limit_type;
-       priv->limit_value = limit_value ? g_array_ref (limit_value) : NULL;
+       priv->limit_value = limit_value ? g_variant_ref (limit_value) : NULL;
 
        priv->cached_all_query = g_object_new (RHYTHMDB_TYPE_QUERY_MODEL,
                                               "db", db,
@@ -856,7 +827,7 @@ void
 rb_auto_playlist_source_get_query (RBAutoPlaylistSource *source,
                                   GPtrArray **query,
                                   RhythmDBQueryModelLimitType *limit_type,
-                                  GArray **limit_value,
+                                  GVariant **limit_value,
                                   char **sort_key,
                                   gint *sort_order)
 {
@@ -870,7 +841,7 @@ rb_auto_playlist_source_get_query (RBAutoPlaylistSource *source,
 
        *query = rhythmdb_query_copy (priv->query);
        *limit_type = priv->limit_type;
-       *limit_value = (priv->limit_value) ? g_array_ref (priv->limit_value) : NULL;
+       *limit_value = (priv->limit_value) ? g_variant_ref (priv->limit_value) : NULL;
 
        rb_entry_view_get_sorting_order (songs, sort_key, sort_order);
 }
diff --git a/sources/rb-auto-playlist-source.h b/sources/rb-auto-playlist-source.h
index 2e7e91c..aba0de8 100644
--- a/sources/rb-auto-playlist-source.h
+++ b/sources/rb-auto-playlist-source.h
@@ -69,14 +69,14 @@ RBSource *  rb_auto_playlist_source_new_from_xml    (RBShell *shell,
 void           rb_auto_playlist_source_set_query       (RBAutoPlaylistSource *source,
                                                         GPtrArray *query,
                                                         RhythmDBQueryModelLimitType limit_type,
-                                                        GArray *limit_value,
+                                                        GVariant *limit_value,
                                                         const char *sort_key,
                                                         gint sort_order);
 
 void           rb_auto_playlist_source_get_query       (RBAutoPlaylistSource *source,
                                                         GPtrArray **query,
                                                         RhythmDBQueryModelLimitType *limit_type,
-                                                        GArray **limit_value,
+                                                        GVariant **limit_value,
                                                         char **sort_key,
                                                         gint *sort_order);
 
diff --git a/tests/test-widgets.c b/tests/test-widgets.c
index 2000a78..9cabbae 100644
--- a/tests/test-widgets.c
+++ b/tests/test-widgets.c
@@ -18,93 +18,6 @@
 #endif
 
 static gboolean
-rb_value_array_equal (GArray *a1, GArray *a2)
-{
-       int i;
-
-       if (a1 == NULL && a2 == NULL)
-               return TRUE;
-       else if (a1 == NULL || a2 == NULL)
-               return FALSE;
-
-       if (a1->len != a2->len)
-               return FALSE;
-
-       for (i = 0; i < a1->len; i++) {
-               GValue *v1, *v2;
-
-               v1 = &g_array_index (a1, GValue, i);
-               v2 = &g_array_index (a2, GValue, i);
-               if (rb_gvalue_compare (v1, v2) != 0)
-                       return FALSE;
-       }
-
-       return TRUE;
-}
-
-static char *
-rb_gvalue_array_to_string (GArray *a)
-{
-       int i;
-       GString *s;
-
-       if (a == NULL)
-               return strdup ("");
-
-       s = g_string_new ("(");
-
-       for (i = 0; i < a->len; i++) {
-               GValue *val;
-       
-               if (i != 0)
-                       g_string_append (s, ", ");
-
-               val = &g_array_index (a, GValue, i);
-               switch (G_VALUE_TYPE (val)) {
-               case G_TYPE_STRING:
-                       g_string_append_printf (s, "\"%s\"", g_value_get_string (val));
-                       break;
-               case G_TYPE_BOOLEAN:
-                       g_string_append_printf (s, "%d", g_value_get_boolean (val));
-                       break;
-               case G_TYPE_INT:
-                       g_string_append_printf (s, "%d", g_value_get_int (val));
-                       break;
-               case G_TYPE_LONG:
-                       g_string_append_printf (s, "%ld", g_value_get_long (val));
-                       break;
-               case G_TYPE_ULONG:
-                       g_string_append_printf (s, "%lu", g_value_get_ulong (val));
-                       break;
-               case G_TYPE_UINT64:
-                       g_string_append_printf (s, "%" G_GUINT64_FORMAT, g_value_get_uint64 (val));
-                       break;
-               case G_TYPE_FLOAT:
-                       g_string_append_printf (s, "%f", g_value_get_float (val));
-                       break;
-               case G_TYPE_DOUBLE:
-                       g_string_append_printf (s, "%f", g_value_get_double (val));
-                       break;
-               case G_TYPE_POINTER:
-                       g_string_append_printf (s, "P:%p", g_value_get_pointer (val));
-                       break;
-               case G_TYPE_BOXED:
-                       g_string_append_printf (s, "B:%p", g_value_get_boxed (val));
-                       break;
-               case G_TYPE_OBJECT:
-                       g_string_append_printf (s, "O:%p", g_value_get_object (val));
-                       break;
-               default:
-                       g_string_append(s, "Unknown");
-               }
-       }
-
-       g_string_append_c (s, ')');
-
-       return g_string_free (s, FALSE);
-}
-
-static gboolean
 rhythmdb_query_equal (const RhythmDBQuery *q1, const RhythmDBQuery *q2)
 {
        int i;
@@ -146,14 +59,14 @@ static void
 query_creator_test_load_query (RhythmDB *db,
                               RhythmDBQuery *query,
                               RhythmDBQueryModelLimitType limit_type,
-                              GArray *limit_value,
+                              GVariant *limit_value,
                               const char *sort_column,
                               gint sort_direction)
 {
        GtkWidget *creator;
        RhythmDBQuery *squery;
        RhythmDBQuery *query2 = NULL;
-       GArray *limit_value2 = NULL;
+       GVariant *limit_value2 = NULL;
        const char *sort_column2 = NULL;
        RhythmDBQueryModelLimitType limit_type2;
        gint sort_direction2;
@@ -185,16 +98,16 @@ query_creator_test_load_query (RhythmDB *db,
        /* check limits */
        rb_query_creator_get_limit (RB_QUERY_CREATOR (creator),
                                    &limit_type2, &limit_value2);
-       str1 = rb_gvalue_array_to_string (limit_value);
-       str2 = rb_gvalue_array_to_string (limit_value2);
        fail_unless (limit_type == limit_type2,
                     "limit types differ: %d; %d", limit_type, limit_type2);
-       fail_unless (rb_value_array_equal (limit_value, limit_value2),
-                    "limit values differ: %s; %s", str1, str2);
-       g_free (str2);
-       g_free (str1);
+       if (limit_value == NULL) {
+               fail_unless (limit_value == limit_value2, "wasn't supposed to get a limit value");
+       } else {
+               fail_unless (g_variant_equal (limit_value, limit_value2),
+                            "limit values differ: %s; %s", g_variant_print (limit_value, TRUE), 
g_variant_print (limit_value2, TRUE));
+       }
        if (limit_value2)
-               g_array_unref (limit_value2);
+               g_variant_unref (limit_value2);
 
        /* check sorting */
        rb_query_creator_get_sort_order (RB_QUERY_CREATOR (creator),
@@ -274,114 +187,84 @@ END_TEST
 START_TEST (test_query_creator_load_limit_count)
 {
        RhythmDBQuery *query;
-       GArray *array;
 
        query = rhythmdb_query_parse (db,
                                      RHYTHMDB_QUERY_END);
-       array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
-       rb_value_array_append_data (array, G_TYPE_ULONG, 47);
        query_creator_test_load_query (db,
                                       query,
-                                      RHYTHMDB_QUERY_MODEL_LIMIT_COUNT, array,
+                                      RHYTHMDB_QUERY_MODEL_LIMIT_COUNT, g_variant_new_uint64 (47),
                                       "Title", GTK_SORT_ASCENDING);
        rhythmdb_query_free (query);
-       g_array_unref (array);
 }
 END_TEST
 
 START_TEST (test_query_creator_load_limit_minutes)
 {
        RhythmDBQuery *query;
-       GArray *array;
 
        query = rhythmdb_query_parse (db,
                                      RHYTHMDB_QUERY_END);
-       array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
-       rb_value_array_append_data (array, G_TYPE_ULONG, 37 * 60);
        query_creator_test_load_query (db,
                                       query,
-                                      RHYTHMDB_QUERY_MODEL_LIMIT_TIME, array,
+                                      RHYTHMDB_QUERY_MODEL_LIMIT_TIME, g_variant_new_uint64 (37 * 60),
                                       "Title", GTK_SORT_ASCENDING);
        rhythmdb_query_free (query);
-       g_array_unref (array);
 }
 END_TEST
 
 START_TEST (test_query_creator_load_limit_hours)
 {
        RhythmDBQuery *query;
-       GArray *array;
 
        query = rhythmdb_query_parse (db,
                                      RHYTHMDB_QUERY_END);
-       array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
-       rb_value_array_append_data (array, G_TYPE_ULONG, 41 * 60 * 60);
        query_creator_test_load_query (db,
                                       query,
-                                      RHYTHMDB_QUERY_MODEL_LIMIT_TIME, array,
+                                      RHYTHMDB_QUERY_MODEL_LIMIT_TIME, g_variant_new_uint64 (41 * 60 * 60),
                                       "Title", GTK_SORT_ASCENDING);
        rhythmdb_query_free (query);
-       g_array_unref (array);
 }
 END_TEST
 
 START_TEST (test_query_creator_load_limit_days)
 {
        RhythmDBQuery *query;
-       GArray *array;
 
        query = rhythmdb_query_parse (db,
                                      RHYTHMDB_QUERY_END);
-       array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
-       rb_value_array_append_data (array, G_TYPE_ULONG, 13 * 60 * 60 * 24);
        query_creator_test_load_query (db,
                                       query,
-                                      RHYTHMDB_QUERY_MODEL_LIMIT_TIME, array,
+                                      RHYTHMDB_QUERY_MODEL_LIMIT_TIME, g_variant_new_uint64 (13 * 60 * 60 * 
24),
                                       "Title", GTK_SORT_ASCENDING);
        rhythmdb_query_free (query);
-       g_array_unref (array);
 }
 END_TEST
 
 START_TEST (test_query_creator_load_limit_mb)
 {
        RhythmDBQuery *query;
-       GArray *array;
 
        query = rhythmdb_query_parse (db,
                                      RHYTHMDB_QUERY_END);
-       array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
-       rb_value_array_append_data (array, G_TYPE_UINT64, (guint64)13);
        query_creator_test_load_query (db,
                                       query,
-                                      RHYTHMDB_QUERY_MODEL_LIMIT_SIZE, array,
+                                      RHYTHMDB_QUERY_MODEL_LIMIT_SIZE, g_variant_new_uint64 (13),
                                       "Title", GTK_SORT_ASCENDING);
        rhythmdb_query_free (query);
-       g_array_unref (array);
 }
 END_TEST
 
 START_TEST (test_query_creator_load_limit_gb)
 {
        RhythmDBQuery *query;
-       GArray *array;
 
        query = rhythmdb_query_parse (db,
                                      RHYTHMDB_QUERY_END);
-       array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-       g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
-       rb_value_array_append_data (array, G_TYPE_UINT64, (guint64)(14 * 1000));
        query_creator_test_load_query (db,
                                       query,
-                                      RHYTHMDB_QUERY_MODEL_LIMIT_SIZE, array,
+                                      RHYTHMDB_QUERY_MODEL_LIMIT_SIZE, g_variant_new_uint64 (14 * 1000),
                                       "Title", GTK_SORT_ASCENDING);
        rhythmdb_query_free (query);
-       g_array_unref (array);
 }
 END_TEST
 
diff --git a/widgets/rb-query-creator.c b/widgets/rb-query-creator.c
index 41d4be3..640d536 100644
--- a/widgets/rb-query-creator.c
+++ b/widgets/rb-query-creator.c
@@ -351,7 +351,7 @@ static gboolean
 rb_query_creator_load_query (RBQueryCreator *creator,
                              GPtrArray *query,
                             RhythmDBQueryModelLimitType limit_type,
-                             GArray *limit_value)
+                             GVariant *limit_value)
 {
        RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
        int i;
@@ -418,17 +418,17 @@ rb_query_creator_load_query (RBQueryCreator *creator,
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
                gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 0);
-               limit = g_value_get_ulong (&g_array_index (limit_value, GValue, 0));
+               limit = g_variant_get_uint64 (limit_value);
                break;
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
                gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 3);
                /* convert to minutes */
-               limit = g_value_get_ulong (&g_array_index (limit_value, GValue, 0)) / 60;
+               limit = g_variant_get_uint64 (limit_value) / 60;
                break;
 
        case RHYTHMDB_QUERY_MODEL_LIMIT_SIZE:
-               limit = g_value_get_uint64 (&g_array_index (limit_value, GValue, 0));
+               limit = g_variant_get_uint64 (limit_value);
 
                if (limit % 1000 == 0) {
                        gtk_combo_box_set_active (GTK_COMBO_BOX (priv->limit_option), 2);
@@ -495,7 +495,7 @@ GtkWidget *
 rb_query_creator_new_from_query (RhythmDB *db,
                                  GPtrArray *query,
                                 RhythmDBQueryModelLimitType limit_type,
-                                 GArray *limit_value,
+                                 GVariant *limit_value,
                                 const char *sort_column,
                                  gint sort_direction)
 {
@@ -632,13 +632,11 @@ rb_query_creator_get_query (RBQueryCreator *creator)
  * @limit: (out): used to return the limit value
  *
  * Retrieves the limit type and value from the query creator.
- * The limit value is returned as the first element in a
- * #GArray.
  */
 void
 rb_query_creator_get_limit (RBQueryCreator *creator,
                            RhythmDBQueryModelLimitType *type,
-                            GArray **limit)
+                            GVariant **limit)
 {
        RBQueryCreatorPrivate *priv;
 
@@ -648,29 +646,26 @@ rb_query_creator_get_limit (RBQueryCreator *creator,
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->limit_check))) {
                guint64 l;
-
                l = gtk_spin_button_get_value(GTK_SPIN_BUTTON (priv->limit_entry));
-               *limit = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0);
-               g_array_set_clear_func (*limit, (GDestroyNotify) g_value_unset);
 
                switch (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->limit_option))) {
                case 0:
                        *type = RHYTHMDB_QUERY_MODEL_LIMIT_COUNT;
-                       rb_value_array_append_data (*limit, G_TYPE_ULONG, (gulong)l);
+                       *limit = g_variant_new_uint64 (l);
                        break;
                case 1:
                        *type = RHYTHMDB_QUERY_MODEL_LIMIT_SIZE;
-                       rb_value_array_append_data (*limit, G_TYPE_UINT64, l);
+                       *limit = g_variant_new_uint64 (l);
                        break;
 
                case 2:
                        *type = RHYTHMDB_QUERY_MODEL_LIMIT_SIZE;
-                       rb_value_array_append_data (*limit, G_TYPE_UINT64, l * 1000);
+                       *limit = g_variant_new_uint64 (l * 1000);
                        break;
 
                case 3:
                        *type = RHYTHMDB_QUERY_MODEL_LIMIT_TIME;
-                       rb_value_array_append_data (*limit, G_TYPE_ULONG, (gulong)l * 60);
+                       *limit = g_variant_new_uint64 (l * 60);
                        break;
 
                default:
diff --git a/widgets/rb-query-creator.h b/widgets/rb-query-creator.h
index ccdd5f4..ab7af42 100644
--- a/widgets/rb-query-creator.h
+++ b/widgets/rb-query-creator.h
@@ -60,14 +60,14 @@ GType               rb_query_creator_get_type       (void);
 GtkWidget *    rb_query_creator_new            (RhythmDB *db);
 
 GtkWidget *    rb_query_creator_new_from_query (RhythmDB *db, GPtrArray *query,
-                                                RhythmDBQueryModelLimitType limit_type, GArray *limit_value,
+                                                RhythmDBQueryModelLimitType limit_type, GVariant 
*limit_value,
                                                 const char *sort_column, gint sort_direction);
 
 GPtrArray *    rb_query_creator_get_query      (RBQueryCreator *creator);
 
 void           rb_query_creator_get_limit      (RBQueryCreator *creator,
                                                 RhythmDBQueryModelLimitType *type,
-                                                GArray **limit);
+                                                GVariant **limit);
 
 void           rb_query_creator_get_sort_order (RBQueryCreator *creator, const char **sort_key, gint 
*sort_direction);
 


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