1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Removed get_time from common.c

Uses GDateTime instead
This commit is contained in:
James Booth 2012-08-26 22:36:00 +01:00
parent 6f2870ed7d
commit 51e5156fab
4 changed files with 17 additions and 31 deletions

View File

@ -48,18 +48,6 @@ create_dir(char *name)
e = mkdir(name, S_IRWXU); 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 * char *
str_replace(const char *string, const char *substr, str_replace(const char *string, const char *substr,
const char *replacement) const char *replacement)

View File

@ -37,7 +37,6 @@
void p_slist_free_full(GSList *items, GDestroyNotify free_func); void p_slist_free_full(GSList *items, GDestroyNotify free_func);
void create_dir(char *name); void create_dir(char *name);
void get_time(char *thetime);
char * str_replace(const char *string, const char *substr, char * str_replace(const char *string, const char *substr,
const char *replacement); const char *replacement);
int str_contains(char str[], int size, char ch); int str_contains(char str[], int size, char ch);

View File

@ -26,7 +26,6 @@
#include <ncurses.h> #include <ncurses.h>
#include "ui.h" #include "ui.h"
#include "common.h"
static WINDOW *status_bar; static WINDOW *status_bar;
static char *message = NULL; static char *message = NULL;
@ -34,7 +33,7 @@ static char _active[29] = "[ ][ ][ ][ ][ ][ ][ ][ ][ ]";
static int is_active[9]; static int is_active[9];
static int is_new[9]; static int is_new[9];
static int dirty; static int dirty;
static char curr_time[80]; static GDateTime *last_time;
static void _status_bar_update_time(void); static void _status_bar_update_time(void);
@ -55,19 +54,21 @@ create_status_bar(void)
mvwprintw(status_bar, 0, cols - 29, _active); mvwprintw(status_bar, 0, cols - 29, _active);
wattroff(status_bar, COLOUR_BAR_DRAW); wattroff(status_bar, COLOUR_BAR_DRAW);
get_time(curr_time); last_time = g_date_time_new_now_local();
dirty = TRUE; dirty = TRUE;
} }
void void
status_bar_refresh(void) status_bar_refresh(void)
{ {
char new_time[80]; GDateTime *now_time = g_date_time_new_now_local();
get_time(new_time); GTimeSpan elapsed = g_date_time_difference(now_time, last_time);
if (strcmp(new_time, curr_time) != 0) { if (elapsed >= 60000000) {
dirty = TRUE; dirty = TRUE;
strcpy(curr_time, new_time); g_date_time_unref(now_time);
last_time = g_date_time_new_now_local();
} }
if (dirty) { if (dirty) {
@ -102,7 +103,7 @@ status_bar_resize(void)
if (message != NULL) if (message != NULL)
mvwprintw(status_bar, 0, 9, message); mvwprintw(status_bar, 0, 9, message);
get_time(curr_time); last_time = g_date_time_new_now_local();
dirty = TRUE; dirty = TRUE;
} }
@ -216,18 +217,17 @@ status_bar_clear(void)
static void static void
_status_bar_update_time(void) _status_bar_update_time(void)
{ {
char bar_time[6]; gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
char tstmp[80];
get_time(tstmp);
sprintf(bar_time, "%s", tstmp);
wattron(status_bar, COLOUR_BAR_DRAW); wattron(status_bar, COLOUR_BAR_DRAW);
mvwaddch(status_bar, 0, 1, '['); mvwaddch(status_bar, 0, 1, '[');
wattroff(status_bar, COLOUR_BAR_DRAW); 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); wattron(status_bar, COLOUR_BAR_DRAW);
mvwaddch(status_bar, 0, 7, ']'); mvwaddch(status_bar, 0, 7, ']');
wattroff(status_bar, COLOUR_BAR_DRAW); wattroff(status_bar, COLOUR_BAR_DRAW);
free(date_fmt);
dirty = TRUE; dirty = TRUE;
} }

View File

@ -31,7 +31,6 @@
#include <ncurses.h> #include <ncurses.h>
#include "command.h" #include "command.h"
#include "common.h"
#include "contact.h" #include "contact.h"
#include "log.h" #include "log.h"
#include "preferences.h" #include "preferences.h"
@ -509,7 +508,6 @@ cons_help(void)
cons_show("Navigation:"); cons_show("Navigation:");
cons_show(""); cons_show("");
cons_show("F1 : This console window."); 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("F2-F10 : Chat windows.");
cons_show("UP, DOWN : Navigate input history."); cons_show("UP, DOWN : Navigate input history.");
cons_show("LEFT, RIGHT, HOME, END : Edit current input."); cons_show("LEFT, RIGHT, HOME, END : Edit current input.");
@ -759,9 +757,10 @@ _win_switch_if_active(const int i)
static void static void
_win_show_time(WINDOW *win) _win_show_time(WINDOW *win)
{ {
char tstmp[80]; GDateTime *time = g_date_time_new_now_local();
get_time(tstmp); gchar *date_fmt = g_date_time_format(time, "%H:%M");
wprintw(win, "%s - ", tstmp); wprintw(win, "%s - ", date_fmt);
g_date_time_unref(time);
} }
static void static void