diff options
Diffstat (limited to 'main/src/ui')
-rw-r--r-- | main/src/ui/application.vala | 13 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/merged_message_item.vala | 35 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/view.vala | 20 | ||||
-rw-r--r-- | main/src/ui/util.vala | 14 |
4 files changed, 59 insertions, 23 deletions
diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index fe930b82..8dbe176b 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -16,8 +16,6 @@ public class Dino.Ui.Application : Dino.Application { notifications = new Notifications(stream_interaction); notifications.start(); Environment.set_application_name("Dino"); - - load_css(); } public override void activate() { @@ -83,16 +81,5 @@ public class Dino.Ui.Application : Dino.Application { private void remove_connection(Account account) { stream_interaction.disconnect(account); } - - private void load_css() { - var css_provider = new Gtk.CssProvider (); - try { - var file = File.new_for_uri("resource:///org/dino-im/style.css"); - css_provider.load_from_file (file); - } catch (GLib.Error e) { - warning ("loading css: %s", e.message); - } - Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - } } 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; diff --git a/main/src/ui/util.vala b/main/src/ui/util.vala index 0a294731..aad0817d 100644 --- a/main/src/ui/util.vala +++ b/main/src/ui/util.vala @@ -9,17 +9,21 @@ public class Util : Object { private const string[] tango_colors_light = {"FCE94F", "FCAF3E", "E9B96E", "8AE234", "729FCF", "AD7FA8", "EF2929"}; private const string[] tango_colors_medium = {"EDD400", "F57900", "C17D11", "73D216", "3465A4", "75507B", "CC0000"}; - private const string[] material_colors_500 = {"F44336", "E91E63", "9C27B0", "673AB7", "3f51B5", "2196F3", "03A9f4", "00BCD4", "009688", "4CAF50", "8BC34a", "CDDC39", "FFEB3B", "FFC107", "FF9800", "FF5722", "795548"}; - private const string[] material_colors_300 = {"E57373", "F06292", "BA68C8", "9575CD", "7986CB", "64B5F6", "4FC3F7", "4DD0E1", "4DB6AC", "81C784", "AED581", "DCE775", "FFF176", "FFD54F", "FFB74D", "FF8A65", "A1887F"}; - private const string[] material_colors_200 = {"EF9A9A", "F48FB1", "CE93D8", "B39DDB", "9FA8DA", "90CAF9", "81D4FA", "80DEEA", "80CBC4", "A5D6A7", "C5E1A5", "E6EE9C", "FFF59D", "FFE082", "FFCC80", "FFAB91", "BCAAA4"}; + private const string[] material_colors_500 = {"F44336", "E91E63", "9C27B0", "673AB7", "3f51B5", "2196F3", "03A9f4", "00BCD4", "009688", "4CAF50", "8BC34a", "CDDC39", "FFC107", "FF9800", "FF5722", "795548"}; + private const string[] material_colors_300 = {"E57373", "F06292", "BA68C8", "9575CD", "7986CB", "64B5F6", "4FC3F7", "4DD0E1", "4DB6AC", "81C784", "AED581", "DCE775", "FFD54F", "FFB74D", "FF8A65", "A1887F"}; + private const string[] material_colors_200 = {"EF9A9A", "F48FB1", "CE93D8", "B39DDB", "9FA8DA", "90CAF9", "81D4FA", "80DEEA", "80CBC4", "A5D6A7", "C5E1A5", "E6EE9C", "FFE082", "FFCC80", "FFAB91", "BCAAA4"}; public static string get_avatar_hex_color(string name) { return material_colors_300[name.hash() % material_colors_300.length]; // return tango_colors_light[name.hash() % tango_colors_light.length]; } - public static string get_name_hex_color(string name) { - return material_colors_500[name.hash() % material_colors_500.length]; + public static string get_name_hex_color(string name, bool dark_theme = false) { + if (dark_theme) { + return material_colors_300[name.hash() % material_colors_300.length]; + } else { + return material_colors_500[name.hash() % material_colors_500.length]; + } // return tango_colors_medium[name.hash() % tango_colors_medium.length]; } |