aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/add_conversation/add_conference_dialog.vala2
-rw-r--r--main/src/ui/add_conversation/conference_list.vala1
-rw-r--r--main/src/ui/add_conversation/list_row.vala57
-rw-r--r--main/src/ui/application.vala33
-rw-r--r--main/src/ui/chat_input/chat_input_controller.vala10
-rw-r--r--main/src/ui/chat_input/chat_text_view.vala133
-rw-r--r--main/src/ui/conversation_content_view/message_widget.vala105
-rw-r--r--main/src/ui/conversation_details.vala32
-rw-r--r--main/src/ui/main_window.vala2
-rw-r--r--main/src/ui/main_window_controller.vala2
-rw-r--r--main/src/ui/notifier_freedesktop.vala7
-rw-r--r--main/src/ui/notifier_gnotifications.vala1
-rw-r--r--main/src/ui/settings_dialog.vala30
-rw-r--r--main/src/ui/util/helper.vala25
-rw-r--r--main/src/view_model/account_details.vala21
-rw-r--r--main/src/view_model/conversation_details.vala13
-rw-r--r--main/src/view_model/preferences_window.vala109
-rw-r--r--main/src/windows/conversation_details.vala50
-rw-r--r--main/src/windows/preferences_window/account_preferences_subpage.vala274
-rw-r--r--main/src/windows/preferences_window/accounts_preferences_page.vala75
-rw-r--r--main/src/windows/preferences_window/encryption_preferences_page.vala73
-rw-r--r--main/src/windows/preferences_window/general_preferences_page.vala39
-rw-r--r--main/src/windows/preferences_window/preferences_window.vala31
23 files changed, 1016 insertions, 109 deletions
diff --git a/main/src/ui/add_conversation/add_conference_dialog.vala b/main/src/ui/add_conversation/add_conference_dialog.vala
index 551f6713..eac55ffc 100644
--- a/main/src/ui/add_conversation/add_conference_dialog.vala
+++ b/main/src/ui/add_conversation/add_conference_dialog.vala
@@ -165,7 +165,7 @@ public class AddConferenceDialog : Gtk.Dialog {
details_fragment.clear();
ListRow? row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row().get_child() as ListRow : null;
- ConferenceListRow? conference_row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row() as ConferenceListRow : null;
+ ConferenceListRow? conference_row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row().get_child() as ConferenceListRow : null;
if (conference_row != null) {
details_fragment.account = conference_row.account;
details_fragment.jid = conference_row.bookmark.jid.to_string();
diff --git a/main/src/ui/add_conversation/conference_list.vala b/main/src/ui/add_conversation/conference_list.vala
index 0b630ae4..bf6191fa 100644
--- a/main/src/ui/add_conversation/conference_list.vala
+++ b/main/src/ui/add_conversation/conference_list.vala
@@ -103,6 +103,7 @@ internal class ConferenceListRow : ListRow {
this.account = account;
this.bookmark = bookmark;
+ status_dot.visible = false;
name_label.label = bookmark.name != null && bookmark.name != "" ? bookmark.name : bookmark.jid.to_string();
if (stream_interactor.get_accounts().size > 1) {
via_label.label = "via " + account.bare_jid.to_string();
diff --git a/main/src/ui/add_conversation/list_row.vala b/main/src/ui/add_conversation/list_row.vala
index c5e344d0..c489aa13 100644
--- a/main/src/ui/add_conversation/list_row.vala
+++ b/main/src/ui/add_conversation/list_row.vala
@@ -8,28 +8,54 @@ namespace Dino.Ui {
public class ListRow : Widget {
- public Grid outer_grid;
+ public Box outer_box;
public AvatarPicture picture;
public Label name_label;
+ public Image status_dot;
public Label via_label;
- public Jid? jid;
- public Account? account;
+ public StreamInteractor stream_interactor;
+ public Jid jid;
+ public Account account;
+
+ private ulong[] handler_ids = new ulong[0];
construct {
Builder builder = new Builder.from_resource("/im/dino/Dino/add_conversation/list_row.ui");
- outer_grid = (Grid) builder.get_object("outer_grid");
+ outer_box = (Box) builder.get_object("outer_box");
picture = (AvatarPicture) builder.get_object("picture");
name_label = (Label) builder.get_object("name_label");
+ status_dot = (Image) builder.get_object("status_dot");
via_label = (Label) builder.get_object("via_label");
+
this.layout_manager = new BinLayout();
- outer_grid.set_parent(this);
+ outer_box.set_parent(this);
}
- public ListRow() {}
+ private void set_status_dot(StreamInteractor stream_interactor){
+ status_dot.visible = stream_interactor.connection_manager.get_state(account) == ConnectionManager.ConnectionState.CONNECTED;
+
+ Gee.List<Jid>? full_jids = stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(jid, account);
+ if (full_jids != null) {
+ var statuses = new ArrayList<string>();
+ foreach (var full_jid in full_jids) {
+ statuses.add(stream_interactor.get_module(PresenceManager.IDENTITY).get_last_show(full_jid, account));
+ }
+
+ if (statuses.contains(Xmpp.Presence.Stanza.SHOW_DND)) status_dot.set_from_icon_name("dino-status-dnd");
+ else if (statuses.contains(Xmpp.Presence.Stanza.SHOW_CHAT)) status_dot.set_from_icon_name("dino-status-chat");
+ else if (statuses.contains(Xmpp.Presence.Stanza.SHOW_ONLINE)) status_dot.set_from_icon_name("dino-status-online");
+ else if (statuses.contains(Xmpp.Presence.Stanza.SHOW_AWAY)) status_dot.set_from_icon_name("dino-status-away");
+ else if (statuses.contains(Xmpp.Presence.Stanza.SHOW_XA)) status_dot.set_from_icon_name("dino-status-away");
+ else status_dot.set_from_icon_name("dino-status-offline");
+ } else {
+ status_dot.set_from_icon_name("dino-status-offline");
+ }
+ }
public ListRow.from_jid(StreamInteractor stream_interactor, Jid jid, Account account, bool show_account) {
+ this.stream_interactor = stream_interactor;
this.jid = jid;
this.account = account;
@@ -46,10 +72,27 @@ public class ListRow : Widget {
}
name_label.label = display_name;
picture.model = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(conv);
+
+ handler_ids += stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect((jid, account) => {
+ if (account.equals(this.account) && jid.equals_bare(this.jid)) {
+ set_status_dot(stream_interactor);
+ }
+ });
+ handler_ids += stream_interactor.get_module(PresenceManager.IDENTITY).received_offline_presence.connect((jid, account) => {
+ if (account.equals(this.account) && jid.equals_bare(this.jid)) {
+ set_status_dot(stream_interactor);
+ }
+ });
+
+ set_status_dot(stream_interactor);
}
public override void dispose() {
- outer_grid.unparent();
+ outer_box.unparent();
+
+ foreach (var handler_id in handler_ids) {
+ stream_interactor.get_module(PresenceManager.IDENTITY).disconnect(handler_id);
+ }
}
}
diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala
index 1c96e9ce..d213ef09 100644
--- a/main/src/ui/application.vala
+++ b/main/src/ui/application.vala
@@ -113,13 +113,17 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application {
}
private void create_actions() {
- SimpleAction accounts_action = new SimpleAction("accounts", null);
- accounts_action.activate.connect(show_accounts_window);
- add_action(accounts_action);
-
- SimpleAction settings_action = new SimpleAction("settings", null);
- settings_action.activate.connect(show_settings_window);
- add_action(settings_action);
+ SimpleAction preferences_action = new SimpleAction("preferences", null);
+ preferences_action.activate.connect(show_preferences_window);
+ add_action(preferences_action);
+
+ SimpleAction preferences_account_action = new SimpleAction("preferences-account", VariantType.INT32);
+ preferences_account_action.activate.connect((variant) => {
+ Account? account = db.get_account_by_id(variant.get_int32());
+ if (account == null) return;
+ show_preferences_account_window(account);
+ });
+ add_action(preferences_account_action);
SimpleAction about_action = new SimpleAction("about", null);
about_action.activate.connect(show_about_window);
@@ -252,17 +256,16 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application {
return Environment.get_variable("GTK_CSD") != "0";
}
- private void show_accounts_window() {
- ManageAccounts.Dialog dialog = new ManageAccounts.Dialog(stream_interactor, db);
- dialog.set_transient_for(get_active_window());
- dialog.account_enabled.connect(add_connection);
- dialog.account_disabled.connect(remove_connection);
+ private void show_preferences_window() {
+ Ui.PreferencesWindow dialog = new Ui.PreferencesWindow() { transient_for = window };
+ dialog.model.populate(db, stream_interactor);
dialog.present();
}
- private void show_settings_window() {
- SettingsDialog dialog = new SettingsDialog();
- dialog.set_transient_for(get_active_window());
+ private void show_preferences_account_window(Account account) {
+ Ui.PreferencesWindow dialog = new Ui.PreferencesWindow() { transient_for = window };
+ dialog.model.populate(db, stream_interactor);
+ dialog.accounts_page.account_chosen(account);
dialog.present();
}
diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala
index d1c42d35..07499aa4 100644
--- a/main/src/ui/chat_input/chat_input_controller.vala
+++ b/main/src/ui/chat_input/chat_input_controller.vala
@@ -1,7 +1,9 @@
using Gee;
using Gdk;
using Gtk;
+using Xmpp;
+using Xmpp;
using Dino.Entities;
namespace Dino.Ui {
@@ -135,6 +137,7 @@ public class ChatInputController : Object {
string text = chat_input.chat_text_view.text_view.buffer.text;
ContentItem? quoted_content_item_bak = quoted_content_item;
+ var markups = chat_input.chat_text_view.get_markups();
// Reset input state. Has do be done before parsing commands, because those directly return.
chat_input.chat_text_view.text_view.buffer.text = "";
@@ -193,11 +196,8 @@ public class ChatInputController : Object {
break;
}
}
- Message out_message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(text, conversation);
- if (quoted_content_item_bak != null) {
- stream_interactor.get_module(Replies.IDENTITY).set_message_is_reply_to(out_message, quoted_content_item_bak);
- }
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(out_message, conversation);
+
+ Dino.send_message(conversation, text, quoted_content_item_bak != null ? quoted_content_item_bak.id : 0, null, markups);
}
private void on_text_input_changed() {
diff --git a/main/src/ui/chat_input/chat_text_view.vala b/main/src/ui/chat_input/chat_text_view.vala
index 72ebc845..c7429318 100644
--- a/main/src/ui/chat_input/chat_text_view.vala
+++ b/main/src/ui/chat_input/chat_text_view.vala
@@ -40,6 +40,10 @@ public class ChatTextView : Box {
private uint wait_queue_resize;
private SmileyConverter smiley_converter;
+ private TextTag italic_tag;
+ private TextTag bold_tag;
+ private TextTag strikethrough_tag;
+
construct {
valign = Align.CENTER;
scrolled_window.set_child(text_view);
@@ -49,6 +53,15 @@ public class ChatTextView : Box {
text_input_key_events.key_pressed.connect(on_text_input_key_press);
text_view.add_controller(text_input_key_events);
+ italic_tag = text_view.buffer.create_tag("italic");
+ italic_tag.style = Pango.Style.ITALIC;
+
+ bold_tag = text_view.buffer.create_tag("bold");
+ bold_tag.weight = Pango.Weight.BOLD;
+
+ strikethrough_tag = text_view.buffer.create_tag("strikethrough");
+ strikethrough_tag.strikethrough = true;
+
smiley_converter = new SmileyConverter(text_view);
scrolled_window.vadjustment.changed.connect(on_upper_notify);
@@ -60,6 +73,37 @@ public class ChatTextView : Box {
});
}
+ public void set_text(Message message) {
+ // Get a copy of the markup spans, such that we can modify them
+ var markups = new ArrayList<Xep.MessageMarkup.Span>();
+ foreach (var markup in message.get_markups()) {
+ markups.add(new Xep.MessageMarkup.Span() { types=markup.types, start_char=markup.start_char, end_char=markup.end_char });
+ }
+
+ text_view.buffer.text = Util.remove_fallbacks_adjust_markups(message.body, message.quoted_item_id > 0, message.get_fallbacks(), markups);
+
+ foreach (var markup in markups) {
+ foreach (var ty in markup.types) {
+ TextTag tag = null;
+ switch (ty) {
+ case Xep.MessageMarkup.SpanType.EMPHASIS:
+ tag = italic_tag;
+ break;
+ case Xep.MessageMarkup.SpanType.STRONG_EMPHASIS:
+ tag = bold_tag;
+ break;
+ case Xep.MessageMarkup.SpanType.DELETED:
+ tag = strikethrough_tag;
+ break;
+ }
+ TextIter start_selection, end_selection;
+ text_view.buffer.get_iter_at_offset(out start_selection, markup.start_char);
+ text_view.buffer.get_iter_at_offset(out end_selection, markup.end_char);
+ text_view.buffer.apply_tag(tag, start_selection, end_selection);
+ }
+ }
+ }
+
public override void dispose() {
base.dispose();
if (wait_queue_resize != 0) {
@@ -95,6 +139,7 @@ public class ChatTextView : Box {
}
private bool on_text_input_key_press(EventControllerKey controller, uint keyval, uint keycode, Gdk.ModifierType state) {
+ // Enter pressed -> Send message (except if it was Shift+Enter)
if (keyval in new uint[]{ Key.Return, Key.KP_Enter }) {
// Allow the text view to process the event. Needed for IME.
if (text_view.im_context_filter_keypress(controller.get_current_event())) {
@@ -102,17 +147,103 @@ public class ChatTextView : Box {
}
if ((state & ModifierType.SHIFT_MASK) > 0) {
- text_view.buffer.insert_at_cursor("\n", 1);
+ // Let the default handler normally insert a newline if shift was hold
+ return false;
} else if (text_view.buffer.text.strip() != "") {
send_text();
}
return true;
}
+
if (keyval == Key.Escape) {
cancel_input();
}
+
+ // Style text section bold (CTRL + b) or italic (CTRL + i)
+ if ((state & ModifierType.CONTROL_MASK) > 0) {
+ if (keyval in new uint[]{ Key.i, Key.b }) {
+ TextIter start_selection, end_selection;
+ text_view.buffer.get_selection_bounds(out start_selection, out end_selection);
+
+ TextTag tag = null;
+ bool already_formatted = false;
+ var markup_types = get_markup_types_from_iter(start_selection);
+ if (keyval == Key.i) {
+ tag = italic_tag;
+ already_formatted = markup_types.contains(Xep.MessageMarkup.SpanType.EMPHASIS);
+ } else if (keyval == Key.b) {
+ tag = bold_tag;
+ already_formatted = markup_types.contains(Xep.MessageMarkup.SpanType.STRONG_EMPHASIS);
+ } else if (keyval == Key.s) {
+ tag = strikethrough_tag;
+ already_formatted = markup_types.contains(Xep.MessageMarkup.SpanType.DELETED);
+ }
+ if (tag != null) {
+ if (already_formatted) {
+ text_view.buffer.remove_tag(tag, start_selection, end_selection);
+ } else {
+ text_view.buffer.apply_tag(tag, start_selection, end_selection);
+ }
+ }
+ }
+ }
+
return false;
}
+
+ public Gee.List<Xep.MessageMarkup.Span> get_markups() {
+ var markups = new HashMap<Xep.MessageMarkup.SpanType, Xep.MessageMarkup.SpanType>();
+ markups[Xep.MessageMarkup.SpanType.EMPHASIS] = Xep.MessageMarkup.SpanType.EMPHASIS;
+ markups[Xep.MessageMarkup.SpanType.STRONG_EMPHASIS] = Xep.MessageMarkup.SpanType.STRONG_EMPHASIS;
+ markups[Xep.MessageMarkup.SpanType.DELETED] = Xep.MessageMarkup.SpanType.DELETED;
+
+ var ended_groups = new ArrayList<Xep.MessageMarkup.Span>();
+ Xep.MessageMarkup.Span current_span = null;
+
+ TextIter iter;
+ text_view.buffer.get_start_iter(out iter);
+ int i = 0;
+ do {
+ var char_markups = get_markup_types_from_iter(iter);
+
+ // Not the same set of markups as last character -> end all spans
+ if (current_span != null && (!char_markups.contains_all(current_span.types) || !current_span.types.contains_all(char_markups))) {
+ ended_groups.add(current_span);
+ current_span = null;
+ }
+
+ if (char_markups.size > 0) {
+ if (current_span == null) {
+ current_span = new Xep.MessageMarkup.Span() { types=char_markups, start_char=i, end_char=i + 1 };
+ } else {
+ current_span.end_char = i + 1;
+ }
+ }
+
+ i++;
+ } while (iter.forward_char());
+
+ if (current_span != null) {
+ ended_groups.add(current_span);
+ }
+
+ return ended_groups;
+ }
+
+ private Gee.List<Xep.MessageMarkup.SpanType> get_markup_types_from_iter(TextIter iter) {
+ var ret = new ArrayList<Xep.MessageMarkup.SpanType>();
+
+ foreach (TextTag tag in iter.get_tags()) {
+ if (tag.style == Pango.Style.ITALIC) {
+ ret.add(Xep.MessageMarkup.SpanType.EMPHASIS);
+ } else if (tag.weight == Pango.Weight.BOLD) {
+ ret.add(Xep.MessageMarkup.SpanType.STRONG_EMPHASIS);
+ } else if (tag.strikethrough) {
+ ret.add(Xep.MessageMarkup.SpanType.DELETED);
+ }
+ }
+ return ret;
+ }
}
}
diff --git a/main/src/ui/conversation_content_view/message_widget.vala b/main/src/ui/conversation_content_view/message_widget.vala
index 11b38286..376ef4bd 100644
--- a/main/src/ui/conversation_content_view/message_widget.vala
+++ b/main/src/ui/conversation_content_view/message_widget.vala
@@ -26,8 +26,8 @@ public class MessageMetaItem : ContentMetaItem {
AdditionalInfo additional_info = AdditionalInfo.NONE;
ulong realize_id = -1;
- ulong style_updated_id = -1;
ulong marked_notify_handler_id = -1;
+ uint pending_timeout_id = -1;
public Label label = new Label("") { use_markup=true, xalign=0, selectable=true, wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR, hexpand=true, vexpand=true };
@@ -64,6 +64,7 @@ public class MessageMetaItem : ContentMetaItem {
if (message.marked in Message.MARKED_RECEIVED) {
binding.unbind();
this.disconnect(marked_notify_handler_id);
+ marked_notify_handler_id = -1;
}
});
}
@@ -71,20 +72,72 @@ public class MessageMetaItem : ContentMetaItem {
update_label();
}
- private string generate_markup_text(ContentItem item) {
+ private void generate_markup_text(ContentItem item, Label label) {
MessageItem message_item = item as MessageItem;
Conversation conversation = message_item.conversation;
Message message = message_item.message;
- bool theme_dependent = false;
+ // Get a copy of the markup spans, such that we can modify them
+ var markups = new ArrayList<Xep.MessageMarkup.Span>();
+ foreach (var markup in message.get_markups()) {
+ markups.add(new Xep.MessageMarkup.Span() { types=markup.types, start_char=markup.start_char, end_char=markup.end_char });
+ }
+
+ string markup_text = message.body;
+
+ var attrs = new AttrList();
+ label.set_attributes(attrs);
- string markup_text = Dino.message_body_without_reply_fallback(message);
+ if (markup_text == null) return; // TODO remove
+ // Only process messages up to a certain size
if (markup_text.length > 10000) {
markup_text = markup_text.substring(0, 10000) + " [" + _("Message too long") + "]";
}
- if (message.body.has_prefix("/me ")) {
- markup_text = markup_text.substring(4);
+
+ bool theme_dependent = false;
+
+ markup_text = Util.remove_fallbacks_adjust_markups(markup_text, message.quoted_item_id > 0, message.get_fallbacks(), markups);
+
+ var bold_attr = Pango.attr_weight_new(Pango.Weight.BOLD);
+ var italic_attr = Pango.attr_style_new(Pango.Style.ITALIC);
+ var strikethrough_attr = Pango.attr_strikethrough_new(true);
+
+ // Prefix message with name instead of /me
+ if (markup_text.has_prefix("/me ")) {
+ string display_name = Util.get_participant_display_name(stream_interactor, conversation, message.from);
+ markup_text = display_name + " " + markup_text.substring(4);
+
+ foreach (Xep.MessageMarkup.Span span in markups) {
+ int length = display_name.char_count() - 4 + 1;
+ span.start_char += length;
+ span.end_char += length;
+ }
+
+ bold_attr.end_index = display_name.length;
+ italic_attr.end_index = display_name.length;
+ attrs.insert(bold_attr.copy());
+ attrs.insert(italic_attr.copy());
+ }
+
+ foreach (var markup in markups) {
+ foreach (var ty in markup.types) {
+ Attribute attr = null;
+ switch (ty) {
+ case Xep.MessageMarkup.SpanType.EMPHASIS:
+ attr = Pango.attr_style_new(Pango.Style.ITALIC);
+ break;
+ case Xep.MessageMarkup.SpanType.STRONG_EMPHASIS:
+ attr = Pango.attr_weight_new(Pango.Weight.BOLD);
+ break;
+ case Xep.MessageMarkup.SpanType.DELETED:
+ attr = Pango.attr_strikethrough_new(true);
+ break;
+ }
+ attr.start_index = markup_text.index_of_nth_char(markup.start_char);
+ attr.end_index = markup_text.index_of_nth_char(markup.end_char);
+ attrs.insert(attr.copy());
+ }
}
if (conversation.type_ == Conversation.Type.GROUPCHAT) {
@@ -93,11 +146,6 @@ public class MessageMetaItem : ContentMetaItem {
markup_text = Util.parse_add_markup_theme(markup_text, null, true, true, true, Util.is_dark_theme(this.label), ref theme_dependent);
}
- if (message.body.has_prefix("/me ")) {
- string display_name = Util.get_participant_display_name(stream_interactor, conversation, message.from);
- markup_text = @"<i><b>$(Markup.escape_text(display_name))</b> " + markup_text + "</i>";
- }
-
int only_emoji_count = Util.get_only_emoji_count(markup_text);
if (only_emoji_count != -1) {
string size_str = only_emoji_count < 5 ? "xx-large" : "large";
@@ -121,8 +169,10 @@ public class MessageMetaItem : ContentMetaItem {
additional_info = AdditionalInfo.PENDING;
} else {
int time_diff = (- (int) message.time.difference(new DateTime.now_utc()) / 1000);
- Timeout.add(10000 - time_diff, () => {
+ if (pending_timeout_id != -1) Source.remove(pending_timeout_id);
+ pending_timeout_id = Timeout.add(10000 - time_diff, () => {
update_label();
+ pending_timeout_id = -1;
return false;
});
}
@@ -136,16 +186,14 @@ public class MessageMetaItem : ContentMetaItem {
if (theme_dependent && realize_id == -1) {
realize_id = label.realize.connect(update_label);
-// style_updated_id = label.style_updated.connect(update_label);
} else if (!theme_dependent && realize_id != -1) {
label.disconnect(realize_id);
- label.disconnect(style_updated_id);
}
- return markup_text;
+ label.label = markup_text;
}
public void update_label() {
- label.label = generate_markup_text(content_item);
+ generate_markup_text(content_item, label);
}
public override Object? get_widget(Plugins.ConversationItemWidgetInterface outer, Plugins.WidgetType type) {
@@ -209,16 +257,15 @@ public class MessageMetaItem : ContentMetaItem {
outer.set_widget(label, Plugins.WidgetType.GTK4, 2);
});
edit_mode.send.connect(() => {
- if (((MessageItem) content_item).message.body != edit_mode.chat_text_view.text_view.buffer.text) {
- on_edit_send(edit_mode.chat_text_view.text_view.buffer.text);
- } else {
-// edit_cancelled();
- }
+ string text = edit_mode.chat_text_view.text_view.buffer.text;
+ var markups = edit_mode.chat_text_view.get_markups();
+ Dino.send_message(message_item.conversation, text, message_item.message.quoted_item_id, message_item.message, markups);
+
in_edit_mode = false;
outer.set_widget(label, Plugins.WidgetType.GTK4, 2);
});
- edit_mode.chat_text_view.text_view.buffer.text = message.body;
+ edit_mode.chat_text_view.set_text(message);
outer.set_widget(edit_mode, Plugins.WidgetType.GTK4, 2);
edit_mode.chat_text_view.text_view.grab_focus();
@@ -227,11 +274,6 @@ public class MessageMetaItem : ContentMetaItem {
}
}
- private void on_edit_send(string text) {
- stream_interactor.get_module(MessageCorrection.IDENTITY).send_correction(message_item.conversation, message_item.message, text);
- this.in_edit_mode = false;
- }
-
private void on_received_correction(ContentItem content_item) {
if (this.content_item.id == content_item.id) {
this.content_item = content_item;
@@ -251,6 +293,15 @@ public class MessageMetaItem : ContentMetaItem {
public override void dispose() {
stream_interactor.get_module(MessageCorrection.IDENTITY).received_correction.disconnect(on_received_correction);
this.notify["in-edit-mode"].disconnect(on_in_edit_mode_changed);
+ if (marked_notify_handler_id != -1) {
+ this.disconnect(marked_notify_handler_id);
+ }
+ if (realize_id != -1) {
+ label.disconnect(realize_id);
+ }
+ if (pending_timeout_id != -1) {
+ Source.remove(pending_timeout_id);
+ }
if (label != null) {
label.unparent();
label.dispose();
diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala
index 1c82f105..4c6a0481 100644
--- a/main/src/ui/conversation_details.vala
+++ b/main/src/ui/conversation_details.vala
@@ -10,6 +10,7 @@ namespace Dino.Ui.ConversationDetails {
model.conversation = conversation;
model.display_name = stream_interactor.get_module(ContactModels.IDENTITY).get_display_name_model(conversation);
model.blocked = stream_interactor.get_module(BlockingManager.IDENTITY).is_blocked(model.conversation.account, model.conversation.counterpart);
+ model.domain_blocked = stream_interactor.get_module(BlockingManager.IDENTITY).is_blocked(model.conversation.account, model.conversation.counterpart.domain_jid);
if (conversation.type_ == Conversation.Type.GROUPCHAT) {
stream_interactor.get_module(MucManager.IDENTITY).get_config_form.begin(conversation.account, conversation.counterpart, (_, res) => {
@@ -24,6 +25,14 @@ namespace Dino.Ui.ConversationDetails {
view_model.avatar = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(model.conversation);
view_model.show_blocked = model.conversation.type_ == Conversation.Type.CHAT && stream_interactor.get_module(BlockingManager.IDENTITY).is_supported(model.conversation.account);
+ if (model.domain_blocked) {
+ view_model.blocked = DOMAIN;
+ } else if (model.blocked) {
+ view_model.blocked = USER;
+ } else {
+ view_model.blocked = UNBLOCK;
+ }
+
model.display_name.bind_property("display-name", view_model, "name", BindingFlags.SYNC_CREATE);
model.conversation.bind_property("notify-setting", view_model, "notification", BindingFlags.SYNC_CREATE, (_, from, ref to) => {
switch (model.conversation.get_notification_setting(stream_interactor)) {
@@ -57,7 +66,6 @@ namespace Dino.Ui.ConversationDetails {
to = ty == Conversation.Type.GROUPCHAT ? ViewModel.ConversationDetails.NotificationOptions.ON_HIGHLIGHT_OFF : ViewModel.ConversationDetails.NotificationOptions.ON_OFF;
return true;
});
- model.bind_property("blocked", view_model, "blocked", BindingFlags.SYNC_CREATE);
model.bind_property("data-form", view_model, "room-configuration-rows", BindingFlags.SYNC_CREATE, (_, from, ref to) => {
var data_form = (DataForms.DataForm) from;
if (data_form == null) return true;
@@ -77,13 +85,21 @@ namespace Dino.Ui.ConversationDetails {
view_model.pin_changed.connect(() => {
model.conversation.pinned = model.conversation.pinned == 1 ? 0 : 1;
});
- view_model.block_changed.connect(() => {
- if (view_model.blocked) {
- stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart);
- } else {
- stream_interactor.get_module(BlockingManager.IDENTITY).block(model.conversation.account, model.conversation.counterpart);
+ view_model.block_changed.connect((action) => {
+ switch (action) {
+ case USER:
+ stream_interactor.get_module(BlockingManager.IDENTITY).block(model.conversation.account, model.conversation.counterpart);
+ stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart.domain_jid);
+ break;
+ case DOMAIN:
+ stream_interactor.get_module(BlockingManager.IDENTITY).block(model.conversation.account, model.conversation.counterpart.domain_jid);
+ break;
+ case UNBLOCK:
+ stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart);
+ stream_interactor.get_module(BlockingManager.IDENTITY).unblock(model.conversation.account, model.conversation.counterpart.domain_jid);
+ break;
}
- view_model.blocked = !view_model.blocked;
+ view_model.blocked = action;
});
view_model.notification_changed.connect((setting) => {
switch (setting) {
@@ -189,4 +205,4 @@ namespace Dino.Ui.ConversationDetails {
break;
}
}
-} \ No newline at end of file
+}
diff --git a/main/src/ui/main_window.vala b/main/src/ui/main_window.vala
index dd54052e..ce71d413 100644
--- a/main/src/ui/main_window.vala
+++ b/main/src/ui/main_window.vala
@@ -20,7 +20,7 @@ public class MainWindow : Adw.ApplicationWindow {
public ConversationTitlebar conversation_titlebar;
public Widget conversation_list_titlebar;
public Box box = new Box(Orientation.VERTICAL, 0) { orientation=Orientation.VERTICAL };
- public Adw.Leaflet leaflet;
+ private Adw.Leaflet leaflet;
public Box left_box;
public Box right_box;
public Adw.Flap search_flap;
diff --git a/main/src/ui/main_window_controller.vala b/main/src/ui/main_window_controller.vala
index 7a3ebcb2..2e270663 100644
--- a/main/src/ui/main_window_controller.vala
+++ b/main/src/ui/main_window_controller.vala
@@ -69,7 +69,7 @@ public class MainWindowController : Object {
dialog.set_transient_for(app.get_active_window());
dialog.present();
});
- window.accounts_placeholder.primary_button.clicked.connect(() => { app.activate_action("accounts", null); });
+ window.accounts_placeholder.primary_button.clicked.connect(() => { app.activate_action("preferences", null); });
window.conversation_selector.conversation_selected.connect((conversation) => select_conversation(conversation));
// ConversationListModel list_model = new ConversationListModel(stream_interactor);
diff --git a/main/src/ui/notifier_freedesktop.vala b/main/src/ui/notifier_freedesktop.vala
index a1df5990..0d263dba 100644
--- a/main/src/ui/notifier_freedesktop.vala
+++ b/main/src/ui/notifier_freedesktop.vala
@@ -201,8 +201,13 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
HashTable<string, Variant> hash_table = new HashTable<string, Variant>(null, null);
hash_table["desktop-entry"] = new Variant.string(Dino.Application.get_default().get_application_id());
hash_table["category"] = new Variant.string("im.error");
+ string[] actions = new string[] {"default", "Open preferences"};
try {
- yield dbus_notifications.notify("Dino", 0, "im.dino.Dino", summary, body, new string[]{}, hash_table, -1);
+ uint32 notification_id = yield dbus_notifications.notify("Dino", 0, "im.dino.Dino", summary, body, actions, hash_table, -1);
+
+ add_action_listener(notification_id, "default", () => {
+ GLib.Application.get_default().activate_action("preferences-account", new Variant.int32(account.id));
+ });
} catch (Error e) {
warning("Failed showing connection error notification: %s", e.message);
}
diff --git a/main/src/ui/notifier_gnotifications.vala b/main/src/ui/notifier_gnotifications.vala
index 4d36620d..462cdf70 100644
--- a/main/src/ui/notifier_gnotifications.vala
+++ b/main/src/ui/notifier_gnotifications.vala
@@ -102,6 +102,7 @@ namespace Dino.Ui {
public async void notify_connection_error(Account account, ConnectionManager.ConnectionError error) {
Notification notification = new Notification(_("Could not connect to %s").printf(account.bare_jid.domainpart));
+ notification.set_default_action_and_target_value("app.preferences-account", new Variant.int32(account.id));
switch (error.source) {
case ConnectionManager.ConnectionError.Source.SASL:
notification.set_body("Wrong password");
diff --git a/main/src/ui/settings_dialog.vala b/main/src/ui/settings_dialog.vala
deleted file mode 100644
index 3635879c..00000000
--- a/main/src/ui/settings_dialog.vala
+++ /dev/null
@@ -1,30 +0,0 @@
-using Gtk;
-
-namespace Dino.Ui {
-
-[GtkTemplate (ui = "/im/dino/Dino/settings_dialog.ui")]
-class SettingsDialog : Adw.PreferencesWindow {
-
- [GtkChild] private unowned Switch typing_switch;
- [GtkChild] private unowned Switch marker_switch;
- [GtkChild] private unowned Switch notification_switch;
- [GtkChild] private unowned Switch emoji_switch;
-
- Dino.Entities.Settings settings = Dino.Application.get_default().settings;
-
- public SettingsDialog() {
- Object();
-
- typing_switch.active = settings.send_typing;
- marker_switch.active = settings.send_marker;
- notification_switch.active = settings.notifications;
- emoji_switch.active = settings.convert_utf8_smileys;
-
- typing_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } );
- marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } );
- notification_switch.notify["active"].connect(() => { settings.notifications = notification_switch.active; } );
- emoji_switch.notify["active"].connect(() => { settings.convert_utf8_smileys = emoji_switch.active; });
- }
-}
-
-}
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 63288fc2..45b96b94 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -297,6 +297,31 @@ public static string parse_add_markup_theme(string s_, string? highlight_word, b
return s;
}
+ // Modifies `markups`.
+ public string remove_fallbacks_adjust_markups(string text, bool contains_quote, Gee.List<Xep.FallbackIndication.Fallback> fallbacks, Gee.List<Xep.MessageMarkup.Span> markups) {
+ string processed_text = text;
+
+ foreach (var fallback in fallbacks) {
+ if (fallback.ns_uri == Xep.Replies.NS_URI && contains_quote) {
+ foreach (var fallback_location in fallback.locations) {
+ processed_text = processed_text[0:processed_text.index_of_nth_char(fallback_location.from_char)] +
+ processed_text[processed_text.index_of_nth_char(fallback_location.to_char):processed_text.length];
+
+ int length = fallback_location.to_char - fallback_location.from_char;
+ foreach (Xep.MessageMarkup.Span span in markups) {
+ if (span.start_char > fallback_location.to_char) {
+ span.start_char -= length;
+ }
+ if (span.end_char > fallback_location.to_char) {
+ span.end_char -= length;
+ }
+ }
+ }
+ }
+ }
+ return processed_text;
+ }
+
/**
* This is a heuristic to count emojis in a string {@link http://example.com/}
*
diff --git a/main/src/view_model/account_details.vala b/main/src/view_model/account_details.vala
new file mode 100644
index 00000000..a9ddeca5
--- /dev/null
+++ b/main/src/view_model/account_details.vala
@@ -0,0 +1,21 @@
+using Dino;
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+
+public class Dino.Ui.ViewModel.AccountDetails : Object {
+ public Entities.Account account { get; set; }
+ public string bare_jid { owned get { return account.bare_jid.to_string(); } }
+ public CompatAvatarPictureModel avatar_model { get; set; }
+ public ConnectionManager.ConnectionState connection_state { get; set; }
+ public ConnectionManager.ConnectionError? connection_error { get; set; }
+
+ public AccountDetails(Account account, StreamInteractor stream_interactor) {
+ var account_conv = new Conversation(account.bare_jid, account, Conversation.Type.CHAT);
+
+ this.account = account;
+ this.avatar_model = new ViewModel.CompatAvatarPictureModel(stream_interactor).set_conversation(account_conv);
+ this.connection_state = stream_interactor.connection_manager.get_state(account);
+ this.connection_error = stream_interactor.connection_manager.get_error(account);
+ }
+} \ No newline at end of file
diff --git a/main/src/view_model/conversation_details.vala b/main/src/view_model/conversation_details.vala
index 15bf7535..75fc9669 100644
--- a/main/src/view_model/conversation_details.vala
+++ b/main/src/view_model/conversation_details.vala
@@ -6,10 +6,16 @@ using Gtk;
public class Dino.Ui.ViewModel.ConversationDetails : Object {
public signal void pin_changed();
- public signal void block_changed();
+ public signal void block_changed(BlockState action);
public signal void notification_flipped();
public signal void notification_changed(NotificationSetting setting);
+ public enum BlockState {
+ USER,
+ DOMAIN,
+ UNBLOCK
+ }
+
public enum NotificationOptions {
ON_OFF,
ON_HIGHLIGHT_OFF
@@ -31,7 +37,7 @@ public class Dino.Ui.ViewModel.ConversationDetails : Object {
public bool notification_is_default { get; set; }
public bool show_blocked { get; set; }
- public bool blocked { get; set; }
+ public BlockState blocked { get; set; }
public GLib.ListStore preferences_rows = new GLib.ListStore(typeof(PreferencesRow.Any));
public GLib.ListStore about_rows = new GLib.ListStore(typeof(PreferencesRow.Any));
@@ -46,4 +52,5 @@ public class Dino.Ui.Model.ConversationDetails : Object {
public DataForms.DataForm? data_form { get; set; }
public string? data_form_bak;
public bool blocked { get; set; }
-} \ No newline at end of file
+ public bool domain_blocked { get; set; }
+}
diff --git a/main/src/view_model/preferences_window.vala b/main/src/view_model/preferences_window.vala
new file mode 100644
index 00000000..9cc5a80e
--- /dev/null
+++ b/main/src/view_model/preferences_window.vala
@@ -0,0 +1,109 @@
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+
+public class Dino.Ui.ViewModel.PreferencesWindow : Object {
+ public signal void update();
+
+ public HashMap<Account, AccountDetails> account_details = new HashMap<Account, AccountDetails>(Account.hash_func, Account.equals_func);
+ public AccountDetails selected_account { get; set; }
+ public Gtk.SingleSelection active_accounts_selection { get; default=new Gtk.SingleSelection(new GLib.ListStore(typeof(ViewModel.AccountDetails))); }
+
+ public StreamInteractor stream_interactor;
+ public Database db;
+
+ public GeneralPreferencesPage general_page { get; set; default=new GeneralPreferencesPage(); }
+
+ public void populate(Database db, StreamInteractor stream_interactor) {
+ this.db = db;
+ this.stream_interactor = stream_interactor;
+
+ stream_interactor.connection_manager.connection_error.connect((account, error) => {
+ var account_detail = account_details[account];
+ if (account_details != null) {
+ account_detail.connection_error = error;
+ }
+ });
+ stream_interactor.connection_manager.connection_state_changed.connect((account, state) => {
+ var account_detail = account_details[account];
+ if (account_details != null) {
+ account_detail.connection_state = state;
+ account_detail.connection_error = stream_interactor.connection_manager.get_error(account);
+ }
+ });
+ stream_interactor.account_added.connect(update_data);
+ stream_interactor.account_removed.connect(update_data);
+
+ bind_general_page();
+ update_data();
+ }
+
+ private void update_data() {
+ // account_details should hold the correct set of accounts (add or remove some if needed), but do not override remaining ones (would destroy bindings)
+ var current_accounts = db.get_accounts();
+ var remove_accounts = new ArrayList<Account>();
+ foreach (var account in account_details.keys) {
+ if (!current_accounts.contains(account)) remove_accounts.add(account);
+ }
+ foreach (var account in remove_accounts) {
+ account_details.unset(account);
+ }
+ foreach (var account in current_accounts) {
+ if (!account_details.has_key(account)) {
+ account_details[account] = new AccountDetails(account, stream_interactor);
+ }
+ if (selected_account == null && account.enabled) selected_account = account_details[account];
+ }
+
+ // Update account picker model with currently active accounts
+ var list_model = (GLib.ListStore) active_accounts_selection.model;
+ list_model.remove_all();
+ foreach (var account in stream_interactor.get_accounts()) {
+ list_model.append(new ViewModel.AccountDetails(account, stream_interactor));
+ }
+
+ update();
+ }
+
+ public void set_avatar_uri(Account account, string uri) {
+ stream_interactor.get_module(AvatarManager.IDENTITY).publish(account, uri);
+ }
+
+ public void remove_avatar(Account account) {
+ stream_interactor.get_module(AvatarManager.IDENTITY).unset_avatar(account);
+ }
+
+ public void remove_account(Account account) {
+ stream_interactor.disconnect_account.begin(account, () => {
+ account.remove();
+ update_data();
+ });
+ }
+
+ public void reconnect_account(Account account) {
+ stream_interactor.disconnect_account.begin(account, () => {
+ stream_interactor.connect_account(account);
+ });
+ }
+
+ public void enable_disable_account(Account account) {
+ if (account.enabled) {
+ account.enabled = false;
+ stream_interactor.disconnect_account.begin(account);
+ } else {
+ account.enabled = true;
+ stream_interactor.connect_account(account);
+ }
+ update_data();
+ }
+
+ private void bind_general_page() {
+ var settings = Dino.Application.get_default().settings;
+ settings.bind_property("send-typing", general_page, "send-typing", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ settings.bind_property("send-marker", general_page, "send-marker", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ settings.bind_property("notifications", general_page, "notifications", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ settings.bind_property("convert-utf8-smileys", general_page, "convert-emojis", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ }
+}
+
diff --git a/main/src/windows/conversation_details.vala b/main/src/windows/conversation_details.vala
index 1dac02c7..7ffa01f1 100644
--- a/main/src/windows/conversation_details.vala
+++ b/main/src/windows/conversation_details.vala
@@ -11,7 +11,7 @@ namespace Dino.Ui.ConversationDetails {
[GtkChild] public unowned Box about_box;
[GtkChild] public unowned Button pin_button;
[GtkChild] public unowned Adw.ButtonContent pin_button_content;
- [GtkChild] public unowned Button block_button;
+ [GtkChild] public unowned MenuButton block_button;
[GtkChild] public unowned Adw.ButtonContent block_button_content;
[GtkChild] public unowned Button notification_button_toggle;
[GtkChild] public unowned Adw.ButtonContent notification_button_toggle_content;
@@ -22,6 +22,8 @@ namespace Dino.Ui.ConversationDetails {
[GtkChild] public unowned ViewModel.ConversationDetails model { get; }
+ private SimpleAction block_action = new SimpleAction.stateful("block", VariantType.INT32, new Variant.int32(ViewModel.ConversationDetails.BlockState.UNBLOCK));
+
class construct {
install_action("notification.on", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.ON); } );
install_action("notification.off", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.OFF); } );
@@ -31,7 +33,6 @@ namespace Dino.Ui.ConversationDetails {
construct {
pin_button.clicked.connect(() => { model.pin_changed(); });
- block_button.clicked.connect(() => { model.block_changed(); });
notification_button_toggle.clicked.connect(() => { model.notification_flipped(); });
notification_button_split.clicked.connect(() => { model.notification_flipped(); });
@@ -47,10 +48,32 @@ namespace Dino.Ui.ConversationDetails {
model.settings_rows.items_changed.connect(create_preferences_rows);
model.notify["room-configuration-rows"].connect(create_preferences_rows);
+ // Create block action
+ SimpleActionGroup block_action_group = new SimpleActionGroup();
+ block_action = new SimpleAction.stateful("block", VariantType.INT32, new Variant.int32(0));
+ block_action.activate.connect((parameter) => {
+ block_action.set_state(parameter);
+ model.block_changed((ViewModel.ConversationDetails.BlockState) parameter.get_int32());
+ });
+ block_action_group.insert(block_action);
+ this.insert_action_group("block", block_action_group);
+
+ // Create block menu model
+ Menu block_menu_model = new Menu();
+ string[] menu_labels = new string[] { _("Block user"), _("Block entire domain"), _("Unblock") };
+ ViewModel.ConversationDetails.BlockState[] menu_states = new ViewModel.ConversationDetails.BlockState[] { ViewModel.ConversationDetails.BlockState.USER, ViewModel.ConversationDetails.BlockState.DOMAIN, ViewModel.ConversationDetails.BlockState.UNBLOCK };
+ for (int i = 0; i < menu_labels.length; i++) {
+ MenuItem item = new MenuItem(menu_labels[i], null);
+ item.set_action_and_target_value("block.block", new Variant.int32(menu_states[i]));
+ block_menu_model.append_item(item);
+ }
+ block_button.menu_model = block_menu_model;
+
#if Adw_1_4
// TODO: replace with putting buttons in new line on small screens
notification_button_menu_content.can_shrink = true;
#endif
+ update_blocked_button();
}
private void update_pinned_button() {
@@ -64,13 +87,22 @@ namespace Dino.Ui.ConversationDetails {
}
private void update_blocked_button() {
- block_button_content.icon_name = "dino-block-symbolic";
- block_button_content.label = model.blocked ? _("Blocked") : _("Block");
- if (model.blocked) {
- block_button.add_css_class("error");
- } else {
- block_button.remove_css_class("error");
+ switch (model.blocked) {
+ case USER:
+ block_button_content.label = _("Blocked");
+ block_button.add_css_class("error");
+ break;
+ case DOMAIN:
+ block_button_content.label = _("Domain blocked");
+ block_button.add_css_class("error");
+ break;
+ case UNBLOCK:
+ block_button_content.label = _("Block");
+ block_button.remove_css_class("error");
+ break;
}
+
+ block_action.set_state(new Variant.int32(model.blocked));
}
private void update_notification_button() {
@@ -229,4 +261,4 @@ namespace Dino.Ui.ConversationDetails {
return preference_group;
}
}
-} \ No newline at end of file
+}
diff --git a/main/src/windows/preferences_window/account_preferences_subpage.vala b/main/src/windows/preferences_window/account_preferences_subpage.vala
new file mode 100644
index 00000000..a1966e34
--- /dev/null
+++ b/main/src/windows/preferences_window/account_preferences_subpage.vala
@@ -0,0 +1,274 @@
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+using Gtk;
+using Gdk;
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window_account.ui")]
+public class Dino.Ui.AccountPreferencesSubpage : Gtk.Box {
+
+ [GtkChild] public unowned Adw.HeaderBar headerbar;
+ [GtkChild] public unowned Button back_button;
+ [GtkChild] public unowned AvatarPicture avatar;
+ [GtkChild] public unowned Adw.ActionRow xmpp_address;
+ [GtkChild] public unowned Adw.ActionRow local_alias; // TODO replace with EntryRow once we require Adw 1.2
+ [GtkChild] public unowned Entry local_alias_entry;
+ [GtkChild] public unowned Adw.ActionRow connection_status;
+ [GtkChild] public unowned Button enter_password_button;
+ [GtkChild] public unowned Box avatar_menu_box;
+ [GtkChild] public unowned Button edit_avatar_button;
+ [GtkChild] public unowned Button remove_avatar_button;
+ [GtkChild] public unowned Widget button_container;
+ [GtkChild] public unowned Button remove_account_button;
+ [GtkChild] public unowned Button disable_account_button;
+
+ public Account account { get { return model.selected_account.account; } }
+ public ViewModel.PreferencesWindow model { get; set; }
+
+ private Binding[] bindings = new Binding[0];
+ private ulong[] account_notify_ids = new ulong[0];
+ private ulong alias_entry_changed = 0;
+
+ construct {
+#if Adw_1_4
+ headerbar.show_title = false;
+#endif
+ button_container.layout_manager = new NaturalDirectionBoxLayout((BoxLayout)button_container.layout_manager);
+ back_button.clicked.connect(() => {
+ var window = (Adw.PreferencesWindow) this.get_root();
+ window.close_subpage();
+ });
+ edit_avatar_button.clicked.connect(() => {
+ show_select_avatar();
+ });
+ remove_avatar_button.clicked.connect(() => {
+ model.remove_avatar(account);
+ });
+ disable_account_button.clicked.connect(() => {
+ model.enable_disable_account(account);
+ });
+ remove_account_button.clicked.connect(() => {
+ show_remove_account_dialog();
+ });
+ enter_password_button.clicked.connect(() => {
+
+ var password = new PasswordEntry() { show_peek_icon=true };
+#if Adw_1_2
+ var dialog = new Adw.MessageDialog((Window)this.get_root(), "Enter password for %s".printf(account.bare_jid.to_string()), null);
+ dialog.response.connect((response) => {
+ if (response == "connect") {
+ account.password = password.text;
+ model.reconnect_account(account);
+ }
+ });
+ dialog.set_default_response("connect");
+ dialog.set_extra_child(password);
+ dialog.add_response("cancel", _("Cancel"));
+ dialog.add_response("connect", _("Connect"));
+#else
+ Gtk.MessageDialog dialog = new Gtk.MessageDialog (
+ (Window)this.get_root(), Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL,
+ "Enter password for %s", account.bare_jid.to_string());
+ Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button;
+ ok_button.label = _("Connect");
+
+ dialog.response.connect((response) => {
+ if (response == ResponseType.OK) {
+ account.password = password.text;
+ model.reconnect_account(account);
+ }
+ dialog.close();
+ });
+ dialog.get_content_area().append(password);
+#endif
+
+ dialog.present();
+ });
+
+ this.notify["model"].connect(() => {
+ model.notify["selected-account"].connect(() => {
+ foreach (var binding in bindings) {
+ binding.unbind();
+ }
+
+ avatar.model = model.selected_account.avatar_model;
+ xmpp_address.subtitle = account.bare_jid.to_string();
+
+ if (alias_entry_changed != 0) local_alias_entry.disconnect(alias_entry_changed);
+ local_alias_entry.text = account.alias ?? "";
+ alias_entry_changed = local_alias_entry.changed.connect(() => {
+ account.alias = local_alias_entry.text;
+ });
+
+ bindings += account.bind_property("enabled", disable_account_button, "label", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ bool enabled_bool = (bool) from;
+ to = enabled_bool ? _("Disable account") : _("Enable account");
+ return true;
+ });
+ bindings += account.bind_property("enabled", avatar_menu_box, "visible", BindingFlags.SYNC_CREATE);
+ bindings += account.bind_property("enabled", connection_status, "visible", BindingFlags.SYNC_CREATE);
+ bindings += model.selected_account.bind_property("connection-state", connection_status, "subtitle", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ to = get_status_label();
+ return true;
+ });
+ bindings += model.selected_account.bind_property("connection-error", connection_status, "subtitle", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ to = get_status_label();
+ return true;
+ });
+ bindings += model.selected_account.bind_property("connection-error", enter_password_button, "visible", BindingFlags.SYNC_CREATE, (binding, from, ref to) => {
+ var error = (ConnectionManager.ConnectionError) from;
+ to = error != null && error.source == ConnectionManager.ConnectionError.Source.SASL;
+ return true;
+ });
+
+ // Only show avatar removal button if an avatar is set
+ var avatar_model = model.selected_account.avatar_model.tiles.get_item(0) as ViewModel.AvatarPictureTileModel;
+ avatar_model.notify["image-file"].connect(() => {
+ remove_avatar_button.visible = avatar_model.image_file != null;
+ });
+ remove_avatar_button.visible = avatar_model.image_file != null;
+
+ model.selected_account.notify["connection-error"].connect(() => {
+ if (model.selected_account.connection_error != null) {
+ connection_status.add_css_class("error");
+ } else {
+ connection_status.remove_css_class("error");
+ }
+ });
+ if (model.selected_account.connection_error != null) {
+ connection_status.add_css_class("error");
+ } else {
+ connection_status.remove_css_class("error");
+ }
+ });
+ });
+ }
+
+ private void show_select_avatar() {
+ FileChooserNative chooser = new FileChooserNative(_("Select avatar"), (Window)this.get_root(), FileChooserAction.OPEN, _("Select"), _("Cancel"));
+ FileFilter filter = new FileFilter();
+ foreach (PixbufFormat pixbuf_format in Pixbuf.get_formats()) {
+ foreach (string mime_type in pixbuf_format.get_mime_types()) {
+ filter.add_mime_type(mime_type);
+ }
+ }
+ filter.set_filter_name(_("Images"));
+ chooser.add_filter(filter);
+
+ filter = new FileFilter();
+ filter.set_filter_name(_("All files"));
+ filter.add_pattern("*");
+ chooser.add_filter(filter);
+
+ chooser.response.connect(() => {
+ string uri = chooser.get_file().get_path();
+ model.set_avatar_uri(account, uri);
+ });
+
+ chooser.show();
+ }
+
+ private void show_remove_account_dialog() {
+ Gtk.MessageDialog msg = new Gtk.MessageDialog (
+ (Window)this.get_root(), Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.WARNING, Gtk.ButtonsType.OK_CANCEL,
+ _("Remove account %s?"), account.bare_jid.to_string());
+ msg.secondary_text = "You won't be able to access your conversation history anymore."; // TODO remove history!
+ Button ok_button = msg.get_widget_for_response(ResponseType.OK) as Button;
+ ok_button.label = _("Remove");
+ ok_button.add_css_class("destructive-action");
+ msg.response.connect((response) => {
+ if (response == ResponseType.OK) {
+ model.remove_account(account);
+ // Close the account subpage
+ var window = (Adw.PreferencesWindow) this.get_root();
+ window.close_subpage();
+// window.pop_subpage();
+ }
+ msg.close();
+ });
+ msg.present();
+ }
+
+ private string get_status_label() {
+ string? error_label = get_connection_error_description();
+ if (error_label != null) return error_label;
+
+ ConnectionManager.ConnectionState state = model.selected_account.connection_state;
+ switch (state) {
+ case ConnectionManager.ConnectionState.CONNECTING:
+ return _("Connecting…");
+ case ConnectionManager.ConnectionState.CONNECTED:
+ return _("Connected");
+ case ConnectionManager.ConnectionState.DISCONNECTED:
+ return _("Disconnected");
+ }
+ assert_not_reached();
+ }
+
+ private string? get_connection_error_description() {
+ ConnectionManager.ConnectionError? error = model.selected_account.connection_error;
+ if (error == null) return null;
+
+ switch (error.source) {
+ case ConnectionManager.ConnectionError.Source.SASL:
+ return _("Wrong password");
+ case ConnectionManager.ConnectionError.Source.TLS:
+ return _("Invalid TLS certificate");
+ }
+ if (error.identifier != null) {
+ return _("Error") + ": " + error.identifier;
+ } else {
+ return _("Error");
+ }
+ }
+}
+
+public class Dino.Ui.NaturalDirectionBoxLayout : LayoutManager {
+ private BoxLayout original;
+ private BoxLayout alternative;
+
+ public NaturalDirectionBoxLayout(BoxLayout original) {
+ this.original = original;
+ if (original.orientation == Orientation.HORIZONTAL) {
+ this.alternative = new BoxLayout(Orientation.VERTICAL);
+ this.alternative.spacing = this.original.spacing / 2;
+ }
+ }
+
+ public override SizeRequestMode get_request_mode(Widget widget) {
+ return original.orientation == Orientation.HORIZONTAL ? SizeRequestMode.HEIGHT_FOR_WIDTH : SizeRequestMode.WIDTH_FOR_HEIGHT;
+ }
+
+ public override void allocate(Widget widget, int width, int height, int baseline) {
+ int blind_minimum, blind_natural, blind_minimum_baseline, blind_natural_baseline;
+ original.measure(widget, original.orientation, -1, out blind_minimum, out blind_natural, out blind_minimum_baseline, out blind_natural_baseline);
+ int for_size = (original.orientation == Orientation.HORIZONTAL ? width : height);
+ if (for_size >= blind_minimum) {
+ original.allocate(widget, width, height, baseline);
+ } else {
+ alternative.allocate(widget, width, height, baseline);
+ }
+ }
+
+ public override void measure(Widget widget, Orientation orientation, int for_size, out int minimum, out int natural, out int minimum_baseline, out int natural_baseline) {
+ if (for_size == -1) {
+ original.measure(widget, orientation, -1, out minimum, out natural, out minimum_baseline, out natural_baseline);
+ int alt_minimum, alt_natural, alt_minimum_baseline, alt_natural_baseline;
+ alternative.measure(widget, orientation, -1, out alt_minimum, out alt_natural, out alt_minimum_baseline, out alt_natural_baseline);
+ if (alt_minimum < minimum && alt_minimum != -1) minimum = alt_minimum;
+ if (alt_minimum_baseline < minimum_baseline && alt_minimum_baseline != -1) minimum = alt_minimum_baseline;
+ } else {
+ Orientation other_orientation = orientation == Orientation.HORIZONTAL ? Orientation.VERTICAL : Orientation.HORIZONTAL;
+ int blind_minimum, blind_natural, blind_minimum_baseline, blind_natural_baseline;
+ original.measure(widget, other_orientation, -1, out blind_minimum, out blind_natural, out blind_minimum_baseline, out blind_natural_baseline);
+ if (for_size >= blind_minimum) {
+ original.measure(widget, orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline);
+ } else {
+ alternative.measure(widget, orientation, for_size, out minimum, out natural, out minimum_baseline, out natural_baseline);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/windows/preferences_window/accounts_preferences_page.vala b/main/src/windows/preferences_window/accounts_preferences_page.vala
new file mode 100644
index 00000000..7f4c2f1b
--- /dev/null
+++ b/main/src/windows/preferences_window/accounts_preferences_page.vala
@@ -0,0 +1,75 @@
+using Dino.Entities;
+using Gee;
+using Gtk;
+
+public class Dino.Ui.PreferencesWindowAccounts : Adw.PreferencesPage {
+
+ public signal void account_chosen(Account account);
+
+ public Adw.PreferencesGroup active_accounts;
+ public Adw.PreferencesGroup disabled_accounts;
+
+ public ViewModel.PreferencesWindow model { get; set; }
+
+ construct {
+ this.title = _("Accounts");
+ this.icon_name = "system-users-symbolic";
+
+ this.notify["model"].connect(() => {
+ model.update.connect(refresh);
+ });
+ }
+
+ private void refresh() {
+ if (active_accounts != null) this.remove(active_accounts);
+ if (disabled_accounts != null) this.remove(disabled_accounts);
+
+ active_accounts = new Adw.PreferencesGroup() { title=_("Accounts")};
+ disabled_accounts = new Adw.PreferencesGroup() { title=_("Disabled accounts")};
+ Button add_account_button = new Button.from_icon_name("list-add-symbolic");
+ add_account_button.add_css_class("flat");
+ add_account_button.tooltip_text = _("Add Account");
+ active_accounts.header_suffix = add_account_button;
+
+ this.add(active_accounts);
+ this.add(disabled_accounts);
+
+ add_account_button.clicked.connect(() => {
+ Ui.ManageAccounts.AddAccountDialog add_account_dialog = new Ui.ManageAccounts.AddAccountDialog(model.stream_interactor, model.db);
+ add_account_dialog.set_transient_for((Window)this.get_root());
+ add_account_dialog.added.connect((account) => {
+ refresh();
+ });
+ add_account_dialog.present();
+ });
+
+ disabled_accounts.visible = false; // Only display disabled section if it contains accounts
+ var enabled_account_added = false;
+
+ foreach (ViewModel.AccountDetails account_details in model.account_details.values) {
+ var row = new Adw.ActionRow() {
+ title = account_details.bare_jid.to_string()
+ };
+ row.add_prefix(new AvatarPicture() { valign=Align.CENTER, height_request=35, width_request=35, model = account_details.avatar_model });
+ row.add_suffix(new Image.from_icon_name("go-next-symbolic"));
+ row.activatable = true;
+
+ if (account_details.account.enabled) {
+ active_accounts.add(row);
+ enabled_account_added = true;
+ } else {
+ disabled_accounts.add(row);
+ disabled_accounts.visible = true;
+ }
+
+ row.activated.connect(() => {
+ account_chosen(account_details.account);
+ });
+ }
+
+ // We always have to show the active accounts group for the add new button. Display placeholder if there are no active accounts
+ if (!enabled_account_added) {
+ active_accounts.add(new Adw.ActionRow() { title=_("No active accounts") });
+ }
+ }
+}
diff --git a/main/src/windows/preferences_window/encryption_preferences_page.vala b/main/src/windows/preferences_window/encryption_preferences_page.vala
new file mode 100644
index 00000000..7477e6cd
--- /dev/null
+++ b/main/src/windows/preferences_window/encryption_preferences_page.vala
@@ -0,0 +1,73 @@
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+using Gtk;
+
+//[GtkTemplate (ui = "/im/dino/Dino/preferences_window_encryption.ui")]
+public class Dino.Ui.PreferencesWindowEncryption : Adw.PreferencesPage {
+
+ private DropDown drop_down = null;
+ private Adw.PreferencesGroup accounts_group = new Adw.PreferencesGroup();
+ private ArrayList<Adw.PreferencesGroup> added_widgets = new ArrayList<Adw.PreferencesGroup>();
+
+ public ViewModel.PreferencesWindow model { get; set; }
+
+ construct {
+ this.add(accounts_group);
+
+ this.notify["model"].connect(() => {
+ this.model.update.connect(() => {
+ repopulate_account_selector();
+ });
+ });
+ }
+
+ private void repopulate_account_selector() {
+ // Remove current selector
+ if (drop_down != null) {
+ accounts_group.remove(drop_down);
+ drop_down = null;
+ }
+
+ // Don't show selector if the user has only one account (active + inactive)
+ accounts_group.visible = model.account_details.size != 1;
+
+ // Populate selector
+ if (model.active_accounts_selection.get_n_items() > 0) {
+ drop_down = new DropDown(model.active_accounts_selection, null) { halign=Align.CENTER };
+ drop_down.factory = new BuilderListItemFactory.from_resource(null, "/im/dino/Dino/account_picker_row.ui");
+
+ drop_down.notify["selected-item"].connect(() => {
+ var account_details = (ViewModel.AccountDetails) drop_down.selected_item;
+ if (account_details == null) return;
+ set_account(account_details.account);
+ });
+
+ drop_down.selected = 0;
+ set_account(((ViewModel.AccountDetails)model.active_accounts_selection.get_item(0)).account);
+ } else {
+ drop_down = new DropDown.from_strings(new string[] { _("No active accounts")}) { halign=Align.CENTER };
+ unset_account();
+ }
+ accounts_group.add(drop_down);
+ }
+
+ private void unset_account() {
+ foreach (var widget in added_widgets) {
+ this.remove(widget);
+ }
+ added_widgets.clear();
+ }
+
+ private void set_account(Account account) {
+ unset_account();
+
+ Application app = GLib.Application.get_default() as Application;
+ foreach (Plugins.EncryptionPreferencesEntry e in app.plugin_registry.encryption_preferences_entries) {
+ var widget = (Adw.PreferencesGroup) e.get_widget(account, Plugins.WidgetType.GTK4);
+ this.add(widget);
+ this.added_widgets.add(widget);
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/windows/preferences_window/general_preferences_page.vala b/main/src/windows/preferences_window/general_preferences_page.vala
new file mode 100644
index 00000000..7aa6c2bd
--- /dev/null
+++ b/main/src/windows/preferences_window/general_preferences_page.vala
@@ -0,0 +1,39 @@
+using Gtk;
+
+public class Dino.Ui.ViewModel.GeneralPreferencesPage : Object {
+ public bool send_typing { get; set; }
+ public bool send_marker { get; set; }
+ public bool notifications { get; set; }
+ public bool convert_emojis { get; set; }
+}
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window_general.ui")]
+public class Dino.Ui.GeneralPreferencesPage : Adw.PreferencesPage {
+ [GtkChild] private unowned Switch typing_switch;
+ [GtkChild] private unowned Switch marker_switch;
+ [GtkChild] private unowned Switch notification_switch;
+ [GtkChild] private unowned Switch emoji_switch;
+
+ public ViewModel.GeneralPreferencesPage model { get; set; default = new ViewModel.GeneralPreferencesPage(); }
+ private Binding[] model_bindings = new Binding[0];
+
+ construct {
+ this.notify["model"].connect(on_model_changed);
+ }
+
+ private void on_model_changed() {
+ foreach (Binding binding in model_bindings) {
+ binding.unbind();
+ }
+ if (model != null) {
+ model_bindings = new Binding[] {
+ model.bind_property("send-typing", typing_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
+ model.bind_property("send-marker", marker_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
+ model.bind_property("notifications", notification_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL),
+ model.bind_property("convert-emojis", emoji_switch, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL)
+ };
+ } else {
+ model_bindings = new Binding[0];
+ }
+ }
+}
diff --git a/main/src/windows/preferences_window/preferences_window.vala b/main/src/windows/preferences_window/preferences_window.vala
new file mode 100644
index 00000000..e34261e9
--- /dev/null
+++ b/main/src/windows/preferences_window/preferences_window.vala
@@ -0,0 +1,31 @@
+using Gdk;
+using Dino.Entities;
+using Xmpp;
+using Xmpp.Xep;
+using Gee;
+using Gtk;
+
+[GtkTemplate (ui = "/im/dino/Dino/preferences_window.ui")]
+public class Dino.Ui.PreferencesWindow : Adw.PreferencesWindow {
+ [GtkChild] public unowned Dino.Ui.PreferencesWindowAccounts accounts_page;
+ [GtkChild] public unowned Dino.Ui.PreferencesWindowEncryption encryption_page;
+ [GtkChild] public unowned Dino.Ui.GeneralPreferencesPage general_page;
+ public Dino.Ui.AccountPreferencesSubpage account_page = new Dino.Ui.AccountPreferencesSubpage();
+
+ [GtkChild] public unowned ViewModel.PreferencesWindow model { get; }
+
+ construct {
+ this.default_height = 500;
+ this.default_width = 700;
+ this.can_navigate_back = true; // remove once we require Adw > 1.4
+ this.bind_property("model", accounts_page, "model", BindingFlags.SYNC_CREATE);
+ this.bind_property("model", account_page, "model", BindingFlags.SYNC_CREATE);
+ this.bind_property("model", encryption_page, "model", BindingFlags.SYNC_CREATE);
+
+ accounts_page.account_chosen.connect((account) => {
+ model.selected_account = model.account_details[account];
+ this.present_subpage(account_page);
+// this.present_subpage(new Adw.NavigationPage(account_page, "Account: %s".printf(account.bare_jid.to_string())));
+ });
+ }
+} \ No newline at end of file