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

Commits:

7 changed files:

Changes:

  • gajim/common/modules/contacts.py
    ... ... @@ -280,6 +280,16 @@ def is_in_roster(self):
    280 280
             item = self._module('Roster').get_item(self._jid)
    
    281 281
             return item is not None
    
    282 282
     
    
    283
    +    @property
    
    284
    +    def is_transport(self):
    
    285
    +        disco_info = app.storage.cache.get_last_disco_info(self._jid)
    
    286
    +        if disco_info is None:
    
    287
    +            return False
    
    288
    +        for identity in disco_info.identities:
    
    289
    +            if identity.category == 'gateway':
    
    290
    +                return True
    
    291
    +        return False
    
    292
    +
    
    283 293
         @property
    
    284 294
         def ask(self):
    
    285 295
             return self._get_roster_attr('ask')
    

  • gajim/gtk/contact_info.py
    ... ... @@ -78,8 +78,12 @@ def __init__(self, account, contact, page=None):
    78 78
     
    
    79 79
             if contact.is_in_roster:
    
    80 80
                 self._ui.edit_name_button.show()
    
    81
    -            self._fill_settings_page()
    
    82 81
                 self._fill_groups_page()
    
    82
    +            if contact.is_transport:
    
    83
    +                side_bar_switcher.hide_row('settings')
    
    84
    +                side_bar_switcher.hide_row('devices')
    
    85
    +            else:
    
    86
    +                self._fill_settings_page()
    
    83 87
             else:
    
    84 88
                 side_bar_switcher.hide_row('settings')
    
    85 89
                 side_bar_switcher.hide_row('groups')
    

  • gajim/gtk/groupchat_settings.py
    ... ... @@ -47,7 +47,8 @@ def __init__(self, account, jid):
    47 47
                 Setting(SettingKind.SWITCH,
    
    48 48
                         _('Show Status Changes'),
    
    49 49
                         SettingType.GROUP_CHAT,
    
    50
    -                    'print_status'),
    
    50
    +                    'print_status',
    
    51
    +                    desc=_('For example: "Julia is now online"')),
    
    51 52
     
    
    52 53
                 Setting(SettingKind.SWITCH,
    
    53 54
                         _('Notify on all Messages'),
    

  • gajim/gtk/roster.py
    ... ... @@ -19,7 +19,10 @@
    19 19
     
    
    20 20
     from gajim.gui_menu_builder import get_roster_menu
    
    21 21
     
    
    22
    +from .dialogs import ConfirmationDialog
    
    23
    +from .dialogs import DialogButton
    
    22 24
     from .tooltips import RosterTooltip
    
    25
    +from .service_registration import ServiceRegistration
    
    23 26
     from .util import EventHelper
    
    24 27
     from .util import get_builder
    
    25 28
     
    
    ... ... @@ -111,6 +114,7 @@ def __init__(self, account):
    111 114
         def _add_actions(self):
    
    112 115
             actions = [
    
    113 116
                 ('contact-info', self._on_contact_info),
    
    117
    +            ('modify-transport', self._on_modify_transport),
    
    114 118
                 ('execute-command', self._on_execute_command),
    
    115 119
                 ('block-contact', self._on_block_contact),
    
    116 120
                 ('remove-contact', self._on_remove_contact),
    
    ... ... @@ -135,6 +139,8 @@ def update_actions(self):
    135 139
     
    
    136 140
             app.window.lookup_action(
    
    137 141
                 f'contact-info-{self._account}').set_enabled(online)
    
    142
    +        app.window.lookup_action(
    
    143
    +            f'modify-transport-{self._account}').set_enabled(online)
    
    138 144
             app.window.lookup_action(
    
    139 145
                 f'execute-command-{self._account}').set_enabled(online)
    
    140 146
             app.window.lookup_action(
    
    ... ... @@ -146,6 +152,7 @@ def update_actions(self):
    146 152
         def _remove_actions(self):
    
    147 153
             actions = [
    
    148 154
                 'contact-info',
    
    155
    +            'modify-transport',
    
    149 156
                 'execute-command',
    
    150 157
                 'block-contact',
    
    151 158
                 'remove-contact',
    
    ... ... @@ -258,6 +265,9 @@ def _on_show_offline(self, action, param):
    258 265
         def _on_contact_info(self, _action, param):
    
    259 266
             app.window.contact_info(self._account, param.get_string())
    
    260 267
     
    
    268
    +    def _on_modify_transport(self, _action, param):
    
    269
    +        ServiceRegistration(self._account, param.get_string())
    
    270
    +
    
    261 271
         def _on_execute_command(self, _action, param):
    
    262 272
             app.window.execute_command(self._account, param.get_string())
    
    263 273
     
    
    ... ... @@ -265,7 +275,37 @@ def _on_block_contact(self, _action, param):
    265 275
             app.window.block_contact(self._account, param.get_string())
    
    266 276
     
    
    267 277
         def _on_remove_contact(self, _action, param):
    
    268
    -        app.window.remove_contact(self._account, param.get_string())
    
    278
    +        jid = param.get_string()
    
    279
    +        selected_contact = self._client.get_module('Contacts').get_contact(jid)
    
    280
    +        if selected_contact.is_transport:
    
    281
    +            # Check for transport users in roster and warn about removing the
    
    282
    +            # transport if there are any
    
    283
    +            has_transport_contacts = False
    
    284
    +            for contact in self._client.get_module('Roster').iter_contacts():
    
    285
    +                if contact.jid.domain == selected_contact.jid.domain:
    
    286
    +                    has_transport_contacts = True
    
    287
    +                    break
    
    288
    +            if has_transport_contacts:
    
    289
    +                def _on_remove():
    
    290
    +                    self._client.get_module('Gateway').unsubscribe(
    
    291
    +                        selected_contact.jid)
    
    292
    +                    app.window.remove_contact(self._account, jid)
    
    293
    +
    
    294
    +                ConfirmationDialog(
    
    295
    +                    _('Remove Transport'),
    
    296
    +                    _('Transport \'%s\' will be '
    
    297
    +                      'removed') % selected_contact.name,
    
    298
    +                    _('You will no longer be able to send and receive '
    
    299
    +                      'messages from and to contacts using this transport.'),
    
    300
    +                    [DialogButton.make('Cancel'),
    
    301
    +                     DialogButton.make('Remove',
    
    302
    +                                       callback=_on_remove)],
    
    303
    +                    transient_for=app.window).show()
    
    304
    +            else:
    
    305
    +                _on_remove()
    
    306
    +            return
    
    307
    +
    
    308
    +        app.window.remove_contact(self._account, jid)
    
    269 309
     
    
    270 310
         def _on_roster_row_activated(self, _treeview, path, _column):
    
    271 311
             path = self._modelfilter.convert_path_to_child_path(path)
    
    ... ... @@ -305,7 +345,9 @@ def _on_focus_out(treeview, _param):
    305 345
             treeview.get_selection().unselect_all()
    
    306 346
     
    
    307 347
         def _show_contact_menu(self, jid, treeview, event):
    
    308
    -        menu = get_roster_menu(self._account, jid)
    
    348
    +        contact = self._client.get_module('Contacts').get_contact(jid)
    
    349
    +        menu = get_roster_menu(
    
    350
    +            self._account, jid, transport=contact.is_transport)
    
    309 351
     
    
    310 352
             rectangle = Gdk.Rectangle()
    
    311 353
             rectangle.x = event.x
    
    ... ... @@ -379,6 +421,7 @@ def _initial_draw(self):
    379 421
     
    
    380 422
         def _connect_contact_signals(self, contact):
    
    381 423
             contact.connect('presence-update', self._on_contact_update)
    
    424
    +        contact.connect('caps-update', self._on_contact_update)
    
    382 425
             contact.connect('avatar-update', self._on_contact_update)
    
    383 426
             contact.connect('blocking-update', self._on_contact_update)
    
    384 427
     
    
    ... ... @@ -531,7 +574,9 @@ def _draw_contact_row(self, ref, contact):
    531 574
             self._store[iter_][Column.TEXT] = name
    
    532 575
     
    
    533 576
             surface = contact.get_avatar(
    
    534
    -            AvatarSize.ROSTER, self.get_scale_factor())
    
    577
    +            AvatarSize.ROSTER,
    
    578
    +            self.get_scale_factor(),
    
    579
    +            add_show=bool(not contact.is_transport))
    
    535 580
             self._store[iter_][Column.AVATAR] = surface
    
    536 581
     
    
    537 582
         def _get_total_user_count(self):
    

  • gajim/gtk/tooltips.py
    ... ... @@ -152,7 +152,10 @@ def _populate_grid(self, contact):
    152 152
             scale = self._ui.tooltip_grid.get_scale_factor()
    
    153 153
     
    
    154 154
             # Avatar
    
    155
    -        surface = contact.get_avatar(AvatarSize.TOOLTIP, scale)
    
    155
    +        surface = contact.get_avatar(
    
    156
    +            AvatarSize.TOOLTIP,
    
    157
    +            scale,
    
    158
    +            add_show=bool(not contact.is_transport))
    
    156 159
             self._ui.avatar.set_from_surface(surface)
    
    157 160
             self._ui.avatar.show()
    
    158 161
     
    

  • gajim/gtkgui_helpers.py
    ... ... @@ -122,8 +122,6 @@ def get_possible_button_event(event):
    122 122
         # BUTTON_PRESS event, so pass event.button
    
    123 123
         return event.button
    
    124 124
     
    
    125
    -def destroy_widget(widget):
    
    126
    -    widget.destroy()
    
    127 125
     
    
    128 126
     def scale_with_ratio(size, width, height):
    
    129 127
         if height == width:
    

  • gajim/gui_menu_builder.py
    ... ... @@ -25,94 +25,6 @@
    25 25
     from gajim.common.i18n import _
    
    26 26
     from gajim.common.const import URIType
    
    27 27
     from gajim.common.const import URIAction
    
    28
    -from gajim.gtkgui_helpers import destroy_widget
    
    29
    -
    
    30
    -
    
    31
    -def get_transport_menu(contact, account):
    
    32
    -    # TODO:
    
    33
    -    roster = app.interface.roster
    
    34
    -    jid = contact.jid
    
    35
    -
    
    36
    -    menu = Gtk.Menu()
    
    37
    -
    
    38
    -    # Send single message
    
    39
    -    item = Gtk.MenuItem.new_with_mnemonic(_('Send Single _Message…'))
    
    40
    -    item.connect('activate', roster.on_send_single_message_menuitem_activate,
    
    41
    -                 account, contact)
    
    42
    -    menu.append(item)
    
    43
    -    if app.account_is_disconnected(account):
    
    44
    -        item.set_sensitive(False)
    
    45
    -
    
    46
    -    blocked = False
    
    47
    -    if helpers.jid_is_blocked(account, jid):
    
    48
    -        blocked = True
    
    49
    -
    
    50
    -    item = Gtk.SeparatorMenuItem.new()
    
    51
    -    menu.append(item)
    
    52
    -
    
    53
    -    # Execute Command
    
    54
    -    item = Gtk.MenuItem.new_with_mnemonic(_('E_xecute Command…'))
    
    55
    -    menu.append(item)
    
    56
    -    item.connect('activate', roster.on_execute_command, contact, account,
    
    57
    -                 contact.resource)
    
    58
    -    if app.account_is_disconnected(account):
    
    59
    -        item.set_sensitive(False)
    
    60
    -
    
    61
    -    # Manage Transport submenu
    
    62
    -    item = Gtk.MenuItem.new_with_mnemonic(_('_Manage Transport'))
    
    63
    -    manage_transport_submenu = Gtk.Menu()
    
    64
    -    item.set_submenu(manage_transport_submenu)
    
    65
    -    menu.append(item)
    
    66
    -
    
    67
    -    # Modify Transport
    
    68
    -    item = Gtk.MenuItem.new_with_mnemonic(_('_Modify Transport'))
    
    69
    -    manage_transport_submenu.append(item)
    
    70
    -    item.connect('activate', roster.on_edit_agent, contact, account)
    
    71
    -    if app.account_is_disconnected(account):
    
    72
    -        item.set_sensitive(False)
    
    73
    -
    
    74
    -    # Rename
    
    75
    -    item = Gtk.MenuItem.new_with_mnemonic(_('_Rename…'))
    
    76
    -    manage_transport_submenu.append(item)
    
    77
    -    item.connect('activate', roster.on_rename, 'agent', jid, account)
    
    78
    -    if app.account_is_disconnected(account):
    
    79
    -        item.set_sensitive(False)
    
    80
    -
    
    81
    -    item = Gtk.SeparatorMenuItem.new()
    
    82
    -    manage_transport_submenu.append(item)
    
    83
    -
    
    84
    -    # Block
    
    85
    -    if blocked:
    
    86
    -        item = Gtk.MenuItem.new_with_mnemonic(_('_Unblock'))
    
    87
    -        item.connect('activate', roster.on_unblock, [(contact, account)])
    
    88
    -    else:
    
    89
    -        item = Gtk.MenuItem.new_with_mnemonic(_('_Block'))
    
    90
    -        item.connect('activate', roster.on_block, [(contact, account)])
    
    91
    -
    
    92
    -    manage_transport_submenu.append(item)
    
    93
    -    if app.account_is_disconnected(account):
    
    94
    -        item.set_sensitive(False)
    
    95
    -
    
    96
    -    # Remove
    
    97
    -    item = Gtk.MenuItem.new_with_mnemonic(_('Remo_ve'))
    
    98
    -    manage_transport_submenu.append(item)
    
    99
    -    item.connect('activate', roster.on_remove_agent, [(contact, account)])
    
    100
    -    if app.account_is_disconnected(account):
    
    101
    -        item.set_sensitive(False)
    
    102
    -
    
    103
    -    item = Gtk.SeparatorMenuItem.new()
    
    104
    -    menu.append(item)
    
    105
    -
    
    106
    -    # Information
    
    107
    -    information_menuitem = Gtk.MenuItem.new_with_mnemonic(_('_Information'))
    
    108
    -    menu.append(information_menuitem)
    
    109
    -    information_menuitem.connect('activate', roster.on_info, contact, account)
    
    110
    -    if app.account_is_disconnected(account):
    
    111
    -        information_menuitem.set_sensitive(False)
    
    112
    -
    
    113
    -    menu.connect('selection-done', destroy_widget)
    
    114
    -    menu.show_all()
    
    115
    -    return menu
    
    116 28
     
    
    117 29
     
    
    118 30
     def get_singlechat_menu(control_id, account, jid, type_):
    
    ... ... @@ -408,7 +320,7 @@ def get_conv_context_menu(account, uri):
    408 320
         return menu
    
    409 321
     
    
    410 322
     
    
    411
    -def get_roster_menu(account, jid):
    
    323
    +def get_roster_menu(account, jid, transport=False):
    
    412 324
         if helpers.jid_is_blocked(account, jid):
    
    413 325
             block_label = _('Unblock')
    
    414 326
         else:
    
    ... ... @@ -419,6 +331,8 @@ def get_roster_menu(account, jid):
    419 331
             ('block-contact', block_label),
    
    420 332
             ('remove-contact', _('Remove…')),
    
    421 333
         ]
    
    334
    +    if transport:
    
    335
    +        menu_items.insert(1, ('modify-transport', _('Modify Transport…')))
    
    422 336
     
    
    423 337
         menu = Gio.Menu()
    
    424 338
         for item in menu_items: