diff --git a/js/Makefile.am b/js/Makefile.am index 3f05b42b3..d4fbd86ef 100644 --- a/js/Makefile.am +++ b/js/Makefile.am @@ -97,6 +97,7 @@ nobase_dist_js_DATA = \ ui/switcherPopup.js \ ui/tweener.js \ ui/unlockDialog.js \ + ui/userAvatar.js \ ui/userMenu.js \ ui/userWidget.js \ ui/viewSelector.js \ diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js index 9c32e8705..84324300d 100644 --- a/js/gdm/loginDialog.js +++ b/js/gdm/loginDialog.js @@ -40,7 +40,7 @@ const GdmUtil = imports.gdm.util; const Main = imports.ui.main; const ModalDialog = imports.ui.modalDialog; const Tweener = imports.ui.tweener; -const UserMenu = imports.ui.userMenu; +const UserAvatar = imports.ui.userAvatar; const UserWidget = imports.ui.userWidget; const _FADE_ANIMATION_TIME = 0.25; @@ -67,8 +67,8 @@ const UserListItem = new Lang.Class({ x_align: St.Align.START, x_fill: true }); - this._userAvatar = new UserMenu.UserAvatarWidget(this.user, - { styleClass: 'login-dialog-user-list-item-icon' }); + this._userAvatar = new UserAvatar.UserAvatar(this.user, + { styleClass: 'login-dialog-user-list-item-icon' }); layout.add(this._userAvatar.actor); let textLayout = new St.BoxLayout({ style_class: 'login-dialog-user-list-item-text-box', vertical: true }); diff --git a/js/ui/components/polkitAgent.js b/js/ui/components/polkitAgent.js index 20e8b2a50..20c6fec0a 100644 --- a/js/ui/components/polkitAgent.js +++ b/js/ui/components/polkitAgent.js @@ -16,7 +16,7 @@ const PolkitAgent = imports.gi.PolkitAgent; const Components = imports.ui.components; const ModalDialog = imports.ui.modalDialog; const ShellEntry = imports.ui.shellEntry; -const UserMenu = imports.ui.userMenu; +const UserAvatar = imports.ui.userAvatar; const DIALOG_ICON_SIZE = 48; @@ -100,9 +100,9 @@ const AuthenticationDialog = new Lang.Class({ let userBox = new St.BoxLayout({ style_class: 'polkit-dialog-user-layout', vertical: false }); messageBox.add(userBox); - this._userAvatar = new UserMenu.UserAvatarWidget(this._user, - { iconSize: DIALOG_ICON_SIZE, - styleClass: 'polkit-dialog-user-icon' }); + this._userAvatar = new UserAvatar.UserAvatar(this._user, + { iconSize: DIALOG_ICON_SIZE, + styleClass: 'polkit-dialog-user-icon' }); this._userAvatar.actor.hide(); userBox.add(this._userAvatar.actor, { x_fill: true, diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js index d3225819a..bc23502cc 100644 --- a/js/ui/endSessionDialog.js +++ b/js/ui/endSessionDialog.js @@ -35,7 +35,7 @@ const GnomeSession = imports.misc.gnomeSession; const Main = imports.ui.main; const ModalDialog = imports.ui.modalDialog; const Tweener = imports.ui.tweener; -const UserMenu = imports.ui.userMenu; +const UserAvatar = imports.ui.userAvatar; let _endSessionDialog = null; @@ -360,9 +360,9 @@ const EndSessionDialog = new Lang.Class({ icon_size: _DIALOG_ICON_SIZE, style_class: dialogContent.iconStyleClass }); } else { - let avatarWidget = new UserMenu.UserAvatarWidget(this._user, - { iconSize: _DIALOG_ICON_SIZE, - styleClass: dialogContent.iconStyleClass }); + let avatarWidget = new UserAvatar.UserAvatar(this._user, + { iconSize: _DIALOG_ICON_SIZE, + styleClass: dialogContent.iconStyleClass }); this._iconBin.child = avatarWidget.actor; avatarWidget.update(); } diff --git a/js/ui/userAvatar.js b/js/ui/userAvatar.js new file mode 100644 index 000000000..57aeba090 --- /dev/null +++ b/js/ui/userAvatar.js @@ -0,0 +1,52 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- + +const Gio = imports.gi.Gio; +const GLib = imports.gi.GLib; +const Lang = imports.lang; +const St = imports.gi.St; + +const Params = imports.misc.params; + +const DIALOG_ICON_SIZE = 64; + +// Adapted from gdm/gui/user-switch-applet/applet.c +// +// Copyright (C) 2004-2005 James M. Cape . +// Copyright (C) 2008,2009 Red Hat, Inc. + +const UserAvatar = new Lang.Class({ + Name: 'UserAvatar', + + _init: function(user, params) { + this._user = user; + params = Params.parse(params, { reactive: false, + iconSize: DIALOG_ICON_SIZE, + styleClass: 'status-chooser-user-icon' }); + this._iconSize = params.iconSize; + + this.actor = new St.Bin({ style_class: params.styleClass, + track_hover: params.reactive, + reactive: params.reactive }); + }, + + setSensitive: function(sensitive) { + this.actor.can_focus = sensitive; + this.actor.reactive = sensitive; + }, + + update: function() { + let iconFile = this._user.get_icon_file(); + if (iconFile && !GLib.file_test(iconFile, GLib.FileTest.EXISTS)) + iconFile = null; + + if (iconFile) { + let file = Gio.File.new_for_path(iconFile); + this.actor.child = null; + this.actor.style = 'background-image: url("%s");'.format(iconFile); + } else { + this.actor.style = null; + this.actor.child = new St.Icon({ icon_name: 'avatar-default-symbolic', + icon_size: this._iconSize }); + } + } +}); diff --git a/js/ui/userMenu.js b/js/ui/userMenu.js index 29d669448..ddaaae47c 100644 --- a/js/ui/userMenu.js +++ b/js/ui/userMenu.js @@ -21,6 +21,7 @@ const ModalDialog = imports.ui.modalDialog; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; const Params = imports.misc.params; +const UserAvatar = imports.ui.userAvatar; const Util = imports.misc.util; const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown'; @@ -57,48 +58,6 @@ const SystemdLoginSessionIface =