diff --git a/src/screen_song.c b/src/screen_song.c
index c83cd45b3a247b24cafc21b527297681437642a7..01e2e340ae72ded67d768ba0633e869b71376958 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "screen_song.h"
+#include "screen_interface.h"
#include "screen_file.h"
+#include "screen_lyrics.h"
+#include "screen_find.h"
#include "i18n.h"
#include "screen.h"
-#include "screen_utils.h"
#include "charset.h"
#include "utils.h"
#include "mpdclient.h"
#include <assert.h>
#include <string.h>
-static list_window_t *lw;
+static struct list_window *lw;
static struct mpd_song *next_song;
max_label_width);
/* create time string and add it */
if (mpd_song_get_duration(song) > 0) {
- unsigned t = mpd_song_get_duration(song);
char length[16];
-
- /*write out the time, using hours if time over 60 minutes*/
- if (t > 3600) {
- g_snprintf(length, sizeof(length),
- "%i:%02i:%02i",
- t/3600, (t%3600)/60, t%60);
- } else {
- g_snprintf(length, sizeof(length),
- "%i:%02i", t/60, t%60);
- }
+ format_duration_short(length, sizeof(length),
+ mpd_song_get_duration(song));
screen_song_append(labels[LENGTH], length, max_label_width);
}
screen_song_append_tag(labels[COMPOSER], song, MPD_TAG_COMPOSER,
}
}
-static void
-screen_song_add_stats(const struct mpdclient *c)
+static bool
+screen_song_add_stats(struct mpd_connection *connection)
{
unsigned i, max_label_width;
char buf[64];
- char *duration;
GDate *date;
enum label {
ARTISTS, ALBUMS, SONGS, UPTIME,
[PLAYTIME] = _("Playtime"),
[DBPLAYTIME] = _("DB playtime")
};
- struct mpd_stats *mpd_stats = NULL;
+ struct mpd_stats *mpd_stats;
- if (c->connection != NULL) {
- mpd_stats = mpd_run_stats(c->connection);
- }
-
- if (mpd_stats != NULL) {
- /* Determine the width of the longest label */
- max_label_width = utf8_width(labels[0]);
- for (i = 1; i < G_N_ELEMENTS(labels); ++i) {
- if (utf8_width(labels[i]) > max_label_width)
- max_label_width = utf8_width(labels[i]);
- }
+ mpd_stats = mpd_run_stats(connection);
+ if (mpd_stats == NULL)
+ return false;
- g_ptr_array_add(current.lines, g_strdup(_("MPD statistics")) );
- g_snprintf(buf, sizeof(buf), "%d",
- mpd_stats_get_number_of_artists(mpd_stats));
- screen_song_append(labels[ARTISTS], buf, max_label_width);
- g_snprintf(buf, sizeof(buf), "%d",
- mpd_stats_get_number_of_albums(mpd_stats));
- screen_song_append(labels[ALBUMS], buf, max_label_width);
- g_snprintf(buf, sizeof(buf), "%d",
- mpd_stats_get_number_of_songs(mpd_stats));
- screen_song_append(labels[SONGS], buf, max_label_width);
- duration = time_seconds_to_durationstr(mpd_stats_get_db_play_time(mpd_stats));
- screen_song_append(labels[DBPLAYTIME], duration, max_label_width);
- g_free(duration);
- duration = time_seconds_to_durationstr(mpd_stats_get_play_time(mpd_stats));
- screen_song_append(labels[PLAYTIME], duration, max_label_width);
- g_free(duration);
- duration = time_seconds_to_durationstr(mpd_stats_get_uptime(mpd_stats));
- screen_song_append(labels[UPTIME], duration, max_label_width);
- g_free(duration);
- date = g_date_new();
- g_date_set_time_t(date, mpd_stats_get_db_update_time(mpd_stats));
- g_date_strftime(buf, sizeof(buf), "%x", date);
- screen_song_append(labels[DBUPTIME], buf, max_label_width);
- g_date_free(date);
-
- mpd_stats_free(mpd_stats);
+ /* Determine the width of the longest label */
+ max_label_width = utf8_width(labels[0]);
+ for (i = 1; i < G_N_ELEMENTS(labels); ++i) {
+ if (utf8_width(labels[i]) > max_label_width)
+ max_label_width = utf8_width(labels[i]);
}
+
+ g_ptr_array_add(current.lines, g_strdup(_("MPD statistics")) );
+ g_snprintf(buf, sizeof(buf), "%d",
+ mpd_stats_get_number_of_artists(mpd_stats));
+ screen_song_append(labels[ARTISTS], buf, max_label_width);
+ g_snprintf(buf, sizeof(buf), "%d",
+ mpd_stats_get_number_of_albums(mpd_stats));
+ screen_song_append(labels[ALBUMS], buf, max_label_width);
+ g_snprintf(buf, sizeof(buf), "%d",
+ mpd_stats_get_number_of_songs(mpd_stats));
+ screen_song_append(labels[SONGS], buf, max_label_width);
+
+ format_duration_long(buf, sizeof(buf),
+ mpd_stats_get_db_play_time(mpd_stats));
+ screen_song_append(labels[DBPLAYTIME], buf, max_label_width);
+
+ format_duration_long(buf, sizeof(buf),
+ mpd_stats_get_play_time(mpd_stats));
+ screen_song_append(labels[PLAYTIME], buf, max_label_width);
+
+ format_duration_long(buf, sizeof(buf),
+ mpd_stats_get_uptime(mpd_stats));
+ screen_song_append(labels[UPTIME], buf, max_label_width);
+
+ date = g_date_new();
+ g_date_set_time_t(date, mpd_stats_get_db_update_time(mpd_stats));
+ g_date_strftime(buf, sizeof(buf), "%x", date);
+ screen_song_append(labels[DBUPTIME], buf, max_label_width);
+ g_date_free(date);
+
+ mpd_stats_free(mpd_stats);
+ return true;
}
static void
}
/* Add some statistics about mpd */
- if (c->connection != NULL)
- screen_song_add_stats(c);
+ if (mpdclient_is_connected(c) &&
+ !screen_song_add_stats(mpdclient_get_connection(c)))
+ mpdclient_handle_error(c);
screen_song_repaint();
}