root/branches/gajim_0.6.1/plugins/gtkgui/history_window.py

Revision 920, 5.3 kB (checked in by nk, 4 years ago)

systray --> Systray (the class)

Line 
1##      plugins/history_window.py
2##
3## Gajim Team:
4##      - Yann Le Boulanger <asterix@lagaule.org>
5##      - Vincent Hanquez <tab@snarc.org>
6##      - Nikos Kouremenos <kourem@gmail.com>
7##
8##      Copyright (C) 2003-2005 Gajim Team
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published
12## by the Free Software Foundation; version 2 only.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18##
19
20import gtk
21import gtk.glade
22import time
23
24from common import i18n
25
26_ = i18n._
27APP = i18n.APP
28gtk.glade.bindtextdomain(APP, i18n.DIR)
29gtk.glade.textdomain(APP)
30
31GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
32
33class history_window:
34        """Class for bowser agent window:
35        to know the agents on the selected server"""
36        def on_history_window_destroy(self, widget):
37                """close window"""
38                del self.plugin.windows['logs'][self.jid]
39
40        def on_close_button_clicked(self, widget):
41                """When Close button is clicked"""
42                widget.get_toplevel().destroy()
43
44        def on_earliest_button_clicked(self, widget):
45                start, end = self.history_buffer.get_bounds()
46                self.history_buffer.delete(start, end)
47                self.earliest_button.set_sensitive(False)
48                self.previous_button.set_sensitive(False)
49                self.forward_button.set_sensitive(True)
50                self.latest_button.set_sensitive(True)
51                end = 50
52                if end > self.nb_line:
53                        end = self.nb_line
54                self.plugin.send('LOG_GET_RANGE', None, (self.jid, 0, end))
55                self.num_begin = self.nb_line
56
57        def on_previous_button_clicked(self, widget):
58                start, end = self.history_buffer.get_bounds()
59                self.history_buffer.delete(start, end)
60                self.earliest_button.set_sensitive(True)
61                self.previous_button.set_sensitive(True)
62                self.forward_button.set_sensitive(True)
63                self.latest_button.set_sensitive(True)
64                begin = self.num_begin - 50
65                if begin < 0:
66                        begin = 0
67                end = begin + 50
68                if end > self.nb_line:
69                        end = self.nb_line
70                self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
71                self.num_begin = self.nb_line
72
73        def on_forward_button_clicked(self, widget):
74                start, end = self.history_buffer.get_bounds()
75                self.history_buffer.delete(start, end)
76                self.earliest_button.set_sensitive(True)
77                self.previous_button.set_sensitive(True)
78                self.forward_button.set_sensitive(True)
79                self.latest_button.set_sensitive(True)
80                begin = self.num_begin + 50
81                if begin > self.nb_line:
82                        begin = self.nb_line
83                end = begin + 50
84                if end > self.nb_line:
85                        end = self.nb_line
86                self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
87                self.num_begin = self.nb_line
88
89        def on_latest_button_clicked(self, widget):
90                start, end = self.history_buffer.get_bounds()
91                self.history_buffer.delete(start, end)
92                self.earliest_button.set_sensitive(True)
93                self.previous_button.set_sensitive(True)
94                self.forward_button.set_sensitive(False)
95                self.latest_button.set_sensitive(False)
96                begin = self.nb_line - 50
97                if begin < 0:
98                        begin = 0
99                self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, self.nb_line))
100                self.num_begin = self.nb_line
101
102        def new_line(self, infos):
103                """write a new line"""
104                #infos = [num_line, date, type, data]
105                if infos[0] < self.num_begin:
106                        self.num_begin = infos[0]
107                if infos[0] == 50:
108                        self.earliest_button.set_sensitive(False)
109                        self.previous_button.set_sensitive(False)
110                if infos[0] == self.nb_line:
111                        self.forward_button.set_sensitive(False)
112                        self.latest_button.set_sensitive(False)
113                start_iter = self.history_buffer.get_start_iter()
114                end_iter = self.history_buffer.get_end_iter()
115                tim = time.strftime("[%x %X] ", time.localtime(float(infos[1])))
116                self.history_buffer.insert(start_iter, tim)
117                if infos[2] == 'recv':
118                        msg = ':'.join(infos[3][0:])
119                        msg = msg.replace('\\n', '\n')
120                        self.history_buffer.insert_with_tags_by_name(start_iter, msg, \
121                                'incoming')
122                elif infos[2] == 'sent':
123                        msg = ':'.join(infos[3][0:])
124                        msg = msg.replace('\\n', '\n')
125                        self.history_buffer.insert_with_tags_by_name(start_iter, msg, \
126                                'outgoing')
127                else:
128                        msg = ':'.join(infos[3][1:])
129                        msg = msg.replace('\\n', '\n')
130                        self.history_buffer.insert_with_tags_by_name(start_iter, \
131                                _('Status is now: ') + infos[3][0]+': ' + msg, 'status')
132       
133        def set_nb_line(self, nb_line):
134                self.nb_line = nb_line
135                self.num_begin = nb_line
136
137        def __init__(self, plugin, jid):
138                self.plugin = plugin
139                self.jid = jid
140                self.nb_line = 0
141                self.num_begin = 0
142                xml = gtk.glade.XML(GTKGUI_GLADE, 'history_window', APP)
143                self.window = xml.get_widget('history_window')
144                self.history_buffer = xml.get_widget('history_textview').get_buffer()
145                self.earliest_button = xml.get_widget('earliest_button')
146                self.previous_button = xml.get_widget('previous_button')
147                self.forward_button = xml.get_widget('forward_button')
148                self.latest_button = xml.get_widget('latest_button')
149                xml.signal_autoconnect(self)
150                tagIn = self.history_buffer.create_tag('incoming')
151                color = self.plugin.config['inmsgcolor']
152                tagIn.set_property('foreground', color)
153                tagOut = self.history_buffer.create_tag('outgoing')
154                color = self.plugin.config['outmsgcolor']
155                tagOut.set_property('foreground', color)
156                tagStatus = self.history_buffer.create_tag('status')
157                color = self.plugin.config['statusmsgcolor']
158                tagStatus.set_property('foreground', color)
159                self.plugin.send('LOG_NB_LINE', None, jid)
Note: See TracBrowser for help on using the browser.