Skip to content
Merged
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
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ src/Misc/Utils.vala
src/Views/GuestSettingsView.vala
src/Views/MainView.vala
src/Views/UserSettingsView.vala
src/Widgets/Popovers/AvatarPopover.vala
src/Widgets/CropView.vala
src/Widgets/ErrorRevealer.vala
src/Widgets/PasswordEditor.vala
Expand Down
34 changes: 34 additions & 0 deletions src/Misc/UserUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,39 @@ namespace SwitchboardPlugUserAccounts {
}
}
}

public void change_avatar (Gdk.Pixbuf? new_pixbuf) {
if (get_current_user () != user) {
var permission = get_permission ();
if (!permission.allowed) {
try {
permission.acquire ();
} catch (Error e) {
critical (e.message);
return;
}
}
}

if (new_pixbuf != null) {
var path = Path.build_filename (Environment.get_tmp_dir (), "user-icon-0");
int i = 0;
while (FileUtils.test (path, FileTest.EXISTS)) {
path = Path.build_filename (Environment.get_tmp_dir (), "user-icon-%d".printf (i));
i++;
}
try {
debug ("Saving temporary avatar file to %s".printf (path));
new_pixbuf.savev (path, "png", {}, {});
debug ("Setting avatar icon file for %s from temporary file %s".printf (user.get_user_name (), path));
user.set_icon_file (path);
} catch (Error e) {
critical (e.message);
}
} else {
debug ("Setting no avatar icon file for %s".printf (user.get_user_name ()));
user.set_icon_file ("");
}
}
}
}
73 changes: 72 additions & 1 deletion src/Views/UserSettingsView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace SwitchboardPlugUserAccounts.Widgets {
private Gtk.Switch autologin_switch;
private Gtk.Switch lock_switch;
private Gtk.InfoBar infobar;
private Gtk.Popover avatar_popover;

//lock widgets
private Gtk.Image full_name_lock;
Expand Down Expand Up @@ -88,7 +89,29 @@ namespace SwitchboardPlugUserAccounts.Widgets {

avatar = new Adw.Avatar (48, user.real_name, true);

var avatar_popover = new AvatarPopover (user, utils);
var remove_button = new Gtk.Button () {
child = new Gtk.Label (_("Remove")) {
xalign = 0
}
};
remove_button.add_css_class (Granite.STYLE_CLASS_MENUITEM);
remove_button.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);

var select_button = new Gtk.Button () {
child = new Gtk.Label (_("Set from File…")) {
xalign = 0
}
};
select_button.add_css_class (Granite.STYLE_CLASS_MENUITEM);

var button_box = new Gtk.Box (VERTICAL, 0);
button_box.append (remove_button);
button_box.append (select_button);

avatar_popover = new Gtk.Popover () {
autohide = true,
child = button_box
};
avatar_popover.add_css_class (Granite.STYLE_CLASS_MENU);

var avatar_button = new Gtk.MenuButton () {
Expand Down Expand Up @@ -423,6 +446,27 @@ namespace SwitchboardPlugUserAccounts.Widgets {

user.changed.connect (update_ui);
user.changed.connect (update_permission);

avatar_button.activate.connect (() => {
if (!avatar_button.active) {
return;
}

select_button.grab_focus ();

if (user.get_icon_file ().contains (".face")) {
remove_button.sensitive = false;
} else {
remove_button.sensitive = true;
}
});

remove_button.clicked.connect (() => {
avatar_popover.popdown ();
utils.change_avatar (null);
});

select_button.clicked.connect (select_from_file);
}

private void update_permission () {
Expand Down Expand Up @@ -701,5 +745,32 @@ namespace SwitchboardPlugUserAccounts.Widgets {
}
}
}

private async void select_from_file () {
avatar_popover.popdown ();

var filter = new Gtk.FileFilter ();
filter.set_filter_name (_("Images"));
filter.add_mime_type ("image/jpeg");
filter.add_mime_type ("image/jpg");
filter.add_mime_type ("image/png");

var file_dialog = new Gtk.FileDialog () {
title = _("Select an image"),
accept_label = _("Open")
};
file_dialog.default_filter = filter;

try {
File file = yield file_dialog.open (((Gtk.Application) Application.get_default ()).active_window, null);
var path = file.get_path ();

var avatar_dialog = new Dialogs.AvatarDialog (path);
avatar_dialog.request_avatar_change.connect (utils.change_avatar);
avatar_dialog.present ();
} catch (Error err) {
warning ("Failed to select image: %s", err.message);
}
}
}
}
131 changes: 0 additions & 131 deletions src/Widgets/Popovers/AvatarPopover.vala

This file was deleted.

1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ plug_files = files(
'Views/GuestSettingsView.vala',
'Views/MainView.vala',
'Views/UserSettingsView.vala',
'Widgets/Popovers/AvatarPopover.vala',
'Widgets/CropView.vala',
'Widgets/ErrorRevealer.vala',
'Widgets/PasswordEditor.vala',
Expand Down
Loading