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