history can now be read from gtkgui plugin

This commit is contained in:
Yann Leboulanger 2004-04-04 22:09:56 +00:00
parent a9be10ace3
commit f803d0db05
4 changed files with 487 additions and 12 deletions

View File

@ -32,6 +32,7 @@ log = logging.getLogger('core.core')
log.setLevel(logging.DEBUG)
CONFPATH = "~/.gajim/config"
LOGPATH = os.path.expanduser("~/.gajim/logs/")
class GajimCore:
"""Core"""
@ -390,6 +391,29 @@ class GajimCore:
t='available';
p = common.jabber.Presence(to=ev[2][0], type=t)
con.send(p)
#('LOG_NB_LINE', account, jid)
elif ev[0] == 'LOG_NB_LINE':
fic = open(LOGPATH + ev[2], "r")
nb = 0
while (fic.readline()):
nb = nb+1
fic.close()
self.hub.sendPlugin('LOG_NB_LINE', ev[1], (ev[2], nb))
#('LOG_GET_RANGE', account, (jid, line_begin, line_end))
elif ev[0] == 'LOG_GET_RANGE':
fic = open(LOGPATH + ev[2][0], "r")
nb = 0
while (nb < ev[2][1] and fic.readline()):
nb = nb+1
while nb < ev[2][2]:
line = fic.readline()
nb = nb+1
if line:
lineSplited = string.split(line, ':')
if len(lineSplited) > 2:
self.hub.sendPlugin('LOG_LINE', ev[1], (ev[2][0], nb, \
lineSplited[0], lineSplited[1], lineSplited[2:]))
fic.close()
else:
log.debug("Unknown Command %s" % ev[0])
else:
@ -423,6 +447,8 @@ def loadPlugins(gc):
gc.hub.register(mod, 'ACC_OK')
gc.hub.register(mod, 'CONFIG')
gc.hub.register(mod, 'VCARD')
gc.hub.register(mod, 'LOG_NB_LINE')
gc.hub.register(mod, 'LOG_LINE')
modObj.load()
# END loadPLugins

View File

@ -354,6 +354,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_history_clicked" last_modification_time="Sun, 04 Apr 2004 05:30:58 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment4">
@ -617,6 +618,7 @@
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="default_height">200</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Wed, 10 Dec 2003 22:31:27 GMT"/>
@ -6360,4 +6362,293 @@ when NOT onlie</property>
</child>
</widget>
<widget class="GtkWindow" id="Log">
<property name="visible">True</property>
<property name="title" translatable="yes">Log</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Sun, 04 Apr 2004 18:55:52 GMT"/>
<child>
<widget class="GtkVBox" id="vbox24">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox11">
<property name="border_width">10</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_DEFAULT_STYLE</property>
<property name="spacing">5</property>
<child>
<widget class="GtkButton" id="earliest_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_earliest_clicked" last_modification_time="Sun, 04 Apr 2004 17:24:23 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment23">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox33">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image146">
<property name="visible">True</property>
<property name="stock">gtk-goto-first</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label132">
<property name="visible">True</property>
<property name="label" translatable="yes">earliest</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="previous_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_previous_clicked" last_modification_time="Sun, 04 Apr 2004 17:24:34 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment22">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox32">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image145">
<property name="visible">True</property>
<property name="stock">gtk-go-back</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label131">
<property name="visible">True</property>
<property name="label" translatable="yes">Previous</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="forward_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-go-forward</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_forward_clicked" last_modification_time="Sun, 04 Apr 2004 16:37:55 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="lastest_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_lastest_clicked" last_modification_time="Sun, 04 Apr 2004 17:24:42 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment24">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox34">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image147">
<property name="visible">True</property>
<property name="stock">gtk-goto-last</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label133">
<property name="visible">True</property>
<property name="label" translatable="yes">lastest</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="close_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_close_clicked" last_modification_time="Sun, 04 Apr 2004 16:34:43 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow16">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_NONE</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1016,6 +1016,11 @@ class message_Window:
deb, end = buffer.get_bounds()
buffer.delete(deb, end)
def on_history(self, widget):
"""When history button is pressed : call log window"""
if not self.plugin.windows['logs'].has_key(self.user.jid):
self.plugin.windows['logs'][self.user.jid] = log_Window(self.plugin, self.user.jid)
def __init__(self, user, plugin, account):
self.user = user
self.plugin = plugin
@ -1038,27 +1043,165 @@ class message_Window:
buffer.create_mark('end', end_iter, 0)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_clear_clicked', self.on_clear)
self.xml.signal_connect('on_history_clicked', self.on_history)
self.xml.signal_connect('on_msg_key_press_event', \
self.on_msg_key_press_event)
self.tagIn = buffer.create_tag("incoming")
tagIn = buffer.create_tag("incoming")
color = self.plugin.config['inmsgcolor']
if not color:
color = 'red'
self.tagIn.set_property("foreground", color)
self.tagOut = buffer.create_tag("outgoing")
tagIn.set_property("foreground", color)
tagOut = buffer.create_tag("outgoing")
color = self.plugin.config['outmsgcolor']
if not color:
color = 'blue'
self.tagOut.set_property("foreground", color)
self.tagStatus = buffer.create_tag("status")
tagOut.set_property("foreground", color)
tagStatus = buffer.create_tag("status")
color = self.plugin.config['statusmsgcolor']
if not color:
color = 'green'
self.tagStatus.set_property("foreground", color)
tagStatus.set_property("foreground", color)
#print queued messages
if plugin.queues[account].has_key(user.jid):
self.read_queue(plugin.queues[account][user.jid])
class log_Window:
"""Class for bowser agent window :
to know the agents on the selected server"""
def delete_event(self, widget):
"""close window"""
del self.plugin.windows['logs'][self.jid]
def on_close(self, widget):
"""When Close button is clicked"""
widget.get_toplevel().destroy()
def on_earliest(self, widget):
buffer = self.xml.get_widget('textview').get_buffer()
start, end = buffer.get_bounds()
buffer.delete(start, end)
self.xml.get_widget('earliest_button').set_sensitive(False)
self.xml.get_widget('previous_button').set_sensitive(False)
self.xml.get_widget('forward_button').set_sensitive(True)
self.xml.get_widget('lastest_button').set_sensitive(True)
end = 50
if end > self.nb_line:
end = nb_line
self.plugin.send('LOG_GET_RANGE', None, (self.jid, 0, end))
self.num_begin = self.nb_line
def on_previous(self, widget):
buffer = self.xml.get_widget('textview').get_buffer()
start, end = buffer.get_bounds()
buffer.delete(start, end)
self.xml.get_widget('earliest_button').set_sensitive(True)
self.xml.get_widget('previous_button').set_sensitive(True)
self.xml.get_widget('forward_button').set_sensitive(True)
self.xml.get_widget('lastest_button').set_sensitive(True)
begin = self.num_begin - 50
if begin < 0:
begin = 0
end = begin + 50
if end > self.nb_line:
end = self.nb_line
self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
self.num_begin = self.nb_line
def on_forward(self, widget):
buffer = self.xml.get_widget('textview').get_buffer()
start, end = buffer.get_bounds()
buffer.delete(start, end)
self.xml.get_widget('earliest_button').set_sensitive(True)
self.xml.get_widget('previous_button').set_sensitive(True)
self.xml.get_widget('forward_button').set_sensitive(True)
self.xml.get_widget('lastest_button').set_sensitive(True)
begin = self.num_begin + 50
if begin > self.nb_line:
begin = self.nb_line
end = begin + 50
if end > self.nb_line:
end = self.nb_line
self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
self.num_begin = self.nb_line
def on_latest(self, widget):
buffer = self.xml.get_widget('textview').get_buffer()
start, end = buffer.get_bounds()
buffer.delete(start, end)
self.xml.get_widget('earliest_button').set_sensitive(True)
self.xml.get_widget('previous_button').set_sensitive(True)
self.xml.get_widget('forward_button').set_sensitive(False)
self.xml.get_widget('lastest_button').set_sensitive(False)
begin = self.nb_line - 50
if begin < 0:
begin = 0
self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, self.nb_line))
self.num_begin = self.nb_line
def new_line(self, infos):
"""write a new line"""
#infos = [num_line, date, type, data]
if infos[0] < self.num_begin:
self.num_begin = infos[0]
if infos[0] == 0:
self.xml.get_widget('earliest_button').set_sensitive(False)
self.xml.get_widget('previous_button').set_sensitive(False)
if infos[0] == self.nb_line:
self.xml.get_widget('forward_button').set_sensitive(False)
self.xml.get_widget('lastest_button').set_sensitive(False)
buffer = self.xml.get_widget('textview').get_buffer()
start_iter = buffer.get_start_iter()
end_iter = buffer.get_end_iter()
tim = time.strftime("[%x %X] ", time.localtime(float(infos[1])))
buffer.insert(start_iter, tim)
if infos[2] == 'recv':
msg = string.join(infos[3][0:], ':')
msg = string.replace(msg, '\\n', '\n')
buffer.insert_with_tags_by_name(start_iter, msg, 'incoming')
elif infos[2] == 'sent':
msg = string.join(infos[3][0:], ':')
msg = string.replace(msg, '\\n', '\n')
buffer.insert_with_tags_by_name(start_iter, msg, 'outgoing')
else:
msg = string.join(infos[3][1:], ':')
msg = string.replace(msg, '\\n', '\n')
buffer.insert_with_tags_by_name(start_iter, 'Status is now : ' + \
infos[3][0]+' : ' + msg, 'status')
def set_nb_line(self, nb_line):
self.nb_line = nb_line
self.num_begin = nb_line
def __init__(self, plugin, jid):
self.plugin = plugin
self.jid = jid
self.nb_line = 0
self.num_begin = 0
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Log')
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_close_clicked', self.on_close)
self.xml.signal_connect('on_earliest_clicked', self.on_earliest)
self.xml.signal_connect('on_previous_clicked', self.on_previous)
self.xml.signal_connect('on_forward_clicked', self.on_forward)
self.xml.signal_connect('on_latest_clicked', self.on_latest)
buffer = self.xml.get_widget('textview').get_buffer()
tagIn = buffer.create_tag("incoming")
color = self.plugin.config['inmsgcolor']
if not color:
color = 'red'
tagIn.set_property("foreground", color)
tagOut = buffer.create_tag("outgoing")
color = self.plugin.config['outmsgcolor']
if not color:
color = 'blue'
tagOut.set_property("foreground", color)
tagStatus = buffer.create_tag("status")
color = self.plugin.config['statusmsgcolor']
if not color:
color = 'green'
tagStatus.set_property("foreground", color)
self.plugin.send('LOG_NB_LINE', None, jid)
class roster_Window:
"""Class for main gtk window"""
@ -1928,6 +2071,20 @@ class plugin:
elif ev[0] == 'VCARD':
if self.windows[ev[1]]['infos'].has_key(ev[2]['jid']):
self.windows[ev[1]]['infos'][ev[2]['jid']].set_values(ev[2])
#('LOG_NB_LINE', account, (jid, nb_line))
elif ev[0] == 'LOG_NB_LINE':
if self.windows['logs'].has_key(ev[2][0]):
self.windows['logs'][ev[2][0]].set_nb_line(ev[2][1])
begin = 0
if ev[2][1] > 50:
begin = ev[2][1] - 50
self.send('LOG_GET_RANGE', None, (ev[2][0], begin, ev[2][1]))
#('LOG_LINE', account, (jid, num_line, date, type, data))
# if type = 'recv' or 'sent' data = [msg]
# else type = jid and data = [status, away_msg]
elif ev[0] == 'LOG_LINE':
if self.windows['logs'].has_key(ev[2][0]):
self.windows['logs'][ev[2][0]].new_line(ev[2][1:])
return 1
def read_sleepy(self):
@ -1971,7 +2128,7 @@ class plugin:
self.config = self.wait('CONFIG')
self.send('ASK_CONFIG', None, ('GtkGui', 'accounts'))
self.accounts = self.wait('CONFIG')
self.windows = {}
self.windows = {'logs':{}}
self.queues = {}
self.connected = {}
for a in self.accounts.keys():

View File

@ -21,7 +21,6 @@ import os
import string
import time
import common.optparser
CONFPATH = "~/.gajim/config"
LOGPATH = os.path.expanduser("~/.gajim/logs/")
class plugin:
@ -36,8 +35,7 @@ class plugin:
lognotusr = self.config['lognotusr']
else:
lognotusr = 1
# tim = time.strftime("%d%m%y%H%M%S")
tim = "%d" % time.time()
tim = time.time()
ev = self.queueIN.get()
if ev[0] == 'QUIT':
@ -48,6 +46,7 @@ class plugin:
jid = string.split(ev[2][0], '/')[0]
if not status:
status = ""
status = string.replace(status, '\n', '\\n')
if lognotsep == 1:
fic = open(LOGPATH + "notify.log", "a")
fic.write("%s:%s:%s:%s\n" % (tim, ev[2][0], \
@ -59,14 +58,16 @@ class plugin:
ev[2][1], status))
fic.close()
elif ev[0] == 'MSG':
msg = string.replace(ev[2][1], '\n', '\\n')
jid = string.split(ev[2][0], '/')[0]
fic = open(LOGPATH + jid, "a")
fic.write("%s:recv:%s\n" % (tim, ev[2][1]))
fic.write("%s:recv:%s\n" % (tim, msg))
fic.close()
elif ev[0] == 'MSGSENT':
msg = string.replace(ev[2][1], '\n', '\\n')
jid = string.split(ev[2][0], '/')[0]
fic = open(LOGPATH + jid, "a")
fic.write("%s:sent:%s\n" % (tim, ev[2][1]))
fic.write("%s:sent:%s\n" % (tim, msg))
fic.close()
time.sleep(0.5)