2007-01-17 00:26:38 +01:00
|
|
|
## atom_window.py - a window to display atom entries from pubsub.
|
|
|
|
##
|
|
|
|
## For now greatly simplified, supports only simple feeds like the
|
|
|
|
## one from pubsub.com.
|
|
|
|
##
|
|
|
|
## Copyright (C) 2006-2007 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Copyright (C) 2007 Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
## Copyright (C) 2006-2007 Liori (I think) put ur self here please
|
|
|
|
##
|
|
|
|
## 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; version 2 only.
|
|
|
|
##
|
|
|
|
## 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.
|
|
|
|
##
|
|
|
|
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
import gtk
|
2007-01-17 00:26:38 +01:00
|
|
|
import gobject
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
import gtkgui_helpers
|
|
|
|
from common import helpers
|
|
|
|
|
|
|
|
class AtomWindow:
|
|
|
|
window = None
|
|
|
|
entries = []
|
|
|
|
|
2007-01-17 00:26:38 +01:00
|
|
|
@classmethod
|
2006-07-21 15:52:36 +02:00
|
|
|
def newAtomEntry(cls, entry):
|
|
|
|
''' Queue new entry, open window if there's no one opened. '''
|
|
|
|
cls.entries.append(entry)
|
|
|
|
|
|
|
|
if cls.window is None:
|
|
|
|
cls.window = AtomWindow()
|
|
|
|
else:
|
|
|
|
cls.window.updateCounter()
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
''' Create new window... only if we have anything to show. '''
|
|
|
|
assert len(self.__class__.entries)>0
|
|
|
|
|
|
|
|
self.entry = None # the entry actually displayed
|
|
|
|
|
|
|
|
self.xml = gtkgui_helpers.get_glade('atom_entry_window.glade')
|
|
|
|
self.window = self.xml.get_widget('atom_entry_window')
|
|
|
|
for name in ('new_entry_label', 'feed_title_label', 'feed_title_eventbox',
|
|
|
|
'feed_tagline_label', 'entry_title_label', 'entry_title_eventbox',
|
|
|
|
'last_modified_label', 'close_button', 'next_button'):
|
|
|
|
self.__dict__[name] = self.xml.get_widget(name)
|
|
|
|
|
|
|
|
self.displayNextEntry()
|
|
|
|
|
|
|
|
self.xml.signal_autoconnect(self)
|
|
|
|
self.window.show_all()
|
|
|
|
|
|
|
|
self.entry_title_eventbox.add_events(gtk.gdk.BUTTON_PRESS_MASK)
|
|
|
|
self.feed_title_eventbox.add_events(gtk.gdk.BUTTON_PRESS_MASK)
|
|
|
|
|
|
|
|
def displayNextEntry(self):
|
|
|
|
''' Get next entry from the queue and display it in the window. '''
|
|
|
|
assert len(self.__class__.entries)>0
|
|
|
|
|
|
|
|
newentry = self.__class__.entries.pop(0)
|
|
|
|
|
|
|
|
# fill the fields
|
|
|
|
if newentry.feed_link is not None:
|
|
|
|
self.feed_title_label.set_markup(
|
|
|
|
u'<span foreground="blue" underline="single">%s</span>' % \
|
2007-01-17 00:26:38 +01:00
|
|
|
gobject.markup_escape_text(newentry.feed_title))
|
2006-07-21 15:52:36 +02:00
|
|
|
else:
|
|
|
|
self.feed_title_label.set_markup(
|
2007-01-17 00:26:38 +01:00
|
|
|
gobject.markup_escape_text(newentry.feed_title))
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
self.feed_tagline_label.set_markup(
|
|
|
|
u'<small>%s</small>' % \
|
2007-01-17 00:26:38 +01:00
|
|
|
gobject.markup_escape_text(newentry.feed_tagline))
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
if newentry.uri is not None:
|
|
|
|
self.entry_title_label.set_markup(
|
|
|
|
u'<span foreground="blue" underline="single">%s</span>' % \
|
2007-01-17 00:26:38 +01:00
|
|
|
gobject.markup_escape_text(newentry.title))
|
2006-07-21 15:52:36 +02:00
|
|
|
else:
|
|
|
|
self.entry_title_label.set_markup(
|
2007-01-17 00:26:38 +01:00
|
|
|
gobject.markup_escape_text(newentry.title))
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
self.last_modified_label.set_text(newentry.updated)
|
|
|
|
|
|
|
|
# update the counters
|
|
|
|
self.updateCounter()
|
|
|
|
|
|
|
|
self.entry = newentry
|
|
|
|
|
|
|
|
def updateCounter(self):
|
|
|
|
''' We display number of events on the top of window, sometimes it needs to be
|
|
|
|
changed...'''
|
|
|
|
count = len(self.__class__.entries)
|
|
|
|
# TODO: translate
|
|
|
|
if count>0:
|
|
|
|
self.new_entry_label.set_text( \
|
|
|
|
'You have received new entries (and %(count)d not displayed):' % \
|
|
|
|
{'count': count})
|
|
|
|
self.next_button.set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self.new_entry_label.set_text('You have received new entry:')
|
|
|
|
self.next_button.set_sensitive(False)
|
|
|
|
|
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def on_next_button_clicked(self, widget):
|
|
|
|
self.displayNextEntry()
|
|
|
|
|
|
|
|
def on_entry_title_button_press_event(self, widget, event):
|
2007-01-17 00:26:38 +01:00
|
|
|
#FIXME: make it using special gtk2.10 widget
|
2006-07-21 15:52:36 +02:00
|
|
|
if event.button == 1: # left click
|
|
|
|
uri = self.entry.uri
|
|
|
|
if uri is not None:
|
|
|
|
helpers.launch_browser_mailer('url', uri)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def on_feed_title_button_press_event(self, widget, event):
|
2007-01-17 00:26:38 +01:00
|
|
|
#FIXME: make it using special gtk2.10 widget
|
2006-07-21 15:52:36 +02:00
|
|
|
if event.button == 1: # left click
|
|
|
|
uri = self.entry.feed_uri
|
|
|
|
if uri is not None:
|
|
|
|
helpers.launch_browser_mailer('url', uri)
|
|
|
|
return True
|