diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-26 12:16:47 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-26 12:16:47 +0100 |
commit | 391ca476742d17d9275ef4e02e9f7cce271697d4 (patch) | |
tree | a598c2a7261a787b686f81468e80e07d8942672a /src/core | |
parent | b770f9c8c52e8af0d42ce94f25ab3d45d3f9b86b (diff) | |
download | weechat-391ca476742d17d9275ef4e02e9f7cce271697d4.zip |
Add info "weechat_upgrading", signal "upgrade_ended", display duration of upgrade
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-command.c | 14 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 30 | ||||
-rw-r--r-- | src/core/wee-upgrade.h | 2 | ||||
-rw-r--r-- | src/core/weechat.c | 33 | ||||
-rw-r--r-- | src/core/weechat.h | 3 |
5 files changed, 54 insertions, 28 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 95612d9a2..dd1d3c95b 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -3865,7 +3865,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer, (void) data; (void) argv_eol; - running_time = time (NULL) - weechat_start_time; + running_time = time (NULL) - weechat_first_start_time; day = running_time / (60 * 60 * 24); hour = (running_time % (60 * 60 * 24)) / (60 * 60); min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; @@ -3880,7 +3880,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer, hour, min, sec, - ctime (&weechat_start_time)); + ctime (&weechat_first_start_time)); string[strlen (string) - 1] = '\0'; input_data (buffer, string); } @@ -3894,7 +3894,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer, hour, min, sec, - util_get_time_string (&weechat_start_time)); + util_get_time_string (&weechat_first_start_time)); input_data (buffer, string); } else @@ -3918,7 +3918,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer, sec, GUI_COLOR(GUI_COLOR_CHAT), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - util_get_time_string (&weechat_start_time)); + util_get_time_string (&weechat_first_start_time)); } return WEECHAT_RC_OK; @@ -3953,7 +3953,7 @@ command_version_display (struct t_gui_buffer *buffer, weechat_upgrade_count, /* TRANSLATORS: text is: "upgraded xx times" */ NG_("time", "times", weechat_upgrade_count), - util_get_time_string (&weechat_start_time)); + util_get_time_string (&weechat_first_start_time)); input_data (buffer, string); } } @@ -3972,7 +3972,7 @@ command_version_display (struct t_gui_buffer *buffer, "Upgraded %d %s, first start: %s", weechat_upgrade_count, (weechat_upgrade_count > 1) ? "times" : "time", - ctime (&weechat_start_time)); + ctime (&weechat_first_start_time)); string[strlen (string) - 1] = '\0'; input_data (buffer, string); } @@ -3996,7 +3996,7 @@ command_version_display (struct t_gui_buffer *buffer, weechat_upgrade_count, /* TRANSLATORS: text is: "upgraded xx times" */ NG_("time", "times", weechat_upgrade_count), - util_get_time_string (&weechat_start_time)); + util_get_time_string (&weechat_first_start_time)); } } } diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 9b3b4e461..c786c66f3 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -29,9 +29,11 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <sys/time.h> #include "weechat.h" #include "wee-upgrade.h" +#include "wee-hook.h" #include "wee-infolist.h" #include "wee-string.h" #include "wee-util.h" @@ -207,7 +209,7 @@ upgrade_weechat_save_uptime (struct t_upgrade_file *upgrade_file) infolist_free (ptr_infolist); return 0; } - if (!infolist_new_var_time (ptr_item, "start_time", weechat_start_time)) + if (!infolist_new_var_time (ptr_item, "start_time", weechat_first_start_time)) { infolist_free (ptr_infolist); return 0; @@ -539,7 +541,7 @@ upgrade_weechat_read_cb (void *data, } break; case UPGRADE_WEECHAT_TYPE_UPTIME: - weechat_start_time = infolist_time (infolist, "start_time"); + weechat_first_start_time = infolist_time (infolist, "start_time"); weechat_upgrade_count = infolist_integer (infolist, "upgrade_count"); break; case UPGRADE_WEECHAT_TYPE_HOTLIST: @@ -628,14 +630,34 @@ upgrade_weechat_remove_file_cb (void *data, const char *filename) } /* - * upgrade_weechat_remove_files: remove *.upgrade files after upgrade + * upgrade_weechat_end: remove *.upgrade files after upgrade and send signal + * "weechat_upgrade_done" */ void -upgrade_weechat_remove_files () +upgrade_weechat_end () { + struct timeval tv_now; + long time_diff; + + /* remove .upgrade files */ util_exec_on_files (weechat_home, 0, NULL, &upgrade_weechat_remove_file_cb); + + /* display message for end of /upgrade with duration */ + gettimeofday (&tv_now, NULL); + time_diff = util_timeval_diff (&weechat_current_start_timeval, &tv_now); + gui_chat_printf (NULL, + /* TRANSLATORS: "%s" is translation of "second" or "seconds" */ + _("Upgrade done (%.02f %s)"), + ((float)time_diff) / 1000, + NG_("second", "seconds", time_diff / 1000)); + + /* upgrading ended */ + weechat_upgrading = 0; + + /* send signal for end of /upgrade */ + hook_signal_send ("upgrade_ended", WEECHAT_HOOK_SIGNAL_STRING, NULL); } diff --git a/src/core/wee-upgrade.h b/src/core/wee-upgrade.h index 3c96779b2..df40d0062 100644 --- a/src/core/wee-upgrade.h +++ b/src/core/wee-upgrade.h @@ -38,6 +38,6 @@ enum t_upgrade_weechat_type int upgrade_weechat_save (); int upgrade_weechat_load (); -void upgrade_weechat_remove_files (); +void upgrade_weechat_end (); #endif /* __WEECHAT_UPGRADE_H */ diff --git a/src/core/weechat.c b/src/core/weechat.c index 8d60ba4a0..0738a7288 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -45,6 +45,7 @@ #include <stdio.h> #include <string.h> #include <sys/stat.h> +#include <sys/time.h> #include <time.h> #include <signal.h> @@ -77,8 +78,10 @@ int weechat_debug_core = 0; /* debug level for core */ char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0])*/ int weechat_upgrading = 0; /* =1 if WeeChat is upgrading */ -time_t weechat_start_time = 0; /* start time (used by /uptime cmd) */ +time_t weechat_first_start_time = 0; /* start time (used by /uptime cmd) */ int weechat_upgrade_count = 0; /* number of /upgrade done */ +struct timeval weechat_current_start_timeval; /* start time used to display */ + /* duration of /upgrade */ int weechat_quit = 0; /* = 1 if quit request from user */ int weechat_sigsegv = 0; /* SIGSEGV received? */ char *weechat_home = NULL; /* home dir. (default: ~/.weechat) */ @@ -90,6 +93,17 @@ int weechat_plugin_no_dlclose = 0; /* remove calls to dlclose for libs */ /* + * weechat_init_vars: initialize some variables + */ + +void +weechat_init_vars () +{ + weechat_first_start_time = time (NULL); + gettimeofday (&weechat_current_start_timeval, NULL); +} + +/* * weechat_display_usage: display WeeChat usage */ @@ -300,17 +314,6 @@ weechat_create_home_dirs () } /* - * weechat_init_vars: initialize some variables - */ - -void -weechat_init_vars () -{ - /* start time, used by /uptime command */ - weechat_start_time = time (NULL); -} - -/* * weechat_welcome_message: display WeeChat welcome message - yeah! */ @@ -373,6 +376,8 @@ weechat_shutdown (int return_code, int crash) int main (int argc, char *argv[]) { + weechat_init_vars (); /* initialize some variables */ + setlocale (LC_ALL, ""); /* initialize gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); @@ -395,7 +400,6 @@ main (int argc, char *argv[]) hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_main_pre_init (&argc, &argv); /* pre-initiliaze interface */ - weechat_init_vars (); /* initialize some variables */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_keyboard_init (); /* init keyboard */ @@ -420,8 +424,7 @@ main (int argc, char *argv[]) command_startup (1); /* command executed after plugins */ gui_layout_window_apply (gui_layout_windows, -1); /* apply saved layout */ if (weechat_upgrading) - upgrade_weechat_remove_files ();/* remove .upgrade files */ - weechat_upgrading = 0; + upgrade_weechat_end (); /* remove .upgrade files + signal */ gui_main_loop (); /* WeeChat main loop */ diff --git a/src/core/weechat.h b/src/core/weechat.h index 2328b377c..f7abe407e 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -103,7 +103,8 @@ extern int weechat_debug_core; extern char *weechat_argv0; extern int weechat_upgrading; -extern time_t weechat_start_time; +extern time_t weechat_first_start_time; +extern struct timeval weechat_current_start_timeval; extern int weechat_upgrade_count; extern int weechat_quit; extern char *weechat_home; |