[libdmapsharing] Back out Alexandre's addition of itemid property from DAAPRecord



commit 2c1dfb2b2f6bb3f4591e1b7190d9fa22690abf3b
Author: W. Michael Petullo <mike flyn org>
Date:   Fri Aug 20 23:36:05 2010 -0500

    Back out Alexandre's addition of itemid property from DAAPRecord
    
    Alexandre's code worked, but this is a little less intrusive. The real
    answer might involve some deeper work later.
    Signed-off-by: W. Michael Petullo <mike flyn org>

 ChangeLog                    |    5 +++++
 libdmapsharing/daap-record.c |   29 ++++++++++++++---------------
 libdmapsharing/daap-record.h |   11 +++++++----
 libdmapsharing/daap-share.c  |   21 ++++++---------------
 libdmapsharing/dmap-share.c  |   22 ++++++++++------------
 5 files changed, 42 insertions(+), 46 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8d8ecd2..6309489 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+20 August 2010 W. Michael Petullo <mike flyn org>
+
+	* Back out Alexandre's addition of itemid property from
+	DAAPRecord. The itemid is the DMAPDb ID.
+
 20 August 2010 Alexandre Rosenfeld <alexandre rosenfeld gmail com>
 
 	* Apply Alexandre Rosenfeld's DACP patch from Google Summer of
diff --git a/libdmapsharing/daap-record.c b/libdmapsharing/daap-record.c
index bfc5f06..5bc514f 100644
--- a/libdmapsharing/daap-record.c
+++ b/libdmapsharing/daap-record.c
@@ -30,17 +30,6 @@ daap_record_init (DAAPRecordInterface *iface)
         daap_record_init_count++;
 
 	if (! is_initialized) {
-
-		g_object_interface_install_property (iface,
-			g_param_spec_int ("itemid",
-			                  "Item ID",
-			                  "Item ID",
-			                  0,
-			                  G_MAXINT,
-			                  0,
-			                  G_PARAM_READWRITE));
-
-		
 		g_object_interface_install_property (iface,
 			g_param_spec_string ("location",
 					     "URI pointing to song data",
@@ -248,14 +237,22 @@ daap_record_read (DAAPRecord *record, GError **err)
 }
 
 gint 
-daap_record_cmp_by_album (DAAPRecord *a, DAAPRecord *b) 
+daap_record_cmp_by_album (gpointer a, gpointer b, DMAPDb *db) 
 {
+	DAAPRecord *record_a, *record_b;
 	gchar *album_a, *album_b;
 	gchar *sort_album_a, *sort_album_b;
 	gint track_a, track_b;
 	gint ret;
-	g_object_get (a, "songalbum", &album_a, "sort-album", &sort_album_a, "track", &track_a, NULL);
-	g_object_get (b, "songalbum", &album_b, "sort-album", &sort_album_b, "track", &track_b, NULL);
+
+	record_a = DAAP_RECORD (dmap_db_lookup_by_id (db, GPOINTER_TO_UINT(a)));
+	record_b = DAAP_RECORD (dmap_db_lookup_by_id (db, GPOINTER_TO_UINT(b)));
+
+	g_assert (record_a);
+	g_assert (record_b);
+
+	g_object_get (record_a, "songalbum", &album_a, "sort-album", &sort_album_a, "track", &track_a, NULL);
+	g_object_get (record_b, "songalbum", &album_b, "sort-album", &sort_album_b, "track", &track_b, NULL);
 	if (sort_album_a && sort_album_b)
 		ret = g_strcmp0 (sort_album_a, sort_album_b);
 	else
@@ -266,9 +263,11 @@ daap_record_cmp_by_album (DAAPRecord *a, DAAPRecord *b)
 		else 
 			ret = (track_a == track_b) ? 0 : 1;
 	}
+	g_object_unref (record_a);
+	g_object_unref (record_b);
 	g_free (album_a);
 	g_free (album_b);
 	g_free (sort_album_a);
 	g_free (sort_album_b);
 	return ret;
-}
\ No newline at end of file
+}
diff --git a/libdmapsharing/daap-record.h b/libdmapsharing/daap-record.h
index 7c8696e..6dacbe0 100644
--- a/libdmapsharing/daap-record.h
+++ b/libdmapsharing/daap-record.h
@@ -25,6 +25,7 @@
 #include <gio/gio.h>
 
 #include <libdmapsharing/dmap-record.h>
+#include <libdmapsharing/dmap-db.h>
 
 G_BEGIN_DECLS
 
@@ -95,12 +96,14 @@ GInputStream *daap_record_read          (DAAPRecord *record, GError **err);
 
 /**
  * daap_record_cmp_by_album:
- * @a: first DAAPRecord.
- * @b: second DAAPRecord.
+ * @a: first ID.
+ * @b: second ID.
+ * @db: A DMAPDb for which a and b are valid ID's.
  *
- * Compares two records according to album. Suitable to sort lists of albums.
+ * Compares the two records associated with the provided keys according
+ * to album. Suitable to sort lists of albums.
  */ 
-gint daap_record_cmp_by_album (DAAPRecord *a, DAAPRecord *b);
+gint daap_record_cmp_by_album (gpointer a, gpointer b, DMAPDb *db);
 
 #endif /* __DAAP_RECORD_H */
 
diff --git a/libdmapsharing/daap-share.c b/libdmapsharing/daap-share.c
index 3d5cccd..126476c 100644
--- a/libdmapsharing/daap-share.c
+++ b/libdmapsharing/daap-share.c
@@ -540,27 +540,18 @@ add_entry_to_mlcl (gpointer id,
 
 	if (_dmap_share_client_requested (mb->bits, ITEM_KIND))
 		dmap_structure_add (mlit, DMAP_CC_MIKD, (gchar) DAAP_ITEM_KIND_AUDIO);
-	if (_dmap_share_client_requested (mb->bits, ITEM_ID)) {
-		gint itemid;
-		g_object_get (record, "itemid", &itemid, NULL);
-		dmap_structure_add (mlit, DMAP_CC_MIID, (guint) itemid);
-	}
+	if (_dmap_share_client_requested (mb->bits, ITEM_ID))
+		dmap_structure_add (mlit, DMAP_CC_MIID, GPOINTER_TO_UINT (id));
 	if (_dmap_share_client_requested (mb->bits, ITEM_NAME)) {
 		gchar *title;
 		g_object_get (record, "title", &title, NULL);
 		dmap_structure_add (mlit, DMAP_CC_MINM, title);
 		g_free (title);
 	}
-	if (_dmap_share_client_requested (mb->bits, PERSISTENT_ID)) {
-		gint itemid;
-		g_object_get (record, "itemid", &itemid, NULL);
-		dmap_structure_add (mlit, DMAP_CC_MPER, (guint) itemid);
-	}
-	if (_dmap_share_client_requested (mb->bits, CONTAINER_ITEM_ID)) {
-		gint itemid;
-		g_object_get (record, "itemid", &itemid, NULL);
-		dmap_structure_add (mlit, DMAP_CC_MCTI, (guint) itemid);
-	}
+	if (_dmap_share_client_requested (mb->bits, PERSISTENT_ID))
+		dmap_structure_add (mlit, DMAP_CC_MPER, GPOINTER_TO_UINT (id));
+	if (_dmap_share_client_requested (mb->bits, CONTAINER_ITEM_ID))
+		dmap_structure_add (mlit, DMAP_CC_MCTI, GPOINTER_TO_UINT (id));
 	if (_dmap_share_client_requested (mb->bits, SONG_DATA_KIND))
 		dmap_structure_add (mlit, DMAP_CC_ASDK, (gchar) DAAP_SONG_DATA_KIND_NONE);
 	/* FIXME: Any use for this?
diff --git a/libdmapsharing/dmap-share.c b/libdmapsharing/dmap-share.c
index 2e6991b..b2ed875 100644
--- a/libdmapsharing/dmap-share.c
+++ b/libdmapsharing/dmap-share.c
@@ -1571,10 +1571,9 @@ _dmap_share_databases (DMAPShare *share,
 			GSList *filter_def;
 			filter_def = _dmap_share_build_filter (record_query);
 			records = dmap_db_apply_filter (DMAP_DB (share->priv->db), filter_def);
-			g_debug ("Found %d records", g_hash_table_size (records));
 			num_songs = g_hash_table_size (records);
+			g_debug ("Found %d records", num_songs);
 			dmap_share_free_filter (filter_def);
-			g_hash_table_destroy (records);
 		} else {
 			num_songs = dmap_db_count (share->priv->db);
 		}
@@ -1662,10 +1661,8 @@ _dmap_share_databases (DMAPShare *share,
 		struct MLCL_Bits mb = {NULL,0};
 		gint pl_id;
 		gchar *record_query;
-		gchar *sort_by;
 		GSList *filter_def;
 		GHashTable *records;
-		GList *sorted_records;
 
 		map = DMAP_SHARE_GET_CLASS (share)->get_meta_data_map (share);
 		mb.bits = _dmap_share_parse_meta (query, map);
@@ -1675,32 +1672,33 @@ _dmap_share_databases (DMAPShare *share,
 		dmap_structure_add (apso, DMAP_CC_MUTY, 0);
 		
 		if (g_ascii_strcasecmp ("/1/items", rest_of_path + 13) == 0) {
+			GList *id;
+			gchar *sort_by;
+			GList *keys;
 			record_query = g_hash_table_lookup (query, "query");
 			filter_def = _dmap_share_build_filter (record_query);
 			records = dmap_db_apply_filter (DMAP_DB (share->priv->db), filter_def);
-			g_debug ("Found %d records", g_hash_table_size (records));
 			gint32 num_songs = g_hash_table_size (records);
+			g_debug ("Found %d records", num_songs);
 			dmap_share_free_filter (filter_def);
 
 			dmap_structure_add (apso, DMAP_CC_MTCO, (gint32) num_songs);
 			dmap_structure_add (apso, DMAP_CC_MRCO, (gint32) num_songs);
 			mb.mlcl = dmap_structure_add (apso, DMAP_CC_MLCL);
 
-			sorted_records = g_hash_table_get_values (records);
 			sort_by = g_hash_table_lookup (query, "sort");
+			keys = g_hash_table_get_keys (records);
 			if (g_strcmp0 (sort_by, "album") == 0) {
-				sorted_records = g_list_sort (sorted_records, (GCompareFunc) daap_record_cmp_by_album);
+				keys = g_list_sort_with_data (keys, (GCompareDataFunc) daap_record_cmp_by_album, records);
 			} else if (sort_by != NULL) {
 				g_warning ("Unknown sort column: %s", sort_by);
 			}
 
-			GList *record;
-			for (record = sorted_records; record; record = record->next) {
-				(*(DMAP_SHARE_GET_CLASS (share)->add_entry_to_mlcl)) (0, record->data, &mb);
+			for (id = keys; id; id = id->next) {
+				(*(DMAP_SHARE_GET_CLASS (share)->add_entry_to_mlcl)) (id->data, g_hash_table_lookup(records, id->data), &mb);
 			}
 
-			//g_hash_table_foreach (records, (GHFunc) DMAP_SHARE_GET_CLASS (share)->add_entry_to_mlcl, &mb);
-			g_list_free (sorted_records);
+			g_list_free (keys);
 			g_hash_table_destroy (records);
 		} else {
 			pl_id = atoi (rest_of_path + 14);



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