Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Views/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SwitchboardPlugUserAccounts.Widgets.MainView : Gtk.Box {
hscrollbar_policy = NEVER
};

var add_button_label = new Gtk.Label (_("Create User Account…"));
var add_button_label = new Gtk.Label (_("Create Account…"));

var add_button_box = new Gtk.Box (HORIZONTAL, 0);
add_button_box.append (new Gtk.Image.from_icon_name ("list-add-symbolic"));
Expand Down Expand Up @@ -86,7 +86,7 @@ public class SwitchboardPlugUserAccounts.Widgets.MainView : Gtk.Box {
var paned = new Gtk.Paned (HORIZONTAL) {
start_child = sidebar,
end_child = overlay,
position = 240,
position = 200,
resize_start_child = false,
shrink_start_child = false,
shrink_end_child = false
Expand Down
192 changes: 83 additions & 109 deletions src/Views/UserSettingsView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

namespace SwitchboardPlugUserAccounts.Widgets {
public class UserSettingsView : Gtk.Grid {
public class UserSettingsView : Gtk.Box {
public weak Act.User user { get; construct; }

private UserUtils utils;
Expand All @@ -37,65 +37,77 @@ namespace SwitchboardPlugUserAccounts.Widgets {
private Gtk.Button language_button;
private Gtk.Switch autologin_switch;

//lock widgets
private Gtk.Image full_name_lock;
private Gtk.Image user_type_lock;
private Gtk.Image language_lock;
private Gtk.Image autologin_lock;
private Gtk.Image password_lock;
private Gtk.Image enable_lock;

private Gee.HashMap<string, string>? default_regions;

public signal void remove_user ();

private const string NO_PERMISSION_STRING = _("You do not have permission to change this");
private const string CURRENT_USER_STRING = _("You cannot change this for the currently active user");
private const string LAST_ADMIN_STRING = _("You cannot remove the last administrator's privileges");
private const string CURRENT_USER_STRING = _("This can't be changed for the currently active account");
private const string LAST_ADMIN_STRING = _("You can't remove the last administrator's privileges");

public UserSettingsView (Act.User user) {
Object (user: user);
}

class construct {
set_css_name ("simplesettingspage");
}

construct {
utils = new UserUtils (user, this);
delta_user = new DeltaUser (user);

default_regions = get_default_regions ();

avatar = new Adw.Avatar (64, user.real_name, true);
avatar = new Adw.Avatar (48, user.real_name, true) {
margin_top = 6,
margin_end = 6,
margin_bottom = 6
};

var avatar_popover = new AvatarPopover (user, utils);
avatar_popover.add_css_class (Granite.STYLE_CLASS_MENU);

var avatar_button = new Gtk.MenuButton () {
child = avatar,
halign = END,
has_frame = false,
valign = END,
icon_name = "edit-symbolic",
popover = avatar_popover
};
avatar_button.get_first_child ().add_css_class (Granite.STYLE_CLASS_CIRCULAR);

var avatar_overlay = new Gtk.Overlay () {
child = avatar
};
avatar_overlay.add_overlay (avatar_button);

full_name_entry = new Gtk.Entry () {
valign = Gtk.Align.CENTER
hexpand = true,
valign = CENTER
};
full_name_entry.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
full_name_entry.add_css_class (Granite.STYLE_CLASS_H2_LABEL);
full_name_entry.activate.connect (() => {
utils.change_full_name (full_name_entry.get_text ().strip ());
});

var user_type_label = new Gtk.Label (_("Account type:")) {
halign = Gtk.Align.END
user_type_box = new Gtk.ComboBoxText () {
hexpand = true
};

user_type_box = new Gtk.ComboBoxText ();
user_type_box.append_text (_("Standard"));
user_type_box.append_text (_("Administrator"));
user_type_box.changed.connect (() => {
utils.change_user_type (user_type_box.active);
});

var lang_label = new Gtk.Label (_("Language:")) {
halign = Gtk.Align.END
var user_type_label = new Granite.HeaderLabel (_("Account Type")) {
mnemonic_widget = user_type_box
};

var lang_label = new Granite.HeaderLabel (_("Language"));

var grid = new Gtk.Grid () {
column_spacing = 6,
row_spacing = 6,
vexpand = true
};

if (user != get_current_user ()) {
Expand All @@ -121,8 +133,8 @@ namespace SwitchboardPlugUserAccounts.Widgets {
reveal_child = true
};

attach (language_box, 1, 2);
attach (region_revealer, 1, 3);
grid.attach (language_box, 0, 3);
grid.attach (region_revealer, 0, 4);

language_box.changed.connect (() => {
Gtk.TreeIter? iter;
Expand Down Expand Up @@ -165,7 +177,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
tooltip_text = _("Click to switch to Language & Locale Settings")
};

attach (language_button, 1, 2);
grid.attach (language_button, 0, 3);
}

var login_label = new Gtk.Label (_("Log In automatically:")) {
Expand All @@ -179,7 +191,9 @@ namespace SwitchboardPlugUserAccounts.Widgets {
};
autologin_switch.notify["active"].connect (() => utils.change_autologin (autologin_switch.active));

password_button = new Gtk.Button.with_label (_("Change Password…"));
password_button = new Gtk.Button.with_label (_("Change Password…")) {
halign = END
};
password_button.clicked.connect (() => {
var permission = get_permission ();
if (user == get_current_user () && permission.allowed) {
Expand All @@ -200,89 +214,64 @@ namespace SwitchboardPlugUserAccounts.Widgets {
};
enable_user_button.clicked.connect (change_lock);

var remove_user_button = new Gtk.Button.with_label (_("Remove User Account")) {
var remove_user_button = new Gtk.Button.with_label (_("Remove Account")) {
sensitive = false
};
remove_user_button.get_style_context ().add_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);
remove_user_button.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);
remove_user_button.clicked.connect (() => remove_user ());

full_name_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
tooltip_text = NO_PERMISSION_STRING
};
full_name_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);

user_type_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
tooltip_text = NO_PERMISSION_STRING
};
user_type_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);

language_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
tooltip_text = NO_PERMISSION_STRING
};
language_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);

autologin_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
margin_top = 20,
tooltip_text = NO_PERMISSION_STRING
};
autologin_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);

password_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
tooltip_text = NO_PERMISSION_STRING
var remove_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
margin_start = 6
};
password_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);

enable_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic");
enable_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);
remove_lock.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var remove_lock = new Gtk.Image.from_icon_name ("changes-prevent-symbolic") {
tooltip_text = NO_PERMISSION_STRING
var header_grid = new Gtk.Grid () {
column_spacing = 12
};
remove_lock.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);


column_spacing = 12;
row_spacing = 6;
halign = CENTER;
margin_top = 24;
margin_end = 24;
margin_bottom = 24;
margin_start = 24;
attach (avatar_button, 0, 0);
attach (full_name_entry, 1, 0);
attach (user_type_label, 0, 1);
attach (user_type_box, 1, 1);
attach (lang_label, 0, 2);
attach (login_label, 0, 4);
attach (autologin_switch, 1, 4);
attach (password_button, 1, 5);
attach (enable_user_button, 1, 6);
attach (remove_user_button, 1, 7);
attach (full_name_lock, 2, 0);
attach (user_type_lock, 2, 1);
attach (language_lock, 2, 2, 1, 2);
attach (autologin_lock, 2, 4);
attach (password_lock, 2, 5);
attach (enable_lock, 2, 6);
attach (remove_lock, 2, 7);
header_grid.add_css_class ("header-area");
header_grid.attach (avatar_overlay, 0, 0);
header_grid.attach (full_name_entry, 1, 0);

var autologin_box = new Gtk.Box (HORIZONTAL, 6);
autologin_box.append (login_label);
autologin_box.append (autologin_switch);

grid.attach (user_type_label, 0, 0);
grid.attach (user_type_box, 0, 1);
grid.attach (lang_label, 0, 2);
grid.attach (autologin_box, 0, 5);
grid.add_css_class ("content-area");

var action_area = new Gtk.Box (HORIZONTAL, 0);
action_area.append (remove_user_button);
action_area.append (enable_user_button);
action_area.append (remove_lock);
action_area.append (new Gtk.Grid () { hexpand = true });
action_area.append (password_button);
action_area.add_css_class ("buttonbox");

margin_top = 6;
margin_end = 12;
margin_bottom = 12;
margin_start = 12;
orientation = VERTICAL;
append (header_grid);
append (grid);
append (action_area);

update_ui ();
update_permission ();

if (get_current_user () == user) {
enable_lock.tooltip_text = CURRENT_USER_STRING;
user_type_lock.tooltip_text = CURRENT_USER_STRING;
user_type_label.secondary_text = CURRENT_USER_STRING;
remove_lock.tooltip_text = CURRENT_USER_STRING;
} else if (is_last_admin (user)) {
enable_lock.tooltip_text = LAST_ADMIN_STRING;
user_type_lock.tooltip_text = LAST_ADMIN_STRING;
user_type_label.secondary_text = LAST_ADMIN_STRING;
remove_lock.tooltip_text = LAST_ADMIN_STRING;
} else {
enable_user_button.sensitive = true;
enable_lock.set_opacity (0);

remove_user_button.sensitive = true;
remove_lock.set_opacity (0);
action_area.remove (remove_lock);
}

get_permission ().notify["allowed"].connect (update_permission);
Expand All @@ -301,39 +290,26 @@ namespace SwitchboardPlugUserAccounts.Widgets {
user_type_box.sensitive = false;
password_button.sensitive = false;
autologin_switch.sensitive = false;

user_type_lock.set_opacity (1);
autologin_lock.set_opacity (1);
password_lock.set_opacity (1);

user_type_lock.tooltip_text = NO_PERMISSION_STRING;
}

if (current_user || allowed) {
full_name_entry.sensitive = true;
full_name_lock.set_opacity (0);
language_lock.set_opacity (0);

if (!user_locked) {
password_button.sensitive = true;
password_lock.set_opacity (0);
} else {
password_button.sensitive = false;
password_lock.set_opacity (1);
}

if (allowed) {
if (!user_locked) {
autologin_switch.sensitive = true;
autologin_lock.set_opacity (0);
} else {
autologin_switch.sensitive = false;
autologin_lock.set_opacity (1);
}

if (!last_admin && !current_user) {
user_type_box.sensitive = true;
user_type_lock.set_opacity (0);
}
}

Expand Down Expand Up @@ -379,11 +355,9 @@ 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 (Granite.STYLE_CLASS_SUGGESTED_ACTION);
enable_user_button.label = _("Enable Account");
} else {
enable_user_button.label = _("Disable User Account");
enable_user_button.get_style_context ().remove_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
enable_user_button.label = _("Disable Account");
}

if (delta_user.language != user.get_language ()) {
Expand Down