2005-03-11 18:57:35 +01:00
|
|
|
## plugins/tabbed_chat_window.py
|
|
|
|
##
|
|
|
|
## 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-04-14 09:05:10 +02:00
|
|
|
from common import gajim
|
2005-04-14 19:07:55 +02:00
|
|
|
import dialogs
|
|
|
|
import history_window
|
|
|
|
import chat
|
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-04-14 19:07:55 +02:00
|
|
|
class Tabbed_chat_window(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-03-11 18:57:35 +01:00
|
|
|
self.users = {}
|
|
|
|
self.new_user(user)
|
|
|
|
self.show_title()
|
|
|
|
self.xml.signal_connect('on_tabbed_chat_window_destroy', \
|
|
|
|
self.on_tabbed_chat_window_destroy)
|
|
|
|
self.xml.signal_connect('on_tabbed_chat_window_delete_event', \
|
|
|
|
self.on_tabbed_chat_window_delete_event)
|
|
|
|
self.xml.signal_connect('on_tabbed_chat_window_focus_in_event', \
|
|
|
|
self.on_tabbed_chat_window_focus_in_event)
|
2005-03-12 22:30:50 +01:00
|
|
|
self.xml.signal_connect('on_chat_notebook_key_press_event', \
|
|
|
|
self.on_chat_notebook_key_press_event)
|
2005-03-11 18:57:35 +01:00
|
|
|
self.xml.signal_connect('on_chat_notebook_switch_page', \
|
|
|
|
self.on_chat_notebook_switch_page)
|
2005-04-27 15:50:13 +02:00
|
|
|
self.window.show_all()
|
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
|
|
|
|
self.xmls[jid].get_widget('gpg_togglebutton').set_active(\
|
|
|
|
var['gpg_enabled'])
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def draw_widgets(self, user):
|
|
|
|
"""draw the widgets in a tab (status_image, contact_button ...)
|
|
|
|
according to the the information in the user variable"""
|
|
|
|
jid = user.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-03-11 18:57:35 +01:00
|
|
|
contact_button.set_label(user.name + ' <' + jid + '>')
|
|
|
|
if not user.keyID:
|
|
|
|
self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(False)
|
|
|
|
|
2005-04-23 03:37:05 +02:00
|
|
|
def set_state_image(self, jid):
|
2005-03-31 21:21:48 +02:00
|
|
|
prio = 0
|
|
|
|
list_users = self.plugin.roster.contacts[self.account][jid]
|
2005-04-23 03:37:05 +02:00
|
|
|
user = list_users[0]
|
|
|
|
show = user.show
|
|
|
|
jid = user.jid
|
2005-03-31 21:21:48 +02:00
|
|
|
for u in list_users:
|
|
|
|
if u.priority > prio:
|
|
|
|
prio = u.priority
|
2005-04-23 03:37:05 +02:00
|
|
|
show = u.show
|
2005-05-03 18:37:59 +02:00
|
|
|
child = self.childs[jid]
|
|
|
|
status_image = self.notebook.get_tab_label(child).get_children()[0]
|
2005-04-23 03:37:05 +02:00
|
|
|
state_images = self.plugin.roster.get_appropriate_state_images(jid)
|
|
|
|
image = state_images[show]
|
2005-05-03 18:37:59 +02:00
|
|
|
non_tabbed_status_image = self.xmls[jid].get_widget(
|
|
|
|
'nontabbed_status_image')
|
2005-03-11 18:57:35 +01:00
|
|
|
if image.get_storage_type() == gtk.IMAGE_ANIMATION:
|
2005-05-03 18:37:59 +02:00
|
|
|
non_tabbed_status_image.set_from_animation(image.get_animation())
|
|
|
|
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-05-03 18:37:59 +02:00
|
|
|
non_tabbed_status_image.set_from_pixbuf(image.get_pixbuf())
|
|
|
|
status_image.set_from_pixbuf(image.get_pixbuf())
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def on_tabbed_chat_window_delete_event(self, widget, event):
|
|
|
|
"""close window"""
|
|
|
|
for jid in self.users:
|
|
|
|
if time.time() - self.last_message_time[jid] < 2: # 2 seconds
|
2005-04-19 01:55:13 +02:00
|
|
|
dialog = dialogs.Confirmation_dialog(_('You received a message from %s in the last two seconds.\nDo you still want to close this window?') % jid)
|
2005-03-11 18:57:35 +01:00
|
|
|
if dialog.get_response() != gtk.RESPONSE_YES:
|
|
|
|
return True #stop the propagation of the event
|
|
|
|
|
|
|
|
def on_tabbed_chat_window_destroy(self, widget):
|
|
|
|
#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-03-12 19:12:15 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
def on_clear_button_clicked(self, widget):
|
2005-05-03 18:37:59 +02:00
|
|
|
"""When clear button is pressed:
|
2005-03-11 18:57:35 +01:00
|
|
|
clear the conversation"""
|
|
|
|
jid = self.get_active_jid()
|
|
|
|
conversation_buffer = self.xmls[jid].get_widget('conversation_textview').\
|
|
|
|
get_buffer()
|
|
|
|
start, end = conversation_buffer.get_bounds()
|
|
|
|
conversation_buffer.delete(start, end)
|
|
|
|
|
|
|
|
def on_history_button_clicked(self, widget):
|
|
|
|
"""When history button is pressed : call history window"""
|
|
|
|
jid = self.get_active_jid()
|
|
|
|
if not self.plugin.windows['logs'].has_key(jid):
|
2005-04-14 19:07:55 +02:00
|
|
|
self.plugin.windows['logs'][jid] = history_window.\
|
|
|
|
History_window(self.plugin, jid)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def remove_tab(self, jid):
|
|
|
|
if time.time() - self.last_message_time[jid] < 2:
|
2005-04-14 19:07:55 +02:00
|
|
|
dialog = dialogs.Confirmation_dialog(_('You received a message from %s in the last two seconds.\nDo you still want to close this tab?') % jid)
|
2005-03-11 18:57:35 +01:00
|
|
|
if dialog.get_response() != gtk.RESPONSE_YES:
|
|
|
|
return
|
|
|
|
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.remove_tab(self, jid, 'chats')
|
2005-03-12 18:18:33 +01:00
|
|
|
if len(self.xmls) > 0:
|
2005-03-11 18:57:35 +01:00
|
|
|
del self.users[jid]
|
2005-05-03 18:37:59 +02:00
|
|
|
|
|
|
|
jid = self.get_active_jid() # get the new active jid
|
|
|
|
nontabbed_status_image = self.xmls[jid].get_widget(
|
|
|
|
'nontabbed_status_image')
|
|
|
|
if len(self.xmls) > 1:
|
|
|
|
nontabbed_status_image.hide()
|
|
|
|
else:
|
|
|
|
nontabbed_status_image.show()
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def new_user(self, user):
|
2005-03-12 19:12:15 +01:00
|
|
|
self.names[user.jid] = user.name
|
2005-03-12 22:30:50 +01:00
|
|
|
self.xmls[user.jid] = gtk.glade.XML(GTKGUI_GLADE, 'chats_vbox', APP)
|
|
|
|
self.childs[user.jid] = self.xmls[user.jid].get_widget('chats_vbox')
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.new_tab(self, user.jid)
|
2005-03-11 18:57:35 +01:00
|
|
|
self.users[user.jid] = user
|
|
|
|
|
|
|
|
self.redraw_tab(user.jid)
|
|
|
|
self.draw_widgets(user)
|
2005-04-17 18:06:40 +02:00
|
|
|
self.print_conversation(_('%s is %s (%s)') % (user.name, \
|
2005-04-03 23:41:10 +02:00
|
|
|
user.show, user.status), user.jid, 'status')
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
#print queued messages
|
|
|
|
if self.plugin.queues[self.account].has_key(user.jid):
|
|
|
|
self.read_queue(user.jid)
|
|
|
|
|
2005-04-12 23:09:06 +02:00
|
|
|
if gajim.config.get('print_time') == 'sometimes':
|
2005-03-11 18:57:35 +01:00
|
|
|
self.print_time_timeout(user.jid)
|
|
|
|
self.print_time_timeout_id[user.jid] = gobject.timeout_add(300000, \
|
|
|
|
self.print_time_timeout, user.jid)
|
2005-05-03 18:37:59 +02:00
|
|
|
#FIXME: why show if already visible from glade?
|
|
|
|
#self.childs[user.jid].show_all()
|
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-03-11 18:57:35 +01:00
|
|
|
if enter is pressed without the shit key, message (if not empty) is sent
|
|
|
|
and printed in the conversation"""
|
2005-03-16 20:57:32 +01:00
|
|
|
jid = self.get_active_jid()
|
|
|
|
conversation_textview = self.xmls[jid].get_widget('conversation_textview')
|
2005-04-12 17:30:09 +02:00
|
|
|
if event.hardware_keycode == 23: # TAB
|
|
|
|
if (event.state & gtk.gdk.CONTROL_MASK) and \
|
|
|
|
(event.state & gtk.gdk.SHIFT_MASK): # CTRL + SHIFT + TAB
|
|
|
|
self.notebook.emit('key_press_event', event)
|
|
|
|
elif event.state & gtk.gdk.CONTROL_MASK: # CTRL + TAB
|
|
|
|
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-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-03-11 18:57:35 +01:00
|
|
|
if (event.state & gtk.gdk.SHIFT_MASK):
|
2005-03-16 18:08:38 +01:00
|
|
|
return False
|
2005-04-14 09:20:14 +02:00
|
|
|
if gajim.connections[self.account].connected < 2: #we are not connected
|
2005-04-14 19:07:55 +02:00
|
|
|
dialogs.Error_dialog(_('You are not connected, so you cannot send a message'))
|
2005-03-16 18:08:38 +01:00
|
|
|
return True
|
2005-03-11 18:57:35 +01:00
|
|
|
message_buffer = widget.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)
|
|
|
|
if message != '':
|
|
|
|
keyID = ''
|
|
|
|
if self.xmls[jid].get_widget('gpg_togglebutton').get_active():
|
|
|
|
keyID = self.users[jid].keyID
|
2005-04-14 11:38:08 +02:00
|
|
|
gajim.connections[self.account].send_message(jid, message, keyID)
|
2005-03-11 18:57:35 +01:00
|
|
|
message_buffer.set_text('', -1)
|
|
|
|
self.print_conversation(message, jid, jid)
|
2005-03-16 18:08:38 +01:00
|
|
|
return True
|
|
|
|
return False
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def on_contact_button_clicked(self, widget):
|
|
|
|
"""When button contact is clicked"""
|
|
|
|
jid = self.get_active_jid()
|
|
|
|
user = self.users[jid]
|
|
|
|
self.plugin.roster.on_info(widget, user, self.account)
|
|
|
|
|
|
|
|
def read_queue(self, jid):
|
|
|
|
"""read queue and print messages containted in it"""
|
|
|
|
q = self.plugin.queues[self.account][jid]
|
|
|
|
user = self.users[jid]
|
|
|
|
while not q.empty():
|
|
|
|
event = q.get()
|
|
|
|
self.print_conversation(event[0], jid, tim = event[1])
|
|
|
|
self.plugin.roster.nb_unread -= 1
|
|
|
|
self.plugin.roster.show_title()
|
|
|
|
del self.plugin.queues[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:
|
|
|
|
if len(self.plugin.roster.contacts[self.account][jid]) == 1:
|
2005-04-12 17:30:09 +02:00
|
|
|
self.plugin.roster.really_remove_user(user, self.account)
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def print_conversation(self, text, jid, contact = '', tim = None):
|
|
|
|
"""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
|
|
|
|
if contact is not set : it's an incomming message"""
|
|
|
|
user = self.users[jid]
|
|
|
|
if contact == 'status':
|
2005-03-16 18:22:20 +01:00
|
|
|
kind = 'status'
|
|
|
|
name = ''
|
2005-03-11 18:57:35 +01:00
|
|
|
else:
|
|
|
|
if contact:
|
2005-03-16 18:22:20 +01:00
|
|
|
kind = 'outgoing'
|
2005-03-11 18:57:35 +01:00
|
|
|
name = self.plugin.nicks[self.account]
|
|
|
|
else:
|
2005-03-16 18:22:20 +01:00
|
|
|
kind = 'incoming'
|
2005-03-11 18:57:35 +01:00
|
|
|
name = user.name
|
|
|
|
|
2005-04-14 19:07:55 +02:00
|
|
|
chat.Chat.print_conversation_line(self, text, jid, kind, name, tim)
|