diff options
| author | fiaxh <git@lightrise.org> | 2025-10-05 16:31:38 +0200 |
|---|---|---|
| committer | fiaxh <git@lightrise.org> | 2025-10-05 17:59:08 +0200 |
| commit | 61f20787151febd54b7271f686bc4f9de5613c15 (patch) | |
| tree | 08d303a97707a2f7de6fa1b4ca0bd70fde24da56 /main/src/ui | |
| parent | e14c7d933bfa0bdd97781857b9341854232058a2 (diff) | |
Cleanup: Remove LabelHybrid, conversation details preferences
Diffstat (limited to 'main/src/ui')
| -rw-r--r-- | main/src/ui/contact_details/permissions_provider.vala | 15 | ||||
| -rw-r--r-- | main/src/ui/contact_details/settings_provider.vala | 61 | ||||
| -rw-r--r-- | main/src/ui/conversation_details.vala | 32 | ||||
| -rw-r--r-- | main/src/ui/util/label_hybrid.vala | 189 | ||||
| -rw-r--r-- | main/src/ui/util/preference_group.vala | 10 |
5 files changed, 31 insertions, 276 deletions
diff --git a/main/src/ui/contact_details/permissions_provider.vala b/main/src/ui/contact_details/permissions_provider.vala index a0ca4d13..54eac7b1 100644 --- a/main/src/ui/contact_details/permissions_provider.vala +++ b/main/src/ui/contact_details/permissions_provider.vala @@ -1,5 +1,3 @@ -using Gtk; - using Dino.Entities; namespace Dino.Ui.ContactDetails { @@ -20,10 +18,15 @@ public class PermissionsProvider : Plugins.ContactDetailsProvider, Object { Xmpp.Jid? own_jid = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); if (own_jid == null) return; - if (stream_interactor.get_module(MucManager.IDENTITY).get_role(own_jid, conversation.account) == Xmpp.Xep.Muc.Role.VISITOR){ - Button voice_request = new Button.with_label(_("Request")); - voice_request.clicked.connect(()=>stream_interactor.get_module(MucManager.IDENTITY).request_voice(conversation.account, conversation.counterpart)); - contact_details.add("Permissions", _("Request permission to send messages"), "", voice_request); + if (true || stream_interactor.get_module(MucManager.IDENTITY).get_role(own_jid, conversation.account) == Xmpp.Xep.Muc.Role.VISITOR) { + var view_model = new Ui.ViewModel.PreferencesRow.Button() { + title = _("Request permission to send messages"), + button_text = _("Request") + }; + view_model.clicked.connect(()=> { + stream_interactor.get_module(MucManager.IDENTITY).request_voice(conversation.account, conversation.counterpart); + }); + contact_details.add_settings_action_row(view_model); } } diff --git a/main/src/ui/contact_details/settings_provider.vala b/main/src/ui/contact_details/settings_provider.vala index c6b87652..83794692 100644 --- a/main/src/ui/contact_details/settings_provider.vala +++ b/main/src/ui/contact_details/settings_provider.vala @@ -10,9 +10,6 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { private StreamInteractor stream_interactor; - private string DETAILS_HEADLINE_CHAT = "Settings"; - private string DETAILS_HEADLINE_ROOM = "Local Settings"; - public SettingsProvider(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; } @@ -21,54 +18,24 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object { if (type != Plugins.WidgetType.GTK4) return; if (!stream_interactor.get<MucManager>().is_public_room(conversation.account, conversation.counterpart)) { - string details_headline = conversation.type_ == Conversation.Type.GROUPCHAT ? DETAILS_HEADLINE_ROOM : DETAILS_HEADLINE_CHAT; - - ComboBoxText combobox_typing = get_combobox(Dino.Application.get_default().settings.send_typing); - combobox_typing.active_id = get_setting_id(conversation.send_typing); - combobox_typing.changed.connect(() => { conversation.send_typing = get_setting(combobox_typing.active_id); } ); - contact_details.add(details_headline, _("Send typing notifications"), "", combobox_typing); + string typing_default_setting = Dino.Application.get_default().settings.send_typing ? _("On") : _("Off"); + var setting_model = new Dino.Ui.ViewModel.PreferencesRow.ComboBox() { title = _("Send typing notifications") }; + setting_model.items.add(_("Default: %s").printf(typing_default_setting)); + setting_model.items.add(_("On")); + setting_model.items.add(_("Off")); + conversation.bind_property("send-typing", setting_model, "active-item", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + contact_details.add_settings_action_row(setting_model); } if (conversation.type_ == Conversation.Type.CHAT) { - ComboBoxText combobox_marker = get_combobox(Dino.Application.get_default().settings.send_marker); - contact_details.add(DETAILS_HEADLINE_CHAT, _("Send read receipts"), "", combobox_marker); - combobox_marker.active_id = get_setting_id(conversation.send_marker); - combobox_marker.changed.connect(() => { conversation.send_marker = get_setting(combobox_marker.active_id); } ); - } - } - - private Conversation.Setting get_setting(string id) { - switch (id) { - case "default": - return Conversation.Setting.DEFAULT; - case "on": - return Conversation.Setting.ON; - case "off": - return Conversation.Setting.OFF; + string marker_default_setting = Dino.Application.get_default().settings.send_marker ? _("On") : _("Off"); + var setting_model = new Dino.Ui.ViewModel.PreferencesRow.ComboBox() { title = _("Send read receipts") }; + setting_model.items.add(_("Default: %s").printf(marker_default_setting)); + setting_model.items.add(_("On")); + setting_model.items.add(_("Off")); + conversation.bind_property("send-marker", setting_model, "active-item", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + contact_details.add_settings_action_row(setting_model); } - assert_not_reached(); - } - - private string get_setting_id(Conversation.Setting setting) { - switch (setting) { - case Conversation.Setting.DEFAULT: - return "default"; - case Conversation.Setting.ON: - return "on"; - case Conversation.Setting.OFF: - return "off"; - } - assert_not_reached(); - } - - private ComboBoxText get_combobox(bool default_val) { - ComboBoxText combobox = new ComboBoxText(); - combobox = new ComboBoxText(); - string default_setting = default_val ? _("On") : _("Off"); - combobox.append("default", _("Default: %s").printf(default_setting) ); - combobox.append("on", _("On")); - combobox.append("off", _("Off")); - return combobox; } public Object? get_widget(Conversation conversation) { diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala index 3b4113ee..a1b7a9ce 100644 --- a/main/src/ui/conversation_details.vala +++ b/main/src/ui/conversation_details.vala @@ -206,8 +206,8 @@ namespace Dino.Ui.ConversationDetails { }); Plugins.ContactDetails contact_details = new Plugins.ContactDetails(); - contact_details.add.connect((c, l, d, wo) => { - add_entry(c, l, d, wo, dialog); + contact_details.add_settings_action_row.connect((entry_row_model) => { + dialog.model.settings_rows.append((Ui.ViewModel.PreferencesRow.Any) entry_row_model); }); Application app = GLib.Application.get_default() as Application; app.plugin_registry.register_contact_details_entry(new ContactDetails.SettingsProvider(stream_interactor)); @@ -223,32 +223,4 @@ namespace Dino.Ui.ConversationDetails { return dialog; } - - private void add_entry(string category, string label, string? description, Object wo, Dialog dialog) { - if (!(wo is Widget)) return; - - Widget widget = (Widget) wo; - if (widget.get_type().is_a(typeof(Entry))) { - Util.EntryLabelHybrid hybrid = new Util.EntryLabelHybrid.wrap(widget as Entry) { xalign=1 }; - widget = hybrid; - } else if (widget.get_type().is_a(typeof(ComboBoxText))) { - Util.ComboBoxTextLabelHybrid hybrid = new Util.ComboBoxTextLabelHybrid.wrap(widget as ComboBoxText) { xalign=1 }; - widget = hybrid; - } - - var view_model = new ViewModel.PreferencesRow.WidgetDeprecated() { - title = label, - widget = widget - }; - - switch (category) { - case "Permissions": - case "Local Settings": - case "Settings": - dialog.model.settings_rows.append(view_model); - break; - default: - break; - } - } } diff --git a/main/src/ui/util/label_hybrid.vala b/main/src/ui/util/label_hybrid.vala deleted file mode 100644 index 0059d2ae..00000000 --- a/main/src/ui/util/label_hybrid.vala +++ /dev/null @@ -1,189 +0,0 @@ -using Gee; -using Gtk; - -namespace Dino.Ui.Util { - -public class LabelHybrid : Widget { - - public Stack stack = new Stack(); - public Label label = new Label("") { max_width_chars=1, ellipsize=Pango.EllipsizeMode.END }; - protected Button button = new Button() { has_frame=false }; - - internal virtual void init(Widget widget) { - this.layout_manager = new BinLayout(); - stack.set_parent(this); - button.child = label; - stack.add_named(button, "label"); - stack.add_named(widget, "widget"); - - button.clicked.connect(() => { - show_widget(); - }); - } - - public void show_widget() { - stack.visible_child_name = "widget"; - stack.get_child_by_name("widget").grab_focus(); - } - - public void show_label() { - stack.visible_child_name = "label"; - } - - public override void dispose() { - stack.unparent(); - } -} - -public class EntryLabelHybrid : LabelHybrid { - - public string text { - get { return entry.text; } - set { - entry.text = value.dup(); - update_label(); - } - } - - public bool visibility { - get { return entry.visibility; } - set { entry.visibility = value; } - } - - public float xalign { - get { return label.xalign; } - set { - label.xalign = value; - entry.set_alignment(value); - } - } - - private Entry? entry_; - public Entry entry { - get { - if (entry_ == null) { - entry_ = new Entry(); - init(entry_); - } - return entry_; - } - set { entry_ = value; } - } - - public EntryLabelHybrid.wrap(Entry e) { - init(e); - } - - internal override void init(Widget widget) { - Entry? e = widget as Entry; - if (e == null) return; - entry = e; - base.init(entry); - update_label(); - - var key_events = new EventControllerKey(); - key_events.key_released.connect(on_key_released); - entry.add_controller(key_events); - entry.changed.connect(update_label); - - var focus_events = new EventControllerFocus(); - focus_events.leave.connect(update_label); - entry.add_controller(focus_events); - } - - private void on_key_released(uint keyval) { - if (keyval == Gdk.Key.Return) { - show_label(); - } - } - - private void update_label() { - if (visibility) { - label.label = entry.text; - } else { - string filler = ""; - for (int i = 0; i < entry.text.length; i++) filler += entry.get_invisible_char().to_string(); - label.label = filler; - } - } -} - -public class ComboBoxTextLabelHybrid : LabelHybrid { - - public int active { - get { return combobox.active; } - set { combobox.active = value; } - } - - public float xalign { - get { return label.xalign; } - set { label.xalign = value; } - } - - private ComboBoxText combobox_; - public ComboBoxText combobox { - get { - if (combobox_ == null) { - combobox_ = new ComboBoxText(); - init(combobox_); - } - return combobox_; - } - set { combobox_ = combobox; } - } - - public ComboBoxTextLabelHybrid.wrap(ComboBoxText cb) { - combobox_ = cb; - init(cb); - } - - public void append(string id, string text) { combobox.append(id, text); } - public string get_active_text() { return combobox.get_active_text(); } - - internal override void init(Widget widget) { - ComboBoxText? combobox = widget as ComboBoxText; if (combobox == null) return; - base.init(combobox); - update_label(); - - combobox.changed.connect(() => { - update_label(); - show_label(); - }); - button.clicked.connect(() => { - combobox.popup(); - }); - - var focus_events = new EventControllerFocus(); - focus_events.leave.connect(on_focus_leave); - combobox.add_controller(focus_events); - } - - private void on_focus_leave() { - update_label(); - show_label(); - } - - private void update_label() { - label.label = combobox.get_active_text(); - } -} - -public class LabelHybridGroup { - - private Gee.List<LabelHybrid> hybrids = new ArrayList<LabelHybrid>(); - - public void add(LabelHybrid hybrid) { - hybrids.add(hybrid); - - hybrid.notify["visible-child-name"].connect(() => { - if (hybrid.stack.visible_child_name == "label") return; - foreach (LabelHybrid h in hybrids) { - if (h != hybrid) { - h.stack.set_visible_child_name("label"); - } - } - }); - } -} - -} diff --git a/main/src/ui/util/preference_group.vala b/main/src/ui/util/preference_group.vala index efb5253a..268a593c 100644 --- a/main/src/ui/util/preference_group.vala +++ b/main/src/ui/util/preference_group.vala @@ -92,10 +92,12 @@ namespace Dino.Ui.Util { return view; } - var widget_view_model = preferences_row as ViewModel.PreferencesRow.WidgetDeprecated; - if (widget_view_model != null) { - var view = new Adw.ActionRow() { title = widget_view_model.title }; - view.add_suffix(widget_view_model.widget); + var button_view_model = preferences_row as ViewModel.PreferencesRow.Button; + if (button_view_model != null) { + var view = new Adw.ActionRow() { title = button_view_model.title }; + var button = new Button.with_label(button_view_model.button_text) { valign = Align.CENTER }; + view.add_suffix(button); + button.clicked.connect(() => button_view_model.clicked()); return view; } |
