root/trunk/src/atom_window.py

Revision 10250, 4.1 kB (checked in by roidelapluie, 4 months ago)

See #4200.

  • remove js from some headers
  • set coding:utf-8 to allow real names in headers
Line 
1# -*- coding:utf-8 -*-
2## src/atom_window.py
3##
4## Copyright (C) 2006 Tomasz Melcer <liori AT exroot.org>
5## Copyright (C) 2006-2007 Yann Leboulanger <asterix AT lagaule.org>
6## Copyright (C) 2007 Nikos Kouremenos <kourem AT gmail.com>
7## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
8##
9## This file is part of Gajim.
10##
11## Gajim is free software; you can redistribute it and/or modify
12## it under the terms of the GNU General Public License as published
13## by the Free Software Foundation; version 3 only.
14##
15## Gajim is distributed in the hope that it will be useful,
16## but WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
22##
23
24
25import gtk
26import gobject
27
28import gtkgui_helpers
29from common import helpers
30
31class AtomWindow:
32        window = None
33        entries = []
34
35        @classmethod
36        def newAtomEntry(cls, entry):
37                ''' Queue new entry, open window if there's no one opened. '''
38                cls.entries.append(entry)
39
40                if cls.window is None:
41                        cls.window = AtomWindow()
42                else:
43                        cls.window.updateCounter()
44
45        def __init__(self):
46                ''' Create new window... only if we have anything to show. '''
47                assert len(self.__class__.entries)>0
48
49                self.entry = None       # the entry actually displayed
50
51                self.xml = gtkgui_helpers.get_glade('atom_entry_window.glade')
52                self.window = self.xml.get_widget('atom_entry_window')
53                for name in ('new_entry_label', 'feed_title_label', 'feed_title_eventbox',
54                        'feed_tagline_label', 'entry_title_label', 'entry_title_eventbox',
55                        'last_modified_label', 'close_button', 'next_button'):
56                        self.__dict__[name] = self.xml.get_widget(name)
57
58                self.displayNextEntry()
59
60                self.xml.signal_autoconnect(self)
61                self.window.show_all()
62
63                self.entry_title_eventbox.add_events(gtk.gdk.BUTTON_PRESS_MASK)
64                self.feed_title_eventbox.add_events(gtk.gdk.BUTTON_PRESS_MASK)
65
66        def displayNextEntry(self):
67                ''' Get next entry from the queue and display it in the window. '''
68                assert len(self.__class__.entries)>0
69
70                newentry = self.__class__.entries.pop(0)
71               
72                # fill the fields
73                if newentry.feed_link is not None:
74                        self.feed_title_label.set_markup(
75                                u'<span foreground="blue" underline="single">%s</span>' % \
76                                gobject.markup_escape_text(newentry.feed_title))
77                else:
78                        self.feed_title_label.set_markup(
79                                gobject.markup_escape_text(newentry.feed_title))
80
81                self.feed_tagline_label.set_markup(
82                        u'<small>%s</small>' % \
83                        gobject.markup_escape_text(newentry.feed_tagline))
84
85                if newentry.uri is not None:
86                        self.entry_title_label.set_markup(
87                                u'<span foreground="blue" underline="single">%s</span>' % \
88                                gobject.markup_escape_text(newentry.title))
89                else:
90                        self.entry_title_label.set_markup(
91                                gobject.markup_escape_text(newentry.title))
92
93                self.last_modified_label.set_text(newentry.updated)
94
95                # update the counters
96                self.updateCounter()
97
98                self.entry = newentry
99
100        def updateCounter(self):
101                ''' We display number of events on the top of window, sometimes it needs to be
102                changed...'''
103                count = len(self.__class__.entries)
104                # TODO: translate
105                if count>0:
106                        self.new_entry_label.set_text( \
107                                'You have received new entries (and %(count)d not displayed):' % \
108                                {'count': count})
109                        self.next_button.set_sensitive(True)
110                else:
111                        self.new_entry_label.set_text('You have received new entry:')
112                        self.next_button.set_sensitive(False)
113
114        def on_close_button_clicked(self, widget):
115                self.window.destroy()
116
117        def on_next_button_clicked(self, widget):
118                self.displayNextEntry()
119
120        def on_entry_title_button_press_event(self, widget, event):
121                #FIXME: make it using special gtk2.10 widget
122                if event.button == 1:   # left click
123                        uri = self.entry.uri
124                        if uri is not None:
125                                helpers.launch_browser_mailer('url', uri)
126                return True
127
128        def on_feed_title_button_press_event(self, widget, event):
129                #FIXME: make it using special gtk2.10 widget
130                if event.button == 1:   # left click
131                        uri = self.entry.feed_uri
132                        if uri is not None:
133                                helpers.launch_browser_mailer('url', uri)
134                return True
135
136# vim: se ts=3:
Note: See TracBrowser for help on using the browser.