Greetings Everyone,

I've modified the Play Queue GUI to display the total play list time.
When there are no tracks queued, the default is displayed as it was
previously:

Play Queue

When there are tracks queued, rather than displaying something like
this...

Play Queue (8)

...it now displays...

Play Queue (8): 39 minutes, 28 seconds

I am receptive to criticism and I'd appreciate it if one of the
maintainers could look over my patch for consideration to apply against
svn head in trunk.

Thanks.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
Index: sources/rb-play-queue-source.c
===================================================================
--- sources/rb-play-queue-source.c	(revision 5821)
+++ sources/rb-play-queue-source.c	(working copy)
@@ -457,28 +457,89 @@
 				   GtkTreeModel *model,
 				   gint offset)
 {
-	gint count = gtk_tree_model_iter_n_children (model, NULL) + offset;
-	RBPlayQueueSourcePrivate *priv = RB_PLAY_QUEUE_SOURCE_GET_PRIVATE (source);
-	char *name = _("Play Queue");
-	GtkAction *action;
 
-	/* update source name */
-	if (count > 0)
-		name = g_strdup_printf ("%s (%d)", name, count);
+        gint count = gtk_tree_model_iter_n_children (model, NULL) + offset;
+        RBPlayQueueSourcePrivate *priv = RB_PLAY_QUEUE_SOURCE_GET_PRIVATE (source);
+        char *name = _("Play Queue");
+        char *pszTemp = NULL;
+        GtkAction *action;
 
-	g_object_set (G_OBJECT (source), "name", name, NULL);
-	gtk_tree_view_column_set_title (priv->sidebar_column, name);
+        // There are items available, update name to reflect this...
+        if (count > 0) {
 
-	if (count > 0)
-		g_free (name);
+            // Compute and format components of total duration needed later...
 
+                // Total duration...
+                glong const lTotalDuration = 
+                rhythmdb_query_model_get_duration(RHYTHMDB_QUERY_MODEL(model));
+
+                /* I think I am doing something wrong in the call above here,
+                   since removing a track from the play queue doesn't always
+                   result in the correct duration being returned here when this
+                   function is invoked - Kip ([EMAIL PROTECTED]) */
+
+                // Days...
+                glong const lDays = lTotalDuration / (60 * 60 * 24);
+                char *pszDays = g_strdup_printf(
+                    ngettext ("%ld day", "%ld days", lDays), lDays);
+
+                // Hours...
+                gint const nHours   = (lTotalDuration / (60 * 60)) - (lDays * 24);
+                char *pszHours = g_strdup_printf(
+                    ngettext ("%d hour", "%d hours", nHours), nHours);
+            
+                // Minutes...
+                gint const nMinutes = (lTotalDuration / 60) - ((lDays * 24 * 60) + (nHours * 60));
+                char *pszMinutes = g_strdup_printf(
+                    ngettext ("%d minute", "%d minutes", nMinutes), nMinutes);
+
+                // Seconds...
+                gint const nSeconds = lTotalDuration % 60;
+                char *pszSeconds = g_strdup_printf(
+                    ngettext ("%d second", "%d seconds", nSeconds), nSeconds);
+
+            // Long enough to mention days, hours, minutes, and seconds...
+            if (lDays > 0)
+                pszTemp = g_strjoin(", ", pszDays, pszHours, pszMinutes, pszSeconds, NULL);
+            
+            // Long enough to mention hours, minutes, and seconds...
+            else if (nHours > 0)
+                pszTemp = g_strjoin(", ", pszHours, pszMinutes, pszSeconds, NULL);
+
+            // Long enough to mention minutes and seconds...
+            else if (nMinutes > 0)
+                pszTemp = g_strjoin(", ", pszMinutes, pszSeconds, NULL);
+            
+            // Too short to mention anything other than seconds...
+            else
+                pszTemp = g_strdup(pszSeconds);
+
+            // Format the final string to display...
+            name = g_strdup_printf(
+            	"%s (%d): %s", _("Play Queue"), count, pszTemp);
+
+            // Cleanup...
+            g_free (pszTemp);
+            g_free (pszDays);
+            g_free (pszHours);
+            g_free (pszMinutes);
+            g_free (pszSeconds);
+        }
+
+        g_object_set (G_OBJECT (source), "name", name, NULL);
+        gtk_tree_view_column_set_title (priv->sidebar_column, name);
+
+        // Cleanup...
+        if (count > 0)
+            g_free (name);
+
 	/* make 'clear queue' and 'shuffle queue' actions sensitive when there are entries in the queue */
-	action = gtk_action_group_get_action (priv->action_group,
-					      "ClearQueue");
-	g_object_set (G_OBJECT (action), "sensitive", (count > 0), NULL);
+        action = gtk_action_group_get_action (
+            priv->action_group, "ClearQueue");
+        g_object_set (G_OBJECT (action), "sensitive", (count > 0), NULL);
 
-	action = gtk_action_group_get_action (priv->action_group, "ShuffleQueue");
-	g_object_set (G_OBJECT (action), "sensitive", (count > 0), NULL);
+        action = gtk_action_group_get_action (priv->action_group, "ShuffleQueue");
+        g_object_set (G_OBJECT (action), "sensitive", (count > 0), NULL);
 }
 
 static void

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
rhythmbox-devel mailing list
rhythmbox-devel@gnome.org
http://mail.gnome.org/mailman/listinfo/rhythmbox-devel

Reply via email to