aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_summary
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-13 15:34:17 +0100
committerMarvin W <git@larma.de>2017-03-13 15:34:17 +0100
commit2804799f61eb4c68c5cf88b9996d13a81fe6317d (patch)
treeaafa39898d776d47293859d3afc90c57f744b2c9 /main/src/ui/conversation_summary
parentbb811f8b29ed8be96664277d2b8ca8a1c9829602 (diff)
downloaddino-2804799f61eb4c68c5cf88b9996d13a81fe6317d.tar.gz
dino-2804799f61eb4c68c5cf88b9996d13a81fe6317d.zip
Reduce GTK dependency to 3.16, fix dark theme
Diffstat (limited to 'main/src/ui/conversation_summary')
-rw-r--r--main/src/ui/conversation_summary/merged_message_item.vala35
-rw-r--r--main/src/ui/conversation_summary/view.vala20
2 files changed, 50 insertions, 5 deletions
diff --git a/main/src/ui/conversation_summary/merged_message_item.vala b/main/src/ui/conversation_summary/merged_message_item.vala
index fa198d21..0270ef42 100644
--- a/main/src/ui/conversation_summary/merged_message_item.vala
+++ b/main/src/ui/conversation_summary/merged_message_item.vala
@@ -22,21 +22,50 @@ public class MergedMessageItem : Grid {
[GtkChild] private Image received_image;
[GtkChild] private TextView message_text_view;
+ private StreamInteractor stream_interactor;
+ private TextTag link_tag;
+
public MergedMessageItem(StreamInteractor stream_interactor, Conversation conversation, Message message) {
this.conversation = conversation;
this.from = message.from;
this.initial_time = message.time;
+ this.stream_interactor = stream_interactor;
setup_tags();
add_message(message);
time_label.label = get_relative_time(initial_time.to_local());
- string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
- name_label.set_markup(@"<span foreground=\"#$(Util.get_name_hex_color(display_name))\">$display_name</span>");
Util.image_set_from_scaled_pixbuf(image, (new AvatarGenerator(30, 30, image.scale_factor)).draw_message(stream_interactor, message));
if (message.encryption != Encryption.NONE) {
encryption_image.visible = true;
encryption_image.set_from_icon_name("changes-prevent-symbolic", IconSize.SMALL_TOOLBAR);
}
+ name_label.label = Util.get_message_display_name(stream_interactor, message, conversation.account);
+
+ update_display_style();
+ message_text_view.style_updated.connect(style_changed);
+ }
+
+ private void style_changed() {
+ lock(message_text_view) {
+ message_text_view.style_updated.disconnect(style_changed);
+ update_display_style();
+ message_text_view.style_updated.connect(style_changed);
+ }
+ }
+
+ private void update_display_style() {
+ TextView tmp = new TextView();
+ RGBA bg = tmp.get_style_context().get_background_color(StateFlags.NORMAL);
+ bool dark_theme = (bg.red < 0.5 && bg.green < 0.5 && bg.blue < 0.5);
+
+ string display_name = Util.get_message_display_name(stream_interactor, messages[0], conversation.account);
+ name_label.set_markup(@"<span foreground=\"#$(Util.get_name_hex_color(display_name, dark_theme))\">$display_name</span>");
+
+ LinkButton lnk = new LinkButton("http://example.com");
+ RGBA link_color = lnk.get_style_context().get_color(StateFlags.LINK);
+ link_tag.foreground_rgba = link_color;
+
+ message_text_view.override_background_color(0, {0,0,0,0});
}
public void update() {
@@ -104,7 +133,7 @@ public class MergedMessageItem : Grid {
}
private void setup_tags() {
- message_text_view.buffer.create_tag("url", underline: Pango.Underline.SINGLE, foreground: "blue");
+ link_tag = message_text_view.buffer.create_tag("url", underline: Pango.Underline.SINGLE, foreground: "blue");
message_text_view.button_release_event.connect(open_url);
message_text_view.motion_notify_event.connect(change_cursor_over_url);
}
diff --git a/main/src/ui/conversation_summary/view.vala b/main/src/ui/conversation_summary/view.vala
index d2599041..87c553c5 100644
--- a/main/src/ui/conversation_summary/view.vala
+++ b/main/src/ui/conversation_summary/view.vala
@@ -27,7 +27,6 @@ public class View : Box {
bool reloading = false;
public View(StreamInteractor stream_interactor) {
- Object(homogeneous : false, spacing : 0);
this.stream_interactor = stream_interactor;
scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify);
scrolled.vadjustment.notify["value"].connect(on_value_notify);
@@ -50,6 +49,23 @@ public class View : Box {
}
return true;
});
+
+ update_background_color();
+ this.style_updated.connect(style_changed);
+ }
+
+ private void update_background_color() {
+ TextView tmp = new TextView();
+ this.override_background_color(0, tmp.get_style_context().get_background_color(0));
+ main.override_background_color(0, tmp.get_style_context().get_background_color(0));
+ }
+
+ private void style_changed() {
+ lock (main) {
+ this.style_updated.disconnect(style_changed);
+ update_background_color();
+ this.style_updated.connect(style_changed);
+ }
}
public void initialize_for_conversation(Conversation? conversation) {
@@ -129,7 +145,7 @@ public class View : Box {
if (was_upper == null || scrolled.vadjustment.value > was_upper - was_page_size - 1 ||
scrolled.vadjustment.value > was_upper - was_page_size - 1) { // scrolled down or content smaller than page size
scrolled.vadjustment.value = scrolled.vadjustment.upper - scrolled.vadjustment.page_size; // scroll down
- } else if (scrolled.vadjustment.value < scrolled.vadjustment.upper - scrolled.vadjustment.page_size - 1){
+ } else if (scrolled.vadjustment.value < scrolled.vadjustment.upper - scrolled.vadjustment.page_size - 1) {
scrolled.vadjustment.value = scrolled.vadjustment.upper - was_upper + scrolled.vadjustment.value; // stay at same content
}
was_upper = scrolled.vadjustment.upper;