Philipp Hörist pushed to branch master at gajim / gajim
Commits: 659ef014 by Philipp Hörist at 2022-10-09T19:32:26+02:00 refactor: Archive: Simplify setting earliest timestamp
- - - - - f2b86948 by Philipp Hörist at 2022-10-09T19:32:26+02:00 refactor: Rows: Add DateTimeLabel
- - - - -
12 changed files:
- gajim/common/storage/archive.py - gajim/gtk/conversation/rows/base.py - gajim/gtk/conversation/rows/call.py - gajim/gtk/conversation/rows/command_output.py - gajim/gtk/conversation/rows/file_transfer.py - gajim/gtk/conversation/rows/file_transfer_jingle.py - gajim/gtk/conversation/rows/info.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/rows/muc_join_left.py - gajim/gtk/conversation/rows/muc_subject.py - gajim/gtk/conversation/rows/user_status.py - gajim/gtk/conversation/rows/widgets.py
Changes:
===================================== gajim/common/storage/archive.py ===================================== @@ -566,9 +566,8 @@ def search_log(self, else: before_ts = before.timestamp()
- if after is None: - after_ts = datetime.datetime(1971, 1, 1).timestamp() - else: + after_ts = 0 + if after is not None: after_ts = after.timestamp()
if from_users is None: @@ -644,9 +643,8 @@ def search_all_logs(self, else: before_ts = before.timestamp()
- if after is None: - after_ts = datetime.datetime(1971, 1, 1).timestamp() - else: + after_ts = 0 + if after is not None: after_ts = after.timestamp()
if from_users is None:
===================================== gajim/gtk/conversation/rows/base.py ===================================== @@ -23,7 +23,6 @@ from gi.repository import Pango
from gajim.common import app -from gajim.common.helpers import from_one_line
class BaseRow(Gtk.ListBoxRow): @@ -60,23 +59,6 @@ def __init__(self, account: str, widget: Optional[str] = None) -> None: def is_merged(self) -> bool: return self._merged
- @staticmethod - def create_timestamp_widget(timestamp: datetime) -> Gtk.Label: - time_format = from_one_line(app.settings.get('chat_timestamp_format')) - if timestamp.date() < datetime.today().date(): - date_format = from_one_line( - app.settings.get('date_timestamp_format')) - time_format = f'{time_format} - {date_format}' - timestamp_formatted = timestamp.strftime(time_format) - label = Gtk.Label(label=timestamp_formatted) - label.set_halign(Gtk.Align.START) - label.set_valign(Gtk.Align.END) - label.set_margin_start(6) - label.set_margin_end(3) - label.get_style_context().add_class('conversation-meta') - label.set_tooltip_text(timestamp.strftime('%a, %d %b %Y - %X')) - return label - @staticmethod def create_name_widget(name: str, from_us: bool) -> Gtk.Label: label = Gtk.Label()
===================================== gajim/gtk/conversation/rows/call.py ===================================== @@ -31,6 +31,7 @@ from gajim.common.jingle_session import JingleSession from gajim.common.storage.archive import ConversationRow
+from .widgets import DateTimeLabel from .widgets import SimpleLabel from .base import BaseRow
@@ -141,7 +142,7 @@ def _add_history_call_widget(self) -> None: name_widget.set_halign(Gtk.Align.START) name_widget.set_valign(Gtk.Align.START)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_halign(Gtk.Align.START) timestamp_widget.set_valign(Gtk.Align.START)
===================================== gajim/gtk/conversation/rows/command_output.py ===================================== @@ -20,6 +20,7 @@
from gajim.common.const import AvatarSize
+from .widgets import DateTimeLabel from .widgets import SimpleLabel from .base import BaseRow
@@ -43,7 +44,7 @@ def __init__(self, account: str, text: str, is_error: bool) -> None: avatar_placeholder.add(icon) self.grid.attach(avatar_placeholder, 0, 0, 1, 1)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_valign(Gtk.Align.START) timestamp_widget.set_margin_start(0) self.grid.attach(timestamp_widget, 1, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/file_transfer.py ===================================== @@ -27,7 +27,7 @@ from gajim.common.modules.httpupload import HTTPFileTransfer
from .base import BaseRow - +from .widgets import DateTimeLabel from ...dialogs import ErrorDialog from ...util import EventHelper from ...builder import get_builder @@ -62,7 +62,7 @@ def __init__(self, account: str, transfer: HTTPFileTransfer) -> None: avatar_placeholder.set_size_request(AvatarSize.ROSTER, -1) self.grid.attach(avatar_placeholder, 0, 0, 1, 1)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_halign(Gtk.Align.START) timestamp_widget.set_valign(Gtk.Align.START) self.grid.attach(timestamp_widget, 1, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/file_transfer_jingle.py ===================================== @@ -48,6 +48,7 @@ from gajim.common.storage.archive import ConversationRow
from .base import BaseRow +from .widgets import DateTimeLabel from ...builder import get_builder from ...util import format_eta
@@ -125,7 +126,7 @@ def __init__(self, name_widget.set_halign(Gtk.Align.START) name_widget.set_valign(Gtk.Align.START)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_hexpand(True) timestamp_widget.set_valign(Gtk.Align.START)
===================================== gajim/gtk/conversation/rows/info.py ===================================== @@ -23,6 +23,7 @@
from gajim.common.const import AvatarSize
+from .widgets import DateTimeLabel from .widgets import SimpleLabel from .base import BaseRow
@@ -55,7 +56,7 @@ def __init__(self, self._label.set_text(text) self.grid.attach(self._label, 2, 0, 1, 1)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_halign(Gtk.Align.START) timestamp_widget.set_valign(Gtk.Align.END) self.grid.attach(timestamp_widget, 3, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -49,6 +49,7 @@ from gajim.common.types import ChatContactT
from .base import BaseRow +from .widgets import DateTimeLabel from .widgets import MoreMenuButton from ..message_widget import MessageWidget from ...dialogs import InputDialog @@ -140,7 +141,7 @@ def __init__(self, self._meta_box = Gtk.Box(spacing=6) self._meta_box.set_hexpand(True) self._meta_box.pack_start(name_widget, False, True, 0) - timestamp_label = self.create_timestamp_widget(self.timestamp) + timestamp_label = DateTimeLabel(self.timestamp) self._meta_box.pack_start(timestamp_label, False, True, 0)
if additional_data is not None:
===================================== gajim/gtk/conversation/rows/muc_join_left.py ===================================== @@ -23,6 +23,7 @@ from gajim.common.const import AvatarSize
from .widgets import SimpleLabel +from .widgets import DateTimeLabel from .base import BaseRow
@@ -65,7 +66,7 @@ def __init__(self, self._label.get_style_context().add_class('gajim-status-message') self.grid.attach(self._label, 2, 0, 1, 1)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_halign(Gtk.Align.START) timestamp_widget.set_valign(Gtk.Align.FILL) self.grid.attach(timestamp_widget, 3, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/muc_subject.py ===================================== @@ -26,6 +26,7 @@ from gajim.common.i18n import _
from .base import BaseRow +from .widgets import DateTimeLabel from ..message_widget import MessageWidget
@@ -79,7 +80,7 @@ def __init__(self, subject_box.add(message_widget) self.grid.attach(subject_box, 1, 0, 1, 1)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_valign(Gtk.Align.START) self.grid.attach(timestamp_widget, 2, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/user_status.py ===================================== @@ -26,6 +26,7 @@ from gajim.common.helpers import get_uf_show
from .widgets import SimpleLabel +from .widgets import DateTimeLabel from .base import BaseRow from ..message_widget import MessageWidget from ...avatar import get_show_circle @@ -70,7 +71,7 @@ def __init__(self, message_widget.add_with_styling(status) self.grid.attach(message_widget, 2, 1, 1, 1)
- timestamp_widget = self.create_timestamp_widget(self.timestamp) + timestamp_widget = DateTimeLabel(self.timestamp) timestamp_widget.set_halign(Gtk.Align.START) timestamp_widget.set_valign(Gtk.Align.END) self.grid.attach(timestamp_widget, 3, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/widgets.py ===================================== @@ -16,6 +16,8 @@
from typing import TYPE_CHECKING
+from datetime import datetime + from gi.repository import Gtk from gi.repository import Pango from gi.repository import GLib @@ -157,3 +159,22 @@ def _create_popover(self, @staticmethod def _on_closed(popover: Gtk.Popover) -> None: GLib.idle_add(popover.destroy) + + +class DateTimeLabel(Gtk.Label): + def __init__(self, timestamp: datetime) -> None: + Gtk.Label.__init__(self) + + time_format = app.settings.get('chat_timestamp_format') + if timestamp.date() < datetime.today().date(): + date_format = app.settings.get('date_timestamp_format') + time_format = f'{time_format} - {date_format}' + timestamp_formatted = timestamp.strftime(time_format) + + self.set_label(timestamp_formatted) + self.set_halign(Gtk.Align.START) + self.set_valign(Gtk.Align.END) + self.set_margin_start(6) + self.set_margin_end(3) + self.get_style_context().add_class('conversation-meta') + self.set_tooltip_text(timestamp.strftime('%a, %d %b %Y - %X'))
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/6ca265f1af0760deb67ed16170335b7c...