forked from feedindicator/Feedindicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedindicator
executable file
·1417 lines (1173 loc) · 44.1 KB
/
feedindicator
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
# -*- coding: utf-8 -*-
#
# feedindicator
# Copyright (C) 2010-2011 Dave Gardner <[email protected]> & Michael Judge <[email protected]>
#
# 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/>.
#
# [SNIPPET_NAME: Parse an RSS feed]
# [SNIPPET_CATEGORIES: feedparser]
# [SNIPPET_DESCRIPTION: Parse and iterate over the items in an RSS feed]
# [SNIPPET_AUTHOR: Tim Voet <[email protected]>]
# [SNIPPET_DOCS: http://www.feedparser.org/docs/introduction.html]
# [SNIPPET_LICENSE: GPL]
# need python-feedparser and app-indicator(should come with ubuntu 10.04 and above)
import pygtk
pygtk.require('2.0')
import glib
import gtk
import appindicator
import feedparser
import gc
import hashlib
import os
import pynotify
import string
import sys
import urllib
import webbrowser
import gconf
import time
import gobject
import shutil
import sqlite3 as lite
from threading import Thread
from time import sleep
from gconf import VALUE_BOOL, VALUE_INT, VALUE_STRING, VALUE_FLOAT
from types import BooleanType, StringType, IntType, FloatType
from configobj import ConfigObj
# clear out the html element list so all are removed
feedparser._HTMLSanitizer.acceptable_elements = []
# common name used for file paths, gconf and indicator identifier
app_identifier = 'feedindicator'
# indicator icon names
app_indicator_icon = 'indicator-feedindicator'
app_indicator_icon_attention = 'indicator-feedindicator-attention'
# XDG config
xdg_config_dir = glib.get_user_config_dir()
app_config_dir = os.path.join(xdg_config_dir, app_identifier)
# XDG cache
xdg_cache_dir = glib.get_user_cache_dir()
app_cache_dir = os.path.join(xdg_cache_dir, app_identifier)
# /usr/share/
app_share_dir = '/usr/share/'+app_identifier+'/'
app_icon = os.path.join(app_share_dir, 'feedindicator-icon.png')
app_logo = os.path.join(app_share_dir, 'feedindicator-logo.png')
app_language_dir = os.path.join(app_share_dir, 'languages/')
# database
app_database = os.path.join(app_config_dir, 'feedindicator.db')
# language properties file
app_language_file = os.path.join(app_config_dir, 'language.properties')
# autostart file
app_autostart_folder = os.path.join(xdg_config_dir, 'autostart')
app_autostart_file = os.path.join(app_autostart_folder, app_identifier+'.desktop')
# general app info mostly used in about dialog
app_name = 'Feedindicator'
app_version = '1.03'
app_comments = 'RSS feed updates in the indicator area'
app_copyright = 'Copyright (C) 2010-2011 Dave Gardner & Michael Judge'
app_website = 'http://code.google.com/p/feedindicator/'
app_license = (('This program is free software: you can redistribute it and/or modify\n'+
'it under the terms of the GNU General Public License as published by\n'+
'the Free Software Foundation, either version 3 of the License, or\n'+
'(at your option) any later version.\n'+
'\n'+
'This program is distributed in the hope that it will be useful,\n'+
'but WITHOUT ANY WARRANTY; without even the implied warranty of\n'+
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n'+
'GNU General Public License for more details.\n'+
'\n'+
'You should have received a copy of the GNU General Public License\n'+
'along with this program. If not, see <http://www.gnu.org/licenses/>.'))
app_authors = ['Dave Gardner <[email protected]>','Michael Judge <[email protected]>']
app_documenters = ['Dave Gardner <[email protected]>','Michael Judge <[email protected]>']
# default autostart status
autostart = False
# default feed refresh time (minutes*seconds)
refreshtime = 30*60
# default stop the timer from running?
stoptimer = False
# default menu items to show per feed
itemsperfeed = 5
# default put feed items in submenus
usesubmenus = False
# default show notification popups
shownotifications = True
# default show notification popups at begining and end of update
shownotificationsupdate = True
# default sound for new posts
sound = "/usr/bin/mplayer -ao alsa /usr/share/sounds/ubuntu/stereo/message.ogg"
# default position of the feeds top or button of the menu
feedstop = True
# language properties
language_properties = None
##################################################
############### SQLite ###############
##################################################
class SQLite:
def get_con():
return self._con
con = property(get_con)
def __init__(self):
self._con = None
def open(self, path):
"""opens a new connection"""
try:
self._con = lite.connect(path)
except lite.Error, e:
print e
def close(self):
"""closes the current connection"""
if self._con:
try:
self._con.close()
except lite.Error, e:
print e
def execute(self, query, data=()):
"""executes the given query and returns the results"""
if self._con:
try:
cur = self._con.cursor()
if data == ():
cur.execute(query)
else:
cur.execute(query, data)
rows = cur.fetchall()
return rows
except lite.Error, e:
print e
return None
def executemany(self, query, data):
"""executes the given query with executemany()"""
if self._con:
try:
cur = self._con.cursor()
cur.executemany(query, data)
except lite.Error, e:
print e
def commit(self):
"""commits changes to the database"""
if self._con:
try:
self._con.commit()
except lite.Error, e:
self._con.rollback()
print e
def contains(self, query, data=()):
"""checks wheter the given query has results or not"""
if self._con:
try:
cur = self._con.cursor()
if data == ():
cur.execute(query)
else:
cur.execute(query, data)
rows = cur.fetchone()
if rows:
return True;
else:
return False;
except lite.Error, e:
print e
##################################################
############### Exit ###############
##################################################
class Exit:
def __init__(self, widget):
sys.exit()
##################################################
############### GConf ###############
##################################################
class GConf:
def __init__ (self, appname, allowed={}):
self._domain = '/apps/%s/' % appname
self._allowed = allowed
self._gconf_client = gconf.client_get_default ()
def __getitem__ (self, attr):
return self.get_value (attr)
def __setitem__ (self, key, val):
allowed = self._allowed
if allowed.has_key(key):
if not key in allowed[key]:
good = ', '.join (allowed[key])
return False
self.set_value (key, val)
def _get_type (self, key):
KeyType = type (key)
if KeyType == BooleanType:
return 'bool'
elif KeyType == StringType:
return 'string'
elif KeyType == IntType:
return 'int'
elif KeyType == FloatType:
return 'float'
else:
return None
# Public functions
def set_allowed (self, allowed):
self._allowed = allowed
def set_domain (self, domain):
self._domain = domain
def get_domain (self):
return self._domain
def get_gconf_client (self):
return self._gconf_client
def get_value (self, key):
"""returns the value of key 'key' """
if '/' in key:
raise 'GConfError', 'key must not contain /'
value = self._gconf_client.get(self._domain + key)
if value is not None:
ValueType = value.type
if ValueType == VALUE_BOOL:
return value.get_bool()
elif ValueType == VALUE_INT:
return value.get_int()
elif ValueType == VALUE_STRING:
return value.get_string()
elif ValueType == VALUE_FLOAT:
return value.get_float()
else:
return None
else:
return None
def set_value (self, key, value):
"""sets the value of key 'key' to 'value' """
value_type = self._get_type(value)
if value_type is not None:
if '/' in key:
raise 'GConfError', 'key must not contain /'
func = getattr (self._gconf_client, 'set_' + value_type)
apply(func, (self._domain + key, value))
def get_string (self, key):
if '/' in key:
raise 'GConfError', 'key must not contain /'
return self._gconf_client.get_string(self._domain + key)
def set_string (self, key, value):
if type (value) != StringType:
raise 'GConfError', 'value must be a string'
if '/' in key:
raise 'GConfError', 'key must not contain /'
self._gconf_client.set_string(self._domain + key, value)
def get_bool (self, key):
if '/' in key:
raise 'GConfError', 'key must not contain /'
return self._gconf_client.get_bool(self._domain + key)
def set_bool (self, key, value):
if type (value) != IntType and (key != 0 or key != 1):
raise 'GConfError', 'value must be a boolean'
if '/' in key:
raise 'GConfError', 'key must not contain /'
self._gconf_client.set_bool(self._domain + key, value)
def get_int (self, key):
if '/' in key:
raise 'GConfError', 'key must not contain /'
return self._gconf_client.get_int(self._domain + key)
def set_int (self, key, value):
if type (value) != IntType:
raise 'GConfError', 'value must be an int'
if '/' in key:
raise 'GConfError', 'key must not contain /'
self._gconf_client.set_int(self._domain + key, value)
def get_float (self, key):
if '/' in key:
raise 'GConfError', 'key must not contain /'
return self._gconf_client.get_float(self._domain + key)
def set_float (self, key, value):
if type (value) != FloatType:
raise 'GConfError', 'value must be a float'
if '/' in key:
raise 'GConfError', 'key must not contain /'
self._gconf_client.set_float(self._domain + key, value)
##################################################
############### FeedThread ###############
##################################################
class FeedThread(Thread):
def run(self):
"""updates all feeds in the database und updates the infos"""
sq = SQLite()
sq.open(app_database)
feeds = sq.execute('select feed_url, title, url, img from feeds')
if len(feeds) > 0:
for feed in feeds:
feedinfo = self.parse_feed(feed[0])
if feedinfo['success']:
if feed[1] == None:
sq.execute('update feeds set title=? where feed_url=?', (unicode(feedinfo['feeddata']['title']), feed[0]))
if not feed[2] == unicode(feedinfo['feeddata']['link']):
sq.execute('update feeds set url=? where feed_url=?', (unicode(feedinfo['feeddata']['link']), feed[0]))
if not unicode(feedinfo['feeddata']['img']) == 'None':
sq.execute('update feeds set img=? where feed_url=?', (unicode(feedinfo['feeddata']['img']), feed[0]))
items = ()
posts = ()
for postdata in feedinfo['postdata']:
if not postdata['date'] == '':
md5 = hashlib.md5(str(postdata['date']) + '@' + str(postdata['title'])).hexdigest()
posts = posts + (md5,)
if not sq.contains('select * from posts where id=?', (md5,)):
items = items + ((md5, unicode(postdata['link']), unicode(postdata['title']), unicode(feed[0])), )
else:
md5 = hashlib.md5(str(postdata['link'])).hexdigest()
posts = posts + (md5,)
if not sq.contains('select * from posts where id=?', (md5,)):
items = items + ((md5, unicode(postdata['link']), unicode(postdata['title']), unicode(feed[0])), )
if not items == ():
sq.executemany('insert into posts (id, post_url, title, feed_url) values (?,?,?,?)', items)
placeholder= '?'
placeholders= ', '.join(placeholder for unused in posts)
posts = posts + (feed[0],)
sq.execute('delete from posts where read=\'true\' and id not in (%s) and feed_url=?' % placeholders, posts)
sq.commit()
sq.close()
gobject.idle_add(indicator.finnished_update)
def parse_feed(self, url):
"""parses a feed and returns the infos"""
feedinfo = {}
feedinfo['feeddata'] = {}
feedinfo['postdata'] = []
feedinfo['success'] = False
try:
rssfeed = feedparser.parse(url)
postdata = []
for val in rssfeed.entries:
val.title = string.replace(val.title, '\n', '')
if len(val.title) > 72:
substr = val.title[:72]
substr = substr.rpartition(' ')
if substr[0] != '':
val.title = substr[0] + '...'
date = ''
if 'published' in val:
date = val.published
elif 'updated' in val:
date = val.updated
elif 'created' in val:
date = val.created
v = {'title': val.title, 'link': val.link, 'date': date}
postdata.append(v)
feedinfo['postdata'] = postdata
feedimg = None
webimg = None
if 'image' in rssfeed.feed:
webimg = rssfeed.feed.image.href
elif 'logo' in rssfeed.feed:
webimg = rssfeed.feed.logo
elif 'icon' in rssfeed.feed:
webimg = rssfeed.feed.icon
if webimg != None:
ext = webimg.rsplit('.', 1)
if len(ext[1]) > 5 or len(ext[1]) == 0:
ext[0] = webimg
ext[1] = 'jpg'
md5hash = hashlib.md5(str(url)).hexdigest()
localimg = os.path.join(app_cache_dir, md5hash + '.' + ext[1])
urllib.urlretrieve(webimg, localimg)
feedimg = md5hash + '.' + ext[1]
feedinfo['feeddata'] = {'title': rssfeed.feed.title, 'link': rssfeed.feed.link, 'img': feedimg}
feedinfo['success'] = True
except:
pass
return feedinfo
##################################################
############### AddFeedDialog ###############
##################################################
class AddFeedDialog:
def __init__(self, widget):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_size_request(450, 120)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_title(language_properties['add_feed'] + ' ' + app_name)
self.window.connect('delete_event', self.cancel_dialog)
self.window.connect('key-press-event', self.keypress)
vbox = gtk.VBox(False, 10)
vbox.set_border_width(10)
self.window.add(vbox)
vbox.show()
hboxl = gtk.HBox(False, 0)
vbox.pack_start(hboxl, False, True, 0)
hboxl.show()
label = gtk.Label(language_properties['add_dialog_column'])
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_line_wrap(True)
hboxl.pack_start(label, False, True, 0)
label.show()
hbox2 = gtk.HBox(False, 0)
vbox.pack_start(hbox2, False, True, 0)
hbox2.show()
self._textbox = gtk.Entry()
hbox2.pack_start(self._textbox, True, True, 0)
self._textbox.connect("activate", self.save_dialog)
self._textbox.show()
hbox3 = gtk.HBox(True, 0)
vbox.pack_end(hbox3, False, True, 5)
hbox3.show()
button_cancel = gtk.Button(language_properties['cancel'])
hbox3.pack_start(button_cancel, True, True, 0)
button_cancel.connect_object('clicked', self.cancel_dialog, button_cancel)
button_cancel.show()
button_save = gtk.Button(language_properties['add'])
hbox3.pack_start(button_save, True, True, 0)
button_save.connect_object('clicked', self.save_dialog, None)
button_save.show()
self.window.set_keep_above(True)
self.window.show()
def cancel_dialog(self, widget, data=None):
"""cancel dialog"""
self.window.destroy()
def save_dialog(self, data):
"""save feed to config file and close add feed dialog"""
self.window.set_modal(True)
sq = SQLite()
sq.open(app_database)
sq.execute('insert into feeds (feed_url) values (?)', (unicode(self._textbox.get_text()),))
sq.commit()
sq.close()
self.window.destroy()
indicator.update_feeds(None, True, True)
def keypress(self, widget, data):
"""keypress handler"""
if data.keyval == gtk.keysyms.Escape:
self.window.destroy()
elif data.keyval == gtk.keysyms.Return:
self.save_dialog(None)
##################################################
############### AboutDialog ###############
##################################################
class AboutDialog:
def __init__(self, widget):
about = gtk.AboutDialog()
about.set_logo(gtk.gdk.pixbuf_new_from_file(app_logo))
about.set_name(app_name)
about.set_program_name(app_name)
about.set_version(app_version)
about.set_comments(app_comments)
about.set_copyright(app_copyright)
about.set_license(app_license)
about.set_website(app_website)
about.set_website_label(app_website)
about.set_authors(app_authors)
about.set_documenters(app_documenters)
about.run()
about.destroy()
##################################################
############### ConfigureDialog ###############
##################################################
class ConfigureDialog:
def __init__(self, widget):
self.refreshtimeset = refreshtime
self.itemsperfeedset = itemsperfeed
self.autostartset = autostart
self.shownotificationsset = shownotifications
self.shownotificationsupdateset = shownotificationsupdate
self.usesubmenusset = usesubmenus
self.feedstopset = feedstop
self.langaugeset = ''
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_size_request(850, 550)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_title(language_properties['configure'] + ' ' + app_name)
self.window.connect('delete_event',self.cancel_dialog)
self.window.connect('key-press-event', self.keypress)
vbox = gtk.VBox(False, 10)
vbox.set_border_width(10)
self.window.add(vbox)
vbox.show()
hboxl = gtk.HBox(False, 0)
vbox.pack_start(hboxl, False, True, 0)
hboxl.show()
label = gtk.Label(language_properties['configure_dialog_label'])
label.set_justify(gtk.JUSTIFY_LEFT)
label.set_line_wrap(True)
hboxl.pack_start(label, False, True, 0)
label.show()
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
scrolled_window.set_shadow_type(gtk.SHADOW_IN)
vbox.pack_start(scrolled_window, True, True, 0)
scrolled_window.show()
liststore = gtk.ListStore(str, str, str)
sq = SQLite()
sq.open(app_database)
feeds = sq.execute('select feed_url, title from feeds order by upper(title)')
for feed in feeds:
liststore.append([unicode(feed[0]), unicode(feed[1]), unicode(feed[0])])
sq.close()
self.treeview = gtk.TreeView(liststore)
self.urlcolumn = gtk.TreeViewColumn(language_properties['column_url'])
self.treeview.append_column(self.urlcolumn)
textrenderer = gtk.CellRendererText()
self.urlcolumn.pack_start(textrenderer, True)
self.urlcolumn.add_attribute(textrenderer, 'text', 0)
textrenderer.set_property('editable', True)
textrenderer.connect('edited', self.cell_edited, liststore, 0)
textrenderer = gtk.CellRendererText()
self.titlecolumn = gtk.TreeViewColumn(language_properties['column_title'])
self.treeview.append_column(self.titlecolumn)
self.titlecolumn.pack_start(textrenderer, True)
self.titlecolumn.add_attribute(textrenderer, 'text', 1)
textrenderer.set_property('editable', True)
textrenderer.connect('edited', self.cell_edited, liststore, 1)
self.treeview.set_headers_clickable(False)
self.treeview.set_reorderable(True)
self.treeview.connect('cursor-changed', self.selection_made)
scrolled_window.add(self.treeview)
self.treeview.show()
hbox1 = gtk.HBox(True, 0)
vbox.pack_start(hbox1, False, True, 0)
hbox1.show()
self.button_change = gtk.Button(language_properties['add_new'])
hbox1.pack_start(self.button_change, True, True, 0)
self.button_change.connect_object('clicked', self.button_add_clicked, liststore)
self.button_change.show()
self.button_remove = gtk.Button(language_properties['remove'])
hbox1.pack_start(self.button_remove, True, True, 0)
self.button_remove.connect_object('clicked', self.button_remove_clicked, liststore)
self.button_remove.set_sensitive(False)
self.button_remove.show()
hbox2sl = gtk.HBox(False, 0)
vbox.pack_start(hbox2sl, False, True, 0)
hbox2sl.show()
self.scaletimerlabel = gtk.Label(language_properties['update_feed_every'] + '...')
hbox2sl.pack_start(self.scaletimerlabel, False, False, 0)
self.scaletimerlabel.show()
hbox2s = gtk.HBox(False, 0)
vbox.pack_start(hbox2s, False, True, 0)
hbox2s.show()
adjtimer = gtk.Adjustment(int(self.refreshtimeset/60), 1.0, 90.0, 1.0, 10.0, 0.0)
adjtimer.connect('value_changed', self.timer_scale)
scaletimer = gtk.HScale(adjtimer)
scaletimer.set_draw_value(False)
scaletimer.set_digits(0)
hbox2s.pack_start(scaletimer, True, True, 0)
self.timer_scale(adjtimer)
scaletimer.show()
hbox2il = gtk.HBox(False, 0)
vbox.pack_start(hbox2il, False, True, 0)
hbox2il.show()
self.scaleitemslabel = gtk.Label(language_properties['label_items_per_feed'])
hbox2il.pack_start(self.scaleitemslabel, False, False, 0)
self.scaleitemslabel.show()
hbox2i = gtk.HBox(False, 0)
vbox.pack_start(hbox2i, False, True, 0)
hbox2i.show()
adjitems = gtk.Adjustment(int(self.itemsperfeedset), 1.0, 30.0, 1.0, 10.0, 0.0)
adjitems.connect('value_changed', self.items_scale)
scaleitems = gtk.HScale(adjitems)
scaleitems.set_draw_value(False)
scaleitems.set_digits(0)
hbox2i.pack_start(scaleitems, True, True, 0)
self.items_scale(adjitems)
scaleitems.show()
hbox2t = gtk.HBox(False, 0)
vbox.pack_start(hbox2t, False, True, 0)
hbox2t.show()
check_autostart = gtk.CheckButton(language_properties['run_startup'])
hbox2t.pack_start(check_autostart, True, True, 0)
if autostart == True:
check_autostart.set_active(True)
check_autostart.connect('toggled', self.autostart_toggle)
check_autostart.show()
check_usesubmenus = gtk.CheckButton(language_properties['submenu_feed'])
hbox2t.pack_start(check_usesubmenus, True, True, 0)
if usesubmenus == True:
check_usesubmenus.set_active(True)
check_usesubmenus.connect('toggled', self.usesubmenus_toggle)
check_usesubmenus.show()
check_feedstop = gtk.CheckButton(language_properties['feeds_top_menu'])
hbox2t.pack_start(check_feedstop, True, True, 0)
if feedstop == True:
check_feedstop.set_active(True)
check_feedstop.connect('toggled', self.feedstop_toggle)
check_feedstop.show()
hbox2tb = gtk.HBox(False, 0)
vbox.pack_start(hbox2tb, False, True, 0)
hbox2tb.show()
check_shownotifications = gtk.CheckButton(language_properties['show_notifications'])
hbox2tb.pack_start(check_shownotifications, True, True, 0)
if shownotifications == True:
check_shownotifications.set_active(True)
check_shownotifications.connect('toggled', self.shownotifications_toggle)
check_shownotifications.show()
self.check_shownotificationsupdate = gtk.CheckButton(language_properties['show_notifications_update'])
hbox2tb.pack_start(self.check_shownotificationsupdate, True, True, 0)
if shownotifications == False:
self.check_shownotificationsupdate.set_sensitive(False)
if shownotificationsupdate == True:
self.check_shownotificationsupdate.set_active(True)
self.check_shownotificationsupdate.connect('toggled', self.shownotificationsupdate_toggle)
self.check_shownotificationsupdate.show()
hbox3l = gtk.HBox(False, 0)
vbox.pack_start(hbox3l, False, True, 0)
hbox3l.show()
entrylabel = gtk.Label(language_properties['signal_command'])
hbox3l.pack_start(entrylabel, False, False, 0)
entrylabel.show()
hbox3 = gtk.HBox(True, 0)
vbox.pack_start(hbox3, False, True, 0)
hbox3.show()
self._textbox = gtk.Entry()
hbox3.pack_start(self._textbox, True, True, 0)
self._textbox.set_text(sound)
self._textbox.show()
hbox4 = gtk.HBox(True, 0)
vbox.pack_start(hbox4, False, True, 0)
hbox4.show()
langaugelabel = gtk.Label(language_properties['choose_language'])
hbox4.pack_start(langaugelabel, True, True, 0)
langaugelabel.show()
language_store = gtk.ListStore(str, str)
languages = os.listdir(app_language_dir)
i = 0
index = 0
for lang in languages:
prop = ConfigObj(os.path.join(app_language_dir, lang))
language_store.append([lang, prop['language']])
if prop['language'] == language_properties['language']:
index = i
i = i + 1
combobox_language = gtk.ComboBox(language_store)
cell = gtk.CellRendererText()
combobox_language.pack_start(cell, True)
combobox_language.add_attribute(cell, 'text', 1)
combobox_language.set_active(index)
combobox_language.connect('changed', self.language_toggle)
hbox4.pack_start(combobox_language, True, True, 0)
combobox_language.show()
hbox5 = gtk.HBox(True, 0)
vbox.pack_end(hbox5, False, True, 5)
hbox5.show()
button_about = gtk.Button(language_properties['about'])
hbox5.pack_start(button_about, True, True, 0)
button_about.connect_object('clicked', AboutDialog, button_about)
button_about.show()
button_cancel = gtk.Button(language_properties['cancel'])
hbox5.pack_start(button_cancel, True, True, 0)
button_cancel.connect_object('clicked', self.cancel_dialog, button_cancel)
button_cancel.show()
button_save = gtk.Button(language_properties['save'])
hbox5.pack_start(button_save, True, True, 0)
button_save.connect_object('clicked', self.save_dialog, liststore)
button_save.show()
self.window.set_keep_above(True)
self.window.show()
def selection_made(self, data=None):
"""entry clicked so we enable the remove button"""
treesel = self.treeview.get_selection()
sel = treesel.get_selected()
if sel[1] != None:
self.button_remove.set_sensitive(True)
def cell_edited(self, cell, row, new_text, data, column):
"""update entry with edited value"""
data[row][column] = new_text
return
def button_add_clicked(self, data):
"""add entry to list and focus cursor"""
sel = data.append(['', '', ''])
pos = data.get_path(sel)
self.treeview.set_cursor(pos, self.urlcolumn, True)
def button_remove_clicked(self, data):
"""remove selected entry from list"""
treesel = self.treeview.get_selection()
sel = treesel.get_selected()
sq = SQLite()
sq.open(app_database)
feed_url = sel[0].get_value(sel[1], 2)
sq.execute('delete from posts where feed_url=?', (feed_url,))
img = sq.execute('select img from feeds where feed_url=?', (feed_url,))
if os.path.exists(os.path.join(app_cache_dir, unicode(img[0]))):
os.remove(os.path.join(app_cache_dir, unicode(img[0])))
sq.execute('delete from feeds where feed_url=?', (feed_url,))
sq.commit()
sq.close()
data.remove(sel[1])
self.button_remove.set_sensitive(False)
def timer_scale(self, widget):
"""refreshtimer slider interaction"""
value = widget.get_value();
if int(value) == 1:
self.refreshtimeset = int(value)*60
self.scaletimerlabel.set_text(language_properties['update_feed_every_m'])
else:
self.refreshtimeset = int(value)*60
self.scaletimerlabel.set_text(language_properties['update_feed_every'] + ' ' + str(self.refreshtimeset/60) + ' ' + language_properties['minutes'])
def items_scale(self, widget):
"""scaleitems slider interaction"""
value = widget.get_value();
if int(value) == 1:
self.itemsperfeedset = int(value)
self.scaleitemslabel.set_text(language_properties['menu_shows_one_item_per_feed'])
else:
self.itemsperfeedset = int(value)
self.scaleitemslabel.set_text(language_properties['menu_shows'] + ' ' + str(self.itemsperfeedset) + ' ' + language_properties['items_per_feed'])
def autostart_toggle(self, widget):
"""check toggle status"""
if widget.get_active():
self.autostartset = True
else:
self.autostartset = False
def shownotifications_toggle(self, widget):
"""check toggle status"""
if widget.get_active():
self.shownotificationsset = True
self.check_shownotificationsupdate.set_sensitive(True)
else:
self.shownotificationsset = False
self.check_shownotificationsupdate.set_sensitive(False)
def shownotificationsupdate_toggle(self, widget):
"""check toggle status"""
if widget.get_active():
self.shownotificationsupdateset = True
else:
self.shownotificationsupdateset = False
def usesubmenus_toggle(self, widget):
"""check toggle status"""
if widget.get_active():
self.usesubmenusset = True
else:
self.usesubmenusset = False
def language_toggle(self, widget):
"""check toggle status"""
tree_iter = widget.get_active_iter()
if tree_iter != None:
model = widget.get_model()
self.langaugeset = model[tree_iter][0]
def feedstop_toggle(self, widget):
"""check toggle status"""
if widget.get_active():
self.feedstopset = True
else:
self.feedstopset = False
def autostart_create(self):
"""create autostart file"""
global autostart
content = "\n"+"[Desktop Entry]\n"+"Type=Application\n"+"Exec="+app_identifier+" --autostarted\n"+"X-GNOME-Autostart-enabled=true\n"+"Icon="+app_identifier+"\n"+"Name="+app_name+"\n"+"Comment="+app_comments
if not os.path.exists(app_autostart_folder):
os.makedirs(app_autostart_folder, 0700)
f = open(app_autostart_file, 'w')
f.write(content)
f.close()
autostart = True
def autostart_delete(self):
"""remove autostart file"""
global autostart
if os.path.exists(app_autostart_file):
os.remove(app_autostart_file)
autostart = False
def keypress(self, widget, data):
"""keypress handler"""
if data.keyval == gtk.keysyms.Escape:
self.window.destroy()
def cancel_dialog(self, widget, data=None):
"""cancel dialog"""
self.window.destroy()
def save_dialog(self, data):
"""save list to config file and close config dialog"""
global refreshtime
global itemsperfeed
global autostart
global shownotifications
global shownotificationsupdate
global usesubmenus
global sound
global feedstop
global language_properties
refreshtime = self.refreshtimeset
gconf['refreshtime'] = self.refreshtimeset
itemsperfeed = self.itemsperfeedset
gconf['itemsperfeed'] = self.itemsperfeedset
shownotifications = self.shownotificationsset
gconf['shownotifications'] = self.shownotificationsset
shownotificationsupdate = self.shownotificationsupdateset
gconf['shownotificationsupdate'] = self.shownotificationsupdateset
usesubmenus = self.usesubmenusset
gconf['usesubmenus'] = self.usesubmenusset
feedstop = self.feedstopset
gconf['feedstop'] = self.feedstopset
sound = self._textbox.get_text()
gconf['sound'] = self._textbox.get_text()
autostart = self.autostartset
if autostart == True:
self.autostart_create()
else:
self.autostart_delete()
if not self.langaugeset == '':
shutil.copyfile(os.path.join(app_language_dir, self.langaugeset), app_language_file)
language_properties = ConfigObj(app_language_file)
sq = SQLite()
sq.open(app_database)
for row in data:
if row[2] == '' and row[1] == '':
sq.execute('insert into feeds (feed_url) values (?)', (unicode(row[0]),))
elif row[2] == '' and row[1] != '':
sq.execute('insert into feeds (feed_url, title) values (?, ?)', (unicode(row[0]), unicode(row[1])))
elif row[2] == row[0]:
sq.execute('update feeds set title=? where feed_url=?', (unicode(row[1]), unicode(row[2])))
else:
sq.execute('update posts set feed_url=? where feed_url=?', (unicode(row[0]), unicode(row[2])))
sq.execute('update feeds set title=?, feed_url=? where feed_url=?', (unicode(row[1]), unicode(row[0]), unicode(row[2])))
sq.commit()
sq.close()
self.window.destroy()
indicator.update_feeds(None, True, True)
##################################################
############### AppIndicator ###############
##################################################
class AppIndicator:
def __init__(self):
global refreshtime
global stoptimer
global itemsperfeed
global autostart
global shownotifications
global shownotificationsupdate