diff -u -u -r1.24 rb-util.c
--- lib/rb-util.c	20 Apr 2006 20:43:21 -0000	1.24
+++ lib/rb-util.c	5 May 2006 12:51:38 -0000
@@ -20,11 +20,14 @@
  */
 #include "config.h"
 
-#include <gtk/gtk.h>
 #include <string.h>
+#include <stdarg.h>
+
+#include <gtk/gtk.h>
 #include <libgnome/gnome-i18n.h>
 #include <libgnomevfs/gnome-vfs.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
+#include <gobject/gvaluecollector.h>
 
 #include "rb-util.h"
 #include "rb-debug.h"
@@ -752,3 +755,23 @@
 	
 	return FALSE;
 }
+
+void
+rb_value_array_append_data (GValueArray *array, GType type, ...)
+{
+	GValue val = {0,};
+	va_list va;
+	gchar *err = NULL;
+
+	va_start (va, type);
+
+	g_value_init (&val, type);
+	G_VALUE_COLLECT (&val, va, 0, &err);
+	g_value_array_append (array, &val);
+
+	if (err)
+		rb_debug ("unable to collect GValue: %s", err);
+
+	va_end (va);
+}
+
diff -u -u -r1.19 rb-util.h
--- lib/rb-util.h	20 Apr 2006 20:43:21 -0000	1.19
+++ lib/rb-util.h	5 May 2006 12:51:38 -0000
@@ -66,6 +66,7 @@
 					       GValue *return_accu,
 					       const GValue *handler_return,
 					       gpointer dummy);
+void rb_value_array_append_data (GValueArray *array, GType type, ...);
 
 G_END_DECLS
 
diff -u -u -r1.120 rhythmdb-query-model.c
--- rhythmdb/rhythmdb-query-model.c	4 May 2006 22:10:03 -0000	1.120
+++ rhythmdb/rhythmdb-query-model.c	5 May 2006 12:51:39 -0000
@@ -152,6 +152,8 @@
 static int rhythmdb_query_model_child_index_to_base_index (RhythmDBQueryModel *model, int index);
 
 static gint _reverse_sorting_func (gpointer a, gpointer b, RhythmDBQueryModel *model);
+static gboolean rhythmdb_query_model_within_limit (RhythmDBQueryModel *model,
+						   RhythmDBEntry *entry);
 
 struct RhythmDBQueryModelUpdate
 {
@@ -194,9 +196,8 @@
 
 	guint stamp;
 
-	guint64 max_size;
-	guint max_count;
-	guint max_time;
+	RhythmDBQueryModelLimitType limit_type;
+	GValueArray *limit_value;
 
 	glong total_duration;
 	guint64 total_size;
@@ -222,9 +223,8 @@
 	PROP_SORT_FUNC,
 	PROP_SORT_PROP_ID,
 	PROP_SORT_REVERSE,
-	PROP_MAX_SIZE,
-	PROP_MAX_COUNT,
-	PROP_MAX_TIME,
+	PROP_LIMIT_TYPE,
+	PROP_LIMIT_VALUE,
 	PROP_SHOW_HIDDEN,
 	PROP_BASE_MODEL,
 };
@@ -291,26 +291,20 @@
 							      FALSE,
 							      G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
-					 PROP_MAX_SIZE,
-					 g_param_spec_int ("max-size",
-							   "maxsize",
-							   "maximum size (MB)",
-							   0, G_MAXINT, 0,
-							   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+					 PROP_LIMIT_TYPE,
+					 g_param_spec_enum ("limit-type",
+							    "limit-type",
+							    "type of limit",
+							    RHYTHMDB_TYPE_QUERY_MODEL_LIMIT_TYPE,
+							    RHYTHMDB_QUERY_MODEL_LIMIT_NONE,
+							    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 	g_object_class_install_property (object_class,
-					 PROP_MAX_COUNT,
-					 g_param_spec_int ("max-count",
-							   "maxcount",
-							   "maximum count (songs)",
-							   0, G_MAXINT, 0,
-							   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-	g_object_class_install_property (object_class,
-					 PROP_MAX_TIME,
-					 g_param_spec_int ("max-time",
-							   "maxtime",
-							   "maximum time (seconds)",
-							   0, G_MAXINT, 0,
-							   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+					 PROP_LIMIT_VALUE,
+					 g_param_spec_boxed ("limit-value",
+							     "limit-value",
+							     "value of limit",
+							     G_TYPE_VALUE_ARRAY,
+							     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 	g_object_class_install_property (object_class,
 					 PROP_SHOW_HIDDEN,
 					 g_param_spec_boolean ("show-hidden",
@@ -433,14 +427,13 @@
 	case PROP_SORT_REVERSE:
 		model->priv->sort_reverse  = g_value_get_boolean (value);
 		break;
-	case PROP_MAX_SIZE:
-		model->priv->max_size = g_value_get_int (value) * 1024 * 1024;
-		break;
-	case PROP_MAX_COUNT:
-		model->priv->max_count = g_value_get_int (value);
+	case PROP_LIMIT_TYPE:
+		model->priv->limit_type = g_value_get_enum (value);
 		break;
-	case PROP_MAX_TIME:
-		model->priv->max_time = g_value_get_int (value);
+	case PROP_LIMIT_VALUE:
+		if (model->priv->limit_value)
+			g_value_array_free (model->priv->limit_value);
+		model->priv->limit_value = (GValueArray*)g_value_dup_boxed (value);
 		break;
 	case PROP_SHOW_HIDDEN:
 		model->priv->show_hidden = g_value_get_boolean (value);
@@ -551,14 +544,11 @@
 	case PROP_SORT_REVERSE:
 		g_value_set_boolean (value, model->priv->sort_reverse);
 		break;
-	case PROP_MAX_SIZE:
-		g_value_set_int (value, model->priv->max_size / (1024 * 1024));
-		break;
-	case PROP_MAX_COUNT:
-		g_value_set_int (value, model->priv->max_count);
+	case PROP_LIMIT_TYPE:
+		g_value_set_enum (value, model->priv->limit_type);
 		break;
-	case PROP_MAX_TIME:
-		g_value_set_int (value, model->priv->max_time);
+	case PROP_LIMIT_VALUE:
+		g_value_set_boxed (value, model->priv->limit_value);
 		break;
 	case PROP_SHOW_HIDDEN:
 		g_value_set_boolean (value, model->priv->show_hidden);
@@ -684,6 +674,9 @@
 	if (model->priv->original_query)
 		rhythmdb_query_free (model->priv->original_query);
 
+	if (model->priv->limit_value)
+		g_value_array_free (model->priv->limit_value);
+
 	G_OBJECT_CLASS (rhythmdb_query_model_parent_class)->finalize (object);
 }
 
@@ -1024,10 +1017,7 @@
 	GSequencePtr ptr;
 
 	/* make it fit inside the limits */
-	while ((model->priv->max_count > 0 && g_hash_table_size (model->priv->reverse_map) > model->priv->max_count) ||
-	      (model->priv->max_size > 0 && model->priv->total_size > model->priv->max_size) ||
-	      (model->priv->max_time > 0 && model->priv->total_duration > model->priv->max_time)) {
-
+	while (!rhythmdb_query_model_within_limit (model, NULL)) {
 		ptr = g_sequence_ptr_prev (g_sequence_get_end_ptr (model->priv->entries));
 		entry = (RhythmDBEntry*) g_sequence_ptr_get_data (ptr);
 
@@ -1037,8 +1027,6 @@
 
 	/* move entries that were previously limited, back to the main list */
 	while (TRUE) {
-		int size;
-		int duration;
 		GtkTreePath *path;
 		GtkTreeIter iter;
 
@@ -1049,12 +1037,7 @@
 		if (!entry)
 			break;
 
-		size = rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE);
-		duration = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION);
-
-		if ((model->priv->max_count > 0 && (g_hash_table_size (model->priv->reverse_map) + 1) > model->priv->max_count) ||
-		    (model->priv->max_size > 0 && model->priv->total_size + size > model->priv->max_size) ||
-		    (model->priv->max_time > 0 && model->priv->total_duration + duration > model->priv->max_time))
+		if (!rhythmdb_query_model_within_limit (model, entry))
 			break;
 
 		rhythmdb_query_model_remove_from_limited_list (model, entry);
@@ -1875,9 +1858,7 @@
 	    (model->priv->sort_reverse == sort_reverse))
 		return;
 	
-	g_return_if_fail (((model->priv->max_count == 0) &&
-			  (model->priv->max_time == 0) &&
-			  (model->priv->max_size == 0)) ||
+	g_return_if_fail ((model->priv->limit_type == RHYTHMDB_QUERY_MODEL_LIMIT_NONE) ||
 			  (model->priv->sort_func == NULL));
 	if (model->priv->sort_func == NULL)
 		g_assert (g_sequence_get_length (model->priv->limited_entries) == 0);
@@ -2393,5 +2374,89 @@
 		return rhythmdb_query_model_location_sort_func (a, b, model);
 }
 
+static gboolean
+rhythmdb_query_model_within_limit (RhythmDBQueryModel *model, RhythmDBEntry *entry)
+{
+	gboolean result = TRUE;
 
+	switch (model->priv->limit_type) {
+	case RHYTHMDB_QUERY_MODEL_LIMIT_NONE:
+		result = TRUE;
+		break;
+
+	case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
+		{
+			gulong limit_count;
+			gulong current_count;
+			
+			limit_count = g_value_get_ulong (g_value_array_get_nth (model->priv->limit_value, 0));
+			current_count = g_hash_table_size (model->priv->reverse_map);
+
+			if (entry)
+				current_count++;
+
+			result = (current_count <= limit_count);
+			break;
+		}
+
+	case RHYTHMDB_QUERY_MODEL_LIMIT_SIZE:
+		{
+			guint64 limit_size;
+			guint64 current_size;
+			
+			limit_size = g_value_get_uint64 (g_value_array_get_nth (model->priv->limit_value, 0));
+			current_size = model->priv->total_size;
+
+			if (entry)
+				current_size += rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE);
+
+			/* the limit is in MB */
+			result = (current_size / (1024 * 1024) <= limit_size);
+			break;
+		}
+
+	case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
+		{
+			gulong limit_time;
+			gulong current_time;
+			
+			limit_time = g_value_get_ulong (g_value_array_get_nth (model->priv->limit_value, 0));
+			current_time = model->priv->total_duration;
+
+			if (entry)
+				current_time += rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION);
+
+			result = (current_time <= limit_time);
+			break;
+		}
+	}
+
+	return result;
+}
+
+/* This should really be standard. */
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+GType
+rhythmdb_query_model_limit_type_get_type (void)
+{
+	static GType etype = 0;
+
+	if (etype == 0)
+	{
+		static const GEnumValue values[] =
+		{
+
+			ENUM_ENTRY (RHYTHMDB_QUERY_MODEL_LIMIT_NONE, "No limit"),
+			ENUM_ENTRY (RHYTHMDB_QUERY_MODEL_LIMIT_COUNT, "Limit by number of entries (count)"),
+			ENUM_ENTRY (RHYTHMDB_QUERY_MODEL_LIMIT_SIZE, "Limit by data size (Mb)"),
+			ENUM_ENTRY (RHYTHMDB_QUERY_MODEL_LIMIT_TIME, "Limit by duration (seconds)"),
+			{ 0, 0, 0 }
+		};
+
+		etype = g_enum_register_static ("RhythmDBQueryModelLimitType", values);
+	}
+
+	return etype;
+}
 
diff -u -u -r1.27 rhythmdb-query-model.h
--- rhythmdb/rhythmdb-query-model.h	20 Apr 2006 20:43:28 -0000	1.27
+++ rhythmdb/rhythmdb-query-model.h	5 May 2006 12:51:39 -0000
@@ -38,6 +38,18 @@
 #define RHYTHMDB_IS_QUERY_MODEL_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), RHYTHMDB_TYPE_QUERY_MODEL))
 #define RHYTHMDB_QUERY_MODEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RHYTHMDB_TYPE_QUERY_MODEL, RhythmDBQueryModelClass))
 
+
+GType rhythmdb_query_model_limit_type_get_type (void);
+#define RHYTHMDB_TYPE_QUERY_MODEL_LIMIT_TYPE (rhythmdb_query_model_limit_type_get_type ())
+
+typedef enum {
+	RHYTHMDB_QUERY_MODEL_LIMIT_NONE,
+	RHYTHMDB_QUERY_MODEL_LIMIT_COUNT,
+	RHYTHMDB_QUERY_MODEL_LIMIT_SIZE,
+	RHYTHMDB_QUERY_MODEL_LIMIT_TIME,
+} RhythmDBQueryModelLimitType;
+
+
 typedef struct RhythmDBQueryModelPrivate RhythmDBQueryModelPrivate;
 
 #define RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK 32
diff -u -u -r1.102 rb-playlist-manager.c
--- shell/rb-playlist-manager.c	3 May 2006 05:58:11 -0000	1.102
+++ shell/rb-playlist-manager.c	5 May 2006 12:51:40 -0000
@@ -1002,26 +1002,17 @@
 					    RBAutoPlaylistSource *playlist,
 					    RBQueryCreator *creator)
 {
-	RBQueryCreatorLimitType type;
-	guint limit, limit_count = 0, limit_size = 0, limit_time = 0;
+	RhythmDBQueryModelLimitType limit_type;
+	GValueArray *limit_value = NULL;
 	const char *sort_key;
 	gint sort_direction;
 
-	rb_query_creator_get_limit (creator, &type, &limit);
-	if (type == RB_QUERY_CREATOR_LIMIT_COUNT)
-		limit_count = limit;
-	else if (type == RB_QUERY_CREATOR_LIMIT_MB)
-		limit_size = limit;
-	else if (type == RB_QUERY_CREATOR_LIMIT_SECONDS)
-		limit_time = limit;
-	else
-		g_assert_not_reached ();
-
+	rb_query_creator_get_limit (creator, &limit_type, &limit_value);
 	rb_query_creator_get_sort_order (creator, &sort_key, &sort_direction);
 
 	rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (playlist),
 					   rb_query_creator_get_query (creator),
-					   limit_count, limit_size, limit_time,
+					   limit_type, limit_value,
 					   sort_key, sort_direction);
 }
 
@@ -1090,21 +1081,27 @@
 {
 	RBQueryCreator *creator;
 	RBAutoPlaylistSource *playlist;
-	GPtrArray *query;
-	guint limit_count = 0, limit_size = 0, limit_time = 0;
-	const char *sort_key;
-	gint sort_direction;
-	EditAutoPlaylistData *data;
 
 	playlist = RB_AUTO_PLAYLIST_SOURCE (mgr->priv->selected_source);
 	creator = g_object_get_data (G_OBJECT (playlist), "rhythmbox-playlist-editor");
+
 	if (creator == NULL) {
-		rb_auto_playlist_source_get_query (playlist, &query, &limit_count, &limit_size, &limit_time, &sort_key, &sort_direction);
+		RhythmDBQueryModelLimitType limit_type;
+		GValueArray *limit_value = NULL;
+		GPtrArray *query;
+		const char *sort_key;
+		gint sort_direction;
+		EditAutoPlaylistData *data;
+
+		rb_auto_playlist_source_get_query (playlist, &query,
+						   &limit_type, &limit_value,
+						   &sort_key, &sort_direction);
 
 		creator = RB_QUERY_CREATOR (rb_query_creator_new_from_query (mgr->priv->db,
 									     query,
-									     limit_count, limit_size, limit_time,
+									     limit_type, limit_value,
 									     sort_key, sort_direction));
+		g_value_array_free (limit_value);
 
 		data = g_new0 (EditAutoPlaylistData, 1);
 		data->mgr = mgr;
diff -u -u -r1.15 rb-auto-playlist-source.c
--- sources/rb-auto-playlist-source.c	20 Apr 2006 20:43:30 -0000	1.15
+++ sources/rb-auto-playlist-source.c	5 May 2006 12:51:41 -0000
@@ -86,9 +86,8 @@
 	RhythmDBQueryModel *cached_all_query;
 	GPtrArray *query;
 	gboolean query_resetting;
-	guint limit_count;
-	guint limit_mb;
-	guint limit_time;
+	RhythmDBQueryModelLimitType limit_type;
+	GValueArray *limit_value;
 
 	gboolean query_active;
 	gboolean search_on_completion;
@@ -160,8 +159,10 @@
 	if (priv->query)
 		rhythmdb_query_free (priv->query);
 
-	if (priv->search_text)
-		g_free (priv->search_text);
+	if (priv->limit_value)
+		g_value_array_free (priv->limit_value);
+
+	g_free (priv->search_text);
 
 	G_OBJECT_CLASS (rb_auto_playlist_source_parent_class)->finalize (object);
 }
@@ -242,9 +243,11 @@
 	xmlNodePtr child;
 	xmlChar *tmp;
 	GPtrArray *query;
-	gint limit_count = 0, limit_mb = 0, limit_time = 0;
+	RhythmDBQueryModelLimitType limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_NONE;
+	GValueArray *limit_value = NULL;
 	gchar *sort_key = NULL;
 	gint sort_direction = 0;
+	GValue val = {0,};
 
 	child = node->children;
 	while (xmlNodeIsText (child))
@@ -253,22 +256,44 @@
 	query = rhythmdb_query_deserialize (rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source)), 
 					    child);
 
+	limit_value = g_value_array_new (0);
 	tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_COUNT);
 	if (!tmp) /* Backwards compatibility */
 		tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT);
 	if (tmp) {
-		limit_count = atoi ((char*) tmp);
+		limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_COUNT;
+
+		g_value_init (&val, G_TYPE_ULONG);
+		g_value_set_ulong (&val, atoi ((char*) tmp));
+		g_value_array_append (limit_value, &val);
 		g_free (tmp);
+		g_value_unset (&val);
 	}
-	tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_SIZE);
-	if (tmp) {
-		limit_mb = atoi ((char*) tmp);
-		g_free (tmp);
+
+	if (limit_value == NULL) {
+		tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_SIZE);
+		if (tmp) {
+			limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_SIZE;
+
+			g_value_init (&val, G_TYPE_ULONG);
+			g_value_set_ulong (&val, atoi ((char*) tmp));
+			g_value_array_append (limit_value, &val);
+			g_free (tmp);
+			g_value_unset (&val);
+		}
 	}
-	tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_TIME);
-	if (tmp) {
-		limit_time = atoi ((char*) tmp);
-		g_free (tmp);
+
+	if (limit_value == NULL) {
+		tmp = xmlGetProp (node, RB_PLAYLIST_LIMIT_TIME);
+		if (tmp) {
+			limit_type = RHYTHMDB_QUERY_MODEL_LIMIT_TIME;
+
+			g_value_init (&val, G_TYPE_ULONG);
+			g_value_set_ulong (&val, atoi ((char*) tmp));
+			g_value_array_append (limit_value, &val);
+			g_free (tmp);
+			g_value_unset (&val);
+		}
 	}
 
 	sort_key = (gchar*) xmlGetProp (node, RB_PLAYLIST_SORT_KEY);
@@ -285,12 +310,12 @@
 	}
 
 	rb_auto_playlist_source_set_query (source, query,
-					    limit_count,
-					    limit_mb,
-					    limit_time,
-					    sort_key,
-					    sort_direction);
+					   limit_type,
+					   limit_value,
+					   sort_key,
+					   sort_direction);
 	g_free (sort_key);
+	g_value_array_free (limit_value);
 
 	return RB_SOURCE (source);
 }
@@ -452,7 +477,9 @@
 					      RHYTHMDB_QUERY_SUBQUERY,
 					      subquery,
 					      RHYTHMDB_QUERY_END);
-		rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (source), query, 0, 0, 0, NULL, 0);
+		rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (source), query,
+						   RHYTHMDB_QUERY_MODEL_LIMIT_NONE, NULL,
+						   NULL, 0);
 	}
 
 	g_object_unref (G_OBJECT (db));
@@ -460,33 +487,58 @@
 	return TRUE;
 }
 
+static void
+_save_write_ulong (xmlNodePtr node, GValueArray *limit_value, const xmlChar *key)
+{
+	gulong l;
+	gchar *str;
+
+	l = g_value_get_ulong (g_value_array_get_nth (limit_value, 0));
+	str = g_strdup_printf ("%u", (guint)l);
+	xmlSetProp (node, key, BAD_CAST str);
+	g_free (str);
+}
+
 static void 
 impl_save_contents_to_xml (RBPlaylistSource *psource, xmlNodePtr node)
 {
 	GPtrArray *query;
-	guint max_count, max_size_mb, max_time;
+	RhythmDBQueryModelLimitType limit_type;
+	GValueArray *limit_value = NULL;
 	const gchar *sort_key;
 	gint sort_direction;
-	gchar *temp_str;
 	RBAutoPlaylistSource *source = RB_AUTO_PLAYLIST_SOURCE (psource);
 
 	xmlSetProp (node, RB_PLAYLIST_TYPE, RB_PLAYLIST_AUTOMATIC);
 
 	rb_auto_playlist_source_get_query (source,
 					    &query,
-					    &max_count, &max_size_mb, &max_time,
+					    &limit_type, &limit_value,
 					    &sort_key, &sort_direction);
-	temp_str = g_strdup_printf ("%d", max_count);
-	xmlSetProp (node, RB_PLAYLIST_LIMIT_COUNT, BAD_CAST temp_str);
-	g_free (temp_str);
-	temp_str = g_strdup_printf ("%d", max_size_mb);
-	xmlSetProp (node, RB_PLAYLIST_LIMIT_SIZE, BAD_CAST temp_str);
-	g_free (temp_str);
-	temp_str = g_strdup_printf ("%d", max_time);
-	xmlSetProp (node, RB_PLAYLIST_LIMIT_TIME, BAD_CAST temp_str);
-	g_free (temp_str);
+
+	switch (limit_type) {
+	case RHYTHMDB_QUERY_MODEL_LIMIT_NONE:
+		break;
+		
+	case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
+		_save_write_ulong (node, limit_value, RB_PLAYLIST_LIMIT_COUNT);
+		break;
+
+	case RHYTHMDB_QUERY_MODEL_LIMIT_SIZE:
+		_save_write_ulong (node, limit_value, RB_PLAYLIST_LIMIT_SIZE);
+		break;
+
+	case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
+		_save_write_ulong (node, limit_value, RB_PLAYLIST_LIMIT_TIME);
+		break;
+
+	default:
+		g_assert_not_reached ();
+	}
 
 	if (sort_key && *sort_key) {
+		gchar *temp_str;
+
 		xmlSetProp (node, RB_PLAYLIST_SORT_KEY, BAD_CAST sort_key);
 		temp_str = g_strdup_printf ("%d", sort_direction);
 		xmlSetProp (node, RB_PLAYLIST_SORT_DIRECTION, BAD_CAST temp_str);
@@ -494,6 +546,9 @@
 	}
 
 	rhythmdb_query_serialize (rb_playlist_source_get_db (psource), query, node);
+
+	if (limit_value)
+		g_value_array_free (limit_value);
 }
 
 static void
@@ -544,9 +599,8 @@
 		/* otherwise, we need a new query model */
 		query_model = g_object_new (RHYTHMDB_TYPE_QUERY_MODEL,
 					    "db", db,
-					    "max-count", priv->limit_count,
-					    "max-size", priv->limit_mb,
-					    "max-time", priv->limit_time, 
+					    "limit-type", priv->limit_type,
+					    "limit-value", priv->limit_value,
 					    NULL);
 		rb_library_browser_set_model (priv->browser, query_model, TRUE);
 
@@ -565,12 +619,11 @@
 
 void
 rb_auto_playlist_source_set_query (RBAutoPlaylistSource *source,
-				    GPtrArray *query,
-				    guint limit_count,
-				    guint limit_mb,
-				    guint limit_time,
-				    const char *sort_key,
-				    gint sort_direction)
+				   GPtrArray *query,
+				   RhythmDBQueryModelLimitType limit_type,
+				   GValueArray *limit_value,
+				   const char *sort_key,
+				   gint sort_direction)
 {
 	RBAutoPlaylistSourcePrivate *priv = RB_AUTO_PLAYLIST_SOURCE_GET_PRIVATE (source);
 	RhythmDB *db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source));
@@ -583,20 +636,21 @@
 		g_object_unref (G_OBJECT (priv->cached_all_query));
 
 	/* playlists that aren't limited, with a particular sort order, are user-orderable */
-	rb_entry_view_set_columns_clickable (songs, (limit_count == 0 && limit_mb == 0 && limit_time == 0));
+	rb_entry_view_set_columns_clickable (songs, (limit_type == RHYTHMDB_QUERY_MODEL_LIMIT_NONE));
 	rb_entry_view_set_sorting_order (songs, sort_key, sort_direction);
 
 	priv->query = query;
-	priv->limit_count = limit_count;
-	priv->limit_mb = limit_mb;
-	priv->limit_time = limit_time;
-	
+	priv->limit_type = limit_type;
+	if (priv->limit_value)
+		g_value_array_free (priv->limit_value);
+	priv->limit_value = limit_value ? g_value_array_copy (limit_value) : NULL;
+
 	priv->cached_all_query = g_object_new (RHYTHMDB_TYPE_QUERY_MODEL,
 					      "db", db,
-					      "max-count", priv->limit_count,
-					      "max-size", priv->limit_mb,
-					      "max-time", priv->limit_time, 
+					      "limit-type", priv->limit_type,
+					      "limit-value", priv->limit_value,
 					      NULL);
+
 	rb_library_browser_set_model (priv->browser, priv->cached_all_query, TRUE);
 	rhythmdb_do_full_query_async_parsed (db, 
 					     RHYTHMDB_QUERY_RESULTS (priv->cached_all_query), 
@@ -609,9 +663,8 @@
 void
 rb_auto_playlist_source_get_query (RBAutoPlaylistSource *source,
 				    GPtrArray **query,
-				    guint *limit_count,
-				    guint *limit_mb,
-				    guint *limit_time,
+				    RhythmDBQueryModelLimitType *limit_type,
+				    GValueArray **limit_value,
 				    const char **sort_key,
 				    gint *sort_direction)
 {
@@ -619,9 +672,8 @@
 	RBEntryView *songs = rb_source_get_entry_view (RB_SOURCE (source));
 
 	*query = priv->query;
-	*limit_count = priv->limit_count;
-	*limit_mb = priv->limit_mb;
-	*limit_time = priv->limit_time;
+	*limit_type = priv->limit_type;
+	*limit_value = (priv->limit_value) ? g_value_array_copy (priv->limit_value) : NULL;
 
 	rb_entry_view_get_sorting_order (songs, sort_key, sort_direction);
 }
diff -u -u -r1.2 rb-auto-playlist-source.h
--- sources/rb-auto-playlist-source.h	20 Apr 2006 20:43:30 -0000	1.2
+++ sources/rb-auto-playlist-source.h	5 May 2006 12:51:41 -0000
@@ -58,17 +58,15 @@
 
 void		rb_auto_playlist_source_set_query	(RBAutoPlaylistSource *source,
 							 GPtrArray *query,
-							 guint limit_count,
-							 guint limit_mb,
-							 guint limit_time,
+							 RhythmDBQueryModelLimitType limit_type,
+							 GValueArray *limit_value,
 							 const char *sort_key,
 						 	 gint sort_order);
 
 void		rb_auto_playlist_source_get_query	(RBAutoPlaylistSource *source,
 							 GPtrArray **query,
-							 guint *limit_count,
-							 guint *limit_mb,
-							 guint *limit_time,
+							 RhythmDBQueryModelLimitType *limit_type,
+							 GValueArray **limit_value,
 							 const char **sort_key,
 							 gint *sort_order);
 
diff -u -u -r1.167 rb-library-source.c
--- sources/rb-library-source.c	3 May 2006 05:58:11 -0000	1.167
+++ sources/rb-library-source.c	5 May 2006 12:51:42 -0000
@@ -1201,7 +1201,9 @@
 				      RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_SONG,
 				      RHYTHMDB_QUERY_PROP_PREFIX, RHYTHMDB_PROP_LOCATION, path,
 				      RHYTHMDB_QUERY_END);
-	rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (source), query, 0, 0, 0, NULL, 0);
+	rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (source), query,
+					   RHYTHMDB_QUERY_MODEL_LIMIT_NONE, NULL,
+					   NULL, 0);
 	rhythmdb_query_free (query);
 
 	g_object_get (G_OBJECT (library_source), "icon", &icon, NULL);
diff -u -u -r1.4 rb-psp-source.c
--- sources/rb-psp-source.c	20 Apr 2006 20:43:30 -0000	1.4
+++ sources/rb-psp-source.c	5 May 2006 12:51:42 -0000
@@ -152,7 +152,8 @@
 
 	playlist = rb_auto_playlist_source_new (shell, rel_path, FALSE);
 	rb_auto_playlist_source_set_query (RB_AUTO_PLAYLIST_SOURCE (playlist), query,
-					  0, 0, 0, NULL, 0);
+					   RHYTHMDB_QUERY_MODEL_LIMIT_NONE, NULL,
+					   NULL, 0);
 	rb_shell_append_source (shell, playlist, RB_SOURCE (source));
 	g_object_unref (G_OBJECT (shell));
 	g_object_unref (G_OBJECT (db));
diff -u -u -r1.37 rb-query-creator.c
--- widgets/rb-query-creator.c	20 Apr 2006 20:43:31 -0000	1.37
+++ widgets/rb-query-creator.c	5 May 2006 12:51:42 -0000
@@ -32,6 +32,7 @@
 #include "rb-debug.h"
 #include "rb-preferences.h"
 #include "rb-glade-helpers.h"
+#include "rb-util.h"
 
 
 static void rb_query_creator_class_init (RBQueryCreatorClass *klass);
@@ -301,7 +302,7 @@
 
 static gboolean
 rb_query_creator_load_query (RBQueryCreator *creator, GPtrArray *query,
-			     int limit_count, int limit_size, int limit_time)
+			     RhythmDBQueryModelLimitType limit_type, GValueArray *limit_value)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
 	int i;
@@ -355,25 +356,38 @@
 
 	/* setup the limits */
 	{
-		int limit;
+		gulong limit;
 
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->disjunction_check),
 					      disjunction);
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->limit_check),
-					      limit_count || limit_size || limit_time);
-				
-		if (limit_count > 0) {
+					      limit_type != RHYTHMDB_QUERY_MODEL_LIMIT_NONE);
+
+		switch (limit_type) {
+		case RHYTHMDB_QUERY_MODEL_LIMIT_COUNT:
 			gtk_option_menu_set_history (GTK_OPTION_MENU (priv->limit_option), 0);
-			limit = limit_count;
-		} else if (limit_time > 0) {
+			limit = g_value_get_ulong (g_value_array_get_nth (limit_value, 0));
+			break;
+
+		case RHYTHMDB_QUERY_MODEL_LIMIT_TIME:
 			gtk_option_menu_set_history (GTK_OPTION_MENU (priv->limit_option), 3);
-			limit = limit_time / 60;
-		} else if (limit_size % 1000 == 0) {
-			gtk_option_menu_set_history (GTK_OPTION_MENU (priv->limit_option), 2);
-			limit = limit_size / 1000;
-		} else {
-			gtk_option_menu_set_history (GTK_OPTION_MENU (priv->limit_option), 1);
-			limit = limit_size;
+			/* convert to minutes */
+			limit = g_value_get_ulong (g_value_array_get_nth (limit_value, 0)) / 60;
+			break;
+
+		case RHYTHMDB_QUERY_MODEL_LIMIT_SIZE:
+			limit = g_value_get_ulong (g_value_array_get_nth (limit_value, 0));
+
+			if (limit % 1000 == 0) {
+				gtk_option_menu_set_history (GTK_OPTION_MENU (priv->limit_option), 2);
+				limit /= 1000;
+			} else {
+				gtk_option_menu_set_history (GTK_OPTION_MENU (priv->limit_option), 1);
+			}
+
+			break;
+		default:
+			g_assert_not_reached ();
 		}
 
 		gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->limit_entry), limit);
@@ -411,7 +425,7 @@
 
 GtkWidget *
 rb_query_creator_new_from_query (RhythmDB *db, GPtrArray *query,
-				 int limit_count, int limit_size, int limit_time,
+				 RhythmDBQueryModelLimitType limit_type, GValueArray *limit_value,
 				 const char *sort_column, gint sort_direction)
 {
 	RBQueryCreator *creator = g_object_new (RB_TYPE_QUERY_CREATOR, "db", db,
@@ -419,7 +433,7 @@
 	if (!creator)
 		return NULL;
 
-	if ( !rb_query_creator_load_query (creator, query, limit_count, limit_size, limit_time)
+	if ( !rb_query_creator_load_query (creator, query, limit_type, limit_value)
 	   | !rb_query_creator_set_sorting (creator, sort_column, sort_direction)) {
 		gtk_widget_destroy (GTK_WIDGET (creator));
 		return NULL;
@@ -520,35 +534,43 @@
 }
 
 void
-rb_query_creator_get_limit (RBQueryCreator *creator, RBQueryCreatorLimitType *type,
-			    guint *limit)
+rb_query_creator_get_limit (RBQueryCreator *creator,
+			    RhythmDBQueryModelLimitType *type, GValueArray **limit)
 {
 	RBQueryCreatorPrivate *priv = QUERY_CREATOR_GET_PRIVATE (creator);
-	guint limitpos;
 
-	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->limit_check)))
-		*limit = (guint) gtk_spin_button_get_value(GTK_SPIN_BUTTON (priv->limit_entry));
-	else
-		*limit = 0;
-	limitpos = gtk_option_menu_get_history (GTK_OPTION_MENU (priv->limit_option));
-	switch (limitpos)
-	{
-	case 0:
-		*type = RB_QUERY_CREATOR_LIMIT_COUNT;
-		break;
-	case 1:
-		*type = RB_QUERY_CREATOR_LIMIT_MB;
-		break;
-	case 2:
-		*type = RB_QUERY_CREATOR_LIMIT_MB;
-		*limit *= 1000;
-		break;
-	case 3:
-		*type = RB_QUERY_CREATOR_LIMIT_SECONDS;
-		*limit *= 60;
-		break;
-	default:
-		g_assert_not_reached ();
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->limit_check))) {
+		gint l;
+
+		l = gtk_spin_button_get_value(GTK_SPIN_BUTTON (priv->limit_entry));
+		*limit = g_value_array_new (0);
+
+		switch (gtk_option_menu_get_history (GTK_OPTION_MENU (priv->limit_option))) {
+		case 0:
+			*type = RHYTHMDB_QUERY_MODEL_LIMIT_COUNT;
+			rb_value_array_append_data (*limit, G_TYPE_ULONG, l);
+			break;
+		case 1:
+			*type = RHYTHMDB_QUERY_MODEL_LIMIT_SIZE;
+			rb_value_array_append_data (*limit, G_TYPE_ULONG, l);
+			break;
+
+		case 2:
+			*type = RHYTHMDB_QUERY_MODEL_LIMIT_SIZE;
+			rb_value_array_append_data (*limit, G_TYPE_ULONG, l);
+			break;
+
+		case 3:
+			*type = RHYTHMDB_QUERY_MODEL_LIMIT_TIME;
+			rb_value_array_append_data (*limit, G_TYPE_ULONG, l * 60);
+			break;
+
+		default:
+			g_assert_not_reached ();
+		}
+	} else {
+		*type = RHYTHMDB_QUERY_MODEL_LIMIT_NONE;
+		*limit = NULL;
 	}
 }
 
diff -u -u -r1.6 rb-query-creator.h
--- widgets/rb-query-creator.h	20 Apr 2006 20:43:31 -0000	1.6
+++ widgets/rb-query-creator.h	5 May 2006 12:51:42 -0000
@@ -20,7 +20,9 @@
  */
 
 #include <gtk/gtkdialog.h>
+
 #include "rhythmdb.h"
+#include "rhythmdb-query-model.h"
 
 #ifndef __RB_QUERY_CREATOR_H
 #define __RB_QUERY_CREATOR_H
@@ -44,27 +46,20 @@
 	GtkDialogClass parent_class;
 } RBQueryCreatorClass;
 
-typedef enum
-{
-	RB_QUERY_CREATOR_LIMIT_COUNT,
-	RB_QUERY_CREATOR_LIMIT_MB,
-	RB_QUERY_CREATOR_LIMIT_SECONDS,
-} RBQueryCreatorLimitType;	
-
 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,
-						 int limit_count, int limit_size, int limit_time,
+						 RhythmDBQueryModelLimitType limit_type, GValueArray *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,
-						 RBQueryCreatorLimitType *type,
-						 guint *limit);
+						 RhythmDBQueryModelLimitType *limit_type,
+						 GValueArray **limit_value);
 
 void		rb_query_creator_get_sort_order (RBQueryCreator *creator, const char **sort_key, gint *sort_direction);
 
