From: Nikolas Garofil Date: Wed, 18 Nov 2009 20:25:05 +0000 (+0100) Subject: Make $user_time, $mpd_elapsed and $mpd_length compatible with times_in_seconds X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=4a1be880d3bf1cc5ac6cf63be70939b56bf76d70;p=monky Make $user_time, $mpd_elapsed and $mpd_length compatible with times_in_seconds --- diff --git a/src/conky.c b/src/conky.c index 350e569..b3565a4 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2007,7 +2007,7 @@ void generate_text_internal(char *p, int p_max_size, snprintf(p, p_max_size, "%s", cur->users.times); } OBJ(user_time) { - update_user_time(obj->data.s); + update_user_time(obj->data.s, times_in_seconds); snprintf(p, p_max_size, "%s", cur->users.ctime); } OBJ(user_number) { @@ -2071,10 +2071,18 @@ void generate_text_internal(char *p, int p_max_size, OBJ(mpd_status) mpd_printf("%s", status); OBJ(mpd_elapsed) { - format_media_player_time(p, p_max_size, mpd_get_info()->elapsed); + if(times_in_seconds) { + snprintf(p, p_max_size, "%d", mpd_get_info()->elapsed); + } else { + format_media_player_time(p, p_max_size, mpd_get_info()->elapsed); + } } OBJ(mpd_length) { - format_media_player_time(p, p_max_size, mpd_get_info()->length); + if(times_in_seconds) { + snprintf(p, p_max_size, "%d", mpd_get_info()->length); + } else { + format_media_player_time(p, p_max_size, mpd_get_info()->length); + } } OBJ(mpd_percent) { percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100)); diff --git a/src/conky.h b/src/conky.h index 7878288..0f47b1e 100644 --- a/src/conky.h +++ b/src/conky.h @@ -309,7 +309,7 @@ extern struct information info; /* defined in users.c */ void update_users(void); -void update_user_time(char *tty); +void update_user_time(char *tty, char times_in_seconds); /* defined in conky.c */ extern double current_update_time, last_update_time, update_interval; diff --git a/src/users.c b/src/users.c index 73e8d08..1b97725 100644 --- a/src/users.c +++ b/src/users.c @@ -93,7 +93,7 @@ static void user_time(char *ptr) } } } -static void tty_user_time(char *ptr, char *tty) +static void tty_user_time(char *ptr, char *tty, char times_in_seconds) { time_t real, diff, log_in; char buf[BUFLEN] = ""; @@ -111,7 +111,11 @@ static void tty_user_time(char *ptr, char *tty) time(&real); diff = difftime(real, log_in); - format_seconds(buf, BUFLEN, diff); + if(times_in_seconds) { + snprintf(buf, BUFLEN, "%d", (int) diff); + } else { + format_seconds(buf, BUFLEN, diff); + } strncpy(ptr, buf, BUFLEN-1); } @@ -129,7 +133,7 @@ static void users_alloc(struct information *ptr) } } -void update_user_time(char *tty) +void update_user_time(char *tty, char times_in_seconds) { struct information *current_info = &info; char temp[BUFLEN] = ""; @@ -138,7 +142,7 @@ void update_user_time(char *tty) current_info->users.ctime = malloc(text_buffer_size); } - tty_user_time(temp, tty); + tty_user_time(temp, tty, times_in_seconds); if (temp != NULL) { if (current_info->users.ctime) {