Manually merge ~thad-fisch/mugshot/improved-accountsservice-integration:97
This commit is contained in:
parent
8fadc36e3c
commit
68ecf14eec
|
@ -40,7 +40,6 @@ libreoffice_prefs = os.path.join(GLib.get_user_config_dir(), 'libreoffice',
|
||||||
'4', 'user', 'registrymodifications.xcu')
|
'4', 'user', 'registrymodifications.xcu')
|
||||||
pidgin_prefs = os.path.join(home, '.purple', 'prefs.xml')
|
pidgin_prefs = os.path.join(home, '.purple', 'prefs.xml')
|
||||||
faces_dir = '/usr/share/pixmaps/faces/'
|
faces_dir = '/usr/share/pixmaps/faces/'
|
||||||
icons_dir = '/var/lib/AccountsService/icons/'
|
|
||||||
|
|
||||||
|
|
||||||
def which(command):
|
def which(command):
|
||||||
|
@ -217,17 +216,22 @@ class MugshotWindow(Window):
|
||||||
# Check for .face and set profile image.
|
# Check for .face and set profile image.
|
||||||
logger.debug('Checking for ~/.face profile image')
|
logger.debug('Checking for ~/.face profile image')
|
||||||
face = os.path.join(home, '.face')
|
face = os.path.join(home, '.face')
|
||||||
|
logger.debug('Checking AccountsService for profile image')
|
||||||
|
image = self.accounts_service_get_user_image()
|
||||||
|
logger.debug('Found profile image: %s' % str(image))
|
||||||
|
|
||||||
if os.path.isfile(face):
|
if os.path.isfile(face):
|
||||||
self.set_user_image(face)
|
if os.path.samefile(image, face):
|
||||||
else:
|
self.updated_image = face
|
||||||
logger.debug('Checking AccountsService for profile image')
|
|
||||||
face = os.path.join(icons_dir, username)
|
|
||||||
logger.debug("%s" % face)
|
|
||||||
if os.path.isfile(face):
|
|
||||||
self.set_user_image(face)
|
|
||||||
else:
|
else:
|
||||||
self.set_user_image(None)
|
self.updated_image = None
|
||||||
self.updated_image = None
|
self.set_user_image(face)
|
||||||
|
elif os.path.isfile(image):
|
||||||
|
self.updated_image = image
|
||||||
|
self.set_user_image(image)
|
||||||
|
else:
|
||||||
|
self.updated_image = None
|
||||||
|
self.set_user_image(None)
|
||||||
|
|
||||||
# Search /etc/passwd for the current user's details.
|
# Search /etc/passwd for the current user's details.
|
||||||
logger.debug('Getting user details from /etc/passwd')
|
logger.debug('Getting user details from /etc/passwd')
|
||||||
|
@ -394,33 +398,57 @@ class MugshotWindow(Window):
|
||||||
logger.debug('Photo not updated, not saving changes.')
|
logger.debug('Photo not updated, not saving changes.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not os.path.isfile(self.updated_image):
|
||||||
|
self.updated_image = ""
|
||||||
|
|
||||||
face = os.path.join(home, '.face')
|
face = os.path.join(home, '.face')
|
||||||
|
|
||||||
# If the .face file already exists, remove it first.
|
if os.path.normpath(face) != os.path.normpath(self.updated_image):
|
||||||
logger.debug('Photo updated, saving changes.')
|
# If the .face file already exists, remove it first.
|
||||||
if os.path.isfile(face):
|
logger.debug('Photo updated, saving ~/.face profile image.')
|
||||||
os.remove(face)
|
if os.path.isfile(face):
|
||||||
|
os.remove(face)
|
||||||
|
# Copy the new file to ~/.face
|
||||||
|
if os.path.isfile(self.updated_image):
|
||||||
|
shutil.copyfile(self.updated_image, face)
|
||||||
|
|
||||||
# Copy the new file to ~/.face
|
# Update AccountsService profile image
|
||||||
if os.path.isfile(self.updated_image):
|
logger.debug('Photo updated, saving AccountsService profile image.')
|
||||||
# Scale the image as necessary (lp: #1298665)
|
self.accounts_service_set_user_image(self.updated_image)
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.updated_image)
|
|
||||||
if pixbuf.get_height() > 512 or pixbuf.get_width() > 512:
|
# Update Pidgin buddy icon
|
||||||
scaled_filename = helpers.new_tempfile('scaled')
|
self.set_pidgin_buddyicon(self.updated_image)
|
||||||
scaled = pixbuf.scale_simple(512, 512,
|
|
||||||
GdkPixbuf.InterpType.HYPER)
|
|
||||||
scaled.savev(scaled_filename, "png", [], [])
|
|
||||||
self.updated_image = scaled_filename
|
|
||||||
|
|
||||||
# Copy the file to ~/.face
|
|
||||||
shutil.copyfile(self.updated_image, face)
|
|
||||||
else:
|
|
||||||
face = ""
|
|
||||||
self.accounts_service_set_user_image(face)
|
|
||||||
self.set_pidgin_buddyicon(face)
|
|
||||||
self.updated_image = None
|
self.updated_image = None
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def accounts_service_get_user_image(self):
|
||||||
|
"""Get user profile image using AccountsService."""
|
||||||
|
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||||
|
result = bus.call_sync('org.freedesktop.Accounts',
|
||||||
|
'/org/freedesktop/Accounts',
|
||||||
|
'org.freedesktop.Accounts',
|
||||||
|
'FindUserByName',
|
||||||
|
GLib.Variant('(s)', (username,)),
|
||||||
|
GLib.VariantType.new('(o)'),
|
||||||
|
Gio.DBusCallFlags.NONE,
|
||||||
|
-1,
|
||||||
|
None)
|
||||||
|
(path,) = result.unpack()
|
||||||
|
|
||||||
|
result = bus.call_sync('org.freedesktop.Accounts',
|
||||||
|
path,
|
||||||
|
'org.freedesktop.DBus.Properties',
|
||||||
|
'GetAll',
|
||||||
|
GLib.Variant('(s)',
|
||||||
|
('org.freedesktop.Accounts.User',)),
|
||||||
|
GLib.VariantType.new('(a{sv})'),
|
||||||
|
Gio.DBusCallFlags.NONE,
|
||||||
|
-1,
|
||||||
|
None)
|
||||||
|
(props,) = result.unpack()
|
||||||
|
return props['IconFile']
|
||||||
|
|
||||||
def accounts_service_set_user_image(self, filename):
|
def accounts_service_set_user_image(self, filename):
|
||||||
"""Set user profile image using AccountsService."""
|
"""Set user profile image using AccountsService."""
|
||||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||||
|
|
Loading…
Reference in New Issue