Skip to content

Commit

Permalink
Start porting to GTK 4
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Oct 16, 2023
1 parent e2e24a3 commit e389267
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 71 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ datadir = join_paths(prefix, get_option('datadir'))
libdir = join_paths(prefix, get_option('libdir'))
localedir = join_paths(prefix, get_option('localedir'))

switchboard_dep = dependency('switchboard-2.0')
switchboard_dep = dependency('switchboard-3')
switchboard_plugsdir = switchboard_dep.get_pkgconfig_variable('plugsdir', define_variable: ['libdir', libdir])
pkgdatadir = join_paths(switchboard_plugsdir, 'system', 'pantheon-useraccounts')

Expand Down
12 changes: 6 additions & 6 deletions src/Dialogs/AvatarDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SwitchboardPlugUserAccounts.Dialogs.AvatarDialog : Granite.MessageD

public string pixbuf_path { get; construct; }

private Widgets.CropView cropview;
// private Widgets.CropView cropview;

public AvatarDialog (string pixbuf_path) {
Object (
Expand All @@ -36,18 +36,18 @@ public class SwitchboardPlugUserAccounts.Dialogs.AvatarDialog : Granite.MessageD

construct {
var button_change = add_button (_("Change Avatar"), Gtk.ResponseType.OK);
button_change.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
button_change.get_style_context ().add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

response.connect (on_response);

try {
var pixbuf = new Gdk.Pixbuf.from_file (pixbuf_path).apply_embedded_orientation ();
cropview = new Widgets.CropView.from_pixbuf_with_size (pixbuf, 400, 400);
cropview.quadratic_selection = true;
cropview.handles_visible = false;
// cropview = new Widgets.CropView.from_pixbuf_with_size (pixbuf, 400, 400);
// cropview.quadratic_selection = true;
// cropview.handles_visible = false;

var frame = new Gtk.Grid ();
frame.add (cropview);
// frame.add (cropview);

var frame_context = frame.get_style_context ();
frame_context.add_class (Granite.STYLE_CLASS_CARD);
Expand Down
2 changes: 1 addition & 1 deletion src/Dialogs/ChangePasswordDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class SwitchboardPlugUserAccounts.ChangePasswordDialog : Granite.Dialog {
button_change.margin_top = 14;
button_change.margin_start = 0;
button_change.sensitive = false;
button_change.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
button_change.get_style_context ().add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

pw_editor.validation_changed.connect (() => {
var permission = get_permission ();
Expand Down
40 changes: 19 additions & 21 deletions src/Dialogs/NewUserDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,32 @@ public class SwitchboardPlugUserAccounts.NewUserDialog : Granite.Dialog {
username_entry = new Granite.ValidatedEntry ();

username_error_revealer = new ErrorRevealer (".");
username_error_revealer.label_widget.get_style_context ().add_class (Gtk.STYLE_CLASS_ERROR);
username_error_revealer.label_widget.get_style_context ().add_class (Granite.STYLE_CLASS_ERROR);

pw_editor = new Widgets.PasswordEditor ();

var form_grid = new Gtk.Grid ();
form_grid.margin_start = form_grid.margin_end = 12;
form_grid.orientation = Gtk.Orientation.VERTICAL;
form_grid.row_spacing = 3;
form_grid.valign = Gtk.Align.CENTER;
form_grid.vexpand = true;
form_grid.add (accounttype_label);
form_grid.add (accounttype_combobox);
form_grid.add (new ErrorRevealer ("."));
form_grid.add (realname_label);
form_grid.add (realname_entry);
form_grid.add (new ErrorRevealer ("."));
form_grid.add (username_label);
form_grid.add (username_entry);
form_grid.add (username_error_revealer);
form_grid.add (pw_editor);
form_grid.show_all ();
var form_box = new Gtk.Box (VERTICAL, 3) {
margin_start = 12,
margin_end = 12,
valign = CENTER,
vexpand = true
};
form_box.append (accounttype_label);
form_box.append (accounttype_combobox);
form_box.append (new ErrorRevealer ("."));
form_box.append (realname_label);
form_box.append (realname_entry);
form_box.append (new ErrorRevealer ("."));
form_box.append (username_label);
form_box.append (username_entry);
form_box.append (username_error_revealer);
form_box.append (pw_editor);

deletable = false;
modal = true;
resizable= false;
width_request = 560;
window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
get_content_area ().add (form_grid);
get_content_area ().add (form_box);

var cancel_button = add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
cancel_button.margin_bottom = 6;
Expand All @@ -84,7 +82,7 @@ public class SwitchboardPlugUserAccounts.NewUserDialog : Granite.Dialog {
create_button.margin_top = 14;
create_button.can_default = true;
create_button.sensitive = false;
create_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
create_button.get_style_context ().add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

realname_entry.changed.connect (() => {
var username = gen_username (realname_entry.text);
Expand Down
23 changes: 7 additions & 16 deletions src/Plug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -57,45 +57,36 @@ namespace SwitchboardPlugUserAccounts {
infobar_reboot = new Gtk.InfoBar ();
infobar_reboot.message_type = Gtk.MessageType.WARNING;
infobar_reboot.revealed = false;
infobar_reboot.add_child (new Gtk.Label (_("Guest session changes will not take effect until you restart your system")));

var reboot_content = infobar_reboot.get_content_area ();
reboot_content.add (new Gtk.Label (_("Guest session changes will not take effect until you restart your system")));

InfobarNotifier.get_default ().notify["reboot-required"].connect (() => {
infobar_reboot.revealed = InfobarNotifier.get_default ().reboot_required;
});

infobar = new Gtk.InfoBar ();
infobar.message_type = Gtk.MessageType.INFO;

lock_button = new Gtk.LockButton (get_permission ());

var area = infobar.get_action_area () as Gtk.Container;
area.add (lock_button);

var content = infobar.get_content_area ();
content.add (new Gtk.Label (_("Some settings require administrator rights to be changed")));
infobar = new Gtk.InfoBar ();
infobar.message_type = Gtk.MessageType.INFO;
infobar.add_action_widget (lock_button, 0);
infobar.add_child (new Gtk.Label (_("Some settings require administrator rights to be changed")));

main_view = new Widgets.MainView ();

main_grid = new Gtk.Grid ();
main_grid.attach (infobar_reboot, 0, 1, 1, 1);
main_grid.attach (infobar, 0, 2, 1, 1);
main_grid.attach (main_view, 0, 3, 1, 1);
main_grid.show_all ();

get_permission ().notify["allowed"].connect (() => {
infobar.visible = !get_permission ().allowed;
infobar.revealed = !get_permission ().allowed;
});

return main_grid;
}

public override void shown () {
if (!get_permission ().allowed) {
infobar.show_all ();
infobar.visible = true;
}
infobar.revealed = !get_permission ().allowed;
}

public override void hidden () {
Expand Down
28 changes: 14 additions & 14 deletions src/Views/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace SwitchboardPlugUserAccounts.Widgets {
public class MainView : Gtk.Paned {
private UserListBox userlist;
private Granite.Widgets.Toast toast;
private Granite.Toast toast;
private Gtk.Stack content;
private Gtk.ScrolledWindow scrolled_window;
private GuestSettingsView guest;
Expand All @@ -33,7 +33,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
}

construct {
scrolled_window = new Gtk.ScrolledWindow (null, null);
scrolled_window = new Gtk.ScrolledWindow ();
scrolled_window.expand = true;
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;

Expand All @@ -49,21 +49,21 @@ namespace SwitchboardPlugUserAccounts.Widgets {
actionbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR);
actionbar.add (button_add);

var sidebar = new Gtk.Grid ();
sidebar.orientation = Gtk.Orientation.VERTICAL;
sidebar.add (scrolled_window);
sidebar.add (actionbar);
var sidebar = new Gtk.Box (VERTICAL, 0);
sidebar.append (scrolled_window);
sidebar.append (actionbar);

guest = new GuestSettingsView ();

content = new Gtk.Stack ();
content.add_named (guest, "guest_session");

toast = new Granite.Widgets.Toast ("");
toast = new Granite.Toast ("");
toast.set_default_action (_("Undo"));

var overlay = new Gtk.Overlay ();
overlay.add (content);
var overlay = new Gtk.Overlay () {
child = toast
};
overlay.add_overlay (toast);

pack1 (sidebar, false, false);
Expand All @@ -89,7 +89,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
Gtk.ButtonsType.CLOSE
) {
badge_icon = new ThemedIcon ("dialog-error"),
transient_for = (Gtk.Window) get_toplevel ()
transient_for = (Gtk.Window) get_root ()
};
message_dialog.show_error_details (e.message);
message_dialog.run ();
Expand All @@ -100,13 +100,13 @@ namespace SwitchboardPlugUserAccounts.Widgets {
}
}

var new_user = new SwitchboardPlugUserAccounts.NewUserDialog ((Gtk.Window) this.get_toplevel ());
var new_user = new SwitchboardPlugUserAccounts.NewUserDialog ((Gtk.Window) this.get_root ());
new_user.present ();
});

get_permission ().notify["allowed"].connect (() => {
if (!get_permission ().allowed) {
toast.reveal_child = false;
// toast.reveal_child = false;
}
});

Expand All @@ -123,7 +123,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
remove_user_settings (user);

if (get_removal_list ().last () == null) {
toast.reveal_child = false;
// toast.reveal_child = false;
}
});

Expand Down Expand Up @@ -159,7 +159,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
Gtk.ButtonsType.CLOSE
) {
badge_icon = new ThemedIcon ("dialog-error"),
transient_for = (Gtk.Window) get_toplevel ()
transient_for = (Gtk.Window) get_root ()
};
message_dialog.show_error_details (e.message);
message_dialog.present ();
Expand Down
12 changes: 6 additions & 6 deletions src/Views/UserSettingsView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
private Gtk.ListStore language_store;
private Gtk.ListStore region_store;

private Hdy.Avatar avatar;
private Adw.Avatar avatar;
private Gtk.ToggleButton avatar_button;
private Gtk.Entry full_name_entry;
private Gtk.Button password_button;
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {

default_regions = get_default_regions ();

avatar = new Hdy.Avatar (64, user.real_name, true);
avatar = new Adw.Avatar (64, user.real_name, true);
avatar.set_image_load_func (avatar_image_load_func);

avatar_button = new Gtk.ToggleButton () {
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
}
}

var change_password_dialog = new ChangePasswordDialog ((Gtk.Window) this.get_toplevel (), user);
var change_password_dialog = new ChangePasswordDialog ((Gtk.Window) this.get_root (), user);
change_password_dialog.present ();
change_password_dialog.request_password_change.connect (change_password);
});
Expand Down Expand Up @@ -380,10 +380,10 @@ namespace SwitchboardPlugUserAccounts.Widgets {
var user_locked = user.get_locked ();
if (user_locked) {
enable_user_button.label = _("Enable User Account");
enable_user_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
enable_user_button.get_style_context ().add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
} else {
enable_user_button.label = _("Disable User Account");
enable_user_button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
enable_user_button.get_style_context ().remove_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
}

if (delta_user.language != user.get_language ()) {
Expand Down Expand Up @@ -559,7 +559,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
new ThemedIcon ("dialog-password")
) {
badge_icon = new ThemedIcon ("dialog-error"),
transient_for = (Gtk.Window) get_toplevel ()
transient_for = (Gtk.Window) get_root ()
};
dialog.show_all ();
dialog.response.connect (dialog.destroy);
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/UserItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace SwitchboardPlugUserAccounts.Widgets {
public class UserItem : Gtk.ListBoxRow {
private Gtk.Revealer description_revealer;
private Hdy.Avatar avatar;
private Adw.Avatar avatar;
private Gtk.Label full_name_label;
private Gtk.Label username_label;
private Gtk.Revealer lock_revealer;
Expand Down
10 changes: 5 additions & 5 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plug_files = files(
'Views/MainView.vala',
'Views/UserSettingsView.vala',
'Widgets/Popovers/AvatarPopover.vala',
'Widgets/CropView.vala',
# 'Widgets/CropView.vala',
'Widgets/ErrorRevealer.vala',
'Widgets/PasswordEditor.vala',
'Widgets/UserItem.vala',
Expand All @@ -39,11 +39,11 @@ shared_module(
dependency('gee-0.8'),
dependency('gio-2.0'),
dependency('glib-2.0'),
dependency('gnome-desktop-3.0'),
# dependency('gnome-desktop-3.0'),
dependency('gobject-2.0'),
dependency('granite', version: '>=6.0.0'),
dependency('gtk+-3.0'),
dependency('libhandy-1', version: '>= 1.1.90'),
dependency('granite-7'),
dependency('gtk4'),
dependency('libadwaita-1'),
dependency('pwquality'),
meson.get_compiler('vala').find_library('run-passwd', dirs: join_paths(meson.current_source_dir())),
polkit_dep,
Expand Down

0 comments on commit e389267

Please sign in to comment.