static void confirm_delete (void) { int playlist = aud_playlist_get_active (); int entry_count = aud_playlist_entry_count (playlist); for (int i = 0; i < entry_count; i ++) { if (! aud_playlist_entry_get_selected (playlist, i)) continue; char * uri = aud_playlist_entry_get_filename (playlist, i); char * filename = uri_to_filename (uri); if (filename) { if (aud_get_bool ("delete_files", "use_trash")) move_to_trash (filename); else really_delete (filename); str_unref (filename); } else { SPRINTF (error, _("Error deleting %s: not a local file."), uri); aud_interface_show_error (error); } str_unref (uri); } aud_playlist_delete_selected (playlist); }
void audgui_infowin_show (int playlist, int entry) { char * filename = aud_playlist_entry_get_filename (playlist, entry); g_return_if_fail (filename != NULL); PluginHandle * decoder = aud_playlist_entry_get_decoder (playlist, entry, FALSE); if (decoder == NULL) goto FREE; if (aud_custom_infowin (filename, decoder)) goto FREE; Tuple * tuple = aud_playlist_entry_get_tuple (playlist, entry, FALSE); if (tuple == NULL) { char * message = g_strdup_printf (_("No info available for %s.\n"), filename); aud_interface_show_error (message); g_free (message); goto FREE; } infowin_show (playlist, entry, filename, tuple, decoder, aud_file_can_write_tuple (filename, decoder)); tuple_unref (tuple); FREE: str_unref (filename); }
/* deprecated */ EXPORT GdkPixbuf * audgui_pixbuf_for_entry (int list, int entry) { char * name = aud_playlist_entry_get_filename (list, entry); g_return_val_if_fail (name, NULL); const void * data; int64_t size; aud_art_get_data (name, & data, & size); if (data) { GdkPixbuf * p = audgui_pixbuf_from_data (data, size); aud_art_unref (name); if (p) { str_unref (name); return p; } } str_unref (name); return audgui_pixbuf_fallback (); }
static void do_add (bool_t play, char * * title) { int list = aud_playlist_by_unique_id (playlist_id); int n_items = index_count (items); int n_selected = 0; Index * filenames = index_new (); Index * tuples = index_new (); for (int i = 0; i < n_items; i ++) { if (! selection->data[i]) continue; Item * item = index_get (items, i); for (int m = 0; m < item->matches->len; m ++) { int entry = g_array_index (item->matches, int, m); index_insert (filenames, -1, aud_playlist_entry_get_filename (list, entry)); index_insert (tuples, -1, aud_playlist_entry_get_tuple (list, entry, TRUE)); } n_selected ++; if (title && n_selected == 1) * title = item->name; } if (title && n_selected != 1) * title = NULL; aud_playlist_entry_insert_batch (aud_playlist_get_active (), -1, filenames, tuples, play); }
static void position_cb (void * data, void * user_data) { gint playlist = GPOINTER_TO_INT (data); gint position = aud_playlist_get_position (playlist); if (! aud_get_bool (NULL, "equalizer_autoload") || playlist != aud_playlist_get_playing () || position == -1) return; gchar * filename = aud_playlist_entry_get_filename (playlist, position); load_auto_preset (filename); str_unref (filename); }
static void begin_add (const char * path) { int list = get_playlist (FALSE, FALSE); if (list < 0) list = create_playlist (); aud_set_str ("search-tool", "path", path); char * uri = filename_to_uri (path); g_return_if_fail (uri); if (! g_str_has_suffix (uri, "/")) { SCONCAT2 (temp, uri, "/"); str_unref (uri); uri = str_get (temp); } destroy_added_table (); added_table = g_hash_table_new_full ((GHashFunc) str_hash, (GEqualFunc) str_equal, (GDestroyNotify) str_unref, NULL); int entries = aud_playlist_entry_count (list); for (int entry = 0; entry < entries; entry ++) { char * filename = aud_playlist_entry_get_filename (list, entry); if (g_str_has_prefix (filename, uri) && ! g_hash_table_contains (added_table, filename)) { aud_playlist_entry_set_selected (list, entry, FALSE); g_hash_table_insert (added_table, filename, NULL); } else { aud_playlist_entry_set_selected (list, entry, TRUE); str_unref (filename); } } aud_playlist_delete_selected (list); aud_playlist_remove_failed (list); Index * add = index_new (); index_insert (add, -1, uri); aud_playlist_entry_insert_filtered (list, -1, add, NULL, filter_cb, NULL, FALSE); adding = TRUE; }
EXPORT GdkPixbuf * audgui_pixbuf_request_current (void) { if (! current_pixbuf) { int list = aud_playlist_get_playing (); int entry = aud_playlist_get_position (list); if (entry < 0) return NULL; char * filename = aud_playlist_entry_get_filename (list, entry); current_pixbuf = audgui_pixbuf_request (filename); str_unref (filename); } if (current_pixbuf) g_object_ref ((GObject *) current_pixbuf); return current_pixbuf; }
static void lyricwiki_playback_began(void) { if (!aud_drct_get_playing()) return; /* FIXME: cancel previous VFS requests (not possible with current API) */ str_unref(state.filename); str_unref(state.title); str_unref(state.artist); str_unref(state.uri); int playlist = aud_playlist_get_playing(); int pos = aud_playlist_get_position(playlist); state.filename = aud_playlist_entry_get_filename(playlist, pos); aud_playlist_entry_describe(playlist, pos, &state.title, &state.artist, NULL, FALSE); state.uri = NULL; get_lyrics_step_1(); }
EXPORT GdkPixbuf * audgui_pixbuf_for_entry (int list, int entry) { char * name = aud_playlist_entry_get_filename (list, entry); g_return_val_if_fail (name, NULL); const void * data; int64_t size; aud_art_get_data (name, & data, & size); if (data) { GdkPixbuf * p = audgui_pixbuf_from_data (data, size); aud_art_unref (name); if (p) { str_unref (name); return p; } } str_unref (name); AUDDBG ("Using fallback pixbuf.\n"); static GdkPixbuf * fallback = NULL; if (! fallback) { char * path = g_strdup_printf ("%s/images/album.png", aud_get_path (AUD_PATH_DATA_DIR)); fallback = gdk_pixbuf_new_from_file (path, NULL); g_free (path); } if (fallback) g_object_ref ((GObject *) fallback); return fallback; }
static gint file_open(gint fmt, gint rate, gint nch) { gchar *filename = NULL, *temp = NULL; gchar * directory; gint pos; gint rv; gint playlist; input.format = fmt; input.frequency = rate; input.channels = nch; playlist = aud_playlist_get_playing (); if (playlist < 0) return 0; pos = aud_playlist_get_position(playlist); tuple = aud_playlist_entry_get_tuple (playlist, pos, FALSE); if (tuple == NULL) return 0; if (filenamefromtags) { gchar * utf8 = aud_playlist_entry_get_title (playlist, pos, FALSE); string_replace_char (utf8, '/', ' '); gchar buf[3 * strlen (utf8) + 1]; str_encode_percent (utf8, -1, buf); str_unref (utf8); filename = g_strdup (buf); } else { temp = aud_playlist_entry_get_filename (playlist, pos); gchar * original = strrchr (temp, '/'); g_return_val_if_fail (original != NULL, 0); filename = g_strdup (original + 1); str_unref (temp); if (!use_suffix) if ((temp = strrchr(filename, '.')) != NULL) *temp = '\0'; } if (prependnumber) { gint number = tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL); if (!tuple || !number) number = pos + 1; temp = g_strdup_printf ("%d%%20%s", number, filename); g_free(filename); filename = temp; } if (save_original) { temp = aud_playlist_entry_get_filename (playlist, pos); directory = g_strdup (temp); str_unref (temp); temp = strrchr (directory, '/'); g_return_val_if_fail (temp != NULL, 0); temp[1] = 0; } else { g_return_val_if_fail (file_path[0], 0); if (file_path[strlen (file_path) - 1] == '/') directory = g_strdup (file_path); else directory = g_strdup_printf ("%s/", file_path); } temp = g_strdup_printf ("%s%s.%s", directory, filename, fileext_str[fileext]); g_free (directory); g_free (filename); filename = temp; output_file = safe_create (filename); g_free (filename); if (output_file == NULL) return 0; convert_init (fmt, plugin->format_required (fmt), nch); rv = (plugin->open)(); samples_written = 0; return rv; }
/* do_command(): do @cmd after replacing the format codes @cmd: command to run */ static void do_command (char * cmd) { int playlist = aud_playlist_get_playing (); int pos = aud_playlist_get_position (playlist); char *shstring = NULL, *temp, numbuf[32]; gboolean playing; Formatter *formatter; if (cmd && strlen(cmd) > 0) { formatter = formatter_new(); char * ctitle = aud_playlist_entry_get_title (playlist, pos, FALSE); if (ctitle) { temp = escape_shell_chars (ctitle); formatter_associate(formatter, 's', temp); formatter_associate(formatter, 'n', temp); g_free(temp); str_unref (ctitle); } else { formatter_associate(formatter, 's', ""); formatter_associate(formatter, 'n', ""); } char * filename = aud_playlist_entry_get_filename (playlist, pos); if (filename) { temp = escape_shell_chars (filename); formatter_associate(formatter, 'f', temp); g_free(temp); str_unref (filename); } else formatter_associate(formatter, 'f', ""); g_snprintf(numbuf, sizeof(numbuf), "%02d", pos + 1); formatter_associate(formatter, 't', numbuf); int length = aud_playlist_entry_get_length (playlist, pos, FALSE); if (length > 0) { g_snprintf(numbuf, sizeof(numbuf), "%d", length); formatter_associate(formatter, 'l', numbuf); } else formatter_associate(formatter, 'l', "0"); playing = aud_drct_get_playing(); g_snprintf(numbuf, sizeof(numbuf), "%d", playing); formatter_associate(formatter, 'p', numbuf); if (playing) { int brate, srate, chans; aud_drct_get_info (& brate, & srate, & chans); snprintf (numbuf, sizeof numbuf, "%d", brate); formatter_associate (formatter, 'r', numbuf); snprintf (numbuf, sizeof numbuf, "%d", srate); formatter_associate (formatter, 'F', numbuf); snprintf (numbuf, sizeof numbuf, "%d", chans); formatter_associate (formatter, 'c', numbuf); } Tuple * tuple = aud_playlist_entry_get_tuple (aud_playlist_get_active (), pos, 0); char * artist = tuple ? tuple_get_str (tuple, FIELD_ARTIST, NULL) : NULL; if (artist) { formatter_associate(formatter, 'a', artist); str_unref(artist); } else formatter_associate(formatter, 'a', ""); char * album = tuple ? tuple_get_str (tuple, FIELD_ALBUM, NULL) : NULL; if (album) { formatter_associate(formatter, 'b', album); str_unref(album); } else formatter_associate(formatter, 'b', ""); char * title = tuple ? tuple_get_str (tuple, FIELD_TITLE, NULL) : NULL; if (title) { formatter_associate(formatter, 'T', title); str_unref(title); } else formatter_associate(formatter, 'T', ""); if (tuple) tuple_unref (tuple); shstring = formatter_format(formatter, cmd); formatter_destroy(formatter); if (shstring) { execute_command(shstring); /* FIXME: This can possibly be freed too early */ g_free(shstring); } } }
static void update_metadata (void * data, GObject * object) { char * title = NULL, * artist = NULL, * album = NULL, * file = NULL; int length = 0; int playlist = aud_playlist_get_playing (); int entry = (playlist >= 0) ? aud_playlist_get_position (playlist) : -1; if (entry >= 0) { aud_playlist_entry_describe (playlist, entry, & title, & artist, & album, TRUE); file = aud_playlist_entry_get_filename (playlist, entry); length = aud_playlist_entry_get_length (playlist, entry, TRUE); } /* pointer comparison works for pooled strings */ if (title == last_title && artist == last_artist && album == last_album && file == last_file && length == last_length) { str_unref (title); str_unref (artist); str_unref (album); str_unref (file); return; } if (file != last_file) { if (image_file) aud_art_unref (last_file); image_file = file ? aud_art_get_file (file) : NULL; } str_unref (last_title); str_unref (last_artist); str_unref (last_album); str_unref (last_file); last_title = title; last_artist = artist; last_album = album; last_file = file; last_length = length; GVariant * elems[7]; int nelems = 0; if (title) { GVariant * key = g_variant_new_string ("xesam:title"); GVariant * str = g_variant_new_string (title); GVariant * var = g_variant_new_variant (str); elems[nelems ++] = g_variant_new_dict_entry (key, var); } if (artist) { GVariant * key = g_variant_new_string ("xesam:artist"); GVariant * str = g_variant_new_string (artist); GVariant * array = g_variant_new_array (G_VARIANT_TYPE_STRING, & str, 1); GVariant * var = g_variant_new_variant (array); elems[nelems ++] = g_variant_new_dict_entry (key, var); } if (album) { GVariant * key = g_variant_new_string ("xesam:album"); GVariant * str = g_variant_new_string (album); GVariant * var = g_variant_new_variant (str); elems[nelems ++] = g_variant_new_dict_entry (key, var); } if (file) { GVariant * key = g_variant_new_string ("xesam:url"); GVariant * str = g_variant_new_string (file); GVariant * var = g_variant_new_variant (str); elems[nelems ++] = g_variant_new_dict_entry (key, var); } if (length > 0) { GVariant * key = g_variant_new_string ("mpris:length"); GVariant * val = g_variant_new_int64 ((int64_t) length * 1000); GVariant * var = g_variant_new_variant (val); elems[nelems ++] = g_variant_new_dict_entry (key, var); } if (image_file) { GVariant * key = g_variant_new_string ("mpris:artUrl"); GVariant * str = g_variant_new_string (image_file); GVariant * var = g_variant_new_variant (str); elems[nelems ++] = g_variant_new_dict_entry (key, var); } GVariant * key = g_variant_new_string ("mpris:trackid"); GVariant * str = g_variant_new_string ("/org/mpris/MediaPlayer2/CurrentTrack"); GVariant * var = g_variant_new_variant (str); elems[nelems ++] = g_variant_new_dict_entry (key, var); if (! metadata_type) metadata_type = g_variant_type_new ("{sv}"); GVariant * array = g_variant_new_array (metadata_type, elems, nelems); g_object_set (object, "metadata", array, NULL); }