Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
65f27b1b
by wurstsalat at 2023-01-11T17:55:07+01:00
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:
| ... | ... | @@ -262,14 +262,50 @@ |
| 262 | 262 | </packing>
|
| 263 | 263 | </child>
|
| 264 | 264 | <child>
|
| 265 | - <object class="GtkLabel">
|
|
| 265 | + <object class="GtkBox">
|
|
| 266 | 266 | <property name="visible">True</property>
|
| 267 | 267 | <property name="can-focus">False</property>
|
| 268 | - <property name="margin-top">6</property>
|
|
| 269 | - <property name="label" translatable="yes">Notifications</property>
|
|
| 270 | - <style>
|
|
| 271 | - <class name="bold16"/>
|
|
| 272 | - </style>
|
|
| 268 | + <property name="spacing">18</property>
|
|
| 269 | + <child type="center">
|
|
| 270 | + <object class="GtkLabel">
|
|
| 271 | + <property name="visible">True</property>
|
|
| 272 | + <property name="can-focus">False</property>
|
|
| 273 | + <property name="margin-top">6</property>
|
|
| 274 | + <property name="label" translatable="yes">Notifications</property>
|
|
| 275 | + <style>
|
|
| 276 | + <class name="bold16"/>
|
|
| 277 | + </style>
|
|
| 278 | + </object>
|
|
| 279 | + <packing>
|
|
| 280 | + <property name="expand">False</property>
|
|
| 281 | + <property name="fill">True</property>
|
|
| 282 | + <property name="position">1</property>
|
|
| 283 | + </packing>
|
|
| 284 | + </child>
|
|
| 285 | + <child>
|
|
| 286 | + <object class="GtkMenuButton" id="notifications_menu_button">
|
|
| 287 | + <property name="visible">True</property>
|
|
| 288 | + <property name="can-focus">True</property>
|
|
| 289 | + <property name="focus-on-click">False</property>
|
|
| 290 | + <property name="receives-default">True</property>
|
|
| 291 | + <property name="halign">start</property>
|
|
| 292 | + <property name="valign">center</property>
|
|
| 293 | + <property name="hexpand">True</property>
|
|
| 294 | + <child>
|
|
| 295 | + <object class="GtkImage">
|
|
| 296 | + <property name="visible">True</property>
|
|
| 297 | + <property name="can-focus">False</property>
|
|
| 298 | + <property name="icon-name">view-more-symbolic</property>
|
|
| 299 | + </object>
|
|
| 300 | + </child>
|
|
| 301 | + </object>
|
|
| 302 | + <packing>
|
|
| 303 | + <property name="expand">False</property>
|
|
| 304 | + <property name="fill">True</property>
|
|
| 305 | + <property name="pack-type">end</property>
|
|
| 306 | + <property name="position">0</property>
|
|
| 307 | + </packing>
|
|
| 308 | + </child>
|
|
| 273 | 309 | </object>
|
| 274 | 310 | <packing>
|
| 275 | 311 | <property name="expand">False</property>
|
| ... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 | |
| 30 | 30 | from gajim.gtk.builder import get_builder
|
| 31 | 31 | from gajim.gtk.menus import get_account_menu
|
| 32 | +from gajim.gtk.menus import get_account_notifications_menu
|
|
| 32 | 33 | from gajim.gtk.menus import get_roster_view_menu
|
| 33 | 34 | from gajim.gtk.notification_manager import NotificationManager
|
| 34 | 35 | from gajim.gtk.roster import Roster
|
| ... | ... | @@ -63,6 +64,9 @@ def __init__(self, account: str) -> None: |
| 63 | 64 | self._notification_manager = NotificationManager(account)
|
| 64 | 65 | self._ui.account_box.add(self._notification_manager)
|
| 65 | 66 | |
| 67 | + self._ui.notifications_menu_button.set_menu_model(
|
|
| 68 | + get_account_notifications_menu(account))
|
|
| 69 | + |
|
| 66 | 70 | self._roster = Roster(account)
|
| 67 | 71 | self._ui.roster_box.add(self._roster)
|
| 68 | 72 |
| ... | ... | @@ -20,6 +20,7 @@ class AccountPageBuilder(Builder): |
| 20 | 20 | account_label: Gtk.Label
|
| 21 | 21 | account_page_menu_button: Gtk.MenuButton
|
| 22 | 22 | status_box: Gtk.Box
|
| 23 | + notifications_menu_button: Gtk.MenuButton
|
|
| 23 | 24 | |
| 24 | 25 | |
| 25 | 26 | class AccountWizardBuilder(Builder):
|
| ... | ... | @@ -444,6 +444,15 @@ def get_roster_view_menu() -> GajimMenu: |
| 444 | 444 | return GajimMenu.from_list(menuitems)
|
| 445 | 445 | |
| 446 | 446 | |
| 447 | +def get_account_notifications_menu(account: str) -> GajimMenu:
|
|
| 448 | + menuitems: MenuItemListT = [
|
|
| 449 | + (_('Deny all subscription requests'),
|
|
| 450 | + f'win.subscription-deny-all-{account}',
|
|
| 451 | + None),
|
|
| 452 | + ]
|
|
| 453 | + return GajimMenu.from_list(menuitems)
|
|
| 454 | + |
|
| 455 | + |
|
| 447 | 456 | def get_subscription_menu(account: str, jid: JID) -> GajimMenu:
|
| 448 | 457 | params = AddChatActionParams(account=account,
|
| 449 | 458 | jid=jid,
|
| ... | ... | @@ -15,6 +15,7 @@ |
| 15 | 15 | from __future__ import annotations
|
| 16 | 16 | |
| 17 | 17 | from typing import Any
|
| 18 | +from typing import Callable
|
|
| 18 | 19 | from typing import cast
|
| 19 | 20 | from typing import Optional
|
| 20 | 21 | from typing import Union
|
| ... | ... | @@ -38,6 +39,11 @@ |
| 38 | 39 | from gajim.gtk.menus import get_subscription_menu
|
| 39 | 40 | from gajim.gtk.util import open_window
|
| 40 | 41 | |
| 42 | +NotificationActionListT = list[
|
|
| 43 | + tuple[str,
|
|
| 44 | + Callable[[Gio.SimpleAction, GLib.Variant], Any],
|
|
| 45 | + Optional[str]]]
|
|
| 46 | + |
|
| 41 | 47 | |
| 42 | 48 | class NotificationManager(Gtk.ListBox):
|
| 43 | 49 | def __init__(self, account: str) -> None:
|
| ... | ... | @@ -64,16 +70,19 @@ def _on_destroy(self, *args: Any) -> None: |
| 64 | 70 | self._remove_actions()
|
| 65 | 71 | |
| 66 | 72 | def _add_actions(self) -> None:
|
| 67 | - actions = [
|
|
| 73 | + actions: NotificationActionListT = [
|
|
| 68 | 74 | ('subscription-accept', self._on_subscription_accept, 'as'),
|
| 69 | 75 | ('subscription-deny', self._on_subscription_deny, 's'),
|
| 76 | + ('subscription-deny-all', self._on_subscription_deny_all, None),
|
|
| 70 | 77 | ('subscription-block', self._on_subscription_block, 's'),
|
| 71 | 78 | ('subscription-report', self._on_subscription_report, 's'),
|
| 72 | 79 | ]
|
| 73 | 80 | for action in actions:
|
| 74 | 81 | action_name, func, typ = action
|
| 82 | + if typ is not None:
|
|
| 83 | + typ = GLib.VariantType.new(typ)
|
|
| 75 | 84 | act = Gio.SimpleAction.new(
|
| 76 | - f'{action_name}-{self._account}', GLib.VariantType.new(typ))
|
|
| 85 | + f'{action_name}-{self._account}', typ)
|
|
| 77 | 86 | act.connect('activate', func)
|
| 78 | 87 | app.window.add_action(act)
|
| 79 | 88 | |
| ... | ... | @@ -91,6 +100,11 @@ def update_actions(self) -> None: |
| 91 | 100 | assert sub_deny is not None
|
| 92 | 101 | sub_deny.set_enabled(online)
|
| 93 | 102 | |
| 103 | + sub_deny_all = app.window.lookup_action(
|
|
| 104 | + f'subscription-deny-all-{self._account}')
|
|
| 105 | + assert sub_deny_all is not None
|
|
| 106 | + sub_deny_all.set_enabled(online)
|
|
| 107 | + |
|
| 94 | 108 | sub_block = app.window.lookup_action(
|
| 95 | 109 | f'subscription-block-{self._account}')
|
| 96 | 110 | assert sub_block is not None
|
| ... | ... | @@ -105,6 +119,7 @@ def _remove_actions(self) -> None: |
| 105 | 119 | actions = [
|
| 106 | 120 | 'subscription-accept',
|
| 107 | 121 | 'subscription-deny',
|
| 122 | + 'subscription-deny-all',
|
|
| 108 | 123 | 'subscription-block',
|
| 109 | 124 | 'subscription-report',
|
| 110 | 125 | ]
|
| ... | ... | @@ -165,6 +180,17 @@ def _on_subscription_deny(self, |
| 165 | 180 | if row is not None:
|
| 166 | 181 | row.destroy()
|
| 167 | 182 | |
| 183 | + def _on_subscription_deny_all(self,
|
|
| 184 | + _action: Gio.SimpleAction,
|
|
| 185 | + _param: GLib.Variant
|
|
| 186 | + ) -> None:
|
|
| 187 | + |
|
| 188 | + for row in cast(list[NotificationRow], self.get_children()):
|
|
| 189 | + if row.type != 'subscribe':
|
|
| 190 | + continue
|
|
| 191 | + self._deny_request(row.jid)
|
|
| 192 | + row.destroy()
|
|
| 193 | + |
|
| 168 | 194 | def _deny_request(self, jid: str) -> None:
|
| 169 | 195 | self._client.get_module('Presence').unsubscribed(jid)
|
| 170 | 196 |