2005-12-31 08:35:14 +01:00
|
|
|
## groupchat_control.py
|
|
|
|
##
|
2006-02-03 08:48:10 +01:00
|
|
|
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
|
|
|
## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
|
2007-01-17 00:26:38 +01:00
|
|
|
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem@gmail.com>
|
2005-12-31 08:35:14 +01:00
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
import os
|
2006-01-05 06:51:28 +01:00
|
|
|
import time
|
2005-12-31 08:35:14 +01:00
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
import gobject
|
|
|
|
import gtkgui_helpers
|
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
|
|
|
|
|
|
|
|
from common import gajim
|
|
|
|
from common import helpers
|
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
|
|
|
|
from conversation_textview import ConversationTextview
|
2006-10-10 17:29:10 +02:00
|
|
|
from common.exceptions import GajimGeneralException
|
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)
|
2006-04-17 23:59:04 +02:00
|
|
|
|
|
|
|
def set_renderer_color(treeview, renderer, set_background = True):
|
|
|
|
'''set style for group row, using PRELIGHT system color'''
|
|
|
|
if set_background:
|
|
|
|
bgcolor = treeview.style.bg[gtk.STATE_PRELIGHT]
|
|
|
|
renderer.set_property('cell-background-gdk', bgcolor)
|
|
|
|
else:
|
|
|
|
fgcolor = treeview.style.fg[gtk.STATE_PRELIGHT]
|
|
|
|
renderer.set_property('foreground-gdk', fgcolor)
|
|
|
|
|
|
|
|
def tree_cell_data_func(column, renderer, model, iter, tv=None):
|
|
|
|
# cell data func is global, because we don't want it to keep
|
|
|
|
# reference to GroupchatControl instance (self)
|
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
if model.iter_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)
|
|
|
|
if isinstance(renderer, gtk.CellRendererText):
|
|
|
|
# foreground property is only with CellRendererText
|
2006-12-17 23:56:16 +01:00
|
|
|
color = gajim.config.get_per('themes', theme, 'contacttextcolor')
|
2006-04-17 23:59:04 +02:00
|
|
|
if color:
|
|
|
|
renderer.set_property('foreground', color)
|
|
|
|
else:
|
|
|
|
renderer.set_property('foreground', None)
|
2006-12-12 23:43:44 +01:00
|
|
|
renderer.set_property('font',
|
|
|
|
gtkgui_helpers.get_theme_font_for_option(theme, 'contactfont'))
|
2006-04-17 23:59:04 +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)
|
|
|
|
if isinstance(renderer, gtk.CellRendererText):
|
|
|
|
# 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)
|
2006-12-07 22:32:53 +01:00
|
|
|
renderer.set_property('font',
|
|
|
|
gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont'))
|
2005-12-31 08:35:14 +01:00
|
|
|
|
2006-01-01 20:40:05 +01:00
|
|
|
class PrivateChatControl(ChatControl):
|
2006-01-02 03:12:34 +01:00
|
|
|
TYPE_ID = message_control.TYPE_PM
|
2006-01-01 20:40:05 +01:00
|
|
|
|
2007-06-07 13:58:56 +02:00
|
|
|
def __init__(self, parent_win, gc_contact, contact, account):
|
2006-10-09 11:40:04 +02:00
|
|
|
room_jid = contact.jid.split('/')[0]
|
2007-06-07 13:58:56 +02:00
|
|
|
room_ctrl = gajim.interface.msg_win_mgr.get_control(room_jid, account)
|
|
|
|
if gajim.interface.minimized_controls.has_key(account) and \
|
|
|
|
gajim.interface.minimized_controls[account].has_key(room_jid):
|
|
|
|
room_ctrl = gajim.interface.minimized_controls[account][room_jid]
|
2006-10-09 11:40:04 +02:00
|
|
|
self.room_name = room_ctrl.name
|
2007-05-20 17:41:20 +02:00
|
|
|
self.gc_contact = gc_contact
|
2007-06-07 13:58:56 +02:00
|
|
|
ChatControl.__init__(self, parent_win, contact, account)
|
2006-01-01 20:40:05 +01:00
|
|
|
self.TYPE_ID = 'pm'
|
|
|
|
|
2006-01-06 07:59:55 +01:00
|
|
|
def send_message(self, message):
|
|
|
|
'''call this function to send our message'''
|
|
|
|
if not message:
|
|
|
|
return
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
# 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)
|
2006-01-06 07:59:55 +01:00
|
|
|
if contact is None:
|
|
|
|
# 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(
|
|
|
|
_('Sending private message failed'),
|
|
|
|
#in second %s code replaces with nickname
|
2006-10-12 04:12:10 +02:00
|
|
|
_('You are no longer in group chat "%s" or "%s" has left.') % \
|
2006-04-02 18:11:21 +02:00
|
|
|
(room, nick))
|
2006-01-06 07:59:55 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
ChatControl.send_message(self, message)
|
2007-06-07 13:58:56 +02:00
|
|
|
|
2006-07-18 11:46:59 +02:00
|
|
|
def update_ui(self):
|
|
|
|
if self.contact.show == 'offline':
|
|
|
|
self.got_disconnected()
|
|
|
|
else:
|
|
|
|
self.got_connected()
|
|
|
|
ChatControl.update_ui(self)
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-01-09 00:14:50 +01:00
|
|
|
|
2005-12-31 08:35:14 +01:00
|
|
|
class GroupchatControl(ChatControlBase):
|
2006-01-02 03:12:34 +01:00
|
|
|
TYPE_ID = message_control.TYPE_GC
|
2007-02-08 20:08:44 +01:00
|
|
|
# alphanum sorted
|
|
|
|
MUC_CMDS = ['ban', 'chat', 'query', 'clear', 'close', 'compact',
|
|
|
|
'help', 'invite', 'join', 'kick', 'leave', 'me', 'msg', 'nick',
|
2007-02-15 16:59:55 +01:00
|
|
|
'part', 'names', 'say', 'topic']
|
2005-12-31 08:35:14 +01:00
|
|
|
|
|
|
|
def __init__(self, parent_win, contact, acct):
|
|
|
|
ChatControlBase.__init__(self, self.TYPE_ID, parent_win,
|
2007-02-08 19:32:10 +01:00
|
|
|
'muc_child_vbox', contact, acct);
|
2006-01-05 06:51:28 +01:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = self.xml.get_widget('muc_window_actions_button')
|
|
|
|
id = widget.connect('clicked', self.on_actions_button_clicked)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = self.xml.get_widget('list_treeview')
|
|
|
|
id = widget.connect('row_expanded', self.on_list_treeview_row_expanded)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
id = widget.connect('row_collapsed',
|
|
|
|
self.on_list_treeview_row_collapsed)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
id = widget.connect('row_activated',
|
|
|
|
self.on_list_treeview_row_activated)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
id = widget.connect('button_press_event',
|
|
|
|
self.on_list_treeview_button_press_event)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
id = widget.connect('key_press_event',
|
|
|
|
self.on_list_treeview_key_press_event)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
id = widget.connect('motion_notify_event',
|
|
|
|
self.on_list_treeview_motion_notify_event)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
id = widget.connect('leave_notify_event',
|
|
|
|
self.on_list_treeview_leave_notify_event)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
self.room_jid = self.contact.jid
|
|
|
|
self.nick = contact.name
|
|
|
|
self.name = self.room_jid.split('@')[0]
|
|
|
|
|
2007-01-10 00:09:14 +01:00
|
|
|
hide_chat_buttons_always = gajim.config.get(
|
2006-09-29 12:43:52 +02:00
|
|
|
'always_hide_groupchat_buttons')
|
2007-01-10 00:09:14 +01:00
|
|
|
self.chat_buttons_set_visible(hide_chat_buttons_always)
|
2006-09-29 12:43:52 +02:00
|
|
|
self.widget_set_visible(self.xml.get_widget('banner_eventbox'),
|
|
|
|
gajim.config.get('hide_groupchat_banner'))
|
|
|
|
self.widget_set_visible(self.xml.get_widget('list_scrolledwindow'),
|
|
|
|
gajim.config.get('hide_groupchat_occupants_list'))
|
2006-01-06 04:36:07 +01:00
|
|
|
|
|
|
|
self._last_selected_contact = None # None or holds jid, account tuple
|
2007-02-08 20:08:44 +01:00
|
|
|
|
2006-01-06 02:54:33 +01:00
|
|
|
# muc attention flag (when we are mentioned in a muc)
|
|
|
|
# if True, the room has mentioned us
|
|
|
|
self.attention_flag = False
|
2007-05-17 17:54:23 +02:00
|
|
|
|
|
|
|
# sorted list of nicks who mentioned us (last at the end)
|
|
|
|
self.attention_list = []
|
2007-02-11 03:35:02 +01:00
|
|
|
self.room_creation = int(time.time()) # Use int to reduce mem usage
|
2006-01-07 23:53:46 +01:00
|
|
|
self.nick_hits = []
|
|
|
|
self.cmd_hits = []
|
2006-01-06 02:54:33 +01:00
|
|
|
self.last_key_tabs = False
|
|
|
|
|
|
|
|
self.subject = ''
|
|
|
|
self.subject_tooltip = gtk.Tooltips()
|
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
self.tooltip = tooltips.GCTooltip()
|
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
# connect the menuitems to their respective functions
|
2006-05-02 17:53:25 +02:00
|
|
|
xm = gtkgui_helpers.get_glade('gc_control_popup_menu.glade')
|
2006-04-17 23:59:04 +02:00
|
|
|
|
|
|
|
widget = xm.get_widget('bookmark_room_menuitem')
|
2006-09-29 12:43:52 +02:00
|
|
|
id = widget.connect('activate',
|
|
|
|
self._on_bookmark_room_menuitem_activate)
|
2006-04-17 23:59:04 +02:00
|
|
|
self.handlers[id] = widget
|
|
|
|
|
2007-06-02 14:03:02 +02:00
|
|
|
self.change_nick_menuitem = xm.get_widget('change_nick_menuitem')
|
|
|
|
id = self.change_nick_menuitem.connect('activate',
|
|
|
|
self._on_change_nick_menuitem_activate)
|
|
|
|
self.handlers[id] = self.change_nick_menuitem
|
2006-04-17 23:59:04 +02:00
|
|
|
|
2007-06-02 14:03:02 +02:00
|
|
|
self.configure_room_menuitem = xm.get_widget('configure_room_menuitem')
|
|
|
|
id = self.configure_room_menuitem.connect('activate',
|
2006-09-29 12:43:52 +02:00
|
|
|
self._on_configure_room_menuitem_activate)
|
2007-06-02 14:03:02 +02:00
|
|
|
self.handlers[id] = self.configure_room_menuitem
|
2006-04-17 23:59:04 +02:00
|
|
|
|
2007-06-02 14:03:02 +02:00
|
|
|
self.destroy_room_menuitem = xm.get_widget('destroy_room_menuitem')
|
|
|
|
id = self.destroy_room_menuitem.connect('activate',
|
2007-03-11 21:14:53 +01:00
|
|
|
self._on_destroy_room_menuitem_activate)
|
2007-06-02 14:03:02 +02:00
|
|
|
self.handlers[id] = self.destroy_room_menuitem
|
2007-03-11 21:14:53 +01:00
|
|
|
|
2007-06-02 14:03:02 +02:00
|
|
|
self.change_subject_menuitem = xm.get_widget('change_subject_menuitem')
|
|
|
|
id = self.change_subject_menuitem.connect('activate',
|
2006-09-29 12:43:52 +02:00
|
|
|
self._on_change_subject_menuitem_activate)
|
2007-06-02 14:03:02 +02:00
|
|
|
self.handlers[id] = self.change_subject_menuitem
|
2006-04-17 23:59:04 +02:00
|
|
|
|
2007-06-02 14:03:02 +02:00
|
|
|
self.compact_view_menuitem = xm.get_widget('compact_view_menuitem')
|
|
|
|
id = self.compact_view_menuitem.connect('activate',
|
|
|
|
self._on_compact_view_menuitem_activate)
|
|
|
|
self.handlers[id] = self.compact_view_menuitem
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = xm.get_widget('history_menuitem')
|
|
|
|
id = widget.connect('activate', self._on_history_menuitem_activate)
|
|
|
|
self.handlers[id] = widget
|
2006-05-07 14:23:28 +02:00
|
|
|
|
2007-05-03 23:02:50 +02:00
|
|
|
widget = xm.get_widget('minimize_menuitem')
|
|
|
|
id = widget.connect('activate', self._on_minimize_menuitem_activate)
|
|
|
|
self.handlers[id] = widget
|
|
|
|
|
2006-01-07 21:43:05 +01:00
|
|
|
self.gc_popup_menu = xm.get_widget('gc_control_popup_menu')
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2006-01-06 02:54:33 +01:00
|
|
|
self.name_label = self.xml.get_widget('banner_name_label')
|
2006-12-12 23:06:24 +01:00
|
|
|
self.event_box = self.xml.get_widget('banner_eventbox')
|
2006-01-06 04:36:07 +01:00
|
|
|
|
|
|
|
# set the position of the current hpaned
|
|
|
|
self.hpaned_position = gajim.config.get('gc-hpaned-position')
|
|
|
|
self.hpaned = self.xml.get_widget('hpaned')
|
|
|
|
self.hpaned.set_position(self.hpaned_position)
|
2006-01-06 02:54:33 +01:00
|
|
|
|
2006-09-29 12:43:52 +02:00
|
|
|
self.list_treeview = self.xml.get_widget('list_treeview')
|
|
|
|
selection = self.list_treeview.get_selection()
|
2006-04-17 23:59:04 +02:00
|
|
|
id = selection.connect('changed',
|
|
|
|
self.on_list_treeview_selection_changed)
|
|
|
|
self.handlers[id] = selection
|
2006-09-29 12:43:52 +02:00
|
|
|
id = self.list_treeview.connect('style-set',
|
|
|
|
self.on_list_treeview_style_set)
|
|
|
|
self.handlers[id] = self.list_treeview
|
2006-01-06 04:36:07 +01:00
|
|
|
# we want to know when the the widget resizes, because that is
|
|
|
|
# an indication that the hpaned has moved...
|
|
|
|
# FIXME: Find a better indicator that the hpaned has moved.
|
2006-04-17 23:59:04 +02:00
|
|
|
id = self.list_treeview.connect('size-allocate',
|
2006-03-16 21:53:39 +01:00
|
|
|
self.on_treeview_size_allocate)
|
2006-04-17 23:59:04 +02:00
|
|
|
self.handlers[id] = self.list_treeview
|
2006-10-07 00:57:23 +02:00
|
|
|
#status_image, shown_nick, type, nickname, avatar
|
2006-03-13 14:25:51 +01:00
|
|
|
store = gtk.TreeStore(gtk.Image, str, str, str, gtk.gdk.Pixbuf)
|
2006-01-06 04:36:07 +01:00
|
|
|
store.set_sort_column_id(C_TEXT, gtk.SORT_ASCENDING)
|
2006-03-13 19:04:19 +01:00
|
|
|
self.list_treeview.set_model(store)
|
|
|
|
|
2006-03-14 00:25:00 +01:00
|
|
|
# columns
|
|
|
|
|
|
|
|
# this col has 3 cells:
|
|
|
|
# first one img, second one text, third is sec pixbuf
|
2006-03-13 19:04:19 +01:00
|
|
|
column = gtk.TreeViewColumn()
|
|
|
|
|
2006-03-16 21:53:39 +01:00
|
|
|
renderer_pixbuf = gtk.CellRendererPixbuf() # avatar image
|
|
|
|
column.pack_start(renderer_pixbuf, expand = False)
|
|
|
|
column.add_attribute(renderer_pixbuf, 'pixbuf', C_AVATAR)
|
2006-04-17 23:59:04 +02:00
|
|
|
column.set_cell_data_func(renderer_pixbuf, tree_cell_data_func,
|
|
|
|
self.list_treeview)
|
|
|
|
renderer_pixbuf.set_property('xalign', 1) # align pixbuf to the right
|
2006-03-16 21:53:39 +01:00
|
|
|
|
2006-03-14 00:25:00 +01:00
|
|
|
renderer_image = cell_renderer_image.CellRendererImage(0, 0) # status img
|
2006-01-06 04:36:07 +01:00
|
|
|
column.pack_start(renderer_image, expand = False)
|
2006-03-13 19:04:19 +01:00
|
|
|
column.add_attribute(renderer_image, 'image', C_IMG)
|
2006-04-17 23:59:04 +02:00
|
|
|
column.set_cell_data_func(renderer_image, tree_cell_data_func,
|
|
|
|
self.list_treeview)
|
2006-03-13 19:04:19 +01:00
|
|
|
|
2006-03-14 00:25:00 +01:00
|
|
|
renderer_text = gtk.CellRendererText() # nickname
|
2006-01-06 04:36:07 +01:00
|
|
|
column.pack_start(renderer_text, expand = True)
|
2006-03-13 19:04:19 +01:00
|
|
|
column.add_attribute(renderer_text, 'markup', C_TEXT)
|
2006-09-29 12:43:52 +02:00
|
|
|
column.set_cell_data_func(renderer_text, tree_cell_data_func,
|
|
|
|
self.list_treeview)
|
2006-03-13 19:04:19 +01:00
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
self.list_treeview.append_column(column)
|
|
|
|
|
|
|
|
# workaround to avoid gtk arrows to be shown
|
2006-03-15 13:28:46 +01:00
|
|
|
column = gtk.TreeViewColumn() # 2nd COLUMN
|
|
|
|
renderer = gtk.CellRendererPixbuf()
|
|
|
|
column.pack_start(renderer, expand = False)
|
|
|
|
self.list_treeview.append_column(column)
|
|
|
|
column.set_visible(False)
|
|
|
|
self.list_treeview.set_expander_column(column)
|
2006-01-06 04:36:07 +01:00
|
|
|
|
2007-01-09 15:23:28 +01:00
|
|
|
gajim.gc_connected[self.account][self.room_jid] = False
|
2007-01-09 15:35:31 +01:00
|
|
|
# disable win, we are not connected yet
|
2007-01-09 15:23:28 +01:00
|
|
|
ChatControlBase.got_disconnected(self)
|
2006-01-06 04:36:07 +01:00
|
|
|
|
2006-01-10 02:47:24 +01:00
|
|
|
self.update_ui()
|
2006-04-18 17:36:16 +02:00
|
|
|
self.conv_textview.tv.grab_focus()
|
2006-01-06 04:36:07 +01:00
|
|
|
self.widget.show_all()
|
|
|
|
|
2006-05-07 14:47:24 +02:00
|
|
|
def on_msg_textview_populate_popup(self, textview, menu):
|
|
|
|
'''we override the default context menu and we prepend Clear
|
|
|
|
and the ability to insert a nick'''
|
2006-09-03 19:04:41 +02:00
|
|
|
ChatControlBase.on_msg_textview_populate_popup(self, textview, menu)
|
2006-05-07 14:47:24 +02:00
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
menu.prepend(item)
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Insert Nickname'))
|
|
|
|
menu.prepend(item)
|
|
|
|
submenu = gtk.Menu()
|
|
|
|
item.set_submenu(submenu)
|
|
|
|
|
2006-09-06 13:58:11 +02:00
|
|
|
for nick in sorted(gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid)):
|
|
|
|
item = gtk.MenuItem(nick, use_underline = False)
|
2006-05-07 14:47:24 +02:00
|
|
|
submenu.append(item)
|
|
|
|
id = item.connect('activate', self.append_nick_in_msg_textview, nick)
|
|
|
|
self.handlers[id] = item
|
|
|
|
|
|
|
|
menu.show_all()
|
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
def on_treeview_size_allocate(self, widget, allocation):
|
|
|
|
'''The MUC treeview has resized. Move the hpaned in all tabs to match'''
|
|
|
|
self.hpaned_position = self.hpaned.get_position()
|
|
|
|
self.hpaned.set_position(self.hpaned_position)
|
2006-01-06 02:54:33 +01:00
|
|
|
|
|
|
|
def iter_contact_rows(self):
|
|
|
|
'''iterate over all contact rows in the tree model'''
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
role_iter = model.get_iter_root()
|
|
|
|
while role_iter:
|
|
|
|
contact_iter = model.iter_children(role_iter)
|
|
|
|
while contact_iter:
|
|
|
|
yield model[contact_iter]
|
|
|
|
contact_iter = model.iter_next(contact_iter)
|
|
|
|
role_iter = model.iter_next(role_iter)
|
|
|
|
|
|
|
|
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():
|
|
|
|
nick = contact[C_NICK].decode('utf-8')
|
|
|
|
self.draw_contact(nick)
|
|
|
|
|
|
|
|
def on_list_treeview_selection_changed(self, selection):
|
|
|
|
model, selected_iter = selection.get_selected()
|
2006-01-06 04:36:07 +01:00
|
|
|
self.draw_contact(self.nick)
|
2006-01-06 02:54:33 +01:00
|
|
|
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]
|
|
|
|
nick = contact[C_NICK].decode('utf-8')
|
|
|
|
self._last_selected_contact = nick
|
|
|
|
if contact[C_TYPE] != 'contact':
|
|
|
|
return
|
|
|
|
self.draw_contact(nick, selected=True, focus=True)
|
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
def get_tab_label(self, chatstate):
|
2006-01-09 01:47:54 +01:00
|
|
|
'''Markup the label if necessary. Returns a tuple such as:
|
2006-01-01 20:40:05 +01:00
|
|
|
(new_label_str, color)
|
|
|
|
either of which can be None
|
|
|
|
if chatstate is given that means we have HE SENT US a chatstate'''
|
2006-02-27 18:14:40 +01:00
|
|
|
|
2006-01-03 08:34:18 +01:00
|
|
|
has_focus = self.parent_win.window.get_property('has-toplevel-focus')
|
2006-01-01 20:40:05 +01:00
|
|
|
current_tab = self.parent_win.get_active_control() == self
|
2006-09-25 16:36:24 +02:00
|
|
|
color_name = None
|
2006-01-01 20:40:05 +01:00
|
|
|
color = None
|
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
if chatstate == 'attention' and (not has_focus or not current_tab):
|
2006-01-08 21:32:39 +01:00
|
|
|
self.attention_flag = True
|
2006-09-25 16:36:24 +02:00
|
|
|
color_name = gajim.config.get_per('themes', theme,
|
2006-03-19 12:15:52 +01:00
|
|
|
'state_muc_directed_msg_color')
|
2006-01-01 20:40:05 +01:00
|
|
|
elif chatstate:
|
|
|
|
if chatstate == 'active' or (current_tab and has_focus):
|
2006-01-08 21:32:39 +01:00
|
|
|
self.attention_flag = False
|
2006-09-25 16:36:24 +02:00
|
|
|
# get active color from gtk
|
|
|
|
color = self.parent_win.notebook.style.fg[gtk.STATE_ACTIVE]
|
2006-01-01 20:40:05 +01:00
|
|
|
elif chatstate == 'newmsg' and (not has_focus or not current_tab) and\
|
2006-01-09 01:47:54 +01:00
|
|
|
not self.attention_flag:
|
2006-10-03 16:12:42 +02:00
|
|
|
color_name = gajim.config.get_per('themes', theme,
|
|
|
|
'state_muc_msg_color')
|
2006-09-25 16:36:24 +02:00
|
|
|
if color_name:
|
|
|
|
color = gtk.gdk.colormap_get_system().alloc_color(color_name)
|
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
label_str = self.name
|
2006-09-30 16:28:10 +02:00
|
|
|
|
|
|
|
# count waiting highlighted messages
|
2007-05-21 23:33:48 +02:00
|
|
|
unread = ''
|
|
|
|
num_unread = self.get_nb_unread()
|
|
|
|
if num_unread == 1:
|
|
|
|
unread = '*'
|
|
|
|
elif num_unread > 1:
|
|
|
|
unread = '[' + unicode(num_unread) + ']'
|
|
|
|
label_str = unread + label_str
|
2006-01-01 20:40:05 +01:00
|
|
|
return (label_str, color)
|
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
def get_tab_image(self):
|
2006-09-30 16:28:10 +02:00
|
|
|
# Set tab image (always 16x16)
|
2006-01-05 06:51:28 +01:00
|
|
|
tab_image = None
|
2006-09-30 16:28:10 +02:00
|
|
|
if gajim.gc_connected[self.account][self.room_jid]:
|
2006-09-30 16:53:05 +02:00
|
|
|
tab_image = gajim.interface.roster.load_icon('muc_active')
|
2006-01-05 06:51:28 +01:00
|
|
|
else:
|
2006-09-30 16:53:05 +02:00
|
|
|
tab_image = gajim.interface.roster.load_icon('muc_inactive')
|
2006-01-05 06:51:28 +01:00
|
|
|
return tab_image
|
|
|
|
|
2006-01-10 02:47:24 +01:00
|
|
|
def update_ui(self):
|
|
|
|
ChatControlBase.update_ui(self)
|
2006-03-13 20:40:06 +01:00
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
|
|
|
self.draw_contact(nick)
|
2006-01-08 21:56:58 +01:00
|
|
|
|
2006-12-16 21:12:16 +01:00
|
|
|
def _change_style(self, model, path, iter):
|
|
|
|
model[iter][C_NICK] = model[iter][C_NICK]
|
|
|
|
|
|
|
|
def change_roster_style(self):
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
model.foreach(self._change_style)
|
|
|
|
|
|
|
|
def repaint_themed_widgets(self):
|
|
|
|
ChatControlBase.repaint_themed_widgets(self)
|
|
|
|
self.change_roster_style()
|
|
|
|
|
2006-11-30 10:05:59 +01:00
|
|
|
def _update_banner_state_image(self):
|
|
|
|
banner_status_img = self.xml.get_widget('gc_banner_status_image')
|
|
|
|
images = gajim.interface.roster.jabber_state_images
|
2006-12-12 20:10:52 +01:00
|
|
|
if gajim.gc_connected[self.account].has_key(self.room_jid) and \
|
|
|
|
gajim.gc_connected[self.account][self.room_jid]:
|
2006-11-30 12:32:49 +01:00
|
|
|
image = 'muc_active'
|
|
|
|
else:
|
|
|
|
image = 'muc_inactive'
|
|
|
|
if images.has_key('32') and images['32'].has_key(image):
|
|
|
|
muc_icon = images['32'][image]
|
2006-11-30 10:05:59 +01:00
|
|
|
if muc_icon.get_storage_type() != gtk.IMAGE_EMPTY:
|
|
|
|
pix = muc_icon.get_pixbuf()
|
|
|
|
banner_status_img.set_from_pixbuf(pix)
|
|
|
|
return
|
|
|
|
# we need to scale 16x16 to 32x32
|
2006-11-30 12:32:49 +01:00
|
|
|
muc_icon = images['16'][image]
|
2006-11-30 10:05:59 +01:00
|
|
|
pix = muc_icon.get_pixbuf()
|
|
|
|
scaled_pix = pix.scale_simple(32, 32, gtk.gdk.INTERP_BILINEAR)
|
|
|
|
banner_status_img.set_from_pixbuf(scaled_pix)
|
|
|
|
|
2007-01-09 15:29:20 +01:00
|
|
|
def draw_banner_text(self):
|
2007-01-09 15:23:28 +01:00
|
|
|
'''Draw the text in the fat line at the top of the window that
|
|
|
|
houses the room jid, subject.
|
2006-12-12 20:10:52 +01:00
|
|
|
'''
|
|
|
|
self.name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
|
|
|
font_attrs, font_attrs_small = self.get_font_attrs()
|
|
|
|
text = '<span %s>%s</span>' % (font_attrs, self.room_jid)
|
|
|
|
if self.subject:
|
|
|
|
subject = helpers.reduce_chars_newlines(self.subject, max_lines = 2)
|
2007-01-17 00:26:38 +01:00
|
|
|
subject = gobject.markup_escape_text(subject)
|
2006-12-12 20:10:52 +01:00
|
|
|
text += '\n<span %s>%s</span>' % (font_attrs_small, subject)
|
|
|
|
|
2006-12-12 23:06:24 +01:00
|
|
|
# tooltip must always hold ALL the subject
|
|
|
|
self.subject_tooltip.set_tip(self.event_box, self.subject)
|
2006-12-12 20:10:52 +01:00
|
|
|
|
|
|
|
self.name_label.set_markup(text)
|
2007-04-19 00:30:42 +02:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
def prepare_context_menu(self):
|
|
|
|
'''sets compact view menuitem active state
|
2006-02-07 14:31:20 +01:00
|
|
|
sets sensitivity state for configure_room'''
|
2007-03-11 21:14:53 +01:00
|
|
|
# Check compact view menuitem
|
2007-06-02 14:03:02 +02:00
|
|
|
self.compact_view_menuitem.set_active(self.hide_chat_buttons_current)
|
2006-03-12 19:55:59 +01:00
|
|
|
if gajim.gc_connected[self.account][self.room_jid]:
|
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
self.nick)
|
|
|
|
if c.affiliation not in ('owner', 'admin'):
|
2007-06-02 14:03:02 +02:00
|
|
|
self.configure_room_menuitem.set_sensitive(False)
|
2007-04-19 00:30:42 +02:00
|
|
|
else:
|
2007-06-02 14:03:02 +02:00
|
|
|
self.configure_room_menuitem.set_sensitive(True)
|
2007-03-11 21:14:53 +01:00
|
|
|
if c.affiliation != 'owner':
|
2007-06-02 14:03:02 +02:00
|
|
|
self.destroy_room_menuitem.set_sensitive(False)
|
2007-04-19 00:30:42 +02:00
|
|
|
else:
|
2007-06-02 14:03:02 +02:00
|
|
|
self.destroy_room_menuitem.set_sensitive(True)
|
|
|
|
self.change_subject_menuitem.set_sensitive(True)
|
|
|
|
self.change_nick_menuitem.set_sensitive(True)
|
2006-03-12 19:55:59 +01:00
|
|
|
else:
|
|
|
|
# We are not connected to this groupchat, disable unusable menuitems
|
2007-06-02 14:03:02 +02:00
|
|
|
self.configure_room_menuitem.set_sensitive(False)
|
|
|
|
self.destroy_room_menuitem.set_sensitive(False)
|
|
|
|
self.change_subject_menuitem.set_sensitive(False)
|
|
|
|
self.change_nick_menuitem.set_sensitive(False)
|
|
|
|
return self.gc_popup_menu
|
2006-01-05 06:51:28 +01:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def on_message(self, nick, msg, tim, has_timestamp = False, xhtml = None):
|
2006-01-05 06:51:28 +01:00
|
|
|
if not nick:
|
|
|
|
# message from server
|
2006-10-03 16:12:42 +02:00
|
|
|
self.print_conversation(msg, tim = tim, xhtml = xhtml)
|
2006-01-05 06:51:28 +01:00
|
|
|
else:
|
|
|
|
# message from someone
|
2006-09-14 15:31:14 +02:00
|
|
|
if has_timestamp:
|
2006-10-03 16:12:42 +02:00
|
|
|
self.print_old_conversation(msg, nick, tim, xhtml)
|
2006-09-14 15:31:14 +02:00
|
|
|
else:
|
2006-10-03 16:12:42 +02:00
|
|
|
self.print_conversation(msg, nick, tim, xhtml)
|
2006-01-05 06:51:28 +01:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def on_private_message(self, nick, msg, tim, xhtml):
|
2006-01-05 06:51:28 +01:00
|
|
|
# Do we have a queue?
|
|
|
|
fjid = self.room_jid + '/' + nick
|
2006-09-02 23:01:11 +02:00
|
|
|
no_queue = len(gajim.events.get_events(self.account, fjid)) == 0
|
2006-01-05 06:51:28 +01:00
|
|
|
|
|
|
|
# We print if window is opened
|
2006-01-25 03:43:55 +01:00
|
|
|
pm_control = gajim.interface.msg_win_mgr.get_control(fjid, self.account)
|
2006-01-05 06:51:28 +01:00
|
|
|
if pm_control:
|
2006-10-03 16:12:42 +02:00
|
|
|
pm_control.print_conversation(msg, tim = tim, xhtml = xhtml)
|
2006-01-05 06:51:28 +01:00
|
|
|
return
|
|
|
|
|
2006-09-06 23:39:32 +02:00
|
|
|
event = gajim.events.create_event('pm', (msg, '', 'incoming', tim,
|
2006-10-09 11:10:32 +02:00
|
|
|
False, '', None, xhtml))
|
2006-09-02 23:01:11 +02:00
|
|
|
gajim.events.add_event(self.account, fjid, event)
|
2006-01-05 06:51:28 +01:00
|
|
|
|
|
|
|
autopopup = gajim.config.get('autopopup')
|
|
|
|
autopopupaway = gajim.config.get('autopopupaway')
|
|
|
|
iter = self.get_contact_iter(nick)
|
|
|
|
path = self.list_treeview.get_model().get_path(iter)
|
|
|
|
if not autopopup or (not autopopupaway and \
|
2006-11-11 00:17:52 +01:00
|
|
|
gajim.connections[self.account].connected > 2):
|
2006-01-05 06:51:28 +01:00
|
|
|
if no_queue: # We didn't have a queue: we change icons
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
state_images =\
|
2006-02-26 16:08:59 +01:00
|
|
|
gajim.interface.roster.get_appropriate_state_images(
|
|
|
|
self.room_jid, icon_name = 'message')
|
2006-01-05 06:51:28 +01:00
|
|
|
image = state_images['message']
|
|
|
|
model[iter][C_IMG] = image
|
2007-05-17 14:55:44 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.show_title()
|
|
|
|
self.parent_win.redraw_tab(self)
|
2006-01-05 06:51:28 +01:00
|
|
|
else:
|
2006-01-08 06:05:16 +01:00
|
|
|
self._start_private_message(nick)
|
2006-01-05 06:51:28 +01:00
|
|
|
# Scroll to line
|
|
|
|
self.list_treeview.expand_row(path[0:1], False)
|
|
|
|
self.list_treeview.scroll_to_cell(path)
|
|
|
|
self.list_treeview.set_cursor(path)
|
2007-06-07 13:58:56 +02:00
|
|
|
contact = gajim.contacts.get_contact_with_highest_priority(self.account, \
|
|
|
|
self.room_jid)
|
|
|
|
if contact:
|
|
|
|
gajim.interface.roster.draw_contact(self.room_jid, self.account)
|
2006-01-05 06:51:28 +01:00
|
|
|
|
|
|
|
def get_contact_iter(self, nick):
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
fin = False
|
|
|
|
role_iter = model.get_iter_root()
|
|
|
|
if not role_iter:
|
|
|
|
return None
|
|
|
|
while not fin:
|
|
|
|
fin2 = False
|
|
|
|
user_iter = model.iter_children(role_iter)
|
|
|
|
if not user_iter:
|
|
|
|
fin2 = True
|
|
|
|
while not fin2:
|
|
|
|
if nick == model[user_iter][C_NICK].decode('utf-8'):
|
|
|
|
return user_iter
|
|
|
|
user_iter = model.iter_next(user_iter)
|
|
|
|
if not user_iter:
|
|
|
|
fin2 = True
|
|
|
|
role_iter = model.iter_next(role_iter)
|
|
|
|
if not role_iter:
|
|
|
|
fin = True
|
|
|
|
return None
|
|
|
|
|
2006-06-22 16:44:06 +02:00
|
|
|
gc_count_nicknames_colors = 0
|
|
|
|
gc_custom_colors = {}
|
|
|
|
|
2006-11-06 00:46:06 +01:00
|
|
|
def print_old_conversation(self, text, contact = '', tim = None,
|
|
|
|
xhtml = None):
|
2006-09-14 15:31:14 +02:00
|
|
|
if isinstance(text, str):
|
|
|
|
text = unicode(text, 'utf-8')
|
2006-11-06 00:46:06 +01:00
|
|
|
if contact:
|
|
|
|
if contact == self.nick: # it's us
|
|
|
|
kind = 'outgoing'
|
|
|
|
else:
|
|
|
|
kind = 'incoming'
|
2006-09-14 15:31:14 +02:00
|
|
|
else:
|
2006-11-06 00:46:06 +01:00
|
|
|
kind = 'status'
|
2006-09-14 15:31:14 +02:00
|
|
|
if gajim.config.get('restored_messages_small'):
|
|
|
|
small_attr = ['small']
|
|
|
|
else:
|
|
|
|
small_attr = []
|
|
|
|
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
|
|
|
|
small_attr, small_attr + ['restored_message'],
|
2007-05-03 23:02:50 +02:00
|
|
|
small_attr + ['restored_message'], count_as_new = False, xhtml = xhtml)
|
2006-09-14 15:31:14 +02:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def print_conversation(self, text, contact = '', tim = None, xhtml = None):
|
2006-01-05 06:51:28 +01:00
|
|
|
'''Print a line in the conversation:
|
2006-02-21 21:24:18 +01:00
|
|
|
if contact is set: it's a message from someone or an info message (contact
|
|
|
|
= 'info' in such a case)
|
2006-01-05 06:51:28 +01:00
|
|
|
if contact is not set: it's a message from the server or help'''
|
|
|
|
if isinstance(text, str):
|
|
|
|
text = unicode(text, 'utf-8')
|
|
|
|
other_tags_for_name = []
|
|
|
|
other_tags_for_text = []
|
|
|
|
if contact:
|
|
|
|
if contact == self.nick: # it's us
|
|
|
|
kind = 'outgoing'
|
2006-02-21 21:24:18 +01:00
|
|
|
elif contact == 'info':
|
|
|
|
kind = 'info'
|
|
|
|
contact = None
|
2006-01-05 06:51:28 +01:00
|
|
|
else:
|
|
|
|
kind = 'incoming'
|
|
|
|
# muc-specific chatstate
|
2007-05-07 23:02:48 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self, 'newmsg')
|
2006-01-05 06:51:28 +01:00
|
|
|
else:
|
|
|
|
kind = 'status'
|
|
|
|
|
|
|
|
if kind == 'incoming': # it's a message NOT from us
|
|
|
|
# highlighting and sounds
|
|
|
|
(highlight, sound) = self.highlighting_for_message(text, tim)
|
2006-09-02 02:35:03 +02:00
|
|
|
if self.gc_custom_colors.has_key(contact):
|
2006-06-22 16:44:06 +02:00
|
|
|
other_tags_for_name.append('gc_nickname_color_' + \
|
2006-09-02 02:35:03 +02:00
|
|
|
str(self.gc_custom_colors[contact]))
|
2006-06-22 16:44:06 +02:00
|
|
|
else:
|
2006-09-02 02:35:03 +02:00
|
|
|
self.gc_count_nicknames_colors += 1
|
2006-07-19 16:53:59 +02:00
|
|
|
number_of_colors = len(gajim.config.get('gc_nicknames_colors').\
|
|
|
|
split(':'))
|
2006-09-02 02:35:03 +02:00
|
|
|
if self.gc_count_nicknames_colors == number_of_colors:
|
|
|
|
self.gc_count_nicknames_colors = 0
|
|
|
|
self.gc_custom_colors[contact] = \
|
|
|
|
self.gc_count_nicknames_colors
|
2006-07-19 16:53:59 +02:00
|
|
|
other_tags_for_name.append('gc_nickname_color_' + \
|
2006-09-02 02:35:03 +02:00
|
|
|
str(self.gc_count_nicknames_colors))
|
2006-01-05 06:51:28 +01:00
|
|
|
if highlight:
|
2006-01-08 21:32:39 +01:00
|
|
|
# muc-specific chatstate
|
2007-05-07 23:02:48 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self, 'attention')
|
2006-01-05 06:51:28 +01:00
|
|
|
other_tags_for_name.append('bold')
|
|
|
|
other_tags_for_text.append('marked')
|
2007-05-17 22:50:11 +02:00
|
|
|
|
|
|
|
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)
|
2007-05-17 17:54:23 +02:00
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
if sound == 'received':
|
|
|
|
helpers.play_sound('muc_message_received')
|
|
|
|
elif sound == 'highlight':
|
|
|
|
helpers.play_sound('muc_message_highlight')
|
2006-09-02 11:56:52 +02:00
|
|
|
if text.startswith('/me ') or text.startswith('/me\n'):
|
|
|
|
other_tags_for_text.append('gc_nickname_color_' + \
|
|
|
|
str(self.gc_custom_colors[contact]))
|
2006-01-05 06:51:28 +01:00
|
|
|
|
2007-05-07 23:02:48 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.check_and_possibly_add_focus_out_line()
|
2006-01-05 06:51:28 +01:00
|
|
|
|
|
|
|
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
|
2006-10-03 16:12:42 +02:00
|
|
|
other_tags_for_name, [], other_tags_for_text, xhtml = xhtml)
|
2006-01-05 06:51:28 +01:00
|
|
|
|
2006-09-07 16:35:23 +02:00
|
|
|
def get_nb_unread(self):
|
2007-05-21 23:39:58 +02:00
|
|
|
type_events = ['printed_marked_gc_msg']
|
2007-05-21 23:33:48 +02:00
|
|
|
if gajim.config.get('notify_on_all_muc_messages'):
|
2007-05-21 23:39:58 +02:00
|
|
|
type_events.append('printed_gc_msg')
|
|
|
|
nb = len(gajim.events.get_events(self.account, self.room_jid,
|
|
|
|
type_events))
|
2006-11-11 00:17:52 +01:00
|
|
|
nb += self.get_nb_unread_pm()
|
|
|
|
return nb
|
|
|
|
|
|
|
|
def get_nb_unread_pm(self):
|
|
|
|
nb = 0
|
2006-09-07 16:35:23 +02:00
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
|
|
|
nb += len(gajim.events.get_events(self.account, self.room_jid + '/' + \
|
|
|
|
nick, ['pm']))
|
|
|
|
return nb
|
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
# Do we play a sound on every muc message?
|
|
|
|
if gajim.config.get_per('soundevents', 'muc_message_received', 'enabled'):
|
2006-10-11 19:03:25 +02:00
|
|
|
sound = 'received'
|
2006-01-05 06:51:28 +01:00
|
|
|
|
|
|
|
# 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',
|
2007-06-03 15:40:14 +02:00
|
|
|
'enabled'):
|
2006-01-05 06:51:28 +01:00
|
|
|
sound = 'highlight'
|
|
|
|
|
|
|
|
# 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):
|
|
|
|
'''checks and possibly adds 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
|
|
|
|
it removes previous line first'''
|
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
win = gajim.interface.msg_win_mgr.get_window(self.room_jid, self.account)
|
2006-01-05 06:51:28 +01:00
|
|
|
if self.room_jid == win.get_active_jid() and\
|
2006-05-18 23:45:59 +02:00
|
|
|
win.window.get_property('has-toplevel-focus') and\
|
|
|
|
self.parent_win.get_active_control() == self:
|
2006-01-05 06:51:28 +01:00
|
|
|
# it's the current room and it's the focused window.
|
|
|
|
# we have full focus (we are reading it!)
|
|
|
|
return
|
|
|
|
|
2006-07-27 12:54:12 +02:00
|
|
|
self.conv_textview.show_focus_out_line()
|
2006-01-05 06:51:28 +01:00
|
|
|
|
|
|
|
def needs_visual_notification(self, text):
|
|
|
|
'''checks 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()
|
|
|
|
|
|
|
|
text_splitted = text.split()
|
|
|
|
for word in text_splitted: # get each word of the text
|
|
|
|
for special_word in special_words:
|
|
|
|
if word.startswith(special_word):
|
2006-05-24 18:15:49 +02:00
|
|
|
# get char after the word that highlight us
|
|
|
|
char_position = len(special_word)
|
|
|
|
refer_to_nick_char = \
|
|
|
|
word[char_position:char_position+1]
|
|
|
|
if (refer_to_nick_char != ''):
|
|
|
|
refer_to_nick_char_code = ord(refer_to_nick_char)
|
2006-10-03 16:12:42 +02:00
|
|
|
if ((refer_to_nick_char_code < 65 or \
|
|
|
|
refer_to_nick_char_code > 123) or \
|
|
|
|
(refer_to_nick_char_code < 97 and \
|
|
|
|
refer_to_nick_char_code > 90)):
|
2006-05-24 18:15:49 +02:00
|
|
|
return True
|
|
|
|
else:
|
2006-10-03 16:12:42 +02:00
|
|
|
# This is A->Z or a->z, we can be sure our nick is the
|
|
|
|
# beginning of a real word, do not highlight. Note that we
|
|
|
|
# can probably do a better detection of non-punctuation
|
|
|
|
# characters
|
2006-05-24 18:15:49 +02:00
|
|
|
return False
|
|
|
|
else: # Special word == word, no char after in word
|
|
|
|
return True
|
2006-01-05 06:51:28 +01:00
|
|
|
return False
|
2006-01-06 02:54:33 +01:00
|
|
|
|
|
|
|
def set_subject(self, subject):
|
2006-01-10 02:47:24 +01:00
|
|
|
self.subject = subject
|
2007-01-09 15:23:28 +01:00
|
|
|
self.draw_banner_text()
|
2006-01-06 02:54:33 +01:00
|
|
|
|
|
|
|
def got_connected(self):
|
|
|
|
gajim.gc_connected[self.account][self.room_jid] = True
|
2006-02-04 03:52:36 +01:00
|
|
|
ChatControlBase.got_connected(self)
|
2007-01-09 16:29:23 +01:00
|
|
|
# We don't redraw the whole banner here, because only icon change
|
|
|
|
self._update_banner_state_image()
|
2006-01-06 02:54:33 +01:00
|
|
|
|
|
|
|
def got_disconnected(self):
|
2006-02-04 03:52:36 +01:00
|
|
|
self.list_treeview.get_model().clear()
|
2006-01-06 02:54:33 +01:00
|
|
|
nick_list = gajim.contacts.get_nick_list(self.account, self.room_jid)
|
|
|
|
for nick in nick_list:
|
2007-01-26 23:11:28 +01:00
|
|
|
# Update pm chat window
|
|
|
|
fjid = self.room_jid + '/' + nick
|
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.account)
|
2006-01-06 02:54:33 +01:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
2007-01-26 23:11:28 +01:00
|
|
|
if ctrl:
|
|
|
|
gc_contact.show = 'offline'
|
|
|
|
gc_contact.status = ''
|
|
|
|
ctrl.update_ui()
|
|
|
|
ctrl.parent_win.redraw_tab(ctrl)
|
2006-01-06 02:54:33 +01:00
|
|
|
gajim.contacts.remove_gc_contact(self.account, gc_contact)
|
|
|
|
gajim.gc_connected[self.account][self.room_jid] = False
|
2006-02-04 03:52:36 +01:00
|
|
|
ChatControlBase.got_disconnected(self)
|
2007-01-09 15:29:20 +01:00
|
|
|
# We don't redraw the whole banner here, because only icon change
|
2007-01-09 15:23:28 +01:00
|
|
|
self._update_banner_state_image()
|
2006-01-06 02:54:33 +01:00
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
def draw_roster(self):
|
2006-02-04 03:52:36 +01:00
|
|
|
self.list_treeview.get_model().clear()
|
2006-01-06 04:36:07 +01:00
|
|
|
for nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
|
2006-03-14 00:25:00 +01:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
2006-01-06 07:59:55 +01:00
|
|
|
self.add_contact_to_roster(nick, gc_contact.show, gc_contact.role,
|
|
|
|
gc_contact.affiliation, gc_contact.status,
|
|
|
|
gc_contact.jid)
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def on_send_pm(self, widget = None, model = None, iter = None, nick = None,
|
|
|
|
msg = None):
|
2006-01-06 07:59:55 +01:00
|
|
|
'''opens a chat window and msg is not None sends private message to a
|
|
|
|
contact in a room'''
|
|
|
|
if nick is None:
|
|
|
|
nick = model[iter][C_NICK].decode('utf-8')
|
|
|
|
fjid = gajim.construct_fjid(self.room_jid, nick) # 'fake' jid
|
|
|
|
|
2006-01-08 06:05:16 +01:00
|
|
|
self._start_private_message(nick)
|
2006-01-06 07:59:55 +01:00
|
|
|
if msg:
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.interface.msg_win_mgr.get_control(fjid, self.account).\
|
|
|
|
send_message(msg)
|
2006-01-06 04:36:07 +01:00
|
|
|
|
2006-01-06 02:54:33 +01:00
|
|
|
def draw_contact(self, nick, selected=False, focus=False):
|
2006-01-06 04:36:07 +01:00
|
|
|
iter = self.get_contact_iter(nick)
|
2006-01-06 02:54:33 +01:00
|
|
|
if not iter:
|
|
|
|
return
|
|
|
|
model = self.list_treeview.get_model()
|
2006-10-03 16:12:42 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
2006-01-06 02:54:33 +01:00
|
|
|
state_images = gajim.interface.roster.jabber_state_images['16']
|
2006-09-02 23:01:11 +02:00
|
|
|
if len(gajim.events.get_events(self.account, self.room_jid + '/' + nick)):
|
2006-01-06 02:54:33 +01:00
|
|
|
image = state_images['message']
|
|
|
|
else:
|
|
|
|
image = state_images[gc_contact.show]
|
|
|
|
|
2007-01-17 00:26:38 +01:00
|
|
|
name = gobject.markup_escape_text(gc_contact.name)
|
2006-01-06 02:54:33 +01:00
|
|
|
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 != '':
|
2006-10-06 16:52:25 +02:00
|
|
|
status = helpers.reduce_chars_newlines(status, max_lines = 1)
|
2006-01-06 02:54:33 +01:00
|
|
|
# escape markup entities and make them small italic and fg color
|
|
|
|
color = gtkgui_helpers._get_fade_color(self.list_treeview,
|
|
|
|
selected, focus)
|
|
|
|
colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue)
|
|
|
|
name += '\n' '<span size="small" style="italic" foreground="%s">%s</span>'\
|
2007-01-17 00:26:38 +01:00
|
|
|
% (colorstring, gobject.markup_escape_text(status))
|
2006-01-06 02:54:33 +01:00
|
|
|
|
|
|
|
model[iter][C_IMG] = image
|
|
|
|
model[iter][C_TEXT] = name
|
2006-03-13 14:25:51 +01:00
|
|
|
|
|
|
|
def draw_avatar(self, nick):
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
iter = self.get_contact_iter(nick)
|
2006-10-09 11:59:08 +02:00
|
|
|
if not iter:
|
|
|
|
return
|
2006-03-13 14:25:51 +01:00
|
|
|
if gajim.config.get('show_avatars_in_roster'):
|
|
|
|
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(self.room_jid + \
|
|
|
|
'/' + nick, True)
|
|
|
|
if pixbuf in ('ask', None):
|
|
|
|
scaled_pixbuf = None
|
|
|
|
else:
|
|
|
|
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster')
|
|
|
|
else:
|
|
|
|
scaled_pixbuf = None
|
|
|
|
model[iter][C_AVATAR] = scaled_pixbuf
|
2006-01-06 04:36:07 +01:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def chg_contact_status(self, nick, show, status, role, affiliation, jid,
|
2007-05-20 17:41:20 +02:00
|
|
|
reason, actor, statusCode, new_nick, avatar_sha, tim = None):
|
2006-01-06 04:36:07 +01:00
|
|
|
'''When an occupant changes his or her status'''
|
|
|
|
if show == 'invisible':
|
|
|
|
return
|
2006-01-09 00:14:50 +01:00
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
if not role:
|
|
|
|
role = 'visitor'
|
|
|
|
if not affiliation:
|
|
|
|
affiliation = 'none'
|
2007-05-20 17:41:20 +02:00
|
|
|
fake_jid = self.room_jid + '/' + nick
|
2006-05-06 22:01:25 +02:00
|
|
|
newly_created = False
|
2006-01-06 04:36:07 +01:00
|
|
|
if show in ('offline', 'error'):
|
|
|
|
if statusCode == '307':
|
|
|
|
if actor is None: # do not print 'kicked by None'
|
|
|
|
s = _('%(nick)s has been kicked: %(reason)s') % {
|
|
|
|
'nick': nick,
|
|
|
|
'reason': reason }
|
|
|
|
else:
|
|
|
|
s = _('%(nick)s has been kicked by %(who)s: %(reason)s') % {
|
|
|
|
'nick': nick,
|
|
|
|
'who': actor,
|
|
|
|
'reason': reason }
|
2007-05-03 23:02:50 +02:00
|
|
|
self.print_conversation(s, 'info', tim = tim)
|
2006-01-06 04:36:07 +01:00
|
|
|
elif statusCode == '301':
|
|
|
|
if actor is None: # do not print 'banned by None'
|
|
|
|
s = _('%(nick)s has been banned: %(reason)s') % {
|
|
|
|
'nick': nick,
|
|
|
|
'reason': reason }
|
|
|
|
else:
|
|
|
|
s = _('%(nick)s has been banned by %(who)s: %(reason)s') % {
|
|
|
|
'nick': nick,
|
|
|
|
'who': actor,
|
|
|
|
'reason': reason }
|
2007-05-03 23:02:50 +02:00
|
|
|
self.print_conversation(s, 'info', tim = tim)
|
2006-01-06 04:36:07 +01:00
|
|
|
elif statusCode == '303': # Someone changed his or her nick
|
2007-06-03 15:40:14 +02:00
|
|
|
if new_nick == self.nick: # We changed our nick
|
2006-01-06 04:36:07 +01:00
|
|
|
s = _('You are now known as %s') % new_nick
|
|
|
|
else:
|
|
|
|
s = _('%s is now known as %s') % (nick, new_nick)
|
2006-05-17 19:56:33 +02:00
|
|
|
# We add new nick to muc roster here, so we don't see
|
|
|
|
# that "new_nick has joined the room" when he just changed nick.
|
|
|
|
# add_contact_to_roster will be called a second time
|
|
|
|
# after that, but that doesn't hurt
|
|
|
|
self.add_contact_to_roster(new_nick, show, role, affiliation,
|
|
|
|
status, jid)
|
2007-06-03 15:40:14 +02:00
|
|
|
if nick in self.attention_list:
|
|
|
|
self.attention_list.remove(nick)
|
2006-09-02 02:35:03 +02:00
|
|
|
# keep nickname color
|
2006-09-03 13:02:48 +02:00
|
|
|
if nick in self.gc_custom_colors:
|
|
|
|
self.gc_custom_colors[new_nick] = self.gc_custom_colors[nick]
|
2006-05-30 13:41:58 +02:00
|
|
|
# rename vcard / avatar
|
|
|
|
puny_jid = helpers.sanitize_filename(self.room_jid)
|
|
|
|
puny_nick = helpers.sanitize_filename(nick)
|
|
|
|
puny_new_nick = helpers.sanitize_filename(new_nick)
|
|
|
|
old_path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
|
|
|
|
new_path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_new_nick)
|
|
|
|
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)] = \
|
|
|
|
os.path.join(path, puny_new_nick + ext)
|
|
|
|
for old_file in files:
|
|
|
|
if os.path.exists(old_file):
|
2007-01-05 19:05:51 +01:00
|
|
|
if os.path.exists(files[old_file]):
|
|
|
|
# Windows require this
|
|
|
|
os.remove(files[old_file])
|
2006-05-30 13:41:58 +02:00
|
|
|
os.rename(old_file, files[old_file])
|
2007-05-03 23:02:50 +02:00
|
|
|
self.print_conversation(s, 'info', tim)
|
2007-03-11 21:14:53 +01:00
|
|
|
elif statusCode == 'destroyed': # Room has been destroyed
|
2007-05-03 23:02:50 +02:00
|
|
|
self.print_conversation(reason, 'info', tim)
|
2006-01-06 04:36:07 +01:00
|
|
|
|
2007-05-20 17:41:20 +02:00
|
|
|
if len(gajim.events.get_events(self.account, fake_jid)) == 0:
|
2006-01-06 04:36:07 +01:00
|
|
|
self.remove_contact(nick)
|
|
|
|
else:
|
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
|
|
|
c.show = show
|
|
|
|
c.status = status
|
|
|
|
if nick == self.nick and statusCode != '303': # We became offline
|
|
|
|
self.got_disconnected()
|
2007-05-07 23:02:48 +02:00
|
|
|
contact = gajim.contacts.\
|
|
|
|
get_contact_with_highest_priority(self.account, self.room_jid)
|
|
|
|
if contact:
|
|
|
|
gajim.interface.roster.draw_contact(self.room_jid, self.account)
|
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self)
|
2006-01-06 04:36:07 +01:00
|
|
|
else:
|
|
|
|
iter = self.get_contact_iter(nick)
|
|
|
|
if not iter:
|
2006-05-06 22:01:25 +02:00
|
|
|
iter = self.add_contact_to_roster(nick, show, role, affiliation,
|
|
|
|
status, jid)
|
|
|
|
newly_created = True
|
Merged revisions 5017-5020,5022-5029 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r5017 | asterix | 2006-01-06 01:55:51 -0700 (Fri, 06 Jan 2006) | 2 lines
use escape for pango markup
........
r5018 | asterix | 2006-01-06 02:21:39 -0700 (Fri, 06 Jan 2006) | 2 lines
missing new contacts function
........
r5019 | asterix | 2006-01-06 11:03:07 -0700 (Fri, 06 Jan 2006) | 2 lines
handle the click on toggle_gpg_encryption menuitem
........
r5020 | asterix | 2006-01-06 11:14:14 -0700 (Fri, 06 Jan 2006) | 2 lines
use the saved size even if a chat window is already opened
........
r5022 | asterix | 2006-01-07 03:43:47 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now resume filetransfert
........
r5023 | asterix | 2006-01-07 03:56:31 -0700 (Sat, 07 Jan 2006) | 2 lines
[Knuckles] Google E-Mail Notification
........
r5024 | asterix | 2006-01-07 04:02:16 -0700 (Sat, 07 Jan 2006) | 2 lines
better string
........
r5025 | asterix | 2006-01-07 04:14:32 -0700 (Sat, 07 Jan 2006) | 2 lines
fix a TB
........
r5026 | asterix | 2006-01-07 05:36:55 -0700 (Sat, 07 Jan 2006) | 2 lines
we can now drag a file on a contact in the roster to send him a file
........
r5027 | asterix | 2006-01-07 06:26:28 -0700 (Sat, 07 Jan 2006) | 2 lines
contact.groups is always a list, even if emtpy
........
r5028 | asterix | 2006-01-07 06:54:30 -0700 (Sat, 07 Jan 2006) | 2 lines
make all buttons insensitive on a category row in disco
........
r5029 | asterix | 2006-01-07 07:19:25 -0700 (Sat, 07 Jan 2006) | 2 lines
auto open groupchat configuration window when we create a new room
........
2006-01-07 18:25:35 +01:00
|
|
|
if statusCode == '201': # We just created the room
|
2006-01-09 01:47:54 +01:00
|
|
|
gajim.connections[self.account].request_gc_config(self.room_jid)
|
2006-01-06 04:36:07 +01:00
|
|
|
else:
|
2007-05-20 17:41:20 +02:00
|
|
|
gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
|
|
|
# Re-get vcard if avatar has changed
|
|
|
|
# We do that here because we may request it to the real JID if we
|
|
|
|
# knows it. connections.py doesn't know it.
|
|
|
|
con = gajim.connections[self.account]
|
|
|
|
if gc_c.jid:
|
|
|
|
real_jid = gc_c.jid
|
|
|
|
if gc_c.resource:
|
|
|
|
real_jid += '/' + gc_c.resource
|
|
|
|
else:
|
|
|
|
real_jid = fake_jid
|
|
|
|
if con.vcard_shas.has_key(fake_jid):
|
|
|
|
if avatar_sha != con.vcard_shas[fake_jid]:
|
|
|
|
con.request_vcard(real_jid, fake_jid)
|
|
|
|
else:
|
|
|
|
cached_vcard = con.get_cached_vcard(fake_jid, True)
|
|
|
|
if cached_vcard and cached_vcard.has_key('PHOTO') and \
|
|
|
|
cached_vcard['PHOTO'].has_key('SHA'):
|
|
|
|
cached_sha = cached_vcard['PHOTO']['SHA']
|
|
|
|
else:
|
|
|
|
cached_sha = ''
|
|
|
|
if cached_sha != avatar_sha:
|
|
|
|
# avatar has been updated
|
|
|
|
# sha in mem will be updated later
|
|
|
|
con.request_vcard(real_jid, fake_jid)
|
|
|
|
else:
|
|
|
|
# save sha in mem NOW
|
2007-05-20 18:20:05 +02:00
|
|
|
con.vcard_shas[fake_jid] = avatar_sha
|
2007-05-20 17:41:20 +02:00
|
|
|
|
2006-01-06 04:36:07 +01:00
|
|
|
actual_role = self.get_role(nick)
|
|
|
|
if role != actual_role:
|
|
|
|
self.remove_contact(nick)
|
|
|
|
self.add_contact_to_roster(nick, show, role,
|
|
|
|
affiliation, status, jid)
|
|
|
|
else:
|
2007-05-20 17:41:20 +02:00
|
|
|
if gc_c.show == show and gc_c.status == status and \
|
|
|
|
gc_c.affiliation == affiliation: # no change
|
2006-01-06 04:36:07 +01:00
|
|
|
return
|
2007-05-20 17:41:20 +02:00
|
|
|
gc_c.show = show
|
|
|
|
gc_c.affiliation = affiliation
|
|
|
|
gc_c.status = status
|
2006-01-06 04:36:07 +01:00
|
|
|
self.draw_contact(nick)
|
2007-05-07 23:02:48 +02:00
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self)
|
2006-01-06 04:36:07 +01:00
|
|
|
if (time.time() - self.room_creation) > 30 and \
|
|
|
|
nick != self.nick and statusCode != '303':
|
2006-05-07 23:44:57 +02:00
|
|
|
st = ''
|
2006-05-18 20:07:53 +02:00
|
|
|
print_status = None
|
2006-05-07 23:44:57 +02:00
|
|
|
for bookmark in gajim.connections[self.account].bookmarks:
|
|
|
|
if bookmark['jid'] == self.room_jid:
|
2006-11-05 23:09:19 +01:00
|
|
|
print_status = bookmark.get('print_status', None)
|
2006-05-07 23:44:57 +02:00
|
|
|
break
|
2006-11-05 23:09:19 +01:00
|
|
|
if not print_status:
|
2006-05-10 18:25:57 +02:00
|
|
|
print_status = gajim.config.get('print_status_in_muc')
|
2006-07-24 15:42:35 +02:00
|
|
|
nick_jid = nick
|
|
|
|
if jid:
|
2006-09-25 01:41:54 +02:00
|
|
|
# delete ressource
|
2006-09-25 08:59:01 +02:00
|
|
|
simple_jid = gajim.get_jid_without_resource(jid)
|
2006-09-25 01:41:54 +02:00
|
|
|
nick_jid += ' (%s)' % simple_jid
|
2007-06-03 15:40:14 +02:00
|
|
|
if show == 'offline':
|
|
|
|
if nick in self.attention_list:
|
|
|
|
self.attention_list.remove(nick)
|
2007-02-20 08:08:36 +01:00
|
|
|
if show == 'offline' and print_status in ('all', 'in_and_out') and \
|
|
|
|
statusCode != '307':
|
2006-07-24 15:42:35 +02:00
|
|
|
st = _('%s has left') % nick_jid
|
2006-05-06 22:01:25 +02:00
|
|
|
if reason:
|
|
|
|
st += ' [%s]' % reason
|
2006-01-06 04:36:07 +01:00
|
|
|
else:
|
2006-05-10 18:25:57 +02:00
|
|
|
if newly_created and print_status in ('all', 'in_and_out'):
|
2006-10-12 04:12:10 +02:00
|
|
|
st = _('%s has joined the group chat') % nick_jid
|
2006-05-10 18:25:57 +02:00
|
|
|
elif print_status == 'all':
|
2006-07-24 15:42:35 +02:00
|
|
|
st = _('%s is now %s') % (nick_jid, helpers.get_uf_show(show))
|
2006-05-07 23:44:57 +02:00
|
|
|
if st:
|
|
|
|
if status:
|
|
|
|
st += ' (' + status + ')'
|
2007-05-03 23:02:50 +02:00
|
|
|
self.print_conversation(st, tim = tim)
|
2006-01-06 04:36:07 +01:00
|
|
|
|
2006-03-14 00:25:00 +01:00
|
|
|
def add_contact_to_roster(self, nick, show, role, affiliation, status,
|
|
|
|
jid = ''):
|
2006-01-06 04:36:07 +01:00
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
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:
|
|
|
|
role_iter = model.append(None,
|
2006-10-07 14:41:19 +02:00
|
|
|
(gajim.interface.roster.jabber_state_images['16']['closed'], role,
|
2006-12-07 22:32:53 +01:00
|
|
|
'role', '%s' % role_name, None))
|
2006-10-07 14:41:19 +02:00
|
|
|
iter = model.append(role_iter, (None, nick, 'contact', name, None))
|
2006-01-06 04:36:07 +01: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,
|
|
|
|
name = nick, show = show, status = status, role = role,
|
|
|
|
affiliation = affiliation, jid = j, resource = resource)
|
|
|
|
gajim.contacts.add_gc_contact(self.account, gc_contact)
|
|
|
|
self.draw_contact(nick)
|
2006-03-13 14:25:51 +01:00
|
|
|
self.draw_avatar(nick)
|
2006-03-15 16:11:31 +01:00
|
|
|
# Do not ask avatar to irc rooms as irc transports reply with messages
|
2006-10-07 14:18:51 +02:00
|
|
|
server = gajim.get_server_from_jid(self.room_jid)
|
2006-03-15 16:11:31 +01:00
|
|
|
if gajim.config.get('ask_avatars_on_startup') and \
|
2006-03-16 20:08:49 +01:00
|
|
|
not server.startswith('irc'):
|
2007-05-20 17:41:20 +02:00
|
|
|
fake_jid = self.room_jid + '/' + nick
|
|
|
|
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid, True)
|
2006-03-13 14:25:51 +01:00
|
|
|
if pixbuf == 'ask':
|
2007-05-12 23:49:27 +02:00
|
|
|
if j:
|
2007-05-20 17:41:20 +02:00
|
|
|
fjid = j
|
|
|
|
if resource:
|
|
|
|
fjid += '/' + resource
|
|
|
|
gajim.connections[self.account].request_vcard(fjid, fake_jid)
|
2007-05-12 23:49:27 +02:00
|
|
|
else:
|
2007-05-20 17:41:20 +02:00
|
|
|
gajim.connections[self.account].request_vcard(fake_jid, fake_jid)
|
2006-01-06 04:36:07 +01:00
|
|
|
if nick == self.nick: # we became online
|
|
|
|
self.got_connected()
|
|
|
|
self.list_treeview.expand_row((model.get_path(role_iter)), False)
|
|
|
|
return iter
|
|
|
|
|
|
|
|
def get_role_iter(self, role):
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
fin = False
|
|
|
|
iter = model.get_iter_root()
|
|
|
|
if not iter:
|
|
|
|
return None
|
|
|
|
while not fin:
|
|
|
|
role_name = model[iter][C_NICK].decode('utf-8')
|
|
|
|
if role == role_name:
|
|
|
|
return iter
|
|
|
|
iter = model.iter_next(iter)
|
|
|
|
if not iter:
|
|
|
|
fin = True
|
|
|
|
return None
|
|
|
|
|
|
|
|
def remove_contact(self, nick):
|
|
|
|
'''Remove a user from the contacts_list'''
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
iter = self.get_contact_iter(nick)
|
|
|
|
if not iter:
|
|
|
|
return
|
2006-10-03 16:12:42 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
2006-01-06 04:36:07 +01:00
|
|
|
if gc_contact:
|
|
|
|
gajim.contacts.remove_gc_contact(self.account, gc_contact)
|
|
|
|
parent_iter = model.iter_parent(iter)
|
|
|
|
model.remove(iter)
|
|
|
|
if model.iter_n_children(parent_iter) == 0:
|
|
|
|
model.remove(parent_iter)
|
|
|
|
|
2006-01-06 07:59:55 +01:00
|
|
|
def _process_command(self, message):
|
|
|
|
if message[0] != '/':
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Handle common commands
|
|
|
|
if ChatControlBase._process_command(self, message):
|
|
|
|
return True
|
|
|
|
|
|
|
|
message = message[1:]
|
|
|
|
message_array = message.split(' ', 1)
|
|
|
|
command = message_array.pop(0).lower()
|
|
|
|
if message_array == ['']:
|
|
|
|
message_array = []
|
2006-01-10 02:47:24 +01:00
|
|
|
|
|
|
|
if command == 'me':
|
|
|
|
return False # This is not really a command
|
2006-02-27 18:14:40 +01:00
|
|
|
|
2006-01-06 07:59:55 +01:00
|
|
|
if command == 'nick':
|
|
|
|
# example: /nick foo
|
2006-06-05 11:16:44 +02:00
|
|
|
if len(message_array) and message_array[0] != self.nick:
|
2006-01-06 07:59:55 +01:00
|
|
|
nick = message_array[0]
|
2007-01-31 22:31:10 +01:00
|
|
|
nick = helpers.parse_resource(nick)
|
2007-02-11 04:22:40 +01:00
|
|
|
gajim.connections[self.account].join_gc(nick, self.room_jid, None)
|
2007-06-03 15:40:14 +02:00
|
|
|
self.nick = nick
|
2006-01-06 07:59:55 +01:00
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
elif command == 'query' or command == 'chat':
|
|
|
|
# Open a chat window to the specified nick
|
|
|
|
# example: /query foo
|
|
|
|
if len(message_array):
|
2006-06-08 12:09:15 +02:00
|
|
|
nick0 = message_array.pop(0)
|
|
|
|
if nick0[-1] == ' ':
|
|
|
|
nick1 = nick0[:-1]
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
2006-06-08 12:09:15 +02:00
|
|
|
nick1 = nick0
|
|
|
|
nicks = gajim.contacts.get_nick_list(self.account, self.room_jid)
|
|
|
|
for nick in [nick0, nick1]:
|
|
|
|
if nick in nicks:
|
|
|
|
self.on_send_pm(nick = nick)
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
return True
|
|
|
|
self.print_conversation(_('Nickname not found: %s') % \
|
|
|
|
nick0, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
elif command == 'msg':
|
2006-01-09 01:47:54 +01:00
|
|
|
# Send a message to a nick. Also opens a private message window.
|
2006-01-06 07:59:55 +01:00
|
|
|
# example: /msg foo Hey, what's up?
|
|
|
|
if len(message_array):
|
|
|
|
message_array = message_array[0].split()
|
|
|
|
nick = message_array.pop(0)
|
2006-07-18 11:46:59 +02:00
|
|
|
room_nicks = gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid)
|
2006-01-06 07:59:55 +01:00
|
|
|
if nick in room_nicks:
|
|
|
|
privmsg = ' '.join(message_array)
|
|
|
|
self.on_send_pm(nick=nick, msg=privmsg)
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Nickname not found: %s') % nick,
|
|
|
|
'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
elif command == 'topic':
|
|
|
|
# display or change the room topic
|
|
|
|
# example: /topic : print topic
|
|
|
|
# /topic foo : change topic to foo
|
|
|
|
if len(message_array):
|
|
|
|
new_topic = message_array.pop(0)
|
|
|
|
gajim.connections[self.account].send_gc_subject(self.room_jid,
|
|
|
|
new_topic)
|
2006-10-05 15:10:33 +02:00
|
|
|
elif self.subject is not '':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(self.subject, 'info')
|
2006-10-05 15:10:33 +02:00
|
|
|
else:
|
2006-10-12 04:12:10 +02:00
|
|
|
self.print_conversation(_('This group chat has no subject'), 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
self.clear(self.msg_textview)
|
|
|
|
return True
|
|
|
|
elif command == 'invite':
|
|
|
|
# invite a user to a room for a reason
|
|
|
|
# example: /invite user@example.com reason
|
|
|
|
if len(message_array):
|
|
|
|
message_array = message_array[0].split()
|
|
|
|
invitee = message_array.pop(0)
|
|
|
|
if invitee.find('@') >= 0:
|
|
|
|
reason = ' '.join(message_array)
|
|
|
|
gajim.connections[self.account].send_invite(self.room_jid,
|
|
|
|
invitee, reason)
|
|
|
|
s = _('Invited %(contact_jid)s to %(room_jid)s.') % {
|
|
|
|
'contact_jid': invitee,
|
|
|
|
'room_jid': self.room_jid}
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(s, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
|
|
|
#%s is something the user wrote but it is not a jid so we inform
|
|
|
|
s = _('%s does not appear to be a valid JID') % invitee
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(s, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
elif command == 'join':
|
|
|
|
# example: /join room@conference.example.com/nick
|
|
|
|
if len(message_array):
|
2006-10-08 21:14:01 +02:00
|
|
|
room_jid = message_array[0]
|
|
|
|
if room_jid.find('@') >= 0:
|
|
|
|
if room_jid.find('/') >= 0:
|
|
|
|
room_jid, nick = room_jid.split('/', 1)
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
nick = ''
|
2006-10-08 22:44:05 +02:00
|
|
|
# join_gc window is needed in order to provide for password entry.
|
2006-01-06 07:59:55 +01:00
|
|
|
if gajim.interface.instances[self.account].has_key('join_gc'):
|
|
|
|
gajim.interface.instances[self.account]['join_gc'].\
|
|
|
|
window.present()
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
gajim.interface.instances[self.account]['join_gc'] =\
|
|
|
|
dialogs.JoinGroupchatWindow(self.account,
|
2006-10-08 21:14:01 +02:00
|
|
|
room_jid = room_jid, nick = nick)
|
2006-10-08 02:16:22 +02:00
|
|
|
except GajimGeneralException:
|
2006-01-06 07:59:55 +01:00
|
|
|
pass
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
|
|
|
#%s is something the user wrote but it is not a jid so we inform
|
2006-10-08 22:44:05 +02:00
|
|
|
s = _('%s does not appear to be a valid JID') % message_array[0]
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(s, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
elif command == 'leave' or command == 'part' or command == 'close':
|
|
|
|
# Leave the room and close the tab or window
|
|
|
|
reason = 'offline'
|
|
|
|
if len(message_array):
|
|
|
|
reason = message_array.pop(0)
|
2006-10-10 17:53:42 +02:00
|
|
|
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND, reason)
|
2006-03-03 14:58:52 +01:00
|
|
|
self.clear(self.msg_textview)
|
2006-01-06 07:59:55 +01:00
|
|
|
return True
|
|
|
|
elif command == 'ban':
|
|
|
|
if len(message_array):
|
|
|
|
message_array = message_array[0].split()
|
|
|
|
nick = message_array.pop(0)
|
2006-10-03 16:12:42 +02:00
|
|
|
room_nicks = gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid)
|
2006-01-06 07:59:55 +01:00
|
|
|
reason = ' '.join(message_array)
|
|
|
|
if nick in room_nicks:
|
2006-10-09 12:15:14 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, nick)
|
|
|
|
nick = gc_contact.jid
|
|
|
|
if nick.find('@') >= 0:
|
2006-01-06 07:59:55 +01:00
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid,
|
|
|
|
nick, 'outcast', reason)
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Nickname not found: %s') % nick,
|
|
|
|
'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
elif command == 'kick':
|
|
|
|
if len(message_array):
|
|
|
|
message_array = message_array[0].split()
|
|
|
|
nick = message_array.pop(0)
|
2006-10-03 16:12:42 +02:00
|
|
|
room_nicks = gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid)
|
2006-01-06 07:59:55 +01:00
|
|
|
reason = ' '.join(message_array)
|
|
|
|
if nick in room_nicks:
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
|
|
|
'none', reason)
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Nickname not found: %s') % nick,
|
|
|
|
'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
2006-06-08 12:09:15 +02:00
|
|
|
elif command == 'names':
|
|
|
|
# print the list of participants
|
2006-06-08 15:49:52 +02:00
|
|
|
nicklist=''
|
2006-06-08 12:09:15 +02:00
|
|
|
i=0
|
|
|
|
for contact in self.iter_contact_rows():
|
|
|
|
nicklist += '[ %-12.12s ] ' % (contact[C_NICK].decode('utf-8'))
|
|
|
|
i=i+1
|
|
|
|
if i == 3:
|
|
|
|
i=0
|
|
|
|
self.print_conversation(nicklist, 'info')
|
2006-06-08 15:49:52 +02:00
|
|
|
nicklist=''
|
|
|
|
if nicklist:
|
|
|
|
self.print_conversation(nicklist, 'info')
|
2006-06-08 12:09:15 +02:00
|
|
|
self.clear(self.msg_textview)
|
|
|
|
return True
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'help':
|
|
|
|
if len(message_array):
|
|
|
|
subcommand = message_array.pop(0)
|
|
|
|
self.get_command_help(subcommand)
|
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
return True
|
|
|
|
elif command == 'say':
|
|
|
|
if len(message_array):
|
|
|
|
gajim.connections[self.account].send_gc_message(self.room_jid,
|
|
|
|
message[4:])
|
|
|
|
self.clear(self.msg_textview)
|
|
|
|
else:
|
|
|
|
self.get_command_help(command)
|
|
|
|
return True
|
|
|
|
else:
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('No such command: /%s (if you want to send '
|
|
|
|
'this, prefix it with /say)') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def send_message(self, message):
|
|
|
|
'''call this function to send our message'''
|
|
|
|
if not message:
|
|
|
|
return
|
|
|
|
|
|
|
|
if message != '' or message != '\n':
|
|
|
|
self.save_sent_message(message)
|
|
|
|
|
|
|
|
if not self._process_command(message):
|
|
|
|
# Send the message
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.connections[self.account].send_gc_message(self.room_jid,
|
|
|
|
message)
|
2006-01-06 07:59:55 +01:00
|
|
|
self.msg_textview.get_buffer().set_text('')
|
|
|
|
self.msg_textview.grab_focus()
|
|
|
|
|
|
|
|
def get_command_help(self, command):
|
|
|
|
if command == 'help':
|
2007-02-08 20:08:44 +01:00
|
|
|
self.print_conversation(_('Commands: %s') % GroupchatControl.MUC_CMDS,
|
|
|
|
'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'ban':
|
2006-10-12 04:12:10 +02:00
|
|
|
s = _('Usage: /%s <nickname|JID> [reason], bans the JID from the group chat.'
|
2006-02-21 21:24:18 +01:00
|
|
|
' The nickname of an occupant may be substituted, but not if it '
|
2006-10-12 04:12:10 +02:00
|
|
|
'contains "@". If the JID is currently in the group chat, '
|
|
|
|
'he/she/it will also be kicked. Does NOT support spaces in '
|
|
|
|
'nickname.') % command
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(s, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'chat' or command == 'query':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s <nickname>, opens a private chat'
|
2007-01-02 14:36:54 +01:00
|
|
|
' window with the specified occupant.') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'clear':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(
|
|
|
|
_('Usage: /%s, clears the text window.') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'close' or command == 'leave' or command == 'part':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s [reason], closes the current '
|
|
|
|
'window or tab, displaying reason if specified.') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'compact':
|
2006-10-03 16:12:42 +02:00
|
|
|
self.print_conversation(_('Usage: /%s, hide the chat buttons.') % \
|
|
|
|
command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'invite':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s <JID> [reason], invites JID to '
|
2006-10-12 04:12:10 +02:00
|
|
|
'the current group chat, optionally providing a reason.') % command,
|
2006-02-21 21:24:18 +01:00
|
|
|
'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'join':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s <room>@<server>[/nickname], '
|
|
|
|
'offers to join room@server optionally using specified nickname.') \
|
|
|
|
% command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'kick':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s <nickname> [reason], removes '
|
2006-10-12 04:12:10 +02:00
|
|
|
'the occupant specified by nickname from the group chat and '
|
|
|
|
'optionally displays a reason. Does NOT support spaces in '
|
|
|
|
'nickname.') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'me':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s <action>, sends action to the '
|
2006-10-12 04:12:10 +02:00
|
|
|
'current group chat. Use third person. (e.g. /%s explodes.)') % \
|
2006-02-21 21:24:18 +01:00
|
|
|
(command, command), 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'msg':
|
2006-02-21 21:24:18 +01:00
|
|
|
s = _('Usage: /%s <nickname> [message], opens a private message window'
|
2007-01-02 14:36:54 +01:00
|
|
|
' and sends message to the occupant specified by nickname.') % \
|
2006-02-21 21:24:18 +01:00
|
|
|
command
|
|
|
|
self.print_conversation(s, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'nick':
|
2006-10-12 04:12:10 +02:00
|
|
|
s = _('Usage: /%s <nickname>, changes your nickname in current group '
|
|
|
|
'chat.') % command
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(s, 'info')
|
2006-06-08 12:09:15 +02:00
|
|
|
elif command == 'names':
|
2006-10-12 04:12:10 +02:00
|
|
|
s = _('Usage: /%s , display the names of group chat occupants.')\
|
2006-06-08 12:09:15 +02:00
|
|
|
% command
|
|
|
|
self.print_conversation(s, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'topic':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s [topic], displays or updates the'
|
2006-10-12 04:12:10 +02:00
|
|
|
' current group chat topic.') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
elif command == 'say':
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('Usage: /%s <message>, sends a message '
|
|
|
|
'without looking for other commands.') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
2006-02-21 21:24:18 +01:00
|
|
|
self.print_conversation(_('No help info for /%s') % command, 'info')
|
2006-01-06 07:59:55 +01:00
|
|
|
|
|
|
|
def get_role(self, nick):
|
2006-10-03 16:12:42 +02:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
|
|
|
|
nick)
|
2006-01-06 07:59:55 +01:00
|
|
|
if gc_contact:
|
|
|
|
return gc_contact.role
|
|
|
|
else:
|
|
|
|
return 'visitor'
|
|
|
|
|
|
|
|
def show_change_nick_input_dialog(self, title, prompt, proposed_nick = None):
|
|
|
|
'''asks user for new nick and on ok it sets it on room'''
|
2006-12-08 20:10:28 +01:00
|
|
|
def on_ok(widget):
|
2006-01-06 07:59:55 +01:00
|
|
|
nick = instance.input_entry.get_text().decode('utf-8')
|
2007-01-31 22:31:10 +01:00
|
|
|
nick = helpers.parse_resource(nick)
|
2007-02-11 04:22:40 +01:00
|
|
|
gajim.connections[self.account].join_gc(nick, self.room_jid, None)
|
2007-06-03 15:40:14 +02:00
|
|
|
self.nick = nick
|
2006-12-08 20:10:28 +01:00
|
|
|
instance = dialogs.InputDialog(title, prompt, proposed_nick,
|
|
|
|
is_modal = False, ok_handler = on_ok)
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-03-03 14:58:52 +01:00
|
|
|
def shutdown(self, status='offline'):
|
2006-01-07 23:53:46 +01:00
|
|
|
gajim.connections[self.account].send_gc_status(self.nick, self.room_jid,
|
2006-03-03 14:58:52 +01:00
|
|
|
show='offline', status=status)
|
2007-01-26 23:11:28 +01: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
|
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.account)
|
|
|
|
if ctrl:
|
|
|
|
contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
|
|
|
contact.show = 'offline'
|
|
|
|
contact.status = ''
|
|
|
|
ctrl.update_ui()
|
|
|
|
ctrl.parent_win.redraw_tab(ctrl)
|
2006-01-06 07:59:55 +01: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]
|
2006-02-21 16:19:36 +01:00
|
|
|
# Save hpaned position
|
|
|
|
gajim.config.set('gc-hpaned-position', self.hpaned_position)
|
2006-04-17 23:59:04 +02:00
|
|
|
# remove all register handlers on wigets, created by self.xml
|
|
|
|
# to prevent circular references among objects
|
|
|
|
for i in self.handlers.keys():
|
2006-04-18 17:36:16 +02:00
|
|
|
if self.handlers[i].handler_is_connected(i):
|
|
|
|
self.handlers[i].disconnect(i)
|
2006-04-17 23:59:04 +02:00
|
|
|
del self.handlers[i]
|
2007-01-06 21:41:03 +01:00
|
|
|
# Remove unread events from systray
|
|
|
|
gajim.events.remove_events(self.account, self.room_jid)
|
2007-06-07 14:47:07 +02:00
|
|
|
contact = gajim.contacts.get_contact_with_highest_priority(self.account, \
|
|
|
|
self.room_jid)
|
|
|
|
if contact:
|
|
|
|
gajim.interface.roster.remove_contact(contact, self.account)
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-10-10 17:53:42 +02:00
|
|
|
def allow_shutdown(self, method):
|
|
|
|
'''If check_selection is True, '''
|
|
|
|
if method == self.parent_win.CLOSE_ESC:
|
|
|
|
model, iter = self.list_treeview.get_selection().get_selected()
|
|
|
|
if iter:
|
|
|
|
self.list_treeview.get_selection().unselect_all()
|
|
|
|
return False
|
2006-01-07 21:43:05 +01:00
|
|
|
retval = True
|
2006-03-07 14:13:36 +01:00
|
|
|
includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
|
|
|
|
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')
|
2006-01-06 07:59:55 +01:00
|
|
|
# whether to ask for comfirmation before closing muc
|
2006-03-08 15:27:04 +01:00
|
|
|
if (gajim.config.get('confirm_close_muc') or self.room_jid in includes) \
|
2006-03-07 14:13:36 +01:00
|
|
|
and gajim.gc_connected[self.account][self.room_jid] and self.room_jid not\
|
|
|
|
in excludes:
|
2006-10-12 04:12:10 +02:00
|
|
|
pritext = _('Are you sure you want to leave group chat "%s"?')\
|
|
|
|
% self.name
|
2006-03-07 14:13:36 +01:00
|
|
|
sectext = _('If you close this window, you will be disconnected '
|
2006-10-12 04:12:10 +02:00
|
|
|
'from this group chat.')
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-03-07 14:13:36 +01:00
|
|
|
dialog = dialogs.ConfirmationDialogCheck(pritext, sectext,
|
|
|
|
_('Do _not ask me again'))
|
2006-01-07 21:43:05 +01:00
|
|
|
|
2006-03-07 14:13:36 +01:00
|
|
|
if dialog.get_response() != gtk.RESPONSE_OK:
|
|
|
|
retval = False
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-03-07 14:13:36 +01:00
|
|
|
if dialog.is_checked(): # user does not want to be asked again
|
|
|
|
gajim.config.set('confirm_close_muc', False)
|
2006-02-27 18:14:40 +01:00
|
|
|
|
2006-03-07 14:13:36 +01:00
|
|
|
dialog.destroy()
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-01-07 21:43:05 +01:00
|
|
|
return retval
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def set_control_active(self, state):
|
2006-09-17 10:32:25 +02:00
|
|
|
self.conv_textview.allow_focus_out_line = True
|
2006-01-08 21:32:39 +01:00
|
|
|
self.attention_flag = False
|
2006-01-07 23:53:46 +01:00
|
|
|
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()
|
2006-01-20 04:43:52 +01:00
|
|
|
# Sending active to undo unread state
|
2006-01-25 06:39:07 +01:00
|
|
|
self.parent_win.redraw_tab(self, 'active')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
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
|
2006-09-02 23:01:11 +02:00
|
|
|
nb += len(gajim.events.get_events(self.account, fjid))
|
|
|
|
# gc can only have messages as event
|
2006-01-07 23:53:46 +01:00
|
|
|
return nb
|
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_change_subject_menuitem_activate(self, widget):
|
2006-01-07 23:53:46 +01:00
|
|
|
instance = dialogs.InputDialog(_('Changing Subject'),
|
|
|
|
_('Please specify the new subject:'), self.subject)
|
|
|
|
response = instance.get_response()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
2006-10-03 16:12:42 +02:00
|
|
|
# Note, we don't update self.subject since we don't know whether it
|
|
|
|
# will work yet
|
2006-01-07 23:53:46 +01:00
|
|
|
subject = instance.input_entry.get_text().decode('utf-8')
|
|
|
|
gajim.connections[self.account].send_gc_subject(self.room_jid, subject)
|
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_change_nick_menuitem_activate(self, widget):
|
2006-01-07 23:53:46 +01:00
|
|
|
title = _('Changing Nickname')
|
|
|
|
prompt = _('Please specify the new nickname you want to use:')
|
|
|
|
self.show_change_nick_input_dialog(title, prompt, self.nick)
|
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_configure_room_menuitem_activate(self, widget):
|
2006-02-07 13:56:20 +01:00
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, self.nick)
|
|
|
|
if c.affiliation == 'owner':
|
|
|
|
gajim.connections[self.account].request_gc_config(self.room_jid)
|
|
|
|
elif c.affiliation == 'admin':
|
|
|
|
if not gajim.interface.instances[self.account]['gc_config'].has_key(
|
|
|
|
self.room_jid):
|
|
|
|
gajim.interface.instances[self.account]['gc_config'][self.room_jid]\
|
|
|
|
= config.GroupchatConfigWindow(self.account, self.room_jid)
|
2006-01-07 23:53:46 +01:00
|
|
|
|
2007-03-11 21:14:53 +01:00
|
|
|
def _on_destroy_room_menuitem_activate(self, widget):
|
|
|
|
# Ask for a reason
|
|
|
|
instance = dialogs.DubbleInputDialog(_('Destroying %s') % self.room_jid,
|
|
|
|
_('You are going to definitively destroy this room.\n'
|
|
|
|
'You may specify a reason below:'),
|
|
|
|
_('You may also enter an alternate venue:'))
|
|
|
|
response = instance.get_response()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
reason = instance.input_entry1.get_text().decode('utf-8')
|
|
|
|
jid = instance.input_entry2.get_text().decode('utf-8')
|
|
|
|
# Test jid
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(jid)
|
|
|
|
except:
|
2007-05-09 22:28:21 +02:00
|
|
|
dialogs.ErrorDialog(_('Invalid group chat Jabber ID'),
|
2007-03-11 21:14:53 +01:00
|
|
|
_('The group chat Jabber ID has not allowed characters.'))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# Abord destroy operation
|
|
|
|
return
|
|
|
|
gajim.connections[self.account].destroy_gc_room(self.room_jid, reason,
|
|
|
|
jid)
|
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_bookmark_room_menuitem_activate(self, widget):
|
2006-01-07 23:53:46 +01:00
|
|
|
bm = {
|
|
|
|
'name': self.name,
|
|
|
|
'jid': self.room_jid,
|
|
|
|
'autojoin': '0',
|
|
|
|
'password': '',
|
2006-11-05 23:09:19 +01:00
|
|
|
'nick': self.nick
|
2006-01-07 23:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for bookmark in gajim.connections[self.account].bookmarks:
|
|
|
|
if bookmark['jid'] == bm['jid']:
|
|
|
|
dialogs.ErrorDialog(
|
|
|
|
_('Bookmark already set'),
|
2006-10-07 16:36:08 +02:00
|
|
|
_('Group Chat "%s" is already in your bookmarks.') % bm['jid'])
|
2006-01-07 23:53:46 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
gajim.connections[self.account].bookmarks.append(bm)
|
|
|
|
gajim.connections[self.account].store_bookmarks()
|
|
|
|
|
2006-03-18 10:05:46 +01:00
|
|
|
gajim.interface.roster.actions_menu_needs_rebuild = True
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
dialogs.InformationDialog(
|
|
|
|
_('Bookmark has been added successfully'),
|
|
|
|
_('You can manage your bookmarks via Actions menu in your roster.'))
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def handle_message_textview_mykey_press(self, widget, event_keyval,
|
|
|
|
event_keymod):
|
2006-01-07 23:53:46 +01:00
|
|
|
# NOTE: handles mykeypress which is custom signal connected to this
|
|
|
|
# CB in new_room(). for this singal see message_textview.py
|
|
|
|
|
|
|
|
# construct event instance from binding
|
|
|
|
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS) # it's always a key-press here
|
|
|
|
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()
|
|
|
|
|
|
|
|
if event.keyval == gtk.keysyms.Tab: # TAB
|
|
|
|
cursor_position = message_buffer.get_insert()
|
|
|
|
end_iter = message_buffer.get_iter_at_mark(cursor_position)
|
2006-10-03 16:12:42 +02:00
|
|
|
text = message_buffer.get_text(start_iter, end_iter, False).decode(
|
|
|
|
'utf-8')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
splitted_text = text.split()
|
2006-11-10 21:06:57 +01:00
|
|
|
# topic completion
|
|
|
|
splitted_text2 = text.split(None, 1)
|
|
|
|
if text.startswith('/topic '):
|
|
|
|
if len(splitted_text2) == 2 and \
|
2007-02-04 14:01:04 +01:00
|
|
|
self.subject.startswith(splitted_text2[1]) and\
|
|
|
|
len(self.subject) > len(splitted_text2[1]):
|
2006-11-10 21:06:57 +01:00
|
|
|
message_buffer.insert_at_cursor(
|
|
|
|
self.subject[len(splitted_text2[1]):])
|
|
|
|
return True
|
|
|
|
elif len(splitted_text2) == 1 and text.startswith('/topic '):
|
|
|
|
message_buffer.delete(start_iter, end_iter)
|
|
|
|
message_buffer.insert_at_cursor('/topic '+self.subject)
|
|
|
|
return True
|
|
|
|
|
2006-01-07 23:53:46 +01:00
|
|
|
# command completion
|
|
|
|
if text.startswith('/') and len(splitted_text) == 1:
|
|
|
|
text = splitted_text[0]
|
|
|
|
if len(text) == 1: # user wants to cycle all commands
|
2007-02-08 20:08:44 +01:00
|
|
|
self.cmd_hits = GroupchatControl.MUC_CMDS
|
2006-01-07 23:53:46 +01:00
|
|
|
else:
|
|
|
|
# cycle possible commands depending on what the user typed
|
|
|
|
if self.last_key_tabs and len(self.cmd_hits) and \
|
|
|
|
self.cmd_hits[0].startswith(text.lstrip('/')):
|
|
|
|
self.cmd_hits.append(self.cmd_hits[0])
|
|
|
|
self.cmd_hits.pop(0)
|
|
|
|
else: # find possible commands
|
|
|
|
self.cmd_hits = []
|
2007-02-08 20:08:44 +01:00
|
|
|
for cmd in GroupchatControl.MUC_CMDS:
|
2006-01-07 23:53:46 +01:00
|
|
|
if cmd.startswith(text.lstrip('/')):
|
|
|
|
self.cmd_hits.append(cmd)
|
|
|
|
if len(self.cmd_hits):
|
|
|
|
message_buffer.delete(start_iter, end_iter)
|
|
|
|
message_buffer.insert_at_cursor('/' + self.cmd_hits[0] + ' ')
|
|
|
|
self.last_key_tabs = True
|
|
|
|
return True
|
|
|
|
|
|
|
|
# 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
|
2006-05-06 21:43:43 +02:00
|
|
|
else:
|
|
|
|
begin = ''
|
|
|
|
|
2007-01-09 23:36:26 +01:00
|
|
|
gc_refer_to_nick_char = gajim.config.get('gc_refer_to_nick_char')
|
2006-05-06 21:43:43 +02:00
|
|
|
if len(self.nick_hits) and \
|
|
|
|
self.nick_hits[0].startswith(begin.replace(
|
2007-01-09 23:36:26 +01:00
|
|
|
gc_refer_to_nick_char, '')) and \
|
2006-05-06 21:43:43 +02:00
|
|
|
self.last_key_tabs: # we should cycle
|
|
|
|
self.nick_hits.append(self.nick_hits[0])
|
|
|
|
self.nick_hits.pop(0)
|
|
|
|
else:
|
|
|
|
self.nick_hits = [] # clear the hit list
|
|
|
|
list_nick = gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid)
|
2007-05-17 17:54:23 +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)
|
|
|
|
|
2007-01-09 23:24:41 +01:00
|
|
|
list_nick.remove(self.nick) # Skip self
|
2006-05-06 21:43:43 +02:00
|
|
|
for nick in list_nick:
|
|
|
|
if nick.lower().startswith(begin.lower()):
|
|
|
|
# the word is the begining of a nick
|
|
|
|
self.nick_hits.append(nick)
|
|
|
|
if len(self.nick_hits):
|
2006-05-06 22:32:07 +02:00
|
|
|
if len(splitted_text) < 2: # This is the 1st word of the line or no word
|
2007-01-09 23:36:26 +01:00
|
|
|
add = gc_refer_to_nick_char + ' '
|
2006-01-07 23:53:46 +01:00
|
|
|
else:
|
2006-05-06 21:43:43 +02:00
|
|
|
add = ' '
|
|
|
|
start_iter = end_iter.copy()
|
|
|
|
if self.last_key_tabs and begin.endswith(', '):
|
|
|
|
# have to accomodate for the added space from last
|
|
|
|
# completion
|
|
|
|
start_iter.backward_chars(len(begin) + 2)
|
|
|
|
elif self.last_key_tabs:
|
|
|
|
# have to accomodate for the added space from last
|
|
|
|
# completion
|
|
|
|
start_iter.backward_chars(len(begin) + 1)
|
|
|
|
else:
|
|
|
|
start_iter.backward_chars(len(begin))
|
2006-01-07 23:53:46 +01:00
|
|
|
|
2006-05-06 21:43:43 +02:00
|
|
|
message_buffer.delete(start_iter, end_iter)
|
|
|
|
message_buffer.insert_at_cursor(self.nick_hits[0] + add)
|
|
|
|
self.last_key_tabs = True
|
|
|
|
return True
|
2006-01-07 23:53:46 +01:00
|
|
|
self.last_key_tabs = False
|
|
|
|
|
|
|
|
def on_list_treeview_key_press_event(self, widget, event):
|
|
|
|
if event.keyval == gtk.keysyms.Escape:
|
2006-09-26 09:05:39 +02:00
|
|
|
selection = widget.get_selection()
|
|
|
|
model, iter = selection.get_selected()
|
|
|
|
if iter:
|
|
|
|
widget.get_selection().unselect_all()
|
|
|
|
return True
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
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.roster.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.roster.jabber_state_images['16']['closed']
|
|
|
|
model[iter][C_IMG] = image
|
|
|
|
|
|
|
|
def kick(self, widget, nick):
|
|
|
|
'''kick a user'''
|
|
|
|
# ask for reason
|
|
|
|
instance = dialogs.InputDialog(_('Kicking %s') % nick,
|
|
|
|
_('You may specify a reason below:'))
|
|
|
|
response = instance.get_response()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
reason = instance.input_entry.get_text().decode('utf-8')
|
|
|
|
else:
|
|
|
|
return # stop kicking procedure
|
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick, 'none',
|
|
|
|
reason)
|
|
|
|
|
|
|
|
def mk_menu(self, event, iter):
|
|
|
|
'''Make contact's popup menu'''
|
|
|
|
model = self.list_treeview.get_model()
|
|
|
|
nick = model[iter][C_NICK].decode('utf-8')
|
|
|
|
c = gajim.contacts.get_gc_contact(self.account, 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
|
2006-10-03 16:12:42 +02:00
|
|
|
user_affiliation = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
self.room_jid, user_nick).affiliation
|
2006-01-07 23:53:46 +01:00
|
|
|
user_role = self.get_role(user_nick)
|
|
|
|
|
|
|
|
# making menu from glade
|
2006-05-02 17:53:25 +02:00
|
|
|
xml = gtkgui_helpers.get_glade('gc_occupants_menu.glade')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
# these conditions were taken from JEP 0045
|
|
|
|
item = xml.get_widget('kick_menuitem')
|
|
|
|
if user_role != 'moderator' or \
|
2006-10-03 16:12:42 +02:00
|
|
|
(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'):
|
2006-01-07 23:53:46 +01:00
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.kick, nick)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('voice_checkmenuitem')
|
|
|
|
item.set_active(target_role != 'visitor')
|
|
|
|
if user_role != 'moderator' or \
|
2006-10-03 16:12:42 +02:00
|
|
|
user_affiliation == 'none' or \
|
|
|
|
(user_affiliation=='member' and target_affiliation!='none') or \
|
|
|
|
target_affiliation in ('admin', 'owner'):
|
2006-01-07 23:53:46 +01:00
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_voice_checkmenuitem_activate,
|
2006-10-03 16:12:42 +02:00
|
|
|
nick)
|
2006-04-17 23:59:04 +02:00
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('moderator_checkmenuitem')
|
|
|
|
item.set_active(target_role == 'moderator')
|
|
|
|
if not user_affiliation in ('admin', 'owner') or \
|
2006-10-03 16:12:42 +02:00
|
|
|
target_affiliation in ('admin', 'owner'):
|
2006-01-07 23:53:46 +01:00
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_moderator_checkmenuitem_activate,
|
|
|
|
nick)
|
|
|
|
self.handlers[id] = item
|
|
|
|
|
2006-01-07 23:53:46 +01:00
|
|
|
item = xml.get_widget('ban_menuitem')
|
|
|
|
if not user_affiliation in ('admin', 'owner') or \
|
2006-10-03 16:12:42 +02:00
|
|
|
(target_affiliation in ('admin', 'owner') and\
|
|
|
|
user_affiliation != 'owner'):
|
2006-01-07 23:53:46 +01:00
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.ban, jid)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('member_checkmenuitem')
|
|
|
|
item.set_active(target_affiliation != 'none')
|
|
|
|
if not user_affiliation in ('admin', 'owner') or \
|
2006-10-03 16:12:42 +02:00
|
|
|
(user_affiliation != 'owner' and target_affiliation in ('admin','owner')):
|
2006-01-07 23:53:46 +01:00
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_member_checkmenuitem_activate,
|
|
|
|
jid)
|
|
|
|
self.handlers[id] = item
|
|
|
|
|
2006-01-07 23:53:46 +01:00
|
|
|
item = xml.get_widget('admin_checkmenuitem')
|
|
|
|
item.set_active(target_affiliation in ('admin', 'owner'))
|
|
|
|
if not user_affiliation == 'owner':
|
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_admin_checkmenuitem_activate, jid)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('owner_checkmenuitem')
|
|
|
|
item.set_active(target_affiliation == 'owner')
|
|
|
|
if not user_affiliation == 'owner':
|
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_owner_checkmenuitem_activate, jid)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('information_menuitem')
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_info, nick)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('history_menuitem')
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_history, nick)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('add_to_roster_menuitem')
|
|
|
|
if not jid:
|
|
|
|
item.set_sensitive(False)
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_add_to_roster, jid)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
item = xml.get_widget('send_private_message_menuitem')
|
2006-04-17 23:59:04 +02:00
|
|
|
id = item.connect('activate', self.on_send_pm, model, iter)
|
|
|
|
self.handlers[id] = item
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
# show the popup now!
|
|
|
|
menu = xml.get_widget('gc_occupants_menu')
|
|
|
|
menu.show_all()
|
2006-05-26 15:25:31 +02:00
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def _start_private_message(self, nick):
|
2006-01-08 06:05:16 +01:00
|
|
|
gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
2007-05-20 17:41:20 +02:00
|
|
|
nick_jid = gc_c.get_full_jid()
|
2006-01-07 23:53:46 +01:00
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account)
|
2006-01-07 23:53:46 +01:00
|
|
|
if not win:
|
2007-05-20 17:41:20 +02:00
|
|
|
gajim.interface.roster.new_private_chat(gc_c, self.account)
|
2006-01-25 03:43:55 +01:00
|
|
|
win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account)
|
|
|
|
win.set_active_tab(nick_jid, self.account)
|
2006-01-07 23:53:46 +01:00
|
|
|
win.window.present()
|
|
|
|
|
2007-04-26 18:44:00 +02:00
|
|
|
def on_row_activated(self, widget, path):
|
|
|
|
'''When an iter is activated (dubblick or single click if gnome is set
|
|
|
|
this way'''
|
2006-01-07 23:53:46 +01:00
|
|
|
model = widget.get_model()
|
|
|
|
if len(path) == 1: # It's a group
|
|
|
|
if (widget.row_expanded(path)):
|
|
|
|
widget.collapse_row(path)
|
|
|
|
else:
|
|
|
|
widget.expand_row(path, False)
|
|
|
|
else: # We want to send a private message
|
2006-02-05 00:07:46 +01:00
|
|
|
nick = model[path][C_NICK].decode('utf-8')
|
2006-01-08 06:05:16 +01:00
|
|
|
self._start_private_message(nick)
|
2007-06-07 13:58:56 +02:00
|
|
|
|
2007-04-26 18:44:00 +02:00
|
|
|
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)
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def on_list_treeview_button_press_event(self, widget, event):
|
|
|
|
'''popup user's group's or agent menu'''
|
|
|
|
if event.button == 3: # right click
|
|
|
|
try:
|
|
|
|
path, column, x, y = widget.get_path_at_pos(int(event.x),
|
|
|
|
int(event.y))
|
|
|
|
except TypeError:
|
|
|
|
widget.get_selection().unselect_all()
|
|
|
|
return
|
|
|
|
widget.get_selection().select_path(path)
|
|
|
|
model = widget.get_model()
|
|
|
|
iter = model.get_iter(path)
|
|
|
|
if len(path) == 2:
|
|
|
|
self.mk_menu(event, iter)
|
|
|
|
return True
|
|
|
|
|
|
|
|
elif event.button == 2: # middle click
|
|
|
|
try:
|
|
|
|
path, column, x, y = widget.get_path_at_pos(int(event.x),
|
|
|
|
int(event.y))
|
|
|
|
except TypeError:
|
|
|
|
widget.get_selection().unselect_all()
|
|
|
|
return
|
|
|
|
widget.get_selection().select_path(path)
|
|
|
|
model = widget.get_model()
|
|
|
|
iter = model.get_iter(path)
|
|
|
|
if len(path) == 2:
|
|
|
|
nick = model[iter][C_NICK].decode('utf-8')
|
2006-01-08 06:05:16 +01:00
|
|
|
self._start_private_message(nick)
|
2006-01-07 23:53:46 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
elif event.button == 1: # left click
|
|
|
|
try:
|
|
|
|
path, column, x, y = widget.get_path_at_pos(int(event.x),
|
|
|
|
int(event.y))
|
|
|
|
except TypeError:
|
|
|
|
widget.get_selection().unselect_all()
|
|
|
|
return
|
|
|
|
|
2007-05-14 19:29:06 +02:00
|
|
|
if gajim.single_click and not event.state & gtk.gdk.SHIFT_MASK:
|
2007-04-26 18:44:00 +02:00
|
|
|
self.on_row_activated(widget, path)
|
2006-05-07 14:23:28 +02:00
|
|
|
return True
|
2007-04-26 18:44:00 +02:00
|
|
|
else:
|
|
|
|
model = widget.get_model()
|
|
|
|
iter = model.get_iter(path)
|
|
|
|
nick = model[iter][C_NICK].decode('utf-8')
|
|
|
|
if not nick in gajim.contacts.get_nick_list(self.account,
|
|
|
|
self.room_jid):
|
2007-05-14 19:29:06 +02:00
|
|
|
# it's a group
|
2007-04-26 18:44:00 +02:00
|
|
|
col = widget.get_column(0)
|
|
|
|
avatar_cell = col.get_cell_renderers()[0]
|
|
|
|
(pos, avatar_size) = col.cell_get_position(avatar_cell)
|
|
|
|
status_cell = col.get_cell_renderers()[1]
|
|
|
|
(pos, status_size) = col.cell_get_position(status_cell)
|
|
|
|
if x > avatar_size and x < avatar_size + status_size:
|
|
|
|
if (widget.row_expanded(path)):
|
|
|
|
widget.collapse_row(path)
|
|
|
|
else:
|
|
|
|
widget.expand_row(path, False)
|
|
|
|
elif event.state & gtk.gdk.SHIFT_MASK:
|
|
|
|
self.append_nick_in_msg_textview(self.msg_textview, nick)
|
|
|
|
self.msg_textview.grab_focus()
|
|
|
|
return True
|
2006-01-07 23:53:46 +01:00
|
|
|
|
2006-05-07 14:47:24 +02:00
|
|
|
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:
|
2007-01-09 23:36:26 +01:00
|
|
|
gc_refer_to_nick_char = gajim.config.get('gc_refer_to_nick_char')
|
|
|
|
add = gc_refer_to_nick_char + ' '
|
2006-05-07 14:47:24 +02:00
|
|
|
message_buffer.insert_at_cursor(start + nick + add)
|
|
|
|
|
2006-01-07 23:53:46 +01:00
|
|
|
def on_list_treeview_motion_notify_event(self, widget, event):
|
|
|
|
model = widget.get_model()
|
|
|
|
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:
|
|
|
|
iter = model.get_iter(row)
|
|
|
|
except:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
return
|
|
|
|
typ = model[iter][C_TYPE].decode('utf-8')
|
|
|
|
if typ == 'contact':
|
|
|
|
account = self.account
|
|
|
|
|
|
|
|
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
|
|
|
|
self.tooltip.id = row
|
|
|
|
nick = model[iter][C_NICK].decode('utf-8')
|
|
|
|
self.tooltip.timeout = gobject.timeout_add(500,
|
|
|
|
self.show_tooltip, gajim.contacts.get_gc_contact(account,
|
|
|
|
self.room_jid, nick))
|
|
|
|
|
|
|
|
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):
|
|
|
|
pointer = self.list_treeview.get_pointer()
|
|
|
|
props = self.list_treeview.get_path_at_pos(pointer[0], pointer[1])
|
2006-02-28 18:24:36 +01:00
|
|
|
# check if the current pointer is at the same path
|
|
|
|
# as it was before setting the timeout
|
2006-01-07 23:53:46 +01:00
|
|
|
if props and self.tooltip.id == props[0]:
|
2006-01-09 01:47:54 +01:00
|
|
|
rect = self.list_treeview.get_cell_area(props[0],props[1])
|
2006-01-07 23:53:46 +01:00
|
|
|
position = self.list_treeview.window.get_origin()
|
2006-02-28 18:24:36 +01:00
|
|
|
self.tooltip.show_tooltip(contact, rect.height,
|
|
|
|
position[1] + rect.y)
|
2006-01-07 23:53:46 +01:00
|
|
|
else:
|
|
|
|
self.tooltip.hide_tooltip()
|
|
|
|
|
|
|
|
|
|
|
|
def grant_voice(self, widget, nick):
|
|
|
|
'''grant voice privilege to a user'''
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
|
|
|
'participant')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def revoke_voice(self, widget, nick):
|
|
|
|
'''revoke voice privilege to a user'''
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
|
|
|
'visitor')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def grant_moderator(self, widget, nick):
|
|
|
|
'''grant moderator privilege to a user'''
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
|
|
|
'moderator')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def revoke_moderator(self, widget, nick):
|
|
|
|
'''revoke moderator privilege to a user'''
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.connections[self.account].gc_set_role(self.room_jid, nick,
|
|
|
|
'participant')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def ban(self, widget, jid):
|
|
|
|
'''ban a user'''
|
|
|
|
# to ban we know the real jid. so jid is not fakejid
|
|
|
|
nick = gajim.get_nick_from_jid(jid)
|
|
|
|
# ask for reason
|
|
|
|
instance = dialogs.InputDialog(_('Banning %s') % nick,
|
|
|
|
_('You may specify a reason below:'))
|
|
|
|
response = instance.get_response()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
reason = instance.input_entry.get_text().decode('utf-8')
|
|
|
|
else:
|
|
|
|
return # stop banning procedure
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2006-10-03 16:12:42 +02:00
|
|
|
'outcast', reason)
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def grant_membership(self, widget, jid):
|
|
|
|
'''grant membership privilege to a user'''
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2006-10-03 16:12:42 +02:00
|
|
|
'member')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def revoke_membership(self, widget, jid):
|
|
|
|
'''revoke membership privilege to a user'''
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
2006-10-03 16:12:42 +02:00
|
|
|
'none')
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def grant_admin(self, widget, jid):
|
|
|
|
'''grant administrative privilege to a user'''
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid, 'admin')
|
|
|
|
|
|
|
|
def revoke_admin(self, widget, jid):
|
|
|
|
'''revoke administrative privilege to a user'''
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
|
|
|
'member')
|
|
|
|
|
|
|
|
def grant_owner(self, widget, jid):
|
|
|
|
'''grant owner privilege to a user'''
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid, 'owner')
|
|
|
|
|
|
|
|
def revoke_owner(self, widget, jid):
|
|
|
|
'''revoke owner privilege to a user'''
|
|
|
|
gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid, 'admin')
|
|
|
|
|
2006-01-10 13:55:23 +01:00
|
|
|
def on_info(self, widget, nick):
|
2006-01-07 23:53:46 +01:00
|
|
|
'''Call vcard_information_window class to display user's information'''
|
|
|
|
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
2006-01-11 08:07:45 +01:00
|
|
|
c2 = gajim.contacts.contact_from_gc_contact(c)
|
|
|
|
if gajim.interface.instances[self.account]['infos'].has_key(c2.jid):
|
2006-10-03 16:12:42 +02:00
|
|
|
gajim.interface.instances[self.account]['infos'][c2.jid].window.\
|
|
|
|
present()
|
2006-01-07 23:53:46 +01:00
|
|
|
else:
|
2006-01-11 08:07:45 +01:00
|
|
|
gajim.interface.instances[self.account]['infos'][c2.jid] = \
|
2006-10-06 16:29:15 +02:00
|
|
|
vcard.VcardWindow(c2, self.account, c)
|
2006-01-07 23:53:46 +01:00
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def on_history(self, widget, nick):
|
2006-01-07 23:53:46 +01:00
|
|
|
jid = gajim.construct_fjid(self.room_jid, nick)
|
2006-01-12 03:36:06 +01:00
|
|
|
self._on_history_menuitem_activate(widget = widget, jid = jid)
|
2006-01-07 23:53:46 +01:00
|
|
|
|
|
|
|
def on_add_to_roster(self, widget, jid):
|
|
|
|
dialogs.AddNewContactWindow(self.account, jid)
|
|
|
|
|
|
|
|
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:
|
2007-05-09 22:28:21 +02:00
|
|
|
self.revoke_owner(widget, jid)
|