static void set_length (GValue * value, int list, int row) { int len = aud_playlist_entry_get_length (list, row, TRUE); if (len) { char s[16]; str_format_time (s, sizeof s, len); g_value_set_string (value, s); } else g_value_set_string (value, ""); }
static void set_length (GValue * value, gint list, gint row) { gint len = aud_playlist_entry_get_length (list, row, TRUE); if (len) { len /= 1000; gchar s[16]; if (len < 3600) snprintf (s, sizeof s, aud_get_bool (NULL, "leading_zero") ? "%02d:%02d" : "%d:%02d", len / 60, len % 60); else snprintf (s, sizeof s, "%d:%02d:%02d", len / 3600, (len / 60) % 60, len % 60); g_value_set_string (value, s); } else g_value_set_string (value, ""); }
static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition, void * data) { char *code; char *c; gint playlist_time, playlist_pos, output_time, v; int ret; char *ptr; gint balance; #if 0 gboolean show_pl; #endif int n; gchar *utf8_title_markup; while ((ret = lirc_nextcode (&code)) == 0 && code != NULL) { while ((ret = lirc_code2char (config, code, &c)) == 0 && c != NULL) { if (strcasecmp ("PLAY", c) == 0) aud_drct_play (); else if (strcasecmp ("STOP", c) == 0) aud_drct_stop (); else if (strcasecmp ("PAUSE", c) == 0) aud_drct_pause (); else if (strcasecmp ("PLAYPAUSE", c) == 0) aud_drct_play_pause (); else if (strncasecmp ("NEXT", c, 4) == 0) { ptr = c + 4; while (isspace (*ptr)) ptr++; n = atoi (ptr); if (n <= 0) n = 1; for (; n > 0; n--) { aud_drct_pl_next (); } } else if (strncasecmp ("PREV", c, 4) == 0) { ptr = c + 4; while (isspace (*ptr)) ptr++; n = atoi (ptr); if (n <= 0) n = 1; for (; n > 0; n--) { aud_drct_pl_prev (); } } else if (strcasecmp ("SHUFFLE", c) == 0) aud_set_bool (NULL, "shuffle", ! aud_get_bool (NULL, "shuffle")); else if (strcasecmp ("REPEAT", c) == 0) aud_set_bool (NULL, "repeat", ! aud_get_bool (NULL, "repeat")); else if (strncasecmp ("FWD", c, 3) == 0) { ptr = c + 3; while (isspace (*ptr)) ptr++; n = atoi (ptr) * 1000; if (n <= 0) n = 5000; output_time = aud_drct_get_time (); int playlist = aud_playlist_get_active (); playlist_pos = aud_playlist_get_position (playlist); playlist_time = aud_playlist_entry_get_length (playlist, playlist_pos, FALSE); if (playlist_time - output_time < n) output_time = playlist_time - n; aud_drct_seek (output_time + n); } else if (strncasecmp ("BWD", c, 3) == 0) { ptr = c + 3; while (isspace (*ptr)) ptr++; n = atoi (ptr) * 1000; if (n <= 0) n = 5000; output_time = aud_drct_get_time (); if (output_time < n) output_time = n; aud_drct_seek (output_time - n); } else if (strncasecmp ("VOL_UP", c, 6) == 0) { ptr = c + 6; while (isspace (*ptr)) ptr++; n = atoi (ptr); if (n <= 0) n = 5; aud_drct_get_volume_main (&v); if (v > (100 - n)) v = 100 - n; aud_drct_set_volume_main (v + n); } else if (strncasecmp ("VOL_DOWN", c, 8) == 0) { ptr = c + 8; while (isspace (*ptr)) ptr++; n = atoi (ptr); if (n <= 0) n = 5; aud_drct_get_volume_main (&v); if (v < n) v = n; aud_drct_set_volume_main (v - n); } else if (strcasecmp ("QUIT", c) == 0) { aud_drct_quit (); } else if (strcasecmp ("MUTE", c) == 0) { if (mute == 0) { mute = 1; /* store the master volume so we can restore it on unmute. */ aud_drct_get_volume_main (&mute_vol); aud_drct_set_volume_main (0); } else { mute = 0; aud_drct_set_volume_main (mute_vol); } } else if (strncasecmp ("BAL_LEFT", c, 8) == 0) { ptr = c + 8; while (isspace (*ptr)) ptr++; n = atoi (ptr); if (n <= 0) n = 5; aud_drct_get_volume_balance (&balance); balance -= n; if (balance < -100) balance = -100; aud_drct_set_volume_balance (balance); } else if (strncasecmp ("BAL_RIGHT", c, 9) == 0) { ptr = c + 9; while (isspace (*ptr)) ptr++; n = atoi (ptr); if (n <= 0) n = 5; aud_drct_get_volume_balance (&balance); balance += n; if (balance > 100) balance = 100; aud_drct_set_volume_balance (balance); } else if (strcasecmp ("BAL_CENTER", c) == 0) { balance = 0; aud_drct_set_volume_balance (balance); } else if (strcasecmp ("LIST", c) == 0) { #if 0 show_pl = aud_drct_pl_win_is_visible (); show_pl = (show_pl) ? 0 : 1; aud_drct_pl_win_toggle (show_pl); #endif } else if (strcasecmp ("PLAYLIST_CLEAR", c) == 0) { aud_drct_stop (); int playlist = aud_playlist_get_active (); aud_playlist_entry_delete (playlist, 0, aud_playlist_entry_count (playlist)); } else if (strncasecmp ("PLAYLIST_ADD ", c, 13) == 0) { aud_drct_pl_add (c + 13, -1); } else if ((strlen (c) == 1) && ((*c >= '0') || (*c <= '9'))) { if (track_no_pos < 63) { if (tid) g_source_remove (tid); track_no[track_no_pos++] = *c; track_no[track_no_pos] = 0; tid = g_timeout_add (1500, jump_to, NULL); utf8_title_markup = g_markup_printf_escaped ("%s", track_no); hook_call ("aosd toggle", utf8_title_markup); } } else { fprintf (stderr, _("%s: unknown command \"%s\"\n"), plugin_name, c); } } free (code); if (ret == -1) break; } if (ret == -1) { /* something went badly wrong */ fprintf (stderr, _("%s: disconnected from LIRC\n"), plugin_name); cleanup (); if (aud_get_bool ("lirc", "enable_reconnect")) { int reconnect_timeout = aud_get_int ("lirc", "reconnect_timeout"); fprintf (stderr, _("%s: will try reconnect every %d seconds...\n"), plugin_name, reconnect_timeout); g_timeout_add (1000 * reconnect_timeout, reconnect_lirc, NULL); } } return TRUE; }
/* 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); }