Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 65f27b1b by wurstsalat at 2023-01-11T17:55:07+01:00 imprv: AccountPage: Add menu item to deny all subscription requests
Fixes #11367
- - - - -
5 changed files:
- gajim/data/gui/account_page.ui - gajim/gtk/account_page.py - gajim/gtk/builder.pyi - gajim/gtk/menus.py - gajim/gtk/notification_manager.py
Changes:
===================================== gajim/data/gui/account_page.ui ===================================== @@ -262,14 +262,50 @@ </packing> </child> <child> - <object class="GtkLabel"> + <object class="GtkBox"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="margin-top">6</property> - <property name="label" translatable="yes">Notifications</property> - <style> - <class name="bold16"/> - </style> + <property name="spacing">18</property> + <child type="center"> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="margin-top">6</property> + <property name="label" translatable="yes">Notifications</property> + <style> + <class name="bold16"/> + </style> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkMenuButton" id="notifications_menu_button"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="focus-on-click">False</property> + <property name="receives-default">True</property> + <property name="halign">start</property> + <property name="valign">center</property> + <property name="hexpand">True</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="icon-name">view-more-symbolic</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">0</property> + </packing> + </child> </object> <packing> <property name="expand">False</property>
===================================== gajim/gtk/account_page.py ===================================== @@ -29,6 +29,7 @@
from gajim.gtk.builder import get_builder from gajim.gtk.menus import get_account_menu +from gajim.gtk.menus import get_account_notifications_menu from gajim.gtk.menus import get_roster_view_menu from gajim.gtk.notification_manager import NotificationManager from gajim.gtk.roster import Roster @@ -63,6 +64,9 @@ def __init__(self, account: str) -> None: self._notification_manager = NotificationManager(account) self._ui.account_box.add(self._notification_manager)
+ self._ui.notifications_menu_button.set_menu_model( + get_account_notifications_menu(account)) + self._roster = Roster(account) self._ui.roster_box.add(self._roster)
===================================== gajim/gtk/builder.pyi ===================================== @@ -20,6 +20,7 @@ class AccountPageBuilder(Builder): account_label: Gtk.Label account_page_menu_button: Gtk.MenuButton status_box: Gtk.Box + notifications_menu_button: Gtk.MenuButton
class AccountWizardBuilder(Builder):
===================================== gajim/gtk/menus.py ===================================== @@ -444,6 +444,15 @@ def get_roster_view_menu() -> GajimMenu: return GajimMenu.from_list(menuitems)
+def get_account_notifications_menu(account: str) -> GajimMenu: + menuitems: MenuItemListT = [ + (_('Deny all subscription requests'), + f'win.subscription-deny-all-{account}', + None), + ] + return GajimMenu.from_list(menuitems) + + def get_subscription_menu(account: str, jid: JID) -> GajimMenu: params = AddChatActionParams(account=account, jid=jid,
===================================== gajim/gtk/notification_manager.py ===================================== @@ -15,6 +15,7 @@ from __future__ import annotations
from typing import Any +from typing import Callable from typing import cast from typing import Optional from typing import Union @@ -38,6 +39,11 @@ from gajim.gtk.menus import get_subscription_menu from gajim.gtk.util import open_window
+NotificationActionListT = list[ + tuple[str, + Callable[[Gio.SimpleAction, GLib.Variant], Any], + Optional[str]]] +
class NotificationManager(Gtk.ListBox): def __init__(self, account: str) -> None: @@ -64,16 +70,19 @@ def _on_destroy(self, *args: Any) -> None: self._remove_actions()
def _add_actions(self) -> None: - actions = [ + actions: NotificationActionListT = [ ('subscription-accept', self._on_subscription_accept, 'as'), ('subscription-deny', self._on_subscription_deny, 's'), + ('subscription-deny-all', self._on_subscription_deny_all, None), ('subscription-block', self._on_subscription_block, 's'), ('subscription-report', self._on_subscription_report, 's'), ] for action in actions: action_name, func, typ = action + if typ is not None: + typ = GLib.VariantType.new(typ) act = Gio.SimpleAction.new( - f'{action_name}-{self._account}', GLib.VariantType.new(typ)) + f'{action_name}-{self._account}', typ) act.connect('activate', func) app.window.add_action(act)
@@ -91,6 +100,11 @@ def update_actions(self) -> None: assert sub_deny is not None sub_deny.set_enabled(online)
+ sub_deny_all = app.window.lookup_action( + f'subscription-deny-all-{self._account}') + assert sub_deny_all is not None + sub_deny_all.set_enabled(online) + sub_block = app.window.lookup_action( f'subscription-block-{self._account}') assert sub_block is not None @@ -105,6 +119,7 @@ def _remove_actions(self) -> None: actions = [ 'subscription-accept', 'subscription-deny', + 'subscription-deny-all', 'subscription-block', 'subscription-report', ] @@ -165,6 +180,17 @@ def _on_subscription_deny(self, if row is not None: row.destroy()
+ def _on_subscription_deny_all(self, + _action: Gio.SimpleAction, + _param: GLib.Variant + ) -> None: + + for row in cast(list[NotificationRow], self.get_children()): + if row.type != 'subscribe': + continue + self._deny_request(row.jid) + row.destroy() + def _deny_request(self, jid: str) -> None: self._client.get_module('Presence').unsubscribed(jid)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/65f27b1baa32142c402c4dc95ee0d5d12...