Tkabber

Check-in [4137497f9f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Implemented showing log messages for all JIDs that correspond to a single metacontact. This closes feature request [7619b16aec].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4137497f9f0c122600aa57310dcfb98dac5aad8e
User & Date: sgolovan 2016-01-13 09:17:53
Context
2016-01-13
13:15
Clarified a bit information on the ispell plugin options. check-in: 1e4a40fbfe user: sgolovan tags: trunk
09:17
Implemented showing log messages for all JIDs that correspond to a single metacontact. This closes feature request [7619b16aec]. check-in: 4137497f9f user: sgolovan tags: trunk
09:15
Made the 'current' subcommand for a combobox a synonym for 'getvalue' ('current' is taken from ttk::combobox). check-in: d32f5868fc user: sgolovan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.

1
2
3
4
5
6
7




8
9
10
11
12
13
14
2016-01-13  Sergei Golovan  <sgolovan@nes.ru>

	* plugins/chat/logger.tcl: Fixed bug with names of temporary arrays
	  clash.

	* tk/bwidget.tcl: Made the 'current' subcommand for a combobox a
	  synonym for 'getvalue' ('current' is taken from ttk::combobox).





2016-01-12  Sergei Golovan  <sgolovan@nes.ru>

	* plugins/chat/log_on_open.tcl, plugins/chat/logger.tcl: Read the
	  logged messages not only for the JID which chat window is being
	  opened, but also for all JIDs in a metacontact it belongs. This
	  option is disabled by default. Since the metacontacts info isn't







>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2016-01-13  Sergei Golovan  <sgolovan@nes.ru>

	* plugins/chat/logger.tcl: Fixed bug with names of temporary arrays
	  clash.

	* tk/bwidget.tcl: Made the 'current' subcommand for a combobox a
	  synonym for 'getvalue' ('current' is taken from ttk::combobox).

	* plugins/chat/logger.tcl: Implemented showing log messages for all
	  JIDs that correspond to a single metacontact. This closes feature
	  request [7619b16aec].

2016-01-12  Sergei Golovan  <sgolovan@nes.ru>

	* plugins/chat/log_on_open.tcl, plugins/chat/logger.tcl: Read the
	  logged messages not only for the JID which chat window is being
	  opened, but also for all JIDs in a metacontact it belongs. This
	  option is disabled by default. Since the metacontacts info isn't

Changes to plugins/chat/logger.tcl.

71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
            if {![chat::is_groupchat [chat::chatid $xlib $nas]]} {
                set jid $nas
            }
        }
    }
    $m add command -label [::msgcat::mc "Show history"] \
           -state $state \
           -command [list logger::show_log $jid -connection $xlib]

}

#############################################################################

hook::add chat_create_user_menu_hook \
    [list ::logger::add_menu_item normal chat] 65
hook::add chat_create_conference_menu_hook \







|
>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
            if {![chat::is_groupchat [chat::chatid $xlib $nas]]} {
                set jid $nas
            }
        }
    }
    $m add command -label [::msgcat::mc "Show history"] \
           -state $state \
           -command [list logger::show_log $jid -connection $xlib \
                                                -metacontact 1]
}

#############################################################################

hook::add chat_create_user_menu_hook \
    [list ::logger::add_menu_item normal chat] 65
hook::add chat_create_conference_menu_hook \
266
267
268
269
270
271
272

273
274
275
276

277
278

279
280
281
282



















283

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
































299
300
301

302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

324


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346

#############################################################################

proc ::logger::create_log_viewer {lw jid args} {
    global tcl_platform
    global defaultnick


    foreach {key val} $args {
        switch -- $key {
            -connection { set xlib $val }
            -subdirs { set subdirs $val }

        }
    }

    if {![info exists xlib]} {
        set xlib [lindex [connections] 0]
    }




















    set logfile [jid_to_filename $jid]


    set mynick [get_group_nick $xlib $jid]

    Toplevel $lw -class Chat
    wm group $lw .
    wm withdraw $lw
    set title [::msgcat::mc "History for %s" $jid]
    wm title $lw $title
    wm iconname $lw $title

    set lf [ScrolledWindow $lw.sw]
    set l [Text $lw.log -wrap word -takefocus 0]

    set mf [Frame $lw.mf]
    pack $mf -side top -fill x -expand no -padx 1m -pady 1m
































    set mlabel [Label $mf.mlabel -text [::msgcat::mc "Select month:"]]
    pack $mlabel -side left
    set ebutton [Button $mf.ebutton -text [::msgcat::mc "Export to XHTML"] \

                                    -command [list [namespace current]::export \
                                                   $l $lw.mf.mcombo $logfile $mynick]]
    pack $ebutton -side right
    pack $lf -padx 1m -pady 1m -fill both -expand yes

    $lf setwidget $l

    regsub -all %W [bind Text <Prior>] [double% $l] prior_binding
    regsub -all %W [bind Text <Next>]  [double% $l] next_binding
    bind $lw <Prior> $prior_binding
    bind $lw <Next>  $next_binding

    $l tag configure they -foreground [option get $lw theyforeground Chat]
    $l tag configure me -foreground [option get $lw meforeground Chat]
    $l tag configure server_lab \
       -foreground [option get $lw serverlabelforeground Chat]
    $l tag configure server \
       -foreground [option get $lw serverforeground Chat]

    $l configure -state disabled

    if {![info exists subdirs]} {

        set subdirs [get_subdirs $logfile]


    }

    set ympairs {}
    foreach sd [lsort -decreasing $subdirs] {
        lappend ympairs [describe_month $sd]
    }
    lappend ympairs [::msgcat::mc "All"]

    set mcombo [Combobox $mf.mcombo \
                         -editable no \
                         -exportselection no \
                         -values $ympairs \
                         -modifycmd [list \
                            [namespace current]::change_month \
                                          $mf.mcombo $logfile $l $mynick]]
    $mcombo set [lindex $ympairs 0]
    pack $mcombo -side left

    hook::run open_log_post_hook $xlib $jid $lw

    wm deiconify $lw
}







>




>


>




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

|
>
|
|




















>
|
>
>














|







267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

#############################################################################

proc ::logger::create_log_viewer {lw jid args} {
    global tcl_platform
    global defaultnick

    set metacontact 0
    foreach {key val} $args {
        switch -- $key {
            -connection { set xlib $val }
            -subdirs { set subdirs $val }
            -metacontact { set metacontact $val }
        }
    }

    if {![info exists xlib]} {
        set xlib [lindex [connections] 0]
    }

    if {!$::ifacetk::roster::options(enable_metacontacts) || \
                [llength [info procs ::plugins::metacontacts::*]] == 0} {
        set metacontact 0
    }

    set jids [list $jid]
    if {$metacontact} {
        foreach tag [::plugins::metacontacts::get_all_tags $xlib] {
            set mjids [::plugins::metacontacts::get_jids $xlib $tag]
            foreach j $mjids {
                if {[::xmpp::jid::equal $j $jid]} {
                    set jids $mjids
                    break
                }
            }
        }
    }

    foreach j $jids {
        lappend logfiles [jid_to_filename $j]
    }

    set mynick [get_group_nick $xlib $jid]

    Toplevel $lw -class Chat
    wm group $lw .
    wm withdraw $lw
    set title [::msgcat::mc "History for %s" $jid]
    wm title $lw $title
    wm iconname $lw $title

    set lf [ScrolledWindow $lw.sw]
    set l [Text $lw.log -wrap word -takefocus 0]

    set mf [Frame $lw.mf]
    pack $mf -side top -fill x -expand no -padx 1m -pady 1m

    set jlabel [Label $mf.jlabel -text [::msgcat::mc "Log for:"]]
    pack $jlabel -side left

    if {[llength $logfiles] == 1} {
        set jselect [Label $mf.jselect \
                           -text "[::msgcat::mc {JID}] $jid"]
    } else {
        set textjids [list "[::msgcat::mc {Metacontact}] [lindex $jids 0]"]
        set idx 0
        foreach j $jids {
            if {[::xmpp::jid::equal $j $jid]} {
                set idx [llength $textjids]
            }
            lappend textjids "[::msgcat::mc {JID}] $j"
        }
        set w 0
        foreach textjid $textjids {
            set w [::tcl::mathfunc::max $w [string length $textjid]]
        }
        set jselect [Combobox $mf.jselect \
                         -editable no \
                         -exportselection no \
                         -values $textjids \
                         -width [expr {$w+2}] \
                         -modifycmd [list \
                            [namespace current]::change_month \
                                    $mf.jselect $mf.mcombo $logfiles $l $mynick]]
        $jselect set [lindex $textjids $idx]
    }
    pack $jselect -side left

    set mlabel [Label $mf.mlabel -text "   [::msgcat::mc {Select month:}]"]
    pack $mlabel -side left
    set ebutton [Button $mf.ebutton \
                        -text [::msgcat::mc "Export to XHTML"] \
                        -command [list [namespace current]::export \
                                       $mf.jselect $mf.mcombo $logfiles $mynick]]
    pack $ebutton -side right
    pack $lf -padx 1m -pady 1m -fill both -expand yes

    $lf setwidget $l

    regsub -all %W [bind Text <Prior>] [double% $l] prior_binding
    regsub -all %W [bind Text <Next>]  [double% $l] next_binding
    bind $lw <Prior> $prior_binding
    bind $lw <Next>  $next_binding

    $l tag configure they -foreground [option get $lw theyforeground Chat]
    $l tag configure me -foreground [option get $lw meforeground Chat]
    $l tag configure server_lab \
       -foreground [option get $lw serverlabelforeground Chat]
    $l tag configure server \
       -foreground [option get $lw serverforeground Chat]

    $l configure -state disabled

    if {![info exists subdirs]} {
        foreach lf $logfiles {
            lappend subdirs {*}[get_subdirs $lf]
        }
        set subdirs [lsort -unique $subdirs]
    }

    set ympairs {}
    foreach sd [lsort -decreasing $subdirs] {
        lappend ympairs [describe_month $sd]
    }
    lappend ympairs [::msgcat::mc "All"]

    set mcombo [Combobox $mf.mcombo \
                         -editable no \
                         -exportselection no \
                         -values $ympairs \
                         -modifycmd [list \
                            [namespace current]::change_month \
                                          $mf.jselect $mf.mcombo $logfiles $l $mynick]]
    $mcombo set [lindex $ympairs 0]
    pack $mcombo -side left

    hook::run open_log_post_hook $xlib $jid $lw

    wm deiconify $lw
}
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395
        }
    }

    set logfile [jid_to_filename $jid]
    set mynick [get_group_nick "" $jid]

    set log $lw.log

    set cbox $lw.mf.mcombo

    set ympairs [$cbox cget -values]
    if {[info exists when]} {
        set text [describe_month $when]
        if {$text ni $ympairs} {
            error "no log entries for: $when"
        }
    } else {
        set text [lindex $ympairs 0]
    }

    $cbox set $text


    change_month $cbox $logfile $log $mynick

    if {[info exists timestamp]} {
        set pos [lindex [$log tag ranges TS-$timestamp] 0]
        if {$pos == ""} { set pos end }
    } else {
        set pos end
    }







>














>
|







427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
        }
    }

    set logfile [jid_to_filename $jid]
    set mynick [get_group_nick "" $jid]

    set log $lw.log
    set jbox $lw.mf.jselect
    set cbox $lw.mf.mcombo

    set ympairs [$cbox cget -values]
    if {[info exists when]} {
        set text [describe_month $when]
        if {$text ni $ympairs} {
            error "no log entries for: $when"
        }
    } else {
        set text [lindex $ympairs 0]
    }

    $cbox set $text

    # TODO
    change_month $jbox $cbox [list $logfile] $log $mynick

    if {[info exists timestamp]} {
        set pos [lindex [$log tag ranges TS-$timestamp] 0]
        if {$pos == ""} { set pos end }
    } else {
        set pos end
    }
486
487
488
489
490
491
492
493
494
495









496
497
498


499






500


501
502
503
504
505


506


507
508
509
510
511
512
513
        }
    }
    $l configure -state disabled
}

#############################################################################

proc ::logger::change_month {mcombo logfile l mynick} {
    variable m2d










    set month [$mcombo get]
    if {$month == [::msgcat::mc "All"]} {
        draw_messages $l {} $mynick


        foreach m [lsort -increasing [get_subdirs $logfile]] {






            add_messages $l [read_hist_from_file $logfile $m] $mynick


            update
        }
    } else {
        set my_list [split $month " "]
        set month [lindex $my_list end]-$m2d([join [lrange $my_list 0 end-1] " "])


        draw_messages $l [read_hist_from_file $logfile $month] $mynick


    }
    $l see end
}

#############################################################################

proc ::logger::read_hist_from_file {logfile month} {







|


>
>
>
>
>
>
>
>
>

<
|
>
>
|
>
>
>
>
>
>
|
>
>





>
>
|
>
>







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
        }
    }
    $l configure -state disabled
}

#############################################################################

proc ::logger::change_month {jselect mcombo logfiles l mynick} {
    variable m2d

    if {[catch {$jselect current} jidx]} {
        # jselect is a label
        set jidx -1
    }
    incr jidx -1
    if {$jidx >= 0 && [llength $logfiles] > 1} {
        set logfiles [list [lindex $logfiles $jidx]]
    }

    set month [$mcombo get]

    draw_messages $l {} $mynick
    if {$month == [::msgcat::mc "All"]} {
        foreach logfile $logfiles {
            foreach m [get_subdirs $logfile] {
                lappend tmp($m) $logfile
            }
        }
        foreach m [lsort -unique -increasing [array names tmp]] {
            set hist {}
            foreach logfile $logfiles {
                lappend hist {*}[read_hist_from_file $logfile $m]
            }
            add_messages $l [lsort -index 1 $hist] $mynick
            update
        }
    } else {
        set my_list [split $month " "]
        set month [lindex $my_list end]-$m2d([join [lrange $my_list 0 end-1] " "])
        set hist {}
        foreach logfile $logfiles {
            lappend hist {*}[read_hist_from_file $logfile $month]
        }
        add_messages $l [lsort -index 1 $hist] $mynick
    }
    $l see end
}

#############################################################################

proc ::logger::read_hist_from_file {logfile month} {
586
587
588
589
590
591
592
593
594
595









596

597






598
599
600


601
602
603
604


605


606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
        }
    }
    return $messages
}

#############################################################################

proc ::logger::export {lw mcombo logfile mynick} {
    variable m2d










    set month [$mcombo get]

    if {$month == [::msgcat::mc "All"]} {






        set hist {}
        foreach m [lsort -increasing [get_subdirs $logfile]] {
            set hist [concat $hist [read_hist_from_file $logfile $m]]


        }
    } else {
        set my_list [split $month " "]
        set month [lindex $my_list end]-$m2d([join [lrange $my_list 0 end-1] " "])


        set hist [read_hist_from_file $logfile $month]


    }

    set filename [tk_getSaveFile -defaultextension .html]
    if {$filename == ""} return
    set fd [open $filename w]
    fconfigure $fd -encoding utf-8

    puts $fd {<?xml version="1.0" encoding="UTF-8"?>}
    puts $fd {<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">}
    puts $fd {<html xmlns="http://www.w3.org/1999/xhtml">}
    set head [::xmpp::xml::create head \
                  -subelement [::xmpp::xml::create link \
                                      -attrs {rel stylesheet
                                              type text/css
                                              href tkabber-logs.css}]]
    puts $fd [::xmpp::xml::toText $head]


    foreach vars $hist {
        array unset tmp
        if {[catch {array set tmp $vars}]} continue

        set subtags {}
        if {[info exists tmp(timestamp)]} {







|


>
>
>
>
>
>
>
>
>

>

>
>
>
>
>
>
|
|
|
>
>




>
>
|
>
>










<
<
<
|
<
|
|







670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721



722

723
724
725
726
727
728
729
730
731
        }
    }
    return $messages
}

#############################################################################

proc ::logger::export {jselect mcombo logfiles mynick} {
    variable m2d

    if {[catch {$jselect current} jidx]} {
        # jselect is a label
        set jidx -1
    }
    incr jidx -1
    if {$jidx >= 0 && [llength $logfiles] > 1} {
        set logfiles [list [lindex $logfiles $jidx]]
    }

    set month [$mcombo get]
    set hist {}
    if {$month == [::msgcat::mc "All"]} {
        foreach logfile $logfiles {
            foreach m [get_subdirs $logfile] {
                lappend tmp($m) $logfile
            }
        }
        foreach m [lsort -unique -increasing [array names tmp]] {
            set h {}
            foreach logfile $logfiles {
                lappend h {*}[read_hist_from_file $logfile $m]
            }
            lappend hist {*}[lsort -index 1 $h]
        }
    } else {
        set my_list [split $month " "]
        set month [lindex $my_list end]-$m2d([join [lrange $my_list 0 end-1] " "])
        set h {}
        foreach logfile $logfiles {
            lappend h {*}[read_hist_from_file $logfile $month]
        }
        lappend hist {*}[lsort -index 1 $h]
    }

    set filename [tk_getSaveFile -defaultextension .html]
    if {$filename == ""} return
    set fd [open $filename w]
    fconfigure $fd -encoding utf-8

    puts $fd {<?xml version="1.0" encoding="UTF-8"?>}
    puts $fd {<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">}
    puts $fd {<html xmlns="http://www.w3.org/1999/xhtml">}



    puts $fd {<head><style type="text/css">}

    puts $fd [write_css]
    puts $fd {</style></head>}

    foreach vars $hist {
        array unset tmp
        if {[catch {array set tmp $vars}]} continue

        set subtags {}
        if {[info exists tmp(timestamp)]} {
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
                        -subelements $subtags]

        puts $fd [::xmpp::xml::toText $msg]
    }

    puts $fd {</html>}
    close $fd

    write_css $lw [file join [file dirname $filename] tkabber-logs.css]
}

#############################################################################

proc ::logger::write_css {lw filename} {
    set fd [open $filename w]

    puts $fd "
html body {
    background-color: white;
    color: black;
}

.me {
    color: red;
}

.they {
    color: blue;
}

.server {
    color: green;
}
"

    close $fd
}

#############################################################################

proc ::logger::convert_subdir_log {t logfrom logto jid dir} {
    if {[catch {
            set fd [cdopen $logfrom r]







<
<




|
<
|
<

















<
<







771
772
773
774
775
776
777


778
779
780
781
782

783

784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800


801
802
803
804
805
806
807
                        -subelements $subtags]

        puts $fd [::xmpp::xml::toText $msg]
    }

    puts $fd {</html>}
    close $fd


}

#############################################################################

proc ::logger::write_css {} {

    return "

html body {
    background-color: white;
    color: black;
}

.me {
    color: red;
}

.they {
    color: blue;
}

.server {
    color: green;
}
"


}

#############################################################################

proc ::logger::convert_subdir_log {t logfrom logto jid dir} {
    if {[catch {
            set fd [cdopen $logfrom r]