1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 00:33:13 +02:00

Add info "weechat_upgrading", signal "upgrade_ended", display duration of upgrade

This commit is contained in:
Sebastien Helleu
2010-12-26 12:16:47 +01:00
parent b770f9c8c5
commit 391ca47674
24 changed files with 180 additions and 43 deletions
+7 -7
View File
@@ -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));
}
}
}
+26 -4
View File
@@ -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);
}
+1 -1
View File
@@ -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 */
+18 -15
View File
@@ -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) */
@@ -89,6 +92,17 @@ int weechat_plugin_no_dlclose = 0; /* remove calls to dlclose for libs */
/* (useful when using valgrind) */
/*
* 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
*/
@@ -299,17 +313,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 */
+2 -1
View File
@@ -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;
+7
View File
@@ -322,6 +322,11 @@ plugin_api_info_get_internal (void *data, const char *info_name,
{
return WEECHAT_WEBSITE_DOWNLOAD;
}
else if (string_strcasecmp (info_name, "weechat_upgrading") == 0)
{
snprintf (value, sizeof (value), "%d", weechat_upgrading);
return value;
}
else if (string_strcasecmp (info_name, "charset_terminal") == 0)
{
return weechat_local_charset;
@@ -957,6 +962,8 @@ plugin_api_init ()
&plugin_api_info_get_internal, NULL);
hook_info (NULL, "weechat_site_download", N_("WeeChat site, download page"), NULL,
&plugin_api_info_get_internal, NULL);
hook_info (NULL, "weechat_upgrading", N_("1 if WeeChat is upgrading (command `/upgrade`)"), NULL,
&plugin_api_info_get_internal, NULL);
hook_info (NULL, "charset_terminal", N_("terminal charset"), NULL,
&plugin_api_info_get_internal, NULL);
hook_info (NULL, "charset_internal", N_("WeeChat internal charset"), NULL,