aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/util
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/util')
-rw-r--r--main/src/ui/util/data_forms.vala93
-rw-r--r--main/src/ui/util/helper.vala6
-rw-r--r--main/src/ui/util/label_hybrid.vala4
3 files changed, 99 insertions, 4 deletions
diff --git a/main/src/ui/util/data_forms.vala b/main/src/ui/util/data_forms.vala
index 1f598025..39dce3ee 100644
--- a/main/src/ui/util/data_forms.vala
+++ b/main/src/ui/util/data_forms.vala
@@ -6,6 +6,99 @@ using Xmpp.Xep;
namespace Dino.Ui.Util {
+public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataForms.DataForm.Field field) {
+ if (field.type_ == null) return null;
+
+ ViewModel.PreferencesRow.Any? view_model = null;
+
+ string? label = null;
+ string? desc = null;
+
+ if (field.var != null) {
+ switch (field.var) {
+ case "muc#roomconfig_roomname":
+ label = _("Name of the room");
+ break;
+ case "muc#roomconfig_roomdesc":
+ label = _("Description of the room");
+ break;
+ case "muc#roomconfig_persistentroom":
+ label = _("Persistent");
+ desc = _("The room will persist after the last occupant leaves");
+ break;
+ case "muc#roomconfig_publicroom":
+ label = _("Publicly searchable");
+ break;
+ case "muc#roomconfig_changesubject":
+ label = _("Occupants may change the subject");
+ break;
+ case "muc#roomconfig_whois":
+ label = _("Permission to view JIDs");
+ desc = _("Who is allowed to view the occupants' JIDs?");
+ break;
+ case "muc#roomconfig_roomsecret":
+ label = _("Password");
+// desc = _("A password to restrict access to the room");
+ break;
+ case "muc#roomconfig_moderatedroom":
+ label = _("Moderated");
+ desc = _("Only occupants with voice may send messages");
+ break;
+ case "muc#roomconfig_membersonly":
+ label = _("Members only");
+ desc = _("Only members may enter the room");
+ break;
+// case "muc#roomconfig_historylength":
+// label = _("Message history");
+// desc = _("Maximum amount of backlog issued by the room");
+// break;
+ }
+ }
+
+ if (label == null) label = field.label;
+
+ switch (field.type_) {
+ case DataForms.DataForm.Type.BOOLEAN:
+ DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField;
+ var toggle_model = new ViewModel.PreferencesRow.Toggle() { subtitle = desc, state = boolean_field.value };
+ boolean_field.bind_property("value", toggle_model, "state", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ view_model = toggle_model;
+ break;
+ case DataForms.DataForm.Type.JID_MULTI:
+ return null;
+ case DataForms.DataForm.Type.LIST_SINGLE:
+ DataForms.DataForm.ListSingleField list_single_field = field as DataForms.DataForm.ListSingleField;
+ var combobox_model = new ViewModel.PreferencesRow.ComboBox();
+ for (int i = 0; i < list_single_field.options.size; i++) {
+ DataForms.DataForm.Option option = list_single_field.options[i];
+ combobox_model.items.add(option.label);
+ if (option.value == list_single_field.value) combobox_model.active_item = i;
+ }
+ combobox_model.bind_property("active-item", list_single_field, "value", BindingFlags.DEFAULT, (binding, from, ref to) => {
+ var active_item = (int) from;
+ to = list_single_field.options[active_item].value;
+ return true;
+ });
+ view_model = combobox_model;
+ break;
+ case DataForms.DataForm.Type.LIST_MULTI:
+ return null;
+ case DataForms.DataForm.Type.TEXT_PRIVATE:
+ return null;
+ case DataForms.DataForm.Type.TEXT_SINGLE:
+ DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField;
+ var entry_model = new ViewModel.PreferencesRow.Entry() { text = text_single_field.value };
+ text_single_field.bind_property("value", entry_model, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ view_model = entry_model;
+ break;
+ default:
+ return null;
+ }
+
+ view_model.title = label;
+ return view_model;
+}
+
public static Widget? get_data_form_field_widget(DataForms.DataForm.Field field) {
if (field.type_ == null) return null;
switch (field.type_) {
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index d6da72dd..63288fc2 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -103,7 +103,13 @@ private const string force_color_css = "%s { color: %s; }";
public static Gtk.CssProvider force_css(Gtk.Widget widget, string css) {
var p = new Gtk.CssProvider();
try {
+#if GTK_4_12 && (VALA_0_56_GREATER_11 || VALA_0_58)
+ p.load_from_string(css);
+#elif (VALA_0_56_11 || VALA_0_56_12)
+ p.load_from_data(css, css.length);
+#else
p.load_from_data(css.data);
+#endif
widget.get_style_context().add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error err) {
// handle err
diff --git a/main/src/ui/util/label_hybrid.vala b/main/src/ui/util/label_hybrid.vala
index f426de7e..0059d2ae 100644
--- a/main/src/ui/util/label_hybrid.vala
+++ b/main/src/ui/util/label_hybrid.vala
@@ -97,10 +97,6 @@ public class EntryLabelHybrid : LabelHybrid {
}
}
- private void on_focus_leave() {
- show_label();
- }
-
private void update_label() {
if (visibility) {
label.label = entry.text;