Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
d17289df
Commit
d17289df
authored
19 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
we can now view history_windows
parent
04165797
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common/gajim.py
+2
-0
2 additions, 0 deletions
src/common/gajim.py
src/common/logger.py
+72
-154
72 additions, 154 deletions
src/common/logger.py
src/history_window.py
+42
-34
42 additions, 34 deletions
src/history_window.py
with
116 additions
and
188 deletions
src/common/gajim.py
+
2
−
0
View file @
d17289df
...
...
@@ -18,8 +18,10 @@
import
logging
import
common.config
import
common.logger
version
=
"
0.7
"
config
=
common
.
config
.
Config
()
connections
=
{}
log
=
logging
.
getLogger
(
'
Gajim
'
)
logger
=
common
.
logger
.
Logger
()
This diff is collapsed.
Click to expand it.
src/common/logger.py
+
72
−
154
View file @
d17289df
...
...
@@ -16,169 +16,87 @@
## GNU General Public License for more details.
##
def
usage
():
#TODO: use i18n
print
"
usage :
"
,
sys
.
argv
[
0
],
'
[OPTION]
'
print
"
-p
\t
port on whitch the sock plugin listen
"
print
"
-h, --help
\t
display this help and exit
"
if
__name__
==
"
__main__
"
:
import
getopt
,
sys
,
pickle
,
socket
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
p:h
"
,
[
"
help
"
])
except
getopt
.
GetoptError
:
# print help information and exit:
usage
()
sys
.
exit
(
2
)
port
=
8255
for
o
,
a
in
opts
:
if
o
==
'
-p
'
:
port
=
a
if
o
in
(
"
-h
"
,
"
--help
"
):
usage
()
sys
.
exit
()
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
sock
.
connect
((
''
,
8255
))
except
:
#TODO: use i18n
print
"
unable to connect to localhost on port
"
+
str
(
port
)
else
:
evp
=
pickle
.
dumps
((
'
EXEC_PLUGIN
'
,
''
,
'
logger
'
))
sock
.
send
(
'
<
'
+
evp
+
'
>
'
)
sock
.
close
()
sys
.
exit
()
import
os
import
time
import
common.
optparser
import
common.
gajim
from
common
import
i18n
LOGPATH
=
os
.
path
.
expanduser
(
"
~/.gajim/logs/
"
)
LOGPATH
=
os
.
path
.
expanduser
(
'
~/.gajim/logs/
'
)
_
=
i18n
.
_
class
plugin
:
def
read_queue
(
self
):
while
1
:
while
self
.
queueIN
.
empty
()
==
0
:
if
self
.
config
.
has_key
(
'
lognotsep
'
):
lognotsep
=
self
.
config
[
'
lognotsep
'
]
else
:
lognotsep
=
1
if
self
.
config
.
has_key
(
'
lognotusr
'
):
lognotusr
=
self
.
config
[
'
lognotusr
'
]
else
:
lognotusr
=
1
tim
=
time
.
time
()
ev
=
self
.
queueIN
.
get
()
if
ev
[
0
]
==
'
QUIT
'
:
print
_
(
"
plugin logger stopped
"
)
return
elif
ev
[
0
]
==
'
NOTIFY
'
:
jid
=
ev
[
2
][
0
].
split
(
'
/
'
)[
0
]
if
jid
in
self
.
no_log_for
[
ev
[
1
]]:
break
if
ev
[
1
]
in
self
.
no_log_for
[
ev
[
1
]]:
break
status
=
ev
[
2
][
2
]
if
not
status
:
status
=
""
status
=
status
.
replace
(
'
\n
'
,
'
\\
n
'
)
if
lognotsep
==
1
:
fic
=
open
(
LOGPATH
+
"
notify.log
"
,
"
a
"
)
fic
.
write
(
"
%s:%s:%s:%s
\n
"
%
(
tim
,
ev
[
2
][
0
]
+
'
/
'
+
ev
[
2
][
3
],
\
ev
[
2
][
1
],
status
))
fic
.
close
()
if
lognotusr
==
1
:
fic
=
open
(
LOGPATH
+
jid
,
"
a
"
)
fic
.
write
(
"
%s:%s:%s:%s
\n
"
%
(
tim
,
ev
[
2
][
0
]
+
'
/
'
+
ev
[
2
][
3
],
\
ev
[
2
][
1
],
status
))
fic
.
close
()
elif
ev
[
0
]
==
'
MSG
'
:
jid
=
ev
[
2
][
0
].
split
(
'
/
'
)[
0
]
if
jid
in
self
.
no_log_for
[
ev
[
1
]]:
break
if
ev
[
1
]
in
self
.
no_log_for
[
ev
[
1
]]:
break
if
not
ev
[
2
][
1
]:
msg
=
''
else
:
msg
=
ev
[
2
][
1
].
replace
(
'
\n
'
,
'
\\
n
'
)
fic
=
open
(
LOGPATH
+
jid
,
"
a
"
)
t
=
time
.
mktime
(
ev
[
2
][
2
])
fic
.
write
(
"
%s:recv:%s
\n
"
%
(
t
,
msg
))
fic
.
close
()
elif
ev
[
0
]
==
'
MSGSENT
'
:
jid
=
ev
[
2
][
0
].
split
(
'
/
'
)[
0
]
if
jid
in
self
.
no_log_for
[
ev
[
1
]]:
break
if
ev
[
1
]
in
self
.
no_log_for
[
ev
[
1
]]:
break
msg
=
ev
[
2
][
1
].
replace
(
'
\n
'
,
'
\\
n
'
)
fic
=
open
(
LOGPATH
+
jid
,
"
a
"
)
fic
.
write
(
"
%s:sent:%s
\n
"
%
(
tim
,
msg
))
fic
.
close
()
elif
ev
[
0
]
==
'
GC_MSG
'
:
msg
=
ev
[
2
][
1
].
replace
(
'
\n
'
,
'
\\
n
'
)
jids
=
ev
[
2
][
0
].
split
(
'
/
'
)
jid
=
jids
[
0
]
nick
=
''
if
len
(
jids
)
>
1
:
nick
=
ev
[
2
][
0
].
split
(
'
/
'
)[
1
]
fic
=
open
(
LOGPATH
+
jid
,
"
a
"
)
t
=
time
.
mktime
(
ev
[
2
][
2
])
fic
.
write
(
"
%s:recv:%s:%s
\n
"
%
(
t
,
nick
,
msg
))
fic
.
close
()
elif
ev
[
0
]
==
'
CONFIG
'
:
if
ev
[
2
][
0
]
==
'
Logger
'
:
self
.
config
=
ev
[
2
][
1
]
if
ev
[
2
][
0
]
==
'
accounts
'
:
accounts
=
ev
[
2
][
1
]
self
.
no_log_for
=
{}
for
acct
in
accounts
.
keys
():
self
.
no_log_for
[
acct
]
=
[]
if
accounts
[
acct
].
has_key
(
'
no_log_for
'
):
self
.
no_log_for
[
acct
]
=
\
accounts
[
acct
][
'
no_log_for
'
].
split
()
time
.
sleep
(
0.1
)
def
wait
(
self
,
what
):
"""
Wait for a message from Core
"""
#TODO: timeout, save messages that don't fit
while
1
:
if
not
self
.
queueIN
.
empty
():
ev
=
self
.
queueIN
.
get
()
if
ev
[
0
]
==
what
and
ev
[
2
][
0
]
==
'
Logger
'
:
return
ev
[
2
][
1
]
time
.
sleep
(
0.1
)
def
__init__
(
self
,
quIN
,
quOUT
):
self
.
queueIN
=
quIN
self
.
queueOUT
=
quOUT
quOUT
.
put
((
'
REG_MESSAGE
'
,
'
logger
'
,
[
'
CONFIG
'
,
'
NOTIFY
'
,
'
MSG
'
,
\
'
MSGSENT
'
,
'
GC_MSG
'
,
'
QUIT
'
]))
quOUT
.
put
((
'
ASK_CONFIG
'
,
None
,
(
'
Logger
'
,
'
Logger
'
,
{
\
'
lognotsep
'
:
1
,
'
lognotusr
'
:
1
})))
self
.
config
=
self
.
wait
(
'
CONFIG
'
)
quOUT
.
put
((
'
ASK_CONFIG
'
,
None
,
(
'
Logger
'
,
'
accounts
'
)))
accounts
=
self
.
wait
(
'
CONFIG
'
)
self
.
no_log_for
=
{}
for
acct
in
accounts
.
keys
():
self
.
no_log_for
[
acct
]
=
[]
if
accounts
[
acct
].
has_key
(
'
no_log_for
'
):
self
.
no_log_for
[
acct
]
=
\
accounts
[
acct
][
'
no_log_for
'
].
split
()
class
Logger
:
def
__init__
(
self
):
#create ~/.gajim/logs/ if it doesn't exist
try
:
os
.
stat
(
os
.
path
.
expanduser
(
"
~/.gajim
"
))
os
.
stat
(
os
.
path
.
expanduser
(
'
~/.gajim
'
))
except
OSError
:
os
.
mkdir
(
os
.
path
.
expanduser
(
"
~/.gajim
"
))
print
_
(
"
creating ~/.gajim/
"
)
os
.
mkdir
(
os
.
path
.
expanduser
(
'
~/.gajim
'
))
print
_
(
'
creating ~/.gajim/
'
)
try
:
os
.
stat
(
LOGPATH
)
except
OSError
:
os
.
mkdir
(
LOGPATH
)
print
_
(
"
creating ~/.gajim/logs/
"
)
self
.
read_queue
()
print
_
(
"
plugin logger loaded
"
)
print
_
(
'
creating ~/.gajim/logs/
'
)
def
write
(
self
,
kind
,
msg
,
jid
,
show
=
None
,
tim
=
None
):
if
not
tim
:
tim
=
time
.
time
()
else
:
tim
=
time
.
mktime
(
tim
)
if
not
msg
:
msg
=
''
msg
=
msg
.
replace
(
'
\n
'
,
'
\\
n
'
)
ji
=
jid
.
split
(
'
/
'
)[
0
]
files
=
[]
if
kind
==
'
status
'
:
#we save time:jid:show:msg
if
not
show
:
show
=
'
online
'
if
common
.
gajim
.
config
.
get
(
'
lognotusr
'
):
files
.
append
(
ji
)
if
common
.
gajim
.
config
.
get
(
'
lognotsep
'
):
files
.
append
(
'
notify.log
'
)
elif
kind
==
'
incoming
'
:
# we save time:recv:message:
files
.
append
(
ji
)
jid
=
'
recv
'
show
=
msg
msg
=
''
elif
kind
==
'
outgoing
'
:
# we save time:sent:message:
files
.
append
(
ji
)
jid
=
'
sent
'
show
=
msg
msg
=
''
elif
kind
==
'
gc
'
:
files
.
append
(
ji
)
jid
=
'
recv
'
jids
=
jid
.
split
(
'
/
'
)
nick
=
''
if
len
(
jids
)
>
1
:
nick
=
jids
[
1
]
show
=
nick
for
f
in
files
:
fic
=
open
(
LOGPATH
+
f
,
'
a
'
)
fic
.
write
(
'
%s:%s:%s:%s
\n
'
%
(
tim
,
jid
,
show
,
msg
))
fic
.
close
()
def
get_nb_line
(
self
,
jid
):
fic
=
open
(
LOGPATH
+
jid
.
split
(
'
/
'
)[
0
],
'
r
'
)
nb
=
0
while
(
fic
.
readline
()):
nb
+=
1
fic
.
close
()
return
nb
def
read
(
self
,
jid
,
begin_line
,
end_line
):
fic
=
open
(
LOGPATH
+
jid
.
split
(
'
/
'
)[
0
],
'
r
'
)
nb
=
0
lines
=
[]
while
(
nb
<
begin_line
and
fic
.
readline
()):
nb
+=
1
while
nb
<
end_line
:
line
=
fic
.
readline
()
if
line
:
lineSplited
=
line
.
split
(
'
:
'
)
if
len
(
lineSplited
)
>
2
:
lines
.
append
(
lineSplited
)
nb
+=
1
return
nb
,
lines
This diff is collapsed.
Click to expand it.
src/history_window.py
+
42
−
34
View file @
d17289df
...
...
@@ -52,9 +52,11 @@ class History_window:
end
=
50
if
end
>
self
.
nb_line
:
end
=
self
.
nb_line
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, 0, end))
self
.
num_begin
=
self
.
nb_line
nb
,
lines
=
gajim
.
logger
.
read
(
self
.
jid
,
0
,
end
)
self
.
set_buttons_sensitivity
(
nb
)
for
line
in
lines
:
self
.
new_line
(
line
[
0
],
line
[
1
],
line
[
2
:])
self
.
num_begin
=
0
def
on_previous_button_clicked
(
self
,
widget
):
start
,
end
=
self
.
history_buffer
.
get_bounds
()
...
...
@@ -69,9 +71,11 @@ class History_window:
end
=
begin
+
50
if
end
>
self
.
nb_line
:
end
=
self
.
nb_line
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
self
.
num_begin
=
self
.
nb_line
nb
,
lines
=
gajim
.
logger
.
read
(
self
.
jid
,
begin
,
end
)
self
.
set_buttons_sensitivity
(
nb
)
for
line
in
lines
:
self
.
new_line
(
line
[
0
],
line
[
1
],
line
[
2
:])
self
.
num_begin
=
begin
def
on_forward_button_clicked
(
self
,
widget
):
start
,
end
=
self
.
history_buffer
.
get_bounds
()
...
...
@@ -86,9 +90,11 @@ class History_window:
end
=
begin
+
50
if
end
>
self
.
nb_line
:
end
=
self
.
nb_line
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, end))
self
.
num_begin
=
self
.
nb_line
nb
,
lines
=
gajim
.
logger
.
read
(
self
.
jid
,
begin
,
end
)
self
.
set_buttons_sensitivity
(
nb
)
for
line
in
lines
:
self
.
new_line
(
line
[
0
],
line
[
1
],
line
[
2
:])
self
.
num_begin
=
begin
def
on_latest_button_clicked
(
self
,
widget
):
start
,
end
=
self
.
history_buffer
.
get_bounds
()
...
...
@@ -100,50 +106,46 @@ class History_window:
begin
=
self
.
nb_line
-
50
if
begin
<
0
:
begin
=
0
#FIXME:
# self.plugin.send('LOG_GET_RANGE', None, (self.jid, begin, self.nb_line))
self
.
num_begin
=
self
.
nb_line
nb
,
lines
=
gajim
.
logger
.
read
(
self
.
jid
,
begin
,
self
.
nb_line
)
self
.
set_buttons_sensitivity
(
nb
)
for
line
in
lines
:
self
.
new_line
(
line
[
0
],
line
[
1
],
line
[
2
:])
self
.
num_begin
=
begin
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
]
==
50
:
def
set_buttons_sensitivity
(
self
,
nb
):
if
nb
==
50
:
self
.
earliest_button
.
set_sensitive
(
False
)
self
.
previous_button
.
set_sensitive
(
False
)
if
infos
[
0
]
==
self
.
nb_line
:
if
nb
==
self
.
nb_line
:
self
.
forward_button
.
set_sensitive
(
False
)
self
.
latest_button
.
set_sensitive
(
False
)
def
new_line
(
self
,
date
,
type
,
data
):
"""
write a new line
"""
start_iter
=
self
.
history_buffer
.
get_start_iter
()
end_iter
=
self
.
history_buffer
.
get_end_iter
()
tim
=
time
.
strftime
(
"
[%x %X]
"
,
time
.
localtime
(
float
(
infos
[
1
]
)))
tim
=
time
.
strftime
(
'
[%x %X]
'
,
time
.
localtime
(
float
(
date
)))
self
.
history_buffer
.
insert
(
start_iter
,
tim
)
if
infos
[
2
]
==
'
recv
'
:
msg
=
'
:
'
.
join
(
infos
[
3
]
[
0
:])
if
type
==
'
recv
'
:
msg
=
'
:
'
.
join
(
data
[
0
:])
msg
=
msg
.
replace
(
'
\\
n
'
,
'
\n
'
)
self
.
history_buffer
.
insert_with_tags_by_name
(
start_iter
,
msg
,
\
'
incoming
'
)
elif
infos
[
2
]
==
'
sent
'
:
msg
=
'
:
'
.
join
(
infos
[
3
]
[
0
:])
elif
type
==
'
sent
'
:
msg
=
'
:
'
.
join
(
data
[
0
:])
msg
=
msg
.
replace
(
'
\\
n
'
,
'
\n
'
)
self
.
history_buffer
.
insert_with_tags_by_name
(
start_iter
,
msg
,
\
'
outgoing
'
)
else
:
msg
=
'
:
'
.
join
(
infos
[
3
]
[
1
:])
msg
=
'
:
'
.
join
(
data
[
1
:])
msg
=
msg
.
replace
(
'
\\
n
'
,
'
\n
'
)
self
.
history_buffer
.
insert_with_tags_by_name
(
start_iter
,
\
_
(
'
Status is now:
'
)
+
infos
[
3
]
[
0
]
+
'
:
'
+
msg
,
'
status
'
)
_
(
'
Status is now:
'
)
+
data
[
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
.
nb_line
=
gajim
.
logger
.
get_nb_line
(
jid
)
xml
=
gtk
.
glade
.
XML
(
GTKGUI_GLADE
,
'
history_window
'
,
APP
)
self
.
window
=
xml
.
get_widget
(
'
history_window
'
)
self
.
history_buffer
=
xml
.
get_widget
(
'
history_textview
'
).
get_buffer
()
...
...
@@ -161,6 +163,12 @@ class History_window:
tagStatus
=
self
.
history_buffer
.
create_tag
(
'
status
'
)
color
=
gajim
.
config
.
get
(
'
statusmsgcolor
'
)
tagStatus
.
set_property
(
'
foreground
'
,
color
)
begin
=
0
if
self
.
nb_line
>
50
:
begin
=
self
.
nb_line
-
50
nb
,
lines
=
gajim
.
logger
.
read
(
self
.
jid
,
begin
,
self
.
nb_line
)
self
.
set_buttons_sensitivity
(
nb
)
for
line
in
lines
:
self
.
new_line
(
line
[
0
],
line
[
1
],
line
[
2
:])
self
.
num_begin
=
begin
self
.
window
.
show_all
()
#FIXME:
# self.plugin.send('LOG_NB_LINE', None, jid)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment