Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2022-10-02 20:11:24 +0300
committerPhilipp Hörist <philipp@hoerist.com>2022-10-02 20:11:24 +0300
commitc0b999e0e65d980576b3bf5b45829ad7e1308442 (patch)
treeb41356a6faff21e731897adbc555e8b8bed6983f
parent75bfb459a8ddfc5997199b76bd3f5b32b43ac075 (diff)
refactor: ChatListRow: Sort methods
-rw-r--r--gajim/gtk/chat_list_row.py338
1 files changed, 169 insertions, 169 deletions
diff --git a/gajim/gtk/chat_list_row.py b/gajim/gtk/chat_list_row.py
index 43045fa72..2c81faa4a 100644
--- a/gajim/gtk/chat_list_row.py
+++ b/gajim/gtk/chat_list_row.py
@@ -238,88 +238,85 @@ class ChatListRow(Gtk.ListBoxRow):
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)]))
+ @property
+ def is_active(self) -> bool:
+ return (self.is_selected() and
+ self.get_toplevel().get_property('is-active'))
- def _popup_menu(self, event: Gdk.EventButton):
- menu = get_chat_list_row_menu(
- self.workspace_id, self.account, self.jid, self._pinned)
+ @property
+ def is_recent(self) -> bool:
+ if self._unread_count:
+ return True
+ return False
- 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
+ @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
- popover = GajimPopover(menu, relative_to=self)
- popover.set_pointing_to_coord(x=x, y=event.y)
- popover.popup()
+ @unread_count.setter
+ def unread_count(self, value: int) -> None:
+ self._unread_count = value
+ self._update_unread()
+ self.emit('unread-changed')
- def _on_drag_begin(self,
- row: ChatListRow,
- drag_context: Gdk.DragContext
- ) -> None:
+ def set_message_id(self, message_id: str) -> None:
+ self.message_id = message_id
- # 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)
- Gtk.drag_set_icon_surface(drag_context, surface)
+ 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})'
- def _on_drag_data_get(self,
- _widget: Gtk.Widget,
- _drag_context: Gdk.DragContext,
- selection_data: Gtk.SelectionData,
- _info: int,
- _time: int
- ) -> None:
+ 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>'
- 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)
+ # 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)
- def toggle_pinned(self) -> None:
- self._pinned = not self._pinned
+ 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()
- def _on_presence_update(self,
- _contact: ChatContactT,
- _signal_name: str
- ) -> None:
- self.update_avatar()
+ 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 _on_avatar_update(self,
- _contact: ChatContactT,
- _signal_name: str
- ) -> None:
- self.update_avatar()
+ def get_real_unread_count(self) -> int:
+ return self._unread_count
- def _on_muc_user_update(self,
- _contact: GroupchatParticipant,
- _signal_name: str,
- *args: Any
- ) -> None:
- self.update_avatar()
+ def set_stanza_id(self, stanza_id: str) -> None:
+ self.stanza_id = stanza_id
- def _on_muc_update(self,
- _contact: GroupchatContact,
- _signal_name: str,
- *args: Any
- ) -> None:
- self.update_avatar()
+ def set_timestamp(self, timestamp: int) -> None:
+ self.timestamp = timestamp
+ self.update_time()
+
+ 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 update_avatar(self) -> None:
scale = self.get_scale_factor()
@@ -338,53 +335,11 @@ class ChatListRow(Gtk.ListBoxRow):
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 update_time(self) -> None:
+ if self.timestamp == 0:
+ return
+ self._ui.timestamp_label.set_text(
+ get_uf_relative_time(self.timestamp))
def add_unread(self, text: str) -> None:
control = app.window.get_control()
@@ -427,16 +382,19 @@ class ChatListRow(Gtk.ListBoxRow):
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'))
+ def toggle_pinned(self) -> None:
+ self._pinned = not self._pinned
- @property
- def is_recent(self) -> bool:
- if self._unread_count:
- return True
- return False
+ 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 _on_state_flags_changed(self,
_row: ChatListRow,
@@ -460,58 +418,100 @@ class ChatListRow(Gtk.ListBoxRow):
'remove-chat',
GLib.Variant('as', [self.account, str(self.jid)]))
- def set_timestamp(self, timestamp: int) -> None:
- self.timestamp = timestamp
- self.update_time()
+ 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 set_stanza_id(self, stanza_id: str) -> None:
- self.stanza_id = stanza_id
+ def _popup_menu(self, event: Gdk.EventButton):
+ menu = get_chat_list_row_menu(
+ self.workspace_id, self.account, self.jid, self._pinned)
- def set_message_id(self, message_id: str) -> None:
- self.message_id = message_id
+ 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
- def update_time(self) -> None:
- if self.timestamp == 0:
- return
- self._ui.timestamp_label.set_text(
- get_uf_relative_time(self.timestamp))
+ popover = GajimPopover(menu, relative_to=self)
+ popover.set_pointing_to_coord(x=x, y=event.y)
+ popover.popup()
- 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 _on_drag_begin(self,
+ row: ChatListRow,
+ drag_context: Gdk.DragContext
+ ) -> None:
- 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})'
+ # 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)
+ Gtk.drag_set_icon_surface(drag_context, surface)
- 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>'
+ def _on_drag_data_get(self,
+ _widget: Gtk.Widget,
+ _drag_context: Gdk.DragContext,
+ selection_data: Gtk.SelectionData,
+ _info: int,
+ _time: int
+ ) -> None:
- # 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)
+ 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)
- if icon is None:
- self._ui.message_icon.hide()
+ 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 _on_chatstate_update(self,
+ contact: OneOnOneContactT,
+ _signal_name: str
+ ) -> None:
+ if contact.chatstate is None:
+ self._ui.chatstate_image.hide()
else:
- self._ui.message_icon.set_from_gicon(icon, Gtk.IconSize.MENU)
- self._ui.message_icon.show()
+ self._ui.chatstate_image.set_visible(contact.chatstate.is_composing)
+
+ def _on_nickname_update(self,
+ _contact: ChatContactT,
+ _signal_name: str
+ ) -> None:
+ self.update_name()
class BaseHeader(Gtk.Box):