static void playing_song_changed_cb (RBShellPlayer *player, RhythmDBEntry *entry, RBGriloPlugin *plugin) { const char *uri; RhythmDBEntryType *entry_type; RBGriloEntryData *data; if (entry == NULL) return; entry_type = rhythmdb_entry_get_entry_type (entry); if (RB_IS_GRILO_ENTRY_TYPE (entry_type) == FALSE) { return; } data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBGriloEntryData); uri = grl_data_get_string (data->grilo_data, GRL_METADATA_KEY_THUMBNAIL); if (uri != NULL) { RBExtDBKey *key; key = rb_ext_db_key_create_storage ("album", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM)); rb_ext_db_key_add_field (key, "artist", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST)); rb_ext_db_store_uri (plugin->art_store, key, RB_EXT_DB_SOURCE_SEARCH, uri); rb_ext_db_key_free (key); } }
/** * rb_ext_db_key_lookups: * @key: a #RBExtDBKey * @callback: (scope call): a callback to process lookup keys * @user_data: data to pass to @callback * * Generates the set of possible lookup keys for @key and * passes them to @callback in order. If the callback returns * %FALSE, processing will stop. * * This should only be used by the metadata store itself. * Metadata providers and consumers shouldn't need to do this. */ void rb_ext_db_key_lookups (RBExtDBKey *key, RBExtDBKeyLookupCallback callback, gpointer user_data) { int i = 0; while (TRUE) { RBExtDBKey *s; TDB_DATA sk; gboolean result; s = create_store_key (key, i); if (s == NULL) break; flatten_store_key (s, &sk); result = callback (sk, s, user_data); g_free (sk.dptr); rb_ext_db_key_free (s); if (result == FALSE) break; i++; } }
static void art_cb (RBExtDBKey *key, RBExtDBKey *store_key, const char *filename, GValue *data, RBNotificationPlugin *plugin) { RhythmDBEntry *entry; entry = rb_shell_player_get_playing_entry (plugin->shell_player); if (entry == NULL) { return; } if (rhythmdb_entry_matches_ext_db_key (plugin->db, entry, store_key)) { guint elapsed = 0; plugin->notify_art_path = g_strdup (filename); rb_shell_player_get_playing_time (plugin->shell_player, &elapsed, NULL); if (elapsed < PLAYING_ENTRY_NOTIFY_TIME) { notify_playing_entry (plugin, FALSE); } if (plugin->notify_art_key != NULL) rb_ext_db_key_free (plugin->notify_art_key); plugin->notify_art_key = rb_ext_db_key_copy (store_key); } rhythmdb_entry_unref (entry); }
static void request_cover_art (MxFrame *frame, RhythmDBEntry *entry) { RBExtDBKey *key; RBExtDB *art_store; art_store = rb_ext_db_new ("album-art"); key = rhythmdb_entry_create_ext_db_key (entry, RHYTHMDB_PROP_ALBUM); rb_ext_db_request (art_store, key, (RBExtDBRequestCallback) art_cb, g_object_ref (frame), g_object_unref); rb_ext_db_key_free (key); g_object_unref (art_store); }
static void impl_deactivate (PeasActivatable *bplugin) { RBNotificationPlugin *plugin; RBShell *shell; plugin = RB_NOTIFICATION_PLUGIN (bplugin); g_object_get (plugin, "object", &shell, NULL); cleanup_notification (plugin); /* disconnect signal handlers used to update the icon */ if (plugin->shell_player != NULL) { g_signal_handlers_disconnect_by_func (plugin->shell_player, playing_entry_changed_cb, plugin); g_object_unref (plugin->shell_player); plugin->shell_player = NULL; } if (plugin->db != NULL) { g_signal_handlers_disconnect_by_func (plugin->db, db_stream_metadata_cb, plugin); g_object_unref (plugin->db); plugin->db = NULL; } g_signal_handlers_disconnect_by_func (shell, shell_notify_playing_cb, plugin); g_signal_handlers_disconnect_by_func (shell, shell_notify_custom_cb, plugin); g_object_unref (plugin->art_store); plugin->art_store = NULL; /* forget what's playing */ if (plugin->notify_art_key) rb_ext_db_key_free (plugin->notify_art_key); g_free (plugin->current_title); g_free (plugin->current_album_and_artist); g_free (plugin->notify_art_path); plugin->notify_art_key = NULL; plugin->current_title = NULL; plugin->current_album_and_artist = NULL; plugin->notify_art_path = NULL; g_object_unref (shell); }
/** * rb_ext_db_key_to_store_key: (skip) * @key: a @RBExtDBKey * * Generates the storage key for @key. This is the value that should * be used to store an item identified by this key in the store. * The storage key includes all optional fields, so keys passed to * this function should be constructed using only the optional fields * that were used to locate the item. The caller must free the data * pointer inside @data. * * This should only be used by the metadata store itself. * Metadata providers and consumers shouldn't need to do this. * * Return value: TDB_DATA structure containing storage key */ TDB_DATA rb_ext_db_key_to_store_key (RBExtDBKey *key) { TDB_DATA k = {0,}; RBExtDBKey *sk; if (key->lookup) { sk = create_store_key (key, 0); if (sk != NULL) { flatten_store_key (sk, &k); rb_ext_db_key_free (sk); } } else { flatten_store_key (key, &k); } return k; }
static gboolean impl_track_added (RBTransferTarget *target, RhythmDBEntry *entry, const char *dest, guint64 filesize, const char *media_type) { LIBMTP_track_t *track = NULL; RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (target); RhythmDB *db; track = g_hash_table_lookup (priv->track_transfer_map, dest); if (track == NULL) { rb_debug ("track-added called, but can't find a track for dest URI %s", dest); return FALSE; } g_hash_table_remove (priv->track_transfer_map, dest); if (strcmp (track->album, _("Unknown")) != 0) { rb_mtp_thread_add_to_album (priv->device_thread, track, track->album); if (priv->album_art_supported) { RBExtDBKey *key; /* need to do this in an idle handler? */ key = rb_ext_db_key_create_lookup ("album", track->album); rb_ext_db_key_add_field (key, "artist", track->artist); rb_ext_db_request (priv->art_store, key, (RBExtDBRequestCallback) art_request_cb, g_object_ref (target), (GDestroyNotify) g_object_unref); rb_ext_db_key_free (key); } } db = get_db_for_source (RB_MTP_SOURCE (target)); add_mtp_track_to_db (RB_MTP_SOURCE (target), db, track); g_object_unref (db); queue_free_space_update (RB_MTP_SOURCE (target)); return FALSE; }
static void update_current_playing_data (RBNotificationPlugin *plugin, RhythmDBEntry *entry) { GValue *value; const char *stream_title = NULL; char *artist = NULL; char *album = NULL; char *title = NULL; GString *secondary; RBExtDBKey *key; const char *artist_template = NULL; const char *album_template = NULL; g_free (plugin->current_title); g_free (plugin->current_album_and_artist); plugin->current_title = NULL; plugin->current_album_and_artist = NULL; if (entry == NULL) { plugin->current_title = g_strdup (_("Not Playing")); plugin->current_album_and_artist = g_strdup (""); g_free (plugin->notify_art_path); plugin->notify_art_path = NULL; return; } secondary = g_string_sized_new (100); if (plugin->notify_art_key == NULL || (rhythmdb_entry_matches_ext_db_key (plugin->db, entry, plugin->notify_art_key) == FALSE)) { if (plugin->notify_art_key) rb_ext_db_key_free (plugin->notify_art_key); plugin->notify_art_key = NULL; g_free (plugin->notify_art_path); plugin->notify_art_path = NULL; /* request album art */ key = rhythmdb_entry_create_ext_db_key (entry, RHYTHMDB_PROP_ALBUM); rb_ext_db_request (plugin->art_store, key, (RBExtDBRequestCallback) art_cb, g_object_ref (plugin), g_object_unref); rb_ext_db_key_free (key); } /* get artist, preferring streaming song details */ value = rhythmdb_entry_request_extra_metadata (plugin->db, entry, RHYTHMDB_PROP_STREAM_SONG_ARTIST); if (value != NULL) { artist = markup_escape (g_value_get_string (value)); g_value_unset (value); g_free (value); } else { artist = markup_escape (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST)); } /* get album, preferring streaming song details */ value = rhythmdb_entry_request_extra_metadata (plugin->db, entry, RHYTHMDB_PROP_STREAM_SONG_ALBUM); if (value != NULL) { album = markup_escape (g_value_get_string (value)); g_value_unset (value); g_free (value); } else { album = markup_escape (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM)); } get_artist_album_templates (artist, album, &artist_template, &album_template); if (artist != NULL && artist[0] != '\0') { g_string_append_printf (secondary, artist_template, artist); } g_free (artist); if (album != NULL && album[0] != '\0') { if (secondary->len != 0) g_string_append_c (secondary, ' '); g_string_append_printf (secondary, album_template, album); } g_free (album); /* get title and possibly stream name. * if we have a streaming song title, the entry's title * property is the stream name. */ value = rhythmdb_entry_request_extra_metadata (plugin->db, entry, RHYTHMDB_PROP_STREAM_SONG_TITLE); if (value != NULL) { title = g_value_dup_string (value); g_value_unset (value); g_free (value); stream_title = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE); } else { title = g_strdup (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE)); } if (stream_title != NULL && stream_title[0] != '\0') { char *escaped; escaped = markup_escape (stream_title); if (secondary->len == 0) g_string_append (secondary, escaped); else g_string_append_printf (secondary, " (%s)", escaped); g_free (escaped); } if (title == NULL) { /* Translators: unknown track title */ title = g_strdup (_("Unknown")); } plugin->current_title = title; plugin->current_album_and_artist = g_string_free (secondary, FALSE); }