2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/chat_control.py
|
2005-12-29 04:21:43 +01:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Copyright (C) 2006-2008 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Nikos Kouremenos <kourem AT gmail.com>
|
2008-08-22 05:15:54 +02:00
|
|
|
## Travis Shirk <travis AT pobox.com>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
|
|
|
|
## Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
2005-12-29 04:21:43 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-12-29 04:21:43 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-12-29 04:21:43 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-12-29 04:21:43 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-12-29 04:21:43 +01:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-12-29 04:21:43 +01:00
|
|
|
|
2006-01-12 00:17:16 +01:00
|
|
|
import os
|
2006-01-01 20:40:05 +01:00
|
|
|
import time
|
2005-12-29 04:21:43 +01:00
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
import gobject
|
|
|
|
import gtkgui_helpers
|
2009-10-27 18:58:27 +01:00
|
|
|
import gui_menu_builder
|
2006-01-02 03:12:34 +01:00
|
|
|
import message_control
|
2006-01-01 20:40:05 +01:00
|
|
|
import dialogs
|
2006-01-12 03:36:06 +01:00
|
|
|
import history_window
|
2006-09-02 23:01:11 +02:00
|
|
|
import notify
|
2007-10-09 19:48:22 +02:00
|
|
|
import re
|
2005-12-29 04:21:43 +01:00
|
|
|
|
|
|
|
from common import gajim
|
2005-12-31 08:19:43 +01:00
|
|
|
from common import helpers
|
2008-03-17 08:22:43 +01:00
|
|
|
from common import exceptions
|
2006-01-02 03:12:34 +01:00
|
|
|
from message_control import MessageControl
|
2005-12-29 04:21:43 +01:00
|
|
|
from conversation_textview import ConversationTextview
|
|
|
|
from message_textview import MessageTextView
|
2006-04-20 09:43:24 +02:00
|
|
|
from common.contacts import GC_Contact
|
2008-12-02 16:10:31 +01:00
|
|
|
from common.logger import constants
|
2008-07-29 00:33:20 +02:00
|
|
|
from common.pep import MOODS, ACTIVITIES
|
2008-11-20 16:19:25 +01:00
|
|
|
from common.xmpp.protocol import NS_XHTML, NS_XHTML_IM, NS_FILE, NS_MUC
|
|
|
|
from common.xmpp.protocol import NS_RECEIPTS, NS_ESESSION
|
2009-10-03 22:40:12 +02:00
|
|
|
from common.xmpp.protocol import NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO, NS_JINGLE_ICE_UDP
|
2005-12-29 04:21:43 +01:00
|
|
|
|
2009-10-02 22:57:11 +02:00
|
|
|
from command_system.implementation.middleware import ChatCommandProcessor
|
|
|
|
from command_system.implementation.middleware import CommandTools
|
|
|
|
from command_system.implementation.hosts import ChatCommands
|
|
|
|
|
|
|
|
# Here we load the module with the standard commands, so they are being detected
|
|
|
|
# and dispatched.
|
|
|
|
import command_system.implementation.standard
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2005-12-31 08:19:43 +01:00
|
|
|
try:
|
|
|
|
import gtkspell
|
|
|
|
HAS_GTK_SPELL = True
|
2009-02-12 23:15:18 +01:00
|
|
|
except ImportError:
|
2005-12-31 08:19:43 +01:00
|
|
|
HAS_GTK_SPELL = False
|
|
|
|
|
2006-09-03 19:04:41 +02:00
|
|
|
# the next script, executed in the "po" directory,
|
|
|
|
# generates the following list.
|
|
|
|
##!/bin/sh
|
2007-10-07 22:36:43 +02:00
|
|
|
#LANG=$(for i in *.po; do j=${i/.po/}; echo -n "_('"$j"')":" '"$j"', " ; done)
|
2006-09-03 19:04:41 +02:00
|
|
|
#echo "{_('en'):'en'",$LANG"}"
|
2007-02-12 19:33:33 +01:00
|
|
|
langs = {_('English'): 'en', _('Belarusian'): 'be', _('Bulgarian'): 'bg', _('Breton'): 'br', _('Czech'): 'cs', _('German'): 'de', _('Greek'): 'el', _('British'): 'en_GB', _('Esperanto'): 'eo', _('Spanish'): 'es', _('Basque'): 'eu', _('French'): 'fr', _('Croatian'): 'hr', _('Italian'): 'it', _('Norwegian (b)'): 'nb', _('Dutch'): 'nl', _('Norwegian'): 'no', _('Polish'): 'pl', _('Portuguese'): 'pt', _('Brazilian Portuguese'): 'pt_BR', _('Russian'): 'ru', _('Serbian'): 'sr', _('Slovak'): 'sk', _('Swedish'): 'sv', _('Chinese (Ch)'): 'zh_CN'}
|
2006-09-03 19:04:41 +02:00
|
|
|
|
2009-09-04 21:02:55 +02:00
|
|
|
if gajim.config.get('use_speller') and HAS_GTK_SPELL:
|
|
|
|
# loop removing non-existent dictionaries
|
|
|
|
# iterating on a copy
|
|
|
|
tv = gtk.TextView()
|
|
|
|
spell = gtkspell.Spell(tv)
|
|
|
|
for lang in dict(langs):
|
|
|
|
try:
|
|
|
|
spell.set_language(langs[lang])
|
|
|
|
except OSError:
|
|
|
|
del langs[lang]
|
2009-09-15 21:19:38 +02:00
|
|
|
if spell:
|
|
|
|
spell.detach()
|
|
|
|
del tv
|
2009-09-04 21:02:55 +02:00
|
|
|
|
2005-12-31 22:55:44 +01:00
|
|
|
################################################################################
|
2009-10-02 22:57:11 +02:00
|
|
|
class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
2006-01-08 05:31:02 +01:00
|
|
|
'''A base class containing a banner, ConversationTextview, MessageTextView
|
2005-12-31 01:50:33 +01:00
|
|
|
'''
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2007-10-09 19:48:22 +02:00
|
|
|
def make_href(self, match):
|
|
|
|
url_color = gajim.config.get('urlmsgcolor')
|
|
|
|
return '<a href="%s"><span color="%s">%s</span></a>' % (match.group(),
|
|
|
|
url_color, match.group())
|
|
|
|
|
2006-03-20 17:22:34 +01:00
|
|
|
def get_font_attrs(self):
|
2007-10-07 22:36:43 +02:00
|
|
|
''' get pango font attributes for banner from theme settings '''
|
2006-03-20 17:22:34 +01:00
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
bannerfont = gajim.config.get_per('themes', theme, 'bannerfont')
|
|
|
|
bannerfontattrs = gajim.config.get_per('themes', theme, 'bannerfontattrs')
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2006-03-20 17:22:34 +01:00
|
|
|
if bannerfont:
|
|
|
|
font = pango.FontDescription(bannerfont)
|
|
|
|
else:
|
|
|
|
font = pango.FontDescription('Normal')
|
|
|
|
if bannerfontattrs:
|
|
|
|
# B attribute is set by default
|
|
|
|
if 'B' in bannerfontattrs:
|
|
|
|
font.set_weight(pango.WEIGHT_HEAVY)
|
|
|
|
if 'I' in bannerfontattrs:
|
|
|
|
font.set_style(pango.STYLE_ITALIC)
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2006-03-20 17:22:34 +01:00
|
|
|
font_attrs = 'font_desc="%s"' % font.to_string()
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2006-03-20 17:22:34 +01:00
|
|
|
# in case there is no font specified we use x-large font size
|
|
|
|
if font.get_size() == 0:
|
|
|
|
font_attrs = '%s size="x-large"' % font_attrs
|
|
|
|
font.set_weight(pango.WEIGHT_NORMAL)
|
2006-03-21 23:55:25 +01:00
|
|
|
font_attrs_small = 'font_desc="%s" size="small"' % font.to_string()
|
2006-03-20 17:22:34 +01:00
|
|
|
return (font_attrs, font_attrs_small)
|
2006-09-02 23:01:11 +02:00
|
|
|
|
|
|
|
def get_nb_unread(self):
|
|
|
|
jid = self.contact.jid
|
|
|
|
if self.resource:
|
|
|
|
jid += '/' + self.resource
|
|
|
|
type_ = self.type_id
|
|
|
|
return len(gajim.events.get_events(self.account, jid, ['printed_' + type_,
|
|
|
|
type_]))
|
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
def draw_banner(self):
|
2008-05-13 03:59:10 +02:00
|
|
|
'''Draw the fat line at the top of the window that
|
|
|
|
houses the icon, jid, ...
|
2007-01-09 15:23:28 +01:00
|
|
|
'''
|
|
|
|
self.draw_banner_text()
|
2005-12-31 01:50:33 +01:00
|
|
|
self._update_banner_state_image()
|
2007-01-09 15:23:28 +01:00
|
|
|
# Derived types MAY implement this
|
|
|
|
|
|
|
|
def draw_banner_text(self):
|
|
|
|
pass # Derived types SHOULD implement this
|
2006-03-28 00:26:30 +02:00
|
|
|
|
2006-01-10 02:47:24 +01:00
|
|
|
def update_ui(self):
|
2005-12-31 01:50:33 +01:00
|
|
|
self.draw_banner()
|
|
|
|
# Derived types SHOULD implement this
|
2006-03-28 00:26:30 +02:00
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
def repaint_themed_widgets(self):
|
2007-01-09 15:23:28 +01:00
|
|
|
self._paint_banner()
|
2005-12-31 01:50:33 +01:00
|
|
|
self.draw_banner()
|
2006-01-07 23:53:46 +01:00
|
|
|
# Derived classes MAY implement this
|
2006-03-28 00:26:30 +02:00
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
def _update_banner_state_image(self):
|
|
|
|
pass # Derived types MAY implement this
|
|
|
|
|
2006-03-28 00:26:30 +02:00
|
|
|
def handle_message_textview_mykey_press(self, widget, event_keyval,
|
|
|
|
event_keymod):
|
2009-02-09 20:38:05 +01:00
|
|
|
# Derived should implement this rather than connecting to the event
|
|
|
|
# itself.
|
2009-09-17 12:25:25 +02:00
|
|
|
|
|
|
|
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
|
|
|
|
event.keyval = event_keyval
|
|
|
|
event.state = event_keymod
|
|
|
|
event.time = 0
|
|
|
|
|
|
|
|
buffer = widget.get_buffer()
|
|
|
|
start, end = buffer.get_bounds()
|
|
|
|
|
|
|
|
if event.keyval -- gtk.keysyms.Tab:
|
|
|
|
position = buffer.get_insert()
|
|
|
|
end = buffer.get_iter_at_mark(position)
|
|
|
|
|
|
|
|
text = buffer.get_text(start, end, False)
|
|
|
|
text = text.decode('utf8')
|
|
|
|
|
2009-09-17 18:06:38 +02:00
|
|
|
splitted = text.split()
|
|
|
|
|
2009-09-17 12:25:25 +02:00
|
|
|
if (text.startswith(self.COMMAND_PREFIX) and not
|
2009-09-17 18:06:38 +02:00
|
|
|
text.startswith(self.COMMAND_PREFIX * 2) and len(splitted) == 1):
|
2009-09-17 12:25:25 +02:00
|
|
|
|
2009-09-17 18:06:38 +02:00
|
|
|
text = splitted[0]
|
2009-09-17 12:25:25 +02:00
|
|
|
bare = text.lstrip(self.COMMAND_PREFIX)
|
|
|
|
|
|
|
|
if len(text) == 1:
|
|
|
|
self.command_hits = []
|
|
|
|
for command in self.list_commands():
|
|
|
|
for name in command.names:
|
|
|
|
self.command_hits.append(name)
|
|
|
|
else:
|
|
|
|
if (self.last_key_tabs and self.command_hits and
|
|
|
|
self.command_hits[0].startswith(bare)):
|
|
|
|
self.command_hits.append(self.command_hits.pop(0))
|
|
|
|
else:
|
|
|
|
self.command_hits = []
|
|
|
|
for command in self.list_commands():
|
|
|
|
for name in command.names:
|
|
|
|
if name.startswith(bare):
|
|
|
|
self.command_hits.append(name)
|
|
|
|
|
|
|
|
if self.command_hits:
|
|
|
|
buffer.delete(start, end)
|
|
|
|
buffer.insert_at_cursor(self.COMMAND_PREFIX + self.command_hits[0] + ' ')
|
|
|
|
self.last_key_tabs = True
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.last_key_tabs = False
|
2006-01-07 23:53:46 +01:00
|
|
|
|
2007-10-09 19:48:22 +02:00
|
|
|
def status_url_clicked(self, widget, url):
|
|
|
|
helpers.launch_browser_mailer('url', url)
|
|
|
|
|
2008-05-13 03:59:10 +02:00
|
|
|
def __init__(self, type_id, parent_win, widget_name, contact, acct,
|
2007-02-08 19:32:10 +01:00
|
|
|
resource = None):
|
2008-07-23 20:21:02 +02:00
|
|
|
if resource is None:
|
|
|
|
# We very likely got a contact with a random resource.
|
|
|
|
# This is bad, we need the highest for caps etc.
|
2008-07-23 20:34:26 +02:00
|
|
|
c = gajim.contacts.get_contact_with_highest_priority(
|
2008-07-23 20:21:02 +02:00
|
|
|
acct, contact.jid)
|
2008-07-26 03:16:24 +02:00
|
|
|
if c and not isinstance(c, GC_Contact):
|
2008-07-23 20:34:26 +02:00
|
|
|
contact = c
|
2008-07-23 20:21:02 +02:00
|
|
|
|
2006-03-28 00:26:30 +02:00
|
|
|
MessageControl.__init__(self, type_id, parent_win, widget_name,
|
2008-12-02 14:58:54 +01:00
|
|
|
contact, acct, resource = resource)
|
2008-05-04 22:47:51 +02:00
|
|
|
|
|
|
|
widget = self.xml.get_widget('history_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('clicked', self._on_history_menuitem_activate)
|
|
|
|
self.handlers[id_] = widget
|
2008-05-04 22:47:51 +02:00
|
|
|
|
2006-09-30 16:28:10 +02:00
|
|
|
# when/if we do XHTML we will put formatting buttons back
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = self.xml.get_widget('emoticons_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('clicked', self.on_emoticons_button_clicked)
|
|
|
|
self.handlers[id_] = widget
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2007-07-23 15:07:04 +02:00
|
|
|
# Create banner and connect signals
|
2006-04-18 17:36:16 +02:00
|
|
|
widget = self.xml.get_widget('banner_eventbox')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('button-press-event',
|
2006-04-18 17:36:16 +02:00
|
|
|
self._on_banner_eventbox_button_press_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
2007-10-09 19:48:22 +02:00
|
|
|
|
2009-02-09 20:38:05 +01:00
|
|
|
self.urlfinder = re.compile(
|
|
|
|
r"(www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'\"]+[^!,\.\s<>\)'\"\]]")
|
2007-10-09 19:48:22 +02:00
|
|
|
|
|
|
|
if gajim.HAVE_PYSEXY:
|
|
|
|
import sexy
|
|
|
|
self.banner_status_label = sexy.UrlLabel()
|
2009-02-09 20:38:05 +01:00
|
|
|
self.banner_status_label.connect('url_activated',
|
|
|
|
self.status_url_clicked)
|
2007-10-09 19:48:22 +02:00
|
|
|
else:
|
|
|
|
self.banner_status_label = gtk.Label()
|
|
|
|
self.banner_status_label.set_selectable(True)
|
|
|
|
self.banner_status_label.set_alignment(0,0.5)
|
2009-04-26 20:57:18 +02:00
|
|
|
self.banner_status_label.connect('populate_popup',
|
|
|
|
self.on_banner_label_populate_popup)
|
2007-10-09 19:48:22 +02:00
|
|
|
|
|
|
|
banner_vbox = self.xml.get_widget('banner_vbox')
|
|
|
|
banner_vbox.pack_start(self.banner_status_label)
|
|
|
|
self.banner_status_label.show()
|
|
|
|
|
2007-07-23 15:07:04 +02:00
|
|
|
# Init DND
|
|
|
|
self.TARGET_TYPE_URI_LIST = 80
|
2007-07-23 23:20:33 +02:00
|
|
|
self.dnd_list = [ ( 'text/uri-list', 0, self.TARGET_TYPE_URI_LIST ),
|
|
|
|
('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_APP, 0)]
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.widget.connect('drag_data_received',
|
2007-07-23 15:07:04 +02:00
|
|
|
self._on_drag_data_received)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.widget
|
2007-07-23 15:07:04 +02:00
|
|
|
self.widget.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
|
|
|
|
gtk.DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
gtk.DEST_DEFAULT_DROP,
|
|
|
|
self.dnd_list, gtk.gdk.ACTION_COPY)
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
# Create textviews and connect signals
|
2006-01-08 05:31:02 +01:00
|
|
|
self.conv_textview = ConversationTextview(self.account)
|
2009-04-30 15:36:29 +02:00
|
|
|
id_ = self.conv_textview.connect('quote', self.on_quote)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.conv_textview.tv.connect('key_press_event',
|
2007-10-10 18:13:16 +02:00
|
|
|
self._conv_textview_key_press_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
2007-07-23 15:07:04 +02:00
|
|
|
# FIXME: DND on non editable TextView, find a better way
|
|
|
|
self.drag_entered = False
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.conv_textview.tv.connect('drag_data_received',
|
2007-07-23 15:07:04 +02:00
|
|
|
self._on_drag_data_received)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
id_ = self.conv_textview.tv.connect('drag_motion', self._on_drag_motion)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
id_ = self.conv_textview.tv.connect('drag_leave', self._on_drag_leave)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
2007-07-23 15:07:04 +02:00
|
|
|
self.conv_textview.tv.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
|
|
|
|
gtk.DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
gtk.DEST_DEFAULT_DROP,
|
|
|
|
self.dnd_list, gtk.gdk.ACTION_COPY)
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2006-01-25 15:05:31 +01:00
|
|
|
self.conv_scrolledwindow = self.xml.get_widget(
|
|
|
|
'conversation_scrolledwindow')
|
2006-04-18 17:36:16 +02:00
|
|
|
self.conv_scrolledwindow.add(self.conv_textview.tv)
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = self.conv_scrolledwindow.get_vadjustment()
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('value-changed',
|
2006-01-02 10:04:30 +01:00
|
|
|
self.on_conversation_vadjustment_value_changed)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
|
|
|
id_ = widget.connect('changed',
|
2007-04-17 11:41:22 +02:00
|
|
|
self.on_conversation_vadjustment_changed)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
2007-04-17 11:41:22 +02:00
|
|
|
self.scroll_to_end_id = None
|
|
|
|
self.was_at_the_end = True
|
2007-07-23 15:07:04 +02:00
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
# add MessageTextView to UI and connect signals
|
2006-01-02 10:04:30 +01:00
|
|
|
self.msg_scrolledwindow = self.xml.get_widget('message_scrolledwindow')
|
2005-12-31 01:50:33 +01:00
|
|
|
self.msg_textview = MessageTextView()
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.msg_textview.connect('mykeypress',
|
2006-09-03 19:04:41 +02:00
|
|
|
self._on_message_textview_mykeypress_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.msg_textview
|
2006-01-02 10:04:30 +01:00
|
|
|
self.msg_scrolledwindow.add(self.msg_textview)
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.msg_textview.connect('key_press_event',
|
2006-09-03 19:04:41 +02:00
|
|
|
self._on_message_textview_key_press_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.msg_textview
|
|
|
|
id_ = self.msg_textview.connect('size-request', self.size_request)
|
|
|
|
self.handlers[id_] = self.msg_textview
|
|
|
|
id_ = self.msg_textview.connect('populate_popup',
|
2006-09-03 19:04:41 +02:00
|
|
|
self.on_msg_textview_populate_popup)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.msg_textview
|
2007-07-23 15:07:04 +02:00
|
|
|
# Setup DND
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.msg_textview.connect('drag_data_received',
|
2007-07-23 15:07:04 +02:00
|
|
|
self._on_drag_data_received)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.msg_textview
|
2007-07-23 15:07:04 +02:00
|
|
|
self.msg_textview.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
|
2007-07-23 17:29:53 +02:00
|
|
|
gtk.DEST_DEFAULT_HIGHLIGHT,
|
2007-07-23 15:07:04 +02:00
|
|
|
self.dnd_list, gtk.gdk.ACTION_COPY)
|
2008-05-13 03:59:10 +02:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
self.update_font()
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2006-01-03 05:05:28 +01:00
|
|
|
# Hook up send button
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = self.xml.get_widget('send_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('clicked', self._on_send_button_clicked)
|
|
|
|
self.handlers[id_] = widget
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2008-11-14 12:13:15 +01:00
|
|
|
widget = self.xml.get_widget('formattings_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('clicked', self.on_formattings_button_clicked)
|
|
|
|
self.handlers[id_] = widget
|
2008-11-14 12:13:15 +01:00
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
# the following vars are used to keep history of user's messages
|
|
|
|
self.sent_history = []
|
2006-01-03 04:34:32 +01:00
|
|
|
self.sent_history_pos = 0
|
2007-02-09 00:36:17 +01:00
|
|
|
self.orig_msg = None
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2005-12-31 05:53:14 +01:00
|
|
|
# Emoticons menu
|
|
|
|
# set image no matter if user wants at this time emoticons or not
|
|
|
|
# (so toggle works ok)
|
|
|
|
img = self.xml.get_widget('emoticons_button_image')
|
2006-03-17 00:37:06 +01:00
|
|
|
img.set_from_file(os.path.join(gajim.DATA_DIR, 'emoticons', 'static',
|
|
|
|
'smile.png'))
|
2005-12-31 05:53:14 +01:00
|
|
|
self.toggle_emoticons()
|
|
|
|
|
2005-12-31 08:19:43 +01:00
|
|
|
# Attach speller
|
|
|
|
if gajim.config.get('use_speller') and HAS_GTK_SPELL:
|
2009-01-28 14:16:02 +01:00
|
|
|
self.set_speller()
|
2006-04-18 17:36:16 +02:00
|
|
|
self.conv_textview.tv.show()
|
2007-01-09 15:23:28 +01:00
|
|
|
self._paint_banner()
|
2006-06-01 17:23:38 +02:00
|
|
|
|
2008-02-06 15:59:28 +01:00
|
|
|
# For XEP-0172
|
2006-06-01 17:23:38 +02:00
|
|
|
self.user_nick = None
|
|
|
|
|
2007-08-23 00:08:04 +02:00
|
|
|
self.smooth = True
|
2008-08-22 05:03:15 +02:00
|
|
|
self.msg_textview.grab_focus()
|
2007-08-23 00:08:04 +02:00
|
|
|
|
2009-09-17 12:25:25 +02:00
|
|
|
self.command_hits = []
|
2009-09-17 18:06:38 +02:00
|
|
|
self.last_key_tabs = False
|
2009-09-17 12:25:25 +02:00
|
|
|
|
2009-01-28 14:16:02 +01:00
|
|
|
def set_speller(self):
|
2009-09-04 21:02:55 +02:00
|
|
|
# now set the one the user selected
|
|
|
|
per_type = 'contacts'
|
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
per_type = 'rooms'
|
|
|
|
lang = gajim.config.get_per(per_type, self.contact.jid,
|
|
|
|
'speller_language')
|
|
|
|
if not lang:
|
|
|
|
# use the default one
|
2009-01-28 14:16:02 +01:00
|
|
|
lang = gajim.config.get('speller_language')
|
|
|
|
if not lang:
|
|
|
|
lang = gajim.LANG
|
2009-09-04 21:02:55 +02:00
|
|
|
if lang:
|
|
|
|
try:
|
|
|
|
gtkspell.Spell(self.msg_textview, lang)
|
2009-01-28 14:16:02 +01:00
|
|
|
self.msg_textview.lang = lang
|
2009-09-04 21:02:55 +02:00
|
|
|
except (gobject.GError, RuntimeError, TypeError, OSError):
|
|
|
|
dialogs.AspellDictError(lang)
|
2009-02-06 20:01:36 +01:00
|
|
|
|
2009-04-26 20:57:18 +02:00
|
|
|
def on_banner_label_populate_popup(self, label, menu):
|
|
|
|
'''We override the default context menu and add our own menutiems'''
|
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
menu.prepend(item)
|
|
|
|
|
|
|
|
menu2 = self.prepare_context_menu()
|
|
|
|
i = 0
|
|
|
|
for item in menu2:
|
|
|
|
menu2.remove(item)
|
|
|
|
menu.prepend(item)
|
|
|
|
menu.reorder_child(item, i)
|
|
|
|
i += 1
|
|
|
|
menu.show_all()
|
|
|
|
|
2006-09-03 19:04:41 +02:00
|
|
|
def on_msg_textview_populate_popup(self, textview, menu):
|
2009-02-09 20:38:05 +01:00
|
|
|
'''we override the default context menu and we prepend an option to switch
|
|
|
|
languages'''
|
2006-09-03 19:04:41 +02:00
|
|
|
def _on_select_dictionary(widget, lang):
|
2006-09-12 09:30:19 +02:00
|
|
|
per_type = 'contacts'
|
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
per_type = 'rooms'
|
|
|
|
if not gajim.config.get_per(per_type, self.contact.jid):
|
|
|
|
gajim.config.add_per(per_type, self.contact.jid)
|
|
|
|
gajim.config.set_per(per_type, self.contact.jid, 'speller_language',
|
2006-09-12 09:18:43 +02:00
|
|
|
lang)
|
2006-09-03 19:04:41 +02:00
|
|
|
spell = gtkspell.get_from_text_view(self.msg_textview)
|
2006-09-04 10:00:49 +02:00
|
|
|
self.msg_textview.lang = lang
|
2006-09-03 19:04:41 +02:00
|
|
|
spell.set_language(lang)
|
|
|
|
widget.set_active(True)
|
|
|
|
|
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
menu.prepend(item)
|
|
|
|
|
2006-09-30 02:18:58 +02:00
|
|
|
item = gtk.ImageMenuItem(gtk.STOCK_CLEAR)
|
|
|
|
menu.prepend(item)
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = item.connect('activate', self.msg_textview.clear)
|
|
|
|
self.handlers[id_] = item
|
2006-09-30 02:18:58 +02:00
|
|
|
|
2006-09-03 19:04:41 +02:00
|
|
|
if gajim.config.get('use_speller') and HAS_GTK_SPELL:
|
|
|
|
item = gtk.MenuItem(_('Spelling language'))
|
|
|
|
menu.prepend(item)
|
|
|
|
submenu = gtk.Menu()
|
|
|
|
item.set_submenu(submenu)
|
|
|
|
for lang in sorted(langs):
|
|
|
|
item = gtk.CheckMenuItem(lang)
|
2006-09-04 10:00:49 +02:00
|
|
|
if langs[lang] == self.msg_textview.lang:
|
2006-09-03 19:04:41 +02:00
|
|
|
item.set_active(True)
|
|
|
|
submenu.append(item)
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = item.connect('activate', _on_select_dictionary, langs[lang])
|
|
|
|
self.handlers[id_] = item
|
2006-09-03 19:04:41 +02:00
|
|
|
|
|
|
|
menu.show_all()
|
|
|
|
|
2009-04-30 15:36:29 +02:00
|
|
|
def on_quote(self, widget, text):
|
|
|
|
text = '>' + text.replace('\n', '\n>') + '\n'
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
message_buffer.insert_at_cursor(text)
|
|
|
|
|
2008-05-13 03:59:10 +02:00
|
|
|
# moved from ChatControl
|
2006-04-18 17:36:16 +02:00
|
|
|
def _on_banner_eventbox_button_press_event(self, widget, event):
|
|
|
|
'''If right-clicked, show popup'''
|
|
|
|
if event.button == 3: # right click
|
|
|
|
self.parent_win.popup_menu(event)
|
2005-12-31 22:55:44 +01:00
|
|
|
|
2006-01-03 05:05:28 +01:00
|
|
|
def _on_send_button_clicked(self, widget):
|
|
|
|
'''When send button is pressed: send the current message'''
|
2006-03-08 13:29:34 +01:00
|
|
|
if gajim.connections[self.account].connected < 2: # we are not connected
|
2006-11-20 20:11:31 +01:00
|
|
|
dialogs.ErrorDialog(_('A connection is not available'),
|
2006-03-08 13:29:34 +01:00
|
|
|
_('Your message can not be sent until you are connected.'))
|
|
|
|
return
|
2006-01-03 05:05:28 +01:00
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
start_iter = message_buffer.get_start_iter()
|
|
|
|
end_iter = message_buffer.get_end_iter()
|
|
|
|
message = message_buffer.get_text(start_iter, end_iter, 0).decode('utf-8')
|
2008-11-14 12:13:15 +01:00
|
|
|
xhtml = self.msg_textview.get_xhtml()
|
2006-01-03 05:05:28 +01:00
|
|
|
|
|
|
|
# send the message
|
2008-11-14 12:13:15 +01:00
|
|
|
self.send_message(message, xhtml=xhtml)
|
2006-01-03 05:05:28 +01:00
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
def _paint_banner(self):
|
|
|
|
'''Repaint banner with theme color'''
|
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
bgcolor = gajim.config.get_per('themes', theme, 'bannerbgcolor')
|
|
|
|
textcolor = gajim.config.get_per('themes', theme, 'bannertextcolor')
|
|
|
|
# the backgrounds are colored by using an eventbox by
|
|
|
|
# setting the bg color of the eventbox and the fg of the name_label
|
|
|
|
banner_eventbox = self.xml.get_widget('banner_eventbox')
|
|
|
|
banner_name_label = self.xml.get_widget('banner_name_label')
|
2006-03-25 02:21:16 +01:00
|
|
|
self.disconnect_style_event(banner_name_label)
|
2007-10-09 19:48:22 +02:00
|
|
|
self.disconnect_style_event(self.banner_status_label)
|
2005-12-31 01:50:33 +01:00
|
|
|
if bgcolor:
|
2008-05-13 03:59:10 +02:00
|
|
|
banner_eventbox.modify_bg(gtk.STATE_NORMAL,
|
2005-12-31 01:50:33 +01:00
|
|
|
gtk.gdk.color_parse(bgcolor))
|
2006-03-25 02:21:16 +01:00
|
|
|
default_bg = False
|
2005-12-31 01:50:33 +01:00
|
|
|
else:
|
2006-03-25 02:21:16 +01:00
|
|
|
default_bg = True
|
2005-12-31 01:50:33 +01:00
|
|
|
if textcolor:
|
|
|
|
banner_name_label.modify_fg(gtk.STATE_NORMAL,
|
|
|
|
gtk.gdk.color_parse(textcolor))
|
2007-10-09 19:48:22 +02:00
|
|
|
self.banner_status_label.modify_fg(gtk.STATE_NORMAL,
|
|
|
|
gtk.gdk.color_parse(textcolor))
|
2006-03-25 02:21:16 +01:00
|
|
|
default_fg = False
|
2005-12-31 01:50:33 +01:00
|
|
|
else:
|
2006-03-25 02:21:16 +01:00
|
|
|
default_fg = True
|
|
|
|
if default_bg or default_fg:
|
2006-03-28 14:39:47 +02:00
|
|
|
self._on_style_set_event(banner_name_label, None, default_fg,
|
|
|
|
default_bg)
|
2009-08-07 23:43:19 +02:00
|
|
|
if self.banner_status_label.flags() & gtk.REALIZED:
|
2009-08-06 18:34:53 +02:00
|
|
|
# Widget is realized
|
|
|
|
self._on_style_set_event(self.banner_status_label, None, default_fg,
|
|
|
|
default_bg)
|
2007-10-09 19:48:22 +02:00
|
|
|
|
2006-03-25 02:21:16 +01:00
|
|
|
def disconnect_style_event(self, widget):
|
2007-10-09 19:48:22 +02:00
|
|
|
# Try to find the event_id
|
2008-12-03 18:38:16 +01:00
|
|
|
for id_ in self.handlers.keys():
|
2008-12-03 18:16:04 +01:00
|
|
|
if self.handlers[id_] == widget:
|
2008-12-03 18:38:16 +01:00
|
|
|
widget.disconnect(id_)
|
|
|
|
del self.handlers[id_]
|
2007-10-09 19:48:22 +02:00
|
|
|
break
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-03-25 02:21:16 +01:00
|
|
|
def connect_style_event(self, widget, set_fg = False, set_bg = False):
|
|
|
|
self.disconnect_style_event(widget)
|
2008-12-03 21:45:26 +01:00
|
|
|
id_ = widget.connect('style-set', self._on_style_set_event, set_fg,
|
|
|
|
set_bg)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
2007-10-09 19:48:22 +02:00
|
|
|
|
2006-03-25 02:21:16 +01:00
|
|
|
def _on_style_set_event(self, widget, style, *opts):
|
2008-05-13 03:59:10 +02:00
|
|
|
'''set style of widget from style class *.Frame.Eventbox
|
2006-03-25 02:21:16 +01:00
|
|
|
opts[0] == True -> set fg color
|
2006-03-28 14:39:47 +02:00
|
|
|
opts[1] == True -> set bg color'''
|
2006-03-25 02:21:16 +01:00
|
|
|
banner_eventbox = self.xml.get_widget('banner_eventbox')
|
|
|
|
self.disconnect_style_event(widget)
|
|
|
|
if opts[1]:
|
|
|
|
bg_color = widget.style.bg[gtk.STATE_SELECTED]
|
|
|
|
banner_eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
|
|
|
|
if opts[0]:
|
|
|
|
fg_color = widget.style.fg[gtk.STATE_SELECTED]
|
|
|
|
widget.modify_fg(gtk.STATE_NORMAL, fg_color)
|
|
|
|
self.connect_style_event(widget, opts[0], opts[1])
|
2007-10-09 19:48:22 +02:00
|
|
|
|
2007-10-10 18:13:16 +02:00
|
|
|
def _conv_textview_key_press_event(self, widget, event):
|
2008-12-13 15:32:37 +01:00
|
|
|
if (event.state & gtk.gdk.CONTROL_MASK and event.keyval in (gtk.keysyms.c,
|
|
|
|
gtk.keysyms.Insert)) or (event.state & gtk.gdk.SHIFT_MASK and \
|
|
|
|
event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)):
|
2007-10-10 18:13:16 +02:00
|
|
|
return False
|
|
|
|
self.parent_win.notebook.emit('key_press_event', event)
|
2008-12-05 15:12:31 +01:00
|
|
|
return True
|
2007-10-10 18:13:16 +02:00
|
|
|
|
2008-08-14 18:17:32 +02:00
|
|
|
def show_emoticons_menu(self):
|
|
|
|
if not gajim.config.get('emoticons_theme'):
|
|
|
|
return
|
|
|
|
def set_emoticons_menu_position(w, msg_tv = self.msg_textview):
|
|
|
|
window = msg_tv.get_window(gtk.TEXT_WINDOW_WIDGET)
|
|
|
|
# get the window position
|
|
|
|
origin = window.get_origin()
|
|
|
|
size = window.get_size()
|
|
|
|
buf = msg_tv.get_buffer()
|
|
|
|
# get the cursor position
|
|
|
|
cursor = msg_tv.get_iter_location(buf.get_iter_at_mark(
|
|
|
|
buf.get_insert()))
|
|
|
|
cursor = msg_tv.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT,
|
|
|
|
cursor.x, cursor.y)
|
|
|
|
x = origin[0] + cursor[0]
|
|
|
|
y = origin[1] + size[1]
|
2008-12-02 16:53:23 +01:00
|
|
|
menu_height = gajim.interface.emoticons_menu.size_request()[1]
|
2008-08-14 18:17:32 +02:00
|
|
|
#FIXME: get_line_count is not so good
|
|
|
|
#get the iter of cursor, then tv.get_line_yrange
|
|
|
|
# so we know in which y we are typing (not how many lines we have
|
|
|
|
# then go show just above the current cursor line for up
|
|
|
|
# or just below the current cursor line for down
|
|
|
|
#TEST with having 3 lines and writing in the 2nd
|
|
|
|
if y + menu_height > gtk.gdk.screen_height():
|
|
|
|
# move menu just above cursor
|
|
|
|
y -= menu_height + (msg_tv.allocation.height / buf.get_line_count())
|
|
|
|
#else: # move menu just below cursor
|
|
|
|
# y -= (msg_tv.allocation.height / buf.get_line_count())
|
|
|
|
return (x, y, True) # push_in True
|
|
|
|
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
|
|
|
gajim.interface.emoticons_menu.popup(None, None,
|
|
|
|
set_emoticons_menu_position, 1, 0)
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
def _on_message_textview_key_press_event(self, widget, event):
|
2008-12-05 15:12:31 +01:00
|
|
|
# Ctrl [+ Shift] + Tab are not forwarded to notebook. We handle it here
|
2006-01-10 17:32:43 +01:00
|
|
|
if self.widget_name == 'muc_child_vbox':
|
|
|
|
if event.keyval not in (gtk.keysyms.ISO_Left_Tab, gtk.keysyms.Tab):
|
|
|
|
self.last_key_tabs = False
|
2006-01-03 04:34:32 +01:00
|
|
|
if event.state & gtk.gdk.SHIFT_MASK:
|
2006-01-14 21:40:48 +01:00
|
|
|
# CTRL + SHIFT + TAB
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK and \
|
|
|
|
event.keyval == gtk.keysyms.ISO_Left_Tab:
|
|
|
|
self.parent_win.move_to_next_unread_tab(False)
|
|
|
|
return True
|
2006-01-03 04:34:32 +01:00
|
|
|
# SHIFT + PAGE_[UP|DOWN]: send to conv_textview
|
2006-01-14 21:40:48 +01:00
|
|
|
elif event.keyval == gtk.keysyms.Page_Down or \
|
2006-01-19 02:30:18 +01:00
|
|
|
event.keyval == gtk.keysyms.Page_Up:
|
2006-04-18 17:36:16 +02:00
|
|
|
self.conv_textview.tv.emit('key_press_event', event)
|
2006-01-03 04:34:32 +01:00
|
|
|
return True
|
2006-01-14 21:40:48 +01:00
|
|
|
elif event.state & gtk.gdk.CONTROL_MASK:
|
|
|
|
if event.keyval == gtk.keysyms.Tab: # CTRL + TAB
|
|
|
|
self.parent_win.move_to_next_unread_tab(True)
|
|
|
|
return True
|
2006-01-03 04:34:32 +01:00
|
|
|
return False
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
def _on_message_textview_mykeypress_event(self, widget, event_keyval,
|
2006-03-28 14:39:47 +02:00
|
|
|
event_keymod):
|
2005-12-31 01:50:33 +01:00
|
|
|
'''When a key is pressed:
|
|
|
|
if enter is pressed without the shift key, message (if not empty) is sent
|
|
|
|
and printed in the conversation'''
|
|
|
|
|
|
|
|
# NOTE: handles mykeypress which is custom signal connected to this
|
|
|
|
# CB in new_tab(). for this singal see message_textview.py
|
|
|
|
message_textview = widget
|
|
|
|
message_buffer = message_textview.get_buffer()
|
|
|
|
start_iter, end_iter = message_buffer.get_bounds()
|
2006-10-03 16:12:42 +02:00
|
|
|
message = message_buffer.get_text(start_iter, end_iter, False).decode(
|
|
|
|
'utf-8')
|
2008-12-03 22:56:12 +01:00
|
|
|
xhtml = self.msg_textview.get_xhtml()
|
2005-12-31 01:50:33 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
if event.keyval == gtk.keysyms.Up:
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # Ctrl+UP
|
2006-01-02 23:08:50 +01:00
|
|
|
self.sent_messages_scroll('up', widget.get_buffer())
|
2005-12-31 01:50:33 +01:00
|
|
|
elif event.keyval == gtk.keysyms.Down:
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # Ctrl+Down
|
2006-01-02 23:08:50 +01:00
|
|
|
self.sent_messages_scroll('down', widget.get_buffer())
|
2005-12-31 01:50:33 +01:00
|
|
|
elif event.keyval == gtk.keysyms.Return or \
|
|
|
|
event.keyval == gtk.keysyms.KP_Enter: # ENTER
|
|
|
|
# NOTE: SHIFT + ENTER is not needed to be emulated as it is not
|
|
|
|
# binding at all (textview's default action is newline)
|
|
|
|
|
|
|
|
if gajim.config.get('send_on_ctrl_enter'):
|
|
|
|
# here, we emulate GTK default action on ENTER (add new line)
|
|
|
|
# normally I would add in keypress but it gets way to complex
|
|
|
|
# to get instant result on changing this advanced setting
|
|
|
|
if event.state == 0: # no ctrl, no shift just ENTER add newline
|
|
|
|
end_iter = message_buffer.get_end_iter()
|
|
|
|
message_buffer.insert_at_cursor('\n')
|
|
|
|
send_message = False
|
|
|
|
elif event.state & gtk.gdk.CONTROL_MASK: # CTRL + ENTER
|
|
|
|
send_message = True
|
|
|
|
else: # send on Enter, do newline on Ctrl Enter
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # Ctrl + ENTER
|
|
|
|
end_iter = message_buffer.get_end_iter()
|
|
|
|
message_buffer.insert_at_cursor('\n')
|
|
|
|
send_message = False
|
|
|
|
else: # ENTER
|
|
|
|
send_message = True
|
2008-05-13 03:59:10 +02:00
|
|
|
|
2008-11-10 14:27:25 +01:00
|
|
|
if gajim.connections[self.account].connected < 2 and send_message:
|
|
|
|
# we are not connected
|
2006-11-20 20:11:31 +01:00
|
|
|
dialogs.ErrorDialog(_('A connection is not available'),
|
2006-01-07 23:53:46 +01:00
|
|
|
_('Your message can not be sent until you are connected.'))
|
2005-12-31 01:50:33 +01:00
|
|
|
send_message = False
|
|
|
|
|
|
|
|
if send_message:
|
2008-11-14 12:13:15 +01:00
|
|
|
self.send_message(message, xhtml=xhtml) # send the message
|
2006-01-07 23:53:46 +01:00
|
|
|
else:
|
|
|
|
# Give the control itself a chance to process
|
2006-10-03 16:12:42 +02:00
|
|
|
self.handle_message_textview_mykey_press(widget, event_keyval,
|
|
|
|
event_keymod)
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2007-07-23 15:07:04 +02:00
|
|
|
def _on_drag_data_received(self, widget, context, x, y, selection,
|
|
|
|
target_type, timestamp):
|
2007-10-07 22:36:43 +02:00
|
|
|
pass # Derived classes SHOULD implement this method
|
2007-07-23 15:07:04 +02:00
|
|
|
|
|
|
|
def _on_drag_leave(self, widget, context, time):
|
|
|
|
# FIXME: DND on non editable TextView, find a better way
|
|
|
|
self.drag_entered = False
|
|
|
|
self.conv_textview.tv.set_editable(False)
|
|
|
|
|
|
|
|
def _on_drag_motion(self, widget, context, x, y, time):
|
|
|
|
# FIXME: DND on non editable TextView, find a better way
|
|
|
|
if not self.drag_entered:
|
|
|
|
# We drag new data over the TextView, make it editable to catch dnd
|
|
|
|
self.drag_entered_conv = True
|
|
|
|
self.conv_textview.tv.set_editable(True)
|
|
|
|
|
2009-02-06 20:01:36 +01:00
|
|
|
def send_message(self, message, keyID='', type_='chat', chatstate=None,
|
2009-09-11 03:54:26 +02:00
|
|
|
msg_id=None, composing_xep=None, resource=None,
|
2009-09-12 15:51:21 +02:00
|
|
|
xhtml=None, callback=None, callback_args=[], process_commands=True):
|
2006-12-06 17:19:47 +01:00
|
|
|
'''Send the given message to the active tab. Doesn't return None if error
|
|
|
|
'''
|
2005-12-31 04:53:48 +01:00
|
|
|
if not message or message == '\n':
|
2008-06-08 18:54:59 +02:00
|
|
|
return None
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2009-09-12 15:51:21 +02:00
|
|
|
if process_commands and self.process_as_command(message):
|
|
|
|
return
|
|
|
|
|
2009-09-11 03:54:26 +02:00
|
|
|
MessageControl.send_message(self, message, keyID, type_=type_,
|
|
|
|
chatstate=chatstate, msg_id=msg_id, composing_xep=composing_xep,
|
|
|
|
resource=resource, user_nick=self.user_nick, xhtml=xhtml,
|
|
|
|
callback=callback, callback_args=callback_args)
|
2008-06-08 17:51:55 +02:00
|
|
|
|
2009-09-11 03:54:26 +02:00
|
|
|
# Record message history
|
|
|
|
self.save_sent_message(message)
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2009-09-11 03:54:26 +02:00
|
|
|
# Be sure to send user nickname only once according to JEP-0172
|
|
|
|
self.user_nick = None
|
2006-06-01 17:23:38 +02:00
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
# Clear msg input
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
message_buffer.set_text('') # clear message buffer (and tv of course)
|
|
|
|
|
|
|
|
def save_sent_message(self, message):
|
2008-03-12 00:05:56 +01:00
|
|
|
# save the message, so user can scroll though the list with key up/down
|
2005-12-31 04:53:48 +01:00
|
|
|
size = len(self.sent_history)
|
2008-03-12 00:05:56 +01:00
|
|
|
# we don't want size of the buffer to grow indefinately
|
2005-12-31 04:53:48 +01:00
|
|
|
max_size = gajim.config.get('key_up_lines')
|
|
|
|
if size >= max_size:
|
2008-05-13 03:59:10 +02:00
|
|
|
for i in xrange(0, size - 1):
|
2005-12-31 04:53:48 +01:00
|
|
|
self.sent_history[i] = self.sent_history[i + 1]
|
|
|
|
self.sent_history[max_size - 1] = message
|
2008-03-12 00:05:56 +01:00
|
|
|
# self.sent_history_pos has changed if we browsed sent_history,
|
|
|
|
# reset to real value
|
|
|
|
self.sent_history_pos = max_size
|
2005-12-31 04:53:48 +01:00
|
|
|
else:
|
|
|
|
self.sent_history.append(message)
|
|
|
|
self.sent_history_pos = size + 1
|
2007-02-09 00:48:52 +01:00
|
|
|
self.orig_msg = None
|
2005-12-31 04:53:48 +01:00
|
|
|
|
|
|
|
def print_conversation_line(self, text, kind, name, tim,
|
2008-02-26 09:31:48 +01:00
|
|
|
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
2009-10-02 16:28:51 +02:00
|
|
|
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
|
|
|
|
xep0184_id=None, graphics=True):
|
2005-12-31 04:53:48 +01:00
|
|
|
'''prints 'chat' type messages'''
|
|
|
|
jid = self.contact.jid
|
2006-04-04 19:21:38 +02:00
|
|
|
full_jid = self.get_full_jid()
|
2005-12-31 04:53:48 +01:00
|
|
|
textview = self.conv_textview
|
|
|
|
end = False
|
2007-04-17 11:41:22 +02:00
|
|
|
if self.was_at_the_end or kind == 'outgoing':
|
2005-12-31 04:53:48 +01:00
|
|
|
end = True
|
|
|
|
textview.print_conversation_line(text, jid, kind, name, tim,
|
2006-05-08 10:19:20 +02:00
|
|
|
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
2009-10-02 16:28:51 +02:00
|
|
|
subject, old_kind, xhtml, simple=simple, graphics=graphics)
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2008-07-18 22:24:34 +02:00
|
|
|
if xep0184_id is not None:
|
|
|
|
textview.show_xep0184_warning(xep0184_id)
|
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
if not count_as_new:
|
|
|
|
return
|
2006-04-03 18:55:31 +02:00
|
|
|
if kind == 'incoming':
|
2008-03-20 21:26:58 +01:00
|
|
|
if not self.type_id == message_control.TYPE_GC or \
|
|
|
|
gajim.config.get('notify_on_all_muc_messages') or \
|
|
|
|
'marked' in other_tags_for_text:
|
|
|
|
# it's a normal message, or a muc message with want to be
|
|
|
|
# notified about if quitting just after
|
|
|
|
# other_tags_for_text == ['marked'] --> highlighted gc message
|
|
|
|
gajim.last_message_time[self.account][full_jid] = time.time()
|
2007-05-07 23:02:48 +02:00
|
|
|
|
2009-02-09 20:38:05 +01:00
|
|
|
if kind in ('incoming', 'incoming_queue', 'error'):
|
2006-09-30 16:28:10 +02:00
|
|
|
gc_message = False
|
2007-10-07 22:36:43 +02:00
|
|
|
if self.type_id == message_control.TYPE_GC:
|
2006-09-30 16:28:10 +02:00
|
|
|
gc_message = True
|
2007-05-08 17:38:23 +02:00
|
|
|
|
2008-05-30 12:07:01 +02:00
|
|
|
if ((self.parent_win and (not self.parent_win.get_active_control() or \
|
|
|
|
self != self.parent_win.get_active_control() or \
|
2007-05-08 17:38:23 +02:00
|
|
|
not self.parent_win.is_active() or not end)) or \
|
2007-05-07 23:02:48 +02:00
|
|
|
(gc_message and \
|
2007-05-20 18:31:09 +02:00
|
|
|
jid in gajim.interface.minimized_controls[self.account])) and \
|
2009-02-09 20:38:05 +01:00
|
|
|
kind in ('incoming', 'incoming_queue', 'error'):
|
2007-05-08 17:38:23 +02:00
|
|
|
# we want to have save this message in events list
|
|
|
|
# other_tags_for_text == ['marked'] --> highlighted gc message
|
2008-02-27 19:25:42 +01:00
|
|
|
if gc_message:
|
2008-03-02 15:23:52 +01:00
|
|
|
if 'marked' in other_tags_for_text:
|
2008-02-27 19:25:42 +01:00
|
|
|
type_ = 'printed_marked_gc_msg'
|
|
|
|
else:
|
|
|
|
type_ = 'printed_gc_msg'
|
|
|
|
event = 'gc_message_received'
|
2008-02-09 07:57:07 +01:00
|
|
|
else:
|
|
|
|
type_ = 'printed_' + self.type_id
|
|
|
|
event = 'message_received'
|
2007-05-07 23:02:48 +02:00
|
|
|
show_in_roster = notify.get_show_in_roster(event,
|
2008-05-13 03:59:10 +02:00
|
|
|
self.account, self.contact, self.session)
|
2007-05-07 23:02:48 +02:00
|
|
|
show_in_systray = notify.get_show_in_systray(event,
|
2008-02-27 22:33:50 +01:00
|
|
|
self.account, self.contact, type_)
|
2008-02-09 07:57:07 +01:00
|
|
|
|
2008-06-14 18:49:48 +02:00
|
|
|
event = gajim.events.create_event(type_, (self,),
|
2006-09-02 23:01:11 +02:00
|
|
|
show_in_roster = show_in_roster,
|
|
|
|
show_in_systray = show_in_systray)
|
|
|
|
gajim.events.add_event(self.account, full_jid, event)
|
|
|
|
# We need to redraw contact if we show in roster
|
|
|
|
if show_in_roster:
|
|
|
|
gajim.interface.roster.draw_contact(self.contact.jid,
|
|
|
|
self.account)
|
2007-05-07 23:02:48 +02:00
|
|
|
|
|
|
|
if not self.parent_win:
|
|
|
|
return
|
|
|
|
|
2008-05-30 12:07:01 +02:00
|
|
|
if (not self.parent_win.get_active_control() or \
|
|
|
|
self != self.parent_win.get_active_control() or \
|
2007-05-07 23:02:48 +02:00
|
|
|
not self.parent_win.is_active() or not end) and \
|
2009-02-09 20:38:05 +01:00
|
|
|
kind in ('incoming', 'incoming_queue', 'error'):
|
2006-01-25 06:39:07 +01:00
|
|
|
self.parent_win.redraw_tab(self)
|
2006-01-22 23:20:00 +01:00
|
|
|
if not self.parent_win.is_active():
|
2008-04-30 04:55:13 +02:00
|
|
|
self.parent_win.show_title(True, self) # Enabled Urgent hint
|
2006-11-03 19:03:59 +01:00
|
|
|
else:
|
2008-04-30 04:55:13 +02:00
|
|
|
self.parent_win.show_title(False, self) # Disabled Urgent hint
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2005-12-31 05:53:14 +01:00
|
|
|
def toggle_emoticons(self):
|
|
|
|
'''hide show emoticons_button and make sure emoticons_menu is always there
|
|
|
|
when needed'''
|
|
|
|
emoticons_button = self.xml.get_widget('emoticons_button')
|
2006-03-17 12:11:45 +01:00
|
|
|
if gajim.config.get('emoticons_theme'):
|
2005-12-31 05:53:14 +01:00
|
|
|
emoticons_button.show()
|
|
|
|
emoticons_button.set_no_show_all(False)
|
|
|
|
else:
|
|
|
|
emoticons_button.hide()
|
|
|
|
emoticons_button.set_no_show_all(True)
|
|
|
|
|
2006-04-05 11:55:22 +02:00
|
|
|
def append_emoticon(self, str_):
|
2008-12-03 18:16:04 +01:00
|
|
|
buffer_ = self.msg_textview.get_buffer()
|
|
|
|
if buffer_.get_char_count():
|
|
|
|
buffer_.insert_at_cursor(' %s ' % str_)
|
2006-04-05 11:55:22 +02:00
|
|
|
else: # we are the beginning of buffer
|
2008-12-03 18:16:04 +01:00
|
|
|
buffer_.insert_at_cursor('%s ' % str_)
|
2006-04-05 11:55:22 +02:00
|
|
|
self.msg_textview.grab_focus()
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2005-12-31 05:53:14 +01:00
|
|
|
def on_emoticons_button_clicked(self, widget):
|
|
|
|
'''popup emoticons menu'''
|
2006-04-05 11:55:22 +02:00
|
|
|
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
2006-04-17 23:59:04 +02:00
|
|
|
gajim.interface.popup_emoticons_under_button(widget, self.parent_win)
|
2005-12-31 05:53:14 +01:00
|
|
|
|
2008-11-14 12:13:15 +01:00
|
|
|
def on_formattings_button_clicked(self, widget):
|
|
|
|
'''popup formattings menu'''
|
2008-11-20 16:47:20 +01:00
|
|
|
menu = gtk.Menu()
|
|
|
|
|
|
|
|
menuitems = ((_('Bold'), 'bold'),
|
|
|
|
(_('Italic'), 'italic'),
|
|
|
|
(_('Underline'), 'underline'),
|
|
|
|
(_('Strike'), 'strike'))
|
2008-11-14 12:13:15 +01:00
|
|
|
|
|
|
|
active_tags = self.msg_textview.get_active_tags()
|
|
|
|
|
|
|
|
for menuitem in menuitems:
|
|
|
|
item = gtk.CheckMenuItem(menuitem[0])
|
|
|
|
if menuitem[1] in active_tags:
|
|
|
|
item.set_active(True)
|
|
|
|
else:
|
|
|
|
item.set_active(False)
|
|
|
|
item.connect('activate', self.msg_textview.set_tag,
|
|
|
|
menuitem[1])
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.SeparatorMenuItem() # separator
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(_('Color'))
|
|
|
|
icon = gtk.image_new_from_stock(gtk.STOCK_SELECT_COLOR, gtk.ICON_SIZE_MENU)
|
|
|
|
item.set_image(icon)
|
|
|
|
item.connect('activate', self.on_color_menuitem_activale)
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(_('Font'))
|
|
|
|
icon = gtk.image_new_from_stock(gtk.STOCK_SELECT_FONT, gtk.ICON_SIZE_MENU)
|
|
|
|
item.set_image(icon)
|
|
|
|
item.connect('activate', self.on_font_menuitem_activale)
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.SeparatorMenuItem() # separator
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(_('Clear formating'))
|
|
|
|
icon = gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU)
|
|
|
|
item.set_image(icon)
|
|
|
|
item.connect('activate', self.msg_textview.clear_tags)
|
|
|
|
menu.append(item)
|
|
|
|
|
|
|
|
menu.show_all()
|
|
|
|
gtkgui_helpers.popup_emoticons_under_button(menu, widget,
|
|
|
|
self.parent_win)
|
|
|
|
|
|
|
|
def on_color_menuitem_activale(self, widget):
|
|
|
|
color_dialog = gtk.ColorSelectionDialog('Select a color')
|
2008-12-03 22:56:12 +01:00
|
|
|
color_dialog.connect('response', self.msg_textview.color_set,
|
2008-11-14 12:13:15 +01:00
|
|
|
color_dialog.colorsel)
|
|
|
|
color_dialog.show_all()
|
|
|
|
|
|
|
|
def on_font_menuitem_activale(self, widget):
|
|
|
|
font_dialog = gtk.FontSelectionDialog('Select a font')
|
2008-12-03 22:56:12 +01:00
|
|
|
font_dialog.connect('response', self.msg_textview.font_set,
|
2008-11-14 12:13:15 +01:00
|
|
|
font_dialog.fontsel)
|
|
|
|
font_dialog.show_all()
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2008-11-14 12:13:15 +01:00
|
|
|
|
2005-12-31 08:19:43 +01:00
|
|
|
def on_actions_button_clicked(self, widget):
|
|
|
|
'''popup action menu'''
|
2009-10-27 18:58:27 +01:00
|
|
|
menu = self.prepare_context_menu(hide_buttonbar_items=True)
|
2005-12-31 08:19:43 +01:00
|
|
|
menu.show_all()
|
2006-07-13 15:07:31 +02:00
|
|
|
gtkgui_helpers.popup_emoticons_under_button(menu, widget,
|
|
|
|
self.parent_win)
|
2005-12-31 08:19:43 +01:00
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
def update_font(self):
|
|
|
|
font = pango.FontDescription(gajim.config.get('conversation_font'))
|
2006-04-18 17:36:16 +02:00
|
|
|
self.conv_textview.tv.modify_font(font)
|
2005-12-31 07:27:22 +01:00
|
|
|
self.msg_textview.modify_font(font)
|
|
|
|
|
|
|
|
def update_tags(self):
|
|
|
|
self.conv_textview.update_tags()
|
|
|
|
|
2005-12-31 08:19:43 +01:00
|
|
|
def clear(self, tv):
|
2008-12-03 18:16:04 +01:00
|
|
|
buffer_ = tv.get_buffer()
|
|
|
|
start, end = buffer_.get_bounds()
|
|
|
|
buffer_.delete(start, end)
|
2005-12-31 05:53:14 +01:00
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_history_menuitem_activate(self, widget = None, jid = None):
|
2006-03-28 14:39:47 +02:00
|
|
|
'''When history menuitem is pressed: call history window'''
|
2006-01-12 03:36:06 +01:00
|
|
|
if not jid:
|
|
|
|
jid = self.contact.jid
|
2006-04-18 17:36:16 +02:00
|
|
|
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'logs' in gajim.interface.instances:
|
2007-09-14 22:18:06 +02:00
|
|
|
gajim.interface.instances['logs'].window.present()
|
|
|
|
gajim.interface.instances['logs'].open_history(jid, self.account)
|
2006-01-02 02:23:40 +01:00
|
|
|
else:
|
2007-09-14 22:18:06 +02:00
|
|
|
gajim.interface.instances['logs'] = \
|
2006-01-12 03:36:06 +01:00
|
|
|
history_window.HistoryWindow(jid, self.account)
|
|
|
|
|
2009-04-07 19:07:04 +02:00
|
|
|
def _on_send_file(self, gc_contact=None):
|
|
|
|
'''gc_contact can be set when we are in a groupchat control'''
|
|
|
|
def _on_ok(c):
|
|
|
|
gajim.interface.instances['file_transfers'].show_file_send_request(
|
|
|
|
self.account, c)
|
|
|
|
if self.TYPE_ID == message_control.TYPE_PM:
|
|
|
|
gc_contact = self.gc_contact
|
|
|
|
if gc_contact:
|
|
|
|
# gc or pm
|
|
|
|
gc_control = gajim.interface.msg_win_mgr.get_gc_control(
|
|
|
|
gc_contact.room_jid, self.account)
|
|
|
|
self_contact = gajim.contacts.get_gc_contact(self.account,
|
|
|
|
gc_control.room_jid, gc_control.nick)
|
|
|
|
if gc_control.is_anonymous and gc_contact.affiliation not in ['admin',
|
|
|
|
'owner'] and self_contact.affiliation in ['admin', 'owner']:
|
|
|
|
contact = gajim.contacts.get_contact(self.account, gc_contact.jid)
|
|
|
|
if not contact or contact.sub not in ('both', 'to'):
|
|
|
|
prim_text = _('Really send file?')
|
|
|
|
sec_text = _('If you send a file to %s, he/she will know your '
|
|
|
|
'real Jabber ID.') % gc_contact.name
|
|
|
|
dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text,
|
|
|
|
on_response_ok = (_on_ok, gc_contact))
|
|
|
|
dialog.popup()
|
|
|
|
return
|
|
|
|
_on_ok(gc_contact)
|
|
|
|
return
|
|
|
|
_on_ok(self.contact)
|
|
|
|
|
2007-06-14 19:44:24 +02:00
|
|
|
def on_minimize_menuitem_toggled(self, widget):
|
2007-05-03 23:02:50 +02:00
|
|
|
'''When a grouchat is minimized, unparent the tab, put it in roster etc'''
|
2007-06-14 19:44:24 +02:00
|
|
|
old_value = False
|
|
|
|
minimized_gc = gajim.config.get_per('accounts', self.account,
|
|
|
|
'minimized_gc').split()
|
|
|
|
if self.contact.jid in minimized_gc:
|
|
|
|
old_value = True
|
|
|
|
minimize = widget.get_active()
|
|
|
|
if minimize and not self.contact.jid in minimized_gc:
|
|
|
|
minimized_gc.append(self.contact.jid)
|
|
|
|
if not minimize and self.contact.jid in minimized_gc:
|
|
|
|
minimized_gc.remove(self.contact.jid)
|
|
|
|
if old_value != minimize:
|
|
|
|
gajim.config.set_per('accounts', self.account, 'minimized_gc',
|
|
|
|
' '.join(minimized_gc))
|
2007-05-03 23:02:50 +02:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
def set_control_active(self, state):
|
|
|
|
if state:
|
|
|
|
jid = self.contact.jid
|
2007-04-17 11:41:22 +02:00
|
|
|
if self.was_at_the_end:
|
2006-09-02 23:01:11 +02:00
|
|
|
# we are at the end
|
2007-05-17 10:39:21 +02:00
|
|
|
type_ = ['printed_' + self.type_id]
|
2006-09-02 23:01:11 +02:00
|
|
|
if self.type_id == message_control.TYPE_GC:
|
2007-05-17 10:39:21 +02:00
|
|
|
type_ = ['printed_gc_msg', 'printed_marked_gc_msg']
|
2006-09-02 23:01:11 +02:00
|
|
|
if not gajim.events.remove_events(self.account, self.get_full_jid(),
|
2007-05-17 10:39:21 +02:00
|
|
|
types = type_):
|
2006-09-02 23:01:11 +02:00
|
|
|
# There were events to remove
|
2006-11-07 22:29:59 +01:00
|
|
|
self.redraw_after_event_removed(jid)
|
2008-03-20 20:37:20 +01:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
|
|
|
|
def bring_scroll_to_end(self, textview, diff_y = 0):
|
|
|
|
''' scrolls to the end of textview if end is not visible '''
|
2007-04-17 11:41:22 +02:00
|
|
|
if self.scroll_to_end_id:
|
|
|
|
# a scroll is already planned
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
buffer_ = textview.get_buffer()
|
|
|
|
end_iter = buffer_.get_end_iter()
|
2006-01-02 10:04:30 +01:00
|
|
|
end_rect = textview.get_iter_location(end_iter)
|
|
|
|
visible_rect = textview.get_visible_rect()
|
|
|
|
# scroll only if expected end is not visible
|
|
|
|
if end_rect.y >= (visible_rect.y + visible_rect.height + diff_y):
|
2007-04-17 11:41:22 +02:00
|
|
|
self.scroll_to_end_id = gobject.idle_add(self.scroll_to_end_iter,
|
|
|
|
textview)
|
2006-01-02 10:04:30 +01:00
|
|
|
|
|
|
|
def scroll_to_end_iter(self, textview):
|
2008-12-03 18:16:04 +01:00
|
|
|
buffer_ = textview.get_buffer()
|
|
|
|
end_iter = buffer_.get_end_iter()
|
2006-01-02 10:04:30 +01:00
|
|
|
textview.scroll_to_iter(end_iter, 0, False, 1, 1)
|
2007-04-17 11:41:22 +02:00
|
|
|
self.scroll_to_end_id = None
|
2006-01-02 10:04:30 +01:00
|
|
|
return False
|
|
|
|
|
2006-04-09 21:16:27 +02:00
|
|
|
def size_request(self, msg_textview , requisition):
|
2006-01-02 10:04:30 +01:00
|
|
|
''' When message_textview changes its size. If the new height
|
|
|
|
will enlarge the window, enable the scrollbar automatic policy
|
|
|
|
Also enable scrollbar automatic policy for horizontal scrollbar
|
|
|
|
if message we have in message_textview is too big'''
|
|
|
|
if msg_textview.window is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
min_height = self.conv_scrolledwindow.get_property('height-request')
|
2006-04-18 17:36:16 +02:00
|
|
|
conversation_height = self.conv_textview.tv.window.get_size()[1]
|
2006-01-02 10:04:30 +01:00
|
|
|
message_height = msg_textview.window.get_size()[1]
|
|
|
|
message_width = msg_textview.window.get_size()[0]
|
|
|
|
# new tab is not exposed yet
|
|
|
|
if conversation_height < 2:
|
|
|
|
return
|
|
|
|
|
|
|
|
if conversation_height < min_height:
|
|
|
|
min_height = conversation_height
|
|
|
|
|
|
|
|
# we don't want to always resize in height the message_textview
|
|
|
|
# so we have minimum on conversation_textview's scrolled window
|
2008-05-13 03:59:10 +02:00
|
|
|
# but we also want to avoid window resizing so if we reach that
|
2006-01-02 10:04:30 +01:00
|
|
|
# minimum for conversation_textview and maximum for message_textview
|
|
|
|
# we set to automatic the scrollbar policy
|
2007-10-07 22:36:43 +02:00
|
|
|
diff_y = message_height - requisition.height
|
2006-01-02 10:04:30 +01:00
|
|
|
if diff_y != 0:
|
|
|
|
if conversation_height + diff_y < min_height:
|
|
|
|
if message_height + conversation_height - min_height > min_height:
|
2007-01-28 15:20:37 +01:00
|
|
|
policy = self.msg_scrolledwindow.get_property(
|
|
|
|
'vscrollbar-policy')
|
|
|
|
# scroll only when scrollbar appear
|
|
|
|
if policy != gtk.POLICY_AUTOMATIC:
|
2008-05-13 03:59:10 +02:00
|
|
|
self.msg_scrolledwindow.set_property('vscrollbar-policy',
|
2007-01-28 15:20:37 +01:00
|
|
|
gtk.POLICY_AUTOMATIC)
|
2008-05-13 03:59:10 +02:00
|
|
|
self.msg_scrolledwindow.set_property('height-request',
|
2007-01-28 15:20:37 +01:00
|
|
|
message_height + conversation_height - min_height)
|
|
|
|
self.bring_scroll_to_end(msg_textview)
|
2006-01-02 10:04:30 +01:00
|
|
|
else:
|
2008-05-13 03:59:10 +02:00
|
|
|
self.msg_scrolledwindow.set_property('vscrollbar-policy',
|
2006-01-02 10:04:30 +01:00
|
|
|
gtk.POLICY_NEVER)
|
|
|
|
self.msg_scrolledwindow.set_property('height-request', -1)
|
2007-08-23 00:08:04 +02:00
|
|
|
self.conv_textview.bring_scroll_to_end(diff_y - 18, False)
|
|
|
|
else:
|
|
|
|
self.conv_textview.bring_scroll_to_end(diff_y - 18, self.smooth)
|
|
|
|
self.smooth = True # reinit the flag
|
2006-01-02 10:04:30 +01:00
|
|
|
# enable scrollbar automatic policy for horizontal scrollbar
|
|
|
|
# if message we have in message_textview is too big
|
|
|
|
if requisition.width > message_width:
|
2008-05-13 03:59:10 +02:00
|
|
|
self.msg_scrolledwindow.set_property('hscrollbar-policy',
|
2006-01-02 10:04:30 +01:00
|
|
|
gtk.POLICY_AUTOMATIC)
|
|
|
|
else:
|
2008-05-13 03:59:10 +02:00
|
|
|
self.msg_scrolledwindow.set_property('hscrollbar-policy',
|
2006-01-02 10:04:30 +01:00
|
|
|
gtk.POLICY_NEVER)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2007-04-17 11:41:22 +02:00
|
|
|
def on_conversation_vadjustment_changed(self, adjustment):
|
|
|
|
# used to stay at the end of the textview when we shrink conversation
|
|
|
|
# textview.
|
|
|
|
if self.was_at_the_end:
|
|
|
|
self.conv_textview.bring_scroll_to_end(-18)
|
|
|
|
self.was_at_the_end = (adjustment.upper - adjustment.value - adjustment.page_size) < 18
|
|
|
|
|
|
|
|
def on_conversation_vadjustment_value_changed(self, adjustment):
|
2008-03-10 17:21:26 +01:00
|
|
|
# stop automatic scroll when we manually scroll
|
|
|
|
if not self.conv_textview.auto_scrolling:
|
|
|
|
self.conv_textview.stop_scrolling()
|
2007-04-17 11:41:22 +02:00
|
|
|
self.was_at_the_end = (adjustment.upper - adjustment.value - adjustment.page_size) < 18
|
2006-07-04 23:23:42 +02:00
|
|
|
if self.resource:
|
|
|
|
jid = self.contact.get_full_jid()
|
|
|
|
else:
|
|
|
|
jid = self.contact.jid
|
2008-03-12 02:34:41 +01:00
|
|
|
types_list = []
|
2006-09-02 23:01:11 +02:00
|
|
|
type_ = self.type_id
|
|
|
|
if type_ == message_control.TYPE_GC:
|
|
|
|
type_ = 'gc_msg'
|
2008-03-12 02:34:41 +01:00
|
|
|
types_list = ['printed_' + type_, type_, 'printed_marked_gc_msg']
|
|
|
|
else: # Not a GC
|
|
|
|
types_list = ['printed_' + type_, type_]
|
|
|
|
|
|
|
|
if not len(gajim.events.get_events(self.account, jid, types_list)):
|
2006-09-02 23:01:11 +02:00
|
|
|
return
|
2007-05-07 23:02:48 +02:00
|
|
|
if not self.parent_win:
|
|
|
|
return
|
2006-01-27 04:43:00 +01:00
|
|
|
if self.conv_textview.at_the_end() and \
|
2007-04-17 11:41:22 +02:00
|
|
|
self.parent_win.get_active_control() == self and \
|
|
|
|
self.parent_win.window.is_active():
|
2006-09-02 23:01:11 +02:00
|
|
|
# we are at the end
|
2009-06-04 21:45:46 +02:00
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
if not gajim.events.remove_events(self.account, jid,
|
|
|
|
types=types_list):
|
|
|
|
self.redraw_after_event_removed(jid)
|
|
|
|
elif self.session and self.session.remove_events(types_list):
|
2006-09-02 23:01:11 +02:00
|
|
|
# There were events to remove
|
2006-11-07 22:29:59 +01:00
|
|
|
self.redraw_after_event_removed(jid)
|
|
|
|
|
|
|
|
def redraw_after_event_removed(self, jid):
|
2008-05-13 03:59:10 +02:00
|
|
|
''' We just removed a 'printed_*' event, redraw contact in roster or
|
2006-11-07 22:29:59 +01:00
|
|
|
gc_roster and titles in roster and msg_win '''
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
self.parent_win.show_title()
|
|
|
|
# TODO : get the contact and check notify.get_show_in_roster()
|
|
|
|
if self.type_id == message_control.TYPE_PM:
|
|
|
|
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
|
2008-05-02 04:32:28 +02:00
|
|
|
groupchat_control = gajim.interface.msg_win_mgr.get_gc_control(
|
2006-11-07 22:29:59 +01:00
|
|
|
room_jid, self.account)
|
2007-06-11 12:13:16 +02:00
|
|
|
if room_jid in gajim.interface.minimized_controls[self.account]:
|
2007-05-17 14:55:44 +02:00
|
|
|
groupchat_control = \
|
|
|
|
gajim.interface.minimized_controls[self.account][room_jid]
|
2007-06-07 13:58:56 +02:00
|
|
|
contact = \
|
|
|
|
gajim.contacts.get_contact_with_highest_priority(self.account, \
|
|
|
|
room_jid)
|
|
|
|
if contact:
|
|
|
|
gajim.interface.roster.draw_contact(room_jid, self.account)
|
2008-12-11 22:15:52 +01:00
|
|
|
if groupchat_control:
|
|
|
|
groupchat_control.draw_contact(nick)
|
|
|
|
if groupchat_control.parent_win:
|
|
|
|
groupchat_control.parent_win.redraw_tab(groupchat_control)
|
2006-11-07 22:29:59 +01:00
|
|
|
else:
|
|
|
|
gajim.interface.roster.draw_contact(jid, self.account)
|
|
|
|
gajim.interface.roster.show_title()
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2006-01-02 23:08:50 +01:00
|
|
|
def sent_messages_scroll(self, direction, conv_buf):
|
2008-05-13 03:59:10 +02:00
|
|
|
size = len(self.sent_history)
|
2007-02-09 00:36:17 +01:00
|
|
|
if self.orig_msg is None:
|
2007-02-11 03:35:02 +01:00
|
|
|
# user was typing something and then went into history, so save
|
|
|
|
# whatever is already typed
|
2006-01-02 23:08:50 +01:00
|
|
|
start_iter = conv_buf.get_start_iter()
|
|
|
|
end_iter = conv_buf.get_end_iter()
|
2006-10-03 16:12:42 +02:00
|
|
|
self.orig_msg = conv_buf.get_text(start_iter, end_iter, 0).decode(
|
|
|
|
'utf-8')
|
2006-01-02 23:08:50 +01:00
|
|
|
if direction == 'up':
|
|
|
|
if self.sent_history_pos == 0:
|
|
|
|
return
|
|
|
|
self.sent_history_pos = self.sent_history_pos - 1
|
2007-08-23 00:08:04 +02:00
|
|
|
self.smooth = False
|
2006-01-02 23:08:50 +01:00
|
|
|
conv_buf.set_text(self.sent_history[self.sent_history_pos])
|
|
|
|
elif direction == 'down':
|
|
|
|
if self.sent_history_pos >= size - 1:
|
2008-12-02 14:58:54 +01:00
|
|
|
conv_buf.set_text(self.orig_msg)
|
2007-02-09 00:36:17 +01:00
|
|
|
self.orig_msg = None
|
2006-01-02 23:08:50 +01:00
|
|
|
self.sent_history_pos = size
|
|
|
|
return
|
|
|
|
|
|
|
|
self.sent_history_pos = self.sent_history_pos + 1
|
2007-08-23 00:08:04 +02:00
|
|
|
self.smooth = False
|
2006-01-02 23:08:50 +01:00
|
|
|
conv_buf.set_text(self.sent_history[self.sent_history_pos])
|
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
def lighten_color(self, color):
|
|
|
|
p = 0.4
|
|
|
|
mask = 0
|
|
|
|
color.red = int((color.red * p) + (mask * (1 - p)))
|
|
|
|
color.green = int((color.green * p) + (mask * (1 - p)))
|
|
|
|
color.blue = int((color.blue * p) + (mask * (1 - p)))
|
|
|
|
return color
|
|
|
|
|
2006-04-10 14:09:05 +02:00
|
|
|
def widget_set_visible(self, widget, state):
|
|
|
|
'''Show or hide a widget. state is bool'''
|
2006-01-06 07:59:55 +01:00
|
|
|
# make the last message visible, when changing to "full view"
|
|
|
|
if not state:
|
|
|
|
gobject.idle_add(self.conv_textview.scroll_to_end_iter)
|
2006-04-10 14:09:05 +02:00
|
|
|
|
|
|
|
widget.set_no_show_all(state)
|
|
|
|
if state:
|
|
|
|
widget.hide()
|
2006-01-06 07:59:55 +01:00
|
|
|
else:
|
2006-04-10 14:09:05 +02:00
|
|
|
widget.show_all()
|
|
|
|
|
|
|
|
def chat_buttons_set_visible(self, state):
|
|
|
|
'''Toggle chat buttons. state is bool'''
|
|
|
|
MessageControl.chat_buttons_set_visible(self, state)
|
|
|
|
self.widget_set_visible(self.xml.get_widget('actions_hbox'), state)
|
2006-01-06 07:59:55 +01:00
|
|
|
|
2006-02-04 03:52:36 +01:00
|
|
|
def got_connected(self):
|
|
|
|
self.msg_textview.set_sensitive(True)
|
2006-03-26 12:43:18 +02:00
|
|
|
self.msg_textview.set_editable(True)
|
2008-11-20 16:44:06 +01:00
|
|
|
# FIXME: Set sensitivity for toolbar
|
2006-02-04 03:52:36 +01:00
|
|
|
|
|
|
|
def got_disconnected(self):
|
|
|
|
self.msg_textview.set_sensitive(False)
|
2006-03-26 12:43:18 +02:00
|
|
|
self.msg_textview.set_editable(False)
|
2006-09-03 19:50:18 +02:00
|
|
|
self.conv_textview.tv.grab_focus()
|
2008-12-13 19:10:37 +01:00
|
|
|
|
|
|
|
self.no_autonegotiation = False
|
2008-11-20 16:44:06 +01:00
|
|
|
# FIXME: Set sensitivity for toolbar
|
2006-02-04 03:52:36 +01:00
|
|
|
|
2005-12-31 22:55:44 +01:00
|
|
|
################################################################################
|
2009-10-02 22:57:11 +02:00
|
|
|
class ChatControl(ChatControlBase):
|
2005-12-31 01:50:33 +01:00
|
|
|
'''A control for standard 1-1 chat'''
|
2009-09-17 14:48:15 +02:00
|
|
|
(
|
2009-09-25 13:52:44 +02:00
|
|
|
JINGLE_STATE_NOT_AVAILABLE,
|
|
|
|
JINGLE_STATE_AVAILABLE,
|
|
|
|
JINGLE_STATE_CONNECTING,
|
|
|
|
JINGLE_STATE_CONNECTION_RECEIVED,
|
|
|
|
JINGLE_STATE_CONNECTED,
|
|
|
|
JINGLE_STATE_ERROR
|
2009-09-17 14:48:15 +02:00
|
|
|
) = range(6)
|
|
|
|
|
2006-01-02 03:12:34 +01:00
|
|
|
TYPE_ID = message_control.TYPE_CHAT
|
2006-05-08 10:19:20 +02:00
|
|
|
old_msg_kind = None # last kind of the printed message
|
2007-06-06 01:19:34 +02:00
|
|
|
|
2009-10-02 22:57:11 +02:00
|
|
|
# Set a command host to bound to. Every command given through a chat will be
|
|
|
|
# processed with this command host.
|
|
|
|
COMMAND_HOST = ChatCommands
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2007-06-05 23:26:45 +02:00
|
|
|
def __init__(self, parent_win, contact, acct, session, resource = None):
|
2006-10-03 16:12:42 +02:00
|
|
|
ChatControlBase.__init__(self, self.TYPE_ID, parent_win,
|
2007-02-08 19:32:10 +01:00
|
|
|
'chat_child_vbox', contact, acct, resource)
|
2007-06-05 23:26:45 +02:00
|
|
|
|
2009-01-17 13:30:24 +01:00
|
|
|
self.gpg_is_active = False
|
2006-04-17 23:59:04 +02:00
|
|
|
# for muc use:
|
|
|
|
# widget = self.xml.get_widget('muc_window_actions_button')
|
2008-05-07 18:36:45 +02:00
|
|
|
self.actions_button = self.xml.get_widget('message_window_actions_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.actions_button.connect('clicked',
|
|
|
|
self.on_actions_button_clicked)
|
|
|
|
self.handlers[id_] = self.actions_button
|
2006-04-17 23:59:04 +02:00
|
|
|
|
2008-11-20 16:19:25 +01:00
|
|
|
self._formattings_button = self.xml.get_widget('formattings_button')
|
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
self._add_to_roster_button = self.xml.get_widget(
|
|
|
|
'add_to_roster_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self._add_to_roster_button.connect('clicked',
|
2008-07-22 17:40:20 +02:00
|
|
|
self._on_add_to_roster_menuitem_activate)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self._add_to_roster_button
|
2008-07-22 17:40:20 +02:00
|
|
|
|
2009-09-25 13:52:44 +02:00
|
|
|
self._audio_button = self.xml.get_widget('audio_togglebutton')
|
|
|
|
id_ = self._audio_button.connect('toggled', self.on_audio_button_toggled)
|
|
|
|
self.handlers[id_] = self._audio_button
|
2009-11-08 10:08:15 +01:00
|
|
|
# add a special img
|
|
|
|
path_to_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
|
|
|
|
'mic_inactive.png')
|
|
|
|
img = gtk.Image()
|
|
|
|
img.set_from_file(path_to_img)
|
|
|
|
self._audio_button.set_image(img)
|
2009-09-17 22:21:06 +02:00
|
|
|
|
2009-09-25 13:52:44 +02:00
|
|
|
self._video_button = self.xml.get_widget('video_togglebutton')
|
|
|
|
id_ = self._video_button.connect('toggled', self.on_video_button_toggled)
|
|
|
|
self.handlers[id_] = self._video_button
|
2009-11-08 10:08:15 +01:00
|
|
|
# add a special img
|
|
|
|
path_to_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
|
|
|
|
'cam_inactive.png')
|
|
|
|
img = gtk.Image()
|
|
|
|
img.set_from_file(path_to_img)
|
|
|
|
self._video_button.set_image(img)
|
2009-09-17 22:21:06 +02:00
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
self._send_file_button = self.xml.get_widget('send_file_button')
|
2008-09-08 13:27:37 +02:00
|
|
|
# add a special img for send file button
|
|
|
|
path_to_upload_img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'upload.png')
|
|
|
|
img = gtk.Image()
|
|
|
|
img.set_from_file(path_to_upload_img)
|
|
|
|
self._send_file_button.set_image(img)
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self._send_file_button.connect('clicked',
|
2008-07-22 17:40:20 +02:00
|
|
|
self._on_send_file_menuitem_activate)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self._send_file_button
|
2008-07-22 17:40:20 +02:00
|
|
|
|
|
|
|
self._convert_to_gc_button = self.xml.get_widget(
|
|
|
|
'convert_to_gc_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self._convert_to_gc_button.connect('clicked',
|
2008-07-22 17:40:20 +02:00
|
|
|
self._on_convert_to_gc_menuitem_activate)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self._convert_to_gc_button
|
2008-07-22 17:40:20 +02:00
|
|
|
|
|
|
|
contact_information_button = self.xml.get_widget(
|
|
|
|
'contact_information_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = contact_information_button.connect('clicked',
|
2008-07-22 17:40:20 +02:00
|
|
|
self._on_contact_information_menuitem_activate)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = contact_information_button
|
2008-05-07 17:34:00 +02:00
|
|
|
|
2007-06-26 01:51:44 +02:00
|
|
|
compact_view = gajim.config.get('compact_view')
|
|
|
|
self.chat_buttons_set_visible(compact_view)
|
2006-10-03 16:12:42 +02:00
|
|
|
self.widget_set_visible(self.xml.get_widget('banner_eventbox'),
|
|
|
|
gajim.config.get('hide_chat_banner'))
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
self.authentication_button = self.xml.get_widget(
|
|
|
|
'authentication_button')
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.authentication_button.connect('clicked',
|
2008-07-22 17:40:20 +02:00
|
|
|
self._on_authentication_button_clicked)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.authentication_button
|
2008-06-29 06:39:29 +02:00
|
|
|
|
2008-01-11 18:45:20 +01:00
|
|
|
# Add lock image to show chat encryption
|
|
|
|
self.lock_image = self.xml.get_widget('lock_image')
|
2008-05-04 22:47:51 +02:00
|
|
|
|
|
|
|
# Convert to GC icon
|
|
|
|
img = self.xml.get_widget('convert_to_gc_button_image')
|
2008-07-22 17:40:20 +02:00
|
|
|
img.set_from_pixbuf(gtkgui_helpers.load_icon(
|
|
|
|
'muc_active').get_pixbuf())
|
2008-05-10 13:39:25 +02:00
|
|
|
|
2009-09-25 13:52:44 +02:00
|
|
|
self._audio_banner_image = self.xml.get_widget('audio_banner_image')
|
|
|
|
self._video_banner_image = self.xml.get_widget('video_banner_image')
|
2009-09-25 15:47:43 +02:00
|
|
|
self.audio_sid = None
|
|
|
|
self.audio_state = self.JINGLE_STATE_NOT_AVAILABLE
|
|
|
|
self.video_sid = None
|
|
|
|
self.video_state = self.JINGLE_STATE_NOT_AVAILABLE
|
2009-09-17 22:21:06 +02:00
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
self.update_toolbar()
|
2008-05-13 03:59:10 +02:00
|
|
|
|
2008-07-22 23:08:52 +02:00
|
|
|
self._mood_image = self.xml.get_widget('mood_image')
|
|
|
|
self._activity_image = self.xml.get_widget('activity_image')
|
|
|
|
self._tune_image = self.xml.get_widget('tune_image')
|
|
|
|
|
|
|
|
self.update_mood()
|
2008-07-29 00:33:20 +02:00
|
|
|
self.update_activity()
|
2008-07-23 01:06:58 +02:00
|
|
|
self.update_tune()
|
2008-07-22 23:08:52 +02:00
|
|
|
|
2006-01-02 23:08:50 +01:00
|
|
|
# keep timeout id and window obj for possible big avatar
|
2008-07-22 17:40:20 +02:00
|
|
|
# it is on enter-notify and leave-notify so no need to be
|
|
|
|
# per jid
|
2006-01-02 23:08:50 +01:00
|
|
|
self.show_bigger_avatar_timeout_id = None
|
|
|
|
self.bigger_avatar_window = None
|
2007-06-06 01:19:34 +02:00
|
|
|
self.show_avatar(self.contact.resource)
|
2006-01-02 23:08:50 +01:00
|
|
|
|
|
|
|
# chatstate timers and state
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
|
|
|
self._schedule_activity_timers()
|
2006-01-03 04:34:32 +01:00
|
|
|
|
|
|
|
# Hook up signals
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = self.parent_win.window.connect('motion-notify-event',
|
2006-03-28 14:39:47 +02:00
|
|
|
self._on_window_motion_notify)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = self.parent_win.window
|
2006-01-03 04:34:32 +01:00
|
|
|
message_tv_buffer = self.msg_textview.get_buffer()
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = message_tv_buffer.connect('changed',
|
2006-10-03 16:12:42 +02:00
|
|
|
self._on_message_tv_buffer_changed)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = message_tv_buffer
|
2007-06-05 23:26:45 +02:00
|
|
|
|
2006-04-17 23:59:04 +02:00
|
|
|
widget = self.xml.get_widget('avatar_eventbox')
|
2009-01-12 18:25:27 +01:00
|
|
|
widget.set_property('height-request', gajim.config.get(
|
|
|
|
'chat_avatar_height'))
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('enter-notify-event',
|
2006-10-03 16:12:42 +02:00
|
|
|
self.on_avatar_eventbox_enter_notify_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
2006-03-28 14:39:47 +02:00
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('leave-notify-event',
|
2006-10-03 16:12:42 +02:00
|
|
|
self.on_avatar_eventbox_leave_notify_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
2006-04-17 23:59:04 +02:00
|
|
|
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = widget.connect('button-press-event',
|
2006-10-03 16:12:42 +02:00
|
|
|
self.on_avatar_eventbox_button_press_event)
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = widget
|
2006-05-26 15:19:52 +02:00
|
|
|
|
2008-06-29 06:39:29 +02:00
|
|
|
if not session:
|
2009-10-06 17:35:25 +02:00
|
|
|
# Don't use previous session if we want to a specific resource
|
|
|
|
# and it's not the same
|
|
|
|
if not resource:
|
|
|
|
resource = contact.resource
|
|
|
|
session = gajim.connections[self.account].find_controlless_session(
|
|
|
|
self.contact.jid, resource)
|
2008-06-29 06:39:29 +02:00
|
|
|
|
2008-06-03 01:26:32 +02:00
|
|
|
if session:
|
|
|
|
session.control = self
|
2008-06-29 06:39:29 +02:00
|
|
|
self.session = session
|
|
|
|
|
|
|
|
if session.enable_encryption:
|
|
|
|
self.print_esession_details()
|
2007-08-20 10:16:48 +02:00
|
|
|
|
2008-06-29 06:39:29 +02:00
|
|
|
# Enable encryption if needed
|
2008-08-09 23:13:41 +02:00
|
|
|
self.no_autonegotiation = False
|
2008-07-14 02:26:14 +02:00
|
|
|
e2e_is_active = self.session and self.session.enable_encryption
|
2008-07-15 18:45:39 +02:00
|
|
|
gpg_pref = gajim.config.get_per('contacts', contact.jid,
|
|
|
|
'gpg_enabled')
|
2008-01-25 22:16:22 +01:00
|
|
|
|
2008-07-14 02:26:14 +02:00
|
|
|
# try GPG first
|
2008-07-15 18:45:39 +02:00
|
|
|
if not e2e_is_active and gpg_pref and \
|
|
|
|
gajim.config.get_per('accounts', self.account, 'keyid') and \
|
2007-12-30 00:28:27 +01:00
|
|
|
gajim.connections[self.account].USE_GPG:
|
2007-12-30 17:30:37 +01:00
|
|
|
self.gpg_is_active = True
|
2007-12-30 00:28:27 +01:00
|
|
|
gajim.encrypted_chats[self.account].append(contact.jid)
|
|
|
|
msg = _('GPG encryption enabled')
|
2008-07-15 18:45:39 +02:00
|
|
|
ChatControlBase.print_conversation_line(self, msg,
|
|
|
|
'status', '', None)
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2008-01-25 22:16:22 +01:00
|
|
|
if self.session:
|
2009-07-02 08:20:17 +02:00
|
|
|
self.session.loggable = gajim.config.get_per('accounts',
|
|
|
|
self.account, 'log_encrypted_sessions')
|
2008-07-15 18:45:39 +02:00
|
|
|
# GPG is always authenticated as we use GPG's WoT
|
2009-07-02 08:20:17 +02:00
|
|
|
self._show_lock_image(self.gpg_is_active, 'GPG', self.gpg_is_active,
|
|
|
|
self.session and self.session.is_loggable(), True)
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-01-10 02:47:24 +01:00
|
|
|
self.update_ui()
|
2006-01-03 04:34:32 +01:00
|
|
|
# restore previous conversation
|
|
|
|
self.restore_conversation()
|
2008-08-22 05:03:15 +02:00
|
|
|
self.msg_textview.grab_focus()
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
def update_toolbar(self):
|
2008-11-20 16:19:25 +01:00
|
|
|
# Formatting
|
2009-10-27 22:41:39 +01:00
|
|
|
if self.contact.supports(NS_XHTML_IM) and not self.gpg_is_active:
|
2008-11-20 16:19:25 +01:00
|
|
|
self._formattings_button.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self._formattings_button.set_sensitive(False)
|
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
# Add to roster
|
2008-07-26 03:16:24 +02:00
|
|
|
if not isinstance(self.contact, GC_Contact) \
|
|
|
|
and _('Not in Roster') in self.contact.groups:
|
2008-07-22 17:40:20 +02:00
|
|
|
self._add_to_roster_button.show()
|
|
|
|
else:
|
|
|
|
self._add_to_roster_button.hide()
|
|
|
|
|
2009-10-03 22:40:12 +02:00
|
|
|
# Jingle detection
|
2009-10-31 17:25:47 +01:00
|
|
|
if self.contact.supports(NS_JINGLE_ICE_UDP) and \
|
2009-10-03 22:40:12 +02:00
|
|
|
gajim.HAVE_FARSIGHT and self.contact.resource:
|
2009-10-31 17:25:47 +01:00
|
|
|
if self.contact.supports(NS_JINGLE_RTP_AUDIO):
|
2009-10-03 22:40:12 +02:00
|
|
|
if self.audio_state == self.JINGLE_STATE_NOT_AVAILABLE:
|
|
|
|
self.set_audio_state('available')
|
|
|
|
else:
|
|
|
|
self.set_audio_state('not_available')
|
|
|
|
|
2009-10-31 17:25:47 +01:00
|
|
|
if self.contact.supports(NS_JINGLE_RTP_VIDEO):
|
2009-10-03 22:40:12 +02:00
|
|
|
if self.video_state == self.JINGLE_STATE_NOT_AVAILABLE:
|
|
|
|
self.set_video_state('available')
|
|
|
|
else:
|
|
|
|
self.set_video_state('not_available')
|
|
|
|
else:
|
|
|
|
if self.audio_state != self.JINGLE_STATE_NOT_AVAILABLE:
|
|
|
|
self.set_audio_state('not_available')
|
|
|
|
if self.video_state != self.JINGLE_STATE_NOT_AVAILABLE:
|
|
|
|
self.set_video_state('not_available')
|
|
|
|
|
2009-09-17 22:21:06 +02:00
|
|
|
# Audio buttons
|
2009-09-25 13:52:44 +02:00
|
|
|
if self.audio_state == self.JINGLE_STATE_NOT_AVAILABLE:
|
|
|
|
self._audio_button.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
self._audio_button.set_sensitive(True)
|
|
|
|
|
|
|
|
# Video buttons
|
|
|
|
if self.video_state == self.JINGLE_STATE_NOT_AVAILABLE:
|
|
|
|
self._video_button.set_sensitive(False)
|
2009-09-17 22:21:06 +02:00
|
|
|
else:
|
2009-09-25 13:52:44 +02:00
|
|
|
self._video_button.set_sensitive(True)
|
2009-09-17 22:21:06 +02:00
|
|
|
|
2008-07-22 17:40:20 +02:00
|
|
|
# Send file
|
2009-10-27 22:41:39 +01:00
|
|
|
if self.contact.supports(NS_FILE) and self.contact.resource:
|
2008-07-22 17:40:20 +02:00
|
|
|
self._send_file_button.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self._send_file_button.set_sensitive(False)
|
2009-10-27 22:41:39 +01:00
|
|
|
if not self.contact.supports(NS_FILE):
|
2009-04-26 00:29:22 +02:00
|
|
|
self._send_file_button.set_tooltip_text(_(
|
|
|
|
"This contact does not support file transfer."))
|
|
|
|
else:
|
|
|
|
self._send_file_button.set_tooltip_text(
|
|
|
|
_("You need to know the real JID of the contact to send him or "
|
|
|
|
"her a file."))
|
2008-07-22 17:40:20 +02:00
|
|
|
|
|
|
|
# Convert to GC
|
2009-10-27 22:41:39 +01:00
|
|
|
if self.contact.supports(NS_MUC):
|
2008-07-22 17:40:20 +02:00
|
|
|
self._convert_to_gc_button.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self._convert_to_gc_button.set_sensitive(False)
|
|
|
|
|
2008-07-22 23:08:52 +02:00
|
|
|
def update_mood(self):
|
2008-07-29 00:33:20 +02:00
|
|
|
if isinstance(self.contact, GC_Contact):
|
|
|
|
return
|
2009-11-15 00:12:15 +01:00
|
|
|
pep = self.contact.pep
|
2009-11-15 10:55:31 +01:00
|
|
|
if 'mood' in pep:
|
2009-11-15 00:12:15 +01:00
|
|
|
self._mood_image.set_from_pixbuf(pep['mood'].asPixbufIcon())
|
2009-11-15 10:55:31 +01:00
|
|
|
self._mood_image.set_tooltip_markup(pep['mood'].asMarkupText())
|
2008-07-22 23:08:52 +02:00
|
|
|
self._mood_image.show()
|
|
|
|
else:
|
|
|
|
self._mood_image.hide()
|
|
|
|
|
2008-07-29 00:33:20 +02:00
|
|
|
def update_activity(self):
|
|
|
|
if isinstance(self.contact, GC_Contact):
|
|
|
|
return
|
2009-11-15 16:52:19 +01:00
|
|
|
pep = self.contact.pep
|
|
|
|
if 'activity' in pep:
|
|
|
|
self._activity_image.set_from_pixbuf(pep['activity'].asPixbufIcon())
|
|
|
|
self._activity_image.set_tooltip_markup(pep['activity'].asMarkupText())
|
2008-07-29 00:33:20 +02:00
|
|
|
self._activity_image.show()
|
|
|
|
else:
|
|
|
|
self._activity_image.hide()
|
|
|
|
|
2008-07-23 01:06:58 +02:00
|
|
|
def update_tune(self):
|
2008-07-29 00:33:20 +02:00
|
|
|
if isinstance(self.contact, GC_Contact):
|
|
|
|
return
|
2009-11-15 10:55:31 +01:00
|
|
|
pep = self.contact.pep
|
|
|
|
if 'tune' in pep:
|
|
|
|
self._tune_image.set_tooltip_markup(pep['tune'].asMarkupText())
|
2008-07-23 01:06:58 +02:00
|
|
|
self._tune_image.show()
|
|
|
|
else:
|
|
|
|
self._tune_image.hide()
|
|
|
|
|
2009-10-16 21:48:28 +02:00
|
|
|
def _update_jingle(self, jingle_type):
|
|
|
|
if jingle_type not in ('audio', 'video'):
|
|
|
|
return
|
|
|
|
if self.__dict__[jingle_type + '_state'] in (
|
|
|
|
self.JINGLE_STATE_NOT_AVAILABLE, self.JINGLE_STATE_AVAILABLE):
|
|
|
|
self.__dict__['_' + jingle_type + '_banner_image'].hide()
|
2009-09-25 13:52:44 +02:00
|
|
|
else:
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_banner_image'].show()
|
2009-09-25 13:52:44 +02:00
|
|
|
if self.audio_state == self.JINGLE_STATE_CONNECTING:
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_banner_image'].set_from_stock(
|
|
|
|
gtk.STOCK_CONVERT, 1)
|
2009-09-25 13:52:44 +02:00
|
|
|
elif self.audio_state == self.JINGLE_STATE_CONNECTION_RECEIVED:
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_banner_image'].set_from_stock(
|
|
|
|
gtk.STOCK_NETWORK, 1)
|
2009-09-25 13:52:44 +02:00
|
|
|
elif self.audio_state == self.JINGLE_STATE_CONNECTED:
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_banner_image'].set_from_stock(
|
|
|
|
gtk.STOCK_CONNECT, 1)
|
2009-09-25 13:52:44 +02:00
|
|
|
elif self.audio_state == self.JINGLE_STATE_ERROR:
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_banner_image'].set_from_stock(
|
|
|
|
gtk.STOCK_DIALOG_WARNING, 1)
|
2009-09-25 13:52:44 +02:00
|
|
|
self.update_toolbar()
|
|
|
|
|
2009-10-16 21:48:28 +02:00
|
|
|
def update_audio(self):
|
|
|
|
self._update_jingle('audio')
|
|
|
|
|
2009-09-25 13:52:44 +02:00
|
|
|
def update_video(self):
|
2009-10-16 21:48:28 +02:00
|
|
|
self._update_jingle('video')
|
2009-09-17 14:48:15 +02:00
|
|
|
|
2009-09-15 17:41:47 +02:00
|
|
|
def change_resource(self, resource):
|
|
|
|
old_full_jid = self.get_full_jid()
|
|
|
|
self.resource = resource
|
|
|
|
new_full_jid = self.get_full_jid()
|
|
|
|
# update gajim.last_message_time
|
|
|
|
if old_full_jid in gajim.last_message_time[self.account]:
|
|
|
|
gajim.last_message_time[self.account][new_full_jid] = \
|
|
|
|
gajim.last_message_time[self.account][old_full_jid]
|
|
|
|
# update events
|
|
|
|
gajim.events.change_jid(self.account, old_full_jid, new_full_jid)
|
|
|
|
# update MessageWindow._controls
|
|
|
|
self.parent_win.change_jid(self.account, old_full_jid, new_full_jid)
|
|
|
|
|
2009-10-16 21:48:28 +02:00
|
|
|
def _set_jingle_state(self, jingle_type, state, sid=None, reason=None):
|
|
|
|
if jingle_type not in ('audio', 'video'):
|
|
|
|
return
|
|
|
|
if state in ('connecting', 'connected', 'stop') and reason:
|
|
|
|
str = _('%(type)s state : %(state)s, reason: %(reason)s') % {
|
|
|
|
'type': jingle_type.capitalize(), 'state': state, 'reason': reason}
|
2009-09-17 22:21:06 +02:00
|
|
|
self.print_conversation(str, 'info')
|
2009-10-16 19:04:04 +02:00
|
|
|
|
2009-10-16 19:36:55 +02:00
|
|
|
states = {'not_available': self.JINGLE_STATE_NOT_AVAILABLE,
|
|
|
|
'available': self.JINGLE_STATE_AVAILABLE,
|
|
|
|
'connecting': self.JINGLE_STATE_CONNECTING,
|
|
|
|
'connection_received': self.JINGLE_STATE_CONNECTION_RECEIVED,
|
|
|
|
'connected': self.JINGLE_STATE_CONNECTED,
|
|
|
|
'stop': self.JINGLE_STATE_AVAILABLE,
|
|
|
|
'error': self.JINGLE_STATE_ERROR}
|
|
|
|
|
|
|
|
if state in states:
|
2009-10-29 10:08:22 +01:00
|
|
|
jingle_state = states[state]
|
|
|
|
if self.__dict__[jingle_type + '_state'] == jingle_state:
|
|
|
|
return
|
|
|
|
self.__dict__[jingle_type + '_state'] = jingle_state
|
2009-10-16 19:36:55 +02:00
|
|
|
|
2009-10-16 20:21:42 +02:00
|
|
|
# Destroy existing session with the user when he signs off
|
|
|
|
# We need to do that before modifying the sid
|
|
|
|
if state == 'not_available':
|
|
|
|
gajim.connections[self.account].delete_jingle_session(
|
2009-10-16 21:48:28 +02:00
|
|
|
self.contact.get_full_jid(), self.__dict__[jingle_type + '_sid'])
|
2009-10-16 20:21:42 +02:00
|
|
|
|
2009-10-16 19:36:55 +02:00
|
|
|
if state in ('not_available', 'available', 'stop'):
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__[jingle_type + '_sid'] = None
|
2009-10-16 19:36:55 +02:00
|
|
|
if state in ('connection_received', 'connecting'):
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__[jingle_type + '_sid'] = sid
|
2009-10-16 19:36:55 +02:00
|
|
|
|
2009-10-16 19:04:04 +02:00
|
|
|
if state in ('connecting', 'connected', 'connection_received'):
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_button'].set_active(True)
|
2009-10-16 19:04:04 +02:00
|
|
|
elif state in ('not_available', 'stop'):
|
2009-10-16 21:48:28 +02:00
|
|
|
self.__dict__['_' + jingle_type + '_button'].set_active(False)
|
2009-10-16 19:04:04 +02:00
|
|
|
|
2009-10-16 21:48:28 +02:00
|
|
|
eval('self.update_' + jingle_type)()
|
2009-09-17 14:48:15 +02:00
|
|
|
|
2009-10-16 21:48:28 +02:00
|
|
|
def set_audio_state(self, state, sid=None, reason=None):
|
|
|
|
self._set_jingle_state('audio', state, sid=sid, reason=reason)
|
2009-10-16 19:04:04 +02:00
|
|
|
|
2009-10-16 21:48:28 +02:00
|
|
|
def set_video_state(self, state, sid=None, reason=None):
|
|
|
|
self._set_jingle_state('video', state, sid=sid, reason=reason)
|
2009-09-25 13:52:44 +02:00
|
|
|
|
2006-01-05 04:09:54 +01:00
|
|
|
def on_avatar_eventbox_enter_notify_event(self, widget, event):
|
2008-07-22 17:40:20 +02:00
|
|
|
'''
|
|
|
|
we enter the eventbox area so we under conditions add a timeout
|
|
|
|
to show a bigger avatar after 0.5 sec
|
|
|
|
'''
|
2006-01-03 04:34:32 +01:00
|
|
|
jid = self.contact.jid
|
2006-03-16 08:51:42 +01:00
|
|
|
is_fake = False
|
|
|
|
if self.type_id == message_control.TYPE_PM:
|
|
|
|
is_fake = True
|
|
|
|
avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid,
|
|
|
|
is_fake)
|
2006-01-03 04:34:32 +01:00
|
|
|
if avatar_pixbuf in ('ask', None):
|
|
|
|
return
|
|
|
|
avatar_w = avatar_pixbuf.get_width()
|
|
|
|
avatar_h = avatar_pixbuf.get_height()
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-01-08 06:27:36 +01:00
|
|
|
scaled_buf = self.xml.get_widget('avatar_image').get_pixbuf()
|
2006-01-03 04:34:32 +01:00
|
|
|
scaled_buf_w = scaled_buf.get_width()
|
|
|
|
scaled_buf_h = scaled_buf.get_height()
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
# do we have something bigger to show?
|
|
|
|
if avatar_w > scaled_buf_w or avatar_h > scaled_buf_h:
|
|
|
|
# wait for 0.5 sec in case we leave earlier
|
2008-08-25 22:13:16 +02:00
|
|
|
self.show_bigger_avatar_timeout_id = gobject.timeout_add(500,
|
2006-01-03 04:34:32 +01:00
|
|
|
self.show_bigger_avatar, widget)
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-01-05 04:09:54 +01:00
|
|
|
def on_avatar_eventbox_leave_notify_event(self, widget, event):
|
2006-01-03 04:34:32 +01:00
|
|
|
'''we left the eventbox area that holds the avatar img'''
|
|
|
|
# did we add a timeout? if yes remove it
|
|
|
|
if self.show_bigger_avatar_timeout_id is not None:
|
2008-08-25 22:13:16 +02:00
|
|
|
gobject.source_remove(self.show_bigger_avatar_timeout_id)
|
2006-01-02 23:08:50 +01:00
|
|
|
|
2006-05-26 15:19:52 +02:00
|
|
|
def on_avatar_eventbox_button_press_event(self, widget, event):
|
|
|
|
'''If right-clicked, show popup'''
|
|
|
|
if event.button == 3: # right click
|
|
|
|
menu = gtk.Menu()
|
|
|
|
menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = menuitem.connect('activate',
|
2006-05-26 15:19:52 +02:00
|
|
|
gtkgui_helpers.on_avatar_save_as_menuitem_activate,
|
2007-10-07 22:36:43 +02:00
|
|
|
self.contact.jid, self.account, self.contact.get_shown_name() + \
|
2006-11-08 03:32:49 +01:00
|
|
|
'.jpeg')
|
2008-12-03 18:16:04 +01:00
|
|
|
self.handlers[id_] = menuitem
|
2006-05-26 15:19:52 +02:00
|
|
|
menu.append(menuitem)
|
|
|
|
menu.show_all()
|
2008-04-30 04:55:13 +02:00
|
|
|
menu.connect('selection-done', lambda w:w.destroy())
|
2006-05-26 15:19:52 +02:00
|
|
|
# show the menu
|
|
|
|
menu.show_all()
|
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
|
|
|
return True
|
|
|
|
|
2006-01-02 23:08:50 +01:00
|
|
|
def _on_window_motion_notify(self, widget, event):
|
|
|
|
'''it gets called no matter if it is the active window or not'''
|
2006-01-07 23:53:46 +01:00
|
|
|
if self.parent_win.get_active_jid() == self.contact.jid:
|
2006-03-28 13:52:25 +02:00
|
|
|
# if window is the active one, change vars assisting chatstate
|
2006-01-02 23:08:50 +01:00
|
|
|
self.mouse_over_in_last_5_secs = True
|
|
|
|
self.mouse_over_in_last_30_secs = True
|
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
def _schedule_activity_timers(self):
|
2008-02-14 20:18:07 +01:00
|
|
|
self.possible_paused_timeout_id = gobject.timeout_add_seconds(5,
|
2006-03-28 13:52:25 +02:00
|
|
|
self.check_for_possible_paused_chatstate, None)
|
2008-02-14 20:18:07 +01:00
|
|
|
self.possible_inactive_timeout_id = gobject.timeout_add_seconds(30,
|
2006-03-28 13:52:25 +02:00
|
|
|
self.check_for_possible_inactive_chatstate, None)
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2006-01-10 02:47:24 +01:00
|
|
|
def update_ui(self):
|
2005-12-30 21:47:59 +01:00
|
|
|
# The name banner is drawn here
|
2006-01-10 02:47:24 +01:00
|
|
|
ChatControlBase.update_ui(self)
|
2008-07-23 19:40:02 +02:00
|
|
|
self.update_toolbar()
|
2005-12-31 01:50:33 +01:00
|
|
|
|
|
|
|
def _update_banner_state_image(self):
|
2006-01-08 08:50:26 +01:00
|
|
|
contact = gajim.contacts.get_contact_with_highest_priority(self.account,
|
2006-03-28 13:52:25 +02:00
|
|
|
self.contact.jid)
|
2006-03-14 19:18:34 +01:00
|
|
|
if not contact or self.resource:
|
2006-01-09 00:14:50 +01:00
|
|
|
# For transient contacts
|
|
|
|
contact = self.contact
|
2005-12-31 01:50:33 +01:00
|
|
|
show = contact.show
|
|
|
|
jid = contact.jid
|
|
|
|
|
|
|
|
# Set banner image
|
|
|
|
img_32 = gajim.interface.roster.get_appropriate_state_images(jid,
|
2006-02-26 16:08:59 +01:00
|
|
|
size = '32', icon_name = show)
|
|
|
|
img_16 = gajim.interface.roster.get_appropriate_state_images(jid,
|
|
|
|
icon_name = show)
|
2008-10-07 22:41:59 +02:00
|
|
|
if show in img_32 and img_32[show].get_pixbuf():
|
2005-12-31 01:50:33 +01:00
|
|
|
# we have 32x32! use it!
|
|
|
|
banner_image = img_32[show]
|
|
|
|
use_size_32 = True
|
|
|
|
else:
|
|
|
|
banner_image = img_16[show]
|
|
|
|
use_size_32 = False
|
|
|
|
|
|
|
|
banner_status_img = self.xml.get_widget('banner_status_image')
|
|
|
|
if banner_image.get_storage_type() == gtk.IMAGE_ANIMATION:
|
|
|
|
banner_status_img.set_from_animation(banner_image.get_animation())
|
|
|
|
else:
|
|
|
|
pix = banner_image.get_pixbuf()
|
2006-01-19 09:36:56 +01:00
|
|
|
if pix is not None:
|
|
|
|
if use_size_32:
|
|
|
|
banner_status_img.set_from_pixbuf(pix)
|
|
|
|
else: # we need to scale 16x16 to 32x32
|
|
|
|
scaled_pix = pix.scale_simple(32, 32,
|
|
|
|
gtk.gdk.INTERP_BILINEAR)
|
|
|
|
banner_status_img.set_from_pixbuf(scaled_pix)
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2007-01-09 15:23:28 +01:00
|
|
|
def draw_banner_text(self):
|
2008-05-13 03:59:10 +02:00
|
|
|
'''Draw the text in the fat line at the top of the window that
|
|
|
|
houses the name, jid.
|
2006-01-02 02:23:40 +01:00
|
|
|
'''
|
2005-12-31 01:50:33 +01:00
|
|
|
contact = self.contact
|
|
|
|
jid = contact.jid
|
|
|
|
|
|
|
|
banner_name_label = self.xml.get_widget('banner_name_label')
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-03-14 18:19:54 +01:00
|
|
|
name = contact.get_shown_name()
|
|
|
|
if self.resource:
|
|
|
|
name += '/' + self.resource
|
2006-07-31 22:52:28 +02:00
|
|
|
if self.TYPE_ID == message_control.TYPE_PM:
|
2006-10-12 04:12:10 +02:00
|
|
|
name = _('%(nickname)s from group chat %(room_name)s') %\
|
2006-10-09 11:40:04 +02:00
|
|
|
{'nickname': name, 'room_name': self.room_name}
|
2007-01-17 00:26:38 +01:00
|
|
|
name = gobject.markup_escape_text(name)
|
2006-02-08 05:11:42 +01:00
|
|
|
|
2006-09-27 23:08:10 +02:00
|
|
|
# We know our contacts nick, but if another contact has the same nick
|
|
|
|
# in another account we need to also display the account.
|
2006-03-28 00:26:30 +02:00
|
|
|
# except if we are talking to two different resources of the same contact
|
2006-02-08 05:11:42 +01:00
|
|
|
acct_info = ''
|
2006-09-27 23:08:10 +02:00
|
|
|
for account in gajim.contacts.get_accounts():
|
|
|
|
if account == self.account:
|
2006-02-08 05:11:42 +01:00
|
|
|
continue
|
2006-09-27 23:08:10 +02:00
|
|
|
if acct_info: # We already found a contact with same nick
|
2006-02-08 05:11:42 +01:00
|
|
|
break
|
2006-09-27 23:08:10 +02:00
|
|
|
for jid in gajim.contacts.get_jid_list(account):
|
2008-03-23 18:44:47 +01:00
|
|
|
other_contact_ = \
|
|
|
|
gajim.contacts.get_first_contact_from_jid(account, jid)
|
|
|
|
if other_contact_.get_shown_name() == self.contact.get_shown_name():
|
2006-09-27 23:08:10 +02:00
|
|
|
acct_info = ' (%s)' % \
|
2007-01-17 00:26:38 +01:00
|
|
|
gobject.markup_escape_text(self.account)
|
2006-09-27 23:08:10 +02:00
|
|
|
break
|
2006-03-14 19:18:34 +01:00
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
status = contact.status
|
|
|
|
if status is not None:
|
|
|
|
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
2007-10-09 19:48:22 +02:00
|
|
|
self.banner_status_label.set_ellipsize(pango.ELLIPSIZE_END)
|
2007-11-29 21:33:10 +01:00
|
|
|
status_reduced = helpers.reduce_chars_newlines(status, max_lines = 1)
|
|
|
|
status_escaped = gobject.markup_escape_text(status_reduced)
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2006-03-20 17:22:34 +01:00
|
|
|
font_attrs, font_attrs_small = self.get_font_attrs()
|
2006-11-26 10:06:47 +01:00
|
|
|
st = gajim.config.get('displayed_chat_state_notifications')
|
2005-12-31 01:50:33 +01:00
|
|
|
cs = contact.chatstate
|
|
|
|
if cs and st in ('composing_only', 'all'):
|
|
|
|
if contact.show == 'offline':
|
|
|
|
chatstate = ''
|
2007-06-16 23:31:19 +02:00
|
|
|
elif contact.composing_xep == 'XEP-0085':
|
2006-11-26 10:06:47 +01:00
|
|
|
if st == 'all' or cs == 'composing':
|
|
|
|
chatstate = helpers.get_uf_chatstate(cs)
|
|
|
|
else:
|
|
|
|
chatstate = ''
|
2007-06-16 23:31:19 +02:00
|
|
|
elif contact.composing_xep == 'XEP-0022':
|
2006-03-05 22:41:49 +01:00
|
|
|
if cs in ('composing', 'paused'):
|
2005-12-31 01:50:33 +01:00
|
|
|
# only print composing, paused
|
|
|
|
chatstate = helpers.get_uf_chatstate(cs)
|
|
|
|
else:
|
|
|
|
chatstate = ''
|
2007-01-09 23:05:27 +01:00
|
|
|
else:
|
|
|
|
# When does that happen ? See [7797] and [7804]
|
2006-03-10 11:53:30 +01:00
|
|
|
chatstate = helpers.get_uf_chatstate(cs)
|
2006-09-13 09:20:49 +02:00
|
|
|
|
2008-07-25 00:11:48 +02:00
|
|
|
label_text = '<span %s>%s</span><span %s>%s %s</span>' \
|
|
|
|
% (font_attrs, name, font_attrs_small,
|
|
|
|
acct_info, chatstate)
|
2008-07-29 09:28:07 +02:00
|
|
|
if acct_info:
|
|
|
|
acct_info = ' ' + acct_info
|
|
|
|
label_tooltip = '%s%s %s' % (name, acct_info, chatstate)
|
2005-12-31 01:50:33 +01:00
|
|
|
else:
|
2006-03-01 12:03:56 +01:00
|
|
|
# weight="heavy" size="x-large"
|
2006-03-20 17:22:34 +01:00
|
|
|
label_text = '<span %s>%s</span><span %s>%s</span>' % \
|
2006-09-13 09:20:49 +02:00
|
|
|
(font_attrs, name, font_attrs_small, acct_info)
|
2008-07-29 09:28:07 +02:00
|
|
|
if acct_info:
|
|
|
|
acct_info = ' ' + acct_info
|
|
|
|
label_tooltip = '%s%s' % (name, acct_info)
|
2007-10-09 19:48:22 +02:00
|
|
|
|
2006-03-21 22:22:08 +01:00
|
|
|
if status_escaped:
|
2007-10-09 19:48:22 +02:00
|
|
|
if gajim.HAVE_PYSEXY:
|
|
|
|
status_text = self.urlfinder.sub(self.make_href, status_escaped)
|
|
|
|
status_text = '<span %s>%s</span>' % (font_attrs_small, status_text)
|
|
|
|
else:
|
|
|
|
status_text = '<span %s>%s</span>' % (font_attrs_small, status_escaped)
|
2009-10-29 11:35:22 +01:00
|
|
|
self.banner_status_label.set_tooltip_text(status)
|
2007-11-29 21:33:10 +01:00
|
|
|
self.banner_status_label.show()
|
|
|
|
self.banner_status_label.set_no_show_all(False)
|
2006-03-20 17:51:17 +01:00
|
|
|
else:
|
2007-10-22 14:02:27 +02:00
|
|
|
status_text = ''
|
2007-11-29 21:33:10 +01:00
|
|
|
self.banner_status_label.hide()
|
|
|
|
self.banner_status_label.set_no_show_all(True)
|
2007-10-22 14:02:27 +02:00
|
|
|
|
|
|
|
self.banner_status_label.set_markup(status_text)
|
2005-12-31 01:50:33 +01:00
|
|
|
# setup the label that holds name and jid
|
|
|
|
banner_name_label.set_markup(label_text)
|
2009-10-29 11:35:22 +01:00
|
|
|
banner_name_label.set_tooltip_text(label_tooltip)
|
2006-09-13 09:20:49 +02:00
|
|
|
|
2009-09-25 13:52:44 +02:00
|
|
|
def on_audio_button_toggled(self, widget):
|
|
|
|
if widget.get_active():
|
2009-11-08 10:08:15 +01:00
|
|
|
path_to_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
|
|
|
|
'mic_active.png')
|
2009-10-03 22:40:12 +02:00
|
|
|
if self.audio_state == self.JINGLE_STATE_AVAILABLE:
|
|
|
|
sid = gajim.connections[self.account].startVoIP(
|
|
|
|
self.contact.get_full_jid())
|
|
|
|
self.set_audio_state('connecting', sid)
|
2009-09-25 13:52:44 +02:00
|
|
|
else:
|
2009-11-08 10:08:15 +01:00
|
|
|
path_to_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
|
|
|
|
'mic_inactive.png')
|
2009-09-25 13:52:44 +02:00
|
|
|
session = gajim.connections[self.account].get_jingle_session(
|
2009-09-25 20:40:53 +02:00
|
|
|
self.contact.get_full_jid(), self.audio_sid)
|
2009-09-25 13:52:44 +02:00
|
|
|
if session:
|
2009-09-25 19:32:13 +02:00
|
|
|
content = session.get_content('audio')
|
|
|
|
if content:
|
|
|
|
session.remove_content(content.creator, content.name)
|
2009-11-08 10:08:15 +01:00
|
|
|
img = self._audio_button.get_property('image')
|
|
|
|
img.set_from_file(path_to_img)
|
2009-09-25 13:52:44 +02:00
|
|
|
|
|
|
|
def on_video_button_toggled(self, widget):
|
|
|
|
if widget.get_active():
|
2009-11-08 10:08:15 +01:00
|
|
|
path_to_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
|
|
|
|
'cam_active.png')
|
2009-10-03 22:40:12 +02:00
|
|
|
if self.video_state == self.JINGLE_STATE_AVAILABLE:
|
|
|
|
sid = gajim.connections[self.account].startVideoIP(
|
|
|
|
self.contact.get_full_jid())
|
|
|
|
self.set_video_state('connecting', sid)
|
2009-09-25 13:52:44 +02:00
|
|
|
else:
|
2009-11-08 10:08:15 +01:00
|
|
|
path_to_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
|
|
|
|
'cam_inactive.png')
|
2009-09-25 13:52:44 +02:00
|
|
|
session = gajim.connections[self.account].get_jingle_session(
|
|
|
|
self.contact.get_full_jid(), self.video_sid)
|
|
|
|
if session:
|
2009-09-25 19:32:13 +02:00
|
|
|
content = session.get_content('video')
|
|
|
|
if content:
|
|
|
|
session.remove_content(content.creator, content.name)
|
2009-11-08 10:08:15 +01:00
|
|
|
img = self._video_button.get_property('image')
|
|
|
|
img.set_from_file(path_to_img)
|
2006-09-13 09:20:49 +02:00
|
|
|
|
2007-12-30 00:28:27 +01:00
|
|
|
def _toggle_gpg(self):
|
2008-10-08 22:11:06 +02:00
|
|
|
if not self.gpg_is_active and not self.contact.keyID:
|
|
|
|
dialogs.ErrorDialog(_('No GPG key assigned'),
|
|
|
|
_('No GPG key is assigned to this contact. So you cannot '
|
|
|
|
'encrypt messages with GPG.'))
|
|
|
|
return
|
2007-12-30 00:28:27 +01:00
|
|
|
ec = gajim.encrypted_chats[self.account]
|
2007-12-30 17:30:37 +01:00
|
|
|
if self.gpg_is_active:
|
2007-12-30 00:28:27 +01:00
|
|
|
# Disable encryption
|
|
|
|
ec.remove(self.contact.jid)
|
2007-12-30 17:30:37 +01:00
|
|
|
self.gpg_is_active = False
|
2008-08-31 14:09:13 +02:00
|
|
|
loggable = False
|
2007-12-30 00:28:27 +01:00
|
|
|
msg = _('GPG encryption disabled')
|
2008-07-15 19:04:36 +02:00
|
|
|
ChatControlBase.print_conversation_line(self, msg,
|
|
|
|
'status', '', None)
|
2008-01-25 22:16:22 +01:00
|
|
|
if self.session:
|
|
|
|
self.session.loggable = True
|
|
|
|
|
2005-12-31 01:50:33 +01:00
|
|
|
else:
|
2007-12-30 00:28:27 +01:00
|
|
|
# Enable encryption
|
|
|
|
ec.append(self.contact.jid)
|
2007-12-30 17:30:37 +01:00
|
|
|
self.gpg_is_active = True
|
2007-12-30 00:28:27 +01:00
|
|
|
msg = _('GPG encryption enabled')
|
2008-07-15 19:04:36 +02:00
|
|
|
ChatControlBase.print_conversation_line(self, msg,
|
|
|
|
'status', '', None)
|
2008-01-25 22:16:22 +01:00
|
|
|
|
2009-01-29 21:16:34 +01:00
|
|
|
loggable = gajim.config.get_per('accounts', self.account,
|
|
|
|
'log_encrypted_sessions')
|
2008-08-30 03:31:25 +02:00
|
|
|
|
2008-01-25 22:16:22 +01:00
|
|
|
if self.session:
|
2008-08-30 03:31:25 +02:00
|
|
|
self.session.loggable = loggable
|
|
|
|
|
|
|
|
loggable = self.session.is_loggable()
|
2008-01-25 22:16:22 +01:00
|
|
|
else:
|
2008-08-30 03:31:25 +02:00
|
|
|
loggable = loggable and gajim.config.should_log(self.account,
|
|
|
|
self.contact.jid)
|
|
|
|
|
|
|
|
if loggable:
|
2008-01-25 22:16:22 +01:00
|
|
|
msg = _('Session WILL be logged')
|
2008-08-30 03:31:25 +02:00
|
|
|
else:
|
|
|
|
msg = _('Session WILL NOT be logged')
|
|
|
|
|
2008-07-15 19:04:36 +02:00
|
|
|
ChatControlBase.print_conversation_line(self, msg,
|
|
|
|
'status', '', None)
|
2007-12-30 00:28:27 +01:00
|
|
|
|
2008-07-15 19:04:36 +02:00
|
|
|
gajim.config.set_per('contacts', self.contact.jid,
|
|
|
|
'gpg_enabled', self.gpg_is_active)
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2008-07-15 19:04:36 +02:00
|
|
|
self._show_lock_image(self.gpg_is_active, 'GPG',
|
2008-08-30 03:31:25 +02:00
|
|
|
self.gpg_is_active, loggable, True)
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2008-05-18 21:11:13 +02:00
|
|
|
def _show_lock_image(self, visible, enc_type = '', enc_enabled = False, chat_logged = False, authenticated = False):
|
2008-05-13 03:59:10 +02:00
|
|
|
'''Set lock icon visibility and create tooltip'''
|
2008-08-14 19:19:21 +02:00
|
|
|
#encryption %s active
|
|
|
|
status_string = enc_enabled and _('is') or _('is NOT')
|
|
|
|
#chat session %s be logged
|
|
|
|
logged_string = chat_logged and _('will') or _('will NOT')
|
2008-05-18 21:11:13 +02:00
|
|
|
|
2008-06-29 06:39:29 +02:00
|
|
|
if authenticated:
|
2008-08-14 19:19:21 +02:00
|
|
|
#About encrypted chat session
|
|
|
|
authenticated_string = _('and authenticated')
|
2008-07-09 04:03:57 +02:00
|
|
|
self.lock_image.set_from_file(os.path.join(gajim.DATA_DIR, 'pixmaps', 'security-high.png'))
|
2008-05-18 21:11:13 +02:00
|
|
|
else:
|
2008-08-14 19:19:21 +02:00
|
|
|
#About encrypted chat session
|
|
|
|
authenticated_string = _('and NOT authenticated')
|
2008-07-09 04:03:57 +02:00
|
|
|
self.lock_image.set_from_file(os.path.join(gajim.DATA_DIR, 'pixmaps', 'security-low.png'))
|
2008-05-18 21:11:13 +02:00
|
|
|
|
2008-08-25 20:10:18 +02:00
|
|
|
#status will become 'is' or 'is not', authentificaed will become
|
|
|
|
#'and authentificated' or 'and not authentificated', logged will become
|
|
|
|
#'will' or 'will not'
|
2008-08-14 19:19:21 +02:00
|
|
|
tooltip = _('%(type)s encryption %(status)s active %(authenticated)s.\n'
|
2008-08-25 20:10:18 +02:00
|
|
|
'Your chat session %(logged)s be logged.') % {'type': enc_type,
|
|
|
|
'status': status_string, 'authenticated': authenticated_string,
|
|
|
|
'logged': logged_string}
|
2008-01-11 18:45:20 +01:00
|
|
|
|
2009-10-29 11:35:22 +01:00
|
|
|
self.authentication_button.set_tooltip_text(tooltip)
|
2008-06-29 06:39:29 +02:00
|
|
|
self.widget_set_visible(self.authentication_button, not visible)
|
2008-01-11 18:45:20 +01:00
|
|
|
self.lock_image.set_sensitive(enc_enabled)
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2008-06-29 06:39:29 +02:00
|
|
|
def _on_authentication_button_clicked(self, widget):
|
2008-10-02 22:20:15 +02:00
|
|
|
if self.gpg_is_active:
|
|
|
|
dialogs.GPGInfoWindow(self)
|
|
|
|
elif self.session and self.session.enable_encryption:
|
2008-06-29 06:39:29 +02:00
|
|
|
dialogs.ESessionInfoWindow(self.session)
|
|
|
|
|
2009-09-12 15:51:21 +02:00
|
|
|
def send_message(self, message, keyID='', chatstate=None, xhtml=None,
|
|
|
|
process_commands=True):
|
2005-12-31 04:53:48 +01:00
|
|
|
'''Send a message to contact'''
|
2009-09-11 03:54:26 +02:00
|
|
|
if message in ('', None, '\n'):
|
2008-06-08 18:54:59 +02:00
|
|
|
return None
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
# refresh timers
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
contact = self.contact
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2007-08-20 10:16:48 +02:00
|
|
|
encrypted = bool(self.session) and self.session.enable_encryption
|
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
keyID = ''
|
2007-12-30 17:30:37 +01:00
|
|
|
if self.gpg_is_active:
|
2005-12-31 04:53:48 +01:00
|
|
|
keyID = contact.keyID
|
|
|
|
encrypted = True
|
2007-12-31 02:19:08 +01:00
|
|
|
if not keyID:
|
2007-12-30 00:28:27 +01:00
|
|
|
keyID = 'UNKNOWN'
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2006-11-26 10:06:47 +01:00
|
|
|
chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \
|
|
|
|
'disabled'
|
2007-06-16 23:31:19 +02:00
|
|
|
composing_xep = contact.composing_xep
|
2005-12-31 04:53:48 +01:00
|
|
|
chatstate_to_send = None
|
|
|
|
if chatstates_on and contact is not None:
|
2007-06-16 23:31:19 +02:00
|
|
|
if composing_xep is None:
|
2005-12-31 04:53:48 +01:00
|
|
|
# no info about peer
|
|
|
|
# send active to discover chat state capabilities
|
|
|
|
# this is here (and not in send_chatstate)
|
|
|
|
# because we want it sent with REAL message
|
|
|
|
# (not standlone) eg. one that has body
|
2007-06-08 21:42:02 +02:00
|
|
|
|
2007-03-31 14:21:53 +02:00
|
|
|
if contact.our_chatstate:
|
|
|
|
# We already asked for xep 85, don't ask it twice
|
2007-06-16 23:31:19 +02:00
|
|
|
composing_xep = 'asked_once'
|
2006-11-26 23:00:53 +01:00
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
chatstate_to_send = 'active'
|
|
|
|
contact.our_chatstate = 'ask' # pseudo state
|
|
|
|
# if peer supports jep85 and we are not 'ask', send 'active'
|
|
|
|
# NOTE: first active and 'ask' is set in gajim.py
|
2007-06-16 23:31:19 +02:00
|
|
|
elif composing_xep is not False:
|
2008-06-08 23:27:31 +02:00
|
|
|
# send active chatstate on every message (as XEP says)
|
2005-12-31 04:53:48 +01:00
|
|
|
chatstate_to_send = 'active'
|
|
|
|
contact.our_chatstate = 'active'
|
|
|
|
|
|
|
|
gobject.source_remove(self.possible_paused_timeout_id)
|
|
|
|
gobject.source_remove(self.possible_inactive_timeout_id)
|
|
|
|
self._schedule_activity_timers()
|
2007-12-30 00:28:27 +01:00
|
|
|
|
2009-02-06 20:01:36 +01:00
|
|
|
def _on_sent(id_, contact, message, encrypted, xhtml):
|
2009-10-27 22:41:39 +01:00
|
|
|
if contact.supports(NS_RECEIPTS) and gajim.config.get_per('accounts',
|
2008-07-18 22:24:34 +02:00
|
|
|
self.account, 'request_receipt'):
|
2008-12-03 18:16:04 +01:00
|
|
|
xep0184_id = id_
|
2008-07-18 22:24:34 +02:00
|
|
|
else:
|
|
|
|
xep0184_id = None
|
|
|
|
|
2009-06-26 19:33:46 +02:00
|
|
|
self.print_conversation(message, self.contact.jid, encrypted=encrypted,
|
|
|
|
xep0184_id=xep0184_id, xhtml=xhtml)
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2009-02-06 20:01:36 +01:00
|
|
|
ChatControlBase.send_message(self, message, keyID, type_='chat',
|
|
|
|
chatstate=chatstate_to_send, composing_xep=composing_xep,
|
2009-09-11 03:54:26 +02:00
|
|
|
xhtml=xhtml, callback=_on_sent,
|
2009-09-12 15:51:21 +02:00
|
|
|
callback_args=[contact, message, encrypted, xhtml],
|
|
|
|
process_commands=process_commands)
|
2009-02-06 20:01:36 +01:00
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
def check_for_possible_paused_chatstate(self, arg):
|
|
|
|
''' did we move mouse of that window or write something in message
|
|
|
|
textview in the last 5 seconds?
|
|
|
|
if yes we go active for mouse, composing for kbd
|
|
|
|
if no we go paused if we were previously composing '''
|
|
|
|
contact = self.contact
|
|
|
|
jid = contact.jid
|
|
|
|
current_state = contact.our_chatstate
|
|
|
|
if current_state is False: # jid doesn't support chatstates
|
|
|
|
return False # stop looping
|
|
|
|
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
if self.kbd_activity_in_last_5_secs and message_buffer.get_char_count():
|
|
|
|
# Only composing if the keyboard activity was in text entry
|
|
|
|
self.send_chatstate('composing')
|
|
|
|
elif self.mouse_over_in_last_5_secs and\
|
|
|
|
jid == self.parent_win.get_active_jid():
|
|
|
|
self.send_chatstate('active')
|
|
|
|
else:
|
|
|
|
if current_state == 'composing':
|
|
|
|
self.send_chatstate('paused') # pause composing
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
# assume no activity and let the motion-notify or 'insert-text' make them
|
|
|
|
# True refresh 30 seconds vars too or else it's 30 - 5 = 25 seconds!
|
2005-12-31 04:53:48 +01:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2008-04-30 04:55:13 +02:00
|
|
|
return True # loop forever
|
2005-12-31 04:53:48 +01:00
|
|
|
|
|
|
|
def check_for_possible_inactive_chatstate(self, arg):
|
|
|
|
''' did we move mouse over that window or wrote something in message
|
|
|
|
textview in the last 30 seconds?
|
|
|
|
if yes we go active
|
|
|
|
if no we go inactive '''
|
|
|
|
contact = self.contact
|
|
|
|
|
|
|
|
current_state = contact.our_chatstate
|
|
|
|
if current_state is False: # jid doesn't support chatstates
|
|
|
|
return False # stop looping
|
|
|
|
|
|
|
|
if self.mouse_over_in_last_5_secs or self.kbd_activity_in_last_5_secs:
|
|
|
|
return True # loop forever
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
if not self.mouse_over_in_last_30_secs or \
|
|
|
|
self.kbd_activity_in_last_30_secs:
|
2005-12-31 09:13:20 +01:00
|
|
|
self.send_chatstate('inactive', contact)
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
# assume no activity and let the motion-notify or 'insert-text' make them
|
|
|
|
# True refresh 30 seconds too or else it's 30 - 5 = 25 seconds!
|
2005-12-31 04:53:48 +01:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
|
|
|
return True # loop forever
|
|
|
|
|
|
|
|
def reset_kbd_mouse_timeout_vars(self):
|
|
|
|
self.kbd_activity_in_last_5_secs = False
|
|
|
|
self.mouse_over_in_last_5_secs = False
|
|
|
|
self.mouse_over_in_last_30_secs = False
|
|
|
|
self.kbd_activity_in_last_30_secs = False
|
|
|
|
|
2007-12-08 09:51:10 +01:00
|
|
|
def on_cancel_session_negotiation(self):
|
|
|
|
msg = _('Session negotiation cancelled')
|
|
|
|
ChatControlBase.print_conversation_line(self, msg, 'status', '', None)
|
2007-12-08 06:49:38 +01:00
|
|
|
|
|
|
|
def print_esession_details(self):
|
2008-01-11 18:45:20 +01:00
|
|
|
'''print esession settings to textview'''
|
2008-05-24 01:27:08 +02:00
|
|
|
e2e_is_active = bool(self.session) and self.session.enable_encryption
|
2008-01-11 18:45:20 +01:00
|
|
|
if e2e_is_active:
|
2008-09-08 17:51:13 +02:00
|
|
|
msg = _('This session is encrypted')
|
2007-12-08 06:49:38 +01:00
|
|
|
|
2008-01-25 22:16:22 +01:00
|
|
|
if self.session.is_loggable():
|
2008-09-08 17:51:13 +02:00
|
|
|
msg += _(' and WILL be logged')
|
2007-12-08 06:49:38 +01:00
|
|
|
else:
|
2008-09-08 17:51:13 +02:00
|
|
|
msg += _(' and WILL NOT be logged')
|
2007-12-08 06:49:38 +01:00
|
|
|
|
|
|
|
ChatControlBase.print_conversation_line(self, msg, 'status', '', None)
|
2008-06-29 06:39:29 +02:00
|
|
|
|
|
|
|
if not self.session.verified_identity:
|
2008-07-09 05:10:50 +02:00
|
|
|
ChatControlBase.print_conversation_line(self, _("Remote contact's identity not verified. Click the shield button for more details."), 'status', '', None)
|
2007-12-08 06:49:38 +01:00
|
|
|
else:
|
|
|
|
msg = _('E2E encryption disabled')
|
|
|
|
ChatControlBase.print_conversation_line(self, msg, 'status', '', None)
|
2008-06-29 06:39:29 +02:00
|
|
|
|
2008-01-11 18:45:20 +01:00
|
|
|
self._show_lock_image(e2e_is_active, 'E2E', e2e_is_active, self.session and \
|
2008-06-29 06:39:29 +02:00
|
|
|
self.session.is_loggable(), self.session and self.session.verified_identity)
|
2007-12-08 06:49:38 +01:00
|
|
|
|
2008-02-26 09:31:48 +01:00
|
|
|
def print_conversation(self, text, frm='', tim=None, encrypted=False,
|
2008-07-18 22:24:34 +02:00
|
|
|
subject=None, xhtml=None, simple=False, xep0184_id=None):
|
2005-12-31 04:53:48 +01:00
|
|
|
'''Print a line in the conversation:
|
2009-02-09 20:38:05 +01:00
|
|
|
if frm is set to status: it's a status message
|
|
|
|
if frm is set to error: it's an error message
|
2009-02-10 22:42:55 +01:00
|
|
|
The difference between status and error is mainly that with error, msg
|
|
|
|
count as a new message (in systray and in control).
|
2009-02-09 20:38:05 +01:00
|
|
|
if frm is set to info: it's a information message
|
|
|
|
if frm is set to print_queue: it is incomming from queue
|
|
|
|
if frm is set to another value: it's an outgoing message
|
|
|
|
if frm is not set: it's an incomming message'''
|
2005-12-31 04:53:48 +01:00
|
|
|
contact = self.contact
|
|
|
|
|
|
|
|
if frm == 'status':
|
2006-05-03 15:22:05 +02:00
|
|
|
if not gajim.config.get('print_status_in_chats'):
|
|
|
|
return
|
2005-12-31 04:53:48 +01:00
|
|
|
kind = 'status'
|
|
|
|
name = ''
|
2009-02-09 20:38:05 +01:00
|
|
|
elif frm == 'error':
|
|
|
|
kind = 'error'
|
|
|
|
name = ''
|
2006-04-10 15:23:56 +02:00
|
|
|
elif frm == 'info':
|
|
|
|
kind = 'info'
|
|
|
|
name = ''
|
2005-12-31 04:53:48 +01:00
|
|
|
else:
|
2007-08-20 19:33:12 +02:00
|
|
|
if self.session and self.session.enable_encryption:
|
2008-05-18 21:11:13 +02:00
|
|
|
# ESessions
|
2007-12-08 06:49:38 +01:00
|
|
|
if not encrypted:
|
2008-08-26 13:10:13 +02:00
|
|
|
msg = _('The following message was NOT encrypted')
|
|
|
|
ChatControlBase.print_conversation_line(self, msg, 'status', '',
|
|
|
|
tim)
|
2007-08-20 10:16:48 +02:00
|
|
|
else:
|
|
|
|
# GPG encryption
|
2007-12-30 17:30:37 +01:00
|
|
|
if encrypted and not self.gpg_is_active:
|
2008-08-26 13:10:13 +02:00
|
|
|
msg = _('The following message was encrypted')
|
|
|
|
ChatControlBase.print_conversation_line(self, msg, 'status', '',
|
|
|
|
tim)
|
2008-08-30 04:50:10 +02:00
|
|
|
# turn on OpenPGP if this was in fact a XEP-0027 encrypted message
|
|
|
|
if encrypted == 'xep27':
|
|
|
|
self._toggle_gpg()
|
2007-12-30 17:30:37 +01:00
|
|
|
elif not encrypted and self.gpg_is_active:
|
2008-08-26 13:10:13 +02:00
|
|
|
msg = _('The following message was NOT encrypted')
|
|
|
|
ChatControlBase.print_conversation_line(self, msg, 'status', '',
|
|
|
|
tim)
|
2005-12-31 04:53:48 +01:00
|
|
|
if not frm:
|
|
|
|
kind = 'incoming'
|
2006-01-10 19:30:57 +01:00
|
|
|
name = contact.get_shown_name()
|
2005-12-31 04:53:48 +01:00
|
|
|
elif frm == 'print_queue': # incoming message, but do not update time
|
|
|
|
kind = 'incoming_queue'
|
2006-01-10 19:30:57 +01:00
|
|
|
name = contact.get_shown_name()
|
2005-12-31 04:53:48 +01:00
|
|
|
else:
|
|
|
|
kind = 'outgoing'
|
2006-05-08 10:19:20 +02:00
|
|
|
name = gajim.nicks[self.account]
|
2009-08-30 11:58:41 +02:00
|
|
|
if not xhtml and not (encrypted and self.gpg_is_active) and \
|
|
|
|
gajim.config.get('rst_formatting_outgoing_messages'):
|
2008-11-05 19:25:40 +01:00
|
|
|
from common.rst_xhtml_generator import create_xhtml
|
2006-10-04 13:53:03 +02:00
|
|
|
xhtml = create_xhtml(text)
|
|
|
|
if xhtml:
|
|
|
|
xhtml = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml)
|
2005-12-31 04:53:48 +01:00
|
|
|
ChatControlBase.print_conversation_line(self, text, kind, name, tim,
|
2008-02-26 09:31:48 +01:00
|
|
|
subject=subject, old_kind=self.old_msg_kind, xhtml=xhtml,
|
2008-07-18 22:24:34 +02:00
|
|
|
simple=simple, xep0184_id=xep0184_id)
|
2006-05-08 10:19:20 +02:00
|
|
|
if text.startswith('/me ') or text.startswith('/me\n'):
|
|
|
|
self.old_msg_kind = None
|
|
|
|
else:
|
|
|
|
self.old_msg_kind = kind
|
2005-12-29 04:21:43 +01:00
|
|
|
|
2006-01-05 03:58:59 +01:00
|
|
|
def get_tab_label(self, chatstate):
|
2005-12-31 07:27:22 +01:00
|
|
|
unread = ''
|
2006-09-02 23:01:11 +02:00
|
|
|
if self.resource:
|
|
|
|
jid = self.contact.get_full_jid()
|
|
|
|
else:
|
|
|
|
jid = self.contact.jid
|
|
|
|
num_unread = len(gajim.events.get_events(self.account, jid,
|
|
|
|
['printed_' + self.type_id, self.type_id]))
|
2005-12-31 07:27:22 +01:00
|
|
|
if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'):
|
|
|
|
unread = '*'
|
|
|
|
elif num_unread > 1:
|
|
|
|
unread = '[' + unicode(num_unread) + ']'
|
|
|
|
|
2008-05-04 02:24:27 +02:00
|
|
|
# Draw tab label using chatstate
|
2005-12-31 07:27:22 +01:00
|
|
|
theme = gajim.config.get('roster_theme')
|
|
|
|
color = None
|
2007-01-29 19:29:51 +01:00
|
|
|
if not chatstate:
|
|
|
|
chatstate = self.contact.chatstate
|
2005-12-31 07:27:22 +01:00
|
|
|
if chatstate is not None:
|
|
|
|
if chatstate == 'composing':
|
|
|
|
color = gajim.config.get_per('themes', theme,
|
|
|
|
'state_composing_color')
|
|
|
|
elif chatstate == 'inactive':
|
|
|
|
color = gajim.config.get_per('themes', theme,
|
|
|
|
'state_inactive_color')
|
|
|
|
elif chatstate == 'gone':
|
|
|
|
color = gajim.config.get_per('themes', theme,
|
|
|
|
'state_gone_color')
|
|
|
|
elif chatstate == 'paused':
|
|
|
|
color = gajim.config.get_per('themes', theme,
|
|
|
|
'state_paused_color')
|
|
|
|
if color:
|
|
|
|
# We set the color for when it's the current tab or not
|
2006-01-08 21:32:39 +01:00
|
|
|
color = gtk.gdk.colormap_get_system().alloc_color(color)
|
2005-12-31 07:27:22 +01:00
|
|
|
# In inactive tab color to be lighter against the darker inactive
|
|
|
|
# background
|
2006-01-08 21:32:39 +01:00
|
|
|
if chatstate in ('inactive', 'gone') and\
|
|
|
|
self.parent_win.get_active_control() != self:
|
2006-01-05 06:51:28 +01:00
|
|
|
color = self.lighten_color(color)
|
2007-01-28 14:31:30 +01:00
|
|
|
else: # active or not chatstate, get color from gtk
|
2006-09-25 06:23:31 +02:00
|
|
|
color = self.parent_win.notebook.style.fg[gtk.STATE_ACTIVE]
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
|
2006-03-15 09:46:44 +01:00
|
|
|
name = self.contact.get_shown_name()
|
|
|
|
if self.resource:
|
|
|
|
name += '/' + self.resource
|
2007-01-17 00:26:38 +01:00
|
|
|
label_str = gobject.markup_escape_text(name)
|
2005-12-31 07:27:22 +01:00
|
|
|
if num_unread: # if unread, text in the label becomes bold
|
|
|
|
label_str = '<b>' + unread + label_str + '</b>'
|
|
|
|
return (label_str, color)
|
2005-12-31 08:19:43 +01:00
|
|
|
|
2009-10-23 10:02:45 +02:00
|
|
|
def get_tab_image(self, count_unread=True):
|
2006-09-02 23:01:11 +02:00
|
|
|
if self.resource:
|
|
|
|
jid = self.contact.get_full_jid()
|
|
|
|
else:
|
|
|
|
jid = self.contact.jid
|
2009-10-23 10:02:45 +02:00
|
|
|
if count_unread:
|
|
|
|
num_unread = len(gajim.events.get_events(self.account, jid,
|
|
|
|
['printed_' + self.type_id, self.type_id]))
|
|
|
|
else:
|
|
|
|
num_unread = 0
|
2007-07-13 12:11:49 +02:00
|
|
|
# Set tab image (always 16x16); unread messages show the 'event' image
|
2006-01-05 03:58:59 +01:00
|
|
|
tab_img = None
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-01-05 03:58:59 +01:00
|
|
|
if num_unread and gajim.config.get('show_unread_tab_icon'):
|
2006-02-26 16:08:59 +01:00
|
|
|
img_16 = gajim.interface.roster.get_appropriate_state_images(
|
2007-07-13 12:11:49 +02:00
|
|
|
self.contact.jid, icon_name = 'event')
|
|
|
|
tab_img = img_16['event']
|
2006-01-05 03:58:59 +01:00
|
|
|
else:
|
2006-09-02 23:01:11 +02:00
|
|
|
contact = gajim.contacts.get_contact_with_highest_priority(
|
|
|
|
self.account, self.contact.jid)
|
2006-03-14 19:18:34 +01:00
|
|
|
if not contact or self.resource:
|
2006-01-09 00:14:50 +01:00
|
|
|
# For transient contacts
|
|
|
|
contact = self.contact
|
2006-02-26 16:08:59 +01:00
|
|
|
img_16 = gajim.interface.roster.get_appropriate_state_images(
|
2009-10-23 10:02:45 +02:00
|
|
|
self.contact.jid, icon_name=contact.show)
|
2006-01-08 08:50:26 +01:00
|
|
|
tab_img = img_16[contact.show]
|
2006-01-05 03:58:59 +01:00
|
|
|
|
|
|
|
return tab_img
|
|
|
|
|
2009-10-27 18:58:27 +01:00
|
|
|
def prepare_context_menu(self, hide_buttonbar_items=False):
|
2005-12-31 08:19:43 +01:00
|
|
|
'''sets compact view menuitem active state
|
2006-03-28 13:33:31 +02:00
|
|
|
sets active and sensitivity state for toggle_gpg_menuitem
|
|
|
|
sets sensitivity for history_menuitem (False for tranasports)
|
|
|
|
and file_transfer_menuitem
|
|
|
|
and hide()/show() for add_to_roster_menuitem
|
|
|
|
'''
|
2009-10-27 18:58:27 +01:00
|
|
|
menu = gui_menu_builder.get_contact_menu(self.contact, self.account,
|
|
|
|
use_multiple_contacts=False, show_start_chat=False,
|
|
|
|
show_encryption=True, control=self,
|
|
|
|
show_buttonbar_items=not hide_buttonbar_items)
|
2005-12-31 08:19:43 +01:00
|
|
|
return menu
|
|
|
|
|
2005-12-31 09:13:20 +01:00
|
|
|
def send_chatstate(self, state, contact = None):
|
|
|
|
''' sends OUR chatstate as STANDLONE chat state message (eg. no body)
|
2006-01-03 04:34:32 +01:00
|
|
|
to contact only if new chatstate is different from the previous one
|
2005-12-31 09:13:20 +01:00
|
|
|
if jid is not specified, send to active tab'''
|
|
|
|
# JEP 85 does not allow resending the same chatstate
|
|
|
|
# this function checks for that and just returns so it's safe to call it
|
|
|
|
# with same state.
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2005-12-31 09:13:20 +01:00
|
|
|
# This functions also checks for violation in state transitions
|
|
|
|
# and raises RuntimeException with appropriate message
|
|
|
|
# more on that http://www.jabber.org/jeps/jep-0085.html#statechart
|
|
|
|
|
|
|
|
# do not send nothing if we have chat state notifications disabled
|
|
|
|
# that means we won't reply to the <active/> from other peer
|
|
|
|
# so we do not broadcast jep85 capabalities
|
2006-11-26 10:06:47 +01:00
|
|
|
chatstate_setting = gajim.config.get('outgoing_chat_state_notifications')
|
2005-12-31 09:13:20 +01:00
|
|
|
if chatstate_setting == 'disabled':
|
|
|
|
return
|
|
|
|
elif chatstate_setting == 'composing_only' and state != 'active' and\
|
|
|
|
state != 'composing':
|
|
|
|
return
|
|
|
|
|
|
|
|
if contact is None:
|
|
|
|
contact = self.parent_win.get_active_contact()
|
2006-03-03 15:41:55 +01:00
|
|
|
if contact is None:
|
|
|
|
# contact was from pm in MUC, and left the room so contact is None
|
|
|
|
# so we cannot send chatstate anymore
|
|
|
|
return
|
2005-12-31 09:13:20 +01:00
|
|
|
|
|
|
|
# Don't send chatstates to offline contacts
|
|
|
|
if contact.show == 'offline':
|
|
|
|
return
|
|
|
|
|
2007-06-16 23:31:19 +02:00
|
|
|
if contact.composing_xep is False: # jid cannot do xep85 nor xep22
|
2005-12-31 09:13:20 +01:00
|
|
|
return
|
|
|
|
|
2008-04-30 04:55:13 +02:00
|
|
|
# if the new state we wanna send (state) equals
|
2005-12-31 09:13:20 +01:00
|
|
|
# the current state (contact.our_chatstate) then return
|
|
|
|
if contact.our_chatstate == state:
|
|
|
|
return
|
|
|
|
|
2007-06-16 23:31:19 +02:00
|
|
|
if contact.composing_xep is None:
|
2005-12-31 09:13:20 +01:00
|
|
|
# we don't know anything about jid, so return
|
|
|
|
# NOTE:
|
|
|
|
# send 'active', set current state to 'ask' and return is done
|
|
|
|
# in self.send_message() because we need REAL message (with <body>)
|
|
|
|
# for that procedure so return to make sure we send only once
|
|
|
|
# 'active' until we know peer supports jep85
|
2008-04-30 04:55:13 +02:00
|
|
|
return
|
2005-12-31 09:13:20 +01:00
|
|
|
|
|
|
|
if contact.our_chatstate == 'ask':
|
|
|
|
return
|
|
|
|
|
2006-03-03 15:41:55 +01:00
|
|
|
# in JEP22, when we already sent stop composing
|
|
|
|
# notification on paused, don't resend it
|
2007-06-16 23:31:19 +02:00
|
|
|
if contact.composing_xep == 'XEP-0022' and \
|
2006-04-17 23:59:04 +02:00
|
|
|
contact.our_chatstate in ('paused', 'active', 'inactive') and \
|
|
|
|
state is not 'composing': # not composing == in (active, inactive, gone)
|
2006-03-03 15:41:55 +01:00
|
|
|
contact.our_chatstate = 'active'
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
|
|
|
return
|
|
|
|
|
2005-12-31 09:13:20 +01:00
|
|
|
# prevent going paused if we we were not composing (JEP violation)
|
|
|
|
if state == 'paused' and not contact.our_chatstate == 'composing':
|
2006-10-03 16:12:42 +02:00
|
|
|
# go active before
|
|
|
|
MessageControl.send_message(self, None, chatstate = 'active')
|
2005-12-31 09:13:20 +01:00
|
|
|
contact.our_chatstate = 'active'
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2005-12-31 09:13:20 +01:00
|
|
|
# if we're inactive prevent composing (JEP violation)
|
2006-02-27 00:29:49 +01:00
|
|
|
elif contact.our_chatstate == 'inactive' and state == 'composing':
|
2006-10-03 16:12:42 +02:00
|
|
|
# go active before
|
|
|
|
MessageControl.send_message(self, None, chatstate = 'active')
|
2005-12-31 09:13:20 +01:00
|
|
|
contact.our_chatstate = 'active'
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
MessageControl.send_message(self, None, chatstate = state,
|
2007-06-16 23:31:19 +02:00
|
|
|
msg_id = contact.msg_id, composing_xep = contact.composing_xep)
|
2005-12-31 09:13:20 +01:00
|
|
|
contact.our_chatstate = state
|
|
|
|
if contact.our_chatstate == 'active':
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2006-01-01 20:40:05 +01:00
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
# Send 'gone' chatstate
|
2006-01-03 06:49:09 +01:00
|
|
|
self.send_chatstate('gone', self.contact)
|
2006-01-01 20:40:05 +01:00
|
|
|
self.contact.chatstate = None
|
|
|
|
self.contact.our_chatstate = None
|
2008-02-06 06:24:07 +01:00
|
|
|
|
2008-05-13 03:59:10 +02:00
|
|
|
# disconnect self from session
|
2008-05-24 01:27:08 +02:00
|
|
|
if self.session:
|
|
|
|
self.session.control = None
|
2008-02-06 06:24:07 +01:00
|
|
|
|
2006-01-01 20:40:05 +01:00
|
|
|
# Disconnect timer callbacks
|
|
|
|
gobject.source_remove(self.possible_paused_timeout_id)
|
|
|
|
gobject.source_remove(self.possible_inactive_timeout_id)
|
2006-06-14 16:54:23 +02:00
|
|
|
# Remove bigger avatar window
|
|
|
|
if self.bigger_avatar_window:
|
|
|
|
self.bigger_avatar_window.destroy()
|
2006-09-02 23:01:11 +02:00
|
|
|
# Clean events
|
|
|
|
gajim.events.remove_events(self.account, self.get_full_jid(),
|
|
|
|
types = ['printed_' + self.type_id, self.type_id])
|
2008-09-16 23:51:48 +02:00
|
|
|
# Remove contact instance if contact has been removed
|
|
|
|
key = (self.contact.jid, self.account)
|
|
|
|
roster = gajim.interface.roster
|
2008-09-29 22:52:53 +02:00
|
|
|
if key in roster.contacts_to_be_removed.keys() and \
|
|
|
|
not roster.contact_has_pending_roster_events(self.contact, self.account):
|
2008-09-16 23:51:48 +02:00
|
|
|
backend = roster.contacts_to_be_removed[key]['backend']
|
|
|
|
del roster.contacts_to_be_removed[key]
|
|
|
|
roster.remove_contact(self.contact.jid, self.account, force=True,
|
|
|
|
backend=backend)
|
2008-06-05 17:09:17 +02:00
|
|
|
# remove all register handlers on widgets, created by self.xml
|
2006-04-17 23:59:04 +02:00
|
|
|
# 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]
|
2006-04-18 17:36:16 +02:00
|
|
|
self.conv_textview.del_handlers()
|
2009-09-15 21:19:38 +02:00
|
|
|
if gajim.config.get('use_speller') and HAS_GTK_SPELL:
|
|
|
|
spell_obj = gtkspell.get_from_text_view(self.msg_textview)
|
|
|
|
if spell_obj:
|
|
|
|
spell_obj.detach()
|
2006-04-18 17:36:16 +02:00
|
|
|
self.msg_textview.destroy()
|
2006-01-01 20:40:05 +01:00
|
|
|
|
2009-04-23 09:26:08 +02:00
|
|
|
def minimizable(self):
|
|
|
|
return False
|
|
|
|
|
2009-04-08 18:28:51 +02:00
|
|
|
def safe_shutdown(self):
|
|
|
|
return False
|
|
|
|
|
2008-08-08 17:19:08 +02:00
|
|
|
def allow_shutdown(self, method, on_yes, on_no, on_minimize):
|
2006-03-14 18:13:34 +01:00
|
|
|
if time.time() - gajim.last_message_time[self.account]\
|
|
|
|
[self.get_full_jid()] < 2:
|
2006-01-01 20:40:05 +01:00
|
|
|
# 2 seconds
|
2008-08-08 17:19:08 +02:00
|
|
|
def on_ok():
|
|
|
|
on_yes(self)
|
|
|
|
|
|
|
|
def on_cancel():
|
|
|
|
on_no(self)
|
|
|
|
|
2008-12-02 16:53:23 +01:00
|
|
|
dialogs.ConfirmationDialog(
|
2007-06-15 20:30:48 +02:00
|
|
|
# %s is being replaced in the code with JID
|
2006-09-09 00:27:04 +02:00
|
|
|
_('You just received a new message from "%s"') % self.contact.jid,
|
2006-01-01 20:40:05 +01:00
|
|
|
_('If you close this tab and you have history disabled, '\
|
2008-08-08 17:19:08 +02:00
|
|
|
'this message will be lost.'), on_response_ok=on_ok,
|
|
|
|
on_response_cancel=on_cancel)
|
|
|
|
return
|
|
|
|
on_yes(self)
|
2006-01-01 20:40:05 +01:00
|
|
|
|
2006-01-02 02:23:40 +01:00
|
|
|
def handle_incoming_chatstate(self):
|
|
|
|
''' handle incoming chatstate that jid SENT TO us '''
|
2007-01-09 15:23:28 +01:00
|
|
|
self.draw_banner_text()
|
2006-01-02 02:23:40 +01:00
|
|
|
# update chatstate in tab for this chat
|
2006-01-25 06:39:07 +01:00
|
|
|
self.parent_win.redraw_tab(self, self.contact.chatstate)
|
2006-01-02 02:23:40 +01:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
def set_control_active(self, state):
|
|
|
|
ChatControlBase.set_control_active(self, state)
|
|
|
|
# send chatstate inactive to the one we're leaving
|
|
|
|
# and active to the one we visit
|
|
|
|
if state:
|
2006-01-03 06:49:09 +01:00
|
|
|
self.send_chatstate('active', self.contact)
|
2006-01-02 10:04:30 +01:00
|
|
|
else:
|
2006-01-03 06:49:09 +01:00
|
|
|
self.send_chatstate('inactive', self.contact)
|
2009-06-23 16:42:32 +02:00
|
|
|
# Hide bigger avatar window
|
|
|
|
if self.bigger_avatar_window:
|
|
|
|
self.bigger_avatar_window.destroy()
|
|
|
|
self.bigger_avatar_window = None
|
|
|
|
# Re-show the small avatar
|
|
|
|
self.show_avatar()
|
2006-01-02 23:08:50 +01:00
|
|
|
|
|
|
|
def show_avatar(self, resource = None):
|
2006-01-08 06:05:16 +01:00
|
|
|
if not gajim.config.get('show_avatar_in_chat'):
|
|
|
|
return
|
|
|
|
|
2007-05-20 17:41:20 +02:00
|
|
|
is_fake = False
|
|
|
|
if self.TYPE_ID == message_control.TYPE_PM:
|
|
|
|
is_fake = True
|
|
|
|
jid_with_resource = self.contact.jid # fake jid
|
|
|
|
else:
|
|
|
|
jid_with_resource = self.contact.jid
|
|
|
|
if resource:
|
|
|
|
jid_with_resource += '/' + resource
|
2006-01-02 23:08:50 +01:00
|
|
|
|
|
|
|
# we assume contact has no avatar
|
|
|
|
scaled_pixbuf = None
|
|
|
|
|
2006-03-09 19:41:57 +01:00
|
|
|
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource,
|
|
|
|
is_fake)
|
|
|
|
if pixbuf == 'ask':
|
|
|
|
# we don't have the vcard
|
2007-05-20 17:41:20 +02:00
|
|
|
if self.TYPE_ID == message_control.TYPE_PM:
|
|
|
|
if self.gc_contact.jid:
|
|
|
|
# We know the real jid of this contact
|
|
|
|
real_jid = self.gc_contact.jid
|
|
|
|
if self.gc_contact.resource:
|
|
|
|
real_jid += '/' + self.gc_contact.resource
|
|
|
|
else:
|
|
|
|
real_jid = jid_with_resource
|
|
|
|
gajim.connections[self.account].request_vcard(real_jid,
|
|
|
|
jid_with_resource)
|
|
|
|
else:
|
|
|
|
gajim.connections[self.account].request_vcard(jid_with_resource)
|
2006-01-02 23:08:50 +01:00
|
|
|
return
|
|
|
|
if pixbuf is not None:
|
|
|
|
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat')
|
|
|
|
|
|
|
|
image = self.xml.get_widget('avatar_image')
|
|
|
|
image.set_from_pixbuf(scaled_pixbuf)
|
|
|
|
image.show_all()
|
|
|
|
|
2006-03-28 13:52:25 +02:00
|
|
|
def _on_drag_data_received(self, widget, context, x, y, selection,
|
|
|
|
target_type, timestamp):
|
2007-08-22 19:20:44 +02:00
|
|
|
if not selection.data:
|
|
|
|
return
|
2007-06-15 19:38:14 +02:00
|
|
|
if self.TYPE_ID == message_control.TYPE_PM:
|
|
|
|
c = self.gc_contact
|
|
|
|
else:
|
|
|
|
c = self.contact
|
2006-01-02 23:08:50 +01:00
|
|
|
if target_type == self.TARGET_TYPE_URI_LIST:
|
2007-08-22 19:20:44 +02:00
|
|
|
if not c.resource: # If no resource is known, we can't send a file
|
2007-07-25 19:30:43 +02:00
|
|
|
return
|
2006-01-02 23:08:50 +01:00
|
|
|
uri = selection.data.strip()
|
|
|
|
uri_splitted = uri.split() # we may have more than one file dropped
|
|
|
|
for uri in uri_splitted:
|
|
|
|
path = helpers.get_file_path_from_dnd_dropped_uri(uri)
|
|
|
|
if os.path.isfile(path): # is it file?
|
|
|
|
ft = gajim.interface.instances['file_transfers']
|
2007-06-15 19:38:14 +02:00
|
|
|
ft.send_file(self.account, c, path)
|
2007-08-22 19:20:44 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
# chat2muc
|
|
|
|
treeview = gajim.interface.roster.tree
|
|
|
|
model = treeview.get_model()
|
|
|
|
data = selection.data
|
|
|
|
path = treeview.get_selection().get_selected_rows()[1][0]
|
2008-12-03 18:16:04 +01:00
|
|
|
iter_ = model.get_iter(path)
|
|
|
|
type_ = model[iter_][2]
|
|
|
|
if type_ != 'contact': # source is not a contact
|
2007-08-22 19:20:44 +02:00
|
|
|
return
|
|
|
|
dropped_jid = data.decode('utf-8')
|
|
|
|
|
|
|
|
dropped_transport = gajim.get_transport_name_from_jid(dropped_jid)
|
|
|
|
c_transport = gajim.get_transport_name_from_jid(c.jid)
|
|
|
|
if dropped_transport or c_transport:
|
|
|
|
return # transport contacts cannot be invited
|
|
|
|
|
|
|
|
dialogs.TransformChatToMUC(self.account, [c.jid], [dropped_jid])
|
2007-07-23 17:29:53 +02:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
def _on_message_tv_buffer_changed(self, textbuffer):
|
|
|
|
self.kbd_activity_in_last_5_secs = True
|
|
|
|
self.kbd_activity_in_last_30_secs = True
|
|
|
|
if textbuffer.get_char_count():
|
|
|
|
self.send_chatstate('composing', self.contact)
|
2008-07-25 00:13:37 +02:00
|
|
|
|
|
|
|
e2e_is_active = self.session and \
|
|
|
|
self.session.enable_encryption
|
2009-01-30 17:48:15 +01:00
|
|
|
e2e_pref = gajim.config.get_per('accounts', self.account,
|
|
|
|
'enable_esessions') and gajim.config.get_per('accounts',
|
|
|
|
self.account, 'autonegotiate_esessions') and gajim.config.get_per(
|
|
|
|
'contacts', self.contact.jid, 'autonegotiate_esessions')
|
2008-07-27 23:42:34 +02:00
|
|
|
want_e2e = not e2e_is_active and not self.gpg_is_active \
|
|
|
|
and e2e_pref
|
|
|
|
|
2008-08-09 23:13:41 +02:00
|
|
|
if want_e2e and not self.no_autonegotiation \
|
2009-10-27 22:41:39 +01:00
|
|
|
and gajim.HAVE_PYCRYPTO and self.contact.supports(NS_ESESSION):
|
2008-07-25 00:13:37 +02:00
|
|
|
self.begin_e2e_negotiation()
|
2006-01-03 04:34:32 +01:00
|
|
|
else:
|
|
|
|
self.send_chatstate('active', self.contact)
|
|
|
|
|
|
|
|
def restore_conversation(self):
|
|
|
|
jid = self.contact.jid
|
|
|
|
# don't restore lines if it's a transport
|
|
|
|
if gajim.jid_is_transport(jid):
|
|
|
|
return
|
2006-03-24 20:20:05 +01:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
# How many lines to restore and when to time them out
|
|
|
|
restore_how_many = gajim.config.get('restore_lines')
|
2006-02-22 22:22:25 +01:00
|
|
|
if restore_how_many <= 0:
|
|
|
|
return
|
2006-01-03 04:34:32 +01:00
|
|
|
timeout = gajim.config.get('restore_timeout') # in minutes
|
2006-03-24 20:20:05 +01:00
|
|
|
|
2006-09-02 23:01:11 +02:00
|
|
|
# number of messages that are in queue and are already logged, we want
|
|
|
|
# to avoid duplication
|
2006-11-11 15:47:08 +01:00
|
|
|
pending_how_many = len(gajim.events.get_events(self.account, jid,
|
|
|
|
['chat', 'pm']))
|
|
|
|
if self.resource:
|
|
|
|
pending_how_many += len(gajim.events.get_events(self.account,
|
|
|
|
self.contact.get_full_jid(), ['chat', 'pm']))
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2008-03-17 08:22:43 +01:00
|
|
|
try:
|
|
|
|
rows = gajim.logger.get_last_conversation_lines(jid, restore_how_many,
|
|
|
|
pending_how_many, timeout, self.account)
|
|
|
|
except exceptions.DatabaseMalformed:
|
2009-06-07 20:59:04 +02:00
|
|
|
import common.logger
|
2008-03-17 08:22:43 +01:00
|
|
|
dialogs.ErrorDialog(_('Database Error'),
|
2009-06-07 20:59:04 +02:00
|
|
|
_('The database file (%s) cannot be read. Try to repair it or remove it (all history will be lost).') % common.logger.LOG_DB_PATH)
|
2008-03-17 08:22:43 +01:00
|
|
|
rows = []
|
2006-05-08 10:19:20 +02:00
|
|
|
local_old_kind = None
|
2006-01-03 04:34:32 +01:00
|
|
|
for row in rows: # row[0] time, row[1] has kind, row[2] the message
|
|
|
|
if not row[2]: # message is empty, we don't print it
|
|
|
|
continue
|
|
|
|
if row[1] in (constants.KIND_CHAT_MSG_SENT,
|
|
|
|
constants.KIND_SINGLE_MSG_SENT):
|
|
|
|
kind = 'outgoing'
|
|
|
|
name = gajim.nicks[self.account]
|
|
|
|
elif row[1] in (constants.KIND_SINGLE_MSG_RECV,
|
|
|
|
constants.KIND_CHAT_MSG_RECV):
|
|
|
|
kind = 'incoming'
|
2006-01-10 19:30:57 +01:00
|
|
|
name = self.contact.get_shown_name()
|
2007-01-10 13:51:15 +01:00
|
|
|
elif row[1] == constants.KIND_ERROR:
|
|
|
|
kind = 'status'
|
2007-01-13 22:42:28 +01:00
|
|
|
name = self.contact.get_shown_name()
|
2006-01-03 04:34:32 +01:00
|
|
|
|
|
|
|
tim = time.localtime(float(row[0]))
|
|
|
|
|
2006-08-28 17:10:23 +02:00
|
|
|
if gajim.config.get('restored_messages_small'):
|
|
|
|
small_attr = ['small']
|
|
|
|
else:
|
|
|
|
small_attr = []
|
2006-01-03 04:34:32 +01:00
|
|
|
ChatControlBase.print_conversation_line(self, row[2], kind, name, tim,
|
2006-08-28 17:10:23 +02:00
|
|
|
small_attr,
|
|
|
|
small_attr + ['restored_message'],
|
|
|
|
small_attr + ['restored_message'],
|
2006-05-08 10:19:20 +02:00
|
|
|
False, old_kind = local_old_kind)
|
|
|
|
if row[2].startswith('/me ') or row[2].startswith('/me\n'):
|
|
|
|
local_old_kind = None
|
|
|
|
else:
|
|
|
|
local_old_kind = kind
|
2006-01-03 04:34:32 +01:00
|
|
|
if len(rows):
|
|
|
|
self.conv_textview.print_empty_line()
|
|
|
|
|
|
|
|
def read_queue(self):
|
|
|
|
'''read queue and print messages containted in it'''
|
2007-12-08 06:49:38 +01:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
jid = self.contact.jid
|
2006-03-28 13:52:25 +02:00
|
|
|
jid_with_resource = jid
|
2006-03-21 19:34:03 +01:00
|
|
|
if self.resource:
|
2006-03-28 13:52:25 +02:00
|
|
|
jid_with_resource += '/' + self.resource
|
2006-09-02 23:01:11 +02:00
|
|
|
events = gajim.events.get_events(self.account, jid_with_resource)
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2006-04-11 00:08:02 +02:00
|
|
|
# list of message ids which should be marked as read
|
|
|
|
message_ids = []
|
2006-09-02 23:01:11 +02:00
|
|
|
for event in events:
|
2006-09-07 15:19:43 +02:00
|
|
|
if event.type_ != self.type_id:
|
2006-01-03 04:34:32 +01:00
|
|
|
continue
|
2006-09-02 23:01:11 +02:00
|
|
|
data = event.parameters
|
2006-01-03 04:34:32 +01:00
|
|
|
kind = data[2]
|
|
|
|
if kind == 'error':
|
2006-04-10 15:23:56 +02:00
|
|
|
kind = 'info'
|
2006-01-03 04:34:32 +01:00
|
|
|
else:
|
|
|
|
kind = 'print_queue'
|
|
|
|
self.print_conversation(data[0], kind, tim = data[3],
|
2006-10-09 11:40:04 +02:00
|
|
|
encrypted = data[4], subject = data[1], xhtml = data[7])
|
2006-04-11 00:08:02 +02:00
|
|
|
if len(data) > 6 and isinstance(data[6], int):
|
|
|
|
message_ids.append(data[6])
|
2007-06-06 01:19:34 +02:00
|
|
|
|
|
|
|
if len(data) > 8:
|
|
|
|
self.set_session(data[8])
|
2006-04-11 00:08:02 +02:00
|
|
|
if message_ids:
|
|
|
|
gajim.logger.set_read_messages(message_ids)
|
2006-09-02 23:01:11 +02:00
|
|
|
gajim.events.remove_events(self.account, jid_with_resource,
|
2006-09-07 15:19:43 +02:00
|
|
|
types = [self.type_id])
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
typ = 'chat' # Is it a normal chat or a pm ?
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2006-01-06 07:59:55 +01:00
|
|
|
# reset to status image in gc if it is a pm
|
2008-04-30 04:55:13 +02:00
|
|
|
# Is it a pm ?
|
|
|
|
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
|
2008-05-13 03:59:10 +02:00
|
|
|
control = gajim.interface.msg_win_mgr.get_gc_control(room_jid,
|
|
|
|
self.account)
|
2008-05-04 02:24:27 +02:00
|
|
|
if control and control.type_id == message_control.TYPE_GC:
|
2006-01-10 02:47:24 +01:00
|
|
|
control.update_ui()
|
2006-12-13 13:52:59 +01:00
|
|
|
control.parent_win.show_title()
|
2006-01-06 07:59:55 +01:00
|
|
|
typ = 'pm'
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2006-11-08 17:47:07 +01:00
|
|
|
self.redraw_after_event_removed(jid)
|
2006-10-16 22:05:09 +02:00
|
|
|
if (self.contact.show in ('offline', 'error')):
|
|
|
|
show_offline = gajim.config.get('showoffline')
|
|
|
|
show_transports = gajim.config.get('show_transports_group')
|
|
|
|
if (not show_transports and gajim.jid_is_transport(jid)) or \
|
|
|
|
(not show_offline and typ == 'chat' and \
|
2007-07-04 15:23:16 +02:00
|
|
|
len(gajim.contacts.get_contacts(self.account, jid)) < 2):
|
2008-04-20 16:01:04 +02:00
|
|
|
gajim.interface.roster.remove_to_be_removed(self.contact.jid,
|
2006-03-28 13:52:25 +02:00
|
|
|
self.account)
|
2006-01-03 04:34:32 +01:00
|
|
|
elif typ == 'pm':
|
2006-01-06 07:59:55 +01:00
|
|
|
control.remove_contact(nick)
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2006-01-03 05:05:28 +01:00
|
|
|
def show_bigger_avatar(self, small_avatar):
|
|
|
|
'''resizes the avatar, if needed, so it has at max half the screen size
|
|
|
|
and shows it'''
|
2006-07-17 14:48:07 +02:00
|
|
|
if not small_avatar.window:
|
|
|
|
# Tab has been closed since we hovered the avatar
|
|
|
|
return
|
2006-03-18 10:22:27 +01:00
|
|
|
is_fake = False
|
|
|
|
if self.type_id == message_control.TYPE_PM:
|
|
|
|
is_fake = True
|
2006-03-18 10:27:41 +01:00
|
|
|
avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(
|
|
|
|
self.contact.jid, is_fake)
|
2006-03-18 10:22:27 +01:00
|
|
|
if avatar_pixbuf in ('ask', None):
|
2006-01-03 05:05:28 +01:00
|
|
|
return
|
2006-02-21 13:59:29 +01:00
|
|
|
# Hide the small avatar
|
2006-03-10 14:54:04 +01:00
|
|
|
# this code hides the small avatar when we show a bigger one in case
|
|
|
|
# the avatar has a transparency hole in the middle
|
|
|
|
# so when we show the big one we avoid seeing the small one behind.
|
|
|
|
# It's why I set it transparent.
|
2006-02-21 13:59:29 +01:00
|
|
|
image = self.xml.get_widget('avatar_image')
|
|
|
|
pixbuf = image.get_pixbuf()
|
2006-07-18 23:14:07 +02:00
|
|
|
pixbuf.fill(0xffffff00L) # RGBA
|
2006-02-21 13:59:29 +01:00
|
|
|
image.queue_draw()
|
|
|
|
|
2006-01-03 05:05:28 +01:00
|
|
|
screen_w = gtk.gdk.screen_width()
|
|
|
|
screen_h = gtk.gdk.screen_height()
|
|
|
|
avatar_w = avatar_pixbuf.get_width()
|
|
|
|
avatar_h = avatar_pixbuf.get_height()
|
|
|
|
half_scr_w = screen_w / 2
|
|
|
|
half_scr_h = screen_h / 2
|
|
|
|
if avatar_w > half_scr_w:
|
|
|
|
avatar_w = half_scr_w
|
|
|
|
if avatar_h > half_scr_h:
|
|
|
|
avatar_h = half_scr_h
|
|
|
|
window = gtk.Window(gtk.WINDOW_POPUP)
|
|
|
|
self.bigger_avatar_window = window
|
|
|
|
pixmap, mask = avatar_pixbuf.render_pixmap_and_mask()
|
|
|
|
window.set_size_request(avatar_w, avatar_h)
|
|
|
|
# we should make the cursor visible
|
|
|
|
# gtk+ doesn't make use of the motion notify on gtkwindow by default
|
|
|
|
# so this line adds that
|
|
|
|
window.set_events(gtk.gdk.POINTER_MOTION_MASK)
|
|
|
|
window.set_app_paintable(True)
|
2009-04-27 21:28:53 +02:00
|
|
|
window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_TOOLTIP)
|
2008-05-04 02:24:27 +02:00
|
|
|
|
2006-01-03 05:05:28 +01:00
|
|
|
window.realize()
|
|
|
|
window.window.set_back_pixmap(pixmap, False) # make it transparent
|
|
|
|
window.window.shape_combine_mask(mask, 0, 0)
|
|
|
|
|
2008-05-04 02:24:27 +02:00
|
|
|
# make the bigger avatar window show up centered
|
2006-01-03 05:05:28 +01:00
|
|
|
x0, y0 = small_avatar.window.get_origin()
|
|
|
|
x0 += small_avatar.allocation.x
|
|
|
|
y0 += small_avatar.allocation.y
|
|
|
|
center_x= x0 + (small_avatar.allocation.width / 2)
|
|
|
|
center_y = y0 + (small_avatar.allocation.height / 2)
|
2008-05-04 02:24:27 +02:00
|
|
|
pos_x, pos_y = center_x - (avatar_w / 2), center_y - (avatar_h / 2)
|
2006-01-03 05:05:28 +01:00
|
|
|
window.move(pos_x, pos_y)
|
|
|
|
# make the cursor invisible so we can see the image
|
|
|
|
invisible_cursor = gtkgui_helpers.get_invisible_cursor()
|
|
|
|
window.window.set_cursor(invisible_cursor)
|
|
|
|
|
|
|
|
# we should hide the window
|
|
|
|
window.connect('leave_notify_event',
|
|
|
|
self._on_window_avatar_leave_notify_event)
|
|
|
|
window.connect('motion-notify-event',
|
|
|
|
self._on_window_motion_notify_event)
|
|
|
|
|
|
|
|
window.show_all()
|
|
|
|
|
|
|
|
def _on_window_avatar_leave_notify_event(self, widget, event):
|
|
|
|
'''we just left the popup window that holds avatar'''
|
|
|
|
self.bigger_avatar_window.destroy()
|
2006-06-14 16:54:23 +02:00
|
|
|
self.bigger_avatar_window = None
|
2006-02-21 13:59:29 +01:00
|
|
|
# Re-show the small avatar
|
|
|
|
self.show_avatar()
|
2006-01-03 05:05:28 +01:00
|
|
|
|
|
|
|
def _on_window_motion_notify_event(self, widget, event):
|
|
|
|
'''we just moved the mouse so show the cursor'''
|
|
|
|
cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
|
|
|
|
self.bigger_avatar_window.window.set_cursor(cursor)
|
|
|
|
|
2006-01-03 05:44:56 +01:00
|
|
|
def _on_send_file_menuitem_activate(self, widget):
|
2009-04-07 19:07:04 +02:00
|
|
|
self._on_send_file()
|
2006-01-03 05:44:56 +01:00
|
|
|
|
|
|
|
def _on_add_to_roster_menuitem_activate(self, widget):
|
|
|
|
dialogs.AddNewContactWindow(self.account, self.contact.jid)
|
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_contact_information_menuitem_activate(self, widget):
|
2006-01-03 05:44:56 +01:00
|
|
|
gajim.interface.roster.on_info(widget, self.contact, self.account)
|
|
|
|
|
2006-01-12 03:36:06 +01:00
|
|
|
def _on_toggle_gpg_menuitem_activate(self, widget):
|
2008-05-13 03:59:10 +02:00
|
|
|
self._toggle_gpg()
|
2007-12-08 09:51:10 +01:00
|
|
|
|
2007-08-22 01:13:03 +02:00
|
|
|
def _on_convert_to_gc_menuitem_activate(self, widget):
|
|
|
|
'''user want to invite some friends to chat'''
|
|
|
|
dialogs.TransformChatToMUC(self.account, [self.contact.jid])
|
|
|
|
|
2007-06-08 21:42:02 +02:00
|
|
|
def _on_toggle_e2e_menuitem_activate(self, widget):
|
2007-07-03 20:00:09 +02:00
|
|
|
if self.session and self.session.enable_encryption:
|
2008-11-23 05:52:55 +01:00
|
|
|
# e2e was enabled, disable it
|
2007-06-29 06:12:08 +02:00
|
|
|
jid = str(self.session.jid)
|
2008-06-29 17:57:07 +02:00
|
|
|
thread_id = self.session.thread_id
|
2007-06-29 06:12:08 +02:00
|
|
|
|
2008-06-29 17:57:07 +02:00
|
|
|
self.session.terminate_e2e()
|
2007-08-20 10:16:48 +02:00
|
|
|
|
2008-06-29 17:57:07 +02:00
|
|
|
gajim.connections[self.account].delete_session(jid, thread_id)
|
2008-11-23 05:52:55 +01:00
|
|
|
|
|
|
|
# presumably the user had a good reason to shut it off, so
|
|
|
|
# disable autonegotiation too
|
|
|
|
self.no_autonegotiation = True
|
2007-06-08 21:42:02 +02:00
|
|
|
else:
|
2008-07-14 02:26:14 +02:00
|
|
|
self.begin_e2e_negotiation()
|
|
|
|
|
|
|
|
def begin_e2e_negotiation(self):
|
2008-10-12 02:51:24 +02:00
|
|
|
self.no_autonegotiation = True
|
|
|
|
|
2008-07-14 02:26:14 +02:00
|
|
|
if not self.session:
|
|
|
|
fjid = self.contact.get_full_jid()
|
2008-10-25 21:48:01 +02:00
|
|
|
new_sess = gajim.connections[self.account].make_new_session(fjid, type_=self.type_id)
|
2008-07-14 02:26:14 +02:00
|
|
|
self.set_session(new_sess)
|
2007-07-03 20:00:09 +02:00
|
|
|
|
2008-07-14 02:26:14 +02:00
|
|
|
self.session.negotiate_e2e(False)
|
2006-02-04 03:52:36 +01:00
|
|
|
|
|
|
|
def got_connected(self):
|
|
|
|
ChatControlBase.got_connected(self)
|
|
|
|
# Refreshing contact
|
2006-04-20 18:57:43 +02:00
|
|
|
contact = gajim.contacts.get_contact_with_highest_priority(
|
2006-02-05 19:42:41 +01:00
|
|
|
self.account, self.contact.jid)
|
2006-04-20 18:57:43 +02:00
|
|
|
if isinstance(contact, GC_Contact):
|
2009-11-05 16:25:13 +01:00
|
|
|
contact = contact.as_contact()
|
2006-04-20 18:57:43 +02:00
|
|
|
if contact:
|
|
|
|
self.contact = contact
|
2006-02-04 03:52:36 +01:00
|
|
|
self.draw_banner()
|
2008-07-19 20:31:45 +02:00
|
|
|
|
|
|
|
def update_status_display(self, name, uf_show, status):
|
|
|
|
'''print the contact's status and update the status/GPG image'''
|
|
|
|
self.update_ui()
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
|
2008-08-01 11:30:36 +02:00
|
|
|
self.print_conversation(_('%(name)s is now %(status)s') % {'name': name,
|
|
|
|
'status': uf_show}, 'status')
|
2008-07-19 20:31:45 +02:00
|
|
|
|
|
|
|
if status:
|
2008-07-19 22:41:53 +02:00
|
|
|
self.print_conversation(' (', 'status', simple=True)
|
|
|
|
self.print_conversation('%s' % (status), 'status', simple=True)
|
|
|
|
self.print_conversation(')', 'status', simple=True)
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-07-30 16:00:21 +02:00
|
|
|
# vim: se ts=3:
|