summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e67bb41)
raw | patch | inline | side by side (parent: e67bb41)
author | Max Kellermann <max@duempel.org> | |
Fri, 2 Oct 2009 06:36:36 +0000 (08:36 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 2 Oct 2009 06:36:36 +0000 (08:36 +0200) |
New function in utils.c. Use that same function in screen_play.c,
status_bar.c and strfsong.c.
status_bar.c and strfsong.c.
src/screen_play.c | patch | blob | history | |
src/screen_song.c | patch | blob | history | |
src/status_bar.c | patch | blob | history | |
src/strfsong.c | patch | blob | history | |
src/utils.c | patch | blob | history | |
src/utils.h | patch | blob | history |
diff --git a/src/screen_play.c b/src/screen_play.c
index f481d5b4f4dfbba78c8e38e7b9880f4b6c1361bd..aaaace14505572e2a152414918985477bc91c66d 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
playlist_save_selection();
}
-#ifndef NCMPC_MINI
-static char *
-format_duration(unsigned duration)
-{
- if (duration == 0)
- return NULL;
-
- return g_strdup_printf("%d:%02d", duration / 60, duration % 60);
-}
-#endif
-
static const char *
list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED void *data)
{
@@ -146,8 +135,12 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
strfsong(songname, MAX_SONG_LENGTH, options.list_format, song);
#ifndef NCMPC_MINI
- if(second_column)
- *second_column = format_duration(mpd_song_get_duration(song));
+ if (second_column != NULL && mpd_song_get_duration(song) > 0) {
+ char duration[32];
+ format_duration_short(duration, sizeof(duration),
+ mpd_song_get_duration(song));
+ *second_column = g_strdup(duration);
+ }
if (idx == lw->selected)
{
diff --git a/src/screen_song.c b/src/screen_song.c
index 7b4a4810f11a320a4ae944736cbe9339f5521b12..d0285e9ab9880632c6597b25e35f1fef87d0aa83 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
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,
diff --git a/src/status_bar.c b/src/status_bar.c
index b778bc032e2af97b5198bf394611e76200e3b404..04881afc939ca2ce2b61755b5b7735ed9afe0ac4 100644 (file)
--- a/src/status_bar.c
+++ b/src/status_bar.c
#include "charset.h"
#include "strfsong.h"
#include "player_command.h"
+#include "utils.h"
#ifndef NCMPC_MINI
#include "hscroll.h"
if (state == MPD_STATE_PLAY || state == MPD_STATE_PAUSE) {
int total_time = mpd_status_get_total_time(status);
if (total_time > 0) {
+ char elapsed_string[32], duration_string[32];
+
/*checks the conf to see whether to display elapsed or remaining time */
if(!strcmp(options.timedisplay_type,"elapsed"))
elapsedTime = mpd_status_get_elapsed_time(status);
}
#endif
- /*write out the time, using hours if time over 60 minutes*/
- if (total_time > 3600) {
- g_snprintf(buffer, sizeof(buffer),
- "%s [%i:%02i:%02i/%i:%02i:%02i]",
- bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
- total_time / 3600,
- (total_time % 3600)/60,
- total_time % 60);
- } else {
- g_snprintf(buffer, sizeof(buffer),
- "%s [%i:%02i/%i:%02i]",
- bitrate, elapsedTime/60, elapsedTime%60,
- total_time / 60, total_time % 60);
- }
+ /* write out the time */
+ format_duration_short(elapsed_string,
+ sizeof(elapsed_string),
+ elapsedTime);
+ format_duration_short(duration_string,
+ sizeof(duration_string),
+ total_time);
+
+ g_snprintf(buffer, sizeof(buffer), "%s [%s/%s]",
+ bitrate, elapsed_string, duration_string);
#ifndef NCMPC_MINI
} else {
g_snprintf(buffer, sizeof(buffer),
diff --git a/src/strfsong.c b/src/strfsong.c
index ff1d6ad6b31931bea0cb9ea22e38ee47e00df099..a146583516553754d14d4c9da03f6362de858db3 100644 (file)
--- a/src/strfsong.c
+++ b/src/strfsong.c
#include "strfsong.h"
#include "charset.h"
+#include "utils.h"
#include <mpd/client.h>
unsigned duration = mpd_song_get_duration(song);
if (duration > 0) {
- if (duration > 3600) {
- temp = g_strdup_printf("%d:%02d:%02d",
- duration / 3600,
- (duration % 3600) / 60,
- duration % 60);
- } else {
- temp = g_strdup_printf("%d:%02d",
- duration / 60,
- duration % 60);
- }
+ char buffer[32];
+ format_duration_short(buffer, sizeof(buffer),
+ duration);
+ temp = g_strdup(buffer);
}
}
diff --git a/src/utils.c b/src/utils.c
index 8023bfb00879c67ae55abac46787fb9fc9ea58aa..857e15d9baa7c63f5677345e8deb87e704484e82 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
return list;
}
+void
+format_duration_short(char *buffer, size_t length, unsigned duration)
+{
+ if (duration < 3600)
+ g_snprintf(buffer, length,
+ "%i:%02i", duration / 60, duration % 60);
+ else
+ g_snprintf(buffer, length,
+ "%i:%02i:%02i", duration / 3600,
+ (duration % 3600) / 60, duration % 60);
+}
+
void
format_duration_long(char *p, size_t length, unsigned long duration)
{
diff --git a/src/utils.h b/src/utils.h
index c9374fa3a3fc51c6b0f140ecf88d47688b22f444..85331bc64943fc616a138db21bee2b567e554066 100644 (file)
--- a/src/utils.h
+++ b/src/utils.h
gcmp_list_from_path(struct mpdclient *c, const gchar *path,
GList *list, gint types);
+void
+format_duration_short(char *buffer, size_t length, unsigned duration);
+
void
format_duration_long(char *buffer, size_t length, unsigned long duration);