Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

6 changed files:

Changes:

  • gajim/common/jingle_rtp.py
    ... ... @@ -124,7 +124,7 @@ def make_bin_from_config(self, config_key, pipeline, text):
    124 124
             try:
    
    125 125
                 gst_bin = Gst.parse_bin_from_description(pipeline, True)
    
    126 126
                 return gst_bin
    
    127
    -        except GLib.GError as err:
    
    127
    +        except GLib.Error as err:
    
    128 128
                 app.ged.raise_event(
    
    129 129
                     InformationEvent(
    
    130 130
                         conn=self.session.connection,
    

  • gajim/common/preview.py
    ... ... @@ -200,10 +200,7 @@ def _create_session(account: str) -> Tuple[
    200 200
         def _accept_uri(urlparts: ParseResult,
    
    201 201
                         uri: str,
    
    202 202
                         additional_data: AdditionalDataDict) -> bool:
    
    203
    -        try:
    
    204
    -            oob_url = additional_data['gajim']['oob_url']
    
    205
    -        except (KeyError, AttributeError):
    
    206
    -            oob_url = None
    
    203
    +        oob_url = additional_data.get_value('gajim', 'oob_url')
    
    207 204
     
    
    208 205
             # geo
    
    209 206
             if urlparts.scheme == 'geo':
    

  • gajim/gtk/account_page.py
    ... ... @@ -12,12 +12,19 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    +from typing import Any
    
    16
    +
    
    17
    +from gi.repository import Gdk
    
    15 18
     from gi.repository import Gio
    
    16 19
     from gi.repository import Gtk
    
    17 20
     
    
    18 21
     from gajim.common import app
    
    19 22
     from gajim.common import ged
    
    20 23
     from gajim.common.const import AvatarSize
    
    24
    +from gajim.common.events import SubscribePresenceReceived
    
    25
    +from gajim.common.events import UnsubscribedPresenceReceived
    
    26
    +from gajim.common.events import MucInvitation
    
    27
    +from gajim.common.events import MucDecline
    
    21 28
     from gajim.common.i18n import _
    
    22 29
     
    
    23 30
     from .roster import Roster
    
    ... ... @@ -84,22 +91,22 @@ def __init__(self, account: str) -> None:
    84 91
             self.show_all()
    
    85 92
             self.connect('destroy', self._on_destroy)
    
    86 93
     
    
    87
    -    def _on_destroy(self, *args):
    
    94
    +    def _on_destroy(self, *args: Any) -> None:
    
    88 95
             app.check_finalize(self)
    
    89 96
     
    
    90
    -    def _on_edit_profile(self, _button):
    
    97
    +    def _on_edit_profile(self, _button: Gtk.Button) -> None:
    
    91 98
             open_window('ProfileWindow', account=self._account)
    
    92 99
     
    
    93
    -    def _on_account_settings(self, _button):
    
    100
    +    def _on_account_settings(self, _button: Gtk.Button) -> None:
    
    94 101
             window = open_window('AccountsWindow')
    
    95 102
             window.select_account(self._account)
    
    96 103
     
    
    97
    -    def _on_search_changed(self, widget):
    
    104
    +    def _on_search_changed(self, widget: Gtk.SearchEntry) -> None:
    
    98 105
             text = widget.get_text().lower()
    
    99 106
             self._roster.set_search_string(text)
    
    100 107
     
    
    101 108
         @staticmethod
    
    102
    -    def _on_button_release(paned, event):
    
    109
    +    def _on_button_release(paned: Gtk.Paned, event: Gdk.EventButton) -> None:
    
    103 110
             if event.window != paned.get_handle_window():
    
    104 111
                 return
    
    105 112
             position = paned.get_position()
    
    ... ... @@ -120,22 +127,24 @@ def update(self) -> None:
    120 127
     
    
    121 128
             self._status_selector.update()
    
    122 129
     
    
    123
    -    def _subscribe_received(self, event):
    
    130
    +    def _subscribe_received(self, event: SubscribePresenceReceived) -> None:
    
    124 131
             if event.account != self._account:
    
    125 132
                 return
    
    126 133
             self._notification_manager.add_subscription_request(event)
    
    127 134
     
    
    128
    -    def _unsubscribed_received(self, event):
    
    135
    +    def _unsubscribed_received(self,
    
    136
    +                               event: UnsubscribedPresenceReceived
    
    137
    +                               ) -> None:
    
    129 138
             if event.account != self._account:
    
    130 139
                 return
    
    131 140
             self._notification_manager.add_unsubscribed(event)
    
    132 141
     
    
    133
    -    def _muc_invitation_received(self, event):
    
    142
    +    def _muc_invitation_received(self, event: MucInvitation) -> None:
    
    134 143
             if event.account != self._account:
    
    135 144
                 return
    
    136 145
             self._notification_manager.add_invitation_received(event)
    
    137 146
     
    
    138
    -    def _muc_invitation_declined(self, event):
    
    147
    +    def _muc_invitation_declined(self, event: MucDecline) -> None:
    
    139 148
             if event.account != self._account:
    
    140 149
                 return
    
    141 150
             self._notification_manager.add_invitation_declined(event)
    

  • gajim/gtk/filechoosers.py
    ... ... @@ -77,7 +77,7 @@ def _update_preview(self, filechooser):
    77 77
             try:
    
    78 78
                 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
    
    79 79
                     path_to_file, *self._preivew_size)
    
    80
    -        except GLib.GError:
    
    80
    +        except GLib.Error:
    
    81 81
                 preview.clear()
    
    82 82
                 return
    
    83 83
             filechooser.get_preview_widget().set_from_pixbuf(pixbuf)
    

  • gajim/gtk/notification_manager.py
    ... ... @@ -12,6 +12,11 @@
    12 12
     # You should have received a copy of the GNU General Public License
    
    13 13
     # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
    
    14 14
     
    
    15
    +from __future__ import annotations
    
    16
    +from typing import Any
    
    17
    +from typing import Optional
    
    18
    +from typing import Union
    
    19
    +
    
    15 20
     from gi.repository import Gio
    
    16 21
     from gi.repository import GLib
    
    17 22
     from gi.repository import Gtk
    
    ... ... @@ -23,6 +28,10 @@
    23 28
     from gajim.common.const import AvatarSize
    
    24 29
     from gajim.common.i18n import _
    
    25 30
     from gajim.common.events import Notification
    
    31
    +from gajim.common.events import SubscribePresenceReceived
    
    32
    +from gajim.common.events import UnsubscribedPresenceReceived
    
    33
    +from gajim.common.events import MucInvitation
    
    34
    +from gajim.common.events import MucDecline
    
    26 35
     from gajim.common.helpers import get_groupchat_name
    
    27 36
     from gajim.common.helpers import get_muc_context
    
    28 37
     
    
    ... ... @@ -31,7 +40,7 @@
    31 40
     
    
    32 41
     
    
    33 42
     class NotificationManager(Gtk.ListBox):
    
    34
    -    def __init__(self, account):
    
    43
    +    def __init__(self, account: str) -> None:
    
    35 44
             Gtk.ListBox.__init__(self)
    
    36 45
             self._account = account
    
    37 46
             self._client = app.get_client(account)
    
    ... ... @@ -51,10 +60,10 @@ def __init__(self, account):
    51 60
             self._add_actions()
    
    52 61
             self.connect('destroy', self._on_destroy)
    
    53 62
     
    
    54
    -    def _on_destroy(self, *args):
    
    63
    +    def _on_destroy(self, *args: Any) -> None:
    
    55 64
             self._remove_actions()
    
    56 65
     
    
    57
    -    def _add_actions(self):
    
    66
    +    def _add_actions(self) -> None:
    
    58 67
             actions = [
    
    59 68
                 ('subscription-accept', self._on_subscription_accept),
    
    60 69
                 ('subscription-deny', self._on_subscription_deny),
    
    ... ... @@ -68,7 +77,7 @@ def _add_actions(self):
    68 77
                 act.connect('activate', func)
    
    69 78
                 app.window.add_action(act)
    
    70 79
     
    
    71
    -    def update_actions(self):
    
    80
    +    def update_actions(self) -> None:
    
    72 81
             online = app.account_is_connected(self._account)
    
    73 82
             blocking_support = self._client.get_module('Blocking').supported
    
    74 83
     
    
    ... ... @@ -83,7 +92,7 @@ def update_actions(self):
    83 92
                 f'subscription-report-{self._account}').set_enabled(
    
    84 93
                     online and blocking_support)
    
    85 94
     
    
    86
    -    def _remove_actions(self):
    
    95
    +    def _remove_actions(self) -> None:
    
    87 96
             actions = [
    
    88 97
                 'subscription-accept',
    
    89 98
                 'subscription-deny',
    
    ... ... @@ -93,7 +102,10 @@ def _remove_actions(self):
    93 102
             for action in actions:
    
    94 103
                 app.window.remove_action(f'{action}-{self._account}')
    
    95 104
     
    
    96
    -    def _on_subscription_accept(self, _action, param):
    
    105
    +    def _on_subscription_accept(self,
    
    106
    +                                _action: Gio.SimpleAction,
    
    107
    +                                param: GLib.Variant
    
    108
    +                                ) -> None:
    
    97 109
             jid = param.get_string()
    
    98 110
             row = self._get_notification_row(jid)
    
    99 111
             self._client.get_module('Presence').subscribed(jid)
    
    ... ... @@ -102,38 +114,53 @@ def _on_subscription_accept(self, _action, param):
    102 114
             if not contact.is_in_roster:
    
    103 115
                 open_window('AddContact', account=self._account,
    
    104 116
                             jid=jid, nick=contact.name)
    
    105
    -        self.remove(row)
    
    117
    +        if row is not None:
    
    118
    +            self.remove(row)
    
    106 119
     
    
    107
    -    def _on_subscription_block(self, _action, param):
    
    120
    +    def _on_subscription_block(self,
    
    121
    +                               _action: Gio.SimpleAction,
    
    122
    +                               param: GLib.Variant
    
    123
    +                               ) -> None:
    
    108 124
             jid = param.get_string()
    
    109 125
             self._deny_request(jid)
    
    110 126
             self._client.get_module('Blocking').block([jid])
    
    111 127
             row = self._get_notification_row(jid)
    
    112
    -        self.remove(row)
    
    128
    +        if row is not None:
    
    129
    +            self.remove(row)
    
    113 130
     
    
    114
    -    def _on_subscription_report(self, _action, param):
    
    131
    +    def _on_subscription_report(self,
    
    132
    +                                _action: Gio.SimpleAction,
    
    133
    +                                param: GLib.Variant
    
    134
    +                                ) -> None:
    
    115 135
             jid = param.get_string()
    
    116 136
             self._deny_request(jid)
    
    117 137
             self._client.get_module('Blocking').block([jid], report='spam')
    
    118 138
             row = self._get_notification_row(jid)
    
    119
    -        self.remove(row)
    
    139
    +        if row is not None:
    
    140
    +            self.remove(row)
    
    120 141
     
    
    121
    -    def _on_subscription_deny(self, _action, param):
    
    142
    +    def _on_subscription_deny(self,
    
    143
    +                              _action: Gio.SimpleAction,
    
    144
    +                              param: GLib.Variant
    
    145
    +                              ) -> None:
    
    122 146
             jid = param.get_string()
    
    123 147
             self._deny_request(jid)
    
    124 148
             row = self._get_notification_row(jid)
    
    125
    -        self.remove(row)
    
    149
    +        if row is not None:
    
    150
    +            self.remove(row)
    
    126 151
     
    
    127
    -    def _deny_request(self, jid):
    
    152
    +    def _deny_request(self, jid: str) -> None:
    
    128 153
             self._client.get_module('Presence').unsubscribed(jid)
    
    129 154
     
    
    130
    -    def _get_notification_row(self, jid):
    
    131
    -        for child in self.get_children():
    
    132
    -            if child.jid == jid:
    
    133
    -                return child
    
    155
    +    def _get_notification_row(self, jid: str) -> Optional[NotificationRow]:
    
    156
    +        for row in self.get_children():
    
    157
    +            if row.jid == jid:
    
    158
    +                return row
    
    134 159
             return None
    
    135 160
     
    
    136
    -    def add_subscription_request(self, event):
    
    161
    +    def add_subscription_request(self,
    
    162
    +                                 event: SubscribePresenceReceived
    
    163
    +                                 ) -> None:
    
    137 164
             row = self._get_notification_row(event.jid)
    
    138 165
             if row is None:
    
    139 166
                 self.add(SubscriptionRequestRow(
    
    ... ... @@ -152,7 +179,9 @@ def add_subscription_request(self, event):
    152 179
             elif row.type == 'unsubscribed':
    
    153 180
                 self.remove(row)
    
    154 181
     
    
    155
    -    def add_unsubscribed(self, event):
    
    182
    +    def add_unsubscribed(self,
    
    183
    +                         event: UnsubscribedPresenceReceived
    
    184
    +                         ) -> None:
    
    156 185
             row = self._get_notification_row(event.jid)
    
    157 186
             if row is None:
    
    158 187
                 self.add(UnsubscribedRow(self._account, event.jid))
    
    ... ... @@ -170,8 +199,8 @@ def add_unsubscribed(self, event):
    170 199
             elif row.type == 'subscribe':
    
    171 200
                 self.remove(row)
    
    172 201
     
    
    173
    -    def add_invitation_received(self, event):
    
    174
    -        row = self._get_notification_row(event.muc)
    
    202
    +    def add_invitation_received(self, event: MucInvitation) -> None:
    
    203
    +        row = self._get_notification_row(str(event.muc))
    
    175 204
             if row is None:
    
    176 205
                 self.add(InvitationReceivedRow(self._account, event))
    
    177 206
     
    
    ... ... @@ -191,24 +220,25 @@ def add_invitation_received(self, event):
    191 220
                                  title=_('Group Chat Invitation'),
    
    192 221
                                  text=text))
    
    193 222
     
    
    194
    -    def add_invitation_declined(self, event):
    
    195
    -        row = self._get_notification_row(event.muc)
    
    223
    +    def add_invitation_declined(self, event: MucDecline) -> None:
    
    224
    +        row = self._get_notification_row(str(event.muc))
    
    196 225
             if row is None:
    
    197 226
                 self.add(InvitationDeclinedRow(self._account, event))
    
    198 227
     
    
    199 228
     
    
    200 229
     class NotificationRow(Gtk.ListBoxRow):
    
    201
    -    def __init__(self, account, jid):
    
    230
    +    def __init__(self, account: str, jid: str) -> None:
    
    202 231
             Gtk.ListBoxRow.__init__(self)
    
    203 232
             self._account = account
    
    204 233
             self._client = app.get_client(account)
    
    205 234
             self.jid = jid
    
    235
    +        self.type = ''
    
    206 236
     
    
    207 237
             self.grid = Gtk.Grid(column_spacing=12)
    
    208 238
             self.add(self.grid)
    
    209 239
     
    
    210 240
         @staticmethod
    
    211
    -    def _generate_label():
    
    241
    +    def _generate_label() -> Gtk.Label:
    
    212 242
             label = Gtk.Label()
    
    213 243
             label.set_halign(Gtk.Align.START)
    
    214 244
             label.set_hexpand(True)
    
    ... ... @@ -217,7 +247,7 @@ def _generate_label():
    217 247
             label.set_max_width_chars(30)
    
    218 248
             return label
    
    219 249
     
    
    220
    -    def _generate_avatar_image(self, jid):
    
    250
    +    def _generate_avatar_image(self, jid: Union[str, JID]) -> Gtk.Image:
    
    221 251
             contact = self._client.get_module('Contacts').get_contact(jid)
    
    222 252
             surface = contact.get_avatar(
    
    223 253
                 AvatarSize.ROSTER, self.get_scale_factor(), add_show=False)
    
    ... ... @@ -227,7 +257,12 @@ def _generate_avatar_image(self, jid):
    227 257
     
    
    228 258
     
    
    229 259
     class SubscriptionRequestRow(NotificationRow):
    
    230
    -    def __init__(self, account, jid, text, user_nick=None):
    
    260
    +    def __init__(self,
    
    261
    +                 account: str,
    
    262
    +                 jid: str,
    
    263
    +                 text: str,
    
    264
    +                 user_nick: Optional[str] = None
    
    265
    +                 ) -> None:
    
    231 266
             NotificationRow.__init__(self, account, jid)
    
    232 267
             self.type = 'subscribe'
    
    233 268
     
    
    ... ... @@ -264,7 +299,7 @@ def __init__(self, account, jid, text, user_nick=None):
    264 299
             more_button = Gtk.MenuButton()
    
    265 300
             more_button.set_valign(Gtk.Align.CENTER)
    
    266 301
             more_button.add(more_image)
    
    267
    -        subscription_menu = get_subscription_menu(self._account, self.jid)
    
    302
    +        subscription_menu = get_subscription_menu(self._account, str(self.jid))
    
    268 303
             more_button.set_menu_model(subscription_menu)
    
    269 304
             self.grid.attach(more_button, 4, 1, 1, 2)
    
    270 305
     
    
    ... ... @@ -272,7 +307,7 @@ def __init__(self, account, jid, text, user_nick=None):
    272 307
     
    
    273 308
     
    
    274 309
     class UnsubscribedRow(NotificationRow):
    
    275
    -    def __init__(self, account, jid):
    
    310
    +    def __init__(self, account: str, jid: str) -> None:
    
    276 311
             NotificationRow.__init__(self, account, jid)
    
    277 312
             self.type = 'unsubscribed'
    
    278 313
     
    
    ... ... @@ -310,13 +345,13 @@ def __init__(self, account, jid):
    310 345
     
    
    311 346
             self.show_all()
    
    312 347
     
    
    313
    -    def _on_dismiss(self, _button):
    
    348
    +    def _on_dismiss(self, _button: Gtk.Button) -> None:
    
    314 349
             self.destroy()
    
    315 350
     
    
    316 351
     
    
    317 352
     class InvitationReceivedRow(NotificationRow):
    
    318
    -    def __init__(self, account, event):
    
    319
    -        NotificationRow.__init__(self, account, event.muc)
    
    353
    +    def __init__(self, account: str, event: MucInvitation) -> None:
    
    354
    +        NotificationRow.__init__(self, account, str(event.muc))
    
    320 355
             self.type = 'invitation-received'
    
    321 356
     
    
    322 357
             self._event = event
    
    ... ... @@ -358,21 +393,21 @@ def __init__(self, account, event):
    358 393
     
    
    359 394
             self.show_all()
    
    360 395
     
    
    361
    -    def _on_show_invitation(self, _button):
    
    396
    +    def _on_show_invitation(self, _button: Gtk.Button) -> None:
    
    362 397
             open_window('GroupChatInvitation',
    
    363 398
                         account=self._account,
    
    364 399
                         event=self._event)
    
    365 400
             self.destroy()
    
    366 401
     
    
    367
    -    def _on_decline_invitation(self, _button):
    
    402
    +    def _on_decline_invitation(self, _button: Gtk.Button) -> None:
    
    368 403
             self._client.get_module('MUC').decline(
    
    369 404
                 self.jid, self._event.from_)
    
    370 405
             self.destroy()
    
    371 406
     
    
    372 407
     
    
    373 408
     class InvitationDeclinedRow(NotificationRow):
    
    374
    -    def __init__(self, account, event):
    
    375
    -        NotificationRow.__init__(self, account, event.muc)
    
    409
    +    def __init__(self, account: str, event: MucDecline) -> None:
    
    410
    +        NotificationRow.__init__(self, account, str(event.muc))
    
    376 411
             self.type = 'invitation-declined'
    
    377 412
     
    
    378 413
             jid = event.from_.bare
    
    ... ... @@ -407,5 +442,5 @@ def __init__(self, account, event):
    407 442
     
    
    408 443
             self.show_all()
    
    409 444
     
    
    410
    -    def _on_dismiss(self, _button):
    
    445
    +    def _on_dismiss(self, _button: Gtk.Button) -> None:
    
    411 446
             self.destroy()

  • gajim/gtk/util.py
    ... ... @@ -145,7 +145,7 @@ def nick_matching(nick: str) -> bool:
    145 145
             return matches + other_nicks
    
    146 146
     
    
    147 147
     
    
    148
    -def set_urgency_hint(window: Any, setting: bool) -> None:
    
    148
    +def set_urgency_hint(window: Gtk.Window, setting: bool) -> None:
    
    149 149
         if app.settings.get('use_urgency_hint'):
    
    150 150
             window.set_urgency_hint(setting)
    
    151 151
     
    
    ... ... @@ -205,9 +205,9 @@ def load_icon_pixbuf(icon_name: str,
    205 205
         return icon_info.load_icon()
    
    206 206
     
    
    207 207
     
    
    208
    -def get_app_icon_list(scale_widget: Any) -> List[GdkPixbuf.Pixbuf]:
    
    208
    +def get_app_icon_list(scale_widget: Gtk.Widget) -> list[GdkPixbuf.Pixbuf]:
    
    209 209
         scale = scale_widget.get_scale_factor()
    
    210
    -    pixbufs = []
    
    210
    +    pixbufs: list[GdkPixbuf.Pixbuf] = []
    
    211 211
         for size in (16, 32, 48, 64, 128):
    
    212 212
             pixbuf = load_icon_pixbuf('org.gajim.Gajim', size=size, scale=scale)
    
    213 213
             if pixbuf is not None:
    
    ... ... @@ -247,8 +247,8 @@ def load_user_iconsets() -> None:
    247 247
             icon_theme.append_search_path(str(path))
    
    248 248
     
    
    249 249
     
    
    250
    -def get_available_iconsets() -> List[str]:
    
    251
    -    iconsets = []
    
    250
    +def get_available_iconsets() -> list[str]:
    
    251
    +    iconsets: list[str] = []
    
    252 252
         for iconset in GajimIconSet:
    
    253 253
             iconsets.append(iconset.value)
    
    254 254
     
    
    ... ... @@ -263,7 +263,7 @@ def get_available_iconsets() -> List[str]:
    263 263
         return iconsets
    
    264 264
     
    
    265 265
     
    
    266
    -def get_total_screen_geometry() -> Tuple[int, int]:
    
    266
    +def get_total_screen_geometry() -> tuple[int, int]:
    
    267 267
         total_width = 0
    
    268 268
         total_height = 0
    
    269 269
         display = Gdk.Display.get_default()
    
    ... ... @@ -630,7 +630,7 @@ def get_pixbuf_from_data(file_data: bytes) -> Optional[GdkPixbuf.Pixbuf]:
    630 630
             pixbufloader.write(file_data)
    
    631 631
             pixbufloader.close()
    
    632 632
             pixbuf = pixbufloader.get_pixbuf()
    
    633
    -    except GLib.GError:
    
    633
    +    except GLib.Error:
    
    634 634
             pixbufloader.close()
    
    635 635
     
    
    636 636
             log.warning('loading avatar using pixbufloader failed, trying to '
    
    ... ... @@ -686,7 +686,7 @@ def load_pixbuf(path: Union[str, Path],
    686 686
             return GdkPixbuf.Pixbuf.new_from_file_at_scale(
    
    687 687
                 str(path), size, size, True)
    
    688 688
     
    
    689
    -    except GLib.GError:
    
    689
    +    except GLib.Error:
    
    690 690
             try:
    
    691 691
                 with open(path, 'rb') as im_handle:
    
    692 692
                     img = Image.open(im_handle)