2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/atom_window.py
|
2007-01-17 00:26:38 +01:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Tomasz Melcer <liori AT exroot.org>
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2007 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
2007-01-17 00:26:38 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2007-01-17 00:26:38 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2007-01-17 00:26:38 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2007-01-17 00:26:38 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2007-01-17 00:26:38 +01:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2007-01-17 00:26:38 +01:00
|
|
|
|
2006-07-21 15:52:36 +02:00
|
|
|
|
2015-01-19 13:39:11 +01:00
|
|
|
from gi.repository import Gdk
|
2013-07-29 21:41:01 +02:00
|
|
|
from gi.repository import GLib
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
import gtkgui_helpers
|
|
|
|
from common import helpers
|
2009-10-29 15:00:48 +01:00
|
|
|
from common import i18n
|
2006-07-21 15:52:36 +02:00
|
|
|
|
|
|
|
class AtomWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
window = None
|
|
|
|
entries = []
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
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()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def windowClosed(cls):
|
|
|
|
cls.window = None
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""
|
|
|
|
Create new window... only if we have anything to show
|
|
|
|
"""
|
2010-05-25 09:36:30 +02:00
|
|
|
assert len(self.__class__.entries)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-05-25 09:36:30 +02:00
|
|
|
self.entry = None # the entry actually displayed
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('atom_entry_window.ui')
|
|
|
|
self.window = self.xml.get_object('atom_entry_window')
|
2010-05-25 09:36:30 +02:00
|
|
|
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'):
|
2010-02-08 15:08:40 +01:00
|
|
|
self.__dict__[name] = self.xml.get_object(name)
|
|
|
|
|
|
|
|
self.displayNextEntry()
|
|
|
|
|
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.window.show_all()
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
self.entry_title_eventbox.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
|
|
|
self.feed_title_eventbox.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
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(
|
2013-01-01 19:44:25 +01:00
|
|
|
'<span foreground="blue" underline="single">%s</span>' % \
|
2013-07-29 21:41:01 +02:00
|
|
|
GLib.markup_escape_text(newentry.feed_title))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2013-07-29 21:41:01 +02:00
|
|
|
self.feed_title_label.set_markup(GLib.markup_escape_text(
|
|
|
|
newentry.feed_title))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.feed_tagline_label.set_markup(
|
2013-07-29 21:41:01 +02:00
|
|
|
'<small>%s</small>' % GLib.markup_escape_text(
|
|
|
|
newentry.feed_tagline))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-05-25 09:46:12 +02:00
|
|
|
if newentry.title:
|
|
|
|
if newentry.uri is not None:
|
|
|
|
self.entry_title_label.set_markup(
|
2013-01-01 19:44:25 +01:00
|
|
|
'<span foreground="blue" underline="single">%s</span>' % \
|
2013-07-29 21:41:01 +02:00
|
|
|
GLib.markup_escape_text(newentry.title))
|
2010-05-25 09:46:12 +02:00
|
|
|
else:
|
2013-07-29 21:41:01 +02:00
|
|
|
self.entry_title_label.set_markup(GLib.markup_escape_text(
|
|
|
|
newentry.title))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2010-05-25 09:46:12 +02:00
|
|
|
self.entry_title_label.set_markup('')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.last_modified_label.set_text(newentry.updated)
|
|
|
|
|
|
|
|
# update the counters
|
|
|
|
self.updateCounter()
|
|
|
|
|
|
|
|
self.entry = newentry
|
|
|
|
|
|
|
|
def updateCounter(self):
|
|
|
|
"""
|
|
|
|
Display number of events on the top of window, sometimes it needs to be
|
|
|
|
changed
|
|
|
|
"""
|
|
|
|
count = len(self.__class__.entries)
|
2010-05-25 09:36:30 +02:00
|
|
|
if count:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.new_entry_label.set_text(i18n.ngettext(
|
2010-05-25 09:36:30 +02:00
|
|
|
'You have received new entries (and %d not displayed):',
|
|
|
|
'You have received new entries (and %d not displayed):', count,
|
|
|
|
count, count))
|
2010-02-08 15:08:40 +01:00
|
|
|
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()
|
|
|
|
self.windowClosed()
|
|
|
|
|
|
|
|
def on_next_button_clicked(self, widget):
|
|
|
|
self.displayNextEntry()
|
|
|
|
|
2010-05-25 09:01:06 +02:00
|
|
|
def on_entry_title_eventbox_button_press_event(self, widget, event):
|
2010-02-08 15:08:40 +01:00
|
|
|
#FIXME: make it using special gtk2.10 widget
|
|
|
|
if event.button == 1: # left click
|
|
|
|
uri = self.entry.uri
|
|
|
|
if uri is not None:
|
|
|
|
helpers.launch_browser_mailer('url', uri)
|
|
|
|
return True
|
|
|
|
|
2010-05-25 09:01:06 +02:00
|
|
|
def on_feed_title_eventbox_button_press_event(self, widget, event):
|
2010-02-08 15:08:40 +01:00
|
|
|
#FIXME: make it using special gtk2.10 widget
|
|
|
|
if event.button == 1: # left click
|
|
|
|
uri = self.entry.feed_uri
|
|
|
|
if uri is not None:
|
|
|
|
helpers.launch_browser_mailer('url', uri)
|
|
|
|
return True
|