2005-07-18 17:42:29 +02:00
|
|
|
## tabbed_chat_window.py
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
|
|
|
## Gajim Team:
|
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
import pango
|
|
|
|
import gobject
|
|
|
|
import time
|
2005-06-09 22:35:44 +02:00
|
|
|
import urllib
|
|
|
|
import base64
|
2005-08-13 03:25:43 +02:00
|
|
|
import os
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-04-14 19:07:55 +02:00
|
|
|
import dialogs
|
|
|
|
import chat
|
2005-07-21 16:56:39 +02:00
|
|
|
import gtkgui_helpers
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-05-20 17:58:23 +02:00
|
|
|
from common import gajim
|
|
|
|
from common import helpers
|
2005-03-11 18:57:35 +01:00
|
|
|
from common import i18n
|
|
|
|
|
|
|
|
_ = i18n._
|
|
|
|
APP = i18n.APP
|
|
|
|
gtk.glade.bindtextdomain(APP, i18n.DIR)
|
|
|
|
gtk.glade.textdomain(APP)
|
|
|
|
|
2005-04-22 01:20:18 +02:00
|
|
|
GTKGUI_GLADE = 'gtkgui.glade'
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-06-11 00:45:50 +02:00
|
|
|
class TabbedChatWindow(chat.Chat):
|
2005-03-11 18:57:35 +01:00
|
|
|
"""Class for tabbed chat window"""
|
|
|
|
def __init__(self, user, plugin, account):
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.__init__(self, plugin, account, 'tabbed_chat_window')
|
2005-07-21 00:14:40 +02:00
|
|
|
self.contacts = {}
|
2005-07-19 23:40:08 +02:00
|
|
|
# keep check for possible paused timeouts per jid
|
|
|
|
self.possible_paused_timeout_id = {}
|
|
|
|
# keep check for possible inactive timeouts per jid
|
|
|
|
self.possible_inactive_timeout_id = {}
|
2005-08-14 00:16:50 +02:00
|
|
|
self.TARGET_TYPE_URI_LIST = 80
|
|
|
|
self.dnd_list = [ ( 'text/uri-list', 0, self.TARGET_TYPE_URI_LIST ) ]
|
2005-08-26 14:55:17 +02:00
|
|
|
self.new_tab(user)
|
2005-03-11 18:57:35 +01:00
|
|
|
self.show_title()
|
2005-09-04 18:57:09 +02:00
|
|
|
|
2005-08-26 14:55:17 +02:00
|
|
|
# NOTE: if it not a window event, connect in new_tab function
|
2005-08-07 17:19:21 +02:00
|
|
|
signal_dict = {
|
|
|
|
'on_tabbed_chat_window_destroy': self.on_tabbed_chat_window_destroy,
|
|
|
|
'on_tabbed_chat_window_delete_event': self.on_tabbed_chat_window_delete_event,
|
|
|
|
'on_tabbed_chat_window_focus_in_event': self.on_tabbed_chat_window_focus_in_event,
|
|
|
|
'on_tabbed_chat_window_focus_out_event': self.on_tabbed_chat_window_focus_out_event,
|
|
|
|
'on_chat_notebook_key_press_event': self.on_chat_notebook_key_press_event,
|
|
|
|
'on_chat_notebook_switch_page': self.on_chat_notebook_switch_page, # in chat.py
|
|
|
|
'on_tabbed_chat_window_motion_notify_event': self.on_tabbed_chat_window_motion_notify_event,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.xml.signal_autoconnect(signal_dict)
|
|
|
|
|
2005-06-13 14:20:34 +02:00
|
|
|
|
|
|
|
if gajim.config.get('saveposition'):
|
2005-07-19 16:38:58 +02:00
|
|
|
# get window position and size from config
|
2005-08-28 12:57:08 +02:00
|
|
|
gtkgui_helpers.move_window(self.window, gajim.config.get('chat-x-position'),
|
|
|
|
gajim.config.get('chat-y-position'))
|
2005-08-28 13:02:59 +02:00
|
|
|
gtkgui_helpers.resize_window(self.window, gajim.config.get('chat-width'),
|
2005-06-13 14:20:34 +02:00
|
|
|
gajim.config.get('chat-height'))
|
|
|
|
|
2005-07-24 00:37:18 +02:00
|
|
|
# gtk+ doesn't make use of the motion notify on gtkwindow by default
|
|
|
|
# so this line adds that
|
|
|
|
self.window.set_events(gtk.gdk.POINTER_MOTION_MASK)
|
|
|
|
|
2005-04-27 15:50:13 +02:00
|
|
|
self.window.show_all()
|
2005-08-07 17:19:21 +02:00
|
|
|
|
2005-04-28 16:38:36 +02:00
|
|
|
def save_var(self, jid):
|
|
|
|
'''return the specific variable of a jid, like gpg_enabled
|
|
|
|
the return value have to be compatible with wthe one given to load_var'''
|
|
|
|
gpg_enabled = self.xmls[jid].get_widget('gpg_togglebutton').get_active()
|
|
|
|
return {'gpg_enabled': gpg_enabled}
|
|
|
|
|
|
|
|
def load_var(self, jid, var):
|
|
|
|
if not self.xmls.has_key(jid):
|
|
|
|
return
|
2005-05-04 18:22:07 +02:00
|
|
|
self.xmls[jid].get_widget('gpg_togglebutton').set_active(
|
2005-04-28 16:38:36 +02:00
|
|
|
var['gpg_enabled'])
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-07-22 00:38:22 +02:00
|
|
|
def on_tabbed_chat_window_motion_notify_event(self, widget, event):
|
2005-07-24 00:37:18 +02:00
|
|
|
'''it gets called no matter if it is the active window or not'''
|
|
|
|
if widget.get_property('has-toplevel-focus'):
|
|
|
|
# change chatstate only if window is the active one
|
2005-07-22 00:38:22 +02:00
|
|
|
self.mouse_over_in_last_5_secs = True
|
|
|
|
self.mouse_over_in_last_30_secs = True
|
|
|
|
|
2005-08-13 03:25:43 +02:00
|
|
|
def on_drag_data_received(self, widget, context, x, y, selection, target_type,
|
|
|
|
timestamp, contact):
|
2005-08-14 00:16:50 +02:00
|
|
|
if target_type == self.TARGET_TYPE_URI_LIST:
|
|
|
|
uri = selection.data.strip()
|
2005-08-17 18:47:40 +02:00
|
|
|
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?
|
|
|
|
self.plugin.windows['file_transfers'].send_file(self.account,
|
|
|
|
contact, path)
|
2005-08-13 03:25:43 +02:00
|
|
|
|
2005-07-06 15:07:11 +02:00
|
|
|
def draw_widgets(self, contact):
|
2005-03-11 18:57:35 +01:00
|
|
|
"""draw the widgets in a tab (status_image, contact_button ...)
|
2005-07-06 15:07:11 +02:00
|
|
|
according to the the information in the contact variable"""
|
|
|
|
jid = contact.jid
|
2005-05-03 18:37:59 +02:00
|
|
|
self.set_state_image(jid)
|
2005-03-11 18:57:35 +01:00
|
|
|
contact_button = self.xmls[jid].get_widget('contact_button')
|
2005-04-17 18:06:40 +02:00
|
|
|
contact_button.set_use_underline(False)
|
2005-07-05 23:40:40 +02:00
|
|
|
tb = self.xmls[jid].get_widget('gpg_togglebutton')
|
2005-07-06 15:31:55 +02:00
|
|
|
if contact.keyID: # we can do gpg
|
2005-07-05 23:40:40 +02:00
|
|
|
tb.set_sensitive(True)
|
2005-07-19 00:41:11 +02:00
|
|
|
tt = _('OpenPGP Encryption')
|
2005-07-06 15:07:11 +02:00
|
|
|
else:
|
|
|
|
tb.set_sensitive(False)
|
2005-08-17 14:17:09 +02:00
|
|
|
#we talk about a contact here
|
2005-07-19 01:21:22 +02:00
|
|
|
tt = _('%s has not broadcasted an OpenPGP key nor you have assigned one') % contact.name
|
2005-07-05 23:40:40 +02:00
|
|
|
tip = gtk.Tooltips()
|
|
|
|
tip.set_tip(self.xmls[jid].get_widget('gpg_eventbox'), tt)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-06-07 23:28:21 +02:00
|
|
|
# add the fat line at the top
|
2005-07-21 16:56:39 +02:00
|
|
|
self.draw_name_banner(contact)
|
2005-06-07 23:28:21 +02:00
|
|
|
|
2005-07-21 16:56:39 +02:00
|
|
|
def draw_name_banner(self, contact, chatstate = None):
|
2005-06-07 23:28:21 +02:00
|
|
|
'''Draw the fat line at the top of the window that
|
|
|
|
houses the status icon, name, jid, and avatar'''
|
|
|
|
# this is the text for the big brown bar
|
2005-07-21 16:56:39 +02:00
|
|
|
# some chars need to be escaped..
|
2005-07-22 01:19:33 +02:00
|
|
|
jid = contact.jid
|
|
|
|
banner_name_label = self.xmls[jid].get_widget('banner_name_label')
|
|
|
|
|
2005-07-21 23:39:47 +02:00
|
|
|
name = gtkgui_helpers.escape_for_pango_markup(contact.name)
|
2005-07-22 00:42:30 +02:00
|
|
|
|
|
|
|
status = contact.status
|
2005-09-03 14:43:12 +02:00
|
|
|
|
|
|
|
if status is not None:
|
2005-07-22 01:19:33 +02:00
|
|
|
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
2005-08-08 17:44:22 +02:00
|
|
|
status = gtkgui_helpers.reduce_chars_newlines(status, 0, 2)
|
|
|
|
|
2005-07-22 00:42:30 +02:00
|
|
|
status = gtkgui_helpers.escape_for_pango_markup(status)
|
2005-07-21 19:54:58 +02:00
|
|
|
|
2005-07-18 17:42:29 +02:00
|
|
|
#FIXME: uncomment me when we support sending messages to specific resource
|
2005-06-23 21:35:47 +02:00
|
|
|
# composing full jid
|
2005-07-18 17:42:29 +02:00
|
|
|
#fulljid = jid
|
2005-07-21 00:14:40 +02:00
|
|
|
#if self.contacts[jid].resource:
|
|
|
|
# fulljid += '/' + self.contacts[jid].resource
|
2005-07-18 17:42:29 +02:00
|
|
|
#label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
|
|
|
|
# % (name, fulljid)
|
|
|
|
|
2005-08-07 22:58:44 +02:00
|
|
|
|
|
|
|
st = gajim.config.get('chat_state_notifications')
|
|
|
|
if chatstate and st in ('composing_only', 'all'):
|
|
|
|
if st == 'all':
|
|
|
|
chatstate = helpers.get_uf_chatstate(chatstate)
|
|
|
|
else: # 'composing_only'
|
|
|
|
if chatstate in ('composing', 'paused'):
|
|
|
|
# only print composing, paused
|
|
|
|
chatstate = helpers.get_uf_chatstate(chatstate)
|
|
|
|
else:
|
|
|
|
chatstate = ''
|
2005-07-21 20:05:04 +02:00
|
|
|
label_text = \
|
2005-07-22 16:30:35 +02:00
|
|
|
'<span weight="heavy" size="x-large">%s</span> %s' % (name, chatstate)
|
2005-07-21 16:56:39 +02:00
|
|
|
else:
|
2005-07-21 20:05:04 +02:00
|
|
|
label_text = '<span weight="heavy" size="x-large">%s</span>' % name
|
|
|
|
|
|
|
|
if status is not None:
|
|
|
|
label_text += '\n%s' % status
|
2005-06-07 23:28:21 +02:00
|
|
|
|
|
|
|
# setup the label that holds name and jid
|
|
|
|
banner_name_label.set_markup(label_text)
|
2005-06-14 00:11:09 +02:00
|
|
|
self.paint_banner(jid)
|
2005-06-07 23:28:21 +02:00
|
|
|
|
2005-06-09 22:35:44 +02:00
|
|
|
def set_avatar(self, vcard):
|
|
|
|
if not vcard.has_key('PHOTO'):
|
|
|
|
return
|
2005-06-10 15:46:41 +02:00
|
|
|
if type(vcard['PHOTO']) != type({}):
|
|
|
|
return
|
2005-06-09 22:35:44 +02:00
|
|
|
img_decoded = None
|
|
|
|
if vcard['PHOTO'].has_key('BINVAL'):
|
|
|
|
try:
|
|
|
|
img_decoded = base64.decodestring(vcard['PHOTO']['BINVAL'])
|
|
|
|
except:
|
|
|
|
pass
|
2005-07-20 23:11:19 +02:00
|
|
|
elif vcard['PHOTO'].has_key('EXTVAL'):
|
|
|
|
url = vcard['PHOTO']['EXTVAL']
|
2005-06-09 22:35:44 +02:00
|
|
|
try:
|
|
|
|
fd = urllib.urlopen(url)
|
|
|
|
img_decoded = fd.read()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if img_decoded:
|
|
|
|
pixbufloader = gtk.gdk.PixbufLoader()
|
2005-08-09 01:06:48 +02:00
|
|
|
try:
|
|
|
|
pixbufloader.write(img_decoded)
|
|
|
|
pixbuf = pixbufloader.get_pixbuf()
|
|
|
|
pixbufloader.close()
|
|
|
|
|
2005-09-01 15:58:20 +02:00
|
|
|
w = gajim.config.get('avatar_width')
|
|
|
|
h = gajim.config.get('avatar_height')
|
|
|
|
scaled_buf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_HYPER)
|
2005-08-09 01:06:48 +02:00
|
|
|
x = None
|
|
|
|
if self.xmls.has_key(vcard['jid']):
|
|
|
|
x = self.xmls[vcard['jid']]
|
|
|
|
# it can be xmls[jid/resource] if it's a vcard from pm
|
|
|
|
elif self.xmls.has_key(vcard['jid'] + '/' + vcard['resource']):
|
|
|
|
x = self.xmls[vcard['jid'] + '/' + vcard['resource']]
|
|
|
|
image = x.get_widget('avatar_image')
|
|
|
|
image.set_from_pixbuf(scaled_buf)
|
|
|
|
image.show_all()
|
2005-08-26 21:54:51 +02:00
|
|
|
# we may get "unknown image format" and/or something like pixbuf can be None
|
|
|
|
except (gobject.GError, AttributeError):
|
2005-08-09 01:06:48 +02:00
|
|
|
pass
|
2005-05-04 18:22:07 +02:00
|
|
|
|
2005-04-23 03:37:05 +02:00
|
|
|
def set_state_image(self, jid):
|
2005-03-31 21:21:48 +02:00
|
|
|
prio = 0
|
2005-07-18 23:08:31 +02:00
|
|
|
if gajim.contacts[self.account].has_key(jid):
|
2005-07-21 00:15:35 +02:00
|
|
|
contacts_list = gajim.contacts[self.account][jid]
|
2005-06-07 18:52:24 +02:00
|
|
|
else:
|
2005-07-21 00:15:35 +02:00
|
|
|
contacts_list = [self.contacts[jid]]
|
2005-08-07 22:58:44 +02:00
|
|
|
|
2005-07-21 00:15:35 +02:00
|
|
|
user = contacts_list[0]
|
2005-04-23 03:37:05 +02:00
|
|
|
show = user.show
|
|
|
|
jid = user.jid
|
2005-05-27 17:47:15 +02:00
|
|
|
keyID = user.keyID
|
2005-08-07 22:58:44 +02:00
|
|
|
|
2005-07-21 00:15:35 +02:00
|
|
|
for u in contacts_list:
|
2005-03-31 21:21:48 +02:00
|
|
|
if u.priority > prio:
|
|
|
|
prio = u.priority
|
2005-04-23 03:37:05 +02:00
|
|
|
show = u.show
|
2005-05-27 17:12:58 +02:00
|
|
|
keyID = u.keyID
|
2005-05-03 18:37:59 +02:00
|
|
|
child = self.childs[jid]
|
2005-08-04 11:42:34 +02:00
|
|
|
hb = self.notebook.get_tab_label(child).get_children()[0]
|
|
|
|
status_image = hb.get_children()[0]
|
2005-04-23 03:37:05 +02:00
|
|
|
state_images = self.plugin.roster.get_appropriate_state_images(jid)
|
2005-09-05 01:30:40 +02:00
|
|
|
# If messages are unread show the 'message' image
|
|
|
|
if self.nb_unread[jid]:
|
|
|
|
show = 'message'
|
2005-04-23 03:37:05 +02:00
|
|
|
image = state_images[show]
|
2005-06-07 23:28:21 +02:00
|
|
|
banner_status_image = self.xmls[jid].get_widget('banner_status_image')
|
2005-08-07 22:58:44 +02:00
|
|
|
|
2005-05-27 17:12:58 +02:00
|
|
|
if keyID:
|
|
|
|
self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(False)
|
2005-08-07 22:58:44 +02:00
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
if image.get_storage_type() == gtk.IMAGE_ANIMATION:
|
2005-06-07 23:28:21 +02:00
|
|
|
banner_status_image.set_from_animation(image.get_animation())
|
2005-05-03 18:37:59 +02:00
|
|
|
status_image.set_from_animation(image.get_animation())
|
2005-03-11 18:57:35 +01:00
|
|
|
elif image.get_storage_type() == gtk.IMAGE_PIXBUF:
|
2005-06-11 15:45:48 +02:00
|
|
|
# make a copy because one will be scaled, one not (tab icon)
|
2005-06-07 23:28:21 +02:00
|
|
|
pix = image.get_pixbuf()
|
|
|
|
scaled_pix = pix.scale_simple(32, 32, gtk.gdk.INTERP_BILINEAR)
|
|
|
|
banner_status_image.set_from_pixbuf(scaled_pix)
|
|
|
|
status_image.set_from_pixbuf(pix)
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def on_tabbed_chat_window_delete_event(self, widget, event):
|
2005-08-07 17:19:21 +02:00
|
|
|
'''close window'''
|
2005-07-21 00:14:40 +02:00
|
|
|
for jid in self.contacts:
|
2005-07-03 17:27:41 +02:00
|
|
|
if time.time() - gajim.last_message_time[self.account][jid] < 2:
|
|
|
|
# 2 seconds
|
2005-06-10 23:14:16 +02:00
|
|
|
dialog = dialogs.ConfirmationDialog(
|
2005-08-17 14:17:09 +02:00
|
|
|
#%s is being replaced in the code with JID
|
2005-06-07 22:24:22 +02:00
|
|
|
_('You just received a new message from "%s"' % jid),
|
2005-08-24 14:38:41 +02:00
|
|
|
_('If you close this tab and you have history disabled, this message will be lost.'))
|
2005-06-07 03:10:24 +02:00
|
|
|
if dialog.get_response() != gtk.RESPONSE_OK:
|
2005-03-11 18:57:35 +01:00
|
|
|
return True #stop the propagation of the event
|
|
|
|
|
2005-06-13 14:20:34 +02:00
|
|
|
if gajim.config.get('saveposition'):
|
2005-07-19 16:38:58 +02:00
|
|
|
# save the window size and position
|
2005-06-13 14:20:34 +02:00
|
|
|
x, y = self.window.get_position()
|
|
|
|
gajim.config.set('chat-x-position', x)
|
|
|
|
gajim.config.set('chat-y-position', y)
|
|
|
|
width, height = self.window.get_size()
|
|
|
|
gajim.config.set('chat-width', width)
|
|
|
|
gajim.config.set('chat-height', height)
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def on_tabbed_chat_window_destroy(self, widget):
|
2005-07-19 17:39:24 +02:00
|
|
|
#clean self.plugin.windows[self.account]['chats']
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.on_window_destroy(self, widget, 'chats')
|
2005-03-12 19:12:15 +01:00
|
|
|
|
|
|
|
def on_tabbed_chat_window_focus_in_event(self, widget, event):
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.on_chat_window_focus_in_event(self, widget, event)
|
2005-08-08 01:04:36 +02:00
|
|
|
# on focus in, send 'active' chatstate to current tab
|
2005-07-19 16:38:58 +02:00
|
|
|
self.send_chatstate('active')
|
|
|
|
|
|
|
|
def on_tabbed_chat_window_focus_out_event(self, widget, event):
|
2005-07-20 17:57:55 +02:00
|
|
|
'''catch focus out and minimized and send inactive chatstate;
|
|
|
|
minimize action also focuses out first so it's catched here'''
|
|
|
|
window_state = widget.window.get_state()
|
|
|
|
if window_state is None:
|
|
|
|
return
|
2005-07-23 22:48:08 +02:00
|
|
|
|
2005-09-05 02:24:26 +02:00
|
|
|
# focus-out is also emitted by showing context menu
|
|
|
|
# so check to see if we're really not paying attention to window/tab
|
|
|
|
# NOTE: if the user changes tab, switch-tab sends inactive to the tab
|
|
|
|
# we are leaving so we just send to active tab here
|
|
|
|
if self.popup_is_shown is False and gajim.config.get('chat_state_send_inactive_on_focus_out'):
|
|
|
|
# we are outside of the window
|
|
|
|
# so no context menu, so send 'inactive' to active tab
|
|
|
|
self.send_chatstate('inactive')
|
|
|
|
|
2005-03-12 22:30:50 +01:00
|
|
|
def on_chat_notebook_key_press_event(self, widget, event):
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.on_chat_notebook_key_press_event(self, widget, event)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-08-04 14:46:31 +02:00
|
|
|
def on_send_file_menuitem_activate(self, widget):
|
|
|
|
jid = self.get_active_jid()
|
|
|
|
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
|
|
|
|
self.plugin.windows['file_transfers'].show_file_send_request(
|
|
|
|
self.account, contact)
|
|
|
|
|
|
|
|
def on_add_to_roster_menuitem_activate(self, widget):
|
|
|
|
jid = self.get_active_jid()
|
|
|
|
dialogs.AddNewContactWindow(self.plugin, self.account, jid)
|
|
|
|
|
2005-06-07 23:28:21 +02:00
|
|
|
def on_send_button_clicked(self, widget):
|
|
|
|
"""When send button is pressed: send the current message"""
|
|
|
|
jid = self.get_active_jid()
|
|
|
|
message_textview = self.xmls[jid].get_widget('message_textview')
|
|
|
|
message_buffer = message_textview.get_buffer()
|
|
|
|
start_iter = message_buffer.get_start_iter()
|
|
|
|
end_iter = message_buffer.get_end_iter()
|
2005-08-26 02:52:44 +02:00
|
|
|
message = message_buffer.get_text(start_iter, end_iter, 0).decode('utf-8')
|
2005-06-07 23:28:21 +02:00
|
|
|
|
|
|
|
# send the message
|
|
|
|
self.send_message(message)
|
|
|
|
|
2005-07-19 19:11:33 +02:00
|
|
|
message_buffer.set_text('')
|
2005-06-07 23:28:21 +02:00
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def remove_tab(self, jid):
|
2005-07-03 17:27:41 +02:00
|
|
|
if time.time() - gajim.last_message_time[self.account][jid] < 2:
|
2005-06-10 23:14:16 +02:00
|
|
|
dialog = dialogs.ConfirmationDialog(
|
2005-06-07 22:24:22 +02:00
|
|
|
_('You just received a new message from "%s"' % jid),
|
2005-08-24 14:38:41 +02:00
|
|
|
_('If you close this tab and you have history disabled, the message will be lost.'))
|
2005-06-07 03:10:24 +02:00
|
|
|
if dialog.get_response() != gtk.RESPONSE_OK:
|
2005-03-11 18:57:35 +01:00
|
|
|
return
|
|
|
|
|
2005-08-08 01:04:36 +02:00
|
|
|
# chatstates - tab is destroyed, send gone
|
2005-07-22 19:39:42 +02:00
|
|
|
self.send_chatstate('gone', jid)
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.remove_tab(self, jid, 'chats')
|
2005-08-03 13:36:00 +02:00
|
|
|
del self.contacts[jid]
|
2005-08-07 17:19:21 +02:00
|
|
|
|
2005-08-26 14:55:17 +02:00
|
|
|
def new_tab(self, contact):
|
2005-06-03 23:52:36 +02:00
|
|
|
'''when new tab is created'''
|
2005-07-19 22:17:28 +02:00
|
|
|
self.names[contact.jid] = contact.name
|
|
|
|
self.xmls[contact.jid] = gtk.glade.XML(GTKGUI_GLADE, 'chats_vbox', APP)
|
|
|
|
self.childs[contact.jid] = self.xmls[contact.jid].get_widget('chats_vbox')
|
2005-07-21 00:14:40 +02:00
|
|
|
self.contacts[contact.jid] = contact
|
2005-08-08 13:59:34 +02:00
|
|
|
|
2005-08-13 03:25:43 +02:00
|
|
|
|
|
|
|
self.childs[contact.jid].connect('drag_data_received',
|
|
|
|
self.on_drag_data_received, contact)
|
|
|
|
self.childs[contact.jid].drag_dest_set( gtk.DEST_DEFAULT_MOTION |
|
|
|
|
gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP,
|
|
|
|
self.dnd_list, gtk.gdk.ACTION_COPY)
|
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
message_textview = self.xmls[contact.jid].get_widget('message_textview')
|
|
|
|
message_tv_buffer = message_textview.get_buffer()
|
2005-09-05 01:30:40 +02:00
|
|
|
message_tv_buffer.connect('changed',
|
|
|
|
self.on_message_tv_buffer_changed, contact)
|
2005-07-02 13:06:02 +02:00
|
|
|
|
2005-07-19 22:17:28 +02:00
|
|
|
if contact.jid in gajim.encrypted_chats[self.account]:
|
|
|
|
self.xmls[contact.jid].get_widget('gpg_togglebutton').set_active(True)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-06-30 15:31:31 +02:00
|
|
|
xm = gtk.glade.XML(GTKGUI_GLADE, 'tabbed_chat_popup_menu', APP)
|
|
|
|
xm.signal_autoconnect(self)
|
|
|
|
self.tabbed_chat_popup_menu = xm.get_widget('tabbed_chat_popup_menu')
|
|
|
|
|
2005-07-19 22:17:28 +02:00
|
|
|
chat.Chat.new_tab(self, contact.jid)
|
2005-09-05 03:39:42 +02:00
|
|
|
self.redraw_tab(contact.jid)
|
2005-07-19 22:17:28 +02:00
|
|
|
self.draw_widgets(contact)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-08-08 18:57:41 +02:00
|
|
|
# restore previous conversation
|
2005-07-19 22:17:28 +02:00
|
|
|
self.restore_conversation(contact.jid)
|
2005-06-03 23:29:07 +02:00
|
|
|
|
2005-07-19 22:17:28 +02:00
|
|
|
if gajim.awaiting_messages[self.account].has_key(contact.jid):
|
|
|
|
self.read_queue(contact.jid)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-07-19 22:17:28 +02:00
|
|
|
gajim.connections[self.account].request_vcard(contact.jid)
|
|
|
|
self.childs[contact.jid].show_all()
|
2005-06-09 22:35:44 +02:00
|
|
|
|
2005-07-19 16:38:58 +02:00
|
|
|
# chatstates
|
2005-08-08 01:44:44 +02:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-07-19 22:17:28 +02:00
|
|
|
|
2005-07-19 23:40:08 +02:00
|
|
|
self.possible_paused_timeout_id[contact.jid] =\
|
|
|
|
gobject.timeout_add(5000, self.check_for_possible_paused_chatstate,
|
2005-08-08 13:59:34 +02:00
|
|
|
contact.jid)
|
2005-07-19 23:40:08 +02:00
|
|
|
self.possible_inactive_timeout_id[contact.jid] =\
|
|
|
|
gobject.timeout_add(30000, self.check_for_possible_inactive_chatstate,
|
2005-08-08 13:59:34 +02:00
|
|
|
contact.jid)
|
2005-07-19 22:17:28 +02:00
|
|
|
|
2005-07-21 16:56:39 +02:00
|
|
|
def handle_incoming_chatstate(self, account, jid, chatstate):
|
|
|
|
''' handle incoming chatstate that jid SENT TO us '''
|
2005-07-22 02:01:05 +02:00
|
|
|
contact = gajim.get_first_contact_instance_from_jid(account, jid)
|
2005-07-21 16:56:39 +02:00
|
|
|
self.draw_name_banner(contact, chatstate)
|
2005-09-05 01:30:40 +02:00
|
|
|
# update chatstate in tab for this chat
|
2005-09-05 03:39:42 +02:00
|
|
|
self.redraw_tab(contact.jid, chatstate)
|
2005-07-21 16:56:39 +02:00
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
def check_for_possible_paused_chatstate(self, jid):
|
2005-09-05 01:30:40 +02:00
|
|
|
''' did we move mouse of that window or write something in message
|
|
|
|
textview
|
2005-07-20 22:00:57 +02:00
|
|
|
in the last 5 seconds?
|
2005-08-07 01:08:05 +02:00
|
|
|
if yes we go active for mouse, composing for kbd
|
2005-07-20 17:57:55 +02:00
|
|
|
if no we go paused if we were previously composing '''
|
2005-08-08 17:38:07 +02:00
|
|
|
if jid not in self.xmls:
|
|
|
|
# the tab with jid is no longer open. stop timer
|
|
|
|
return False # stop looping
|
2005-09-05 01:30:40 +02:00
|
|
|
|
|
|
|
# FIXME: Why don't we just pass contact?
|
|
|
|
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
|
|
|
|
current_state = contact.chatstate
|
2005-08-08 13:59:34 +02:00
|
|
|
if current_state is False: # jid doesn't support chatstates
|
2005-07-19 23:40:08 +02:00
|
|
|
return False # stop looping
|
2005-07-20 01:02:58 +02:00
|
|
|
|
2005-09-05 01:30:40 +02:00
|
|
|
message_buffer = self.xmls[jid].get_widget('message_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
|
2005-08-08 13:59:34 +02:00
|
|
|
self.send_chatstate('composing', jid)
|
2005-09-05 01:30:40 +02:00
|
|
|
elif self.mouse_over_in_last_5_secs:
|
|
|
|
self.send_chatstate('active', jid)
|
2005-07-19 22:17:28 +02:00
|
|
|
else:
|
2005-09-05 01:30:40 +02:00
|
|
|
if current_state == 'composing':
|
2005-08-08 13:59:34 +02:00
|
|
|
self.send_chatstate('paused', jid) # pause composing
|
2005-07-20 00:40:54 +02:00
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
# assume no activity and let the motion-notify or 'insert-text' make them True
|
2005-08-08 01:44:44 +02:00
|
|
|
# refresh 30 seconds vars too or else it's 30 - 5 = 25 seconds!
|
2005-08-08 12:20:24 +02:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-07-19 23:40:08 +02:00
|
|
|
return True # loop forever
|
2005-07-19 22:17:28 +02:00
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
def check_for_possible_inactive_chatstate(self, jid):
|
2005-09-05 01:30:40 +02:00
|
|
|
''' did we move mouse over that window or wrote something in message
|
|
|
|
textview
|
2005-07-20 22:00:57 +02:00
|
|
|
in the last 30 seconds?
|
2005-08-07 01:08:05 +02:00
|
|
|
if yes we go active
|
|
|
|
if no we go inactive '''
|
2005-08-08 17:38:07 +02:00
|
|
|
if jid not in self.xmls:
|
|
|
|
# the tab with jid is no longer open. stop timer
|
|
|
|
return False # stop looping
|
|
|
|
|
2005-09-05 01:30:40 +02:00
|
|
|
# FIXME: Why don't we just pass contact?
|
|
|
|
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
|
|
|
|
current_state = contact.chatstate
|
2005-08-08 13:59:34 +02:00
|
|
|
if current_state is False: # jid doesn't support chatstates
|
2005-07-19 23:40:08 +02:00
|
|
|
return False # stop looping
|
2005-07-20 00:40:54 +02:00
|
|
|
|
2005-08-08 11:29:34 +02:00
|
|
|
if self.mouse_over_in_last_5_secs or self.kbd_activity_in_last_5_secs:
|
|
|
|
return True # loop forever
|
|
|
|
|
2005-07-20 17:57:55 +02:00
|
|
|
if not (self.mouse_over_in_last_30_secs or\
|
2005-09-05 01:30:40 +02:00
|
|
|
self.kbd_activity_in_last_30_secs):
|
2005-08-08 13:59:34 +02:00
|
|
|
self.send_chatstate('inactive', jid)
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
# assume no activity and let the motion-notify or 'insert-text' make them True
|
2005-08-08 01:44:44 +02:00
|
|
|
# refresh 30 seconds too or else it's 30 - 5 = 25 seconds!
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-07-20 01:46:21 +02:00
|
|
|
|
2005-07-19 23:40:08 +02:00
|
|
|
return True # loop forever
|
|
|
|
|
2005-09-05 01:30:40 +02:00
|
|
|
def on_message_tv_buffer_changed(self, textbuffer, contact):
|
|
|
|
self.kbd_activity_in_last_5_secs = True
|
|
|
|
self.kbd_activity_in_last_30_secs = True
|
2005-09-05 03:39:42 +02:00
|
|
|
if textbuffer.get_char_count():
|
|
|
|
self.send_chatstate('composing', contact.jid)
|
|
|
|
else:
|
2005-09-05 01:30:40 +02:00
|
|
|
self.send_chatstate('active', contact.jid)
|
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
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
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def on_message_textview_key_press_event(self, widget, event):
|
2005-04-12 17:30:09 +02:00
|
|
|
"""When a key is pressed:
|
2005-06-10 18:45:54 +02:00
|
|
|
if enter is pressed without the shift key, message (if not empty) is sent
|
2005-03-11 18:57:35 +01:00
|
|
|
and printed in the conversation"""
|
2005-07-24 20:41:31 +02:00
|
|
|
|
2005-03-16 20:57:32 +01:00
|
|
|
jid = self.get_active_jid()
|
2005-08-07 01:08:05 +02:00
|
|
|
conversation_textview = widget
|
|
|
|
message_buffer = conversation_textview.get_buffer()
|
2005-06-07 18:25:55 +02:00
|
|
|
start_iter, end_iter = message_buffer.get_bounds()
|
2005-08-26 02:52:44 +02:00
|
|
|
message = message_buffer.get_text(start_iter, end_iter, False).decode('utf-8')
|
2005-06-07 18:25:55 +02:00
|
|
|
|
2005-05-15 22:58:04 +02:00
|
|
|
if event.keyval == gtk.keysyms.ISO_Left_Tab: # SHIFT + TAB
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # CTRL + SHIFT + TAB
|
2005-04-12 17:30:09 +02:00
|
|
|
self.notebook.emit('key_press_event', event)
|
2005-05-15 22:58:04 +02:00
|
|
|
if event.keyval == gtk.keysyms.Tab:
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # CTRL + TAB
|
2005-04-12 17:30:09 +02:00
|
|
|
self.notebook.emit('key_press_event', event)
|
2005-03-16 20:57:32 +01:00
|
|
|
elif event.keyval == gtk.keysyms.Page_Down: # PAGE DOWN
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # CTRL + PAGE DOWN
|
|
|
|
self.notebook.emit('key_press_event', event)
|
2005-04-03 11:13:14 +02:00
|
|
|
elif event.state & gtk.gdk.SHIFT_MASK: # SHIFT + PAGE DOWN
|
2005-03-16 20:57:32 +01:00
|
|
|
conversation_textview.emit('key_press_event', event)
|
|
|
|
elif event.keyval == gtk.keysyms.Page_Up: # PAGE UP
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: # CTRL + PAGE UP
|
|
|
|
self.notebook.emit('key_press_event', event)
|
2005-04-03 11:13:14 +02:00
|
|
|
elif event.state & gtk.gdk.SHIFT_MASK: # SHIFT + PAGE UP
|
2005-03-16 20:57:32 +01:00
|
|
|
conversation_textview.emit('key_press_event', event)
|
2005-07-24 20:41:31 +02:00
|
|
|
elif event.keyval == gtk.keysyms.Up:
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: #Ctrl+UP
|
|
|
|
self.sent_messages_scroll(jid, 'up', widget.get_buffer())
|
|
|
|
return True # override the default gtk+ thing for ctrl+up
|
|
|
|
elif event.keyval == gtk.keysyms.Down:
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK: #Ctrl+Down
|
|
|
|
self.sent_messages_scroll(jid, 'down', widget.get_buffer())
|
|
|
|
return True # override the default gtk+ thing for ctrl+down
|
2005-03-18 02:28:59 +01:00
|
|
|
elif event.keyval == gtk.keysyms.Return or \
|
2005-03-18 02:25:11 +01:00
|
|
|
event.keyval == gtk.keysyms.KP_Enter: # ENTER
|
2005-06-05 22:34:17 +02:00
|
|
|
if gajim.config.get('send_on_ctrl_enter'):
|
|
|
|
if not (event.state & gtk.gdk.CONTROL_MASK):
|
|
|
|
return False
|
|
|
|
elif (event.state & gtk.gdk.SHIFT_MASK):
|
|
|
|
return False
|
2005-04-14 09:20:14 +02:00
|
|
|
if gajim.connections[self.account].connected < 2: #we are not connected
|
2005-08-07 01:08:05 +02:00
|
|
|
dialogs.ErrorDialog(_('A connection is not available'),
|
|
|
|
_('Your message can not be sent until you are connected.')).get_response()
|
2005-03-16 18:08:38 +01:00
|
|
|
return True
|
2005-06-07 23:28:21 +02:00
|
|
|
|
|
|
|
# send the message
|
|
|
|
self.send_message(message)
|
|
|
|
|
2005-07-19 19:11:33 +02:00
|
|
|
message_buffer.set_text('')
|
2005-03-16 18:08:38 +01:00
|
|
|
return True
|
2005-08-08 01:44:44 +02:00
|
|
|
|
2005-07-22 19:39:42 +02:00
|
|
|
def send_chatstate(self, state, jid = None):
|
2005-08-08 01:04:36 +02:00
|
|
|
''' sends OUR chatstate as STANDLONE chat state message (eg. no body)
|
|
|
|
to jid only if new chatstate is different
|
|
|
|
from the previous one
|
|
|
|
if jid is not specified, send to active tab'''
|
2005-07-20 17:57:55 +02:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
# 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
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-07-20 01:00:05 +02:00
|
|
|
# do not send nothing if we have chat state notifications disabled
|
2005-07-20 22:00:57 +02:00
|
|
|
# that means we won't reply to the <active/> from other peer
|
|
|
|
# so we do not broadcast jep85 capabalities
|
2005-08-07 22:58:44 +02:00
|
|
|
if gajim.config.get('chat_state_notifications') == 'disabled':
|
2005-07-20 00:59:20 +02:00
|
|
|
return
|
|
|
|
|
2005-07-22 19:39:42 +02:00
|
|
|
if jid is None:
|
|
|
|
jid = self.get_active_jid()
|
2005-07-26 17:00:34 +02:00
|
|
|
|
2005-07-22 02:34:08 +02:00
|
|
|
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-08-01 17:45:33 +02: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-07-22 02:34:08 +02:00
|
|
|
if contact.chatstate is False: # jid cannot do jep85
|
2005-07-19 16:38:58 +02:00
|
|
|
return
|
|
|
|
|
2005-08-08 01:04:36 +02:00
|
|
|
# if the new state we wanna send (state) equals
|
|
|
|
# the current state (contact.chastate) then return
|
2005-07-22 02:34:08 +02:00
|
|
|
if contact.chatstate == state:
|
2005-07-19 16:38:58 +02:00
|
|
|
return
|
|
|
|
|
2005-07-22 02:34:08 +02:00
|
|
|
if contact.chatstate is None:
|
|
|
|
# we don't know anything about jid, so return
|
2005-07-21 00:31:03 +02:00
|
|
|
# NOTE:
|
|
|
|
# send 'active', set current state to 'ask' and return is done
|
2005-08-08 13:59:34 +02:00
|
|
|
# in self.send_message() because we need REAL message (with <body>)
|
2005-09-05 01:30:40 +02:00
|
|
|
# for that procedure so return to make sure we send only once
|
|
|
|
# 'active' until we know peer supports jep85
|
2005-07-21 00:31:03 +02:00
|
|
|
return
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-07-22 02:34:08 +02:00
|
|
|
if contact.chatstate == 'ask':
|
2005-07-19 16:38:58 +02:00
|
|
|
return
|
2005-07-20 17:57:55 +02:00
|
|
|
|
|
|
|
# prevent going paused if we we were not composing (JEP violation)
|
2005-07-22 02:34:08 +02:00
|
|
|
if state == 'paused' and not contact.chatstate == 'composing':
|
2005-07-21 00:08:42 +02:00
|
|
|
gajim.connections[self.account].send_message(jid, None, None,
|
|
|
|
chatstate = 'active') # go active before
|
2005-08-08 01:04:36 +02:00
|
|
|
contact.chatstate = 'active'
|
2005-08-08 01:44:44 +02:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-07-20 17:57:55 +02:00
|
|
|
# if we're inactive prevent composing (JEP violation)
|
2005-07-22 02:34:08 +02:00
|
|
|
if contact.chatstate == 'inactive' and state == 'composing':
|
2005-07-20 22:00:57 +02:00
|
|
|
gajim.connections[self.account].send_message(jid, None, None,
|
2005-07-21 00:08:42 +02:00
|
|
|
chatstate = 'active') # go active before
|
2005-08-08 01:04:36 +02:00
|
|
|
contact.chatstate = 'active'
|
2005-08-08 01:44:44 +02:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-07-19 22:17:28 +02:00
|
|
|
gajim.connections[self.account].send_message(jid, None, None,
|
|
|
|
chatstate = state)
|
2005-08-08 01:04:36 +02:00
|
|
|
contact.chatstate = state
|
2005-08-08 01:44:44 +02:00
|
|
|
if contact.chatstate == 'active':
|
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-06-07 23:28:21 +02:00
|
|
|
def send_message(self, message):
|
2005-07-20 22:00:57 +02:00
|
|
|
"""Send the given message to the active tab"""
|
2005-06-21 22:04:23 +02:00
|
|
|
if not message:
|
|
|
|
return
|
2005-08-04 19:05:39 +02:00
|
|
|
|
2005-06-07 23:28:21 +02:00
|
|
|
jid = self.get_active_jid()
|
2005-07-22 02:34:08 +02:00
|
|
|
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
|
2005-08-04 19:05:39 +02:00
|
|
|
if contact is None:
|
|
|
|
# contact was from pm in MUC, and left the room, or we left the room
|
|
|
|
room, nick = gajim.get_room_and_nick_from_fjid(jid)
|
|
|
|
dialogs.ErrorDialog(_('Sending private message failed'),
|
2005-08-17 14:17:09 +02:00
|
|
|
#in second %s code replaces with nickname
|
2005-08-04 19:05:39 +02:00
|
|
|
_('You are no longer in room "%s" or "%s" has left.') % \
|
|
|
|
(room, nick)).get_response()
|
|
|
|
return
|
2005-08-06 22:17:45 +02:00
|
|
|
|
2005-06-07 23:28:21 +02:00
|
|
|
conversation_textview = self.xmls[jid].get_widget('conversation_textview')
|
|
|
|
message_textview = self.xmls[jid].get_widget('message_textview')
|
|
|
|
message_buffer = message_textview.get_buffer()
|
2005-07-22 02:34:08 +02:00
|
|
|
|
2005-06-07 23:28:21 +02:00
|
|
|
if message != '' or message != '\n':
|
|
|
|
self.save_sent_message(jid, message)
|
|
|
|
if message == '/clear':
|
|
|
|
self.on_clear(None, conversation_textview) # clear conversation
|
2005-06-22 21:39:19 +02:00
|
|
|
self.on_clear(None, message_textview) # clear message textview too
|
|
|
|
return True
|
|
|
|
elif message == '/compact':
|
2005-06-30 15:31:31 +02:00
|
|
|
self.set_compact_view(not self.compact_view_current_state)
|
2005-06-22 21:39:19 +02:00
|
|
|
self.on_clear(None, message_textview)
|
2005-06-07 23:28:21 +02:00
|
|
|
return True
|
|
|
|
keyID = ''
|
|
|
|
encrypted = False
|
|
|
|
if self.xmls[jid].get_widget('gpg_togglebutton').get_active():
|
2005-07-21 00:14:40 +02:00
|
|
|
keyID = self.contacts[jid].keyID
|
2005-06-07 23:28:21 +02:00
|
|
|
encrypted = True
|
2005-07-19 16:38:58 +02:00
|
|
|
|
2005-07-22 02:34:08 +02:00
|
|
|
chatstates_on = gajim.config.get(
|
2005-08-07 22:58:44 +02:00
|
|
|
'chat_state_notifications') != 'disabled'
|
2005-07-21 00:31:03 +02:00
|
|
|
|
2005-07-21 00:08:42 +02:00
|
|
|
chatstate_to_send = None
|
2005-07-22 02:34:08 +02:00
|
|
|
|
2005-08-01 23:59:34 +02:00
|
|
|
if chatstates_on and contact is not None:
|
2005-07-22 02:34:08 +02:00
|
|
|
if contact.chatstate is None:
|
2005-07-21 00:31:03 +02: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
|
2005-07-20 22:00:57 +02:00
|
|
|
chatstate_to_send = 'active'
|
2005-07-22 02:34:08 +02:00
|
|
|
contact.chatstate = 'ask' # pseudo state
|
2005-07-20 22:00:57 +02:00
|
|
|
|
2005-08-08 13:59:34 +02:00
|
|
|
# if peer supports jep85 and we are not 'ask', send 'active'
|
|
|
|
# NOTE: first active and 'ask' is set in gajim.py
|
|
|
|
elif contact.chatstate not in (False, 'ask'):
|
2005-07-20 22:00:57 +02:00
|
|
|
#send active chatstate on every message (as JEP says)
|
|
|
|
chatstate_to_send = 'active'
|
2005-08-08 01:34:02 +02:00
|
|
|
contact.chatstate = 'active'
|
2005-08-08 13:59:34 +02:00
|
|
|
|
|
|
|
# refresh timers
|
|
|
|
# avoid sending composing in less than 5 seconds
|
|
|
|
# if we just send a message
|
|
|
|
gobject.source_remove(self.possible_paused_timeout_id[jid])
|
|
|
|
gobject.source_remove(self.possible_inactive_timeout_id[jid])
|
|
|
|
self.possible_paused_timeout_id[jid] =\
|
|
|
|
gobject.timeout_add(5000, self.check_for_possible_paused_chatstate,
|
|
|
|
jid)
|
|
|
|
self.possible_inactive_timeout_id[jid] =\
|
|
|
|
gobject.timeout_add(30000, self.check_for_possible_inactive_chatstate,
|
|
|
|
jid)
|
2005-08-08 01:44:44 +02:00
|
|
|
self.reset_kbd_mouse_timeout_vars()
|
2005-07-19 22:17:28 +02:00
|
|
|
|
2005-07-20 22:00:57 +02:00
|
|
|
gajim.connections[self.account].send_message(jid, message, keyID,
|
|
|
|
chatstate = chatstate_to_send)
|
2005-07-21 00:08:42 +02:00
|
|
|
|
2005-07-19 19:11:33 +02:00
|
|
|
message_buffer.set_text('')
|
2005-06-07 23:28:21 +02:00
|
|
|
self.print_conversation(message, jid, jid, encrypted = encrypted)
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def on_contact_button_clicked(self, widget):
|
|
|
|
jid = self.get_active_jid()
|
2005-07-21 00:14:40 +02:00
|
|
|
contact = self.contacts[jid]
|
2005-07-20 00:40:54 +02:00
|
|
|
self.plugin.roster.on_info(widget, contact, self.account)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def read_queue(self, jid):
|
|
|
|
"""read queue and print messages containted in it"""
|
2005-07-18 23:08:31 +02:00
|
|
|
l = gajim.awaiting_messages[self.account][jid]
|
2005-07-21 00:14:40 +02:00
|
|
|
user = self.contacts[jid]
|
2005-06-08 12:02:50 +02:00
|
|
|
for event in l:
|
2005-05-30 12:41:55 +02:00
|
|
|
self.print_conversation(event[0], jid, tim = event[1],
|
2005-07-22 12:29:54 +02:00
|
|
|
encrypted = event[2], contact='print_queue')
|
2005-03-11 18:57:35 +01:00
|
|
|
self.plugin.roster.nb_unread -= 1
|
|
|
|
self.plugin.roster.show_title()
|
2005-07-18 23:08:31 +02:00
|
|
|
del gajim.awaiting_messages[self.account][jid]
|
2005-04-23 02:37:51 +02:00
|
|
|
self.plugin.roster.draw_contact(jid, self.account)
|
2005-03-29 18:16:42 +02:00
|
|
|
if self.plugin.systray_enabled:
|
|
|
|
self.plugin.systray.remove_jid(jid, self.account)
|
2005-04-12 23:09:06 +02:00
|
|
|
showOffline = gajim.config.get('showoffline')
|
2005-03-11 18:57:35 +01:00
|
|
|
if (user.show == 'offline' or user.show == 'error') and \
|
|
|
|
not showOffline:
|
2005-07-18 23:08:31 +02:00
|
|
|
if len(gajim.contacts[self.account][jid]) == 1:
|
2005-07-21 19:54:58 +02:00
|
|
|
self.plugin.roster.really_remove_contact(user, self.account)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-05-30 12:41:55 +02:00
|
|
|
def print_conversation(self, text, jid, contact = '', tim = None,
|
2005-07-05 23:35:37 +02:00
|
|
|
encrypted = False, subject = None):
|
2005-05-13 18:53:30 +02:00
|
|
|
"""Print a line in the conversation:
|
|
|
|
if contact is set to status: it's a status message
|
|
|
|
if contact is set to another value: it's an outgoing message
|
2005-07-22 12:29:54 +02:00
|
|
|
if contact is set to print_queue: it is incomming from queue
|
2005-05-13 18:53:30 +02:00
|
|
|
if contact is not set: it's an incomming message"""
|
2005-07-21 00:14:40 +02:00
|
|
|
user = self.contacts[jid]
|
2005-03-11 18:57:35 +01:00
|
|
|
if contact == 'status':
|
2005-03-16 18:22:20 +01:00
|
|
|
kind = 'status'
|
|
|
|
name = ''
|
2005-03-11 18:57:35 +01:00
|
|
|
else:
|
2005-07-02 13:06:02 +02:00
|
|
|
ec = gajim.encrypted_chats[self.account]
|
|
|
|
if encrypted and jid not in ec:
|
2005-07-06 16:05:22 +02:00
|
|
|
msg = _('Encryption enabled')
|
2005-07-06 14:13:54 +02:00
|
|
|
chat.Chat.print_conversation_line(self, msg, jid,
|
2005-05-30 12:41:55 +02:00
|
|
|
'status', '', tim)
|
2005-07-02 13:06:02 +02:00
|
|
|
ec.append(jid)
|
|
|
|
if not encrypted and jid in ec:
|
2005-07-06 16:05:22 +02:00
|
|
|
msg = _('Encryption disabled')
|
2005-07-06 14:13:54 +02:00
|
|
|
chat.Chat.print_conversation_line(self, msg, jid,
|
2005-05-30 12:41:55 +02:00
|
|
|
'status', '', tim)
|
2005-07-02 13:06:02 +02:00
|
|
|
ec.remove(jid)
|
2005-05-30 12:41:55 +02:00
|
|
|
self.xmls[jid].get_widget('gpg_togglebutton').set_active(encrypted)
|
2005-07-22 12:29:54 +02:00
|
|
|
if not contact:
|
2005-03-16 18:22:20 +01:00
|
|
|
kind = 'incoming'
|
2005-03-11 18:57:35 +01:00
|
|
|
name = user.name
|
2005-07-22 12:29:54 +02:00
|
|
|
elif contact == 'print_queue': # incoming message, but do not update time
|
|
|
|
kind = 'incoming_queue'
|
|
|
|
name = user.name
|
|
|
|
else:
|
|
|
|
kind = 'outgoing'
|
|
|
|
name = gajim.nicks[self.account]
|
2005-07-05 23:35:37 +02:00
|
|
|
chat.Chat.print_conversation_line(self, text, jid, kind, name, tim,
|
|
|
|
subject = subject)
|
2005-05-30 23:12:34 +02:00
|
|
|
|
|
|
|
def restore_conversation(self, jid):
|
2005-05-31 19:53:28 +02:00
|
|
|
# don't restore lines if it's a transport
|
2005-08-26 15:11:20 +02:00
|
|
|
if gajim.jid_is_transport(jid):
|
|
|
|
return
|
2005-05-30 23:12:34 +02:00
|
|
|
|
2005-08-16 13:35:14 +02:00
|
|
|
# How many lines to restore and when to time them out
|
2005-06-02 18:28:01 +02:00
|
|
|
restore = gajim.config.get('restore_lines')
|
|
|
|
time_out = gajim.config.get('restore_timeout')
|
2005-08-16 13:59:53 +02:00
|
|
|
pos = 0 # position, while reading from history
|
|
|
|
size = 0 # how many lines we alreay retreived
|
|
|
|
lines = [] # we'll need to reverse the lines from history
|
|
|
|
count = gajim.logger.get_no_of_lines(jid)
|
2005-05-30 23:12:34 +02:00
|
|
|
|
2005-06-02 18:28:01 +02:00
|
|
|
|
2005-07-18 23:08:31 +02:00
|
|
|
if gajim.awaiting_messages[self.account].has_key(jid):
|
|
|
|
pos = len(gajim.awaiting_messages[self.account][jid])
|
2005-06-02 18:28:01 +02:00
|
|
|
else:
|
|
|
|
pos = 0
|
|
|
|
|
|
|
|
now = time.time()
|
2005-05-30 23:12:34 +02:00
|
|
|
while size <= restore:
|
|
|
|
if pos == count or size > restore - 1:
|
2005-08-16 13:35:14 +02:00
|
|
|
# don't try to read beyond history, not read more than required
|
2005-05-30 23:12:34 +02:00
|
|
|
break
|
|
|
|
|
|
|
|
nb, line = gajim.logger.read(jid, count - 1 - pos, count - pos)
|
|
|
|
pos = pos + 1
|
|
|
|
|
2005-08-17 22:00:06 +02:00
|
|
|
# line is [] if log file for jid is not a file (does not exist or dir)
|
2005-08-16 13:59:53 +02:00
|
|
|
if line == []:
|
|
|
|
break
|
|
|
|
|
|
|
|
if (now - float(line[0][0]))/60 >= time_out:
|
|
|
|
# stop looking for messages if we found something too old
|
|
|
|
break
|
2005-08-16 13:35:14 +02:00
|
|
|
|
2005-08-16 13:59:53 +02:00
|
|
|
if line[0][1] != 'sent' and line[0][1] != 'recv':
|
|
|
|
# we don't want to display status lines, do we?
|
|
|
|
continue
|
2005-08-16 13:35:14 +02:00
|
|
|
|
2005-08-17 22:00:06 +02:00
|
|
|
lines.append(line[0])
|
|
|
|
size = size + 1
|
2005-08-16 13:35:14 +02:00
|
|
|
|
2005-08-16 13:59:53 +02:00
|
|
|
if lines != []:
|
|
|
|
lines.reverse()
|
2005-06-07 18:25:55 +02:00
|
|
|
|
2005-05-30 23:12:34 +02:00
|
|
|
for msg in lines:
|
|
|
|
if msg[1] == 'sent':
|
|
|
|
kind = 'outgoing'
|
2005-07-18 23:08:31 +02:00
|
|
|
name = gajim.nicks[self.account]
|
2005-05-30 23:12:34 +02:00
|
|
|
elif msg[1] == 'recv':
|
|
|
|
kind = 'incoming'
|
2005-07-21 00:14:40 +02:00
|
|
|
name = self.contacts[jid].name
|
2005-05-30 23:12:34 +02:00
|
|
|
|
2005-06-30 23:21:33 +02:00
|
|
|
tim = time.localtime(float(msg[0]))
|
2005-06-02 18:28:01 +02:00
|
|
|
|
2005-07-19 23:43:06 +02:00
|
|
|
text = ':'.join(msg[2:])[:-1] #remove the latest \n
|
2005-06-02 21:38:22 +02:00
|
|
|
self.print_conversation_line(text, jid, kind, name, tim,
|
2005-07-01 20:29:23 +02:00
|
|
|
['small'], ['small', 'grey'], ['small', 'grey'], False)
|
2005-06-03 23:35:46 +02:00
|
|
|
|
|
|
|
if len(lines):
|
|
|
|
self.print_empty_line(jid)
|