Philipp Hörist pushed to branch master at gajim / gajim
Commits: c63aa71b by Philipp Hörist at 2022-10-02T19:53:22+02:00 refactor: ChatListRow: Remove unused code
- - - - - 66a6d633 by Philipp Hörist at 2022-10-02T19:59:30+02:00 refactor: ChatListRow: Make row headers private attributes
- - - - - e17cb70d by Philipp Hörist at 2022-10-02T20:06:54+02:00 refactor: ChatListRow: Define signal handlers in builder xml
- - - - - 0f44c5d4 by Philipp Hörist at 2022-10-02T20:09:23+02:00 refactor: ChatListRow: Use Gdk button enums
- - - - - 9019cf24 by Philipp Hörist at 2022-10-02T20:31:59+02:00 refactor: ChatListRow: Move connecting contact signals into own method
- - - - - 84008836 by Philipp Hörist at 2022-10-02T20:38:13+02:00 refactor: ChatListRow: Simplify setting timestamp
- - - - - 447c9d51 by Philipp Hörist at 2022-10-02T20:57:36+02:00 refactor: ChatList: Simplify update time callback
- - - - - 81dbde35 by Philipp Hörist at 2022-10-02T21:03:27+02:00 refactor: ChatList: Sort methods
- - - - - 3c1323e6 by Philipp Hörist at 2022-10-02T21:07:23+02:00 refactor: ChatListRow: Remove unused code
- - - - - 0453e014 by Philipp Hörist at 2022-10-02T21:22:27+02:00 refactor: ChatListRow: Add setter/getter methods for header type
- - - - - 1f2dbcad by Philipp Hörist at 2022-10-02T21:31:46+02:00 refactor: ChatListRow: Simplify row header
- - - - -
4 changed files:
- gajim/common/const.py - gajim/data/gui/chat_list_row.ui - gajim/gtk/chat_list.py - gajim/gtk/chat_list_row.py
Changes:
===================================== gajim/common/const.py ===================================== @@ -51,9 +51,8 @@ class Entity(NamedTuple):
class RowHeaderType(IntEnum): - ACTIVE = 0 - CONVERSATIONS = 1 - PINNED = 2 + CONVERSATIONS = 0 + PINNED = 1
class AvatarSize(IntEnum):
===================================== gajim/data/gui/chat_list_row.ui ===================================== @@ -1,10 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 --> +<!-- Generated with glade 3.40.0 --> <interface> <requires lib="gtk+" version="3.24"/> <object class="GtkEventBox" id="eventbox"> <property name="visible">True</property> <property name="can-focus">False</property> + <signal name="button-press-event" handler="_on_row_button_press_event" swapped="no"/> <child> <object class="GtkBox"> <property name="visible">True</property> @@ -231,6 +232,7 @@ <property name="receives-default">True</property> <property name="valign">center</property> <property name="margin-end">6</property> + <signal name="clicked" handler="_on_close_button_clicked" swapped="no"/> <child> <object class="GtkImage"> <property name="visible">True</property>
===================================== gajim/gtk/chat_list.py ===================================== @@ -99,7 +99,7 @@ def __init__(self, workspace_id: str) -> None: self.connect('drag-data-received', self._on_drag_data_received) self.connect('destroy', self._on_destroy)
- self._timer_id = GLib.timeout_add_seconds(60, self._update_timer) + self._timer_id = GLib.timeout_add_seconds(60, self._update_time)
self.show_all()
@@ -131,11 +131,207 @@ def set_chat_unread_count(self, if chat is not None: chat.unread_count = count
+ def set_filter(self, name: str) -> None: + self._current_filter = name + self.invalidate_filter() + + def set_filter_text(self, text: str) -> None: + self._current_filter_text = text + self.invalidate_filter() + + def get_chat_type(self, account: str, jid: JID) -> Optional[str]: + row = self._chats.get((account, jid)) + if row is not None: + return row.type + return None + + def get_selected_chat(self) -> Optional[ChatListRow]: + row = cast(ChatListRow, self.get_selected_row()) + if row is None: + return None + return row + + def get_open_chats(self) -> OpenChatsSettingT: + open_chats: OpenChatsSettingT = [] + for key, row in self._chats.items(): + account, jid = key + open_chats.append({'account': account, + 'jid': jid, + 'type': row.type, + 'pinned': row.is_pinned, + 'position': row.position}) + return open_chats + def mark_as_read(self, account: str, jid: JID) -> None: chat = self._chats.get((account, jid)) if chat is not None: chat.reset_unread()
+ def toggle_chat_pinned(self, account: str, jid: JID) -> None: + row = self._chats[(account, jid)] + + if row.is_pinned: + self._chat_order.remove(row) + row.position = -1 + else: + self._chat_order.append(row) + row.position = self._chat_order.index(row) + + row.toggle_pinned() + self.invalidate_sort() + + def add_chat(self, + account: str, + jid: JID, + type_: str, + pinned: bool, + position: int + ) -> None: + + key = (account, jid) + if self._chats.get(key) is not None: + # Chat is already in the List + return + + row = ChatListRow(self._workspace_id, + account, + jid, + type_, + pinned, + position) + + self._chats[key] = row + if pinned: + self._chat_order.insert(position, row) + + row.connect('drag-begin', self._on_row_drag_begin) + row.connect('unread-changed', self._on_row_unread_changed) + + self.add(row) + + def select_chat(self, account: str, jid: JID) -> None: + row = self._chats[(account, jid)] + self.select_row(row) + + def select_next_chat(self, direction: Direction, + unread_first: bool = False) -> None: + # Selects the next chat, but prioritizes chats with unread messages. + row = self.get_selected_chat() + if row is None: + row = self.get_row_at_index(0) + if row is None: + return + assert isinstance(row, ChatListRow) + self.select_chat(row.account, row.jid) + return + + unread_found = False + if unread_first: + index = row.get_index() + current = index + + # Loop until finding a chat with unread count or completing a cycle + while True: + if direction == Direction.NEXT: + index += 1 + if index >= len(self.get_children()): + index = 0 + else: + index -= 1 + if index < 0: + index = len(self.get_children()) - 1 + + row = self.get_row_at_index(index) + if row is None: + return + assert isinstance(row, ChatListRow) + if row.unread_count > 0: + unread_found = True + break + if index == current: + break + + if unread_found: + self.select_chat(row.account, row.jid) + return + + index = row.get_index() + if direction == Direction.NEXT: + next_row = self.get_row_at_index(index + 1) + else: + next_row = self.get_row_at_index(index - 1) + if next_row is None: + if direction == Direction.NEXT: + next_row = self.get_row_at_index(0) + else: + last = len(self.get_children()) - 1 + next_row = self.get_row_at_index(last) + assert isinstance(next_row, ChatListRow) + self.select_chat(next_row.account, next_row.jid) + return + + assert isinstance(next_row, ChatListRow) + self.select_chat(next_row.account, next_row.jid) + + def select_chat_number(self, number: int) -> None: + row = self.get_row_at_index(number) + if row is not None: + assert isinstance(row, ChatListRow) + self.select_chat(row.account, row.jid) + + def remove_chat(self, + account: str, + jid: JID, + emit_unread: bool = True + ) -> None: + + row = self._chats.pop((account, jid)) + if row.is_pinned: + self._chat_order.remove(row) + self.remove(row) + row.destroy() + if emit_unread: + self._emit_unread_changed() + + def remove_chats_for_account(self, account: str) -> None: + for row_account, jid in list(self._chats.keys()): + if row_account != account: + continue + self.remove_chat(account, jid) + self._emit_unread_changed() + + def contains_chat(self, account: str, jid: JID) -> bool: + return self._chats.get((account, jid)) is not None + + def process_event(self, event: events.ChatListEventT) -> None: + if isinstance(event, (events.MessageReceived, + events.MamMessageReceived, + events.GcMessageReceived)): + self._on_message_received(event) + elif isinstance(event, events.MessageUpdated): + self._on_message_updated(event) + elif isinstance(event, events.MessageModerated): + self._on_message_moderated(event) + elif isinstance(event, events.PresenceReceived): + self._on_presence_received(event) + elif isinstance(event, events.MessageSent): + self._on_message_sent(event) + elif isinstance(event, events.JingleRequestReceived): + self._on_jingle_request_received(event) + elif isinstance(event, events.FileRequestReceivedEvent): # pyright: ignore [reportUnnecessaryIsInstance] # noqa + self._on_file_request_received(event) + else: + log.warning('Unhandled Event: %s', event.name) + + def _set_placeholder(self) -> None: + button = Gtk.Button.new_with_label(_('Start Chat')) + button.get_style_context().add_class('suggested-action') + button.set_halign(Gtk.Align.CENTER) + button.set_valign(Gtk.Align.CENTER) + button.connect('clicked', self._on_start_chat_clicked) + button.show() + self.set_placeholder(button) + def _emit_unread_changed(self) -> None: count = self.get_unread_count() chat_list = self.get_parent() @@ -239,11 +435,9 @@ def _change_pinned_order(self, row_before: Optional[ChatListRow]) -> None: self.emit('chat-order-changed') self.invalidate_sort()
- def _on_destroy(self, _widget: Gtk.Widget) -> None: - GLib.source_remove(self._timer_id) - - def _update_timer(self) -> bool: - self.update_time() + def _update_time(self) -> bool: + for _key, row in self._chats.items(): + row.update_time() return True
def _filter_func(self, row: ChatListRow) -> bool: @@ -263,28 +457,20 @@ def _filter_func(self, row: ChatListRow) -> bool: def _header_func(row: ChatListRow, before: ChatListRow) -> None: if before is None: if row.is_pinned: - row.header = RowHeaderType.PINNED - # elif row.is_active(): - # row.header = RowHeaderType.ACTIVE + row.set_header_type(RowHeaderType.PINNED) else: - row.header = None + row.set_header_type(None) else: if row.is_pinned: if before.is_pinned: - row.header = None + row.set_header_type(None) else: - row.header = RowHeaderType.PINNED - # elif row.is_active(): - # if before.is_active() and not before.is_pinned: - # row.header = None - # else: - # row.header = RowHeaderType.ACTIVE + row.set_header_type(RowHeaderType.PINNED) else: - # if before.is_active() or before.is_pinned: if before.is_pinned: - row.header = RowHeaderType.CONVERSATIONS + row.set_header_type(RowHeaderType.CONVERSATIONS) else: - row.header = None + row.set_header_type(None)
def _sort_func(self, row1: ChatListRow, row2: ChatListRow) -> int: if self._mouseover: @@ -319,209 +505,43 @@ def _on_mouse_focus_changed(self, # Not hovering a Gtk.ListBoxRow (row is INFERIOR) self._mouseover = False
- def _set_placeholder(self) -> None: - button = Gtk.Button.new_with_label(_('Start Chat')) - button.get_style_context().add_class('suggested-action') - button.set_halign(Gtk.Align.CENTER) - button.set_valign(Gtk.Align.CENTER) - button.connect('clicked', self._on_start_chat_clicked) - button.show() - self.set_placeholder(button) - @staticmethod def _on_start_chat_clicked(_button: Gtk.Button) -> None: app.app.activate_action('start-chat', GLib.Variant('as', ['', '']))
- def set_filter(self, name: str) -> None: - self._current_filter = name - self.invalidate_filter() - - def set_filter_text(self, text: str) -> None: - self._current_filter_text = text - self.invalidate_filter() - - def get_chat_type(self, account: str, jid: JID) -> Optional[str]: - row = self._chats.get((account, jid)) - if row is not None: - return row.type - return None - - def add_chat(self, - account: str, - jid: JID, - type_: str, - pinned: bool, - position: int - ) -> None: - - key = (account, jid) - if self._chats.get(key) is not None: - # Chat is already in the List - return - - row = ChatListRow(self._workspace_id, - account, - jid, - type_, - pinned, - position) - - self._chats[key] = row - if pinned: - self._chat_order.insert(position, row) - - row.connect('drag-begin', self._on_row_drag_begin) - row.connect('unread-changed', self._on_row_unread_changed) - - self.add(row) - - def select_chat(self, account: str, jid: JID) -> None: - row = self._chats[(account, jid)] - self.select_row(row) + @staticmethod + def _get_nick_for_received_message(event: MessageEventT) -> str: + nick = _('Me') + if event.properties.type.is_groupchat: + event_nick = event.properties.muc_nickname + our_nick = get_group_chat_nick(event.account, event.jid) + if event_nick != our_nick: + nick = event_nick + else: + con = app.get_client(event.account) + own_jid = con.get_own_jid() + if not own_jid.bare_match(event.properties.from_): + nick = '' + return nick
- def select_next_chat(self, direction: Direction, - unread_first: bool = False) -> None: - # Selects the next chat, but prioritizes chats with unread messages. - row = self.get_selected_chat() - if row is None: - row = self.get_row_at_index(0) - if row is None: + @staticmethod + def _add_unread(row: ChatListRow, event: MessageEventT) -> None: + if event.properties.is_carbon_message: + if event.properties.carbon.is_sent: return - assert isinstance(row, ChatListRow) - self.select_chat(row.account, row.jid) - return - - unread_found = False - if unread_first: - index = row.get_index() - current = index - - # Loop until finding a chat with unread count or completing a cycle - while True: - if direction == Direction.NEXT: - index += 1 - if index >= len(self.get_children()): - index = 0 - else: - index -= 1 - if index < 0: - index = len(self.get_children()) - 1
- row = self.get_row_at_index(index) - if row is None: - return - assert isinstance(row, ChatListRow) - if row.unread_count > 0: - unread_found = True - break - if index == current: - break - - if unread_found: - self.select_chat(row.account, row.jid) + if event.properties.is_from_us(): + # Last message was from us (1:1), reset counter + row.reset_unread() return
- index = row.get_index() - if direction == Direction.NEXT: - next_row = self.get_row_at_index(index + 1) - else: - next_row = self.get_row_at_index(index - 1) - if next_row is None: - if direction == Direction.NEXT: - next_row = self.get_row_at_index(0) - else: - last = len(self.get_children()) - 1 - next_row = self.get_row_at_index(last) - assert isinstance(next_row, ChatListRow) - self.select_chat(next_row.account, next_row.jid) + our_nick = get_group_chat_nick(event.account, event.jid) + if event.properties.muc_nickname == our_nick: + # Last message was from us (MUC), reset counter + row.reset_unread() return
- assert isinstance(next_row, ChatListRow) - self.select_chat(next_row.account, next_row.jid) - - def select_chat_number(self, number: int) -> None: - row = self.get_row_at_index(number) - if row is not None: - assert isinstance(row, ChatListRow) - self.select_chat(row.account, row.jid) - - def toggle_chat_pinned(self, account: str, jid: JID) -> None: - row = self._chats[(account, jid)] - - if row.is_pinned: - self._chat_order.remove(row) - row.position = -1 - else: - self._chat_order.append(row) - row.position = self._chat_order.index(row) - - row.toggle_pinned() - self.invalidate_sort() - - def remove_chat(self, - account: str, - jid: JID, - emit_unread: bool = True - ) -> None: - - row = self._chats.pop((account, jid)) - if row.is_pinned: - self._chat_order.remove(row) - self.remove(row) - row.destroy() - if emit_unread: - self._emit_unread_changed() - - def remove_chats_for_account(self, account: str) -> None: - for row_account, jid in list(self._chats.keys()): - if row_account != account: - continue - self.remove_chat(account, jid) - self._emit_unread_changed() - - def get_selected_chat(self) -> Optional[ChatListRow]: - row = cast(ChatListRow, self.get_selected_row()) - if row is None: - return None - return row - - def contains_chat(self, account: str, jid: JID) -> bool: - return self._chats.get((account, jid)) is not None - - def get_open_chats(self) -> OpenChatsSettingT: - open_chats: OpenChatsSettingT = [] - for key, row in self._chats.items(): - account, jid = key - open_chats.append({'account': account, - 'jid': jid, - 'type': row.type, - 'pinned': row.is_pinned, - 'position': row.position}) - return open_chats - - def update_time(self) -> None: - for _key, row in self._chats.items(): - row.update_time() - - def process_event(self, event: events.ChatListEventT) -> None: - if isinstance(event, (events.MessageReceived, - events.MamMessageReceived, - events.GcMessageReceived)): - self._on_message_received(event) - elif isinstance(event, events.MessageUpdated): - self._on_message_updated(event) - elif isinstance(event, events.MessageModerated): - self._on_message_moderated(event) - elif isinstance(event, events.PresenceReceived): - self._on_presence_received(event) - elif isinstance(event, events.MessageSent): - self._on_message_sent(event) - elif isinstance(event, events.JingleRequestReceived): - self._on_jingle_request_received(event) - elif isinstance(event, events.FileRequestReceivedEvent): # pyright: ignore [reportUnnecessaryIsInstance] # noqa - self._on_file_request_received(event) - else: - log.warning('Unhandled Event: %s', event.name) + row.add_unread(event.msgtxt)
def _on_message_received(self, event: MessageEventT) -> None: if not event.msgtxt: @@ -546,21 +566,6 @@ def _on_message_received(self, event: MessageEventT) -> None: self._add_unread(row, event) row.changed()
- @staticmethod - def _get_nick_for_received_message(event: MessageEventT) -> str: - nick = _('Me') - if event.properties.type.is_groupchat: - event_nick = event.properties.muc_nickname - our_nick = get_group_chat_nick(event.account, event.jid) - if event_nick != our_nick: - nick = event_nick - else: - con = app.get_client(event.account) - own_jid = con.get_own_jid() - if not own_jid.bare_match(event.properties.from_): - nick = '' - return nick - def _on_message_updated(self, event: events.MessageUpdated) -> None: row = self._chats.get((event.account, JID.from_string(event.jid))) if row is None: @@ -640,25 +645,6 @@ def _on_file_request_received(self, row.set_message_text( _('File'), icon_name='text-x-generic-symbolic')
- @staticmethod - def _add_unread(row: ChatListRow, event: MessageEventT) -> None: - if event.properties.is_carbon_message: - if event.properties.carbon.is_sent: - return - - if event.properties.is_from_us(): - # Last message was from us (1:1), reset counter - row.reset_unread() - return - - our_nick = get_group_chat_nick(event.account, event.jid) - if event.properties.muc_nickname == our_nick: - # Last message was from us (MUC), reset counter - row.reset_unread() - return - - row.add_unread(event.msgtxt) - def _on_account_changed(self, *args: Any) -> None: rows = cast(list[ChatListRow], self.get_children()) for row in rows: @@ -668,3 +654,6 @@ def _on_bookmarks_received(self, _event: events.BookmarksReceived) -> None: rows = cast(list[ChatListRow], self.get_children()) for row in rows: row.update_name() + + def _on_destroy(self, _widget: Gtk.Widget) -> None: + GLib.source_remove(self._timer_id)
===================================== gajim/gtk/chat_list_row.py ===================================== @@ -78,39 +78,19 @@ def __init__(self, self.type = type_ self.position = position
- self.active_label = ActiveHeader() - self.conversations_label = ConversationsHeader() - self.pinned_label = PinnedHeader() + self._conversations_header = RowHeader(RowHeaderType.CONVERSATIONS) + self._pinned_header = RowHeader(RowHeaderType.PINNED)
self._client = app.get_client(account) - self.contact = self._client.get_module('Contacts').get_contact(jid) - - if isinstance(self.contact, BareContact): - self.contact.connect('presence-update', self._on_presence_update) - self.contact.connect('chatstate-update', self._on_chatstate_update) - self.contact.connect('nickname-update', self._on_nickname_update) - self.contact.connect('caps-update', self._on_avatar_update) - self.contact.connect('avatar-update', self._on_avatar_update) - - elif isinstance(self.contact, GroupchatContact): - self.contact.connect('avatar-update', self._on_avatar_update)
- elif isinstance(self.contact, GroupchatParticipant): - self.contact.connect('chatstate-update', self._on_chatstate_update) - self.contact.connect('user-joined', self._on_muc_user_update) - self.contact.connect('user-left', self._on_muc_user_update) - self.contact.connect('user-avatar-update', self._on_muc_user_update) - self.contact.connect('user-status-show-changed', - self._on_muc_user_update) - - self.contact.room.connect('room-left', self._on_muc_update) - self.contact.room.connect('room-destroyed', self._on_muc_update) - self.contact.room.connect('room-kicked', self._on_muc_update) + self.contact = self._client.get_module('Contacts').get_contact(jid) + self._connect_contact_signals()
self.contact_name: str = self.contact.name self.timestamp: float = 0 self.stanza_id: Optional[str] = None self.message_id: Optional[str] = None + self._unread_count: int = 0 self._needs_muc_highlight: bool = False self._pinned: bool = pinned @@ -118,12 +98,11 @@ def __init__(self, self.get_style_context().add_class('chatlist-row')
self._ui = get_builder('chat_list_row.ui') + self._ui.connect_signals(self) self.add(self._ui.eventbox)
self.connect('state-flags-changed', self._on_state_flags_changed) self.connect('destroy', self._on_destroy) - self._ui.eventbox.connect('button-press-event', self._on_button_press) - self._ui.close_button.connect('clicked', self._on_close_button_clicked)
# Drag and Drop entries = [Gtk.TargetEntry.new( @@ -188,9 +167,7 @@ def __init__(self, nickname=me_nickname, additional_data=line.additional_data)
- self.timestamp = line.time - uf_timestamp = get_uf_relative_time(line.time) - self._ui.timestamp_label.set_text(uf_timestamp) + self.set_timestamp(line.time)
self.stanza_id = line.stanza_id self.message_id = line.message_id @@ -199,41 +176,16 @@ def __init__(self, KindConstant.FILE_TRANSFER_OUTGOING): self.set_message_text( _('File'), icon_name='text-x-generic-symbolic') - self.timestamp = line.time - uf_timestamp = get_uf_relative_time(line.time) - self._ui.timestamp_label.set_text(uf_timestamp) + self.set_timestamp(line.time)
if line.kind in (KindConstant.CALL_INCOMING, KindConstant.CALL_OUTGOING): self.set_message_text( _('Call'), icon_name='call-start-symbolic') - self.timestamp = line.time - uf_timestamp = get_uf_relative_time(line.time) - self._ui.timestamp_label.set_text(uf_timestamp) + self.set_timestamp(line.time)
self.show_all()
- @property - def header(self) -> Optional[RowHeaderType]: - header = self.get_header() - if header is None: - return None - assert isinstance(header, BaseHeader) - return header.type - - @header.setter - def header(self, type_: Optional[RowHeaderType]) -> None: - if type_ == self.header: - return - if type_ is None: - self.set_header(None) - elif type_ is RowHeaderType.PINNED: - self.set_header(self.pinned_label) - elif type_ == RowHeaderType.ACTIVE: - self.set_header(self.active_label) - else: - self.set_header(self.conversations_label) - @property def is_pinned(self) -> bool: return self._pinned @@ -243,12 +195,6 @@ def is_active(self) -> bool: return (self.is_selected() and self.get_toplevel().get_property('is-active'))
- @property - def is_recent(self) -> bool: - if self._unread_count: - return True - return False - @property def unread_count(self) -> int: if (self.contact.is_groupchat and not self.contact.can_notify() and @@ -262,6 +208,26 @@ def unread_count(self, value: int) -> None: self._update_unread() self.emit('unread-changed')
+ def get_header_type(self) -> Optional[RowHeaderType]: + header = self.get_header() + if header is None: + return None + assert isinstance(header, RowHeader) + return header.type + + def set_header_type(self, header_type: Optional[RowHeaderType]) -> None: + if header_type == self.get_header_type(): + return + + if header_type is None: + self.set_header(None) + + elif header_type == RowHeaderType.PINNED: + self.set_header(self._pinned_header) + + else: + self.set_header(self._conversations_header) + def set_message_id(self, message_id: str) -> None: self.message_id = message_id
@@ -308,7 +274,7 @@ def get_real_unread_count(self) -> int: def set_stanza_id(self, stanza_id: str) -> None: self.stanza_id = stanza_id
- def set_timestamp(self, timestamp: int) -> None: + def set_timestamp(self, timestamp: float) -> None: self.timestamp = timestamp self.update_time()
@@ -418,13 +384,15 @@ def _on_close_button_clicked(self, _button: Gtk.Button) -> None: 'remove-chat', GLib.Variant('as', [self.account, str(self.jid)]))
- def _on_button_press(self, - _widget: Gtk.Widget, - event: Gdk.EventButton - ) -> None: - if event.button == 3: # right click + def _on_row_button_press_event(self, + _widget: Gtk.EventBox, + event: Gdk.EventButton + ) -> None: + + if event.button == Gdk.BUTTON_SECONDARY: self._popup_menu(event) - elif event.button == 2: # middle click + + elif event.button == Gdk.BUTTON_MIDDLE: app.window.activate_action( 'remove-chat', GLib.Variant('as', [self.account, str(self.jid)])) @@ -472,6 +440,32 @@ def _on_drag_data_get(self, byte_data = pickle.dumps((self.account, self.jid)) selection_data.set(drop_type, 8, byte_data)
+ def _connect_contact_signals(self) -> None: + if isinstance(self.contact, BareContact): + self.contact.connect('presence-update', self._on_presence_update) + self.contact.connect('chatstate-update', self._on_chatstate_update) + self.contact.connect('nickname-update', self._on_nickname_update) + self.contact.connect('caps-update', self._on_avatar_update) + self.contact.connect('avatar-update', self._on_avatar_update) + + elif isinstance(self.contact, GroupchatContact): + self.contact.connect('avatar-update', self._on_avatar_update) + + elif isinstance(self.contact, GroupchatParticipant): + self.contact.connect('chatstate-update', self._on_chatstate_update) + self.contact.connect('user-joined', self._on_muc_user_update) + self.contact.connect('user-left', self._on_muc_user_update) + self.contact.connect('user-avatar-update', self._on_muc_user_update) + self.contact.connect('user-status-show-changed', + self._on_muc_user_update) + + self.contact.room.connect('room-left', self._on_muc_update) + self.contact.room.connect('room-destroyed', self._on_muc_update) + self.contact.room.connect('room-kicked', self._on_muc_update) + + else: + raise TypeError('Unkown contact type: %s' % type(self.contact)) + def _on_presence_update(self, _contact: ChatContactT, _signal_name: str @@ -514,37 +508,23 @@ def _on_nickname_update(self, self.update_name()
-class BaseHeader(Gtk.Box): - def __init__(self, row_type: RowHeaderType, text: str) -> None: +class RowHeader(Gtk.Box): + def __init__(self, header_type: RowHeaderType) -> None: Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) - self.type = row_type - label = Gtk.Label(label=text) - label.set_halign(Gtk.Align.START) - self.add(label) - self.get_style_context().add_class('header-box') - self.show_all() - - -class ActiveHeader(BaseHeader): + self.type = header_type
- def __init__(self): - BaseHeader.__init__(self, - RowHeaderType.ACTIVE, - _('Active')) - - -class ConversationsHeader(BaseHeader): + if header_type == RowHeaderType.CONVERSATIONS: + text = _('Conversations') + else: + text = _('Pinned')
- def __init__(self): - BaseHeader.__init__(self, - RowHeaderType.CONVERSATIONS, - _('Conversations')) + label = Gtk.Label(label=text) + label.set_halign(Gtk.Align.START)
+ self.add(label)
-class PinnedHeader(BaseHeader): + self.get_style_context().add_class('header-box') + if header_type == RowHeaderType.PINNED: + self.get_style_context().add_class('header-box-first')
- def __init__(self): - BaseHeader.__init__(self, - RowHeaderType.PINNED, - _('Pinned')) - self.get_style_context().add_class('header-box-first') + self.show_all()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/c0b999e0e65d980576b3bf5b45829ad7...