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-09 19:16:47 +0300
committerPhilipp Hörist <philipp@hoerist.com>2022-10-09 20:32:26 +0300
commitf2b86948fae7037ab253ca498f63cdccfd0ed9bf (patch)
tree250f7edaaf566ee944cec16cd4f9f8b3d94795e4
parent659ef014485b5c25e37bfd504c38bfaf2a16aef5 (diff)
refactor: Rows: Add DateTimeLabel
-rw-r--r--gajim/gtk/conversation/rows/base.py18
-rw-r--r--gajim/gtk/conversation/rows/call.py3
-rw-r--r--gajim/gtk/conversation/rows/command_output.py3
-rw-r--r--gajim/gtk/conversation/rows/file_transfer.py4
-rw-r--r--gajim/gtk/conversation/rows/file_transfer_jingle.py3
-rw-r--r--gajim/gtk/conversation/rows/info.py3
-rw-r--r--gajim/gtk/conversation/rows/message.py3
-rw-r--r--gajim/gtk/conversation/rows/muc_join_left.py3
-rw-r--r--gajim/gtk/conversation/rows/muc_subject.py3
-rw-r--r--gajim/gtk/conversation/rows/user_status.py3
-rw-r--r--gajim/gtk/conversation/rows/widgets.py21
11 files changed, 39 insertions, 28 deletions
diff --git a/gajim/gtk/conversation/rows/base.py b/gajim/gtk/conversation/rows/base.py
index 4f5f5b112..9871fbf56 100644
--- a/gajim/gtk/conversation/rows/base.py
+++ b/gajim/gtk/conversation/rows/base.py
@@ -23,7 +23,6 @@ from gi.repository import Gtk
from gi.repository import Pango
from gajim.common import app
-from gajim.common.helpers import from_one_line
class BaseRow(Gtk.ListBoxRow):
@@ -61,23 +60,6 @@ class BaseRow(Gtk.ListBoxRow):
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()
label.set_selectable(True)
diff --git a/gajim/gtk/conversation/rows/call.py b/gajim/gtk/conversation/rows/call.py
index 42851e653..c174fc71c 100644
--- a/gajim/gtk/conversation/rows/call.py
+++ b/gajim/gtk/conversation/rows/call.py
@@ -31,6 +31,7 @@ from gajim.common.i18n import _
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 @@ class CallRow(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/command_output.py b/gajim/gtk/conversation/rows/command_output.py
index 295f64e39..844d67f3e 100644
--- a/gajim/gtk/conversation/rows/command_output.py
+++ b/gajim/gtk/conversation/rows/command_output.py
@@ -20,6 +20,7 @@ from gi.repository import Gtk
from gajim.common.const import AvatarSize
+from .widgets import DateTimeLabel
from .widgets import SimpleLabel
from .base import BaseRow
@@ -43,7 +44,7 @@ class CommandOutputRow(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/file_transfer.py b/gajim/gtk/conversation/rows/file_transfer.py
index a00695121..79fba1df1 100644
--- a/gajim/gtk/conversation/rows/file_transfer.py
+++ b/gajim/gtk/conversation/rows/file_transfer.py
@@ -27,7 +27,7 @@ from gajim.common.i18n import _
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 @@ class FileTransferRow(BaseRow, EventHelper):
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)
diff --git a/gajim/gtk/conversation/rows/file_transfer_jingle.py b/gajim/gtk/conversation/rows/file_transfer_jingle.py
index e74efa6f8..954bf9def 100644
--- a/gajim/gtk/conversation/rows/file_transfer_jingle.py
+++ b/gajim/gtk/conversation/rows/file_transfer_jingle.py
@@ -48,6 +48,7 @@ from gajim.common.modules.contacts import BareContact
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 @@ class FileTransferJingleRow(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/info.py b/gajim/gtk/conversation/rows/info.py
index 6b774115b..1349dca0b 100644
--- a/gajim/gtk/conversation/rows/info.py
+++ b/gajim/gtk/conversation/rows/info.py
@@ -23,6 +23,7 @@ from gi.repository import Gtk
from gajim.common.const import AvatarSize
+from .widgets import DateTimeLabel
from .widgets import SimpleLabel
from .base import BaseRow
@@ -55,7 +56,7 @@ class InfoMessage(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/message.py b/gajim/gtk/conversation/rows/message.py
index 9e7c8463d..9d520489b 100644
--- a/gajim/gtk/conversation/rows/message.py
+++ b/gajim/gtk/conversation/rows/message.py
@@ -49,6 +49,7 @@ from gajim.common.modules.contacts import GroupchatContact
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 @@ class MessageRow(BaseRow):
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:
diff --git a/gajim/gtk/conversation/rows/muc_join_left.py b/gajim/gtk/conversation/rows/muc_join_left.py
index 1de61264a..e586eca25 100644
--- a/gajim/gtk/conversation/rows/muc_join_left.py
+++ b/gajim/gtk/conversation/rows/muc_join_left.py
@@ -23,6 +23,7 @@ from gajim.common.i18n import _
from gajim.common.const import AvatarSize
from .widgets import SimpleLabel
+from .widgets import DateTimeLabel
from .base import BaseRow
@@ -65,7 +66,7 @@ class MUCJoinLeft(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/muc_subject.py b/gajim/gtk/conversation/rows/muc_subject.py
index d15d09903..8cd38b438 100644
--- a/gajim/gtk/conversation/rows/muc_subject.py
+++ b/gajim/gtk/conversation/rows/muc_subject.py
@@ -26,6 +26,7 @@ from gajim.common.const import AvatarSize
from gajim.common.i18n import _
from .base import BaseRow
+from .widgets import DateTimeLabel
from ..message_widget import MessageWidget
@@ -79,7 +80,7 @@ class MUCSubject(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/user_status.py b/gajim/gtk/conversation/rows/user_status.py
index 450a38dec..6100cfd91 100644
--- a/gajim/gtk/conversation/rows/user_status.py
+++ b/gajim/gtk/conversation/rows/user_status.py
@@ -26,6 +26,7 @@ from gajim.common.const import AvatarSize
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 @@ class UserStatus(BaseRow):
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)
diff --git a/gajim/gtk/conversation/rows/widgets.py b/gajim/gtk/conversation/rows/widgets.py
index ea77f966c..666033c1e 100644
--- a/gajim/gtk/conversation/rows/widgets.py
+++ b/gajim/gtk/conversation/rows/widgets.py
@@ -16,6 +16,8 @@ from __future__ import annotations
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 @@ class MoreMenuButton(Gtk.Button):
@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'))