Clean up ConversationTitlebar

This commit is contained in:
fiaxh 2019-04-12 17:43:47 +02:00
parent d9e45071d0
commit 6e1938b089
9 changed files with 78 additions and 107 deletions

View file

@ -102,8 +102,8 @@ SOURCES
src/ui/conversation_list_titlebar.vala
src/ui/conversation_list_titlebar_csd.vala
src/ui/global_search.vala
src/ui/conversation_selector/conversation_row.vala
src/ui/conversation_selector/list.vala
src/ui/conversation_selector/conversation_selector_row.vala
src/ui/conversation_selector/conversation_selector.vala
src/ui/conversation_summary/chat_state_populator.vala
src/ui/conversation_summary/content_item_widget_factory.vala
src/ui/conversation_summary/content_populator.vala
@ -114,8 +114,7 @@ SOURCES
src/ui/conversation_titlebar/menu_entry.vala
src/ui/conversation_titlebar/occupants_entry.vala
src/ui/conversation_titlebar/search_entry.vala
src/ui/conversation_titlebar/view.vala
src/ui/conversation_titlebar/view_csd.vala
src/ui/conversation_titlebar/conversation_titlebar.vala
src/ui/manage_accounts/account_row.vala
src/ui/manage_accounts/add_account_dialog.vala
src/ui/manage_accounts/dialog.vala

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="DinoUiConversationSelectorConversationRow">
<template class="DinoUiConversationSelectorRow">
<property name="visible">True</property>
<child>
<object class="GtkRevealer" id="main_revealer">

View file

@ -10,7 +10,7 @@
<property name="hscrollbar_policy">never</property>
<property name="visible">True</property>
<child>
<object class="DinoUiConversationSelectorList" id="conversation_list">
<object class="DinoUiConversationSelector" id="conversation_list">
<property name="visible">True</property>
</object>
</child>

View file

@ -4,17 +4,17 @@ using Gtk;
using Xmpp;
using Dino.Entities;
namespace Dino.Ui.ConversationSelector {
namespace Dino.Ui {
public class List : ListBox {
public class ConversationSelector : ListBox {
public signal void conversation_selected(Conversation conversation);
private StreamInteractor stream_interactor;
private string[]? filter_values;
private HashMap<Conversation, ConversationRow> rows = new HashMap<Conversation, ConversationRow>(Conversation.hash_func, Conversation.equals_func);
private HashMap<Conversation, ConversationSelectorRow> rows = new HashMap<Conversation, ConversationSelectorRow>(Conversation.hash_func, Conversation.equals_func);
public List init(StreamInteractor stream_interactor) {
public ConversationSelector init(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(add_conversation);
@ -22,7 +22,7 @@ public class List : ListBox {
stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received);
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_message_received);
Timeout.add_seconds(60, () => {
foreach (ConversationRow row in rows.values) row.update();
foreach (ConversationSelectorRow row in rows.values) row.update();
return true;
});
@ -50,8 +50,8 @@ public class List : ListBox {
}
public override void row_activated(ListBoxRow r) {
if (r.get_type().is_a(typeof(ConversationRow))) {
ConversationRow row = r as ConversationRow;
ConversationSelectorRow? row = r as ConversationSelectorRow;
if (row != null) {
conversation_selected(row.conversation);
}
}
@ -78,9 +78,9 @@ public class List : ListBox {
}
private void add_conversation(Conversation conversation) {
ConversationRow row;
ConversationSelectorRow row;
if (!rows.has_key(conversation)) {
row = new ConversationRow(stream_interactor, conversation);
row = new ConversationSelectorRow(stream_interactor, conversation);
rows[conversation] = row;
add(row);
row.closed.connect(() => { select_fallback_conversation(conversation); });
@ -130,8 +130,8 @@ public class List : ListBox {
}
private bool filter(ListBoxRow r) {
if (r.get_type().is_a(typeof(ConversationRow))) {
ConversationRow row = r as ConversationRow;
ConversationSelectorRow? row = r as ConversationSelectorRow;
if (row != null) {
if (filter_values != null && filter_values.length != 0) {
foreach (string filter in filter_values) {
if (!(Util.get_conversation_display_name(stream_interactor, row.conversation).down().contains(filter.down()) ||
@ -145,8 +145,8 @@ public class List : ListBox {
}
private int sort(ListBoxRow row1, ListBoxRow row2) {
ConversationRow cr1 = row1 as ConversationRow;
ConversationRow cr2 = row2 as ConversationRow;
ConversationSelectorRow cr1 = row1 as ConversationSelectorRow;
ConversationSelectorRow cr2 = row2 as ConversationSelectorRow;
if (cr1 != null && cr2 != null) {
Conversation c1 = cr1.conversation;
Conversation c2 = cr2.conversation;

View file

@ -7,10 +7,10 @@ using Dino;
using Dino.Entities;
using Xmpp;
namespace Dino.Ui.ConversationSelector {
namespace Dino.Ui {
[GtkTemplate (ui = "/im/dino/Dino/conversation_selector/conversation_row.ui")]
public class ConversationRow : ListBoxRow {
public class ConversationSelectorRow : ListBoxRow {
public signal void closed();
@ -38,7 +38,7 @@ public class ConversationRow : ListBoxRow {
name_label.attributes = new AttrList();
}
public ConversationRow(StreamInteractor stream_interactor, Conversation conversation) {
public ConversationSelectorRow(StreamInteractor stream_interactor, Conversation conversation) {
this.conversation = conversation;
this.stream_interactor = stream_interactor;

View file

@ -6,7 +6,12 @@ using Dino.Entities;
namespace Dino.Ui {
public class ConversationTitlebar : Gtk.Box {
public interface ConversationTitlebar: Widget {
public abstract string? subtitle { get; set; }
public abstract string? title { get; set; }
}
public class ConversationTitlebarNoCsd : ConversationTitlebar, Gtk.Box {
public string? title {
get { return title_label.label; }
@ -21,8 +26,6 @@ public class ConversationTitlebar : Gtk.Box {
}
}
private StreamInteractor stream_interactor;
private Box content_box = new Box(Orientation.HORIZONTAL, 0) { margin=5, margin_start=15, margin_end=5, hexpand=true, visible=true };
private Label title_label = new Label("") { visible=true };
private Label subtitle_label = new Label("") { use_markup=true, ellipsize=EllipsizeMode.END, visible=false };
@ -45,9 +48,7 @@ public class ConversationTitlebar : Gtk.Box {
content_box.add(placeholder_box);
}
public ConversationTitlebar(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
public ConversationTitlebarNoCsd() {
this.get_style_context().add_class("dino-header-right");
hexpand = true;
search_button.set_image(new Gtk.Image.from_icon_name("system-search-symbolic", Gtk.IconSize.MENU) { visible = true });
@ -64,4 +65,29 @@ public class ConversationTitlebar : Gtk.Box {
}
}
public class ConversationTitlebarCsd : ConversationTitlebar, Gtk.HeaderBar {
public new string? title { get { return this.get_title(); } set { base.set_title(value); } }
public new string? subtitle { get { return this.get_subtitle(); } set { base.set_subtitle(value); } }
public ConversationTitlebarCsd() {
this.get_style_context().add_class("dino-right");
show_close_button = true;
hexpand = true;
Application app = GLib.Application.get_default() as Application;
ArrayList<Plugins.ConversationTitlebarWidget> widgets = new ArrayList<Plugins.ConversationTitlebarWidget>();
foreach(var e in app.plugin_registry.conversation_titlebar_entries) {
Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
widgets.insert(0, widget);
}
}
foreach (var w in widgets) {
Button gtk_widget = (Gtk.Button)w;
this.pack_end(gtk_widget);
}
}
}
}

View file

@ -1,36 +0,0 @@
using Gtk;
using Gee;
using Dino.Entities;
namespace Dino.Ui {
public class ConversationTitlebarCsd : Gtk.HeaderBar {
private StreamInteractor stream_interactor;
private Window window;
public ConversationTitlebarCsd(StreamInteractor stream_interactor, Window window) {
this.stream_interactor = stream_interactor;
this.window = window;
this.get_style_context().add_class("dino-right");
show_close_button = true;
hexpand = true;
Application app = GLib.Application.get_default() as Application;
ArrayList<Plugins.ConversationTitlebarWidget> widgets = new ArrayList<Plugins.ConversationTitlebarWidget>();
foreach(var e in app.plugin_registry.conversation_titlebar_entries) {
Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
widgets.insert(0, widget);
}
}
foreach (var w in widgets) {
Button gtk_widget = (Gtk.Button)w;
this.pack_end(gtk_widget);
}
}
}
}

View file

@ -10,43 +10,16 @@ public class UnifiedWindow : Gtk.Window {
public signal void conversation_selected(Conversation conversation);
public new string? title {
get {
return Util.use_csd() ? conversation_titlebar_csd.title : conversation_titlebar.title;
}
set {
if (Util.use_csd()) {
conversation_titlebar_csd.title = value;
} else {
conversation_titlebar.title = value;
}
}
}
public string? subtitle {
get {
return Util.use_csd() ? conversation_titlebar_csd.subtitle : conversation_titlebar.subtitle;
}
set {
string? new_subtitle = value == null ? null : (/\s+/).replace_literal(value, -1, 0, " ");
if (Util.use_csd()) {
conversation_titlebar_csd.subtitle = new_subtitle;
} else {
conversation_titlebar.subtitle = new_subtitle;
}
}
}
public new string? title { get; set; }
public string? subtitle { get; set; }
public WelcomePlceholder welcome_placeholder = new WelcomePlceholder() { visible=true };
public NoAccountsPlaceholder accounts_placeholder = new NoAccountsPlaceholder() { visible=true };
public NoConversationsPlaceholder conversations_placeholder = new NoConversationsPlaceholder() { visible=true };
public ChatInput.View chat_input;
public ConversationListTitlebar conversation_list_titlebar;
public ConversationListTitlebarCsd conversation_list_titlebar_csd;
public ConversationSelector.List filterable_conversation_list;
public ConversationSelector conversation_selector;
public ConversationSummary.ConversationView conversation_frame;
public ConversationTitlebar conversation_titlebar;
public ConversationTitlebarCsd conversation_titlebar_csd;
public HeaderBar placeholder_headerbar = new HeaderBar() { title="Dino", show_close_button=true, visible=true };
public Box box = new Box(Orientation.VERTICAL, 0) { orientation=Orientation.VERTICAL, visible=true };
public Paned headerbar_paned = new Paned(Orientation.HORIZONTAL) { visible=true };
@ -74,13 +47,15 @@ public class UnifiedWindow : Gtk.Window {
setup_unified();
setup_stack();
this.bind_property("title", conversation_titlebar, "title");
this.bind_property("subtitle", conversation_titlebar, "subtitle");
paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
stream_interactor.account_added.connect((account) => { check_stack(true); });
stream_interactor.account_removed.connect((account) => { check_stack(); });
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(() => check_stack());
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(() => check_stack());
paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
check_stack();
}
@ -97,7 +72,7 @@ public class UnifiedWindow : Gtk.Window {
box.add(paned);
chat_input = ((ChatInput.View) builder.get_object("chat_input")).init(stream_interactor);
conversation_frame = ((ConversationSummary.ConversationView) builder.get_object("conversation_frame")).init(stream_interactor);
filterable_conversation_list = ((ConversationSelector.List) builder.get_object("conversation_list")).init(stream_interactor);
conversation_selector = ((ConversationSelector) builder.get_object("conversation_list")).init(stream_interactor);
goto_end_revealer = (Revealer) builder.get_object("goto_end_revealer");
goto_end_button = (Button) builder.get_object("goto_end_button");
search_box = ((GlobalSearch) builder.get_object("search_box")).init(stream_interactor);
@ -107,9 +82,11 @@ public class UnifiedWindow : Gtk.Window {
private void setup_headerbar() {
if (Util.use_csd()) {
conversation_titlebar_csd = new ConversationTitlebarCsd(stream_interactor, this) { visible=true };
conversation_list_titlebar_csd = new ConversationListTitlebarCsd(stream_interactor, this) { visible=true };
ConversationListTitlebarCsd conversation_list_titlebar_csd = new ConversationListTitlebarCsd(stream_interactor, this) { visible=true };
headerbar_paned.pack1(conversation_list_titlebar_csd, false, false);
ConversationTitlebarCsd conversation_titlebar_csd = new ConversationTitlebarCsd() { visible=true };
conversation_titlebar = conversation_titlebar_csd;
headerbar_paned.pack2(conversation_titlebar_csd, true, false);
// Distribute start/end decoration_layout buttons to left/right headerbar. Ensure app menu fallback.
@ -125,9 +102,10 @@ public class UnifiedWindow : Gtk.Window {
}
}
} else {
conversation_list_titlebar = new ConversationListTitlebar(stream_interactor, this) { visible=true };
conversation_titlebar = new ConversationTitlebar(stream_interactor) { visible=true };
ConversationListTitlebar conversation_list_titlebar = new ConversationListTitlebar(stream_interactor, this) { visible=true };
headerbar_paned.pack1(conversation_list_titlebar, false, false);
conversation_titlebar = new ConversationTitlebarNoCsd() { visible=true };
headerbar_paned.pack2(conversation_titlebar, true, false);
box.add(headerbar_paned);
@ -167,7 +145,7 @@ public class UnifiedWindow : Gtk.Window {
}
public void loop_conversations(bool backwards) {
filterable_conversation_list.loop_conversations(backwards);
conversation_selector.loop_conversations(backwards);
}
}

View file

@ -79,7 +79,7 @@ public class UnifiedWindowController : Object {
window.accounts_placeholder.primary_button.clicked.connect(() => { app.activate_action("accounts", null); });
window.conversations_placeholder.primary_button.clicked.connect(() => { app.activate_action("add_chat", null); });
window.conversations_placeholder.secondary_button.clicked.connect(() => { app.activate_action("add_conference", null); });
window.filterable_conversation_list.conversation_selected.connect((conversation) => select_conversation(conversation));
window.conversation_selector.conversation_selected.connect((conversation) => select_conversation(conversation));
var vadjustment = window.conversation_frame.scrolled.vadjustment;
vadjustment.notify["value"].connect(() => {
@ -131,7 +131,7 @@ public class UnifiedWindowController : Object {
stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation);
conversation.active = true; // only for conversation_selected
window.filterable_conversation_list.on_conversation_selected(conversation); // only for conversation_opened
window.conversation_selector.on_conversation_selected(conversation); // only for conversation_opened
if (do_reset_search) {
reset_search_entry();
@ -148,10 +148,14 @@ public class UnifiedWindowController : Object {
private void update_conversation_topic(string? subtitle = null) {
if (subtitle != null) {
conversation_topic = subtitle;
conversation_topic = (/\s+/).replace_literal(subtitle, -1, 0, " ");
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
string subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
conversation_topic = subject != "" ? subject : null;
string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
if (subject != null) {
conversation_topic = (/\s+/).replace_literal(subject, -1, 0, " ");
} else {
conversation_topic = null;
}
} else {
conversation_topic = null;
}