static void tracker_evt_update_items_cb (gpointer key, gpointer value, tracker_evt_update_t *evt) { guint id = GPOINTER_TO_INT (key); gchar *str_id; GrlTrackerSource *source = (GrlTrackerSource *) value; GrlMedia *media; GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt); if (!source) { g_assert ("\tnot in cache ???"); return; } if (!grl_tracker_source_can_notify (source)) { GRL_DEBUG ("\tno notification for source %s...", grl_source_get_name (GRL_SOURCE (source))); return; } media = grl_media_new (); str_id = g_strdup_printf ("%i", id); grl_media_set_id (media, str_id); g_free (str_id); GRL_DEBUG ("\tNotify id=%u source=%s", id, grl_source_get_name (GRL_SOURCE (source))); grl_source_notify_change (GRL_SOURCE (source), media, evt->change_type, FALSE); g_object_unref (media); }
static void on_g_volume_monitor_event (GVolumeMonitor *monitor, gpointer device, GrlOpticalMediaSource *source) { grl_source_notify_change (GRL_SOURCE (source), NULL, GRL_CONTENT_CHANGED, TRUE); }
static void on_g_volume_monitor_changed_event (GVolumeMonitor *monitor, GMount *mount, GrlOpticalMediaSource *source) { GList *l; l = g_list_find_custom (source->priv->list, mount, find_mount); if (!l) return; media_set_metadata (mount, l->data); if (source->priv->notify_changes) { grl_source_notify_change (GRL_SOURCE (source), l->data, GRL_CONTENT_CHANGED, FALSE); } }
static void on_g_volume_monitor_removed_event (GVolumeMonitor *monitor, GMount *mount, GrlOpticalMediaSource *source) { GList *l; GrlMedia *media; l = g_list_find_custom (source->priv->list, mount, find_mount); if (!l) return; media = l->data; source->priv->list = g_list_remove (source->priv->list, media); if (source->priv->notify_changes) { grl_source_notify_change (GRL_SOURCE (source), media, GRL_CONTENT_REMOVED, FALSE); } g_object_unref (media); }
static void parsed_finished_item (TotemPlParser *pl, GAsyncResult *result, GrlOpticalMediaSource *source) { GrlMedia **media; TotemPlParserResult retval; media = g_object_get_data (G_OBJECT (pl), "media"); retval = totem_pl_parser_parse_finish (TOTEM_PL_PARSER (pl), result, NULL); if (retval == TOTEM_PL_PARSER_RESULT_SUCCESS && grl_media_get_url (*media) != NULL) { source->priv->list = g_list_append (source->priv->list, g_object_ref (*media)); if (source->priv->notify_changes) { grl_source_notify_change (GRL_SOURCE (source), *media, GRL_CONTENT_ADDED, FALSE); } } g_object_unref (*media); g_object_unref (pl); }
static void remove_bookmark (GrlBookmarksSource *bookmarks_source, const gchar *bookmark_id, GrlMedia *media, GError **error) { GomResource *resource; gint64 id; GError *local_error = NULL; GRL_DEBUG ("remove_bookmark"); id = g_ascii_strtoll (bookmark_id, NULL, 0); resource = g_object_new (BOOKMARKS_TYPE_RESOURCE, "id", id, "repository", bookmarks_source->priv->repository, NULL); if (!gom_resource_delete_sync (resource, &local_error)) { GRL_WARNING ("Failed to remove bookmark '%s': %s", bookmark_id, local_error->message); *error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_REMOVE_FAILED, _("Failed to remove: %s"), local_error->message); g_error_free (local_error); } g_object_unref (resource); if (bookmarks_source->priv->notify_changes) { /* We can improve accuracy computing the parent container of removed element */ grl_source_notify_change (GRL_SOURCE (bookmarks_source), media, GRL_CONTENT_REMOVED, TRUE); } }
static void store_bookmark (GrlBookmarksSource *bookmarks_source, GList **keylist, GrlMediaBox *parent, GrlMedia *bookmark, GError **error) { GomResource *resource; const gchar *title; const gchar *url; const gchar *desc; const gchar *thumb; GTimeVal now; gint64 parent_id; const gchar *mime; gchar *date; guint type; gint64 id; gchar *str_id; GError *local_error = NULL; gboolean ret; GRL_DEBUG ("store_bookmark"); title = grl_media_get_title (bookmark); url = grl_media_get_url (bookmark); thumb = grl_media_get_thumbnail (bookmark); desc = grl_media_get_description (bookmark); mime = grl_media_get_mime (bookmark); g_get_current_time (&now); date = g_time_val_to_iso8601 (&now); if (!parent) { parent_id = 0; } else { parent_id = g_ascii_strtoll (grl_media_get_id (GRL_MEDIA (parent)), NULL, 0); } if (parent_id < 0) { parent_id = 0; } GRL_DEBUG ("URL: '%s'", url); if (GRL_IS_MEDIA_BOX (bookmark)) { type = BOOKMARK_TYPE_CATEGORY; } else { type = BOOKMARK_TYPE_STREAM; } resource = g_object_new (BOOKMARKS_TYPE_RESOURCE, "repository", bookmarks_source->priv->repository, "parent", parent_id, "type", type, NULL); if (type == BOOKMARK_TYPE_STREAM) { g_object_set (G_OBJECT (resource), "url", url, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_URL)); } if (title) { g_object_set (G_OBJECT (resource), "title", title, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_TITLE)); } else if (url) { g_object_set (G_OBJECT (resource), "title", url, NULL); } else { g_object_set (G_OBJECT (resource), "title", "(unknown)", NULL); } if (date) { g_object_set (G_OBJECT (resource), "date", date, NULL); } if (mime) { g_object_set (G_OBJECT (resource), "mime", mime, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_MIME)); } if (desc) { g_object_set (G_OBJECT (resource), "desc", desc, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_DESCRIPTION)); } if (thumb) { g_object_set (G_OBJECT (resource), "thumbnail-url", desc, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_THUMBNAIL)); } ret = gom_resource_save_sync (resource, &local_error); if (!ret) { GRL_WARNING ("Failed to store bookmark '%s': %s", title, local_error->message); *error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_STORE_FAILED, _("Failed to store: %s"), local_error->message); g_error_free (local_error); g_object_unref (resource); return; } g_object_get (resource, "id", &id, NULL); str_id = g_strdup_printf ("%" G_GINT64_FORMAT, id); grl_media_set_id (bookmark, str_id); g_free (str_id); g_object_unref (resource); if (bookmarks_source->priv->notify_changes) { grl_source_notify_change (GRL_SOURCE (bookmarks_source), bookmark, GRL_CONTENT_ADDED, FALSE); } }
static void tracker_evt_update_orphans (tracker_evt_update_t *evt) { gboolean first = TRUE; GString *request_str; GList *subject, *subjects; GList *source, *sources; GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt); if (g_hash_table_size (evt->orphan_items) < 1) { tracker_evt_postupdate_sources (evt); return; } sources = grl_registry_get_sources (grl_registry_get_default (), FALSE); request_str = g_string_new (""); subjects = g_hash_table_get_keys (evt->orphan_items); subject = subjects; while (subject != NULL) { guint id = GPOINTER_TO_INT (subject->data); if (GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items, subject->data)) != GRL_CONTENT_REMOVED) { if (first) { g_string_append_printf (request_str, "%u", id); first = FALSE; } else { g_string_append_printf (request_str, ", %u", id); } } else { /* Notify all sources that a media been removed */ source = sources; while (source != NULL) { if (GRL_IS_TRACKER_SOURCE (source->data)) { GRL_DEBUG ("\tNotify id=%u source=%s p=%p", id, grl_source_get_name (GRL_SOURCE (source->data)), source->data); if (grl_tracker_source_can_notify (GRL_TRACKER_SOURCE (source->data))) { GrlMedia *media = grl_media_new (); gchar *str_id = g_strdup_printf ("%u", id); grl_media_set_id (media, str_id); g_free (str_id); grl_source_notify_change (GRL_SOURCE (source->data), media, GRL_CONTENT_REMOVED, FALSE); g_object_unref (media); } } source = source->next; } } subject = subject->next; } g_list_free (subjects); if (request_str->len > 0) { gchar *sparql_final = g_strdup_printf (TRACKER_MEDIA_ITEM, request_str->str); GRL_DEBUG ("\trequest : '%s'", sparql_final); tracker_sparql_connection_query_async (grl_tracker_connection, sparql_final, NULL, (GAsyncReadyCallback) tracker_evt_update_orphans_cb, evt); g_free (sparql_final); } else { tracker_evt_postupdate_sources (evt); } g_string_free (request_str, TRUE); }
static void tracker_evt_update_orphan_item_cb (GObject *object, GAsyncResult *result, tracker_evt_update_t *evt) { guint id; const gchar *type, *datasource; GrlTrackerSource *source = NULL; GError *error = NULL; GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt); if (!tracker_sparql_cursor_next_finish (evt->cursor, result, &error)) { if (error != NULL) { GRL_DEBUG ("\terror in parsing : %s", error->message); g_error_free (error); } else { GRL_DEBUG ("\tend of parsing..."); } g_clear_object (&evt->cursor); if (grl_tracker_per_device_source) { /* Once all items have been processed, add new sources and we're done. */ tracker_evt_postupdate_sources (evt); } else { tracker_evt_update_free (evt); } return; } type = tracker_sparql_cursor_get_string (evt->cursor, 0, NULL); id = tracker_sparql_cursor_get_integer (evt->cursor, 1); datasource = tracker_sparql_cursor_get_string (evt->cursor, 2, NULL); GRL_DEBUG ("\tOrphan item: id=%u datasource=%s", id, datasource); if (!grl_tracker_per_device_source) source = grl_tracker_source_find (""); if (!source && datasource) source = grl_tracker_source_find (datasource); if (source && GRL_IS_TRACKER_SOURCE (source)) { GrlMedia *media; GRL_DEBUG (" \tAdding to cache id=%u", id); grl_tracker_source_cache_add_item (grl_tracker_item_cache, id, source); if (grl_tracker_source_can_notify (source)) { media = grl_tracker_build_grilo_media (type); if (media) { gchar *str_id = g_strdup_printf ("%i", id); gint change_type = GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items, GSIZE_TO_POINTER (id))); grl_media_set_id (media, str_id); g_free (str_id); GRL_DEBUG ("\tNotify id=%u source=%s p=%p", id, grl_source_get_name (GRL_SOURCE (source)), source); grl_source_notify_change (GRL_SOURCE (source), media, change_type, FALSE); g_object_unref (media); } } } tracker_sparql_cursor_next_async (evt->cursor, NULL, (GAsyncReadyCallback) tracker_evt_update_orphan_item_cb, (gpointer) evt); }