From d4ca32832ec330a794e0bbe25e6afb01c2bf4319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 21 Aug 2024 20:37:00 +0200 Subject: [PATCH] relay: redefine bar item "input_prompt" to display the connection status on remote buffers, if different from "connected" --- CHANGELOG.md | 4 + doc/en/weechat_dev.en.adoc | 1 + doc/fr/weechat_dev.fr.adoc | 1 + doc/ja/weechat_dev.ja.adoc | 2 + doc/sr/weechat_dev.sr.adoc | 2 + src/plugins/relay/CMakeLists.txt | 1 + src/plugins/relay/relay-bar-item.c | 90 +++++++++++++++++++ src/plugins/relay/relay-bar-item.h | 25 ++++++ src/plugins/relay/relay-remote.c | 1 + src/plugins/relay/relay.c | 3 + tests/CMakeLists.txt | 1 + .../plugins/relay/test-relay-bar-item.cpp | 54 +++++++++++ 12 files changed, 185 insertions(+) create mode 100644 src/plugins/relay/relay-bar-item.c create mode 100644 src/plugins/relay/relay-bar-item.h create mode 100644 tests/unit/plugins/relay/test-relay-bar-item.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index b617bf063..5091764a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Version 4.5.0 (under dev) +### Added + +- relay: redefine bar item "input_prompt" to display the connection status on remote buffers, if different from "connected" + ### Fixed - lua: fix compilation on Fedora with Lua < 5.2.0 ([#2173](https://github.com/weechat/weechat/issues/2173), [#2174](https://github.com/weechat/weechat/issues/2174)) diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 482935068..49a347c7c 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -326,6 +326,7 @@ WeeChat "core" is located in following directories: |    relay/ | Relay plugin (IRC proxy and relay for remote interfaces). |       relay.c | Main relay functions. |       relay-auth.c | Clients authentication. +|       relay-bar-item.c | Relay bar items. |       relay-buffer.c | Relay buffer. |       relay-client.c | Clients of relay. |       relay-command.c | Relay commands. diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index d43ef67a6..56bc0e12b 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -328,6 +328,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : |    relay/ | Extension Relay (proxy IRC et relai pour des interfaces distantes). |       relay.c | Fonctions principales de Relay. |       relay-auth.c | Authentification des clients. +|       relay-bar-item.c | Objets de barre Relay. |       relay-buffer.c | Tampon Relay. |       relay-client.c | Clients du relai. |       relay-command.c | Commandes de Relay. diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index 3c170b9ed..f1a7520a8 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -347,6 +347,8 @@ WeeChat "core" は以下のディレクトリに配置されています: |       relay.c | relay の主要関数 // TRANSLATION MISSING |       relay-auth.c | Clients authentification. +// TRANSLATION MISSING +|       relay-bar-item.c | Relay bar items. |       relay-buffer.c | relay バッファ |       relay-client.c | relay クライアント |       relay-command.c | relay コマンド diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc index e875eb1e0..1d6750a7a 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -328,6 +328,8 @@ WeeChat „језгро” се налази у следећим директо |    relay/ | Релеј додатак (IRC прокси и релеј за удаљене интерфејсе). |       relay.c | Главне релеј функције. |       relay-auth.c | Аутентификација клијената. +// TRANSLATION MISSING +|       relay-bar-item.c | Relay bar items. |       relay-buffer.c | Релеј бафер. |       relay-client.c | Клијенти релеја. |       relay-command.c | Релеј команде. diff --git a/src/plugins/relay/CMakeLists.txt b/src/plugins/relay/CMakeLists.txt index 22853b555..5a25b45af 100644 --- a/src/plugins/relay/CMakeLists.txt +++ b/src/plugins/relay/CMakeLists.txt @@ -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 diff --git a/src/plugins/relay/relay-bar-item.c b/src/plugins/relay/relay-bar-item.c new file mode 100644 index 000000000..b5b429761 --- /dev/null +++ b/src/plugins/relay/relay-bar-item.c @@ -0,0 +1,90 @@ +/* + * relay-bar-item.c - bar items for relay plugin + * + * Copyright (C) 2024 Sébastien Helleu + * + * 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 . + */ + +#include +#include +#include + +#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); +} diff --git a/src/plugins/relay/relay-bar-item.h b/src/plugins/relay/relay-bar-item.h new file mode 100644 index 000000000..a71ba0b86 --- /dev/null +++ b/src/plugins/relay/relay-bar-item.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 Sébastien Helleu + * + * 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 . + */ + +#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 */ diff --git a/src/plugins/relay/relay-remote.c b/src/plugins/relay/relay-remote.c index 5a2e956ae..b899dafe2 100644 --- a/src/plugins/relay/relay-remote.c +++ b/src/plugins/relay/relay-remote.c @@ -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"); } /* diff --git a/src/plugins/relay/relay.c b/src/plugins/relay/relay.c index 57501dfc1..e530906c9 100644 --- a/src/plugins/relay/relay.c +++ b/src/plugins/relay/relay.c @@ -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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8eb04e537..d6842e417 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -158,6 +158,7 @@ endif() if (ENABLE_RELAY) list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC unit/plugins/relay/test-relay-auth.cpp + unit/plugins/relay/test-relay-bar-item.cpp unit/plugins/relay/test-relay-http.cpp unit/plugins/relay/test-relay-raw.cpp unit/plugins/relay/test-relay-remote.cpp diff --git a/tests/unit/plugins/relay/test-relay-bar-item.cpp b/tests/unit/plugins/relay/test-relay-bar-item.cpp new file mode 100644 index 000000000..2e4755cca --- /dev/null +++ b/tests/unit/plugins/relay/test-relay-bar-item.cpp @@ -0,0 +1,54 @@ +/* + * test-relay-bar-item.cpp - test relay bar item functions + * + * Copyright (C) 2024 Sébastien Helleu + * + * 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 . + */ + +#include "CppUTest/TestHarness.h" + +extern "C" +{ +#include +#include +#include "src/plugins/relay/relay.h" +#include "src/plugins/relay/relay-bar-item.h" +} + +TEST_GROUP(RelayBarItem) +{ +}; + +/* + * Tests functions: + * relay_bar_item_input_prompt + */ + +TEST(RelayBarItem, InputPrompt) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * relay_bar_item_init + */ + +TEST(RelayBarItem, Init) +{ + /* TODO: write tests */ +}