17
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
21
from AvatarHistory import getLastCachedAvatar
25
import dbus, dbus.service
26
27
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
29
if getattr(dbus, 'version', (0,0,0)) >= (0,80,0):
30
import _dbus_bindings as dbus_bindings
31
from dbus.mainloop.glib import DBusGMainLoop
32
DBusGMainLoop(set_as_default=True)
29
35
import dbus.mainloop.glib
36
import dbus.dbus_bindings as dbus_bindings
30
38
except Exception, e:
33
41
BUS_NAME = 'org.emesene.dbus'
34
42
OBJECT_PATH = '/org/emesene/dbus'
44
PLUGIN_DESCRIPTION = _('With this plugin you can interact via D-Bus with emesene')
45
PLUGIN_AUTHORS = {'Roger Duran' : 'RogerDuran at gmail dot com'}
46
PLUGIN_WEBSITE = 'http://www.rogerpc.com.ar'
47
PLUGIN_DISPLAY_NAME = 'D-Bus'
36
50
class MainClass(Plugin.Plugin):
37
51
'''Main plugin class'''
38
description = _('With this plugin you can interact via Dbus with emesene')
39
authors = {'Roger Duran' : 'RogerDuran at gmail dot com'}
40
website = 'http://www.rogerpc.com.ar'
41
displayName = _('Dbus')
52
description = PLUGIN_DESCRIPTION
53
authors = PLUGIN_AUTHORS
54
website = PLUGIN_WEBSITE
55
displayName = PLUGIN_DISPLAY_NAME
44
58
def __init__(self, controller, msn):
47
61
Plugin.Plugin.__init__(self, controller, msn)
48
62
self.theme = controller.theme
50
self.description = _('With this plugin you can interact via Dbus with emesene')
51
self.authors = {'Roger Duran' : 'RogerDuran at gmail dot com'}
52
self.website = 'http://www.rogerpc.com.ar'
53
self.displayName = _('Dbus')
64
self.description = PLUGIN_DESCRIPTION
65
self.authors = PLUGIN_AUTHORS
66
self.website = PLUGIN_WEBSITE
67
self.displayName = PLUGIN_DISPLAY_NAME
68
self.name = PLUGIN_NAME
57
71
self.user_connect_id = None
58
72
self.user_offline_id = None
59
73
self.self_nick_changed_id = None
60
74
self.psm_changed_id = None
75
self.status_changed_id = None
76
self.new_message_id = None
77
self.message_read_id = None
79
self.unread_message_count = None
62
81
self.dbus_object = None
118
147
self.dbus_object = None
149
''' The tests on each function are there in case the internet connection dropped,
150
and dbus is restarted. When this happens, dbus_object can fail to
151
instantiate, which can cause headaches.
121
154
def user_connect(self, msnp, user, oldStatus):
122
if(oldStatus=='FLN'):
155
if self.dbus_object == None:
158
if oldStatus == 'FLN':
123
159
self.dbus_object.user_connect(user)
161
def status_changed(self, msnp, status):
162
if self.dbus_object == None:
165
newstatus = self.msn.status
166
self.dbus_object.status_changed('', newstatus)
125
168
def user_offline(self, msnp, user):
169
if self.dbus_object == None:
126
172
self.dbus_object.user_offline(user)
128
174
def self_nick_changed(self, msnp, old, nick):
175
if self.dbus_object == None:
129
178
self.dbus_object.self_changed_nick(nick)
131
180
def psm_changed(self, msnp, email, pm):
181
if self.dbus_object == None:
132
184
self.dbus_object.psm_changed(email, pm)
186
def new_message(self, msn, switchboard, signal, args, stamp=None):
187
if self.dbus_object == None:
190
count = self.unread_message_count
192
self.unread_message_count = count
193
self.dbus_object.set_message_count(count)
194
self.dbus_object.unread_messages(count)
196
def message_read(self, arg1):
197
if self.dbus_object == None:
200
self.unread_message_count = 0
201
self.dbus_object.set_message_count(0)
202
self.dbus_object.unread_messages(0)
135
205
class EmeseneObject(dbus.service.Object):
136
206
def __init__(self, bus_name, object_path, main):
137
dbus.service.Object.__init__(self, bus_name, object_path)
207
''' Try to create a new service object. This will only fail if emesene already has a signal
208
service running in dbus, where the plugin was brought down due to a loss of connection.
209
If it does fail, it doesn't matter, it will just reconnect with the service again.
212
dbus.service.Object.__init__(self, bus_name, object_path)
213
except Exception, ex:
214
print 'dbus.py: ERROR: %s' % str(ex)
139
217
self.msn = main.msn
140
218
self.controller = main.controller
141
219
self.contact_manager = self.controller.contacts
144
223
@dbus.service.method(BUS_NAME)
224
def get_status(self):
225
return self.msn.status
227
@dbus.service.method(BUS_NAME)
230
mainWindow = self.controller.mainWindow
231
if mainWindow != None:
232
flags = mainWindow.flags()
233
if not (flags & gtk.MAPPED):
234
mainWindow.deiconify()
237
# Also show all open converstations
238
manager = self.controller.conversationManager
240
for win, conv in manager.conversations:
243
# call map again so dialogs will refresh their contents
244
if mainWindow != None:
245
mainWindow.emit('map')
247
@dbus.service.method(BUS_NAME)
145
248
def set_psm(self, text):
146
249
self.contact_manager.set_message(text)
147
250
return 'Psm Changed'