2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/groupchat_control.py
|
2005-12-31 08:35:14 +01:00
|
|
|
##
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Alex Mauer <hawke AT hawkesnest.net>
|
|
|
|
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
2008-08-22 05:15:54 +02:00
|
|
|
## Travis Shirk <travis AT pobox.com>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2007-2008 Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jonathan Schleifer <js-gajim AT webkeks.org>
|
2005-12-31 08:35:14 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-12-31 08:35:14 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-12-31 08:35:14 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-12-31 08:35:14 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-12-31 08:35:14 +01:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-12-31 08:35:14 +01:00
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
import os
|
2006-01-05 06:51:28 +01:00
|
|
|
import time
|
2009-11-24 15:41:16 +01:00
|
|
|
import locale
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
2013-01-03 14:26:12 +01:00
|
|
|
from gi.repository import Gdk
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import GdkPixbuf
|
|
|
|
from gi.repository import Pango
|
2013-07-28 20:50:30 +02:00
|
|
|
from gi.repository import GLib
|
2005-12-31 08:35:14 +01:00
|
|
|
import gtkgui_helpers
|
2011-03-18 10:09:06 +01:00
|
|
|
import gui_menu_builder
|
2006-01-02 03:12:34 +01:00
|
|
|
import message_control
|
2006-01-06 04:36:07 +01:00
|
|
|
import tooltips
|
|
|
|
import dialogs
|
2006-02-07 13:56:20 +01:00
|
|
|
import config
|
2006-01-06 04:36:07 +01:00
|
|
|
import vcard
|
|
|
|
import cell_renderer_image
|
2010-06-27 23:09:07 +02:00
|
|
|
import dataforms_widget
|
2013-12-02 12:17:32 +01:00
|
|
|
import nbxmpp
|
2006-01-06 04:36:07 +01:00
|
|
|
|
|
|
|
from common import gajim
|
|
|
|
from common import helpers
|
2010-06-27 23:09:07 +02:00
|
|
|
from common import dataforms
|
2010-09-28 15:13:51 +02:00
|
|
|
from common import ged
|
2013-07-23 15:55:24 +02:00
|
|
|
from common import i18n
|
2005-12-31 08:35:14 +01:00
|
|
|
|
2006-01-01 20:40:05 +01:00
|
|
|
from chat_control import ChatControl
|
2005-12-31 08:35:14 +01:00
|
|
|
from chat_control import ChatControlBase
|
2007-11-27 22:14:04 +01:00
|
|
|
from common.exceptions import GajimGeneralException
|
2006-01-03 08:34:18 +01:00
|
|
|
|
2009-10-02 22:57:11 +02:00
|
|
|
from command_system.implementation.hosts import PrivateChatCommands
|
|
|
|
from command_system.implementation.hosts import GroupChatCommands
|
2013-07-19 11:52:37 +02:00
|
|
|
from common.connection_handlers_events import GcMessageOutgoingEvent
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2009-08-26 21:57:54 +02:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.groupchat_control')
|
|
|
|
|
2006-01-03 08:34:18 +01:00
|
|
|
#(status_image, type, nick, shown_nick)
|
|
|
|
(
|
|
|
|
C_IMG, # image to show state (online, new message etc)
|
2006-10-07 14:41:19 +02:00
|
|
|
C_NICK, # contact nickame or ROLE name
|
|
|
|
C_TYPE, # type of the row ('contact' or 'role')
|
|
|
|
C_TEXT, # text shown in the cellrenderer
|
2006-03-13 14:25:51 +01:00
|
|
|
C_AVATAR, # avatar of the contact
|
|
|
|
) = range(5)
|
2008-05-02 04:32:28 +02:00
|
|
|
|
2013-01-07 09:45:47 +01:00
|
|
|
empty_pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 1, 1)
|
|
|
|
empty_pixbuf.fill(0xffffff00)
|
|
|
|
|
2009-01-28 13:12:13 +01:00
|
|
|
def set_renderer_color(treeview, renderer, set_background=True):
|
2010-04-08 01:20:17 +02:00
|
|
|
"""
|
|
|
|
Set style for group row, using PRELIGHT system color
|
|
|
|
"""
|
2013-01-05 15:53:14 +01:00
|
|
|
context = treeview.get_style_context()
|
2010-04-08 01:20:17 +02:00
|
|
|
if set_background:
|
2013-01-05 15:53:14 +01:00
|
|
|
bgcolor = context.get_background_color(Gtk.StateFlags.PRELIGHT)
|
|
|
|
renderer.set_property('cell-background-rgba', bgcolor)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2013-01-05 15:53:14 +01:00
|
|
|
fgcolor = context.get_color(Gtk.StateFlags.PRELIGHT)
|
|
|
|
renderer.set_property('foreground-rgba', fgcolor)
|
2006-04-17 23:59:04 +02:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def tree_cell_data_func(column, renderer, model, iter_, tv=None):
|
2010-04-08 01:20:17 +02:00
|
|
|
# cell data func is global, because we don't want it to keep
|
|
|
|
# reference to GroupchatControl instance (self)
|
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
# allocate space for avatar only if needed
|
|
|
|
parent_iter = model.iter_parent(iter_)
|
2012-12-23 16:23:43 +01:00
|
|
|
if isinstance(renderer, Gtk.CellRendererPixbuf):
|
2010-04-08 01:20:17 +02:00
|
|
|
avatar_position = gajim.config.get('avatar_position_in_roster')
|
|
|
|
if avatar_position == 'right':
|
|
|
|
renderer.set_property('xalign', 1) # align pixbuf to the right
|
|
|
|
else:
|
|
|
|
renderer.set_property('xalign', 0.5)
|
2010-05-20 09:17:56 +02:00
|
|
|
if parent_iter and (model[iter_][C_AVATAR] or avatar_position == \
|
|
|
|
'left'):
|
2010-04-08 01:20:17 +02:00
|
|
|
renderer.set_property('visible', True)
|
2010-05-20 09:17:56 +02:00
|
|
|
renderer.set_property('width', gajim.config.get(
|
|
|
|
'roster_avatar_width'))
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
renderer.set_property('visible', False)
|
|
|
|
if parent_iter:
|
|
|
|
bgcolor = gajim.config.get_per('themes', theme, 'contactbgcolor')
|
|
|
|
if bgcolor:
|
|
|
|
renderer.set_property('cell-background', bgcolor)
|
|
|
|
else:
|
|
|
|
renderer.set_property('cell-background', None)
|
2012-12-23 16:23:43 +01:00
|
|
|
if isinstance(renderer, Gtk.CellRendererText):
|
2010-04-08 01:20:17 +02:00
|
|
|
# foreground property is only with CellRendererText
|
|
|
|
color = gajim.config.get_per('themes', theme, 'contacttextcolor')
|
|
|
|
if color:
|
|
|
|
renderer.set_property('foreground', color)
|
|
|
|
else:
|
|
|
|
renderer.set_property('foreground', None)
|
|
|
|
renderer.set_property('font',
|
2010-05-20 09:17:56 +02:00
|
|
|
gtkgui_helpers.get_theme_font_for_option(theme, 'contactfont'))
|
2010-04-08 01:20:17 +02:00
|
|
|
else: # it is root (eg. group)
|
|
|
|
bgcolor = gajim.config.get_per('themes', theme, 'groupbgcolor')
|
|
|
|
if bgcolor:
|
|
|
|
renderer.set_property('cell-background', bgcolor)
|
|
|
|
else:
|
|
|
|
set_renderer_color(tv, renderer)
|
2012-12-23 16:23:43 +01:00
|
|
|
if isinstance(renderer, Gtk.CellRendererText):
|
2010-04-08 01:20:17 +02:00
|
|
|
# foreground property is only with CellRendererText
|
|
|
|
color = gajim.config.get_per('themes', theme, 'grouptextcolor')
|
|
|
|
if color:
|
|
|
|
renderer.set_property('foreground', color)
|
|
|
|
else:
|
|
|
|
set_renderer_color(tv, renderer, False)
|
|
|
|
renderer.set_property('font',
|
2010-05-20 09:17:56 +02:00
|
|
|
gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont'))
|
2005-12-31 08:35:14 +01:00
|
|
|
|
2009-12-28 20:14:15 +01:00
|
|
|
|
2006-01-01 20:40:05 +01:00
|
|
|
class PrivateChatControl(ChatControl):
|
2010-04-08 01:20:17 +02:00
|
|
|
TYPE_ID = message_control.TYPE_PM
|
|
|
|
|
|
|
|
# Set a command host to bound to. Every command given through a private chat
|
|
|
|
# will be processed with this command host.
|
|
|
|
COMMAND_HOST = PrivateChatCommands
|
|
|
|
|
|
|
|
def __init__(self, parent_win, gc_contact, contact, account, session):
|
|
|
|
room_jid = gc_contact.room_jid
|
2011-09-22 11:43:51 +02:00
|
|
|
self.room_ctrl = gajim.interface.msg_win_mgr.get_gc_control(room_jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
account)
|
2010-04-08 01:20:17 +02:00
|
|
|
if room_jid in gajim.interface.minimized_controls[account]:
|
2011-09-22 11:43:51 +02:00
|
|
|
self.room_ctrl = gajim.interface.minimized_controls[account][room_jid]
|
|
|
|
if self.room_ctrl:
|
|
|
|
self.room_name = self.room_ctrl.name
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
self.room_name = room_jid
|
|
|
|
self.gc_contact = gc_contact
|
|
|
|
ChatControl.__init__(self, parent_win, contact, account, session)
|
|
|
|
self.TYPE_ID = 'pm'
|
2010-11-23 23:10:43 +01:00
|
|
|
gajim.ged.register_event_handler('caps-received', ged.GUI1,
|
2010-12-23 17:51:26 +01:00
|
|
|
self._nec_caps_received_pm)
|
2010-11-23 23:10:43 +01:00
|
|
|
gajim.ged.register_event_handler('gc-presence-received', ged.GUI1,
|
|
|
|
self._nec_gc_presence_received)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2011-09-22 11:43:51 +02:00
|
|
|
def get_our_nick(self):
|
|
|
|
return self.room_ctrl.nick
|
|
|
|
|
2010-11-17 17:27:36 +01:00
|
|
|
def shutdown(self):
|
2010-11-22 08:52:58 +01:00
|
|
|
super(PrivateChatControl, self).shutdown()
|
2010-11-17 17:27:36 +01:00
|
|
|
gajim.ged.remove_event_handler('caps-received', ged.GUI1,
|
2010-12-23 17:51:26 +01:00
|
|
|
self._nec_caps_received_pm)
|
2010-11-23 23:10:43 +01:00
|
|
|
gajim.ged.remove_event_handler('gc-presence-received', ged.GUI1,
|
|
|
|
self._nec_gc_presence_received)
|
2010-11-17 17:27:36 +01:00
|
|
|
|
2010-12-23 17:51:26 +01:00
|
|
|
def _nec_caps_received_pm(self, obj):
|
2010-11-17 17:27:36 +01:00
|
|
|
if obj.conn.name != self.account or \
|
|
|
|
obj.fjid != self.gc_contact.get_full_jid():
|
|
|
|
return
|
|
|
|
self.update_contact()
|
|
|
|
|
2010-11-23 23:10:43 +01:00
|
|
|
def _nec_gc_presence_received(self, obj):
|
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
if obj.fjid != self.full_jid:
|
|
|
|
return
|
|
|
|
if '303' in obj.status_code:
|
|
|
|
self.print_conversation(_('%(nick)s is now known as '
|
|
|
|
'%(new_nick)s') % {'nick': obj.nick, 'new_nick': obj.new_nick},
|
|
|
|
'status')
|
|
|
|
gc_c = gajim.contacts.get_gc_contact(obj.conn.name, obj.room_jid,
|
|
|
|
obj.new_nick)
|
|
|
|
c = gc_c.as_contact()
|
|
|
|
self.gc_contact = gc_c
|
|
|
|
self.contact = c
|
|
|
|
if self.session:
|
|
|
|
# stop e2e
|
|
|
|
if self.session.enable_encryption:
|
|
|
|
thread_id = self.session.thread_id
|
|
|
|
self.session.terminate_e2e()
|
|
|
|
obj.conn.delete_session(obj.fjid, thread_id)
|
|
|
|
self.no_autonegotiation = False
|
|
|
|
self.draw_banner()
|
|
|
|
old_jid = obj.room_jid + '/' + obj.nick
|
|
|
|
new_jid = obj.room_jid + '/' + obj.new_nick
|
|
|
|
gajim.interface.msg_win_mgr.change_key(old_jid, new_jid,
|
|
|
|
obj.conn.name)
|
|
|
|
else:
|
|
|
|
self.contact.show = obj.show
|
|
|
|
self.contact.status = obj.status
|
|
|
|
self.gc_contact.show = obj.show
|
|
|
|
self.gc_contact.status = obj.status
|
|
|
|
uf_show = helpers.get_uf_show(obj.show)
|
|
|
|
self.print_conversation(_('%(nick)s is now %(status)s') % {
|
|
|
|
'nick': obj.nick, 'status': uf_show}, 'status')
|
|
|
|
if obj.status:
|
|
|
|
self.print_conversation(' (', 'status', simple=True)
|
|
|
|
self.print_conversation('%s' % (obj.status), 'status',
|
|
|
|
simple=True)
|
|
|
|
self.print_conversation(')', 'status', simple=True)
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
self.update_ui()
|
|
|
|
|
2012-04-09 13:38:28 +02:00
|
|
|
def send_message(self, message, xhtml=None, process_commands=True,
|
|
|
|
attention=False):
|
2010-04-08 01:20:17 +02:00
|
|
|
"""
|
|
|
|
Call this method to send the message
|
|
|
|
"""
|
|
|
|
message = helpers.remove_invalid_xml_chars(message)
|
|
|
|
if not message:
|
|
|
|
return
|
|
|
|
|
|
|
|
# We need to make sure that we can still send through the room and that
|
|
|
|
# the recipient did not go away
|
|
|
|
contact = gajim.contacts.get_first_contact_from_jid(self.account,
|
|
|
|
self.contact.jid)
|
|
|
|
if not contact:
|
|
|
|
# contact was from pm in MUC
|
|
|
|
room, nick = gajim.get_room_and_nick_from_fjid(self.contact.jid)
|
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, room, nick)
|
|
|
|
if not gc_contact:
|
|
|
|
dialogs.ErrorDialog(
|
2010-05-20 09:17:56 +02:00
|
|
|
_('Sending private message failed'),
|
|
|
|
#in second %s code replaces with nickname
|
|
|
|
_('You are no longer in group chat "%(room)s" or '
|
2013-08-11 14:44:46 +02:00
|
|
|
'"%(nick)s" has left.') % {'room': '\u200E' + room,
|
2013-11-16 19:23:13 +01:00
|
|
|
'nick': nick}, transient_for=self.parent_win.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
ChatControl.send_message(self, message, xhtml=xhtml,
|
2012-04-09 13:38:28 +02:00
|
|
|
process_commands=process_commands, attention=attention)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def update_ui(self):
|
|
|
|
if self.contact.show == 'offline':
|
|
|
|
self.got_disconnected()
|
|
|
|
else:
|
|
|
|
self.got_connected()
|
|
|
|
ChatControl.update_ui(self)
|
|
|
|
|
|
|
|
def update_contact(self):
|
|
|
|
self.contact = self.gc_contact.as_contact()
|
|
|
|
|
|
|
|
def begin_e2e_negotiation(self):
|
|
|
|
self.no_autonegotiation = True
|
|
|
|
|
|
|
|
if not self.session:
|
|
|
|
fjid = self.gc_contact.get_full_jid()
|
2010-05-20 09:17:56 +02:00
|
|
|
new_sess = gajim.connections[self.account].make_new_session(fjid,
|
|
|
|
type_=self.type_id)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.set_session(new_sess)
|
|
|
|
|
|
|
|
self.session.negotiate_e2e(False)
|
2006-01-09 00:14:50 +01:00
|
|
|
|
2011-03-18 10:09:06 +01:00
|
|
|
def prepare_context_menu(self, hide_buttonbar_items=False):
|
|
|
|
"""
|
|
|
|
Set compact view menuitem active state sets active and sensitivity state
|
|
|
|
for toggle_gpg_menuitem sets sensitivity for history_menuitem (False for
|
|
|
|
tranasports) and file_transfer_menuitem and hide()/show() for
|
|
|
|
add_to_roster_menuitem
|
|
|
|
"""
|
|
|
|
menu = gui_menu_builder.get_contact_menu(self.contact, self.account,
|
|
|
|
use_multiple_contacts=False, show_start_chat=False,
|
|
|
|
show_encryption=True, control=self,
|
|
|
|
show_buttonbar_items=not hide_buttonbar_items,
|
2012-04-16 23:03:30 +02:00
|
|
|
gc_contact=self.gc_contact,
|
|
|
|
is_anonymous=self.room_ctrl.is_anonymous)
|
2011-03-18 10:09:06 +01:00
|
|
|
return menu
|
|
|
|
|
2013-07-27 17:10:08 +02:00
|
|
|
def got_disconnected(self):
|
|
|
|
ChatControl.got_disconnected(self)
|
|
|
|
|
2005-12-31 08:35:14 +01:00
|
|
|
class GroupchatControl(ChatControlBase):
|
2010-04-08 01:20:17 +02:00
|
|
|
TYPE_ID = message_control.TYPE_GC
|
|
|
|
|
|
|
|
# Set a command host to bound to. Every command given through a group chat
|
|
|
|
# will be processed with this command host.
|
|
|
|
COMMAND_HOST = GroupChatCommands
|
|
|
|
|
|
|
|
def __init__(self, parent_win, contact, acct, is_continued=False):
|
|
|
|
ChatControlBase.__init__(self, self.TYPE_ID, parent_win,
|
2010-05-20 09:17:56 +02:00
|
|
|
'groupchat_control', contact, acct)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2010-05-20 09:17:56 +02:00
|
|
|
self.is_continued = is_continued
|
2010-04-08 01:20:17 +02:00
|
|
|
self.is_anonymous = True
|
|
|
|
|
|
|
|
# Controls the state of autorejoin.
|
|
|
|
# None - autorejoin is neutral.
|
|
|
|
# False - autorejoin is to be prevented (gets reset to initial state in
|
|
|
|
# got_connected()).
|
|
|
|
# int - autorejoin is being active and working (gets reset to initial
|
|
|
|
# state in got_connected()).
|
|
|
|
self.autorejoin = None
|
|
|
|
|
2010-05-20 18:45:09 +02:00
|
|
|
# Keep error dialog instance to be sure to have only once at a time
|
|
|
|
self.error_dialog = None
|
2013-07-27 17:10:08 +02:00
|
|
|
send_button = self.xml.get_object('send_button')
|
|
|
|
send_button.set_sensitive(False)
|
2010-05-20 18:45:09 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
self.actions_button = self.xml.get_object('muc_window_actions_button')
|
|
|
|
id_ = self.actions_button.connect('clicked',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_actions_button_clicked)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = self.actions_button
|
|
|
|
|
|
|
|
widget = self.xml.get_object('change_nick_button')
|
2013-07-27 17:10:08 +02:00
|
|
|
widget.set_sensitive(False)
|
2010-04-08 01:20:17 +02:00
|
|
|
id_ = widget.connect('clicked', self._on_change_nick_menuitem_activate)
|
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
widget = self.xml.get_object('change_subject_button')
|
2013-07-27 17:10:08 +02:00
|
|
|
widget.set_sensitive(False)
|
2010-05-20 09:17:56 +02:00
|
|
|
id_ = widget.connect('clicked',
|
|
|
|
self._on_change_subject_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
2013-07-27 17:10:08 +02:00
|
|
|
formattings_button = self.xml.get_object('formattings_button')
|
|
|
|
formattings_button.set_sensitive(False)
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
widget = self.xml.get_object('bookmark_button')
|
|
|
|
for bm in gajim.connections[self.account].bookmarks:
|
|
|
|
if bm['jid'] == self.contact.jid:
|
|
|
|
widget.hide()
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
id_ = widget.connect('clicked',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_bookmark_room_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
2011-05-25 20:59:18 +02:00
|
|
|
|
2011-05-25 21:45:51 +02:00
|
|
|
if gtkgui_helpers.gtk_icon_theme.has_icon('bookmark-new'):
|
2011-05-25 20:59:18 +02:00
|
|
|
img = self.xml.get_object('image7')
|
2012-12-23 16:23:43 +01:00
|
|
|
img.set_from_icon_name('bookmark-new', Gtk.IconSize.MENU)
|
2012-11-20 10:00:57 +01:00
|
|
|
widget.set_sensitive(
|
|
|
|
gajim.connections[self.account].private_storage_supported or \
|
|
|
|
(gajim.connections[self.account].pubsub_supported and \
|
|
|
|
gajim.connections[self.account].pubsub_publish_options_supported))
|
|
|
|
widget.show()
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2013-03-16 20:56:22 +01:00
|
|
|
if gtkgui_helpers.gtk_icon_theme.has_icon('document-open-recent'):
|
2013-03-17 19:33:51 +01:00
|
|
|
img = self.xml.get_object('history_image')
|
|
|
|
img.set_from_icon_name('document-open-recent', Gtk.IconSize.MENU)
|
2010-04-08 01:20:17 +02:00
|
|
|
widget = self.xml.get_object('list_treeview')
|
|
|
|
id_ = widget.connect('row_expanded', self.on_list_treeview_row_expanded)
|
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
2010-05-20 09:17:56 +02:00
|
|
|
id_ = widget.connect('row_collapsed',
|
|
|
|
self.on_list_treeview_row_collapsed)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
id_ = widget.connect('row_activated',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_row_activated)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
id_ = widget.connect('button_press_event',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_button_press_event)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
id_ = widget.connect('key_press_event',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_key_press_event)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
id_ = widget.connect('motion_notify_event',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_motion_notify_event)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
id_ = widget.connect('leave_notify_event',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_leave_notify_event)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
|
|
|
|
self.room_jid = self.contact.jid
|
2013-01-01 19:44:25 +01:00
|
|
|
self.nick = contact.name
|
2010-04-08 01:20:17 +02:00
|
|
|
self.new_nick = ''
|
|
|
|
self.name = ''
|
|
|
|
for bm in gajim.connections[self.account].bookmarks:
|
|
|
|
if bm['jid'] == self.room_jid:
|
|
|
|
self.name = bm['name']
|
|
|
|
break
|
|
|
|
if not self.name:
|
|
|
|
self.name = self.room_jid.split('@')[0]
|
|
|
|
|
|
|
|
compact_view = gajim.config.get('compact_view')
|
|
|
|
self.chat_buttons_set_visible(compact_view)
|
|
|
|
self.widget_set_visible(self.xml.get_object('banner_eventbox'),
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.config.get('hide_groupchat_banner'))
|
2010-04-08 01:20:17 +02:00
|
|
|
self.widget_set_visible(self.xml.get_object('list_scrolledwindow'),
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.config.get('hide_groupchat_occupants_list'))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
self._last_selected_contact = None # None or holds jid, account tuple
|
|
|
|
|
|
|
|
# muc attention flag (when we are mentioned in a muc)
|
|
|
|
# if True, the room has mentioned us
|
|
|
|
self.attention_flag = False
|
|
|
|
|
|
|
|
# sorted list of nicks who mentioned us (last at the end)
|
|
|
|
self.attention_list = []
|
|
|
|
self.room_creation = int(time.time()) # Use int to reduce mem usage
|
|
|
|
self.nick_hits = []
|
|
|
|
self.last_key_tabs = False
|
|
|
|
|
|
|
|
self.subject = ''
|
|
|
|
|
|
|
|
self.tooltip = tooltips.GCTooltip()
|
|
|
|
|
|
|
|
# nickname coloring
|
2011-11-15 12:09:39 +01:00
|
|
|
self.gc_count_nicknames_colors = -1
|
2010-04-08 01:20:17 +02:00
|
|
|
self.gc_custom_colors = {}
|
|
|
|
self.number_of_colors = len(gajim.config.get('gc_nicknames_colors').\
|
2010-05-20 09:17:56 +02:00
|
|
|
split(':'))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
self.name_label = self.xml.get_object('banner_name_label')
|
|
|
|
self.event_box = self.xml.get_object('banner_eventbox')
|
|
|
|
|
|
|
|
self.list_treeview = self.xml.get_object('list_treeview')
|
|
|
|
selection = self.list_treeview.get_selection()
|
|
|
|
id_ = selection.connect('changed',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_selection_changed)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = selection
|
|
|
|
id_ = self.list_treeview.connect('style-set',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_list_treeview_style_set)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = self.list_treeview
|
2011-03-03 17:18:38 +01:00
|
|
|
self.resize_from_another_muc = False
|
2010-04-08 01:20:17 +02:00
|
|
|
# we want to know when the the widget resizes, because that is
|
|
|
|
# an indication that the hpaned has moved...
|
2011-02-08 17:04:18 +01:00
|
|
|
self.hpaned = self.xml.get_object('hpaned')
|
|
|
|
id_ = self.hpaned.connect('notify', self.on_hpaned_notify)
|
|
|
|
self.handlers[id_] = self.hpaned
|
|
|
|
|
|
|
|
# set the position of the current hpaned
|
|
|
|
hpaned_position = gajim.config.get('gc-hpaned-position')
|
|
|
|
self.hpaned.set_position(hpaned_position)
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
#status_image, shown_nick, type, nickname, avatar
|
2012-12-23 16:23:43 +01:00
|
|
|
self.columns = [Gtk.Image, str, str, str, GdkPixbuf.Pixbuf]
|
|
|
|
self.model = Gtk.TreeStore(*self.columns)
|
2011-08-24 11:58:06 +02:00
|
|
|
self.model.set_sort_func(C_NICK, self.tree_compare_iters)
|
2012-12-23 16:23:43 +01:00
|
|
|
self.model.set_sort_column_id(C_NICK, Gtk.SortType.ASCENDING)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# columns
|
2012-12-23 16:23:43 +01:00
|
|
|
column = Gtk.TreeViewColumn()
|
2010-10-12 21:50:18 +02:00
|
|
|
# list of renderers with attributes / properties in the form:
|
|
|
|
# (name, renderer_object, expand?, attribute_name, attribute_value,
|
|
|
|
# cell_data_func, func_arg)
|
|
|
|
self.renderers_list = []
|
|
|
|
# Number of renderers plugins added
|
|
|
|
self.nb_ext_renderers = 0
|
|
|
|
self.renderers_propertys = {}
|
2010-05-20 09:17:56 +02:00
|
|
|
renderer_image = cell_renderer_image.CellRendererImage(0, 0)
|
2010-10-12 21:50:18 +02:00
|
|
|
self.renderers_propertys[renderer_image] = ('width', 26)
|
2012-12-23 16:23:43 +01:00
|
|
|
renderer_text = Gtk.CellRendererText()
|
2010-10-12 21:50:18 +02:00
|
|
|
self.renderers_propertys[renderer_text] = ('ellipsize',
|
2012-12-23 16:23:43 +01:00
|
|
|
Pango.EllipsizeMode.END)
|
2010-10-12 21:50:18 +02:00
|
|
|
|
|
|
|
self.renderers_list += (
|
|
|
|
# status img
|
|
|
|
('icon', renderer_image, False,
|
|
|
|
'image', C_IMG, tree_cell_data_func, self.list_treeview),
|
|
|
|
# contact name
|
|
|
|
('name', renderer_text, True,
|
|
|
|
'markup', C_TEXT, tree_cell_data_func, self.list_treeview))
|
|
|
|
|
|
|
|
# avatar img
|
2012-12-23 16:23:43 +01:00
|
|
|
avater_renderer = ('avatar', Gtk.CellRendererPixbuf(),
|
2010-10-12 21:50:18 +02:00
|
|
|
False, 'pixbuf', C_AVATAR,
|
|
|
|
tree_cell_data_func, self.list_treeview)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
if gajim.config.get('avatar_position_in_roster') == 'right':
|
2010-10-12 21:50:18 +02:00
|
|
|
self.renderers_list.append(avater_renderer)
|
|
|
|
else:
|
|
|
|
self.renderers_list.insert(0, avater_renderer)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2010-10-12 21:50:18 +02:00
|
|
|
self.fill_column(column)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.list_treeview.append_column(column)
|
|
|
|
|
|
|
|
# workaround to avoid gtk arrows to be shown
|
2012-12-23 16:23:43 +01:00
|
|
|
column = Gtk.TreeViewColumn() # 2nd COLUMN
|
|
|
|
renderer = Gtk.CellRendererPixbuf()
|
2013-01-02 10:32:17 +01:00
|
|
|
column.pack_start(renderer, False)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.list_treeview.append_column(column)
|
|
|
|
column.set_visible(False)
|
|
|
|
self.list_treeview.set_expander_column(column)
|
|
|
|
|
2010-06-07 19:11:44 +02:00
|
|
|
self.setup_seclabel(self.xml.get_object('label_selector'))
|
2010-09-28 15:13:51 +02:00
|
|
|
|
2010-08-09 14:51:42 +02:00
|
|
|
self.form_widget = None
|
2010-06-07 19:11:44 +02:00
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
gajim.ged.register_event_handler('gc-presence-received', ged.GUI1,
|
|
|
|
self._nec_gc_presence_received)
|
2010-10-18 22:05:41 +02:00
|
|
|
gajim.ged.register_event_handler('gc-message-received', ged.GUI1,
|
|
|
|
self._nec_gc_message_received)
|
2010-11-08 22:34:04 +01:00
|
|
|
gajim.ged.register_event_handler('vcard-published', ged.GUI1,
|
|
|
|
self._nec_vcard_published)
|
2010-11-26 21:14:59 +01:00
|
|
|
gajim.ged.register_event_handler('vcard-received', ged.GUI1,
|
|
|
|
self._nec_vcard_received)
|
2010-11-27 19:12:43 +01:00
|
|
|
gajim.ged.register_event_handler('gc-subject-received', ged.GUI1,
|
|
|
|
self._nec_gc_subject_received)
|
2010-11-27 21:02:41 +01:00
|
|
|
gajim.ged.register_event_handler('gc-config-changed-received', ged.GUI1,
|
|
|
|
self._nec_gc_config_changed_received)
|
2010-11-29 11:11:24 +01:00
|
|
|
gajim.ged.register_event_handler('signed-in', ged.GUI1,
|
|
|
|
self._nec_signed_in)
|
2011-05-01 22:09:50 +02:00
|
|
|
gajim.ged.register_event_handler('decrypted-message-received', ged.GUI2,
|
|
|
|
self._nec_decrypted_message_received)
|
2010-04-08 01:20:17 +02:00
|
|
|
gajim.gc_connected[self.account][self.room_jid] = False
|
|
|
|
# disable win, we are not connected yet
|
|
|
|
ChatControlBase.got_disconnected(self)
|
|
|
|
|
|
|
|
self.update_ui()
|
|
|
|
self.widget.show_all()
|
|
|
|
|
2010-10-12 17:09:53 +02:00
|
|
|
# PluginSystem: adding GUI extension point for this GroupchatControl
|
|
|
|
# instance object
|
|
|
|
gajim.plugin_manager.gui_extension_point('groupchat_control', self)
|
|
|
|
|
2010-10-12 21:50:18 +02:00
|
|
|
def fill_column(self, col):
|
|
|
|
for rend in self.renderers_list:
|
2013-01-02 10:32:17 +01:00
|
|
|
col.pack_start(rend[1], rend[2])
|
2010-10-12 21:50:18 +02:00
|
|
|
col.add_attribute(rend[1], rend[3], rend[4])
|
|
|
|
col.set_cell_data_func(rend[1], rend[5], rend[6])
|
|
|
|
# set renderers propertys
|
|
|
|
for renderer in self.renderers_propertys.keys():
|
|
|
|
renderer.set_property(self.renderers_propertys[renderer][0],
|
|
|
|
self.renderers_propertys[renderer][1])
|
|
|
|
|
2013-01-05 15:32:53 +01:00
|
|
|
def tree_compare_iters(self, model, iter1, iter2, data=None):
|
2010-04-08 01:20:17 +02:00
|
|
|
"""
|
|
|
|
Compare two iters to sort them
|
|
|
|
"""
|
|
|
|
type1 = model[iter1][C_TYPE]
|
|
|
|
type2 = model[iter2][C_TYPE]
|
|
|
|
if not type1 or not type2:
|
|
|
|
return 0
|
|
|
|
nick1 = model[iter1][C_NICK]
|
|
|
|
nick2 = model[iter2][C_NICK]
|
|
|
|
if not nick1 or not nick2:
|
|
|
|
return 0
|
|
|
|
if type1 == 'role':
|
|
|
|
return locale.strcoll(nick1, nick2)
|
|
|
|
if type1 == 'contact':
|
|
|
|
gc_contact1 = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, nick1)
|
|
|
|
if not gc_contact1:
|
|
|
|
return 0
|
|
|
|
if type2 == 'contact':
|
|
|
|
gc_contact2 = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, nick2)
|
|
|
|
if not gc_contact2:
|
|
|
|
return 0
|
|
|
|
if type1 == 'contact' and type2 == 'contact' and \
|
|
|
|
gajim.config.get('sort_by_show_in_muc'):
|
|
|
|
cshow = {'chat':0, 'online': 1, 'away': 2, 'xa': 3, 'dnd': 4,
|
2010-05-20 09:17:56 +02:00
|
|
|
'invisible': 5, 'offline': 6, 'error': 7}
|
2010-04-08 01:20:17 +02:00
|
|
|
show1 = cshow[gc_contact1.show]
|
|
|
|
show2 = cshow[gc_contact2.show]
|
|
|
|
if show1 < show2:
|
|
|
|
return -1
|
|
|
|
elif show1 > show2:
|
|
|
|
return 1
|
|
|
|
# We compare names
|
|
|
|
name1 = gc_contact1.get_shown_name()
|
|
|
|
name2 = gc_contact2.get_shown_name()
|
|
|
|
return locale.strcoll(name1.lower(), name2.lower())
|
|
|
|
|
|
|
|
def on_msg_textview_populate_popup(self, textview, menu):
|
|
|
|
"""
|
|
|
|
Override the default context menu and we prepend Clear
|
|
|
|
and the ability to insert a nick
|
|
|
|
"""
|
|
|
|
ChatControlBase.on_msg_textview_populate_popup(self, textview, menu)
|
2013-01-01 16:46:04 +01:00
|
|
|
item = Gtk.SeparatorMenuItem.new()
|
2010-04-08 01:20:17 +02:00
|
|
|
menu.prepend(item)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
item = Gtk.MenuItem(_('Insert Nickname'))
|
2010-04-08 01:20:17 +02:00
|
|
|
menu.prepend(item)
|
2012-12-23 16:23:43 +01:00
|
|
|
submenu = Gtk.Menu()
|
2010-04-08 01:20:17 +02:00
|
|
|
item.set_submenu(submenu)
|
|
|
|
|
|
|
|
for nick in sorted(gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid)):
|
2012-12-23 16:23:43 +01:00
|
|
|
item = Gtk.MenuItem(nick, use_underline=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
submenu.append(item)
|
2010-05-20 09:17:56 +02:00
|
|
|
id_ = item.connect('activate', self.append_nick_in_msg_textview,
|
|
|
|
nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
menu.show_all()
|
|
|
|
|
2011-03-03 17:18:38 +01:00
|
|
|
def resize_occupant_treeview(self, position):
|
|
|
|
self.resize_from_another_muc = True
|
|
|
|
self.hpaned.set_position(position)
|
|
|
|
def reset_flag():
|
|
|
|
self.resize_from_another_muc = False
|
|
|
|
# Reset the flag when everything will be redrawn, and in particular when
|
|
|
|
# on_treeview_size_allocate will have been called.
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.idle_add(reset_flag)
|
2011-03-03 17:18:38 +01:00
|
|
|
|
2011-02-08 17:04:18 +01:00
|
|
|
def on_hpaned_notify(self, pane, gparamspec):
|
2010-04-08 01:20:17 +02:00
|
|
|
"""
|
|
|
|
The MUC treeview has resized. Move the hpaned in all tabs to match
|
|
|
|
"""
|
2013-01-02 10:32:17 +01:00
|
|
|
# print pane, dir(pane)
|
|
|
|
#if gparamspec.name != 'position':
|
|
|
|
#return
|
2011-03-03 17:18:38 +01:00
|
|
|
if self.resize_from_another_muc:
|
2010-04-08 01:20:17 +02:00
|
|
|
# Don't send the event to other MUC
|
|
|
|
return
|
2011-02-08 17:04:18 +01:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
hpaned_position = self.hpaned.get_position()
|
2011-02-08 17:04:18 +01:00
|
|
|
gajim.config.set('gc-hpaned-position', hpaned_position)
|
2010-04-08 01:20:17 +02:00
|
|
|
for account in gajim.gc_connected:
|
|
|
|
for room_jid in [i for i in gajim.gc_connected[account] if \
|
|
|
|
gajim.gc_connected[account][i] and i != self.room_jid]:
|
2010-04-25 19:35:22 +02:00
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_gc_control(room_jid,
|
|
|
|
account)
|
|
|
|
if not ctrl and room_jid in \
|
|
|
|
gajim.interface.minimized_controls[account]:
|
2010-04-08 01:20:17 +02:00
|
|
|
ctrl = gajim.interface.minimized_controls[account][room_jid]
|
2010-12-10 08:54:15 +01:00
|
|
|
if ctrl and gajim.config.get('one_message_window') != 'never':
|
2011-03-03 17:18:38 +01:00
|
|
|
ctrl.resize_occupant_treeview(hpaned_position)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def iter_contact_rows(self):
|
|
|
|
"""
|
|
|
|
Iterate over all contact rows in the tree model
|
|
|
|
"""
|
2012-12-23 16:23:43 +01:00
|
|
|
role_iter = self.model.get_iter_first()
|
2010-04-08 01:20:17 +02:00
|
|
|
while role_iter:
|
2011-08-24 11:58:06 +02:00
|
|
|
contact_iter = self.model.iter_children(role_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
while contact_iter:
|
2011-08-24 11:58:06 +02:00
|
|
|
yield self.model[contact_iter]
|
|
|
|
contact_iter = self.model.iter_next(contact_iter)
|
|
|
|
role_iter = self.model.iter_next(role_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_list_treeview_style_set(self, treeview, style):
|
|
|
|
"""
|
|
|
|
When style (theme) changes, redraw all contacts
|
|
|
|
"""
|
|
|
|
# Get the room_jid from treeview
|
|
|
|
for contact in self.iter_contact_rows():
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = contact[C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
self.draw_contact(nick)
|
|
|
|
|
|
|
|
def on_list_treeview_selection_changed(self, selection):
|
|
|
|
model, selected_iter = selection.get_selected()
|
|
|
|
self.draw_contact(self.nick)
|
|
|
|
if self._last_selected_contact is not None:
|
|
|
|
self.draw_contact(self._last_selected_contact)
|
|
|
|
if selected_iter is None:
|
|
|
|
self._last_selected_contact = None
|
|
|
|
return
|
|
|
|
contact = model[selected_iter]
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = contact[C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
self._last_selected_contact = nick
|
|
|
|
if contact[C_TYPE] != 'contact':
|
|
|
|
return
|
|
|
|
self.draw_contact(nick, selected=True, focus=True)
|
|
|
|
|
|
|
|
def get_tab_label(self, chatstate):
|
|
|
|
"""
|
|
|
|
Markup the label if necessary. Returns a tuple such as: (new_label_str,
|
|
|
|
color) either of which can be None if chatstate is given that means we
|
|
|
|
have HE SENT US a chatstate
|
|
|
|
"""
|
|
|
|
|
|
|
|
has_focus = self.parent_win.window.get_property('has-toplevel-focus')
|
|
|
|
current_tab = self.parent_win.get_active_control() == self
|
|
|
|
color_name = None
|
|
|
|
color = None
|
|
|
|
theme = gajim.config.get('roster_theme')
|
2013-01-05 15:53:14 +01:00
|
|
|
context = self.parent_win.notebook.get_style_context()
|
2010-04-08 01:20:17 +02:00
|
|
|
if chatstate == 'attention' and (not has_focus or not current_tab):
|
|
|
|
self.attention_flag = True
|
|
|
|
color_name = gajim.config.get_per('themes', theme,
|
2013-01-05 15:53:14 +01:00
|
|
|
'state_muc_directed_msg_color')
|
2010-04-08 01:20:17 +02:00
|
|
|
elif chatstate:
|
|
|
|
if chatstate == 'active' or (current_tab and has_focus):
|
|
|
|
self.attention_flag = False
|
|
|
|
# get active color from gtk
|
2013-01-05 15:53:14 +01:00
|
|
|
color = context.get_color(Gtk.StateFlags.ACTIVE)
|
2010-05-20 09:17:56 +02:00
|
|
|
elif chatstate == 'newmsg' and (not has_focus or not current_tab) \
|
|
|
|
and not self.attention_flag:
|
2010-04-08 01:20:17 +02:00
|
|
|
color_name = gajim.config.get_per('themes', theme,
|
2013-01-05 15:53:14 +01:00
|
|
|
'state_muc_msg_color')
|
2010-04-08 01:20:17 +02:00
|
|
|
if color_name:
|
2013-01-05 15:53:14 +01:00
|
|
|
color = Gdk.RGBA()
|
|
|
|
ok = Gdk.RGBA.parse(color, color_name)
|
|
|
|
if not ok:
|
|
|
|
del color
|
|
|
|
color = context.get_color(Gtk.StateFlags.ACTIVE)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
if self.is_continued:
|
|
|
|
# if this is a continued conversation
|
|
|
|
label_str = self.get_continued_conversation_name()
|
|
|
|
else:
|
|
|
|
label_str = self.name
|
|
|
|
|
|
|
|
# count waiting highlighted messages
|
|
|
|
unread = ''
|
|
|
|
num_unread = self.get_nb_unread()
|
|
|
|
if num_unread == 1:
|
|
|
|
unread = '*'
|
|
|
|
elif num_unread > 1:
|
2013-01-01 21:06:16 +01:00
|
|
|
unread = '[' + str(num_unread) + ']'
|
2010-04-08 01:20:17 +02:00
|
|
|
label_str = unread + label_str
|
|
|
|
return (label_str, color)
|
|
|
|
|
|
|
|
def get_tab_image(self, count_unread=True):
|
|
|
|
# Set tab image (always 16x16)
|
|
|
|
tab_image = None
|
|
|
|
if gajim.gc_connected[self.account][self.room_jid]:
|
|
|
|
tab_image = gtkgui_helpers.load_icon('muc_active')
|
|
|
|
else:
|
|
|
|
tab_image = gtkgui_helpers.load_icon('muc_inactive')
|
|
|
|
return tab_image
|
|
|
|
|
|
|
|
def update_ui(self):
|
|
|
|
ChatControlBase.update_ui(self)
|
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
|
|
|
self.draw_contact(nick)
|
|
|
|
|
2013-03-23 20:34:34 +01:00
|
|
|
def _change_style(self, model, path, iter_, option):
|
2010-04-08 01:20:17 +02:00
|
|
|
model[iter_][C_NICK] = model[iter_][C_NICK]
|
|
|
|
|
|
|
|
def change_roster_style(self):
|
2013-01-03 14:26:12 +01:00
|
|
|
self.model.foreach(self._change_style, None)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def repaint_themed_widgets(self):
|
|
|
|
ChatControlBase.repaint_themed_widgets(self)
|
|
|
|
self.change_roster_style()
|
|
|
|
|
|
|
|
def _update_banner_state_image(self):
|
2010-02-08 15:08:40 +01:00
|
|
|
banner_status_img = self.xml.get_object('gc_banner_status_image')
|
2010-04-08 01:20:17 +02:00
|
|
|
images = gajim.interface.jabber_state_images
|
|
|
|
if self.room_jid in gajim.gc_connected[self.account] and \
|
|
|
|
gajim.gc_connected[self.account][self.room_jid]:
|
|
|
|
image = 'muc_active'
|
|
|
|
else:
|
|
|
|
image = 'muc_inactive'
|
|
|
|
if '32' in images and image in images['32']:
|
|
|
|
muc_icon = images['32'][image]
|
2012-12-23 16:23:43 +01:00
|
|
|
if muc_icon.get_storage_type() != Gtk.ImageType.EMPTY:
|
2010-04-08 01:20:17 +02:00
|
|
|
pix = muc_icon.get_pixbuf()
|
|
|
|
banner_status_img.set_from_pixbuf(pix)
|
|
|
|
return
|
|
|
|
# we need to scale 16x16 to 32x32
|
|
|
|
muc_icon = images['16'][image]
|
|
|
|
pix = muc_icon.get_pixbuf()
|
2012-12-23 16:23:43 +01:00
|
|
|
scaled_pix = pix.scale_simple(32, 32, GdkPixbuf.InterpType.BILINEAR)
|
2010-04-08 01:20:17 +02:00
|
|
|
banner_status_img.set_from_pixbuf(scaled_pix)
|
|
|
|
|
|
|
|
def get_continued_conversation_name(self):
|
|
|
|
"""
|
|
|
|
Get the name of a continued conversation. Will return Continued
|
|
|
|
Conversation if there isn't any other contact in the room
|
|
|
|
"""
|
|
|
|
nicks = []
|
|
|
|
for nick in gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid):
|
|
|
|
if nick != self.nick:
|
|
|
|
nicks.append(nick)
|
|
|
|
if nicks != []:
|
|
|
|
title = ', '
|
|
|
|
title = _('Conversation with ') + title.join(nicks)
|
|
|
|
else:
|
|
|
|
title = _('Continued conversation')
|
|
|
|
return title
|
|
|
|
|
|
|
|
def draw_banner_text(self):
|
|
|
|
"""
|
|
|
|
Draw the text in the fat line at the top of the window that houses the
|
|
|
|
room jid, subject
|
|
|
|
"""
|
2012-12-23 16:23:43 +01:00
|
|
|
self.name_label.set_ellipsize(Pango.EllipsizeMode.END)
|
|
|
|
self.banner_status_label.set_ellipsize(Pango.EllipsizeMode.END)
|
2010-04-08 01:20:17 +02:00
|
|
|
font_attrs, font_attrs_small = self.get_font_attrs()
|
|
|
|
if self.is_continued:
|
|
|
|
name = self.get_continued_conversation_name()
|
|
|
|
else:
|
|
|
|
name = self.room_jid
|
2013-08-11 14:44:46 +02:00
|
|
|
text = '<span %s>%s</span>' % (font_attrs, '\u200E' + name)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.name_label.set_markup(text)
|
|
|
|
|
|
|
|
if self.subject:
|
|
|
|
subject = helpers.reduce_chars_newlines(self.subject, max_lines=2)
|
2013-07-28 20:50:30 +02:00
|
|
|
subject = GLib.markup_escape_text(subject)
|
2010-04-08 01:20:17 +02:00
|
|
|
subject_text = self.urlfinder.sub(self.make_href, subject)
|
2010-05-20 09:17:56 +02:00
|
|
|
subject_text = '<span %s>%s</span>' % (font_attrs_small,
|
|
|
|
subject_text)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# tooltip must always hold ALL the subject
|
|
|
|
self.event_box.set_tooltip_text(self.subject)
|
|
|
|
self.banner_status_label.set_no_show_all(False)
|
|
|
|
self.banner_status_label.show()
|
|
|
|
else:
|
|
|
|
subject_text = ''
|
|
|
|
self.event_box.set_has_tooltip(False)
|
|
|
|
self.banner_status_label.hide()
|
|
|
|
self.banner_status_label.set_no_show_all(True)
|
|
|
|
|
|
|
|
self.banner_status_label.set_markup(subject_text)
|
|
|
|
|
|
|
|
def prepare_context_menu(self, hide_buttonbar_items=False):
|
|
|
|
"""
|
|
|
|
Set sensitivity state for configure_room
|
|
|
|
"""
|
|
|
|
xml = gtkgui_helpers.get_gtk_builder('gc_control_popup_menu.ui')
|
|
|
|
menu = xml.get_object('gc_control_popup_menu')
|
|
|
|
|
|
|
|
bookmark_room_menuitem = xml.get_object('bookmark_room_menuitem')
|
|
|
|
change_nick_menuitem = xml.get_object('change_nick_menuitem')
|
|
|
|
configure_room_menuitem = xml.get_object('configure_room_menuitem')
|
|
|
|
destroy_room_menuitem = xml.get_object('destroy_room_menuitem')
|
|
|
|
change_subject_menuitem = xml.get_object('change_subject_menuitem')
|
|
|
|
history_menuitem = xml.get_object('history_menuitem')
|
|
|
|
minimize_menuitem = xml.get_object('minimize_menuitem')
|
2011-04-26 15:54:46 +02:00
|
|
|
request_voice_menuitem = xml.get_object('request_voice_menuitem')
|
2010-04-08 01:20:17 +02:00
|
|
|
bookmark_separator = xml.get_object('bookmark_separator')
|
|
|
|
separatormenuitem2 = xml.get_object('separatormenuitem2')
|
2011-04-26 15:54:46 +02:00
|
|
|
request_voice_separator = xml.get_object('request_voice_separator')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2011-05-26 11:35:33 +02:00
|
|
|
if gtkgui_helpers.gtk_icon_theme.has_icon('bookmark-new'):
|
2013-09-15 11:54:42 +02:00
|
|
|
img = Gtk.Image()
|
|
|
|
img.set_from_icon_name('bookmark-new', Gtk.IconSize.MENU)
|
2013-09-04 16:01:57 +02:00
|
|
|
bookmark_room_menuitem.set_image(img)
|
2013-03-16 20:56:22 +01:00
|
|
|
if gtkgui_helpers.gtk_icon_theme.has_icon('document-open-recent'):
|
2013-09-15 11:54:42 +02:00
|
|
|
img = Gtk.Image()
|
|
|
|
img.set_from_icon_name('document-open-recent', Gtk.IconSize.MENU)
|
2013-09-04 16:01:57 +02:00
|
|
|
history_menuitem.set_image(img)
|
2011-05-26 11:35:33 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
if hide_buttonbar_items:
|
|
|
|
change_nick_menuitem.hide()
|
|
|
|
change_subject_menuitem.hide()
|
|
|
|
bookmark_room_menuitem.hide()
|
|
|
|
history_menuitem.hide()
|
|
|
|
bookmark_separator.hide()
|
|
|
|
separatormenuitem2.hide()
|
|
|
|
else:
|
|
|
|
change_nick_menuitem.show()
|
|
|
|
change_subject_menuitem.show()
|
|
|
|
bookmark_room_menuitem.show()
|
|
|
|
history_menuitem.show()
|
|
|
|
bookmark_separator.show()
|
|
|
|
separatormenuitem2.show()
|
|
|
|
for bm in gajim.connections[self.account].bookmarks:
|
|
|
|
if bm['jid'] == self.room_jid:
|
|
|
|
bookmark_room_menuitem.hide()
|
|
|
|
bookmark_separator.hide()
|
|
|
|
break
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
ag = Gtk.accel_groups_from_object(self.parent_win.window)[0]
|
|
|
|
change_nick_menuitem.add_accelerator('activate', ag, Gdk.KEY_n,
|
|
|
|
Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK, Gtk.AccelFlags.VISIBLE)
|
2010-04-08 01:20:17 +02:00
|
|
|
change_subject_menuitem.add_accelerator('activate', ag,
|
2012-12-23 16:23:43 +01:00
|
|
|
Gdk.KEY_t, Gdk.ModifierType.MOD1_MASK, Gtk.AccelFlags.VISIBLE)
|
|
|
|
bookmark_room_menuitem.add_accelerator('activate', ag, Gdk.KEY_b,
|
|
|
|
Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE)
|
|
|
|
history_menuitem.add_accelerator('activate', ag, Gdk.KEY_h,
|
|
|
|
Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
if self.contact.jid in gajim.config.get_per('accounts', self.account,
|
|
|
|
'minimized_gc').split(' '):
|
|
|
|
minimize_menuitem.set_active(True)
|
2012-11-20 10:00:57 +01:00
|
|
|
conn = gajim.connections[self.account]
|
|
|
|
if not conn.private_storage_supported and (not conn.pubsub_supported or \
|
|
|
|
not conn.pubsub_publish_options_supported):
|
2010-04-08 01:20:17 +02:00
|
|
|
bookmark_room_menuitem.set_sensitive(False)
|
|
|
|
if gajim.gc_connected[self.account][self.room_jid]:
|
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
self.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
if c.affiliation not in ('owner', 'admin'):
|
|
|
|
configure_room_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
configure_room_menuitem.set_sensitive(True)
|
|
|
|
if c.affiliation != 'owner':
|
|
|
|
destroy_room_menuitem.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
destroy_room_menuitem.set_sensitive(True)
|
|
|
|
change_subject_menuitem.set_sensitive(True)
|
|
|
|
change_nick_menuitem.set_sensitive(True)
|
2011-04-26 15:54:46 +02:00
|
|
|
if c.role == 'visitor':
|
|
|
|
request_voice_menuitem.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
request_voice_menuitem.set_sensitive(False)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
# We are not connected to this groupchat, disable unusable menuitems
|
|
|
|
configure_room_menuitem.set_sensitive(False)
|
|
|
|
destroy_room_menuitem.set_sensitive(False)
|
|
|
|
change_subject_menuitem.set_sensitive(False)
|
|
|
|
change_nick_menuitem.set_sensitive(False)
|
2011-04-26 15:54:46 +02:00
|
|
|
request_voice_menuitem.set_sensitive(False)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# connect the menuitems to their respective functions
|
|
|
|
id_ = bookmark_room_menuitem.connect('activate',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_bookmark_room_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = bookmark_room_menuitem
|
|
|
|
|
|
|
|
id_ = change_nick_menuitem.connect('activate',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_change_nick_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = change_nick_menuitem
|
|
|
|
|
|
|
|
id_ = configure_room_menuitem.connect('activate',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_configure_room_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = configure_room_menuitem
|
|
|
|
|
|
|
|
id_ = destroy_room_menuitem.connect('activate',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_destroy_room_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = destroy_room_menuitem
|
|
|
|
|
|
|
|
id_ = change_subject_menuitem.connect('activate',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_change_subject_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = change_subject_menuitem
|
|
|
|
|
|
|
|
id_ = history_menuitem.connect('activate',
|
2010-05-20 09:17:56 +02:00
|
|
|
self._on_history_menuitem_activate)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = history_menuitem
|
|
|
|
|
2011-04-26 15:54:46 +02:00
|
|
|
id_ = request_voice_menuitem.connect('activate',
|
|
|
|
self._on_request_voice_menuitem_activate)
|
|
|
|
self.handlers[id_] = request_voice_menuitem
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
id_ = minimize_menuitem.connect('toggled',
|
2010-05-20 09:17:56 +02:00
|
|
|
self.on_minimize_menuitem_toggled)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = minimize_menuitem
|
|
|
|
|
|
|
|
menu.connect('selection-done', self.destroy_menu,
|
2010-05-20 09:17:56 +02:00
|
|
|
change_nick_menuitem, change_subject_menuitem,
|
|
|
|
bookmark_room_menuitem, history_menuitem)
|
2010-04-08 01:20:17 +02:00
|
|
|
return menu
|
|
|
|
|
|
|
|
def destroy_menu(self, menu, change_nick_menuitem, change_subject_menuitem,
|
2010-05-20 09:17:56 +02:00
|
|
|
bookmark_room_menuitem, history_menuitem):
|
2010-04-08 01:20:17 +02:00
|
|
|
# destroy accelerators
|
2012-12-23 16:23:43 +01:00
|
|
|
ag = Gtk.accel_groups_from_object(self.parent_win.window)[0]
|
|
|
|
change_nick_menuitem.remove_accelerator(ag, Gdk.KEY_n,
|
|
|
|
Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK)
|
|
|
|
change_subject_menuitem.remove_accelerator(ag, Gdk.KEY_t,
|
|
|
|
Gdk.ModifierType.MOD1_MASK)
|
|
|
|
bookmark_room_menuitem.remove_accelerator(ag, Gdk.KEY_b,
|
|
|
|
Gdk.ModifierType.CONTROL_MASK)
|
|
|
|
history_menuitem.remove_accelerator(ag, Gdk.KEY_h,
|
|
|
|
Gdk.ModifierType.CONTROL_MASK)
|
2010-04-08 01:20:17 +02:00
|
|
|
# destroy menu
|
|
|
|
menu.destroy()
|
|
|
|
|
2010-11-08 22:34:04 +01:00
|
|
|
def _nec_vcard_published(self, obj):
|
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
show = gajim.SHOW_LIST[obj.conn.connected]
|
|
|
|
status = obj.conn.status
|
|
|
|
obj.conn.send_gc_status(self.nick, self.room_jid, show, status)
|
|
|
|
|
2010-11-26 21:14:59 +01:00
|
|
|
def _nec_vcard_received(self, obj):
|
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
if obj.jid != self.room_jid:
|
|
|
|
return
|
|
|
|
self.draw_avatar(obj.resource)
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
def _nec_gc_message_received(self, obj):
|
2010-10-19 21:43:44 +02:00
|
|
|
if obj.room_jid != self.room_jid or obj.conn.name != self.account:
|
2010-10-18 22:05:41 +02:00
|
|
|
return
|
|
|
|
if obj.captcha_form:
|
2010-08-09 14:51:42 +02:00
|
|
|
if self.form_widget:
|
|
|
|
self.form_widget.hide()
|
|
|
|
self.form_widget.destroy()
|
|
|
|
self.btn_box.destroy()
|
2010-10-18 22:05:41 +02:00
|
|
|
dataform = dataforms.ExtendForm(node=obj.captcha_form)
|
2010-06-27 23:09:07 +02:00
|
|
|
self.form_widget = dataforms_widget.DataFormWidget(dataform)
|
|
|
|
|
|
|
|
def on_send_dataform_clicked(widget):
|
|
|
|
if not self.form_widget:
|
|
|
|
return
|
|
|
|
form_node = self.form_widget.data_form.get_purged()
|
2012-08-22 12:55:57 +02:00
|
|
|
form_node.type_ = 'submit'
|
2010-10-18 22:05:41 +02:00
|
|
|
obj.conn.send_captcha(self.room_jid, form_node)
|
2010-06-27 23:09:07 +02:00
|
|
|
self.form_widget.hide()
|
|
|
|
self.form_widget.destroy()
|
|
|
|
self.btn_box.destroy()
|
2010-08-09 14:51:42 +02:00
|
|
|
self.form_widget = None
|
2010-06-27 23:09:07 +02:00
|
|
|
del self.btn_box
|
|
|
|
|
2010-11-14 21:21:39 +01:00
|
|
|
self.form_widget.connect('validated', on_send_dataform_clicked)
|
|
|
|
self.form_widget.show_all()
|
|
|
|
vbox = self.xml.get_object('gc_textviews_vbox')
|
2012-12-23 16:23:43 +01:00
|
|
|
vbox.pack_start(self.form_widget, False, True, 0)
|
2010-11-14 21:21:39 +01:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
valid_button = Gtk.Button(stock=Gtk.STOCK_OK)
|
2010-06-27 23:09:07 +02:00
|
|
|
valid_button.connect('clicked', on_send_dataform_clicked)
|
2012-12-23 16:23:43 +01:00
|
|
|
self.btn_box = Gtk.HButtonBox()
|
|
|
|
self.btn_box.set_layout(Gtk.ButtonBoxStyle.END)
|
|
|
|
self.btn_box.pack_start(valid_button, True, True, 0)
|
2010-06-27 23:09:07 +02:00
|
|
|
self.btn_box.show_all()
|
2012-12-23 16:23:43 +01:00
|
|
|
vbox.pack_start(self.btn_box, False, False, 0)
|
2010-06-27 23:09:07 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self, 'attention')
|
|
|
|
else:
|
|
|
|
self.attention_flag = True
|
2010-10-18 22:05:41 +02:00
|
|
|
if '100' in obj.status_code:
|
2010-04-08 01:20:17 +02:00
|
|
|
# Room is not anonymous
|
|
|
|
self.is_anonymous = False
|
2010-10-18 22:05:41 +02:00
|
|
|
if not obj.nick:
|
2010-04-08 01:20:17 +02:00
|
|
|
# message from server
|
2010-10-18 22:05:41 +02:00
|
|
|
self.print_conversation(obj.msgtxt, tim=obj.timestamp,
|
|
|
|
xhtml=obj.xhtml_msgtxt, displaymarking=obj.displaymarking)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
# message from someone
|
2010-10-18 22:05:41 +02:00
|
|
|
if obj.has_timestamp:
|
2010-04-08 01:20:17 +02:00
|
|
|
# don't print xhtml if it's an old message.
|
|
|
|
# Like that xhtml messages are grayed too.
|
2010-10-18 22:05:41 +02:00
|
|
|
self.print_old_conversation(obj.msgtxt, contact=obj.nick,
|
|
|
|
tim=obj.timestamp, xhtml=None,
|
|
|
|
displaymarking=obj.displaymarking)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2013-04-25 20:38:18 +02:00
|
|
|
if obj.nick in self.last_received_txt and obj.correct_id and \
|
|
|
|
obj.correct_id == self.last_received_id[obj.nick]:
|
|
|
|
if obj.nick == self.nick:
|
|
|
|
old_txt = self.last_sent_txt
|
|
|
|
self.last_sent_txt = obj.msgtxt
|
|
|
|
self.conv_textview.correct_last_sent_message(obj.msgtxt,
|
|
|
|
obj.xhtml_msgtxt, obj.nick, old_txt)
|
|
|
|
else:
|
|
|
|
old_txt = self.last_received_txt[obj.nick]
|
|
|
|
self.conv_textview.correct_last_received_message(obj.msgtxt,
|
|
|
|
obj.xhtml_msgtxt, obj.nick, old_txt)
|
|
|
|
self.last_received_txt[obj.nick] = obj.msgtxt
|
|
|
|
self.last_received_id[obj.nick] = obj.stanza.getID()
|
|
|
|
return
|
|
|
|
if obj.nick == self.nick:
|
|
|
|
self.last_sent_txt = obj.msgtxt
|
2010-10-18 22:05:41 +02:00
|
|
|
self.print_conversation(obj.msgtxt, contact=obj.nick,
|
|
|
|
tim=obj.timestamp, xhtml=obj.xhtml_msgtxt,
|
2013-04-25 20:38:18 +02:00
|
|
|
displaymarking=obj.displaymarking,
|
|
|
|
correct_id=(obj.stanza.getID(), None))
|
2010-10-18 22:05:41 +02:00
|
|
|
obj.needs_highlight = self.needs_visual_notification(obj.msgtxt)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_private_message(self, nick, msg, tim, xhtml, session, msg_id=None,
|
2010-06-07 19:11:44 +02:00
|
|
|
encrypted=False, displaymarking=None):
|
2010-04-08 01:20:17 +02:00
|
|
|
# Do we have a queue?
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
no_queue = len(gajim.events.get_events(self.account, fjid)) == 0
|
|
|
|
|
|
|
|
event = gajim.events.create_event('pm', (msg, '', 'incoming', tim,
|
2011-11-08 20:01:51 +01:00
|
|
|
encrypted, '', msg_id, xhtml, session, None, displaymarking, False))
|
2010-04-08 01:20:17 +02:00
|
|
|
gajim.events.add_event(self.account, fjid, event)
|
|
|
|
|
|
|
|
autopopup = gajim.config.get('autopopup')
|
|
|
|
autopopupaway = gajim.config.get('autopopupaway')
|
|
|
|
iter_ = self.get_contact_iter(nick)
|
2011-08-24 11:58:06 +02:00
|
|
|
path = self.model.get_path(iter_)
|
2010-04-08 01:20:17 +02:00
|
|
|
if not autopopup or (not autopopupaway and \
|
|
|
|
gajim.connections[self.account].connected > 2):
|
|
|
|
if no_queue: # We didn't have a queue: we change icons
|
2010-05-20 09:17:56 +02:00
|
|
|
state_images = \
|
|
|
|
gajim.interface.roster.get_appropriate_state_images(
|
|
|
|
self.room_jid, icon_name='event')
|
2010-04-08 01:20:17 +02:00
|
|
|
image = state_images['event']
|
2011-08-24 11:58:06 +02:00
|
|
|
self.model[iter_][C_IMG] = image
|
2010-04-08 01:20:17 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.show_title()
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
else:
|
|
|
|
self._start_private_message(nick)
|
|
|
|
# Scroll to line
|
2013-01-08 19:11:51 +01:00
|
|
|
path_ = path
|
|
|
|
path_.up()
|
|
|
|
self.list_treeview.expand_row(path_, False)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.list_treeview.scroll_to_cell(path)
|
|
|
|
self.list_treeview.set_cursor(path)
|
2010-05-20 09:17:56 +02:00
|
|
|
contact = gajim.contacts.get_contact_with_highest_priority(
|
|
|
|
self.account, self.room_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
if contact:
|
|
|
|
gajim.interface.roster.draw_contact(self.room_jid, self.account)
|
|
|
|
|
|
|
|
def get_contact_iter(self, nick):
|
2012-12-23 16:23:43 +01:00
|
|
|
role_iter = self.model.get_iter_first()
|
2010-04-08 01:20:17 +02:00
|
|
|
while role_iter:
|
2011-08-24 11:58:06 +02:00
|
|
|
user_iter = self.model.iter_children(role_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
while user_iter:
|
2013-01-01 19:44:25 +01:00
|
|
|
if nick == self.model[user_iter][C_NICK]:
|
2010-04-08 01:20:17 +02:00
|
|
|
return user_iter
|
|
|
|
else:
|
2011-08-24 11:58:06 +02:00
|
|
|
user_iter = self.model.iter_next(user_iter)
|
|
|
|
role_iter = self.model.iter_next(role_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
return None
|
|
|
|
|
2010-06-07 19:11:44 +02:00
|
|
|
def print_old_conversation(self, text, contact='', tim=None, xhtml = None,
|
2013-01-01 21:06:16 +01:00
|
|
|
displaymarking=None):
|
2010-04-08 01:20:17 +02:00
|
|
|
if contact:
|
|
|
|
if contact == self.nick: # it's us
|
|
|
|
kind = 'outgoing'
|
|
|
|
else:
|
|
|
|
kind = 'incoming'
|
|
|
|
else:
|
|
|
|
kind = 'status'
|
|
|
|
if gajim.config.get('restored_messages_small'):
|
|
|
|
small_attr = ['small']
|
|
|
|
else:
|
|
|
|
small_attr = []
|
|
|
|
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
|
2010-05-20 09:17:56 +02:00
|
|
|
small_attr, small_attr + ['restored_message'],
|
2010-06-07 19:11:44 +02:00
|
|
|
small_attr + ['restored_message'], count_as_new=False, xhtml=xhtml,
|
|
|
|
displaymarking=displaymarking)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def print_conversation(self, text, contact='', tim=None, xhtml=None,
|
2013-04-25 20:38:18 +02:00
|
|
|
graphics=True, displaymarking=None, correct_id=None):
|
2010-04-08 01:20:17 +02:00
|
|
|
"""
|
|
|
|
Print a line in the conversation
|
|
|
|
|
|
|
|
If contact is set: it's a message from someone or an info message
|
|
|
|
(contact = 'info' in such a case).
|
|
|
|
If contact is not set: it's a message from the server or help.
|
|
|
|
"""
|
|
|
|
other_tags_for_name = []
|
|
|
|
other_tags_for_text = []
|
|
|
|
if contact:
|
|
|
|
if contact == self.nick: # it's us
|
|
|
|
kind = 'outgoing'
|
|
|
|
elif contact == 'info':
|
|
|
|
kind = 'info'
|
|
|
|
contact = None
|
|
|
|
else:
|
|
|
|
kind = 'incoming'
|
|
|
|
# muc-specific chatstate
|
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self, 'newmsg')
|
|
|
|
else:
|
|
|
|
kind = 'status'
|
|
|
|
|
|
|
|
if kind == 'incoming': # it's a message NOT from us
|
|
|
|
# highlighting and sounds
|
|
|
|
(highlight, sound) = self.highlighting_for_message(text, tim)
|
|
|
|
if contact in self.gc_custom_colors:
|
|
|
|
other_tags_for_name.append('gc_nickname_color_' + \
|
2010-05-20 09:17:56 +02:00
|
|
|
str(self.gc_custom_colors[contact]))
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
self.gc_count_nicknames_colors += 1
|
|
|
|
if self.gc_count_nicknames_colors == self.number_of_colors:
|
|
|
|
self.gc_count_nicknames_colors = 0
|
|
|
|
self.gc_custom_colors[contact] = \
|
2010-05-20 09:17:56 +02:00
|
|
|
self.gc_count_nicknames_colors
|
2010-04-08 01:20:17 +02:00
|
|
|
other_tags_for_name.append('gc_nickname_color_' + \
|
2010-05-20 09:17:56 +02:00
|
|
|
str(self.gc_count_nicknames_colors))
|
2010-04-08 01:20:17 +02:00
|
|
|
if highlight:
|
|
|
|
# muc-specific chatstate
|
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self, 'attention')
|
|
|
|
else:
|
|
|
|
self.attention_flag = True
|
|
|
|
other_tags_for_name.append('bold')
|
|
|
|
other_tags_for_text.append('marked')
|
|
|
|
|
|
|
|
if contact in self.attention_list:
|
|
|
|
self.attention_list.remove(contact)
|
|
|
|
elif len(self.attention_list) > 6:
|
|
|
|
self.attention_list.pop(0) # remove older
|
|
|
|
self.attention_list.append(contact)
|
|
|
|
|
|
|
|
if text.startswith('/me ') or text.startswith('/me\n'):
|
|
|
|
other_tags_for_text.append('gc_nickname_color_' + \
|
2010-05-20 09:17:56 +02:00
|
|
|
str(self.gc_custom_colors[contact]))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
self.check_and_possibly_add_focus_out_line()
|
|
|
|
|
|
|
|
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
|
2010-05-20 09:17:56 +02:00
|
|
|
other_tags_for_name, [], other_tags_for_text, xhtml=xhtml,
|
2013-04-25 20:38:18 +02:00
|
|
|
graphics=graphics, displaymarking=displaymarking,
|
|
|
|
correct_id=correct_id)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def get_nb_unread(self):
|
|
|
|
type_events = ['printed_marked_gc_msg']
|
|
|
|
if gajim.config.get('notify_on_all_muc_messages'):
|
|
|
|
type_events.append('printed_gc_msg')
|
|
|
|
nb = len(gajim.events.get_events(self.account, self.room_jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
type_events))
|
2010-04-08 01:20:17 +02:00
|
|
|
nb += self.get_nb_unread_pm()
|
|
|
|
return nb
|
|
|
|
|
|
|
|
def get_nb_unread_pm(self):
|
|
|
|
nb = 0
|
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
2010-05-20 09:17:56 +02:00
|
|
|
nb += len(gajim.events.get_events(self.account, self.room_jid + \
|
|
|
|
'/' + nick, ['pm']))
|
2010-04-08 01:20:17 +02:00
|
|
|
return nb
|
|
|
|
|
|
|
|
def highlighting_for_message(self, text, tim):
|
|
|
|
"""
|
|
|
|
Returns a 2-Tuple. The first says whether or not to highlight the text,
|
|
|
|
the second, what sound to play
|
|
|
|
"""
|
|
|
|
highlight, sound = (None, None)
|
|
|
|
|
|
|
|
# Are any of the defined highlighting words in the text?
|
|
|
|
if self.needs_visual_notification(text):
|
|
|
|
highlight = True
|
|
|
|
if gajim.config.get_per('soundevents', 'muc_message_highlight',
|
|
|
|
'enabled'):
|
|
|
|
sound = 'highlight'
|
|
|
|
|
|
|
|
# Do we play a sound on every muc message?
|
|
|
|
elif gajim.config.get_per('soundevents', 'muc_message_received', \
|
|
|
|
'enabled'):
|
|
|
|
sound = 'received'
|
|
|
|
|
|
|
|
# Is it a history message? Don't want sound-floods when we join.
|
|
|
|
if tim != time.localtime():
|
|
|
|
sound = None
|
|
|
|
|
|
|
|
return (highlight, sound)
|
|
|
|
|
|
|
|
def check_and_possibly_add_focus_out_line(self):
|
|
|
|
"""
|
|
|
|
Check and possibly add focus out line for room_jid if it needs it and
|
|
|
|
does not already have it as last event. If it goes to add this line
|
|
|
|
- remove previous line first
|
|
|
|
"""
|
2010-05-20 09:17:56 +02:00
|
|
|
win = gajim.interface.msg_win_mgr.get_window(self.room_jid,
|
|
|
|
self.account)
|
2010-04-08 01:20:17 +02:00
|
|
|
if win and self.room_jid == win.get_active_jid() and\
|
|
|
|
win.window.get_property('has-toplevel-focus') and\
|
|
|
|
self.parent_win.get_active_control() == self:
|
|
|
|
# it's the current room and it's the focused window.
|
|
|
|
# we have full focus (we are reading it!)
|
|
|
|
return
|
|
|
|
|
2010-12-17 12:09:56 +01:00
|
|
|
at_the_end = self.conv_textview.at_the_end()
|
|
|
|
self.conv_textview.show_focus_out_line(scroll=at_the_end)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def needs_visual_notification(self, text):
|
|
|
|
"""
|
|
|
|
Check text to see whether any of the words in (muc_highlight_words and
|
|
|
|
nick) appear
|
|
|
|
"""
|
|
|
|
special_words = gajim.config.get('muc_highlight_words').split(';')
|
|
|
|
special_words.append(self.nick)
|
|
|
|
# Strip empties: ''.split(';') == [''] and would highlight everything.
|
|
|
|
# Also lowercase everything for case insensitive compare.
|
|
|
|
special_words = [word.lower() for word in special_words if word]
|
|
|
|
text = text.lower()
|
|
|
|
|
|
|
|
for special_word in special_words:
|
|
|
|
found_here = text.find(special_word)
|
|
|
|
while(found_here > -1):
|
|
|
|
end_here = found_here + len(special_word)
|
|
|
|
if (found_here == 0 or not text[found_here - 1].isalpha()) and \
|
|
|
|
(end_here == len(text) or not text[end_here].isalpha()):
|
|
|
|
# It is beginning of text or char before is not alpha AND
|
|
|
|
# it is end of text or char after is not alpha
|
|
|
|
return True
|
|
|
|
# continue searching
|
|
|
|
start = found_here + 1
|
|
|
|
found_here = text.find(special_word, start)
|
|
|
|
return False
|
|
|
|
|
|
|
|
def set_subject(self, subject):
|
|
|
|
self.subject = subject
|
|
|
|
self.draw_banner_text()
|
|
|
|
|
2010-11-27 19:12:43 +01:00
|
|
|
def _nec_gc_subject_received(self, obj):
|
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
if obj.room_jid != self.room_jid:
|
|
|
|
return
|
|
|
|
self.set_subject(obj.subject)
|
|
|
|
text = _('%(nick)s has set the subject to %(subject)s') % {
|
|
|
|
'nick': obj.nickname, 'subject': obj.subject}
|
|
|
|
if obj.has_timestamp:
|
|
|
|
self.print_old_conversation(text)
|
|
|
|
else:
|
|
|
|
self.print_conversation(text)
|
|
|
|
|
2010-11-27 21:02:41 +01:00
|
|
|
def _nec_gc_config_changed_received(self, obj):
|
|
|
|
# statuscode is a list
|
|
|
|
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
|
|
|
|
# http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes...
|
|
|
|
# -init
|
2010-12-03 08:48:13 +01:00
|
|
|
if obj.room_jid != self.room_jid or obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
|
2010-11-27 21:02:41 +01:00
|
|
|
changes = []
|
2010-11-29 21:15:54 +01:00
|
|
|
if '100' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
# Can be a presence (see chg_contact_status in groupchat_control.py)
|
|
|
|
changes.append(_('Any occupant is allowed to see your full JID'))
|
2010-12-03 08:48:13 +01:00
|
|
|
self.is_anonymous = False
|
2010-11-29 21:15:54 +01:00
|
|
|
if '102' in obj.status_code:
|
2013-08-15 10:33:27 +02:00
|
|
|
changes.append(_('Room now shows unavailable members'))
|
2010-11-29 21:15:54 +01:00
|
|
|
if '103' in obj.status_code:
|
2013-08-15 10:33:27 +02:00
|
|
|
changes.append(_('Room now does not show unavailable members'))
|
2010-11-29 21:15:54 +01:00
|
|
|
if '104' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
changes.append(_('A non-privacy-related room configuration change '
|
|
|
|
'has occurred'))
|
2010-11-29 21:15:54 +01:00
|
|
|
if '170' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
# Can be a presence (see chg_contact_status in groupchat_control.py)
|
|
|
|
changes.append(_('Room logging is now enabled'))
|
2010-11-29 21:15:54 +01:00
|
|
|
if '171' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
changes.append(_('Room logging is now disabled'))
|
2010-11-29 21:15:54 +01:00
|
|
|
if '172' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
changes.append(_('Room is now non-anonymous'))
|
2010-12-03 08:48:13 +01:00
|
|
|
self.is_anonymous = False
|
2010-11-29 21:15:54 +01:00
|
|
|
if '173' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
changes.append(_('Room is now semi-anonymous'))
|
2010-12-03 08:48:13 +01:00
|
|
|
self.is_anonymous = True
|
2010-11-29 21:15:54 +01:00
|
|
|
if '174' in obj.status_code:
|
2010-11-27 21:02:41 +01:00
|
|
|
changes.append(_('Room is now fully-anonymous'))
|
2010-12-03 08:48:13 +01:00
|
|
|
self.is_anonymous = True
|
2010-11-27 21:02:41 +01:00
|
|
|
|
|
|
|
for change in changes:
|
|
|
|
self.print_conversation(change)
|
|
|
|
|
2010-11-29 11:11:24 +01:00
|
|
|
def _nec_signed_in(self, obj):
|
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
if self.room_jid in gajim.gc_connected[obj.conn.name] and \
|
|
|
|
gajim.gc_connected[obj.conn.name][self.room_jid]:
|
|
|
|
return
|
|
|
|
password = gajim.gc_passwords.get(self.room_jid, '')
|
2012-02-18 19:48:03 +01:00
|
|
|
obj.conn.join_gc(self.nick, self.room_jid, password, rejoin=True)
|
2010-11-29 11:11:24 +01:00
|
|
|
|
2011-05-01 22:09:50 +02:00
|
|
|
def _nec_decrypted_message_received(self, obj):
|
|
|
|
if obj.conn.name != self.account:
|
|
|
|
return
|
|
|
|
if obj.gc_control == self and obj.resource:
|
|
|
|
# We got a pm from this room
|
|
|
|
nick = obj.resource
|
|
|
|
if obj.session.control:
|
|
|
|
# print if a control is open
|
|
|
|
obj.session.control.print_conversation(obj.msgtxt,
|
|
|
|
tim=obj.timestamp, xhtml=obj.xhtml, encrypted=obj.encrypted,
|
|
|
|
displaymarking=obj.displaymarking)
|
|
|
|
else:
|
|
|
|
# otherwise pass it off to the control to be queued
|
|
|
|
self.on_private_message(nick, obj.msgtxt, obj.timestamp,
|
2011-05-04 22:37:47 +02:00
|
|
|
obj.xhtml, self.session, msg_id=obj.msg_id,
|
|
|
|
encrypted=obj.encrypted, displaymarking=obj.displaymarking)
|
2011-05-01 22:09:50 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
def got_connected(self):
|
|
|
|
# Make autorejoin stop.
|
|
|
|
if self.autorejoin:
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.source_remove(self.autorejoin)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.autorejoin = None
|
|
|
|
|
|
|
|
gajim.gc_connected[self.account][self.room_jid] = True
|
|
|
|
ChatControlBase.got_connected(self)
|
2011-08-24 11:58:06 +02:00
|
|
|
self.list_treeview.set_model(self.model)
|
|
|
|
self.list_treeview.expand_all()
|
2010-04-08 01:20:17 +02:00
|
|
|
# We don't redraw the whole banner here, because only icon change
|
|
|
|
self._update_banner_state_image()
|
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
|
2013-07-27 17:10:08 +02:00
|
|
|
send_button = self.xml.get_object('send_button')
|
|
|
|
send_button.set_sensitive(True)
|
|
|
|
emoticons_button = self.xml.get_object('emoticons_button')
|
|
|
|
emoticons_button.set_sensitive(True)
|
|
|
|
formattings_button = self.xml.get_object('formattings_button')
|
|
|
|
formattings_button.set_sensitive(True)
|
|
|
|
change_nick_button = self.xml.get_object('change_nick_button')
|
|
|
|
change_nick_button.set_sensitive(True)
|
|
|
|
change_subject_button = self.xml.get_object('change_subject_button')
|
|
|
|
change_subject_button.set_sensitive(True)
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
def got_disconnected(self):
|
2013-07-27 17:10:08 +02:00
|
|
|
send_button = self.xml.get_object('send_button')
|
|
|
|
send_button.set_sensitive(False)
|
|
|
|
emoticons_button = self.xml.get_object('emoticons_button')
|
|
|
|
emoticons_button.set_sensitive(False)
|
|
|
|
formattings_button = self.xml.get_object('formattings_button')
|
|
|
|
formattings_button.set_sensitive(False)
|
|
|
|
change_nick_button = self.xml.get_object('change_nick_button')
|
|
|
|
change_nick_button.set_sensitive(False)
|
|
|
|
change_subject_button = self.xml.get_object('change_subject_button')
|
|
|
|
change_subject_button.set_sensitive(False)
|
2011-08-24 11:58:06 +02:00
|
|
|
self.list_treeview.set_model(None)
|
|
|
|
self.model.clear()
|
2010-04-08 01:20:17 +02:00
|
|
|
nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid)
|
|
|
|
for nick in nick_list:
|
|
|
|
# Update pm chat window
|
|
|
|
fjid = self.room_jid + '/' + nick
|
2010-05-20 09:17:56 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.account)
|
|
|
|
if ctrl:
|
|
|
|
gc_contact.show = 'offline'
|
|
|
|
gc_contact.status = ''
|
|
|
|
ctrl.update_ui()
|
|
|
|
if ctrl.parent_win:
|
|
|
|
ctrl.parent_win.redraw_tab(ctrl)
|
|
|
|
|
|
|
|
gajim.contacts.remove_gc_contact(self.account, gc_contact)
|
|
|
|
gajim.gc_connected[self.account][self.room_jid] = False
|
|
|
|
ChatControlBase.got_disconnected(self)
|
|
|
|
# Tell connection to note the date we disconnect to avoid duplicate logs
|
|
|
|
gajim.connections[self.account].gc_got_disconnected(self.room_jid)
|
|
|
|
# We don't redraw the whole banner here, because only icon change
|
|
|
|
self._update_banner_state_image()
|
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
|
|
|
|
# Autorejoin stuff goes here.
|
|
|
|
# Notice that we don't need to activate autorejoin if connection is lost
|
|
|
|
# or in progress.
|
|
|
|
if self.autorejoin is None and gajim.account_is_connected(self.account):
|
|
|
|
ar_to = gajim.config.get('muc_autorejoin_timeout')
|
|
|
|
if ar_to:
|
2013-07-28 20:50:30 +02:00
|
|
|
self.autorejoin = GLib.timeout_add_seconds(ar_to, self.rejoin)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def rejoin(self):
|
|
|
|
if not self.autorejoin:
|
|
|
|
return False
|
|
|
|
password = gajim.gc_passwords.get(self.room_jid, '')
|
|
|
|
gajim.connections[self.account].join_gc(self.nick, self.room_jid,
|
2012-02-18 19:48:03 +01:00
|
|
|
password, rejoin=True)
|
2010-04-08 01:20:17 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
def draw_roster(self):
|
2011-08-24 11:58:06 +02:00
|
|
|
self.model.clear()
|
2010-04-08 01:20:17 +02:00
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
2010-05-20 09:17:56 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.add_contact_to_roster(nick, gc_contact.show, gc_contact.role,
|
2010-05-20 09:17:56 +02:00
|
|
|
gc_contact.affiliation, gc_contact.status, gc_contact.jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.draw_all_roles()
|
|
|
|
# Recalculate column width for ellipsizin
|
|
|
|
self.list_treeview.columns_autosize()
|
|
|
|
|
|
|
|
def on_send_pm(self, widget=None, model=None, iter_=None, nick=None,
|
2010-05-20 09:17:56 +02:00
|
|
|
msg=None):
|
2010-04-08 01:20:17 +02:00
|
|
|
"""
|
|
|
|
Open a chat window and if msg is not None - send private message to a
|
|
|
|
contact in a room
|
|
|
|
"""
|
|
|
|
if nick is None:
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = model[iter_][C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
ctrl = self._start_private_message(nick)
|
|
|
|
if ctrl and msg:
|
|
|
|
ctrl.send_message(msg)
|
|
|
|
|
|
|
|
def on_send_file(self, widget, gc_contact):
|
|
|
|
"""
|
|
|
|
Send a file to a contact in the room
|
|
|
|
"""
|
|
|
|
self._on_send_file(gc_contact)
|
|
|
|
|
|
|
|
def draw_contact(self, nick, selected=False, focus=False):
|
|
|
|
iter_ = self.get_contact_iter(nick)
|
|
|
|
if not iter_:
|
|
|
|
return
|
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
|
|
|
state_images = gajim.interface.jabber_state_images['16']
|
2010-05-20 09:17:56 +02:00
|
|
|
if len(gajim.events.get_events(self.account, self.room_jid + '/' + \
|
|
|
|
nick)):
|
2010-04-08 01:20:17 +02:00
|
|
|
image = state_images['event']
|
|
|
|
else:
|
|
|
|
image = state_images[gc_contact.show]
|
|
|
|
|
2013-07-28 20:50:30 +02:00
|
|
|
name = GLib.markup_escape_text(gc_contact.name)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# Strike name if blocked
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
if helpers.jid_is_blocked(self.account, fjid):
|
|
|
|
name = '<span strikethrough="true">%s</span>' % name
|
|
|
|
|
|
|
|
status = gc_contact.status
|
|
|
|
# add status msg, if not empty, under contact name in the treeview
|
|
|
|
if status and gajim.config.get('show_status_msgs_in_roster'):
|
|
|
|
status = status.strip()
|
|
|
|
if status != '':
|
|
|
|
status = helpers.reduce_chars_newlines(status, max_lines=1)
|
|
|
|
# escape markup entities and make them small italic and fg color
|
2010-02-17 11:32:55 +01:00
|
|
|
color = gtkgui_helpers.get_fade_color(self.list_treeview,
|
2010-04-08 01:20:17 +02:00
|
|
|
selected, focus)
|
2010-05-20 09:17:56 +02:00
|
|
|
colorstring = "#%04x%04x%04x" % (color.red, color.green,
|
|
|
|
color.blue)
|
2010-04-08 01:20:17 +02:00
|
|
|
name += ('\n<span size="small" style="italic" foreground="%s">'
|
2013-07-28 20:50:30 +02:00
|
|
|
'%s</span>') % (colorstring, GLib.markup_escape_text(
|
2010-05-20 09:17:56 +02:00
|
|
|
status))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
if image.get_storage_type() == Gtk.ImageType.PIXBUF and \
|
2010-04-08 01:20:17 +02:00
|
|
|
gc_contact.affiliation != 'none' and gajim.config.get(
|
|
|
|
'show_affiliation_in_groupchat'):
|
|
|
|
pixbuf1 = image.get_pixbuf().copy()
|
2013-01-02 10:32:17 +01:00
|
|
|
pixbuf2 = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 4, 4)
|
2010-04-08 01:20:17 +02:00
|
|
|
if gc_contact.affiliation == 'owner':
|
|
|
|
pixbuf2.fill(0xff0000ff) # Red
|
|
|
|
elif gc_contact.affiliation == 'admin':
|
|
|
|
pixbuf2.fill(0xffb200ff) # Oragne
|
|
|
|
elif gc_contact.affiliation == 'member':
|
|
|
|
pixbuf2.fill(0x00ff00ff) # Green
|
|
|
|
pixbuf2.composite(pixbuf1, 12, 12, pixbuf2.get_property('width'),
|
2010-05-20 09:17:56 +02:00
|
|
|
pixbuf2.get_property('height'), 0, 0, 1.0, 1.0,
|
2012-12-23 16:23:43 +01:00
|
|
|
GdkPixbuf.InterpType.HYPER, 127)
|
2013-01-02 10:32:17 +01:00
|
|
|
image = Gtk.Image.new_from_pixbuf(pixbuf1)
|
2011-08-24 11:58:06 +02:00
|
|
|
self.model[iter_][C_IMG] = image
|
|
|
|
self.model[iter_][C_TEXT] = name
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def draw_avatar(self, nick):
|
|
|
|
if not gajim.config.get('show_avatars_in_roster'):
|
|
|
|
return
|
|
|
|
iter_ = self.get_contact_iter(nick)
|
|
|
|
if not iter_:
|
|
|
|
return
|
|
|
|
fake_jid = self.room_jid + '/' + nick
|
|
|
|
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid)
|
|
|
|
if pixbuf in ('ask', None):
|
2013-01-07 09:45:47 +01:00
|
|
|
scaled_pixbuf = empty_pixbuf
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster')
|
2013-01-07 09:45:47 +01:00
|
|
|
if not scaled_pixbuf:
|
|
|
|
scaled_pixbuf = empty_pixbuf
|
2011-08-24 11:58:06 +02:00
|
|
|
self.model[iter_][C_AVATAR] = scaled_pixbuf
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def draw_role(self, role):
|
|
|
|
role_iter = self.get_role_iter(role)
|
|
|
|
if not role_iter:
|
|
|
|
return
|
|
|
|
role_name = helpers.get_uf_role(role, plural=True)
|
|
|
|
if gajim.config.get('show_contacts_number'):
|
|
|
|
nbr_role, nbr_total = gajim.contacts.get_nb_role_total_gc_contacts(
|
2010-05-20 09:17:56 +02:00
|
|
|
self.account, self.room_jid, role)
|
2010-04-08 01:20:17 +02:00
|
|
|
role_name += ' (%s/%s)' % (repr(nbr_role), repr(nbr_total))
|
2011-08-24 11:58:06 +02:00
|
|
|
self.model[role_iter][C_TEXT] = role_name
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def draw_all_roles(self):
|
|
|
|
for role in ('visitor', 'participant', 'moderator'):
|
|
|
|
self.draw_role(role)
|
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
def _nec_gc_presence_received(self, obj):
|
2010-10-19 21:43:44 +02:00
|
|
|
if obj.room_jid != self.room_jid or obj.conn.name != self.account:
|
2010-09-28 15:13:51 +02:00
|
|
|
return
|
|
|
|
if obj.ptype == 'error':
|
2010-04-08 01:20:17 +02:00
|
|
|
return
|
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
role = obj.role
|
2010-04-08 01:20:17 +02:00
|
|
|
if not role:
|
|
|
|
role = 'visitor'
|
2010-09-28 15:13:51 +02:00
|
|
|
|
|
|
|
affiliation = obj.affiliation
|
2010-04-08 01:20:17 +02:00
|
|
|
if not affiliation:
|
|
|
|
affiliation = 'none'
|
2010-09-28 15:13:51 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
newly_created = False
|
2013-07-23 15:55:24 +02:00
|
|
|
nick = i18n.direction_mark + obj.nick
|
2013-09-12 17:41:33 +02:00
|
|
|
nick_jid = nick + i18n.direction_mark
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# Set to true if role or affiliation have changed
|
|
|
|
right_changed = False
|
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.real_jid:
|
2010-04-08 01:20:17 +02:00
|
|
|
# delete ressource
|
2010-09-28 15:13:51 +02:00
|
|
|
simple_jid = gajim.get_jid_without_resource(obj.real_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
nick_jid += ' (%s)' % simple_jid
|
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
# status_code
|
2010-05-20 09:17:56 +02:00
|
|
|
# http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes-\
|
|
|
|
# init
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.status_code:
|
2011-10-15 10:47:22 +02:00
|
|
|
if '110' in obj.status_code:
|
|
|
|
# We just join the room
|
|
|
|
if self.room_jid in gajim.automatic_rooms[self.account] and \
|
|
|
|
gajim.automatic_rooms[self.account][self.room_jid]['invities']:
|
|
|
|
if self.room_jid not in gajim.interface.instances[
|
|
|
|
self.account]['gc_config']:
|
2013-08-13 13:02:31 +02:00
|
|
|
if obj.role == 'owner':
|
|
|
|
# We need to configure the room if it's a new one.
|
|
|
|
# We cannot know it's a new one. Status 201 is not
|
|
|
|
# sent by all servers.
|
|
|
|
gajim.connections[self.account].request_gc_config(
|
|
|
|
self.room_jid)
|
|
|
|
elif 'continue_tag' not in gajim.automatic_rooms[
|
|
|
|
self.account][self.room_jid]:
|
|
|
|
# We just need to invite contacts
|
|
|
|
for jid in gajim.automatic_rooms[self.account][
|
|
|
|
self.room_jid]['invities']:
|
|
|
|
obj.conn.send_invite(self.room_jid, jid)
|
|
|
|
self.print_conversation(_('%(jid)s has been '
|
|
|
|
'invited in this room') % {'jid': jid},
|
|
|
|
graphics=False)
|
2010-09-28 15:13:51 +02:00
|
|
|
if '100' in obj.status_code:
|
2010-05-20 09:17:56 +02:00
|
|
|
# Can be a message (see handle_event_gc_config_change in
|
|
|
|
# gajim.py)
|
2010-09-28 15:13:51 +02:00
|
|
|
self.print_conversation(
|
2010-05-20 09:17:56 +02:00
|
|
|
_('Any occupant is allowed to see your full JID'))
|
2011-07-22 11:18:26 +02:00
|
|
|
self.is_anonymous = False
|
2010-09-28 15:13:51 +02:00
|
|
|
if '170' in obj.status_code:
|
2010-05-20 09:17:56 +02:00
|
|
|
# Can be a message (see handle_event_gc_config_change in
|
|
|
|
# gajim.py)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.print_conversation(_('Room logging is enabled'))
|
2010-09-28 15:13:51 +02:00
|
|
|
if '201' in obj.status_code:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.print_conversation(_('A new room has been created'))
|
2010-09-28 15:13:51 +02:00
|
|
|
if '210' in obj.status_code:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.print_conversation(\
|
2010-05-20 09:17:56 +02:00
|
|
|
_('The server has assigned or modified your roomnick'))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.show in ('offline', 'error'):
|
|
|
|
if obj.status_code:
|
|
|
|
if '307' in obj.status_code:
|
|
|
|
if obj.actor is None: # do not print 'kicked by None'
|
2010-04-08 01:20:17 +02:00
|
|
|
s = _('%(nick)s has been kicked: %(reason)s') % {
|
2013-07-23 15:55:24 +02:00
|
|
|
'nick': nick, 'reason': obj.reason}
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-05-20 09:17:56 +02:00
|
|
|
s = _('%(nick)s has been kicked by %(who)s: '
|
2013-07-23 15:55:24 +02:00
|
|
|
'%(reason)s') % {'nick': nick, 'who': obj.actor,
|
2010-09-28 15:13:51 +02:00
|
|
|
'reason': obj.reason}
|
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
|
|
|
if obj.nick == self.nick and not gajim.config.get(
|
2010-04-08 01:20:17 +02:00
|
|
|
'muc_autorejoin_on_kick'):
|
|
|
|
self.autorejoin = False
|
2010-09-28 15:13:51 +02:00
|
|
|
elif '301' in obj.status_code:
|
|
|
|
if obj.actor is None: # do not print 'banned by None'
|
2010-04-08 01:20:17 +02:00
|
|
|
s = _('%(nick)s has been banned: %(reason)s') % {
|
2013-07-23 15:55:24 +02:00
|
|
|
'nick': nick, 'reason': obj.reason}
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-05-20 09:17:56 +02:00
|
|
|
s = _('%(nick)s has been banned by %(who)s: '
|
2013-07-23 15:55:24 +02:00
|
|
|
'%(reason)s') % {'nick': nick, 'who': obj.actor,
|
2010-09-28 15:13:51 +02:00
|
|
|
'reason': obj.reason}
|
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
|
|
|
if obj.nick == self.nick:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.autorejoin = False
|
2010-09-28 15:13:51 +02:00
|
|
|
elif '303' in obj.status_code: # Someone changed his or her nick
|
|
|
|
if obj.new_nick == self.new_nick or obj.nick == self.nick:
|
2010-04-08 01:20:17 +02:00
|
|
|
# We changed our nick
|
2010-09-28 15:13:51 +02:00
|
|
|
self.nick = obj.new_nick
|
2010-04-08 01:20:17 +02:00
|
|
|
self.new_nick = ''
|
2010-09-28 15:13:51 +02:00
|
|
|
s = _('You are now known as %s') % self.nick
|
2010-04-08 01:20:17 +02:00
|
|
|
# Stop all E2E sessions
|
|
|
|
nick_list = gajim.contacts.get_nick_list(self.account,
|
2010-05-20 09:17:56 +02:00
|
|
|
self.room_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
for nick_ in nick_list:
|
|
|
|
fjid_ = self.room_jid + '/' + nick_
|
2010-05-20 09:17:56 +02:00
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(
|
|
|
|
fjid_, self.account)
|
2010-04-08 01:20:17 +02:00
|
|
|
if ctrl and ctrl.session and \
|
|
|
|
ctrl.session.enable_encryption:
|
|
|
|
thread_id = ctrl.session.thread_id
|
|
|
|
ctrl.session.terminate_e2e()
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.connections[self.account].delete_session(
|
|
|
|
fjid_, thread_id)
|
2010-04-08 01:20:17 +02:00
|
|
|
ctrl.no_autonegotiation = False
|
|
|
|
else:
|
|
|
|
s = _('%(nick)s is now known as %(new_nick)s') % {
|
2013-07-23 15:55:24 +02:00
|
|
|
'nick': nick, 'new_nick': obj.new_nick}
|
2013-04-25 20:38:18 +02:00
|
|
|
tv = self.conv_textview
|
|
|
|
if obj.nick in tv.last_received_message_marks:
|
|
|
|
tv.last_received_message_marks[obj.new_nick] = \
|
|
|
|
tv.last_received_message_marks[obj.nick]
|
|
|
|
del tv.last_received_message_marks[obj.nick]
|
|
|
|
if obj.nick in self.last_received_txt:
|
|
|
|
self.last_received_txt[obj.new_nick] = \
|
|
|
|
self.last_received_txt[obj.nick]
|
|
|
|
del self.last_received_txt[obj.nick]
|
|
|
|
self.last_received_id[obj.new_nick] = \
|
|
|
|
self.last_received_id[obj.nick]
|
|
|
|
del self.last_received_id[obj.nick]
|
2010-04-08 01:20:17 +02:00
|
|
|
# We add new nick to muc roster here, so we don't see
|
2010-05-20 09:17:56 +02:00
|
|
|
# that "new_nick has joined the room" when he just changed
|
|
|
|
# nick.
|
2010-04-08 01:20:17 +02:00
|
|
|
# add_contact_to_roster will be called a second time
|
|
|
|
# after that, but that doesn't hurt
|
2010-09-28 15:13:51 +02:00
|
|
|
self.add_contact_to_roster(obj.new_nick, obj.show, role,
|
|
|
|
affiliation, obj.status, obj.real_jid)
|
|
|
|
if obj.nick in self.attention_list:
|
|
|
|
self.attention_list.remove(obj.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
# keep nickname color
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.nick in self.gc_custom_colors:
|
|
|
|
self.gc_custom_colors[obj.new_nick] = \
|
|
|
|
self.gc_custom_colors[obj.nick]
|
2010-04-08 01:20:17 +02:00
|
|
|
# rename vcard / avatar
|
|
|
|
puny_jid = helpers.sanitize_filename(self.room_jid)
|
2010-09-28 15:13:51 +02:00
|
|
|
puny_nick = helpers.sanitize_filename(obj.nick)
|
|
|
|
puny_new_nick = helpers.sanitize_filename(obj.new_nick)
|
2010-05-20 09:17:56 +02:00
|
|
|
old_path = os.path.join(gajim.VCARD_PATH, puny_jid,
|
|
|
|
puny_nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
new_path = os.path.join(gajim.VCARD_PATH, puny_jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
puny_new_nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
files = {old_path: new_path}
|
|
|
|
path = os.path.join(gajim.AVATAR_PATH, puny_jid)
|
|
|
|
# possible extensions
|
|
|
|
for ext in ('.png', '.jpeg', '_notif_size_bw.png',
|
|
|
|
'_notif_size_colored.png'):
|
|
|
|
files[os.path.join(path, puny_nick + ext)] = \
|
2010-05-20 09:17:56 +02:00
|
|
|
os.path.join(path, puny_new_nick + ext)
|
2010-04-08 01:20:17 +02:00
|
|
|
for old_file in files:
|
2010-05-20 09:17:56 +02:00
|
|
|
if os.path.exists(old_file) and old_file != \
|
|
|
|
files[old_file]:
|
|
|
|
if os.path.exists(files[old_file]) and \
|
|
|
|
helpers.windowsify(old_file) != helpers.windowsify(
|
|
|
|
files[old_file]):
|
|
|
|
# Windows require this, but os.remove('test')
|
|
|
|
# will also remove 'TEST'
|
2010-04-08 01:20:17 +02:00
|
|
|
os.remove(files[old_file])
|
|
|
|
os.rename(old_file, files[old_file])
|
2010-09-28 15:13:51 +02:00
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
|
|
|
elif '321' in obj.status_code:
|
2010-05-20 09:17:56 +02:00
|
|
|
s = _('%(nick)s has been removed from the room '
|
2013-07-23 15:55:24 +02:00
|
|
|
'(%(reason)s)') % { 'nick': nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'reason': _('affiliation changed') }
|
2010-09-28 15:13:51 +02:00
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
|
|
|
elif '322' in obj.status_code:
|
2010-05-20 09:17:56 +02:00
|
|
|
s = _('%(nick)s has been removed from the room '
|
2013-07-23 15:55:24 +02:00
|
|
|
'(%(reason)s)') % { 'nick': nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'reason': _('room configuration changed to '
|
|
|
|
'members-only') }
|
2010-09-28 15:13:51 +02:00
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
|
|
|
elif '332' in obj.status_code:
|
2010-05-05 08:56:36 +02:00
|
|
|
s = _('%(nick)s has been removed from the room '
|
2013-07-23 15:55:24 +02:00
|
|
|
'(%(reason)s)') % {'nick': nick,
|
2010-05-05 08:56:36 +02:00
|
|
|
'reason': _('system shutdown') }
|
2010-09-28 15:13:51 +02:00
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
# Room has been destroyed.
|
2010-09-28 15:13:51 +02:00
|
|
|
elif 'destroyed' in obj.status_code:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.autorejoin = False
|
2010-10-10 21:20:59 +02:00
|
|
|
self.print_conversation(obj.reason, 'info', graphics=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2010-09-28 15:13:51 +02:00
|
|
|
if len(gajim.events.get_events(self.account, jid=obj.fjid,
|
2010-04-08 01:20:17 +02:00
|
|
|
types=['pm'])) == 0:
|
2010-09-28 15:13:51 +02:00
|
|
|
self.remove_contact(obj.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.draw_all_roles()
|
|
|
|
else:
|
2010-05-05 08:56:36 +02:00
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
2010-09-28 15:13:51 +02:00
|
|
|
obj.nick)
|
|
|
|
c.show = obj.show
|
|
|
|
c.status = obj.status
|
|
|
|
if obj.nick == self.nick and (not obj.status_code or \
|
|
|
|
'303' not in obj.status_code): # We became offline
|
2010-04-08 01:20:17 +02:00
|
|
|
self.got_disconnected()
|
|
|
|
contact = gajim.contacts.\
|
2010-05-05 08:56:36 +02:00
|
|
|
get_contact_with_highest_priority(self.account,
|
|
|
|
self.room_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
if contact:
|
2010-05-05 08:56:36 +02:00
|
|
|
gajim.interface.roster.draw_contact(self.room_jid,
|
|
|
|
self.account)
|
2010-04-08 01:20:17 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
else:
|
2010-09-28 15:13:51 +02:00
|
|
|
iter_ = self.get_contact_iter(obj.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
if not iter_:
|
2010-09-28 15:13:51 +02:00
|
|
|
if '210' in obj.status_code:
|
2010-04-08 01:20:17 +02:00
|
|
|
# Server changed our nick
|
2010-09-28 15:13:51 +02:00
|
|
|
self.nick = obj.nick
|
2013-07-23 15:55:24 +02:00
|
|
|
s = _('You are now known as %s') % nick
|
2010-09-28 15:13:51 +02:00
|
|
|
self.print_conversation(s, 'info', graphics=False)
|
|
|
|
iter_ = self.add_contact_to_roster(obj.nick, obj.show, role,
|
|
|
|
affiliation, obj.status, obj.real_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
newly_created = True
|
|
|
|
self.draw_all_roles()
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.status_code and '201' in obj.status_code:
|
2010-05-05 08:56:36 +02:00
|
|
|
# We just created the room
|
|
|
|
gajim.connections[self.account].request_gc_config(
|
|
|
|
self.room_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-05-05 08:56:36 +02:00
|
|
|
gc_c = gajim.contacts.get_gc_contact(self.account,
|
2010-09-28 15:13:51 +02:00
|
|
|
self.room_jid, obj.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
if not gc_c:
|
2010-05-05 08:56:36 +02:00
|
|
|
log.error('%s has an iter, but no gc_contact instance' % \
|
2010-09-28 15:13:51 +02:00
|
|
|
obj.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
return
|
|
|
|
# Re-get vcard if avatar has changed
|
2010-05-05 08:56:36 +02:00
|
|
|
# We do that here because we may request it to the real JID if
|
|
|
|
# we knows it. connections.py doesn't know it.
|
2010-04-08 01:20:17 +02:00
|
|
|
con = gajim.connections[self.account]
|
|
|
|
if gc_c and gc_c.jid:
|
|
|
|
real_jid = gc_c.jid
|
|
|
|
else:
|
2010-09-28 15:13:51 +02:00
|
|
|
real_jid = obj.fjid
|
|
|
|
if obj.fjid in obj.conn.vcard_shas:
|
|
|
|
if obj.avatar_sha != obj.conn.vcard_shas[obj.fjid]:
|
2010-04-08 01:20:17 +02:00
|
|
|
server = gajim.get_server_from_jid(self.room_jid)
|
|
|
|
if not server.startswith('irc'):
|
2010-09-28 15:13:51 +02:00
|
|
|
obj.conn.request_vcard(real_jid, obj.fjid)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-09-28 15:13:51 +02:00
|
|
|
cached_vcard = obj.conn.get_cached_vcard(obj.fjid, True)
|
2010-04-08 01:20:17 +02:00
|
|
|
if cached_vcard and 'PHOTO' in cached_vcard and \
|
|
|
|
'SHA' in cached_vcard['PHOTO']:
|
|
|
|
cached_sha = cached_vcard['PHOTO']['SHA']
|
|
|
|
else:
|
|
|
|
cached_sha = ''
|
2010-09-28 15:13:51 +02:00
|
|
|
if cached_sha != obj.avatar_sha:
|
2010-04-08 01:20:17 +02:00
|
|
|
# avatar has been updated
|
|
|
|
# sha in mem will be updated later
|
|
|
|
server = gajim.get_server_from_jid(self.room_jid)
|
|
|
|
if not server.startswith('irc'):
|
2010-09-28 15:13:51 +02:00
|
|
|
obj.conn.request_vcard(real_jid, obj.fjid)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
# save sha in mem NOW
|
2010-09-28 15:13:51 +02:00
|
|
|
obj.conn.vcard_shas[obj.fjid] = obj.avatar_sha
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
actual_affiliation = gc_c.affiliation
|
|
|
|
if affiliation != actual_affiliation:
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.actor:
|
2010-04-08 01:20:17 +02:00
|
|
|
st = _('** Affiliation of %(nick)s has been set to '
|
2010-05-20 09:17:56 +02:00
|
|
|
'%(affiliation)s by %(actor)s') % {'nick': nick_jid,
|
2010-09-28 15:13:51 +02:00
|
|
|
'affiliation': affiliation, 'actor': obj.actor}
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
st = _('** Affiliation of %(nick)s has been set to '
|
2010-05-20 09:17:56 +02:00
|
|
|
'%(affiliation)s') % {'nick': nick_jid,
|
|
|
|
'affiliation': affiliation}
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.reason:
|
|
|
|
st += ' (%s)' % obj.reason
|
|
|
|
self.print_conversation(st, graphics=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
right_changed = True
|
2010-09-28 15:13:51 +02:00
|
|
|
actual_role = self.get_role(obj.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
if role != actual_role:
|
2010-09-28 15:13:51 +02:00
|
|
|
self.remove_contact(obj.nick)
|
|
|
|
self.add_contact_to_roster(obj.nick, obj.show, role,
|
|
|
|
affiliation, obj.status, obj.real_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.draw_role(actual_role)
|
|
|
|
self.draw_role(role)
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.actor:
|
2010-05-20 09:17:56 +02:00
|
|
|
st = _('** Role of %(nick)s has been set to %(role)s '
|
|
|
|
'by %(actor)s') % {'nick': nick_jid, 'role': role,
|
2010-09-28 15:13:51 +02:00
|
|
|
'actor': obj.actor}
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-05-20 09:17:56 +02:00
|
|
|
st = _('** Role of %(nick)s has been set to '
|
|
|
|
'%(role)s') % {'nick': nick_jid, 'role': role}
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.reason:
|
|
|
|
st += ' (%s)' % obj.reason
|
|
|
|
self.print_conversation(st, graphics=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
right_changed = True
|
|
|
|
else:
|
2010-09-28 15:13:51 +02:00
|
|
|
if gc_c.show == obj.show and gc_c.status == obj.status and \
|
2010-05-20 09:17:56 +02:00
|
|
|
gc_c.affiliation == affiliation: # no change
|
2010-04-08 01:20:17 +02:00
|
|
|
return
|
2010-09-28 15:13:51 +02:00
|
|
|
gc_c.show = obj.show
|
2010-04-08 01:20:17 +02:00
|
|
|
gc_c.affiliation = affiliation
|
2010-09-28 15:13:51 +02:00
|
|
|
gc_c.status = obj.status
|
|
|
|
self.draw_contact(obj.nick)
|
|
|
|
if (time.time() - self.room_creation) > 30 and obj.nick != self.nick \
|
|
|
|
and (not obj.status_code or '303' not in obj.status_code) and not \
|
|
|
|
right_changed:
|
2010-04-08 01:20:17 +02:00
|
|
|
st = ''
|
|
|
|
print_status = None
|
|
|
|
for bookmark in gajim.connections[self.account].bookmarks:
|
|
|
|
if bookmark['jid'] == self.room_jid:
|
|
|
|
print_status = bookmark.get('print_status', None)
|
|
|
|
break
|
|
|
|
if not print_status:
|
|
|
|
print_status = gajim.config.get('print_status_in_muc')
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.show == 'offline':
|
|
|
|
if obj.nick in self.attention_list:
|
|
|
|
self.attention_list.remove(obj.nick)
|
|
|
|
if obj.show == 'offline' and print_status in ('all', 'in_and_out') \
|
|
|
|
and (not obj.status_code or '307' not in obj.status_code):
|
2010-04-08 01:20:17 +02:00
|
|
|
st = _('%s has left') % nick_jid
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.reason:
|
|
|
|
st += ' [%s]' % obj.reason
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
if newly_created and print_status in ('all', 'in_and_out'):
|
|
|
|
st = _('%s has joined the group chat') % nick_jid
|
|
|
|
elif print_status == 'all':
|
|
|
|
st = _('%(nick)s is now %(status)s') % {'nick': nick_jid,
|
2010-09-28 15:13:51 +02:00
|
|
|
'status': helpers.get_uf_show(obj.show)}
|
2010-04-08 01:20:17 +02:00
|
|
|
if st:
|
2010-09-28 15:13:51 +02:00
|
|
|
if obj.status:
|
|
|
|
st += ' (' + obj.status + ')'
|
|
|
|
self.print_conversation(st, graphics=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def add_contact_to_roster(self, nick, show, role, affiliation, status,
|
2010-04-30 14:18:06 +02:00
|
|
|
jid=''):
|
2010-04-08 01:20:17 +02:00
|
|
|
role_name = helpers.get_uf_role(role, plural=True)
|
|
|
|
|
|
|
|
resource = ''
|
|
|
|
if jid:
|
|
|
|
jids = jid.split('/', 1)
|
|
|
|
j = jids[0]
|
|
|
|
if len(jids) > 1:
|
|
|
|
resource = jids[1]
|
|
|
|
else:
|
|
|
|
j = ''
|
|
|
|
|
|
|
|
name = nick
|
|
|
|
|
|
|
|
role_iter = self.get_role_iter(role)
|
|
|
|
if not role_iter:
|
2011-08-24 11:58:06 +02:00
|
|
|
role_iter = self.model.append(None,
|
2010-10-12 21:50:18 +02:00
|
|
|
[gajim.interface.jabber_state_images['16']['closed'], role,
|
|
|
|
'role', role_name, None] + [None] * self.nb_ext_renderers)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.draw_all_roles()
|
2011-08-24 11:58:06 +02:00
|
|
|
iter_ = self.model.append(role_iter, [None, nick, 'contact', name, None] + \
|
2010-10-12 21:50:18 +02:00
|
|
|
[None] * self.nb_ext_renderers)
|
2010-04-30 14:18:06 +02:00
|
|
|
if not nick in gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid):
|
|
|
|
gc_contact = gajim.contacts.create_gc_contact(
|
|
|
|
room_jid=self.room_jid, account=self.account,
|
|
|
|
name=nick, show=show, status=status, role=role,
|
|
|
|
affiliation=affiliation, jid=j, resource=resource)
|
2010-04-08 01:20:17 +02:00
|
|
|
gajim.contacts.add_gc_contact(self.account, gc_contact)
|
|
|
|
self.draw_contact(nick)
|
|
|
|
self.draw_avatar(nick)
|
|
|
|
# Do not ask avatar to irc rooms as irc transports reply with messages
|
|
|
|
server = gajim.get_server_from_jid(self.room_jid)
|
|
|
|
if gajim.config.get('ask_avatars_on_startup') and \
|
|
|
|
not server.startswith('irc'):
|
|
|
|
fake_jid = self.room_jid + '/' + nick
|
|
|
|
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid)
|
|
|
|
if pixbuf == 'ask':
|
2010-04-30 14:18:06 +02:00
|
|
|
if j and not self.is_anonymous:
|
|
|
|
gajim.connections[self.account].request_vcard(j, fake_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
2010-04-30 14:18:06 +02:00
|
|
|
gajim.connections[self.account].request_vcard(fake_jid,
|
|
|
|
fake_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
if nick == self.nick: # we became online
|
|
|
|
self.got_connected()
|
2012-11-24 07:19:56 +01:00
|
|
|
if self.list_treeview.get_model():
|
|
|
|
self.list_treeview.expand_row((self.model.get_path(role_iter)), False)
|
2010-04-08 01:20:17 +02:00
|
|
|
if self.is_continued:
|
|
|
|
self.draw_banner_text()
|
|
|
|
return iter_
|
|
|
|
|
|
|
|
def get_role_iter(self, role):
|
2012-12-23 16:23:43 +01:00
|
|
|
role_iter = self.model.get_iter_first()
|
2010-04-08 01:20:17 +02:00
|
|
|
while role_iter:
|
2013-01-01 19:44:25 +01:00
|
|
|
role_name = self.model[role_iter][C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
if role == role_name:
|
|
|
|
return role_iter
|
2011-08-24 11:58:06 +02:00
|
|
|
role_iter = self.model.iter_next(role_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
def remove_contact(self, nick):
|
|
|
|
"""
|
|
|
|
Remove a user from the contacts_list
|
|
|
|
"""
|
|
|
|
iter_ = self.get_contact_iter(nick)
|
|
|
|
if not iter_:
|
|
|
|
return
|
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
|
|
|
if gc_contact:
|
|
|
|
gajim.contacts.remove_gc_contact(self.account, gc_contact)
|
2011-08-24 11:58:06 +02:00
|
|
|
parent_iter = self.model.iter_parent(iter_)
|
|
|
|
self.model.remove(iter_)
|
|
|
|
if self.model.iter_n_children(parent_iter) == 0:
|
|
|
|
self.model.remove(parent_iter)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def send_message(self, message, xhtml=None, process_commands=True):
|
|
|
|
"""
|
|
|
|
Call this function to send our message
|
|
|
|
"""
|
|
|
|
if not message:
|
|
|
|
return
|
|
|
|
|
|
|
|
if process_commands and self.process_as_command(message):
|
|
|
|
return
|
|
|
|
|
|
|
|
message = helpers.remove_invalid_xml_chars(message)
|
|
|
|
|
|
|
|
if not message:
|
|
|
|
return
|
|
|
|
|
2010-06-07 19:11:44 +02:00
|
|
|
label = self.get_seclabel()
|
2010-04-08 01:20:17 +02:00
|
|
|
if message != '' or message != '\n':
|
2011-03-10 22:35:26 +01:00
|
|
|
self.save_message(message, 'sent')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2013-04-25 20:38:18 +02:00
|
|
|
def _cb(msg, msg_txt):
|
|
|
|
# we'll save sent message text when we'll receive it in
|
|
|
|
# _nec_gc_message_received
|
|
|
|
self.last_sent_msg = msg
|
|
|
|
if self.correcting:
|
|
|
|
self.correcting = False
|
2013-07-31 16:40:33 +02:00
|
|
|
self.msg_textview.override_background_color(
|
|
|
|
Gtk.StateType.NORMAL, self.old_message_tv_color)
|
2013-04-25 20:38:18 +02:00
|
|
|
|
|
|
|
if self.correcting and self.last_sent_msg:
|
|
|
|
correction_msg = self.last_sent_msg
|
|
|
|
else:
|
|
|
|
correction_msg = None
|
2010-04-08 01:20:17 +02:00
|
|
|
# Send the message
|
2013-07-19 11:52:37 +02:00
|
|
|
gajim.nec.push_outgoing_event(GcMessageOutgoingEvent(None,
|
|
|
|
account=self.account, jid=self.room_jid, message=message,
|
|
|
|
xhtml=xhtml, label=label, callback=_cb,
|
|
|
|
callback_args=[_cb] + [message], correction_msg=correction_msg))
|
2010-04-08 01:20:17 +02:00
|
|
|
self.msg_textview.get_buffer().set_text('')
|
|
|
|
self.msg_textview.grab_focus()
|
|
|
|
|
|
|
|
def get_role(self, nick):
|
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
|
|
|
if gc_contact:
|
|
|
|
return gc_contact.role
|
|
|
|
else:
|
|
|
|
return 'visitor'
|
|
|
|
|
|
|
|
def minimizable(self):
|
|
|
|
if self.contact.jid in gajim.config.get_per('accounts', self.account,
|
|
|
|
'minimized_gc').split(' '):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def minimize(self, status='offline'):
|
|
|
|
# Minimize it
|
|
|
|
win = gajim.interface.msg_win_mgr.get_window(self.contact.jid,
|
|
|
|
self.account)
|
|
|
|
ctrl = win.get_control(self.contact.jid, self.account)
|
|
|
|
|
|
|
|
ctrl_page = win.notebook.page_num(ctrl.widget)
|
|
|
|
control = win.notebook.get_nth_page(ctrl_page)
|
|
|
|
|
|
|
|
win.notebook.remove_page(ctrl_page)
|
|
|
|
control.unparent()
|
|
|
|
ctrl.parent_win = None
|
|
|
|
|
|
|
|
gajim.interface.roster.add_groupchat(self.contact.jid, self.account,
|
2010-05-20 09:17:56 +02:00
|
|
|
status = self.subject)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
del win._controls[self.account][self.contact.jid]
|
|
|
|
|
|
|
|
def shutdown(self, status='offline'):
|
2010-09-28 15:13:51 +02:00
|
|
|
# PluginSystem: calling shutdown of super class (ChatControlBase)
|
2010-04-08 01:20:17 +02:00
|
|
|
# to let it remove it's GUI extension points
|
|
|
|
super(GroupchatControl, self).shutdown()
|
2010-10-12 17:09:53 +02:00
|
|
|
# PluginSystem: removing GUI extension points connected with
|
|
|
|
# GrouphatControl instance object
|
|
|
|
gajim.plugin_manager.remove_gui_extension_point('groupchat_control',
|
|
|
|
self)
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
# Preventing autorejoin from being activated
|
|
|
|
self.autorejoin = False
|
|
|
|
|
2010-09-28 22:38:42 +02:00
|
|
|
gajim.ged.remove_event_handler('gc-presence-received', ged.GUI1,
|
|
|
|
self._nec_gc_presence_received)
|
2010-10-18 22:05:41 +02:00
|
|
|
gajim.ged.remove_event_handler('gc-message-received', ged.GUI1,
|
|
|
|
self._nec_gc_message_received)
|
2010-11-08 22:34:04 +01:00
|
|
|
gajim.ged.remove_event_handler('vcard-published', ged.GUI1,
|
|
|
|
self._nec_vcard_published)
|
2010-11-27 19:12:43 +01:00
|
|
|
gajim.ged.remove_event_handler('vcard-received', ged.GUI1,
|
|
|
|
self._nec_vcard_received)
|
|
|
|
gajim.ged.remove_event_handler('gc-subject-received', ged.GUI1,
|
|
|
|
self._nec_gc_subject_received)
|
2010-11-27 21:02:41 +01:00
|
|
|
gajim.ged.remove_event_handler('gc-config-changed-received', ged.GUI1,
|
|
|
|
self._nec_gc_config_changed_received)
|
2010-11-29 11:11:24 +01:00
|
|
|
gajim.ged.remove_event_handler('signed-in', ged.GUI1,
|
|
|
|
self._nec_signed_in)
|
2011-10-31 09:52:23 +01:00
|
|
|
gajim.ged.remove_event_handler('decrypted-message-received', ged.GUI2,
|
|
|
|
self._nec_decrypted_message_received)
|
2010-09-28 22:38:42 +02:00
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
if self.room_jid in gajim.gc_connected[self.account] and \
|
|
|
|
gajim.gc_connected[self.account][self.room_jid]:
|
|
|
|
# Tell connection to note the date we disconnect to avoid duplicate
|
|
|
|
# logs. We do it only when connected because if connection was lost
|
|
|
|
# there may be new messages since disconnection.
|
|
|
|
gajim.connections[self.account].gc_got_disconnected(self.room_jid)
|
2011-03-29 15:18:50 +02:00
|
|
|
gajim.connections[self.account].send_gc_status(self.nick,
|
|
|
|
self.room_jid, show='offline', status=status)
|
2010-04-08 01:20:17 +02:00
|
|
|
nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid)
|
|
|
|
for nick in nick_list:
|
|
|
|
# Update pm chat window
|
|
|
|
fjid = self.room_jid + '/' + nick
|
2010-05-20 09:17:56 +02:00
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_gc_control(fjid,
|
|
|
|
self.account)
|
2010-04-08 01:20:17 +02:00
|
|
|
if ctrl:
|
2010-05-20 09:17:56 +02:00
|
|
|
contact = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
contact.show = 'offline'
|
|
|
|
contact.status = ''
|
|
|
|
ctrl.update_ui()
|
|
|
|
ctrl.parent_win.redraw_tab(ctrl)
|
|
|
|
for sess in gajim.connections[self.account].get_sessions(fjid):
|
|
|
|
if sess.control:
|
|
|
|
sess.control.no_autonegotiation = False
|
|
|
|
if sess.enable_encryption:
|
|
|
|
sess.terminate_e2e()
|
|
|
|
gajim.connections[self.account].delete_session(fjid,
|
2010-05-20 09:17:56 +02:00
|
|
|
sess.thread_id)
|
2010-04-08 01:20:17 +02:00
|
|
|
# They can already be removed by the destroy function
|
|
|
|
if self.room_jid in gajim.contacts.get_gc_list(self.account):
|
|
|
|
gajim.contacts.remove_room(self.account, self.room_jid)
|
|
|
|
del gajim.gc_connected[self.account][self.room_jid]
|
|
|
|
# Save hpaned position
|
|
|
|
gajim.config.set('gc-hpaned-position', self.hpaned.get_position())
|
|
|
|
# remove all register handlers on wigets, created by self.xml
|
|
|
|
# to prevent circular references among objects
|
2013-01-03 14:26:12 +01:00
|
|
|
for i in list(self.handlers.keys()):
|
2010-04-08 01:20:17 +02:00
|
|
|
if self.handlers[i].handler_is_connected(i):
|
|
|
|
self.handlers[i].disconnect(i)
|
|
|
|
del self.handlers[i]
|
|
|
|
# Remove unread events from systray
|
|
|
|
gajim.events.remove_events(self.account, self.room_jid)
|
|
|
|
|
|
|
|
def safe_shutdown(self):
|
|
|
|
if self.minimizable():
|
|
|
|
return True
|
|
|
|
includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
|
|
|
|
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')
|
|
|
|
# whether to ask for comfirmation before closing muc
|
2010-05-20 09:17:56 +02:00
|
|
|
if (gajim.config.get('confirm_close_muc') or self.room_jid in includes)\
|
|
|
|
and gajim.gc_connected[self.account][self.room_jid] and self.room_jid \
|
|
|
|
not in excludes:
|
2010-04-08 01:20:17 +02:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def allow_shutdown(self, method, on_yes, on_no, on_minimize):
|
|
|
|
if self.minimizable():
|
|
|
|
on_minimize(self)
|
|
|
|
return
|
|
|
|
if method == self.parent_win.CLOSE_ESC:
|
|
|
|
iter_ = self.list_treeview.get_selection().get_selected()[1]
|
|
|
|
if iter_:
|
|
|
|
self.list_treeview.get_selection().unselect_all()
|
|
|
|
on_no(self)
|
|
|
|
return
|
|
|
|
includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
|
|
|
|
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')
|
|
|
|
# whether to ask for comfirmation before closing muc
|
2010-05-20 09:17:56 +02:00
|
|
|
if (gajim.config.get('confirm_close_muc') or self.room_jid in includes)\
|
|
|
|
and gajim.gc_connected[self.account][self.room_jid] and self.room_jid \
|
|
|
|
not in excludes:
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_ok(clicked):
|
|
|
|
if clicked:
|
|
|
|
# user does not want to be asked again
|
|
|
|
gajim.config.set('confirm_close_muc', False)
|
|
|
|
on_yes(self)
|
|
|
|
|
|
|
|
def on_cancel(clicked):
|
|
|
|
if clicked:
|
|
|
|
# user does not want to be asked again
|
|
|
|
gajim.config.set('confirm_close_muc', False)
|
|
|
|
on_no(self)
|
|
|
|
|
|
|
|
pritext = _('Are you sure you want to leave group chat "%s"?')\
|
2010-05-20 09:17:56 +02:00
|
|
|
% self.name
|
2010-04-08 01:20:17 +02:00
|
|
|
sectext = _('If you close this window, you will be disconnected '
|
2010-05-20 09:17:56 +02:00
|
|
|
'from this group chat.')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
dialogs.ConfirmationDialogCheck(pritext, sectext,
|
2010-05-21 09:38:09 +02:00
|
|
|
_('_Do not ask me again'), on_response_ok=on_ok,
|
2013-08-15 23:14:42 +02:00
|
|
|
on_response_cancel=on_cancel,
|
|
|
|
transient_for=self.parent_win.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
on_yes(self)
|
|
|
|
|
|
|
|
def set_control_active(self, state):
|
|
|
|
self.conv_textview.allow_focus_out_line = True
|
|
|
|
self.attention_flag = False
|
|
|
|
ChatControlBase.set_control_active(self, state)
|
|
|
|
if not state:
|
|
|
|
# add the focus-out line to the tab we are leaving
|
|
|
|
self.check_and_possibly_add_focus_out_line()
|
|
|
|
# Sending active to undo unread state
|
|
|
|
self.parent_win.redraw_tab(self, 'active')
|
|
|
|
|
|
|
|
def get_specific_unread(self):
|
|
|
|
# returns the number of the number of unread msgs
|
|
|
|
# for room_jid & number of unread private msgs with each contact
|
|
|
|
# that we have
|
|
|
|
nb = 0
|
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
nb += len(gajim.events.get_events(self.account, fjid))
|
|
|
|
# gc can only have messages as event
|
|
|
|
return nb
|
|
|
|
|
|
|
|
def _on_change_subject_menuitem_activate(self, widget):
|
|
|
|
def on_ok(subject):
|
|
|
|
# Note, we don't update self.subject since we don't know whether it
|
|
|
|
# will work yet
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.connections[self.account].send_gc_subject(self.room_jid,
|
|
|
|
subject)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
dialogs.InputTextDialog(_('Changing Subject'),
|
2010-05-20 09:17:56 +02:00
|
|
|
_('Please specify the new subject:'), input_str=self.subject,
|
|
|
|
ok_handler=on_ok)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def _on_change_nick_menuitem_activate(self, widget):
|
|
|
|
if 'change_nick_dialog' in gajim.interface.instances:
|
|
|
|
gajim.interface.instances['change_nick_dialog'].present()
|
|
|
|
else:
|
|
|
|
title = _('Changing Nickname')
|
|
|
|
prompt = _('Please specify the new nickname you want to use:')
|
|
|
|
gajim.interface.instances['change_nick_dialog'] = \
|
2010-03-25 19:52:27 +01:00
|
|
|
dialogs.ChangeNickDialog(self.account, self.room_jid, title,
|
|
|
|
prompt, change_nick=True)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def _on_configure_room_menuitem_activate(self, widget):
|
2010-05-20 09:17:56 +02:00
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
self.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
if c.affiliation == 'owner':
|
|
|
|
gajim.connections[self.account].request_gc_config(self.room_jid)
|
|
|
|
elif c.affiliation == 'admin':
|
|
|
|
if self.room_jid not in gajim.interface.instances[self.account][
|
|
|
|
'gc_config']:
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.interface.instances[self.account]['gc_config'][
|
|
|
|
self.room_jid] = config.GroupchatConfigWindow(self.account,
|
|
|
|
self.room_jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def _on_destroy_room_menuitem_activate(self, widget):
|
|
|
|
def on_ok(reason, jid):
|
|
|
|
if jid:
|
|
|
|
# Test jid
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(jid)
|
|
|
|
except Exception:
|
|
|
|
dialogs.ErrorDialog(_('Invalid group chat Jabber ID'),
|
|
|
|
_('The group chat Jabber ID has not allowed characters.'))
|
|
|
|
return
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.connections[self.account].destroy_gc_room(self.room_jid,
|
|
|
|
reason, jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# Ask for a reason
|
2013-08-11 14:44:46 +02:00
|
|
|
dialogs.DoubleInputDialog(_('Destroying %s') % '\u200E' + \
|
2013-08-05 22:27:15 +02:00
|
|
|
self.room_jid, _('You are going to definitively destroy this '
|
|
|
|
'room.\nYou may specify a reason below:'),
|
2013-08-15 23:14:42 +02:00
|
|
|
_('You may also enter an alternate venue:'), ok_handler=on_ok,
|
|
|
|
transient_for=self.parent_win.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def _on_bookmark_room_menuitem_activate(self, widget):
|
|
|
|
"""
|
|
|
|
Bookmark the room, without autojoin and not minimized
|
|
|
|
"""
|
|
|
|
password = gajim.gc_passwords.get(self.room_jid, '')
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.interface.add_gc_bookmark(self.account, self.name, self.room_jid,\
|
|
|
|
'0', '0', password, self.nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
2011-04-26 15:54:46 +02:00
|
|
|
def _on_request_voice_menuitem_activate(self, widget):
|
|
|
|
"""
|
|
|
|
Request voice in the current room
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].request_voice(self.room_jid)
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
def _on_drag_data_received(self, widget, context, x, y, selection,
|
2010-05-20 09:17:56 +02:00
|
|
|
target_type, timestamp):
|
2010-04-08 01:20:17 +02:00
|
|
|
# Invite contact to groupchat
|
|
|
|
treeview = gajim.interface.roster.tree
|
|
|
|
model = treeview.get_model()
|
|
|
|
if not selection.data or target_type == 80:
|
|
|
|
# target_type = 80 means a file is dropped
|
|
|
|
return
|
|
|
|
data = selection.data
|
|
|
|
path = treeview.get_selection().get_selected_rows()[1][0]
|
|
|
|
iter_ = model.get_iter(path)
|
|
|
|
type_ = model[iter_][2]
|
|
|
|
if type_ != 'contact': # source is not a contact
|
|
|
|
return
|
2013-01-01 19:44:25 +01:00
|
|
|
contact_jid = data
|
2010-04-08 01:20:17 +02:00
|
|
|
gajim.connections[self.account].send_invite(self.room_jid, contact_jid)
|
2012-08-20 15:46:20 +02:00
|
|
|
self.print_conversation(_('%(jid)s has been invited in this room') % {
|
|
|
|
'jid': contact_jid}, graphics=False)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def handle_message_textview_mykey_press(self, widget, event_keyval,
|
2010-05-20 09:17:56 +02:00
|
|
|
event_keymod):
|
2010-04-08 01:20:17 +02:00
|
|
|
# NOTE: handles mykeypress which is custom signal connected to this
|
|
|
|
# CB in new_room(). for this singal see message_textview.py
|
|
|
|
|
2010-08-09 12:14:59 +02:00
|
|
|
if not widget.get_sensitive():
|
|
|
|
# Textview is not sensitive, don't handle keypress
|
|
|
|
return
|
2010-04-08 01:20:17 +02:00
|
|
|
# construct event instance from binding
|
2012-12-27 21:58:52 +01:00
|
|
|
event = Gdk.Event(Gdk.EventType.KEY_PRESS) # it's always a key-press here
|
2010-04-08 01:20:17 +02:00
|
|
|
event.keyval = event_keyval
|
|
|
|
event.state = event_keymod
|
|
|
|
event.time = 0 # assign current time
|
|
|
|
|
|
|
|
message_buffer = widget.get_buffer()
|
|
|
|
start_iter, end_iter = message_buffer.get_bounds()
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval == Gdk.KEY_Tab: # TAB
|
2010-04-08 01:20:17 +02:00
|
|
|
cursor_position = message_buffer.get_insert()
|
|
|
|
end_iter = message_buffer.get_iter_at_mark(cursor_position)
|
|
|
|
text = message_buffer.get_text(start_iter, end_iter, False).decode(
|
2010-05-20 09:17:56 +02:00
|
|
|
'utf-8')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
splitted_text = text.split()
|
|
|
|
|
|
|
|
# HACK: Not the best soltution.
|
|
|
|
if (text.startswith(self.COMMAND_PREFIX) and not
|
2010-05-20 09:17:56 +02:00
|
|
|
text.startswith(self.COMMAND_PREFIX * 2) and \
|
|
|
|
len(splitted_text) == 1):
|
|
|
|
return super(GroupchatControl, self).\
|
|
|
|
handle_message_textview_mykey_press(widget, event_keyval,
|
|
|
|
event_keymod)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# nick completion
|
|
|
|
# check if tab is pressed with empty message
|
|
|
|
if len(splitted_text): # if there are any words
|
|
|
|
begin = splitted_text[-1] # last word we typed
|
|
|
|
else:
|
|
|
|
begin = ''
|
|
|
|
|
|
|
|
gc_refer_to_nick_char = gajim.config.get('gc_refer_to_nick_char')
|
|
|
|
with_refer_to_nick_char = False
|
|
|
|
after_nick_len = 1 # the space that is printed after we type [Tab]
|
|
|
|
|
|
|
|
# first part of this if : works fine even if refer_to_nick_char
|
|
|
|
if gc_refer_to_nick_char and text.endswith(
|
|
|
|
gc_refer_to_nick_char + ' '):
|
|
|
|
with_refer_to_nick_char = True
|
|
|
|
after_nick_len = len(gc_refer_to_nick_char + ' ')
|
|
|
|
if len(self.nick_hits) and self.last_key_tabs and \
|
|
|
|
text[:-after_nick_len].endswith(self.nick_hits[0]):
|
|
|
|
# we should cycle
|
2010-05-20 09:17:56 +02:00
|
|
|
# Previous nick in list may had a space inside, so we check text
|
|
|
|
# and not splitted_text and store it into 'begin' var
|
2010-04-08 01:20:17 +02:00
|
|
|
self.nick_hits.append(self.nick_hits[0])
|
|
|
|
begin = self.nick_hits.pop(0)
|
|
|
|
else:
|
|
|
|
self.nick_hits = [] # clear the hit list
|
|
|
|
list_nick = gajim.contacts.get_nick_list(self.account,
|
2010-05-20 09:17:56 +02:00
|
|
|
self.room_jid)
|
2013-01-01 21:06:16 +01:00
|
|
|
list_nick.sort(key=str.lower) # case-insensitive sort
|
2010-04-08 01:20:17 +02:00
|
|
|
if begin == '':
|
|
|
|
# empty message, show lasts nicks that highlighted us first
|
|
|
|
for nick in self.attention_list:
|
|
|
|
if nick in list_nick:
|
|
|
|
list_nick.remove(nick)
|
|
|
|
list_nick.insert(0, nick)
|
|
|
|
|
|
|
|
list_nick.remove(self.nick) # Skip self
|
|
|
|
for nick in list_nick:
|
2013-07-29 22:05:39 +02:00
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
if nick.lower().startswith(begin.lower()) and not \
|
|
|
|
helpers.jid_is_blocked(self.account, fjid):
|
2010-04-08 01:20:17 +02:00
|
|
|
# the word is the begining of a nick
|
|
|
|
self.nick_hits.append(nick)
|
|
|
|
if len(self.nick_hits):
|
|
|
|
if len(splitted_text) < 2 or with_refer_to_nick_char:
|
|
|
|
# This is the 1st word of the line or no word or we are cycling
|
|
|
|
# at the beginning, possibly with a space in one nick
|
|
|
|
add = gc_refer_to_nick_char + ' '
|
|
|
|
else:
|
|
|
|
add = ' '
|
|
|
|
start_iter = end_iter.copy()
|
|
|
|
if self.last_key_tabs and with_refer_to_nick_char or (text and \
|
|
|
|
text[-1] == ' '):
|
|
|
|
# have to accomodate for the added space from last
|
|
|
|
# completion
|
|
|
|
# gc_refer_to_nick_char may be more than one char!
|
|
|
|
start_iter.backward_chars(len(begin) + len(add))
|
|
|
|
elif self.last_key_tabs and not gajim.config.get(
|
|
|
|
'shell_like_completion'):
|
|
|
|
# have to accomodate for the added space from last
|
|
|
|
# completion
|
|
|
|
start_iter.backward_chars(len(begin) + \
|
2010-05-20 09:17:56 +02:00
|
|
|
len(gc_refer_to_nick_char))
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
start_iter.backward_chars(len(begin))
|
|
|
|
|
|
|
|
message_buffer.delete(start_iter, end_iter)
|
|
|
|
# get a shell-like completion
|
2010-05-20 09:17:56 +02:00
|
|
|
# if there's more than one nick for this completion, complete
|
|
|
|
# only the part that all these nicks have in common
|
2010-04-08 01:20:17 +02:00
|
|
|
if gajim.config.get('shell_like_completion') and \
|
|
|
|
len(self.nick_hits) > 1:
|
|
|
|
end = False
|
|
|
|
completion = ''
|
|
|
|
add = "" # if nick is not complete, don't add anything
|
|
|
|
while not end and len(completion) < len(self.nick_hits[0]):
|
|
|
|
completion = self.nick_hits[0][:len(completion)+1]
|
|
|
|
for nick in self.nick_hits:
|
|
|
|
if completion.lower() not in nick.lower():
|
|
|
|
end = True
|
|
|
|
completion = completion[:-1]
|
|
|
|
break
|
|
|
|
# if the current nick matches a COMPLETE existing nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
# and if the user tab TWICE, complete that nick (with the
|
|
|
|
# "add")
|
2010-04-08 01:20:17 +02:00
|
|
|
if self.last_key_tabs:
|
|
|
|
for nick in self.nick_hits:
|
|
|
|
if nick == completion:
|
2010-05-20 09:17:56 +02:00
|
|
|
# The user seems to want this nick, so
|
|
|
|
# complete it as if it were the only nick
|
|
|
|
# available
|
2010-04-08 01:20:17 +02:00
|
|
|
add = gc_refer_to_nick_char + ' '
|
|
|
|
else:
|
|
|
|
completion = self.nick_hits[0]
|
|
|
|
message_buffer.insert_at_cursor(completion + add)
|
|
|
|
self.last_key_tabs = True
|
|
|
|
return True
|
|
|
|
self.last_key_tabs = False
|
|
|
|
|
|
|
|
def on_list_treeview_key_press_event(self, widget, event):
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval == Gdk.KEY_Escape:
|
2010-04-08 01:20:17 +02:00
|
|
|
selection = widget.get_selection()
|
|
|
|
iter_ = selection.get_selected()[1]
|
|
|
|
if iter_:
|
|
|
|
widget.get_selection().unselect_all()
|
|
|
|
return True
|
|
|
|
|
|
|
|
def on_list_treeview_row_expanded(self, widget, iter_, path):
|
|
|
|
"""
|
|
|
|
When a row is expanded: change the icon of the arrow
|
|
|
|
"""
|
|
|
|
model = widget.get_model()
|
|
|
|
image = gajim.interface.jabber_state_images['16']['opened']
|
|
|
|
model[iter_][C_IMG] = image
|
|
|
|
|
|
|
|
def on_list_treeview_row_collapsed(self, widget, iter_, path):
|
|
|
|
"""
|
|
|
|
When a row is collapsed: change the icon of the arrow
|
|
|
|
"""
|
|
|
|
model = widget.get_model()
|
|
|
|
image = gajim.interface.jabber_state_images['16']['closed']
|
|
|
|
model[iter_][C_IMG] = image
|
|
|
|
|
|
|
|
def kick(self, widget, nick):
|
|
|
|
"""
|
|
|
|
Kick a user
|
|
|
|
"""
|
|
|
|
def on_ok(reason):
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'none', reason)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# ask for reason
|
|
|
|
dialogs.InputDialog(_('Kicking %s') % nick,
|
2013-08-15 23:14:42 +02:00
|
|
|
_('You may specify a reason below:'), ok_handler=on_ok,
|
|
|
|
transient_for=self.parent_win.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def mk_menu(self, event, iter_):
|
|
|
|
"""
|
|
|
|
Make contact's popup menu
|
|
|
|
"""
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = self.model[iter_][C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
jid = c.jid
|
|
|
|
target_affiliation = c.affiliation
|
|
|
|
target_role = c.role
|
|
|
|
|
|
|
|
# looking for user's affiliation and role
|
|
|
|
user_nick = self.nick
|
|
|
|
user_affiliation = gajim.contacts.get_gc_contact(self.account,
|
2010-05-20 09:17:56 +02:00
|
|
|
self.room_jid, user_nick).affiliation
|
2010-04-08 01:20:17 +02:00
|
|
|
user_role = self.get_role(user_nick)
|
|
|
|
|
|
|
|
# making menu from gtk builder
|
|
|
|
xml = gtkgui_helpers.get_gtk_builder('gc_occupants_menu.ui')
|
|
|
|
|
|
|
|
# these conditions were taken from JEP 0045
|
|
|
|
item = xml.get_object('kick_menuitem')
|
|
|
|
if user_role != 'moderator' or \
|
|
|
|
(user_affiliation == 'admin' and target_affiliation == 'owner') or \
|
|
|
|
(user_affiliation == 'member' and target_affiliation in ('admin',
|
|
|
|
'owner')) or (user_affiliation == 'none' and target_affiliation != \
|
|
|
|
'none'):
|
|
|
|
item.set_sensitive(False)
|
|
|
|
id_ = item.connect('activate', self.kick, nick)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('voice_checkmenuitem')
|
|
|
|
item.set_active(target_role != 'visitor')
|
|
|
|
if user_role != 'moderator' or \
|
|
|
|
user_affiliation == 'none' or \
|
|
|
|
(user_affiliation=='member' and target_affiliation!='none') or \
|
|
|
|
target_affiliation in ('admin', 'owner'):
|
|
|
|
item.set_sensitive(False)
|
|
|
|
id_ = item.connect('activate', self.on_voice_checkmenuitem_activate,
|
2010-05-20 09:17:56 +02:00
|
|
|
nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('moderator_checkmenuitem')
|
|
|
|
item.set_active(target_role == 'moderator')
|
|
|
|
if not user_affiliation in ('admin', 'owner') or \
|
|
|
|
target_affiliation in ('admin', 'owner'):
|
|
|
|
item.set_sensitive(False)
|
|
|
|
id_ = item.connect('activate', self.on_moderator_checkmenuitem_activate,
|
2010-05-20 09:17:56 +02:00
|
|
|
nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('ban_menuitem')
|
|
|
|
if not user_affiliation in ('admin', 'owner') or \
|
|
|
|
(target_affiliation in ('admin', 'owner') and\
|
|
|
|
user_affiliation != 'owner'):
|
|
|
|
item.set_sensitive(False)
|
|
|
|
id_ = item.connect('activate', self.ban, jid)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('member_checkmenuitem')
|
|
|
|
item.set_active(target_affiliation != 'none')
|
|
|
|
if not user_affiliation in ('admin', 'owner') or \
|
2010-05-20 09:17:56 +02:00
|
|
|
(user_affiliation != 'owner' and target_affiliation in ('admin',
|
|
|
|
'owner')):
|
2010-04-08 01:20:17 +02:00
|
|
|
item.set_sensitive(False)
|
2010-05-20 09:17:56 +02:00
|
|
|
id_ = item.connect('activate', self.on_member_checkmenuitem_activate,
|
|
|
|
jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('admin_checkmenuitem')
|
|
|
|
item.set_active(target_affiliation in ('admin', 'owner'))
|
|
|
|
if not user_affiliation == 'owner':
|
|
|
|
item.set_sensitive(False)
|
2010-05-20 09:17:56 +02:00
|
|
|
id_ = item.connect('activate', self.on_admin_checkmenuitem_activate,
|
|
|
|
jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('owner_checkmenuitem')
|
|
|
|
item.set_active(target_affiliation == 'owner')
|
|
|
|
if not user_affiliation == 'owner':
|
|
|
|
item.set_sensitive(False)
|
2010-05-20 09:17:56 +02:00
|
|
|
id_ = item.connect('activate', self.on_owner_checkmenuitem_activate,
|
|
|
|
jid)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
2011-03-30 15:23:10 +02:00
|
|
|
item = xml.get_object('invite_menuitem')
|
|
|
|
muc_icon = gtkgui_helpers.load_icon('muc_active')
|
|
|
|
if muc_icon:
|
|
|
|
item.set_image(muc_icon)
|
2013-12-02 12:17:32 +01:00
|
|
|
if jid and c.name != self.nick:
|
|
|
|
bookmarked = False
|
|
|
|
contact = gajim.contacts.get_contact(self.account, jid, c.resource)
|
|
|
|
if contact and contact.supports(nbxmpp.NS_CONFERENCE):
|
|
|
|
bookmarked=True
|
2011-03-30 15:23:10 +02:00
|
|
|
gui_menu_builder.build_invite_submenu(item, ((c, self.account),),
|
2013-12-02 12:17:32 +01:00
|
|
|
ignore_rooms=[self.room_jid], show_bookmarked=bookmarked)
|
2011-03-30 15:23:10 +02:00
|
|
|
else:
|
|
|
|
item.set_sensitive(False)
|
|
|
|
|
2010-04-08 01:20:17 +02:00
|
|
|
item = xml.get_object('information_menuitem')
|
|
|
|
id_ = item.connect('activate', self.on_info, nick)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('history_menuitem')
|
2013-03-17 20:14:34 +01:00
|
|
|
if gtkgui_helpers.gtk_icon_theme.has_icon('document-open-recent'):
|
|
|
|
img = Gtk.Image()
|
|
|
|
img.set_from_icon_name('document-open-recent', Gtk.IconSize.MENU)
|
|
|
|
item.set_image(img)
|
2010-04-08 01:20:17 +02:00
|
|
|
id_ = item.connect('activate', self.on_history, nick)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('add_to_roster_menuitem')
|
|
|
|
our_jid = gajim.get_jid_from_account(self.account)
|
2011-08-09 17:14:13 +02:00
|
|
|
if not jid or jid == our_jid or not gajim.connections[self.account].\
|
|
|
|
roster_supported:
|
2010-04-08 01:20:17 +02:00
|
|
|
item.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
id_ = item.connect('activate', self.on_add_to_roster, jid)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('block_menuitem')
|
|
|
|
item2 = xml.get_object('unblock_menuitem')
|
|
|
|
if helpers.jid_is_blocked(self.account, fjid):
|
|
|
|
item.set_no_show_all(True)
|
|
|
|
item.hide()
|
|
|
|
id_ = item2.connect('activate', self.on_unblock, nick)
|
|
|
|
self.handlers[id_] = item2
|
|
|
|
else:
|
|
|
|
id_ = item.connect('activate', self.on_block, nick)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
item2.set_no_show_all(True)
|
|
|
|
item2.hide()
|
|
|
|
|
|
|
|
item = xml.get_object('send_private_message_menuitem')
|
2011-08-24 11:58:06 +02:00
|
|
|
id_ = item.connect('activate', self.on_send_pm, self.model, iter_)
|
2010-04-08 01:20:17 +02:00
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = xml.get_object('send_file_menuitem')
|
|
|
|
# add a special img for send file menuitem
|
2013-08-28 16:33:27 +02:00
|
|
|
pixbuf = gtkgui_helpers.get_icon_pixmap('document-send', quiet=True)
|
|
|
|
if not pixbuf:
|
|
|
|
pixbuf = gtkgui_helpers.get_icon_pixmap('gajim-upload')
|
|
|
|
img = Gtk.Image.new_from_pixbuf(pixbuf)
|
2010-04-08 01:20:17 +02:00
|
|
|
item.set_image(img)
|
|
|
|
|
|
|
|
if not c.resource:
|
|
|
|
item.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
id_ = item.connect('activate', self.on_send_file, c)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
# show the popup now!
|
|
|
|
menu = xml.get_object('gc_occupants_menu')
|
|
|
|
menu.show_all()
|
2013-01-06 22:29:22 +01:00
|
|
|
menu.attach_to_widget(gajim.interface.roster.window, None)
|
2012-12-27 21:58:52 +01:00
|
|
|
menu.popup(None, None, None, None, event.button, event.time)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def _start_private_message(self, nick):
|
|
|
|
gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
|
|
|
nick_jid = gc_c.get_full_jid()
|
|
|
|
|
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(nick_jid, self.account)
|
|
|
|
if not ctrl:
|
|
|
|
ctrl = gajim.interface.new_private_chat(gc_c, self.account)
|
|
|
|
|
|
|
|
if ctrl:
|
|
|
|
ctrl.parent_win.set_active_tab(ctrl)
|
|
|
|
|
|
|
|
return ctrl
|
|
|
|
|
|
|
|
def on_row_activated(self, widget, path):
|
|
|
|
"""
|
|
|
|
When an iter is activated (dubblick or single click if gnome is set this
|
|
|
|
way
|
|
|
|
"""
|
2013-01-08 16:41:51 +01:00
|
|
|
if path.get_depth() == 1: # It's a group
|
2010-04-08 01:20:17 +02:00
|
|
|
if (widget.row_expanded(path)):
|
|
|
|
widget.collapse_row(path)
|
|
|
|
else:
|
|
|
|
widget.expand_row(path, False)
|
|
|
|
else: # We want to send a private message
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = self.model[path][C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
self._start_private_message(nick)
|
|
|
|
|
|
|
|
def on_list_treeview_row_activated(self, widget, path, col=0):
|
|
|
|
"""
|
|
|
|
When an iter is double clicked: open the chat window
|
|
|
|
"""
|
|
|
|
if not gajim.single_click:
|
|
|
|
self.on_row_activated(widget, path)
|
|
|
|
|
|
|
|
def on_list_treeview_button_press_event(self, widget, event):
|
|
|
|
"""
|
|
|
|
Popup user's group's or agent menu
|
|
|
|
"""
|
|
|
|
# hide tooltip, no matter the button is pressed
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
try:
|
|
|
|
pos = widget.get_path_at_pos(int(event.x), int(event.y))
|
|
|
|
path, x = pos[0], pos[2]
|
|
|
|
except TypeError:
|
|
|
|
widget.get_selection().unselect_all()
|
|
|
|
return
|
|
|
|
if event.button == 3: # right click
|
|
|
|
widget.get_selection().select_path(path)
|
2011-08-24 11:58:06 +02:00
|
|
|
iter_ = self.model.get_iter(path)
|
2013-01-06 22:29:22 +01:00
|
|
|
if path.get_depth() == 2:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.mk_menu(event, iter_)
|
|
|
|
return True
|
|
|
|
|
|
|
|
elif event.button == 2: # middle click
|
|
|
|
widget.get_selection().select_path(path)
|
2011-08-24 11:58:06 +02:00
|
|
|
iter_ = self.model.get_iter(path)
|
2013-01-08 16:46:12 +01:00
|
|
|
if path.get_depth() == 2:
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = self.model[iter_][C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
self._start_private_message(nick)
|
|
|
|
return True
|
|
|
|
|
|
|
|
elif event.button == 1: # left click
|
2012-12-23 16:23:43 +01:00
|
|
|
if gajim.single_click and not event.get_state() & Gdk.ModifierType.SHIFT_MASK:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.on_row_activated(widget, path)
|
|
|
|
return True
|
|
|
|
else:
|
2011-08-24 11:58:06 +02:00
|
|
|
iter_ = self.model.get_iter(path)
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = self.model[iter_][C_NICK]
|
2010-04-08 01:20:17 +02:00
|
|
|
if not nick in gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid):
|
|
|
|
# it's a group
|
|
|
|
if x < 27:
|
|
|
|
if (widget.row_expanded(path)):
|
|
|
|
widget.collapse_row(path)
|
|
|
|
else:
|
|
|
|
widget.expand_row(path, False)
|
2012-12-23 16:23:43 +01:00
|
|
|
elif event.get_state() & Gdk.ModifierType.SHIFT_MASK:
|
2010-04-08 01:20:17 +02:00
|
|
|
self.append_nick_in_msg_textview(self.msg_textview, nick)
|
|
|
|
self.msg_textview.grab_focus()
|
|
|
|
return True
|
|
|
|
|
|
|
|
def append_nick_in_msg_textview(self, widget, nick):
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
start_iter, end_iter = message_buffer.get_bounds()
|
|
|
|
cursor_position = message_buffer.get_insert()
|
|
|
|
end_iter = message_buffer.get_iter_at_mark(cursor_position)
|
|
|
|
text = message_buffer.get_text(start_iter, end_iter, False)
|
|
|
|
start = ''
|
|
|
|
if text: # Cursor is not at first position
|
|
|
|
if not text[-1] in (' ', '\n', '\t'):
|
|
|
|
start = ' '
|
|
|
|
add = ' '
|
|
|
|
else:
|
|
|
|
gc_refer_to_nick_char = gajim.config.get('gc_refer_to_nick_char')
|
|
|
|
add = gc_refer_to_nick_char + ' '
|
|
|
|
message_buffer.insert_at_cursor(start + nick + add)
|
|
|
|
|
|
|
|
def on_list_treeview_motion_notify_event(self, widget, event):
|
|
|
|
props = widget.get_path_at_pos(int(event.x), int(event.y))
|
|
|
|
if self.tooltip.timeout > 0:
|
|
|
|
if not props or self.tooltip.id != props[0]:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
if props:
|
|
|
|
[row, col, x, y] = props
|
|
|
|
iter_ = None
|
|
|
|
try:
|
2011-08-24 11:58:06 +02:00
|
|
|
iter_ = self.model.get_iter(row)
|
2010-04-08 01:20:17 +02:00
|
|
|
except Exception:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
return
|
2013-01-01 19:44:25 +01:00
|
|
|
typ = self.model[iter_][C_TYPE]
|
2010-04-08 01:20:17 +02:00
|
|
|
if typ == 'contact':
|
|
|
|
account = self.account
|
|
|
|
|
|
|
|
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
|
|
|
|
self.tooltip.id = row
|
2013-01-01 19:44:25 +01:00
|
|
|
nick = self.model[iter_][C_NICK]
|
2013-07-28 20:50:30 +02:00
|
|
|
self.tooltip.timeout = GLib.timeout_add(500,
|
2010-05-20 09:17:56 +02:00
|
|
|
self.show_tooltip, gajim.contacts.get_gc_contact(
|
|
|
|
account, self.room_jid, nick))
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_list_treeview_leave_notify_event(self, widget, event):
|
|
|
|
props = widget.get_path_at_pos(int(event.x), int(event.y))
|
|
|
|
if self.tooltip.timeout > 0:
|
|
|
|
if not props or self.tooltip.id == props[0]:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
|
|
|
|
def show_tooltip(self, contact):
|
2013-01-02 14:30:54 +01:00
|
|
|
if not self.list_treeview.get_window():
|
2010-04-08 01:20:17 +02:00
|
|
|
# control has been destroyed since tooltip was requested
|
|
|
|
return
|
2013-07-29 14:38:09 +02:00
|
|
|
w = self.list_treeview.get_window()
|
|
|
|
device = w.get_display().get_device_manager().get_client_pointer()
|
|
|
|
pointer = w.get_device_position(device)
|
|
|
|
props = self.list_treeview.get_path_at_pos(pointer[1], pointer[2])
|
2010-04-08 01:20:17 +02:00
|
|
|
# check if the current pointer is at the same path
|
|
|
|
# as it was before setting the timeout
|
|
|
|
if props and self.tooltip.id == props[0]:
|
|
|
|
rect = self.list_treeview.get_cell_area(props[0], props[1])
|
2013-07-29 14:38:09 +02:00
|
|
|
position = w.get_origin()[1:]
|
2010-04-08 01:20:17 +02:00
|
|
|
self.tooltip.show_tooltip(contact, rect.height,
|
2010-05-20 09:17:56 +02:00
|
|
|
position[1] + rect.y)
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
|
|
|
|
def grant_voice(self, widget, nick):
|
|
|
|
"""
|
|
|
|
Grant voice privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'participant')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def revoke_voice(self, widget, nick):
|
|
|
|
"""
|
|
|
|
Revoke voice privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'visitor')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def grant_moderator(self, widget, nick):
|
|
|
|
"""
|
|
|
|
Grant moderator privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'moderator')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def revoke_moderator(self, widget, nick):
|
|
|
|
"""
|
|
|
|
Revoke moderator privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
2010-05-20 09:17:56 +02:00
|
|
|
'participant')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def ban(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Ban a user
|
|
|
|
"""
|
|
|
|
def on_ok(reason):
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid,
|
|
|
|
jid, 'outcast', reason)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
# to ban we know the real jid. so jid is not fakejid
|
|
|
|
nick = gajim.get_nick_from_jid(jid)
|
|
|
|
# ask for reason
|
|
|
|
dialogs.InputDialog(_('Banning %s') % nick,
|
2013-08-15 23:14:42 +02:00
|
|
|
_('You may specify a reason below:'), ok_handler=on_ok,
|
|
|
|
transient_for=self.parent_win.window)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def grant_membership(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Grant membership privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
'member')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def revoke_membership(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Revoke membership privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
'none')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def grant_admin(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Grant administrative privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
'admin')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def revoke_admin(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Revoke administrative privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
'member')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def grant_owner(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Grant owner privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
'owner')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def revoke_owner(self, widget, jid):
|
|
|
|
"""
|
|
|
|
Revoke owner privilege to a user
|
|
|
|
"""
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2010-05-20 09:17:56 +02:00
|
|
|
'admin')
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_info(self, widget, nick):
|
|
|
|
"""
|
|
|
|
Call vcard_information_window class to display user's information
|
|
|
|
"""
|
2010-05-20 09:17:56 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
2010-04-08 01:20:17 +02:00
|
|
|
contact = gc_contact.as_contact()
|
|
|
|
if contact.jid in gajim.interface.instances[self.account]['infos']:
|
2010-05-20 09:17:56 +02:00
|
|
|
gajim.interface.instances[self.account]['infos'][contact.jid].\
|
|
|
|
window.present()
|
2010-04-08 01:20:17 +02:00
|
|
|
else:
|
|
|
|
gajim.interface.instances[self.account]['infos'][contact.jid] = \
|
2010-05-20 09:17:56 +02:00
|
|
|
vcard.VcardWindow(contact, self.account, gc_contact)
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_history(self, widget, nick):
|
|
|
|
jid = gajim.construct_fjid(self.room_jid, nick)
|
|
|
|
self._on_history_menuitem_activate(widget=widget, jid=jid)
|
|
|
|
|
|
|
|
def on_add_to_roster(self, widget, jid):
|
|
|
|
dialogs.AddNewContactWindow(self.account, jid)
|
|
|
|
|
|
|
|
def on_block(self, widget, nick):
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
connection = gajim.connections[self.account]
|
|
|
|
if fjid in connection.blocked_contacts:
|
|
|
|
return
|
2013-05-26 12:58:19 +02:00
|
|
|
max_order = connection.get_max_blocked_list_order()
|
2013-07-28 19:38:49 +02:00
|
|
|
new_rule = {'order': str(max_order + 1), 'type': 'jid',
|
|
|
|
'action': 'deny', 'value' : fjid, 'child': ['message', 'iq',
|
2013-05-26 12:58:19 +02:00
|
|
|
'presence-out']}
|
2010-04-08 01:20:17 +02:00
|
|
|
connection.blocked_list.append(new_rule)
|
|
|
|
connection.blocked_contacts.append(fjid)
|
|
|
|
self.draw_contact(nick)
|
|
|
|
connection.set_privacy_list('block', connection.blocked_list)
|
|
|
|
if len(connection.blocked_list) == 1:
|
|
|
|
connection.set_active_list('block')
|
|
|
|
connection.set_default_list('block')
|
|
|
|
connection.get_privacy_list('block')
|
|
|
|
|
|
|
|
def on_unblock(self, widget, nick):
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
connection = gajim.connections[self.account]
|
|
|
|
connection.new_blocked_list = []
|
|
|
|
# needed for draw_contact:
|
|
|
|
if fjid in connection.blocked_contacts:
|
|
|
|
connection.blocked_contacts.remove(fjid)
|
|
|
|
self.draw_contact(nick)
|
|
|
|
for rule in connection.blocked_list:
|
|
|
|
if rule['action'] != 'deny' or rule['type'] != 'jid' \
|
|
|
|
or rule['value'] != fjid:
|
|
|
|
connection.new_blocked_list.append(rule)
|
|
|
|
|
|
|
|
connection.set_privacy_list('block', connection.new_blocked_list)
|
|
|
|
connection.get_privacy_list('block')
|
|
|
|
if len(connection.new_blocked_list) == 0:
|
|
|
|
connection.blocked_list = []
|
|
|
|
connection.blocked_contacts = []
|
|
|
|
connection.blocked_groups = []
|
|
|
|
connection.set_default_list('')
|
|
|
|
connection.set_active_list('')
|
|
|
|
connection.del_privacy_list('block')
|
2010-11-24 22:48:39 +01:00
|
|
|
if 'privay_list_block' in gajim.interface.instances[self.account]:
|
|
|
|
del gajim.interface.instances[self.account]\
|
|
|
|
['privay_list_block']
|
2010-04-08 01:20:17 +02:00
|
|
|
|
|
|
|
def on_voice_checkmenuitem_activate(self, widget, nick):
|
|
|
|
if widget.get_active():
|
|
|
|
self.grant_voice(widget, nick)
|
|
|
|
else:
|
|
|
|
self.revoke_voice(widget, nick)
|
|
|
|
|
|
|
|
def on_moderator_checkmenuitem_activate(self, widget, nick):
|
|
|
|
if widget.get_active():
|
|
|
|
self.grant_moderator(widget, nick)
|
|
|
|
else:
|
|
|
|
self.revoke_moderator(widget, nick)
|
|
|
|
|
|
|
|
def on_member_checkmenuitem_activate(self, widget, jid):
|
|
|
|
if widget.get_active():
|
|
|
|
self.grant_membership(widget, jid)
|
|
|
|
else:
|
|
|
|
self.revoke_membership(widget, jid)
|
|
|
|
|
|
|
|
def on_admin_checkmenuitem_activate(self, widget, jid):
|
|
|
|
if widget.get_active():
|
|
|
|
self.grant_admin(widget, jid)
|
|
|
|
else:
|
|
|
|
self.revoke_admin(widget, jid)
|
|
|
|
|
|
|
|
def on_owner_checkmenuitem_activate(self, widget, jid):
|
|
|
|
if widget.get_active():
|
|
|
|
self.grant_owner(widget, jid)
|
|
|
|
else:
|
|
|
|
self.revoke_owner(widget, jid)
|