[roidelapluie] gajim-remote change_avatar feature. Fixes #2793
This commit is contained in:
parent
c1d0013cb0
commit
eb74b2e592
2 changed files with 36 additions and 0 deletions
|
@ -264,6 +264,15 @@ class GajimRemote:
|
||||||
False)
|
False)
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'change_avatar': [
|
||||||
|
_('Change the avatar'),
|
||||||
|
[
|
||||||
|
('picture', _('Picture to use'), True),
|
||||||
|
('account', _('Account in which the avatar will be set; '
|
||||||
|
'if not specified, the avatar will be set for all accounts'),
|
||||||
|
False)
|
||||||
|
]
|
||||||
|
],
|
||||||
'handle_uri': [
|
'handle_uri': [
|
||||||
_('Handle a xmpp:/ uri'),
|
_('Handle a xmpp:/ uri'),
|
||||||
[
|
[
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
import os
|
import os
|
||||||
|
import base64
|
||||||
|
import mimetypes
|
||||||
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common import helpers
|
from common import helpers
|
||||||
|
@ -736,6 +738,31 @@ class SignalObject(dbus.service.Object):
|
||||||
for acc in gajim.contacts.get_accounts():
|
for acc in gajim.contacts.get_accounts():
|
||||||
gajim.connections[acc].send_stanza(str(xml))
|
gajim.connections[acc].send_stanza(str(xml))
|
||||||
|
|
||||||
|
@dbus.service.method(INTERFACE, in_signature='ss', out_signature='')
|
||||||
|
def change_avatar(self, picture, account):
|
||||||
|
filesize = os.path.getsize(picture)
|
||||||
|
invalid_file = False
|
||||||
|
if os.path.isfile(picture):
|
||||||
|
stat = os.stat(picture)
|
||||||
|
if stat[6] == 0:
|
||||||
|
invalid_file = True
|
||||||
|
else:
|
||||||
|
invalid_file = True
|
||||||
|
if not invalid_file and filesize < 16384:
|
||||||
|
fd = open(picture, 'rb')
|
||||||
|
data = fd.read()
|
||||||
|
avatar = base64.encodestring(data)
|
||||||
|
avatar_mime_type = mimetypes.guess_type(picture)[0]
|
||||||
|
vcard={}
|
||||||
|
vcard['PHOTO'] = {'BINVAL': avatar}
|
||||||
|
if avatar_mime_type:
|
||||||
|
vcard['PHOTO']['TYPE'] = avatar_mime_type
|
||||||
|
if account:
|
||||||
|
gajim.connections[account].send_vcard(vcard)
|
||||||
|
else:
|
||||||
|
for acc in gajim.connections:
|
||||||
|
gajim.connections[acc].send_vcard(vcard)
|
||||||
|
|
||||||
@dbus.service.method(INTERFACE, in_signature='ssss', out_signature='')
|
@dbus.service.method(INTERFACE, in_signature='ssss', out_signature='')
|
||||||
def join_room(self, room_jid, nick, password, account):
|
def join_room(self, room_jid, nick, password, account):
|
||||||
if not account:
|
if not account:
|
||||||
|
|
Loading…
Add table
Reference in a new issue