Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 2743de11 by wurstsalat at 2022-01-26T20:11:02+01:00 Roster: Typing, fix error
- - - - - ba90f881 by wurstsalat at 2022-01-26T20:11:02+01:00 RosterItemExchange: Typing
- - - - -
3 changed files:
- gajim/common/events.py - gajim/gtk/roster.py - gajim/gtk/roster_item_exchange.py
Changes:
===================================== gajim/common/events.py ===================================== @@ -418,7 +418,7 @@ class RosterItemExchangeEvent(ApplicationEvent): name: str = field(init=False, default='roster-item-exchange') client: 'Client' jid: JID - exchange_items_list: list[str] + exchange_items_list: dict[str, list[str]] action: str
===================================== gajim/gtk/roster.py ===================================== @@ -30,7 +30,7 @@ from gi.repository import Gtk
from nbxmpp import JID -from nbxmpp import Namespace +from nbxmpp.namespaces import Namespace
from gajim.common import app from gajim.common import ged @@ -39,6 +39,8 @@ from gajim.common.const import StyleAttr from gajim.common.const import PresenceShowExt from gajim.common.events import ApplicationEvent +from gajim.common.events import RosterPush +from gajim.common.events import RosterReceived from gajim.common.helpers import event_filter from gajim.common.i18n import _
@@ -358,11 +360,12 @@ def _on_remove_contact(self, if contact.jid.domain == selected_contact.jid.domain: has_transport_contacts = True break - if has_transport_contacts: - def _on_remove(): - self._client.get_module('Gateway').unsubscribe( - selected_contact.jid)
+ def _on_remove(): + self._client.get_module('Gateway').unsubscribe( + selected_contact.jid) + + if has_transport_contacts: ConfirmationDialog( _('Remove Transport'), _('Transport '%s' will be ' @@ -406,6 +409,9 @@ def _on_roster_button_press_event(self, return
path, _, _, _ = pos + if path is None: + return + path = self._modelfilter.convert_path_to_child_path(path) assert path is not None iter_ = self._store.get_iter(path) @@ -524,12 +530,12 @@ def _on_contact_update(self, self._draw_contact(contact)
@event_filter(['account']) - def _on_roster_received(self, _event: ApplicationEvent) -> None: + def _on_roster_received(self, _event: RosterReceived) -> None: self._reset_roster()
@event_filter(['account']) - def _on_roster_push(self, event: ApplicationEvent) -> None: - contact = self._get_contact(event.item.jid) + def _on_roster_push(self, event: RosterPush) -> None: + contact = self._get_contact(str(event.item.jid))
if event.item.subscription == 'remove': contact.disconnect(self) @@ -718,15 +724,15 @@ def _text_cell_data_func(_column: Gtk.TreeViewColumn, has_parent = bool(model.iter_parent(iter_)) style = 'contact' if has_parent else 'group'
- bgcolor = app.css_config.get_value('.gajim-%s-row' % style, + bgcolor = app.css_config.get_value(f'.gajim-{style}-row', StyleAttr.BACKGROUND) renderer.set_property('cell-background', bgcolor)
- color = app.css_config.get_value('.gajim-%s-row' % style, + color = app.css_config.get_value(f'.gajim-{style}-row', StyleAttr.COLOR) renderer.set_property('foreground', color)
- desc = app.css_config.get_font('.gajim-%s-row' % style) + desc = app.css_config.get_font(f'.gajim-{style}-row') renderer.set_property('font-desc', desc)
if not has_parent:
===================================== gajim/gtk/roster_item_exchange.py ===================================== @@ -12,8 +12,12 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import Optional + from gi.repository import Gtk
+from nbxmpp.protocol import JID + from gajim.common import app from gajim.common import i18n from gajim.common.i18n import _ @@ -26,8 +30,13 @@ class RosterItemExchange(Gtk.ApplicationWindow): """ Used when someone sends a Roster Item Exchange suggestion (XEP-0144) """ - def __init__(self, account, action, exchange_list, jid_from, - message_body=None): + def __init__(self, + account: str, + action: str, + exchange_list: dict[str, list[str]], + jid_from: JID, + message_body: Optional[str] = None + ) -> None: Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_position(Gtk.WindowPosition.CENTER) @@ -46,6 +55,7 @@ def __init__(self, account, action, exchange_list, jid_from,
# Set label depending on action contact = self._client.get_module('Contacts').get_contact(jid_from) + type_label = '' if action == 'add': type_label = _('%(name)s (%(jid)s) would like to add some ' 'contacts to your contact list.') % { @@ -75,7 +85,8 @@ def __init__(self, account, action, exchange_list, jid_from, # Columns renderer1 = Gtk.CellRendererToggle() renderer1.set_property('activatable', True) - renderer1.connect('toggled', self._toggled) + renderer1.connect('toggled', self._on_toggled) + title = '' if self._action == 'add': title = _('Add') elif self._action == 'modify': @@ -95,8 +106,9 @@ def __init__(self, account, action, exchange_list, jid_from, -1, _('Groups'), renderer4, text=3)
# Init contacts - self.model = self._ui.items_list_treeview.get_model() - self.model.clear() + self._model = self._ui.items_list_treeview.get_model() + assert isinstance(self._model, Gtk.ListStore) + self._model.clear()
if action == 'add': self._add() @@ -107,12 +119,13 @@ def __init__(self, account, action, exchange_list, jid_from,
self._ui.connect_signals(self)
- def _toggled(self, cell, path): + def _on_toggled(self, cell: Gtk.CellRendererToggle, path: str) -> None: model = self._ui.items_list_treeview.get_model() + assert isinstance(model, Gtk.ListStore) iter_ = model.get_iter(path) model[iter_][0] = not cell.get_active()
- def _add(self): + def _add(self) -> None: for jid in self._exchange_list: contact = self._client.get_module('Contacts').get_contact(jid) name = self._exchange_list[jid][0] @@ -127,12 +140,13 @@ def _add(self): groups = groups + group + ', ' if not contact.is_in_roster: self.show_all() - iter_ = self.model.append() - self.model.set(iter_, 0, True, 1, jid, 2, name, 3, groups) + assert isinstance(self._model, Gtk.ListStore) + iter_ = self._model.append() + self._model.set(iter_, 0, True, 1, jid, 2, name, 3, groups)
self._ui.accept_button.set_label(_('Add'))
- def _modify(self): + def _modify(self) -> None: for jid in self._exchange_list: is_right = True contact = self._client.get_module('Contacts').get_contact(jid) @@ -153,12 +167,13 @@ def _modify(self): groups = groups + group + ', ' if not is_right and contact.is_in_roster: self.show_all() - iter_ = self.model.append() - self.model.set(iter_, 0, True, 1, jid, 2, name, 3, groups) + assert isinstance(self._model, Gtk.ListStore) + iter_ = self._model.append() + self._model.set(iter_, 0, True, 1, jid, 2, name, 3, groups)
self._ui.accept_button.set_label(_('Modify'))
- def _delete(self): + def _delete(self) -> None: for jid in self._exchange_list: contact = self._client.get_module('Contacts').get_contact(jid) name = self._exchange_list[jid][0] @@ -173,13 +188,15 @@ def _delete(self): groups = groups + group + ', ' if contact.is_in_roster: self.show_all() - iter_ = self.model.append() - self.model.set(iter_, 0, True, 1, jid, 2, name, 3, groups) + assert isinstance(self._model, Gtk.ListStore) + iter_ = self._model.append() + self._model.set(iter_, 0, True, 1, jid, 2, name, 3, groups)
self._ui.accept_button.set_label(_('Delete'))
- def _on_accept_button_clicked(self, _widget): + def _on_accept_button_clicked(self, _button: Gtk.Button) -> None: model = self._ui.items_list_treeview.get_model() + assert isinstance(model, Gtk.ListStore) iter_ = model.get_iter_first() if self._action == 'add': count = 0 @@ -198,7 +215,7 @@ def _on_accept_button_clicked(self, _widget): if groups == ['']: groups = [] jid = model[iter_][1] - if app.jid_is_transport(self._jid_from): + if app.jid_is_transport(str(self._jid_from)): self._client.get_module('Presence').automatically_added.append( jid)
@@ -211,7 +228,7 @@ def _on_accept_button_clicked(self, _widget): iter_ = model.iter_next(iter_) InformationDialog(i18n.ngettext('Added %d contact', 'Added %d contacts', - count, count, count)) + count, str(count), str(count))) elif self._action == 'modify': count = 0 while iter_: @@ -244,8 +261,8 @@ def _on_accept_button_clicked(self, _widget): iter_ = model.iter_next(iter_) InformationDialog(i18n.ngettext('Removed %d contact', 'Removed %d contacts', - count, count, count)) + count, str(count), str(count))) self.destroy()
- def _on_cancel_button_clicked(self, _widget): + def _on_cancel_button_clicked(self, _button: Gtk.Button) -> None: self.destroy()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/ed50151e036b8fda6580e2fadeef5b9a...