summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 122d196)
raw | patch | inline | side by side (parent: 122d196)
author | Max Kellermann <max@duempel.org> | |
Fri, 2 Oct 2009 06:25:14 +0000 (08:25 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 2 Oct 2009 06:25:14 +0000 (08:25 +0200) |
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 78fbf45e5a957d5537bfa157fc0d47e605b00763..7b4a4810f11a320a4ae944736cbe9339f5521b12 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
{
unsigned i, max_label_width;
char buf[64];
- char *duration;
GDate *date;
enum label {
ARTISTS, ALBUMS, SONGS, UPTIME,
g_snprintf(buf, sizeof(buf), "%d",
mpd_stats_get_number_of_songs(mpd_stats));
screen_song_append(labels[SONGS], buf, max_label_width);
- duration = format_duration_long(mpd_stats_get_db_play_time(mpd_stats));
- screen_song_append(labels[DBPLAYTIME], duration, max_label_width);
- g_free(duration);
- duration = format_duration_long(mpd_stats_get_play_time(mpd_stats));
- screen_song_append(labels[PLAYTIME], duration, max_label_width);
- g_free(duration);
- duration = format_duration_long(mpd_stats_get_uptime(mpd_stats));
- screen_song_append(labels[UPTIME], duration, max_label_width);
- g_free(duration);
+
+ 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);
diff --git a/src/utils.c b/src/utils.c
index 688f6c88f4463afc93938fe3008dca8d16794d39..8023bfb00879c67ae55abac46787fb9fc9ea58aa 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
return list;
}
-char *
-format_duration_long(unsigned long duration)
+void
+format_duration_long(char *p, size_t length, unsigned long duration)
{
const char *year = _("year");
const char *years = _("years");
const char *weeks = _("weeks");
const char *day = _("day");
const char *days = _("days");
- char *buffer, *p;
unsigned bytes_written = 0;
- unsigned length = utf8_width(years) +
- utf8_width(weeks) + utf8_width(days) + 32;
- buffer = g_malloc(length);
- p = buffer;
if (duration / 31536000 > 0) {
if (duration / 31536000 == 1)
bytes_written = g_snprintf(p, length, "%d %s, ", 1, year);
length -= bytes_written;
p += bytes_written;
}
+
g_snprintf(p, length, "%02lu:%02lu:%02lu", duration / 3600,
duration % 3600 / 60, duration % 3600 % 60);
- return buffer;
}
-
-
diff --git a/src/utils.h b/src/utils.h
index 1c8fe8ba0c914a3a272124a44aaa9eebc3682ded..c9374fa3a3fc51c6b0f140ecf88d47688b22f444 100644 (file)
--- a/src/utils.h
+++ b/src/utils.h
gcmp_list_from_path(struct mpdclient *c, const gchar *path,
GList *list, gint types);
-char *
-format_duration_long(unsigned long duration);
+void
+format_duration_long(char *buffer, size_t length, unsigned long duration);
#endif