static void update_track_info (MxLabel *label, RhythmDB *db, RhythmDBEntry *entry, const char *streaming_title) { const char *title; ClutterActor *text; GString *str; text = mx_label_get_clutter_text (label); str = g_string_sized_new (100); if (entry == NULL) { g_string_append_printf (str, "<big>%s</big>", _("Not Playing")); } else { title = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE); if (streaming_title) { str_append_printf_escaped (str, "<big>%s</big>\n", streaming_title); str_append_printf_escaped (str, _("from <i>%s</i>"), title); } else { const char *artist_template = NULL; const char *album_template = NULL; const char *artist; const char *album; gboolean space = FALSE; artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST); album = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM); get_artist_album_templates (artist, album, &artist_template, &album_template); str_append_printf_escaped (str, "<big>%s</big>\n", title); if (album != NULL && album[0] != '\0') { str_append_printf_escaped (str, album_template, album); space = TRUE; } if (artist != NULL && artist[0] != '\0') { if (space) { g_string_append_c (str, ' '); } str_append_printf_escaped (str, artist_template, artist); } } } /* tiny bit of extra padding */ g_string_append (str, " "); clutter_text_set_markup (CLUTTER_TEXT (text), str->str); clutter_text_set_ellipsize (CLUTTER_TEXT (text), PANGO_ELLIPSIZE_NONE); g_string_free (str, TRUE); }
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); }