-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkLOR.tcl
executable file
·2653 lines (2302 loc) · 76.3 KB
/
tkLOR.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
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
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
############################################################################
# tkLOR -- Client for reading www.linux.org.ru site #
# Copyright (C) 2008 Alexander Galanin <gaa.nnov@mail.ru> #
# #
# 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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
############################################################################
# \
exec wish "$0" "$@"
package require Tcl 8.4
package require Tk 8.4
package require tile 0.8
package require htmlparse 1.1
package require struct::stack 1.3
package require msgcat 1.3
namespace import ::msgcat::*
set appName "tkLOR"
set appVersion "APP_VERSION"
set appId "$appName $appVersion $tcl_platform(os) $tcl_platform(osVersion) $tcl_platform(machine)"
set appHome "http://code.google.com/p/tklor/"
set bugzillaURL "http://code.google.com/p/tklor/issues/list"
set xdg_config_home ""
catch {set xdg_config_home $::env(XDG_CONFIG_HOME)}
if { $xdg_config_home == "" } {
set xdg_config_home [ file join $::env(HOME) ".config" ]
}
set configDir [ file join $xdg_config_home $appName ]
set xdg_cache_home ""
catch {set xdg_cache_home $::env(XDG_CACHE_HOME)}
if { $xdg_cache_home == "" } {
set xdg_cache_home [ file join $::env(HOME) ".cache" ]
}
set cacheDir [ file join $xdg_cache_home $appName ]
set tclshPath [ auto_execok "tclsh" ]
if {[ string first Windows $tcl_platform(os) ] == -1} {
set libDir "/usr/lib/tkLOR"
} else {
set libDir ".\\lib"
}
############################################################################
# VARIABLES #
############################################################################
set messageTextWidget ""
set topicTree ""
set messageTree ""
set horPane ""
set tasksWidget ""
set currentSubject ""
set currentNick ""
set currentTopic ""
set currentMessage ""
set lastId 0
set topicHeader ""
set lorLogin ""
set lorPassword ""
set useProxy 0
set proxyAutoSelect 0
set proxyHost ""
set proxyPort ""
set proxyAuthorization 0
set proxyUser ""
set proxyPassword ""
set browser ""
set ignoreList ""
set userTagList {{maxcom "project coordinator"} {anonymous "spirit of LOR"}}
set menuMessage ""
set messageMenu ""
set menuTopic ""
set topicMenu ""
set messageTextMenu ""
set autonomousMode 0
set expandNewMessages 1
set updateOnStart 0
set doubleClickAllTopics 1
set markIgnoredMessagesAsRead 0
set threadListSize 20
set perspectiveAutoSwitch 1
set currentPerspective navigation
set navigationSashPos 50
set readingSashPos 20
set colorList {{tklor blue foreground}}
set colorCount [ llength $colorList ]
# Mail queues
set draft ""
set sent ""
set outcoming ""
# dirty hack: at current moment tile does not provide interface to get current theme
if [ catch {set tileTheme $::ttk::currentTheme} ] {
set tileTheme "default"
}
set findString ""
set findPos ""
set messageTextFont [ font actual system ]
set messageTextMonospaceFont "-family Courier"
set messageTextQuoteFont "-slant italic"
set forumVisibleGroups {126 1339 1340 1342 4066 4068 7300 8403 8404 9326 10161 19109 19390}
set tasksWidgetVisible 0
set loadTaskId ""
set deliverTaskId ""
set loggedIn 0
set rightViewState "UNKNOWN"
set debug 0
set plugins ""
array set fontPart {
none ""
item "-family Sans"
unread "-weight bold"
child "-slant italic"
ignored "-overstrike 1"
}
array set color {
htmlFg "black"
htmlBg "white"
}
set options {
"Global options" {
"Widget theme" readOnlyCombo tileTheme { ttk::style theme names }
"Autonomous mode" hidden autonomousMode ""
"Update topics list on start" check updateOnStart ""
"Use double-click to open topic" check doubleClickAllTopics ""
"Browser" editableCombo browser { list "sensible-browser" "opera" "mozilla" "konqueror" "iexplore.exe" }
"Thread history size" string threadListSize ""
"Expand new messages" check expandNewMessages ""
"Mark messages from ignored users as read" check markIgnoredMessagesAsRead ""
"Auto-switch perspective" check perspectiveAutoSwitch ""
"Current perspective" hidden currentPerspective ""
"Sash position(navigation), %" string navigationSashPos ""
"Sash position(reading), %" string readingSashPos ""
}
"Connection" {
"LOR login" string lorLogin ""
"LOR password" password lorPassword ""
"Use proxy" check useProxy ""
"Proxy auto-config" check proxyAutoSelect ""
"Proxy host" string proxyHost ""
"Proxy port" string proxyPort ""
"Proxy autorization" check proxyAuthorization ""
"Proxy user" string proxyUser ""
"Proxy password" password proxyPassword ""
}
"Ignored users" {
"Ignore list" list ignoreList { list [ list "Nick" ] "addIgnoreListItem" "modifyIgnoreListItem" }
}
"User tags" {
"Tags" list userTagList { list [ list "Nick" "Tag" ] "addUserTagListItem" "modifyUserTagListItem" }
}
"Colors" {
"Message colors" list colorList { list [ list "Regexp" "Color" "Element" ] "addColorListItem" "modifyColorListItem" }
}
"Fonts" {
"Normal font" font fontPart(item) ""
"Unread font" font fontPart(unread) ""
"Unread childs font" font fontPart(child) ""
"Ignored font" font fontPart(ignored) ""
}
"Message text" {
"Normal font" font messageTextFont ""
"Monospace font" font messageTextMonospaceFont ""
"Quote font" font messageTextQuoteFont ""
}
"Forum groups" {
"Visible forum groups" selectList forumVisibleGroups {set lor::forumGroups}
}
}
############################################################################
# FUNCTIONS #
############################################################################
proc initMenu {} {
global topicTree messageTree
global messageMenu topicMenu messageTextMenu
global menuTopic menuMessage
menu .menu -tearoff 0
.menu add cascade \
-label [ mc "LOR" ] \
-menu .menu.lor \
-underline 0
.menu add cascade \
-label [ mc "View" ] \
-menu .menu.view \
-underline 0
.menu add cascade \
-label [ mc "Topic" ] \
-menu .menu.topic \
-underline 0 \
-state disabled
.menu add cascade \
-label [ mc "Message" ] \
-menu .menu.message \
-underline 0 \
-state disabled
.menu add cascade \
-label [ mc "Search" ] \
-menu .menu.search \
-underline 0 \
-state disabled
.menu add cascade \
-label [ mc "Help" ] \
-menu .menu.help \
-underline 0
set m [ menu .menu.lor -tearoff 0 ]
$m add command \
-label [ mc "Add topic..." ] \
-command addTopic
$m add command \
-label [ mc "Search new topics" ] \
-accelerator "F2" \
-command updateTopicList
$m add command \
-label [ mc "Clear old topics..." ] \
-command clearOldTopics
$m add separator
$m add checkbutton \
-label [ mc "Autonomous mode" ] \
-variable autonomousMode
$m add command \
-label [ mc "Send queued messages" ] \
-command startDelivery
$m add separator
$m add command \
-label [ mc "Options..." ] \
-command showOptionsDialog
$m add separator
$m add command \
-label [ mc "Exit" ] \
-accelerator "Alt-F4" \
-command exitProc
set m [ menu .menu.view -tearoff 0 ]
$m add radiobutton \
-label [ mc "Navigation perspective" ] \
-accelerator "Ctrl-Z" \
-command {setPerspective navigation -force} \
-value navigation \
-variable currentPerspective
$m add radiobutton \
-label [ mc "Reading perspective" ] \
-accelerator "Ctrl-X" \
-command {setPerspective reading -force} \
-value reading \
-variable currentPerspective
$m add separator
$m add checkbutton \
-label [ mc "Auto switch" ] \
-variable perspectiveAutoSwitch
set menuTopic [ menu .menu.topic -tearoff 0 ]
set topicMenu [ menu .topicMenu -tearoff 0 ]
set menuMessage [ menu .menu.message -tearoff 0 ]
set messageMenu [ menu .messageMenu -tearoff 0 ]
set m $menuMessage
$m add command -label [ mc "Refresh messages" ] -accelerator "F5" -command refreshTopic
$m add separator
foreach {m invoke} [ list \
$menuTopic invokeMenuCommand \
$topicMenu invokeItemCommand ] {
$m add command -label [ mc "Refresh sub-tree" ] -command [ list $invoke $topicTree refreshTopicSubList ] -accelerator "F4"
$m add separator
}
foreach {m w invoke} [ list \
$menuTopic $topicTree invokeMenuCommand \
$topicMenu $topicTree invokeItemCommand \
$menuMessage $messageTree invokeMenuCommand \
$messageMenu $messageTree invokeItemCommand ] {
$m add command -label [ mc "Reply" ] -accelerator "Ctrl-R" -command [ list $invoke $w reply ]
$m add command -label [ mc "Open in browser" ] -accelerator "Ctrl-O" -command [ list $invoke $w openMessage ]
$m add command -label [ mc "Go to next unread" ] -accelerator n -command [ list $invoke $w nextUnread ]
$m add cascade -label [ mc "Mark" ] -menu $m.mark
set mm [ menu $m.mark -tearoff 0 ]
$mm add command -label [ mc "Mark as read" ] -command [ list $invoke $w mark message 0 ] -accelerator "M"
$mm add command -label [ mc "Mark as unread" ] -command [ list $invoke $w mark message 1 ] -accelerator "U"
$mm add command -label [ mc "Mark thread as read" ] -command [ list $invoke $w mark thread 0 ] -accelerator "Ctrl-M"
$mm add command -label [ mc "Mark thread as unread" ] -command [ list $invoke $w mark thread 1 ] -accelerator "Ctrl-U"
$mm add command -label [ mc "Mark all as read" ] -command [ list markAllMessages $w 0 ] -accelerator "Ctrl-Alt-M"
$mm add command -label [ mc "Mark all as unread" ] -command [ list markAllMessages $w 1 ] -accelerator "Ctrl-Alt-U"
$m add cascade -label [ mc "User" ] -menu $m.user
set mm [ menu $m.user -tearoff 0 ]
$mm add command -label [ mc "User info" ] -accelerator "Ctrl-I" -command [ list $invoke $w userInfo ]
$mm add command -label [ mc "Ignore user" ] -command [ list $invoke $w ignoreUser ]
$mm add command -label [ mc "Tag user..." ] -command [ list $invoke $w tagUser . ]
}
foreach {m invoke} [ list \
$menuTopic invokeMenuCommand \
$topicMenu invokeItemCommand ] {
$m add separator
$m add command -label [ mc "Move to favorites..." ] -command [ list $invoke $topicTree addToFavorites ]
$m add command -label [ mc "Clear cache" ] -command [ list $invoke $topicTree clearTopicCache ]
$m add command -label [ mc "Delete" ] -command [ list $invoke $topicTree deleteTopic ]
}
set m [ menu .menu.search -tearoff 0 ]
$m add command -label [ mc "Find..." ] -accelerator "Ctrl-F" -command find
$m add command -label [ mc "Find next" ] -accelerator "F3" -command findNext
set m [ menu .menu.help -tearoff 0 ]
$m add command -label [ mc "Project home" ] -command {openUrl $appHome}
$m add command -label [ mc "Report bug" ] -command {openUrl $bugzillaURL}
$m add command -label [ mc "About LOR" ] -command {openUrl "$::lor::lorUrl/server.jsp"}
$m add separator
$m add command -label [ mc "About" ] -command helpAbout -accelerator "F1"
. configure -menu .menu
set m [ menu .messageTextMenu -tearoff 0 ]
set messageTextMenu $m
$m add command -label [ mc "Copy selection" ] -command {tk_textCopy $messageTextWidget}
$m add command -label [ mc "Open selection in browser" ] -command {tk_textCopy $messageTextWidget;openUrl [ clipboard get ]}
foreach {m invoke} [ list \
$menuMessage invokeMenuCommand \
$messageMenu invokeItemCommand ] {
$m add separator
$m add command \
-label [ mc "Edit" ] \
-accelerator "Ctrl-E" \
-command [ list $invoke $messageTree edit ]
$m add command \
-label [ mc "Delete" ] \
-command [ list $invoke $messageTree deleteMessage ]
}
}
proc initTopicTree {} {
upvar #0 topicTree w
global forumVisibleGroups
set f [ ttk::frame .topicTreeFrame -width 250 -relief sunken ]
set w [ ttk::treeview $f.w -columns {nick unread unreadChild text msg} -displaycolumns {nick unreadChild} -yscrollcommand "$f.scroll set" ]
configureTags $w
$w heading #0 -text [ mc "Title" ] -anchor w
$w heading nick -text [ mc "Nick" ] -anchor w
$w heading unreadChild -text [ mc "Threads" ] -anchor w
$w column #0 -minwidth 100
$w column nick -minwidth 0 -width 10
$w column unreadChild -width 30 -stretch 0
$w insert {} end -id messages -text [ mc "Local folders" ] -values [ list "" 0 0 [ mc "Local folders" ] ]
$w insert messages end -id draft -text [ mc "Draft" ] -values [ list "" 0 0 [ mc "Draft" ] ]
updateItemState $w draft
$w insert messages end -id outcoming -text [ mc "Outcoming" ] -values [ list "" 0 0 [ mc "Outcoming" ] ]
updateItemState $w outcoming
$w insert messages end -id sent -text [ mc "Sent" ] -values [ list "" 0 0 [ mc "Sent" ] ]
updateItemState $w sent
$w insert "" end -id news -text [ mc "News" ] -values [ list "" 0 0 [ mc "News" ] ]
$w insert "" end -id gallery -text [ mc "Gallery" ] -values [ list "" 0 0 [ mc "Gallery" ] ]
$w insert "" end -id votes -text [ mc "Votes" ] -values [ list "" 0 0 [ mc "Votes" ] ]
$w insert "" end -id forum -text [ mc "Forum" ] -values [ list "" 0 0 [ mc "Forum" ] ]
foreach {id title} $::lor::forumGroups {
if { [ lsearch $forumVisibleGroups $id ] != -1 } {
$w insert forum end -id "forum$id" -text $title -values [ list "" 0 0 $title ]
updateItemState $w "forum$id"
}
}
sortChildrens $w "forum"
$w insert "" end -id favorites -text [ mc "Favorites" ] -values [ list "" 0 0 [ mc "Favorites" ] ]
foreach item [ $w children "" ] {
updateItemState $w $item
}
ttk::scrollbar $f.scroll -command "$w yview"
pack $f.scroll -side right -fill y
pack $w -expand yes -fill both
return $f
}
proc initMessageTree {} {
upvar #0 messageTree w
set f [ ttk::frame .messageTreeFrame -relief sunken ]
set w [ ttk::treeview $f.w -columns {nick header time msg unread unreadChild text} -displaycolumns {header time} -xscrollcommand "$f.scrollx set" -yscrollcommand "$f.scrolly set" ]
$w heading #0 -text [ mc "Nick" ] -anchor w
$w heading header -text [ mc "Header" ] -anchor w
$w heading time -text [ mc "Time" ] -anchor w
$w column header -width 1
$w column time -width 1
configureTags $w
ttk::scrollbar $f.scrollx -command "$w xview" -orient horizontal
ttk::scrollbar $f.scrolly -command "$w yview"
grid $w $f.scrolly -sticky nswe
grid $f.scrollx x -sticky nswe
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f
}
proc initMessageWidget {} {
global messageTextWidget
global currentSubject currentNick currentPrevNick currentTime
global messageTextFont
set mf [ ttk::frame .msgFrame -relief sunken ]
set f [ ttk::frame $mf.labels ]
foreach {var label} [ list \
currentSubject [ mc "Subject: " ] \
currentNick [ mc "From: " ] \
currentPrevNick [ mc "To: " ] \
currentTime [ mc "Time: " ] \
] {
grid \
[ ttk::label $f.${var}Label -text $label -anchor w ] \
[ ttk::label $f.${var}Text -textvariable $var ] \
-sticky nswe
}
grid columnconfigure $f 1 -weight 1
grid $f -sticky nswe
set f [ ttk::frame $mf.text ]
set messageTextWidget [ text $f.msg -state disabled -yscrollcommand "$f.scroll set" -setgrid true -wrap word -height 10 ]
ttk::scrollbar $f.scroll -command "$messageTextWidget yview"
grid $messageTextWidget $f.scroll -sticky nswe
grid columnconfigure $f 0 -weight 1
grid rowconfigure $f 0 -weight 1
grid $f -sticky nswe
grid columnconfigure $mf 0 -weight 1
grid rowconfigure $mf 1 -weight 1
return $mf
}
proc initMainWindow {} {
global appName
global tileTheme
global statusBarWidget
global horPane
wm protocol . WM_DELETE_WINDOW exitProc
wm title . $appName
image create photo appIcon -data {
R0lGODlhIAAgAOfbAAMCBAQDBQwCBAUEBgYEBQYFBgYFBwgGBwgHCRcDBQoJCgoJCwsKCwsKDAwL
DQ4NDg8OEBAPEBEQERIQEhIREhISExMSFBQTFRUUFRcWFxgWFhkYGRkYGkcOEHIDBRwbHR0cHh4c
Hh0dHh4dHx4eH4oCBCAfICAfISEfISEgIiIhI5UCBCMiIiMiIyUkJCUkJaYCBKkCBKoCBCgnKLgC
BJ8JC7oCBCsqK8ACBCsrK8MCBLYGCMUCBMgCBKMOENACBC8uLl4kJt0CBNoDBeACBDIyMucCBDQz
NJ8XGTk4ODs6Oz49ProdHj8/P0c9Pm44OZ4rLUVERIk2OHZERZ4+PlZWVldWV1hXWFhYWFlZWVlZ
WrNBQmJiYmxiUX9kMmhnaGhoaLZTVIZoH6hdXW1tbXFxcZVxDnJycnlzXrtgYHV1dHV1dbZpaYl6
RrtoaHt6ent6e3x8fH9/f4B/gMlwcIWGhrSGJLmMKqKKireQFZmOja6RPLyQNK2NjaqZYMCQkc2Z
G86ZKsqeMdqhFdugIaSkpN2iFKWlpNqkILKkpN6mFdqkN9OnM9ymJNylL+CoFcSio+CoFt+mLuWn
F+CpFdyoK9qpNd2qKeaoI+GrFcmko+aqJ+eqJeCsJuKtH+atFNuwMOKxFN6vObCxsOivIeOyFM+q
quezI7O0s9Gsquu4FOu6FOy5Mry9vPLAFL/Av/PCFMDBwPXDFO25uNnEic3OzOjMk+fLydLU0tja
2Ori4OPl4+/k4+rs6uzu7PPu7O/x7/Dy8PDy8fDz8fHz8fLz7/L08vX39Pb49fb49vf49fn48vf5
9/n59vj69/j6+Pn6+Pr6+Pj7+fn7+Pn7+fr9+vr9+/v9+vv9+/v++/v+/P//////////////////
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////yH+EUNyZWF0ZWQgd2l0aCBH
SU1QACH5BAEKAP8ALAAAAAAgACAAAAj+AP8JHEiQ4AgDAz4UXMiw4b8TLoAEGKDAoUWGEEyQYBAA
wIaLIAWeKcIih5aJIUGqQdOm0CETAFJe3BOqVB4/GmLKbAjKlSpYslaZQbCzoSg7gzIZEtQFRdGG
cGidslXs1ZKnDFFhW4YN264JWAkesWKt2rRq2GopmRNWoJJX2px1xZaLBIUQbZsIi9u1GrEsFnRi
LcMM2zFqXY1ViQKgBVYwuLRpw1YNLbY4WAJUwLpGmrZnc7u24pLhwlMneGZFA90Xm68qXyg8neJD
Bx3ElbteI3OlwFMpPIzs4NW12a1UVJ44WPAUSQ8hTKBRTgOjRJ8xCWZgrUHDzbNsmjyN2JABJVGH
F1j1QNKFDJupGER+rAgiQEnYYdqUYZu2BceQMEkI9tQoknX1Cxt/vIGACG39U0cwwCTTSyxySBBA
g//cAEEDHGAQwQMApIDhPwcQAIIIKgAwwIj/8HHHQGJ4waIjkgxkSSANAoJIJ59MMhAhizQYySOe
XDJQI4pQwgiLArHCCSakbFKJRQEBADs=
}
wm iconphoto . -default appIcon
image delete appIcon
set horPane [ ttk::panedwindow .horPaned -orient horizontal ]
grid .horPaned -sticky nwse
.horPaned add [ initTopicTree ] -weight 0
ttk::panedwindow .vertPaned -orient vertical
.horPaned add .vertPaned -weight 1
.vertPaned add [ initMessageTree ] -weight 0
.vertPaned add [ initMessageWidget ] -weight 1
set statusBarWidget [ ttk::frame .statusBar -relief sunken -padding 1 ]
grid \
[ ttk::label $statusBarWidget.text -text "" ] \
[ ttk::progressbar $statusBarWidget.progress -mode indeterminate -orient horizontal ] \
[ ttk::button $statusBarWidget.button -text "^" -command toggleTaskList -width 1 ] \
-sticky nswe
$statusBarWidget.progress configure -mode determinate -value 0
$statusBarWidget.progress state disabled
grid columnconfigure $statusBarWidget 0 -weight 1
grid $statusBarWidget -sticky nswe
grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1
}
proc helpAbout {} {
global appName appVersion
messageBox \
-title [ mc "About %s" $appName ] \
-message [ mc "%s %s" $appName $appVersion ] \
-detail [ mc "Client for reading linux.org.ru written on Tcl/Tk/Tile.\nCopyright (c) 2008 Alexander Galanin (gaa at linux.org.ru)\nLicense: GPLv3" ] \
-parent . \
-type ok
}
proc exitProc {} {
global appName
global currentTopic
set total [ expr [ llength [ ::taskManager::getTasks ] ] / 2 ]
if { $total != 0 } {
if { [ messageBox \
-message [ mc "There are %s running tasks" $total ] \
-detail [ mc "Are you want to exit and stop it?" ] \
-type yesno \
-icon question \
] == "yes" } {
stopAllTasks
} else {
return
}
}
saveTopicToCache $currentTopic
saveTopicListToCache
saveMessageQueuesToCache
saveOptions
exit
}
proc renderHtml {w msg} {
global messageTextMonospaceFont messageTextQuoteFont
set msg [ string trim $msg ]
$w configure -state normal
$w delete 0.0 end
foreach tag [ $w tag names ] {
$w tag delete $tag
}
$w tag configure br -background white
$w tag configure i -font $messageTextQuoteFont
$w tag configure hyperlink
$w tag configure pre -font $messageTextMonospaceFont
$w tag bind hyperlink <Enter> "$w configure -cursor hand1"
$w tag bind hyperlink <Leave> "$w configure -cursor {}"
set stackId [ ::struct::stack ]
::htmlparse::parse -cmd [ list "renderHtmlTag" $w $stackId ] " $msg"
$stackId destroy
$w yview 0.0
$w configure -state disabled
}
proc renderHtmlTag {w stack tag slash param text} {
set text [ ::htmlparse::mapEscapes $text ]
regsub -lineanchor -- {^[\n\r \t]+} $text {} text
regsub -lineanchor -- {[\n\r \t]+$} $text { } text
set tag [ string tolower $tag ]
set pos [ $w index end-1chars ]
if { $slash != "/" } {
switch -exact -- $tag {
pre -
i {
$stack push [ list $tag $pos ]
}
br {
$w insert end "\n"
}
p {
if { [ $w get 0.0 end ] != "\n" } {
$w insert end "\n\n"
}
$stack push [ list $tag $pos ]
}
li {
$w insert end "\n* "
}
a {
if [ regexp -- {href="{0,1}([^"> ]+)"{0,1}} $param dummy url ] {
if { ![ regexp -lineanchor {^\w+://} $url ] } {
set url "$::lor::lorUrl/$url"
}
set tagName [ join [ list "link" [ generateId ] ] "" ]
$w tag configure $tagName -underline 1 -foreground blue
set url [ ::htmlparse::mapEscapes $url ]
regsub -all -- {%} $url {%%} url
$w tag bind $tagName <ButtonPress-1> [ list "openUrl" $url ]
$stack push [ list $tagName $pos ]
} else {
$stack push [ list $tag $pos ]
}
}
img {
set text {[]}
}
}
} else {
switch -exact -- $tag {
pre -
a -
i -
p {
catch {
set list [ $stack pop ]
$w tag add [ lindex $list 0 ] [ lindex $list 1 ] [ $w index end-1chars ]
if { $tag == "a" } {
$w tag add hyperlink [ lindex $list 1 ] [ $w index end-1chars ]
}
}
if { $tag == "a" } {
$w insert end " "
}
}
tr {
$w insert end "\n"
}
td {
$w insert end "\t"
}
}
}
$w insert end $text
}
#TODO: move htmlToText for Subject into lorBackend (v1.2)
proc showMessageInMainWindow {msg} {
global messageTextWidget
global currentSubject currentNick currentPrevNick currentTime
foreach {subj currentNick currentPrevNick currentTime type body} \
[ ::mailUtils::getMailHeaders $msg \
{Subject From To X-LOR-Time Content-Type body} ] \
{
break
}
set currentSubject [ ::htmlparse::mapEscapes $subj ]
if { $type == "" || $type == "text/html" } {
renderHtml $messageTextWidget $body
} else {
set w $messageTextWidget
$w configure -state normal
$w delete 0.0 end
$w insert 0.0 $body
$w configure -state disabled
}
}
proc configureTags {w} {
global fontPart
global colorList
global colorCount
foreach a { none unread } {
foreach b { none child } {
foreach c { none ignored } {
set id [ join [ list "item" $a $b $c ] "_" ]
regsub -all {_none} $id "" id
$w tag configure $id -font [ join [ list $fontPart(item) $fontPart($a) $fontPart($b) $fontPart($c) ] " " ]
}
}
}
for {set i 0} {$i < $colorCount} {incr i} {
$w tag configure "color$i" -foreground "" -background ""
}
for {set i 0} {$i < [ llength $colorList ]} {incr i} {
set color [ lindex [ lindex $colorList $i ] 1 ]
set mode [ lindex [ lindex $colorList $i ] 2 ]
if { $mode == "foreground" } {
$w tag configure "color$i" -foreground $color -background ""
} else {
$w tag configure "color$i" -background $color -foreground ""
}
}
}
proc setTopic {topic} {
global appName
global messageTree messageTextWidget
global currentTopic currentSubject currentNick currentPrevNick currentTime
global expandNewMessages
global loadTaskId
global lastId
if { $loadTaskId != "" } {
catch {
::taskManager::stopTask $loadTaskId
}
set loadTaskId ""
}
update
setPerspective reading
focus $messageTree
if { $currentTopic != "" } {
saveTopicToCache $currentTopic
}
if { $topic == "sent" || $topic == "draft" || $topic == "outcoming" } {
set currentTopic $topic
renderHtml $messageTextWidget ""
clearTreeItemChildrens $messageTree ""
showMessageQueue $topic
return
}
if { $topic != $currentTopic } {
setItemValue $messageTree "" unreadChild 0
clearTreeItemChildrens $messageTree ""
foreach item {currentSubject currentNick currentPrevNick currentTime} {
set $item ""
}
set lastId 0
set currentTopic $topic
set loadTaskId [ loadTopicFromCache $topic [ closure {topic} {} {
global loadTaskId autonomousMode lastId
upvar #0 messageTree w
set loadTaskId ""
if { $autonomousMode && ! [ $w exists "topic" ] } {
goOnline
}
getNewMessages $topic
} ] ]
} else {
getNewMessages $topic
}
}
proc getNewMessages {topic} {
global autonomousMode
global lastId
global loadTaskId
if { $autonomousMode } {
return
}
set parser [ ::mbox::initParser [ list insertMessage 0 ] ]
set onerror [ list errorProc [ mc "Error while getting messages" ] ]
defclosure oncomplete {parser onerror} {} {
global loadTaskId expandNewMessages messageTree
if [ catch {
::mbox::closeParser $parser
} err ] {
lappend onerror $err $::errorInfo
uplevel #0 $onerror
}
set loadTaskId ""
focus $messageTree
updateWindowTitle
if { $expandNewMessages == "1" } {
nextUnread $messageTree ""
focus $messageTree
}
}
set loadTaskId [ callPlugin get [ list $topic -last $lastId ] \
-title [ mc "Getting new messages" ] \
-onoutput [ list ::mbox::parseLine $parser ] \
-oncomplete $oncomplete \
-onerror $onerror \
]
}
proc insertMessage {replace letter} {
upvar #0 messageTree w
global markIgnoredMessagesAsRead
global lastId
array set res $letter
set nick $res(From)
set time $res(X-LOR-Time)
set msg $letter
set header [ ::htmlparse::mapEscapes $res(Subject) ]
if [ info exists res(To) ] {
set id $res(X-LOR-Id)
if [ info exists res(X-LOR-ReplyTo-Id) ] {
set parent $res(X-LOR-ReplyTo-Id)
} else {
set parent "topic"
}
if { $parent == "" } {
set parent "topic"
}
} else {
set id "topic"
set parent ""
}
if [ info exists res(X-LOR-Unread) ] {
set unread $res(X-LOR-Unread)
} else {
set unread 1
}
array unset res
if [ $w exists $id ] {
if { !$replace && $id != "topic" } {
return
}
set unread [ getItemValue $w $id unread ]
} else {
if { ![ $w exists $parent ] } {
set parent ""
}
$w insert $parent end -id $id -text $nick
setItemValue $w $id unreadChild 0
}
foreach i {nick time msg} {
setItemValue $w $id $i [ set $i ]
}
setItemValue $w $id header $header
setItemValue $w $id unread 0
if { $unread && ( ![ isUserIgnored $nick ] || $markIgnoredMessagesAsRead != "1" ) } {
mark $w $id item 1
}
updateItemState $w $id
if { $id == "topic" } {
$w item $id -open 1
set ::topicHeader $header
#TODO: найти более удачное место
saveTopicTextToCache $::currentTopic $letter
}
if { [ string is integer $id ] && $id > $lastId } {
set lastId $id
}
}
proc getItemValue {w item valueName} {
set val [ $w item $item -values ]
set pos [ lsearch -exact [ $w cget -columns ] $valueName ]
return [ lindex $val $pos ]
}
proc setItemValue {w item valueName value} {
set val [ $w item $item -values ]
if { $val == "" } {
set val [ $w cget -columns ]
}
set pos [ lsearch -exact [ $w cget -columns ] $valueName ]
lset val $pos $value
$w item $item -values $val
}
proc click {w item} {
global topicTree
global messageMenu
mark $w $item item 0
if { [ getItemValue $w $item msg ] != "" } {
showMessageInMainWindow [ getItemValue $w $item msg ]
}
if { $w == $topicTree } {
if [ regexp -lineanchor -- {^\d} $item ] {
set ::rightViewState MESSAGE
} elseif { $item == "sent" ||
$item == "draft" ||
$item == "outcoming" } {
set ::rightViewState LOCAL
} else {
updateItemState $w $item
return
}
setTopic $item
} else {
global currentMessage
set currentMessage $item
}
updateItemState $w $item
updateWindowTitle
}
proc addUnreadChild {w item {count 1}} {
if { ![ string is integer [ getItemValue $w $item unreadChild ] ] } {
setItemValue $w $item unreadChild 0
}
setItemValue $w $item unreadChild [ expr [ getItemValue $w $item unreadChild ] + $count ]
if { $item != "" } {
addUnreadChild $w [ $w parent $item ] $count
}
updateItemState $w $item
}
proc getItemText {w item} {
global messageTree
if { $w == $messageTree } {
set text [ getItemValue $w $item nick ]
if [ getItemValue $w $item unreadChild ] {
append text " ([ getItemValue $w $item unreadChild ])"
}
return $text
} else {
return [ getItemValue $w $item text ]
}
}
proc updateItemState {w item} {
global userTagList
global colorList
if { $item == "" } return
set tag "item"
if [ getItemValue $w $item unread ] {
append tag "_unread"
}
if [ getItemValue $w $item unreadChild ] {
append tag "_child"
}
if [ isUserIgnored [ getItemValue $w $item nick ] ] {
append tag "_ignored"
}
set tagList [ list $tag ]
if { $w == $::topicTree } {
set text [ getItemValue $w $item text ]
} else {
set text [ getItemValue $w $item msg ]
}
for {set i 0} {$i < [ llength $colorList ] } {incr i} {
set re [ lindex [ lindex $colorList $i ] 0 ]
if [ regexp -nocase -lineanchor -- $re $text ] {
lappend tagList "color$i"
}
}
$w item $item -tags $tagList
set text [ getItemText $w $item ]
if { $w != $::topicTree } {
foreach i $userTagList {
if { [ lindex $i 0 ] == [ getItemValue $w $item nick ] } {
append text [ join [ list " (" [ lindex $i 1 ] ")" ] "" ]
}