Module atom_window
[hide private]
[frames] | no frames]

Source Code for Module atom_window

  1  # -*- coding:utf-8 -*- 
  2  ## src/atom_window.py 
  3  ## 
  4  ## Copyright (C) 2006 Tomasz Melcer <liori AT exroot.org> 
  5  ## Copyright (C) 2006-2010 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   
 25  import gtk 
 26  import gobject 
 27   
 28  import gtkgui_helpers 
 29  from common import helpers 
 30  from common import i18n 
31 32 -class AtomWindow:
33 window = None 34 entries = [] 35 36 @classmethod
37 - def newAtomEntry(cls, entry):
38 """ 39 Queue new entry, open window if there's no one opened 40 """ 41 cls.entries.append(entry) 42 43 if cls.window is None: 44 cls.window = AtomWindow() 45 else: 46 cls.window.updateCounter()
47 48 @classmethod
49 - def windowClosed(cls):
50 cls.window = None
51
52 - def __init__(self):
53 """ 54 Create new window... only if we have anything to show 55 """ 56 assert len(self.__class__.entries) 57 58 self.entry = None # the entry actually displayed 59 60 self.xml = gtkgui_helpers.get_gtk_builder('atom_entry_window.ui') 61 self.window = self.xml.get_object('atom_entry_window') 62 for name in ('new_entry_label', 'feed_title_label', 63 'feed_title_eventbox', 'feed_tagline_label', 'entry_title_label', 64 'entry_title_eventbox', 'last_modified_label', 'close_button', 65 'next_button'): 66 self.__dict__[name] = self.xml.get_object(name) 67 68 self.displayNextEntry() 69 70 self.xml.connect_signals(self) 71 self.window.show_all() 72 73 self.entry_title_eventbox.add_events(gtk.gdk.BUTTON_PRESS_MASK) 74 self.feed_title_eventbox.add_events(gtk.gdk.BUTTON_PRESS_MASK)
75
76 - def displayNextEntry(self):
77 """ 78 Get next entry from the queue and display it in the window 79 """ 80 assert len(self.__class__.entries)>0 81 82 newentry = self.__class__.entries.pop(0) 83 84 # fill the fields 85 if newentry.feed_link is not None: 86 self.feed_title_label.set_markup( 87 u'<span foreground="blue" underline="single">%s</span>' % \ 88 gobject.markup_escape_text(newentry.feed_title)) 89 else: 90 self.feed_title_label.set_markup( 91 gobject.markup_escape_text(newentry.feed_title)) 92 93 self.feed_tagline_label.set_markup( 94 u'<small>%s</small>' % \ 95 gobject.markup_escape_text(newentry.feed_tagline)) 96 97 if newentry.title: 98 if newentry.uri is not None: 99 self.entry_title_label.set_markup( 100 u'<span foreground="blue" underline="single">%s</span>' % \ 101 gobject.markup_escape_text(newentry.title)) 102 else: 103 self.entry_title_label.set_markup( 104 gobject.markup_escape_text(newentry.title)) 105 else: 106 self.entry_title_label.set_markup('') 107 108 self.last_modified_label.set_text(newentry.updated) 109 110 # update the counters 111 self.updateCounter() 112 113 self.entry = newentry
114
115 - def updateCounter(self):
116 """ 117 Display number of events on the top of window, sometimes it needs to be 118 changed 119 """ 120 count = len(self.__class__.entries) 121 if count: 122 self.new_entry_label.set_text(i18n.ngettext( 123 'You have received new entries (and %d not displayed):', 124 'You have received new entries (and %d not displayed):', count, 125 count, count)) 126 self.next_button.set_sensitive(True) 127 else: 128 self.new_entry_label.set_text(_('You have received new entry:')) 129 self.next_button.set_sensitive(False)
130
131 - def on_close_button_clicked(self, widget):
132 self.window.destroy() 133 self.windowClosed()
134
135 - def on_next_button_clicked(self, widget):
136 self.displayNextEntry()
137
138 - def on_entry_title_eventbox_button_press_event(self, widget, event):
139 #FIXME: make it using special gtk2.10 widget 140 if event.button == 1: # left click 141 uri = self.entry.uri 142 if uri is not None: 143 helpers.launch_browser_mailer('url', uri) 144 return True
145
146 - def on_feed_title_eventbox_button_press_event(self, widget, event):
147 #FIXME: make it using special gtk2.10 widget 148 if event.button == 1: # left click 149 uri = self.entry.feed_uri 150 if uri is not None: 151 helpers.launch_browser_mailer('url', uri) 152 return True
153