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
.ged
.register_event_handler('decrypted-message-received', ged
.GUI2
,
484 self
._nec
_decrypted
_message
_received
)
485 gajim
.gc_connected
[self
.account
][self
.room_jid
] = False
486 # disable win, we are not connected yet
487 ChatControlBase
.got_disconnected(self
)
490 self
.widget
.show_all()
492 # PluginSystem: adding GUI extension point for this GroupchatControl
494 gajim
.plugin_manager
.gui_extension_point('groupchat_control', self
)
496 def fill_column(self
, col
):
497 for rend
in self
.renderers_list
:
498 col
.pack_start(rend
[1], expand
=rend
[2])
499 col
.add_attribute(rend
[1], rend
[3], rend
[4])
500 col
.set_cell_data_func(rend
[1], rend
[5], rend
[6])
501 # set renderers propertys
502 for renderer
in self
.renderers_propertys
.keys():
503 renderer
.set_property(self
.renderers_propertys
[renderer
][0],
504 self
.renderers_propertys
[renderer
][1])
506 def tree_compare_iters(self
, model
, iter1
, iter2
):
508 Compare two iters to sort them
510 type1
= model
[iter1
][C_TYPE
]
511 type2
= model
[iter2
][C_TYPE
]
512 if not type1
or not type2
:
514 nick1
= model
[iter1
][C_NICK
]
515 nick2
= model
[iter2
][C_NICK
]
516 if not nick1
or not nick2
:
518 nick1
= nick1
.decode('utf-8')
519 nick2
= nick2
.decode('utf-8')
521 return locale
.strcoll(nick1
, nick2
)
522 if type1
== 'contact':
523 gc_contact1
= gajim
.contacts
.get_gc_contact(self
.account
,
524 self
.room_jid
, nick1
)
527 if type2
== 'contact':
528 gc_contact2
= gajim
.contacts
.get_gc_contact(self
.account
,
529 self
.room_jid
, nick2
)
532 if type1
== 'contact' and type2
== 'contact' and \
533 gajim
.config
.get('sort_by_show_in_muc'):
534 cshow
= {'chat':0, 'online': 1, 'away': 2, 'xa': 3, 'dnd': 4,
535 'invisible': 5, 'offline': 6, 'error': 7}
536 show1
= cshow
[gc_contact1
.show
]
537 show2
= cshow
[gc_contact2
.show
]
543 name1
= gc_contact1
.get_shown_name()
544 name2
= gc_contact2
.get_shown_name()
545 return locale
.strcoll(name1
.lower(), name2
.lower())
547 def on_msg_textview_populate_popup(self
, textview
, menu
):
549 Override the default context menu and we prepend Clear
550 and the ability to insert a nick
552 ChatControlBase
.on_msg_textview_populate_popup(self
, textview
, menu
)
553 item
= gtk
.SeparatorMenuItem()
556 item
= gtk
.MenuItem(_('Insert Nickname'))
559 item
.set_submenu(submenu
)
561 for nick
in sorted(gajim
.contacts
.get_nick_list(self
.account
,
563 item
= gtk
.MenuItem(nick
, use_underline
=False)
565 id_
= item
.connect('activate', self
.append_nick_in_msg_textview
,
567 self
.handlers
[id_
] = item
571 def resize_occupant_treeview(self
, position
):
572 self
.resize_from_another_muc
= True
573 self
.hpaned
.set_position(position
)
575 self
.resize_from_another_muc
= False
576 # Reset the flag when everything will be redrawn, and in particular when
577 # on_treeview_size_allocate will have been called.
578 gobject
.idle_add(reset_flag
)
580 def on_hpaned_notify(self
, pane
, gparamspec
):
582 The MUC treeview has resized. Move the hpaned in all tabs to match
584 if gparamspec
.name
!= 'position':
586 if self
.resize_from_another_muc
:
587 # Don't send the event to other MUC
590 hpaned_position
= self
.hpaned
.get_position()
591 gajim
.config
.set('gc-hpaned-position', hpaned_position
)
592 for account
in gajim
.gc_connected
:
593 for room_jid
in [i
for i
in gajim
.gc_connected
[account
] if \
594 gajim
.gc_connected
[account
][i
] and i
!= self
.room_jid
]:
595 ctrl
= gajim
.interface
.msg_win_mgr
.get_gc_control(room_jid
,
597 if not ctrl
and room_jid
in \
598 gajim
.interface
.minimized_controls
[account
]:
599 ctrl
= gajim
.interface
.minimized_controls
[account
][room_jid
]
600 if ctrl
and gajim
.config
.get('one_message_window') != 'never':
601 ctrl
.resize_occupant_treeview(hpaned_position
)
603 def iter_contact_rows(self
):
605 Iterate over all contact rows in the tree model
607 model
= self
.list_treeview
.get_model()
608 role_iter
= model
.get_iter_root()
610 contact_iter
= model
.iter_children(role_iter
)
612 yield model
[contact_iter
]
613 contact_iter
= model
.iter_next(contact_iter
)
614 role_iter
= model
.iter_next(role_iter
)
616 def on_list_treeview_style_set(self
, treeview
, style
):
618 When style (theme) changes, redraw all contacts
620 # Get the room_jid from treeview
621 for contact
in self
.iter_contact_rows():
622 nick
= contact
[C_NICK
].decode('utf-8')
623 self
.draw_contact(nick
)
625 def on_list_treeview_selection_changed(self
, selection
):
626 model
, selected_iter
= selection
.get_selected()
627 self
.draw_contact(self
.nick
)
628 if self
._last
_selected
_contact
is not None:
629 self
.draw_contact(self
._last
_selected
_contact
)
630 if selected_iter
is None:
631 self
._last
_selected
_contact
= None
633 contact
= model
[selected_iter
]
634 nick
= contact
[C_NICK
].decode('utf-8')
635 self
._last
_selected
_contact
= nick
636 if contact
[C_TYPE
] != 'contact':
638 self
.draw_contact(nick
, selected
=True, focus
=True)
640 def get_tab_label(self
, chatstate
):
642 Markup the label if necessary. Returns a tuple such as: (new_label_str,
643 color) either of which can be None if chatstate is given that means we
644 have HE SENT US a chatstate
647 has_focus
= self
.parent_win
.window
.get_property('has-toplevel-focus')
648 current_tab
= self
.parent_win
.get_active_control() == self
651 theme
= gajim
.config
.get('roster_theme')
652 if chatstate
== 'attention' and (not has_focus
or not current_tab
):
653 self
.attention_flag
= True
654 color_name
= gajim
.config
.get_per('themes', theme
,
655 'state_muc_directed_msg_color')
657 if chatstate
== 'active' or (current_tab
and has_focus
):
658 self
.attention_flag
= False
659 # get active color from gtk
660 color
= self
.parent_win
.notebook
.style
.fg
[gtk
.STATE_ACTIVE
]
661 elif chatstate
== 'newmsg' and (not has_focus
or not current_tab
) \
662 and not self
.attention_flag
:
663 color_name
= gajim
.config
.get_per('themes', theme
,
664 'state_muc_msg_color')
666 color
= gtk
.gdk
.colormap_get_system().alloc_color(color_name
)
668 if self
.is_continued
:
669 # if this is a continued conversation
670 label_str
= self
.get_continued_conversation_name()
672 label_str
= self
.name
674 # count waiting highlighted messages
676 num_unread
= self
.get_nb_unread()
680 unread
= '[' + unicode(num_unread
) + ']'
681 label_str
= unread
+ label_str
682 return (label_str
, color
)
684 def get_tab_image(self
, count_unread
=True):
685 # Set tab image (always 16x16)
687 if gajim
.gc_connected
[self
.account
][self
.room_jid
]:
688 tab_image
= gtkgui_helpers
.load_icon('muc_active')
690 tab_image
= gtkgui_helpers
.load_icon('muc_inactive')
694 ChatControlBase
.update_ui(self
)
695 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
696 self
.draw_contact(nick
)
698 def _change_style(self
, model
, path
, iter_
):
699 model
[iter_
][C_NICK
] = model
[iter_
][C_NICK
]
701 def change_roster_style(self
):
702 model
= self
.list_treeview
.get_model()
703 model
.foreach(self
._change
_style
)
705 def repaint_themed_widgets(self
):
706 ChatControlBase
.repaint_themed_widgets(self
)
707 self
.change_roster_style()
709 def _update_banner_state_image(self
):
710 banner_status_img
= self
.xml
.get_object('gc_banner_status_image')
711 images
= gajim
.interface
.jabber_state_images
712 if self
.room_jid
in gajim
.gc_connected
[self
.account
] and \
713 gajim
.gc_connected
[self
.account
][self
.room_jid
]:
716 image
= 'muc_inactive'
717 if '32' in images
and image
in images
['32']:
718 muc_icon
= images
['32'][image
]
719 if muc_icon
.get_storage_type() != gtk
.IMAGE_EMPTY
:
720 pix
= muc_icon
.get_pixbuf()
721 banner_status_img
.set_from_pixbuf(pix
)
723 # we need to scale 16x16 to 32x32
724 muc_icon
= images
['16'][image
]
725 pix
= muc_icon
.get_pixbuf()
726 scaled_pix
= pix
.scale_simple(32, 32, gtk
.gdk
.INTERP_BILINEAR
)
727 banner_status_img
.set_from_pixbuf(scaled_pix
)
729 def get_continued_conversation_name(self
):
731 Get the name of a continued conversation. Will return Continued
732 Conversation if there isn't any other contact in the room
735 for nick
in gajim
.contacts
.get_nick_list(self
.account
,
737 if nick
!= self
.nick
:
741 title
= _('Conversation with ') + title
.join(nicks
)
743 title
= _('Continued conversation')
746 def draw_banner_text(self
):
748 Draw the text in the fat line at the top of the window that houses the
751 self
.name_label
.set_ellipsize(pango
.ELLIPSIZE_END
)
752 self
.banner_status_label
.set_ellipsize(pango
.ELLIPSIZE_END
)
753 font_attrs
, font_attrs_small
= self
.get_font_attrs()
754 if self
.is_continued
:
755 name
= self
.get_continued_conversation_name()
758 text
= '<span %s>%s</span>' % (font_attrs
, name
)
759 self
.name_label
.set_markup(text
)
762 subject
= helpers
.reduce_chars_newlines(self
.subject
, max_lines
=2)
763 subject
= gobject
.markup_escape_text(subject
)
764 subject_text
= self
.urlfinder
.sub(self
.make_href
, subject
)
765 subject_text
= '<span %s>%s</span>' % (font_attrs_small
,
768 # tooltip must always hold ALL the subject
769 self
.event_box
.set_tooltip_text(self
.subject
)
770 self
.banner_status_label
.set_no_show_all(False)
771 self
.banner_status_label
.show()
774 self
.event_box
.set_has_tooltip(False)
775 self
.banner_status_label
.hide()
776 self
.banner_status_label
.set_no_show_all(True)
778 self
.banner_status_label
.set_markup(subject_text
)
780 def prepare_context_menu(self
, hide_buttonbar_items
=False):
782 Set sensitivity state for configure_room
784 xml
= gtkgui_helpers
.get_gtk_builder('gc_control_popup_menu.ui')
785 menu
= xml
.get_object('gc_control_popup_menu')
787 bookmark_room_menuitem
= xml
.get_object('bookmark_room_menuitem')
788 change_nick_menuitem
= xml
.get_object('change_nick_menuitem')
789 configure_room_menuitem
= xml
.get_object('configure_room_menuitem')
790 destroy_room_menuitem
= xml
.get_object('destroy_room_menuitem')
791 change_subject_menuitem
= xml
.get_object('change_subject_menuitem')
792 history_menuitem
= xml
.get_object('history_menuitem')
793 minimize_menuitem
= xml
.get_object('minimize_menuitem')
794 request_voice_menuitem
= xml
.get_object('request_voice_menuitem')
795 bookmark_separator
= xml
.get_object('bookmark_separator')
796 separatormenuitem2
= xml
.get_object('separatormenuitem2')
797 request_voice_separator
= xml
.get_object('request_voice_separator')
799 if hide_buttonbar_items
:
800 change_nick_menuitem
.hide()
801 change_subject_menuitem
.hide()
802 bookmark_room_menuitem
.hide()
803 history_menuitem
.hide()
804 bookmark_separator
.hide()
805 separatormenuitem2
.hide()
807 change_nick_menuitem
.show()
808 change_subject_menuitem
.show()
809 bookmark_room_menuitem
.show()
810 history_menuitem
.show()
811 bookmark_separator
.show()
812 separatormenuitem2
.show()
813 for bm
in gajim
.connections
[self
.account
].bookmarks
:
814 if bm
['jid'] == self
.room_jid
:
815 bookmark_room_menuitem
.hide()
816 bookmark_separator
.hide()
819 ag
= gtk
.accel_groups_from_object(self
.parent_win
.window
)[0]
820 change_nick_menuitem
.add_accelerator('activate', ag
, gtk
.keysyms
.n
,
821 gtk
.gdk
.CONTROL_MASK | gtk
.gdk
.SHIFT_MASK
, gtk
.ACCEL_VISIBLE
)
822 change_subject_menuitem
.add_accelerator('activate', ag
,
823 gtk
.keysyms
.t
, gtk
.gdk
.MOD1_MASK
, gtk
.ACCEL_VISIBLE
)
824 bookmark_room_menuitem
.add_accelerator('activate', ag
, gtk
.keysyms
.b
,
825 gtk
.gdk
.CONTROL_MASK
, gtk
.ACCEL_VISIBLE
)
826 history_menuitem
.add_accelerator('activate', ag
, gtk
.keysyms
.h
,
827 gtk
.gdk
.CONTROL_MASK
, gtk
.ACCEL_VISIBLE
)
829 if self
.contact
.jid
in gajim
.config
.get_per('accounts', self
.account
,
830 'minimized_gc').split(' '):
831 minimize_menuitem
.set_active(True)
832 if not gajim
.connections
[self
.account
].private_storage_supported
:
833 bookmark_room_menuitem
.set_sensitive(False)
834 if gajim
.gc_connected
[self
.account
][self
.room_jid
]:
835 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
837 if c
.affiliation
not in ('owner', 'admin'):
838 configure_room_menuitem
.set_sensitive(False)
840 configure_room_menuitem
.set_sensitive(True)
841 if c
.affiliation
!= 'owner':
842 destroy_room_menuitem
.set_sensitive(False)
844 destroy_room_menuitem
.set_sensitive(True)
845 change_subject_menuitem
.set_sensitive(True)
846 change_nick_menuitem
.set_sensitive(True)
847 if c
.role
== 'visitor':
848 request_voice_menuitem
.set_sensitive(True)
850 request_voice_menuitem
.set_sensitive(False)
852 # We are not connected to this groupchat, disable unusable menuitems
853 configure_room_menuitem
.set_sensitive(False)
854 destroy_room_menuitem
.set_sensitive(False)
855 change_subject_menuitem
.set_sensitive(False)
856 change_nick_menuitem
.set_sensitive(False)
857 request_voice_menuitem
.set_sensitive(False)
859 # connect the menuitems to their respective functions
860 id_
= bookmark_room_menuitem
.connect('activate',
861 self
._on
_bookmark
_room
_menuitem
_activate
)
862 self
.handlers
[id_
] = bookmark_room_menuitem
864 id_
= change_nick_menuitem
.connect('activate',
865 self
._on
_change
_nick
_menuitem
_activate
)
866 self
.handlers
[id_
] = change_nick_menuitem
868 id_
= configure_room_menuitem
.connect('activate',
869 self
._on
_configure
_room
_menuitem
_activate
)
870 self
.handlers
[id_
] = configure_room_menuitem
872 id_
= destroy_room_menuitem
.connect('activate',
873 self
._on
_destroy
_room
_menuitem
_activate
)
874 self
.handlers
[id_
] = destroy_room_menuitem
876 id_
= change_subject_menuitem
.connect('activate',
877 self
._on
_change
_subject
_menuitem
_activate
)
878 self
.handlers
[id_
] = change_subject_menuitem
880 id_
= history_menuitem
.connect('activate',
881 self
._on
_history
_menuitem
_activate
)
882 self
.handlers
[id_
] = history_menuitem
884 id_
= request_voice_menuitem
.connect('activate',
885 self
._on
_request
_voice
_menuitem
_activate
)
886 self
.handlers
[id_
] = request_voice_menuitem
888 id_
= minimize_menuitem
.connect('toggled',
889 self
.on_minimize_menuitem_toggled
)
890 self
.handlers
[id_
] = minimize_menuitem
892 menu
.connect('selection-done', self
.destroy_menu
,
893 change_nick_menuitem
, change_subject_menuitem
,
894 bookmark_room_menuitem
, history_menuitem
)
897 def destroy_menu(self
, menu
, change_nick_menuitem
, change_subject_menuitem
,
898 bookmark_room_menuitem
, history_menuitem
):
899 # destroy accelerators
900 ag
= gtk
.accel_groups_from_object(self
.parent_win
.window
)[0]
901 change_nick_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.n
,
902 gtk
.gdk
.CONTROL_MASK | gtk
.gdk
.SHIFT_MASK
)
903 change_subject_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.t
,
905 bookmark_room_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.b
,
906 gtk
.gdk
.CONTROL_MASK
)
907 history_menuitem
.remove_accelerator(ag
, gtk
.keysyms
.h
,
908 gtk
.gdk
.CONTROL_MASK
)
912 def _nec_vcard_published(self
, obj
):
913 if obj
.conn
.name
!= self
.account
:
915 show
= gajim
.SHOW_LIST
[obj
.conn
.connected
]
916 status
= obj
.conn
.status
917 obj
.conn
.send_gc_status(self
.nick
, self
.room_jid
, show
, status
)
919 def _nec_vcard_received(self
, obj
):
920 if obj
.conn
.name
!= self
.account
:
922 if obj
.jid
!= self
.room_jid
:
924 self
.draw_avatar(obj
.resource
)
926 def _nec_gc_message_received(self
, obj
):
927 if obj
.room_jid
!= self
.room_jid
or obj
.conn
.name
!= self
.account
:
931 self
.form_widget
.hide()
932 self
.form_widget
.destroy()
933 self
.btn_box
.destroy()
934 dataform
= dataforms
.ExtendForm(node
=obj
.captcha_form
)
935 self
.form_widget
= dataforms_widget
.DataFormWidget(dataform
)
937 def on_send_dataform_clicked(widget
):
938 if not self
.form_widget
:
940 form_node
= self
.form_widget
.data_form
.get_purged()
941 form_node
.type = 'submit'
942 obj
.conn
.send_captcha(self
.room_jid
, form_node
)
943 self
.form_widget
.hide()
944 self
.form_widget
.destroy()
945 self
.btn_box
.destroy()
946 self
.form_widget
= None
949 self
.form_widget
.connect('validated', on_send_dataform_clicked
)
950 self
.form_widget
.show_all()
951 vbox
= self
.xml
.get_object('gc_textviews_vbox')
952 vbox
.pack_start(self
.form_widget
, expand
=False, fill
=False)
954 valid_button
= gtk
.Button(stock
=gtk
.STOCK_OK
)
955 valid_button
.connect('clicked', on_send_dataform_clicked
)
956 self
.btn_box
= gtk
.HButtonBox()
957 self
.btn_box
.set_layout(gtk
.BUTTONBOX_END
)
958 self
.btn_box
.pack_start(valid_button
)
959 self
.btn_box
.show_all()
960 vbox
.pack_start(self
.btn_box
, expand
=False, fill
=False)
962 self
.parent_win
.redraw_tab(self
, 'attention')
964 self
.attention_flag
= True
965 helpers
.play_sound('muc_message_received')
966 if '100' in obj
.status_code
:
967 # Room is not anonymous
968 self
.is_anonymous
= False
970 # message from server
971 self
.print_conversation(obj
.msgtxt
, tim
=obj
.timestamp
,
972 xhtml
=obj
.xhtml_msgtxt
, displaymarking
=obj
.displaymarking
)
974 # message from someone
975 if obj
.has_timestamp
:
976 # don't print xhtml if it's an old message.
977 # Like that xhtml messages are grayed too.
978 self
.print_old_conversation(obj
.msgtxt
, contact
=obj
.nick
,
979 tim
=obj
.timestamp
, xhtml
=None,
980 displaymarking
=obj
.displaymarking
)
982 self
.print_conversation(obj
.msgtxt
, contact
=obj
.nick
,
983 tim
=obj
.timestamp
, xhtml
=obj
.xhtml_msgtxt
,
984 displaymarking
=obj
.displaymarking
)
985 obj
.needs_highlight
= self
.needs_visual_notification(obj
.msgtxt
)
987 def on_private_message(self
, nick
, msg
, tim
, xhtml
, session
, msg_id
=None,
988 encrypted
=False, displaymarking
=None):
989 # Do we have a queue?
990 fjid
= self
.room_jid
+ '/' + nick
991 no_queue
= len(gajim
.events
.get_events(self
.account
, fjid
)) == 0
993 event
= gajim
.events
.create_event('pm', (msg
, '', 'incoming', tim
,
994 encrypted
, '', msg_id
, xhtml
, session
, displaymarking
))
995 gajim
.events
.add_event(self
.account
, fjid
, event
)
997 autopopup
= gajim
.config
.get('autopopup')
998 autopopupaway
= gajim
.config
.get('autopopupaway')
999 iter_
= self
.get_contact_iter(nick
)
1000 path
= self
.list_treeview
.get_model().get_path(iter_
)
1001 if not autopopup
or (not autopopupaway
and \
1002 gajim
.connections
[self
.account
].connected
> 2):
1003 if no_queue
: # We didn't have a queue: we change icons
1004 model
= self
.list_treeview
.get_model()
1006 gajim
.interface
.roster
.get_appropriate_state_images(
1007 self
.room_jid
, icon_name
='event')
1008 image
= state_images
['event']
1009 model
[iter_
][C_IMG
] = image
1011 self
.parent_win
.show_title()
1012 self
.parent_win
.redraw_tab(self
)
1014 self
._start
_private
_message
(nick
)
1016 self
.list_treeview
.expand_row(path
[0:1], False)
1017 self
.list_treeview
.scroll_to_cell(path
)
1018 self
.list_treeview
.set_cursor(path
)
1019 contact
= gajim
.contacts
.get_contact_with_highest_priority(
1020 self
.account
, self
.room_jid
)
1022 gajim
.interface
.roster
.draw_contact(self
.room_jid
, self
.account
)
1024 def get_contact_iter(self
, nick
):
1025 model
= self
.list_treeview
.get_model()
1026 role_iter
= model
.get_iter_root()
1028 user_iter
= model
.iter_children(role_iter
)
1030 if nick
== model
[user_iter
][C_NICK
].decode('utf-8'):
1033 user_iter
= model
.iter_next(user_iter
)
1034 role_iter
= model
.iter_next(role_iter
)
1037 def print_old_conversation(self
, text
, contact
='', tim
=None, xhtml
= None,
1038 displaymarking
=None):
1039 if isinstance(text
, str):
1040 text
= unicode(text
, 'utf-8')
1042 if contact
== self
.nick
: # it's us
1048 if gajim
.config
.get('restored_messages_small'):
1049 small_attr
= ['small']
1052 ChatControlBase
.print_conversation_line(self
, text
, kind
, contact
, tim
,
1053 small_attr
, small_attr
+ ['restored_message'],
1054 small_attr
+ ['restored_message'], count_as_new
=False, xhtml
=xhtml
,
1055 displaymarking
=displaymarking
)
1057 def print_conversation(self
, text
, contact
='', tim
=None, xhtml
=None,
1058 graphics
=True, displaymarking
=None):
1060 Print a line in the conversation
1062 If contact is set: it's a message from someone or an info message
1063 (contact = 'info' in such a case).
1064 If contact is not set: it's a message from the server or help.
1066 if isinstance(text
, str):
1067 text
= unicode(text
, 'utf-8')
1068 other_tags_for_name
= []
1069 other_tags_for_text
= []
1071 if contact
== self
.nick
: # it's us
1073 elif contact
== 'info':
1078 # muc-specific chatstate
1080 self
.parent_win
.redraw_tab(self
, 'newmsg')
1084 if kind
== 'incoming': # it's a message NOT from us
1085 # highlighting and sounds
1086 (highlight
, sound
) = self
.highlighting_for_message(text
, tim
)
1087 if contact
in self
.gc_custom_colors
:
1088 other_tags_for_name
.append('gc_nickname_color_' + \
1089 str(self
.gc_custom_colors
[contact
]))
1091 self
.gc_count_nicknames_colors
+= 1
1092 if self
.gc_count_nicknames_colors
== self
.number_of_colors
:
1093 self
.gc_count_nicknames_colors
= 0
1094 self
.gc_custom_colors
[contact
] = \
1095 self
.gc_count_nicknames_colors
1096 other_tags_for_name
.append('gc_nickname_color_' + \
1097 str(self
.gc_count_nicknames_colors
))
1099 # muc-specific chatstate
1101 self
.parent_win
.redraw_tab(self
, 'attention')
1103 self
.attention_flag
= True
1104 other_tags_for_name
.append('bold')
1105 other_tags_for_text
.append('marked')
1107 if contact
in self
.attention_list
:
1108 self
.attention_list
.remove(contact
)
1109 elif len(self
.attention_list
) > 6:
1110 self
.attention_list
.pop(0) # remove older
1111 self
.attention_list
.append(contact
)
1113 if text
.startswith('/me ') or text
.startswith('/me\n'):
1114 other_tags_for_text
.append('gc_nickname_color_' + \
1115 str(self
.gc_custom_colors
[contact
]))
1117 self
.check_and_possibly_add_focus_out_line()
1119 ChatControlBase
.print_conversation_line(self
, text
, kind
, contact
, tim
,
1120 other_tags_for_name
, [], other_tags_for_text
, xhtml
=xhtml
,
1121 graphics
=graphics
, displaymarking
=displaymarking
)
1123 def get_nb_unread(self
):
1124 type_events
= ['printed_marked_gc_msg']
1125 if gajim
.config
.get('notify_on_all_muc_messages'):
1126 type_events
.append('printed_gc_msg')
1127 nb
= len(gajim
.events
.get_events(self
.account
, self
.room_jid
,
1129 nb
+= self
.get_nb_unread_pm()
1132 def get_nb_unread_pm(self
):
1134 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
1135 nb
+= len(gajim
.events
.get_events(self
.account
, self
.room_jid
+ \
1136 '/' + nick
, ['pm']))
1139 def highlighting_for_message(self
, text
, tim
):
1141 Returns a 2-Tuple. The first says whether or not to highlight the text,
1142 the second, what sound to play
1144 highlight
, sound
= (None, None)
1146 # Are any of the defined highlighting words in the text?
1147 if self
.needs_visual_notification(text
):
1149 if gajim
.config
.get_per('soundevents', 'muc_message_highlight',
1153 # Do we play a sound on every muc message?
1154 elif gajim
.config
.get_per('soundevents', 'muc_message_received', \
1158 # Is it a history message? Don't want sound-floods when we join.
1159 if tim
!= time
.localtime():
1162 return (highlight
, sound
)
1164 def check_and_possibly_add_focus_out_line(self
):
1166 Check and possibly add focus out line for room_jid if it needs it and
1167 does not already have it as last event. If it goes to add this line
1168 - remove previous line first
1170 win
= gajim
.interface
.msg_win_mgr
.get_window(self
.room_jid
,
1172 if win
and self
.room_jid
== win
.get_active_jid() and\
1173 win
.window
.get_property('has-toplevel-focus') and\
1174 self
.parent_win
.get_active_control() == self
:
1175 # it's the current room and it's the focused window.
1176 # we have full focus (we are reading it!)
1179 at_the_end
= self
.conv_textview
.at_the_end()
1180 self
.conv_textview
.show_focus_out_line(scroll
=at_the_end
)
1182 def needs_visual_notification(self
, text
):
1184 Check text to see whether any of the words in (muc_highlight_words and
1187 special_words
= gajim
.config
.get('muc_highlight_words').split(';')
1188 special_words
.append(self
.nick
)
1189 # Strip empties: ''.split(';') == [''] and would highlight everything.
1190 # Also lowercase everything for case insensitive compare.
1191 special_words
= [word
.lower() for word
in special_words
if word
]
1194 for special_word
in special_words
:
1195 found_here
= text
.find(special_word
)
1196 while(found_here
> -1):
1197 end_here
= found_here
+ len(special_word
)
1198 if (found_here
== 0 or not text
[found_here
- 1].isalpha()) and \
1199 (end_here
== len(text
) or not text
[end_here
].isalpha()):
1200 # It is beginning of text or char before is not alpha AND
1201 # it is end of text or char after is not alpha
1203 # continue searching
1204 start
= found_here
+ 1
1205 found_here
= text
.find(special_word
, start
)
1208 def set_subject(self
, subject
):
1209 self
.subject
= subject
1210 self
.draw_banner_text()
1212 def _nec_gc_subject_received(self
, obj
):
1213 if obj
.conn
.name
!= self
.account
:
1215 if obj
.room_jid
!= self
.room_jid
:
1217 self
.set_subject(obj
.subject
)
1218 text
= _('%(nick)s has set the subject to %(subject)s') % {
1219 'nick': obj
.nickname
, 'subject': obj
.subject
}
1220 if obj
.has_timestamp
:
1221 self
.print_old_conversation(text
)
1223 self
.print_conversation(text
)
1225 def _nec_gc_config_changed_received(self
, obj
):
1226 # statuscode is a list
1227 # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
1228 # http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes...
1230 if obj
.room_jid
!= self
.room_jid
or obj
.conn
.name
!= self
.account
:
1234 if '100' in obj
.status_code
:
1235 # Can be a presence (see chg_contact_status in groupchat_control.py)
1236 changes
.append(_('Any occupant is allowed to see your full JID'))
1237 self
.is_anonymous
= False
1238 if '102' in obj
.status_code
:
1239 changes
.append(_('Room now shows unavailable member'))
1240 if '103' in obj
.status_code
:
1241 changes
.append(_('room now does not show unavailable members'))
1242 if '104' in obj
.status_code
:
1243 changes
.append(_('A non-privacy-related room configuration change '
1245 if '170' in obj
.status_code
:
1246 # Can be a presence (see chg_contact_status in groupchat_control.py)
1247 changes
.append(_('Room logging is now enabled'))
1248 if '171' in obj
.status_code
:
1249 changes
.append(_('Room logging is now disabled'))
1250 if '172' in obj
.status_code
:
1251 changes
.append(_('Room is now non-anonymous'))
1252 self
.is_anonymous
= False
1253 if '173' in obj
.status_code
:
1254 changes
.append(_('Room is now semi-anonymous'))
1255 self
.is_anonymous
= True
1256 if '174' in obj
.status_code
:
1257 changes
.append(_('Room is now fully-anonymous'))
1258 self
.is_anonymous
= True
1260 for change
in changes
:
1261 self
.print_conversation(change
)
1263 def _nec_signed_in(self
, obj
):
1264 if obj
.conn
.name
!= self
.account
:
1266 if self
.room_jid
in gajim
.gc_connected
[obj
.conn
.name
] and \
1267 gajim
.gc_connected
[obj
.conn
.name
][self
.room_jid
]:
1269 password
= gajim
.gc_passwords
.get(self
.room_jid
, '')
1270 obj
.conn
.join_gc(self
.nick
, self
.room_jid
, password
)
1272 def _nec_decrypted_message_received(self
, obj
):
1273 if obj
.conn
.name
!= self
.account
:
1275 if obj
.gc_control
== self
and obj
.resource
:
1276 # We got a pm from this room
1278 if obj
.session
.control
:
1279 # print if a control is open
1280 obj
.session
.control
.print_conversation(obj
.msgtxt
,
1281 tim
=obj
.timestamp
, xhtml
=obj
.xhtml
, encrypted
=obj
.encrypted
,
1282 displaymarking
=obj
.displaymarking
)
1284 # otherwise pass it off to the control to be queued
1285 self
.on_private_message(nick
, obj
.msgtxt
, obj
.timestamp
,
1286 obj
.xhtml
, self
, msg_id
=obj
.msg_id
, encrypted
=obj
.encrypted
,
1287 displaymarking
=obj
.displaymarking
)
1289 def got_connected(self
):
1290 # Make autorejoin stop.
1292 gobject
.source_remove(self
.autorejoin
)
1293 self
.autorejoin
= None
1295 gajim
.gc_connected
[self
.account
][self
.room_jid
] = True
1296 ChatControlBase
.got_connected(self
)
1297 # We don't redraw the whole banner here, because only icon change
1298 self
._update
_banner
_state
_image
()
1300 self
.parent_win
.redraw_tab(self
)
1301 gobject
.idle_add(self
.msg_textview
.grab_focus
)
1303 def got_disconnected(self
):
1304 self
.list_treeview
.get_model().clear()
1305 nick_list
= gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
)
1306 for nick
in nick_list
:
1307 # Update pm chat window
1308 fjid
= self
.room_jid
+ '/' + nick
1309 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
,
1310 self
.room_jid
, nick
)
1312 ctrl
= gajim
.interface
.msg_win_mgr
.get_control(fjid
, self
.account
)
1314 gc_contact
.show
= 'offline'
1315 gc_contact
.status
= ''
1318 ctrl
.parent_win
.redraw_tab(ctrl
)
1320 gajim
.contacts
.remove_gc_contact(self
.account
, gc_contact
)
1321 gajim
.gc_connected
[self
.account
][self
.room_jid
] = False
1322 ChatControlBase
.got_disconnected(self
)
1323 # Tell connection to note the date we disconnect to avoid duplicate logs
1324 gajim
.connections
[self
.account
].gc_got_disconnected(self
.room_jid
)
1325 # We don't redraw the whole banner here, because only icon change
1326 self
._update
_banner
_state
_image
()
1328 self
.parent_win
.redraw_tab(self
)
1330 # Autorejoin stuff goes here.
1331 # Notice that we don't need to activate autorejoin if connection is lost
1333 if self
.autorejoin
is None and gajim
.account_is_connected(self
.account
):
1334 ar_to
= gajim
.config
.get('muc_autorejoin_timeout')
1336 self
.autorejoin
= gobject
.timeout_add_seconds(ar_to
,
1340 if not self
.autorejoin
:
1342 password
= gajim
.gc_passwords
.get(self
.room_jid
, '')
1343 gajim
.connections
[self
.account
].join_gc(self
.nick
, self
.room_jid
,
1347 def draw_roster(self
):
1348 self
.list_treeview
.get_model().clear()
1349 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
1350 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
,
1351 self
.room_jid
, nick
)
1352 self
.add_contact_to_roster(nick
, gc_contact
.show
, gc_contact
.role
,
1353 gc_contact
.affiliation
, gc_contact
.status
, gc_contact
.jid
)
1354 self
.draw_all_roles()
1355 # Recalculate column width for ellipsizin
1356 self
.list_treeview
.columns_autosize()
1358 def on_send_pm(self
, widget
=None, model
=None, iter_
=None, nick
=None,
1361 Open a chat window and if msg is not None - send private message to a
1365 nick
= model
[iter_
][C_NICK
].decode('utf-8')
1367 ctrl
= self
._start
_private
_message
(nick
)
1369 ctrl
.send_message(msg
)
1371 def on_send_file(self
, widget
, gc_contact
):
1373 Send a file to a contact in the room
1375 self
._on
_send
_file
(gc_contact
)
1377 def draw_contact(self
, nick
, selected
=False, focus
=False):
1378 iter_
= self
.get_contact_iter(nick
)
1381 model
= self
.list_treeview
.get_model()
1382 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1384 state_images
= gajim
.interface
.jabber_state_images
['16']
1385 if len(gajim
.events
.get_events(self
.account
, self
.room_jid
+ '/' + \
1387 image
= state_images
['event']
1389 image
= state_images
[gc_contact
.show
]
1391 name
= gobject
.markup_escape_text(gc_contact
.name
)
1393 # Strike name if blocked
1394 fjid
= self
.room_jid
+ '/' + nick
1395 if helpers
.jid_is_blocked(self
.account
, fjid
):
1396 name
= '<span strikethrough="true">%s</span>' % name
1398 status
= gc_contact
.status
1399 # add status msg, if not empty, under contact name in the treeview
1400 if status
and gajim
.config
.get('show_status_msgs_in_roster'):
1401 status
= status
.strip()
1403 status
= helpers
.reduce_chars_newlines(status
, max_lines
=1)
1404 # escape markup entities and make them small italic and fg color
1405 color
= gtkgui_helpers
.get_fade_color(self
.list_treeview
,
1407 colorstring
= "#%04x%04x%04x" % (color
.red
, color
.green
,
1409 name
+= ('\n<span size="small" style="italic" foreground="%s">'
1410 '%s</span>') % (colorstring
, gobject
.markup_escape_text(
1413 if image
.get_storage_type() == gtk
.IMAGE_PIXBUF
and \
1414 gc_contact
.affiliation
!= 'none' and gajim
.config
.get(
1415 'show_affiliation_in_groupchat'):
1416 pixbuf1
= image
.get_pixbuf().copy()
1417 pixbuf2
= gtk
.gdk
.Pixbuf(gtk
.gdk
.COLORSPACE_RGB
, True, 8, 4, 4)
1418 if gc_contact
.affiliation
== 'owner':
1419 pixbuf2
.fill(0xff0000ff) # Red
1420 elif gc_contact
.affiliation
== 'admin':
1421 pixbuf2
.fill(0xffb200ff) # Oragne
1422 elif gc_contact
.affiliation
== 'member':
1423 pixbuf2
.fill(0x00ff00ff) # Green
1424 pixbuf2
.composite(pixbuf1
, 12, 12, pixbuf2
.get_property('width'),
1425 pixbuf2
.get_property('height'), 0, 0, 1.0, 1.0,
1426 gtk
.gdk
.INTERP_HYPER
, 127)
1427 image
= gtk
.image_new_from_pixbuf(pixbuf1
)
1428 model
[iter_
][C_IMG
] = image
1429 model
[iter_
][C_TEXT
] = name
1431 def draw_avatar(self
, nick
):
1432 if not gajim
.config
.get('show_avatars_in_roster'):
1434 model
= self
.list_treeview
.get_model()
1435 iter_
= self
.get_contact_iter(nick
)
1438 fake_jid
= self
.room_jid
+ '/' + nick
1439 pixbuf
= gtkgui_helpers
.get_avatar_pixbuf_from_cache(fake_jid
)
1440 if pixbuf
in ('ask', None):
1441 scaled_pixbuf
= None
1443 scaled_pixbuf
= gtkgui_helpers
.get_scaled_pixbuf(pixbuf
, 'roster')
1444 model
[iter_
][C_AVATAR
] = scaled_pixbuf
1446 def draw_role(self
, role
):
1447 role_iter
= self
.get_role_iter(role
)
1450 model
= self
.list_treeview
.get_model()
1451 role_name
= helpers
.get_uf_role(role
, plural
=True)
1452 if gajim
.config
.get('show_contacts_number'):
1453 nbr_role
, nbr_total
= gajim
.contacts
.get_nb_role_total_gc_contacts(
1454 self
.account
, self
.room_jid
, role
)
1455 role_name
+= ' (%s/%s)' % (repr(nbr_role
), repr(nbr_total
))
1456 model
[role_iter
][C_TEXT
] = role_name
1458 def draw_all_roles(self
):
1459 for role
in ('visitor', 'participant', 'moderator'):
1460 self
.draw_role(role
)
1462 def _nec_gc_presence_received(self
, obj
):
1463 if obj
.room_jid
!= self
.room_jid
or obj
.conn
.name
!= self
.account
:
1465 if obj
.ptype
== 'error':
1472 affiliation
= obj
.affiliation
1474 affiliation
= 'none'
1476 newly_created
= False
1479 # Set to true if role or affiliation have changed
1480 right_changed
= False
1484 simple_jid
= gajim
.get_jid_without_resource(obj
.real_jid
)
1485 nick_jid
+= ' (%s)' % simple_jid
1488 # http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes-\
1491 if '100' in obj
.status_code
:
1492 # Can be a message (see handle_event_gc_config_change in
1494 self
.print_conversation(
1495 _('Any occupant is allowed to see your full JID'))
1496 if '170' in obj
.status_code
:
1497 # Can be a message (see handle_event_gc_config_change in
1499 self
.print_conversation(_('Room logging is enabled'))
1500 if '201' in obj
.status_code
:
1501 self
.print_conversation(_('A new room has been created'))
1502 if '210' in obj
.status_code
:
1503 self
.print_conversation(\
1504 _('The server has assigned or modified your roomnick'))
1506 if obj
.show
in ('offline', 'error'):
1508 if '307' in obj
.status_code
:
1509 if obj
.actor
is None: # do not print 'kicked by None'
1510 s
= _('%(nick)s has been kicked: %(reason)s') % {
1511 'nick': obj
.nick
, 'reason': obj
.reason
}
1513 s
= _('%(nick)s has been kicked by %(who)s: '
1514 '%(reason)s') % {'nick': obj
.nick
, 'who': obj
.actor
,
1515 'reason': obj
.reason
}
1516 self
.print_conversation(s
, 'info', graphics
=False)
1517 if obj
.nick
== self
.nick
and not gajim
.config
.get(
1518 'muc_autorejoin_on_kick'):
1519 self
.autorejoin
= False
1520 elif '301' in obj
.status_code
:
1521 if obj
.actor
is None: # do not print 'banned by None'
1522 s
= _('%(nick)s has been banned: %(reason)s') % {
1523 'nick': obj
.nick
, 'reason': obj
.reason
}
1525 s
= _('%(nick)s has been banned by %(who)s: '
1526 '%(reason)s') % {'nick': obj
.nick
, 'who': obj
.actor
,
1527 'reason': obj
.reason
}
1528 self
.print_conversation(s
, 'info', graphics
=False)
1529 if obj
.nick
== self
.nick
:
1530 self
.autorejoin
= False
1531 elif '303' in obj
.status_code
: # Someone changed his or her nick
1532 if obj
.new_nick
== self
.new_nick
or obj
.nick
== self
.nick
:
1533 # We changed our nick
1534 self
.nick
= obj
.new_nick
1536 s
= _('You are now known as %s') % self
.nick
1537 # Stop all E2E sessions
1538 nick_list
= gajim
.contacts
.get_nick_list(self
.account
,
1540 for nick_
in nick_list
:
1541 fjid_
= self
.room_jid
+ '/' + nick_
1542 ctrl
= gajim
.interface
.msg_win_mgr
.get_control(
1543 fjid_
, self
.account
)
1544 if ctrl
and ctrl
.session
and \
1545 ctrl
.session
.enable_encryption
:
1546 thread_id
= ctrl
.session
.thread_id
1547 ctrl
.session
.terminate_e2e()
1548 gajim
.connections
[self
.account
].delete_session(
1550 ctrl
.no_autonegotiation
= False
1552 s
= _('%(nick)s is now known as %(new_nick)s') % {
1553 'nick': obj
.nick
, 'new_nick': obj
.new_nick
}
1554 # We add new nick to muc roster here, so we don't see
1555 # that "new_nick has joined the room" when he just changed
1557 # add_contact_to_roster will be called a second time
1558 # after that, but that doesn't hurt
1559 self
.add_contact_to_roster(obj
.new_nick
, obj
.show
, role
,
1560 affiliation
, obj
.status
, obj
.real_jid
)
1561 if obj
.nick
in self
.attention_list
:
1562 self
.attention_list
.remove(obj
.nick
)
1563 # keep nickname color
1564 if obj
.nick
in self
.gc_custom_colors
:
1565 self
.gc_custom_colors
[obj
.new_nick
] = \
1566 self
.gc_custom_colors
[obj
.nick
]
1567 # rename vcard / avatar
1568 puny_jid
= helpers
.sanitize_filename(self
.room_jid
)
1569 puny_nick
= helpers
.sanitize_filename(obj
.nick
)
1570 puny_new_nick
= helpers
.sanitize_filename(obj
.new_nick
)
1571 old_path
= os
.path
.join(gajim
.VCARD_PATH
, puny_jid
,
1573 new_path
= os
.path
.join(gajim
.VCARD_PATH
, puny_jid
,
1575 files
= {old_path
: new_path
}
1576 path
= os
.path
.join(gajim
.AVATAR_PATH
, puny_jid
)
1577 # possible extensions
1578 for ext
in ('.png', '.jpeg', '_notif_size_bw.png',
1579 '_notif_size_colored.png'):
1580 files
[os
.path
.join(path
, puny_nick
+ ext
)] = \
1581 os
.path
.join(path
, puny_new_nick
+ ext
)
1582 for old_file
in files
:
1583 if os
.path
.exists(old_file
) and old_file
!= \
1585 if os
.path
.exists(files
[old_file
]) and \
1586 helpers
.windowsify(old_file
) != helpers
.windowsify(
1588 # Windows require this, but os.remove('test')
1589 # will also remove 'TEST'
1590 os
.remove(files
[old_file
])
1591 os
.rename(old_file
, files
[old_file
])
1592 self
.print_conversation(s
, 'info', graphics
=False)
1593 elif '321' in obj
.status_code
:
1594 s
= _('%(nick)s has been removed from the room '
1595 '(%(reason)s)') % { 'nick': obj
.nick
,
1596 'reason': _('affiliation changed') }
1597 self
.print_conversation(s
, 'info', graphics
=False)
1598 elif '322' in obj
.status_code
:
1599 s
= _('%(nick)s has been removed from the room '
1600 '(%(reason)s)') % { 'nick': obj
.nick
,
1601 'reason': _('room configuration changed to '
1603 self
.print_conversation(s
, 'info', graphics
=False)
1604 elif '332' in obj
.status_code
:
1605 s
= _('%(nick)s has been removed from the room '
1606 '(%(reason)s)') % {'nick': obj
.nick
,
1607 'reason': _('system shutdown') }
1608 self
.print_conversation(s
, 'info', graphics
=False)
1609 # Room has been destroyed.
1610 elif 'destroyed' in obj
.status_code
:
1611 self
.autorejoin
= False
1612 self
.print_conversation(obj
.reason
, 'info', graphics
=False)
1614 if len(gajim
.events
.get_events(self
.account
, jid
=obj
.fjid
,
1615 types
=['pm'])) == 0:
1616 self
.remove_contact(obj
.nick
)
1617 self
.draw_all_roles()
1619 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1622 c
.status
= obj
.status
1623 if obj
.nick
== self
.nick
and (not obj
.status_code
or \
1624 '303' not in obj
.status_code
): # We became offline
1625 self
.got_disconnected()
1626 contact
= gajim
.contacts
.\
1627 get_contact_with_highest_priority(self
.account
,
1630 gajim
.interface
.roster
.draw_contact(self
.room_jid
,
1633 self
.parent_win
.redraw_tab(self
)
1635 iter_
= self
.get_contact_iter(obj
.nick
)
1637 if '210' in obj
.status_code
:
1638 # Server changed our nick
1639 self
.nick
= obj
.nick
1640 s
= _('You are now known as %s') % obj
.nick
1641 self
.print_conversation(s
, 'info', graphics
=False)
1642 iter_
= self
.add_contact_to_roster(obj
.nick
, obj
.show
, role
,
1643 affiliation
, obj
.status
, obj
.real_jid
)
1644 newly_created
= True
1645 self
.draw_all_roles()
1646 if obj
.status_code
and '201' in obj
.status_code
:
1647 # We just created the room
1648 gajim
.connections
[self
.account
].request_gc_config(
1651 gc_c
= gajim
.contacts
.get_gc_contact(self
.account
,
1652 self
.room_jid
, obj
.nick
)
1654 log
.error('%s has an iter, but no gc_contact instance' % \
1657 # Re-get vcard if avatar has changed
1658 # We do that here because we may request it to the real JID if
1659 # we knows it. connections.py doesn't know it.
1660 con
= gajim
.connections
[self
.account
]
1661 if gc_c
and gc_c
.jid
:
1665 if obj
.fjid
in obj
.conn
.vcard_shas
:
1666 if obj
.avatar_sha
!= obj
.conn
.vcard_shas
[obj
.fjid
]:
1667 server
= gajim
.get_server_from_jid(self
.room_jid
)
1668 if not server
.startswith('irc'):
1669 obj
.conn
.request_vcard(real_jid
, obj
.fjid
)
1671 cached_vcard
= obj
.conn
.get_cached_vcard(obj
.fjid
, True)
1672 if cached_vcard
and 'PHOTO' in cached_vcard
and \
1673 'SHA' in cached_vcard
['PHOTO']:
1674 cached_sha
= cached_vcard
['PHOTO']['SHA']
1677 if cached_sha
!= obj
.avatar_sha
:
1678 # avatar has been updated
1679 # sha in mem will be updated later
1680 server
= gajim
.get_server_from_jid(self
.room_jid
)
1681 if not server
.startswith('irc'):
1682 obj
.conn
.request_vcard(real_jid
, obj
.fjid
)
1684 # save sha in mem NOW
1685 obj
.conn
.vcard_shas
[obj
.fjid
] = obj
.avatar_sha
1687 actual_affiliation
= gc_c
.affiliation
1688 if affiliation
!= actual_affiliation
:
1690 st
= _('** Affiliation of %(nick)s has been set to '
1691 '%(affiliation)s by %(actor)s') % {'nick': nick_jid
,
1692 'affiliation': affiliation
, 'actor': obj
.actor
}
1694 st
= _('** Affiliation of %(nick)s has been set to '
1695 '%(affiliation)s') % {'nick': nick_jid
,
1696 'affiliation': affiliation
}
1698 st
+= ' (%s)' % obj
.reason
1699 self
.print_conversation(st
, graphics
=False)
1700 right_changed
= True
1701 actual_role
= self
.get_role(obj
.nick
)
1702 if role
!= actual_role
:
1703 self
.remove_contact(obj
.nick
)
1704 self
.add_contact_to_roster(obj
.nick
, obj
.show
, role
,
1705 affiliation
, obj
.status
, obj
.real_jid
)
1706 self
.draw_role(actual_role
)
1707 self
.draw_role(role
)
1709 st
= _('** Role of %(nick)s has been set to %(role)s '
1710 'by %(actor)s') % {'nick': nick_jid
, 'role': role
,
1713 st
= _('** Role of %(nick)s has been set to '
1714 '%(role)s') % {'nick': nick_jid
, 'role': role
}
1716 st
+= ' (%s)' % obj
.reason
1717 self
.print_conversation(st
, graphics
=False)
1718 right_changed
= True
1720 if gc_c
.show
== obj
.show
and gc_c
.status
== obj
.status
and \
1721 gc_c
.affiliation
== affiliation
: # no change
1723 gc_c
.show
= obj
.show
1724 gc_c
.affiliation
= affiliation
1725 gc_c
.status
= obj
.status
1726 self
.draw_contact(obj
.nick
)
1727 if (time
.time() - self
.room_creation
) > 30 and obj
.nick
!= self
.nick \
1728 and (not obj
.status_code
or '303' not in obj
.status_code
) and not \
1732 for bookmark
in gajim
.connections
[self
.account
].bookmarks
:
1733 if bookmark
['jid'] == self
.room_jid
:
1734 print_status
= bookmark
.get('print_status', None)
1736 if not print_status
:
1737 print_status
= gajim
.config
.get('print_status_in_muc')
1738 if obj
.show
== 'offline':
1739 if obj
.nick
in self
.attention_list
:
1740 self
.attention_list
.remove(obj
.nick
)
1741 if obj
.show
== 'offline' and print_status
in ('all', 'in_and_out') \
1742 and (not obj
.status_code
or '307' not in obj
.status_code
):
1743 st
= _('%s has left') % nick_jid
1745 st
+= ' [%s]' % obj
.reason
1747 if newly_created
and print_status
in ('all', 'in_and_out'):
1748 st
= _('%s has joined the group chat') % nick_jid
1749 elif print_status
== 'all':
1750 st
= _('%(nick)s is now %(status)s') % {'nick': nick_jid
,
1751 'status': helpers
.get_uf_show(obj
.show
)}
1754 st
+= ' (' + obj
.status
+ ')'
1755 self
.print_conversation(st
, graphics
=False)
1757 def add_contact_to_roster(self
, nick
, show
, role
, affiliation
, status
,
1759 model
= self
.list_treeview
.get_model()
1760 role_name
= helpers
.get_uf_role(role
, plural
=True)
1764 jids
= jid
.split('/', 1)
1773 role_iter
= self
.get_role_iter(role
)
1775 role_iter
= model
.append(None,
1776 [gajim
.interface
.jabber_state_images
['16']['closed'], role
,
1777 'role', role_name
, None] + [None] * self
.nb_ext_renderers
)
1778 self
.draw_all_roles()
1779 iter_
= model
.append(role_iter
, [None, nick
, 'contact', name
, None] + \
1780 [None] * self
.nb_ext_renderers
)
1781 if not nick
in gajim
.contacts
.get_nick_list(self
.account
,
1783 gc_contact
= gajim
.contacts
.create_gc_contact(
1784 room_jid
=self
.room_jid
, account
=self
.account
,
1785 name
=nick
, show
=show
, status
=status
, role
=role
,
1786 affiliation
=affiliation
, jid
=j
, resource
=resource
)
1787 gajim
.contacts
.add_gc_contact(self
.account
, gc_contact
)
1788 self
.draw_contact(nick
)
1789 self
.draw_avatar(nick
)
1790 # Do not ask avatar to irc rooms as irc transports reply with messages
1791 server
= gajim
.get_server_from_jid(self
.room_jid
)
1792 if gajim
.config
.get('ask_avatars_on_startup') and \
1793 not server
.startswith('irc'):
1794 fake_jid
= self
.room_jid
+ '/' + nick
1795 pixbuf
= gtkgui_helpers
.get_avatar_pixbuf_from_cache(fake_jid
)
1797 if j
and not self
.is_anonymous
:
1798 gajim
.connections
[self
.account
].request_vcard(j
, fake_jid
)
1800 gajim
.connections
[self
.account
].request_vcard(fake_jid
,
1802 if nick
== self
.nick
: # we became online
1803 self
.got_connected()
1804 self
.list_treeview
.expand_row((model
.get_path(role_iter
)), False)
1805 if self
.is_continued
:
1806 self
.draw_banner_text()
1809 def get_role_iter(self
, role
):
1810 model
= self
.list_treeview
.get_model()
1811 role_iter
= model
.get_iter_root()
1813 role_name
= model
[role_iter
][C_NICK
].decode('utf-8')
1814 if role
== role_name
:
1816 role_iter
= model
.iter_next(role_iter
)
1819 def remove_contact(self
, nick
):
1821 Remove a user from the contacts_list
1823 model
= self
.list_treeview
.get_model()
1824 iter_
= self
.get_contact_iter(nick
)
1827 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1830 gajim
.contacts
.remove_gc_contact(self
.account
, gc_contact
)
1831 parent_iter
= model
.iter_parent(iter_
)
1833 if model
.iter_n_children(parent_iter
) == 0:
1834 model
.remove(parent_iter
)
1836 def send_message(self
, message
, xhtml
=None, process_commands
=True):
1838 Call this function to send our message
1843 if process_commands
and self
.process_as_command(message
):
1846 message
= helpers
.remove_invalid_xml_chars(message
)
1851 label
= self
.get_seclabel()
1852 if message
!= '' or message
!= '\n':
1853 self
.save_message(message
, 'sent')
1856 gajim
.connections
[self
.account
].send_gc_message(self
.room_jid
,
1857 message
, xhtml
=xhtml
, label
=label
)
1858 self
.msg_textview
.get_buffer().set_text('')
1859 self
.msg_textview
.grab_focus()
1861 def get_role(self
, nick
):
1862 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
1865 return gc_contact
.role
1869 def minimizable(self
):
1870 if self
.contact
.jid
in gajim
.config
.get_per('accounts', self
.account
,
1871 'minimized_gc').split(' '):
1875 def minimize(self
, status
='offline'):
1877 win
= gajim
.interface
.msg_win_mgr
.get_window(self
.contact
.jid
,
1879 ctrl
= win
.get_control(self
.contact
.jid
, self
.account
)
1881 ctrl_page
= win
.notebook
.page_num(ctrl
.widget
)
1882 control
= win
.notebook
.get_nth_page(ctrl_page
)
1884 win
.notebook
.remove_page(ctrl_page
)
1886 ctrl
.parent_win
= None
1888 gajim
.interface
.roster
.add_groupchat(self
.contact
.jid
, self
.account
,
1889 status
= self
.subject
)
1891 del win
._controls
[self
.account
][self
.contact
.jid
]
1893 def shutdown(self
, status
='offline'):
1894 # PluginSystem: calling shutdown of super class (ChatControlBase)
1895 # to let it remove it's GUI extension points
1896 super(GroupchatControl
, self
).shutdown()
1897 # PluginSystem: removing GUI extension points connected with
1898 # GrouphatControl instance object
1899 gajim
.plugin_manager
.remove_gui_extension_point('groupchat_control',
1902 # Preventing autorejoin from being activated
1903 self
.autorejoin
= False
1905 gajim
.ged
.remove_event_handler('gc-presence-received', ged
.GUI1
,
1906 self
._nec
_gc
_presence
_received
)
1907 gajim
.ged
.remove_event_handler('gc-message-received', ged
.GUI1
,
1908 self
._nec
_gc
_message
_received
)
1909 gajim
.ged
.remove_event_handler('vcard-published', ged
.GUI1
,
1910 self
._nec
_vcard
_published
)
1911 gajim
.ged
.remove_event_handler('vcard-received', ged
.GUI1
,
1912 self
._nec
_vcard
_received
)
1913 gajim
.ged
.remove_event_handler('gc-subject-received', ged
.GUI1
,
1914 self
._nec
_gc
_subject
_received
)
1915 gajim
.ged
.remove_event_handler('gc-config-changed-received', ged
.GUI1
,
1916 self
._nec
_gc
_config
_changed
_received
)
1917 gajim
.ged
.remove_event_handler('signed-in', ged
.GUI1
,
1918 self
._nec
_signed
_in
)
1920 if self
.room_jid
in gajim
.gc_connected
[self
.account
] and \
1921 gajim
.gc_connected
[self
.account
][self
.room_jid
]:
1922 # Tell connection to note the date we disconnect to avoid duplicate
1923 # logs. We do it only when connected because if connection was lost
1924 # there may be new messages since disconnection.
1925 gajim
.connections
[self
.account
].gc_got_disconnected(self
.room_jid
)
1926 gajim
.connections
[self
.account
].send_gc_status(self
.nick
,
1927 self
.room_jid
, show
='offline', status
=status
)
1928 nick_list
= gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
)
1929 for nick
in nick_list
:
1930 # Update pm chat window
1931 fjid
= self
.room_jid
+ '/' + nick
1932 ctrl
= gajim
.interface
.msg_win_mgr
.get_gc_control(fjid
,
1935 contact
= gajim
.contacts
.get_gc_contact(self
.account
,
1936 self
.room_jid
, nick
)
1937 contact
.show
= 'offline'
1940 ctrl
.parent_win
.redraw_tab(ctrl
)
1941 for sess
in gajim
.connections
[self
.account
].get_sessions(fjid
):
1943 sess
.control
.no_autonegotiation
= False
1944 if sess
.enable_encryption
:
1945 sess
.terminate_e2e()
1946 gajim
.connections
[self
.account
].delete_session(fjid
,
1948 # They can already be removed by the destroy function
1949 if self
.room_jid
in gajim
.contacts
.get_gc_list(self
.account
):
1950 gajim
.contacts
.remove_room(self
.account
, self
.room_jid
)
1951 del gajim
.gc_connected
[self
.account
][self
.room_jid
]
1952 # Save hpaned position
1953 gajim
.config
.set('gc-hpaned-position', self
.hpaned
.get_position())
1954 # remove all register handlers on wigets, created by self.xml
1955 # to prevent circular references among objects
1956 for i
in self
.handlers
.keys():
1957 if self
.handlers
[i
].handler_is_connected(i
):
1958 self
.handlers
[i
].disconnect(i
)
1959 del self
.handlers
[i
]
1960 # Remove unread events from systray
1961 gajim
.events
.remove_events(self
.account
, self
.room_jid
)
1963 def safe_shutdown(self
):
1964 if self
.minimizable():
1966 includes
= gajim
.config
.get('confirm_close_muc_rooms').split(' ')
1967 excludes
= gajim
.config
.get('noconfirm_close_muc_rooms').split(' ')
1968 # whether to ask for comfirmation before closing muc
1969 if (gajim
.config
.get('confirm_close_muc') or self
.room_jid
in includes
)\
1970 and gajim
.gc_connected
[self
.account
][self
.room_jid
] and self
.room_jid \
1975 def allow_shutdown(self
, method
, on_yes
, on_no
, on_minimize
):
1976 if self
.minimizable():
1979 if method
== self
.parent_win
.CLOSE_ESC
:
1980 iter_
= self
.list_treeview
.get_selection().get_selected()[1]
1982 self
.list_treeview
.get_selection().unselect_all()
1985 includes
= gajim
.config
.get('confirm_close_muc_rooms').split(' ')
1986 excludes
= gajim
.config
.get('noconfirm_close_muc_rooms').split(' ')
1987 # whether to ask for comfirmation before closing muc
1988 if (gajim
.config
.get('confirm_close_muc') or self
.room_jid
in includes
)\
1989 and gajim
.gc_connected
[self
.account
][self
.room_jid
] and self
.room_jid \
1994 # user does not want to be asked again
1995 gajim
.config
.set('confirm_close_muc', False)
1998 def on_cancel(clicked
):
2000 # user does not want to be asked again
2001 gajim
.config
.set('confirm_close_muc', False)
2004 pritext
= _('Are you sure you want to leave group chat "%s"?')\
2006 sectext
= _('If you close this window, you will be disconnected '
2007 'from this group chat.')
2009 dialogs
.ConfirmationDialogCheck(pritext
, sectext
,
2010 _('_Do not ask me again'), on_response_ok
=on_ok
,
2011 on_response_cancel
=on_cancel
)
2016 def set_control_active(self
, state
):
2017 self
.conv_textview
.allow_focus_out_line
= True
2018 self
.attention_flag
= False
2019 ChatControlBase
.set_control_active(self
, state
)
2021 # add the focus-out line to the tab we are leaving
2022 self
.check_and_possibly_add_focus_out_line()
2023 # Sending active to undo unread state
2024 self
.parent_win
.redraw_tab(self
, 'active')
2026 def get_specific_unread(self
):
2027 # returns the number of the number of unread msgs
2028 # for room_jid & number of unread private msgs with each contact
2031 for nick
in gajim
.contacts
.get_nick_list(self
.account
, self
.room_jid
):
2032 fjid
= self
.room_jid
+ '/' + nick
2033 nb
+= len(gajim
.events
.get_events(self
.account
, fjid
))
2034 # gc can only have messages as event
2037 def _on_change_subject_menuitem_activate(self
, widget
):
2039 # Note, we don't update self.subject since we don't know whether it
2041 gajim
.connections
[self
.account
].send_gc_subject(self
.room_jid
,
2044 dialogs
.InputTextDialog(_('Changing Subject'),
2045 _('Please specify the new subject:'), input_str
=self
.subject
,
2048 def _on_change_nick_menuitem_activate(self
, widget
):
2049 if 'change_nick_dialog' in gajim
.interface
.instances
:
2050 gajim
.interface
.instances
['change_nick_dialog'].present()
2052 title
= _('Changing Nickname')
2053 prompt
= _('Please specify the new nickname you want to use:')
2054 gajim
.interface
.instances
['change_nick_dialog'] = \
2055 dialogs
.ChangeNickDialog(self
.account
, self
.room_jid
, title
,
2056 prompt
, change_nick
=True)
2058 def _on_configure_room_menuitem_activate(self
, widget
):
2059 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
2061 if c
.affiliation
== 'owner':
2062 gajim
.connections
[self
.account
].request_gc_config(self
.room_jid
)
2063 elif c
.affiliation
== 'admin':
2064 if self
.room_jid
not in gajim
.interface
.instances
[self
.account
][
2066 gajim
.interface
.instances
[self
.account
]['gc_config'][
2067 self
.room_jid
] = config
.GroupchatConfigWindow(self
.account
,
2070 def _on_destroy_room_menuitem_activate(self
, widget
):
2071 def on_ok(reason
, jid
):
2075 jid
= helpers
.parse_jid(jid
)
2077 dialogs
.ErrorDialog(_('Invalid group chat Jabber ID'),
2078 _('The group chat Jabber ID has not allowed characters.'))
2080 gajim
.connections
[self
.account
].destroy_gc_room(self
.room_jid
,
2084 dialogs
.DoubleInputDialog(_('Destroying %s') % self
.room_jid
,
2085 _('You are going to definitively destroy this room.\n'
2086 'You may specify a reason below:'),
2087 _('You may also enter an alternate venue:'), ok_handler
=on_ok
)
2089 def _on_bookmark_room_menuitem_activate(self
, widget
):
2091 Bookmark the room, without autojoin and not minimized
2093 password
= gajim
.gc_passwords
.get(self
.room_jid
, '')
2094 gajim
.interface
.add_gc_bookmark(self
.account
, self
.name
, self
.room_jid
,\
2095 '0', '0', password
, self
.nick
)
2097 def _on_request_voice_menuitem_activate(self
, widget
):
2099 Request voice in the current room
2101 gajim
.connections
[self
.account
].request_voice(self
.room_jid
)
2103 def _on_drag_data_received(self
, widget
, context
, x
, y
, selection
,
2104 target_type
, timestamp
):
2105 # Invite contact to groupchat
2106 treeview
= gajim
.interface
.roster
.tree
2107 model
= treeview
.get_model()
2108 if not selection
.data
or target_type
== 80:
2109 # target_type = 80 means a file is dropped
2111 data
= selection
.data
2112 path
= treeview
.get_selection().get_selected_rows()[1][0]
2113 iter_
= model
.get_iter(path
)
2114 type_
= model
[iter_
][2]
2115 if type_
!= 'contact': # source is not a contact
2117 contact_jid
= data
.decode('utf-8')
2118 gajim
.connections
[self
.account
].send_invite(self
.room_jid
, contact_jid
)
2120 def handle_message_textview_mykey_press(self
, widget
, event_keyval
,
2122 # NOTE: handles mykeypress which is custom signal connected to this
2123 # CB in new_room(). for this singal see message_textview.py
2125 if not widget
.get_sensitive():
2126 # Textview is not sensitive, don't handle keypress
2128 # construct event instance from binding
2129 event
= gtk
.gdk
.Event(gtk
.gdk
.KEY_PRESS
) # it's always a key-press here
2130 event
.keyval
= event_keyval
2131 event
.state
= event_keymod
2132 event
.time
= 0 # assign current time
2134 message_buffer
= widget
.get_buffer()
2135 start_iter
, end_iter
= message_buffer
.get_bounds()
2137 if event
.keyval
== gtk
.keysyms
.Tab
: # TAB
2138 cursor_position
= message_buffer
.get_insert()
2139 end_iter
= message_buffer
.get_iter_at_mark(cursor_position
)
2140 text
= message_buffer
.get_text(start_iter
, end_iter
, False).decode(
2143 splitted_text
= text
.split()
2145 # HACK: Not the best soltution.
2146 if (text
.startswith(self
.COMMAND_PREFIX
) and not
2147 text
.startswith(self
.COMMAND_PREFIX
* 2) and \
2148 len(splitted_text
) == 1):
2149 return super(GroupchatControl
, self
).\
2150 handle_message_textview_mykey_press(widget
, event_keyval
,
2154 # check if tab is pressed with empty message
2155 if len(splitted_text
): # if there are any words
2156 begin
= splitted_text
[-1] # last word we typed
2160 gc_refer_to_nick_char
= gajim
.config
.get('gc_refer_to_nick_char')
2161 with_refer_to_nick_char
= False
2162 after_nick_len
= 1 # the space that is printed after we type [Tab]
2164 # first part of this if : works fine even if refer_to_nick_char
2165 if gc_refer_to_nick_char
and text
.endswith(
2166 gc_refer_to_nick_char
+ ' '):
2167 with_refer_to_nick_char
= True
2168 after_nick_len
= len(gc_refer_to_nick_char
+ ' ')
2169 if len(self
.nick_hits
) and self
.last_key_tabs
and \
2170 text
[:-after_nick_len
].endswith(self
.nick_hits
[0]):
2172 # Previous nick in list may had a space inside, so we check text
2173 # and not splitted_text and store it into 'begin' var
2174 self
.nick_hits
.append(self
.nick_hits
[0])
2175 begin
= self
.nick_hits
.pop(0)
2177 self
.nick_hits
= [] # clear the hit list
2178 list_nick
= gajim
.contacts
.get_nick_list(self
.account
,
2180 list_nick
.sort(key
=unicode.lower
) # case-insensitive sort
2182 # empty message, show lasts nicks that highlighted us first
2183 for nick
in self
.attention_list
:
2184 if nick
in list_nick
:
2185 list_nick
.remove(nick
)
2186 list_nick
.insert(0, nick
)
2188 list_nick
.remove(self
.nick
) # Skip self
2189 for nick
in list_nick
:
2190 if nick
.lower().startswith(begin
.lower()):
2191 # the word is the begining of a nick
2192 self
.nick_hits
.append(nick
)
2193 if len(self
.nick_hits
):
2194 if len(splitted_text
) < 2 or with_refer_to_nick_char
:
2195 # This is the 1st word of the line or no word or we are cycling
2196 # at the beginning, possibly with a space in one nick
2197 add
= gc_refer_to_nick_char
+ ' '
2200 start_iter
= end_iter
.copy()
2201 if self
.last_key_tabs
and with_refer_to_nick_char
or (text
and \
2203 # have to accomodate for the added space from last
2205 # gc_refer_to_nick_char may be more than one char!
2206 start_iter
.backward_chars(len(begin
) + len(add
))
2207 elif self
.last_key_tabs
and not gajim
.config
.get(
2208 'shell_like_completion'):
2209 # have to accomodate for the added space from last
2211 start_iter
.backward_chars(len(begin
) + \
2212 len(gc_refer_to_nick_char
))
2214 start_iter
.backward_chars(len(begin
))
2216 message_buffer
.delete(start_iter
, end_iter
)
2217 # get a shell-like completion
2218 # if there's more than one nick for this completion, complete
2219 # only the part that all these nicks have in common
2220 if gajim
.config
.get('shell_like_completion') and \
2221 len(self
.nick_hits
) > 1:
2224 add
= "" # if nick is not complete, don't add anything
2225 while not end
and len(completion
) < len(self
.nick_hits
[0]):
2226 completion
= self
.nick_hits
[0][:len(completion
)+1]
2227 for nick
in self
.nick_hits
:
2228 if completion
.lower() not in nick
.lower():
2230 completion
= completion
[:-1]
2232 # if the current nick matches a COMPLETE existing nick,
2233 # and if the user tab TWICE, complete that nick (with the
2235 if self
.last_key_tabs
:
2236 for nick
in self
.nick_hits
:
2237 if nick
== completion
:
2238 # The user seems to want this nick, so
2239 # complete it as if it were the only nick
2241 add
= gc_refer_to_nick_char
+ ' '
2243 completion
= self
.nick_hits
[0]
2244 message_buffer
.insert_at_cursor(completion
+ add
)
2245 self
.last_key_tabs
= True
2247 self
.last_key_tabs
= False
2249 def on_list_treeview_key_press_event(self
, widget
, event
):
2250 if event
.keyval
== gtk
.keysyms
.Escape
:
2251 selection
= widget
.get_selection()
2252 iter_
= selection
.get_selected()[1]
2254 widget
.get_selection().unselect_all()
2257 def on_list_treeview_row_expanded(self
, widget
, iter_
, path
):
2259 When a row is expanded: change the icon of the arrow
2261 model
= widget
.get_model()
2262 image
= gajim
.interface
.jabber_state_images
['16']['opened']
2263 model
[iter_
][C_IMG
] = image
2265 def on_list_treeview_row_collapsed(self
, widget
, iter_
, path
):
2267 When a row is collapsed: change the icon of the arrow
2269 model
= widget
.get_model()
2270 image
= gajim
.interface
.jabber_state_images
['16']['closed']
2271 model
[iter_
][C_IMG
] = image
2273 def kick(self
, widget
, nick
):
2278 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2282 dialogs
.InputDialog(_('Kicking %s') % nick
,
2283 _('You may specify a reason below:'), ok_handler
=on_ok
)
2285 def mk_menu(self
, event
, iter_
):
2287 Make contact's popup menu
2289 model
= self
.list_treeview
.get_model()
2290 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2291 c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
, nick
)
2292 fjid
= self
.room_jid
+ '/' + nick
2294 target_affiliation
= c
.affiliation
2295 target_role
= c
.role
2297 # looking for user's affiliation and role
2298 user_nick
= self
.nick
2299 user_affiliation
= gajim
.contacts
.get_gc_contact(self
.account
,
2300 self
.room_jid
, user_nick
).affiliation
2301 user_role
= self
.get_role(user_nick
)
2303 # making menu from gtk builder
2304 xml
= gtkgui_helpers
.get_gtk_builder('gc_occupants_menu.ui')
2306 # these conditions were taken from JEP 0045
2307 item
= xml
.get_object('kick_menuitem')
2308 if user_role
!= 'moderator' or \
2309 (user_affiliation
== 'admin' and target_affiliation
== 'owner') or \
2310 (user_affiliation
== 'member' and target_affiliation
in ('admin',
2311 'owner')) or (user_affiliation
== 'none' and target_affiliation
!= \
2313 item
.set_sensitive(False)
2314 id_
= item
.connect('activate', self
.kick
, nick
)
2315 self
.handlers
[id_
] = item
2317 item
= xml
.get_object('voice_checkmenuitem')
2318 item
.set_active(target_role
!= 'visitor')
2319 if user_role
!= 'moderator' or \
2320 user_affiliation
== 'none' or \
2321 (user_affiliation
=='member' and target_affiliation
!='none') or \
2322 target_affiliation
in ('admin', 'owner'):
2323 item
.set_sensitive(False)
2324 id_
= item
.connect('activate', self
.on_voice_checkmenuitem_activate
,
2326 self
.handlers
[id_
] = item
2328 item
= xml
.get_object('moderator_checkmenuitem')
2329 item
.set_active(target_role
== 'moderator')
2330 if not user_affiliation
in ('admin', 'owner') or \
2331 target_affiliation
in ('admin', 'owner'):
2332 item
.set_sensitive(False)
2333 id_
= item
.connect('activate', self
.on_moderator_checkmenuitem_activate
,
2335 self
.handlers
[id_
] = item
2337 item
= xml
.get_object('ban_menuitem')
2338 if not user_affiliation
in ('admin', 'owner') or \
2339 (target_affiliation
in ('admin', 'owner') and\
2340 user_affiliation
!= 'owner'):
2341 item
.set_sensitive(False)
2342 id_
= item
.connect('activate', self
.ban
, jid
)
2343 self
.handlers
[id_
] = item
2345 item
= xml
.get_object('member_checkmenuitem')
2346 item
.set_active(target_affiliation
!= 'none')
2347 if not user_affiliation
in ('admin', 'owner') or \
2348 (user_affiliation
!= 'owner' and target_affiliation
in ('admin',
2350 item
.set_sensitive(False)
2351 id_
= item
.connect('activate', self
.on_member_checkmenuitem_activate
,
2353 self
.handlers
[id_
] = item
2355 item
= xml
.get_object('admin_checkmenuitem')
2356 item
.set_active(target_affiliation
in ('admin', 'owner'))
2357 if not user_affiliation
== 'owner':
2358 item
.set_sensitive(False)
2359 id_
= item
.connect('activate', self
.on_admin_checkmenuitem_activate
,
2361 self
.handlers
[id_
] = item
2363 item
= xml
.get_object('owner_checkmenuitem')
2364 item
.set_active(target_affiliation
== 'owner')
2365 if not user_affiliation
== 'owner':
2366 item
.set_sensitive(False)
2367 id_
= item
.connect('activate', self
.on_owner_checkmenuitem_activate
,
2369 self
.handlers
[id_
] = item
2371 item
= xml
.get_object('invite_menuitem')
2372 muc_icon
= gtkgui_helpers
.load_icon('muc_active')
2374 item
.set_image(muc_icon
)
2375 if c
.jid
and c
.name
!= self
.nick
:
2376 gui_menu_builder
.build_invite_submenu(item
, ((c
, self
.account
),),
2377 ignore_rooms
=[self
.room_jid
])
2379 item
.set_sensitive(False)
2381 item
= xml
.get_object('information_menuitem')
2382 id_
= item
.connect('activate', self
.on_info
, nick
)
2383 self
.handlers
[id_
] = item
2385 item
= xml
.get_object('history_menuitem')
2386 id_
= item
.connect('activate', self
.on_history
, nick
)
2387 self
.handlers
[id_
] = item
2389 item
= xml
.get_object('add_to_roster_menuitem')
2390 our_jid
= gajim
.get_jid_from_account(self
.account
)
2391 if not jid
or jid
== our_jid
:
2392 item
.set_sensitive(False)
2394 id_
= item
.connect('activate', self
.on_add_to_roster
, jid
)
2395 self
.handlers
[id_
] = item
2397 item
= xml
.get_object('block_menuitem')
2398 item2
= xml
.get_object('unblock_menuitem')
2399 if helpers
.jid_is_blocked(self
.account
, fjid
):
2400 item
.set_no_show_all(True)
2402 id_
= item2
.connect('activate', self
.on_unblock
, nick
)
2403 self
.handlers
[id_
] = item2
2405 id_
= item
.connect('activate', self
.on_block
, nick
)
2406 self
.handlers
[id_
] = item
2407 item2
.set_no_show_all(True)
2410 item
= xml
.get_object('send_private_message_menuitem')
2411 id_
= item
.connect('activate', self
.on_send_pm
, model
, iter_
)
2412 self
.handlers
[id_
] = item
2414 item
= xml
.get_object('send_file_menuitem')
2415 # add a special img for send file menuitem
2416 path_to_upload_img
= gtkgui_helpers
.get_icon_path('gajim-upload')
2418 img
.set_from_file(path_to_upload_img
)
2422 item
.set_sensitive(False)
2424 id_
= item
.connect('activate', self
.on_send_file
, c
)
2425 self
.handlers
[id_
] = item
2427 # show the popup now!
2428 menu
= xml
.get_object('gc_occupants_menu')
2430 menu
.popup(None, None, None, event
.button
, event
.time
)
2432 def _start_private_message(self
, nick
):
2433 gc_c
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
, nick
)
2434 nick_jid
= gc_c
.get_full_jid()
2436 ctrl
= gajim
.interface
.msg_win_mgr
.get_control(nick_jid
, self
.account
)
2438 ctrl
= gajim
.interface
.new_private_chat(gc_c
, self
.account
)
2441 ctrl
.parent_win
.set_active_tab(ctrl
)
2445 def on_row_activated(self
, widget
, path
):
2447 When an iter is activated (dubblick or single click if gnome is set this
2450 model
= widget
.get_model()
2451 if len(path
) == 1: # It's a group
2452 if (widget
.row_expanded(path
)):
2453 widget
.collapse_row(path
)
2455 widget
.expand_row(path
, False)
2456 else: # We want to send a private message
2457 nick
= model
[path
][C_NICK
].decode('utf-8')
2458 self
._start
_private
_message
(nick
)
2460 def on_list_treeview_row_activated(self
, widget
, path
, col
=0):
2462 When an iter is double clicked: open the chat window
2464 if not gajim
.single_click
:
2465 self
.on_row_activated(widget
, path
)
2467 def on_list_treeview_button_press_event(self
, widget
, event
):
2469 Popup user's group's or agent menu
2471 # hide tooltip, no matter the button is pressed
2472 self
.tooltip
.hide_tooltip()
2474 pos
= widget
.get_path_at_pos(int(event
.x
), int(event
.y
))
2475 path
, x
= pos
[0], pos
[2]
2477 widget
.get_selection().unselect_all()
2479 if event
.button
== 3: # right click
2480 widget
.get_selection().select_path(path
)
2481 model
= widget
.get_model()
2482 iter_
= model
.get_iter(path
)
2484 self
.mk_menu(event
, iter_
)
2487 elif event
.button
== 2: # middle click
2488 widget
.get_selection().select_path(path
)
2489 model
= widget
.get_model()
2490 iter_
= model
.get_iter(path
)
2492 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2493 self
._start
_private
_message
(nick
)
2496 elif event
.button
== 1: # left click
2497 if gajim
.single_click
and not event
.state
& gtk
.gdk
.SHIFT_MASK
:
2498 self
.on_row_activated(widget
, path
)
2501 model
= widget
.get_model()
2502 iter_
= model
.get_iter(path
)
2503 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2504 if not nick
in gajim
.contacts
.get_nick_list(self
.account
,
2508 if (widget
.row_expanded(path
)):
2509 widget
.collapse_row(path
)
2511 widget
.expand_row(path
, False)
2512 elif event
.state
& gtk
.gdk
.SHIFT_MASK
:
2513 self
.append_nick_in_msg_textview(self
.msg_textview
, nick
)
2514 self
.msg_textview
.grab_focus()
2517 def append_nick_in_msg_textview(self
, widget
, nick
):
2518 message_buffer
= self
.msg_textview
.get_buffer()
2519 start_iter
, end_iter
= message_buffer
.get_bounds()
2520 cursor_position
= message_buffer
.get_insert()
2521 end_iter
= message_buffer
.get_iter_at_mark(cursor_position
)
2522 text
= message_buffer
.get_text(start_iter
, end_iter
, False)
2524 if text
: # Cursor is not at first position
2525 if not text
[-1] in (' ', '\n', '\t'):
2529 gc_refer_to_nick_char
= gajim
.config
.get('gc_refer_to_nick_char')
2530 add
= gc_refer_to_nick_char
+ ' '
2531 message_buffer
.insert_at_cursor(start
+ nick
+ add
)
2533 def on_list_treeview_motion_notify_event(self
, widget
, event
):
2534 model
= widget
.get_model()
2535 props
= widget
.get_path_at_pos(int(event
.x
), int(event
.y
))
2536 if self
.tooltip
.timeout
> 0:
2537 if not props
or self
.tooltip
.id != props
[0]:
2538 self
.tooltip
.hide_tooltip()
2540 [row
, col
, x
, y
] = props
2543 iter_
= model
.get_iter(row
)
2545 self
.tooltip
.hide_tooltip()
2547 typ
= model
[iter_
][C_TYPE
].decode('utf-8')
2548 if typ
== 'contact':
2549 account
= self
.account
2551 if self
.tooltip
.timeout
== 0 or self
.tooltip
.id != props
[0]:
2552 self
.tooltip
.id = row
2553 nick
= model
[iter_
][C_NICK
].decode('utf-8')
2554 self
.tooltip
.timeout
= gobject
.timeout_add(500,
2555 self
.show_tooltip
, gajim
.contacts
.get_gc_contact(
2556 account
, self
.room_jid
, nick
))
2558 def on_list_treeview_leave_notify_event(self
, widget
, event
):
2559 props
= widget
.get_path_at_pos(int(event
.x
), int(event
.y
))
2560 if self
.tooltip
.timeout
> 0:
2561 if not props
or self
.tooltip
.id == props
[0]:
2562 self
.tooltip
.hide_tooltip()
2564 def show_tooltip(self
, contact
):
2565 if not self
.list_treeview
.window
:
2566 # control has been destroyed since tooltip was requested
2568 pointer
= self
.list_treeview
.get_pointer()
2569 props
= self
.list_treeview
.get_path_at_pos(pointer
[0], pointer
[1])
2570 # check if the current pointer is at the same path
2571 # as it was before setting the timeout
2572 if props
and self
.tooltip
.id == props
[0]:
2573 rect
= self
.list_treeview
.get_cell_area(props
[0], props
[1])
2574 position
= self
.list_treeview
.window
.get_origin()
2575 self
.tooltip
.show_tooltip(contact
, rect
.height
,
2576 position
[1] + rect
.y
)
2578 self
.tooltip
.hide_tooltip()
2580 def grant_voice(self
, widget
, nick
):
2582 Grant voice privilege to a user
2584 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2587 def revoke_voice(self
, widget
, nick
):
2589 Revoke voice privilege to a user
2591 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2594 def grant_moderator(self
, widget
, nick
):
2596 Grant moderator privilege to a user
2598 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2601 def revoke_moderator(self
, widget
, nick
):
2603 Revoke moderator privilege to a user
2605 gajim
.connections
[self
.account
].gc_set_role(self
.room_jid
, nick
,
2608 def ban(self
, widget
, jid
):
2613 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
,
2614 jid
, 'outcast', reason
)
2616 # to ban we know the real jid. so jid is not fakejid
2617 nick
= gajim
.get_nick_from_jid(jid
)
2619 dialogs
.InputDialog(_('Banning %s') % nick
,
2620 _('You may specify a reason below:'), ok_handler
=on_ok
)
2622 def grant_membership(self
, widget
, jid
):
2624 Grant membership privilege to a user
2626 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2629 def revoke_membership(self
, widget
, jid
):
2631 Revoke membership privilege to a user
2633 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2636 def grant_admin(self
, widget
, jid
):
2638 Grant administrative privilege to a user
2640 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2643 def revoke_admin(self
, widget
, jid
):
2645 Revoke administrative privilege to a user
2647 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2650 def grant_owner(self
, widget
, jid
):
2652 Grant owner privilege to a user
2654 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2657 def revoke_owner(self
, widget
, jid
):
2659 Revoke owner privilege to a user
2661 gajim
.connections
[self
.account
].gc_set_affiliation(self
.room_jid
, jid
,
2664 def on_info(self
, widget
, nick
):
2666 Call vcard_information_window class to display user's information
2668 gc_contact
= gajim
.contacts
.get_gc_contact(self
.account
, self
.room_jid
,
2670 contact
= gc_contact
.as_contact()
2671 if contact
.jid
in gajim
.interface
.instances
[self
.account
]['infos']:
2672 gajim
.interface
.instances
[self
.account
]['infos'][contact
.jid
].\
2675 gajim
.interface
.instances
[self
.account
]['infos'][contact
.jid
] = \
2676 vcard
.VcardWindow(contact
, self
.account
, gc_contact
)
2678 def on_history(self
, widget
, nick
):
2679 jid
= gajim
.construct_fjid(self
.room_jid
, nick
)
2680 self
._on
_history
_menuitem
_activate
(widget
=widget
, jid
=jid
)
2682 def on_add_to_roster(self
, widget
, jid
):
2683 dialogs
.AddNewContactWindow(self
.account
, jid
)
2685 def on_block(self
, widget
, nick
):
2686 fjid
= self
.room_jid
+ '/' + nick
2687 connection
= gajim
.connections
[self
.account
]
2688 if fjid
in connection
.blocked_contacts
:
2690 new_rule
= {'order': u
'1', 'type': u
'jid', 'action': u
'deny',
2691 'value' : fjid
, 'child': [u
'message', u
'iq', u
'presence-out']}
2692 connection
.blocked_list
.append(new_rule
)
2693 connection
.blocked_contacts
.append(fjid
)
2694 self
.draw_contact(nick
)
2695 connection
.set_privacy_list('block', connection
.blocked_list
)
2696 if len(connection
.blocked_list
) == 1:
2697 connection
.set_active_list('block')
2698 connection
.set_default_list('block')
2699 connection
.get_privacy_list('block')
2701 def on_unblock(self
, widget
, nick
):
2702 fjid
= self
.room_jid
+ '/' + nick
2703 connection
= gajim
.connections
[self
.account
]
2704 connection
.new_blocked_list
= []
2705 # needed for draw_contact:
2706 if fjid
in connection
.blocked_contacts
:
2707 connection
.blocked_contacts
.remove(fjid
)
2708 self
.draw_contact(nick
)
2709 for rule
in connection
.blocked_list
:
2710 if rule
['action'] != 'deny' or rule
['type'] != 'jid' \
2711 or rule
['value'] != fjid
:
2712 connection
.new_blocked_list
.append(rule
)
2714 connection
.set_privacy_list('block', connection
.new_blocked_list
)
2715 connection
.get_privacy_list('block')
2716 if len(connection
.new_blocked_list
) == 0:
2717 connection
.blocked_list
= []
2718 connection
.blocked_contacts
= []
2719 connection
.blocked_groups
= []
2720 connection
.set_default_list('')
2721 connection
.set_active_list('')
2722 connection
.del_privacy_list('block')
2723 if 'privay_list_block' in gajim
.interface
.instances
[self
.account
]:
2724 del gajim
.interface
.instances
[self
.account
]\
2725 ['privay_list_block']
2727 def on_voice_checkmenuitem_activate(self
, widget
, nick
):
2728 if widget
.get_active():
2729 self
.grant_voice(widget
, nick
)
2731 self
.revoke_voice(widget
, nick
)
2733 def on_moderator_checkmenuitem_activate(self
, widget
, nick
):
2734 if widget
.get_active():
2735 self
.grant_moderator(widget
, nick
)
2737 self
.revoke_moderator(widget
, nick
)
2739 def on_member_checkmenuitem_activate(self
, widget
, jid
):
2740 if widget
.get_active():
2741 self
.grant_membership(widget
, jid
)
2743 self
.revoke_membership(widget
, jid
)
2745 def on_admin_checkmenuitem_activate(self
, widget
, jid
):
2746 if widget
.get_active():
2747 self
.grant_admin(widget
, jid
)
2749 self
.revoke_admin(widget
, jid
)
2751 def on_owner_checkmenuitem_activate(self
, widget
, jid
):
2752 if widget
.get_active():
2753 self
.grant_owner(widget
, jid
)
2755 self
.revoke_owner(widget
, jid
)