From 1f5c95d9e92360bb72ad415aca6698af8774b094 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Thu, 17 Jun 2021 15:22:40 -0500 Subject: Always pass a valid URI to gtk_show_uri() This can fix issues like a crash when invalid characters get passed through. --- src/fe-gtk/fe-gtk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index ee3e847c..b9945002 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -1071,7 +1071,9 @@ fe_open_url_inner (const char *url) #elif defined(__APPLE__) osx_show_uri (url); #else - gtk_show_uri (NULL, url, GDK_CURRENT_TIME, NULL); + char *escaped_url = g_uri_escape_string (url, G_URI_RESERVED_CHARS_GENERIC_DELIMITERS, FALSE); + gtk_show_uri (NULL, escaped_url, GDK_CURRENT_TIME, NULL); + g_free (escaped_url); #endif } -- cgit 1.4.1 From 747a52aae8806a9072a23ea68212767f352ac431 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 23 May 2021 06:58:18 +0100 Subject: Default new servers to use TLS if built with OpenSSL. --- src/common/outbound.c | 2 +- src/common/servlist.c | 3 +++ src/fe-gtk/servlistgui.c | 14 ++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/common/outbound.c b/src/common/outbound.c index 614aad38..e8d35c96 100644 --- a/src/common/outbound.c +++ b/src/common/outbound.c @@ -3930,7 +3930,7 @@ cmd_voice (struct session *sess, char *tbuf, char *word[], char *word_eol[]) const struct commands xc_cmds[] = { {"ADDBUTTON", cmd_addbutton, 0, 0, 1, N_("ADDBUTTON , adds a button under the user-list")}, - {"ADDSERVER", cmd_addserver, 0, 0, 1, N_("ADDSERVER , adds a new network with a new server to the network list")}, + {"ADDSERVER", cmd_addserver, 0, 0, 1, N_("ADDSERVER , adds a new network with a new server to the network list")}, {"ALLCHAN", cmd_allchannels, 0, 0, 1, N_("ALLCHAN , sends a command to all channels you're in")}, {"ALLCHANL", cmd_allchannelslocal, 0, 0, 1, diff --git a/src/common/servlist.c b/src/common/servlist.c index 79a5694b..45bc4999 100644 --- a/src/common/servlist.c +++ b/src/common/servlist.c @@ -947,6 +947,9 @@ servlist_net_add (char *name, char *comment, int prepend) net = g_new0 (ircnet, 1); net->name = g_strdup (name); net->flags = FLAG_CYCLE | FLAG_USE_GLOBAL | FLAG_USE_PROXY; +#ifdef USE_OPENSSL + net->flags |= FLAG_USE_SSL; +#endif if (prepend) network_list = g_slist_prepend (network_list, net); diff --git a/src/fe-gtk/servlistgui.c b/src/fe-gtk/servlistgui.c index b22330ac..0220525d 100644 --- a/src/fe-gtk/servlistgui.c +++ b/src/fe-gtk/servlistgui.c @@ -39,6 +39,12 @@ #define SERVLIST_X_PADDING 4 /* horizontal paddig in the network editor */ #define SERVLIST_Y_PADDING 0 /* vertical padding in the network editor */ +#ifdef USE_OPENSSL +# define DEFAULT_SERVER "irc.example.com/6697" +#else +# define DEFAULT_SERVER "irc.example.com/6667" +#endif + /* servlistgui.c globals */ static GtkWidget *serverlist_win = NULL; static GtkWidget *networks_tree; /* network TreeView */ @@ -299,7 +305,7 @@ servlist_networks_populate_ (GtkWidget *treeview, GSList *netlist, gboolean favo if (!netlist) { net = servlist_net_add (_("New Network"), "", FALSE); - servlist_server_add (net, "newserver/6667"); + servlist_server_add (net, DEFAULT_SERVER); netlist = network_list; } store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); @@ -434,10 +440,10 @@ servlist_addserver (void) return; store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (edit_trees[SERVER_TREE]))); - servlist_server_add (selected_net, "newserver/6667"); + servlist_server_add (selected_net, DEFAULT_SERVER); gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, "newserver/6667", 1, TRUE, -1); + gtk_list_store_set (store, &iter, 0, DEFAULT_SERVER, 1, TRUE, -1); /* select this server */ servlist_select_and_show (GTK_TREE_VIEW (edit_trees[SERVER_TREE]), &iter, store); @@ -498,7 +504,7 @@ servlist_addnet_cb (GtkWidget *item, GtkTreeView *treeview) net = servlist_net_add (_("New Network"), "", TRUE); net->encoding = g_strdup (IRC_DEFAULT_CHARSET); - servlist_server_add (net, "newserver/6667"); + servlist_server_add (net, DEFAULT_SERVER); store = (GtkListStore *)gtk_tree_view_get_model (treeview); gtk_list_store_prepend (store, &iter); -- cgit 1.4.1 From 623d93c6f14679ef04fb35b52cde40a08e377444 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 30 May 2021 18:45:22 +0100 Subject: Switch back to using newserver as the default server name. --- src/fe-gtk/servlistgui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/servlistgui.c b/src/fe-gtk/servlistgui.c index 0220525d..edcd4609 100644 --- a/src/fe-gtk/servlistgui.c +++ b/src/fe-gtk/servlistgui.c @@ -40,9 +40,9 @@ #define SERVLIST_Y_PADDING 0 /* vertical padding in the network editor */ #ifdef USE_OPENSSL -# define DEFAULT_SERVER "irc.example.com/6697" +# define DEFAULT_SERVER "newserver/6697" #else -# define DEFAULT_SERVER "irc.example.com/6667" +# define DEFAULT_SERVER "newserver/6667" #endif /* servlistgui.c globals */ -- cgit 1.4.1 From 55e4f1c42e8d1131b01659fad67db5d084780227 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 1 Jun 2021 13:31:38 +0100 Subject: Implement support for strikethrough text. https://defs.ircdocs.horse/info/formatting.html --- src/common/outbound.c | 3 +++ src/common/util.c | 1 + src/fe-gtk/maingui.c | 5 ++++- src/fe-gtk/sexy-spell-entry.c | 20 ++++++++++++++++++++ src/fe-gtk/xtext.c | 17 +++++++++++++++++ src/fe-gtk/xtext.h | 22 ++++++++++++---------- 6 files changed, 57 insertions(+), 11 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/common/outbound.c b/src/common/outbound.c index c39a1d46..70fcd436 100644 --- a/src/common/outbound.c +++ b/src/common/outbound.c @@ -4434,6 +4434,9 @@ check_special_chars (char *cmd, int do_ascii) /* check for %X */ case 'I': buf[i] = '\035'; break; + case 'S': + buf[i] = '\036'; + break; case 'C': buf[i] = '\003'; break; diff --git a/src/common/util.c b/src/common/util.c index 5b5fb23f..fa0783d4 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -329,6 +329,7 @@ strip_color2 (const char *src, int len, char *dst, int flags) case '\026': /*ATTR_REVERSE: */ case '\002': /*ATTR_BOLD: */ case '\037': /*ATTR_UNDERLINE: */ + case '\036': /*ATTR_STRIKETHROUGH: */ case '\035': /*ATTR_ITALICS: */ if (!(flags & STRIP_ATTRIB)) goto pass_char; break; diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c index 4e5baaa0..b77da59b 100644 --- a/src/fe-gtk/maingui.c +++ b/src/fe-gtk/maingui.c @@ -1394,6 +1394,8 @@ mg_color_insert (GtkWidget *item, gpointer userdata) text = "\037"; break; case 102: text = "\035"; break; + case 103: + text = "\036"; break; default: text = "\017"; break; } @@ -1447,7 +1449,8 @@ mg_create_color_menu (GtkWidget *menu, session *sess) mg_markup_item (submenu, _("Bold"), 100); mg_markup_item (submenu, _("Underline"), 101); mg_markup_item (submenu, _("Italic"), 102); - mg_markup_item (submenu, _("Normal"), 103); + mg_markup_item (submenu, _("Strikethrough"), 103); + mg_markup_item (submenu, _("Normal"), 999); subsubmenu = mg_submenu (submenu, _("Colors 0-7")); diff --git a/src/fe-gtk/sexy-spell-entry.c b/src/fe-gtk/sexy-spell-entry.c index dce19b82..04ff0f8a 100644 --- a/src/fe-gtk/sexy-spell-entry.c +++ b/src/fe-gtk/sexy-spell-entry.c @@ -389,6 +389,17 @@ insert_italic (SexySpellEntry *entry, guint start, gboolean toggle) pango_attr_list_change (entry->priv->attr_list, iattr); } +static void +insert_strikethrough (SexySpellEntry *entry, guint start, gboolean toggle) +{ + PangoAttribute *sattr; + + sattr = pango_attr_strikethrough_new (!toggle); + sattr->start_index = start; + sattr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END; + pango_attr_list_change (entry->priv->attr_list, sattr); +} + static void insert_color (SexySpellEntry *entry, guint start, int fgcolor, int bgcolor) { @@ -429,6 +440,7 @@ insert_reset (SexySpellEntry *entry, guint start) insert_bold (entry, start, TRUE); insert_underline (entry, start, TRUE); insert_italic (entry, start, TRUE); + insert_strikethrough (entry, start, TRUE); insert_color (entry, start, -1, -1); } @@ -918,6 +930,7 @@ check_attributes (SexySpellEntry *entry, const char *text, int len) gboolean bold = FALSE; gboolean italic = FALSE; gboolean underline = FALSE; + gboolean strikethrough = FALSE; int parsing_color = 0; char fg_color[3]; char bg_color[3]; @@ -942,6 +955,12 @@ check_attributes (SexySpellEntry *entry, const char *text, int len) italic = !italic; goto check_color; + case ATTR_STRIKETHROUGH: + insert_hiddenchar (entry, i, i + 1); + insert_strikethrough (entry, i, strikethrough); + strikethrough = !strikethrough; + goto check_color; + case ATTR_UNDERLINE: insert_hiddenchar (entry, i, i + 1); insert_underline (entry, i, underline); @@ -954,6 +973,7 @@ check_attributes (SexySpellEntry *entry, const char *text, int len) bold = FALSE; italic = FALSE; underline = FALSE; + strikethrough = FALSE; goto check_color; case ATTR_HIDDEN: diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c index 418bb4da..6a0fccba 100644 --- a/src/fe-gtk/xtext.c +++ b/src/fe-gtk/xtext.c @@ -433,6 +433,7 @@ gtk_xtext_init (GtkXText * xtext) xtext->nc = 0; xtext->pixel_offset = 0; xtext->underline = FALSE; + xtext->strikethrough = FALSE; xtext->hidden = FALSE; xtext->font = NULL; xtext->layout = NULL; @@ -2451,6 +2452,7 @@ gtk_xtext_strip_color (unsigned char *text, int len, unsigned char *outbuf, case ATTR_REVERSE: case ATTR_BOLD: case ATTR_UNDERLINE: + case ATTR_STRIKETHROUGH: case ATTR_ITALICS: xtext_do_chunk (&c); if (*text == ATTR_RESET) @@ -2627,6 +2629,13 @@ gtk_xtext_render_flush (GtkXText * xtext, int x, int y, unsigned char *str, g_object_unref (pix); } + if (xtext->strikethrough) + { + /* pango_attr_strikethrough_new does not render in the custom widget so we need to reinvent the wheel */ + y = dest_y + (xtext->fontsize / 2); + gdk_draw_line (xtext->draw_buf, gc, dest_x, y, dest_x + str_width - 1, y); + } + if (xtext->underline) { dounder: @@ -2651,6 +2660,7 @@ gtk_xtext_reset (GtkXText * xtext, int mark, int attribs) if (attribs) { xtext->underline = FALSE; + xtext->strikethrough = FALSE; xtext->hidden = FALSE; } if (!mark) @@ -2961,6 +2971,12 @@ gtk_xtext_render_str (GtkXText * xtext, int y, textentry * ent, pstr += j + 1; j = 0; break; + case ATTR_STRIKETHROUGH: + RENDER_FLUSH; + xtext->strikethrough = !xtext->strikethrough; + pstr += j + 1; + j = 0; + break; case ATTR_ITALICS: RENDER_FLUSH; *emphasis ^= EMPH_ITAL; @@ -3191,6 +3207,7 @@ find_next_wrap (GtkXText * xtext, textentry * ent, unsigned char *str, case ATTR_REVERSE: case ATTR_BOLD: case ATTR_UNDERLINE: + case ATTR_STRIKETHROUGH: case ATTR_ITALICS: if (*str == ATTR_RESET) emphasis = 0; diff --git a/src/fe-gtk/xtext.h b/src/fe-gtk/xtext.h index 12d6f563..18d769fb 100644 --- a/src/fe-gtk/xtext.h +++ b/src/fe-gtk/xtext.h @@ -29,16 +29,17 @@ #define GTK_IS_XTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_XTEXT)) #define GTK_XTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_XTEXT, GtkXTextClass)) -#define ATTR_BOLD '\002' -#define ATTR_COLOR '\003' -#define ATTR_BLINK '\006' -#define ATTR_BEEP '\007' -#define ATTR_HIDDEN '\010' -#define ATTR_ITALICS2 '\011' -#define ATTR_RESET '\017' -#define ATTR_REVERSE '\026' -#define ATTR_ITALICS '\035' -#define ATTR_UNDERLINE '\037' +#define ATTR_BOLD '\002' +#define ATTR_COLOR '\003' +#define ATTR_BLINK '\006' +#define ATTR_BEEP '\007' +#define ATTR_HIDDEN '\010' +#define ATTR_ITALICS2 '\011' +#define ATTR_RESET '\017' +#define ATTR_REVERSE '\026' +#define ATTR_ITALICS '\035' +#define ATTR_STRIKETHROUGH '\036' +#define ATTR_UNDERLINE '\037' /* these match palette.h */ #define XTEXT_MIRC_COLS 32 @@ -207,6 +208,7 @@ struct _GtkXText /* current text states */ unsigned int underline:1; + unsigned int strikethrough:1; unsigned int hidden:1; /* text parsing states */ -- cgit 1.4.1 From 869a8d7ab335cf785e06450e4ab1ca02a9f5005f Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 10 Jul 2021 11:35:35 -0500 Subject: Fix allowed characters when escaping URIs Closes #2608 --- src/fe-gtk/fe-gtk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index b9945002..4ed4aac9 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -1071,7 +1071,8 @@ fe_open_url_inner (const char *url) #elif defined(__APPLE__) osx_show_uri (url); #else - char *escaped_url = g_uri_escape_string (url, G_URI_RESERVED_CHARS_GENERIC_DELIMITERS, FALSE); + char *escaped_url = g_uri_escape_string (url, G_URI_RESERVED_CHARS_GENERIC_DELIMITERS G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, + FALSE); gtk_show_uri (NULL, escaped_url, GDK_CURRENT_TIME, NULL); g_free (escaped_url); #endif -- cgit 1.4.1 From 25440a07c3b421134b4376d7db3ee4b7ed57ad98 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Mon, 12 Jul 2021 08:38:02 -0500 Subject: Avoid direct use of libproxy Since hexchat already depends on GLib, it's better to use GProxyResolver instead. This might use libproxy, or not, as appropriate. P.S. This removes a memory safety issue because proxy_list is allocated using malloc(), not g_malloc(), and therefore using g_strfreev() is incorrect. The proper way to free the proxy list returned by libproxy is to use px_proxy_factory_free_proxies() (but nobody does that because it was added in libproxy 0.4.16, which is somewhat recent). --- meson.build | 1 - meson_options.txt | 3 --- src/common/hexchat.c | 16 ---------------- src/common/meson.build | 4 ---- src/common/server.c | 26 ++++++++++++++++---------- src/fe-gtk/setup.c | 2 -- 6 files changed, 16 insertions(+), 36 deletions(-) (limited to 'src/fe-gtk') diff --git a/meson.build b/meson.build index 9b33574b..0f5faca8 100644 --- a/meson.build +++ b/meson.build @@ -33,7 +33,6 @@ config_h.set10('ENABLE_NLS', true) # Optional features config_h.set('USE_OPENSSL', get_option('with-ssl')) -config_h.set('USE_LIBPROXY', get_option('with-libproxy')) config_h.set('USE_LIBCANBERRA', get_option('with-libcanberra')) config_h.set('USE_DBUS', get_option('with-dbus')) config_h.set('USE_PLUGIN', get_option('with-plugin')) diff --git a/meson_options.txt b/meson_options.txt index 100a5ee7..ad03d6bc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -13,9 +13,6 @@ option('with-plugin', type: 'boolean', option('with-dbus', type: 'boolean', description: 'Support used for single-instance and scripting interface, Unix only' ) -option('with-libproxy', type: 'boolean', - description: 'Support for getting proxy information, Unix only' -) option('with-libnotify', type: 'boolean', description: 'Support for freedesktop notifications, Unix only' ) diff --git a/src/common/hexchat.c b/src/common/hexchat.c index 8702c63d..3ba7ed6d 100644 --- a/src/common/hexchat.c +++ b/src/common/hexchat.c @@ -57,10 +57,6 @@ #include /* for g_type_init() */ #endif -#ifdef USE_LIBPROXY -#include -#endif - GSList *popup_list = 0; GSList *button_list = 0; GSList *dlgbutton_list = 0; @@ -111,10 +107,6 @@ struct session *current_tab; struct session *current_sess = 0; struct hexchatprefs prefs; -#ifdef USE_LIBPROXY -pxProxyFactory *libproxy_factory; -#endif - /* * Update the priority queue of the "interesting sessions" * (sess_list_by_lastact). @@ -1102,10 +1094,6 @@ main (int argc, char *argv[]) hexchat_remote (); #endif -#ifdef USE_LIBPROXY - libproxy_factory = px_proxy_factory_new (); -#endif - #ifdef WIN32 coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED (coinit_result)) @@ -1148,10 +1136,6 @@ main (int argc, char *argv[]) } #endif -#ifdef USE_LIBPROXY - px_proxy_factory_free (libproxy_factory); -#endif - #ifdef WIN32 WSACleanup (); #endif diff --git a/src/common/meson.build b/src/common/meson.build index 492227b2..09491e84 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -77,10 +77,6 @@ if get_option('with-ssl') common_deps += libssl_dep endif -if get_option('with-libproxy') - common_deps += dependency('libproxy-1.0') -endif - if get_option('with-libcanberra') common_deps += dependency('libcanberra', version: '>= 0.22') endif diff --git a/src/common/server.c b/src/common/server.c index 5c645eb5..4f809fa8 100644 --- a/src/common/server.c +++ b/src/common/server.c @@ -61,10 +61,6 @@ #include "ssl.h" #endif -#ifdef USE_LIBPROXY -#include -#endif - #ifdef USE_OPENSSL /* local variables */ static struct session *g_sess = NULL; @@ -78,9 +74,15 @@ static void server_disconnect (session * sess, int sendquit, int err); static int server_cleanup (server * serv); static void server_connect (server *serv, char *hostname, int port, int no_login); -#ifdef USE_LIBPROXY -extern pxProxyFactory *libproxy_factory; -#endif +static void +write_error (char *message, GError **error) +{ + if (error == NULL || *error == NULL) { + return; + } + g_printerr ("%s: %s\n", message, (*error)->message); + g_clear_error (error); +} /* actually send to the socket. This might do a character translation or send via SSL. server/dcc both use this function. */ @@ -1392,14 +1394,16 @@ server_child (server * serv) if (!serv->dont_use_proxy) /* blocked in serverlist? */ { -#ifdef USE_LIBPROXY if (prefs.hex_net_proxy_type == 5) { char **proxy_list; char *url, *proxy; + GProxyResolver *resolver; + GError *error = NULL; + resolver = g_proxy_resolver_get_default (); url = g_strdup_printf ("irc://%s:%d", hostname, port); - proxy_list = px_proxy_factory_get_proxies (libproxy_factory, url); + proxy_list = g_proxy_resolver_lookup (resolver, url, NULL, &error); if (proxy_list) { /* can use only one */ @@ -1412,6 +1416,8 @@ server_child (server * serv) proxy_type = 3; else if (!strncmp (proxy, "socks", 5)) proxy_type = 2; + } else { + write_error ("Failed to lookup proxy", &error); } if (proxy_type) { @@ -1426,7 +1432,7 @@ server_child (server * serv) g_strfreev (proxy_list); g_free (url); } -#endif + if (prefs.hex_net_proxy_host[0] && prefs.hex_net_proxy_type > 0 && prefs.hex_net_proxy_use != 2) /* proxy is NOT dcc-only */ diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c index 3d003eef..a7e3a15c 100644 --- a/src/fe-gtk/setup.c +++ b/src/fe-gtk/setup.c @@ -614,9 +614,7 @@ static const char *const proxytypes[] = N_("SOCKS4"), N_("SOCKS5"), N_("HTTP"), -#ifdef USE_LIBPROXY N_("Auto"), -#endif NULL }; -- cgit 1.4.1 From cbb0927a7a9113d3b6b772e7b0566752dd54e6dd Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 13 Jul 2021 11:12:22 -0500 Subject: build: Misc cleanup of options Cleanup of option names, use features where applicable, and printing of summary. --- .github/workflows/ubuntu-build.yml | 5 ++-- data/meson.build | 6 ++--- data/misc/meson.build | 12 +++++----- meson.build | 49 +++++++++++++++++++++++++++++++------- meson_options.txt | 33 ++++++++++++++----------- src/common/dbus/meson.build | 2 +- src/common/meson.build | 11 ++++----- src/fe-gtk/meson.build | 6 ++--- src/meson.build | 6 ++--- 9 files changed, 83 insertions(+), 47 deletions(-) (limited to 'src/fe-gtk') diff --git a/.github/workflows/ubuntu-build.yml b/.github/workflows/ubuntu-build.yml index fdeb9b00..cf5a60c1 100644 --- a/.github/workflows/ubuntu-build.yml +++ b/.github/workflows/ubuntu-build.yml @@ -10,10 +10,11 @@ jobs: - name: Install Dependencies run: | sudo apt-get update - sudo apt-get install -y meson libcanberra-dev libdbus-glib-1-dev libglib2.0-dev libgtk2.0-dev libluajit-5.1-dev libnotify-dev libpci-dev libperl-dev libproxy-dev libssl-dev python3-dev python3-cffi mono-devel desktop-file-utils + sudo apt-get install -y python3-setuptools python3-pip libcanberra-dev libdbus-glib-1-dev libglib2.0-dev libgtk2.0-dev libluajit-5.1-dev libnotify-dev libpci-dev libperl-dev libproxy-dev libssl-dev python3-dev python3-cffi mono-devel desktop-file-utils + sudo pip3 install meson - name: Configure - run: meson build -Dwith-text=true -Dwith-theme-manager=true + run: meson build -Dtext=true -Dtheme-manager=true -Dauto_features=enabled - name: Build run: ninja -C build diff --git a/data/meson.build b/data/meson.build index b905c314..6c6b1a9c 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,11 +1,11 @@ -if get_option('with-plugin') +if get_option('plugin') subdir('pkgconfig') endif -if get_option('with-gtk') +if get_option('gtk-frontend') subdir('icons') subdir('misc') subdir('man') -elif get_option('with-theme-manager') +elif get_option('theme-manager') subdir('misc') endif diff --git a/data/misc/meson.build b/data/misc/meson.build index f7f1c27f..2abf3075 100644 --- a/data/misc/meson.build +++ b/data/misc/meson.build @@ -2,8 +2,8 @@ appdir = join_paths(get_option('datadir'), 'applications') metainfodir = join_paths(get_option('datadir'), 'metainfo') desktop_utils = find_program('desktop-file-validate', required: false) -if get_option('with-gtk') - if get_option('with-appdata') +if get_option('gtk-frontend') + if get_option('install-appdata') hexchat_appdata = i18n.merge_file( input: 'io.github.Hexchat.appdata.xml.in', output: 'io.github.Hexchat.appdata.xml', @@ -21,7 +21,7 @@ if get_option('with-gtk') endif desktop_conf = configuration_data() - if get_option('with-dbus') + if dbus_glib_dep.found() desktop_conf.set('exec_command', 'hexchat --existing %U') else desktop_conf.set('exec_command', 'hexchat %U') @@ -49,7 +49,7 @@ if get_option('with-gtk') endif endif -if get_option('with-theme-manager') +if get_option('theme-manager') htm_desktop = i18n.merge_file( input: 'io.github.Hexchat.ThemeManager.desktop.in', output: 'io.github.Hexchat.ThemeManager.desktop', @@ -70,7 +70,7 @@ if get_option('with-theme-manager') ) endif -if get_option('with-plugin') and get_option('with-appdata') +if get_option('plugin') plugin_metainfo = [] # FIXME: These should all get translated somewhere @@ -124,4 +124,4 @@ if get_option('with-plugin') and get_option('with-appdata') install_dir: get_option('install-plugin-metainfo') ? metainfodir : '', ) endforeach -endif \ No newline at end of file +endif diff --git a/meson.build b/meson.build index 0f5faca8..7a29fd23 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('hexchat', 'c', version: '2.14.3', - meson_version: '>= 0.40.0', + meson_version: '>= 0.47.0', default_options: [ 'c_std=gnu89', 'buildtype=debugoptimized', @@ -15,12 +15,18 @@ cc = meson.get_compiler('c') libgio_dep = dependency('gio-2.0', version: '>= 2.34.0') libgmodule_dep = dependency('gmodule-2.0') + +libcanberra_dep = dependency('libcanberra', version: '>= 0.22', + required: get_option('libcanberra')) +dbus_glib_dep = dependency('dbus-glib-1', required: get_option('dbus')) +libnotify_dep = dependency('libnotify', required: get_option('libnotify')) + global_deps = [] if cc.get_id() == 'msvc' libssl_dep = cc.find_library('libeay32') else libssl_dep = dependency('openssl', version: '>= 0.9.8', - required: get_option('with-ssl')) + required: get_option('tls')) endif config_h = configuration_data() @@ -32,10 +38,10 @@ config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), config_h.set10('ENABLE_NLS', true) # Optional features -config_h.set('USE_OPENSSL', get_option('with-ssl')) -config_h.set('USE_LIBCANBERRA', get_option('with-libcanberra')) -config_h.set('USE_DBUS', get_option('with-dbus')) -config_h.set('USE_PLUGIN', get_option('with-plugin')) +config_h.set('USE_OPENSSL', libssl_dep.found()) +config_h.set('USE_LIBCANBERRA', libcanberra_dep.found()) +config_h.set('USE_DBUS', dbus_glib_dep.found()) +config_h.set('USE_PLUGIN', get_option('plugin')) config_h.set('G_DISABLE_SINGLE_INCLUDES', true) config_h.set('GTK_DISABLE_DEPRECATED', true) @@ -152,7 +158,7 @@ endforeach add_project_link_arguments(global_ldflags, language: 'c') subdir('src') -if get_option('with-plugin') +if get_option('plugin') subdir('plugins') endif if cc.get_id() != 'msvc' @@ -160,6 +166,33 @@ if cc.get_id() != 'msvc' subdir('po') # FIXME: build xgettext meson.add_install_script('meson_post_install.py', - '@0@'.format(get_option('with-theme-manager')) + '@0@'.format(get_option('theme-manager')) ) endif + +if meson.version().version_compare('>= 0.53.0') + summary({ + 'prefix': get_option('prefix'), + 'bindir': get_option('bindir'), + 'libdir': get_option('libdir'), + 'datadir': get_option('datadir'), + }, section: 'Directories') + + summary({ + 'TLS (openssl)': libssl_dep.found(), + 'Plugin Support': get_option('plugin'), + 'DBus Support': dbus_glib_dep.found(), + 'libnotify': libnotify_dep.found(), + 'libcanberra': libcanberra_dep.found(), + }, section: 'Features') + + summary({ + 'Lua': get_option('with-lua'), + 'Python': get_option('with-python'), + 'Perl': get_option('with-perl'), + 'Perl Legacy API': get_option('with-perl-legacy-api'), + 'FiSH': get_option('with-fishlim'), + 'Sysinfo': get_option('with-sysinfo'), + 'DCC Checksum': get_option('with-checksum'), + }, section: 'Plugins') +endif diff --git a/meson_options.txt b/meson_options.txt index ad03d6bc..58a8012a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,33 +1,41 @@ -option('with-gtk', type: 'boolean', +# Applications +option('gtk-frontend', type: 'boolean', description: 'Main graphical interface' ) -option('with-text', type: 'boolean', value: false, +option('text-frontend', type: 'boolean', value: false, description: 'Text interface (not generally useful)' ) -option('with-ssl', type: 'boolean', +option('theme-manager', type: 'boolean', value: false, + description: 'Utility to help manage themes, requires mono/.net' +) + +# Features +option('tls', type: 'feature', value: 'enabled', description: 'Support for TLS connections, requires openssl' ) -option('with-plugin', type: 'boolean', +option('plugin', type: 'boolean', description: 'Support for loadable plugins' ) -option('with-dbus', type: 'boolean', +option('dbus', type: 'feature', value: 'auto', description: 'Support used for single-instance and scripting interface, Unix only' ) -option('with-libnotify', type: 'boolean', +option('libnotify', type: 'feature', value: 'auto', description: 'Support for freedesktop notifications, Unix only' ) -option('with-libcanberra', type: 'boolean', +option('libcanberra', type: 'feature', value: 'auto', description: 'Support for sound alerts, Unix only' ) -option('with-theme-manager', type: 'boolean', value: false, - description: 'Utility to help manage themes, requires mono/.net' -) + +# Install options option('dbus-service-use-appid', type: 'boolean', value: false, description: 'Rename dbus service to match app-id, required for Flatpak' ) -option('with-appdata', type: 'boolean', +option('install-appdata', type: 'boolean', description: 'Install appdata files for app stores' ) +option('install-plugin-metainfo', type: 'boolean', value: false, + description: 'Installs metainfo files for enabled plugins, useful when distros create split packages' +) # Plugins option('with-checksum', type: 'boolean', @@ -57,9 +65,6 @@ option('with-upd', type: 'boolean', option('with-winamp', type: 'boolean', description: 'Winamp plugin, Windows only' ) -option('install-plugin-metainfo', type: 'boolean', value: false, - description: 'Installs metainfo files for enabled plugins, useful when distros create split packages' -) option('with-perl-legacy-api', type: 'boolean', value: false, description: 'Enables the legacy IRC perl module for compatibility with old scripts' ) diff --git a/src/common/dbus/meson.build b/src/common/dbus/meson.build index 69066be0..856bbe55 100644 --- a/src/common/dbus/meson.build +++ b/src/common/dbus/meson.build @@ -1,5 +1,5 @@ dbus_deps = [ - dependency('dbus-glib-1') + dbus_glib_dep ] dbus_sources = [ diff --git a/src/common/meson.build b/src/common/meson.build index 09491e84..6ca0f20c 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -28,6 +28,7 @@ common_sysinfo_deps = [] common_deps = [ libgio_dep, + libcanberra_dep, ] + global_deps common_includes = [ @@ -72,22 +73,18 @@ textevents = custom_target('textevents', # SIGACTION # HAVE_GTK_MAC -if get_option('with-ssl') +if libssl_dep.found() common_sources += 'ssl.c' common_deps += libssl_dep endif -if get_option('with-libcanberra') - common_deps += dependency('libcanberra', version: '>= 0.22') -endif - -if get_option('with-dbus') +if dbus_glib_dep.found() subdir('dbus') common_deps += hexchat_dbus_dep common_includes += include_directories('dbus') endif -if get_option('with-plugin') +if get_option('plugin') common_deps += libgmodule_dep install_headers('hexchat-plugin.h') endif diff --git a/src/fe-gtk/meson.build b/src/fe-gtk/meson.build index 3dfc7427..020d2631 100644 --- a/src/fe-gtk/meson.build +++ b/src/fe-gtk/meson.build @@ -43,9 +43,9 @@ hexchat_gtk_cflags = [] hexchat_gtk_ldflags = [] -if get_option('with-libnotify') +if libnotify_dep.found() hexchat_gtk_sources += 'notifications/notification-libnotify.c' - hexchat_gtk_deps += dependency('libnotify') + hexchat_gtk_deps += libnotify_dep elif false # TODO HAVE_GTK_MAC elif host_machine.system() == 'windows' hexchat_gtk_sources += 'notifications/notification-windows.c' @@ -69,7 +69,7 @@ if iso_codes.found() join_paths(iso_codes_prefix, 'share/locale')) endif -if get_option('with-plugin') +if get_option('plugin') hexchat_gtk_sources += 'plugingui.c' endif diff --git a/src/meson.build b/src/meson.build index ff2c8871..23453ec1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,13 +1,13 @@ subdir('common') -if get_option('with-gtk') +if get_option('gtk-frontend') subdir('fe-gtk') endif -if get_option('with-text') +if get_option('text-frontend') subdir('fe-text') endif -if get_option('with-theme-manager') +if get_option('theme-manager') subdir('htm') endif -- cgit 1.4.1 From c144d0468b5643cafd702000aee65eef8c5c1565 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 13 Jul 2021 12:24:19 -0500 Subject: Remove libnotify dependency Instead just talk directly to the service. This fixes *sending* a notification being blocking IO. --- .github/workflows/ubuntu-build.yml | 2 +- meson.build | 2 - meson_options.txt | 3 - src/fe-gtk/meson.build | 8 +- .../notifications/notification-freedesktop.c | 147 +++++++++++++++++++++ src/fe-gtk/notifications/notification-libnotify.c | 81 ------------ 6 files changed, 150 insertions(+), 93 deletions(-) create mode 100644 src/fe-gtk/notifications/notification-freedesktop.c delete mode 100644 src/fe-gtk/notifications/notification-libnotify.c (limited to 'src/fe-gtk') diff --git a/.github/workflows/ubuntu-build.yml b/.github/workflows/ubuntu-build.yml index d69e63f5..3bb10dda 100644 --- a/.github/workflows/ubuntu-build.yml +++ b/.github/workflows/ubuntu-build.yml @@ -10,7 +10,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get update - sudo apt-get install -y meson libcanberra-dev libdbus-glib-1-dev libglib2.0-dev libgtk2.0-dev libluajit-5.1-dev libnotify-dev libpci-dev libperl-dev libproxy-dev libssl-dev python3-dev python3-cffi mono-devel desktop-file-utils + sudo apt-get install -y meson libcanberra-dev libdbus-glib-1-dev libglib2.0-dev libgtk2.0-dev libluajit-5.1-dev libpci-dev libperl-dev libproxy-dev libssl-dev python3-dev python3-cffi mono-devel desktop-file-utils - name: Configure run: meson build -Dtext=true -Dtheme-manager=true -Dauto_features=enabled diff --git a/meson.build b/meson.build index 7a29fd23..fe5f245d 100644 --- a/meson.build +++ b/meson.build @@ -19,7 +19,6 @@ libgmodule_dep = dependency('gmodule-2.0') libcanberra_dep = dependency('libcanberra', version: '>= 0.22', required: get_option('libcanberra')) dbus_glib_dep = dependency('dbus-glib-1', required: get_option('dbus')) -libnotify_dep = dependency('libnotify', required: get_option('libnotify')) global_deps = [] if cc.get_id() == 'msvc' @@ -182,7 +181,6 @@ if meson.version().version_compare('>= 0.53.0') 'TLS (openssl)': libssl_dep.found(), 'Plugin Support': get_option('plugin'), 'DBus Support': dbus_glib_dep.found(), - 'libnotify': libnotify_dep.found(), 'libcanberra': libcanberra_dep.found(), }, section: 'Features') diff --git a/meson_options.txt b/meson_options.txt index 58a8012a..c2ca54a2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -19,9 +19,6 @@ option('plugin', type: 'boolean', option('dbus', type: 'feature', value: 'auto', description: 'Support used for single-instance and scripting interface, Unix only' ) -option('libnotify', type: 'feature', value: 'auto', - description: 'Support for freedesktop notifications, Unix only' -) option('libcanberra', type: 'feature', value: 'auto', description: 'Support for sound alerts, Unix only' ) diff --git a/src/fe-gtk/meson.build b/src/fe-gtk/meson.build index 020d2631..d07514db 100644 --- a/src/fe-gtk/meson.build +++ b/src/fe-gtk/meson.build @@ -43,11 +43,7 @@ hexchat_gtk_cflags = [] hexchat_gtk_ldflags = [] -if libnotify_dep.found() - hexchat_gtk_sources += 'notifications/notification-libnotify.c' - hexchat_gtk_deps += libnotify_dep -elif false # TODO HAVE_GTK_MAC -elif host_machine.system() == 'windows' +if host_machine.system() == 'windows' hexchat_gtk_sources += 'notifications/notification-windows.c' # TODO: mingw doesn't have these headers or libs @@ -57,7 +53,7 @@ elif host_machine.system() == 'windows' #) else - hexchat_gtk_sources += 'notifications/notification-dummy.c' + hexchat_gtk_sources += 'notifications/notification-freedesktop.c' endif iso_codes = dependency('iso-codes', required: false) diff --git a/src/fe-gtk/notifications/notification-freedesktop.c b/src/fe-gtk/notifications/notification-freedesktop.c new file mode 100644 index 00000000..920a879a --- /dev/null +++ b/src/fe-gtk/notifications/notification-freedesktop.c @@ -0,0 +1,147 @@ +/* HexChat + * Copyright (C) 2021 Patrick Griffis. + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" + +#include + +static GDBusProxy *fdo_notifications; +static gboolean strip_markup; + +static void +on_notify_ready (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) +{ + GError *error = NULL; + guint32 notification_id; + GVariant *response = g_dbus_proxy_call_finish (proxy, res, &error); + if (error) + { + g_info ("Failed to send notification: %s", error->message); + g_error_free (error); + return; + } + + g_variant_get (response, "(u)", ¬ification_id); + g_info ("Notification sent. ID=%u", notification_id); + + g_variant_unref (response); +} + +void +notification_backend_show (const char *title, const char *text) +{ + GVariantBuilder params; + + g_assert (fdo_notifications); + + if (strip_markup) + text = g_markup_escape_text (text, -1); + + g_variant_builder_init (¶ms, G_VARIANT_TYPE ("(susssasa{sv}i)")); + g_variant_builder_add (¶ms, "s", "hexchat"); /* App name */ + g_variant_builder_add (¶ms, "u", 0); /* ID, 0 means don't replace */ + g_variant_builder_add (¶ms, "s", ""); /* App icon (set from hints instead) */ + g_variant_builder_add (¶ms, "s", title); + g_variant_builder_add (¶ms, "s", text); + g_variant_builder_add (¶ms, "as", NULL); /* Actions */ + + /* Hints */ + g_variant_builder_open (¶ms, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_open (¶ms, G_VARIANT_TYPE ("{sv}")); + g_variant_builder_add (¶ms, "s", "desktop-entry"); + g_variant_builder_add (¶ms, "v", g_variant_new_string ("io.github.Hexchat")); + g_variant_builder_close (¶ms); + g_variant_builder_close (¶ms); + + g_variant_builder_add (¶ms, "i", -1); /* Expiration */ + + g_dbus_proxy_call (fdo_notifications, + "Notify", + g_variant_builder_end (¶ms), + G_DBUS_CALL_FLAGS_NONE, + 1000, + NULL, + (GAsyncReadyCallback)on_notify_ready, + NULL); + + if (strip_markup) + g_free ((char*)text); +} + +int +notification_backend_init (const char **error) +{ + GError *err = NULL; + GVariant *response; + char **capabilities; + guint i; + + fdo_notifications = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + NULL, + &err); + + if (err) + goto return_error; + + response = g_dbus_proxy_call_sync (fdo_notifications, + "GetCapabilities", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 30, + NULL, + &err); + + if (err) + { + g_clear_object (&fdo_notifications); + goto return_error; + } + + g_variant_get (response, "(^a&s)", &capabilities); + for (i = 0; capabilities[i]; i++) + { + if (strcmp (capabilities[i], "body-markup") == 0) + strip_markup = TRUE; + } + + g_free (capabilities); + g_variant_unref (response); + return 1; + +return_error: + *error = g_strdup (err->message); + g_error_free (err); + return 0; +} + +void +notification_backend_deinit (void) +{ + g_clear_object (&fdo_notifications); +} + +int +notification_backend_supported (void) +{ + return fdo_notifications != NULL; +} diff --git a/src/fe-gtk/notifications/notification-libnotify.c b/src/fe-gtk/notifications/notification-libnotify.c deleted file mode 100644 index ee417396..00000000 --- a/src/fe-gtk/notifications/notification-libnotify.c +++ /dev/null @@ -1,81 +0,0 @@ -/* HexChat - * Copyright (C) 2015 Patrick Griffis. - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" -#include -#include - -#ifndef NOTIFY_CHECK_VERSION -#define NOTIFY_CHECK_VERSION(x,y,z) 0 -#endif - -static gboolean strip_markup = FALSE; - -void -notification_backend_show (const char *title, const char *text) -{ - NotifyNotification *notification; - - if (strip_markup) - text = g_markup_escape_text (text, -1); - -#if NOTIFY_CHECK_VERSION(0,7,0) - notification = notify_notification_new (title, text, "hexchat"); -#else - notification = notify_notification_new (title, text, "hexchat", NULL); -#endif -#if NOTIFY_CHECK_VERSION(0,6,0) - notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("io.github.Hexchat")); -#else - notify_notification_set_hint_string (notification, "desktop-entry", "io.github.Hexchat"); -#endif - - notify_notification_show (notification, NULL); - - g_object_unref (notification); - if (strip_markup) - g_free ((char*)text); -} - -int -notification_backend_init (const char **error) -{ - GList* server_caps; - - if (!notify_init (PACKAGE_NAME)) - return 0; - - server_caps = notify_get_server_caps (); - if (g_list_find_custom (server_caps, "body-markup", (GCompareFunc)g_strcmp0)) - strip_markup = TRUE; - g_list_free_full (server_caps, g_free); - - return 1; -} - -void -notification_backend_deinit (void) -{ - notify_uninit (); -} - -int -notification_backend_supported (void) -{ - return notify_is_initted (); -} -- cgit 1.4.1 From 91439f04c08b95121947cc6fa6efcdd011d856a0 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 13 Jul 2021 12:30:47 -0500 Subject: Fix whitespace issues --- .../notifications/notification-freedesktop.c | 112 ++++++++++----------- 1 file changed, 56 insertions(+), 56 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/notifications/notification-freedesktop.c b/src/fe-gtk/notifications/notification-freedesktop.c index 920a879a..99ec79ae 100644 --- a/src/fe-gtk/notifications/notification-freedesktop.c +++ b/src/fe-gtk/notifications/notification-freedesktop.c @@ -26,58 +26,58 @@ static gboolean strip_markup; static void on_notify_ready (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { - GError *error = NULL; - guint32 notification_id; - GVariant *response = g_dbus_proxy_call_finish (proxy, res, &error); - if (error) - { - g_info ("Failed to send notification: %s", error->message); - g_error_free (error); - return; - } - - g_variant_get (response, "(u)", ¬ification_id); - g_info ("Notification sent. ID=%u", notification_id); - - g_variant_unref (response); + GError *error = NULL; + guint32 notification_id; + GVariant *response = g_dbus_proxy_call_finish (proxy, res, &error); + if (error) + { + g_info ("Failed to send notification: %s", error->message); + g_error_free (error); + return; + } + + g_variant_get (response, "(u)", ¬ification_id); + g_info ("Notification sent. ID=%u", notification_id); + + g_variant_unref (response); } void notification_backend_show (const char *title, const char *text) { - GVariantBuilder params; + GVariantBuilder params; - g_assert (fdo_notifications); + g_assert (fdo_notifications); if (strip_markup) - text = g_markup_escape_text (text, -1); - - g_variant_builder_init (¶ms, G_VARIANT_TYPE ("(susssasa{sv}i)")); - g_variant_builder_add (¶ms, "s", "hexchat"); /* App name */ - g_variant_builder_add (¶ms, "u", 0); /* ID, 0 means don't replace */ - g_variant_builder_add (¶ms, "s", ""); /* App icon (set from hints instead) */ - g_variant_builder_add (¶ms, "s", title); - g_variant_builder_add (¶ms, "s", text); - g_variant_builder_add (¶ms, "as", NULL); /* Actions */ - - /* Hints */ - g_variant_builder_open (¶ms, G_VARIANT_TYPE ("a{sv}")); - g_variant_builder_open (¶ms, G_VARIANT_TYPE ("{sv}")); - g_variant_builder_add (¶ms, "s", "desktop-entry"); - g_variant_builder_add (¶ms, "v", g_variant_new_string ("io.github.Hexchat")); - g_variant_builder_close (¶ms); - g_variant_builder_close (¶ms); - - g_variant_builder_add (¶ms, "i", -1); /* Expiration */ - - g_dbus_proxy_call (fdo_notifications, - "Notify", - g_variant_builder_end (¶ms), - G_DBUS_CALL_FLAGS_NONE, - 1000, - NULL, + text = g_markup_escape_text (text, -1); + + g_variant_builder_init (¶ms, G_VARIANT_TYPE ("(susssasa{sv}i)")); + g_variant_builder_add (¶ms, "s", "hexchat"); /* App name */ + g_variant_builder_add (¶ms, "u", 0); /* ID, 0 means don't replace */ + g_variant_builder_add (¶ms, "s", ""); /* App icon (set from hints instead) */ + g_variant_builder_add (¶ms, "s", title); + g_variant_builder_add (¶ms, "s", text); + g_variant_builder_add (¶ms, "as", NULL); /* Actions */ + + /* Hints */ + g_variant_builder_open (¶ms, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_open (¶ms, G_VARIANT_TYPE ("{sv}")); + g_variant_builder_add (¶ms, "s", "desktop-entry"); + g_variant_builder_add (¶ms, "v", g_variant_new_string ("io.github.Hexchat")); + g_variant_builder_close (¶ms); + g_variant_builder_close (¶ms); + + g_variant_builder_add (¶ms, "i", -1); /* Expiration */ + + g_dbus_proxy_call (fdo_notifications, + "Notify", + g_variant_builder_end (¶ms), + G_DBUS_CALL_FLAGS_NONE, + 1000, + NULL, (GAsyncReadyCallback)on_notify_ready, - NULL); + NULL); if (strip_markup) g_free ((char*)text); @@ -88,8 +88,8 @@ notification_backend_init (const char **error) { GError *err = NULL; GVariant *response; - char **capabilities; - guint i; + char **capabilities; + guint i; fdo_notifications = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, @@ -112,20 +112,20 @@ notification_backend_init (const char **error) &err); if (err) - { - g_clear_object (&fdo_notifications); + { + g_clear_object (&fdo_notifications); goto return_error; - } + } - g_variant_get (response, "(^a&s)", &capabilities); - for (i = 0; capabilities[i]; i++) - { - if (strcmp (capabilities[i], "body-markup") == 0) - strip_markup = TRUE; - } + g_variant_get (response, "(^a&s)", &capabilities); + for (i = 0; capabilities[i]; i++) + { + if (strcmp (capabilities[i], "body-markup") == 0) + strip_markup = TRUE; + } - g_free (capabilities); - g_variant_unref (response); + g_free (capabilities); + g_variant_unref (response); return 1; return_error: -- cgit 1.4.1 From 2985dde7f05aef73ac8f682f0ee9fa1666066be2 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Fri, 1 Oct 2021 11:56:49 -0500 Subject: Explicitly set app icon in notifications --- src/fe-gtk/notifications/notification-freedesktop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/notifications/notification-freedesktop.c b/src/fe-gtk/notifications/notification-freedesktop.c index 99ec79ae..80ae0e1d 100644 --- a/src/fe-gtk/notifications/notification-freedesktop.c +++ b/src/fe-gtk/notifications/notification-freedesktop.c @@ -55,7 +55,7 @@ notification_backend_show (const char *title, const char *text) g_variant_builder_init (¶ms, G_VARIANT_TYPE ("(susssasa{sv}i)")); g_variant_builder_add (¶ms, "s", "hexchat"); /* App name */ g_variant_builder_add (¶ms, "u", 0); /* ID, 0 means don't replace */ - g_variant_builder_add (¶ms, "s", ""); /* App icon (set from hints instead) */ + g_variant_builder_add (¶ms, "s", "io.github.Hexchat"); /* App icon */ g_variant_builder_add (¶ms, "s", title); g_variant_builder_add (¶ms, "s", text); g_variant_builder_add (¶ms, "as", NULL); /* Actions */ -- cgit 1.4.1 From 9039a5d75ba854d00bfbd9bb5235ec547eeffbe1 Mon Sep 17 00:00:00 2001 From: Nolan Lum Date: Thu, 14 Oct 2021 07:44:11 -0700 Subject: Add -NOOVERRIDE flag to GUI COLOR. (#2644) --- src/common/fe.h | 11 ++++++++++- src/common/outbound.c | 12 +++++++++--- src/fe-gtk/fe-gtk.c | 8 ++++---- src/fe-gtk/maingui.c | 22 +++++++++++++++------- src/fe-text/fe-text.c | 2 +- 5 files changed, 39 insertions(+), 16 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/common/fe.h b/src/common/fe.h index 6614055b..9da4e230 100644 --- a/src/common/fe.h +++ b/src/common/fe.h @@ -69,7 +69,16 @@ int fe_input_add (int sok, int flags, void *func, void *data); void fe_input_remove (int tag); void fe_idle_add (void *func, void *data); void fe_set_topic (struct session *sess, char *topic, char *stripped_topic); -void fe_set_tab_color (struct session *sess, int col); +typedef enum +{ + FE_COLOR_NONE = 0, + FE_COLOR_NEW_DATA = 1, + FE_COLOR_NEW_MSG = 2, + FE_COLOR_NEW_HILIGHT = 3, + FE_COLOR_FLAG_NOOVERRIDE = 8, +} tabcolor; +#define FE_COLOR_ALLFLAGS (FE_COLOR_FLAG_NOOVERRIDE) +void fe_set_tab_color (struct session *sess, tabcolor col); void fe_flash_window (struct session *sess); void fe_update_mode_buttons (struct session *sess, char mode, char sign); void fe_update_channel_key (struct session *sess); diff --git a/src/common/outbound.c b/src/common/outbound.c index 70fcd436..fcc731e2 100644 --- a/src/common/outbound.c +++ b/src/common/outbound.c @@ -2152,7 +2152,6 @@ cmd_gui (struct session *sess, char *tbuf, char *word[], char *word_eol[]) { case 0x058b836e: fe_ctrl_gui (sess, 8, 0); break; /* APPLY */ case 0xac1eee45: fe_ctrl_gui (sess, 7, 2); break; /* ATTACH */ - case 0x05a72f63: fe_ctrl_gui (sess, 4, atoi (word[3])); break; /* COLOR */ case 0xb06a1793: fe_ctrl_gui (sess, 7, 1); break; /* DETACH */ case 0x05cfeff0: fe_ctrl_gui (sess, 3, 0); break; /* FLASH */ case 0x05d154d8: fe_ctrl_gui (sess, 2, 0); break; /* FOCUS */ @@ -2166,6 +2165,12 @@ cmd_gui (struct session *sess, char *tbuf, char *word[], char *word_eol[]) else return FALSE; break; + case 0x05a72f63: /* COLOR */ + if (!g_ascii_strcasecmp (word[4], "-NOOVERRIDE")) + fe_ctrl_gui (sess, 4, FE_COLOR_FLAG_NOOVERRIDE | atoi (word[3])); + else + fe_ctrl_gui (sess, 4, atoi (word[3])); + break; default: return FALSE; } @@ -4015,8 +4020,9 @@ const struct commands xc_cmds[] = { {"GETINT", cmd_getint, 0, 0, 1, "GETINT "}, {"GETSTR", cmd_getstr, 0, 0, 1, "GETSTR "}, {"GHOST", cmd_ghost, 1, 0, 1, N_("GHOST [password], Kills a ghosted nickname")}, - {"GUI", cmd_gui, 0, 0, 1, "GUI [APPLY|ATTACH|DETACH|SHOW|HIDE|FOCUS|FLASH|ICONIFY|COLOR ]\n" - " GUI [MSGBOX |MENU TOGGLE]"}, + {"GUI", cmd_gui, 0, 0, 1, "GUI [APPLY|ATTACH|DETACH|SHOW|HIDE|FOCUS|FLASH|ICONIFY]\n" + " GUI [MSGBOX |MENU TOGGLE]\n" + " GUI COLOR [-NOOVERRIDE]"}, {"HELP", cmd_help, 0, 0, 1, 0}, {"HOP", cmd_hop, 1, 1, 1, N_("HOP , gives chanhalf-op status to the nick (needs chanop)")}, diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index 4ed4aac9..3d3c8052 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -664,13 +664,13 @@ fe_print_text (struct session *sess, char *text, time_t stamp, return; if (sess == current_tab) - fe_set_tab_color (sess, 0); + fe_set_tab_color (sess, FE_COLOR_NONE); else if (sess->tab_state & TAB_STATE_NEW_HILIGHT) - fe_set_tab_color (sess, 3); + fe_set_tab_color (sess, FE_COLOR_NEW_HILIGHT); else if (sess->tab_state & TAB_STATE_NEW_MSG) - fe_set_tab_color (sess, 2); + fe_set_tab_color (sess, FE_COLOR_NEW_MSG); else - fe_set_tab_color (sess, 1); + fe_set_tab_color (sess, FE_COLOR_NEW_DATA); } void diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c index b77da59b..61f59856 100644 --- a/src/fe-gtk/maingui.c +++ b/src/fe-gtk/maingui.c @@ -175,20 +175,26 @@ fe_flash_window (session *sess) /* set a tab plain, red, light-red, or blue */ void -fe_set_tab_color (struct session *sess, int col) +fe_set_tab_color (struct session *sess, tabcolor col) { struct session *server_sess = sess->server->server_session; + int col_noflags = (col & ~FE_COLOR_ALLFLAGS); + int col_shouldoverride = !(col & FE_COLOR_FLAG_NOOVERRIDE); + if (sess->res->tab && sess->gui->is_tab && (col == 0 || sess != current_tab)) { - switch (col) + switch (col_noflags) { case 0: /* no particular color (theme default) */ sess->tab_state = TAB_STATE_NONE; chan_set_color (sess->res->tab, plain_list); break; case 1: /* new data has been displayed (dark red) */ - sess->tab_state = TAB_STATE_NEW_DATA; - chan_set_color (sess->res->tab, newdata_list); + if (col_shouldoverride || !((sess->tab_state & TAB_STATE_NEW_MSG) + || (sess->tab_state & TAB_STATE_NEW_HILIGHT))) { + sess->tab_state = TAB_STATE_NEW_DATA; + chan_set_color (sess->res->tab, newdata_list); + } if (chan_is_collapsed (sess->res->tab) && !((server_sess->tab_state & TAB_STATE_NEW_MSG) @@ -201,8 +207,10 @@ fe_set_tab_color (struct session *sess, int col) break; case 2: /* new message arrived in channel (light red) */ - sess->tab_state = TAB_STATE_NEW_MSG; - chan_set_color (sess->res->tab, newmsg_list); + if (col_shouldoverride || !(sess->tab_state & TAB_STATE_NEW_HILIGHT)) { + sess->tab_state = TAB_STATE_NEW_MSG; + chan_set_color (sess->res->tab, newmsg_list); + } if (chan_is_collapsed (sess->res->tab) && !(server_sess->tab_state & TAB_STATE_NEW_HILIGHT) @@ -540,7 +548,7 @@ mg_focus (session *sess) /* when called via mg_changui_new, is_tab might be true, but sess->res->tab is still NULL. */ if (sess->res->tab) - fe_set_tab_color (sess, 0); + fe_set_tab_color (sess, FE_COLOR_NONE); } static int diff --git a/src/fe-text/fe-text.c b/src/fe-text/fe-text.c index 1d411ddf..3673a81f 100644 --- a/src/fe-text/fe-text.c +++ b/src/fe-text/fe-text.c @@ -623,7 +623,7 @@ fe_cleanup (void) { } void -fe_set_tab_color (struct session *sess, int col) +fe_set_tab_color (struct session *sess, tabcolor col) { } void -- cgit 1.4.1 From ba5d79b496d0f7d2c01626a90c2de934eb918a10 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Wed, 22 Dec 2021 11:50:36 -0600 Subject: Be smarter about conditionally escaping URIs that are opened Fixes #2659 --- src/fe-gtk/fe-gtk.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index 3d3c8052..285ba42b 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -1054,6 +1054,46 @@ osx_show_uri (const char *url) #endif +static inline char * +escape_uri (const char *uri) +{ + return g_uri_escape_string(uri, G_URI_RESERVED_CHARS_GENERIC_DELIMITERS G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, FALSE); +} + +static inline gboolean +uri_contains_forbidden_characters (const char *uri) +{ + while (*uri) + { + /* This is not an exhaustive list, the full URI has segments that allow characters like "[]:" for example. */ + if (strchr ("`<> ${}\"+", *uri) != NULL || (*uri & 0x80) /* non-ascii */) + return TRUE; + uri++; + } + + return FALSE; +} + +static char * +maybe_escape_uri (const char *uri) +{ + /* There isn't an exact way to know if a string has already been escaped or not + * so we can try some heuristics. */ + + /* If we find characters that should clearly be escaped. */ + if (uri_contains_forbidden_characters (uri)) + return escape_uri (uri); + + /* If it fails to be unescaped then it was not escaped. */ + char *unescaped = g_uri_unescape_string (uri, NULL); + if (!unescaped) + return escape_uri (uri); + g_free (unescaped); + + /* At this point it is probably safe to pass through as-is. */ + return g_strdup (uri); +} + static void fe_open_url_inner (const char *url) { @@ -1071,8 +1111,8 @@ fe_open_url_inner (const char *url) #elif defined(__APPLE__) osx_show_uri (url); #else - char *escaped_url = g_uri_escape_string (url, G_URI_RESERVED_CHARS_GENERIC_DELIMITERS G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, - FALSE); + char *escaped_url = maybe_escape_uri (url); + g_debug ("Opening URL \"%s\" (%s)", escaped_url, url); gtk_show_uri (NULL, escaped_url, GDK_CURRENT_TIME, NULL); g_free (escaped_url); #endif -- cgit 1.4.1 From 66f596822509c0d2adb3b90caba1edd09dd61d65 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Wed, 22 Dec 2021 12:04:48 -0600 Subject: Update comment --- src/fe-gtk/fe-gtk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index 285ba42b..7eca0710 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -1077,8 +1077,8 @@ uri_contains_forbidden_characters (const char *uri) static char * maybe_escape_uri (const char *uri) { - /* There isn't an exact way to know if a string has already been escaped or not - * so we can try some heuristics. */ + /* The only way to know if a string has already been escaped or not + * is by fulling parsing each segement but we can try some more simple heuristics. */ /* If we find characters that should clearly be escaped. */ if (uri_contains_forbidden_characters (uri)) -- cgit 1.4.1 From d936b653ac0c6c265f676f5b92a8da2375b59402 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 6 Jan 2022 20:36:14 -0600 Subject: Add missing header https://github.com/hexchat/hexchat/issues/2652#issuecomment-1007015314 --- src/fe-gtk/notifications/notification-freedesktop.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/notifications/notification-freedesktop.c b/src/fe-gtk/notifications/notification-freedesktop.c index 80ae0e1d..a23284e5 100644 --- a/src/fe-gtk/notifications/notification-freedesktop.c +++ b/src/fe-gtk/notifications/notification-freedesktop.c @@ -18,6 +18,7 @@ #include "config.h" +#include #include static GDBusProxy *fdo_notifications; -- cgit 1.4.1 From d99a98ff4cc9d9184ceb5b625abe0e737e009fbe Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 26 Mar 2022 11:18:00 -0500 Subject: notification: Don't print failure to load backend in UI This isn't actually helpful information to users generally Closes #2152 Closes #2684 --- src/fe-gtk/plugin-notification.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/plugin-notification.c b/src/fe-gtk/plugin-notification.c index 29478d7a..875b50f4 100644 --- a/src/fe-gtk/plugin-notification.c +++ b/src/fe-gtk/plugin-notification.c @@ -218,7 +218,7 @@ notification_plugin_init (hexchat_plugin *plugin_handle, char **plugin_name, cha if (!notification_backend_init (&error)) { if (error) - hexchat_printf(plugin_handle, "Failed loading notification plugin: %s\n", error); + g_debug("Failed loading notification plugin: %s\n", error); return 0; } -- cgit 1.4.1