This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpn.py
executable file
·2905 lines (2531 loc) · 136 KB
/
xpn.py
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
#!/usr/bin/env python
import os,shutil
#os.environ['PATH'] += ';'+os.path.join('gtk/lib')+';'+os.path.join('gtk/bin') #OLD
#os.environ['PATH'] = os.path.join('gtk/lib')+';'+os.path.join('gtk/bin')+';'+os.path.join('gtk\\lib')+';'+os.path.join('gtk\\bin')+';'+os.environ['PATH'] #NEW
#py2exe 0.6.8 problem
import email
import email.mime.text
import email.iterators
import email.generator
import email.utils
#py2exe 0.6.8 problem
import sys
import gtk
import gobject
import pango
import cPickle
import time
import re
import platform
import glob
import gettext
import locale
import webbrowser
import ConfigParser
from urllib import quote as url_quote
from optparse import OptionParser
from email.Utils import parsedate_tz, mktime_tz
from xpn_src.Groups_Pane import Groups_Pane
from xpn_src.Threads_Pane import Threads_Pane
from xpn_src.Article_Pane import Article_Pane
from xpn_src.Groups_Win import Groups_Win
from xpn_src.Config_File import Config_File
from xpn_src.Config_Win import Config_Win
from xpn_src.Edit_Win import Edit_Win
from xpn_src.Edit_Mail_Win import Edit_Mail_Win
from xpn_src.Dialogs import About_Dialog, Dialog_YES_NO, Error_Dialog, MidDialog, Dialog_OK, Dialog_Import_Newsrc
from xpn_src.Article import Article, Article_To_Send
from xpn_src.Show_Logs import Logs_Window
from xpn_src.Newsrc import ImportNewsrc, ExportNewsrc
from xpn_src.Find_Win import Find_Win, Search_Win, GlobalSearch
from xpn_src.Score import Score_Rules, Score_Win
from xpn_src.Charset_List import load_ordered_list
from xpn_src.Connections_Handler import Connection, SMTPConnection, SSLConnection
from xpn_src.UserDir import UserDir, get_wdir
from xpn_src.Outbox_Manager import Outbox_Manager
from xpn_src.KeyBindings import KeyBindings, load_shortcuts
from xpn_src.Server_Win import NNTPServer_Win
from xpn_src.Groups_Vs_ID import Groups_Vs_ID
from xpn_src.Articles_DB import Articles_DB, Groups_DB
from xpn_src.Custom_Search_Entry import Custom_Search_Entry
try:
set()
except:
from sets import Set as set
try:
user_system=" ; "+platform.system()
except:
user_system=""
NUMBER="1.2.6"
VERSION="XPN/%s (Street Spirit%s)" % (NUMBER,user_system)
gettext.NullTranslations()
gettext.install("xpn")
ui_string="""<ui>
<menubar name='MainMenuBar'>
<menu action='File'>
<menuitem action='groups' />
<separator/>
<menuitem action='rules' />
<separator/>
<menuitem action='logs' />
<separator/>
<menuitem action='exp_newsrc' />
<menuitem action='imp_newsrc' />
<separator />
<menuitem action='accelerator' />
<separator />
<menuitem action='conf' />
<separator />
<menuitem action='exit' />
</menu>
<menu action='Search'>
<menuitem action='find' />
<menuitem action='global' />
<menuitem action='filter' />
<separator />
<menuitem action='search' />
</menu>
<menu action ='View'>
<menu action='view_articles_opts'>
<menuitem action='raw' />
<menuitem action='spoiler' />
<menuitem action='show_quote' />
<menuitem action='show_sign' />
<menuitem action='fixed' />
<menuitem action='show_hide_headers' />
<menuitem action='rot13' />
</menu>
<separator />
<menu action='view_group_opts'>
<menuitem action='show_threads' />
<menuitem action='show_all_read_threads' />
<menuitem action='show_threads_without_watched' />
<menuitem action='show_read_articles' />
<menuitem action='show_unread_articles' />
<menuitem action='show_kept_articles' />
<menuitem action='show_unkept_articles' />
<menuitem action='show_watched_articles' />
<menuitem action='show_ignored_articles' />
<menuitem action='show_unwatchedignored_articles' />
<menuitem action='show_score_neg_articles' />
<menuitem action='show_score_zero_articles' />
<menuitem action='show_score_pos_articles' />
</menu>
</menu>
<menu action ='Navigate'>
<menuitem action='group' />
<separator />
<menuitem action='previous' />
<menuitem action='next' />
<menuitem action='next_unread' />
<menuitem action='parent' />
<menuitem action='one_key' />
<menuitem action='move_up' />
<separator />
<menuitem action='focus_groups' />
<menuitem action='focus_threads' />
<menuitem action='focus_article' />
<separator />
<menuitem action='zoom_groups' />
<menuitem action='zoom_threads' />
<menuitem action='zoom_article' />
</menu>
<menu action='Subscribed'>
<menuitem action='gethdrs' />
<menuitem action='gethdrssel' />
<menuitem action='getbodies' />
<menuitem action='getbodiessel' />
<separator />
<menuitem action='expand_row' />
<menuitem action='collapse_row' />
<menuitem action='expand' />
<menuitem action='collapse' />
<separator />
<menu action='mark_group'>
<menuitem action='mark' />
<menuitem action='mark_unread_group' />
<menuitem action='mark_download_group' />
<menuitem action='keepall' />
<separator />
<menuitem action='markall' />
<menuitem action='markall_unread' />
</menu>
<separator />
<menuitem action='apply_score' />
<separator />
<menuitem action='groups_vs_id' />
</menu>
<menu action='Articles'>
<menuitem action='post' />
<menuitem action='followup' />
<menuitem action='reply' />
<menuitem action='outbox_manager' />
<separator />
<menuitem action='cancel' />
<menuitem action='supersede' />
<separator />
<menu action='flags'>
<menuitem action='mark_read' />
<menuitem action='mark_unread' />
<menuitem action='mark_download' />
<menuitem action='keep' />
<menuitem action='delete' />
<separator />
<menuitem action='mark_read_sub' />
<menuitem action='mark_unread_sub' />
<menuitem action='mark_download_sub' />
<menuitem action='keep_sub' />
<menuitem action='watch' />
<menuitem action='ignore' />
<separator />
<menuitem action='raise_score' />
<menuitem action='lower_score' />
<menuitem action='set_score' />
</menu>
</menu>
<menu action='Help'>
<menuitem action='about' />
</menu>
</menubar>
<popup action='mark_group'>
<menuitem action='mark' />
<menuitem action='mark_unread_group' />
<menuitem action='mark_download_group' />
<menuitem action='keepall' />
<separator />
<menuitem action='markall' />
<menuitem action='markall_unread' />
</popup>
<popup action='flags'>
<menuitem action='mark_read' />
<menuitem action='mark_unread' />
<menuitem action='mark_download' />
<menuitem action='keep' />
<menuitem action='delete' />
<separator />
<menuitem action='mark_read_sub' />
<menuitem action='mark_unread_sub' />
<menuitem action='mark_download_sub' />
<menuitem action='keep_sub' />
<menuitem action='watch' />
<menuitem action='ignore' />
<separator />
<menuitem action='raise_score' />
<menuitem action='lower_score' />
<menuitem action='set_score' />
</popup>
<toolbar name='MainToolBar'>
<toolitem action='groups' />
<toolitem action='gethdrs' />
<toolitem action='getbodies' />
<toolitem action='mark' />
<toolitem action='markall' />
<separator />
<toolitem action='post' />
<toolitem action='followup' />
<toolitem action='reply' />
<toolitem action='outbox_manager' />
<separator />
<toolitem action='previous' />
<toolitem action='next' />
<toolitem action='next_unread' />
<toolitem action='rot13' />
<separator />
<toolitem action='expand_row' />
<toolitem action='collapse_row' />
<toolitem action='expand' />
<toolitem action='collapse' />
<separator />
<toolitem action='rules' />
<toolitem action='conf' />
</toolbar>
</ui>"""
def escape(data):
"""Escape &, <, and > in a string of data.
"""
# must do ampersand first
data = data.replace("&", "&")
data = data.replace(">", ">")
data = data.replace("<", "<")
return data
class MainWin:
def open_logs_win(self,object):
self.logs_win=Logs_Window(self.window)
def open_groups_win(self,object):
self.win2=Groups_Win(self)
self.win2.show()
def open_configure_win(self,object):
self.save_sizes()
self.win3=Config_Win(self.conf,self)
self.win3.show()
def open_rules_win(self,object):
self.score_win=Score_Win(self.score_rules,self)
self.score_win.show()
def open_groups_vs_id(self,object):
self.groups_vs_id=Groups_Vs_ID(self.subscribed_groups,self)
self.groups_vs_id.show()
def supersede_cancel_message(self,object,mode):
group_selected=""
id_name=""
model,path,iter_selected=self.groups_pane.get_first_selected_row()
if iter_selected!=None:
group_selected=model.get_value(iter_selected,0)
id_name=self.get_id_for_group(group_selected)
model,iter_selected=self.threads_pane.threads_tree.get_selection().get_selected()
subj=""
cp_id=ConfigParser.ConfigParser()
cp_id.read(os.path.join(get_wdir(),"dats","id.txt"))
if iter_selected!=None:
#subj=model.get_value(iter_selected,1).decode("utf-8")
article=self.threads_pane.get_article(model,iter_selected)
subj=article.subj
try:
article.ngroups
except AttributeError:
self.statusbar.push(1,_("First you have to read the article"))
else:
nick=cp_id.get(id_name,"nick")
email=cp_id.get(id_name,"email")
user=nick+" <"+email+">"
if article.user_agent.startswith("XPN") and user==article.from_name:
if mode=="Supersede":
self.win4=Edit_Win(self.configs,article.ngroups,article,None,self.subscribed_groups,"Supersede",server_name=self.current_server,id_name=id_name)
#self.win4.show()
else:
message=Dialog_YES_NO(_("Do you want to CANCEL this article?\n\nSubject: %s ""\nMessage-ID: %s") % (article.subj.encode("utf-8"),escape(article.msgid.encode("utf-8"))))
if message.resp:
canc_mess=Article_To_Send(article.ngroups,user,"cmsg cancel "+article.msgid,"",VERSION,"us-ascii",load_ordered_list(),["Cancel Message for "+article.msgid],["Control"],["cancel "+article.msgid],cp_id.get(id_name,"gen_mid"),cp_id.get(id_name,"fqdn"))
cancel_message=canc_mess.get_article()
message,articlePosted=self.connectionsPool[self.current_server].sendArticle(cancel_message)
if articlePosted:
self.statusbar.push(1,_("Cancel Article Sent: ")+message)
else:
self.statusbar.push(1,message)
else:
self.statusbar.push(1,_("You can Cancel/Supersede only your articles"))
def open_outbox_manager(self,obj):
self.win_outbox=Outbox_Manager(self,VERSION)
self.win_outbox.show()
def open_edit_win(self,object,is_followup=False):
group=""
id_name=""
model,path,iter_selected=self.groups_pane.get_first_selected_row()
if iter_selected!=None:
group=model.get_value(iter_selected,0)
id_name=self.get_id_for_group(group)
if is_followup:
#this is a followup
model,iter_selected=self.threads_pane.threads_tree.get_selection().get_selected()
subj=""
if iter_selected!=None:
#subj=model.get_value(iter_selected,1).decode("utf-8")
article=self.threads_pane.get_article(model,iter_selected)
subj=article.subj
group=article.original_group
try:
article.ngroups
except AttributeError:
self.statusbar.push(1,_("First you have to read the article"))
else:
self.threads_pane.update_article_icon("fup")
bounds=self.article_pane.buffer.get_selection_bounds()
selected_text=None
if bounds:
start=bounds[0]
stop=bounds[1]
selected_text=self.article_pane.buffer.get_text(start,stop,True).decode("utf-8").split("\n")
newsgroups=group
if group!=article.ngroups:
#this is a crosspost
crosspost=True
newsgroups=article.ngroups
else:
crosspost=False
if article.fup_to!="":
newsgroups=article.fup_to
followup_to=True
else:
followup_to=False
if crosspost and not followup_to:
message=Dialog_YES_NO(_("This is a crosspost! \n Do you want to send the article only on the original newsgroup (%s) ?") % (group,))
if message.resp:
newsgroups=group
if followup_to:
if article.fup_to!="poster":
message=Dialog_YES_NO(_("Original Poster set \"Followup_to\" on %s,\n\nDo you want to send your article on the original newsgroup (%s) ?") % (article.fup_to,group))
if message.resp:
newsgroups=group
else:
message=Dialog_YES_NO(_("Original Poster set \"Followup_to: poster\",\n\nDo you want to reply by mail ?"))
if message.resp:
self.open_edit_mail_win(None)
return None
else:
newsgroups=group
self.win4=Edit_Win(self.configs,newsgroups,article,selected_text,self.subscribed_groups,server_name=self.current_server,id_name=id_name)
#self.win4.show()
else:
#this is a new post
self.win4=Edit_Win(self.configs,group,None,None,self.subscribed_groups,server_name=self.current_server,id_name=id_name)
#self.win4.show()
def open_edit_mail_win(self,object):
to_name=""
id_name=""
model,path,iter_selected=self.groups_pane.get_first_selected_row()
if iter_selected!=None:
group=model.get_value(iter_selected,0)
id_name=self.get_id_for_group(group)
model,iter_selected=self.threads_pane.threads_tree.get_selection().get_selected()
subj=""
if iter_selected!=None:
#subj=model.get_value(iter_selected,1).decode("utf-8")
article=self.threads_pane.get_article(model,iter_selected)
subj=article.subj
try:
article.reply_to
except AttributeError:
self.statusbar.push(1,_("First you have to read the article"))
else:
self.threads_pane.update_article_icon("fup")
if article.reply_to!="":
to_name=article.reply_to
else:
to_name=article.from_name
bounds=self.article_pane.buffer.get_selection_bounds()
selected_text=None
if bounds:
start=bounds[0]
stop=bounds[1]
selected_text=self.article_pane.buffer.get_text(start,stop,True).decode("utf-8").split("\n")
self.win4=Edit_Mail_Win(self.configs,to_name,article,selected_text,id_name=id_name)
self.win4.show()
def open_about_dialog(self,object):
self.about_dialog=About_Dialog(NUMBER)
self.about_dialog.show()
def delete_event(self,widget,event,data=None):
self.mainwin_width,self.mainwin_height=self.window.get_size()
self.mainwin_pos_x,self.mainwin_pos_y=self.window.get_position()
return False
def save_sizes(self):
try:
f=open(os.path.join(self.wdir,"dats/sizes.dat"),"rb")
except IOError:
sizes={}
else:
sizes=cPickle.load(f)
sizes["vpaned_pos"]=self.vpaned.get_position()
sizes["hpaned_pos"]=self.hpaned.get_position()
sizes["threads_col_status"]=self.threads_pane.column1.get_width()
sizes["threads_col_subject"]=self.threads_pane.column2.get_width()
sizes["threads_col_from"]=self.threads_pane.column3.get_width()
sizes["threads_col_date"]=self.threads_pane.column4.get_width()
sizes["threads_col_score"]=self.threads_pane.column5.get_width()
sizes["groups_col1"]=self.groups_pane.column1.get_width()
if not self.mainwin_width:
sizes["mainwin_width"],sizes["mainwin_height"]=self.window.get_size()
else:
sizes["mainwin_width"]=self.mainwin_width
sizes["mainwin_height"]=self.mainwin_height
if not self.mainwin_pos_x:
sizes["mainwin_pos_x"],sizes["mainwin_pos_y"]=self.window.get_position()
else:
sizes["mainwin_pos_x"]=self.mainwin_pos_x
sizes["mainwin_pos_x"]=self.mainwin_pos_x
try:
f=open(os.path.join(self.wdir,"dats/sizes.dat"),"wb")
except IOError:
pass
else:
cPickle.dump(sizes,f,1)
f.close()
def save_checkmenu_options(self):
self.configs["raw"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_articles_opts/raw").get_active()))
self.configs["fixed"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_articles_opts/fixed").get_active()))
self.configs["show_quote"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_articles_opts/show_quote").get_active()))
self.configs["show_sign"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_articles_opts/show_sign").get_active()))
self.configs["show_spoiler"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_articles_opts/spoiler").get_active()))
self.configs["show_threads"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads").get_active()))
self.configs["show_all_read_threads"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_all_read_threads").get_active()))
self.configs["show_threads_without_watched"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads_without_watched").get_active()))
self.configs["show_read_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_read_articles").get_active()))
self.configs["show_unread_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unread_articles").get_active()))
self.configs["show_kept_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_kept_articles").get_active()))
self.configs["show_unkept_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unkept_articles").get_active()))
self.configs["show_watched_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_watched_articles").get_active()))
self.configs["show_ignored_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_ignored_articles").get_active()))
self.configs["show_unwatchedignored_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unwatchedignored_articles").get_active()))
self.configs["show_score_neg_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_neg_articles").get_active()))
self.configs["show_score_zero_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_zero_articles").get_active()))
self.configs["show_score_pos_articles"]=str(bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_pos_articles").get_active()))
self.conf.write_configs()
def update_checkmenu_options(self):
if self.configs["raw"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/raw").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/raw").set_active(False)
if self.configs["fixed"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/fixed").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/fixed").set_active(False)
if self.configs["show_quote"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/show_quote").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/show_quote").set_active(False)
if self.configs["show_sign"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/show_sign").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/show_sign").set_active(False)
if self.configs["show_spoiler"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/spoiler").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_articles_opts/spoiler").set_active(False)
if self.configs["show_threads"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads").set_active(False)
if self.configs["show_all_read_threads"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_all_read_threads").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_all_read_threads").set_active(False)
if self.configs["show_threads_without_watched"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads_without_watched").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads_without_watched").set_active(False)
if self.configs["show_read_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_read_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_read_articles").set_active(False)
if self.configs["show_unread_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unread_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unread_articles").set_active(False)
if self.configs["show_kept_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_kept_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_kept_articles").set_active(False)
if self.configs["show_unkept_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unkept_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unkept_articles").set_active(False)
if self.configs["show_watched_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_watched_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_watched_articles").set_active(False)
if self.configs["show_ignored_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_ignored_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_ignored_articles").set_active(False)
if self.configs["show_unwatchedignored_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unwatchedignored_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unwatchedignored_articles").set_active(False)
if self.configs["show_score_neg_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_neg_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_neg_articles").set_active(False)
if self.configs["show_score_zero_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_zero_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_zero_articles").set_active(False)
if self.configs["show_score_pos_articles"]=="True":
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_pos_articles").set_active(True)
else:
self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_pos_articles").set_active(False)
def destroy(self,widget):
for connection in self.connectionsPool.itervalues():
connection.closeConnection()
self.save_sorting_type()
self.save_sizes()
self.save_checkmenu_options()
self.purge_groups()
try: os.remove(os.path.join(self.wdir,"xpn.lock"))
except: pass
gtk.main_quit()
def save_sorting_type(self,obj=None):
for n in range(1,5):
col=self.threads_pane.threads_tree.get_column(n)
if col.get_sort_indicator():
order=col.get_sort_order()
col_name=["Subject","From","Date","Score"][n-1]
if order==gtk.SORT_ASCENDING:
ascend_order="True"
else:
ascend_order="False"
self.configs["ascend_order"]=ascend_order
self.configs["sort_col"]=col_name
self.conf.write_configs()
def show_subscribed(self):
model,path_list,iter_list=self.groups_pane.get_selected_rows()
list=self.art_db.getSubscribed()
new_list=[]
self.subscribed_groups=[]
groups_to_open=[group[0] for group in list]
self.art_db.addGroups(groups_to_open)
for group in list:
total,unread_number=self.art_db.getArticlesNumbers(group[0])
new_list.append((group[0],str(unread_number)+" ("+str(total)+")"))
self.subscribed_groups.append([group[0],group[2],group[3]]) #group_name,server_name,id_name
self.groups_pane.show_list(new_list,True)
self.threads_pane.clear()
self.article_pane.clear()
if path_list:
self.groups_pane.select_row_by_path(path_list[0])
def show_threads(self,group,search_type=None,text=None):
art_fup=gtk.gdk.pixbuf_new_from_file("pixmaps/art_fup.xpm")
art_body=gtk.gdk.pixbuf_new_from_file("pixmaps/art_body.xpm")
art_unread=gtk.gdk.pixbuf_new_from_file("pixmaps/art_unread.xpm")
art_read=gtk.gdk.pixbuf_new_from_file("pixmaps/art_read.xpm")
art_mark=gtk.gdk.pixbuf_new_from_file("pixmaps/art_mark.xpm")
art_keep=gtk.gdk.pixbuf_new_from_file("pixmaps/art_keep.xpm")
art_unkeep=gtk.gdk.pixbuf_new_from_file("pixmaps/art_unkeep.xpm")
art_watch=gtk.gdk.pixbuf_new_from_file("pixmaps/art_watch.xpm")
art_unwatchignore=gtk.gdk.pixbuf_new_from_file("pixmaps/art_unwatchignore.xpm")
art_ignore=gtk.gdk.pixbuf_new_from_file("pixmaps/art_ignore.xpm")
icons=(art_fup,art_body,art_unread,art_read,art_mark,art_keep,art_unkeep,art_watch,art_unwatchignore,art_ignore)
show_read_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_read_articles").get_active())
show_unread_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unread_articles").get_active())
show_kept_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_kept_articles").get_active())
show_unkept_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unkept_articles").get_active())
show_watched_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_watched_articles").get_active())
show_ignored_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_ignored_articles").get_active())
show_unwatchedignored_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_unwatchedignored_articles").get_active())
show_score_neg_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_neg_articles").get_active())
show_score_zero_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_zero_articles").get_active())
show_score_pos_articles=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_score_pos_articles").get_active())
show_threads=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads").get_active())
show_all_read_threads=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_all_read_threads").get_active())
show_threads_without_watched=bool(self.ui.get_widget("/MainMenuBar/View/view_group_opts/show_threads_without_watched").get_active())
show_bools=(show_read_articles,show_unread_articles,show_kept_articles,show_unkept_articles,show_watched_articles,show_ignored_articles,show_unwatchedignored_articles,show_score_neg_articles,show_score_zero_articles,show_score_pos_articles,show_threads,show_all_read_threads)
if group:
self.window.set_title( "%s - XPN %s" % ( group, NUMBER ) )
else:
self.window.set_title( "XPN %s" % (NUMBER,) )
if not group: return
groups=[line[0] for line in self.groups_pane.model]
if not group in groups: return
self.threads_pane.clear()
model=self.threads_pane.new_model()
article_tree = {}
self.statusbar.push(1,_("Please Wait. Building Threads"))
def thread_alg_1(search_type=None,text=None):
sort=True
sorted=[]
for xpn_article in self.art_db.getArticles(group,show_bools,False,search_type,text):
sorted.append((xpn_article.secs,xpn_article))
if sort:
sorted.sort()
articles=sorted
for secs, xpn_article in articles:
article_info = xpn_article.get_article_info(icons)
nick,from_name,ref,subj,date,date_parsed=xpn_article.get_headers()
msgid=xpn_article.msgid
if show_threads:
try:
idx=ref.rindex("<")
except ValueError:
#Root node
article_tree[msgid] = (True, [], article_info)
else:
#Child node
last_ref=ref[idx:]
if last_ref in article_tree:
#I found the father
article_tree[last_ref][1].append(msgid)
article_tree[msgid] = (False, [], article_info)
else:
#Trying threading by subject
for old_article_msgid, (old_article_is_root, old_branchs, old_article_info) in article_tree.iteritems():
old_article_subj = old_article_info[1]
diff_len = len(subj) - len(old_article_subj)
if (old_article_subj in subj) and old_article_is_root and diff_len<=6:
#Found a root article with similar subject
article_tree[old_article_msgid][1].append(msgid)
article_tree[msgid] = (False, [], article_info)
break
else:
#In the list there aren't articles with similar subject
article_tree[msgid] = (True, [], article_info)
else:
# we're populating "article_tree", but always with true because
# they're all "root nodes" (show_threads is false)
article_tree[msgid] = (True, [], article_info)
def thread_alg_2(search_type=None,text=None):
#t1=time.time()
for xpn_article in self.art_db.getArticles(group,show_bools,False,search_type,text):
article_info = xpn_article.get_article_info(icons)
msgid=xpn_article.msgid
#first create all the nodes
article_tree[msgid] = (True, [], article_info)
#t2=time.time()
if show_threads:
for is_root,children,article_info in article_tree.itervalues():
xpn_article=article_info[4]
msgid=xpn_article.msgid
nick,from_name,ref,subj,date,date_parsed=xpn_article.get_headers()
try:
idx=ref.rindex("<")
except ValueError:
#Root node
pass
else:
#Child node
last_ref=ref[idx:]
if last_ref in article_tree:
#I found the father
article_tree[last_ref][1].append(msgid)
article_tree[msgid] = (False, article_tree[msgid][1], article_tree[msgid][2])
#t3=time.time()
#threading by subject
orphaned=[(art_info[4].secs,art_info[4]) for mid,(is_root,children,art_info) in article_tree.iteritems() if (is_root and art_info[4].ref)]
orphaned.sort()
orp=orphaned[:]
#t4=time.time()
for secs,xpn_article in orphaned:
subj=xpn_article.subj
for is_root,children,art_info in article_tree.itervalues():
if is_root and not ((art_info[4].secs,art_info[4]) in orp):
old_xpn_article=art_info[4]
old_subj=old_xpn_article.subj
diff_len = len(subj) - len(old_subj)
if (old_subj in subj) and diff_len <=6:
article_tree[old_xpn_article.msgid][1].append(xpn_article.msgid)
article_tree[xpn_article.msgid] = (False, article_tree[xpn_article.msgid][1], article_tree[xpn_article.msgid][2])
break
else: continue
#found nothing but we can use this article as parent
else: #else of the for is not executed when break is called
orp.remove((xpn_article.secs,xpn_article))
#t5=time.time()
#print "Lettura degli articoli e prima passata:",t2-t1
#print "Seconda passata, vegono riconosciuti i legami padre figlio:",t3-t2
#print "Estrazione degli articoli orfani:", t4-t3
#print "Terza passata, threading by subject:",t5-t4
# here we apply all the "tree wide" filters
def anyUnread(node):
'''Recursive function to check if all the branch is read.'''
(root, branchs, info) = article_tree[node]
# if the node is unread, the whole branch has any unread
if info[5]:
return True
# if any of the sons is unread, just pass the flag to the previous call
for branch in branchs:
if anyUnread(branch):
return True
# all my sons are read
return False
def anyWatched(node):
(root, branchs, info) = article_tree[node]
if info[11]==art_watch:
return True
for branch in branchs:
if anyWatched(branch):
return True
return False
if search_type:
search_type=search_type.lower()
text=text.lower()
if search_type=="from": search_type="from_name"
if search_type=="body": search_type="bodies.raw_body"
try: self.configs["threading_method"]
except KeyError: self.configs["threading_method"]="2"
if self.configs["threading_method"]=="2": thread_alg_2(search_type,text)
else: thread_alg_1(search_type,text)
if not show_all_read_threads:
roots = [k for k,v in article_tree.iteritems() if v[0]]
for article_root in roots:
if not anyUnread(article_root):
del article_tree[article_root]
if not show_threads_without_watched:
roots = [k for k,v in article_tree.iteritems() if v[0]]
for article_root in roots:
if not anyWatched(article_root):
del article_tree[article_root]
def walkTree(node, iter_mom):
'''Recursive function to build the articles tree in the GTK Widget.'''
# took the info about the article in the node
(root, branchs, info) = article_tree[node]
if info[5]:
unread_in_thread = 1
else:
unread_in_thread = 0
if info[11]==art_watch:
watched_in_thread = 1
else:
watched_in_thread = 0
watched_unread_in_thread = unread_in_thread and watched_in_thread
# tell TreeStore to build a branch
iter_new = self.threads_pane.insert(model, iter_mom, None, info)
# build all its sons
for branch in branchs:
(node_iter, more_unread, more_watched, more_watched_unread) = walkTree(branch, iter_new)
unread_in_thread += more_unread
watched_in_thread += more_watched
watched_unread_in_thread += more_watched_unread
return (iter_new, unread_in_thread, watched_in_thread, watched_unread_in_thread)
# with the help of walkTree, we'll build... well... the tree
roots = [k for k,v in article_tree.iteritems() if v[0]]
for article_root in roots:
# start a branch from its root
(root_iter, unread_in_thread, watched_in_thread, watched_unread_in_thread) = walkTree(article_root, None)
# show how many unread items the branch has
self.threads_pane.set_unread_in_thread(model, root_iter, unread_in_thread)
self.threads_pane.set_unread_in_thread_visible(model, root_iter, unread_in_thread!=0)
self.threads_pane.set_watched_in_thread(model, root_iter, watched_in_thread)
self.threads_pane.set_watched_unread_in_thread(model, root_iter, watched_unread_in_thread)
message=_("%s selected") % (group,)
self.statusbar.push(1,message)
self.threads_pane.set_model(model)
#adjust sorting
model=self.threads_pane.threads_tree.get_model()
sort_col=self.configs["sort_col"].lower()
sortings={"subject":1,"from":2,"date":6,"score":7}
sort_col=sortings.get(sort_col,6)
if self.configs["ascend_order"]=="True":
sort_order=gtk.SORT_ASCENDING
else:
sort_order=gtk.SORT_DESCENDING
model.set_sort_column_id(sort_col,sort_order)
def get_server_for_group(self,group_name):
server_name=""
for group,server,id in self.subscribed_groups:
if group==group_name: server_name=server
return server_name
def get_id_for_group(self,group_name):
id_name=""
for group,server,id in self.subscribed_groups:
if group==group_name: id_name=id
return id_name
def view_group(self,*params):
clicktype=params[-1]
if self.configs["oneclick"]=="True" and clicktype=="doubleclick": return
if self.configs["oneclick"]=="False" and clicktype=="oneclick": return
if self.groups_lock==False:
self.groups_lock=True
model,path_list,iter_list=self.groups_pane.get_selected_rows()
if iter_list:
self.group_to_thread=model.get_value(iter_list[0],0)
self.current_server=self.get_server_for_group(self.group_to_thread)
self.article_pane.clear()
self.show_threads(self.group_to_thread)
self.msgids[self.group_to_thread]=None
self.groups_lock=False
if self.configs["expand_group"]=="True": self.expand_all_threads(None,True)
def mark_for_download(self,article):
'''mark article for download'''
article.marked_for_download=not article.marked_for_download
self.art_db.updateArticle(self.group_to_thread,article)
def mark_subthread_for_download(self,model,root_iter,force_value=None):
'''mark subthread for download'''
xpn_article=self.threads_pane.get_article(model,root_iter)
#let's mark the root article
if force_value==True:
if xpn_article.body==None:
xpn_article.marked_for_download=force_value
elif force_value==False:
xpn_article.marked_for_download=force_value
else:
status=not xpn_article.marked_for_download
if status==True:
if xpn_article.body==None:
xpn_article.marked_for_download=status
else:
xpn_article.marked_for_download=status
if xpn_article.marked_for_download:
self.threads_pane.update_article_icon("download",root_iter)
else:
if xpn_article.is_read:
self.threads_pane.update_article_icon("read",root_iter)
elif xpn_article.body!=None:
self.threads_pane.update_article_icon("body",root_iter)
else:
self.threads_pane.update_article_icon("unread",root_iter)
self.art_db.updateArticle(self.group_to_thread,xpn_article)
self.threads_pane.set_article(model,root_iter,xpn_article)
iter_list=self.threads_pane.get_subthread(root_iter,model,[])
for iter_child in iter_list:
xpn_sub_article=self.threads_pane.get_article(model,iter_child)
#watching others articles in the subthread
if force_value==True:
if xpn_sub_article.body==None:
xpn_sub_article.marked_for_download=force_value
elif force_value==False:
xpn_sub_article.marked_for_download=force_value
else:
status=xpn_article.marked_for_download
if status==True:
if xpn_sub_article.body==None:
xpn_sub_article.marked_for_download=status
else:
xpn_sub_article.marked_for_download=status
if xpn_sub_article.marked_for_download:
self.threads_pane.update_article_icon("download",iter_child)
else:
if xpn_sub_article.is_read:
self.threads_pane.update_article_icon("read",iter_child)
elif xpn_sub_article.body!=None:
self.threads_pane.update_article_icon("body",iter_child)
else:
self.threads_pane.update_article_icon("unread",iter_child)
self.art_db.updateArticle(self.group_to_thread,xpn_sub_article)
self.threads_pane.set_article(model,iter_child,xpn_sub_article)
def mark_group_for_download(self,group):
'''mark the whole group for download'''
if group:
self.art_db.markGroupForDownload(group)
self.view_group(None,None)
def keep_subthread(self, model, root_iter):
xpn_root_article=self.threads_pane.get_article(model,root_iter)
status= xpn_root_article.keep
xpn_root_article.keep=not status
if status:
self.threads_pane.update_article_icon("unkeep",root_iter)
else:
self.threads_pane.update_article_icon("keep",root_iter)
self.art_db.updateArticle(self.group_to_thread,xpn_root_article)
self.threads_pane.set_article(model,root_iter,xpn_root_article)
iter_list=self.threads_pane.get_subthread(root_iter,model,[])
for iter_child in iter_list:
xpn_sub_article=self.threads_pane.get_article(model,iter_child)
xpn_sub_article.keep=not status
if status:
self.threads_pane.update_article_icon("unkeep",iter_child)
else:
self.threads_pane.update_article_icon("keep",iter_child)
self.art_db.updateArticle(self.group_to_thread,xpn_sub_article)
self.threads_pane.set_article(model,iter_child,xpn_sub_article)