Remove some use_markup usages, put skeleton header into .ui file

This commit is contained in:
fiaxh 2019-09-11 01:19:24 +02:00
parent 2a70a4e83f
commit 43720d3d2f
7 changed files with 87 additions and 52 deletions

View file

@ -47,6 +47,7 @@ set(RESOURCE_LIST
conversation_selector/chat_row_tooltip.ui conversation_selector/chat_row_tooltip.ui
conversation_selector/conversation_row.ui conversation_selector/conversation_row.ui
conversation_summary/image_toolbar.ui conversation_summary/image_toolbar.ui
conversation_summary/item_metadata_header.ui
conversation_summary/view.ui conversation_summary/view.ui
manage_accounts/account_row.ui manage_accounts/account_row.ui
manage_accounts/add_account_dialog.ui manage_accounts/add_account_dialog.ui

View file

@ -83,7 +83,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="message_label"> <object class="GtkLabel" id="message_label">
<property name="use_markup">True</property>
<property name="max_width_chars">1</property> <property name="max_width_chars">1</property>
<property name="ellipsize">end</property> <property name="ellipsize">end</property>
<property name="expand">True</property> <property name="expand">True</property>

View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="DinoUiConversationSummaryItemMetaDataHeader">
<property name="spacing">4</property>
<property name="orientation">horizontal</property>
<child>
<object class="GtkLabel" id="name_label">
<property name="use_markup">True</property>
<property name="xalign">0</property>
<property name="valign">start</property>
<property name="visible">True</property>
<attributes>
<attribute name="scale" value="0.8"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel" id="dot_label">
<property name="label">·</property>
<property name="xalign">0</property>
<property name="valign">start</property>
<property name="visible">True</property>
<attributes>
<attribute name="scale" value="0.8"/>
</attributes>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="time_label">
<property name="xalign">0</property>
<property name="valign">start</property>
<property name="visible">True</property>
<attributes>
<attribute name="scale" value="0.8"/>
</attributes>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkImage" id="encryption_image">
<property name="opacity">0.4</property>
</object>
</child>
<child>
<object class="GtkImage" id="received_image">
<property name="opacity">0.4</property>
</object>
</child>
</template>
</interface>

View file

@ -136,6 +136,7 @@ public class ConversationSelectorRow : ListBoxRow {
nick_label.label = last_message.direction == Message.DIRECTION_SENT ? _("Me") + ": " : ""; nick_label.label = last_message.direction == Message.DIRECTION_SENT ? _("Me") + ": " : "";
} }
name_label.attributes.filter((attr) => attr.equal(attr_style_new(Pango.Style.ITALIC)));
message_label.label = Util.summarize_whitespaces_to_space(last_message.body); message_label.label = Util.summarize_whitespaces_to_space(last_message.body);
break; break;
case FileItem.TYPE: case FileItem.TYPE:
@ -151,10 +152,11 @@ public class ConversationSelectorRow : ListBoxRow {
} }
bool file_is_image = transfer.mime_type != null && transfer.mime_type.has_prefix("image"); bool file_is_image = transfer.mime_type != null && transfer.mime_type.has_prefix("image");
message_label.attributes.insert(attr_style_new(Pango.Style.ITALIC));
if (transfer.direction == Message.DIRECTION_SENT) { if (transfer.direction == Message.DIRECTION_SENT) {
message_label.label = "<i>" + (file_is_image ? _("Image sent") : _("File sent") ) + "</i>"; message_label.label = (file_is_image ? _("Image sent") : _("File sent") );
} else { } else {
message_label.label = "<i>" + (file_is_image ? _("Image received") : _("File received") ) + "</i>"; message_label.label = (file_is_image ? _("Image received") : _("File received") );
} }
break; break;
} }

View file

@ -20,11 +20,12 @@ public class ConversationItemSkeleton : EventBox {
private Box image_content_box = new Box(Orientation.HORIZONTAL, 8) { visible=true }; private Box image_content_box = new Box(Orientation.HORIZONTAL, 8) { visible=true };
private Box header_content_box = new Box(Orientation.VERTICAL, 0) { visible=true }; private Box header_content_box = new Box(Orientation.VERTICAL, 0) { visible=true };
private DefaultSkeletonHeader default_header; private ItemMetaDataHeader metadata_header;
public ConversationItemSkeleton(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) { public ConversationItemSkeleton(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) {
this.conversation = conversation;
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
this.conversation = conversation;
this.item = item;
this.get_style_context().add_class("message-box"); this.get_style_context().add_class("message-box");
if (item.requires_avatar) { if (item.requires_avatar) {
@ -32,19 +33,14 @@ public class ConversationItemSkeleton : EventBox {
image_content_box.add(image); image_content_box.add(image);
} }
if (item.display_time != null) { if (item.display_time != null) {
default_header = new DefaultSkeletonHeader(stream_interactor, conversation, item) { visible=true }; metadata_header = new ItemMetaDataHeader(stream_interactor, conversation, item) { visible=true };
if (!item.requires_header) { if (!item.requires_header) {
default_header.name_label.visible = false; metadata_header.name_label.visible = false;
default_header.dot_label.visible = false; metadata_header.dot_label.visible = false;
} }
header_content_box.add(default_header); header_content_box.add(metadata_header);
} }
// add item
this.item = item;
if (default_header != null) {
default_header.add_item(item);
}
Widget? widget = item.get_widget(Plugins.WidgetType.GTK) as Widget; Widget? widget = item.get_widget(Plugins.WidgetType.GTK) as Widget;
if (widget != null) { if (widget != null) {
widget.valign = Align.END; widget.valign = Align.END;
@ -78,15 +74,15 @@ public class ConversationItemSkeleton : EventBox {
} }
public void update_time() { public void update_time() {
if (default_header != null) { if (metadata_header != null) {
default_header.update_time(); metadata_header.update_time();
} }
} }
public void update_margin() { public void update_margin() {
image.visible = this.show_skeleton; image.visible = this.show_skeleton;
if (default_header != null) { if (metadata_header != null) {
default_header.visible = this.show_skeleton; metadata_header.visible = this.show_skeleton;
} }
image_content_box.margin_start = this.show_skeleton ? 15 : 58; image_content_box.margin_start = this.show_skeleton ? 15 : 58;
image_content_box.margin_end = 15; image_content_box.margin_end = 15;
@ -101,40 +97,26 @@ public class ConversationItemSkeleton : EventBox {
} }
} }
public class DefaultSkeletonHeader : Box { [GtkTemplate (ui = "/im/dino/Dino/conversation_summary/item_metadata_header.ui")]
private Box box = new Box(Orientation.HORIZONTAL, 4) { visible=true }; public class ItemMetaDataHeader : Box {
public Label name_label = new Label("") { use_markup=true, valign=Align.START, xalign=0, visible=true }; [GtkChild] public Label name_label;
public Label time_label = new Label("") { use_markup=true, valign=Align.START, xalign=0, visible=true }; [GtkChild] public Label dot_label;
public Label dot_label = new Label("<span size='small'>·</span>") { use_markup=true, valign=Align.START, xalign=0, visible=true }; [GtkChild] public Label time_label;
public Image encryption_image = new Image(); [GtkChild] public Image encryption_image;
public Image received_image = new Image(); [GtkChild] public Image received_image;
public static IconSize ICON_SIZE_HEADER = Gtk.icon_size_register("im.dino.Dino.HEADER_ICON", 17, 12);
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
private Conversation conversation; private Conversation conversation;
private Plugins.MetaConversationItem item; private Plugins.MetaConversationItem item;
private ArrayList<Plugins.MetaConversationItem> items = new ArrayList<Plugins.MetaConversationItem>(); private ArrayList<Plugins.MetaConversationItem> items = new ArrayList<Plugins.MetaConversationItem>();
public static IconSize ICON_SIZE_HEADER = Gtk.icon_size_register("im.dino.Dino.HEADER_ICON", 17, 12); public ItemMetaDataHeader(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) {
public virtual string TEXT_SIZE { get { return "small"; } }
construct {
time_label.get_style_context().add_class("dim-label");
dot_label.get_style_context().add_class("dim-label");
encryption_image.opacity = 0.4;
received_image.opacity = 0.4;
}
public DefaultSkeletonHeader(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
this.conversation = conversation; this.conversation = conversation;
this.item = item; this.item = item;
items.add(item);
box.add(name_label);
box.add(dot_label);
box.add(time_label);
box.add(received_image);
box.add(encryption_image);
this.add(box);
update_name_label(); update_name_label();
name_label.style_updated.connect(update_name_label); name_label.style_updated.connect(update_name_label);
@ -143,25 +125,21 @@ public class DefaultSkeletonHeader : Box {
encryption_image.set_from_icon_name("dino-changes-prevent-symbolic", ICON_SIZE_HEADER); encryption_image.set_from_icon_name("dino-changes-prevent-symbolic", ICON_SIZE_HEADER);
} }
update_time(); update_time();
add_item(item);
}
public void add_item(Plugins.MetaConversationItem item) {
items.add(item);
item.notify["mark"].connect_after(update_received_mark); item.notify["mark"].connect_after(update_received_mark);
update_received_mark(); update_received_mark();
} }
public void update_time() { public void update_time() {
if (item.display_time != null) { if (item.display_time != null) {
time_label.label = @"<span size='$TEXT_SIZE'>" + get_relative_time(item.display_time.to_local()) + "</span>"; time_label.label = get_relative_time(item.display_time.to_local()).to_string();
} }
} }
private void update_name_label() { private void update_name_label() {
string display_name = Util.get_display_name(stream_interactor, item.jid, conversation.account); string display_name = Markup.escape_text(Util.get_display_name(stream_interactor, item.jid, conversation.account));
string color = Util.get_name_hex_color(stream_interactor, conversation.account, item.jid, Util.is_dark_theme(name_label)); string color = Util.get_name_hex_color(stream_interactor, conversation.account, item.jid, Util.is_dark_theme(name_label));
name_label.label = @"<span size='$TEXT_SIZE' foreground=\"#$color\">$display_name</span>"; name_label.label = @"<span foreground=\"#$color\">$display_name</span>";
} }
private void update_received_mark() { private void update_received_mark() {

View file

@ -154,7 +154,7 @@ public class GlobalSearch : Overlay {
context_box.add(get_context_message_widget(after_message.first())); context_box.add(get_context_message_widget(after_message.first()));
} }
Label date_label = new Label(ConversationSummary.DefaultSkeletonHeader.get_relative_time(item.display_time)) { xalign=0, visible=true }; Label date_label = new Label(ConversationSummary.ItemMetaDataHeader.get_relative_time(item.display_time)) { xalign=0, visible=true };
date_label.get_style_context().add_class("dim-label"); date_label.get_style_context().add_class("dim-label");
string display_name = Util.get_conversation_display_name(stream_interactor, item.conversation); string display_name = Util.get_conversation_display_name(stream_interactor, item.conversation);

View file

@ -295,7 +295,7 @@ public class AddAccountDialog : Gtk.Dialog {
register_title.label = _("Register on %s").printf(server.to_string()); register_title.label = _("Register on %s").printf(server.to_string());
if (form.oob != null) { if (form.oob != null) {
form_box.add(new Label(_("The server requires to sign up through a website")){ use_markup=true, visible=true } ); form_box.add(new Label(_("The server requires to sign up through a website")){ visible=true } );
form_box.add(new Label(@"<a href=\"$(form.oob)\">$(form.oob)</a>") { use_markup=true, visible=true }); form_box.add(new Label(@"<a href=\"$(form.oob)\">$(form.oob)</a>") { use_markup=true, visible=true });
register_form_continue_label.label = _("Open Registration"); register_form_continue_label.label = _("Open Registration");
register_form_continue.visible = true; register_form_continue.visible = true;