From da26097aab554c44540c25f0741dc19f6e92cc41 Mon Sep 17 00:00:00 2001 From: BakasuraRCE Date: Wed, 29 Jul 2020 09:50:12 -0500 Subject: notification: Implement notification option for channels --- src/common/chanopt.c | 2 ++ src/common/hexchat.c | 1 + src/common/hexchat.h | 1 + src/common/plugin.c | 6 +++++- src/fe-gtk/maingui.c | 26 ++++++++++++++++++++++---- src/fe-gtk/plugin-notification.c | 40 ++++++++++++++++++++++++++++++++++++---- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/common/chanopt.c b/src/common/chanopt.c index 1870c99c..67cb46cf 100644 --- a/src/common/chanopt.c +++ b/src/common/chanopt.c @@ -58,6 +58,7 @@ typedef struct static const channel_options chanopt[] = { + {"alert_balloon", NULL, S_F(alert_balloon)}, {"alert_beep", "BEEP", S_F(alert_beep)}, {"alert_taskbar", NULL, S_F(alert_taskbar)}, {"alert_tray", "TRAY", S_F(alert_tray)}, @@ -182,6 +183,7 @@ typedef struct { /* Per-Channel Alerts */ /* use a byte, because we need a pointer to each element */ + guint8 alert_balloon; guint8 alert_beep; guint8 alert_taskbar; guint8 alert_tray; diff --git a/src/common/hexchat.c b/src/common/hexchat.c index e9a9a7fc..8702c63d 100644 --- a/src/common/hexchat.c +++ b/src/common/hexchat.c @@ -493,6 +493,7 @@ session_new (server *serv, char *from, int type, int focus) sess->logfd = -1; sess->type = type; + sess->alert_balloon = SET_DEFAULT; sess->alert_beep = SET_DEFAULT; sess->alert_taskbar = SET_DEFAULT; sess->alert_tray = SET_DEFAULT; diff --git a/src/common/hexchat.h b/src/common/hexchat.h index f9ca006b..d8effa1f 100644 --- a/src/common/hexchat.h +++ b/src/common/hexchat.h @@ -363,6 +363,7 @@ typedef struct session { /* Per-Channel Alerts */ /* use a byte, because we need a pointer to each element */ + guint8 alert_balloon; guint8 alert_beep; guint8 alert_taskbar; guint8 alert_tray; diff --git a/src/common/plugin.c b/src/common/plugin.c index 00cf4599..f2c2ecfb 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -138,7 +138,9 @@ enum CHANNEL_FLAG_TRAY_UNSET = 1 << 18, CHANNEL_FLAG_TASKBAR = 1 << 19, CHANNEL_FLAG_TASKBAR_UNSET = 1 << 20, - CHANNEL_FLAG_COUNT = 21 + CHANNEL_FLAG_BALLOON = 1 << 21, + CHANNEL_FLAG_BALLOON_UNSET = 1 << 22, + CHANNEL_FLAG_COUNT = 23 }; GSList *plugin_list = NULL; /* export for plugingui.c */ @@ -1633,6 +1635,8 @@ hexchat_list_int (hexchat_plugin *ph, hexchat_list *xlist, const char *name) channel_flags[18] = ((struct session *)data)->alert_tray == SET_DEFAULT; channel_flags[19] = ((struct session *)data)->alert_taskbar; channel_flags[20] = ((struct session *)data)->alert_taskbar == SET_DEFAULT; + channel_flags[21] = ((struct session *)data)->alert_balloon; + channel_flags[22] = ((struct session *)data)->alert_balloon == SET_DEFAULT; /* Set flags */ for (channel_flag = 0; channel_flag < CHANNEL_FLAG_COUNT; ++channel_flag) { diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c index 335522a0..4e5baaa0 100644 --- a/src/fe-gtk/maingui.c +++ b/src/fe-gtk/maingui.c @@ -1520,14 +1520,32 @@ static void mg_create_alertmenu (session *sess, GtkWidget *menu) { GtkWidget *submenu; + int hex_balloon, hex_beep, hex_tray, hex_flash; - submenu = menu_quick_sub (_("_Extra Alerts"), menu, NULL, XCMENU_MNEMONIC, -1); - mg_perchan_menu_item (_("Beep on _Message"), submenu, &sess->alert_beep, prefs.hex_input_beep_chans); + switch (sess->type) { + case SESS_DIALOG: + hex_balloon = prefs.hex_input_balloon_priv; + hex_beep = prefs.hex_input_beep_priv; + hex_tray = prefs.hex_input_tray_priv; + hex_flash = prefs.hex_input_flash_priv; + break; + default: + hex_balloon = prefs.hex_input_balloon_chans; + hex_beep = prefs.hex_input_beep_chans; + hex_tray = prefs.hex_input_tray_chans; + hex_flash = prefs.hex_input_flash_chans; + } + + submenu = menu_quick_sub(_("_Extra Alerts"), menu, NULL, XCMENU_MNEMONIC, -1); + + mg_perchan_menu_item(_("Show Notifications"), submenu, &sess->alert_balloon, hex_balloon); + + mg_perchan_menu_item(_("Beep on _Message"), submenu, &sess->alert_beep, hex_beep); - mg_perchan_menu_item (_("Blink Tray _Icon"), submenu, &sess->alert_tray, prefs.hex_input_tray_chans); + mg_perchan_menu_item(_("Blink Tray _Icon"), submenu, &sess->alert_tray, hex_tray); - mg_perchan_menu_item (_("Blink Task _Bar"), submenu, &sess->alert_taskbar, prefs.hex_input_flash_chans); + mg_perchan_menu_item(_("Blink Task _Bar"), submenu, &sess->alert_taskbar, hex_flash); } static void diff --git a/src/fe-gtk/plugin-notification.c b/src/fe-gtk/plugin-notification.c index 3ac89244..29478d7a 100644 --- a/src/fe-gtk/plugin-notification.c +++ b/src/fe-gtk/plugin-notification.c @@ -25,6 +25,9 @@ static hexchat_plugin *ph; +const int CHANNEL_FLAG_BALLOON = 1 << 21; +const int CHANNEL_FLAG_BALLOON_UNSET = 1 << 22; + static gboolean should_alert (void) { @@ -117,10 +120,24 @@ static int incoming_message_cb (char *word[], gpointer userdata) { int message; + int flags; + int alert = 0; + + flags = hexchat_list_int(ph, NULL, "flags"); + + /* Let sure that can alert */ + if (should_alert()) { + /* Follow the channel rules if set */ + if (!(flags & CHANNEL_FLAG_BALLOON_UNSET)) { + alert = (flags & CHANNEL_FLAG_BALLOON); + } else { + /* Else follow global environment */ + alert = (hexchat_get_prefs(ph, "input_balloon_chans", NULL, &message) == 3 && message); + } + } - if (hexchat_get_prefs (ph, "input_balloon_chans", NULL, &message) == 3 && message && should_alert ()) - { - show_notificationf (word[2], _("Channel message from: %s (%s)"), word[1], hexchat_get_info (ph, "channel")); + if (alert) { + show_notificationf(word[2], _("Channel message from: %s (%s)"), word[1], hexchat_get_info(ph, "channel")); } return HEXCHAT_EAT_NONE; } @@ -129,8 +146,23 @@ static int incoming_priv_cb (char *word[], gpointer userdata) { int priv; + int flags; + int alert = 0; + + flags = hexchat_list_int(ph, NULL, "flags"); + + /* Let sure that can alert */ + if (should_alert()) { + /* Follow the private rules if set */ + if (!(flags & CHANNEL_FLAG_BALLOON_UNSET)) { + alert = (flags & CHANNEL_FLAG_BALLOON); + } else { + /* Else follow global environment */ + alert = (hexchat_get_prefs(ph, "input_balloon_priv", NULL, &priv) == 3 && priv); + } + } - if (hexchat_get_prefs (ph, "input_balloon_priv", NULL, &priv) == 3 && priv && should_alert ()) + if (alert) { const char *network = hexchat_get_info (ph, "network"); if (!network) -- cgit v1.2.3