2 ## src/groupchat_control.py
4 ## Copyright (C) 2003-2010 Yann Leboulanger <asterix AT lagaule.org>
5 ## Copyright (C) 2005-2007 Nikos Kouremenos <kourem AT gmail.com>
6 ## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
7 ## Alex Mauer <hawke AT hawkesnest.net>
8 ## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
9 ## Travis Shirk <travis AT pobox.com>
10 ## Copyright (C) 2007-2008 Julien Pivotto <roidelapluie AT gmail.com>
11 ## Stephan Erb <steve-e AT h3c.de>
12 ## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
13 ## Jonathan Schleifer <js-gajim AT webkeks.org>
15 ## This file is part of Gajim.
17 ## Gajim is free software; you can redistribute it and/or modify
18 ## it under the terms of the GNU General Public License as published
19 ## by the Free Software Foundation; version 3 only.
21 ## Gajim is distributed in the hope that it will be useful,
22 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ## GNU General Public License for more details.
26 ## You should have received a copy of the GNU General Public License
27 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
37 import gui_menu_builder
38 import message_control
43 import cell_renderer_image
44 import dataforms_widget
46 from common
import gajim
47 from common
import helpers
48 from common
import dataforms
49 from common
import ged
51 from chat_control
import ChatControl
52 from chat_control
import ChatControlBase
53 from common
.exceptions
import GajimGeneralException
55 from command_system
.implementation
.hosts
import PrivateChatCommands
56 from command_system
.implementation
.hosts
import GroupChatCommands
59 log
= logging
.getLogger('gajim.groupchat_control')
61 #(status_image, type, nick, shown_nick)
63 C_IMG
, # image to show state (online, new message etc)
64 C_NICK
, # contact nickame or ROLE name
65 C_TYPE
, # type of the row ('contact' or 'role')
66 C_TEXT
, # text shown in the cellrenderer
67 C_AVATAR
, # avatar of the contact
70 def set_renderer_color(treeview
, renderer
, set_background
=True):
72 Set style for group row, using PRELIGHT system color
75 bgcolor
= treeview
.style
.bg
[gtk
.STATE_PRELIGHT
]
76 renderer
.set_property('cell-background-gdk', bgcolor
)
78 fgcolor
= treeview
.style
.fg
[gtk
.STATE_PRELIGHT
]
79 renderer
.set_property('foreground-gdk', fgcolor
)
81 def tree_cell_data_func(column
, renderer
, model
, iter_
, tv
=None):
82 # cell data func is global, because we don't want it to keep
83 # reference to GroupchatControl instance (self)
84 theme
= gajim
.config
.get('roster_theme')
85 # allocate space for avatar only if needed
86 parent_iter
= model
.iter_parent(iter_
)
87 if isinstance(renderer
, gtk
.CellRendererPixbuf
):
88 avatar_position
= gajim
.config
.get('avatar_position_in_roster')
89 if avatar_position
== 'right':
90 renderer
.set_property('xalign', 1) # align pixbuf to the right
92 renderer
.set_property('xalign', 0.5)
93 if parent_iter
and (model
[iter_
][C_AVATAR
] or avatar_position
== \
95 renderer
.set_property('visible', True)
96 renderer
.set_property('width', gajim
.config
.get(
97 'roster_avatar_width'))
99 renderer
.set_property('visible', False)
101 bgcolor
= gajim
.config
.get_per('themes', theme
, 'contactbgcolor')
103 renderer
.set_property('cell-background', bgcolor
)
105 renderer
.set_property('cell-background', None)
106 if isinstance(renderer
, gtk
.CellRendererText
):
107 # foreground property is only with CellRendererText
108 color
= gajim
.config
.get_per('themes', theme
, 'contacttextcolor')
110 renderer
.set_property('foreground', color
)
112 renderer
.set_property('foreground', None)
113 renderer
.set_property('font',
114 gtkgui_helpers
.get_theme_font_for_option(theme
, 'contactfont'))
115 else: # it is root (eg. group)
116 bgcolor
= gajim
.config
.get_per('themes', theme
, 'groupbgcolor')
118 renderer
.set_property('cell-background', bgcolor
)
120 set_renderer_color(tv
, renderer
)
121 if isinstance(renderer
, gtk
.CellRendererText
):
122 # foreground property is only with CellRendererText
123 color
= gajim
.config
.get_per('themes', theme
, 'grouptextcolor')
125 renderer
.set_property('foreground', color
)
127 set_renderer_color(tv
, renderer
, False)
128 renderer
.set_property('font',
129 gtkgui_helpers
.get_theme_font_for_option(theme
, 'groupfont'))
132 class PrivateChatControl(ChatControl
):
133 TYPE_ID
= message_control
.TYPE_PM
135 # Set a command host to bound to. Every command given through a private chat
136 # will be processed with this command host.
137 COMMAND_HOST
= PrivateChatCommands
139 def __init__(self
, parent_win
, gc_contact
, contact
, account
, session
):
140 room_jid
= gc_contact
.room_jid
141 room_ctrl
= gajim
.interface
.msg_win_mgr
.get_gc_control(room_jid
,
143 if room_jid
in gajim
.interface
.minimized_controls
[account
]:
144 room_ctrl
= gajim
.interface
.minimized_controls
[account
][room_jid
]
146 self
.room_name
= room_ctrl
.name
148 self
.room_name
= room_jid
149 self
.gc_contact
= gc_contact
150 ChatControl
.__init
__(self
, parent_win
, contact
, account
, session
)
152 gajim
.ged
.register_event_handler('caps-received', ged
.GUI1
,
153 self
._nec
_caps
_received
_pm
)
154 gajim
.ged
.register_event_handler('gc-presence-received', ged
.GUI1
,
155 self
._nec
_gc
_presence
_received
)
158 super(PrivateChatControl
, self
).shutdown()
159 gajim
.ged
.remove_event_handler('caps-received', ged
.GUI1
,
160 self
._nec
_caps
_received
_pm
)
161 gajim
.ged
.remove_event_handler('gc-presence-received', ged
.GUI1
,
162 self
._nec
_gc
_presence
_received
)
164 def _nec_caps_received_pm(self
, obj
):
165 if obj
.conn
.name
!= self
.account
or \
166 obj
.fjid
!= self
.gc_contact
.get_full_jid():
168 self
.update_contact()
170 def _nec_gc_presence_received(self
, obj
):
171 if obj
.conn
.name
!= self
.account
:
173 if obj
.fjid
!= self
.full_jid
:
175 if '303' in obj
.status_code
:
176 self
.print_conversation(_('%(nick)s is now known as '
177 '%(new_nick)s') % {'nick': obj
.nick
, 'new_nick': obj
.new_nick
},
179 gc_c
= gajim
.contacts
.get_gc_contact(obj
.conn
.name
, obj
.room_jid
,
181 c
= gc_c
.as_contact()
182 self
.gc_contact
= gc_c
186 if self
.session
.enable_encryption
:
187 thread_id
= self
.session
.thread_id
188 self
.session
.terminate_e2e()
189 obj
.conn
.delete_session(obj
.fjid
, thread_id
)
190 self
.no_autonegotiation
= False
192 old_jid
= obj
.room_jid
+ '/' + obj
.nick
193 new_jid
= obj
.room_jid
+ '/' + obj
.new_nick
194 gajim
.interface
.msg_win_mgr
.change_key(old_jid
, new_jid
,
197 self
.contact
.show
= obj
.show
198 self
.contact
.status
= obj
.status
199 self
.gc_contact
.show
= obj
.show
200 self
.gc_contact
.status
= obj
.status
201 uf_show
= helpers
.get_uf_show(obj
.show
)
202 self
.print_conversation(_('%(nick)s is now %(status)s') % {
203 'nick': obj
.nick
, 'status': uf_show
}, 'status')
205 self
.print_conversation(' (', 'status', simple
=True)
206 self
.print_conversation('%s' % (obj
.status
), 'status',
208 self
.print_conversation(')', 'status', simple
=True)
209 self
.parent_win
.redraw_tab(self
)
212 def send_message(self
, message
, xhtml
=None, process_commands
=True):
214 Call this method to send the message
216 message
= helpers
.remove_invalid_xml_chars(message
)
220 # We need to make sure that we can still send through the room and that
221 # the recipient did not go away
222 contact
= gajim
.contacts
.get_first_contact_from_jid(self
.account
,
225 # contact was from pm in MUC
226 room
, nick
= gajim
.get_room_and_nick_from_fjid(self
.contact
.jid
)
227 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, room
, nick
)
230 _('Sending private message failed'),
231 #in second %s code replaces with nickname
232 _('You are no longer in group chat "%(room)s" or '
233 '"%(nick)s" has left.') % {'room': room
, 'nick': nick
})
236 ChatControl
.send_message(self
, message
, xhtml
=xhtml
,
237 process_commands
=process_commands
)
240 if self
.contact
.show
== 'offline':
241 self
.got_disconnected()
244 ChatControl
.update_ui(self
)
246 def update_contact(self
):
247 self
.contact
= self
.gc_contact
.as_contact()
249 def begin_e2e_negotiation(self
):
250 self
.no_autonegotiation
= True
253 fjid
= self
.gc_contact
.get_full_jid()
254 new_sess
= gajim
.connections
[self
.account
].make_new_session(fjid
,
256 self
.set_session(new_sess
)
258 self
.session
.negotiate_e2e(False)
260 def prepare_context_menu(self
, hide_buttonbar_items
=False):
262 Set compact view menuitem active state sets active and sensitivity state
263 for toggle_gpg_menuitem sets sensitivity for history_menuitem (False for
264 tranasports) and file_transfer_menuitem and hide()/show() for
265 add_to_roster_menuitem
267 menu
= gui_menu_builder
.get_contact_menu(self
.contact
, self
.account
,
268 use_multiple_contacts
=False, show_start_chat
=False,
269 show_encryption
=True, control
=self
,
270 show_buttonbar_items
=not hide_buttonbar_items
,
271 gc_contact
=self
.gc_contact
)
274 class GroupchatControl(ChatControlBase
):
275 TYPE_ID
= message_control
.TYPE_GC
277 # Set a command host to bound to. Every command given through a group chat
278 # will be processed with this command host.
279 COMMAND_HOST
= GroupChatCommands
281 def __init__(self
, parent_win
, contact
, acct
, is_continued
=False):
282 ChatControlBase
.__init
__(self
, self
.TYPE_ID
, parent_win
,
283 'groupchat_control', contact
, acct
)
285 self
.is_continued
= is_continued
286 self
.is_anonymous
= True
288 # Controls the state of autorejoin.
289 # None - autorejoin is neutral.
290 # False - autorejoin is to be prevented (gets reset to initial state in
292 # int - autorejoin is being active and working (gets reset to initial
293 # state in got_connected()).
294 self
.autorejoin
= None
296 # Keep error dialog instance to be sure to have only once at a time
297 self
.error_dialog
= None
299 self
.actions_button
= self
.xml
.get_object('muc_window_actions_button')
300 id_
= self
.actions_button
.connect('clicked',
301 self
.on_actions_button_clicked
)
302 self
.handlers
[id_
] = self
.actions_button
304 widget
= self
.xml
.get_object('change_nick_button')
305 id_
= widget
.connect('clicked', self
._on
_change
_nick
_menuitem
_activate
)
306 self
.handlers
[id_
] = widget
308 widget
= self
.xml
.get_object('change_subject_button')
309 id_
= widget
.connect('clicked',
310 self
._on
_change
_subject
_menuitem
_activate
)
311 self
.handlers
[id_
] = widget
313 widget
= self
.xml
.get_object('bookmark_button')
314 for bm
in gajim
.connections
[self
.account
].bookmarks
:
315 if bm
['jid'] == self
.contact
.jid
:
319 id_
= widget
.connect('clicked',
320 self
._on
_bookmark
_room
_menuitem
_activate
)
321 self
.handlers
[id_
] = widget
324 widget
= self
.xml
.get_object('list_treeview')
325 id_
= widget
.connect('row_expanded', self
.on_list_treeview_row_expanded
)
326 self
.handlers
[id_
] = widget
328 id_
= widget
.connect('row_collapsed',
329 self
.on_list_treeview_row_collapsed
)
330 self
.handlers
[id_
] = widget
332 id_
= widget
.connect('row_activated',
333 self
.on_list_treeview_row_activated
)
334 self
.handlers
[id_
] = widget
336 id_
= widget
.connect('button_press_event',
337 self
.on_list_treeview_button_press_event
)
338 self
.handlers
[id_
] = widget
340 id_
= widget
.connect('key_press_event',
341 self
.on_list_treeview_key_press_event
)
342 self
.handlers
[id_
] = widget
344 id_
= widget
.connect('motion_notify_event',
345 self
.on_list_treeview_motion_notify_event
)
346 self
.handlers
[id_
] = widget
348 id_
= widget
.connect('leave_notify_event',
349 self
.on_list_treeview_leave_notify_event
)
350 self
.handlers
[id_
] = widget
352 self
.room_jid
= self
.contact
.jid
353 self
.nick
= contact
.name
.decode('utf-8')
356 for bm
in gajim
.connections
[self
.account
].bookmarks
:
357 if bm
['jid'] == self
.room_jid
:
358 self
.name
= bm
['name']
361 self
.name
= self
.room_jid
.split('@')[0]
363 compact_view
= gajim
.config
.get('compact_view')
364 self
.chat_buttons_set_visible(compact_view
)
365 self
.widget_set_visible(self
.xml
.get_object('banner_eventbox'),
366 gajim
.config
.get('hide_groupchat_banner'))
367 self
.widget_set_visible(self
.xml
.get_object('list_scrolledwindow'),
368 gajim
.config
.get('hide_groupchat_occupants_list'))
370 self
._last
_selected
_contact
= None # None or holds jid, account tuple
372 # muc attention flag (when we are mentioned in a muc)
373 # if True, the room has mentioned us
374 self
.attention_flag
= False
376 # sorted list of nicks who mentioned us (last at the end)
377 self
.attention_list
= []
378 self
.room_creation
= int(time
.time()) # Use int to reduce mem usage
380 self
.last_key_tabs
= False
384 self
.tooltip
= tooltips
.GCTooltip()
387 self
.gc_count_nicknames_colors
= 0
388 self
.gc_custom_colors
= {}
389 self
.number_of_colors
= len(gajim
.config
.get('gc_nicknames_colors').\
392 self
.name_label
= self
.xml
.get_object('banner_name_label')
393 self
.event_box
= self
.xml
.get_object('banner_eventbox')
395 self
.list_treeview
= self
.xml
.get_object('list_treeview')
396 selection
= self
.list_treeview
.get_selection()
397 id_
= selection
.connect('changed',
398 self
.on_list_treeview_selection_changed
)
399 self
.handlers
[id_
] = selection
400 id_
= self
.list_treeview
.connect('style-set',
401 self
.on_list_treeview_style_set
)
402 self
.handlers
[id_
] = self
.list_treeview
403 self
.resize_from_another_muc
= False
404 # we want to know when the the widget resizes, because that is
405 # an indication that the hpaned has moved...
406 self
.hpaned
= self
.xml
.get_object('hpaned')
407 id_
= self
.hpaned
.connect('notify', self
.on_hpaned_notify
)
408 self
.handlers
[id_
] = self
.hpaned
410 # set the position of the current hpaned
411 hpaned_position
= gajim
.config
.get('gc-hpaned-position')
412 self
.hpaned
.set_position(hpaned_position
)
414 #status_image, shown_nick, type, nickname, avatar
415 self
.columns
= [gtk
.Image
, str, str, str, gtk
.gdk
.Pixbuf
]
416 store
= gtk
.TreeStore(*self
.columns
)
417 store
.set_sort_func(C_NICK
, self
.tree_compare_iters
)
418 store
.set_sort_column_id(C_NICK
, gtk
.SORT_ASCENDING
)
419 self
.list_treeview
.set_model(store
)
422 column
= gtk
.TreeViewColumn()
423 # list of renderers with attributes / properties in the form:
424 # (name, renderer_object, expand?, attribute_name, attribute_value,
425 # cell_data_func, func_arg)
426 self
.renderers_list
= []
427 # Number of renderers plugins added
428 self
.nb_ext_renderers
= 0
429 self
.renderers_propertys
= {}
430 renderer_image
= cell_renderer_image
.CellRendererImage(0, 0)
431 self
.renderers_propertys
[renderer_image
] = ('width', 26)
432 renderer_text
= gtk
.CellRendererText()
433 self
.renderers_propertys
[renderer_text
] = ('ellipsize',
436 self
.renderers_list
+= (
438 ('icon', renderer_image
, False,
439 'image', C_IMG
, tree_cell_data_func
, self
.list_treeview
),
441 ('name', renderer_text
, True,
442 'markup', C_TEXT
, tree_cell_data_func
, self
.list_treeview
))
445 avater_renderer
= ('avatar', gtk
.CellRendererPixbuf(),
446 False, 'pixbuf', C_AVATAR
,
447 tree_cell_data_func
, self
.list_treeview
)
449 if gajim
.config
.get('avatar_position_in_roster') == 'right':
450 self
.renderers_list
.append(avater_renderer
)
452 self
.renderers_list
.insert(0, avater_renderer
)
454 self
.fill_column(column
)
455 self
.list_treeview
.append_column(column
)
457 # workaround to avoid gtk arrows to be shown
458 column
= gtk
.TreeViewColumn() # 2nd COLUMN
459 renderer
= gtk
.CellRendererPixbuf()
460 column
.pack_start(renderer
, expand
=False)
461 self
.list_treeview
.append_column(column
)
462 column
.set_visible(False)
463 self
.list_treeview
.set_expander_column(column
)
465 self
.setup_seclabel(self
.xml
.get_object('label_selector'))
467 self
.form_widget
= None
469 gajim
.ged
.register_event_handler('gc-presence-received', ged
.GUI1
,
470 self
._nec
_gc
_presence
_received
)
471 gajim
.ged
.register_event_handler('gc-message-received', ged
.GUI1
,
472 self
._nec
_gc
_message
_received
)
473 gajim
.ged
.register_event_handler('vcard-published', ged
.GUI1
,
474 self
._nec
_vcard
_published
)
475 gajim
.ged
.register_event_handler('vcard-received', ged
.GUI1
,
476 self
._nec
_vcard
_received
)
477 gajim
.ged
.register_event_handler('gc-subject-received', ged
.GUI1
,
478 self
._nec
_gc
_subject
_received
)
479 gajim
.ged
.register_event_handler('gc-config-changed-received', ged
.GUI1
,
480 self
._nec
_gc
_config
_changed
_received
)
481 gajim
.ged
.register_event_handler('signed-in', ged
.GUI1
,
483 gajim
.gc_connected
[self
.account
][self
.room_jid
] = False
484 # disable win, we are not connected yet
485 ChatControlBase
.got_disconnected(self
)
488 self
.widget
.show_all()
490 # PluginSystem: adding GUI extension point for this GroupchatControl
492 gajim
.plugin_manager
.gui_extension_point('groupchat_control', self
)
494 def fill_column(self
, col
):
495 for rend
in self
.renderers_list
:
496 col
.pack_start(rend
[1], expand
=rend
[2])
497 col
.add_attribute(rend
[1], rend
[3], rend
[4])
498 col
.set_cell_data_func(rend
[1], rend
[5], rend
[6])
499 # set renderers propertys
500 for renderer
in self
.renderers_propertys
.keys():
501 renderer
.set_property(self
.renderers_propertys
[renderer
][0],
502 self
.renderers_propertys
[renderer
][1])
504 def tree_compare_iters(self
, model
, iter1
, iter2
):
506 Compare two iters to sort them
508 type1
= model
[iter1
][C_TYPE
]
509 type2
= model
[iter2
][C_TYPE
]
510 if not type1
or not type2
:
512 nick1
= model
[iter1
][C_NICK
]
513 nick2
= model
[iter2
][C_NICK
]
514 if not nick1
or not nick2
:
516 nick1
= nick1
.decode('utf-8')
517 nick2
= nick2
.decode('utf-8')
519 return locale
.strcoll(nick1
, nick2
)
520 if type1
== 'contact':
521 gc_contact1
= gajim
.contacts
.get_gc_contact(self
.account
,
522 self
.room_jid
, nick1
)
525 if type2
== 'contact':
526 gc_contact2
= gajim
.contacts
.get_gc_contact(self
.account
,
527 self
.room_jid
, nick2
)
530 if type1
== 'contact' and type2
== 'contact' and \
531 gajim
.config
.get('sort_by_show_in_muc'):
532 cshow
= {'chat':0, 'online': 1, 'away': 2, 'xa': 3, 'dnd': 4,
533 'invisible': 5, 'offline': 6, 'error': 7}
534 show1
= cshow
[gc_contact1
.show
]
535 show2
= cshow
[gc_contact2
.show
]
541 name1
= gc_contact1
.get_shown_name()
542 name2
= gc_contact2
.get_shown_name()
543 return locale
.strcoll(name1
.lower(), name2
.lower())
545 def on_msg_textview_populate_popup(self
, textview
, menu
):
547 Override the default context menu and we prepend Clear
548 and the ability to insert a nick
550 ChatControlBase
.on_msg_textview_populate_popup(self
, textview
, menu
)
551 item
= gtk
.SeparatorMenuItem()
554 item
= gtk
.MenuItem(_('Insert Nickname'))
557 item
.set_submenu(submenu
)
559 for nick
in sorted(gajim
.contacts
.get_nick_list(self
.account
,
561 item
= gtk
.MenuItem(nick
, use_underline
=False)
563 id_
= item
.connect('activate', self
.append_nick_in_msg_textview
,
565 self
.handlers
[id_
] = item
569 def resize_occupant_treeview(self
, position
):
570 self
.resize_from_another_muc
= True
571 self
.hpaned
.set_position(position
)
573 self
.resize_from_another_muc
= False
574 # Reset the flag when everything will be redrawn, and in particular when
575 # on_treeview_size_allocate will have been called.
576 gobject
.idle_add(reset_flag
)
578 def on_hpaned_notify(self
, pane
, gparamspec
):
580 The MUC treeview has resized. Move the hpaned in all tabs to match
582 if gparamspec
.name
!= 'position':
584 if self
.resize_from_another_muc
:
585 # Don't send the event to other MUC
588 hpaned_position
= self
.hpaned
.get_position()
589 gajim
.config
.set('gc-hpaned-position', hpaned_position
)
590 for account
in gajim
.gc_connected
:
591 for room_jid
in [i
for i
in gajim
.gc_connected
[account
] if \
592 gajim
.gc_connected
[account
][i
] and i
!= self
.room_jid
]:
593 ctrl
= gajim
.interface
.msg_win_mgr
.get_gc_control(room_jid
,
595 if not ctrl
and room_jid
in \
596 gajim
.interface
.minimized_controls
[account
]:
597 ctrl
= gajim
.interface
.minimized_controls
[account
][room_jid
]
598 if ctrl
and gajim
.config
.get('one_message_window') != 'never':
599 ctrl
.resize_occupant_treeview(hpaned_position
)
601 def iter_contact_rows(self
):
603 Iterate over all contact rows in the tree model
605 model
= self
.list_treeview
.get_model()
606 role_iter
= model
.get_iter_root()
608 contact_iter
= model
.iter_children(role_iter
)
610 yield model
[contact_iter
]
611 contact_iter
= model
.iter_next(contact_iter
)
612 role_iter
= model
.iter_next(role_iter
)
614 def on_list_treeview_style_set(self
, treeview
, style
):
616 When style (theme) changes, redraw all contacts
618 # Get the room_jid from treeview
619 for contact
in self
.iter_contact_rows():
620 nick
= contact
[C_NICK
].decode('utf-8')
621 self
.draw_contact(nick
)
623 def on_list_treeview_selection_changed(self
, selection
):
624 model
, selected_iter
= selection
.get_selected()
625 self
.draw_contact(self
.nick
)
626 if self
._last
_selected
_contact
is not None:
627 self
.draw_contact(self
._last
_selected
_contact
)
628 if selected_iter
is None:
629 self
._last
_selected
_contact
= None
631 contact
= model
[selected_iter
]
632 nick
= contact
[C_NICK
].decode('utf-8')
633 self
._last
_selected
_contact
= nick
634 if contact
[C_TYPE
] != 'contact':
636 self
.draw_contact(nick
, selected
=True, focus
=True)
638 def get_tab_label(self
, chatstate
):
640 Markup the label if necessary. Returns a tuple such as: (new_label_str,
641 color) either of which can be None if chatstate is given that means we
642 have HE SENT US a chatstate
645 has_focus
= self
.parent_win
.window
.get_property('has-toplevel-focus')
646 current_tab
= self
.parent_win
.get_active_control() == self
649 theme
= gajim
.config
.get('roster_theme')
650 if chatstate
== 'attention' and (not has_focus
or not current_tab
):
651 self
.attention_flag
= True
652 color_name
= gajim
.config
.get_per('themes', theme
,
653 'state_muc_directed_msg_color')
655 if chatstate
== 'active' or (current_tab
and has_focus
):
656 self
.attention_flag
= False
657 # get active color from gtk
658 color
= self
.parent_win
.notebook
.style
.fg
[gtk
.STATE_ACTIVE
]
659 elif chatstate
== 'newmsg' and (not has_focus
or not current_tab
) \
660 and not self
.attention_flag
:
661 color_name
= gajim
.config
.get_per('themes', theme
,
662 'state_muc_msg_color')
664 color
= gtk
.gdk
.colormap_get_system().alloc_color(color_name
)
666 if self
.is_continued
:
667 # if this is a continued conversation
668 label_str
= self
.get_continued_conversation_name()
670 label_str
= self
.name
672 # count waiting highlighted messages
674 num_unread
= self
.get_nb_unread()
678 unread
= '[' + unicode(num_unread
) + ']'
679 label_str
= unread
+ label_str
680 return (label_str
, color
)
682 def get_tab_image(self
, count_unread
=True):
683 # Set tab image (always 16x16)
685 if gajim
.gc_connected
[self
.account
][self
.room_jid
]:
686 tab_image
= gtkgui_helpers
.load_icon('muc_active')
688 tab_image
= gtkgui_helpers
.load_icon('muc_inactive')
692 ChatControlBase
.update_ui(self
)
693 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
694 self
.draw_contact(nick
)
696 def _change_style(self
, model
, path
, iter_
):
697 model
[iter_
][C_NICK
] = model
[iter_
][C_NICK
]
699 def change_roster_style(self
):
700 model
= self
.list_treeview
.get_model()
701 model
.foreach(self
._change
_style
)
703 def repaint_themed_widgets(self
):
704 ChatControlBase
.repaint_themed_widgets(self
)
705 self
.change_roster_style()
707 def _update_banner_state_image(self
):
708 banner_status_img
= self
.xml
.get_object('gc_banner_status_image')
709 images
= gajim
.interface
.jabber_state_images
710 if self
.room_jid
in gajim
.gc_connected
[self
.account
] and \
711 gajim
.gc_connected
[self
.account
][self
.room_jid
]:
714 image
= 'muc_inactive'
715 if '32' in images
and image
in images
['32']:
716 muc_icon
= images
['32'][image
]
717 if muc_icon
.get_storage_type() != gtk
.IMAGE_EMPTY
:
718 pix
= muc_icon
.get_pixbuf()
719 banner_status_img
.set_from_pixbuf(pix
)
721 # we need to scale 16x16 to 32x32
722 muc_icon
= images
['16'][image
]
723 pix
= muc_icon
.get_pixbuf()
724 scaled_pix
= pix
.scale_simple(32, 32, gtk
.gdk
.INTERP_BILINEAR
)
725 banner_status_img
.set_from_pixbuf(scaled_pix
)
727 def get_continued_conversation_name(self
):
729 Get the name of a continued conversation. Will return Continued
730 Conversation if there isn't any other contact in the room
733 for nick
in gajim
.contacts
.get_nick_list(self
.account
,
735 if nick
!= self
.nick
:
739 title
= _('Conversation with ') + title
.join(nicks
)
741 title
= _('Continued conversation')
744 def draw_banner_text(self
):
746 Draw the text in the fat line at the top of the window that houses the
749 self
.name_label
.set_ellipsize(pango
.ELLIPSIZE_END
)
750 self
.banner_status_label
.set_ellipsize(pango
.ELLIPSIZE_END
)
751 font_attrs
, font_attrs_small
= self
.get_font_attrs()
752 if self
.is_continued
:
753 name
= self
.get_continued_conversation_name()
756 text
= '<span %s>%s</span>' % (font_attrs
, name
)
757 self
.name_label
.set_markup(text
)
760 subject
= helpers
.reduce_chars_newlines(self
.subject
, max_lines
=2)
761 subject
= gobject
.markup_escape_text(subject
)
762 subject_text
= self
.urlfinder
.sub(self
.make_href
, subject
)
763 subject_text
= '<span %s>%s</span>' % (font_attrs_small
,
766 # tooltip must always hold ALL the subject
767 self
.event_box
.set_tooltip_text(self
.subject
)
768 self
.banner_status_label
.set_no_show_all(False)
769 self
.banner_status_label
.show()
772 self
.event_box
.set_has_tooltip(False)
773 self
.banner_status_label
.hide()
774 self
.banner_status_label
.set_no_show_all(True)
776 self
.banner_status_label
.set_markup(subject_text
)
778 def prepare_context_menu(self
, hide_buttonbar_items
=False):
780 Set sensitivity state for configure_room
782 xml
= gtkgui_helpers
.get_gtk_builder('gc_control_popup_menu.ui')
783 menu
= xml
.get_object('gc_control_popup_menu')
785 bookmark_room_menuitem
= xml
.get_object('bookmark_room_menuitem')
786 change_nick_menuitem
= xml
.get_object('change_nick_menuitem')
787 configure_room_menuitem
= xml
.get_object('configure_room_menuitem')
788 destroy_room_menuitem
= xml
.get_object('destroy_room_menuitem')
789 change_subject_menuitem
= xml
.get_object('change_subject_menuitem')
790 history_menuitem
= xml
.get_object('history_menuitem')
791 minimize_menuitem
= xml
.get_object('minimize_menuitem')
792 bookmark_separator
= xml
.get_object('bookmark_separator')
793 separatormenuitem2
= xml
.get_object('separatormenuitem2')
795 if hide_buttonbar_items
:
796 change_nick_menuitem
.hide()
797 change_subject_menuitem
.hide()
798 bookmark_room_menuitem
.hide()
799 history_menuitem
.hide()
800 bookmark_separator
.hide()
801 separatormenuitem2
.hide()
803 change_nick_menuitem
.show()
804 change_subject_menuitem
.show()
805 bookmark_room_menuitem
.show()
806 history_menuitem
.show()
807 bookmark_separator
.show()
808 separatormenuitem2
.show()
809 for bm
in gajim
.connections
[self
.account
].bookmarks
:
810 if bm
['jid'] == self
.room_jid
:
811 bookmark_room_menuitem
.hide()
812 bookmark_separator
.hide()
815 ag
= gtk
.accel_groups_from_object(self
.parent_win
.window
)[0]
816 change_nick_menuitem
.add_accelerator('activate', ag
, gtk
.keysyms
.n
,
817 gtk
.gdk
.CONTROL_MASK | gtk
.gdk
.SHIFT_MASK
, gtk
.ACCEL_VISIBLE
)
818 change_subject_menuitem
.add_accelerator('activate', ag
,
819 gtk
.keysyms
.t
, gtk
.gdk
.MOD1_MASK
, gtk
.ACCEL_VISIBLE
)
820 bookmark_room_menuitem
.add_accelerator('activate', ag
, gtk
.keysyms
.b
,
821 gtk
.gdk
.CONTROL_MASK
, gtk
.ACCEL_VISIBLE
)
822 history_menuitem
.add_accelerator('activate', ag
, gtk
.keysyms
.h
,
823 gtk
.gdk
.CONTROL_MASK
, gtk
.ACCEL_VISIBLE
)
825 if self
.contact
.jid
in gajim
.config
.get_per('accounts', self
.account
,
826 'minimized_gc').split(' '):
827 minimize_menuitem
.set_active(True)
828 if not gajim
.connections
[self
.account
].private_storage_supported
:
829 bookmark_room_menuitem
.set_sensitive(False)
830 if gajim
.gc_connected
[self
.account
][self
.room_jid
]:
831 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
833 if c
.affiliation
not in ('owner', 'admin'):
834 configure_room_menuitem
.set_sensitive(False)
836 configure_room_menuitem
.set_sensitive(True)
837 if c
.affiliation
!= 'owner':
838 destroy_room_menuitem
.set_sensitive(False)
840 destroy_room_menuitem
.set_sensitive(True)
841 change_subject_menuitem
.set_sensitive(True)
842 change_nick_menuitem
.set_sensitive(True)
844 # We are not connected to this groupchat, disable unusable menuitems
845 configure_room_menuitem
.set_sensitive(False)
846 destroy_room_menuitem
.set_sensitive(False)
847 change_subject_menuitem
.set_sensitive(False)
848 change_nick_menuitem
.set_sensitive(False)
850 # connect the menuitems to their respective functions
851 id_
= bookmark_room_menuitem
.connect('activate',
852 self
._on
_bookmark
_room
_menuitem
_activate
)
853 self
.handlers
[id_
] = bookmark_room_menuitem
855 id_
= change_nick_menuitem
.connect('activate',
856 self
._on
_change
_nick
_menuitem
_activate
)
857 self
.handlers
[id_
] = change_nick_menuitem
859 id_
= configure_room_menuitem
.connect('activate',
860 self
._on
_configure
_room
_menuitem
_activate
)
861 self
.handlers
[id_
] = configure_room_menuitem
863 id_
= destroy_room_menuitem
.connect('activate',
864 self
._on
_destroy
_room
_menuitem
_activate
)
865 self
.handlers
[id_
] = destroy_room_menuitem
867 id_
= change_subject_menuitem
.connect('activate',
868 self
._on
_change
_subject
_menuitem
_activate
)
869 self
.handlers
[id_
] = change_subject_menuitem
871 id_
= history_menuitem
.connect('activate',
872 self
._on
_history
_menuitem
_activate
)
873 self
.handlers
[id_
] = history_menuitem
875 id_
= minimize_menuitem
.connect('toggled',
876 self
.on_minimize_menuitem_toggled
)
877 self
.handlers
[id_
] = minimize_menuitem
879 menu
.connect('selection-done', self
.destroy_menu
,
880 change_nick_menuitem
, change_subject_menuitem
,
881 bookmark_room_menuitem
, history_menuitem
)
884 def destroy_menu(self
, menu
, change_nick_menuitem
, change_subject_menuitem
,
885 bookmark_room_menuitem
, history_menuitem
):
886 # destroy accelerators
887 ag
= gtk
.accel_groups_from_object(self
.parent_win
.window
)[0]
888 change_nick_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.n
,
889 gtk
.gdk
.CONTROL_MASK | gtk
.gdk
.SHIFT_MASK
)
890 change_subject_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.t
,
892 bookmark_room_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.b
,
893 gtk
.gdk
.CONTROL_MASK
)
894 history_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.h
,
895 gtk
.gdk
.CONTROL_MASK
)
899 def _nec_vcard_published(self
, obj
):
900 if obj
.conn
.name
!= self
.account
:
902 show
= gajim
.SHOW_LIST
[obj
.conn
.connected
]
903 status
= obj
.conn
.status
904 obj
.conn
.send_gc_status(self
.nick
, self
.room_jid
, show
, status
)
906 def _nec_vcard_received(self
, obj
):
907 if obj
.conn
.name
!= self
.account
:
909 if obj
.jid
!= self
.room_jid
:
911 self
.draw_avatar(obj
.resource
)
913 def _nec_gc_message_received(self
, obj
):
914 if obj
.room_jid
!= self
.room_jid
or obj
.conn
.name
!= self
.account
:
918 self
.form_widget
.hide()
919 self
.form_widget
.destroy()
920 self
.btn_box
.destroy()
921 dataform
= dataforms
.ExtendForm(node
=obj
.captcha_form
)
922 self
.form_widget
= dataforms_widget
.DataFormWidget(dataform
)
924 def on_send_dataform_clicked(widget
):
925 if not self
.form_widget
:
927 form_node
= self
.form_widget
.data_form
.get_purged()
928 form_node
.type = 'submit'
929 obj
.conn
.send_captcha(self
.room_jid
, form_node
)
930 self
.form_widget
.hide()
931 self
.form_widget
.destroy()
932 self
.btn_box
.destroy()
933 self
.form_widget
= None
936 self
.form_widget
.connect('validated', on_send_dataform_clicked
)
937 self
.form_widget
.show_all()
938 vbox
= self
.xml
.get_object('gc_textviews_vbox')
939 vbox
.pack_start(self
.form_widget
, expand
=False, fill
=False)
941 valid_button
= gtk
.Button(stock
=gtk
.STOCK_OK
)
942 valid_button
.connect('clicked', on_send_dataform_clicked
)
943 self
.btn_box
= gtk
.HButtonBox()
944 self
.btn_box
.set_layout(gtk
.BUTTONBOX_END
)
945 self
.btn_box
.pack_start(valid_button
)
946 self
.btn_box
.show_all()
947 vbox
.pack_start(self
.btn_box
, expand
=False, fill
=False)
949 self
.parent_win
.redraw_tab(self
, 'attention')
951 self
.attention_flag
= True
952 helpers
.play_sound('muc_message_received')
953 if '100' in obj
.status_code
:
954 # Room is not anonymous
955 self
.is_anonymous
= False
957 # message from server
958 self
.print_conversation(obj
.msgtxt
, tim
=obj
.timestamp
,
959 xhtml
=obj
.xhtml_msgtxt
, displaymarking
=obj
.displaymarking
)
961 # message from someone
962 if obj
.has_timestamp
:
963 # don't print xhtml if it's an old message.
964 # Like that xhtml messages are grayed too.
965 self
.print_old_conversation(obj
.msgtxt
, contact
=obj
.nick
,
966 tim
=obj
.timestamp
, xhtml
=None,
967 displaymarking
=obj
.displaymarking
)
969 self
.print_conversation(obj
.msgtxt
, contact
=obj
.nick
,
970 tim
=obj
.timestamp
, xhtml
=obj
.xhtml_msgtxt
,
971 displaymarking
=obj
.displaymarking
)
972 obj
.needs_highlight
= self
.needs_visual_notification(obj
.msgtxt
)
974 def on_private_message(self
, nick
, msg
, tim
, xhtml
, session
, msg_id
=None,
975 encrypted
=False, displaymarking
=None):
976 # Do we have a queue?
977 fjid
= self
.room_jid
+ '/' + nick
978 no_queue
= len(gajim
.events
.get_events(self
.account
, fjid
)) == 0
980 event
= gajim
.events
.create_event('pm', (msg
, '', 'incoming', tim
,
981 encrypted
, '', msg_id
, xhtml
, session
, displaymarking
))
982 gajim
.events
.add_event(self
.account
, fjid
, event
)
984 autopopup
= gajim
.config
.get('autopopup')
985 autopopupaway
= gajim
.config
.get('autopopupaway')
986 iter_
= self
.get_contact_iter(nick
)
987 path
= self
.list_treeview
.get_model().get_path(iter_
)
988 if not autopopup
or (not autopopupaway
and \
989 gajim
.connections
[self
.account
].connected
> 2):
990 if no_queue
: # We didn't have a queue: we change icons
991 model
= self
.list_treeview
.get_model()
993 gajim
.interface
.roster
.get_appropriate_state_images(
994 self
.room_jid
, icon_name
='event')
995 image
= state_images
['event']
996 model
[iter_
][C_IMG
] = image
998 self
.parent_win
.show_title()
999 self
.parent_win
.redraw_tab(self
)
1001 self
._start
_private
_message
(nick
)
1003 self
.list_treeview
.expand_row(path
[0:1], False)
1004 self
.list_treeview
.scroll_to_cell(path
)
1005 self
.list_treeview
.set_cursor(path
)
1006 contact
= gajim
.contacts
.get_contact_with_highest_priority(
1007 self
.account
, self
.room_jid
)
1009 gajim
.interface
.roster
.draw_contact(self
.room_jid
, self
.account
)
1011 def get_contact_iter(self
, nick
):
1012 model
= self
.list_treeview
.get_model()
1013 role_iter
= model
.get_iter_root()
1015 user_iter
= model
.iter_children(role_iter
)
1017 if nick
== model
[user_iter
][C_NICK
].decode('utf-8'):
1020 user_iter
= model
.iter_next(user_iter
)
1021 role_iter
= model
.iter_next(role_iter
)
1024 def print_old_conversation(self
, text
, contact
='', tim
=None, xhtml
= None,
1025 displaymarking
=None):
1026 if isinstance(text
, str):
1027 text
= unicode(text
, 'utf-8')
1029 if contact
== self
.nick
: # it's us
1035 if gajim
.config
.get('restored_messages_small'):
1036 small_attr
= ['small']
1039 ChatControlBase
.print_conversation_line(self
, text
, kind
, contact
, tim
,
1040 small_attr
, small_attr
+ ['restored_message'],
1041 small_attr
+ ['restored_message'], count_as_new
=False, xhtml
=xhtml
,
1042 displaymarking
=displaymarking
)
1044 def print_conversation(self
, text
, contact
='', tim
=None, xhtml
=None,
1045 graphics
=True, displaymarking
=None):
1047 Print a line in the conversation
1049 If contact is set: it's a message from someone or an info message
1050 (contact = 'info' in such a case).
1051 If contact is not set: it's a message from the server or help.
1053 if isinstance(text
, str):
1054 text
= unicode(text
, 'utf-8')
1055 other_tags_for_name
= []
1056 other_tags_for_text
= []
1058 if contact
== self
.nick
: # it's us
1060 elif contact
== 'info':
1065 # muc-specific chatstate
1067 self
.parent_win
.redraw_tab(self
, 'newmsg')
1071 if kind
== 'incoming': # it's a message NOT from us
1072 # highlighting and sounds
1073 (highlight
, sound
) = self
.highlighting_for_message(text
, tim
)
1074 if contact
in self
.gc_custom_colors
:
1075 other_tags_for_name
.append('gc_nickname_color_' + \
1076 str(self
.gc_custom_colors
[contact
]))
1078 self
.gc_count_nicknames_colors
+= 1
1079 if self
.gc_count_nicknames_colors
== self
.number_of_colors
:
1080 self
.gc_count_nicknames_colors
= 0
1081 self
.gc_custom_colors
[contact
] = \
1082 self
.gc_count_nicknames_colors
1083 other_tags_for_name
.append('gc_nickname_color_' + \
1084 str(self
.gc_count_nicknames_colors
))
1086 # muc-specific chatstate
1088 self
.parent_win
.redraw_tab(self
, 'attention')
1090 self
.attention_flag
= True
1091 other_tags_for_name
.append('bold')
1092 other_tags_for_text
.append('marked')
1094 if contact
in self
.attention_list
:
1095 self
.attention_list
.remove(contact
)
1096 elif len(self
.attention_list
) > 6:
1097 self
.attention_list
.pop(0) # remove older
1098 self
.attention_list
.append(contact
)
1100 if sound
== 'received':
1101 helpers
.play_sound('muc_message_received')
1102 elif sound
== 'highlight':
1103 helpers
.play_sound('muc_message_highlight')
1104 if text
.startswith('/me ') or text
.startswith('/me\n'):
1105 other_tags_for_text
.append('gc_nickname_color_' + \
1106 str(self
.gc_custom_colors
[contact
]))
1108 self
.check_and_possibly_add_focus_out_line()
1110 ChatControlBase
.print_conversation_line(self
, text
, kind
, contact
, tim
,
1111 other_tags_for_name
, [], other_tags_for_text
, xhtml
=xhtml
,
1112 graphics
=graphics
, displaymarking
=displaymarking
)
1114 def get_nb_unread(self
):
1115 type_events
= ['printed_marked_gc_msg']
1116 if gajim
.config
.get('notify_on_all_muc_messages'):
1117 type_events
.append('printed_gc_msg')
1118 nb
= len(gajim
.events
.get_events(self
.account
, self
.room_jid
,
1120 nb
+= self
.get_nb_unread_pm()
1123 def get_nb_unread_pm(self
):
1125 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
1126 nb
+= len(gajim
.events
.get_events(self
.account
, self
.room_jid
+ \
1127 '/' + nick
, ['pm']))
1130 def highlighting_for_message(self
, text
, tim
):
1132 Returns a 2-Tuple. The first says whether or not to highlight the text,
1133 the second, what sound to play
1135 highlight
, sound
= (None, None)
1137 # Are any of the defined highlighting words in the text?
1138 if self
.needs_visual_notification(text
):
1140 if gajim
.config
.get_per('soundevents', 'muc_message_highlight',
1144 # Do we play a sound on every muc message?
1145 elif gajim
.config
.get_per('soundevents', 'muc_message_received', \
1149 # Is it a history message? Don't want sound-floods when we join.
1150 if tim
!= time
.localtime():
1153 return (highlight
, sound
)
1155 def check_and_possibly_add_focus_out_line(self
):
1157 Check and possibly add focus out line for room_jid if it needs it and
1158 does not already have it as last event. If it goes to add this line
1159 - remove previous line first
1161 win
= gajim
.interface
.msg_win_mgr
.get_window(self
.room_jid
,
1163 if win
and self
.room_jid
== win
.get_active_jid() and\
1164 win
.window
.get_property('has-toplevel-focus') and\
1165 self
.parent_win
.get_active_control() == self
:
1166 # it's the current room and it's the focused window.
1167 # we have full focus (we are reading it!)
1170 at_the_end
= self
.conv_textview
.at_the_end()
1171 self
.conv_textview
.show_focus_out_line(scroll
=at_the_end
)
1173 def needs_visual_notification(self
, text
):
1175 Check text to see whether any of the words in (muc_highlight_words and
1178 special_words
= gajim
.config
.get('muc_highlight_words').split(';')
1179 special_words
.append(self
.nick
)
1180 # Strip empties: ''.split(';') == [''] and would highlight everything.
1181 # Also lowercase everything for case insensitive compare.
1182 special_words
= [word
.lower() for word
in special_words
if word
]
1185 for special_word
in special_words
:
1186 found_here
= text
.find(special_word
)
1187 while(found_here
> -1):
1188 end_here
= found_here
+ len(special_word
)
1189 if (found_here
== 0 or not text
[found_here
- 1].isalpha()) and \
1190 (end_here
== len(text
) or not text
[end_here
].isalpha()):
1191 # It is beginning of text or char before is not alpha AND
1192 # it is end of text or char after is not alpha
1194 # continue searching
1195 start
= found_here
+ 1
1196 found_here
= text
.find(special_word
, start
)
1199 def set_subject(self
, subject
):
1200 self
.subject
= subject
1201 self
.draw_banner_text()
1203 def _nec_gc_subject_received(self
, obj
):
1204 if obj
.conn
.name
!= self
.account
:
1206 if obj
.room_jid
!= self
.room_jid
:
1208 self
.set_subject(obj
.subject
)
1209 text
= _('%(nick)s has set the subject to %(subject)s') % {
1210 'nick': obj
.nickname
, 'subject': obj
.subject
}
1211 if obj
.has_timestamp
:
1212 self
.print_old_conversation(text
)
1214 self
.print_conversation(text
)
1216 def _nec_gc_config_changed_received(self
, obj
):
1217 # statuscode is a list
1218 # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
1219 # http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes...
1221 if obj
.room_jid
!= self
.room_jid
or obj
.conn
.name
!= self
.account
:
1225 if '100' in obj
.status_code
:
1226 # Can be a presence (see chg_contact_status in groupchat_control.py)
1227 changes
.append(_('Any occupant is allowed to see your full JID'))
1228 self
.is_anonymous
= False
1229 if '102' in obj
.status_code
:
1230 changes
.append(_('Room now shows unavailable member'))
1231 if '103' in obj
.status_code
:
1232 changes
.append(_('room now does not show unavailable members'))
1233 if '104' in obj
.status_code
:
1234 changes
.append(_('A non-privacy-related room configuration change '
1236 if '170' in obj
.status_code
:
1237 # Can be a presence (see chg_contact_status in groupchat_control.py)
1238 changes
.append(_('Room logging is now enabled'))
1239 if '171' in obj
.status_code
:
1240 changes
.append(_('Room logging is now disabled'))
1241 if '172' in obj
.status_code
:
1242 changes
.append(_('Room is now non-anonymous'))
1243 self
.is_anonymous
= False
1244 if '173' in obj
.status_code
:
1245 changes
.append(_('Room is now semi-anonymous'))
1246 self
.is_anonymous
= True
1247 if '174' in obj
.status_code
:
1248 changes
.append(_('Room is now fully-anonymous'))
1249 self
.is_anonymous
= True
1251 for change
in changes
:
1252 self
.print_conversation(change
)
1254 def _nec_signed_in(self
, obj
):
1255 if obj
.conn
.name
!= self
.account
:
1257 if self
.room_jid
in gajim
.gc_connected
[obj
.conn
.name
] and \
1258 gajim
.gc_connected
[obj
.conn
.name
][self
.room_jid
]:
1260 password
= gajim
.gc_passwords
.get(self
.room_jid
, '')
1261 obj
.conn
.join_gc(self
.nick
, self
.room_jid
, password
)
1263 def got_connected(self
):
1264 # Make autorejoin stop.
1266 gobject
.source_remove(self
.autorejoin
)
1267 self
.autorejoin
= None
1269 gajim
.gc_connected
[self
.account
][self
.room_jid
] = True
1270 ChatControlBase
.got_connected(self
)
1271 # We don't redraw the whole banner here, because only icon change
1272 self
._update
_banner
_state
_image
()
1274 self
.parent_win
.redraw_tab(self
)
1275 gobject
.idle_add(self
.msg_textview
.grab_focus
)
1277 def got_disconnected(self
):
1278 self
.list_treeview
.get_model().clear()
1279 nick_list
= gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
)
1280 for nick
in nick_list
:
1281 # Update pm chat window
1282 fjid
= self
.room_jid
+ '/' + nick
1283 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
,
1284 self
.room_jid
, nick
)
1286 ctrl
= gajim
.interface
.msg_win_mgr
.get_control(fjid
, self
.account
)
1288 gc_contact
.show
= 'offline'
1289 gc_contact
.status
= ''
1292 ctrl
.parent_win
.redraw_tab(ctrl
)
1294 gajim
.contacts
.remove_gc_contact(self
.account
, gc_contact
)
1295 gajim
.gc_connected
[self
.account
][self
.room_jid
] = False
1296 ChatControlBase
.got_disconnected(self
)
1297 # Tell connection to note the date we disconnect to avoid duplicate logs
1298 gajim
.connections
[self
.account
].gc_got_disconnected(self
.room_jid
)
1299 # We don't redraw the whole banner here, because only icon change
1300 self
._update
_banner
_state
_image
()
1302 self
.parent_win
.redraw_tab(self
)
1304 # Autorejoin stuff goes here.
1305 # Notice that we don't need to activate autorejoin if connection is lost
1307 if self
.autorejoin
is None and gajim
.account_is_connected(self
.account
):
1308 ar_to
= gajim
.config
.get('muc_autorejoin_timeout')
1310 self
.autorejoin
= gobject
.timeout_add_seconds(ar_to
,
1314 if not self
.autorejoin
:
1316 password
= gajim
.gc_passwords
.get(self
.room_jid
, '')
1317 gajim
.connections
[self
.account
].join_gc(self
.nick
, self
.room_jid
,
1321 def draw_roster(self
):
1322 self
.list_treeview
.get_model().clear()
1323 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
1324 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
,
1325 self
.room_jid
, nick
)
1326 self
.add_contact_to_roster(nick
, gc_contact
.show
, gc_contact
.role
,
1327 gc_contact
.affiliation
, gc_contact
.status
, gc_contact
.jid
)
1328 self
.draw_all_roles()
1329 # Recalculate column width for ellipsizin
1330 self
.list_treeview
.columns_autosize()
1332 def on_send_pm(self
, widget
=None, model
=None, iter_
=None, nick
=None,
1335 Open a chat window and if msg is not None - send private message to a
1339 nick
= model
[iter_
][C_NICK
].decode('utf-8')
1341 ctrl
= self
._start
_private
_message
(nick
)
1343 ctrl
.send_message(msg
)
1345 def on_send_file(self
, widget
, gc_contact
):
1347 Send a file to a contact in the room
1349 self
._on
_send
_file
(gc_contact
)
1351 def draw_contact(self
, nick
, selected
=False, focus
=False):
1352 iter_
= self
.get_contact_iter(nick
)
1355 model
= self
.list_treeview
.get_model()
1356 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1358 state_images
= gajim
.interface
.jabber_state_images
['16']
1359 if len(gajim
.events
.get_events(self
.account
, self
.room_jid
+ '/' + \
1361 image
= state_images
['event']
1363 image
= state_images
[gc_contact
.show
]
1365 name
= gobject
.markup_escape_text(gc_contact
.name
)
1367 # Strike name if blocked
1368 fjid
= self
.room_jid
+ '/' + nick
1369 if helpers
.jid_is_blocked(self
.account
, fjid
):
1370 name
= '<span strikethrough="true">%s</span>' % name
1372 status
= gc_contact
.status
1373 # add status msg, if not empty, under contact name in the treeview
1374 if status
and gajim
.config
.get('show_status_msgs_in_roster'):
1375 status
= status
.strip()
1377 status
= helpers
.reduce_chars_newlines(status
, max_lines
=1)
1378 # escape markup entities and make them small italic and fg color
1379 color
= gtkgui_helpers
.get_fade_color(self
.list_treeview
,
1381 colorstring
= "#%04x%04x%04x" % (color
.red
, color
.green
,
1383 name
+= ('\n<span size="small" style="italic" foreground="%s">'
1384 '%s</span>') % (colorstring
, gobject
.markup_escape_text(
1387 if image
.get_storage_type() == gtk
.IMAGE_PIXBUF
and \
1388 gc_contact
.affiliation
!= 'none' and gajim
.config
.get(
1389 'show_affiliation_in_groupchat'):
1390 pixbuf1
= image
.get_pixbuf().copy()
1391 pixbuf2
= gtk
.gdk
.Pixbuf(gtk
.gdk
.COLORSPACE_RGB
, True, 8, 4, 4)
1392 if gc_contact
.affiliation
== 'owner':
1393 pixbuf2
.fill(0xff0000ff) # Red
1394 elif gc_contact
.affiliation
== 'admin':
1395 pixbuf2
.fill(0xffb200ff) # Oragne
1396 elif gc_contact
.affiliation
== 'member':
1397 pixbuf2
.fill(0x00ff00ff) # Green
1398 pixbuf2
.composite(pixbuf1
, 12, 12, pixbuf2
.get_property('width'),
1399 pixbuf2
.get_property('height'), 0, 0, 1.0, 1.0,
1400 gtk
.gdk
.INTERP_HYPER
, 127)
1401 image
= gtk
.image_new_from_pixbuf(pixbuf1
)
1402 model
[iter_
][C_IMG
] = image
1403 model
[iter_
][C_TEXT
] = name
1405 def draw_avatar(self
, nick
):
1406 if not gajim
.config
.get('show_avatars_in_roster'):
1408 model
= self
.list_treeview
.get_model()
1409 iter_
= self
.get_contact_iter(nick
)
1412 fake_jid
= self
.room_jid
+ '/' + nick
1413 pixbuf
= gtkgui_helpers
.get_avatar_pixbuf_from_cache(fake_jid
)
1414 if pixbuf
in ('ask', None):
1415 scaled_pixbuf
= None
1417 scaled_pixbuf
= gtkgui_helpers
.get_scaled_pixbuf(pixbuf
, 'roster')
1418 model
[iter_
][C_AVATAR
] = scaled_pixbuf
1420 def draw_role(self
, role
):
1421 role_iter
= self
.get_role_iter(role
)
1424 model
= self
.list_treeview
.get_model()
1425 role_name
= helpers
.get_uf_role(role
, plural
=True)
1426 if gajim
.config
.get('show_contacts_number'):
1427 nbr_role
, nbr_total
= gajim
.contacts
.get_nb_role_total_gc_contacts(
1428 self
.account
, self
.room_jid
, role
)
1429 role_name
+= ' (%s/%s)' % (repr(nbr_role
), repr(nbr_total
))
1430 model
[role_iter
][C_TEXT
] = role_name
1432 def draw_all_roles(self
):
1433 for role
in ('visitor', 'participant', 'moderator'):
1434 self
.draw_role(role
)
1436 def _nec_gc_presence_received(self
, obj
):
1437 if obj
.room_jid
!= self
.room_jid
or obj
.conn
.name
!= self
.account
:
1439 if obj
.ptype
== 'error':
1446 affiliation
= obj
.affiliation
1448 affiliation
= 'none'
1450 newly_created
= False
1453 # Set to true if role or affiliation have changed
1454 right_changed
= False
1458 simple_jid
= gajim
.get_jid_without_resource(obj
.real_jid
)
1459 nick_jid
+= ' (%s)' % simple_jid
1462 # http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes-\
1465 if '100' in obj
.status_code
:
1466 # Can be a message (see handle_event_gc_config_change in
1468 self
.print_conversation(
1469 _('Any occupant is allowed to see your full JID'))
1470 if '170' in obj
.status_code
:
1471 # Can be a message (see handle_event_gc_config_change in
1473 self
.print_conversation(_('Room logging is enabled'))
1474 if '201' in obj
.status_code
:
1475 self
.print_conversation(_('A new room has been created'))
1476 if '210' in obj
.status_code
:
1477 self
.print_conversation(\
1478 _('The server has assigned or modified your roomnick'))
1480 if obj
.show
in ('offline', 'error'):
1482 if '307' in obj
.status_code
:
1483 if obj
.actor
is None: # do not print 'kicked by None'
1484 s
= _('%(nick)s has been kicked: %(reason)s') % {
1485 'nick': obj
.nick
, 'reason': obj
.reason
}
1487 s
= _('%(nick)s has been kicked by %(who)s: '
1488 '%(reason)s') % {'nick': obj
.nick
, 'who': obj
.actor
,
1489 'reason': obj
.reason
}
1490 self
.print_conversation(s
, 'info', graphics
=False)
1491 if obj
.nick
== self
.nick
and not gajim
.config
.get(
1492 'muc_autorejoin_on_kick'):
1493 self
.autorejoin
= False
1494 elif '301' in obj
.status_code
:
1495 if obj
.actor
is None: # do not print 'banned by None'
1496 s
= _('%(nick)s has been banned: %(reason)s') % {
1497 'nick': obj
.nick
, 'reason': obj
.reason
}
1499 s
= _('%(nick)s has been banned by %(who)s: '
1500 '%(reason)s') % {'nick': obj
.nick
, 'who': obj
.actor
,
1501 'reason': obj
.reason
}
1502 self
.print_conversation(s
, 'info', graphics
=False)
1503 if obj
.nick
== self
.nick
:
1504 self
.autorejoin
= False
1505 elif '303' in obj
.status_code
: # Someone changed his or her nick
1506 if obj
.new_nick
== self
.new_nick
or obj
.nick
== self
.nick
:
1507 # We changed our nick
1508 self
.nick
= obj
.new_nick
1510 s
= _('You are now known as %s') % self
.nick
1511 # Stop all E2E sessions
1512 nick_list
= gajim
.contacts
.get_nick_list(self
.account
,
1514 for nick_
in nick_list
:
1515 fjid_
= self
.room_jid
+ '/' + nick_
1516 ctrl
= gajim
.interface
.msg_win_mgr
.get_control(
1517 fjid_
, self
.account
)
1518 if ctrl
and ctrl
.session
and \
1519 ctrl
.session
.enable_encryption
:
1520 thread_id
= ctrl
.session
.thread_id
1521 ctrl
.session
.terminate_e2e()
1522 gajim
.connections
[self
.account
].delete_session(
1524 ctrl
.no_autonegotiation
= False
1526 s
= _('%(nick)s is now known as %(new_nick)s') % {
1527 'nick': obj
.nick
, 'new_nick': obj
.new_nick
}
1528 # We add new nick to muc roster here, so we don't see
1529 # that "new_nick has joined the room" when he just changed
1531 # add_contact_to_roster will be called a second time
1532 # after that, but that doesn't hurt
1533 self
.add_contact_to_roster(obj
.new_nick
, obj
.show
, role
,
1534 affiliation
, obj
.status
, obj
.real_jid
)
1535 if obj
.nick
in self
.attention_list
:
1536 self
.attention_list
.remove(obj
.nick
)
1537 # keep nickname color
1538 if obj
.nick
in self
.gc_custom_colors
:
1539 self
.gc_custom_colors
[obj
.new_nick
] = \
1540 self
.gc_custom_colors
[obj
.nick
]
1541 # rename vcard / avatar
1542 puny_jid
= helpers
.sanitize_filename(self
.room_jid
)
1543 puny_nick
= helpers
.sanitize_filename(obj
.nick
)
1544 puny_new_nick
= helpers
.sanitize_filename(obj
.new_nick
)
1545 old_path
= os
.path
.join(gajim
.VCARD_PATH
, puny_jid
,
1547 new_path
= os
.path
.join(gajim
.VCARD_PATH
, puny_jid
,
1549 files
= {old_path
: new_path
}
1550 path
= os
.path
.join(gajim
.AVATAR_PATH
, puny_jid
)
1551 # possible extensions
1552 for ext
in ('.png', '.jpeg', '_notif_size_bw.png',
1553 '_notif_size_colored.png'):
1554 files
[os
.path
.join(path
, puny_nick
+ ext
)] = \
1555 os
.path
.join(path
, puny_new_nick
+ ext
)
1556 for old_file
in files
:
1557 if os
.path
.exists(old_file
) and old_file
!= \
1559 if os
.path
.exists(files
[old_file
]) and \
1560 helpers
.windowsify(old_file
) != helpers
.windowsify(
1562 # Windows require this, but os.remove('test')
1563 # will also remove 'TEST'
1564 os
.remove(files
[old_file
])
1565 os
.rename(old_file
, files
[old_file
])
1566 self
.print_conversation(s
, 'info', graphics
=False)
1567 elif '321' in obj
.status_code
:
1568 s
= _('%(nick)s has been removed from the room '
1569 '(%(reason)s)') % { 'nick': obj
.nick
,
1570 'reason': _('affiliation changed') }
1571 self
.print_conversation(s
, 'info', graphics
=False)
1572 elif '322' in obj
.status_code
:
1573 s
= _('%(nick)s has been removed from the room '
1574 '(%(reason)s)') % { 'nick': obj
.nick
,
1575 'reason': _('room configuration changed to '
1577 self
.print_conversation(s
, 'info', graphics
=False)
1578 elif '332' in obj
.status_code
:
1579 s
= _('%(nick)s has been removed from the room '
1580 '(%(reason)s)') % {'nick': obj
.nick
,
1581 'reason': _('system shutdown') }
1582 self
.print_conversation(s
, 'info', graphics
=False)
1583 # Room has been destroyed.
1584 elif 'destroyed' in obj
.status_code
:
1585 self
.autorejoin
= False
1586 self
.print_conversation(obj
.reason
, 'info', graphics
=False)
1588 if len(gajim
.events
.get_events(self
.account
, jid
=obj
.fjid
,
1589 types
=['pm'])) == 0:
1590 self
.remove_contact(obj
.nick
)
1591 self
.draw_all_roles()
1593 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1596 c
.status
= obj
.status
1597 if obj
.nick
== self
.nick
and (not obj
.status_code
or \
1598 '303' not in obj
.status_code
): # We became offline
1599 self
.got_disconnected()
1600 contact
= gajim
.contacts
.\
1601 get_contact_with_highest_priority(self
.account
,
1604 gajim
.interface
.roster
.draw_contact(self
.room_jid
,
1607 self
.parent_win
.redraw_tab(self
)
1609 iter_
= self
.get_contact_iter(obj
.nick
)
1611 if '210' in obj
.status_code
:
1612 # Server changed our nick
1613 self
.nick
= obj
.nick
1614 s
= _('You are now known as %s') % obj
.nick
1615 self
.print_conversation(s
, 'info', graphics
=False)
1616 iter_
= self
.add_contact_to_roster(obj
.nick
, obj
.show
, role
,
1617 affiliation
, obj
.status
, obj
.real_jid
)
1618 newly_created
= True
1619 self
.draw_all_roles()
1620 if obj
.status_code
and '201' in obj
.status_code
:
1621 # We just created the room
1622 gajim
.connections
[self
.account
].request_gc_config(
1625 gc_c
= gajim
.contacts
.get_gc_contact(self
.account
,
1626 self
.room_jid
, obj
.nick
)
1628 log
.error('%s has an iter, but no gc_contact instance' % \
1631 # Re-get vcard if avatar has changed
1632 # We do that here because we may request it to the real JID if
1633 # we knows it. connections.py doesn't know it.
1634 con
= gajim
.connections
[self
.account
]
1635 if gc_c
and gc_c
.jid
:
1639 if obj
.fjid
in obj
.conn
.vcard_shas
:
1640 if obj
.avatar_sha
!= obj
.conn
.vcard_shas
[obj
.fjid
]:
1641 server
= gajim
.get_server_from_jid(self
.room_jid
)
1642 if not server
.startswith('irc'):
1643 obj
.conn
.request_vcard(real_jid
, obj
.fjid
)
1645 cached_vcard
= obj
.conn
.get_cached_vcard(obj
.fjid
, True)
1646 if cached_vcard
and 'PHOTO' in cached_vcard
and \
1647 'SHA' in cached_vcard
['PHOTO']:
1648 cached_sha
= cached_vcard
['PHOTO']['SHA']
1651 if cached_sha
!= obj
.avatar_sha
:
1652 # avatar has been updated
1653 # sha in mem will be updated later
1654 server
= gajim
.get_server_from_jid(self
.room_jid
)
1655 if not server
.startswith('irc'):
1656 obj
.conn
.request_vcard(real_jid
, obj
.fjid
)
1658 # save sha in mem NOW
1659 obj
.conn
.vcard_shas
[obj
.fjid
] = obj
.avatar_sha
1661 actual_affiliation
= gc_c
.affiliation
1662 if affiliation
!= actual_affiliation
:
1664 st
= _('** Affiliation of %(nick)s has been set to '
1665 '%(affiliation)s by %(actor)s') % {'nick': nick_jid
,
1666 'affiliation': affiliation
, 'actor': obj
.actor
}
1668 st
= _('** Affiliation of %(nick)s has been set to '
1669 '%(affiliation)s') % {'nick': nick_jid
,
1670 'affiliation': affiliation
}
1672 st
+= ' (%s)' % obj
.reason
1673 self
.print_conversation(st
, graphics
=False)
1674 right_changed
= True
1675 actual_role
= self
.get_role(obj
.nick
)
1676 if role
!= actual_role
:
1677 self
.remove_contact(obj
.nick
)
1678 self
.add_contact_to_roster(obj
.nick
, obj
.show
, role
,
1679 affiliation
, obj
.status
, obj
.real_jid
)
1680 self
.draw_role(actual_role
)
1681 self
.draw_role(role
)
1683 st
= _('** Role of %(nick)s has been set to %(role)s '
1684 'by %(actor)s') % {'nick': nick_jid
, 'role': role
,
1687 st
= _('** Role of %(nick)s has been set to '
1688 '%(role)s') % {'nick': nick_jid
, 'role': role
}
1690 st
+= ' (%s)' % obj
.reason
1691 self
.print_conversation(st
, graphics
=False)
1692 right_changed
= True
1694 if gc_c
.show
== obj
.show
and gc_c
.status
== obj
.status
and \
1695 gc_c
.affiliation
== affiliation
: # no change
1697 gc_c
.show
= obj
.show
1698 gc_c
.affiliation
= affiliation
1699 gc_c
.status
= obj
.status
1700 self
.draw_contact(obj
.nick
)
1701 if (time
.time() - self
.room_creation
) > 30 and obj
.nick
!= self
.nick \
1702 and (not obj
.status_code
or '303' not in obj
.status_code
) and not \
1706 for bookmark
in gajim
.connections
[self
.account
].bookmarks
:
1707 if bookmark
['jid'] == self
.room_jid
:
1708 print_status
= bookmark
.get('print_status', None)
1710 if not print_status
:
1711 print_status
= gajim
.config
.get('print_status_in_muc')
1712 if obj
.show
== 'offline':
1713 if obj
.nick
in self
.attention_list
:
1714 self
.attention_list
.remove(obj
.nick
)
1715 if obj
.show
== 'offline' and print_status
in ('all', 'in_and_out') \
1716 and (not obj
.status_code
or '307' not in obj
.status_code
):
1717 st
= _('%s has left') % nick_jid
1719 st
+= ' [%s]' % obj
.reason
1721 if newly_created
and print_status
in ('all', 'in_and_out'):
1722 st
= _('%s has joined the group chat') % nick_jid
1723 elif print_status
== 'all':
1724 st
= _('%(nick)s is now %(status)s') % {'nick': nick_jid
,
1725 'status': helpers
.get_uf_show(obj
.show
)}
1728 st
+= ' (' + obj
.status
+ ')'
1729 self
.print_conversation(st
, graphics
=False)
1731 def add_contact_to_roster(self
, nick
, show
, role
, affiliation
, status
,
1733 model
= self
.list_treeview
.get_model()
1734 role_name
= helpers
.get_uf_role(role
, plural
=True)
1738 jids
= jid
.split('/', 1)
1747 role_iter
= self
.get_role_iter(role
)
1749 role_iter
= model
.append(None,
1750 [gajim
.interface
.jabber_state_images
['16']['closed'], role
,
1751 'role', role_name
, None] + [None] * self
.nb_ext_renderers
)
1752 self
.draw_all_roles()
1753 iter_
= model
.append(role_iter
, [None, nick
, 'contact', name
, None] + \
1754 [None] * self
.nb_ext_renderers
)
1755 if not nick
in gajim
.contacts
.get_nick_list(self
.account
,
1757 gc_contact
= gajim
.contacts
.create_gc_contact(
1758 room_jid
=self
.room_jid
, account
=self
.account
,
1759 name
=nick
, show
=show
, status
=status
, role
=role
,
1760 affiliation
=affiliation
, jid
=j
, resource
=resource
)
1761 gajim
.contacts
.add_gc_contact(self
.account
, gc_contact
)
1762 self
.draw_contact(nick
)
1763 self
.draw_avatar(nick
)
1764 # Do not ask avatar to irc rooms as irc transports reply with messages
1765 server
= gajim
.get_server_from_jid(self
.room_jid
)
1766 if gajim
.config
.get('ask_avatars_on_startup') and \
1767 not server
.startswith('irc'):
1768 fake_jid
= self
.room_jid
+ '/' + nick
1769 pixbuf
= gtkgui_helpers
.get_avatar_pixbuf_from_cache(fake_jid
)
1771 if j
and not self
.is_anonymous
:
1772 gajim
.connections
[self
.account
].request_vcard(j
, fake_jid
)
1774 gajim
.connections
[self
.account
].request_vcard(fake_jid
,
1776 if nick
== self
.nick
: # we became online
1777 self
.got_connected()
1778 self
.list_treeview
.expand_row((model
.get_path(role_iter
)), False)
1779 if self
.is_continued
:
1780 self
.draw_banner_text()
1783 def get_role_iter(self
, role
):
1784 model
= self
.list_treeview
.get_model()
1785 role_iter
= model
.get_iter_root()
1787 role_name
= model
[role_iter
][C_NICK
].decode('utf-8')
1788 if role
== role_name
:
1790 role_iter
= model
.iter_next(role_iter
)
1793 def remove_contact(self
, nick
):
1795 Remove a user from the contacts_list
1797 model
= self
.list_treeview
.get_model()
1798 iter_
= self
.get_contact_iter(nick
)
1801 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1804 gajim
.contacts
.remove_gc_contact(self
.account
, gc_contact
)
1805 parent_iter
= model
.iter_parent(iter_
)
1807 if model
.iter_n_children(parent_iter
) == 0:
1808 model
.remove(parent_iter
)
1810 def send_message(self
, message
, xhtml
=None, process_commands
=True):
1812 Call this function to send our message
1817 if process_commands
and self
.process_as_command(message
):
1820 message
= helpers
.remove_invalid_xml_chars(message
)
1825 label
= self
.get_seclabel()
1826 if message
!= '' or message
!= '\n':
1827 self
.save_message(message
, 'sent')
1830 gajim
.connections
[self
.account
].send_gc_message(self
.room_jid
,
1831 message
, xhtml
=xhtml
, label
=label
)
1832 self
.msg_textview
.get_buffer().set_text('')
1833 self
.msg_textview
.grab_focus()
1835 def get_role(self
, nick
):
1836 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1839 return gc_contact
.role
1843 def minimizable(self
):
1844 if self
.contact
.jid
in gajim
.config
.get_per('accounts', self
.account
,
1845 'minimized_gc').split(' '):
1849 def minimize(self
, status
='offline'):
1851 win
= gajim
.interface
.msg_win_mgr
.get_window(self
.contact
.jid
,
1853 ctrl
= win
.get_control(self
.contact
.jid
, self
.account
)
1855 ctrl_page
= win
.notebook
.page_num(ctrl
.widget
)
1856 control
= win
.notebook
.get_nth_page(ctrl_page
)
1858 win
.notebook
.remove_page(ctrl_page
)
1860 ctrl
.parent_win
= None
1862 gajim
.interface
.roster
.add_groupchat(self
.contact
.jid
, self
.account
,
1863 status
= self
.subject
)
1865 del win
._controls
[self
.account
][self
.contact
.jid
]
1867 def shutdown(self
, status
='offline'):
1868 # PluginSystem: calling shutdown of super class (ChatControlBase)
1869 # to let it remove it's GUI extension points
1870 super(GroupchatControl
, self
).shutdown()
1871 # PluginSystem: removing GUI extension points connected with
1872 # GrouphatControl instance object
1873 gajim
.plugin_manager
.remove_gui_extension_point('groupchat_control',
1876 # Preventing autorejoin from being activated
1877 self
.autorejoin
= False
1879 gajim
.ged
.remove_event_handler('gc-presence-received', ged
.GUI1
,
1880 self
._nec
_gc
_presence
_received
)
1881 gajim
.ged
.remove_event_handler('gc-message-received', ged
.GUI1
,
1882 self
._nec
_gc
_message
_received
)
1883 gajim
.ged
.remove_event_handler('vcard-published', ged
.GUI1
,
1884 self
._nec
_vcard
_published
)
1885 gajim
.ged
.remove_event_handler('vcard-received', ged
.GUI1
,
1886 self
._nec
_vcard
_received
)
1887 gajim
.ged
.remove_event_handler('gc-subject-received', ged
.GUI1
,
1888 self
._nec
_gc
_subject
_received
)
1889 gajim
.ged
.remove_event_handler('gc-config-changed-received', ged
.GUI1
,
1890 self
._nec
_gc
_config
_changed
_received
)
1891 gajim
.ged
.remove_event_handler('signed-in', ged
.GUI1
,
1892 self
._nec
_signed
_in
)
1894 if self
.room_jid
in gajim
.gc_connected
[self
.account
] and \
1895 gajim
.gc_connected
[self
.account
][self
.room_jid
]:
1896 # Tell connection to note the date we disconnect to avoid duplicate
1897 # logs. We do it only when connected because if connection was lost
1898 # there may be new messages since disconnection.
1899 gajim
.connections
[self
.account
].gc_got_disconnected(self
.room_jid
)
1900 gajim
.connections
[self
.account
].send_gc_status(self
.nick
, self
.room_jid
,
1901 show
='offline', status
=status
)
1902 nick_list
= gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
)
1903 for nick
in nick_list
:
1904 # Update pm chat window
1905 fjid
= self
.room_jid
+ '/' + nick
1906 ctrl
= gajim
.interface
.msg_win_mgr
.get_gc_control(fjid
,
1909 contact
= gajim
.contacts
.get_gc_contact(self
.account
,
1910 self
.room_jid
, nick
)
1911 contact
.show
= 'offline'
1914 ctrl
.parent_win
.redraw_tab(ctrl
)
1915 for sess
in gajim
.connections
[self
.account
].get_sessions(fjid
):
1917 sess
.control
.no_autonegotiation
= False
1918 if sess
.enable_encryption
:
1919 sess
.terminate_e2e()
1920 gajim
.connections
[self
.account
].delete_session(fjid
,
1922 # They can already be removed by the destroy function
1923 if self
.room_jid
in gajim
.contacts
.get_gc_list(self
.account
):
1924 gajim
.contacts
.remove_room(self
.account
, self
.room_jid
)
1925 del gajim
.gc_connected
[self
.account
][self
.room_jid
]
1926 # Save hpaned position
1927 gajim
.config
.set('gc-hpaned-position', self
.hpaned
.get_position())
1928 # remove all register handlers on wigets, created by self.xml
1929 # to prevent circular references among objects
1930 for i
in self
.handlers
.keys():
1931 if self
.handlers
[i
].handler_is_connected(i
):
1932 self
.handlers
[i
].disconnect(i
)
1933 del self
.handlers
[i
]
1934 # Remove unread events from systray
1935 gajim
.events
.remove_events(self
.account
, self
.room_jid
)
1937 def safe_shutdown(self
):
1938 if self
.minimizable():
1940 includes
= gajim
.config
.get('confirm_close_muc_rooms').split(' ')
1941 excludes
= gajim
.config
.get('noconfirm_close_muc_rooms').split(' ')
1942 # whether to ask for comfirmation before closing muc
1943 if (gajim
.config
.get('confirm_close_muc') or self
.room_jid
in includes
)\
1944 and gajim
.gc_connected
[self
.account
][self
.room_jid
] and self
.room_jid \
1949 def allow_shutdown(self
, method
, on_yes
, on_no
, on_minimize
):
1950 if self
.minimizable():
1953 if method
== self
.parent_win
.CLOSE_ESC
:
1954 iter_
= self
.list_treeview
.get_selection().get_selected()[1]
1956 self
.list_treeview
.get_selection().unselect_all()
1959 includes
= gajim
.config
.get('confirm_close_muc_rooms').split(' ')
1960 excludes
= gajim
.config
.get('noconfirm_close_muc_rooms').split(' ')
1961 # whether to ask for comfirmation before closing muc
1962 if (gajim
.config
.get('confirm_close_muc') or self
.room_jid
in includes
)\
1963 and gajim
.gc_connected
[self
.account
][self
.room_jid
] and self
.room_jid \
1968 # user does not want to be asked again
1969 gajim
.config
.set('confirm_close_muc', False)
1972 def on_cancel(clicked
):
1974 # user does not want to be asked again
1975 gajim
.config
.set('confirm_close_muc', False)
1978 pritext
= _('Are you sure you want to leave group chat "%s"?')\
1980 sectext
= _('If you close this window, you will be disconnected '
1981 'from this group chat.')
1983 dialogs
.ConfirmationDialogCheck(pritext
, sectext
,
1984 _('_Do not ask me again'), on_response_ok
=on_ok
,
1985 on_response_cancel
=on_cancel
)
1990 def set_control_active(self
, state
):
1991 self
.conv_textview
.allow_focus_out_line
= True
1992 self
.attention_flag
= False
1993 ChatControlBase
.set_control_active(self
, state
)
1995 # add the focus-out line to the tab we are leaving
1996 self
.check_and_possibly_add_focus_out_line()
1997 # Sending active to undo unread state
1998 self
.parent_win
.redraw_tab(self
, 'active')
2000 def get_specific_unread(self
):
2001 # returns the number of the number of unread msgs
2002 # for room_jid & number of unread private msgs with each contact
2005 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
2006 fjid
= self
.room_jid
+ '/' + nick
2007 nb
+= len(gajim
.events
.get_events(self
.account
, fjid
))
2008 # gc can only have messages as event
2011 def _on_change_subject_menuitem_activate(self
, widget
):
2013 # Note, we don't update self.subject since we don't know whether it
2015 gajim
.connections
[self
.account
].send_gc_subject(self
.room_jid
,
2018 dialogs
.InputTextDialog(_('Changing Subject'),
2019 _('Please specify the new subject:'), input_str
=self
.subject
,
2022 def _on_change_nick_menuitem_activate(self
, widget
):
2023 if 'change_nick_dialog' in gajim
.interface
.instances
:
2024 gajim
.interface
.instances
['change_nick_dialog'].present()
2026 title
= _('Changing Nickname')
2027 prompt
= _('Please specify the new nickname you want to use:')
2028 gajim
.interface
.instances
['change_nick_dialog'] = \
2029 dialogs
.ChangeNickDialog(self
.account
, self
.room_jid
, title
,
2030 prompt
, change_nick
=True)
2032 def _on_configure_room_menuitem_activate(self
, widget
):
2033 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
2035 if c
.affiliation
== 'owner':
2036 gajim
.connections
[self
.account
].request_gc_config(self
.room_jid
)
2037 elif c
.affiliation
== 'admin':
2038 if self
.room_jid
not in gajim
.interface
.instances
[self
.account
][
2040 gajim
.interface
.instances
[self
.account
]['gc_config'][
2041 self
.room_jid
] = config
.GroupchatConfigWindow(self
.account
,
2044 def _on_destroy_room_menuitem_activate(self
, widget
):
2045 def on_ok(reason
, jid
):
2049 jid
= helpers
.parse_jid(jid
)
2051 dialogs
.ErrorDialog(_('Invalid group chat Jabber ID'),
2052 _('The group chat Jabber ID has not allowed characters.'))
2054 gajim
.connections
[self
.account
].destroy_gc_room(self
.room_jid
,
2058 dialogs
.DoubleInputDialog(_('Destroying %s') % self
.room_jid
,
2059 _('You are going to definitively destroy this room.\n'
2060 'You may specify a reason below:'),
2061 _('You may also enter an alternate venue:'), ok_handler
=on_ok
)
2063 def _on_bookmark_room_menuitem_activate(self
, widget
):
2065 Bookmark the room, without autojoin and not minimized
2067 password
= gajim
.gc_passwords
.get(self
.room_jid
, '')
2068 gajim
.interface
.add_gc_bookmark(self
.account
, self
.name
, self
.room_jid
,\
2069 '0', '0', password
, self
.nick
)
2071 def _on_drag_data_received(self
, widget
, context
, x
, y
, selection
,
2072 target_type
, timestamp
):
2073 # Invite contact to groupchat
2074 treeview
= gajim
.interface
.roster
.tree
2075 model
= treeview
.get_model()
2076 if not selection
.data
or target_type
== 80:
2077 # target_type = 80 means a file is dropped
2079 data
= selection
.data
2080 path
= treeview
.get_selection().get_selected_rows()[1][0]
2081 iter_
= model
.get_iter(path
)
2082 type_
= model
[iter_
][2]
2083 if type_
!= 'contact': # source is not a contact
2085 contact_jid
= data
.decode('utf-8')
2086 gajim
.connections
[self
.account
].send_invite(self
.room_jid
, contact_jid
)
2088 def handle_message_textview_mykey_press(self
, widget
, event_keyval
,
2090 # NOTE: handles mykeypress which is custom signal connected to this
2091 # CB in new_room(). for this singal see message_textview.py
2093 if not widget
.get_sensitive():
2094 # Textview is not sensitive, don't handle keypress
2096 # construct event instance from binding
2097 event
= gtk
.gdk
.Event(gtk
.gdk
.KEY_PRESS
) # it's always a key-press here
2098 event
.keyval
= event_keyval
2099 event
.state
= event_keymod
2100 event
.time
= 0 # assign current time
2102 message_buffer
= widget
.get_buffer()
2103 start_iter
, end_iter
= message_buffer
.get_bounds()
2105 if event
.keyval
== gtk
.keysyms
.Tab
: # TAB
2106 cursor_position
= message_buffer
.get_insert()
2107 end_iter
= message_buffer
.get_iter_at_mark(cursor_position
)
2108 text
= message_buffer
.get_text(start_iter
, end_iter
, False).decode(
2111 splitted_text
= text
.split()
2113 # HACK: Not the best soltution.
2114 if (text
.startswith(self
.COMMAND_PREFIX
) and not
2115 text
.startswith(self
.COMMAND_PREFIX
* 2) and \
2116 len(splitted_text
) == 1):
2117 return super(GroupchatControl
, self
).\
2118 handle_message_textview_mykey_press(widget
, event_keyval
,
2122 # check if tab is pressed with empty message
2123 if len(splitted_text
): # if there are any words
2124 begin
= splitted_text
[-1] # last word we typed
2128 gc_refer_to_nick_char
= gajim
.config
.get('gc_refer_to_nick_char')
2129 with_refer_to_nick_char
= False
2130 after_nick_len
= 1 # the space that is printed after we type [Tab]
2132 # first part of this if : works fine even if refer_to_nick_char
2133 if gc_refer_to_nick_char
and text
.endswith(
2134 gc_refer_to_nick_char
+ ' '):
2135 with_refer_to_nick_char
= True
2136 after_nick_len
= len(gc_refer_to_nick_char
+ ' ')
2137 if len(self
.nick_hits
) and self
.last_key_tabs
and \
2138 text
[:-after_nick_len
].endswith(self
.nick_hits
[0]):
2140 # Previous nick in list may had a space inside, so we check text
2141 # and not splitted_text and store it into 'begin' var
2142 self
.nick_hits
.append(self
.nick_hits
[0])
2143 begin
= self
.nick_hits
.pop(0)
2145 self
.nick_hits
= [] # clear the hit list
2146 list_nick
= gajim
.contacts
.get_nick_list(self
.account
,
2148 list_nick
.sort(key
=unicode.lower
) # case-insensitive sort
2150 # empty message, show lasts nicks that highlighted us first
2151 for nick
in self
.attention_list
:
2152 if nick
in list_nick
:
2153 list_nick
.remove(nick
)
2154 list_nick
.insert(0, nick
)
2156 list_nick
.remove(self
.nick
) # Skip self
2157 for nick
in list_nick
:
2158 if nick
.lower().startswith(begin
.lower()):
2159 # the word is the begining of a nick
2160 self
.nick_hits
.append(nick
)
2161 if len(self
.nick_hits
):
2162 if len(splitted_text
) < 2 or with_refer_to_nick_char
:
2163 # This is the 1st word of the line or no word or we are cycling
2164 # at the beginning, possibly with a space in one nick
2165 add
= gc_refer_to_nick_char
+ ' '
2168 start_iter
= end_iter
.copy()
2169 if self
.last_key_tabs
and with_refer_to_nick_char
or (text
and \
2171 # have to accomodate for the added space from last
2173 # gc_refer_to_nick_char may be more than one char!
2174 start_iter
.backward_chars(len(begin
) + len(add
))
2175 elif self
.last_key_tabs
and not gajim
.config
.get(
2176 'shell_like_completion'):
2177 # have to accomodate for the added space from last
2179 start_iter
.backward_chars(len(begin
) + \
2180 len(gc_refer_to_nick_char
))
2182 start_iter
.backward_chars(len(begin
))
2184 message_buffer
.delete(start_iter
, end_iter
)
2185 # get a shell-like completion
2186 # if there's more than one nick for this completion, complete
2187 # only the part that all these nicks have in common
2188 if gajim
.config
.get('shell_like_completion') and \
2189 len(self
.nick_hits
) > 1:
2192 add
= "" # if nick is not complete, don't add anything
2193 while not end
and len(completion
) < len(self
.nick_hits
[0]):
2194 completion
= self
.nick_hits
[0][:len(completion
)+1]
2195 for nick
in self
.nick_hits
:
2196 if completion
.lower() not in nick
.lower():
2198 completion
= completion
[:-1]
2200 # if the current nick matches a COMPLETE existing nick,
2201 # and if the user tab TWICE, complete that nick (with the
2203 if self
.last_key_tabs
:
2204 for nick
in self
.nick_hits
:
2205 if nick
== completion
:
2206 # The user seems to want this nick, so
2207 # complete it as if it were the only nick
2209 add
= gc_refer_to_nick_char
+ ' '
2211 completion
= self
.nick_hits
[0]
2212 message_buffer
.insert_at_cursor(completion
+ add
)
2213 self
.last_key_tabs
= True
2215 self
.last_key_tabs
= False
2217 def on_list_treeview_key_press_event(self
, widget
, event
):
2218 if event
.keyval
== gtk
.keysyms
.Escape
:
2219 selection
= widget
.get_selection()
2220 iter_
= selection
.get_selected()[1]
2222 widget
.get_selection().unselect_all()
2225 def on_list_treeview_row_expanded(self
, widget
, iter_
, path
):
2227 When a row is expanded: change the icon of the arrow
2229 model
= widget
.get_model()
2230 image
= gajim
.interface
.jabber_state_images
['16']['opened']
2231 model
[iter_
][C_IMG
] = image
2233 def on_list_treeview_row_collapsed(self
, widget
, iter_
, path
):
2235 When a row is collapsed: change the icon of the arrow
2237 model
= widget
.get_model()
2238 image
= gajim
.interface
.jabber_state_images
['16']['closed']
2239 model
[iter_
][C_IMG
] = image
2241 def kick(self
, widget
, nick
):
2246 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2250 dialogs
.InputDialog(_('Kicking %s') % nick
,
2251 _('You may specify a reason below:'), ok_handler
=on_ok
)
2253 def mk_menu(self
, event
, iter_
):
2255 Make contact's popup menu
2257 model
= self
.list_treeview
.get_model()
2258 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2259 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
, nick
)
2260 fjid
= self
.room_jid
+ '/' + nick
2262 target_affiliation
= c
.affiliation
2263 target_role
= c
.role
2265 # looking for user's affiliation and role
2266 user_nick
= self
.nick
2267 user_affiliation
= gajim
.contacts
.get_gc_contact(self
.account
,
2268 self
.room_jid
, user_nick
).affiliation
2269 user_role
= self
.get_role(user_nick
)
2271 # making menu from gtk builder
2272 xml
= gtkgui_helpers
.get_gtk_builder('gc_occupants_menu.ui')
2274 # these conditions were taken from JEP 0045
2275 item
= xml
.get_object('kick_menuitem')
2276 if user_role
!= 'moderator' or \
2277 (user_affiliation
== 'admin' and target_affiliation
== 'owner') or \
2278 (user_affiliation
== 'member' and target_affiliation
in ('admin',
2279 'owner')) or (user_affiliation
== 'none' and target_affiliation
!= \
2281 item
.set_sensitive(False)
2282 id_
= item
.connect('activate', self
.kick
, nick
)
2283 self
.handlers
[id_
] = item
2285 item
= xml
.get_object('voice_checkmenuitem')
2286 item
.set_active(target_role
!= 'visitor')
2287 if user_role
!= 'moderator' or \
2288 user_affiliation
== 'none' or \
2289 (user_affiliation
=='member' and target_affiliation
!='none') or \
2290 target_affiliation
in ('admin', 'owner'):
2291 item
.set_sensitive(False)
2292 id_
= item
.connect('activate', self
.on_voice_checkmenuitem_activate
,
2294 self
.handlers
[id_
] = item
2296 item
= xml
.get_object('moderator_checkmenuitem')
2297 item
.set_active(target_role
== 'moderator')
2298 if not user_affiliation
in ('admin', 'owner') or \
2299 target_affiliation
in ('admin', 'owner'):
2300 item
.set_sensitive(False)
2301 id_
= item
.connect('activate', self
.on_moderator_checkmenuitem_activate
,
2303 self
.handlers
[id_
] = item
2305 item
= xml
.get_object('ban_menuitem')
2306 if not user_affiliation
in ('admin', 'owner') or \
2307 (target_affiliation
in ('admin', 'owner') and\
2308 user_affiliation
!= 'owner'):
2309 item
.set_sensitive(False)
2310 id_
= item
.connect('activate', self
.ban
, jid
)
2311 self
.handlers
[id_
] = item
2313 item
= xml
.get_object('member_checkmenuitem')
2314 item
.set_active(target_affiliation
!= 'none')
2315 if not user_affiliation
in ('admin', 'owner') or \
2316 (user_affiliation
!= 'owner' and target_affiliation
in ('admin',
2318 item
.set_sensitive(False)
2319 id_
= item
.connect('activate', self
.on_member_checkmenuitem_activate
,
2321 self
.handlers
[id_
] = item
2323 item
= xml
.get_object('admin_checkmenuitem')
2324 item
.set_active(target_affiliation
in ('admin', 'owner'))
2325 if not user_affiliation
== 'owner':
2326 item
.set_sensitive(False)
2327 id_
= item
.connect('activate', self
.on_admin_checkmenuitem_activate
,
2329 self
.handlers
[id_
] = item
2331 item
= xml
.get_object('owner_checkmenuitem')
2332 item
.set_active(target_affiliation
== 'owner')
2333 if not user_affiliation
== 'owner':
2334 item
.set_sensitive(False)
2335 id_
= item
.connect('activate', self
.on_owner_checkmenuitem_activate
,
2337 self
.handlers
[id_
] = item
2339 item
= xml
.get_object('information_menuitem')
2340 id_
= item
.connect('activate', self
.on_info
, nick
)
2341 self
.handlers
[id_
] = item
2343 item
= xml
.get_object('history_menuitem')
2344 id_
= item
.connect('activate', self
.on_history
, nick
)
2345 self
.handlers
[id_
] = item
2347 item
= xml
.get_object('add_to_roster_menuitem')
2348 our_jid
= gajim
.get_jid_from_account(self
.account
)
2349 if not jid
or jid
== our_jid
:
2350 item
.set_sensitive(False)
2352 id_
= item
.connect('activate', self
.on_add_to_roster
, jid
)
2353 self
.handlers
[id_
] = item
2355 item
= xml
.get_object('block_menuitem')
2356 item2
= xml
.get_object('unblock_menuitem')
2357 if helpers
.jid_is_blocked(self
.account
, fjid
):
2358 item
.set_no_show_all(True)
2360 id_
= item2
.connect('activate', self
.on_unblock
, nick
)
2361 self
.handlers
[id_
] = item2
2363 id_
= item
.connect('activate', self
.on_block
, nick
)
2364 self
.handlers
[id_
] = item
2365 item2
.set_no_show_all(True)
2368 item
= xml
.get_object('send_private_message_menuitem')
2369 id_
= item
.connect('activate', self
.on_send_pm
, model
, iter_
)
2370 self
.handlers
[id_
] = item
2372 item
= xml
.get_object('send_file_menuitem')
2373 # add a special img for send file menuitem
2374 path_to_upload_img
= gtkgui_helpers
.get_icon_path('gajim-upload')
2376 img
.set_from_file(path_to_upload_img
)
2380 item
.set_sensitive(False)
2382 id_
= item
.connect('activate', self
.on_send_file
, c
)
2383 self
.handlers
[id_
] = item
2385 # show the popup now!
2386 menu
= xml
.get_object('gc_occupants_menu')
2388 menu
.popup(None, None, None, event
.button
, event
.time
)
2390 def _start_private_message(self
, nick
):
2391 gc_c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
, nick
)
2392 nick_jid
= gc_c
.get_full_jid()
2394 ctrl
= gajim
.interface
.msg_win_mgr
.get_control(nick_jid
, self
.account
)
2396 ctrl
= gajim
.interface
.new_private_chat(gc_c
, self
.account
)
2399 ctrl
.parent_win
.set_active_tab(ctrl
)
2403 def on_row_activated(self
, widget
, path
):
2405 When an iter is activated (dubblick or single click if gnome is set this
2408 model
= widget
.get_model()
2409 if len(path
) == 1: # It's a group
2410 if (widget
.row_expanded(path
)):
2411 widget
.collapse_row(path
)
2413 widget
.expand_row(path
, False)
2414 else: # We want to send a private message
2415 nick
= model
[path
][C_NICK
].decode('utf-8')
2416 self
._start
_private
_message
(nick
)
2418 def on_list_treeview_row_activated(self
, widget
, path
, col
=0):
2420 When an iter is double clicked: open the chat window
2422 if not gajim
.single_click
:
2423 self
.on_row_activated(widget
, path
)
2425 def on_list_treeview_button_press_event(self
, widget
, event
):
2427 Popup user's group's or agent menu
2429 # hide tooltip, no matter the button is pressed
2430 self
.tooltip
.hide_tooltip()
2432 pos
= widget
.get_path_at_pos(int(event
.x
), int(event
.y
))
2433 path
, x
= pos
[0], pos
[2]
2435 widget
.get_selection().unselect_all()
2437 if event
.button
== 3: # right click
2438 widget
.get_selection().select_path(path
)
2439 model
= widget
.get_model()
2440 iter_
= model
.get_iter(path
)
2442 self
.mk_menu(event
, iter_
)
2445 elif event
.button
== 2: # middle click
2446 widget
.get_selection().select_path(path
)
2447 model
= widget
.get_model()
2448 iter_
= model
.get_iter(path
)
2450 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2451 self
._start
_private
_message
(nick
)
2454 elif event
.button
== 1: # left click
2455 if gajim
.single_click
and not event
.state
& gtk
.gdk
.SHIFT_MASK
:
2456 self
.on_row_activated(widget
, path
)
2459 model
= widget
.get_model()
2460 iter_
= model
.get_iter(path
)
2461 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2462 if not nick
in gajim
.contacts
.get_nick_list(self
.account
,
2466 if (widget
.row_expanded(path
)):
2467 widget
.collapse_row(path
)
2469 widget
.expand_row(path
, False)
2470 elif event
.state
& gtk
.gdk
.SHIFT_MASK
:
2471 self
.append_nick_in_msg_textview(self
.msg_textview
, nick
)
2472 self
.msg_textview
.grab_focus()
2475 def append_nick_in_msg_textview(self
, widget
, nick
):
2476 message_buffer
= self
.msg_textview
.get_buffer()
2477 start_iter
, end_iter
= message_buffer
.get_bounds()
2478 cursor_position
= message_buffer
.get_insert()
2479 end_iter
= message_buffer
.get_iter_at_mark(cursor_position
)
2480 text
= message_buffer
.get_text(start_iter
, end_iter
, False)
2482 if text
: # Cursor is not at first position
2483 if not text
[-1] in (' ', '\n', '\t'):
2487 gc_refer_to_nick_char
= gajim
.config
.get('gc_refer_to_nick_char')
2488 add
= gc_refer_to_nick_char
+ ' '
2489 message_buffer
.insert_at_cursor(start
+ nick
+ add
)
2491 def on_list_treeview_motion_notify_event(self
, widget
, event
):
2492 model
= widget
.get_model()
2493 props
= widget
.get_path_at_pos(int(event
.x
), int(event
.y
))
2494 if self
.tooltip
.timeout
> 0:
2495 if not props
or self
.tooltip
.id != props
[0]:
2496 self
.tooltip
.hide_tooltip()
2498 [row
, col
, x
, y
] = props
2501 iter_
= model
.get_iter(row
)
2503 self
.tooltip
.hide_tooltip()
2505 typ
= model
[iter_
][C_TYPE
].decode('utf-8')
2506 if typ
== 'contact':
2507 account
= self
.account
2509 if self
.tooltip
.timeout
== 0 or self
.tooltip
.id != props
[0]:
2510 self
.tooltip
.id = row
2511 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2512 self
.tooltip
.timeout
= gobject
.timeout_add(500,
2513 self
.show_tooltip
, gajim
.contacts
.get_gc_contact(
2514 account
, self
.room_jid
, nick
))
2516 def on_list_treeview_leave_notify_event(self
, widget
, event
):
2517 props
= widget
.get_path_at_pos(int(event
.x
), int(event
.y
))
2518 if self
.tooltip
.timeout
> 0:
2519 if not props
or self
.tooltip
.id == props
[0]:
2520 self
.tooltip
.hide_tooltip()
2522 def show_tooltip(self
, contact
):
2523 if not self
.list_treeview
.window
:
2524 # control has been destroyed since tooltip was requested
2526 pointer
= self
.list_treeview
.get_pointer()
2527 props
= self
.list_treeview
.get_path_at_pos(pointer
[0], pointer
[1])
2528 # check if the current pointer is at the same path
2529 # as it was before setting the timeout
2530 if props
and self
.tooltip
.id == props
[0]:
2531 rect
= self
.list_treeview
.get_cell_area(props
[0], props
[1])
2532 position
= self
.list_treeview
.window
.get_origin()
2533 self
.tooltip
.show_tooltip(contact
, rect
.height
,
2534 position
[1] + rect
.y
)
2536 self
.tooltip
.hide_tooltip()
2538 def grant_voice(self
, widget
, nick
):
2540 Grant voice privilege to a user
2542 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2545 def revoke_voice(self
, widget
, nick
):
2547 Revoke voice privilege to a user
2549 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2552 def grant_moderator(self
, widget
, nick
):
2554 Grant moderator privilege to a user
2556 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2559 def revoke_moderator(self
, widget
, nick
):
2561 Revoke moderator privilege to a user
2563 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2566 def ban(self
, widget
, jid
):
2571 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
,
2572 jid
, 'outcast', reason
)
2574 # to ban we know the real jid. so jid is not fakejid
2575 nick
= gajim
.get_nick_from_jid(jid
)
2577 dialogs
.InputDialog(_('Banning %s') % nick
,
2578 _('You may specify a reason below:'), ok_handler
=on_ok
)
2580 def grant_membership(self
, widget
, jid
):
2582 Grant membership privilege to a user
2584 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2587 def revoke_membership(self
, widget
, jid
):
2589 Revoke membership privilege to a user
2591 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2594 def grant_admin(self
, widget
, jid
):
2596 Grant administrative privilege to a user
2598 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2601 def revoke_admin(self
, widget
, jid
):
2603 Revoke administrative privilege to a user
2605 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2608 def grant_owner(self
, widget
, jid
):
2610 Grant owner privilege to a user
2612 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2615 def revoke_owner(self
, widget
, jid
):
2617 Revoke owner privilege to a user
2619 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2622 def on_info(self
, widget
, nick
):
2624 Call vcard_information_window class to display user's information
2626 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
2628 contact
= gc_contact
.as_contact()
2629 if contact
.jid
in gajim
.interface
.instances
[self
.account
]['infos']:
2630 gajim
.interface
.instances
[self
.account
]['infos'][contact
.jid
].\
2633 gajim
.interface
.instances
[self
.account
]['infos'][contact
.jid
] = \
2634 vcard
.VcardWindow(contact
, self
.account
, gc_contact
)
2636 def on_history(self
, widget
, nick
):
2637 jid
= gajim
.construct_fjid(self
.room_jid
, nick
)
2638 self
._on
_history
_menuitem
_activate
(widget
=widget
, jid
=jid
)
2640 def on_add_to_roster(self
, widget
, jid
):
2641 dialogs
.AddNewContactWindow(self
.account
, jid
)
2643 def on_block(self
, widget
, nick
):
2644 fjid
= self
.room_jid
+ '/' + nick
2645 connection
= gajim
.connections
[self
.account
]
2646 if fjid
in connection
.blocked_contacts
:
2648 new_rule
= {'order': u
'1', 'type': u
'jid', 'action': u
'deny',
2649 'value' : fjid
, 'child': [u
'message', u
'iq', u
'presence-out']}
2650 connection
.blocked_list
.append(new_rule
)
2651 connection
.blocked_contacts
.append(fjid
)
2652 self
.draw_contact(nick
)
2653 connection
.set_privacy_list('block', connection
.blocked_list
)
2654 if len(connection
.blocked_list
) == 1:
2655 connection
.set_active_list('block')
2656 connection
.set_default_list('block')
2657 connection
.get_privacy_list('block')
2659 def on_unblock(self
, widget
, nick
):
2660 fjid
= self
.room_jid
+ '/' + nick
2661 connection
= gajim
.connections
[self
.account
]
2662 connection
.new_blocked_list
= []
2663 # needed for draw_contact:
2664 if fjid
in connection
.blocked_contacts
:
2665 connection
.blocked_contacts
.remove(fjid
)
2666 self
.draw_contact(nick
)
2667 for rule
in connection
.blocked_list
:
2668 if rule
['action'] != 'deny' or rule
['type'] != 'jid' \
2669 or rule
['value'] != fjid
:
2670 connection
.new_blocked_list
.append(rule
)
2672 connection
.set_privacy_list('block', connection
.new_blocked_list
)
2673 connection
.get_privacy_list('block')
2674 if len(connection
.new_blocked_list
) == 0:
2675 connection
.blocked_list
= []
2676 connection
.blocked_contacts
= []
2677 connection
.blocked_groups
= []
2678 connection
.set_default_list('')
2679 connection
.set_active_list('')
2680 connection
.del_privacy_list('block')
2681 if 'privay_list_block' in gajim
.interface
.instances
[self
.account
]:
2682 del gajim
.interface
.instances
[self
.account
]\
2683 ['privay_list_block']
2685 def on_voice_checkmenuitem_activate(self
, widget
, nick
):
2686 if widget
.get_active():
2687 self
.grant_voice(widget
, nick
)
2689 self
.revoke_voice(widget
, nick
)
2691 def on_moderator_checkmenuitem_activate(self
, widget
, nick
):
2692 if widget
.get_active():
2693 self
.grant_moderator(widget
, nick
)
2695 self
.revoke_moderator(widget
, nick
)
2697 def on_member_checkmenuitem_activate(self
, widget
, jid
):
2698 if widget
.get_active():
2699 self
.grant_membership(widget
, jid
)
2701 self
.revoke_membership(widget
, jid
)
2703 def on_admin_checkmenuitem_activate(self
, widget
, jid
):
2704 if widget
.get_active():
2705 self
.grant_admin(widget
, jid
)
2707 self
.revoke_admin(widget
, jid
)
2709 def on_owner_checkmenuitem_activate(self
, widget
, jid
):
2710 if widget
.get_active():
2711 self
.grant_owner(widget
, jid
)
2713 self
.revoke_owner(widget
, jid
)