mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 08:13:14 +02:00
relay: redefine bar item "input_prompt" to display the connection status on remote buffers, if different from "connected"
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
set(RELAY_SRC
|
||||
relay.c relay.h
|
||||
relay-auth.c relay-auth.h
|
||||
relay-bar-item.c relay-bar-item.h
|
||||
relay-buffer.c relay-buffer.h
|
||||
relay-client.c relay-client.h
|
||||
relay-command.c relay-command.h
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* relay-bar-item.c - bar items for relay plugin
|
||||
*
|
||||
* Copyright (C) 2024 Sébastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "relay.h"
|
||||
#include "relay-config.h"
|
||||
#include "relay-remote.h"
|
||||
|
||||
|
||||
/*
|
||||
* Returns content of bar item "input_prompt".
|
||||
*/
|
||||
|
||||
char *
|
||||
relay_bar_item_input_prompt (const void *pointer, void *data,
|
||||
struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_hashtable *extra_info)
|
||||
{
|
||||
char str_status[512], *input_prompt;
|
||||
const char *ptr_input_prompt;
|
||||
struct t_relay_remote *ptr_remote;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) item;
|
||||
(void) window;
|
||||
(void) extra_info;
|
||||
|
||||
if (!buffer)
|
||||
return NULL;
|
||||
|
||||
str_status[0] = '\0';
|
||||
ptr_remote = relay_remote_search (weechat_buffer_get_string (buffer, "localvar_relay_remote"));
|
||||
if (ptr_remote && (ptr_remote->status != RELAY_STATUS_CONNECTED))
|
||||
{
|
||||
snprintf (str_status, sizeof (str_status),
|
||||
"%s<%s>",
|
||||
weechat_color (weechat_config_string (relay_config_color_status[ptr_remote->status])),
|
||||
_(relay_status_string[ptr_remote->status]));
|
||||
}
|
||||
|
||||
ptr_input_prompt = weechat_buffer_get_string (buffer, "input_prompt");
|
||||
if (!ptr_input_prompt && !str_status[0])
|
||||
return NULL;
|
||||
|
||||
if (weechat_asprintf (
|
||||
&input_prompt, "%s%s%s",
|
||||
(ptr_input_prompt) ? ptr_input_prompt : "",
|
||||
(ptr_input_prompt && ptr_input_prompt[0] && str_status[0]) ? " " : "",
|
||||
str_status) >= 0)
|
||||
return input_prompt;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes relay bar items.
|
||||
*/
|
||||
|
||||
void
|
||||
relay_bar_item_init ()
|
||||
{
|
||||
weechat_bar_item_new ("input_prompt",
|
||||
&relay_bar_item_input_prompt, NULL, NULL);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Sébastien Helleu <flashcode@flashtux.org>
|
||||
*
|
||||
* This file is part of WeeChat, the extensible chat client.
|
||||
*
|
||||
* WeeChat is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WEECHAT_PLUGIN_RELAY_BAR_ITEM_H
|
||||
#define WEECHAT_PLUGIN_RELAY_BAR_ITEM_H
|
||||
|
||||
extern void relay_bar_item_init ();
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_RELAY_BAR_ITEM_H */
|
||||
@@ -650,6 +650,7 @@ relay_remote_set_status (struct t_relay_remote *remote,
|
||||
remote->status = status;
|
||||
|
||||
relay_remote_send_signal (remote);
|
||||
weechat_bar_item_update ("input_prompt");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "relay.h"
|
||||
#include "relay-bar-item.h"
|
||||
#include "relay-buffer.h"
|
||||
#include "relay-client.h"
|
||||
#include "relay-command.h"
|
||||
@@ -297,6 +298,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
/* hook completions */
|
||||
relay_completion_init ();
|
||||
|
||||
relay_bar_item_init ();
|
||||
|
||||
weechat_hook_signal ("upgrade", &relay_signal_upgrade_cb, NULL, NULL);
|
||||
weechat_hook_signal ("debug_dump", &relay_debug_dump_cb, NULL, NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user