1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
# -*- coding:utf-8 -*-
## src/common/pep.py
##
## Copyright (C) 2007 Piotr Gaczkowski <doomhammerng AT gmail.com>
## Copyright (C) 2007-2008 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
## Jean-Marie Traissard <jim AT lapin.org>
## Jonathan Schleifer <js-gajim AT webkeks.org>
## Stephan Erb <steve-e AT h3c.de>
##
## 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/>.
##
from common import gajim, xmpp
MOODS = {
'afraid': _('Afraid'), 'amazed': _('Amazed'),
'angry': _('Angry'), 'annoyed': _('Annoyed'),
'anxious': _('Anxious'), 'aroused': _('Aroused'),
'ashamed': _('Ashamed'), 'bored': _('Bored'),
'brave': _('Brave'), 'calm': _('Calm'),
'cold': _('Cold'), 'confused': _('Confused'),
'contented': _('Contented'), 'cranky': _('Cranky'),
'curious': _('Curious'), 'depressed': _('Depressed'),
'disappointed': _('Disappointed'), 'disgusted': _('Disgusted'),
'distracted': _('Distracted'), 'embarrassed': _('Embarrassed'),
'excited': _('Excited'), 'flirtatious': _('Flirtatious'),
'frustrated': _('Frustrated'), 'grumpy': _('Grumpy'),
'guilty': _('Guilty'), 'happy': _('Happy'),
'hot': _('Hot'), 'humbled': _('Humbled'),
'humiliated': _('Humiliated'), 'hungry': _('Hungry'),
'hurt': _('Hurt'), 'impressed': _('Impressed'),
'in_awe': _('In Awe'), 'in_love': _('In Love'),
'indignant': _('Indignant'), 'interested': _('Interested'),
'intoxicated': _('Intoxicated'), 'invincible': _('Invincible'),
'jealous': _('Jealous'), 'lonely': _('Lonely'),
'mean': _('Mean'), 'moody': _('Moody'),
'nervous': _('Nervous'), 'neutral': _('Neutral'),
'offended': _('Offended'), 'playful': _('Playful'),
'proud': _('Proud'), 'relieved': _('Relieved'),
'remorseful': _('Remorseful'), 'restless': _('Restless'),
'sad': _('Sad'), 'sarcastic': _('Sarcastic'),
'serious': _('Serious'), 'shocked': _('Shocked'),
'shy': _('Shy'), 'sick': _('Sick'),
'sleepy': _('Sleepy'), 'stressed': _('Stressed'),
'surprised': _('Surprised'), 'thirsty': _('Thirsty'),
'thoughtful': _('Thoughtful'), 'worried': _('Worried')}
# These moods are only available in the Gajim namespace
GAJIM_MOODS = ['thoughtful']
ACTIVITIES = {
'doing_chores': {'category': _('Doing Chores'),
'buying_groceries': _('Buying Groceries'),
'cleaning': _('Cleaning'),
'cooking': _('Cooking'),
'doing_maintenance': _('Doing Maintenance'),
'doing_the_dishes': _('Doing the Dishes'),
'doing_the_laundry': _('Doing the Laundry'),
'gardening': _('Gardening'),
'running_an_errand': _('Running an Errand'),
'walking_the_dog': _('Walking the Dog')},
'drinking': {'category': _('Drinking'),
'having_a_beer': _('Having a Beer'),
'having_coffee': _('Having Coffee'),
'having_tea': _('Having Tea')},
'eating': {'category': _('Eating'),
'having_a_snack': _('Having a Snack'),
'having_breakfast': _('Having Breakfast'),
'having_dinner': _('Having Dinner'),
'having_lunch': _('Having Lunch')},
'exercising': {'category': _('Exercising'),
'cycling': _('Cycling'),
'hiking': _('Hiking'),
'jogging': _('Jogging'),
'playing_sports': _('Playing Sports'),
'running': _('Running'),
'skiing': _('Skiing'),
'swimming': _('Swimming'),
'working_out': _('Working out')},
'grooming': {'category': _('Grooming'),
'at_the_spa': _('At the Spa'),
'brushing_teeth': _('Brushing Teeth'),
'getting_a_haircut': _('Getting a Haircut'),
'shaving': _('Shaving'),
'taking_a_bath': _('Taking a Bath'),
'taking_a_shower': _('Taking a Shower')},
'having_appointment': {'category': _('Having an Appointment')},
'inactive': {'category': _('Inactive'),
'day_off': _('Day Off'),
'hanging_out': _('Hanging out'),
'on_vacation': _('On Vacation'),
'scheduled_holiday': _('Scheduled Holiday'),
'sleeping': _('Sleeping')},
'relaxing': {'category': _('Relaxing'),
'gaming': _('Gaming'),
'going_out': _('Going out'),
'partying': _('Partying'),
'reading': _('Reading'),
'rehearsing': _('Rehearsing'),
'shopping': _('Shopping'),
'socializing': _('Socializing'),
'sunbathing': _('Sunbathing'),
'watching_tv': _('Watching TV'),
'watching_a_movie': _('Watching a Movie')},
'talking': {'category': _('Talking'),
'in_real_life': _('In Real Life'),
'on_the_phone': _('On the Phone'),
'on_video_phone': _('On Video Phone')},
'traveling': {'category': _('Traveling'),
'commuting': _('Commuting'),
'cycling': _('Cycling'),
'driving': _('Driving'),
'in_a_car': _('In a Car'),
'on_a_bus': _('On a Bus'),
'on_a_plane': _('On a Plane'),
'on_a_train': _('On a Train'),
'on_a_trip': _('On a Trip'),
'walking': _('Walking')},
'working': {'category': _('Working'),
'coding': _('Coding'),
'in_a_meeting': _('In a Meeting'),
'studying': _('Studying'),
'writing': _('Writing')}}
def user_mood(items, name, jid):
has_child = False
retract = False
mood = None
text = None
for item in items.getTags('item'):
child = item.getTag('mood')
if child is not None:
has_child = True
for ch in child.getChildren():
if ch.getName() != 'text':
mood = ch.getName()
else:
text = ch.getData()
if items.getTag('retract') is not None:
retract = True
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
if has_child:
if 'mood' in acc.mood:
del acc.mood['mood']
if 'text' in acc.mood:
del acc.mood['text']
if mood is not None:
acc.mood['mood'] = mood
if text is not None:
acc.mood['text'] = text
elif retract:
if 'mood' in acc.mood:
del acc.mood['mood']
if 'text' in acc.mood:
del acc.mood['text']
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
for contact in gajim.contacts.get_contacts(name, user):
if has_child:
if 'mood' in contact.mood:
del contact.mood['mood']
if 'text' in contact.mood:
del contact.mood['text']
if mood is not None:
contact.mood['mood'] = mood
if text is not None:
contact.mood['text'] = text
elif retract:
if 'mood' in contact.mood:
del contact.mood['mood']
if 'text' in contact.mood:
del contact.mood['text']
if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name)
gajim.interface.roster.draw_mood(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl:
ctrl.update_mood()
def user_tune(items, name, jid):
has_child = False
retract = False
artist = None
title = None
source = None
track = None
length = None
for item in items.getTags('item'):
child = item.getTag('tune')
if child is not None:
has_child = True
for ch in child.getChildren():
if ch.getName() == 'artist':
artist = ch.getData()
elif ch.getName() == 'title':
title = ch.getData()
elif ch.getName() == 'source':
source = ch.getData()
elif ch.getName() == 'track':
track = ch.getData()
elif ch.getName() == 'length':
length = ch.getData()
if items.getTag('retract') is not None:
retract = True
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
if has_child:
if 'artist' in acc.tune:
del acc.tune['artist']
if 'title' in acc.tune:
del acc.tune['title']
if 'source' in acc.tune:
del acc.tune['source']
if 'track' in acc.tune:
del acc.tune['track']
if 'length' in acc.tune:
del acc.tune['length']
if artist is not None:
acc.tune['artist'] = artist
if title is not None:
acc.tune['title'] = title
if source is not None:
acc.tune['source'] = source
if track is not None:
acc.tune['track'] = track
if length is not None:
acc.tune['length'] = length
elif retract:
if 'artist' in acc.tune:
del acc.tune['artist']
if 'title' in acc.tune:
del acc.tune['title']
if 'source' in acc.tune:
del acc.tune['source']
if 'track' in acc.tune:
del acc.tune['track']
if 'length' in acc.tune:
del acc.tune['length']
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
for contact in gajim.contacts.get_contacts(name, user):
if has_child:
if 'artist' in contact.tune:
del contact.tune['artist']
if 'title' in contact.tune:
del contact.tune['title']
if 'source' in contact.tune:
del contact.tune['source']
if 'track' in contact.tune:
del contact.tune['track']
if 'length' in contact.tune:
del contact.tune['length']
if artist is not None:
contact.tune['artist'] = artist
if title is not None:
contact.tune['title'] = title
if source is not None:
contact.tune['source'] = source
if track is not None:
contact.tune['track'] = track
if length is not None:
contact.tune['length'] = length
elif retract:
if 'artist' in contact.tune:
del contact.tune['artist']
if 'title' in contact.tune:
del contact.tune['title']
if 'source' in contact.tune:
del contact.tune['source']
if 'track' in contact.tune:
del contact.tune['track']
if 'length' in contact.tune:
del contact.tune['length']
if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name)
gajim.interface.roster.draw_tune(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl:
ctrl.update_tune()
def user_geoloc(items, name, jid):
pass
def user_activity(items, name, jid):
has_child = False
retract = False
activity = None
subactivity = None
text = None
for item in items.getTags('item'):
child = item.getTag('activity')
if child is not None:
has_child = True
for ch in child.getChildren():
if ch.getName() != 'text':
activity = ch.getName()
for chi in ch.getChildren():
subactivity = chi.getName()
else:
text = ch.getData()
if items.getTag('retract') is not None:
retract = True
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
if has_child:
if 'activity' in acc.activity:
del acc.activity['activity']
if 'subactivity' in acc.activity:
del acc.activity['subactivity']
if 'text' in acc.activity:
del acc.activity['text']
if activity is not None:
acc.activity['activity'] = activity
if subactivity is not None:
acc.activity['subactivity'] = subactivity
if text is not None:
acc.activity['text'] = text
elif retract:
if 'activity' in acc.activity:
del acc.activity['activity']
if 'subactivity' in acc.activity:
del acc.activity['subactivity']
if 'text' in acc.activity:
del acc.activity['text']
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
for contact in gajim.contacts.get_contacts(name, user):
if has_child:
if 'activity' in contact.activity:
del contact.activity['activity']
if 'subactivity' in contact.activity:
del contact.activity['subactivity']
if 'text' in contact.activity:
del contact.activity['text']
if activity is not None:
contact.activity['activity'] = activity
if subactivity is not None:
contact.activity['subactivity'] = subactivity
if text is not None:
contact.activity['text'] = text
elif retract:
if 'activity' in contact.activity:
del contact.activity['activity']
if 'subactivity' in contact.activity:
del contact.activity['subactivity']
if 'text' in contact.activity:
del contact.activity['text']
if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name)
gajim.interface.roster.draw_activity(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl:
ctrl.update_activity()
def user_nickname(items, name, jid):
has_child = False
retract = False
nick = None
for item in items.getTags('item'):
child = item.getTag('nick')
if child is not None:
has_child = True
nick = child.getData()
break
if items.getTag('retract') is not None:
retract = True
if jid == gajim.get_jid_from_account(name):
if has_child:
gajim.nicks[name] = nick
if retract:
gajim.nicks[name] = gajim.config.get_per('accounts',
name, 'name')
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
if has_child:
if nick is not None:
for contact in gajim.contacts.get_contacts(name, user):
contact.contact_name = nick
gajim.interface.roster.draw_contact(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user,
name)
if ctrl:
ctrl.update_ui()
win = ctrl.parent_win
win.redraw_tab(ctrl)
win.show_title()
elif retract:
contact.contact_name = ''
def user_send_mood(account, mood, message = ''):
if not gajim.connections[account].pep_supported:
return
item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD})
if mood != '':
if mood in GAJIM_MOODS:
ns = 'http://gajim.org/moods'
else:
ns = None
item.addChild(mood, namespace = ns)
if message != '':
i = item.addChild('text')
i.addData(message)
gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item, '0')
def user_send_activity(account, activity, subactivity = '', message = ''):
if not gajim.connections[account].pep_supported:
return
item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY})
if activity != '':
i = item.addChild(activity)
if subactivity != '':
i.addChild(subactivity)
if message != '':
i = item.addChild('text')
i.addData(message)
gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY,
item, '0')
def user_send_tune(account, artist = '', title = '', source = '', track = 0,
length = 0, items = None):
if not (gajim.config.get_per('accounts', account, 'publish_tune') and \
gajim.connections[account].pep_supported):
return
item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE})
if artist != '':
i = item.addChild('artist')
i.addData(artist)
if title != '':
i = item.addChild('title')
i.addData(title)
if source != '':
i = item.addChild('source')
i.addData(source)
if track != 0:
i = item.addChild('track')
i.addData(track)
if length != 0:
i = item.addChild('length')
i.addData(length)
if items is not None:
item.addChild(payload=items)
gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0')
def user_send_nickname(account, nick):
if not gajim.connections[account].pep_supported:
return
item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK})
item.addData(nick)
gajim.connections[account].send_pb_publish('', xmpp.NS_NICK, item, '0')
def user_retract_mood(account):
gajim.connections[account].send_pb_retract('', xmpp.NS_MOOD, '0')
def user_retract_activity(account):
gajim.connections[account].send_pb_retract('', xmpp.NS_ACTIVITY, '0')
def user_retract_tune(account):
gajim.connections[account].send_pb_retract('', xmpp.NS_TUNE, '0')
def user_retract_nickname(account):
gajim.connections[account].send_pb_retract('', xmpp.NS_NICK, '0')
def delete_pep(jid, name):
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
if jid == gajim.get_jid_from_account(name):
acc = gajim.connections[name]
del acc.activity
acc.activity = {}
del acc.tune
acc.tune = {}
del acc.mood
acc.mood = {}
for contact in gajim.contacts.get_contacts(name, user):
del contact.activity
contact.activity = {}
del contact.tune
contact.tune = {}
del contact.mood
contact.mood = {}
if jid == gajim.get_jid_from_account(name):
gajim.interface.roster.draw_account(name)
gajim.interface.roster.draw_activity(user, name)
gajim.interface.roster.draw_tune(user, name)
gajim.interface.roster.draw_mood(user, name)
ctrl = gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl:
ctrl.update_activity()
ctrl.update_tune()
ctrl.update_mood()
# vim: se ts=3:
|