2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2005-2006 Andrew Sayman <lorien420 AT myrealbox.com>
|
|
|
|
# Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
# Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
# Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2006-2007 Travis Shirk <travis AT pobox.com>
|
|
|
|
# Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
# Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
|
|
|
|
# Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
# Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-17 23:41:54 +02:00
|
|
|
|
2005-08-15 20:28:19 +02:00
|
|
|
import os
|
2010-01-07 19:46:32 +01:00
|
|
|
import base64
|
|
|
|
import mimetypes
|
2019-01-10 21:50:49 +01:00
|
|
|
import logging
|
2018-02-02 17:56:55 +01:00
|
|
|
|
|
|
|
from gi.repository import GLib
|
|
|
|
from gi.repository import Gio
|
2005-07-17 23:41:54 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
2018-09-26 19:06:47 +02:00
|
|
|
from gajim.gtk.add_contact import AddNewContactWindow
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import ged
|
|
|
|
from gajim.common.connection_handlers_events import MessageOutgoingEvent
|
|
|
|
from gajim.common.connection_handlers_events import GcMessageOutgoingEvent
|
2013-07-19 11:52:37 +02:00
|
|
|
|
2019-01-10 21:50:49 +01:00
|
|
|
log = logging.getLogger('gajim.remote_control')
|
|
|
|
|
2005-07-19 22:12:02 +02:00
|
|
|
|
2006-02-18 10:49:26 +01:00
|
|
|
def get_dbus_struct(obj):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Recursively go through all the items and replace them with their casted dbus
|
|
|
|
equivalents
|
|
|
|
"""
|
|
|
|
if obj is None:
|
2018-02-02 17:56:55 +01:00
|
|
|
return None
|
2013-01-01 21:06:16 +01:00
|
|
|
if isinstance(obj, str):
|
2018-02-02 17:56:55 +01:00
|
|
|
return GLib.Variant('s', obj)
|
2010-02-08 15:08:40 +01:00
|
|
|
if isinstance(obj, int):
|
2018-02-02 17:56:55 +01:00
|
|
|
return GLib.Variant('i', obj)
|
2010-02-08 15:08:40 +01:00
|
|
|
if isinstance(obj, float):
|
2018-02-02 17:56:55 +01:00
|
|
|
return GLib.Variant('d', obj)
|
2010-02-08 15:08:40 +01:00
|
|
|
if isinstance(obj, bool):
|
2018-02-02 17:56:55 +01:00
|
|
|
return GLib.Variant('b', obj)
|
2010-02-08 15:08:40 +01:00
|
|
|
if isinstance(obj, (list, tuple)):
|
2018-08-17 21:08:47 +02:00
|
|
|
lst = [get_dbus_struct(i) for i in obj if i is not None]
|
|
|
|
result = GLib.Variant('av', lst)
|
2010-02-08 15:08:40 +01:00
|
|
|
return result
|
|
|
|
if isinstance(obj, dict):
|
2018-02-02 17:56:55 +01:00
|
|
|
result = GLib.VariantDict()
|
2010-02-08 15:08:40 +01:00
|
|
|
for key, value in obj.items():
|
2018-02-02 17:56:55 +01:00
|
|
|
result.insert_value(key, get_dbus_struct(value))
|
|
|
|
return result.end()
|
2010-02-08 15:08:40 +01:00
|
|
|
# unknown type
|
2018-09-17 00:28:38 +02:00
|
|
|
return GLib.Variant('s', str(obj))
|
2006-02-18 10:49:26 +01:00
|
|
|
|
2006-08-03 12:48:11 +02:00
|
|
|
|
2018-02-02 17:56:55 +01:00
|
|
|
class Server:
|
|
|
|
def __init__(self, con, path):
|
|
|
|
method_outargs = {}
|
|
|
|
method_inargs = {}
|
|
|
|
for interface in Gio.DBusNodeInfo.new_for_xml(self.__doc__).interfaces:
|
|
|
|
|
|
|
|
for method in interface.methods:
|
|
|
|
method_outargs[method.name] = '(' + ''.join(
|
|
|
|
[arg.signature for arg in method.out_args]) + ')'
|
|
|
|
method_inargs[method.name] = tuple(
|
|
|
|
arg.signature for arg in method.in_args)
|
|
|
|
|
|
|
|
con.register_object(
|
|
|
|
object_path=path,
|
|
|
|
interface_info=interface,
|
|
|
|
method_call_closure=self.on_method_call)
|
|
|
|
|
|
|
|
self.method_inargs = method_inargs
|
|
|
|
self.method_outargs = method_outargs
|
|
|
|
|
|
|
|
def on_method_call(self, connection, sender, object_path, interface_name,
|
|
|
|
method_name, parameters, invocation):
|
|
|
|
|
|
|
|
args = list(parameters.unpack())
|
|
|
|
for i, sig in enumerate(self.method_inargs[method_name]):
|
2018-09-17 23:03:45 +02:00
|
|
|
if sig == 'h':
|
2018-02-02 17:56:55 +01:00
|
|
|
msg = invocation.get_message()
|
|
|
|
fd_list = msg.get_unix_fd_list()
|
|
|
|
args[i] = fd_list.get(args[i])
|
|
|
|
|
|
|
|
result = getattr(self, method_name)(*args)
|
|
|
|
|
|
|
|
# out_args is atleast (signature1). We therefore always wrap the result
|
|
|
|
# as a tuple. Refer to https://bugzilla.gnome.org/show_bug.cgi?id=765603
|
|
|
|
result = (result, )
|
|
|
|
|
|
|
|
out_args = self.method_outargs[method_name]
|
|
|
|
if out_args != '()':
|
|
|
|
variant = GLib.Variant(out_args, result)
|
|
|
|
invocation.return_value(variant)
|
|
|
|
else:
|
|
|
|
invocation.return_value(None)
|
|
|
|
|
|
|
|
|
|
|
|
class GajimRemote(Server):
|
|
|
|
'''
|
|
|
|
<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'
|
|
|
|
'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>
|
|
|
|
<node>
|
|
|
|
<interface name='org.freedesktop.DBus.Introspectable'>
|
|
|
|
<method name='Introspect'>
|
|
|
|
<arg name='data' direction='out' type='s'/>
|
|
|
|
</method>
|
|
|
|
</interface>
|
|
|
|
<interface name='org.gajim.dbus.RemoteInterface'>
|
|
|
|
<method name='account_info'>
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='a{ss}' />
|
|
|
|
</method>
|
|
|
|
<method name='add_contact'>
|
|
|
|
<arg name='jid' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='change_avatar'>
|
|
|
|
<arg name='picture' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='change_status'>
|
|
|
|
<arg name='status' type='s' />
|
|
|
|
<arg name='message' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='get_status'>
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='get_status_message'>
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='get_unread_msgs_number'>
|
|
|
|
<arg direction='out' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='join_room'>
|
|
|
|
<arg name='room_jid' type='s' />
|
|
|
|
<arg name='nick' type='s' />
|
|
|
|
<arg name='password' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='list_accounts'>
|
|
|
|
<arg direction='out' type='as' />
|
|
|
|
</method>
|
|
|
|
<method name='list_contacts'>
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='aa{sv}' />
|
|
|
|
</method>
|
|
|
|
<method name='open_chat'>
|
|
|
|
<arg name='jid' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg name='message' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='prefs_del'>
|
|
|
|
<arg name='key' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='prefs_list'>
|
|
|
|
<arg direction='out' type='a{ss}' />
|
|
|
|
</method>
|
|
|
|
<method name='prefs_put'>
|
|
|
|
<arg name='key' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='prefs_store'>
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='remove_contact'>
|
|
|
|
<arg name='jid' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='send_chat_message'>
|
|
|
|
<arg name='jid' type='s' />
|
|
|
|
<arg name='message' type='s' />
|
|
|
|
<arg name='keyID' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='send_file'>
|
|
|
|
<arg name='file_path' type='s' />
|
|
|
|
<arg name='jid' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='send_groupchat_message'>
|
|
|
|
<arg name='room_jid' type='s' />
|
|
|
|
<arg name='message' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='send_single_message'>
|
|
|
|
<arg name='jid' type='s' />
|
|
|
|
<arg name='subject' type='s' />
|
|
|
|
<arg name='message' type='s' />
|
|
|
|
<arg name='keyID' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='send_xml'>
|
|
|
|
<arg name='xml' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='set_priority'>
|
|
|
|
<arg name='prio' type='s' />
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
</method>
|
|
|
|
<method name='show_next_pending_event' />
|
|
|
|
<method name='show_roster' />
|
|
|
|
<method name='start_chat'>
|
|
|
|
<arg name='account' type='s' />
|
|
|
|
<arg direction='out' type='b' />
|
|
|
|
</method>
|
|
|
|
<method name='toggle_ipython' />
|
|
|
|
<method name='toggle_roster_appearance' />
|
|
|
|
<signal name='AccountPresence'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='ChatState'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='ContactAbsence'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='ContactPresence'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='ContactStatus'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='EntityTime'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='GCMessage'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='GCPresence'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='MessageSent'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='NewAccount'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='NewMessage'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='OsInfo'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='Roster'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='RosterInfo'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='Subscribe'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='Subscribed'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='Unsubscribed'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
<signal name='VcardInfo'>
|
|
|
|
<arg type='av' />
|
|
|
|
</signal>
|
|
|
|
</interface>
|
|
|
|
</node>
|
|
|
|
'''
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.con = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
|
|
|
Gio.bus_own_name_on_connection(self.con, 'org.gajim.Gajim',
|
|
|
|
Gio.BusNameOwnerFlags.NONE, None, None)
|
|
|
|
super().__init__(self.con, '/org/gajim/dbus/RemoteObject')
|
|
|
|
self.first_show = True
|
2010-09-17 12:41:30 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('version-result-received', ged.POSTGUI,
|
2010-07-20 16:53:07 +02:00
|
|
|
self.on_os_info)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('time-result-received', ged.POSTGUI,
|
2010-07-20 16:53:07 +02:00
|
|
|
self.on_time)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('roster-info', ged.POSTGUI,
|
2010-08-23 14:35:03 +02:00
|
|
|
self.on_roster_info)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('presence-received', ged.POSTGUI,
|
2010-09-17 12:41:30 +02:00
|
|
|
self.on_presence_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('subscribe-presence-received',
|
2010-10-04 10:56:34 +02:00
|
|
|
ged.POSTGUI, self.on_subscribe_presence_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('subscribed-presence-received',
|
2010-10-04 10:56:34 +02:00
|
|
|
ged.POSTGUI, self.on_subscribed_presence_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('unsubscribed-presence-received',
|
2010-10-04 10:56:34 +02:00
|
|
|
ged.POSTGUI, self.on_unsubscribed_presence_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('gc-message-received',
|
2010-10-18 22:05:41 +02:00
|
|
|
ged.POSTGUI, self.on_gc_message_received)
|
2019-01-10 21:34:17 +01:00
|
|
|
app.ged.register_event_handler('decrypted-message-received',
|
|
|
|
ged.POSTGUI, self._nec_decrypted_message_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('our-show', ged.POSTGUI,
|
2010-11-26 21:14:59 +01:00
|
|
|
self.on_our_status)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('account-created', ged.POSTGUI,
|
2010-11-26 21:14:59 +01:00
|
|
|
self.on_account_created)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('vcard-received', ged.POSTGUI,
|
2010-11-26 21:14:59 +01:00
|
|
|
self.on_vcard_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('chatstate-received', ged.POSTGUI,
|
2011-03-24 22:48:56 +01:00
|
|
|
self.on_chatstate_received)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('message-sent', ged.POSTGUI,
|
2011-03-24 22:48:56 +01:00
|
|
|
self.on_message_sent)
|
|
|
|
|
|
|
|
def on_chatstate_received(self, obj):
|
2018-10-09 00:01:35 +02:00
|
|
|
if obj.contact.is_gc_contact:
|
|
|
|
jid = obj.contact.get_full_jid()
|
|
|
|
chatstate = obj.contact.chatstate
|
|
|
|
else:
|
|
|
|
jid = obj.contact.jid
|
|
|
|
chatstate = app.contacts.get_combined_chatstate(
|
|
|
|
obj.account, obj.contact.jid)
|
|
|
|
self.raise_signal('ChatState', (obj.account, [jid, chatstate]))
|
2011-03-24 22:48:56 +01:00
|
|
|
|
|
|
|
def on_message_sent(self, obj):
|
|
|
|
try:
|
|
|
|
chatstate = obj.chatstate
|
|
|
|
except AttributeError:
|
2018-08-17 21:08:47 +02:00
|
|
|
chatstate = ''
|
2011-03-24 22:48:56 +01:00
|
|
|
self.raise_signal('MessageSent', (obj.conn.name, [
|
|
|
|
obj.jid, obj.message, obj.keyID, chatstate]))
|
2010-07-20 16:53:07 +02:00
|
|
|
|
|
|
|
def on_os_info(self, obj):
|
2018-06-24 19:53:09 +02:00
|
|
|
self.raise_signal('OsInfo', (obj.conn.name, [obj.jid.getStripped(),
|
2018-07-01 23:43:50 +02:00
|
|
|
obj.jid.getResource(),
|
2018-06-24 19:53:09 +02:00
|
|
|
obj.client_info,
|
|
|
|
obj.os_info]))
|
2010-07-20 16:53:07 +02:00
|
|
|
|
|
|
|
def on_time(self, obj):
|
2018-06-24 17:00:13 +02:00
|
|
|
self.raise_signal('EntityTime', (obj.conn.name, [obj.jid.getStripped(),
|
|
|
|
obj.jid.getResource(),
|
|
|
|
obj.time_info]))
|
2005-07-19 17:07:00 +02:00
|
|
|
|
2010-08-23 14:35:03 +02:00
|
|
|
def on_roster_info(self, obj):
|
2010-08-23 14:47:59 +02:00
|
|
|
self.raise_signal('RosterInfo', (obj.conn.name, [obj.jid, obj.nickname,
|
2010-08-23 14:35:03 +02:00
|
|
|
obj.sub, obj.ask, obj.groups]))
|
|
|
|
|
2010-09-17 12:41:30 +02:00
|
|
|
def on_presence_received(self, obj):
|
|
|
|
if obj.old_show < 2 and obj.new_show > 1:
|
|
|
|
event = 'ContactPresence'
|
|
|
|
elif obj.old_show > 1 and obj.new_show < 2:
|
|
|
|
event = 'ContactAbsence'
|
|
|
|
elif obj.new_show > 1:
|
|
|
|
event = 'ContactStatus'
|
2018-02-02 17:56:55 +01:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
self.raise_signal(event, (obj.conn.name, [obj.jid, obj.show,
|
2019-01-01 16:19:35 +01:00
|
|
|
obj.status, obj.resource, obj.prio, obj.keyID, obj.timestamp]))
|
2010-09-17 12:41:30 +02:00
|
|
|
|
2010-10-04 10:56:34 +02:00
|
|
|
def on_subscribe_presence_received(self, obj):
|
|
|
|
self.raise_signal('Subscribe', (obj.conn.name, [obj.jid, obj.status,
|
|
|
|
obj.user_nick]))
|
|
|
|
|
|
|
|
def on_subscribed_presence_received(self, obj):
|
|
|
|
self.raise_signal('Subscribed', (obj.conn.name, [obj.jid,
|
|
|
|
obj.resource]))
|
|
|
|
|
|
|
|
def on_unsubscribed_presence_received(self, obj):
|
|
|
|
self.raise_signal('Unsubscribed', (obj.conn.name, obj.jid))
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
def on_gc_message_received(self, obj):
|
2010-10-25 11:23:10 +02:00
|
|
|
if not hasattr(obj, 'needs_highlight'):
|
|
|
|
# event has not been handled at GUI level
|
|
|
|
return
|
2010-10-18 22:05:41 +02:00
|
|
|
self.raise_signal('GCMessage', (obj.conn.name, [obj.fjid, obj.msgtxt,
|
2018-12-19 02:22:16 +01:00
|
|
|
obj.timestamp, obj.delayed, obj.xhtml_msgtxt,
|
2018-12-19 11:01:09 +01:00
|
|
|
obj.displaymarking, obj.needs_highlight]))
|
2010-10-18 22:05:41 +02:00
|
|
|
|
2019-01-10 21:34:17 +01:00
|
|
|
def _nec_decrypted_message_received(self, obj):
|
|
|
|
self.raise_signal('NewMessage', (
|
|
|
|
obj.conn.name, [obj.fjid, obj.msgtxt, obj.timestamp,
|
|
|
|
obj.encrypted, obj.mtype, obj.subject,
|
|
|
|
obj.msg_log_id, obj.user_nick, obj.xhtml, obj.form_node]))
|
|
|
|
|
2010-11-06 10:04:41 +01:00
|
|
|
def on_our_status(self, obj):
|
|
|
|
self.raise_signal('AccountPresence', (obj.show, obj.conn.name))
|
|
|
|
|
2010-11-07 18:26:31 +01:00
|
|
|
def on_account_created(self, obj):
|
|
|
|
self.raise_signal('NewAccount', (obj.conn.name, obj.account_info))
|
|
|
|
|
2010-11-26 21:14:59 +01:00
|
|
|
def on_vcard_received(self, obj):
|
|
|
|
self.raise_signal('VcardInfo', (obj.conn.name, obj.vcard_dict))
|
|
|
|
|
2018-02-02 17:56:55 +01:00
|
|
|
def raise_signal(self, event_name, data):
|
2019-01-10 21:50:49 +01:00
|
|
|
log.info('Send event %s', event_name)
|
2018-02-02 17:56:55 +01:00
|
|
|
self.con.emit_signal(None,
|
|
|
|
'/org/gajim/dbus/RemoteObject',
|
|
|
|
'org.gajim.dbus.RemoteInterface',
|
|
|
|
event_name,
|
|
|
|
GLib.Variant.new_tuple(get_dbus_struct(data)))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def get_status(self, account):
|
|
|
|
"""
|
2018-02-02 17:56:55 +01:00
|
|
|
Return status (show to be exact) which is the global one unless
|
|
|
|
account is given
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
if not account:
|
|
|
|
# If user did not ask for account, returns the global status
|
2018-02-02 17:56:55 +01:00
|
|
|
return helpers.get_global_show()
|
2010-02-08 15:08:40 +01:00
|
|
|
# return show for the given account
|
2017-08-13 13:18:56 +02:00
|
|
|
index = app.connections[account].connected
|
2018-02-02 17:56:55 +01:00
|
|
|
return app.SHOW_LIST[index]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def get_status_message(self, account):
|
|
|
|
"""
|
|
|
|
Return status which is the global one unless account is given
|
|
|
|
"""
|
|
|
|
if not account:
|
|
|
|
# If user did not ask for account, returns the global status
|
2018-02-02 17:56:55 +01:00
|
|
|
return str(helpers.get_global_status())
|
2010-02-08 15:08:40 +01:00
|
|
|
# return show for the given account
|
2017-08-13 13:18:56 +02:00
|
|
|
status = app.connections[account].status
|
2018-02-02 17:56:55 +01:00
|
|
|
return status
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _get_account_and_contact(self, account, jid):
|
|
|
|
"""
|
|
|
|
Get the account (if not given) and contact instance from jid
|
|
|
|
"""
|
|
|
|
connected_account = None
|
|
|
|
contact = None
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.contacts.get_accounts()
|
2010-02-08 15:08:40 +01:00
|
|
|
# if there is only one account in roster, take it as default
|
|
|
|
# if user did not ask for account
|
|
|
|
if not account and len(accounts) == 1:
|
|
|
|
account = accounts[0]
|
|
|
|
if account:
|
2018-02-02 17:56:55 +01:00
|
|
|
if app.connections[account].connected > 1: # account is connected
|
2010-02-08 15:08:40 +01:00
|
|
|
connected_account = account
|
2018-02-02 17:56:55 +01:00
|
|
|
contact = app.contacts.get_contact_with_highest_priority(
|
|
|
|
account, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2018-09-18 08:37:18 +02:00
|
|
|
for account_ in accounts:
|
2018-02-02 17:56:55 +01:00
|
|
|
contact = app.contacts.get_contact_with_highest_priority(
|
|
|
|
account, jid)
|
2018-09-18 08:37:18 +02:00
|
|
|
if contact and app.connections[account_].connected > 1:
|
2010-02-08 15:08:40 +01:00
|
|
|
# account is connected
|
2018-09-18 08:37:18 +02:00
|
|
|
connected_account = account_
|
2010-02-08 15:08:40 +01:00
|
|
|
break
|
|
|
|
if not contact:
|
|
|
|
contact = jid
|
|
|
|
|
|
|
|
return connected_account, contact
|
|
|
|
|
|
|
|
def _get_account_for_groupchat(self, account, room_jid):
|
|
|
|
"""
|
|
|
|
Get the account which is connected to groupchat (if not given)
|
|
|
|
or check if the given account is connected to the groupchat
|
|
|
|
"""
|
|
|
|
connected_account = None
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.contacts.get_accounts()
|
2010-02-08 15:08:40 +01:00
|
|
|
# if there is only one account in roster, take it as default
|
|
|
|
# if user did not ask for account
|
|
|
|
if not account and len(accounts) == 1:
|
|
|
|
account = accounts[0]
|
|
|
|
if account:
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.connections[account].connected > 1 and \
|
2018-02-02 17:56:55 +01:00
|
|
|
room_jid in app.gc_connected[account] and \
|
|
|
|
app.gc_connected[account][room_jid]:
|
2010-02-08 15:08:40 +01:00
|
|
|
# account and groupchat are connected
|
|
|
|
connected_account = account
|
|
|
|
else:
|
2018-09-18 08:37:18 +02:00
|
|
|
for account_ in accounts:
|
|
|
|
if app.connections[account_].connected > 1 and \
|
|
|
|
room_jid in app.gc_connected[account_] and \
|
|
|
|
app.gc_connected[account_][room_jid]:
|
2010-02-08 15:08:40 +01:00
|
|
|
# account and groupchat are connected
|
2018-09-18 08:37:18 +02:00
|
|
|
connected_account = account_
|
2010-02-08 15:08:40 +01:00
|
|
|
break
|
|
|
|
return connected_account
|
|
|
|
|
|
|
|
def send_file(self, file_path, jid, account):
|
|
|
|
"""
|
|
|
|
Send file, located at 'file_path' to 'jid', using account (optional)
|
|
|
|
'account'
|
|
|
|
"""
|
|
|
|
jid = self._get_real_jid(jid, account)
|
2018-02-02 17:56:55 +01:00
|
|
|
connected_account, contact = self._get_account_and_contact(
|
|
|
|
account, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if connected_account:
|
|
|
|
if file_path.startswith('file://'):
|
2018-02-02 17:56:55 +01:00
|
|
|
file_path = file_path[7:]
|
|
|
|
if os.path.isfile(file_path): # is it file?
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.instances['file_transfers'].send_file(
|
2018-02-02 17:56:55 +01:00
|
|
|
connected_account, contact, file_path)
|
|
|
|
return True
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-02-02 17:56:55 +01:00
|
|
|
def _send_message(self,
|
|
|
|
jid,
|
|
|
|
message,
|
|
|
|
keyID,
|
|
|
|
account,
|
|
|
|
type_='chat',
|
|
|
|
subject=None):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Can be called from send_chat_message (default when send_message) or
|
|
|
|
send_single_message
|
|
|
|
"""
|
|
|
|
if not jid or not message:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
if not keyID:
|
|
|
|
keyID = ''
|
|
|
|
|
2018-09-17 21:11:45 +02:00
|
|
|
connected_account = self._get_account_and_contact(account, jid)[0]
|
2010-02-08 15:08:40 +01:00
|
|
|
if connected_account:
|
2017-08-13 13:18:56 +02:00
|
|
|
connection = app.connections[connected_account]
|
2011-09-13 10:18:54 +02:00
|
|
|
sessions = connection.get_sessions(jid)
|
2018-09-17 21:11:45 +02:00
|
|
|
if not sessions:
|
|
|
|
connection.make_new_session(jid)
|
2018-02-02 17:56:55 +01:00
|
|
|
ctrl = app.interface.msg_win_mgr.search_control(
|
|
|
|
jid, connected_account)
|
2011-09-15 21:51:51 +02:00
|
|
|
if ctrl:
|
2013-09-02 14:35:54 +02:00
|
|
|
ctrl.send_message(message)
|
|
|
|
else:
|
2018-02-02 17:56:55 +01:00
|
|
|
app.nec.push_outgoing_event(
|
|
|
|
MessageOutgoingEvent(
|
|
|
|
None,
|
|
|
|
account=connected_account,
|
|
|
|
jid=jid,
|
|
|
|
message=message,
|
|
|
|
keyID=keyID,
|
|
|
|
type_=type_,
|
|
|
|
control=ctrl))
|
2013-03-19 10:25:10 +01:00
|
|
|
|
2018-02-02 17:56:55 +01:00
|
|
|
return True
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def send_chat_message(self, jid, message, keyID, account):
|
|
|
|
"""
|
|
|
|
Send chat 'message' to 'jid', using account (optional) 'account'. If keyID
|
|
|
|
is specified, encrypt the message with the pgp key
|
|
|
|
"""
|
|
|
|
jid = self._get_real_jid(jid, account)
|
|
|
|
return self._send_message(jid, message, keyID, account)
|
|
|
|
|
|
|
|
def send_single_message(self, jid, subject, message, keyID, account):
|
|
|
|
"""
|
|
|
|
Send single 'message' to 'jid', using account (optional) 'account'. If
|
|
|
|
keyID is specified, encrypt the message with the pgp key
|
|
|
|
"""
|
|
|
|
jid = self._get_real_jid(jid, account)
|
2018-02-02 17:56:55 +01:00
|
|
|
return self._send_message(jid, message, keyID, account, 'normal',
|
|
|
|
subject)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def send_groupchat_message(self, room_jid, message, account):
|
|
|
|
"""
|
|
|
|
Send 'message' to groupchat 'room_jid', using account (optional) 'account'
|
|
|
|
"""
|
|
|
|
if not room_jid or not message:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
connected_account = self._get_account_for_groupchat(account, room_jid)
|
|
|
|
if connected_account:
|
2018-02-02 17:56:55 +01:00
|
|
|
app.nec.push_outgoing_event(
|
|
|
|
GcMessageOutgoingEvent(
|
|
|
|
None,
|
|
|
|
account=connected_account,
|
|
|
|
jid=room_jid,
|
|
|
|
message=message))
|
|
|
|
return True
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def open_chat(self, jid, account, message):
|
|
|
|
"""
|
|
|
|
Shows the tabbed window for new message to 'jid', using account (optional)
|
|
|
|
'account'
|
|
|
|
"""
|
|
|
|
if not jid:
|
2018-07-24 21:49:01 +02:00
|
|
|
raise ValueError('jid is missing')
|
2010-02-08 15:08:40 +01:00
|
|
|
jid = self._get_real_jid(jid, account)
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(jid)
|
|
|
|
except Exception:
|
|
|
|
# Jid is not conform, ignore it
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-12-20 11:26:27 +01:00
|
|
|
minimized_control = None
|
2010-02-08 15:08:40 +01:00
|
|
|
if account:
|
|
|
|
accounts = [account]
|
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.connections.keys()
|
2010-02-08 15:08:40 +01:00
|
|
|
if len(accounts) == 1:
|
|
|
|
account = accounts[0]
|
|
|
|
connected_account = None
|
|
|
|
first_connected_acct = None
|
|
|
|
for acct in accounts:
|
2018-02-02 17:56:55 +01:00
|
|
|
if app.connections[acct].connected > 1: # account is online
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_first_contact_from_jid(acct, jid)
|
|
|
|
if app.interface.msg_win_mgr.has_window(jid, acct):
|
2010-02-08 15:08:40 +01:00
|
|
|
connected_account = acct
|
|
|
|
break
|
|
|
|
# jid is in roster
|
|
|
|
elif contact:
|
2010-12-15 10:17:34 +01:00
|
|
|
minimized_control = \
|
2017-08-13 13:18:56 +02:00
|
|
|
jid in app.interface.minimized_controls[acct]
|
2010-02-08 15:08:40 +01:00
|
|
|
connected_account = acct
|
|
|
|
break
|
|
|
|
# we send the message to jid not in roster, because account is
|
|
|
|
# specified, or there is only one account
|
|
|
|
elif account:
|
|
|
|
connected_account = acct
|
|
|
|
elif first_connected_acct is None:
|
|
|
|
first_connected_acct = acct
|
|
|
|
|
2018-06-27 00:52:14 +02:00
|
|
|
# if jid is not a contact, open-chat with first connected account
|
2010-02-08 15:08:40 +01:00
|
|
|
if connected_account is None and first_connected_acct:
|
|
|
|
connected_account = first_connected_acct
|
|
|
|
|
2010-12-15 10:17:34 +01:00
|
|
|
if minimized_control:
|
2018-02-02 17:56:55 +01:00
|
|
|
app.interface.roster.on_groupchat_maximized(
|
|
|
|
None, jid, connected_account)
|
2010-12-15 10:17:34 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if connected_account:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.new_chat_from_jid(connected_account, jid, message)
|
2010-02-08 15:08:40 +01:00
|
|
|
# preserve the 'steal focus preservation'
|
2018-02-02 17:56:55 +01:00
|
|
|
win = app.interface.msg_win_mgr.get_window(
|
|
|
|
jid, connected_account).window
|
2010-02-08 15:08:40 +01:00
|
|
|
if win.get_property('visible'):
|
2017-12-26 21:43:33 +01:00
|
|
|
win.window.present()
|
2018-02-02 17:56:55 +01:00
|
|
|
return True
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def change_status(self, status, message, account):
|
|
|
|
"""
|
|
|
|
change_status(status, message, account). Account is optional - if not
|
|
|
|
specified status is changed for all accounts
|
|
|
|
"""
|
2018-02-02 17:56:55 +01:00
|
|
|
if status not in ('offline', 'online', 'chat', 'away', 'xa', 'dnd',
|
|
|
|
'invisible'):
|
2010-02-08 15:08:40 +01:00
|
|
|
status = ''
|
|
|
|
if account:
|
|
|
|
if not status:
|
2017-08-13 13:18:56 +02:00
|
|
|
if account not in app.connections:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2017-08-13 13:18:56 +02:00
|
|
|
status = app.SHOW_LIST[app.connections[account].connected]
|
|
|
|
GLib.idle_add(app.interface.roster.send_status, account, status,
|
2018-02-02 17:56:55 +01:00
|
|
|
message)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# account not specified, so change the status of all accounts
|
2017-08-13 13:18:56 +02:00
|
|
|
for acc in app.contacts.get_accounts():
|
|
|
|
if not app.config.get_per('accounts', acc,
|
2018-02-02 17:56:55 +01:00
|
|
|
'sync_with_global_status'):
|
2010-02-08 15:08:40 +01:00
|
|
|
continue
|
|
|
|
if status:
|
|
|
|
status_ = status
|
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
if acc not in app.connections:
|
2010-02-08 15:08:40 +01:00
|
|
|
continue
|
2017-08-13 13:18:56 +02:00
|
|
|
status_ = app.SHOW_LIST[app.connections[acc].connected]
|
|
|
|
GLib.idle_add(app.interface.roster.send_status, acc, status_,
|
2018-02-02 17:56:55 +01:00
|
|
|
message)
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def set_priority(self, prio, account):
|
|
|
|
"""
|
|
|
|
set_priority(prio, account). Account is optional - if not specified
|
|
|
|
priority is changed for all accounts. That are synced with global status
|
|
|
|
"""
|
|
|
|
if account:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('accounts', account, 'priority', prio)
|
|
|
|
show = app.SHOW_LIST[app.connections[account].connected]
|
|
|
|
status = app.connections[account].status
|
2018-02-02 17:56:55 +01:00
|
|
|
GLib.idle_add(app.connections[account].change_status, show, status)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# account not specified, so change prio of all accounts
|
2017-08-13 13:18:56 +02:00
|
|
|
for acc in app.contacts.get_accounts():
|
|
|
|
if not app.account_is_connected(acc):
|
2010-02-08 15:08:40 +01:00
|
|
|
continue
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.config.get_per('accounts', acc,
|
2018-02-02 17:56:55 +01:00
|
|
|
'sync_with_global_status'):
|
2010-02-08 15:08:40 +01:00
|
|
|
continue
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('accounts', acc, 'priority', prio)
|
|
|
|
show = app.SHOW_LIST[app.connections[acc].connected]
|
|
|
|
status = app.connections[acc].status
|
2018-02-02 17:56:55 +01:00
|
|
|
GLib.idle_add(app.connections[acc].change_status, show, status)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def show_next_pending_event(self):
|
|
|
|
"""
|
|
|
|
Show the window(s) with next pending event in tabbed/group chats
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.events.get_nb_events():
|
|
|
|
account, jid, event = app.events.get_first_systray_event()
|
2011-08-01 19:31:22 +02:00
|
|
|
if not event:
|
|
|
|
return
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.handle_event(account, jid, event.type_)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def list_accounts(self):
|
|
|
|
"""
|
|
|
|
List register accounts
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
result = app.contacts.get_accounts()
|
2018-02-02 17:56:55 +01:00
|
|
|
result_array = []
|
|
|
|
if result:
|
2010-02-08 15:08:40 +01:00
|
|
|
for account in result:
|
2018-02-02 17:56:55 +01:00
|
|
|
result_array.append(account)
|
2010-02-08 15:08:40 +01:00
|
|
|
return result_array
|
|
|
|
|
|
|
|
def account_info(self, account):
|
|
|
|
"""
|
|
|
|
Show info on account: resource, jid, nick, prio, message
|
|
|
|
"""
|
2018-02-02 17:56:55 +01:00
|
|
|
result = {}
|
2017-08-13 13:18:56 +02:00
|
|
|
if account in app.connections:
|
2010-02-08 15:08:40 +01:00
|
|
|
# account is valid
|
2017-08-13 13:18:56 +02:00
|
|
|
con = app.connections[account]
|
2010-02-08 15:08:40 +01:00
|
|
|
index = con.connected
|
2018-02-02 17:56:55 +01:00
|
|
|
result['status'] = app.SHOW_LIST[index]
|
|
|
|
result['name'] = con.name
|
|
|
|
result['jid'] = app.get_jid_from_account(con.name)
|
|
|
|
result['message'] = con.status
|
|
|
|
result['priority'] = str(con.priority)
|
|
|
|
result['resource'] = app.config.get_per('accounts', con.name,
|
|
|
|
'resource')
|
2010-02-08 15:08:40 +01:00
|
|
|
return result
|
|
|
|
|
|
|
|
def list_contacts(self, account):
|
|
|
|
"""
|
2018-02-02 17:56:55 +01:00
|
|
|
List all contacts in the roster. If the first argument is specified,
|
|
|
|
then return the contacts for the specified account
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2018-02-02 17:56:55 +01:00
|
|
|
result = []
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.contacts.get_accounts()
|
2018-02-02 17:56:55 +01:00
|
|
|
if not accounts:
|
2010-02-08 15:08:40 +01:00
|
|
|
return result
|
|
|
|
if account:
|
|
|
|
accounts_to_search = [account]
|
|
|
|
else:
|
|
|
|
accounts_to_search = accounts
|
|
|
|
for acct in accounts_to_search:
|
|
|
|
if acct in accounts:
|
2017-08-13 13:18:56 +02:00
|
|
|
for jid in app.contacts.get_jid_list(acct):
|
2010-02-08 15:08:40 +01:00
|
|
|
item = self._contacts_as_dbus_structure(
|
2017-08-13 13:18:56 +02:00
|
|
|
app.contacts.get_contacts(acct, jid))
|
2010-02-08 15:08:40 +01:00
|
|
|
if item:
|
|
|
|
result.append(item)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def prefs_list(self):
|
2018-02-02 17:56:55 +01:00
|
|
|
prefs_dict = {}
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def get_prefs(data, name, path, value):
|
|
|
|
if value is None:
|
|
|
|
return
|
|
|
|
key = ''
|
|
|
|
if path is not None:
|
|
|
|
for node in path:
|
|
|
|
key += node + '#'
|
|
|
|
key += name
|
2018-02-02 17:56:55 +01:00
|
|
|
prefs_dict[key] = str(value)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.foreach(get_prefs)
|
2010-02-08 15:08:40 +01:00
|
|
|
return prefs_dict
|
|
|
|
|
|
|
|
def prefs_store(self):
|
|
|
|
try:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.save_config()
|
2013-01-05 00:03:36 +01:00
|
|
|
except Exception:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def prefs_del(self, key):
|
|
|
|
if not key:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
key_path = key.split('#', 2)
|
|
|
|
if len(key_path) != 3:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
if key_path[2] == '*':
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.del_per(key_path[0], key_path[1])
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.del_per(key_path[0], key_path[1], key_path[2])
|
2018-02-02 17:56:55 +01:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def prefs_put(self, key):
|
|
|
|
if not key:
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
key_path = key.split('#', 2)
|
|
|
|
if len(key_path) < 3:
|
|
|
|
subname, value = key.split('=', 1)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set(subname, value)
|
2018-02-02 17:56:55 +01:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
subname, value = key_path[2].split('=', 1)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per(key_path[0], key_path[1], subname, value)
|
2018-02-02 17:56:55 +01:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def add_contact(self, jid, account):
|
|
|
|
if account:
|
2017-08-13 13:18:56 +02:00
|
|
|
if account in app.connections and \
|
|
|
|
app.connections[account].connected > 1:
|
2010-02-08 15:08:40 +01:00
|
|
|
# if given account is active, use it
|
2018-02-02 17:56:55 +01:00
|
|
|
AddNewContactWindow(account=account, jid=jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# wrong account
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# if account is not given, show account combobox
|
2018-02-02 17:56:55 +01:00
|
|
|
AddNewContactWindow(account=None, jid=jid)
|
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def remove_contact(self, jid, account):
|
|
|
|
jid = self._get_real_jid(jid, account)
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.contacts.get_accounts()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# if there is only one account in roster, take it as default
|
|
|
|
if account:
|
|
|
|
accounts = [account]
|
|
|
|
contact_exists = False
|
2018-09-18 08:37:18 +02:00
|
|
|
for account_ in accounts:
|
|
|
|
contacts = app.contacts.get_contacts(account_, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if contacts:
|
2018-09-18 08:37:18 +02:00
|
|
|
app.connections[account_].get_module('Presence').unsubscribe(jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
for contact in contacts:
|
2018-09-18 08:37:18 +02:00
|
|
|
app.interface.roster.remove_contact(contact, account_)
|
|
|
|
app.contacts.remove_jid(account_, jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
contact_exists = True
|
2018-02-02 17:56:55 +01:00
|
|
|
return contact_exists
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _is_first(self):
|
|
|
|
if self.first_show:
|
|
|
|
self.first_show = False
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2018-02-02 17:56:55 +01:00
|
|
|
def _get_real_jid(self, jid, account=None):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Get the real jid from the given one: removes xmpp: or get jid from nick if
|
|
|
|
account is specified, search only in this account
|
|
|
|
"""
|
|
|
|
if account:
|
|
|
|
accounts = [account]
|
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.connections.keys()
|
2010-02-08 15:08:40 +01:00
|
|
|
if jid.startswith('xmpp:'):
|
2018-02-02 17:56:55 +01:00
|
|
|
return jid[5:] # len('xmpp:') = 5
|
|
|
|
nick_in_roster = None # Is jid a nick ?
|
2018-09-18 08:37:18 +02:00
|
|
|
for account_ in accounts:
|
2010-02-08 15:08:40 +01:00
|
|
|
# Does jid exists in roster of one account ?
|
2018-09-18 08:37:18 +02:00
|
|
|
if app.contacts.get_contacts(account_, jid):
|
2010-02-08 15:08:40 +01:00
|
|
|
return jid
|
|
|
|
if not nick_in_roster:
|
|
|
|
# look in all contact if one has jid as nick
|
2018-09-18 08:37:18 +02:00
|
|
|
for jid_ in app.contacts.get_jid_list(account_):
|
|
|
|
c = app.contacts.get_contacts(account_, jid_)
|
2010-02-08 15:08:40 +01:00
|
|
|
if c[0].name == jid:
|
|
|
|
nick_in_roster = jid_
|
|
|
|
break
|
|
|
|
if nick_in_roster:
|
|
|
|
# We have not found jid in roster, but we found is as a nick
|
|
|
|
return nick_in_roster
|
|
|
|
# We have not found it as jid nor as nick, probably a not in roster jid
|
|
|
|
return jid
|
|
|
|
|
|
|
|
def _contacts_as_dbus_structure(self, contacts):
|
|
|
|
"""
|
|
|
|
Get info from list of Contact objects and create dbus dict
|
|
|
|
"""
|
|
|
|
if not contacts:
|
|
|
|
return None
|
2018-02-02 17:56:55 +01:00
|
|
|
prim_contact = None # primary contact
|
2010-02-08 15:08:40 +01:00
|
|
|
for contact in contacts:
|
|
|
|
if prim_contact is None or contact.priority > prim_contact.priority:
|
|
|
|
prim_contact = contact
|
2018-02-02 17:56:55 +01:00
|
|
|
contact_dict = {}
|
2018-08-17 21:08:47 +02:00
|
|
|
name = prim_contact.name if prim_contact.name is not None else ''
|
|
|
|
contact_dict['name'] = GLib.Variant('s', name)
|
2018-02-02 17:56:55 +01:00
|
|
|
contact_dict['show'] = GLib.Variant('s', prim_contact.show)
|
|
|
|
contact_dict['jid'] = GLib.Variant('s', prim_contact.jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if prim_contact.keyID:
|
|
|
|
keyID = None
|
|
|
|
if len(prim_contact.keyID) == 8:
|
|
|
|
keyID = prim_contact.keyID
|
|
|
|
elif len(prim_contact.keyID) == 16:
|
|
|
|
keyID = prim_contact.keyID[8:]
|
|
|
|
if keyID:
|
2018-02-02 17:56:55 +01:00
|
|
|
contact_dict['openpgp'] = GLib.Variant('s', keyID)
|
|
|
|
resources = GLib.VariantBuilder(GLib.VariantType('a(sis)'))
|
2010-02-08 15:08:40 +01:00
|
|
|
for contact in contacts:
|
2018-02-02 17:56:55 +01:00
|
|
|
resource_props = (contact.resource, int(contact.priority),
|
|
|
|
contact.status)
|
2018-08-17 21:08:47 +02:00
|
|
|
resources.add_value(GLib.Variant('(sis)', resource_props))
|
2018-02-02 17:56:55 +01:00
|
|
|
contact_dict['resources'] = resources.end()
|
2018-08-17 21:08:47 +02:00
|
|
|
|
|
|
|
groups = GLib.VariantBuilder(GLib.VariantType('as'))
|
|
|
|
for group in prim_contact.groups:
|
|
|
|
groups.add_value(GLib.Variant('s', group))
|
|
|
|
contact_dict['groups'] = groups.end()
|
2010-02-08 15:08:40 +01:00
|
|
|
return contact_dict
|
|
|
|
|
|
|
|
def get_unread_msgs_number(self):
|
2018-12-15 23:59:27 +01:00
|
|
|
unread = app.events.get_nb_events()
|
|
|
|
for event in app.events.get_all_events(['printed_gc_msg']):
|
|
|
|
if not app.config.notify_for_muc(event.jid):
|
|
|
|
unread -= 1
|
|
|
|
return str(unread)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def start_chat(self, account):
|
|
|
|
if not account:
|
|
|
|
# error is shown in gajim-remote check_arguments(..)
|
2018-02-02 17:56:55 +01:00
|
|
|
return False
|
2017-11-30 22:55:06 +01:00
|
|
|
app.app.activate_action('start-chat')
|
2018-02-02 17:56:55 +01:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def send_xml(self, xml, account):
|
|
|
|
if account:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.connections[account].send_stanza(str(xml))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
for acc in app.contacts.get_accounts():
|
|
|
|
app.connections[acc].send_stanza(str(xml))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
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:
|
2018-05-20 01:03:22 +02:00
|
|
|
sha = app.interface.save_avatar(picture, publish=True)
|
2017-09-16 11:49:31 +02:00
|
|
|
if sha is None:
|
|
|
|
return
|
|
|
|
app.config.set_per('accounts', self.name, 'avatar_sha', sha)
|
|
|
|
data = app.interface.get_avatar(sha, publish=True)
|
2013-01-03 14:03:40 +01:00
|
|
|
avatar = base64.b64encode(data).decode('utf-8')
|
2010-02-08 15:08:40 +01:00
|
|
|
avatar_mime_type = mimetypes.guess_type(picture)[0]
|
2017-09-16 11:49:31 +02:00
|
|
|
vcard = {}
|
2010-02-08 15:08:40 +01:00
|
|
|
vcard['PHOTO'] = {'BINVAL': avatar}
|
|
|
|
if avatar_mime_type:
|
|
|
|
vcard['PHOTO']['TYPE'] = avatar_mime_type
|
|
|
|
if account:
|
2018-06-30 19:23:10 +02:00
|
|
|
app.connections[account].get_module('VCardTemp').send_vcard(
|
|
|
|
vcard, sha)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
for acc in app.connections:
|
2018-06-30 19:23:10 +02:00
|
|
|
app.connections[acc].get_module('VCardTemp').send_vcard(
|
|
|
|
vcard, sha)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def join_room(self, room_jid, nick, password, account):
|
|
|
|
if not account:
|
|
|
|
# get the first connected account
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.connections.keys()
|
2010-02-08 15:08:40 +01:00
|
|
|
for acct in accounts:
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.account_is_connected(acct):
|
|
|
|
if not app.connections[acct].is_zeroconf:
|
2011-03-29 15:18:50 +02:00
|
|
|
account = acct
|
|
|
|
break
|
2010-02-08 15:08:40 +01:00
|
|
|
if not account:
|
|
|
|
return
|
2011-03-29 15:18:50 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.connections[account].is_zeroconf:
|
2011-03-29 15:18:50 +02:00
|
|
|
# zeroconf not support groupchats
|
|
|
|
return
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if not nick:
|
2017-11-25 15:33:54 +01:00
|
|
|
app.interface.join_gc_minimal(account, room_jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.join_gc_room(account, room_jid, nick, password)
|
2018-02-02 17:56:55 +01:00
|
|
|
|
|
|
|
def Introspect(self):
|
|
|
|
return self.__doc__
|