rhythmbox r6276 - in trunk: . rhythmdb widgets



Author: jmatthew
Date: Tue Apr  7 06:32:46 2009
New Revision: 6276
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=6276&view=rev

Log:
2009-04-07  Jonathan Matthew  <jonathan d14n org>

	patch by:  Paul Bellamy  <paul a bellamy gmail com>

	* rhythmdb/rhythmdb.c: (rhythmdb_entry_is_lossless):
	* rhythmdb/rhythmdb.h:
	Add a function to determine if an entry represents a lossless encoded
	stream.  This currently just checks that the bitrate field is 0 and
	the media type is 'audio/x-flac'.  More media types and other checks
	can be added later.

	* rhythmdb/rhythmdb-query-model.c:
	(rhythmdb_query_model_bitrate_sort_func):
	* rhythmdb/rhythmdb-query-model.h:
	Add a query model sort function for bitrate comparisons, sorting
	lossless encodings as being of higher quality than anything with a
	bitrate.  Not exactly correct, but it's the best we can do.

	* widgets/rb-entry-view.c: (rb_entry_view_quality_cell_data_func),
	(rb_entry_view_append_column):
	* widgets/rb-song-info.c: (rb_song_info_update_bitrate):
	Display "Lossless" for lossless encodings in the 'quality' column in
	track lists and the same field in the song info dialog.

	Fixes #337438.


Modified:
   trunk/ChangeLog
   trunk/rhythmdb/rhythmdb-query-model.c
   trunk/rhythmdb/rhythmdb-query-model.h
   trunk/rhythmdb/rhythmdb.c
   trunk/rhythmdb/rhythmdb.h
   trunk/widgets/rb-entry-view.c
   trunk/widgets/rb-song-info.c

Modified: trunk/rhythmdb/rhythmdb-query-model.c
==============================================================================
--- trunk/rhythmdb/rhythmdb-query-model.c	(original)
+++ trunk/rhythmdb/rhythmdb-query-model.c	Tue Apr  7 06:32:46 2009
@@ -2792,6 +2792,32 @@
 }
 
 gint
+rhythmdb_query_model_bitrate_sort_func (RhythmDBEntry *a,
+					RhythmDBEntry *b,
+					gpointer data)
+{
+	gulong a_val, b_val;
+	
+	if (rhythmdb_entry_is_lossless (a)) {
+		if (rhythmdb_entry_is_lossless (b))
+			return rhythmdb_query_model_location_sort_func (a, b, data);
+		else
+			return 1;
+	} else {
+		if (rhythmdb_entry_is_lossless (b))
+			return -1;
+	}
+
+	a_val = rhythmdb_entry_get_ulong (a, RHYTHMDB_PROP_BITRATE);
+	b_val = rhythmdb_entry_get_ulong (b, RHYTHMDB_PROP_BITRATE);
+
+	if (a_val != b_val)
+		return (a_val > b_val ? 1 : -1);
+	else
+		return rhythmdb_query_model_location_sort_func (a, b, data);
+}
+
+gint
 rhythmdb_query_model_date_sort_func (RhythmDBEntry *a,
 				     RhythmDBEntry *b,
 				     gpointer data)

Modified: trunk/rhythmdb/rhythmdb-query-model.h
==============================================================================
--- trunk/rhythmdb/rhythmdb-query-model.h	(original)
+++ trunk/rhythmdb/rhythmdb-query-model.h	Tue Apr  7 06:32:46 2009
@@ -188,6 +188,10 @@
 gint 			rhythmdb_query_model_ulong_sort_func	(RhythmDBEntry *a,
 								 RhythmDBEntry *b,
 								 gpointer data);
+								 
+gint			rhythmdb_query_model_bitrate_sort_func  (RhythmDBEntry *a,
+								 RhythmDBEntry *b,
+								 gpointer data);
 
 gint 			rhythmdb_query_model_date_sort_func	(RhythmDBEntry *a,
 								 RhythmDBEntry *b,

Modified: trunk/rhythmdb/rhythmdb.c
==============================================================================
--- trunk/rhythmdb/rhythmdb.c	(original)
+++ trunk/rhythmdb/rhythmdb.c	Tue Apr  7 06:32:46 2009
@@ -5327,3 +5327,20 @@
 
 	return type;
 }
+
+gboolean
+rhythmdb_entry_is_lossless (RhythmDBEntry *entry)
+{
+	const char *mime_type;
+
+	if (rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_BITRATE) != 0)
+		return FALSE;
+       
+	/* possible performance improvement here, if it proves necessary:
+	 * keep references to the refstrings for all lossless media types here,
+	 * and use pointer comparisons rather than string comparisons to check entries.
+	 */
+	mime_type = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_MIMETYPE);
+	return (g_str_equal (mime_type, "audio/x-flac"));
+}
+

Modified: trunk/rhythmdb/rhythmdb.h
==============================================================================
--- trunk/rhythmdb/rhythmdb.h	(original)
+++ trunk/rhythmdb/rhythmdb.h	Tue Apr  7 06:32:46 2009
@@ -382,6 +382,8 @@
 
 char *		rhythmdb_entry_get_playback_uri	(RhythmDBEntry *entry);
 
+gboolean	rhythmdb_entry_is_lossless (RhythmDBEntry *entry);
+
 gpointer	rhythmdb_entry_get_type_data (RhythmDBEntry *entry, guint expected_size);
 #define		RHYTHMDB_ENTRY_GET_TYPE_DATA(e,t)	((t*)rhythmdb_entry_get_type_data((e),sizeof(t)))
 

Modified: trunk/widgets/rb-entry-view.c
==============================================================================
--- trunk/widgets/rb-entry-view.c	(original)
+++ trunk/widgets/rb-entry-view.c	Tue Apr  7 06:32:46 2009
@@ -1052,18 +1052,21 @@
 				      struct RBEntryViewCellDataFuncData *data)
 {
 	RhythmDBEntry *entry;
-	guint bitrate;
+	gulong bitrate;
 
 	entry = rhythmdb_query_model_iter_to_entry (data->view->priv->model, iter);
+	bitrate = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_BITRATE);
 
-	bitrate = rhythmdb_entry_get_ulong (entry, data->propid);
-
-	if (bitrate > 0) {
-		char *s = g_strdup_printf (_("%u kbps"), (guint)bitrate);
+	if (rhythmdb_entry_is_lossless (entry)) {
+		g_object_set (renderer, "text", _("Lossless"), NULL);
+	} else if (bitrate == 0) {
+		g_object_set (renderer, "text", _("Unknown"), NULL);
+	} else {
+		char *s;
+	       
+		s = g_strdup_printf (_("%lu kbps"), bitrate);
 		g_object_set (renderer, "text", s, NULL);
 		g_free (s);
-	} else {
-		g_object_set (renderer, "text", _("Unknown"), NULL);
 	}
 
 	rhythmdb_entry_unref (entry);
@@ -1391,7 +1394,7 @@
 	struct RBEntryViewCellDataFuncData *cell_data;
 	const char *title = NULL;
 	const char *key = NULL;
-	const char *strings[4] = {0};
+	const char *strings[5] = {0};
 	GtkTreeCellDataFunc cell_data_func = NULL;
 	GCompareDataFunc sort_func = NULL;
 	RhythmDBPropType propid;
@@ -1485,12 +1488,13 @@
 		cell_data->propid = propid;
 		cell_data_func = (GtkTreeCellDataFunc) rb_entry_view_quality_cell_data_func;
 		sort_propid = cell_data->propid;
-		sort_func = (GCompareDataFunc) rhythmdb_query_model_ulong_sort_func;
+		sort_func = (GCompareDataFunc) rhythmdb_query_model_bitrate_sort_func;
 		title = _("Quality");
 		key = "Quality";
 		strings[0] = title;
 		strings[1] = _("000 kbps");
 		strings[2] = _("Unknown");
+		strings[3] = _("Lossless");
 		break;
 	case RB_ENTRY_VIEW_COL_RATING:
 		propid = RHYTHMDB_PROP_RATING;

Modified: trunk/widgets/rb-song-info.c
==============================================================================
--- trunk/widgets/rb-song-info.c	(original)
+++ trunk/widgets/rb-song-info.c	Tue Apr  7 06:32:46 2009
@@ -1045,14 +1045,19 @@
 static void
 rb_song_info_update_bitrate (RBSongInfo *song_info)
 {
-	char *tmp = NULL;
-	gulong bitrate = 0;
+	char *tmp;
+	gulong bitrate;
+
 	bitrate = rhythmdb_entry_get_ulong (song_info->priv->current_entry, RHYTHMDB_PROP_BITRATE);
 
-	if (bitrate > 0)
-		tmp = g_strdup_printf (_("%lu kbps"), bitrate);
-	else
+	if (rhythmdb_entry_is_lossless (song_info->priv->current_entry)) {
+		tmp = g_strdup (_("Lossless"));
+	} else if (bitrate == 0) {
 		tmp = g_strdup (_("Unknown"));
+	} else {
+		tmp = g_strdup_printf (_("%lu kbps"), bitrate);
+	}
+
 	gtk_label_set_text (GTK_LABEL (song_info->priv->bitrate),
 			    tmp);
 	g_free (tmp);



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