On Tue, Apr 26, 2005 at 11:04:53PM +1000, James Livingston wrote:
> G'day everyone,
> 
> I've got some more autoplaylist goodness for you all, hot off the press:
> support for Recently Added & Recently Played criteria.
> 
> Recently Played isn't very much use at the moment, because the playlist
> will only update when Rhythmbox re-runs the query - which from my
> experience (in the last 10 minutes) is when you quit and restart the RB.
> 
> One word of warning: if you have a playlist that uses either of these
> two criteria, and try to open an older version that doesn't support them
> _IT WILL CRASH_ as older versions don't understand my new
> "current-time-within" operator.

Does anyone think it's worth handling this a bit better?  Maybe show
the playlist as broken or disabled, and somehow manage to write the
query out to the playlist file untouched?

> I think I've pretty much got everything apart from polish done on the
> playlist criteria - so if you see anything like bugs, typos, defaults
> that could have better values, etc. let me know. Also if there are
> criteria that aren't there though you think should be (or ones that are
> there that shouldn't be) let me know too.

The attached patch fixes a bug where you'd get an assertion failure if
you had text in the search box and you selected an artist/album/genre
from the browser.  The resulting query has 3 components (song type,
search text, artist/album/genre), but rhythmbox_query_magic_transform
was only handling queries with 2 components.

thanks,
-jonathan
--- orig/rhythmdb/rhythmdb.c
+++ mod/rhythmdb/rhythmdb.c
@@ -2975,59 +2975,60 @@
 rhythmdb_query_magic_transform(GPtrArray *query)
 {
        int i;
+       int q;
        RhythmDBQueryData *qdata;
        GPtrArray *subquery;
        GTimeVal current_time;
+       gulong relative_time;
+       gulong absolute_time;
        
        /* make sure it is a valid query to transform */
-       if (query == NULL || query->len == 1)
+       if (query == NULL || query->len == 0)
                return;
 
-       qdata = g_ptr_array_index (query, 1);
-       if (qdata->type != RHYTHMDB_QUERY_SUBQUERY)
-               return;
-
-       g_assert (query->len == 2);
-               
-       subquery = qdata->subquery;
-       
        /*
         * Determine things that will be needed to convert the operators,
         * such as the current time
         */
        g_get_current_time  (&current_time);
-       
-       for (i = 0; i < subquery->len; i++) {
-               RhythmDBQueryData *data = g_ptr_array_index (subquery, i);
 
-               switch (data->type) {
-               /*
-                * Convert the current-time relative operators into ones that
-                * the backend(s) understand
-                */
-               case RHYTHMDB_QUERY_PROP_CURRENT_TIME_WITHIN:
-                       {
-                               gulong relative_time = g_value_get_ulong 
(data->val);
-                               gulong absolute_time = current_time.tv_sec - 
relative_time;
-                               
-                               rb_debug("Converting current-time-within 
operator. Rel %d(%s), Abs %d", relative_time, G_VALUE_TYPE_NAME (data->val), 
absolute_time);
+       /* process all subqueries */
+       for (q = 0; q < query->len; q++) {
+               qdata = g_ptr_array_index (query, q);
+               if (qdata->type != RHYTHMDB_QUERY_SUBQUERY)
+                       continue;
+
+               subquery = qdata->subquery;
+
+               for (i = 0; i < subquery->len; i++) {
+                       RhythmDBQueryData *data = g_ptr_array_index (subquery, 
i);
+
+
+                       switch (data->type) {
+                       /*
+                        * Convert the current-time relative operators into 
ones that
+                        * the backend(s) understand
+                        */
+                       case RHYTHMDB_QUERY_PROP_CURRENT_TIME_WITHIN:
+                               relative_time = g_value_get_ulong (data->val);
+                               absolute_time = current_time.tv_sec - 
relative_time;
+                               rb_debug("Converting current-time-within 
operator. Rel %d(%s), Abs %d", 
+                                        relative_time, G_VALUE_TYPE_NAME 
(data->val), absolute_time);
                                
                                g_value_set_ulong(data->val, absolute_time);
                                data->type = RHYTHMDB_QUERY_PROP_GREATER_EQUALS;
-                       }
-                       break;
-                               
-               case RHYTHMDB_QUERY_PROP_CURRENT_TIME_NOT_WITHIN:
-                       {
-                               gulong relative_time = g_value_get_ulong 
(data->val);
-                               gulong absolute_time = current_time.tv_sec - 
relative_time;
-                               
-                               rb_debug("Converting current-time-not-within 
operator. Rel %d, Abs %d", relative_time, absolute_time);
+                               break;
+                                       
+                       case RHYTHMDB_QUERY_PROP_CURRENT_TIME_NOT_WITHIN:
+                               relative_time = g_value_get_ulong (data->val);
+                               absolute_time = current_time.tv_sec - 
relative_time;
+                               rb_debug("Converting current-time-not-within 
operator. Rel %d, Abs %d", 
+                                        relative_time, absolute_time);
                                
                                g_value_set_ulong(data->val, absolute_time);
                                data->type = RHYTHMDB_QUERY_PROP_LESS;
+                               break;
                        }
-                       break;
                }
        }
 }
_______________________________________________
rhythmbox-devel mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/rhythmbox-devel

Reply via email to