gajim

view src/gajim.py @ 10773:1076fc9700f5

merge elghinn's branch (roster versioning) to trunk. Fixes #4661, #3190
author Yann Leboulanger <asterix@lagaule.org>
date Fri, 10 Jul 2009 15:05:01 +0200
parents a08a9bccf39d 06e57851eb8e
children b24f17156faa 4640ff9054a1
line source
1 # -*- coding:utf-8 -*-
2 ## src/gajim.py
3 ##
4 ## Copyright (C) 2003-2008 Yann Leboulanger <asterix AT lagaule.org>
5 ## Copyright (C) 2004-2005 Vincent Hanquez <tab AT snarc.org>
6 ## Copyright (C) 2005 Alex Podaras <bigpod AT gmail.com>
7 ## Norman Rasmussen <norman AT rasmussen.co.za>
8 ## Stéphan Kochen <stephan AT kochen.nl>
9 ## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
10 ## Alex Mauer <hawke AT hawkesnest.net>
11 ## Copyright (C) 2005-2007 Travis Shirk <travis AT pobox.com>
12 ## Nikos Kouremenos <kourem AT gmail.com>
13 ## Copyright (C) 2006 Junglecow J <junglecow AT gmail.com>
14 ## Stefan Bethge <stefan AT lanpartei.de>
15 ## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
16 ## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
17 ## James Newton <redshodan AT gmail.com>
18 ## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
19 ## Julien Pivotto <roidelapluie AT gmail.com>
20 ## Stephan Erb <steve-e AT h3c.de>
21 ## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
22 ##
23 ## This file is part of Gajim.
24 ##
25 ## Gajim is free software; you can redistribute it and/or modify
26 ## it under the terms of the GNU General Public License as published
27 ## by the Free Software Foundation; version 3 only.
28 ##
29 ## Gajim is distributed in the hope that it will be useful,
30 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ## GNU General Public License for more details.
33 ##
34 ## You should have received a copy of the GNU General Public License
35 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
36 ##
38 import os
39 import sys
40 import warnings
42 if os.name == 'nt':
43 warnings.filterwarnings(action='ignore')
45 if os.path.isdir('gtk'):
46 # Used to create windows installer with GTK included
47 paths = os.environ['PATH']
48 list_ = paths.split(';')
49 new_list = []
50 for p in list_:
51 if p.find('gtk') < 0 and p.find('GTK') < 0:
52 new_list.append(p)
53 new_list.insert(0, 'gtk/lib')
54 new_list.insert(0, 'gtk/bin')
55 os.environ['PATH'] = ';'.join(new_list)
56 os.environ['GTK_BASEPATH'] = 'gtk'
58 if os.name == 'nt':
59 # needed for docutils
60 sys.path.append('.')
62 from common import logging_helpers
63 logging_helpers.init('TERM' in os.environ)
65 import logging
66 # gajim.gui or gajim.gtk more appropriate ?
67 log = logging.getLogger('gajim.gajim')
69 import getopt
70 from common import i18n
72 def parseOpts():
73 profile = ''
74 config_path = None
76 try:
77 shortargs = 'hqvl:p:c:'
78 longargs = 'help quiet verbose loglevel= profile= config_path='
79 opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
80 except getopt.error, msg:
81 print msg
82 print 'for help use --help'
83 sys.exit(2)
84 for o, a in opts:
85 if o in ('-h', '--help'):
86 print 'gajim [--help] [--quiet] [--verbose] [--loglevel subsystem=level[,subsystem=level[...]]] [--profile name] [--config-path]'
87 sys.exit()
88 elif o in ('-q', '--quiet'):
89 logging_helpers.set_quiet()
90 elif o in ('-v', '--verbose'):
91 logging_helpers.set_verbose()
92 elif o in ('-p', '--profile'): # gajim --profile name
93 profile = a
94 elif o in ('-l', '--loglevel'):
95 logging_helpers.set_loglevels(a)
96 elif o in ('-c', '--config-path'):
97 config_path = a
98 return profile, config_path
100 profile, config_path = parseOpts()
101 del parseOpts
103 import locale
104 profile = unicode(profile, locale.getpreferredencoding())
106 import common.configpaths
107 common.configpaths.gajimpaths.init(config_path)
108 del config_path
109 common.configpaths.gajimpaths.init_profile(profile)
110 del profile
112 if os.name == 'nt':
113 class MyStderr(object):
114 _file = None
115 _error = None
116 def write(self, text):
117 fname=os.path.join(common.configpaths.gajimpaths.root,
118 os.path.split(sys.executable)[1]+'.log')
119 if self._file is None and self._error is None:
120 try:
121 self._file = open(fname, 'a')
122 except Exception, details:
123 self._error = details
124 if self._file is not None:
125 self._file.write(text)
126 self._file.flush()
127 def flush(self):
128 if self._file is not None:
129 self._file.flush()
131 sys.stderr = MyStderr()
133 # PyGTK2.10+ only throws a warning
134 warnings.filterwarnings('error', module='gtk')
135 try:
136 import gtk
137 except Warning, msg:
138 if str(msg) == 'could not open display':
139 print >> sys.stderr, _('Gajim needs X server to run. Quiting...')
140 sys.exit()
141 warnings.resetwarnings()
143 if os.name == 'nt':
144 warnings.filterwarnings(action='ignore')
146 pritext = ''
148 from common import exceptions
149 try:
150 from common import gajim
151 except exceptions.DatabaseMalformed:
152 pritext = _('Database Error')
153 sectext = _('The database file (%s) cannot be read. Try to repair it (see http://trac.gajim.org/wiki/DatabaseBackup) or remove it (all history will be lost).') % common.logger.LOG_DB_PATH
154 else:
155 from common import dbus_support
156 if dbus_support.supported:
157 import dbus
159 if os.name == 'posix': # dl module is Unix Only
160 try: # rename the process name to gajim
161 import dl
162 libc = dl.open('/lib/libc.so.6')
163 libc.call('prctl', 15, 'gajim\0', 0, 0, 0)
164 except Exception:
165 pass
167 if gtk.pygtk_version < (2, 12, 0):
168 pritext = _('Gajim needs PyGTK 2.12 or above')
169 sectext = _('Gajim needs PyGTK 2.12 or above to run. Quiting...')
170 elif gtk.gtk_version < (2, 12, 0):
171 pritext = _('Gajim needs GTK 2.12 or above')
172 sectext = _('Gajim needs GTK 2.12 or above to run. Quiting...')
174 try:
175 import gtk.glade # check if user has libglade (in pygtk and in gtk)
176 except ImportError:
177 pritext = _('GTK+ runtime is missing libglade support')
178 if os.name == 'nt':
179 sectext = _('Please remove your current GTK+ runtime and install the latest stable version from %s') % 'http://gladewin32.sourceforge.net'
180 else:
181 sectext = _('Please make sure that GTK+ and PyGTK have libglade support in your system.')
183 try:
184 from common import check_paths
185 except exceptions.PysqliteNotAvailable, e:
186 pritext = _('Gajim needs PySQLite2 to run')
187 sectext = str(e)
189 if os.name == 'nt':
190 try:
191 import winsound # windows-only built-in module for playing wav
192 import win32api # do NOT remove. we req this module
193 except Exception:
194 pritext = _('Gajim needs pywin32 to run')
195 sectext = _('Please make sure that Pywin32 is installed on your system. You can get it at %s') % 'http://sourceforge.net/project/showfiles.php?group_id=78018'
197 if pritext:
198 dlg = gtk.MessageDialog(None,
199 gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
200 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message_format = pritext)
202 dlg.format_secondary_text(sectext)
203 dlg.run()
204 dlg.destroy()
205 sys.exit()
207 del pritext
209 import gtkexcepthook
211 import gobject
212 if not hasattr(gobject, 'timeout_add_seconds'):
213 def timeout_add_seconds_fake(time_sec, *args):
214 return gobject.timeout_add(time_sec * 1000, *args)
215 gobject.timeout_add_seconds = timeout_add_seconds_fake
217 import re
218 import signal
219 import time
220 import math
222 import gtkgui_helpers
223 import notify
224 import message_control
226 from chat_control import ChatControlBase
227 from chat_control import ChatControl
228 from groupchat_control import GroupchatControl
229 from groupchat_control import PrivateChatControl
230 from atom_window import AtomWindow
231 from session import ChatControlSession
233 import common.sleepy
235 from common.xmpp import idlequeue
236 from common.zeroconf import connection_zeroconf
237 from common import resolver
238 from common import proxy65_manager
239 from common import socks5
240 from common import helpers
241 from common import optparser
242 from common import dataforms
243 from common import passwords
245 gajimpaths = common.configpaths.gajimpaths
247 pid_filename = gajimpaths['PID_FILE']
248 config_filename = gajimpaths['CONFIG_FILE']
250 import traceback
251 import errno
253 import dialogs
254 def pid_alive():
255 try:
256 pf = open(pid_filename)
257 except IOError:
258 # probably file not found
259 return False
261 try:
262 pid = int(pf.read().strip())
263 pf.close()
264 except Exception:
265 traceback.print_exc()
266 # PID file exists, but something happened trying to read PID
267 # Could be 0.10 style empty PID file, so assume Gajim is running
268 return True
270 if os.name == 'nt':
271 try:
272 from ctypes import (windll, c_ulong, c_int, Structure, c_char, POINTER, pointer, )
273 except Exception:
274 return True
276 class PROCESSENTRY32(Structure):
277 _fields_ = [
278 ('dwSize', c_ulong, ),
279 ('cntUsage', c_ulong, ),
280 ('th32ProcessID', c_ulong, ),
281 ('th32DefaultHeapID', c_ulong, ),
282 ('th32ModuleID', c_ulong, ),
283 ('cntThreads', c_ulong, ),
284 ('th32ParentProcessID', c_ulong, ),
285 ('pcPriClassBase', c_ulong, ),
286 ('dwFlags', c_ulong, ),
287 ('szExeFile', c_char*512, ),
288 ]
289 def __init__(self):
290 Structure.__init__(self, 512+9*4)
292 k = windll.kernel32
293 k.CreateToolhelp32Snapshot.argtypes = c_ulong, c_ulong,
294 k.CreateToolhelp32Snapshot.restype = c_int
295 k.Process32First.argtypes = c_int, POINTER(PROCESSENTRY32),
296 k.Process32First.restype = c_int
297 k.Process32Next.argtypes = c_int, POINTER(PROCESSENTRY32),
298 k.Process32Next.restype = c_int
300 def get_p(p):
301 h = k.CreateToolhelp32Snapshot(2, 0) # TH32CS_SNAPPROCESS
302 assert h > 0, 'CreateToolhelp32Snapshot failed'
303 b = pointer(PROCESSENTRY32())
304 f = k.Process32First(h, b)
305 while f:
306 if b.contents.th32ProcessID == p:
307 return b.contents.szExeFile
308 f = k.Process32Next(h, b)
310 if get_p(pid) in ('python.exe', 'gajim.exe'):
311 return True
312 return False
313 try:
314 if not os.path.exists('/proc'):
315 return True # no /proc, assume Gajim is running
317 try:
318 f = open('/proc/%d/cmdline'% pid)
319 except IOError, e:
320 if e.errno == errno.ENOENT:
321 return False # file/pid does not exist
322 raise
324 n = f.read().lower()
325 f.close()
326 if n.find('gajim') < 0:
327 return False
328 return True # Running Gajim found at pid
329 except Exception:
330 traceback.print_exc()
332 # If we are here, pidfile exists, but some unexpected error occured.
333 # Assume Gajim is running.
334 return True
336 if pid_alive():
337 path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')
338 pix = gtk.gdk.pixbuf_new_from_file(path_to_file)
339 gtk.window_set_default_icon(pix) # set the icon to all newly opened wind
340 pritext = _('Gajim is already running')
341 sectext = _('Another instance of Gajim seems to be running\nRun anyway?')
342 dialog = dialogs.YesNoDialog(pritext, sectext)
343 dialog.popup()
344 if dialog.run() != gtk.RESPONSE_YES:
345 sys.exit(3)
346 dialog.destroy()
347 # run anyway, delete pid and useless global vars
348 if os.path.exists(pid_filename):
349 os.remove(pid_filename)
350 del path_to_file
351 del pix
352 del pritext
353 del sectext
354 dialog.destroy()
356 # Create .gajim dir
357 pid_dir = os.path.dirname(pid_filename)
358 if not os.path.exists(pid_dir):
359 check_paths.create_path(pid_dir)
360 # Create pid file
361 try:
362 f = open(pid_filename, 'w')
363 f.write(str(os.getpid()))
364 f.close()
365 except IOError, e:
366 dlg = dialogs.ErrorDialog(_('Disk Write Error'), str(e))
367 dlg.run()
368 dlg.destroy()
369 sys.exit()
370 del pid_dir
371 del f
373 def on_exit():
374 # delete pid file on normal exit
375 if os.path.exists(pid_filename):
376 os.remove(pid_filename)
377 # Shutdown GUI and save config
378 gajim.interface.roster.prepare_quit()
380 import atexit
381 atexit.register(on_exit)
383 parser = optparser.OptionsParser(config_filename)
385 import roster_window
386 import profile_window
387 import config
388 from threading import Thread
391 class PassphraseRequest:
392 def __init__(self, keyid):
393 self.keyid = keyid
394 self.callbacks = []
395 self.dialog_created = False
396 self.dialog = None
397 self.completed = False
399 def interrupt(self):
400 self.dialog.window.destroy()
401 self.callbacks = []
403 def run_callback(self, account, callback):
404 gajim.connections[account].gpg_passphrase(self.passphrase)
405 callback()
407 def add_callback(self, account, cb):
408 if self.completed:
409 self.run_callback(account, cb)
410 else:
411 self.callbacks.append((account, cb))
412 if not self.dialog_created:
413 self.create_dialog(account)
415 def complete(self, passphrase):
416 self.passphrase = passphrase
417 self.completed = True
418 if passphrase is not None:
419 gobject.timeout_add_seconds(30, gajim.interface.forget_gpg_passphrase,
420 self.keyid)
421 for (account, cb) in self.callbacks:
422 self.run_callback(account, cb)
423 del self.callbacks
425 def create_dialog(self, account):
426 title = _('Passphrase Required')
427 second = _('Enter GPG key passphrase for key %(keyid)s (account '
428 '%(account)s).') % {'keyid': self.keyid, 'account': account}
430 def _cancel():
431 # user cancelled, continue without GPG
432 self.complete(None)
434 def _ok(passphrase, checked, count):
435 result = gajim.connections[account].test_gpg_passphrase(passphrase)
436 if result == 'ok':
437 # passphrase is good
438 self.complete(passphrase)
439 return
440 elif result == 'expired':
441 dialogs.ErrorDialog(_('GPG key expired'),
442 _('Your GPG key has expied, you will be connected to %s without '
443 'OpenPGP.') % account)
444 # Don't try to connect with GPG
445 gajim.connections[account].continue_connect_info[2] = False
446 self.complete(None)
447 return
449 if count < 3:
450 # ask again
451 dialogs.PassphraseDialog(_('Wrong Passphrase'),
452 _('Please retype your GPG passphrase or press Cancel.'),
453 ok_handler=(_ok, count + 1), cancel_handler=_cancel)
454 else:
455 # user failed 3 times, continue without GPG
456 self.complete(None)
458 self.dialog = dialogs.PassphraseDialog(title, second, ok_handler=(_ok, 1),
459 cancel_handler=_cancel)
460 self.dialog_created = True
463 class ThreadInterface:
464 def __init__(self, func, func_args, callback, callback_args):
465 '''Call a function in a thread
467 :param func: the function to call in the thread
468 :param func_args: list or arguments for this function
469 :param callback: callback to call once function is finished
470 :param callback_args: list of arguments for this callback
471 '''
472 def thread_function(func, func_args, callback, callback_args):
473 output = func(*func_args)
474 gobject.idle_add(callback, output, *callback_args)
475 Thread(target=thread_function, args=(func, func_args, callback,
476 callback_args)).start()
478 class Interface:
480 ################################################################################
481 ### Methods handling events from connection
482 ################################################################################
484 def handle_event_roster(self, account, data):
485 #('ROSTER', account, array)
486 # FIXME: Those methods depend to highly on each other
487 # and the order in which they are called
488 self.roster.fill_contacts_and_groups_dicts(data, account)
489 self.roster.add_account_contacts(account)
490 self.roster.fire_up_unread_messages_events(account)
491 if self.remote_ctrl:
492 self.remote_ctrl.raise_signal('Roster', (account, data))
494 def handle_event_warning(self, unused, data):
495 #('WARNING', account, (title_text, section_text))
496 dialogs.WarningDialog(data[0], data[1])
498 def handle_event_error(self, unused, data):
499 #('ERROR', account, (title_text, section_text))
500 dialogs.ErrorDialog(data[0], data[1])
502 def handle_event_information(self, unused, data):
503 #('INFORMATION', account, (title_text, section_text))
504 dialogs.InformationDialog(data[0], data[1])
506 def handle_event_ask_new_nick(self, account, data):
507 #('ASK_NEW_NICK', account, (room_jid,))
508 room_jid = data[0]
509 gc_control = self.msg_win_mgr.get_gc_control(room_jid, account)
510 if not gc_control and \
511 room_jid in self.minimized_controls[account]:
512 gc_control = self.minimized_controls[account][room_jid]
513 if gc_control: # user may close the window before we are here
514 title = _('Unable to join group chat')
515 prompt = _('Your desired nickname in group chat %s is in use or '
516 'registered by another occupant.\nPlease specify another nickname '
517 'below:') % room_jid
518 gc_control.show_change_nick_input_dialog(title, prompt)
520 def handle_event_http_auth(self, account, data):
521 #('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))
522 def response(account, iq_obj, answer):
523 self.dialog.destroy()
524 gajim.connections[account].build_http_auth_answer(iq_obj, answer)
526 def on_yes(is_checked, account, iq_obj):
527 response(account, iq_obj, 'yes')
529 sec_msg = _('Do you accept this request?')
530 if gajim.get_number_of_connected_accounts() > 1:
531 sec_msg = _('Do you accept this request on account %s?') % account
532 if data[4]:
533 sec_msg = data[4] + '\n' + sec_msg
534 self.dialog = dialogs.YesNoDialog(_('HTTP (%(method)s) Authorization for '
535 '%(url)s (id: %(id)s)') % {'method': data[0], 'url': data[1],
536 'id': data[2]}, sec_msg, on_response_yes=(on_yes, account, data[3]),
537 on_response_no=(response, account, data[3], 'no'))
539 def handle_event_error_answer(self, account, array):
540 #('ERROR_ANSWER', account, (id, jid_from, errmsg, errcode))
541 id_, jid_from, errmsg, errcode = array
542 if unicode(errcode) in ('400', '403', '406') and id_:
543 # show the error dialog
544 ft = self.instances['file_transfers']
545 sid = id_
546 if len(id_) > 3 and id_[2] == '_':
547 sid = id_[3:]
548 if sid in ft.files_props['s']:
549 file_props = ft.files_props['s'][sid]
550 if unicode(errcode) == '400':
551 file_props['error'] = -3
552 else:
553 file_props['error'] = -4
554 self.handle_event_file_request_error(account,
555 (jid_from, file_props, errmsg))
556 conn = gajim.connections[account]
557 conn.disconnect_transfer(file_props)
558 return
559 elif unicode(errcode) == '404':
560 conn = gajim.connections[account]
561 sid = id_
562 if len(id_) > 3 and id_[2] == '_':
563 sid = id_[3:]
564 if sid in conn.files_props:
565 file_props = conn.files_props[sid]
566 self.handle_event_file_send_error(account,
567 (jid_from, file_props))
568 conn.disconnect_transfer(file_props)
569 return
571 ctrl = self.msg_win_mgr.get_control(jid_from, account)
572 if ctrl and ctrl.type_id == message_control.TYPE_GC:
573 ctrl.print_conversation('Error %s: %s' % (array[2], array[1]))
575 def handle_event_con_type(self, account, con_type):
576 # ('CON_TYPE', account, con_type) which can be 'ssl', 'tls', 'plain'
577 gajim.con_types[account] = con_type
578 self.roster.draw_account(account)
580 def handle_event_connection_lost(self, account, array):
581 # ('CONNECTION_LOST', account, [title, text])
582 path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
583 'connection_lost.png')
584 path = gtkgui_helpers.get_path_to_generic_or_avatar(path)
585 notify.popup(_('Connection Failed'), account, account,
586 'connection_failed', path, array[0], array[1])
588 def unblock_signed_in_notifications(self, account):
589 gajim.block_signed_in_notifications[account] = False
591 def handle_event_status(self, account, status): # OUR status
592 #('STATUS', account, status)
593 model = self.roster.status_combobox.get_model()
594 if status in ('offline', 'error'):
595 for name in self.instances[account]['online_dialog'].keys():
596 # .keys() is needed to not have a dictionary length changed during
597 # iteration error
598 self.instances[account]['online_dialog'][name].destroy()
599 del self.instances[account]['online_dialog'][name]
600 for request in self.gpg_passphrase.values():
601 if request:
602 request.interrupt()
603 # .keys() is needed because dict changes during loop
604 for account in self.pass_dialog.keys():
605 self.pass_dialog[account].window.destroy()
606 if status == 'offline':
607 # sensitivity for this menuitem
608 if gajim.get_number_of_connected_accounts() == 0:
609 model[self.roster.status_message_menuitem_iter][3] = False
610 gajim.block_signed_in_notifications[account] = True
611 else:
612 # 30 seconds after we change our status to sth else than offline
613 # we stop blocking notifications of any kind
614 # this prevents from getting the roster items as 'just signed in'
615 # contacts. 30 seconds should be enough time
616 gobject.timeout_add_seconds(30, self.unblock_signed_in_notifications, account)
617 # sensitivity for this menuitem
618 model[self.roster.status_message_menuitem_iter][3] = True
620 # Inform all controls for this account of the connection state change
621 ctrls = self.msg_win_mgr.get_controls()
622 if account in self.minimized_controls:
623 # Can not be the case when we remove account
624 ctrls += self.minimized_controls[account].values()
625 for ctrl in ctrls:
626 if ctrl.account == account:
627 if status == 'offline' or (status == 'invisible' and \
628 gajim.connections[account].is_zeroconf):
629 ctrl.got_disconnected()
630 else:
631 # Other code rejoins all GCs, so we don't do it here
632 if not ctrl.type_id == message_control.TYPE_GC:
633 ctrl.got_connected()
634 if ctrl.parent_win:
635 ctrl.parent_win.redraw_tab(ctrl)
637 self.roster.on_status_changed(account, status)
638 if account in self.show_vcard_when_connect and status not in ('offline',
639 'error'):
640 self.edit_own_details(account)
641 if self.remote_ctrl:
642 self.remote_ctrl.raise_signal('AccountPresence', (status, account))
644 def edit_own_details(self, account):
645 jid = gajim.get_jid_from_account(account)
646 if 'profile' not in self.instances[account]:
647 self.instances[account]['profile'] = \
648 profile_window.ProfileWindow(account)
649 gajim.connections[account].request_vcard(jid)
651 def handle_event_notify(self, account, array):
652 # 'NOTIFY' (account, (jid, status, status message, resource,
653 # priority, # keyID, timestamp, contact_nickname))
654 #
655 # Contact changed show
657 # FIXME: Drop and rewrite...
659 statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
660 'invisible']
661 # Ignore invalid show
662 if array[1] not in statuss:
663 return
664 old_show = 0
665 new_show = statuss.index(array[1])
666 status_message = array[2]
667 jid = array[0].split('/')[0]
668 keyID = array[5]
669 contact_nickname = array[7]
671 # Get the proper keyID
672 keyID = helpers.prepare_and_validate_gpg_keyID(account, jid, keyID)
674 resource = array[3]
675 if not resource:
676 resource = ''
677 priority = array[4]
678 if gajim.jid_is_transport(jid):
679 # It must be an agent
680 ji = jid.replace('@', '')
681 else:
682 ji = jid
684 highest = gajim.contacts. \
685 get_contact_with_highest_priority(account, jid)
686 was_highest = (highest and highest.resource == resource)
688 conn = gajim.connections[account]
690 # Update contact
691 jid_list = gajim.contacts.get_jid_list(account)
692 if ji in jid_list or jid == gajim.get_jid_from_account(account):
693 lcontact = gajim.contacts.get_contacts(account, ji)
694 contact1 = None
695 resources = []
696 for c in lcontact:
697 resources.append(c.resource)
698 if c.resource == resource:
699 contact1 = c
700 break
702 if contact1:
703 if contact1.show in statuss:
704 old_show = statuss.index(contact1.show)
705 # nick changed
706 if contact_nickname is not None and \
707 contact1.contact_name != contact_nickname:
708 contact1.contact_name = contact_nickname
709 self.roster.draw_contact(jid, account)
711 if old_show == new_show and contact1.status == status_message and \
712 contact1.priority == priority: # no change
713 return
714 else:
715 contact1 = gajim.contacts.get_first_contact_from_jid(account, ji)
716 if not contact1:
717 # Presence of another resource of our
718 # jid
719 # Create self contact and add to roster
720 if resource == conn.server_resource:
721 return
722 # Ignore offline presence of unknown self resource
723 if new_show < 2:
724 return
725 contact1 = gajim.contacts.create_contact(jid=ji,
726 name=gajim.nicks[account], groups=['self_contact'],
727 show=array[1], status=status_message, sub='both', ask='none',
728 priority=priority, keyID=keyID, resource=resource,
729 mood=conn.mood, tune=conn.tune, activity=conn.activity)
730 old_show = 0
731 gajim.contacts.add_contact(account, contact1)
732 lcontact.append(contact1)
733 elif contact1.show in statuss:
734 old_show = statuss.index(contact1.show)
735 # FIXME: What am I?
736 if (resources != [''] and (len(lcontact) != 1 or \
737 lcontact[0].show != 'offline')) and jid.find('@') > 0:
738 old_show = 0
739 contact1 = gajim.contacts.copy_contact(contact1)
740 lcontact.append(contact1)
741 contact1.resource = resource
743 self.roster.add_contact(contact1.jid, account)
745 if contact1.jid.find('@') > 0 and len(lcontact) == 1:
746 # It's not an agent
747 if old_show == 0 and new_show > 1:
748 if not contact1.jid in gajim.newly_added[account]:
749 gajim.newly_added[account].append(contact1.jid)
750 if contact1.jid in gajim.to_be_removed[account]:
751 gajim.to_be_removed[account].remove(contact1.jid)
752 gobject.timeout_add_seconds(5, self.roster.remove_newly_added,
753 contact1.jid, account)
754 elif old_show > 1 and new_show == 0 and conn.connected > 1:
755 if not contact1.jid in gajim.to_be_removed[account]:
756 gajim.to_be_removed[account].append(contact1.jid)
757 if contact1.jid in gajim.newly_added[account]:
758 gajim.newly_added[account].remove(contact1.jid)
759 self.roster.draw_contact(contact1.jid, account)
760 gobject.timeout_add_seconds(5, self.roster.remove_to_be_removed,
761 contact1.jid, account)
763 # unset custom status
764 if (old_show == 0 and new_show > 1) or (old_show > 1 and new_show == 0\
765 and conn.connected > 1):
766 if account in self.status_sent_to_users and \
767 jid in self.status_sent_to_users[account]:
768 del self.status_sent_to_users[account][jid]
770 contact1.show = array[1]
771 contact1.status = status_message
772 contact1.priority = priority
773 contact1.keyID = keyID
774 timestamp = array[6]
775 if timestamp:
776 contact1.last_status_time = timestamp
777 elif not gajim.block_signed_in_notifications[account]:
778 # We're connected since more that 30 seconds
779 contact1.last_status_time = time.localtime()
780 contact1.contact_nickname = contact_nickname
782 if gajim.jid_is_transport(jid):
783 # It must be an agent
784 if ji in jid_list:
785 # Update existing iter and group counting
786 self.roster.draw_contact(ji, account)
787 self.roster.draw_group(_('Transports'), account)
788 if new_show > 1 and ji in gajim.transport_avatar[account]:
789 # transport just signed in.
790 # request avatars
791 for jid_ in gajim.transport_avatar[account][ji]:
792 conn.request_vcard(jid_)
793 # transport just signed in/out, don't show
794 # popup notifications for 30s
795 account_ji = account + '/' + ji
796 gajim.block_signed_in_notifications[account_ji] = True
797 gobject.timeout_add_seconds(30,
798 self.unblock_signed_in_notifications, account_ji)
799 locations = (self.instances, self.instances[account])
800 for location in locations:
801 if 'add_contact' in location:
802 if old_show == 0 and new_show > 1:
803 location['add_contact'].transport_signed_in(jid)
804 break
805 elif old_show > 1 and new_show == 0:
806 location['add_contact'].transport_signed_out(jid)
807 break
808 elif ji in jid_list:
809 # It isn't an agent
810 # reset chatstate if needed:
811 # (when contact signs out or has errors)
812 if array[1] in ('offline', 'error'):
813 contact1.our_chatstate = contact1.chatstate = \
814 contact1.composing_xep = None
816 # TODO: This causes problems when another
817 # resource signs off!
818 conn.remove_transfers_for_contact(contact1)
820 # disable encryption, since if any messages are
821 # lost they'll be not decryptable (note that
822 # this contradicts XEP-0201 - trying to get that
823 # in the XEP, though)
825 # there won't be any sessions here if the contact terminated
826 # their sessions before going offline (which we do)
827 for sess in conn.get_sessions(ji):
828 if (ji+'/'+resource) != str(sess.jid):
829 continue
830 if sess.control:
831 sess.control.no_autonegotiation = False
832 if sess.enable_encryption:
833 sess.terminate_e2e()
834 conn.delete_session(jid, sess.thread_id)
836 self.roster.chg_contact_status(contact1, array[1], status_message,
837 account)
838 # Notifications
839 if old_show < 2 and new_show > 1:
840 notify.notify('contact_connected', jid, account, status_message)
841 if self.remote_ctrl:
842 self.remote_ctrl.raise_signal('ContactPresence', (account,
843 array))
845 elif old_show > 1 and new_show < 2:
846 notify.notify('contact_disconnected', jid, account, status_message)
847 if self.remote_ctrl:
848 self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
849 # FIXME: stop non active file transfers
850 # Status change (not connected/disconnected or
851 # error (<1))
852 elif new_show > 1:
853 notify.notify('status_change', jid, account, [new_show,
854 status_message])
855 if self.remote_ctrl:
856 self.remote_ctrl.raise_signal('ContactStatus', (account, array))
857 else:
858 # FIXME: MSN transport (CMSN1.2.1 and PyMSN) don't
859 # follow the XEP, still the case in 2008.
860 # It's maybe a GC_NOTIFY (specialy for MSN gc)
861 self.handle_event_gc_notify(account, (jid, array[1], status_message,
862 array[3], None, None, None, None, None, [], None, None))
864 highest = gajim.contacts.get_contact_with_highest_priority(account, jid)
865 is_highest = (highest and highest.resource == resource)
867 # disconnect the session from the ctrl if the highest resource has changed
868 if (was_highest and not is_highest) or (not was_highest and is_highest):
869 ctrl = self.msg_win_mgr.get_control(jid, account)
871 if ctrl:
872 ctrl.set_session(None)
873 ctrl.contact = highest
875 def handle_event_msgerror(self, account, array):
876 #'MSGERROR' (account, (jid, error_code, error_msg, msg, time[, session]))
877 full_jid_with_resource = array[0]
878 jids = full_jid_with_resource.split('/', 1)
879 jid = jids[0]
881 session = None
882 if len(array) > 5:
883 session = array[5]
885 gc_control = self.msg_win_mgr.get_gc_control(jid, account)
886 if not gc_control and \
887 jid in self.minimized_controls[account]:
888 gc_control = self.minimized_controls[account][jid]
889 if gc_control and gc_control.type_id != message_control.TYPE_GC:
890 gc_control = None
891 if gc_control:
892 if len(jids) > 1: # it's a pm
893 nick = jids[1]
895 if session:
896 ctrl = session.control
897 else:
898 ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account)
900 if not ctrl:
901 tv = gc_control.list_treeview
902 model = tv.get_model()
903 iter_ = gc_control.get_contact_iter(nick)
904 if iter_:
905 show = model[iter_][3]
906 else:
907 show = 'offline'
908 gc_c = gajim.contacts.create_gc_contact(room_jid = jid,
909 name = nick, show = show)
910 ctrl = self.new_private_chat(gc_c, account, session)
912 ctrl.print_conversation(_('Error %(code)s: %(msg)s') % {
913 'code': array[1], 'msg': array[2]}, 'status')
914 return
916 gc_control.print_conversation(_('Error %(code)s: %(msg)s') % {
917 'code': array[1], 'msg': array[2]}, 'status')
918 if gc_control.parent_win and gc_control.parent_win.get_active_jid() == jid:
919 gc_control.set_subject(gc_control.subject)
920 return
922 if gajim.jid_is_transport(jid):
923 jid = jid.replace('@', '')
924 msg = array[2]
925 if array[3]:
926 msg = _('error while sending %(message)s ( %(error)s )') % {
927 'message': array[3], 'error': msg}
928 if session:
929 session.roster_message(jid, msg, array[4], msg_type='error')
931 def handle_event_msgsent(self, account, array):
932 #('MSGSENT', account, (jid, msg, keyID))
933 msg = array[1]
934 # do not play sound when standalone chatstate message (eg no msg)
935 if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled'):
936 helpers.play_sound('message_sent')
938 def handle_event_msgnotsent(self, account, array):
939 #('MSGNOTSENT', account, (jid, ierror_msg, msg, time, session))
940 msg = _('error while sending %(message)s ( %(error)s )') % {
941 'message': array[2], 'error': array[1]}
942 if not array[4]:
943 # No session. This can happen when sending a message from gajim-remote
944 log.warn(msg)
945 return
946 array[4].roster_message(array[0], msg, array[3], account,
947 msg_type='error')
949 def handle_event_subscribe(self, account, array):
950 #('SUBSCRIBE', account, (jid, text, user_nick)) user_nick is JEP-0172
951 if self.remote_ctrl:
952 self.remote_ctrl.raise_signal('Subscribe', (account, array))
954 jid = array[0]
955 text = array[1]
956 nick = array[2]
957 if helpers.allow_popup_window(account) or not self.systray_enabled:
958 dialogs.SubscriptionRequestWindow(jid, text, account, nick)
959 return
961 self.add_event(account, jid, 'subscription_request', (text, nick))
963 if helpers.allow_showing_notification(account):
964 path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
965 'subscription_request.png')
966 path = gtkgui_helpers.get_path_to_generic_or_avatar(path)
967 event_type = _('Subscription request')
968 notify.popup(event_type, jid, account, 'subscription_request', path,
969 event_type, jid)
971 def handle_event_subscribed(self, account, array):
972 #('SUBSCRIBED', account, (jid, resource))
973 jid = array[0]
974 if jid in gajim.contacts.get_jid_list(account):
975 c = gajim.contacts.get_first_contact_from_jid(account, jid)
976 c.resource = array[1]
977 self.roster.remove_contact_from_groups(c.jid, account,
978 [_('Not in Roster'), _('Observers')], update=False)
979 else:
980 keyID = ''
981 attached_keys = gajim.config.get_per('accounts', account,
982 'attached_gpg_keys').split()
983 if jid in attached_keys:
984 keyID = attached_keys[attached_keys.index(jid) + 1]
985 name = jid.split('@', 1)[0]
986 name = name.split('%', 1)[0]
987 contact1 = gajim.contacts.create_contact(jid=jid, name=name,
988 groups=[], show='online', status='online',
989 ask='to', resource=array[1], keyID=keyID)
990 gajim.contacts.add_contact(account, contact1)
991 self.roster.add_contact(jid, account)
992 dialogs.InformationDialog(_('Authorization accepted'),
993 _('The contact "%s" has authorized you to see his or her status.')
994 % jid)
995 if not gajim.config.get_per('accounts', account, 'dont_ack_subscription'):
996 gajim.connections[account].ack_subscribed(jid)
997 if self.remote_ctrl:
998 self.remote_ctrl.raise_signal('Subscribed', (account, array))
1000 def show_unsubscribed_dialog(self, account, contact):
1001 def on_yes(is_checked, list_):
1002 self.roster.on_req_usub(None, list_)
1003 list_ = [(contact, account)]
1004 dialogs.YesNoDialog(
1005 _('Contact "%s" removed subscription from you') % contact.jid,
1006 _('You will always see him or her as offline.\nDo you want to '
1007 'remove him or her from your contact list?'),
1008 on_response_yes=(on_yes, list_))
1009 # FIXME: Per RFC 3921, we can "deny" ack as well, but the GUI does
1010 # not show deny
1012 def handle_event_unsubscribed(self, account, jid):
1013 #('UNSUBSCRIBED', account, jid)
1014 gajim.connections[account].ack_unsubscribed(jid)
1015 if self.remote_ctrl:
1016 self.remote_ctrl.raise_signal('Unsubscribed', (account, jid))
1018 contact = gajim.contacts.get_first_contact_from_jid(account, jid)
1019 if not contact:
1020 return
1022 if helpers.allow_popup_window(account) or not self.systray_enabled:
1023 self.show_unsubscribed_dialog(account, contact)
1025 self.add_event(account, jid, 'unsubscribed', contact)
1027 if helpers.allow_showing_notification(account):
1028 path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
1029 'unsubscribed.png')
1030 path = gtkgui_helpers.get_path_to_generic_or_avatar(path)
1031 event_type = _('Unsubscribed')
1032 notify.popup(event_type, jid, account, 'unsubscribed', path,
1033 event_type, jid)
1035 def handle_event_agent_info_error(self, account, agent):
1036 #('AGENT_ERROR_INFO', account, (agent))
1037 try:
1038 gajim.connections[account].services_cache.agent_info_error(agent)
1039 except AttributeError:
1040 return
1042 def handle_event_agent_items_error(self, account, agent):
1043 #('AGENT_ERROR_INFO', account, (agent))
1044 try:
1045 gajim.connections[account].services_cache.agent_items_error(agent)
1046 except AttributeError:
1047 return
1049 def handle_event_agent_removed(self, account, agent):
1050 # remove transport's contacts from treeview
1051 jid_list = gajim.contacts.get_jid_list(account)
1052 for jid in jid_list:
1053 if jid.endswith('@' + agent):
1054 c = gajim.contacts.get_first_contact_from_jid(account, jid)
1055 gajim.log.debug(
1056 'Removing contact %s due to unregistered transport %s'\
1057 % (jid, agent))
1058 gajim.connections[account].unsubscribe(c.jid)
1059 # Transport contacts can't have 2 resources
1060 if c.jid in gajim.to_be_removed[account]:
1061 # This way we'll really remove it
1062 gajim.to_be_removed[account].remove(c.jid)
1063 self.roster.remove_contact(c.jid, account, backend=True)
1065 def handle_event_register_agent_info(self, account, array):
1066 # ('REGISTER_AGENT_INFO', account, (agent, infos, is_form))
1067 # info in a dataform if is_form is True
1068 if array[2] or 'instructions' in array[1]:
1069 config.ServiceRegistrationWindow(array[0], array[1], account,
1070 array[2])
1071 else:
1072 dialogs.ErrorDialog(_('Contact with "%s" cannot be established') \
1073 % array[0], _('Check your connection or try again later.'))
1075 def handle_event_agent_info_items(self, account, array):
1076 #('AGENT_INFO_ITEMS', account, (agent, node, items))
1077 our_jid = gajim.get_jid_from_account(account)
1078 if 'pep_services' in gajim.interface.instances[account] and \
1079 array[0] == our_jid:
1080 gajim.interface.instances[account]['pep_services'].items_received(
1081 array[2])
1082 try:
1083 gajim.connections[account].services_cache.agent_items(array[0],
1084 array[1], array[2])
1085 except AttributeError:
1086 return
1088 def handle_event_agent_info_info(self, account, array):
1089 #('AGENT_INFO_INFO', account, (agent, node, identities, features, data))
1090 try:
1091 gajim.connections[account].services_cache.agent_info(array[0],
1092 array[1], array[2], array[3], array[4])
1093 except AttributeError:
1094 return
1096 def handle_event_new_acc_connected(self, account, array):
1097 #('NEW_ACC_CONNECTED', account, (infos, is_form, ssl_msg, ssl_err,
1098 # ssl_cert, ssl_fingerprint))
1099 if 'account_creation_wizard' in self.instances:
1100 self.instances['account_creation_wizard'].new_acc_connected(array[0],
1101 array[1], array[2], array[3], array[4], array[5])
1103 def handle_event_new_acc_not_connected(self, account, array):
1104 #('NEW_ACC_NOT_CONNECTED', account, (reason))
1105 if 'account_creation_wizard' in self.instances:
1106 self.instances['account_creation_wizard'].new_acc_not_connected(array)
1108 def handle_event_acc_ok(self, account, array):
1109 #('ACC_OK', account, (config))
1110 if 'account_creation_wizard' in self.instances:
1111 self.instances['account_creation_wizard'].acc_is_ok(array)
1113 if self.remote_ctrl:
1114 self.remote_ctrl.raise_signal('NewAccount', (account, array))
1116 def handle_event_acc_not_ok(self, account, array):
1117 #('ACC_NOT_OK', account, (reason))
1118 if 'account_creation_wizard' in self.instances:
1119 self.instances['account_creation_wizard'].acc_is_not_ok(array)
1121 def handle_event_quit(self, p1, p2):
1122 self.roster.quit_gtkgui_interface()
1124 def handle_event_myvcard(self, account, array):
1125 nick = ''
1126 if 'NICKNAME' in array and array['NICKNAME']:
1127 gajim.nicks[account] = array['NICKNAME']
1128 elif 'FN' in array and array['FN']:
1129 gajim.nicks[account] = array['FN']
1130 if 'profile' in self.instances[account]:
1131 win = self.instances[account]['profile']
1132 win.set_values(array)
1133 if account in self.show_vcard_when_connect:
1134 self.show_vcard_when_connect.remove(account)
1135 jid = array['jid']
1136 if jid in self.instances[account]['infos']:
1137 self.instances[account]['infos'][jid].set_values(array)
1139 def handle_event_vcard(self, account, vcard):
1140 # ('VCARD', account, data)
1141 '''vcard holds the vcard data'''
1142 jid = vcard['jid']
1143 resource = vcard.get('resource', '')
1144 fjid = jid + '/' + str(resource)
1146 # vcard window
1147 win = None
1148 if jid in self.instances[account]['infos']:
1149 win = self.instances[account]['infos'][jid]
1150 elif resource and fjid in self.instances[account]['infos']:
1151 win = self.instances[account]['infos'][fjid]
1152 if win:
1153 win.set_values(vcard)
1155 # show avatar in chat
1156 ctrl = None
1157 if resource and self.msg_win_mgr.has_window(fjid, account):
1158 win = self.msg_win_mgr.get_window(fjid, account)
1159 ctrl = win.get_control(fjid, account)
1160 elif self.msg_win_mgr.has_window(jid, account):
1161 win = self.msg_win_mgr.get_window(jid, account)
1162 ctrl = win.get_control(jid, account)
1164 if ctrl and ctrl.type_id != message_control.TYPE_GC:
1165 ctrl.show_avatar()
1167 # Show avatar in roster or gc_roster
1168 gc_ctrl = self.msg_win_mgr.get_gc_control(jid, account)
1169 if not gc_ctrl and \
1170 jid in self.minimized_controls[account]:
1171 gc_ctrl = self.minimized_controls[account][jid]
1172 if gc_ctrl and gc_ctrl.type_id == message_control.TYPE_GC:
1173 gc_ctrl.draw_avatar(resource)
1174 else:
1175 self.roster.draw_avatar(jid, account)
1176 if self.remote_ctrl:
1177 self.remote_ctrl.raise_signal('VcardInfo', (account, vcard))
1179 def handle_event_last_status_time(self, account, array):
1180 # ('LAST_STATUS_TIME', account, (jid, resource, seconds, status))
1181 tim = array[2]
1182 if tim < 0:
1183 # Ann error occured
1184 return
1185 win = None
1186 if array[0] in self.instances[account]['infos']:
1187 win = self.instances[account]['infos'][array[0]]
1188 elif array[0] + '/' + array[1] in self.instances[account]['infos']:
1189 win = self.instances[account]['infos'][array[0] + '/' + array[1]]
1190 c = gajim.contacts.get_contact(account, array[0], array[1])
1191 if c: # c can be none if it's a gc contact
1192 c.last_status_time = time.localtime(time.time() - tim)
1193 if array[3]:
1194 c.status = array[3]
1195 self.roster.draw_contact(c.jid, account) # draw offline status
1196 if win:
1197 win.set_last_status_time()
1198 if self.remote_ctrl:
1199 self.remote_ctrl.raise_signal('LastStatusTime', (account, array))
1201 def handle_event_os_info(self, account, array):
1202 #'OS_INFO' (account, (jid, resource, client_info, os_info))
1203 win = None
1204 if array[0] in self.instances[account]['infos']:
1205 win = self.instances[account]['infos'][array[0]]
1206 elif array[0] + '/' + array[1] in self.instances[account]['infos']:
1207 win = self.instances[account]['infos'][array[0] + '/' + array[1]]
1208 if win:
1209 win.set_os_info(array[1], array[2], array[3])
1210 if self.remote_ctrl:
1211 self.remote_ctrl.raise_signal('OsInfo', (account, array))
1213 def handle_event_entity_time(self, account, array):
1214 #'ENTITY_TIME' (account, (jid, resource, time_info))
1215 win = None
1216 if array[0] in self.instances[account]['infos']:
1217 win = self.instances[account]['infos'][array[0]]
1218 elif array[0] + '/' + array[1] in self.instances[account]['infos']:
1219 win = self.instances[account]['infos'][array[0] + '/' + array[1]]
1220 if win:
1221 win.set_entity_time(array[1], array[2])
1222 if self.remote_ctrl:
1223 self.remote_ctrl.raise_signal('EntityTime', (account, array))
1225 def handle_event_gc_notify(self, account, array):
1226 #'GC_NOTIFY' (account, (room_jid, show, status, nick,
1227 # role, affiliation, jid, reason, actor, statusCode, newNick, avatar_sha))
1228 nick = array[3]
1229 if not nick:
1230 return
1231 room_jid = array[0]
1232 fjid = room_jid + '/' + nick
1233 show = array[1]
1234 status = array[2]
1236 # Get the window and control for the updated status, this may be a
1237 # PrivateChatControl
1238 control = self.msg_win_mgr.get_gc_control(room_jid, account)
1240 if not control and \
1241 room_jid in self.minimized_controls[account]:
1242 control = self.minimized_controls[account][room_jid]
1244 if not control or (control and control.type_id != message_control.TYPE_GC):
1245 return
1247 control.chg_contact_status(nick, show, status, array[4], array[5],
1248 array[6], array[7], array[8], array[9], array[10], array[11])
1250 contact = gajim.contacts.\
1251 get_contact_with_highest_priority(account, room_jid)
1252 if contact:
1253 self.roster.draw_contact(room_jid, account)
1255 # print status in chat window and update status/GPG image
1256 ctrl = self.msg_win_mgr.get_control(fjid, account)
1257 if ctrl:
1258 statusCode = array[9]
1259 if '303' in statusCode:
1260 new_nick = array[10]
1261 ctrl.print_conversation(_('%(nick)s is now known as %(new_nick)s') \
1262 % {'nick': nick, 'new_nick': new_nick}, 'status')
1263 gc_c = gajim.contacts.get_gc_contact(account, room_jid, new_nick)
1264 c = gajim.contacts.contact_from_gc_contact(gc_c)
1265 ctrl.gc_contact = gc_c
1266 ctrl.contact = c
1267 ctrl.draw_banner()
1268 old_jid = room_jid + '/' + nick
1269 new_jid = room_jid + '/' + new_nick
1270 self.msg_win_mgr.change_key(old_jid, new_jid, account)
1271 else:
1272 contact = ctrl.contact
1273 contact.show = show
1274 contact.status = status
1275 gc_contact = ctrl.gc_contact
1276 gc_contact.show = show
1277 gc_contact.status = status
1278 uf_show = helpers.get_uf_show(show)
1279 ctrl.print_conversation(_('%(nick)s is now %(status)s') % {
1280 'nick': nick, 'status': uf_show}, 'status')
1281 if status:
1282 ctrl.print_conversation(' (', 'status', simple=True)
1283 ctrl.print_conversation('%s' % (status), 'status', simple=True)
1284 ctrl.print_conversation(')', 'status', simple=True)
1285 ctrl.parent_win.redraw_tab(ctrl)
1286 ctrl.update_ui()
1287 if self.remote_ctrl:
1288 self.remote_ctrl.raise_signal('GCPresence', (account, array))
1290 def handle_event_gc_msg(self, account, array):
1291 # ('GC_MSG', account, (jid, msg, time, has_timestamp, htmlmsg,
1292 # [status_codes]))
1293 jids = array[0].split('/', 1)
1294 room_jid = jids[0]
1296 msg = array[1]
1298 gc_control = self.msg_win_mgr.get_gc_control(room_jid, account)
1299 if not gc_control and \
1300 room_jid in self.minimized_controls[account]:
1301 gc_control = self.minimized_controls[account][room_jid]
1303 if not gc_control:
1304 return
1305 xhtml = array[4]
1307 if gajim.config.get('ignore_incoming_xhtml'):
1308 xhtml = None
1309 if len(jids) == 1:
1310 # message from server
1311 nick = ''
1312 else:
1313 # message from someone
1314 nick = jids[1]
1316 gc_control.on_message(nick, msg, array[2], array[3], xhtml, array[5])
1318 if self.remote_ctrl:
1319 highlight = gc_control.needs_visual_notification(msg)
1320 array += (highlight,)
1321 self.remote_ctrl.raise_signal('GCMessage', (account, array))
1323 def handle_event_gc_subject(self, account, array):
1324 #('GC_SUBJECT', account, (jid, subject, body, has_timestamp))
1325 jids = array[0].split('/', 1)
1326 jid = jids[0]
1328 gc_control = self.msg_win_mgr.get_gc_control(jid, account)
1330 if not gc_control and \
1331 jid in self.minimized_controls[account]:
1332 gc_control = self.minimized_controls[account][jid]
1334 contact = gajim.contacts.\
1335 get_contact_with_highest_priority(account, jid)
1336 if contact:
1337 contact.status = array[1]
1338 self.roster.draw_contact(jid, account)
1340 if not gc_control:
1341 return
1342 gc_control.set_subject(array[1])
1343 # Standard way, the message comes from the occupant who set the subject
1344 text = None
1345 if len(jids) > 1:
1346 text = _('%(jid)s has set the subject to %(subject)s') % {
1347 'jid': jids[1], 'subject': array[1]}
1348 # Workaround for psi bug http://flyspray.psi-im.org/task/595 , to be
1349 # deleted one day. We can receive a subject with a body that contains
1350 # "X has set the subject to Y" ...
1351 elif array[2]:
1352 text = array[2]
1353 if text is not None:
1354 if array[3]:
1355 gc_control.print_old_conversation(text)
1356 else:
1357 gc_control.print_conversation(text)
1359 def handle_event_gc_config(self, account, array):
1360 #('GC_CONFIG', account, (jid, form)) config is a dict
1361 room_jid = array[0].split('/')[0]
1362 if room_jid in gajim.automatic_rooms[account]:
1363 if 'continue_tag' in gajim.automatic_rooms[account][room_jid]:
1364 # We're converting chat to muc. allow participants to invite
1365 form = dataforms.ExtendForm(node = array[1])
1366 for f in form.iter_fields():
1367 if f.var == 'muc#roomconfig_allowinvites':
1368 f.value = True
1369 elif f.var == 'muc#roomconfig_publicroom':
1370 f.value = False
1371 elif f.var == 'muc#roomconfig_membersonly':
1372 f.value = True
1373 elif f.var == 'public_list':
1374 f.value = False
1375 gajim.connections[account].send_gc_config(room_jid, form)
1376 else:
1377 # use default configuration
1378 gajim.connections[account].send_gc_config(room_jid, array[1])
1379 # invite contacts
1380 # check if it is necessary to add <continue />
1381 continue_tag = False
1382 if 'continue_tag' in gajim.automatic_rooms[account][room_jid]:
1383 continue_tag = True
1384 if 'invities' in gajim.automatic_rooms[account][room_jid]:
1385 for jid in gajim.automatic_rooms[account][room_jid]['invities']:
1386 gajim.connections[account].send_invite(room_jid, jid,
1387 continue_tag=continue_tag)
1388 del gajim.automatic_rooms[account][room_jid]
1389 elif room_jid not in self.instances[account]['gc_config']:
1390 self.instances[account]['gc_config'][room_jid] = \
1391 config.GroupchatConfigWindow(account, room_jid, array[1])
1393 def handle_event_gc_config_change(self, account, array):
1394 #('GC_CONFIG_CHANGE', account, (jid, statusCode)) statuscode is a list
1395 # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
1396 # http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes-init
1397 jid = array[0]
1398 statusCode = array[1]
1400 gc_control = self.msg_win_mgr.get_gc_control(jid, account)
1401 if not gc_control and \
1402 jid in self.minimized_controls[account]:
1403 gc_control = self.minimized_controls[account][jid]
1404 if not gc_control:
1405 return
1407 changes = []
1408 if '100' in statusCode:
1409 # Can be a presence (see chg_contact_status in groupchat_control.py)
1410 changes.append(_('Any occupant is allowed to see your full JID'))
1411 gc_control.is_anonymous = False
1412 if '102' in statusCode:
1413 changes.append(_('Room now shows unavailable member'))
1414 if '103' in statusCode:
1415 changes.append(_('room now does not show unavailable members'))
1416 if '104' in statusCode:
1417 changes.append(
1418 _('A non-privacy-related room configuration change has occurred'))
1419 if '170' in statusCode:
1420 # Can be a presence (see chg_contact_status in groupchat_control.py)
1421 changes.append(_('Room logging is now enabled'))
1422 if '171' in statusCode:
1423 changes.append(_('Room logging is now disabled'))
1424 if '172' in statusCode:
1425 changes.append(_('Room is now non-anonymous'))
1426 gc_control.is_anonymous = False
1427 if '173' in statusCode:
1428 changes.append(_('Room is now semi-anonymous'))
1429 gc_control.is_anonymous = True
1430 if '174' in statusCode:
1431 changes.append(_('Room is now fully-anonymous'))
1432 gc_control.is_anonymous = True
1434 for change in changes:
1435 gc_control.print_conversation(change)
1437 def handle_event_gc_affiliation(self, account, array):
1438 #('GC_AFFILIATION', account, (room_jid, users_dict))
1439 room_jid = array[0]
1440 if room_jid in self.instances[account]['gc_config']:
1441 self.instances[account]['gc_config'][room_jid].\
1442 affiliation_list_received(array[1])
1444 def handle_event_gc_password_required(self, account, array):
1445 #('GC_PASSWORD_REQUIRED', account, (room_jid, nick))
1446 room_jid = array[0]
1447 nick = array[1]
1449 def on_ok(text):
1450 gajim.connections[account].join_gc(nick, room_jid, text)
1451 gajim.gc_passwords[room_jid] = text
1453 def on_cancel():
1454 # get and destroy window
1455 if room_jid in gajim.interface.minimized_controls[account]:
1456 self.roster.on_disconnect(None, room_jid, account)
1457 else:
1458 win = self.msg_win_mgr.get_window(room_jid, account)
1459 ctrl = self.msg_win_mgr.get_gc_control(room_jid, account)
1460 win.remove_tab(ctrl, 3)
1462 dlg = dialogs.InputDialog(_('Password Required'),
1463 _('A Password is required to join the room %s. Please type it.') % \
1464 room_jid, is_modal=False, ok_handler=on_ok, cancel_handler=on_cancel)
1465 dlg.input_entry.set_visibility(False)
1467 def handle_event_gc_invitation(self, account, array):
1468 #('GC_INVITATION', (room_jid, jid_from, reason, password, is_continued))
1469 jid = gajim.get_jid_without_resource(array[1])
1470 room_jid = array[0]
1471 if helpers.allow_popup_window(account) or not self.systray_enabled:
1472 dialogs.InvitationReceivedDialog(account, room_jid, jid, array[3],
1473 array[2], is_continued=array[4])
1474 return
1476 self.add_event(account, jid, 'gc-invitation', (room_jid, array[2],
1477 array[3], array[4]))
1479 if helpers.allow_showing_notification(account):
1480 path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
1481 'gc_invitation.png')
1482 path = gtkgui_helpers.get_path_to_generic_or_avatar(path)
1483 event_type = _('Groupchat Invitation')
1484 notify.popup(event_type, jid, account, 'gc-invitation', path,
1485 event_type, room_jid)
1487 def forget_gpg_passphrase(self, keyid):
1488 if keyid in self.gpg_passphrase:
1489 del self.gpg_passphrase[keyid]
1490 return False
1492 def handle_event_bad_passphrase(self, account, array):
1493 #('BAD_PASSPHRASE', account, ())
1494 use_gpg_agent = gajim.config.get('use_gpg_agent')
1495 sectext = ''
1496 if use_gpg_agent:
1497 sectext = _('You configured Gajim to use GPG agent, but there is no '
1498 'GPG agent running or it returned a wrong passphrase.\n')
1499 sectext += _('You are currently connected without your OpenPGP key.')
1500 keyID = gajim.config.get_per('accounts', account, 'keyid')
1501 self.forget_gpg_passphrase(keyID)
1502 dialogs.WarningDialog(_('Your passphrase is incorrect'), sectext)
1504 def handle_event_gpg_password_required(self, account, array):
1505 #('GPG_PASSWORD_REQUIRED', account, (callback,))
1506 callback = array[0]
1507 keyid = gajim.config.get_per('accounts', account, 'keyid')
1508 if keyid in self.gpg_passphrase:
1509 request = self.gpg_passphrase[keyid]
1510 else:
1511 request = PassphraseRequest(keyid)
1512 self.gpg_passphrase[keyid] = request
1513 request.add_callback(account, callback)
1515 def handle_event_gpg_always_trust(self, account, callback):
1516 #('GPG_ALWAYS_TRUST', account, callback)
1517 def on_yes(checked):
1518 if checked:
1519 gajim.connections[account].gpg.always_trust = True
1520 callback(True)
1522 def on_no():
1523 callback(False)
1525 dialogs.YesNoDialog(_('GPG key not trusted'), _('The GPG key used to '
1526 'encrypt this chat is not trusted. Do you really want to encrypt this '
1527 'message?'), checktext=_('Do _not ask me again'),
1528 on_response_yes=on_yes, on_response_no=on_no)
1530 def handle_event_password_required(self, account, array):
1531 #('PASSWORD_REQUIRED', account, None)
1532 if account in self.pass_dialog:
1533 return
1534 text = _('Enter your password for account %s') % account
1535 if passwords.USER_HAS_GNOMEKEYRING and \
1536 not passwords.USER_USES_GNOMEKEYRING:
1537 text += '\n' + _('Gnome Keyring is installed but not \
1538 correctly started (environment variable probably not \
1539 correctly set)')
1541 def on_ok(passphrase, save):
1542 if save:
1543 gajim.config.set_per('accounts', account, 'savepass', True)
1544 passwords.save_password(account, passphrase)
1545 gajim.connections[account].set_password(passphrase)
1546 del self.pass_dialog[account]
1548 def on_cancel():
1549 self.roster.set_state(account, 'offline')
1550 self.roster.update_status_combobox()
1551 del self.pass_dialog[account]
1553 self.pass_dialog[account] = dialogs.PassphraseDialog(
1554 _('Password Required'), text, _('Save password'), ok_handler=on_ok,
1555 cancel_handler=on_cancel)
1557 def handle_event_roster_info(self, account, array):
1558 #('ROSTER_INFO', account, (jid, name, sub, ask, groups))
1559 jid = array[0]
1560 name = array[1]
1561 sub = array[2]
1562 ask = array[3]
1563 groups = array[4]
1564 contacts = gajim.contacts.get_contacts(account, jid)
1565 if (not sub or sub == 'none') and (not ask or ask == 'none') and \
1566 not name and not groups:
1567 # contact removed us.
1568 if contacts:
1569 self.roster.remove_contact(jid, account, backend=True)
1570 return
1571 elif not contacts:
1572 if sub == 'remove':
1573 return
1574 # Add new contact to roster
1575 contact = gajim.contacts.create_contact(jid=jid, name=name,
1576 groups=groups, show='offline', sub=sub, ask=ask)
1577 gajim.contacts.add_contact(account, contact)
1578 self.roster.add_contact(jid, account)
1579 else:
1580 # it is an existing contact that might has changed
1581 re_place = False
1582 # If contact has changed (sub, ask or group) update roster
1583 # Mind about observer status changes:
1584 # According to xep 0162, a contact is not an observer anymore when
1585 # we asked for auth, so also remove him if ask changed
1586 old_groups = contacts[0].groups
1587 if contacts[0].sub != sub or contacts[0].ask != ask\
1588 or old_groups != groups:
1589 re_place = True
1590 # c.get_shown_groups() has changed. Reflect that in roster_winodow
1591 self.roster.remove_contact(jid, account, force=True)
1592 for contact in contacts:
1593 contact.name = name or ''
1594 contact.sub = sub
1595 contact.ask = ask
1596 contact.groups = groups or []
1597 if re_place:
1598 self.roster.add_contact(jid, account)
1599 # Refilter and update old groups
1600 for group in old_groups:
1601 self.roster.draw_group(group, account)
1602 else:
1603 self.roster.draw_contact(jid, account)
1605 if self.remote_ctrl:
1606 self.remote_ctrl.raise_signal('RosterInfo', (account, array))
1608 def handle_event_bookmarks(self, account, bms):
1609 # ('BOOKMARKS', account, [{name,jid,autojoin,password,nick}, {}])
1610 # We received a bookmark item from the server (JEP48)
1611 # Auto join GC windows if neccessary
1613 self.roster.set_actions_menu_needs_rebuild()
1614 invisible_show = gajim.SHOW_LIST.index('invisible')
1615 # do not autojoin if we are invisible
1616 if gajim.connections[account].connected == invisible_show:
1617 return
1619 self.auto_join_bookmarks(account)
1621 def handle_event_file_send_error(self, account, array):
1622 jid = array[0]
1623 file_props = array[1]
1624 ft = self.instances['file_transfers']
1625 ft.set_status(file_props['type'], file_props['sid'], 'stop')
1627 if helpers.allow_popup_window(account):
1628 ft.show_send_error(file_props)
1629 return
1631 self.add_event(account, jid, 'file-send-error', file_props)
1633 if helpers.allow_showing_notification(account):
1634 img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'ft_error.png')
1635 path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
1636 event_type = _('File Transfer Error')
1637 notify.popup(event_type, jid, account, 'file-send-error', path,
1638 event_type, file_props['name'])
1640 def handle_event_gmail_notify(self, account, array):
1641 jid = array[0]
1642 gmail_new_messages = int(array[1])
1643 gmail_messages_list = array[2]
1644 if gajim.config.get('notify_on_new_gmail_email'):
1645 img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
1646 'new_email_recv.png')
1647 title = _('New mail on %(gmail_mail_address)s') % \
1648 {'gmail_mail_address': jid}
1649 text = i18n.ngettext('You have %d new mail conversation',
1650 'You have %d new mail conversations', gmail_new_messages,
1651 gmail_new_messages, gmail_new_messages)
1653 if gajim.config.get('notify_on_new_gmail_email_extra'):
1654 cnt = 0
1655 for gmessage in gmail_messages_list:
1656 #FIXME: emulate Gtalk client popups. find out what they parse and
1657 # how they decide what to show each message has a 'From',
1658 # 'Subject' and 'Snippet' field
1659 if cnt >=5:
1660 break
1661 senders = ',\n '.join(reversed(gmessage['From']))
1662 text += _('\n\nFrom: %(from_address)s\nSubject: %(subject)s\n%(snippet)s') % \
1663 {'from_address': senders, 'subject': gmessage['Subject'],
1664 'snippet': gmessage['Snippet']}
1665 cnt += 1
1667 if gajim.config.get_per('soundevents', 'gmail_received', 'enabled'):
1668 helpers.play_sound('gmail_received')
1669 path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
1670 notify.popup(_('New E-mail'), jid, account, 'gmail',
1671 path_to_image=path, title=title,
1672 text=text)
1674 if self.remote_ctrl:
1675 self.remote_ctrl.raise_signal('NewGmail', (account, array))
1677 def handle_event_file_request_error(self, account, array):
1678 # ('FILE_REQUEST_ERROR', account, (jid, file_props, error_msg))
1679 jid, file_props, errmsg = array
1680 ft = self.instances['file_transfers']
1681 ft.set_status(file_props['type'], file_props['sid'], 'stop')
1682 errno = file_props['error']
1684 if helpers.allow_popup_window(account):
1685 if errno in (-4, -5):
1686 ft.show_stopped(jid, file_props, errmsg)
1687 else:
1688 ft.show_request_error(file_props)
1689 return
1691 if errno in (-4, -5):
1692 msg_type = 'file-error'
1693 else:
1694 msg_type = 'file-request-error'
1696 self.add_event(account, jid, msg_type, file_props)
1698 if helpers.allow_showing_notification(account):
1699 # check if we should be notified
1700 img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'ft_error.png')
1702 path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
1703 event_type = _('File Transfer Error')
1704 notify.popup(event_type, jid, account, msg_type, path,
1705 title = event_type, text = file_props['name'])
1707 def handle_event_file_request(self, account, array):
1708 jid = array[0]
1709 if jid not in gajim.contacts.get_jid_list(account):
1710 keyID = ''
1711 attached_keys = gajim.config.get_per('accounts', account,
1712 'attached_gpg_keys').split()
1713 if jid in attached_keys:
1714 keyID = attached_keys[attached_keys.index(jid) + 1]
1715 contact = gajim.contacts.create_contact(jid=jid, name='',
1716 groups=[_('Not in Roster')], show='not in roster', status='',
1717 sub='none', keyID=keyID)
1718 gajim.contacts.add_contact(account, contact)
1719 self.roster.add_contact(contact.jid, account)
1720 file_props = array[1]
1721 contact = gajim.contacts.get_first_contact_from_jid(account, jid)
1723 if helpers.allow_popup_window(account):
1724 self.instances['file_transfers'].show_file_request(account, contact,
1725 file_props)
1726 return
1728 self.add_event(account, jid, 'file-request', file_props)
1730 if helpers.allow_showing_notification(account):
1731 img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
1732 'ft_request.png')
1733 txt = _('%s wants to send you a file.') % gajim.get_name_from_jid(
1734 account, jid)
1735 path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
1736 event_type = _('File Transfer Request')
1737 notify.popup(event_type, jid, account, 'file-request',
1738 path_to_image = path, title = event_type, text = txt)
1740 def handle_event_file_error(self, title, message):
1741 dialogs.ErrorDialog(title, message)
1743 def handle_event_file_progress(self, account, file_props):
1744 if time.time() - self.last_ftwindow_update > 0.5:
1745 # update ft window every 500ms
1746 self.last_ftwindow_update = time.time()
1747 self.instances['file_transfers'].set_progress(file_props['type'],
1748 file_props['sid'], file_props['received-len'])
1750 def handle_event_file_rcv_completed(self, account, file_props):
1751 ft = self.instances['file_transfers']
1752 if file_props['error'] == 0:
1753 ft.set_progress(file_props['type'], file_props['sid'],
1754 file_props['received-len'])
1755 else:
1756 ft.set_status(file_props['type'], file_props['sid'], 'stop')
1757 if 'stalled' in file_props and file_props['stalled'] or \
1758 'paused' in file_props and file_props['paused']:
1759 return
1760 if file_props['type'] == 'r': # we receive a file
1761 jid = unicode(file_props['sender'])
1762 else: # we send a file
1763 jid = unicode(file_props['receiver'])
1765 if helpers.allow_popup_window(account):
1766 if file_props['error'] == 0:
1767 if gajim.config.get('notify_on_file_complete'):
1768 ft.show_completed(jid, file_props)
1769 elif file_props['error'] == -1:
1770 ft.show_stopped(jid, file_props)
1771 return
1773 msg_type = ''
1774 event_type = ''
1775 if file_props['error'] == 0 and gajim.config.get(
1776 'notify_on_file_complete'):
1777 msg_type = 'file-completed'
1778 event_type = _('File Transfer Completed')
1779 elif file_props['error'] == -1:
1780 msg_type = 'file-stopped'
1781 event_type = _('File Transfer Stopped')
1783 if event_type == '':
1784 # FIXME: ugly workaround (this can happen Gajim sent, Gaim recvs)
1785 # this should never happen but it does. see process_result() in socks5.py
1786 # who calls this func (sth is really wrong unless this func is also registered
1787 # as progress_cb
1788 return
1790 if msg_type:
1791 self.add_event(account, jid, msg_type, file_props)
1793 if file_props is not None:
1794 if file_props['type'] == 'r':
1795 # get the name of the sender, as it is in the roster
1796 sender = unicode(file_props['sender']).split('/')[0]
1797 name = gajim.contacts.get_first_contact_from_jid(account,
1798 sender).get_shown_name()
1799 filename = os.path.basename(file_props['file-name'])
1800 if event_type == _('File Transfer Completed'):
1801 txt = _('You successfully received %(filename)s from %(name)s.')\
1802 % {'filename': filename, 'name': name}
1803 img = 'ft_done.png'
1804 else: # ft stopped
1805 txt = _('File transfer of %(filename)s from %(name)s stopped.')\
1806 % {'filename': filename, 'name': name}
1807 img = 'ft_stopped.png'
1808 else:
1809 receiver = file_props['receiver']
1810 if hasattr(receiver, 'jid'):
1811 receiver = receiver.jid
1812 receiver = receiver.split('/')[0]
1813 # get the name of the contact, as it is in the roster
1814 name = gajim.contacts.get_first_contact_from_jid(account,
1815 receiver).get_shown_name()
1816 filename = os.path.basename(file_props['file-name'])
1817 if event_type == _('File Transfer Completed'):
1818 txt = _('You successfully sent %(filename)s to %(name)s.')\
1819 % {'filename': filename, 'name': name}
1820 img = 'ft_done.png'
1821 else: # ft stopped
1822 txt = _('File transfer of %(filename)s to %(name)s stopped.')\
1823 % {'filename': filename, 'name': name}
1824 img = 'ft_stopped.png'
1825 img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img)
1826 path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
1827 else:
1828 txt = ''
1830 if gajim.config.get('notify_on_file_complete') and \
1831 (gajim.config.get('autopopupaway') or \
1832 gajim.connections[account].connected in (2, 3)):
1833 # we want to be notified and we are online/chat or we don't mind
1834 # bugged when away/na/busy
1835 notify.popup(event_type, jid, account, msg_type, path_to_image = path,
1836 title = event_type, text = txt)
1838 def handle_event_stanza_arrived(self, account, stanza):
1839 if account not in self.instances:
1840 return
1841 if 'xml_console' in self.instances[account]:
1842 self.instances[account]['xml_console'].print_stanza(stanza, 'incoming')
1844 def handle_event_stanza_sent(self, account, stanza):
1845 if account not in self.instances:
1846 return
1847 if 'xml_console' in self.instances[account]:
1848 self.instances[account]['xml_console'].print_stanza(stanza, 'outgoing')
1850 def handle_event_vcard_published(self, account, array):
1851 if 'profile' in self.instances[account]:
1852 win = self.instances[account]['profile']
1853 win.vcard_published()
1854 for gc_control in self.msg_win_mgr.get_controls(message_control.TYPE_GC) + \
1855 self.minimized_controls[account].values():
1856 if gc_control.account == account:
1857 show = gajim.SHOW_LIST[gajim.connections[account].connected]
1858 status = gajim.connections[account].status
1859 gajim.connections[account].send_gc_status(gc_control.nick,
1860 gc_control.room_jid, show, status)
1862 def handle_event_vcard_not_published(self, account, array):
1863 if 'profile' in self.instances[account]:
1864 win = self.instances[account]['profile']
1865 win.vcard_not_published()
1867 def ask_offline_status(self, account):
1868 for contact in gajim.contacts.iter_contacts(account):
1869 gajim.connections[account].request_last_status_time(contact.jid,
1870 contact.resource)
1872 def handle_event_signed_in(self, account, empty):
1873 '''SIGNED_IN event is emitted when we sign in, so handle it'''
1874 # block signed in notifications for 30 seconds
1875 gajim.block_signed_in_notifications[account] = True
1876 self.roster.set_actions_menu_needs_rebuild()
1877 self.roster.draw_account(account)
1878 state = self.sleeper.getState()
1879 connected = gajim.connections[account].connected
1880 if gajim.config.get('ask_offline_status_on_connection'):
1881 # Ask offline status in 1 minute so w'are sure we got all online
1882 # presences
1883 gobject.timeout_add_seconds(60, self.ask_offline_status, account)
1884 if state != common.sleepy.STATE_UNKNOWN and connected in (2, 3):
1885 # we go online or free for chat, so we activate auto status
1886 gajim.sleeper_state[account] = 'online'
1887 elif not ((state == common.sleepy.STATE_AWAY and connected == 4) or \
1888 (state == common.sleepy.STATE_XA and connected == 5)):
1889 # If we are autoaway/xa and come back after a disconnection, do nothing
1890 # Else disable autoaway
1891 gajim.sleeper_state[account] = 'off'
1892 invisible_show = gajim.SHOW_LIST.index('invisible')
1893 # We cannot join rooms if we are invisible
1894 if gajim.connections[account].connected == invisible_show:
1895 return
1896 # join already open groupchats
1897 for gc_control in self.msg_win_mgr.get_controls(message_control.TYPE_GC) \
1898 + self.minimized_controls[account].values():
1899 if account != gc_control.account:
1900 continue
1901 room_jid = gc_control.room_jid
1902 if room_jid in gajim.gc_connected[account] and \
1903 gajim.gc_connected[account][room_jid]:
1904 continue
1905 nick = gc_control.nick
1906 password = gajim.gc_passwords.get(room_jid, '')
1907 gajim.connections[account].join_gc(nick, room_jid, password)
1909 def handle_event_metacontacts(self, account, tags_list):
1910 gajim.contacts.define_metacontacts(account, tags_list)
1912 def handle_atom_entry(self, account, data):
1913 atom_entry, = data
1914 AtomWindow.newAtomEntry(atom_entry)
1916 def handle_event_failed_decrypt(self, account, data):
1917 jid, tim, session = data
1919 details = _('Unable to decrypt message from '
1920 '%s\nIt may have been tampered with.') % jid
1922 ctrl = session.control
1923 if ctrl:
1924 ctrl.print_conversation_line(details, 'status', '', tim)
1925 else:
1926 dialogs.WarningDialog(_('Unable to decrypt message'),
1927 details)
1929 # terminate the session
1930 session.terminate_e2e()
1931 session.conn.delete_session(jid, session.thread_id)
1933 # restart the session
1934 if ctrl:
1935 ctrl.begin_e2e_negotiation()
1937 def handle_event_privacy_lists_received(self, account, data):
1938 # ('PRIVACY_LISTS_RECEIVED', account, list)
1939 if account not in self.instances:
1940 return
1941 if 'privacy_lists' in self.instances[account]:
1942 self.instances[account]['privacy_lists'].privacy_lists_received(data)
1944 def handle_event_privacy_list_received(self, account, data):
1945 # ('PRIVACY_LIST_RECEIVED', account, (name, rules))
1946 if account not in self.instances:
1947 return
1948 name = data[0]
1949 rules = data[1]
1950 if 'privacy_list_%s' % name in self.instances[account]:
1951 self.instances[account]['privacy_list_%s' % name].\
1952 privacy_list_received(rules)
1953 if name == 'block':
1954 gajim.connections[account].blocked_contacts = []
1955 gajim.connections[account].blocked_groups = []
1956 gajim.connections[account].blocked_list = []
1957 gajim.connections[account].blocked_all = False
1958 for rule in rules:
1959 if not 'type' in rule:
1960 gajim.connections[account].blocked_all = True
1961 elif rule['type'] == 'jid' and rule['action'] == 'deny':
1962 gajim.connections[account].blocked_contacts.append(rule['value'])
1963 elif rule['type'] == 'group' and rule['action'] == 'deny':
1964 gajim.connections[account].blocked_groups.append(rule['value'])
1965 gajim.connections[account].blocked_list.append(rule)
1966 #elif rule['type'] == "group" and action == "deny":
1967 # text_item = _('%s group "%s"') % _(rule['action']), rule['value']
1968 # self.store.append([text_item])
1969 # self.global_rules.append(rule)
1970 #else:
1971 # self.global_rules_to_append.append(rule)
1972 if 'blocked_contacts' in self.instances[account]:
1973 self.instances[account]['blocked_contacts'].\
1974 privacy_list_received(rules)
1976 def handle_event_privacy_lists_active_default(self, account, data):
1977 if not data:
1978 return
1979 # Send to all privacy_list_* windows as we can't know which one asked
1980 for win in self.instances[account]:
1981 if win.startswith('privacy_list_'):
1982 self.instances[account][win].check_active_default(data)
1984 def handle_event_privacy_list_removed(self, account, name):
1985 # ('PRIVACY_LISTS_REMOVED', account, name)
1986 if account not in self.instances:
1987 return
1988 if 'privacy_lists' in self.instances[account]:
1989 self.instances[account]['privacy_lists'].privacy_list_removed(name)
1991 def handle_event_zc_name_conflict(self, account, data):
1992 def on_ok(new_name):
1993 gajim.config.set_per('accounts', account, 'name', new_name)
1994 status = gajim.connections[account].status
1995 gajim.connections[account].username = new_name
1996 gajim.connections[account].change_status(status, '')
1997 def on_cancel():
1998 gajim.connections[account].change_status('offline','')
2000 dlg = dialogs.InputDialog(_('Username Conflict'),
2001 _('Please type a new username for your local account'), input_str=data,
2002 is_modal=True, ok_handler=on_ok, cancel_handler=on_cancel)
2004 def handle_event_ping_sent(self, account, contact):
2005 if contact.jid == contact.get_full_jid():
2006 # If contact is a groupchat user
2007 jids = [contact.jid]
2008 else:
2009 jids = [contact.jid, contact.get_full_jid()]
2010 for jid in jids:
2011 ctrl = self.msg_win_mgr.get_control(jid, account)
2012 if ctrl:
2013 ctrl.print_conversation(_('Ping?'), 'status')
2015 def handle_event_ping_reply(self, account, data):
2016 contact = data[0]
2017 seconds = data[1]
2018 if contact.jid == contact.get_full_jid():
2019 # If contact is a groupchat user
2020 jids = [contact.jid]
2021 else:
2022 jids = [contact.jid, contact.get_full_jid()]
2023 for jid in jids:
2024 ctrl = self.msg_win_mgr.get_control(jid, account)
2025 if ctrl:
2026 ctrl.print_conversation(_('Pong! (%s s.)') % seconds, 'status')
2028 def handle_event_ping_error(self, account, contact):
2029 if contact.jid == contact.get_full_jid():
2030 # If contact is a groupchat user
2031 jids = [contact.jid]
2032 else:
2033 jids = [contact.jid, contact.get_full_jid()]
2034 for jid in jids:
2035 ctrl = self.msg_win_mgr.get_control(jid, account)
2036 if ctrl:
2037 ctrl.print_conversation(_('Error.'), 'status')
2039 def handle_event_search_form(self, account, data):
2040 # ('SEARCH_FORM', account, (jid, dataform, is_dataform))
2041 if data[0] not in self.instances[account]['search']:
2042 return
2043 self.instances[account]['search'][data[0]].on_form_arrived(data[1],
2044 data[2])
2046 def handle_event_search_result(self, account, data):
2047 # ('SEARCH_RESULT', account, (jid, dataform, is_dataform))
2048 if data[0] not in self.instances[account]['search']:
2049 return
2050 self.instances[account]['search'][data[0]].on_result_arrived(data[1],
2051 data[2])
2053 def handle_event_resource_conflict(self, account, data):
2054 # ('RESOURCE_CONFLICT', account, ())
2055 # First we go offline, but we don't overwrite status message
2056 self.roster.send_status(account, 'offline',
2057 gajim.connections[account].status)
2058 def on_ok(new_resource):
2059 gajim.config.set_per('accounts', account, 'resource', new_resource)
2060 self.roster.send_status(account, gajim.connections[account].old_show,
2061 gajim.connections[account].status)
2062 dlg = dialogs.InputDialog(_('Resource Conflict'),
2063 _('You are already connected to this account with the same resource. Please type a new one'), input_str = gajim.connections[account].server_resource,
2064 is_modal = False, ok_handler = on_ok)
2066 def handle_event_pep_config(self, account, data):
2067 # ('PEP_CONFIG', account, (node, form))
2068 if 'pep_services' in self.instances[account]:
2069 self.instances[account]['pep_services'].config(data[0], data[1])
2071 def handle_event_roster_item_exchange(self, account, data):
2072 # data = (action in [add, delete, modify], exchange_list, jid_from)
2073 dialogs.RosterItemExchangeWindow(account, data[0], data[1], data[2])
2075 def handle_event_unique_room_id_supported(self, account, data):
2076 '''Receive confirmation that unique_room_id are supported'''
2077 # ('UNIQUE_ROOM_ID_SUPPORTED', server, instance, room_id)
2078 instance = data[1]
2079 instance.unique_room_id_supported(data[0], data[2])
2081 def handle_event_unique_room_id_unsupported(self, account, data):
2082 # ('UNIQUE_ROOM_ID_UNSUPPORTED', server, instance)
2083 instance = data[1]
2084 instance.unique_room_id_error(data[0])
2086 def handle_event_ssl_error(self, account, data):
2087 # ('SSL_ERROR', account, (text, errnum, cert, sha1_fingerprint))
2088 server = gajim.config.get_per('accounts', account, 'hostname')
2090 def on_ok(is_checked):
2091 del self.instances[account]['online_dialog']['ssl_error']
2092 if is_checked[0]:
2093 # Check if cert is already in file
2094 certs = ''
2095 if os.path.isfile(gajim.MY_CACERTS):
2096 f = open(gajim.MY_CACERTS)
2097 certs = f.read()
2098 f.close()
2099 if data[2] in certs:
2100 dialogs.ErrorDialog(_('Certificate Already in File'),
2101 _('This certificate is already in file %s, so it\'s not added again.') % gajim.MY_CACERTS)
2102 else:
2103 f = open(gajim.MY_CACERTS, 'a')
2104 f.write(server + '\n')
2105 f.write(data[2] + '\n\n')
2106 f.close()
2107 gajim.config.set_per('accounts', account, 'ssl_fingerprint_sha1',
2108 data[3])
2109 if is_checked[1]:
2110 ignore_ssl_errors = gajim.config.get_per('accounts', account,
2111 'ignore_ssl_errors').split()
2112 ignore_ssl_errors.append(str(data[1]))
2113 gajim.config.set_per('accounts', account, 'ignore_ssl_errors',
2114 ' '.join(ignore_ssl_errors))
2115 gajim.connections[account].ssl_certificate_accepted()
2117 def on_cancel():
2118 del self.instances[account]['online_dialog']['ssl_error']
2119 gajim.connections[account].disconnect(on_purpose=True)
2120 self.handle_event_status(account, 'offline')
2122 pritext = _('Error verifying SSL certificate')
2123 sectext = _('There was an error verifying the SSL certificate of your jabber server: %(error)s\nDo you still want to connect to this server?') % {'error': data[0]}
2124 if data[1] in (18, 27):
2125 checktext1 = _('Add this certificate to the list of trusted certificates.\nSHA1 fingerprint of the certificate:\n%s') % data[3]
2126 else:
2127 checktext1 = ''
2128 checktext2 = _('Ignore this error for this certificate.')
2129 if 'ssl_error' in self.instances[account]['online_dialog']:
2130 self.instances[account]['online_dialog']['ssl_error'].destroy()
2131 self.instances[account]['online_dialog']['ssl_error'] = \
2132 dialogs.ConfirmationDialogDubbleCheck(pritext, sectext, checktext1,
2133 checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel)
2135 def handle_event_fingerprint_error(self, account, data):
2136 # ('FINGERPRINT_ERROR', account, (new_fingerprint,))
2137 def on_yes(is_checked):
2138 del self.instances[account]['online_dialog']['fingerprint_error']
2139 gajim.config.set_per('accounts', account, 'ssl_fingerprint_sha1',
2140 data[0])
2141 # Reset the ignored ssl errors
2142 gajim.config.set_per('accounts', account, 'ignore_ssl_errors', '')
2143 gajim.connections[account].ssl_certificate_accepted()
2144 def on_no():
2145 del self.instances[account]['online_dialog']['fingerprint_error']
2146 gajim.connections[account].disconnect(on_purpose=True)
2147 self.handle_event_status(account, 'offline')
2148 pritext = _('SSL certificate error')
2149 sectext = _('It seems the SSL certificate of account %(account)s has '
2150 'changed or your connection is being hacked.\nOld fingerprint: %(old)s'
2151 '\nNew fingerprint: %(new)s\n\nDo you still want to connect and update'
2152 ' the fingerprint of the certificate?') % {'account': account,
2153 'old': gajim.config.get_per('accounts', account,
2154 'ssl_fingerprint_sha1'), 'new': data[0]}
2155 if 'fingerprint_error' in self.instances[account]['online_dialog']:
2156 self.instances[account]['online_dialog']['fingerprint_error'].destroy()
2157 self.instances[account]['online_dialog']['fingerprint_error'] = \
2158 dialogs.YesNoDialog(pritext, sectext, on_response_yes=on_yes,
2159 on_response_no=on_no)
2161 def handle_event_plain_connection(self, account, data):
2162 # ('PLAIN_CONNECTION', account, (connection))
2163 server = gajim.config.get_per('accounts', account, 'hostname')
2164 def on_ok(is_checked):
2165 if not is_checked[0]:
2166 on_cancel()
2167 return
2168 # On cancel call del self.instances, so don't call it another time
2169 # before
2170 del self.instances[account]['online_dialog']['plain_connection']
2171 if is_checked[1]:
2172 gajim.config.set_per('accounts', account,
2173 'warn_when_plaintext_connection', False)
2174 gajim.connections[account].connection_accepted(data[0], 'plain')
2175 def on_cancel():
2176 del self.instances[account]['online_dialog']['plain_connection']
2177 gajim.connections[account].disconnect(on_purpose=True)
2178 self.handle_event_status(account, 'offline')
2179 pritext = _('Insecure connection')
2180 sectext = _('You are about to send your password on an unencrypted '
2181 'connection. Are you sure you want to do that?')
2182 checktext1 = _('Yes, I really want to connect insecurely')
2183 checktext2 = _('Do _not ask me again')
2184 if 'plain_connection' in self.instances[account]['online_dialog']:
2185 self.instances[account]['online_dialog']['plain_connection'].destroy()
2186 self.instances[account]['online_dialog']['plain_connection'] = \
2187 dialogs.ConfirmationDialogDubbleCheck(pritext, sectext,
2188 checktext1, checktext2, on_response_ok=on_ok,
2189 on_response_cancel=on_cancel, is_modal=False)
2191 def handle_event_insecure_ssl_connection(self, account, data):
2192 # ('INSECURE_SSL_CONNECTION', account, (connection, connection_type))
2193 server = gajim.config.get_per('accounts', account, 'hostname')
2194 def on_ok(is_checked):
2195 del self.instances[account]['online_dialog']['insecure_ssl']
2196 if not is_checked[0]:
2197 on_cancel()
2198 return
2199 if is_checked[1]:
2200 gajim.config.set_per('accounts', account,
2201 'warn_when_insecure_ssl_connection', False)
2202 if gajim.connections[account].connected == 0:
2203 # We have been disconnecting (too long time since window is opened)
2204 # re-connect with auto-accept
2205 gajim.connections[account].connection_auto_accepted = True
2206 show, msg = gajim.connections[account].continue_connect_info[:2]
2207 self.roster.send_status(account, show, msg)
2208 return
2209 gajim.connections[account].connection_accepted(data[0], data[1])
2210 def on_cancel():
2211 del self.instances[account]['online_dialog']['insecure_ssl']
2212 gajim.connections[account].disconnect(on_purpose=True)
2213 self.handle_event_status(account, 'offline')
2214 pritext = _('Insecure connection')
2215 sectext = _('You are about to send your password on an insecure '
2216 'connection. You should install PyOpenSSL to prevent that. Are you sure you want to do that?')
2217 checktext1 = _('Yes, I really want to connect insecurely')
2218 checktext2 = _('Do _not ask me again')
2219 if 'insecure_ssl' in self.instances[account]['online_dialog']:
2220 self.instances[account]['online_dialog']['insecure_ssl'].destroy()
2221 self.instances[account]['online_dialog']['insecure_ssl'] = \
2222 dialogs.ConfirmationDialogDubbleCheck(pritext, sectext,
2223 checktext1, checktext2, on_response_ok=on_ok,
2224 on_response_cancel=on_cancel, is_modal=False)
2226 def handle_event_pubsub_node_removed(self, account, data):
2227 # ('PUBSUB_NODE_REMOVED', account, (jid, node))
2228 if 'pep_services' in self.instances[account]:
2229 if data[0] == gajim.get_jid_from_account(account):
2230 self.instances[account]['pep_services'].node_removed(data[1])
2232 def handle_event_pubsub_node_not_removed(self, account, data):
2233 # ('PUBSUB_NODE_NOT_REMOVED', account, (jid, node, msg))
2234 if data[0] == gajim.get_jid_from_account(account):
2235 dialogs.WarningDialog(_('PEP node was not removed'),
2236 _('PEP node %(node)s was not removed: %(message)s') % {
2237 'node': data[1], 'message': data[2]})
2239 def register_handlers(self):
2240 self.handlers = {
2241 'ROSTER': self.handle_event_roster,
2242 'WARNING': self.handle_event_warning,
2243 'ERROR': self.handle_event_error,
2244 'INFORMATION': self.handle_event_information,
2245 'ERROR_ANSWER': self.handle_event_error_answer,
2246 'STATUS': self.handle_event_status,
2247 'NOTIFY': self.handle_event_notify,
2248 'MSGERROR': self.handle_event_msgerror,
2249 'MSGSENT': self.handle_event_msgsent,
2250 'MSGNOTSENT': self.handle_event_msgnotsent,
2251 'SUBSCRIBED': self.handle_event_subscribed,
2252 'UNSUBSCRIBED': self.handle_event_unsubscribed,
2253 'SUBSCRIBE': self.handle_event_subscribe,
2254 'AGENT_ERROR_INFO': self.handle_event_agent_info_error,
2255 'AGENT_ERROR_ITEMS': self.handle_event_agent_items_error,
2256 'AGENT_REMOVED': self.handle_event_agent_removed,
2257 'REGISTER_AGENT_INFO': self.handle_event_register_agent_info,
2258 'AGENT_INFO_ITEMS': self.handle_event_agent_info_items,
2259 'AGENT_INFO_INFO': self.handle_event_agent_info_info,
2260 'QUIT': self.handle_event_quit,
2261 'NEW_ACC_CONNECTED': self.handle_event_new_acc_connected,
2262 'NEW_ACC_NOT_CONNECTED': self.handle_event_new_acc_not_connected,
2263 'ACC_OK': self.handle_event_acc_ok,
2264 'ACC_NOT_OK': self.handle_event_acc_not_ok,
2265 'MYVCARD': self.handle_event_myvcard,
2266 'VCARD': self.handle_event_vcard,
2267 'LAST_STATUS_TIME': self.handle_event_last_status_time,
2268 'OS_INFO': self.handle_event_os_info,
2269 'ENTITY_TIME': self.handle_event_entity_time,
2270 'GC_NOTIFY': self.handle_event_gc_notify,
2271 'GC_MSG': self.handle_event_gc_msg,
2272 'GC_SUBJECT': self.handle_event_gc_subject,
2273 'GC_CONFIG': self.handle_event_gc_config,
2274 'GC_CONFIG_CHANGE': self.handle_event_gc_config_change,
2275 'GC_INVITATION': self.handle_event_gc_invitation,
2276 'GC_AFFILIATION': self.handle_event_gc_affiliation,
2277 'GC_PASSWORD_REQUIRED': self.handle_event_gc_password_required,
2278 'BAD_PASSPHRASE': self.handle_event_bad_passphrase,
2279 'ROSTER_INFO': self.handle_event_roster_info,
2280 'BOOKMARKS': self.handle_event_bookmarks,
2281 'CON_TYPE': self.handle_event_con_type,
2282 'CONNECTION_LOST': self.handle_event_connection_lost,
2283 'FILE_REQUEST': self.handle_event_file_request,
2284 'GMAIL_NOTIFY': self.handle_event_gmail_notify,
2285 'FILE_REQUEST_ERROR': self.handle_event_file_request_error,
2286 'FILE_SEND_ERROR': self.handle_event_file_send_error,
2287 'STANZA_ARRIVED': self.handle_event_stanza_arrived,
2288 'STANZA_SENT': self.handle_event_stanza_sent,
2289 'HTTP_AUTH': self.handle_event_http_auth,
2290 'VCARD_PUBLISHED': self.handle_event_vcard_published,
2291 'VCARD_NOT_PUBLISHED': self.handle_event_vcard_not_published,
2292 'ASK_NEW_NICK': self.handle_event_ask_new_nick,
2293 'SIGNED_IN': self.handle_event_signed_in,
2294 'METACONTACTS': self.handle_event_metacontacts,
2295 'ATOM_ENTRY': self.handle_atom_entry,
2296 'FAILED_DECRYPT': self.handle_event_failed_decrypt,
2297 'PRIVACY_LISTS_RECEIVED': self.handle_event_privacy_lists_received,
2298 'PRIVACY_LIST_RECEIVED': self.handle_event_privacy_list_received,
2299 'PRIVACY_LISTS_ACTIVE_DEFAULT': \
2300 self.handle_event_privacy_lists_active_default,
2301 'PRIVACY_LIST_REMOVED': self.handle_event_privacy_list_removed,
2302 'ZC_NAME_CONFLICT': self.handle_event_zc_name_conflict,
2303 'PING_SENT': self.handle_event_ping_sent,
2304 'PING_REPLY': self.handle_event_ping_reply,
2305 'PING_ERROR': self.handle_event_ping_error,
2306 'SEARCH_FORM': self.handle_event_search_form,
2307 'SEARCH_RESULT': self.handle_event_search_result,
2308 'RESOURCE_CONFLICT': self.handle_event_resource_conflict,
2309 'ROSTERX': self.handle_event_roster_item_exchange,
2310 'PEP_CONFIG': self.handle_event_pep_config,
2311 'UNIQUE_ROOM_ID_UNSUPPORTED': \
2312 self.handle_event_unique_room_id_unsupported,
2313 'UNIQUE_ROOM_ID_SUPPORTED': self.handle_event_unique_room_id_supported,
2314 'GPG_PASSWORD_REQUIRED': self.handle_event_gpg_password_required,
2315 'GPG_ALWAYS_TRUST': self.handle_event_gpg_always_trust,
2316 'PASSWORD_REQUIRED': self.handle_event_password_required,
2317 'SSL_ERROR': self.handle_event_ssl_error,
2318 'FINGERPRINT_ERROR': self.handle_event_fingerprint_error,
2319 'PLAIN_CONNECTION': self.handle_event_plain_connection,
2320 'INSECURE_SSL_CONNECTION': self.handle_event_insecure_ssl_connection,
2321 'PUBSUB_NODE_REMOVED': self.handle_event_pubsub_node_removed,
2322 'PUBSUB_NODE_NOT_REMOVED': self.handle_event_pubsub_node_not_removed,
2324 gajim.handlers = self.handlers
2326 ################################################################################
2327 ### Methods dealing with gajim.events
2328 ################################################################################
2330 def add_event(self, account, jid, type_, event_args):
2331 '''add an event to the gajim.events var'''
2332 # We add it to the gajim.events queue
2333 # Do we have a queue?
2334 jid = gajim.get_jid_without_resource(jid)
2335 no_queue = len(gajim.events.get_events(account, jid)) == 0
2336 # type_ can be gc-invitation file-send-error file-error file-request-error
2337 # file-request file-completed file-stopped
2338 # event_type can be in advancedNotificationWindow.events_list
2339 event_types = {'file-request': 'ft_request',
2340 'file-completed': 'ft_finished'}
2341 event_type = event_types.get(type_)
2342 show_in_roster = notify.get_show_in_roster(event_type, account, jid)
2343 show_in_systray = notify.get_show_in_systray(event_type, account, jid)
2344 event = gajim.events.create_event(type_, event_args,
2345 show_in_roster=show_in_roster,
2346 show_in_systray=show_in_systray)
2347 gajim.events.add_event(account, jid, event)
2349 self.roster.show_title()
2350 if no_queue: # We didn't have a queue: we change icons
2351 if not gajim.contacts.get_contact_with_highest_priority(account, jid):
2352 if type_ == 'gc-invitation':
2353 self.roster.add_groupchat(jid, account, status='offline')
2354 else:
2355 # add contact to roster ("Not In The Roster") if he is not
2356 self.roster.add_to_not_in_the_roster(account, jid)
2357 else:
2358 self.roster.draw_contact(jid, account)
2360 # Select the big brother contact in roster, it's visible because it has
2361 # events.
2362 family = gajim.contacts.get_metacontacts_family(account, jid)
2363 if family:
2364 nearby_family, bb_jid, bb_account = \
2365 self.roster._get_nearby_family_and_big_brother(family, account)
2366 else:
2367 bb_jid, bb_account = jid, account
2368 self.roster.select_contact(bb_jid, bb_account)
2370 def handle_event(self, account, fjid, type_):
2371 w = None
2372 ctrl = None
2373 session = None
2375 resource = gajim.get_resource_from_jid(fjid)
2376 jid = gajim.get_jid_without_resource(fjid)
2378 if type_ in ('printed_gc_msg', 'printed_marked_gc_msg', 'gc_msg'):
2379 w = self.msg_win_mgr.get_window(jid, account)
2380 if jid in self.minimized_controls[account]:
2381 self.roster.on_groupchat_maximized(None, jid, account)
2382 return
2383 else:
2384 ctrl = self.msg_win_mgr.get_gc_control(jid, account)
2386 elif type_ in ('printed_chat', 'chat', ''):
2387 # '' is for log in/out notifications
2389 if type_ != '':
2390 event = gajim.events.get_first_event(account, fjid, type_)
2391 if not event:
2392 event = gajim.events.get_first_event(account, jid, type_)
2393 if not event:
2394 return
2396 if type_ == 'printed_chat':
2397 ctrl = event.parameters[0]
2398 elif type_ == 'chat':
2399 session = event.parameters[8]
2400 ctrl = session.control
2401 elif type_ == '':
2402 ctrl = self.msg_win_mgr.get_control(fjid, account)
2404 if not ctrl:
2405 highest_contact = gajim.contacts.get_contact_with_highest_priority(
2406 account, jid)
2407 # jid can have a window if this resource was lower when he sent
2408 # message and is now higher because the other one is offline
2409 if resource and highest_contact.resource == resource and \
2410 not self.msg_win_mgr.has_window(jid, account):
2411 # remove resource of events too
2412 gajim.events.change_jid(account, fjid, jid)
2413 resource = None
2414 fjid = jid
2415 contact = None
2416 if resource:
2417 contact = gajim.contacts.get_contact(account, jid, resource)
2418 if not contact:
2419 contact = highest_contact
2421 ctrl = self.new_chat(contact, account, resource = resource, session = session)
2423 gajim.last_message_time[account][jid] = 0 # long time ago
2425 w = ctrl.parent_win
2426 elif type_ in ('printed_pm', 'pm'):
2427 # assume that the most recently updated control we have for this party
2428 # is the one that this event was in
2429 event = gajim.events.get_first_event(account, fjid, type_)
2430 if not event:
2431 event = gajim.events.get_first_event(account, jid, type_)
2433 if type_ == 'printed_pm':
2434 ctrl = event.parameters[0]
2435 elif type_ == 'pm':
2436 session = event.parameters[8]
2438 if session and session.control:
2439 ctrl = session.control
2440 elif not ctrl:
2441 room_jid = jid
2442 nick = resource
2443 gc_contact = gajim.contacts.get_gc_contact(account, room_jid,
2444 nick)
2445 if gc_contact:
2446 show = gc_contact.show
2447 else:
2448 show = 'offline'
2449 gc_contact = gajim.contacts.create_gc_contact(
2450 room_jid = room_jid, name = nick, show = show)
2452 if not session:
2453 session = gajim.connections[account].make_new_session(
2454 fjid, None, type_='pm')
2456 self.new_private_chat(gc_contact, account, session=session)
2457 ctrl = session.control
2459 w = ctrl.parent_win
2460 elif type_ in ('normal', 'file-request', 'file-request-error',
2461 'file-send-error', 'file-error', 'file-stopped', 'file-completed'):
2462 # Get the first single message event
2463 event = gajim.events.get_first_event(account, fjid, type_)
2464 if not event:
2465 # default to jid without resource
2466 event = gajim.events.get_first_event(account, jid, type_)
2467 if not event:
2468 return
2469 # Open the window
2470 self.roster.open_event(account, jid, event)
2471 else:
2472 # Open the window
2473 self.roster.open_event(account, fjid, event)
2474 elif type_ == 'gmail':
2475 url=gajim.connections[account].gmail_url
2476 if url:
2477 helpers.launch_browser_mailer('url', url)
2478 elif type_ == 'gc-invitation':
2479 event = gajim.events.get_first_event(account, jid, type_)
2480 data = event.parameters
2481 dialogs.InvitationReceivedDialog(account, data[0], jid, data[2],
2482 data[1], data[3])
2483 gajim.events.remove_events(account, jid, event)
2484 self.roster.draw_contact(jid, account)
2485 elif type_ == 'subscription_request':
2486 event = gajim.events.get_first_event(account, jid, type_)
2487 data = event.parameters
2488 dialogs.SubscriptionRequestWindow(jid, data[0], account, data[1])
2489 gajim.events.remove_events(account, jid, event)
2490 self.roster.draw_contact(jid, account)
2491 elif type_ == 'unsubscribed':
2492 event = gajim.events.get_first_event(account, jid, type_)
2493 contact = event.parameters
2494 self.show_unsubscribed_dialog(account, contact)
2495 gajim.events.remove_events(account, jid, event)
2496 self.roster.draw_contact(jid, account)
2497 if w:
2498 w.set_active_tab(ctrl)
2499 w.window.window.focus()
2500 # Using isinstance here because we want to catch all derived types
2501 if isinstance(ctrl, ChatControlBase):
2502 tv = ctrl.conv_textview
2503 tv.scroll_to_end()
2505 ################################################################################
2506 ### Methods dealing with emoticons
2507 ################################################################################
2509 def image_is_ok(self, image):
2510 if not os.path.exists(image):
2511 return False
2512 img = gtk.Image()
2513 try:
2514 img.set_from_file(image)
2515 except Exception:
2516 return False
2517 t = img.get_storage_type()
2518 if t != gtk.IMAGE_PIXBUF and t != gtk.IMAGE_ANIMATION:
2519 return False
2520 return True
2522 @property
2523 def basic_pattern_re(self):
2524 try:
2525 return self._basic_pattern_re
2526 except AttributeError:
2527 self._basic_pattern_re = re.compile(self.basic_pattern, re.IGNORECASE)
2528 return self._basic_pattern_re
2530 @property
2531 def emot_and_basic_re(self):
2532 try:
2533 return self._emot_and_basic_re
2534 except AttributeError:
2535 self._emot_and_basic_re = re.compile(self.emot_and_basic,
2536 re.IGNORECASE + re.UNICODE)
2537 return self._emot_and_basic_re
2539 @property
2540 def sth_at_sth_dot_sth_re(self):
2541 try:
2542 return self._sth_at_sth_dot_sth_re
2543 except AttributeError:
2544 self._sth_at_sth_dot_sth_re = re.compile(self.sth_at_sth_dot_sth)
2545 return self._sth_at_sth_dot_sth_re
2547 @property
2548 def invalid_XML_chars_re(self):
2549 try:
2550 return self._invalid_XML_chars_re
2551 except AttributeError:
2552 self._invalid_XML_chars_re = re.compile(self.invalid_XML_chars)
2553 return self._invalid_XML_chars_re
2555 def make_regexps(self):
2556 # regexp meta characters are: . ^ $ * + ? { } [ ] \ | ( )
2557 # one escapes the metachars with \
2558 # \S matches anything but ' ' '\t' '\n' '\r' '\f' and '\v'
2559 # \s matches any whitespace character
2560 # \w any alphanumeric character
2561 # \W any non-alphanumeric character
2562 # \b means word boundary. This is a zero-width assertion that
2563 # matches only at the beginning or end of a word.
2564 # ^ matches at the beginning of lines
2566 # * means 0 or more times
2567 # + means 1 or more times
2568 # ? means 0 or 1 time
2569 # | means or
2570 # [^*] anything but '*' (inside [] you don't have to escape metachars)
2571 # [^\s*] anything but whitespaces and '*'
2572 # (?<!\S) is a one char lookbehind assertion and asks for any leading whitespace
2573 # and mathces beginning of lines so we have correct formatting detection
2574 # even if the the text is just '*foo*'
2575 # (?!\S) is the same thing but it's a lookahead assertion
2576 # \S*[^\s\W] --> in the matching string don't match ? or ) etc.. if at the end
2577 # so http://be) will match http://be and http://be)be) will match http://be)be
2579 legacy_prefixes = r"((?<=\()(www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))"\
2580 r"|((www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+"\
2581 r"\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+)"
2582 # NOTE: it's ok to catch www.gr such stuff exist!
2584 #FIXME: recognize xmpp: and treat it specially
2585 links = r"((?<=\()[A-Za-z][A-Za-z0-9\+\.\-]*:"\
2586 r"([\w\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+"\
2587 r"(?=\)))|([A-Za-z][A-Za-z0-9\+\.\-]*:([\w\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+)"
2589 #2nd one: at_least_one_char@at_least_one_char.at_least_one_char
2590 mail = r'\bmailto:\S*[^\s\W]|' r'\b\S+@\S+\.\S*[^\s\W]'
2592 #detects eg. *b* *bold* *bold bold* test *bold* *bold*! (*bold*)
2593 #doesn't detect (it's a feature :P) * bold* *bold * * bold * test*bold*
2594 formatting = r'|(?<!\w)' r'\*[^\s*]' r'([^*]*[^\s*])?' r'\*(?!\w)|'\
2595 r'(?<!\w|\<)' r'/[^\s/]' r'([^/]*[^\s/])?' r'/(?!\w)|'\
2596 r'(?<!\w)' r'_[^\s_]' r'([^_]*[^\s_])?' r'_(?!\w)'
2598 latex = r'|\$\$[^$\\]*?([\]\[0-9A-Za-z()|+*/-]|[\\][\]\[0-9A-Za-z()|{}$])(.*?[^\\])?\$\$'
2600 basic_pattern = links + '|' + mail + '|' + legacy_prefixes
2602 link_pattern = basic_pattern
2603 self.link_pattern_re = re.compile(link_pattern, re.IGNORECASE)
2605 if gajim.config.get('use_latex'):
2606 basic_pattern += latex
2608 if gajim.config.get('ascii_formatting'):
2609 basic_pattern += formatting
2610 self.basic_pattern = basic_pattern
2612 emoticons_pattern = ''
2613 if gajim.config.get('emoticons_theme'):
2614 # When an emoticon is bordered by an alpha-numeric character it is NOT
2615 # expanded. e.g., foo:) NO, foo :) YES, (brb) NO, (:)) YES, etc.
2616 # We still allow multiple emoticons side-by-side like :P:P:P
2617 # sort keys by length so :qwe emot is checked before :q
2618 keys = sorted(self.emoticons, key=len, reverse=True)
2619 emoticons_pattern_prematch = ''
2620 emoticons_pattern_postmatch = ''
2621 emoticon_length = 0
2622 for emoticon in keys: # travel thru emoticons list
2623 emoticon = emoticon.decode('utf-8')
2624 emoticon_escaped = re.escape(emoticon) # espace regexp metachars
2625 emoticons_pattern += emoticon_escaped + '|'# | means or in regexp
2626 if (emoticon_length != len(emoticon)):
2627 # Build up expressions to match emoticons next to other emoticons
2628 emoticons_pattern_prematch = emoticons_pattern_prematch[:-1] + ')|(?<='
2629 emoticons_pattern_postmatch = emoticons_pattern_postmatch[:-1] + ')|(?='
2630 emoticon_length = len(emoticon)
2631 emoticons_pattern_prematch += emoticon_escaped + '|'
2632 emoticons_pattern_postmatch += emoticon_escaped + '|'
2633 # We match from our list of emoticons, but they must either have
2634 # whitespace, or another emoticon next to it to match successfully
2635 # [\w.] alphanumeric and dot (for not matching 8) in (2.8))
2636 emoticons_pattern = '|' + \
2637 '(?:(?<![\w.]' + emoticons_pattern_prematch[:-1] + '))' + \
2638 '(?:' + emoticons_pattern[:-1] + ')' + \
2639 '(?:(?![\w]' + emoticons_pattern_postmatch[:-1] + '))'
2641 # because emoticons match later (in the string) they need to be after
2642 # basic matches that may occur earlier
2643 self.emot_and_basic = basic_pattern + emoticons_pattern
2645 # needed for xhtml display
2646 self.emot_only = emoticons_pattern
2648 # at least one character in 3 parts (before @, after @, after .)
2649 self.sth_at_sth_dot_sth = r'\S+@\S+\.\S*[^\s)?]'
2651 # Invalid XML chars
2652 self.invalid_XML_chars = u'[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19]|[\ud800-\udfff]|[\ufffe-\uffff]'
2654 def popup_emoticons_under_button(self, button, parent_win):
2655 ''' pops emoticons menu under button, located in parent_win'''
2656 gtkgui_helpers.popup_emoticons_under_button(self.emoticons_menu,
2657 button, parent_win)
2659 def prepare_emoticons_menu(self):
2660 menu = gtk.Menu()
2661 def emoticon_clicked(w, str_):
2662 if self.emoticon_menuitem_clicked:
2663 self.emoticon_menuitem_clicked(str_)
2664 # don't keep reference to CB of object
2665 # this will prevent making it uncollectable
2666 self.emoticon_menuitem_clicked = None
2667 def selection_done(widget):
2668 # remove reference to CB of object, which will
2669 # make it uncollectable
2670 self.emoticon_menuitem_clicked = None
2671 counter = 0
2672 # Calculate the side lenght of the popup to make it a square
2673 size = int(round(math.sqrt(len(self.emoticons_images))))
2674 for image in self.emoticons_images:
2675 item = gtk.MenuItem()
2676 img = gtk.Image()
2677 if isinstance(image[1], gtk.gdk.PixbufAnimation):
2678 img.set_from_animation(image[1])
2679 else:
2680 img.set_from_pixbuf(image[1])
2681 item.add(img)
2682 item.connect('activate', emoticon_clicked, image[0])
2683 #FIXME: add tooltip with ascii
2684 menu.attach(item, counter % size, counter % size + 1,
2685 counter / size, counter / size + 1)
2686 counter += 1
2687 menu.connect('selection-done', selection_done)
2688 menu.show_all()
2689 return menu
2691 def _init_emoticons(self, path, need_reload = False):
2692 #initialize emoticons dictionary and unique images list
2693 self.emoticons_images = list()
2694 self.emoticons = dict()
2695 self.emoticons_animations = dict()
2697 sys.path.append(path)
2698 import emoticons
2699 if need_reload:
2700 # we need to reload else that doesn't work when changing emoticon set
2701 reload(emoticons)
2702 emots = emoticons.emoticons
2703 for emot_filename in emots:
2704 emot_file = os.path.join(path, emot_filename)
2705 if not self.image_is_ok(emot_file):
2706 continue
2707 for emot in emots[emot_filename]:
2708 emot = emot.decode('utf-8')
2709 # This avoids duplicated emoticons with the same image eg. :) and :-)
2710 if not emot_file in self.emoticons.values():
2711 if emot_file.endswith('.gif'):
2712 pix = gtk.gdk.PixbufAnimation(emot_file)
2713 else:
2714 pix = gtk.gdk.pixbuf_new_from_file(emot_file)
2715 self.emoticons_images.append((emot, pix))
2716 self.emoticons[emot.upper()] = emot_file
2717 del emoticons
2718 sys.path.remove(path)
2720 def init_emoticons(self, need_reload = False):
2721 emot_theme = gajim.config.get('emoticons_theme')
2722 if not emot_theme:
2723 return
2725 path = os.path.join(gajim.DATA_DIR, 'emoticons', emot_theme)
2726 if not os.path.exists(path):
2727 # It's maybe a user theme
2728 path = os.path.join(gajim.MY_EMOTS_PATH, emot_theme)
2729 if not os.path.exists(path): # theme doesn't exist, disable emoticons
2730 dialogs.WarningDialog(_('Emoticons disabled'),
2731 _('Your configured emoticons theme has not been found, so emoticons have been disabled.'))
2732 gajim.config.set('emoticons_theme', '')
2733 return
2734 self._init_emoticons(path, need_reload)
2735 if len(self.emoticons) == 0:
2736 # maybe old format of emoticons file, try to convert it
2737 try:
2738 import pprint
2739 import emoticons
2740 emots = emoticons.emoticons
2741 fd = open(os.path.join(path, 'emoticons.py'), 'w')
2742 fd.write('emoticons = ')
2743 pprint.pprint( dict([
2744 (file_, [i for i in emots.keys() if emots[i] == file_])
2745 for file_ in set(emots.values())]), fd)
2746 fd.close()
2747 del emoticons
2748 self._init_emoticons(path, need_reload=True)
2749 except Exception:
2750 pass
2751 if len(self.emoticons) == 0:
2752 dialogs.WarningDialog(_('Emoticons disabled'),
2753 _('Your configured emoticons theme cannot been loaded. You maybe need to update the format of emoticons.py file. See http://trac.gajim.org/wiki/Emoticons for more details.'))
2754 if self.emoticons_menu:
2755 self.emoticons_menu.destroy()
2756 self.emoticons_menu = self.prepare_emoticons_menu()
2758 ################################################################################
2759 ### Methods for opening new messages controls
2760 ################################################################################
2762 def join_gc_room(self, account, room_jid, nick, password, minimize=False,
2763 is_continued=False):
2764 '''joins the room immediately'''
2765 if not nick:
2766 nick = gajim.nicks[account]
2768 if self.msg_win_mgr.has_window(room_jid, account) and \
2769 gajim.gc_connected[account][room_jid]:
2770 gc_ctrl = self.msg_win_mgr.get_gc_control(room_jid, account)
2771 win = gc_ctrl.parent_win
2772 win.set_active_tab(gc_ctrl)
2773 dialogs.ErrorDialog(_('You are already in group chat %s') % room_jid)
2774 return
2776 invisible_show = gajim.SHOW_LIST.index('invisible')
2777 if gajim.connections[account].connected == invisible_show:
2778 dialogs.ErrorDialog(
2779 _('You cannot join a group chat while you are invisible'))
2780 return
2782 minimized_control = gajim.interface.minimized_controls[account].get(
2783 room_jid, None)
2785 if minimized_control is None and not self.msg_win_mgr.has_window(room_jid,
2786 account):
2787 # Join new groupchat
2788 if minimize:
2789 contact = gajim.contacts.create_contact(jid=room_jid, name=nick)
2790 gc_control = GroupchatControl(None, contact, account)
2791 gajim.interface.minimized_controls[account][room_jid] = gc_control
2792 self.roster.add_groupchat(room_jid, account)
2793 else:
2794 self.new_room(room_jid, nick, account, is_continued=is_continued)
2795 elif minimized_control is None:
2796 # We are already in that groupchat
2797 gc_control = self.msg_win_mgr.get_gc_control(room_jid, account)
2798 gc_control.nick = nick
2799 gc_control.parent_win.set_active_tab(gc_control)
2800 else:
2801 # We are already in this groupchat and it is minimized
2802 minimized_control.nick = nick
2803 self.roster.add_groupchat(room_jid, account)
2805 # Connect
2806 gajim.connections[account].join_gc(nick, room_jid, password)
2807 if password:
2808 gajim.gc_passwords[room_jid] = password
2810 def new_room(self, room_jid, nick, account, is_continued=False):
2811 # Get target window, create a control, and associate it with the window
2812 contact = gajim.contacts.create_contact(jid=room_jid, name=nick)
2813 mw = self.msg_win_mgr.get_window(contact.jid, account)
2814 if not mw:
2815 mw = self.msg_win_mgr.create_window(contact, account,
2816 GroupchatControl.TYPE_ID)
2817 gc_control = GroupchatControl(mw, contact, account,
2818 is_continued=is_continued)
2819 mw.new_tab(gc_control)
2821 def new_private_chat(self, gc_contact, account, session=None):
2822 contact = gajim.contacts.contact_from_gc_contact(gc_contact)
2823 type_ = message_control.TYPE_PM
2824 fjid = gc_contact.room_jid + '/' + gc_contact.name
2826 conn = gajim.connections[account]
2828 if not session and fjid in conn.sessions:
2829 sessions = [s for s in conn.sessions[fjid].values() if isinstance(s, ChatControlSession)]
2831 # look for an existing session with a chat control
2832 for s in sessions:
2833 if s.control:
2834 session = s
2835 break
2837 if not session and not len(sessions) == 0:
2838 # there are no sessions with chat controls, just take the first one
2839 session = sessions[0]
2841 if not session:
2842 # couldn't find an existing ChatControlSession, just make a new one
2844 session = conn.make_new_session(fjid, None, 'pm')
2846 if not session.control:
2847 mw = self.msg_win_mgr.get_window(fjid, account)
2848 if not mw:
2849 mw = self.msg_win_mgr.create_window(contact, account, type_)
2851 session.control = PrivateChatControl(mw, gc_contact, contact, account,
2852 session)
2853 mw.new_tab(session.control)
2855 if len(gajim.events.get_events(account, fjid)):
2856 # We call this here to avoid race conditions with widget validation
2857 session.control.read_queue()
2859 return session.control
2861 def new_chat(self, contact, account, resource=None, session=None):
2862 # Get target window, create a control, and associate it with the window
2863 type_ = message_control.TYPE_CHAT
2865 fjid = contact.jid
2866 if resource:
2867 fjid += '/' + resource
2869 mw = self.msg_win_mgr.get_window(fjid, account)
2870 if not mw:
2871 mw = self.msg_win_mgr.create_window(contact, account, type_, resource)
2873 chat_control = ChatControl(mw, contact, account, session, resource)
2875 mw.new_tab(chat_control)
2877 if len(gajim.events.get_events(account, fjid)):
2878 # We call this here to avoid race conditions with widget validation
2879 chat_control.read_queue()
2881 return chat_control
2883 def new_chat_from_jid(self, account, fjid):
2884 jid, resource = gajim.get_room_and_nick_from_fjid(fjid)
2885 contact = gajim.contacts.get_contact(account, jid, resource)
2886 added_to_roster = False
2887 if not contact:
2888 added_to_roster = True
2889 contact = self.roster.add_to_not_in_the_roster(account, jid,
2890 resource=resource)
2892 ctrl = self.msg_win_mgr.get_control(fjid, account)
2894 if not ctrl:
2895 ctrl = self.new_chat(contact, account,
2896 resource=resource)
2897 if len(gajim.events.get_events(account, fjid)):
2898 ctrl.read_queue()
2900 mw = ctrl.parent_win
2901 mw.set_active_tab(ctrl)
2902 # For JEP-0172
2903 if added_to_roster:
2904 ctrl.user_nick = gajim.nicks[account]
2906 def on_open_chat_window(self, widget, contact, account, resource=None,
2907 session=None):
2909 # Get the window containing the chat
2910 fjid = contact.jid
2912 if resource:
2913 fjid += '/' + resource
2915 ctrl = None
2917 if session:
2918 ctrl = session.control
2919 if not ctrl:
2920 win = self.msg_win_mgr.get_window(fjid, account)
2922 if win:
2923 ctrl = win.get_control(fjid, account)
2925 if not ctrl:
2926 ctrl = self.new_chat(contact, account, resource=resource,
2927 session=session)
2928 # last message is long time ago
2929 gajim.last_message_time[account][ctrl.get_full_jid()] = 0
2931 win = ctrl.parent_win
2933 win.set_active_tab(ctrl)
2935 if gajim.connections[account].is_zeroconf and \
2936 gajim.connections[account].status in ('offline', 'invisible'):
2937 ctrl = win.get_control(fjid, account)
2938 if ctrl:
2939 ctrl.got_disconnected()
2941 ################################################################################
2942 ### Other Methods
2943 ################################################################################
2945 def read_sleepy(self):
2946 '''Check idle status and change that status if needed'''
2947 if not self.sleeper.poll():
2948 # idle detection is not supported in that OS
2949 return False # stop looping in vain
2950 state = self.sleeper.getState()
2951 for account in gajim.connections:
2952 if account not in gajim.sleeper_state or \
2953 not gajim.sleeper_state[account]:
2954 continue
2955 if state == common.sleepy.STATE_AWAKE and \
2956 gajim.sleeper_state[account] in ('autoaway', 'autoxa'):
2957 # we go online
2958 self.roster.send_status(account, 'online',
2959 gajim.status_before_autoaway[account])
2960 gajim.status_before_autoaway[account] = ''
2961 gajim.sleeper_state[account] = 'online'
2962 elif state == common.sleepy.STATE_AWAY and \
2963 gajim.sleeper_state[account] == 'online' and \
2964 gajim.config.get('autoaway'):
2965 # we save out online status
2966 gajim.status_before_autoaway[account] = \
2967 gajim.connections[account].status
2968 # we go away (no auto status) [we pass True to auto param]
2969 auto_message = gajim.config.get('autoaway_message')
2970 if not auto_message:
2971 auto_message = gajim.connections[account].status
2972 else:
2973 auto_message = auto_message.replace('$S','%(status)s')
2974 auto_message = auto_message.replace('$T','%(time)s')
2975 auto_message = auto_message % {
2976 'status': gajim.status_before_autoaway[account],
2977 'time': gajim.config.get('autoawaytime')
2979 self.roster.send_status(account, 'away', auto_message, auto=True)
2980 gajim.sleeper_state[account] = 'autoaway'
2981 elif state == common.sleepy.STATE_XA and \
2982 gajim.sleeper_state[account] in ('online', 'autoaway',
2983 'autoaway-forced') and gajim.config.get('autoxa'):
2984 # we go extended away [we pass True to auto param]
2985 auto_message = gajim.config.get('autoxa_message')
2986 if not auto_message:
2987 auto_message = gajim.connections[account].status
2988 else:
2989 auto_message = auto_message.replace('$S','%(status)s')
2990 auto_message = auto_message.replace('$T','%(time)s')
2991 auto_message = auto_message % {
2992 'status': gajim.status_before_autoaway[account],
2993 'time': gajim.config.get('autoxatime')
2995 self.roster.send_status(account, 'xa', auto_message, auto=True)
2996 gajim.sleeper_state[account] = 'autoxa'
2997 return True # renew timeout (loop for ever)
2999 def autoconnect(self):
3000 '''auto connect at startup'''
3001 # dict of account that want to connect sorted by status
3002 shows = {}
3003 for a in gajim.connections:
3004 if gajim.config.get_per('accounts', a, 'autoconnect'):
3005 if gajim.config.get_per('accounts', a, 'restore_last_status'):
3006 self.roster.send_status(a, gajim.config.get_per('accounts', a,
3007 'last_status'), helpers.from_one_line(gajim.config.get_per(
3008 'accounts', a, 'last_status_msg')))
3009 continue
3010 show = gajim.config.get_per('accounts', a, 'autoconnect_as')
3011 if not show in gajim.SHOW_LIST:
3012 continue
3013 if not show in shows:
3014 shows[show] = [a]
3015 else:
3016 shows[show].append(a)
3017 def on_message(message, pep_dict):
3018 if message is None:
3019 return
3020 for a in shows[show]:
3021 self.roster.send_status(a, show, message)
3022 self.roster.send_pep(a, pep_dict)
3023 for show in shows:
3024 message = self.roster.get_status_message(show, on_message)
3025 return False
3027 def show_systray(self):
3028 self.systray_enabled = True
3029 self.systray.show_icon()
3031 def hide_systray(self):
3032 self.systray_enabled = False
3033 self.systray.hide_icon()
3035 def on_launch_browser_mailer(self, widget, url, kind):
3036 helpers.launch_browser_mailer(kind, url)
3038 def process_connections(self):
3039 ''' Called each foo (200) miliseconds. Check for idlequeue timeouts. '''
3040 try:
3041 gajim.idlequeue.process()
3042 except Exception:
3043 # Otherwise, an exception will stop our loop
3044 timeout, in_seconds = gajim.idlequeue.PROCESS_TIMEOUT
3045 if in_seconds:
3046 gobject.timeout_add_seconds(timeout, self.process_connections)
3047 else:
3048 gobject.timeout_add(timeout, self.process_connections)
3049 raise
3050 return True # renew timeout (loop for ever)
3052 def save_config(self):
3053 err_str = parser.write()
3054 if err_str is not None:
3055 print >> sys.stderr, err_str
3056 # it is good to notify the user
3057 # in case he or she cannot see the output of the console
3058 dialogs.ErrorDialog(_('Could not save your settings and preferences'),
3059 err_str)
3060 sys.exit()
3062 def save_avatar_files(self, jid, photo, puny_nick = None, local = False):
3063 '''Saves an avatar to a separate file, and generate files for dbus notifications. An avatar can be given as a pixmap directly or as an decoded image.'''
3064 puny_jid = helpers.sanitize_filename(jid)
3065 path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
3066 if puny_nick:
3067 path_to_file = os.path.join(path_to_file, puny_nick)
3068 # remove old avatars
3069 for typ in ('jpeg', 'png'):
3070 if local:
3071 path_to_original_file = path_to_file + '_local'+ '.' + typ
3072 else:
3073 path_to_original_file = path_to_file + '.' + typ
3074 if os.path.isfile(path_to_original_file):
3075 os.remove(path_to_original_file)
3076 if local and photo:
3077 pixbuf = photo
3078 typ = 'png'
3079 extension = '_local.png' # save local avatars as png file
3080 else:
3081 pixbuf, typ = gtkgui_helpers.get_pixbuf_from_data(photo, want_type = True)
3082 if pixbuf is None:
3083 return
3084 extension = '.' + typ
3085 if typ not in ('jpeg', 'png'):
3086 gajim.log.debug('gtkpixbuf cannot save other than jpeg and png formats. saving %s\'avatar as png file (originaly %s)' % (jid, typ))
3087 typ = 'png'
3088 extension = '.png'
3089 path_to_original_file = path_to_file + extension
3090 try:
3091 pixbuf.save(path_to_original_file, typ)
3092 except Exception, e:
3093 log.error('Error writing avatar file %s: %s' % (path_to_original_file,
3094 str(e)))
3095 # Generate and save the resized, color avatar
3096 pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'notification')
3097 if pixbuf:
3098 path_to_normal_file = path_to_file + '_notif_size_colored' + extension
3099 try:
3100 pixbuf.save(path_to_normal_file, 'png')
3101 except Exception, e:
3102 log.error('Error writing avatar file %s: %s' % \
3103 (path_to_original_file, str(e)))
3104 # Generate and save the resized, black and white avatar
3105 bwbuf = gtkgui_helpers.get_scaled_pixbuf(
3106 gtkgui_helpers.make_pixbuf_grayscale(pixbuf), 'notification')
3107 if bwbuf:
3108 path_to_bw_file = path_to_file + '_notif_size_bw' + extension
3109 try:
3110 bwbuf.save(path_to_bw_file, 'png')
3111 except Exception, e:
3112 log.error('Error writing avatar file %s: %s' % \
3113 (path_to_original_file, str(e)))
3115 def remove_avatar_files(self, jid, puny_nick = None, local = False):
3116 '''remove avatar files of a jid'''
3117 puny_jid = helpers.sanitize_filename(jid)
3118 path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
3119 if puny_nick:
3120 path_to_file = os.path.join(path_to_file, puny_nick)
3121 for ext in ('.jpeg', '.png'):
3122 if local:
3123 ext = '_local' + ext
3124 path_to_original_file = path_to_file + ext
3125 if os.path.isfile(path_to_file + ext):
3126 os.remove(path_to_file + ext)
3127 if os.path.isfile(path_to_file + '_notif_size_colored' + ext):
3128 os.remove(path_to_file + '_notif_size_colored' + ext)
3129 if os.path.isfile(path_to_file + '_notif_size_bw' + ext):
3130 os.remove(path_to_file + '_notif_size_bw' + ext)
3132 def auto_join_bookmarks(self, account):
3133 '''autojoin bookmarked GCs that have 'auto join' on for this account'''
3134 for bm in gajim.connections[account].bookmarks:
3135 if bm['autojoin'] in ('1', 'true'):
3136 jid = bm['jid']
3137 # Only join non-opened groupchats. Opened one are already
3138 # auto-joined on re-connection
3139 if not jid in gajim.gc_connected[account]:
3140 # we are not already connected
3141 minimize = bm['minimize'] in ('1', 'true')
3142 gajim.interface.join_gc_room(account, jid, bm['nick'],
3143 bm['password'], minimize = minimize)
3144 elif jid in self.minimized_controls[account]:
3145 # more or less a hack:
3146 # On disconnect the minimized gc contact instances
3147 # were set to offline. Reconnect them to show up in the roster.
3148 self.roster.add_groupchat(jid, account)
3150 def add_gc_bookmark(self, account, name, jid, autojoin, minimize, password,
3151 nick):
3152 '''add a bookmark for this account, sorted in bookmark list'''
3153 bm = {
3154 'name': name,
3155 'jid': jid,
3156 'autojoin': autojoin,
3157 'minimize': minimize,
3158 'password': password,
3159 'nick': nick
3161 place_found = False
3162 index = 0
3163 # check for duplicate entry and respect alpha order
3164 for bookmark in gajim.connections[account].bookmarks:
3165 if bookmark['jid'] == bm['jid']:
3166 dialogs.ErrorDialog(
3167 _('Bookmark already set'),
3168 _('Group Chat "%s" is already in your bookmarks.') % bm['jid'])
3169 return
3170 if bookmark['name'] > bm['name']:
3171 place_found = True
3172 break
3173 index += 1
3174 if place_found:
3175 gajim.connections[account].bookmarks.insert(index, bm)
3176 else:
3177 gajim.connections[account].bookmarks.append(bm)
3178 gajim.connections[account].store_bookmarks()
3179 self.roster.set_actions_menu_needs_rebuild()
3180 dialogs.InformationDialog(
3181 _('Bookmark has been added successfully'),
3182 _('You can manage your bookmarks via Actions menu in your roster.'))
3185 # does JID exist only within a groupchat?
3186 def is_pm_contact(self, fjid, account):
3187 bare_jid = gajim.get_jid_without_resource(fjid)
3189 gc_ctrl = self.msg_win_mgr.get_gc_control(bare_jid, account)
3191 if not gc_ctrl and \
3192 bare_jid in self.minimized_controls[account]:
3193 gc_ctrl = self.minimized_controls[account][bare_jid]
3195 return gc_ctrl and gc_ctrl.type_id == message_control.TYPE_GC
3197 def create_ipython_window(self):
3198 try:
3199 from ipython_view import IPythonView
3200 except ImportError:
3201 print 'ipython_view not found'
3202 return
3203 import pango
3205 if os.name == 'nt':
3206 font = 'Lucida Console 9'
3207 else:
3208 font = 'Luxi Mono 10'
3210 window = gtk.Window()
3211 window.set_size_request(750,550)
3212 window.set_resizable(True)
3213 sw = gtk.ScrolledWindow()
3214 sw.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
3215 view = IPythonView()
3216 view.modify_font(pango.FontDescription(font))
3217 view.set_wrap_mode(gtk.WRAP_CHAR)
3218 sw.add(view)
3219 window.add(sw)
3220 window.show_all()
3221 def on_delete(win, event):
3222 win.hide()
3223 return True
3224 window.connect('delete_event',on_delete)
3225 view.updateNamespace({'gajim': gajim})
3226 gajim.ipython_window = window
3228 def __init__(self):
3229 gajim.interface = self
3230 gajim.thread_interface = ThreadInterface
3231 # This is the manager and factory of message windows set by the module
3232 self.msg_win_mgr = None
3233 self.jabber_state_images = {'16': {}, '32': {}, 'opened': {},
3234 'closed': {}}
3235 self.emoticons_menu = None
3236 # handler when an emoticon is clicked in emoticons_menu
3237 self.emoticon_menuitem_clicked = None
3238 self.minimized_controls = {}
3239 self.status_sent_to_users = {}
3240 self.status_sent_to_groups = {}
3241 self.gpg_passphrase = {}
3242 self.pass_dialog = {}
3243 self.default_colors = {
3244 'inmsgcolor': gajim.config.get('inmsgcolor'),
3245 'outmsgcolor': gajim.config.get('outmsgcolor'),
3246 'statusmsgcolor': gajim.config.get('statusmsgcolor'),
3247 'urlmsgcolor': gajim.config.get('urlmsgcolor'),
3250 cfg_was_read = parser.read()
3251 # override logging settings from config (don't take care of '-q' option)
3252 if gajim.config.get('verbose'):
3253 logging_helpers.set_verbose()
3255 # Is Gajim default app?
3256 if os.name != 'nt' and gajim.config.get('check_if_gajim_is_default'):
3257 gtkgui_helpers.possibly_set_gajim_as_xmpp_handler()
3259 for account in gajim.config.get_per('accounts'):
3260 if gajim.config.get_per('accounts', account, 'is_zeroconf'):
3261 gajim.ZEROCONF_ACC_NAME = account
3262 break
3263 # Is gnome configured to activate row on single click ?
3264 try:
3265 import gconf
3266 client = gconf.client_get_default()
3267 click_policy = client.get_string(
3268 '/apps/nautilus/preferences/click_policy')
3269 if click_policy == 'single':
3270 gajim.single_click = True
3271 except Exception:
3272 pass
3273 # add default status messages if there is not in the config file
3274 if len(gajim.config.get_per('statusmsg')) == 0:
3275 default = gajim.config.statusmsg_default
3276 for msg in default:
3277 gajim.config.add_per('statusmsg', msg)
3278 gajim.config.set_per('statusmsg', msg, 'message', default[msg][0])
3279 gajim.config.set_per('statusmsg', msg, 'activity', default[msg][1])
3280 gajim.config.set_per('statusmsg', msg, 'subactivity',
3281 default[msg][2])
3282 gajim.config.set_per('statusmsg', msg, 'activity_text',
3283 default[msg][3])
3284 gajim.config.set_per('statusmsg', msg, 'mood', default[msg][4])
3285 gajim.config.set_per('statusmsg', msg, 'mood_text', default[msg][5])
3286 #add default themes if there is not in the config file
3287 theme = gajim.config.get('roster_theme')
3288 if not theme in gajim.config.get_per('themes'):
3289 gajim.config.set('roster_theme', _('default'))
3290 if len(gajim.config.get_per('themes')) == 0:
3291 d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
3292 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
3293 'groupfontattrs', 'contacttextcolor', 'contactbgcolor',
3294 'contactfont', 'contactfontattrs', 'bannertextcolor',
3295 'bannerbgcolor']
3297 default = gajim.config.themes_default
3298 for theme_name in default:
3299 gajim.config.add_per('themes', theme_name)
3300 theme = default[theme_name]
3301 for o in d:
3302 gajim.config.set_per('themes', theme_name, o,
3303 theme[d.index(o)])
3305 if gajim.config.get('autodetect_browser_mailer') or not cfg_was_read:
3306 gtkgui_helpers.autodetect_browser_mailer()
3308 gajim.idlequeue = idlequeue.get_idlequeue()
3309 # resolve and keep current record of resolved hosts
3310 gajim.resolver = resolver.get_resolver(gajim.idlequeue)
3311 gajim.socks5queue = socks5.SocksQueue(gajim.idlequeue,
3312 self.handle_event_file_rcv_completed,
3313 self.handle_event_file_progress,
3314 self.handle_event_file_error)
3315 gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
3316 gajim.default_session_type = ChatControlSession
3317 self.register_handlers()
3318 if gajim.config.get('enable_zeroconf') and gajim.HAVE_ZEROCONF:
3319 gajim.connections[gajim.ZEROCONF_ACC_NAME] = \
3320 connection_zeroconf.ConnectionZeroconf(gajim.ZEROCONF_ACC_NAME)
3321 for account in gajim.config.get_per('accounts'):
3322 if not gajim.config.get_per('accounts', account, 'is_zeroconf'):
3323 gajim.connections[account] = common.connection.Connection(account)
3325 # gtk hooks
3326 gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')
3327 gtk.about_dialog_set_url_hook(self.on_launch_browser_mailer, 'url')
3328 gtk.link_button_set_uri_hook(self.on_launch_browser_mailer, 'url')
3330 self.instances = {}
3332 for a in gajim.connections:
3333 self.instances[a] = {'infos': {}, 'disco': {}, 'gc_config': {},
3334 'search': {}, 'online_dialog': {}}
3335 # online_dialog contains all dialogs that have a meaning only when we
3336 # are not disconnected
3337 self.minimized_controls[a] = {}
3338 gajim.contacts.add_account(a)
3339 gajim.groups[a] = {}
3340 gajim.gc_connected[a] = {}
3341 gajim.automatic_rooms[a] = {}
3342 gajim.newly_added[a] = []
3343 gajim.to_be_removed[a] = []
3344 gajim.nicks[a] = gajim.config.get_per('accounts', a, 'name')
3345 gajim.block_signed_in_notifications[a] = True
3346 gajim.sleeper_state[a] = 0
3347 gajim.encrypted_chats[a] = []
3348 gajim.last_message_time[a] = {}
3349 gajim.status_before_autoaway[a] = ''
3350 gajim.transport_avatar[a] = {}
3351 gajim.gajim_optional_features[a] = []
3352 gajim.caps_hash[a] = ''
3354 helpers.update_optional_features()
3356 self.remote_ctrl = None
3358 if gajim.config.get('networkmanager_support') and dbus_support.supported:
3359 import network_manager_listener
3361 # Handle gnome screensaver
3362 if dbus_support.supported:
3363 def gnome_screensaver_ActiveChanged_cb(active):
3364 if not active:
3365 for account in gajim.connections:
3366 if gajim.sleeper_state[account] == 'autoaway-forced':
3367 # We came back online ofter gnome-screensaver autoaway
3368 self.roster.send_status(account, 'online',
3369 gajim.status_before_autoaway[account])
3370 gajim.status_before_autoaway[account] = ''
3371 gajim.sleeper_state[account] = 'online'
3372 return
3373 if not gajim.config.get('autoaway'):
3374 # Don't go auto away if user disabled the option
3375 return
3376 for account in gajim.connections:
3377 if account not in gajim.sleeper_state or \
3378 not gajim.sleeper_state[account]:
3379 continue
3380 if gajim.sleeper_state[account] == 'online':
3381 # we save out online status
3382 gajim.status_before_autoaway[account] = \
3383 gajim.connections[account].status
3384 # we go away (no auto status) [we pass True to auto param]
3385 auto_message = gajim.config.get('autoaway_message')
3386 if not auto_message:
3387 auto_message = gajim.connections[account].status
3388 else:
3389 auto_message = auto_message.replace('$S','%(status)s')
3390 auto_message = auto_message.replace('$T','%(time)s')
3391 auto_message = auto_message % {
3392 'status': gajim.status_before_autoaway[account],
3393 'time': gajim.config.get('autoxatime')
3395 self.roster.send_status(account, 'away', auto_message,
3396 auto=True)
3397 gajim.sleeper_state[account] = 'autoaway-forced'
3399 try:
3400 bus = dbus.SessionBus()
3401 bus.add_signal_receiver(gnome_screensaver_ActiveChanged_cb,
3402 'ActiveChanged', 'org.gnome.ScreenSaver')
3403 except Exception:
3404 pass
3406 self.show_vcard_when_connect = []
3408 self.sleeper = common.sleepy.Sleepy(
3409 gajim.config.get('autoawaytime') * 60, # make minutes to seconds
3410 gajim.config.get('autoxatime') * 60)
3412 gtkgui_helpers.make_jabber_state_images()
3414 self.systray_enabled = False
3415 self.systray_capabilities = False
3417 if (os.name == 'nt'):
3418 import statusicon
3419 self.systray = statusicon.StatusIcon()
3420 self.systray_capabilities = True
3421 else: # use ours, not GTK+ one
3422 # [FIXME: remove this when we migrate to 2.10 and we can do
3423 # cool tooltips somehow and (not dying to keep) animation]
3424 import systray
3425 self.systray_capabilities = systray.HAS_SYSTRAY_CAPABILITIES
3426 if self.systray_capabilities:
3427 self.systray = systray.Systray()
3429 if self.systray_capabilities and gajim.config.get('trayicon') != 'never':
3430 self.show_systray()
3432 path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'gajim.png')
3433 pix = gtk.gdk.pixbuf_new_from_file(path_to_file)
3434 # set the icon to all windows
3435 gtk.window_set_default_icon(pix)
3437 self.roster = roster_window.RosterWindow()
3438 for account in gajim.connections:
3439 gajim.connections[account].load_roster_from_db()
3441 self.init_emoticons()
3442 self.make_regexps()
3444 # get instances for windows/dialogs that will show_all()/hide()
3445 self.instances['file_transfers'] = dialogs.FileTransfersWindow()
3447 # get transports type from DB
3448 gajim.transport_type = gajim.logger.get_transports_type()
3450 # test is dictionnary is present for speller
3451 if gajim.config.get('use_speller'):
3452 lang = gajim.config.get('speller_language')
3453 if not lang:
3454 lang = gajim.LANG
3455 tv = gtk.TextView()
3456 try:
3457 import gtkspell
3458 spell = gtkspell.Spell(tv, lang)
3459 except (ImportError, TypeError, RuntimeError, OSError):
3460 dialogs.AspellDictError(lang)
3462 if gajim.config.get('soundplayer') == '':
3463 # only on first time Gajim starts
3464 commands = ('aplay', 'play', 'esdplay', 'artsplay', 'ossplay')
3465 for command in commands:
3466 if helpers.is_in_path(command):
3467 if command == 'aplay':
3468 command += ' -q'
3469 gajim.config.set('soundplayer', command)
3470 break
3472 self.last_ftwindow_update = 0
3474 gobject.timeout_add(100, self.autoconnect)
3475 timeout, in_seconds = gajim.idlequeue.PROCESS_TIMEOUT
3476 if in_seconds:
3477 gobject.timeout_add_seconds(timeout, self.process_connections)
3478 else:
3479 gobject.timeout_add(timeout, self.process_connections)
3480 gobject.timeout_add_seconds(gajim.config.get(
3481 'check_idle_every_foo_seconds'), self.read_sleepy)
3483 # when using libasyncns we need to process resolver in regular intervals
3484 if resolver.USE_LIBASYNCNS:
3485 gobject.timeout_add(200, gajim.resolver.process)
3487 # setup the indicator
3488 if gajim.HAVE_INDICATOR:
3489 notify.setup_indicator_server()
3491 def remote_init():
3492 if gajim.config.get('remote_control'):
3493 try:
3494 import remote_control
3495 self.remote_ctrl = remote_control.Remote()
3496 except Exception:
3497 pass
3498 gobject.timeout_add_seconds(5, remote_init)
3500 if __name__ == '__main__':
3501 def sigint_cb(num, stack):
3502 sys.exit(5)
3503 # ^C exits the application normally to delete pid file
3504 signal.signal(signal.SIGINT, sigint_cb)
3506 log.info("Encodings: d:%s, fs:%s, p:%s", sys.getdefaultencoding(), \
3507 sys.getfilesystemencoding(), locale.getpreferredencoding())
3509 if os.name != 'nt':
3510 # Session Management support
3511 try:
3512 import gnome.ui
3513 except ImportError:
3514 pass
3515 else:
3516 def die_cb(cli):
3517 gajim.interface.roster.quit_gtkgui_interface()
3518 gnome.program_init('gajim', gajim.version)
3519 cli = gnome.ui.master_client()
3520 cli.connect('die', die_cb)
3522 path_to_gajim_script = gtkgui_helpers.get_abspath_for_script(
3523 'gajim')
3525 if path_to_gajim_script:
3526 argv = [path_to_gajim_script]
3527 # FIXME: remove this typeerror catch when gnome python is old and
3528 # not bad patched by distro men [2.12.0 + should not need all that
3529 # NORMALLY]
3530 try:
3531 cli.set_restart_command(argv)
3532 except AttributeError:
3533 cli.set_restart_command(len(argv), argv)
3535 check_paths.check_and_possibly_create_paths()
3537 Interface()
3539 try:
3540 if os.name != 'nt':
3541 # This makes Gajim unusable under windows, and threads are used only
3542 # for GPG, so not under windows
3543 gtk.gdk.threads_init()
3544 gtk.main()
3545 except KeyboardInterrupt:
3546 print >> sys.stderr, 'KeyboardInterrupt'
3548 # vim: se ts=3: