From 58d7096acaac59f0308cf2503bebecedfcb64763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Apitzsch?= Date: Sat, 5 Jan 2019 16:46:36 +0100 Subject: [PATCH] Remove obsolete dbus plugin --- plugins/dbus_plugin/__init__.py | 1 - plugins/dbus_plugin/dbus_plugin.png | Bin 2146 -> 0 bytes plugins/dbus_plugin/manifest.ini | 10 - plugins/dbus_plugin/plugin.py | 718 ---------------------------- 4 files changed, 729 deletions(-) delete mode 100644 plugins/dbus_plugin/__init__.py delete mode 100644 plugins/dbus_plugin/dbus_plugin.png delete mode 100644 plugins/dbus_plugin/manifest.ini delete mode 100644 plugins/dbus_plugin/plugin.py diff --git a/plugins/dbus_plugin/__init__.py b/plugins/dbus_plugin/__init__.py deleted file mode 100644 index e35d8d4db..000000000 --- a/plugins/dbus_plugin/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .plugin import DBusPlugin diff --git a/plugins/dbus_plugin/dbus_plugin.png b/plugins/dbus_plugin/dbus_plugin.png deleted file mode 100644 index 5844d139c554a3258a8f282b94b63b5dcfcaaf61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2146 zcmV-o2%YzdP)M?wHNCO;}Nl{j>qHS zaA;YU<2a+yNKq7B*L7W&Bq<02(=;v1s@LnaT8)UNswPNB)lKa?`WVNt@B5}{+O|C! zjZ&$UVHk#C=(;`#dB^qJy#WB!OSv;ebu=8TtgJK|jcT=uh=~%6qG;;9V=;{5*z-Kc zak|~E=Xs1V!!U})VlI~>CTyF-J6q=8*7n!;odahyd6(ghh02e={)`y=&1UoZ_3P<$ z`Zy!vI7UPw@_oPG@0+ISI1Xbhm&=vQWmV0IlGL`mm505*ukEk2txkUw#av(r2mpY9 zL;wiH>GGMvYu|lw{r;!AuFuTOBmol>7|wYR1nqXa*Xwc4RaG?%V{UGai796k-QF_q zZ0+3M>~x&bXdEFRA|QewAOHX*C_mn857r?zUR3 zQmJ(Q{CQc)Sl)PT&w2gM+9z#mqtg$gm=hoX0tgI=04H`NKnWBfA`l@0LwI|o{ld%F zhO4Vl6v?s-03zr7;NW0uYwOabOPET(-Q4-}KklyXIsH*MVICp^GJHgI1Uf{S;1LlK zpNvOE|JL{S6)F^Zzi&CLrJF7!hD`RngB+t$(SkwjskswtAV z)anvH)Q^W|5eWiYsOlGI@;4flMn$U`nYV6lzWV#6UEAC5`&3-->Dp|usHO#mul(|__jhe1BqU7i1c*4ja`WkLeqljLJxa%C z=F14ci9X)!eD!Rh)oRVn%?W}anxNqQD5i@&Y9#99>z~l-ZKHZ4Q=O=F5v`!Y~YiKv5KNJRYY~sZMXiIT6A2 zda+T}@x-ZheXjJ@?adntm5d|`j0p@FV#oEDTHSHXC2?XC5h*F5QPH-|!AiRqa+D-# zI2j?33ZgiS`8bNBn9?bsHwdb_ zLIh#V_v~S_ZLJ^l0l@acR@cqv^Oj{53I)+HjBdAkdafj=1TWzC+Lr5wMn;~n79g2u zic~W)_jas=5kLe8$iR={-`(11RJ7$S^Y%t(-x+z~m>~kdIO2D<%&%RpJb3Vch?u5n z!{IQSVxOyO0MH%y+ucFJ?ZhSmu!g~{jZW7cC2}M{L<9talA8WYbLXdTe)Pr%4_aL} zh+=^;L_|b}aBH(8rIjEEf*=qTMM1=P99}wISl%)b;NAOsS7wU?f86T2%UkBHjm~DL zA9J#X;WT3tmJ5u%c)s?@LyL$6hCuLmroq~tGm0pcO1Z8pBBHMAmSsJ+Q2Fh9tAP0C zhYy-N)~@aCJKi|rh#)fdrKg|b9NxXZ8*z?@7GIey4*Y2SppQxVB483(0zyE*fj@5d zhPtlXw#@(_pU>O2-6(5DRwe>3j6QmBuwxBlPKhTXPVY2#8N!z@oJui907R5aOO1;5 z{@NZ99iFZThy+Lz(<$QI3nNX_!Z2ivF-_Av&r@ZgQPBVa6bpDRsuALil&7yx2U zAFLl-oXP*}ThIOahc|!q{jXGYCGiy!AP^?ADHg%mnqDvE9LLG!av}gEW;u?tST8X| zI^0pBWCDi(2%>=Bcy|8M=|aN(3p4pGbMR;xOy2_lDCW{Xdg&^}W6QE;XJ=U)$3$cp zhGkjxqFTJj?m_>;CpL_rjr178*eo-iIKzT+GiqLGnbx;p#XcfNS8 zqBfh&YPFh9rze$A*Y)-F^{m9^E80PSl$5l`HhNf){k>?~tUoZcE_S$19b#dEdy*Y;sT+k{V#@DTCS zUHjgy4FoY!Ru)eevWxZ7GxOzhPZ@@i8V7-GTdmcm@B5M@&Ckyl3WZ7FqbL#tfpfmG zu@Oa4<@DV5e)0Cc<00a)JS3u|@}4QFmu3pjpRJy)8K?4@z#sJ;$23jXbwyEBRkd6$ zXR}#FQ4$gyzp;3px4gW3?b@|_`@^5S@u4~Jrx=W3A)CH(rtoZ|yjU-nb26jYwr$(C zd%YfGOjXrlv8e01EXzrSJvkmBan4(_mfSCqNr(FKA%@rRg$Ft zx??zwl*~EjQ512`8DpX-CfbkPbC0$TCwrKa!pH8gNB=w77MyI7p19^;`EbJW|3m-u YPqZw~T;LJGzyJUM07*qoM6N<$f-=k=r2qf` diff --git a/plugins/dbus_plugin/manifest.ini b/plugins/dbus_plugin/manifest.ini deleted file mode 100644 index 974540211..000000000 --- a/plugins/dbus_plugin/manifest.ini +++ /dev/null @@ -1,10 +0,0 @@ -[info] -name: D-Bus Support -short_name: dbus -version: 0.1.1 -description: D-Bus support. Based on remote_control module from - Gajim core but uses new events handling system. -authors = Mateusz Biliński -homepage = http://blog.bilinski.it - - diff --git a/plugins/dbus_plugin/plugin.py b/plugins/dbus_plugin/plugin.py deleted file mode 100644 index 90fd5090f..000000000 --- a/plugins/dbus_plugin/plugin.py +++ /dev/null @@ -1,718 +0,0 @@ -# -*- coding: utf-8 -*- - -## Copyright (C) 2005-2006 Yann Leboulanger -## Copyright (C) 2005-2006 Nikos Kouremenos -## Copyright (C) 2005-2006 Dimitur Kirov -## Copyright (C) 2005-2006 Andrew Sayman -## Copyright (C) 2007 Lukas Petrovicky -## Copyright (C) 2007 Julien Pivotto -## Copyright (C) 2007 Travis Shirk -## Copyright (C) 2008 Mateusz Biliński -## -## 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 . -## -''' -D-BUS Support plugin. - -Based on gajim/remote_control.py - -:author: Mateusz Biliński -:since: 8th August 2008 -:copyright: Copyright (2008) Mateusz Biliński -:license: GPL -''' -import os -# import new # depricated in python3; use types instead -import types - -import gobject - - -from gajim.common import dbus_support -if dbus_support.supported: - import dbus - if dbus_support: - INTERFACE = 'org.gajim.dbusplugin.RemoteInterface' - OBJ_PATH = '/org/gajim/dbusplugin/RemoteObject' - SERVICE = 'org.gajim.dbusplugin' - - import dbus.service - # type mapping - - # in most cases it is a utf-8 string - DBUS_STRING = dbus.String - - # general type (for use in dicts, where all values should have the same type) - DBUS_BOOLEAN = dbus.Boolean - DBUS_DOUBLE = dbus.Double - DBUS_INT32 = dbus.Int32 - # dictionary with string key and binary value - DBUS_DICT_SV = lambda : dbus.Dictionary({}, signature="sv") - # dictionary with string key and value - DBUS_DICT_SS = lambda : dbus.Dictionary({}, signature="ss") - # empty type (there is no equivalent of None on D-Bus, but historically gajim - # used 0 instead) - DBUS_NONE = lambda : dbus.Int32(0) - - def get_dbus_struct(obj): - ''' recursively go through all the items and replace - them with their casted dbus equivalents - ''' - if obj is None: - return DBUS_NONE() - if isinstance(obj, (unicode, str)): - return DBUS_STRING(obj) - if isinstance(obj, int): - return DBUS_INT32(obj) - if isinstance(obj, float): - return DBUS_DOUBLE(obj) - if isinstance(obj, bool): - return DBUS_BOOLEAN(obj) - if isinstance(obj, (list, tuple)): - result = dbus.Array([get_dbus_struct(i) for i in obj], - signature='v') - if result == []: - return DBUS_NONE() - return result - if isinstance(obj, dict): - result = DBUS_DICT_SV() - for key, value in obj.items(): - result[DBUS_STRING(key)] = get_dbus_struct(value) - if result == {}: - return DBUS_NONE() - return result - # unknown type - return DBUS_NONE() - - class SignalObject(dbus.service.Object): - ''' Local object definition for /org/gajim/dbus/RemoteObject. - (This docstring is not be visible, - because the clients can access only the remote object.)''' - - def __init__(self, bus_name): - self.first_show = True - self.vcard_account = None - - # register our dbus API - dbus.service.Object.__init__(self, bus_name, OBJ_PATH) - - @dbus.service.signal(INTERFACE, signature='av') - def Roster(self, account_and_data): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def AccountPresence(self, status_and_account): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def ContactPresence(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def ContactAbsence(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def ContactStatus(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def NewMessage(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def Subscribe(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def Subscribed(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def Unsubscribed(self, account_and_jid): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def NewAccount(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def VcardInfo(self, account_and_vcard): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def LastStatusTime(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def OsInfo(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def GCPresence(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def GCMessage(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def RosterInfo(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def NewGmail(self, account_and_array): - pass - - @dbus.service.signal(INTERFACE, signature='av') - def EntityTime(self, account_and_array): - pass - - def raise_signal(self, signal, arg): - '''raise a signal, with a single argument of unspecified type - Instead of obj.raise_signal("Foo", bar), use obj.Foo(bar).''' - getattr(self, signal)(arg) - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='s') - def get_status(self, account): - '''Returns status (show to be exact) which is the global one - unless account is given''' - if not account: - # If user did not ask for account, returns the global status - return DBUS_STRING(helpers.get_global_show()) - # return show for the given account - index = gajim.connections[account].connected - return DBUS_STRING(gajim.SHOW_LIST[index]) - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='s') - def get_status_message(self, account): - '''Returns status which is the global one - unless account is given''' - if not account: - # If user did not ask for account, returns the global status - return DBUS_STRING(str(helpers.get_global_status())) - # return show for the given account - status = gajim.connections[account].status - return DBUS_STRING(status) - - def _get_account_and_contact(self, account, jid): - '''get the account (if not given) and contact instance from jid''' - connected_account = None - contact = None - accounts = gajim.contacts.get_accounts() - # 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: - if gajim.connections[account].connected > 1: # account is connected - connected_account = account - contact = gajim.contacts.get_contact_with_highest_priority(account, - jid) - else: - for account in accounts: - contact = gajim.contacts.get_contact_with_highest_priority(account, - jid) - if contact and gajim.connections[account].connected > 1: - # account is connected - connected_account = account - 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 - accounts = gajim.contacts.get_accounts() - # 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: - if gajim.connections[account].connected > 1 and \ - room_jid in gajim.gc_connected[account] and \ - gajim.gc_connected[account][room_jid]: - # account and groupchat are connected - connected_account = account - else: - for account in accounts: - if gajim.connections[account].connected > 1 and \ - room_jid in gajim.gc_connected[account] and \ - gajim.gc_connected[account][room_jid]: - # account and groupchat are connected - connected_account = account - break - return connected_account - - @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') - 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) - connected_account, contact = self._get_account_and_contact(account, jid) - - if connected_account: - if file_path[:7] == 'file://': - file_path=file_path[7:] - if os.path.isfile(file_path): # is it file? - gajim.interface.instances['file_transfers'].send_file( - connected_account, contact, file_path) - return DBUS_BOOLEAN(True) - return DBUS_BOOLEAN(False) - - def _send_message(self, jid, message, keyID, account, type = 'chat', - subject = None): - '''can be called from send_chat_message (default when send_message) - or send_single_message''' - if not jid or not message: - return DBUS_BOOLEAN(False) - if not keyID: - keyID = '' - - connected_account, contact = self._get_account_and_contact(account, jid) - if connected_account: - connection = gajim.connections[connected_account] - connection.send_message(jid, message, keyID, type, subject) - return DBUS_BOOLEAN(True) - return DBUS_BOOLEAN(False) - - @dbus.service.method(INTERFACE, in_signature='ssss', out_signature='b') - 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) - - @dbus.service.method(INTERFACE, in_signature='sssss', out_signature='b') - 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) - return self._send_message(jid, message, keyID, account, type, subject) - - @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') - 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: - return DBUS_BOOLEAN(False) - connected_account = self._get_account_for_groupchat(account, room_jid) - if connected_account: - connection = gajim.connections[connected_account] - connection.send_gc_message(room_jid, message) - return DBUS_BOOLEAN(True) - return DBUS_BOOLEAN(False) - - @dbus.service.method(INTERFACE, in_signature='ss', out_signature='b') - def open_chat(self, jid, account): - '''Shows the tabbed window for new message to 'jid', using account - (optional) 'account' ''' - if not jid: - raise MissingArgument - return DBUS_BOOLEAN(False) - jid = self._get_real_jid(jid, account) - try: - jid = helpers.parse_jid(jid) - except Exception: - # Jid is not conform, ignore it - return DBUS_BOOLEAN(False) - - if account: - accounts = [account] - else: - accounts = gajim.connections.keys() - if len(accounts) == 1: - account = accounts[0] - connected_account = None - first_connected_acct = None - for acct in accounts: - if gajim.connections[acct].connected > 1: # account is online - contact = gajim.contacts.get_first_contact_from_jid(acct, jid) - if gajim.interface.msg_win_mgr.has_window(jid, acct): - connected_account = acct - break - # jid is in roster - elif contact: - 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 - - # if jid is not a conntact, open-chat with first connected account - if connected_account is None and first_connected_acct: - connected_account = first_connected_acct - - if connected_account: - gajim.interface.new_chat_from_jid(connected_account, jid) - # preserve the 'steal focus preservation' - win = gajim.interface.msg_win_mgr.get_window(jid, - connected_account).window - if win.get_property('visible'): - win.window.present() - return DBUS_BOOLEAN(True) - return DBUS_BOOLEAN(False) - - @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') - def change_status(self, status, message, account): - ''' change_status(status, message, account). account is optional - - if not specified status is changed for all accounts. ''' - if status not in ('offline', 'online', 'chat', - 'away', 'xa', 'dnd', 'invisible'): - return DBUS_BOOLEAN(False) - if account: - gobject.idle_add(gajim.interface.roster.send_status, account, - status, message) - else: - # account not specified, so change the status of all accounts - for acc in gajim.contacts.get_accounts(): - if not gajim.config.get_per('accounts', acc, - 'sync_with_global_status'): - continue - gobject.idle_add(gajim.interface.roster.send_status, acc, - status, message) - return DBUS_BOOLEAN(False) - - @dbus.service.method(INTERFACE, in_signature='', out_signature='') - def show_next_pending_event(self): - '''Show the window(s) with next pending event in tabbed/group chats.''' - if gajim.events.get_nb_events(): - gajim.interface.systray.handle_first_event() - - @dbus.service.method(INTERFACE, in_signature='', out_signature='as') - def list_accounts(self): - '''list register accounts''' - result = gajim.contacts.get_accounts() - result_array = dbus.Array([], signature='s') - if result and len(result) > 0: - for account in result: - result_array.append(DBUS_STRING(account)) - return result_array - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='a{ss}') - def account_info(self, account): - '''show info on account: resource, jid, nick, prio, message''' - result = DBUS_DICT_SS() - if account in gajim.connections: - # account is valid - con = gajim.connections[account] - index = con.connected - result['status'] = DBUS_STRING(gajim.SHOW_LIST[index]) - result['name'] = DBUS_STRING(con.name) - result['jid'] = DBUS_STRING(gajim.get_jid_from_account(con.name)) - result['message'] = DBUS_STRING(con.status) - result['priority'] = DBUS_STRING(unicode(con.priority)) - result['resource'] = DBUS_STRING(unicode(gajim.config.get_per( - 'accounts', con.name, 'resource'))) - return result - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='aa{sv}') - def list_contacts(self, account): - '''list all contacts in the roster. If the first argument is specified, - then return the contacts for the specified account''' - result = dbus.Array([], signature='aa{sv}') - accounts = gajim.contacts.get_accounts() - if len(accounts) == 0: - return result - if account: - accounts_to_search = [account] - else: - accounts_to_search = accounts - for acct in accounts_to_search: - if acct in accounts: - for jid in gajim.contacts.get_jid_list(acct): - item = self._contacts_as_dbus_structure( - gajim.contacts.get_contacts(acct, jid)) - if item: - result.append(item) - return result - - @dbus.service.method(INTERFACE, in_signature='', out_signature='') - def toggle_roster_appearance(self): - ''' shows/hides the roster window ''' - win = gajim.interface.roster.window - if win.get_property('visible'): - gobject.idle_add(win.hide) - else: - win.present() - # preserve the 'steal focus preservation' - if self._is_first(): - win.window.present() - else: - win.window.present_with_time(long(time())) - - @dbus.service.method(INTERFACE, in_signature='', out_signature='') - def toggle_ipython(self): - ''' shows/hides the ipython window ''' - win = gajim.ipython_window - if win: - if win.window.is_visible(): - gobject.idle_add(win.hide) - else: - win.show_all() - win.present() - else: - gajim.interface.create_ipython_window() - - @dbus.service.method(INTERFACE, in_signature='', out_signature='a{ss}') - def prefs_list(self): - prefs_dict = DBUS_DICT_SS() - 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 - prefs_dict[DBUS_STRING(key)] = DBUS_STRING(value) - gajim.config.foreach(get_prefs) - return prefs_dict - - @dbus.service.method(INTERFACE, in_signature='', out_signature='b') - def prefs_store(self): - try: - gajim.interface.save_config() - except Exception: - return DBUS_BOOLEAN(False) - return DBUS_BOOLEAN(True) - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='b') - def prefs_del(self, key): - if not key: - return DBUS_BOOLEAN(False) - key_path = key.split('#', 2) - if len(key_path) != 3: - return DBUS_BOOLEAN(False) - if key_path[2] == '*': - gajim.config.del_per(key_path[0], key_path[1]) - else: - gajim.config.del_per(key_path[0], key_path[1], key_path[2]) - return DBUS_BOOLEAN(True) - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='b') - def prefs_put(self, key): - if not key: - return DBUS_BOOLEAN(False) - key_path = key.split('#', 2) - if len(key_path) < 3: - subname, value = key.split('=', 1) - gajim.config.set(subname, value) - return DBUS_BOOLEAN(True) - subname, value = key_path[2].split('=', 1) - gajim.config.set_per(key_path[0], key_path[1], subname, value) - return DBUS_BOOLEAN(True) - - @dbus.service.method(INTERFACE, in_signature='ss', out_signature='b') - def add_contact(self, jid, account): - if account: - if account in gajim.connections and \ - gajim.connections[account].connected > 1: - # if given account is active, use it - AddNewContactWindow(account = account, jid = jid) - else: - # wrong account - return DBUS_BOOLEAN(False) - else: - # if account is not given, show account combobox - AddNewContactWindow(account = None, jid = jid) - return DBUS_BOOLEAN(True) - - @dbus.service.method(INTERFACE, in_signature='ss', out_signature='b') - def remove_contact(self, jid, account): - jid = self._get_real_jid(jid, account) - accounts = gajim.contacts.get_accounts() - - # if there is only one account in roster, take it as default - if account: - accounts = [account] - contact_exists = False - for account in accounts: - contacts = gajim.contacts.get_contacts(account, jid) - if contacts: - gajim.connections[account].unsubscribe(jid) - for contact in contacts: - gajim.interface.roster.remove_contact(contact, account) - gajim.contacts.remove_jid(account, jid) - contact_exists = True - return DBUS_BOOLEAN(contact_exists) - - def _is_first(self): - if self.first_show: - self.first_show = False - return True - return False - - def _get_real_jid(self, jid, account = None): - '''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: - accounts = gajim.connections.keys() - if jid.startswith('xmpp:'): - return jid[5:] # len('xmpp:') = 5 - nick_in_roster = None # Is jid a nick ? - for account in accounts: - # Does jid exists in roster of one account ? - if gajim.contacts.get_contacts(account, jid): - return jid - if not nick_in_roster: - # look in all contact if one has jid as nick - for jid_ in gajim.contacts.get_jid_list(account): - c = gajim.contacts.get_contacts(account, jid_) - 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 - prim_contact = None # primary contact - for contact in contacts: - if prim_contact is None or contact.priority > prim_contact.priority: - prim_contact = contact - contact_dict = DBUS_DICT_SV() - contact_dict['name'] = DBUS_STRING(prim_contact.name) - contact_dict['show'] = DBUS_STRING(prim_contact.show) - contact_dict['jid'] = DBUS_STRING(prim_contact.jid) - 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: - contact_dict['openPGP'] = keyID - contact_dict['resources'] = dbus.Array([], signature='(sis)') - for contact in contacts: - resource_props = dbus.Struct((DBUS_STRING(contact.resource), - dbus.Int32(contact.priority), DBUS_STRING(contact.status))) - contact_dict['resources'].append(resource_props) - contact_dict['groups'] = dbus.Array([], signature='(s)') - for group in prim_contact.groups: - contact_dict['groups'].append((DBUS_STRING(group),)) - return contact_dict - - @dbus.service.method(INTERFACE, in_signature='', out_signature='s') - def get_unread_msgs_number(self): - return DBUS_STRING(str(gajim.events.get_nb_events())) - - @dbus.service.method(INTERFACE, in_signature='s', out_signature='b') - def start_chat(self, account): - if not account: - # error is shown in gajim-remote check_arguments(..) - return DBUS_BOOLEAN(False) - app.app.activate_action('start-chat') - return DBUS_BOOLEAN(True) - - @dbus.service.method(INTERFACE, in_signature='ss', out_signature='') - def send_xml(self, xml, account): - if account: - gajim.connections[account].send_stanza(xml) - else: - for acc in gajim.contacts.get_accounts(): - gajim.connections[acc].send_stanza(xml) - - @dbus.service.method(INTERFACE, in_signature='ssss', out_signature='') - def join_room(self, room_jid, nick, password, account): - if not account: - # get the first connected account - accounts = gajim.connections.keys() - for acct in accounts: - if gajim.account_is_connected(acct): - account = acct - break - if not account: - return - if not nick: - gajim.interface.join_gc_minimal(account, room_jid) - else: - gajim.interface.join_gc_room(account, room_jid, nick, password) - -from gajim.common import app -from gajim.common import helpers -from time import time -from gajim.dialogs import AddNewContactWindow, JoinGroupchatWindow - -from gajim.plugins import GajimPlugin -from gajim.plugins.helpers import log_calls, log -from gajim.common import ged - -class DBusPlugin(GajimPlugin): - - @log_calls('DBusPlugin') - def init(self): - self.description = _('D-Bus support.' - ' Based on remote_control module from' - '\nGajim core but uses new events handling system.') - self.config_dialog = None - #self.gui_extension_points = {} - #self.config_default_values = {} - - self.events_names = ['Roster', 'AccountPresence', 'ContactPresence', - 'ContactAbsence', 'ContactStatus', 'NewMessage', - 'Subscribe', 'Subscribed', 'Unsubscribed', - 'NewAccount', 'VcardInfo', 'LastStatusTime', - 'OsInfo', 'GCPresence', 'GCMessage', 'RosterInfo', - 'NewGmail', 'EntityTime'] - - self.signal_object = None - - self.events_handlers = {} - self._set_handling_methods() - - @log_calls('DBusPlugin') - def activate(self): - session_bus = dbus_support.session_bus.SessionBus() - - bus_name = dbus.service.BusName(SERVICE, bus=session_bus) - self.signal_object = SignalObject(bus_name) - - @log_calls('DBusPlugin') - def deactivate(self): - self.signal_object.remove_from_connection() - self.signal_object = None - - @log_calls('DBusPlugin') - def _set_handling_methods(self): - for event_name in self.events_names: - setattr(self, event_name, - types.MethodType( - self._generate_handling_method(event_name), - self)) - self.events_handlers[event_name] = (ged.POSTCORE, - getattr(self, event_name)) - - def _generate_handling_method(self, event_name): - def handler(self, arg): - #print "Handler of event %s called"%(event_name) - if self.signal_object: - getattr(self.signal_object, event_name)(get_dbus_struct(arg)) - - return handler