mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 06:46:38 +02:00
api: add info "auto_connect" (closes #1453)
This commit is contained in:
@@ -165,6 +165,7 @@ int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
{
|
||||
int i, auto_connect;
|
||||
char *info_auto_connect;
|
||||
|
||||
weechat_plugin = plugin;
|
||||
|
||||
@@ -217,16 +218,17 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
|
||||
irc_bar_item_init ();
|
||||
|
||||
/* check if auto-connect is enabled */
|
||||
info_auto_connect = weechat_info_get ("auto_connect", NULL);
|
||||
auto_connect = (info_auto_connect && (strcmp (info_auto_connect, "1") == 0)) ?
|
||||
1 : 0;
|
||||
if (info_auto_connect)
|
||||
free (info_auto_connect);
|
||||
|
||||
/* look at arguments */
|
||||
auto_connect = 1;
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if ((weechat_strcasecmp (argv[i], "-a") == 0)
|
||||
|| (weechat_strcasecmp (argv[i], "--no-connect") == 0))
|
||||
{
|
||||
auto_connect = 0;
|
||||
}
|
||||
else if ((weechat_strncasecmp (argv[i], IRC_PLUGIN_NAME, 3) == 0))
|
||||
if ((weechat_strncasecmp (argv[i], IRC_PLUGIN_NAME, 3) == 0))
|
||||
{
|
||||
if (!irc_server_alloc_with_url (argv[i]))
|
||||
{
|
||||
|
||||
@@ -337,6 +337,27 @@ plugin_api_info_weechat_headless_cb (const void *pointer, void *data,
|
||||
return strdup (value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns WeeChat info "auto_connect".
|
||||
*/
|
||||
|
||||
char *
|
||||
plugin_api_info_auto_connect_cb (const void *pointer, void *data,
|
||||
const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
char value[32];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) info_name;
|
||||
(void) arguments;
|
||||
|
||||
snprintf (value, sizeof (value), "%d", weechat_auto_connect);
|
||||
return strdup (value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns WeeChat info "charset_terminal".
|
||||
*/
|
||||
@@ -1764,6 +1785,11 @@ plugin_api_info_init ()
|
||||
hook_info (NULL, "weechat_headless",
|
||||
N_("1 if WeeChat is running headless"),
|
||||
NULL, &plugin_api_info_weechat_headless_cb, NULL, NULL);
|
||||
hook_info (NULL, "auto_connect",
|
||||
N_("1 if automatic connection to servers is enabled, "
|
||||
"0 if it has been disabled by the user (option \"-a\" or "
|
||||
"\"--no-connect\")"),
|
||||
NULL, &plugin_api_info_auto_connect_cb, NULL, NULL);
|
||||
hook_info (NULL, "charset_terminal",
|
||||
N_("terminal charset"),
|
||||
NULL, &plugin_api_info_charset_terminal_cb, NULL, NULL);
|
||||
|
||||
+21
-9
@@ -271,7 +271,8 @@ plugin_check_autoload (const char *filename)
|
||||
void
|
||||
plugin_get_args (struct t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
int *plugin_argc, char ***plugin_argv)
|
||||
int *plugin_argc, char ***plugin_argv,
|
||||
int *no_connect)
|
||||
{
|
||||
int i, temp_argc, length_plugin_name;
|
||||
char **temp_argv;
|
||||
@@ -279,6 +280,8 @@ plugin_get_args (struct t_weechat_plugin *plugin,
|
||||
temp_argc = 0;
|
||||
temp_argv = NULL;
|
||||
|
||||
*no_connect = 0;
|
||||
|
||||
length_plugin_name = strlen (plugin->name);
|
||||
|
||||
if (argc > 0)
|
||||
@@ -289,12 +292,15 @@ plugin_get_args (struct t_weechat_plugin *plugin,
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if ((strcmp (argv[i], "-a") == 0)
|
||||
|| (strcmp (argv[i], "--no-connect") == 0)
|
||||
|| (strcmp (argv[i], "-s") == 0)
|
||||
|| (strcmp (argv[i], "--no-script") == 0)
|
||||
|| ((strncmp (argv[i], plugin->name,
|
||||
length_plugin_name) == 0)
|
||||
&& (argv[i][length_plugin_name] == ':')))
|
||||
|| (strcmp (argv[i], "--no-connect") == 0))
|
||||
{
|
||||
*no_connect = 1;
|
||||
}
|
||||
else if ((strcmp (argv[i], "-s") == 0)
|
||||
|| (strcmp (argv[i], "--no-script") == 0)
|
||||
|| ((strncmp (argv[i], plugin->name,
|
||||
length_plugin_name) == 0)
|
||||
&& (argv[i][length_plugin_name] == ':')))
|
||||
{
|
||||
temp_argv[temp_argc++] = argv[i];
|
||||
}
|
||||
@@ -325,7 +331,7 @@ int
|
||||
plugin_call_init (struct t_weechat_plugin *plugin, int argc, char **argv)
|
||||
{
|
||||
t_weechat_init_func *init_func;
|
||||
int plugin_argc, rc;
|
||||
int plugin_argc, no_connect, rc, old_auto_connect;
|
||||
char **plugin_argv;
|
||||
|
||||
if (plugin->initialized)
|
||||
@@ -337,7 +343,11 @@ plugin_call_init (struct t_weechat_plugin *plugin, int argc, char **argv)
|
||||
return 0;
|
||||
|
||||
/* get arguments for the plugin */
|
||||
plugin_get_args (plugin, argc, argv, &plugin_argc, &plugin_argv);
|
||||
plugin_get_args (plugin, argc, argv,
|
||||
&plugin_argc, &plugin_argv, &no_connect);
|
||||
|
||||
old_auto_connect = weechat_auto_connect;
|
||||
weechat_auto_connect = (no_connect) ? 0 : 1;
|
||||
|
||||
/* init plugin */
|
||||
if (weechat_debug_core >= 1)
|
||||
@@ -362,6 +372,8 @@ plugin_call_init (struct t_weechat_plugin *plugin, int argc, char **argv)
|
||||
plugin->filename);
|
||||
}
|
||||
|
||||
weechat_auto_connect = old_auto_connect;
|
||||
|
||||
if (plugin_argv)
|
||||
free (plugin_argv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user