gajim.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2026
October
September
August
July
June
May
April
March
February
January
2025
December
November
October
September
August
July
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
List overview
Download
Commits
October 2022
----- 2026 -----
October 2026
September 2026
August 2026
July 2026
June 2026
May 2026
April 2026
March 2026
February 2026
January 2026
----- 2025 -----
December 2025
November 2025
October 2025
September 2025
August 2025
July 2025
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
commits@gajim.org
1 participants
208 discussions
Start a n
N
ew thread
[Git][gajim/gajim][master] 2 commits: refactor: Rename ChatRow to ChatListRow
by Philipp Hörist (@lovetox)
02 Oct '22
02 Oct '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 2512903e by Philipp Hörist at 2022-10-02T16:48:00+02:00 refactor: Rename ChatRow to ChatListRow - - - - - e0fea792 by Philipp Hörist at 2022-10-02T16:50:35+02:00 refactor: ChatListRow: Don’t invalid sort if only one row changed - - - - - 3 changed files: - gajim/gtk/chat_list.py - gajim/gtk/chat_list_row.py - gajim/gtk/chat_list_stack.py Changes: ===================================== gajim/gtk/chat_list.py ===================================== @@ -39,7 +39,7 @@ from gajim.common.helpers import get_retraction_text from gajim.common.setting_values import OpenChatsSettingT -from .chat_list_row import ChatRow +from .chat_list_row import ChatListRow from .util import EventHelper @@ -87,8 +87,8 @@ def __init__(self, workspace_id: str) -> None: entries, Gdk.DragAction.MOVE) - self._drag_row: Optional[ChatRow] = None - self._chat_order: list[ChatRow] = [] + self._drag_row: Optional[ChatListRow] = None + self._chat_order: list[ChatListRow] = [] self.register_events([ ('account-enabled', ged.GUI2, self._on_account_changed), @@ -144,32 +144,32 @@ def _emit_unread_changed(self) -> None: self._workspace_id, count) - def _get_row_before(self, row: ChatRow) -> Optional[ChatRow]: + def _get_row_before(self, row: ChatListRow) -> Optional[ChatListRow]: row_before = self.get_row_at_index(row.get_index() - 1) if row_before is None: return - return cast(ChatRow, row_before) + return cast(ChatListRow, row_before) - def _get_row_after(self, row: ChatRow) -> Optional[ChatRow]: + def _get_row_after(self, row: ChatListRow) -> Optional[ChatListRow]: row_after = self.get_row_at_index(row.get_index() + 1) if row_after is None: return - return cast(ChatRow, row_after) + return cast(ChatListRow, row_after) - def _get_last_row(self) -> ChatRow: + def _get_last_row(self) -> ChatListRow: index = len(self.get_children()) - 1 last_row = self.get_row_at_index(index) assert last_row is not None - return cast(ChatRow, last_row) + return cast(ChatListRow, last_row) def _on_row_drag_begin(self, - row: ChatRow, + row: ChatListRow, _drag_context: Gdk.DragContext ) -> None: self._drag_row = row - def _on_row_unread_changed(self, row: ChatRow) -> None: + def _on_row_unread_changed(self, row: ChatListRow) -> None: self._emit_unread_changed() def _on_drag_data_received(self, @@ -193,7 +193,7 @@ def _on_drag_data_received(self, log.debug('Dropped row is not pinned') return - row = cast(ChatRow, self.get_row_at_y(y_coord)) + row = cast(ChatListRow, self.get_row_at_y(y_coord)) if row is not None: alloc = row.get_allocation() hover_row_y = alloc.y @@ -219,7 +219,7 @@ def _on_drag_data_received(self, self._change_pinned_order(row_before) - def _change_pinned_order(self, row_before: Optional[ChatRow]) -> None: + def _change_pinned_order(self, row_before: Optional[ChatListRow]) -> None: assert self._drag_row is not None self._chat_order.remove(self._drag_row) @@ -246,7 +246,7 @@ def _update_timer(self) -> bool: self.update_time() return True - def _filter_func(self, row: ChatRow) -> bool: + def _filter_func(self, row: ChatListRow) -> bool: is_groupchat = row.type == 'groupchat' if self._current_filter == 'chats' and is_groupchat: return False @@ -260,7 +260,7 @@ def _filter_func(self, row: ChatRow) -> bool: return text in row.contact_name.lower() @staticmethod - def _header_func(row: ChatRow, before: ChatRow) -> None: + def _header_func(row: ChatListRow, before: ChatListRow) -> None: if before is None: if row.is_pinned: row.header = RowHeaderType.PINNED @@ -286,7 +286,7 @@ def _header_func(row: ChatRow, before: ChatRow) -> None: else: row.header = None - def _sort_func(self, row1: ChatRow, row2: ChatRow) -> int: + def _sort_func(self, row1: ChatListRow, row2: ChatListRow) -> int: if self._mouseover: log.debug('Mouseover active, don’t sort rows') return 0 @@ -359,12 +359,12 @@ def add_chat(self, # Chat is already in the List return - row = ChatRow(self._workspace_id, - account, - jid, - type_, - pinned, - position) + row = ChatListRow(self._workspace_id, + account, + jid, + type_, + pinned, + position) self._chats[key] = row if pinned: @@ -387,7 +387,7 @@ def select_next_chat(self, direction: Direction, row = self.get_row_at_index(0) if row is None: return - assert isinstance(row, ChatRow) + assert isinstance(row, ChatListRow) self.select_chat(row.account, row.jid) return @@ -410,7 +410,7 @@ def select_next_chat(self, direction: Direction, row = self.get_row_at_index(index) if row is None: return - assert isinstance(row, ChatRow) + assert isinstance(row, ChatListRow) if row.unread_count > 0: unread_found = True break @@ -432,17 +432,17 @@ def select_next_chat(self, direction: Direction, else: last = len(self.get_children()) - 1 next_row = self.get_row_at_index(last) - assert isinstance(next_row, ChatRow) + assert isinstance(next_row, ChatListRow) self.select_chat(next_row.account, next_row.jid) return - assert isinstance(next_row, ChatRow) + 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, ChatRow) + assert isinstance(row, ChatListRow) self.select_chat(row.account, row.jid) def toggle_chat_pinned(self, account: str, jid: JID) -> None: @@ -479,8 +479,8 @@ def remove_chats_for_account(self, account: str) -> None: self.remove_chat(account, jid) self._emit_unread_changed() - def get_selected_chat(self) -> Optional[ChatRow]: - row = cast(ChatRow, self.get_selected_row()) + def get_selected_chat(self) -> Optional[ChatListRow]: + row = cast(ChatListRow, self.get_selected_row()) if row is None: return None return row @@ -544,7 +544,7 @@ def _on_message_received(self, event: MessageEventT) -> None: additional_data=event.additional_data) self._add_unread(row, event) - self.invalidate_sort() + row.changed() @staticmethod def _get_nick_for_received_message(event: MessageEventT) -> str: @@ -605,7 +605,7 @@ def _on_message_sent(self, event: events.MessageSent) -> None: event.message, nickname=app.nicks[event.account], additional_data=event.additional_data) - self.invalidate_sort() + row.changed() def _on_presence_received(self, event: events.PresenceReceived) -> None: row = self._chats.get((event.account, JID.from_string(event.jid))) @@ -641,7 +641,7 @@ def _on_file_request_received(self, _('File'), icon_name='text-x-generic-symbolic') @staticmethod - def _add_unread(row: ChatRow, event: MessageEventT) -> None: + def _add_unread(row: ChatListRow, event: MessageEventT) -> None: if event.properties.is_carbon_message: if event.properties.carbon.is_sent: return @@ -660,11 +660,11 @@ def _add_unread(row: ChatRow, event: MessageEventT) -> None: row.add_unread(event.msgtxt) def _on_account_changed(self, *args: Any) -> None: - rows = cast(list[ChatRow], self.get_children()) + rows = cast(list[ChatListRow], self.get_children()) for row in rows: row.update_account_identifier() def _on_bookmarks_received(self, _event: events.BookmarksReceived) -> None: - rows = cast(list[ChatRow], self.get_children()) + rows = cast(list[ChatListRow], self.get_children()) for row in rows: row.update_name() ===================================== gajim/gtk/chat_list_row.py ===================================== @@ -52,7 +52,7 @@ from .util import GajimPopover -class ChatRow(Gtk.ListBoxRow): +class ChatListRow(Gtk.ListBoxRow): __gsignals__ = { 'unread-changed': ( @@ -268,11 +268,11 @@ def _popup_menu(self, event: Gdk.EventButton): popover.popup() def _on_drag_begin(self, - row: ChatRow, + row: ChatListRow, drag_context: Gdk.DragContext ) -> None: - # Use rendered ChatRow as drag icon + # Use rendered ChatListRow as drag icon alloc = self.get_allocation() surface = cairo.ImageSurface( cairo.Format.ARGB32, alloc.width, alloc.height) @@ -444,7 +444,7 @@ def is_recent(self) -> bool: return False def _on_state_flags_changed(self, - _row: ChatRow, + _row: ChatListRow, _flags: Gtk.StateFlags ) -> None: state = self.get_state_flags() @@ -453,7 +453,7 @@ def _on_state_flags_changed(self, else: self._ui.revealer.set_reveal_child(False) - def _on_destroy(self, _row: ChatRow) -> None: + def _on_destroy(self, _row: ChatListRow) -> None: self.contact.disconnect_all_from_obj(self) if isinstance(self.contact, GroupchatParticipant): self.contact.room.disconnect_all_from_obj(self) ===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -33,7 +33,7 @@ from . import structs from .chat_filter import ChatFilter from .chat_list import ChatList -from .chat_list import ChatRow +from .chat_list import ChatListRow from .dialogs import DialogButton from .dialogs import ConfirmationCheckDialog @@ -120,7 +120,7 @@ def _on_visible_child_name(self, _stack: Gtk.Stack, _param: str) -> None: def get_chatlist(self, workspace_id: str) -> ChatList: return self._chat_lists[workspace_id] - def get_selected_chat(self) -> Optional[ChatRow]: + def get_selected_chat(self) -> Optional[ChatListRow]: chat_list = self.get_current_chat_list() if chat_list is None: return None @@ -171,7 +171,7 @@ def remove_chat_list(self, workspace_id: str) -> None: def _on_row_selected(self, _chat_list: ChatList, - row: Optional[ChatRow] + row: Optional[ChatListRow] ) -> None: if row is None: self.emit('chat-unselected') View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/4a1a317151cad15659c9a0f587e1be6…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/4a1a317151cad15659c9a0f587e1be6…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] refactor: Split ChatRow out into own module
by Philipp Hörist (@lovetox)
02 Oct '22
02 Oct '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 4a1a3171 by Philipp Hörist at 2022-10-02T16:43:52+02:00 refactor: Split ChatRow out into own module - - - - - 3 changed files: - gajim/gtk/chat_list.py - + gajim/gtk/chat_list_row.py - pyrightconfig.json Changes: ===================================== gajim/gtk/chat_list.py ===================================== @@ -21,44 +21,26 @@ import logging import time -import pickle -from gi.repository import Gio from gi.repository import Gdk from gi.repository import GLib from gi.repository import GObject from gi.repository import Gtk -import cairo from nbxmpp import JID from gajim.common import app from gajim.common import ged from gajim.common import events -from gajim.common.const import AvatarSize from gajim.common.const import Direction -from gajim.common.const import KindConstant from gajim.common.const import RowHeaderType from gajim.common.i18n import _ -from gajim.common.helpers import get_groupchat_name from gajim.common.helpers import get_group_chat_nick from gajim.common.helpers import get_retraction_text -from gajim.common.helpers import get_uf_relative_time -from gajim.common.helpers import message_needs_highlight -from gajim.common.helpers import AdditionalDataDict -from gajim.common.preview_helpers import filename_from_uri -from gajim.common.preview_helpers import guess_simple_file_type from gajim.common.setting_values import OpenChatsSettingT -from gajim.common.types import ChatContactT -from gajim.common.types import OneOnOneContactT -from gajim.common.modules.contacts import BareContact -from gajim.common.modules.contacts import GroupchatContact -from gajim.common.modules.contacts import GroupchatParticipant - -from .menus import get_chat_list_row_menu -from .builder import get_builder + +from .chat_list_row import ChatRow from .util import EventHelper -from .util import GajimPopover log = logging.getLogger('gajim.gui.chatlist') @@ -154,9 +136,10 @@ def mark_as_read(self, account: str, jid: JID) -> None: if chat is not None: chat.reset_unread() - def emit_unread_changed(self) -> None: + def _emit_unread_changed(self) -> None: count = self.get_unread_count() - chat_list = cast(ChatList, self.get_parent()) + chat_list = self.get_parent() + assert chat_list is not None chat_list.emit('unread-count-changed', self._workspace_id, count) @@ -179,9 +162,16 @@ def _get_last_row(self) -> ChatRow: assert last_row is not None return cast(ChatRow, last_row) - def set_drag_row(self, row: ChatRow) -> None: + def _on_row_drag_begin(self, + row: ChatRow, + _drag_context: Gdk.DragContext + ) -> None: + self._drag_row = row + def _on_row_unread_changed(self, row: ChatRow) -> None: + self._emit_unread_changed() + def _on_drag_data_received(self, _widget: Gtk.Widget, _drag_context: Gdk.DragContext, @@ -320,6 +310,7 @@ def _on_mouse_focus_changed(self, _widget: Gtk.ListBox, event: Gdk.EventCrossing ) -> None: + if event.type == Gdk.EventType.ENTER_NOTIFY: self._mouseover = True @@ -379,6 +370,9 @@ def add_chat(self, 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: @@ -476,14 +470,14 @@ def remove_chat(self, self.remove(row) row.destroy() if emit_unread: - self.emit_unread_changed() + 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() + self._emit_unread_changed() def get_selected_chat(self) -> Optional[ChatRow]: row = cast(ChatRow, self.get_selected_row()) @@ -674,502 +668,3 @@ def _on_bookmarks_received(self, _event: events.BookmarksReceived) -> None: rows = cast(list[ChatRow], self.get_children()) for row in rows: row.update_name() - - -class ChatRow(Gtk.ListBoxRow): - def __init__(self, - workspace_id: str, - account: str, - jid: JID, - type_: str, - pinned: bool, - position: int - ) -> None: - - Gtk.ListBoxRow.__init__(self) - - self.account = account - self.jid = jid - self.workspace_id = workspace_id - self.type = type_ - self.position = position - - self.active_label = ActiveHeader() - self.conversations_label = ConversationsHeader() - self.pinned_label = PinnedHeader() - - 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_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 - - self.get_style_context().add_class('chatlist-row') - - self._ui = get_builder('chat_list_row.ui') - 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( - 'CHAT_LIST_ITEM', - Gtk.TargetFlags.SAME_APP, - 0)] - self._ui.eventbox.drag_source_set( - Gdk.ModifierType.BUTTON1_MASK, - entries, - Gdk.DragAction.MOVE) - self._ui.eventbox.connect('drag-begin', self._on_drag_begin) - self._ui.eventbox.connect('drag-data-get', self._on_drag_data_get) - - if self.type == 'groupchat': - self._ui.group_chat_indicator.show() - - self.update_avatar() - self.update_name() - self.update_account_identifier() - - if (isinstance(self.contact, GroupchatContact) and - not self.contact.can_notify()): - self._ui.unread_label.get_style_context().add_class( - 'unread-counter-silent') - - # Get last chat message from archive - line = app.storage.archive.get_last_conversation_line(account, jid) - - if line is None: - self.show_all() - return - - if line.message is not None: - message_text = line.message - - if line.additional_data is not None: - retracted_by = line.additional_data.get_value( - 'retracted', 'by') - if retracted_by is not None: - reason = line.additional_data.get_value( - 'retracted', 'reason') - message_text = get_retraction_text( - self.account, retracted_by, reason) - - me_nickname = None - if line.kind in (KindConstant.CHAT_MSG_SENT, - KindConstant.SINGLE_MSG_SENT): - self.set_nick(_('Me')) - me_nickname = app.nicks[account] - - if line.kind == KindConstant.GC_MSG: - our_nick = get_group_chat_nick(account, jid) - if line.contact_name == our_nick: - self.set_nick(_('Me')) - me_nickname = our_nick - else: - self.set_nick(line.contact_name) - me_nickname = line.contact_name - - self.set_message_text( - message_text, - 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.stanza_id = line.stanza_id - self.message_id = line.message_id - - if line.kind in (KindConstant.FILE_TRANSFER_INCOMING, - 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) - - 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.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 - - def _on_button_press(self, - _widget: Gtk.Widget, - event: Gdk.EventButton - ) -> None: - if event.button == 3: # right click - self._popup_menu(event) - elif event.button == 2: # middle click - app.window.activate_action( - 'remove-chat', - GLib.Variant('as', [self.account, str(self.jid)])) - - def _popup_menu(self, event: Gdk.EventButton): - menu = get_chat_list_row_menu( - self.workspace_id, self.account, self.jid, self._pinned) - - event_widget = Gtk.get_event_widget(event) - x = event.x - if isinstance(event_widget, Gtk.Button): - # When the event is triggered by pressing the close button we get - # a x coordinate relative to the window of the close button, which - # would be a very low x integer as the close button is small, this - # leads to opening the menu far away from the mouse. We overwrite - # the x coordinate with an approx. position of the close button. - x = self.get_allocated_width() - 10 - - popover = GajimPopover(menu, relative_to=self) - popover.set_pointing_to_coord(x=x, y=event.y) - popover.popup() - - def _on_drag_begin(self, - widget: Gtk.Widget, - drag_context: Gdk.DragContext - ) -> None: - - chat_list = cast(ChatList, self.get_parent()) - chat_list.set_drag_row(self) - - # Use rendered ChatListRow as drag icon - alloc = self.get_allocation() - surface = cairo.ImageSurface( - cairo.Format.ARGB32, alloc.width, alloc.height) - context = cairo.Context(surface) - self.draw(context) - coords = widget.translate_coordinates(self, 0, 0) - if coords is None: - return - dest_x, dest_y = coords - surface.set_device_offset(-dest_x, -dest_y) - Gtk.drag_set_icon_surface(drag_context, surface) - - def _on_drag_data_get(self, - _widget: Gtk.Widget, - _drag_context: Gdk.DragContext, - selection_data: Gtk.SelectionData, - _info: int, - _time: int - ) -> None: - drop_type = Gdk.Atom.intern_static_string('CHAT_LIST_ITEM') - byte_data = pickle.dumps((self.account, self.jid)) - selection_data.set(drop_type, 8, byte_data) - - def toggle_pinned(self) -> None: - self._pinned = not self._pinned - - def _on_presence_update(self, - _contact: ChatContactT, - _signal_name: str - ) -> None: - self.update_avatar() - - def _on_avatar_update(self, - _contact: ChatContactT, - _signal_name: str - ) -> None: - self.update_avatar() - - def _on_muc_user_update(self, - _contact: GroupchatParticipant, - _signal_name: str, - *args: Any - ) -> None: - self.update_avatar() - - def _on_muc_update(self, - _contact: GroupchatContact, - _signal_name: str, - *args: Any - ) -> None: - self.update_avatar() - - def update_avatar(self) -> None: - scale = self.get_scale_factor() - surface = self.contact.get_avatar(AvatarSize.ROSTER, scale) - self._ui.avatar_image.set_from_surface(surface) - - def update_name(self) -> None: - if self.type == 'pm': - client = app.get_client(self.account) - muc_name = get_groupchat_name(client, self.jid.new_as_bare()) - self._ui.name_label.set_text(f'{self.contact.name} ({muc_name})') - return - - self.contact_name = self.contact.name - if self.jid == self._client.get_own_jid().bare: - self.contact_name = _('Note to myself') - self._ui.name_label.set_text(self.contact_name) - - def update_account_identifier(self) -> None: - account_class = app.css_config.get_dynamic_class(self.account) - self._ui.account_identifier.get_style_context().add_class(account_class) - show = len(app.settings.get_active_accounts()) > 1 - self._ui.account_identifier.set_visible(show) - - def _on_chatstate_update(self, - contact: OneOnOneContactT, - _signal_name: str - ) -> None: - if contact.chatstate is None: - self._ui.chatstate_image.hide() - else: - self._ui.chatstate_image.set_visible(contact.chatstate.is_composing) - - def _on_nickname_update(self, - _contact: ChatContactT, - _signal_name: str - ) -> None: - self.update_name() - - def get_real_unread_count(self) -> int: - return self._unread_count - - @property - def unread_count(self) -> int: - if (self.contact.is_groupchat and not self.contact.can_notify() and - not self._needs_muc_highlight): - return 0 - return self._unread_count - - @unread_count.setter - def unread_count(self, value: int) -> None: - self._unread_count = value - self._update_unread() - chat_list = cast(ChatList, self.get_parent()) - chat_list.emit_unread_changed() - - def _update_unread(self) -> None: - unread_count = self._get_unread_string(self._unread_count) - self._ui.unread_label.set_text(unread_count) - self._ui.unread_label.set_visible(bool(self._unread_count)) - - @staticmethod - def _get_unread_string(count: int) -> str: - if count < 1000: - return str(count) - return '999+' - - def add_unread(self, text: str) -> None: - control = app.window.get_control() - if (self.is_active and - control.is_loaded(self.account, self.jid) and - control.get_autoscroll()): - return - - self._unread_count += 1 - self._update_unread() - app.storage.cache.set_unread_count( - self.account, - self.jid, - self.get_real_unread_count(), - self.message_id, - self.timestamp) - - if self.contact.is_groupchat: - needs_highlight = message_needs_highlight( - text, - self.contact.nickname, - self._client.get_own_jid().bare) - if needs_highlight: - self._needs_muc_highlight = True - self._ui.unread_label.get_style_context().remove_class( - 'unread-counter-silent') - - chat_list = cast(ChatList, self.get_parent()) - chat_list.emit_unread_changed() - - def reset_unread(self) -> None: - self._needs_muc_highlight = False - self._unread_count = 0 - self._update_unread() - chat_list = cast(ChatList, self.get_parent()) - chat_list.emit_unread_changed() - app.storage.cache.reset_unread_count(self.account, self.jid) - - # Add class again in case we were mentioned previously - if self.contact.is_groupchat and not self.contact.can_notify(): - self._ui.unread_label.get_style_context().add_class( - 'unread-counter-silent') - - @property - 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 - - def _on_state_flags_changed(self, - _row: ChatRow, - _flags: Gtk.StateFlags - ) -> None: - state = self.get_state_flags() - if (state & Gtk.StateFlags.PRELIGHT) != 0: - self._ui.revealer.set_reveal_child(True) - else: - self._ui.revealer.set_reveal_child(False) - - def _on_destroy(self, _row: ChatRow) -> None: - self.contact.disconnect_all_from_obj(self) - if isinstance(self.contact, GroupchatParticipant): - self.contact.room.disconnect_all_from_obj(self) - - app.check_finalize(self) - - def _on_close_button_clicked(self, _button: Gtk.Button) -> None: - app.window.activate_action( - 'remove-chat', - GLib.Variant('as', [self.account, str(self.jid)])) - - def set_timestamp(self, timestamp: int) -> None: - self.timestamp = timestamp - self.update_time() - - def set_stanza_id(self, stanza_id: str) -> None: - self.stanza_id = stanza_id - - def set_message_id(self, message_id: str) -> None: - self.message_id = message_id - - def update_time(self) -> None: - if self.timestamp == 0: - return - self._ui.timestamp_label.set_text( - get_uf_relative_time(self.timestamp)) - - def set_nick(self, nickname: str) -> None: - self._ui.nick_label.set_visible(bool(nickname)) - self._ui.nick_label.set_text( - _('%(nickname)s:') % {'nickname': nickname}) - - def set_message_text(self, - text: str, - nickname: Optional[str] = None, - icon_name: Optional[str] = None, - additional_data: Optional[AdditionalDataDict] = None - ) -> None: - icon = None - if icon_name is not None: - icon = Gio.Icon.new_for_string(icon_name) - if additional_data is not None: - if app.preview_manager.is_previewable(text, additional_data): - file_name = filename_from_uri(text) - icon, file_type = guess_simple_file_type(text) - text = f'{file_type} ({file_name})' - - text = GLib.markup_escape_text(text) - if text.startswith('/me') and nickname is not None: - nickname = GLib.markup_escape_text(nickname) - text = text.replace('/me', f'* {nickname}', 1) - text = f'<i>{text}</i>' - - # Split by newline and display last line (or first, if last is newline) - lines = text.split('\n') - text = lines[-1] or lines[0] - self._ui.message_label.set_markup(text) - - if icon is None: - self._ui.message_icon.hide() - else: - self._ui.message_icon.set_from_gicon(icon, Gtk.IconSize.MENU) - self._ui.message_icon.show() - - -class BaseHeader(Gtk.Box): - def __init__(self, row_type: RowHeaderType, text: str) -> 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): - - def __init__(self): - BaseHeader.__init__(self, - RowHeaderType.ACTIVE, - _('Active')) - - -class ConversationsHeader(BaseHeader): - - def __init__(self): - BaseHeader.__init__(self, - RowHeaderType.CONVERSATIONS, - _('Conversations')) - - -class PinnedHeader(BaseHeader): - - def __init__(self): - BaseHeader.__init__(self, - RowHeaderType.PINNED, - _('Pinned')) - self.get_style_context().add_class('header-box-first') ===================================== gajim/gtk/chat_list_row.py ===================================== @@ -0,0 +1,555 @@ +# This file is part of Gajim. +# +# Gajim is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. +# +# Gajim is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. + +from __future__ import annotations + +from typing import Optional +from typing import Any + +import pickle + +from gi.repository import Gdk +from gi.repository import Gio +from gi.repository import GLib +from gi.repository import Gtk +from gi.repository import GObject +import cairo + +from nbxmpp import JID + +from gajim.common import app +from gajim.common.const import AvatarSize +from gajim.common.const import KindConstant +from gajim.common.const import RowHeaderType +from gajim.common.i18n import _ +from gajim.common.helpers import get_groupchat_name +from gajim.common.helpers import get_group_chat_nick +from gajim.common.helpers import get_retraction_text +from gajim.common.helpers import get_uf_relative_time +from gajim.common.helpers import message_needs_highlight +from gajim.common.helpers import AdditionalDataDict +from gajim.common.preview_helpers import filename_from_uri +from gajim.common.preview_helpers import guess_simple_file_type +from gajim.common.types import ChatContactT +from gajim.common.types import OneOnOneContactT +from gajim.common.modules.contacts import BareContact +from gajim.common.modules.contacts import GroupchatContact +from gajim.common.modules.contacts import GroupchatParticipant + +from .menus import get_chat_list_row_menu +from .builder import get_builder +from .util import GajimPopover + + +class ChatRow(Gtk.ListBoxRow): + + __gsignals__ = { + 'unread-changed': ( + GObject.SignalFlags.RUN_LAST, + None, + ()), + } + + def __init__(self, + workspace_id: str, + account: str, + jid: JID, + type_: str, + pinned: bool, + position: int + ) -> None: + + Gtk.ListBoxRow.__init__(self) + + self.account = account + self.jid = jid + self.workspace_id = workspace_id + self.type = type_ + self.position = position + + self.active_label = ActiveHeader() + self.conversations_label = ConversationsHeader() + self.pinned_label = PinnedHeader() + + 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_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 + + self.get_style_context().add_class('chatlist-row') + + self._ui = get_builder('chat_list_row.ui') + 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( + 'CHAT_LIST_ITEM', + Gtk.TargetFlags.SAME_APP, + 0)] + self.drag_source_set( + Gdk.ModifierType.BUTTON1_MASK, + entries, + Gdk.DragAction.MOVE) + self.connect('drag-begin', self._on_drag_begin) + self.connect('drag-data-get', self._on_drag_data_get) + + if self.type == 'groupchat': + self._ui.group_chat_indicator.show() + + self.update_avatar() + self.update_name() + self.update_account_identifier() + + if (isinstance(self.contact, GroupchatContact) and + not self.contact.can_notify()): + self._ui.unread_label.get_style_context().add_class( + 'unread-counter-silent') + + # Get last chat message from archive + line = app.storage.archive.get_last_conversation_line(account, jid) + + if line is None: + self.show_all() + return + + if line.message is not None: + message_text = line.message + + if line.additional_data is not None: + retracted_by = line.additional_data.get_value( + 'retracted', 'by') + if retracted_by is not None: + reason = line.additional_data.get_value( + 'retracted', 'reason') + message_text = get_retraction_text( + self.account, retracted_by, reason) + + me_nickname = None + if line.kind in (KindConstant.CHAT_MSG_SENT, + KindConstant.SINGLE_MSG_SENT): + self.set_nick(_('Me')) + me_nickname = app.nicks[account] + + if line.kind == KindConstant.GC_MSG: + our_nick = get_group_chat_nick(account, jid) + if line.contact_name == our_nick: + self.set_nick(_('Me')) + me_nickname = our_nick + else: + self.set_nick(line.contact_name) + me_nickname = line.contact_name + + self.set_message_text( + message_text, + 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.stanza_id = line.stanza_id + self.message_id = line.message_id + + if line.kind in (KindConstant.FILE_TRANSFER_INCOMING, + 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) + + 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.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 + + def _on_button_press(self, + _widget: Gtk.Widget, + event: Gdk.EventButton + ) -> None: + if event.button == 3: # right click + self._popup_menu(event) + elif event.button == 2: # middle click + app.window.activate_action( + 'remove-chat', + GLib.Variant('as', [self.account, str(self.jid)])) + + def _popup_menu(self, event: Gdk.EventButton): + menu = get_chat_list_row_menu( + self.workspace_id, self.account, self.jid, self._pinned) + + event_widget = Gtk.get_event_widget(event) + x = event.x + if isinstance(event_widget, Gtk.Button): + # When the event is triggered by pressing the close button we get + # a x coordinate relative to the window of the close button, which + # would be a very low x integer as the close button is small, this + # leads to opening the menu far away from the mouse. We overwrite + # the x coordinate with an approx. position of the close button. + x = self.get_allocated_width() - 10 + + popover = GajimPopover(menu, relative_to=self) + popover.set_pointing_to_coord(x=x, y=event.y) + popover.popup() + + def _on_drag_begin(self, + row: ChatRow, + drag_context: Gdk.DragContext + ) -> None: + + # Use rendered ChatRow as drag icon + alloc = self.get_allocation() + surface = cairo.ImageSurface( + cairo.Format.ARGB32, alloc.width, alloc.height) + context = cairo.Context(surface) + self.draw(context) + coords = row.translate_coordinates(self, 0, 0) + if coords is None: + return + dest_x, dest_y = coords + surface.set_device_offset(-dest_x, -dest_y) + Gtk.drag_set_icon_surface(drag_context, surface) + + def _on_drag_data_get(self, + _widget: Gtk.Widget, + _drag_context: Gdk.DragContext, + selection_data: Gtk.SelectionData, + _info: int, + _time: int + ) -> None: + + drop_type = Gdk.Atom.intern_static_string('CHAT_LIST_ITEM') + byte_data = pickle.dumps((self.account, self.jid)) + selection_data.set(drop_type, 8, byte_data) + + def toggle_pinned(self) -> None: + self._pinned = not self._pinned + + def _on_presence_update(self, + _contact: ChatContactT, + _signal_name: str + ) -> None: + self.update_avatar() + + def _on_avatar_update(self, + _contact: ChatContactT, + _signal_name: str + ) -> None: + self.update_avatar() + + def _on_muc_user_update(self, + _contact: GroupchatParticipant, + _signal_name: str, + *args: Any + ) -> None: + self.update_avatar() + + def _on_muc_update(self, + _contact: GroupchatContact, + _signal_name: str, + *args: Any + ) -> None: + self.update_avatar() + + def update_avatar(self) -> None: + scale = self.get_scale_factor() + surface = self.contact.get_avatar(AvatarSize.ROSTER, scale) + self._ui.avatar_image.set_from_surface(surface) + + def update_name(self) -> None: + if self.type == 'pm': + client = app.get_client(self.account) + muc_name = get_groupchat_name(client, self.jid.new_as_bare()) + self._ui.name_label.set_text(f'{self.contact.name} ({muc_name})') + return + + self.contact_name = self.contact.name + if self.jid == self._client.get_own_jid().bare: + self.contact_name = _('Note to myself') + self._ui.name_label.set_text(self.contact_name) + + def update_account_identifier(self) -> None: + account_class = app.css_config.get_dynamic_class(self.account) + self._ui.account_identifier.get_style_context().add_class(account_class) + show = len(app.settings.get_active_accounts()) > 1 + self._ui.account_identifier.set_visible(show) + + def _on_chatstate_update(self, + contact: OneOnOneContactT, + _signal_name: str + ) -> None: + if contact.chatstate is None: + self._ui.chatstate_image.hide() + else: + self._ui.chatstate_image.set_visible(contact.chatstate.is_composing) + + def _on_nickname_update(self, + _contact: ChatContactT, + _signal_name: str + ) -> None: + self.update_name() + + def get_real_unread_count(self) -> int: + return self._unread_count + + @property + def unread_count(self) -> int: + if (self.contact.is_groupchat and not self.contact.can_notify() and + not self._needs_muc_highlight): + return 0 + return self._unread_count + + @unread_count.setter + def unread_count(self, value: int) -> None: + self._unread_count = value + self._update_unread() + self.emit('unread-changed') + + def _update_unread(self) -> None: + unread_count = self._get_unread_string(self._unread_count) + self._ui.unread_label.set_text(unread_count) + self._ui.unread_label.set_visible(bool(self._unread_count)) + + @staticmethod + def _get_unread_string(count: int) -> str: + if count < 1000: + return str(count) + return '999+' + + def add_unread(self, text: str) -> None: + control = app.window.get_control() + if (self.is_active and + control.is_loaded(self.account, self.jid) and + control.get_autoscroll()): + return + + self._unread_count += 1 + self._update_unread() + app.storage.cache.set_unread_count( + self.account, + self.jid, + self.get_real_unread_count(), + self.message_id, + self.timestamp) + + if self.contact.is_groupchat: + needs_highlight = message_needs_highlight( + text, + self.contact.nickname, + self._client.get_own_jid().bare) + if needs_highlight: + self._needs_muc_highlight = True + self._ui.unread_label.get_style_context().remove_class( + 'unread-counter-silent') + + self.emit('unread-changed') + + def reset_unread(self) -> None: + self._needs_muc_highlight = False + self._unread_count = 0 + self._update_unread() + self.emit('unread-changed') + + app.storage.cache.reset_unread_count(self.account, self.jid) + + # Add class again in case we were mentioned previously + if self.contact.is_groupchat and not self.contact.can_notify(): + self._ui.unread_label.get_style_context().add_class( + 'unread-counter-silent') + + @property + 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 + + def _on_state_flags_changed(self, + _row: ChatRow, + _flags: Gtk.StateFlags + ) -> None: + state = self.get_state_flags() + if (state & Gtk.StateFlags.PRELIGHT) != 0: + self._ui.revealer.set_reveal_child(True) + else: + self._ui.revealer.set_reveal_child(False) + + def _on_destroy(self, _row: ChatRow) -> None: + self.contact.disconnect_all_from_obj(self) + if isinstance(self.contact, GroupchatParticipant): + self.contact.room.disconnect_all_from_obj(self) + + app.check_finalize(self) + + def _on_close_button_clicked(self, _button: Gtk.Button) -> None: + app.window.activate_action( + 'remove-chat', + GLib.Variant('as', [self.account, str(self.jid)])) + + def set_timestamp(self, timestamp: int) -> None: + self.timestamp = timestamp + self.update_time() + + def set_stanza_id(self, stanza_id: str) -> None: + self.stanza_id = stanza_id + + def set_message_id(self, message_id: str) -> None: + self.message_id = message_id + + def update_time(self) -> None: + if self.timestamp == 0: + return + self._ui.timestamp_label.set_text( + get_uf_relative_time(self.timestamp)) + + def set_nick(self, nickname: str) -> None: + self._ui.nick_label.set_visible(bool(nickname)) + self._ui.nick_label.set_text( + _('%(nickname)s:') % {'nickname': nickname}) + + def set_message_text(self, + text: str, + nickname: Optional[str] = None, + icon_name: Optional[str] = None, + additional_data: Optional[AdditionalDataDict] = None + ) -> None: + icon = None + if icon_name is not None: + icon = Gio.Icon.new_for_string(icon_name) + if additional_data is not None: + if app.preview_manager.is_previewable(text, additional_data): + file_name = filename_from_uri(text) + icon, file_type = guess_simple_file_type(text) + text = f'{file_type} ({file_name})' + + text = GLib.markup_escape_text(text) + if text.startswith('/me') and nickname is not None: + nickname = GLib.markup_escape_text(nickname) + text = text.replace('/me', f'* {nickname}', 1) + text = f'<i>{text}</i>' + + # Split by newline and display last line (or first, if last is newline) + lines = text.split('\n') + text = lines[-1] or lines[0] + self._ui.message_label.set_markup(text) + + if icon is None: + self._ui.message_icon.hide() + else: + self._ui.message_icon.set_from_gicon(icon, Gtk.IconSize.MENU) + self._ui.message_icon.show() + + +class BaseHeader(Gtk.Box): + def __init__(self, row_type: RowHeaderType, text: str) -> 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): + + def __init__(self): + BaseHeader.__init__(self, + RowHeaderType.ACTIVE, + _('Active')) + + +class ConversationsHeader(BaseHeader): + + def __init__(self): + BaseHeader.__init__(self, + RowHeaderType.CONVERSATIONS, + _('Conversations')) + + +class PinnedHeader(BaseHeader): + + def __init__(self): + BaseHeader.__init__(self, + RowHeaderType.PINNED, + _('Pinned')) + self.get_style_context().add_class('header-box-first') ===================================== pyrightconfig.json ===================================== @@ -63,6 +63,7 @@ "gajim/gtk/chat_filter.py", "gajim/gtk/chat_function_page.py", "gajim/gtk/chat_list.py", + "gajim/gtk/chat_list_row.py", "gajim/gtk/chat_list_stack.py", "gajim/gtk/chat_page.py", "gajim/gtk/chat_stack.py", View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/4a1a317151cad15659c9a0f587e1be6a…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/4a1a317151cad15659c9a0f587e1be6a…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] refactor: Add GajimPopover
by Philipp Hörist (@lovetox)
01 Oct '22
01 Oct '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 65c22279 by Philipp Hörist at 2022-10-01T22:25:21+02:00 refactor: Add GajimPopover - - - - - 8 changed files: - gajim/gtk/chat_list.py - gajim/gtk/component_search.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/groupchat_roster.py - gajim/gtk/roster.py - gajim/gtk/start_chat.py - gajim/gtk/util.py - gajim/gtk/workspace_side_bar.py Changes: ===================================== gajim/gtk/chat_list.py ===================================== @@ -58,6 +58,8 @@ from .menus import get_chat_list_row_menu from .builder import get_builder from .util import EventHelper +from .util import GajimPopover + log = logging.getLogger('gajim.gui.chatlist') @@ -867,24 +869,18 @@ def _popup_menu(self, event: Gdk.EventButton): menu = get_chat_list_row_menu( self.workspace_id, self.account, self.jid, self._pinned) - rectangle = Gdk.Rectangle() - rectangle.x = int(event.x) - rectangle.y = int(event.y) - rectangle.width = rectangle.height = 1 - event_widget = Gtk.get_event_widget(event) + x = event.x if isinstance(event_widget, Gtk.Button): # When the event is triggered by pressing the close button we get # a x coordinate relative to the window of the close button, which # would be a very low x integer as the close button is small, this # leads to opening the menu far away from the mouse. We overwrite # the x coordinate with an approx. position of the close button. - rectangle.x = int(self.get_allocated_width() - 10) + x = self.get_allocated_width() - 10 - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_relative_to(self) - popover.set_position(Gtk.PositionType.RIGHT) - popover.set_pointing_to(rectangle) + popover = GajimPopover(menu, relative_to=self) + popover.set_pointing_to_coord(x=x, y=event.y) popover.popup() def _on_drag_begin(self, ===================================== gajim/gtk/component_search.py ===================================== @@ -41,6 +41,7 @@ from .assistant import ProgressPage from .dataform import DataFormWidget from .menus import get_component_search_menu +from .util import GajimPopover from .util import ensure_not_destroyed from .util import EventHelper @@ -311,15 +312,7 @@ def _on_button_press(self, jid = column_values[self._jid_col] menu = get_component_search_menu(jid, text) - rectangle = Gdk.Rectangle() - rectangle.x = int(event.x) - rectangle.y = int(event.y) - rectangle.width = rectangle.height = 1 - - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_relative_to(self) - popover.set_position(Gtk.PositionType.RIGHT) - popover.set_pointing_to(rectangle) + popover = GajimPopover(menu, relative_to=self, event=event) popover.popup() return True ===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -55,6 +55,7 @@ from ...dialogs import DialogButton from ...menus import get_groupchat_participant_menu from ...preview import PreviewWidget +from ...util import GajimPopover from ...util import format_fingerprint from ...util import get_cursor @@ -270,14 +271,11 @@ def _on_avatar_clicked(self, if event.button == 1: app.window.activate_action('mention', GLib.Variant('s', name)) elif event.button == 3: - rect = Gdk.Rectangle() - rect.x, rect.y = int(event.x), int(event.y) - rect.height, rect.width = 1, 1 - self._show_participant_menu(name, rect) + self._show_participant_menu(name, event) return Gdk.EVENT_STOP - def _show_participant_menu(self, nick: str, rect: Gdk.Rectangle) -> None: + def _show_participant_menu(self, nick: str, event: Gdk.EventButton) -> None: assert isinstance(self._contact, GroupchatContact) if not self._contact.is_joined: return @@ -294,13 +292,7 @@ def _show_participant_menu(self, nick: str, rect: Gdk.Rectangle) -> None: self_contact, contact) - def destroy(popover: Gtk.Popover) -> None: - app.check_finalize(popover) - GLib.idle_add(popover.set_relative_to, None) - - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_pointing_to(rect) - popover.connect('closed', destroy) + popover = GajimPopover(menu, relative_to=self, event=event) popover.popup() @staticmethod ===================================== gajim/gtk/groupchat_roster.py ===================================== @@ -42,6 +42,7 @@ from .tooltips import GCTooltip from .builder import get_builder from .util import EventHelper +from .util import GajimPopover log = logging.getLogger('gajim.gui.groupchat_roster') @@ -414,15 +415,12 @@ def _on_roster_button_press_event(self, return if event.button == 3: # right click - rec = Gdk.Rectangle() - rec.x, rec.y = int(event.x), int(event.y) - rec.height, rec.width = 1, 1 - self._show_contact_menu(nick, rec) + self._show_contact_menu(nick, event) # if event.button == 2: # middle click # self.roster.emit('row-activated', nick) - def _show_contact_menu(self, nick: str, rect: Gdk.Rectangle) -> None: + def _show_contact_menu(self, nick: str, event: Gdk.EventButton) -> None: assert self._contact is not None self_contact = self._contact.get_self() assert self_contact is not None @@ -431,13 +429,7 @@ def _show_contact_menu(self, nick: str, rect: Gdk.Rectangle) -> None: self_contact, contact) - def destroy(popover: Gtk.Popover) -> None: - app.check_finalize(popover) - GLib.idle_add(popover.set_relative_to, None) - - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_pointing_to(rect) - popover.connect('closed', destroy) + popover = GajimPopover(menu, relative_to=self, event=event) popover.popup() def _on_muc_state_changed(self, ===================================== gajim/gtk/roster.py ===================================== @@ -50,6 +50,7 @@ from .dialogs import DialogButton from .tooltips import RosterTooltip from .util import EventHelper +from .util import GajimPopover from .builder import get_builder from .util import open_window @@ -384,18 +385,9 @@ def _show_contact_menu(self, contact = self._contacts.get_bare_contact(jid) gateway_register = contact.is_gateway and contact.supports( Namespace.REGISTER) - menu = get_roster_menu( - self._account, jid, gateway=gateway_register) - - rectangle = Gdk.Rectangle() - rectangle.x = int(event.x) - rectangle.y = int(event.y) - rectangle.width = rectangle.height = 1 - - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_relative_to(treeview) - popover.set_position(Gtk.PositionType.RIGHT) - popover.set_pointing_to(rectangle) + + menu = get_roster_menu(self._account, jid, gateway=gateway_register) + popover = GajimPopover(menu, relative_to=treeview, event=event) popover.popup() def set_search_string(self, text: str) -> None: ===================================== gajim/gtk/start_chat.py ===================================== @@ -56,7 +56,7 @@ from .groupchat_info import GroupChatInfoScrolled from .groupchat_nick import NickChooser from .builder import get_builder -from .util import get_icon_name +from .util import GajimPopover, get_icon_name from .util import AccountBadge ContactT = Union[BareContact, GroupchatContact] @@ -829,15 +829,7 @@ def _popup_menu(self, menu = get_start_chat_row_menu(self.account, self.jid) - rectangle = Gdk.Rectangle() - rectangle.x = int(event.x) - rectangle.y = int(event.y) - rectangle.width = rectangle.height = 1 - - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_relative_to(self) - popover.set_position(Gtk.PositionType.RIGHT) - popover.set_pointing_to(rectangle) + popover = GajimPopover(menu, relative_to=self, event=event) popover.popup() def _get_avatar_image(self, contact: ContactT) -> Gtk.Image: ===================================== gajim/gtk/util.py ===================================== @@ -866,3 +866,47 @@ def add_submenu(self, label: str) -> GajimMenu: menu = GajimMenu() self.append_submenu(label, menu) return menu + + +class GdkRectangle(Gdk.Rectangle): + def __init__(self, + x: int, + y: int, + height: int = 1, + width: int = 1 + ) -> None: + + Gdk.Rectangle.__init__(self) + self.x = x + self.y = y + self.height = height + self.width = width + + +class GajimPopover(Gtk.Popover): + def __init__(self, + menu: Gio.MenuModel, + relative_to: Optional[Gtk.Widget] = None, + position: Gtk.PositionType = Gtk.PositionType.RIGHT, + event: Optional[Gdk.EventButton] = None) -> None: + + Gtk.Popover.__init__(self) + + self.bind_model(menu) + self.set_relative_to(relative_to) + self.set_position(position) + if event is not None: + self.set_pointing_from_event(event) + + self.connect('closed', self._destroy) + + def set_pointing_from_event(self, event: Gdk.EventButton) -> None: + self.set_pointing_to_coord(event.x, event.y) + + def set_pointing_to_coord(self, x: float, y: float) -> None: + rectangle = GdkRectangle(x=int(x), y=int(y)) + self.set_pointing_to(rectangle) + + def _destroy(self, popover: Gtk.Popover) -> None: + app.check_finalize(popover) + GLib.idle_add(popover.set_relative_to, None) ===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -33,8 +33,10 @@ from .chat_page import ChatPage from .menus import get_workspace_menu from .structs import ChatListEntryParam +from .util import GajimPopover from .util import open_window + log = logging.getLogger('gajim.gui.workspace_sidebar') @@ -332,15 +334,7 @@ def _popup_menu(self, _widget: Gtk.Widget, event: Gdk.EventButton) -> None: menu = get_workspace_menu(self.workspace_id) - rectangle = Gdk.Rectangle() - rectangle.x = int(event.x) - rectangle.y = int(event.y) - rectangle.width = rectangle.height = 1 - - popover = Gtk.Popover.new_from_model(self, menu) - popover.set_relative_to(self) - popover.set_position(Gtk.PositionType.RIGHT) - popover.set_pointing_to(rectangle) + popover = GajimPopover(menu, relative_to=self, event=event) popover.popup() def update_avatar(self) -> None: View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/65c22279bae34bb7161aed8b9172fc7e…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/65c22279bae34bb7161aed8b9172fc7e…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim] Deleted branch muc-participant-menu
by Daniel Brötzmann (@wurstsalat)
01 Oct '22
01 Oct '22
Daniel Brötzmann deleted branch muc-participant-menu at gajim / gajim -- You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] imprv: MUC: Add participant menu to avatar
by Philipp Hörist (@lovetox)
01 Oct '22
01 Oct '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: cb7c00f1 by wurstsalat at 2022-10-01T18:54:47+00:00 imprv: MUC: Add participant menu to avatar - - - - - 3 changed files: - gajim/gtk/conversation/rows/message.py - gajim/gtk/groupchat_roster.py - gajim/gtk/menus.py Changes: ===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -53,6 +53,7 @@ from ..message_widget import MessageWidget from ...dialogs import InputDialog from ...dialogs import DialogButton +from ...menus import get_groupchat_participant_menu from ...preview import PreviewWidget from ...util import format_fingerprint from ...util import get_cursor @@ -265,10 +266,43 @@ def _on_avatar_clicked(self, event: Gdk.EventButton, name: str ) -> int: - if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1: - app.window.activate_action('mention', GLib.Variant('s', name)) + if event.type == Gdk.EventType.BUTTON_PRESS: + if event.button == 1: + app.window.activate_action('mention', GLib.Variant('s', name)) + elif event.button == 3: + rect = Gdk.Rectangle() + rect.x, rect.y = int(event.x), int(event.y) + rect.height, rect.width = 1, 1 + self._show_participant_menu(name, rect) + return Gdk.EVENT_STOP + def _show_participant_menu(self, nick: str, rect: Gdk.Rectangle) -> None: + assert isinstance(self._contact, GroupchatContact) + if not self._contact.is_joined: + return + + self_contact = self._contact.get_self() + assert self_contact is not None + + if nick == self_contact.name: + # Don’t show menu for us + return + + contact = self._contact.get_resource(nick) + menu = get_groupchat_participant_menu(self._contact.account, + self_contact, + contact) + + def destroy(popover: Gtk.Popover) -> None: + app.check_finalize(popover) + GLib.idle_add(popover.set_relative_to, None) + + popover = Gtk.Popover.new_from_model(self, menu) + popover.set_pointing_to(rect) + popover.connect('closed', destroy) + popover.popup() + @staticmethod def _on_realize(event_box: Gtk.EventBox) -> None: window = event_box.get_window() ===================================== gajim/gtk/groupchat_roster.py ===================================== @@ -38,7 +38,7 @@ from gajim.common.events import MUCNicknameChanged from gajim.common.modules.contacts import GroupchatContact -from .menus import get_groupchat_roster_menu +from .menus import get_groupchat_participant_menu from .tooltips import GCTooltip from .builder import get_builder from .util import EventHelper @@ -427,9 +427,9 @@ def _show_contact_menu(self, nick: str, rect: Gdk.Rectangle) -> None: self_contact = self._contact.get_self() assert self_contact is not None contact = self._contact.get_resource(nick) - menu = get_groupchat_roster_menu(self._contact.account, - self_contact, - contact) + menu = get_groupchat_participant_menu(self._contact.account, + self_contact, + contact) def destroy(popover: Gtk.Popover) -> None: app.check_finalize(popover) ===================================== gajim/gtk/menus.py ===================================== @@ -465,6 +465,10 @@ def get_groupchat_admin_menu(self_contact: types.GroupchatParticipant, menu = GajimMenu() + if contact.real_jid is None: + menu.add_item(_('Not Available'), 'dummy', None) + return menu + action = 'win.muc-change-affiliation' if is_affiliation_change_allowed(self_contact, contact, 'owner'): @@ -499,6 +503,10 @@ def get_groupchat_mod_menu(self_contact: types.GroupchatParticipant, menu = GajimMenu() + if not contact.is_available: + menu.add_item(_('Not Available'), 'dummy', None) + return menu + if is_role_change_allowed(self_contact, contact): value = f'"{contact.name}"' menu.add_item(_('Kick…'), 'win.muc-kick', value) @@ -519,10 +527,10 @@ def get_groupchat_mod_menu(self_contact: types.GroupchatParticipant, return menu -def get_groupchat_roster_menu(account: str, - self_contact: types.GroupchatParticipant, - contact: types.GroupchatParticipant - ) -> GajimMenu: +def get_groupchat_participant_menu(account: str, + self_contact: types.GroupchatParticipant, + contact: types.GroupchatParticipant + ) -> GajimMenu: value = f'"{contact.name}"' View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/cb7c00f1e3fb37fe22de03e031140f7e…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/cb7c00f1e3fb37fe22de03e031140f7e…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][muc-participant-menu] 7 commits: fix: Update chat actions when account state changes
by Philipp Hörist (@lovetox)
01 Oct '22
01 Oct '22
Philipp Hörist pushed to branch muc-participant-menu at gajim / gajim Commits: 95cd9b4c by wurstsalat at 2022-09-30T21:03:05+02:00 fix: Update chat actions when account state changes Fixes #11184 - - - - - 3c849310 by Philipp Hörist at 2022-10-01T00:43:32+02:00 refactor: MessageRow: Move security label creation into own method - - - - - 10c86624 by Philipp Hörist at 2022-10-01T00:43:32+02:00 refactor: Store messages before raising MessageSent event - - - - - 327eca05 by Philipp Hörist at 2022-10-01T00:57:05+02:00 fix: Scroll to end after sending message Scrolling to end is much simpler than reseting the view and less error prone. Fixes #10871 - - - - - d558d99c by Philipp Hörist at 2022-10-01T17:00:52+02:00 new: Allow passing a timeout to as_task decorator - - - - - d4736d92 by Philipp Hörist at 2022-10-01T17:05:49+02:00 imprv: StartChat: Add timeout when requesting MUC disco info - - - - - cb7c00f1 by wurstsalat at 2022-10-01T18:54:47+00:00 imprv: MUC: Add participant menu to avatar - - - - - 9 changed files: - gajim/common/client.py - gajim/common/modules/util.py - gajim/gtk/chat_stack.py - gajim/gtk/control.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/view.py - gajim/gtk/groupchat_roster.py - gajim/gtk/menus.py - gajim/gtk/start_chat.py Changes: ===================================== gajim/common/client.py ===================================== @@ -503,6 +503,9 @@ def _send_message(self, message: OutgoingMessage) -> None: message.set_sent_timestamp() message.message_id = self.send_stanza(message.stanza) + if not message.is_groupchat: + self.get_module('Message').log_message(message) + app.ged.raise_event( MessageSent(jid=message.jid, account=message.account, @@ -515,11 +518,6 @@ def _send_message(self, message: OutgoingMessage) -> None: message_id=message.message_id, play_sound=message.play_sound)) - if message.is_groupchat: - return - - self.get_module('Message').log_message(message) - def _prepare_for_connect(self) -> None: custom_host = get_custom_host(self._account) if custom_host is not None: ===================================== gajim/common/modules/util.py ===================================== @@ -111,8 +111,15 @@ def process(self, msg: str, kwargs: Any) -> tuple[str, Any]: def as_task(func): @wraps(func) - def func_wrapper(self, *args, callback=None, user_data=None, **kwargs): + def func_wrapper(self, + *args, + timeout=None, + callback=None, + user_data=None, + **kwargs): + task_ = Task(func(self, *args, **kwargs)) + task_.set_timeout(timeout) app.register_task(self, task_) task_.set_finalize_func(app.remove_task, id(self)) task_.set_user_data(user_data) ===================================== gajim/gtk/chat_stack.py ===================================== @@ -15,6 +15,7 @@ from __future__ import annotations from typing import Optional +from typing import Union import sys import logging @@ -147,6 +148,8 @@ def __init__(self): ('message-received', 85, self._on_message_received), ('gc-message-received', 85, self._on_message_received), ('muc-disco-update', 85, self._on_muc_disco_update), + ('account-connected', 85, self._on_account_state), + ('account-disconnected', 85, self._on_account_state), ]) def _get_current_contact(self) -> ChatContactT: @@ -189,6 +192,7 @@ def show_chat(self, account: str, jid: JID) -> None: self._message_action_box.switch_contact(self._current_contact) self._update_base_actions(self._current_contact) + if isinstance(self._current_contact, GroupchatContact): self._current_contact.multi_connect({ 'user-joined': self._on_user_joined, @@ -333,6 +337,26 @@ def _on_muc_disco_update(self, event: events.MucDiscoUpdate) -> None: self._update_group_chat_actions(self._current_contact) + def _on_account_state(self, + event: Union[events.AccountConnected, + events.AccountDisconnected] + ) -> None: + + if self._current_contact is None: + return + + if event.account != self._current_contact.account: + return + + self._update_base_actions(self._current_contact) + + if isinstance(self._current_contact, GroupchatContact): + self._update_group_chat_actions(self._current_contact) + elif isinstance(self._current_contact, GroupchatParticipant): + self._update_participant_actions(self._current_contact) + else: + self._update_chat_actions(self._current_contact) + def _on_message_received(self, event: events.MessageReceived) -> None: if not event.msgtxt or event.properties.is_sent_carbon: return ===================================== gajim/gtk/control.py ===================================== @@ -531,7 +531,7 @@ def _add_message(self, if not self._scrolled_view.get_autoscroll(): if kind == 'outgoing': - self.reset_view() + self._scrolled_view.scroll_to_end() else: self._jump_to_end_button.add_unread_count() else: ===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -53,6 +53,7 @@ from ..message_widget import MessageWidget from ...dialogs import InputDialog from ...dialogs import DialogButton +from ...menus import get_groupchat_participant_menu from ...preview import PreviewWidget from ...util import format_fingerprint from ...util import get_cursor @@ -146,21 +147,7 @@ def __init__(self, if encryption_img: self._meta_box.pack_start(encryption_img, False, True, 0) - if display_marking and app.settings.get_account_setting( - account, 'enable_security_labels'): - label_text = GLib.markup_escape_text(display_marking.name) - if label_text: - display_marking_label = Gtk.Label() - display_marking_label.set_ellipsize(Pango.EllipsizeMode.END) - display_marking_label.set_max_width_chars(30) - display_marking_label.set_tooltip_text(label_text) - bgcolor = display_marking.bgcolor - fgcolor = display_marking.fgcolor - label_text = ( - f'<span size="small" bgcolor="{bgcolor}" ' - f'fgcolor="{fgcolor}"><tt>{label_text}</tt></span>') - display_marking_label.set_markup(label_text) - self._meta_box.add(display_marking_label) + self._add_security_label(display_marking) self._message_icons = MessageIcons() @@ -217,6 +204,31 @@ def __init__(self, self.show_all() + def _add_security_label(self, + display_marking: Optional[Displaymarking] + ) -> None: + + if display_marking is None: + return + + if not app.settings.get_account_setting(self._account, + 'enable_security_labels'): + return + + label_text = GLib.markup_escape_text(display_marking.name) + if label_text: + display_marking_label = Gtk.Label() + display_marking_label.set_ellipsize(Pango.EllipsizeMode.END) + display_marking_label.set_max_width_chars(30) + display_marking_label.set_tooltip_text(label_text) + bgcolor = display_marking.bgcolor + fgcolor = display_marking.fgcolor + label_text = ( + f'<span size="small" bgcolor="{bgcolor}" ' + f'fgcolor="{fgcolor}"><tt>{label_text}</tt></span>') + display_marking_label.set_markup(label_text) + self._meta_box.add(display_marking_label) + def _check_for_highlight(self, text: str) -> None: assert isinstance(self._contact, GroupchatContact) if self._contact.nickname is None: @@ -254,10 +266,43 @@ def _on_avatar_clicked(self, event: Gdk.EventButton, name: str ) -> int: - if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1: - app.window.activate_action('mention', GLib.Variant('s', name)) + if event.type == Gdk.EventType.BUTTON_PRESS: + if event.button == 1: + app.window.activate_action('mention', GLib.Variant('s', name)) + elif event.button == 3: + rect = Gdk.Rectangle() + rect.x, rect.y = int(event.x), int(event.y) + rect.height, rect.width = 1, 1 + self._show_participant_menu(name, rect) + return Gdk.EVENT_STOP + def _show_participant_menu(self, nick: str, rect: Gdk.Rectangle) -> None: + assert isinstance(self._contact, GroupchatContact) + if not self._contact.is_joined: + return + + self_contact = self._contact.get_self() + assert self_contact is not None + + if nick == self_contact.name: + # Don’t show menu for us + return + + contact = self._contact.get_resource(nick) + menu = get_groupchat_participant_menu(self._contact.account, + self_contact, + contact) + + def destroy(popover: Gtk.Popover) -> None: + app.check_finalize(popover) + GLib.idle_add(popover.set_relative_to, None) + + popover = Gtk.Popover.new_from_model(self, menu) + popover.set_pointing_to(rect) + popover.connect('closed', destroy) + popover.popup() + @staticmethod def _on_realize(event_box: Gtk.EventBox) -> None: window = event_box.get_window() ===================================== gajim/gtk/conversation/view.py ===================================== @@ -216,6 +216,7 @@ def _emit(self, signal_name: str, *args: Any) -> None: def _reset(self) -> None: self._current_upper = 0 + self._autoscroll = True self._request_history_at_upper = None self._upper_complete = False self._lower_complete = True @@ -633,6 +634,10 @@ def scroll_to_message_and_highlight(self, log_line_id: int) -> None: # This scrolls the ListBox to the highlighted row highlight_row.grab_focus() + def scroll_to_end(self) -> None: + adj = self.get_vadjustment() + adj.set_value(adj.get_upper() - adj.get_page_size()) + def _get_row_by_message_id(self, id_: str) -> Optional[MessageRow]: return self._message_id_row_map.get(id_) ===================================== gajim/gtk/groupchat_roster.py ===================================== @@ -38,7 +38,7 @@ from gajim.common.events import MUCNicknameChanged from gajim.common.modules.contacts import GroupchatContact -from .menus import get_groupchat_roster_menu +from .menus import get_groupchat_participant_menu from .tooltips import GCTooltip from .builder import get_builder from .util import EventHelper @@ -427,9 +427,9 @@ def _show_contact_menu(self, nick: str, rect: Gdk.Rectangle) -> None: self_contact = self._contact.get_self() assert self_contact is not None contact = self._contact.get_resource(nick) - menu = get_groupchat_roster_menu(self._contact.account, - self_contact, - contact) + menu = get_groupchat_participant_menu(self._contact.account, + self_contact, + contact) def destroy(popover: Gtk.Popover) -> None: app.check_finalize(popover) ===================================== gajim/gtk/menus.py ===================================== @@ -465,6 +465,10 @@ def get_groupchat_admin_menu(self_contact: types.GroupchatParticipant, menu = GajimMenu() + if contact.real_jid is None: + menu.add_item(_('Not Available'), 'dummy', None) + return menu + action = 'win.muc-change-affiliation' if is_affiliation_change_allowed(self_contact, contact, 'owner'): @@ -499,6 +503,10 @@ def get_groupchat_mod_menu(self_contact: types.GroupchatParticipant, menu = GajimMenu() + if not contact.is_available: + menu.add_item(_('Not Available'), 'dummy', None) + return menu + if is_role_change_allowed(self_contact, contact): value = f'"{contact.name}"' menu.add_item(_('Kick…'), 'win.muc-kick', value) @@ -519,10 +527,10 @@ def get_groupchat_mod_menu(self_contact: types.GroupchatParticipant, return menu -def get_groupchat_roster_menu(account: str, - self_contact: types.GroupchatParticipant, - contact: types.GroupchatParticipant - ) -> GajimMenu: +def get_groupchat_participant_menu(account: str, + self_contact: types.GroupchatParticipant, + contact: types.GroupchatParticipant + ) -> GajimMenu: value = f'"{contact.name}"' ===================================== gajim/gtk/start_chat.py ===================================== @@ -433,13 +433,14 @@ def _disco_muc(self, account: str, jid: JID, request_vcard: bool) -> None: jid, request_vcard=request_vcard, allow_redirect=True, + timeout=10, callback=self._muc_disco_info_received, user_data=account) def _muc_disco_info_received(self, task: Task) -> None: try: result = cast(DiscoInfo, task.finish()) - except StanzaError as error: + except (StanzaError, TimeoutStanzaError) as error: self._set_error(error) return @@ -455,12 +456,15 @@ def _muc_disco_info_received(self, task: Task) -> None: else: self._set_error_from_code('not-muc-service') - def _set_error(self, error: StanzaError) -> None: - text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error)) - if error.condition == 'gone': - reason = error.get_text(get_rfc5646_lang()) - if reason: - text = f'{text}:\n{reason}' + def _set_error(self, error: Union[StanzaError, TimeoutStanzaError]) -> None: + if isinstance(error, TimeoutStanzaError): + text = _('This address is not reachable.') + else: + text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error)) + if error.condition == 'gone': + reason = error.get_text(get_rfc5646_lang()) + if reason: + text = f'{text}:\n{reason}' self._show_error_page(text) def _set_error_from_code(self, error_code: str) -> None: View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/c25b2f6797524fd062ec7bb70f366cd…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/c25b2f6797524fd062ec7bb70f366cd…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 2 commits: new: Allow passing a timeout to as_task decorator
by Philipp Hörist (@lovetox)
01 Oct '22
01 Oct '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: d558d99c by Philipp Hörist at 2022-10-01T17:00:52+02:00 new: Allow passing a timeout to as_task decorator - - - - - d4736d92 by Philipp Hörist at 2022-10-01T17:05:49+02:00 imprv: StartChat: Add timeout when requesting MUC disco info - - - - - 2 changed files: - gajim/common/modules/util.py - gajim/gtk/start_chat.py Changes: ===================================== gajim/common/modules/util.py ===================================== @@ -111,8 +111,15 @@ def process(self, msg: str, kwargs: Any) -> tuple[str, Any]: def as_task(func): @wraps(func) - def func_wrapper(self, *args, callback=None, user_data=None, **kwargs): + def func_wrapper(self, + *args, + timeout=None, + callback=None, + user_data=None, + **kwargs): + task_ = Task(func(self, *args, **kwargs)) + task_.set_timeout(timeout) app.register_task(self, task_) task_.set_finalize_func(app.remove_task, id(self)) task_.set_user_data(user_data) ===================================== gajim/gtk/start_chat.py ===================================== @@ -433,13 +433,14 @@ def _disco_muc(self, account: str, jid: JID, request_vcard: bool) -> None: jid, request_vcard=request_vcard, allow_redirect=True, + timeout=10, callback=self._muc_disco_info_received, user_data=account) def _muc_disco_info_received(self, task: Task) -> None: try: result = cast(DiscoInfo, task.finish()) - except StanzaError as error: + except (StanzaError, TimeoutStanzaError) as error: self._set_error(error) return @@ -455,12 +456,15 @@ def _muc_disco_info_received(self, task: Task) -> None: else: self._set_error_from_code('not-muc-service') - def _set_error(self, error: StanzaError) -> None: - text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error)) - if error.condition == 'gone': - reason = error.get_text(get_rfc5646_lang()) - if reason: - text = f'{text}:\n{reason}' + def _set_error(self, error: Union[StanzaError, TimeoutStanzaError]) -> None: + if isinstance(error, TimeoutStanzaError): + text = _('This address is not reachable.') + else: + text = MUC_DISCO_ERRORS.get(error.condition, to_user_string(error)) + if error.condition == 'gone': + reason = error.get_text(get_rfc5646_lang()) + if reason: + text = f'{text}:\n{reason}' self._show_error_page(text) def _set_error_from_code(self, error_code: str) -> None: View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/327eca05543f97429205d7713da160b…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/327eca05543f97429205d7713da160b…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/python-nbxmpp][master] imprv: Tasks: Track timeouts within the task
by Philipp Hörist (@lovetox)
01 Oct '22
01 Oct '22
Philipp Hörist pushed to branch master at gajim / python-nbxmpp Commits: 1346d8c4 by Philipp Hörist at 2022-10-01T16:38:32+02:00 imprv: Tasks: Track timeouts within the task Previously we passed the timeout to send_stanza() which would not allow to set timeouts on other non-stanza related tasks. - - - - - 1 changed file: - nbxmpp/task.py Changes: ===================================== nbxmpp/task.py ===================================== @@ -28,6 +28,7 @@ from enum import IntEnum from functools import wraps from gi.repository import Soup +from gi.repository import GLib from nbxmpp.modules.base import BaseModule from nbxmpp.simplexml import Node @@ -146,6 +147,7 @@ class Task: self._error = None self._user_data: Optional[Any] = None self._timeout: Optional[int] = None + self._timeout_id: Optional[int] = None self._finalize_func = None self._finalize_context = None self._state = TaskState.INIT @@ -177,6 +179,12 @@ class Task: if not self._state.is_init: raise RuntimeError('Task already started') + if self._timeout is not None: + self._logger.info('Add timeout for task: %s s, task id: %s', + self._timeout, id(self)) + self._timeout_id = GLib.timeout_add_seconds( + self._timeout, self._on_timeout) + self._state = TaskState.RUNNING next(self._gen) self._next_step(self) @@ -284,19 +292,36 @@ class Task: self._finalize_func = func self._finalize_context = context - def cancel(self): + def _on_timeout(self) -> None: + self._logger.info('Timeout reached, task id: %s', id(self)) + if not self._state.is_running: + return + + self._timeout_id = None + + if self._sub_task is not None: + self._sub_task.cancel(invoke_callbacks=False) + + self._error = TimeoutStanzaError() + self._set_finished() + + def cancel(self, invoke_callbacks: bool = True) -> None: if not self._state.is_running: return self._state = TaskState.CANCELLED if self._sub_task is not None: - self._sub_task.cancel() + self._sub_task.cancel(invoke_callbacks=False) self._error = CancelledError() - self._invoke_callbacks() + if invoke_callbacks: + self._invoke_callbacks() self._finalize() def _finalize(self): + if self._timeout_id is not None: + GLib.source_remove(self._timeout_id) + self._timeout_id = None self._done_callbacks.clear() self._sub_task = None self._error = None View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/1346d8c4dae3757920ef1feb…
-- View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/1346d8c4dae3757920ef1feb…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
← Newer
1
...
18
19
20
21
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Results per page:
10
25
50
100
200