diff options
-rw-r--r-- | src/common.c | 12 | ||||
-rw-r--r-- | src/common.h | 1 | ||||
-rw-r--r-- | src/status_bar.c | 26 | ||||
-rw-r--r-- | src/windows.c | 9 |
4 files changed, 17 insertions, 31 deletions
diff --git a/src/common.c b/src/common.c index fd8da3e4..40f9d925 100644 --- a/src/common.c +++ b/src/common.c @@ -48,18 +48,6 @@ create_dir(char *name) e = mkdir(name, S_IRWXU); } -void -get_time(char *thetime) -{ - time_t rawtime; - struct tm *timeinfo; - - time(&rawtime); - timeinfo = localtime(&rawtime); - - strftime(thetime, 80, "%H:%M", timeinfo); -} - char * str_replace(const char *string, const char *substr, const char *replacement) diff --git a/src/common.h b/src/common.h index 22daa038..2515e065 100644 --- a/src/common.h +++ b/src/common.h @@ -37,7 +37,6 @@ void p_slist_free_full(GSList *items, GDestroyNotify free_func); void create_dir(char *name); -void get_time(char *thetime); char * str_replace(const char *string, const char *substr, const char *replacement); int str_contains(char str[], int size, char ch); diff --git a/src/status_bar.c b/src/status_bar.c index d2094cf9..28456f6f 100644 --- a/src/status_bar.c +++ b/src/status_bar.c @@ -26,7 +26,6 @@ #include <ncurses.h> #include "ui.h" -#include "common.h" static WINDOW *status_bar; static char *message = NULL; @@ -34,7 +33,7 @@ static char _active[29] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ]"; static int is_active[9]; static int is_new[9]; static int dirty; -static char curr_time[80]; +static GDateTime *last_time; static void _status_bar_update_time(void); @@ -55,19 +54,21 @@ create_status_bar(void) mvwprintw(status_bar, 0, cols - 29, _active); wattroff(status_bar, COLOUR_BAR_DRAW); - get_time(curr_time); + last_time = g_date_time_new_now_local(); + dirty = TRUE; } void status_bar_refresh(void) { - char new_time[80]; - get_time(new_time); + GDateTime *now_time = g_date_time_new_now_local(); + GTimeSpan elapsed = g_date_time_difference(now_time, last_time); - if (strcmp(new_time, curr_time) != 0) { + if (elapsed >= 60000000) { dirty = TRUE; - strcpy(curr_time, new_time); + g_date_time_unref(now_time); + last_time = g_date_time_new_now_local(); } if (dirty) { @@ -102,7 +103,7 @@ status_bar_resize(void) if (message != NULL) mvwprintw(status_bar, 0, 9, message); - get_time(curr_time); + last_time = g_date_time_new_now_local(); dirty = TRUE; } @@ -216,18 +217,17 @@ status_bar_clear(void) static void _status_bar_update_time(void) { - char bar_time[6]; - char tstmp[80]; - get_time(tstmp); - sprintf(bar_time, "%s", tstmp); + gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); wattron(status_bar, COLOUR_BAR_DRAW); mvwaddch(status_bar, 0, 1, '['); wattroff(status_bar, COLOUR_BAR_DRAW); - mvwprintw(status_bar, 0, 2, bar_time); + mvwprintw(status_bar, 0, 2, date_fmt); wattron(status_bar, COLOUR_BAR_DRAW); mvwaddch(status_bar, 0, 7, ']'); wattroff(status_bar, COLOUR_BAR_DRAW); + free(date_fmt); + dirty = TRUE; } diff --git a/src/windows.c b/src/windows.c index 136d9d78..df0da33d 100644 --- a/src/windows.c +++ b/src/windows.c @@ -31,7 +31,6 @@ #include <ncurses.h> #include "command.h" -#include "common.h" #include "contact.h" #include "log.h" #include "preferences.h" @@ -509,7 +508,6 @@ cons_help(void) cons_show("Navigation:"); cons_show(""); cons_show("F1 : This console window."); - cons_show(" You may need to change the help key in your terminal settings."); cons_show("F2-F10 : Chat windows."); cons_show("UP, DOWN : Navigate input history."); cons_show("LEFT, RIGHT, HOME, END : Edit current input."); @@ -759,9 +757,10 @@ _win_switch_if_active(const int i) static void _win_show_time(WINDOW *win) { - char tstmp[80]; - get_time(tstmp); - wprintw(win, "%s - ", tstmp); + GDateTime *time = g_date_time_new_now_local(); + gchar *date_fmt = g_date_time_format(time, "%H:%M"); + wprintw(win, "%s - ", date_fmt); + g_date_time_unref(time); } static void |