aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/manage_accounts
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2022-02-14 14:55:59 +0100
committerfiaxh <git@lightrise.org>2022-07-27 20:34:20 +0200
commit7e7dcedaf31ee35499875491c9f569c575d28435 (patch)
tree0c5fee2b28baf320775fbc92b3c252e97d9d054f /main/src/ui/manage_accounts
parentf25bfb00969a7e09996da2d5500e6718f4cc0148 (diff)
downloaddino-7e7dcedaf31ee35499875491c9f569c575d28435.tar.gz
dino-7e7dcedaf31ee35499875491c9f569c575d28435.zip
Port from GTK3 to GTK4
Diffstat (limited to 'main/src/ui/manage_accounts')
-rw-r--r--main/src/ui/manage_accounts/add_account_dialog.vala65
-rw-r--r--main/src/ui/manage_accounts/dialog.vala48
2 files changed, 56 insertions, 57 deletions
diff --git a/main/src/ui/manage_accounts/add_account_dialog.vala b/main/src/ui/manage_accounts/add_account_dialog.vala
index 9cf60e3f..d3dbf390 100644
--- a/main/src/ui/manage_accounts/add_account_dialog.vala
+++ b/main/src/ui/manage_accounts/add_account_dialog.vala
@@ -110,9 +110,9 @@ public class AddAccountDialog : Gtk.Dialog {
foreach (string server in server_list) {
ListBoxRow list_box_row = new ListBoxRow() { visible=true };
- list_box_row.add(new Label(server) { xalign=0, margin=3, margin_start=7, margin_end=7, visible=true });
+ list_box_row.set_child(new Label(server) { xalign=0, margin_start=7, margin_end=7, visible=true });
list_box_jids[list_box_row] = server;
- server_list_box.add(list_box_row);
+ server_list_box.append(list_box_row);
}
// Register Form
@@ -134,7 +134,7 @@ public class AddAccountDialog : Gtk.Dialog {
create_account_box.visible = false;
register_box.visible = false;
success_box.visible = false;
- set_default(sign_in_jid_continue_button);
+// set_default(sign_in_jid_continue_button);
sign_in_jid_error_label.label = "";
jid_entry.sensitive = true;
@@ -174,7 +174,7 @@ public class AddAccountDialog : Gtk.Dialog {
create_account_box.visible = false;
register_box.visible = false;
success_box.visible = false;
- set_default(sign_in_password_continue_button);
+// set_default(sign_in_password_continue_button);
sign_in_password_error_label.label = "";
sign_in_password_title.label = _("Sign in to %s").printf(login_jid.to_string());
@@ -184,7 +184,7 @@ public class AddAccountDialog : Gtk.Dialog {
private void show_select_server() {
server_entry.text = "";
server_entry.grab_focus();
- set_default(select_server_continue);
+// set_default(select_server_continue);
server_list_box.row_activated.disconnect(on_server_list_row_activated);
server_list_box.unselect_all();
@@ -209,7 +209,7 @@ public class AddAccountDialog : Gtk.Dialog {
create_account_box.visible = false;
success_box.visible = false;
- set_default(register_form_continue);
+// set_default(register_form_continue);
animate_window_resize(register_box);
}
@@ -223,7 +223,7 @@ public class AddAccountDialog : Gtk.Dialog {
register_box.visible = false;
success_description.label = _("You can now use the account %s.").printf("<b>" + Markup.escape_text(account.bare_jid.to_string()) + "</b>");
- set_default(success_continue_button);
+// set_default(success_continue_button);
}
private void on_jid_entry_changed() {
@@ -329,36 +329,41 @@ public class AddAccountDialog : Gtk.Dialog {
}
private void set_register_form(Jid server, Xep.InBandRegistration.Form form) {
- form_box.foreach((widget) => { form_box.remove(widget); });
+ Widget widget = form_box.get_first_child();
+ while (widget != null) {
+ form_box.remove(widget);
+ widget = form_box.get_first_child();
+ }
+// form_box.foreach((widget) => { form_box.remove(widget); });
register_title.label = _("Register on %s").printf(server.to_string());
if (form.oob != null) {
- form_box.add(new Label(_("The server requires to sign up through a website")){ visible=true } );
- form_box.add(new Label(@"<a href=\"$(form.oob)\">$(form.oob)</a>") { use_markup=true, visible=true });
+ form_box.append(new Label(_("The server requires to sign up through a website")){ visible=true } );
+ form_box.append(new Label(@"<a href=\"$(form.oob)\">$(form.oob)</a>") { use_markup=true, visible=true });
register_form_continue_label.label = _("Open website");
register_form_continue.visible = true;
register_form_continue.grab_focus();
} else if (form.fields.size > 0) {
if (form.instructions != null && form.instructions != "") {
string markup_instructions = Util.parse_add_markup(form.instructions, null, true, false);
- form_box.add(new Label(markup_instructions) { use_markup=true, halign=Align.CENTER, xalign=0, margin_top=7,
+ form_box.append(new Label(markup_instructions) { use_markup=true, halign=Align.CENTER, xalign=0, margin_top=7,
wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR, visible=true });
}
foreach (Xep.DataForms.DataForm.Field field in form.fields) {
Widget? field_widget = Util.get_data_form_field_widget(field);
if (field.label != null && field.label != "" && field_widget != null) {
- form_box.add(new Label(field.label) { xalign=0, margin_top=7, visible=true });
- form_box.add(field_widget);
+ form_box.append(new Label(field.label) { xalign=0, margin_top=7, visible=true });
+ form_box.append(field_widget);
} else if (field.type_ == Xep.DataForms.DataForm.Type.FIXED && field.get_value_string() != "") {
string markup_fixed_field = Util.parse_add_markup(field.get_value_string(), null, true, false);
- form_box.add(new Label(markup_fixed_field) { use_markup=true, xalign=0, margin_top=7,
+ form_box.append(new Label(markup_fixed_field) { use_markup=true, xalign=0, margin_top=7,
wrap=true, wrap_mode=Pango.WrapMode.WORD_CHAR, visible=true });
}
}
register_form_continue.visible = true;
register_form_continue_label.label = _("Register");
} else {
- form_box.add(new Label(_("Check %s for information on how to sign up").printf(@"<a href=\"http://$(server)\">$(server)</a>")) { use_markup=true, visible=true });
+ form_box.append(new Label(_("Check %s for information on how to sign up").printf(@"<a href=\"http://$(server)\">$(server)</a>")) { use_markup=true, visible=true });
register_form_continue.visible = false;
}
}
@@ -418,21 +423,21 @@ public class AddAccountDialog : Gtk.Dialog {
}
private void animate_window_resize(Widget widget) { // TODO code duplication
- int def_height, curr_width, curr_height;
- get_size(out curr_width, out curr_height);
- widget.get_preferred_height(null, out def_height);
- def_height += 5;
- int difference = def_height - curr_height;
- Timer timer = new Timer();
- Timeout.add((int) (stack.transition_duration / 30),
- () => {
- ulong microsec;
- timer.elapsed(out microsec);
- ulong millisec = microsec / 1000;
- double partial = double.min(1, (double) millisec / stack.transition_duration);
- resize(curr_width, (int) (curr_height + difference * partial));
- return millisec < stack.transition_duration;
- });
+// int def_height, curr_width, curr_height;
+// get_size(out curr_width, out curr_height);
+// widget.get_preferred_height(null, out def_height);
+// def_height += 5;
+// int difference = def_height - curr_height;
+// Timer timer = new Timer();
+// Timeout.add((int) (stack.transition_duration / 30),
+// () => {
+// ulong microsec;
+// timer.elapsed(out microsec);
+// ulong millisec = microsec / 1000;
+// double partial = double.min(1, (double) millisec / stack.transition_duration);
+// resize(curr_width, (int) (curr_height + difference * partial));
+// return millisec < stack.transition_duration;
+// });
}
}
diff --git a/main/src/ui/manage_accounts/dialog.vala b/main/src/ui/manage_accounts/dialog.vala
index 5d596bc2..88dc7485 100644
--- a/main/src/ui/manage_accounts/dialog.vala
+++ b/main/src/ui/manage_accounts/dialog.vala
@@ -17,8 +17,8 @@ public class Dialog : Gtk.Dialog {
[GtkChild] public unowned Stack main_stack;
[GtkChild] public unowned ListBox account_list;
[GtkChild] public unowned Button no_accounts_add;
- [GtkChild] public unowned ToolButton add_account_button;
- [GtkChild] public unowned ToolButton remove_account_button;
+ [GtkChild] public unowned Button add_account_button;
+ [GtkChild] public unowned Button remove_account_button;
[GtkChild] public unowned AvatarImage image;
[GtkChild] public unowned Button image_button;
[GtkChild] public unowned Label jid_label;
@@ -28,8 +28,6 @@ public class Dialog : Gtk.Dialog {
[GtkChild] public unowned Util.EntryLabelHybrid alias_hybrid;
[GtkChild] public unowned Grid settings_list;
- private ArrayList<Plugins.AccountSettingsWidget> plugin_widgets = new ArrayList<Plugins.AccountSettingsWidget>();
-
private Database db;
private StreamInteractor stream_interactor;
private Account? selected_account;
@@ -44,8 +42,8 @@ public class Dialog : Gtk.Dialog {
if (selected_account != null) remove_account(account_row);
});
image_button.clicked.connect(show_select_avatar);
- alias_hybrid.entry.key_release_event.connect(() => { selected_account.alias = alias_hybrid.text; return false; });
- password_hybrid.entry.key_release_event.connect(() => { selected_account.password = password_hybrid.text; return false; });
+// alias_hybrid.entry.key_release_event.connect(() => { selected_account.alias = alias_hybrid.text; return false; });
+// password_hybrid.entry.key_release_event.connect(() => { selected_account.password = password_hybrid.text; return false; });
Util.LabelHybridGroup label_hybrid_group = new Util.LabelHybridGroup();
label_hybrid_group.add(alias_hybrid);
@@ -54,25 +52,18 @@ public class Dialog : Gtk.Dialog {
main_stack.set_visible_child_name("no_accounts");
int row_index = 4;
- int16 default_top_padding = new Gtk.Button().get_style_context().get_padding(Gtk.StateFlags.NORMAL).top + 1;
+ int16 default_top_padding = new Gtk.Button().get_style_context().get_padding().top + 1;
Application app = GLib.Application.get_default() as Application;
- foreach (var e in app.plugin_registry.account_settings_entries) {
- Plugins.AccountSettingsWidget widget = e.get_widget(Plugins.WidgetType.GTK);
- plugin_widgets.add(widget);
+ foreach (Plugins.AccountSettingsEntry e in app.plugin_registry.account_settings_entries) {
+ Widget? widget = e.get_widget(Plugins.WidgetType.GTK4) as Widget;
+ if (widget == null) continue;
Label label = new Label(e.name) { xalign=1, yalign=0, visible=true };
label.get_style_context().add_class("dim-label");
label.margin_top = e.label_top_padding == -1 ? default_top_padding : e.label_top_padding;
-
settings_list.attach(label, 0, row_index);
- if (widget is Widget) {
- Widget gtkw = (Widget) widget;
- plugin_widgets.add(widget);
- gtkw.visible = true;
- settings_list.attach(gtkw, 1, row_index, 2);
- } else {
- // TODO
- }
+
+ settings_list.attach(widget, 1, row_index, 2);
row_index++;
}
}
@@ -102,7 +93,7 @@ public class Dialog : Gtk.Dialog {
public AccountRow add_account(Account account) {
AccountRow account_item = new AccountRow (stream_interactor, account);
- account_list.add(account_item);
+ account_list.append(account_item);
main_stack.set_visible_child_name("accounts_exist");
return account_item;
}
@@ -127,7 +118,7 @@ public class Dialog : Gtk.Dialog {
Button ok_button = msg.get_widget_for_response(ResponseType.OK) as Button;
ok_button.label = _("Remove");
ok_button.get_style_context().add_class("destructive-action");
- if (msg.run() == Gtk.ResponseType.OK) {
+ if (/*msg.run() == Gtk.ResponseType.OK*/ true) {
account_list.remove(account_item);
if (account_item.account.enabled) account_disabled(account_item.account);
account_item.account.remove();
@@ -149,7 +140,7 @@ public class Dialog : Gtk.Dialog {
}
private void show_select_avatar() {
- PreviewFileChooserNative chooser = new PreviewFileChooserNative(_("Select avatar"), this, FileChooserAction.OPEN, _("Select"), _("Cancel"));
+ FileChooserNative chooser = new FileChooserNative(_("Select avatar"), this, 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()) {
@@ -164,10 +155,12 @@ public class Dialog : Gtk.Dialog {
filter.add_pattern("*");
chooser.add_filter(filter);
- if (chooser.run() == Gtk.ResponseType.ACCEPT) {
- string uri = chooser.get_filename();
+ chooser.response.connect(() => {
+ string uri = chooser.get_file().get_path();
stream_interactor.get_module(AvatarManager.IDENTITY).publish(selected_account, uri);
- }
+ });
+
+ chooser.show();
}
private bool change_account_state(bool state) {
@@ -201,8 +194,9 @@ public class Dialog : Gtk.Dialog {
active_switch.state_set.connect(change_account_state);
- foreach(Plugins.AccountSettingsWidget widget in plugin_widgets) {
- widget.set_account(account);
+ Application app = GLib.Application.get_default() as Application;
+ foreach (Plugins.AccountSettingsEntry e in app.plugin_registry.account_settings_entries) {
+ e.set_account(account);
}
}