Skip to content

Commit

Permalink
Refresh "Add account" UI
Browse files Browse the repository at this point in the history
  • Loading branch information
fiaxh committed Sep 15, 2024
1 parent 13123dc commit 63ba0bc
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 599 deletions.
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ SOURCES
src/ui/util/data_forms.vala
src/ui/util/helper.vala
src/ui/util/label_hybrid.vala
src/ui/util/preference_group.vala
src/ui/util/sizing_bin.vala
src/ui/util/size_request_box.vala

Expand Down
418 changes: 135 additions & 283 deletions main/data/manage_accounts/add_account_dialog.ui

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ sources = files(
'src/ui/util/data_forms.vala',
'src/ui/util/helper.vala',
'src/ui/util/label_hybrid.vala',
'src/ui/util/preference_group.vala',
'src/ui/util/size_request_box.vala',
'src/ui/util/sizing_bin.vala',
'src/ui/widgets/avatar_picture.vala',
Expand Down
310 changes: 137 additions & 173 deletions main/src/ui/manage_accounts/add_account_dialog.vala

Large diffs are not rendered by default.

65 changes: 21 additions & 44 deletions main/src/ui/util/data_forms.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ using Dino.Entities;
using Xmpp.Xep;

namespace Dino.Ui.Util {
public static GLib.ListStore get_data_form_view_model(DataForms.DataForm data_form) {
var list_store = new GLib.ListStore(typeof(ViewModel.PreferencesRow.Any));

foreach (var field in data_form.fields) {
var field_view_model = Util.get_data_form_field_view_model(field);
if (field_view_model != null) {
list_store.append(field_view_model);
}
}
return list_store;
}

public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataForms.DataForm.Field field) {
if (field.type_ == null) return null;
Expand Down Expand Up @@ -58,6 +69,11 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF
if (label == null) label = field.label;

switch (field.type_) {
case DataForms.DataForm.Type.FIXED:
var fixed_field = field as DataForms.DataForm.FixedField;
var fixed_model = new ViewModel.PreferencesRow.Text() { text=fixed_field.value };
view_model = fixed_model;
break;
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 };
Expand All @@ -84,7 +100,11 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF
case DataForms.DataForm.Type.LIST_MULTI:
return null;
case DataForms.DataForm.Type.TEXT_PRIVATE:
return null;
DataForms.DataForm.TextPrivateField text_private_field = field as DataForms.DataForm.TextPrivateField;
var private_entry_model = new ViewModel.PreferencesRow.PrivateText() { text = text_private_field.value };
text_private_field.bind_property("value", private_entry_model, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
view_model = private_entry_model;
break;
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 };
Expand All @@ -98,47 +118,4 @@ public static ViewModel.PreferencesRow.Any? get_data_form_field_view_model(DataF
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_) {
case DataForms.DataForm.Type.BOOLEAN:
DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField;
Switch sw = new Switch() { active=boolean_field.value, halign=Align.START, valign=Align.CENTER };
sw.state_set.connect((state) => {
boolean_field.value = state;
return false;
});
return sw;
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;
ComboBoxText combobox = new ComboBoxText() { valign=Align.CENTER };
for (int i = 0; i < list_single_field.options.size; i++) {
DataForms.DataForm.Option option = list_single_field.options[i];
combobox.append(option.value, option.label);
if (option.value == list_single_field.value) combobox.active = i;
}
combobox.changed.connect(() => {
list_single_field.value = combobox.get_active_id();
});
return combobox;
case DataForms.DataForm.Type.LIST_MULTI:
return null;
case DataForms.DataForm.Type.TEXT_PRIVATE:
DataForms.DataForm.TextPrivateField text_private_field = field as DataForms.DataForm.TextPrivateField;
PasswordEntry entry = new PasswordEntry() { text=text_private_field.value ?? "", valign=Align.CENTER };
entry.changed.connect(() => { text_private_field.value = entry.text; });
return entry;
case DataForms.DataForm.Type.TEXT_SINGLE:
DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField;
Entry entry = new Entry() { text=text_single_field.value ?? "", valign=Align.CENTER };
entry.changed.connect(() => { text_single_field.value = entry.text; });
return entry;
default:
return null;
}
}

}
106 changes: 106 additions & 0 deletions main/src/ui/util/preference_group.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Gee;
using Gtk;

using Dino.Entities;
using Xmpp.Xep;

namespace Dino.Ui.Util {
public Adw.PreferencesGroup rows_to_preference_group(GLib.ListStore row_view_models, string title) {
var preference_group = new Adw.PreferencesGroup() { title=title };

for (int preference_group_i = 0; preference_group_i < row_view_models.get_n_items(); preference_group_i++) {
var preferences_row = (ViewModel.PreferencesRow.Any) row_view_models.get_item(preference_group_i);

Widget? w = null;

var entry_view_model = preferences_row as ViewModel.PreferencesRow.Entry;
if (entry_view_model != null) {
Adw.EntryRow view = new Adw.EntryRow() { title = entry_view_model.title, show_apply_button=true };
entry_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => {
var str = (string) from;
to = str ?? "";
return true;
});
view.apply.connect(() => {
entry_view_model.changed();
});
w = view;
}

var password_view_model = preferences_row as ViewModel.PreferencesRow.PrivateText;
if (password_view_model != null) {
Adw.PasswordEntryRow view = new Adw.PasswordEntryRow() { title = password_view_model.title, show_apply_button=true };
password_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => {
var str = (string) from;
to = str ?? "";
return true;
});
view.apply.connect(() => {
password_view_model.changed();
});

w = view;
}

var row_text = preferences_row as ViewModel.PreferencesRow.Text;
if (row_text != null) {
w = new Adw.ActionRow() {
title = row_text.title,
subtitle = row_text.text,
#if Adw_1_3
subtitle_selectable = true,
#endif
};
w.add_css_class("property");

Util.force_css(w, "row.property > box.header > box.title > .title { font-weight: 400; font-size: 9pt; opacity: 0.55; }");
Util.force_css(w, "row.property > box.header > box.title > .subtitle { font-size: inherit; opacity: 1; }");
}

var toggle_view_model = preferences_row as ViewModel.PreferencesRow.Toggle;
if (toggle_view_model != null) {
var view = new Adw.ActionRow() { title = toggle_view_model.title, subtitle = toggle_view_model.subtitle };
var toggle = new Switch() { valign = Align.CENTER };
view.activatable_widget = toggle;
view.add_suffix(toggle);
toggle_view_model.bind_property("state", toggle, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
w = view;
}

var combobox_view_model = preferences_row as ViewModel.PreferencesRow.ComboBox;
if (combobox_view_model != null) {
var string_list = new StringList(null);
foreach (string text in combobox_view_model.items) {
string_list.append(text);
}
#if Adw_1_4
var view = new Adw.ComboRow() { title = combobox_view_model.title };
view.model = string_list;
combobox_view_model.bind_property("active-item", view, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
#else
var view = new Adw.ActionRow() { title = combobox_view_model.title };
var drop_down = new DropDown(string_list, null) { valign = Align.CENTER };
combobox_view_model.bind_property("active-item", drop_down, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
view.activatable_widget = drop_down;
view.add_suffix(drop_down);
#endif
w = 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);
w = view;
}

if (w == null) {
continue;
}

preference_group.add(w);
}

return preference_group;
}
}
5 changes: 5 additions & 0 deletions main/src/view_model/preferences_row.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace Dino.Ui.ViewModel.PreferencesRow {
public string text { get; set; }
}

public class PrivateText : Any {
public signal void changed();
public string text { get; set; }
}

public class Toggle : Any {
public string subtitle { get; set; }
public bool state { get; set; }
Expand Down
103 changes: 4 additions & 99 deletions main/src/windows/conversation_details.vala
Original file line number Diff line number Diff line change
Expand Up @@ -153,112 +153,17 @@ namespace Dino.Ui.ConversationDetails {
}

if (model.about_rows.get_n_items() > 0) {
about_box.append(rows_to_preference_group(model.about_rows, _("About")));
about_box.append(Util.rows_to_preference_group(model.about_rows, _("About")));
}
if (model.encryption_rows.get_n_items() > 0) {
about_box.append(rows_to_preference_group(model.encryption_rows, _("Encryption")));
about_box.append(Util.rows_to_preference_group(model.encryption_rows, _("Encryption")));
}
if (model.settings_rows.get_n_items() > 0) {
about_box.append(rows_to_preference_group(model.settings_rows, _("Settings")));
about_box.append(Util.rows_to_preference_group(model.settings_rows, _("Settings")));
}
if (model.room_configuration_rows != null && model.room_configuration_rows.get_n_items() > 0) {
about_box.append(rows_to_preference_group(model.room_configuration_rows, _("Room Configuration")));
about_box.append(Util.rows_to_preference_group(model.room_configuration_rows, _("Room Configuration")));
}
}

private Adw.PreferencesGroup rows_to_preference_group(GLib.ListStore row_view_models, string title) {
var preference_group = new Adw.PreferencesGroup() { title=title };

for (int preference_group_i = 0; preference_group_i < row_view_models.get_n_items(); preference_group_i++) {
var preferences_row = (ViewModel.PreferencesRow.Any) row_view_models.get_item(preference_group_i);

Widget? w = null;

var entry_view_model = preferences_row as ViewModel.PreferencesRow.Entry;
if (entry_view_model != null) {
#if Adw_1_2
Adw.EntryRow view = new Adw.EntryRow() { title = entry_view_model.title, show_apply_button=true };
entry_view_model.bind_property("text", view, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, (_, from, ref to) => {
var str = (string) from;
to = str ?? "";
return true;
});
view.apply.connect(() => {
entry_view_model.changed();
});
#else
var view = new Adw.ActionRow() { title = entry_view_model.title };
var entry = new Entry() { text=entry_view_model.text, valign=Align.CENTER };
entry_view_model.bind_property("text", entry, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
entry.changed.connect(() => {
entry_view_model.changed();
});
view.activatable_widget = entry;
view.add_suffix(entry);
#endif
w = view;
}

var row_text = preferences_row as ViewModel.PreferencesRow.Text;
if (row_text != null) {
w = new Adw.ActionRow() {
title = row_text.title,
subtitle = row_text.text,
#if Adw_1_3
subtitle_selectable = true
#endif
};
w.add_css_class("property");

Util.force_css(w, "row.property > box.header > box.title > .title { font-weight: 400; font-size: 9pt; opacity: 0.55; }");
Util.force_css(w, "row.property > box.header > box.title > .subtitle { font-size: inherit; opacity: 1; }");
}

var toggle_view_model = preferences_row as ViewModel.PreferencesRow.Toggle;
if (toggle_view_model != null) {
var view = new Adw.ActionRow() { title = toggle_view_model.title, subtitle = toggle_view_model.subtitle };
var toggle = new Switch() { valign = Align.CENTER };
view.activatable_widget = toggle;
view.add_suffix(toggle);
toggle_view_model.bind_property("state", toggle, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
w = view;
}

var combobox_view_model = preferences_row as ViewModel.PreferencesRow.ComboBox;
if (combobox_view_model != null) {
var string_list = new StringList(null);
foreach (string text in combobox_view_model.items) {
string_list.append(text);
}
#if Adw_1_4
var view = new Adw.ComboRow() { title = combobox_view_model.title };
view.model = string_list;
combobox_view_model.bind_property("active-item", view, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
#else
var view = new Adw.ActionRow() { title = combobox_view_model.title };
var drop_down = new DropDown(string_list, null) { valign = Align.CENTER };
combobox_view_model.bind_property("active-item", drop_down, "selected", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
view.activatable_widget = drop_down;
view.add_suffix(drop_down);
#endif
w = 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);
w = view;
}

if (w == null) {
continue;
}

preference_group.add(w);
}

return preference_group;
}
}
}

0 comments on commit 63ba0bc

Please sign in to comment.