Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
18cd0156
by lovetox at 2022-01-04T22:18:26+01:00
-
93216c47
by lovetox at 2022-01-04T22:20:10+01:00
-
4d430d23
by lovetox at 2022-01-04T23:44:10+01:00
4 changed files:
Changes:
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 |
from gajim.common.events import PlainConnection
|
| 42 | 42 |
from gajim.common.events import ShowChanged
|
| 43 | 43 |
from gajim.common.events import SignedIn
|
| 44 |
-from gajim.common.events import SimpleNotification
|
|
| 44 |
+from gajim.common.events import Notification
|
|
| 45 | 45 |
from gajim.common.events import StanzaReceived
|
| 46 | 46 |
from gajim.common.events import StanzaSent
|
| 47 | 47 |
from gajim.common.const import ClientState
|
| ... | ... | @@ -292,10 +292,10 @@ def _on_password(password: str) -> None: |
| 292 | 292 |
on_password=_on_password))
|
| 293 | 293 |
|
| 294 | 294 |
app.ged.raise_event(
|
| 295 |
- SimpleNotification(account=self._account,
|
|
| 296 |
- notif_type='connection-failed',
|
|
| 297 |
- title=_('Authentication failed'),
|
|
| 298 |
- text=text or error))
|
|
| 295 |
+ Notification(account=self._account,
|
|
| 296 |
+ notif_type='connection-failed',
|
|
| 297 |
+ title=_('Authentication failed'),
|
|
| 298 |
+ text=text or error))
|
|
| 299 | 299 |
|
| 300 | 300 |
if self._reconnect:
|
| 301 | 301 |
self._after_disconnect()
|
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 |
|
| 15 | 15 |
import typing
|
| 16 | 16 |
from typing import Any
|
| 17 |
+from typing import Union
|
|
| 17 | 18 |
from typing import Optional
|
| 18 | 19 |
from typing import Callable
|
| 19 | 20 |
|
| ... | ... | @@ -88,24 +89,15 @@ class PasswordRequired(ApplicationEvent): |
| 88 | 89 |
class Notification(ApplicationEvent):
|
| 89 | 90 |
name: str = field(init=False, default='notification')
|
| 90 | 91 |
account: str
|
| 91 |
- jid: str
|
|
| 92 | 92 |
notif_type: str
|
| 93 | 93 |
title: str
|
| 94 | 94 |
text: str
|
| 95 |
+ jid: Optional[Union[JID, str]] = None
|
|
| 95 | 96 |
notif_detail: Optional[str] = None
|
| 96 | 97 |
sound: Optional[str] = None
|
| 97 | 98 |
icon_name: Optional[str] = None
|
| 98 | 99 |
|
| 99 | 100 |
|
| 100 |
-@dataclass
|
|
| 101 |
-class SimpleNotification(ApplicationEvent):
|
|
| 102 |
- name: str = field(init=False, default='simple-notification')
|
|
| 103 |
- account: str
|
|
| 104 |
- notif_type: str
|
|
| 105 |
- title: str
|
|
| 106 |
- text: str
|
|
| 107 |
- |
|
| 108 |
- |
|
| 109 | 101 |
@dataclass
|
| 110 | 102 |
class StanzaSent(ApplicationEvent):
|
| 111 | 103 |
name: str = field(init=False, default='stanza-sent')
|
| ... | ... | @@ -41,8 +41,8 @@ |
| 41 | 41 |
POSTGUI = 110
|
| 42 | 42 |
|
| 43 | 43 |
|
| 44 |
-HandlerFuncT = Callable[[ApplicationEvent], Any]
|
|
| 45 |
-EventHelperHandlersT = list[tuple[str, int, Callable[[ApplicationEvent], Any]]]
|
|
| 44 |
+HandlerFuncT = Callable[[Any], Any]
|
|
| 45 |
+EventHandlerT = tuple[str, int, HandlerFuncT]
|
|
| 46 | 46 |
|
| 47 | 47 |
|
| 48 | 48 |
class GlobalEventsDispatcher:
|
| ... | ... | @@ -112,18 +112,17 @@ def raise_event(self, event_obj: ApplicationEvent) -> Any: |
| 112 | 112 |
|
| 113 | 113 |
class EventHelper:
|
| 114 | 114 |
def __init__(self):
|
| 115 |
- self.__event_handlers: EventHelperHandlersT = []
|
|
| 115 |
+ self.__event_handlers: list[EventHandlerT] = []
|
|
| 116 | 116 |
|
| 117 | 117 |
def register_event(self,
|
| 118 | 118 |
event_name: str,
|
| 119 | 119 |
priority: int,
|
| 120 |
- handler: Callable[[ApplicationEvent], Any]) -> None:
|
|
| 120 |
+ handler: HandlerFuncT) -> None:
|
|
| 121 | 121 |
|
| 122 | 122 |
self.__event_handlers.append((event_name, priority, handler))
|
| 123 | 123 |
app.ged.register_event_handler(event_name, priority, handler)
|
| 124 | 124 |
|
| 125 |
- def register_events(self, events: EventHelperHandlersT) -> None:
|
|
| 126 |
- |
|
| 125 |
+ def register_events(self, events: list[EventHandlerT]) -> None:
|
|
| 127 | 126 |
for handler in events:
|
| 128 | 127 |
self.__event_handlers.append(handler)
|
| 129 | 128 |
app.ged.register_event_handler(*handler)
|
| ... | ... | @@ -131,7 +130,7 @@ def register_events(self, events: EventHelperHandlersT) -> None: |
| 131 | 130 |
def unregister_event(self,
|
| 132 | 131 |
event_name: str,
|
| 133 | 132 |
priority: int,
|
| 134 |
- handler: Callable[[ApplicationEvent], Any]) -> None:
|
|
| 133 |
+ handler: HandlerFuncT) -> None:
|
|
| 135 | 134 |
|
| 136 | 135 |
self.__event_handlers.remove((event_name, priority, handler))
|
| 137 | 136 |
app.ged.register_event_handler(event_name, priority, handler)
|
| ... | ... | @@ -24,9 +24,9 @@ |
| 24 | 24 |
# You should have received a copy of the GNU General Public License
|
| 25 | 25 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 26 | 26 |
|
| 27 |
-from typing import Dict
|
|
| 27 |
+from __future__ import annotations
|
|
| 28 |
+ |
|
| 28 | 29 |
from typing import Optional
|
| 29 |
-from typing import Tuple
|
|
| 30 | 30 |
|
| 31 | 31 |
import sys
|
| 32 | 32 |
import logging
|
| ... | ... | @@ -36,16 +36,14 @@ |
| 36 | 36 |
from gi.repository import Gdk
|
| 37 | 37 |
from gi.repository import GdkPixbuf
|
| 38 | 38 |
from gi.repository import Gtk
|
| 39 |
-from gi.repository import GObject
|
|
| 40 | 39 |
|
| 41 | 40 |
from gajim.common import app
|
| 42 | 41 |
from gajim.common import ged
|
| 42 |
+from gajim.common import events
|
|
| 43 | 43 |
from gajim.common.const import StyleAttr
|
| 44 | 44 |
from gajim.common.i18n import _
|
| 45 | 45 |
from gajim.common.helpers import allow_showing_notification
|
| 46 |
-from gajim.common.helpers import exec_command
|
|
| 47 | 46 |
from gajim.common.helpers import play_sound
|
| 48 |
-from gajim.common.helpers import play_sound_file
|
|
| 49 | 47 |
from gajim.common.ged import EventHelper
|
| 50 | 48 |
|
| 51 | 49 |
from .util import add_css_to_widget
|
| ... | ... | @@ -55,7 +53,8 @@ |
| 55 | 53 |
|
| 56 | 54 |
log = logging.getLogger('gajim.gui.notification')
|
| 57 | 55 |
|
| 58 |
-NOTIFICATION_ICONS: Dict[str, str] = {
|
|
| 56 |
+ |
|
| 57 |
+NOTIFICATION_ICONS: dict[str, str] = {
|
|
| 59 | 58 |
'incoming-message': 'gajim-chat_msg_recv',
|
| 60 | 59 |
'group-chat-invitation': 'gajim-gc_invitation',
|
| 61 | 60 |
'incoming-call': 'call-start-symbolic',
|
| ... | ... | @@ -80,9 +79,7 @@ def __init__(self) -> None: |
| 80 | 79 |
|
| 81 | 80 |
self.register_events([
|
| 82 | 81 |
('notification', ged.GUI2, self._on_notification),
|
| 83 |
- ('simple-notification', ged.GUI2, self._on_notification),
|
|
| 84 |
- ('our-show', ged.GUI2, self._on_our_show),
|
|
| 85 |
- ('connection-lost', ged.GUI2, self._on_connection_lost)
|
|
| 82 |
+ ('our-show', ged.GUI2, self._on_our_show)
|
|
| 86 | 83 |
])
|
| 87 | 84 |
|
| 88 | 85 |
def _detect_dbus_caps(self) -> None:
|
| ... | ... | @@ -93,10 +90,8 @@ def _detect_dbus_caps(self) -> None: |
| 93 | 90 |
self._dbus_available = True
|
| 94 | 91 |
return
|
| 95 | 92 |
|
| 96 |
- def on_proxy_ready(_source: GObject.Object,
|
|
| 97 |
- res: Gio.AsyncResult,
|
|
| 98 |
- _data: Optional[object] = None
|
|
| 99 |
- ) -> None:
|
|
| 93 |
+ def on_proxy_ready(_source: Gio.DBusProxy,
|
|
| 94 |
+ res: Gio.AsyncResult) -> None:
|
|
| 100 | 95 |
try:
|
| 101 | 96 |
proxy = Gio.DBusProxy.new_finish(res)
|
| 102 | 97 |
self._daemon_capabilities = proxy.GetCapabilities()
|
| ... | ... | @@ -116,42 +111,22 @@ def on_proxy_ready(_source: GObject.Object, |
| 116 | 111 |
None,
|
| 117 | 112 |
on_proxy_ready)
|
| 118 | 113 |
|
| 119 |
- def _on_notification(self, event):
|
|
| 120 |
- if hasattr(event, 'jid'):
|
|
| 114 |
+ def _on_notification(self, event: events.Notification) -> None:
|
|
| 115 |
+ if event.jid is not None:
|
|
| 121 | 116 |
jid = str(event.jid)
|
| 122 |
- else:
|
|
| 123 |
- jid = None
|
|
| 124 |
- if hasattr(event, 'command'):
|
|
| 125 |
- # Used by Triggers plugin
|
|
| 126 |
- try:
|
|
| 127 |
- exec_command(event.command, use_shell=True)
|
|
| 128 |
- except Exception:
|
|
| 129 |
- pass
|
|
| 130 |
- |
|
| 131 |
- if hasattr(event, 'sound_file'):
|
|
| 132 |
- # Allow override here, used by Triggers plugin
|
|
| 133 |
- play_sound_file(event.sound_file)
|
|
| 134 |
- elif hasattr(event, 'sound'):
|
|
| 117 |
+ |
|
| 118 |
+ if event.sound is not None:
|
|
| 135 | 119 |
play_sound(event.sound, event.account)
|
| 136 | 120 |
|
| 137 |
- if hasattr(event, 'show_notification'):
|
|
| 138 |
- # Allow override here, used by Triggers plugin
|
|
| 139 |
- if not event.show_notification:
|
|
| 140 |
- return
|
|
| 141 |
- else:
|
|
| 142 |
- if not allow_showing_notification(event.account):
|
|
| 143 |
- return
|
|
| 121 |
+ if not allow_showing_notification(event.account):
|
|
| 122 |
+ return
|
|
| 144 | 123 |
|
| 145 |
- if hasattr(event, 'notif_detail'):
|
|
| 146 |
- notif_detail = event.notif_detail
|
|
| 147 |
- else:
|
|
| 148 |
- notif_detail = event.notif_type
|
|
| 124 |
+ notif_detail = event.notif_detail or event.notif_type
|
|
| 149 | 125 |
|
| 150 |
- if hasattr(event, 'icon_name'):
|
|
| 126 |
+ if event.icon_name is not None:
|
|
| 151 | 127 |
icon_name = event.icon_name
|
| 152 | 128 |
else:
|
| 153 |
- icon_name = NOTIFICATION_ICONS.get(
|
|
| 154 |
- notif_detail, 'mail-unread')
|
|
| 129 |
+ icon_name = NOTIFICATION_ICONS.get(notif_detail, 'mail-unread')
|
|
| 155 | 130 |
|
| 156 | 131 |
self._issue_notification(
|
| 157 | 132 |
event.notif_type,
|
| ... | ... | @@ -162,33 +137,10 @@ def _on_notification(self, event): |
| 162 | 137 |
text=event.text,
|
| 163 | 138 |
icon_name=icon_name)
|
| 164 | 139 |
|
| 165 |
- def _on_simple_notification(self, event):
|
|
| 166 |
- if not allow_showing_notification(event.account):
|
|
| 167 |
- return
|
|
| 168 |
- |
|
| 169 |
- self._issue_notification(
|
|
| 170 |
- event.notif_type,
|
|
| 171 |
- event.account,
|
|
| 172 |
- None,
|
|
| 173 |
- title=event.title,
|
|
| 174 |
- text=event.text)
|
|
| 175 |
- |
|
| 176 |
- def _on_our_show(self, event):
|
|
| 140 |
+ def _on_our_show(self, event: events.ShowChanged) -> None:
|
|
| 177 | 141 |
if app.account_is_connected(event.account):
|
| 178 | 142 |
self._withdraw('connection-failed', event.account)
|
| 179 | 143 |
|
| 180 |
- def _on_connection_lost(self, event):
|
|
| 181 |
- if not allow_showing_notification(event.conn.name):
|
|
| 182 |
- return
|
|
| 183 |
- |
|
| 184 |
- self._issue_notification(
|
|
| 185 |
- 'connection-lost',
|
|
| 186 |
- event.conn.name,
|
|
| 187 |
- None,
|
|
| 188 |
- title=event.title,
|
|
| 189 |
- text=event.msg,
|
|
| 190 |
- icon_name='gajim-connection_lost')
|
|
| 191 |
- |
|
| 192 | 144 |
def _issue_notification(self,
|
| 193 | 145 |
notif_type: str,
|
| 194 | 146 |
account: str,
|
| ... | ... | @@ -375,7 +327,7 @@ def __init__(self, |
| 375 | 327 |
self._timeout_id = GLib.timeout_add_seconds(timeout, self.destroy)
|
| 376 | 328 |
|
| 377 | 329 |
@staticmethod
|
| 378 |
- def _get_window_pos() -> Tuple[int, int]:
|
|
| 330 |
+ def _get_window_pos() -> tuple[int, int]:
|
|
| 379 | 331 |
pos_x = app.settings.get('notification_position_x')
|
| 380 | 332 |
screen_w, screen_h = get_total_screen_geometry()
|
| 381 | 333 |
if pos_x < 0:
|
| ... | ... | @@ -397,6 +349,6 @@ def _on_button_press(self, |
| 397 | 349 |
self._account, self._jid, self._notif_type)
|
| 398 | 350 |
self.destroy()
|
| 399 | 351 |
|
| 400 |
- def _on_destroy(self, *args):
|
|
| 352 |
+ def _on_destroy(self, _widget: Gtk.Window) -> None:
|
|
| 401 | 353 |
if self._timeout_id is not None:
|
| 402 | 354 |
GLib.source_remove(self._timeout_id)
|