tracker r2181 - in branches/indexer-split: . src/tracker-indexer
- From: carlosg svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2181 - in branches/indexer-split: . src/tracker-indexer
- Date: Thu, 28 Aug 2008 11:45:25 +0000 (UTC)
Author: carlosg
Date: Thu Aug 28 11:45:25 2008
New Revision: 2181
URL: http://svn.gnome.org/viewvc/tracker?rev=2181&view=rev
Log:
2008-08-28 Carlos Garnacho <carlos imendio com>
* src/tracker-indexer/tracker-metadata-utils.c (lists_equal)
(metadata_action_item_new) (calculate_merge_action)
(add_deleted_items) (tracker_metadata_utils_calculate_merge)
(tracker_metadata_utils_action_item_free): Removed functions, they
weren't used anywhere.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c
Modified: branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-metadata-utils.c Thu Aug 28 11:45:25 2008
@@ -560,245 +560,3 @@
return g_string_free (thumbnail, FALSE);
}
-
-typedef struct {
- TrackerMetadata *old_metadata;
- TrackerMetadata *new_metadata;
- GSList *actions;
-} MergeForeach;
-
-static gboolean
-lists_equal (GList *one, GList *two)
-{
- GList *one_iter, *two_iter;
-
- one_iter = one;
- two_iter = two;
-
- if (g_list_length (one_iter) != g_list_length (two_iter)) {
- return FALSE;
- }
-
-
- for (one_iter = one, two_iter = two;
- one_iter != NULL && two_iter != NULL;
- one_iter = one_iter->next, two_iter = two_iter->next) {
- if (strcmp ((gchar *) one_iter->data, (gchar *) two_iter->data)) {
- return FALSE;
- }
-
- }
- return TRUE;
-}
-
-static MetadataActionItem *
-metadata_action_item_new () {
-
- MetadataActionItem *action;
-
- action = g_slice_new (MetadataActionItem);
-
- action->action = TRACKER_METADATA_ACTION_NEW;
- action->metadata_type = NULL;
-
- action->old_value = NULL;
- action->new_value = NULL;
-
- action->old_values = NULL;
- action->new_values = NULL;
-
- return action;
-}
-
-static void
-calculate_merge_action (TrackerField *field,
- gpointer value,
- gpointer user_data) {
-
- MergeForeach *data;
- MetadataActionItem *action;
-
- data = (MergeForeach *) user_data;
-
- if (tracker_field_get_multiple_values (field)) {
-
- const GList *old_values;
-
- old_values = tracker_metadata_lookup_multiple_values (data->old_metadata,
- tracker_field_get_name (field));
-
- if (!old_values) {
- action = metadata_action_item_new ();
-
- action->action = TRACKER_METADATA_ACTION_NEW;
- action->metadata_type = g_strdup (tracker_field_get_name (field));
- action->old_values = NULL;
- action->new_values = g_list_copy ((GList *)value);
-
- data->actions = g_slist_prepend (data->actions, action);
- return;
- }
-
- if (old_values && !value) {
- action = metadata_action_item_new ();
-
- action->action = TRACKER_METADATA_ACTION_DELETE;
- action->metadata_type = g_strdup (tracker_field_get_name (field));
- action->old_values = old_values;
- action->new_value = NULL;
-
- data->actions = g_slist_prepend (data->actions, action);
- return;
- }
-
- if (!lists_equal (old_values, (GList *)value)) {
- action = metadata_action_item_new ();
-
- action->action = TRACKER_METADATA_ACTION_UPDATE;
- action->metadata_type = g_strdup (tracker_field_get_name (field));
- action->old_values = g_list_copy (old_values);
- action->new_values = g_list_copy ((GList *)value);
-
- data->actions = g_slist_prepend (data->actions, action);
- return;
- }
-
- } else {
-
- const gchar *old_value;
-
- old_value = tracker_metadata_lookup (data->old_metadata,
- tracker_field_get_name (field));
-
- /* New metadata */
- if (!old_value) {
- action = metadata_action_item_new ();
-
- action->action = TRACKER_METADATA_ACTION_NEW;
- action->metadata_type = g_strdup (tracker_field_get_name (field));
- action->old_value = NULL;
- action->new_value = g_strdup ((const gchar *)value);
-
- data->actions = g_slist_prepend (data->actions, action);
- return;
- }
-
- /* Metadata with previous value but now is NULL: Delete */
- if (old_value && !value) {
- action = metadata_action_item_new ();
-
- action->action = TRACKER_METADATA_ACTION_DELETE;
- action->metadata_type = g_strdup (tracker_field_get_name (field));
- action->old_value = g_strdup (old_value);
- action->new_value = NULL;
-
- data->actions = g_slist_prepend (data->actions, action);
- return;
- }
-
- /* Different old and new values: Update */
- if (strcmp (old_value, (const gchar *)value) != 0) {
- action = metadata_action_item_new ();
-
- action->action = TRACKER_METADATA_ACTION_UPDATE;
- action->metadata_type = g_strdup (tracker_field_get_name (field));
- action->old_value = g_strdup (old_value);
- action->new_value = g_strdup ((const gchar *)value);
-
- data->actions = g_slist_prepend (data->actions, action);
- return;
- }
- }
-}
-
-
-static void
-add_deleted_items (TrackerField *field,
- gpointer value,
- gpointer user_data)
-{
- MergeForeach *data;
-
- data = (MergeForeach *)user_data;
-
- /*
- * If the metadata is embedded and is not in the new metadata set
- * of the file, we move it to "new metadata" with NULL value, to
- * remove it from the DB.
- *
- * If the metadata is not embedded we must not remove it! (For instance,
- * playcount of a music file).
- */
- if (tracker_field_get_multiple_values (field)) {
- if (!tracker_metadata_lookup_multiple_values (data->new_metadata,
- tracker_field_get_name (field))
- && tracker_field_get_embedded (field)) {
- tracker_metadata_insert_multiple_values (data->new_metadata,
- tracker_field_get_name (field),
- NULL);
- }
-
- } else {
- if (!tracker_metadata_lookup (data->new_metadata,
- tracker_field_get_name (field))
- && tracker_field_get_embedded (field)) {
-
- tracker_metadata_insert (data->new_metadata,
- tracker_field_get_name (field),
- NULL);
- }
- }
-}
-
-
-GSList *
-tracker_metadata_utils_calculate_merge (TrackerMetadata *old_metadata,
- TrackerMetadata *new_metadata)
-{
- MergeForeach data;
-
- data.old_metadata = old_metadata;
- data.new_metadata = new_metadata;
- data.actions = NULL;
-
- /*
- * First we check all the old metadata are in the new metadata.
- * If a metadata is embedded and is not in the new metadata, we
- * must remove it from the DB. We indicate that adding it to the
- * new metadata with a NULL value.
- */
- tracker_metadata_foreach (old_metadata,
- add_deleted_items,
- &data);
-
- /*
- * Traverse the new metadata table, checking old and new value, and
- * decide what action is required in the DB.
- */
- tracker_metadata_foreach (new_metadata,
- calculate_merge_action,
- &data);
-
- return data.actions;
-}
-
-void
-tracker_metadata_utils_action_item_free (MetadataActionItem *item, gpointer user_data)
-{
- if (!item) {
- return;
- }
-
- if (item->old_value) {
- g_free (item->old_value);
- }
-
- if (item->new_value) {
- g_free (item->new_value);
- }
-
- if (item->metadata_type) {
- g_free (item->metadata_type);
- }
-
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]