summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0709a19)
raw | patch | inline | side by side (parent: 0709a19)
author | Patrick Hallen <patrick.hallen@rwth-aachen.de> | |
Fri, 13 Mar 2009 20:40:37 +0000 (21:40 +0100) | ||
committer | Patrick Hallen <patrick.hallen@rwth-aachen.de> | |
Fri, 13 Mar 2009 20:40:37 +0000 (21:40 +0100) |
src/screen_song.c | patch | blob | history | |
src/utils.c | patch | blob | history | |
src/utils.h | patch | blob | history |
diff --git a/src/screen_song.c b/src/screen_song.c
index d7e086928ccf34815bf360cc87edc37d99d7f3d7..3af2d8bca0dff66ad307f80d707544f65a13a508 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
#include "screen.h"
#include "screen_utils.h"
#include "charset.h"
+#include "utils.h"
#include <glib/gprintf.h>
#include <string.h>
}
}
+static void
+screen_song_add_stats(const mpdclient_t *c)
+{
+ unsigned i, max_label_width;
+ char buf[64];
+ char *duration;
+ GDate *date;
+ enum label {
+ ARTISTS, ALBUMS, SONGS, UPTIME,
+ DBUPTIME, PLAYTIME, DBPLAYTIME
+ };
+ const char *labels[] = { [ARTISTS] = _("Number of artists"),
+ [ALBUMS] = _("Number of albums"),
+ [SONGS] = _("Number of songs"),
+ [UPTIME] = _("Uptime"),
+ [DBUPTIME] =_("DB last updated"),
+ [PLAYTIME] = _("Playtime"),
+ [DBPLAYTIME] = _("DB playtime")
+ };
+ mpd_Stats *mpd_stats = NULL;
+ if (c->connection != NULL) {
+ mpd_sendStatsCommand(c->connection);
+ mpd_stats = mpd_getStats(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]);
+ }
+
+ g_ptr_array_add(current.lines, g_strdup(_("MPD Statistics")) );
+ g_snprintf(buf, sizeof(buf), "%d", mpd_stats->numberOfArtists);
+ screen_song_append(labels[ARTISTS], buf, max_label_width);
+ g_snprintf(buf, sizeof(buf), "%d", mpd_stats->numberOfAlbums);
+ screen_song_append(labels[ALBUMS], buf, max_label_width);
+ g_snprintf(buf, sizeof(buf), "%d", mpd_stats->numberOfSongs);
+ screen_song_append(labels[SONGS], buf, max_label_width);
+ duration = time_seconds_to_durationstr(mpd_stats->dbPlayTime);
+ screen_song_append(labels[DBPLAYTIME], duration, max_label_width);
+ g_free(duration);
+ duration = time_seconds_to_durationstr(mpd_stats->playTime);
+ screen_song_append(labels[PLAYTIME], duration, max_label_width);
+ g_free(duration);
+ duration = time_seconds_to_durationstr(mpd_stats->uptime);
+ screen_song_append(labels[UPTIME], duration, max_label_width);
+ g_free(duration);
+ date = g_date_new();
+ g_date_set_time_t(date, mpd_stats->dbUpdateTime);
+ g_date_strftime(buf, sizeof(buf), "%x", date);
+ screen_song_append(labels[DBUPTIME], buf, max_label_width);
+ g_date_free(date);
+ }
+}
+
static void
screen_song_update(mpdclient_t *c)
{
g_ptr_array_add(current.lines, g_strdup("\0"));
}
+ /* Add some statistics about mpd */
+ if (c->connection != NULL)
+ screen_song_add_stats(c);
+
screen_song_repaint();
//}
}
diff --git a/src/utils.c b/src/utils.c
index cd125099e67a72edd245608b411bcf0dbf7f14c0..32707eb48901ac164ee8d23e4e9fdde377a8c89d 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
#include "utils.h"
#include "options.h"
#include "charset.h"
+#include "i18n.h"
#include <ctype.h>
#include <stdlib.h>
@@ -113,3 +114,56 @@ gcmp_list_from_path(mpdclient_t *c, const gchar *path, GList *list, gint types)
filelist_free(filelist);
return list;
}
+
+char *
+time_seconds_to_durationstr(unsigned long time_seconds)
+{
+ const char *year = _("year");
+ const char *years = _("years");
+ const char *week = _("week");
+ const char *weeks = _("weeks");
+ const char *day = _("day");
+ const char *days = _("days");
+ char *duration;
+ char *iter;
+ unsigned bytes_written = 0;
+ unsigned length = utf8_width(years) +
+ utf8_width(weeks) + utf8_width(days) + 32;
+
+ duration = g_malloc(length);
+ iter = duration;
+ if (time_seconds / 31536000 > 0) {
+ if (time_seconds % 31536000 == 1)
+ bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 31536000, year);
+ else
+ bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 31536000, years);
+ time_seconds %= 31536000;
+ length -= bytes_written;
+ iter += bytes_written;
+ }
+ if (time_seconds / 604800 > 0) {
+ if (time_seconds % 604800 == 1)
+ bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 604800, week);
+ else
+ bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 604800, weeks);
+ time_seconds %= 604800;
+ length -= bytes_written;
+ iter += bytes_written;
+ }
+ if (time_seconds / 86400 > 0) {
+ if (time_seconds % 86400 == 1)
+ bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 86400, day);
+ else
+ bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 86400, days);
+ time_seconds %= 86400;
+ length -= bytes_written;
+ iter += bytes_written;
+ }
+ g_snprintf(iter, length, "%02lu:%02lu:%02lu",
+ time_seconds / 3600,
+ time_seconds % 3600 / 60,
+ time_seconds % 3600 % 60);
+ return duration;
+}
+
+
diff --git a/src/utils.h b/src/utils.h
index a75ef8d7f0099d3f4171df950527676593f0c957..20077f0b231a7a1e4881180fa058dbbbf6416d5a 100644 (file)
--- a/src/utils.h
+++ b/src/utils.h
GList *list,
gint types);
+char *
+time_seconds_to_durationstr(unsigned long time_seconds);
+
#endif