psa: adding missing opml_lib library
[feedingit] / src / aboutdialog.py
1 # -*- coding: utf-8 -*-
2 #
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
5 #
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 # Python implementation of HeAboutDialog from hildon-extras
21 # Copyright (c) 2010-04-11 Thomas Perl <thp@thpinfo.com>
22
23 import hildon
24 import gtk
25 import dbus
26
27 _ = lambda x: x
28
29 class HeAboutDialog(gtk.Dialog):
30     RESPONSE_WEBSITE, \
31     RESPONSE_BUGTRACKER, \
32     RESPONSE_DONATE = range(3)
33
34     def __init__(self):
35         gtk.Dialog.__init__(self)
36
37         self.website_url = None
38         self.bugtracker_url = None
39         self.donate_url = None
40
41         self.set_title(_('About'))
42
43         self.image_icon = gtk.Image()
44         self.label_app_name = gtk.Label()
45         self.label_version = gtk.Label()
46         self.label_description = gtk.Label()
47         self.label_copyright = gtk.Label()
48         self.table_layout = gtk.Table(3, 3, False)
49
50         hildon.hildon_helper_set_logical_font(self.label_app_name, 'X-LargeSystemFont')
51         hildon.hildon_helper_set_logical_font(self.label_version, 'LargeSystemFont')
52         hildon.hildon_helper_set_logical_font(self.label_copyright, 'SmallSystemFont')
53         hildon.hildon_helper_set_logical_color(self.label_copyright, gtk.RC_FG, gtk.STATE_NORMAL, 'SecondaryTextColor')
54
55         self.label_app_name.set_alignment(0, 1)
56         self.label_version.set_alignment(0, 1)
57         self.label_description.set_alignment(0, 0)
58         self.label_copyright.set_alignment(0, 1)
59         self.label_version.set_padding(10, 0)
60         self.label_copyright.set_padding(0, 5)
61         self.image_icon.set_padding(5, 5)
62
63         #content_area = self.get_content_area() # Starting with PyGTK 2.14
64         content_area = self.vbox
65
66         self.table_layout.attach(self.image_icon, 0, 1, 0, 2, 0, gtk.EXPAND, 0, 0)
67         self.table_layout.attach(self.label_app_name, 1, 2, 0, 1, 0, gtk.EXPAND | gtk.FILL, 0, 0)
68         self.table_layout.attach(self.label_version, 2, 3, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)
69         self.table_layout.attach(self.label_description, 1, 3, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)
70         self.table_layout.attach(self.label_copyright, 0, 3, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)
71         content_area.add(self.table_layout)
72         self.connect('response', self._on_response)
73         self.show_all()
74
75     def _on_response(self, dialog, response_id):
76         if response_id == HeAboutDialog.RESPONSE_WEBSITE:
77             self.open_webbrowser(self.website_url)
78         elif response_id == HeAboutDialog.RESPONSE_BUGTRACKER:
79             self.open_webbrowser(self.bugtracker_url)
80         elif response_id == HeAboutDialog.RESPONSE_DONATE:
81             self.open_webbrowser(self.donate_url)
82
83     def set_app_name(self, app_name):
84         self.label_app_name.set_text(app_name)
85         self.set_title(_('About %s') % app_name)
86
87     def set_icon_name(self, icon_name):
88         self.image_icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_DIALOG)
89
90     def set_version(self, version):
91         self.label_version.set_text(version)
92
93     def set_description(self, description):
94         self.label_description.set_text(description)
95
96     def set_copyright(self, copyright):
97         self.label_copyright.set_text(copyright)
98
99     def set_website(self, url):
100         if self.website_url is None:
101             self.add_button(_('Visit website'), HeAboutDialog.RESPONSE_WEBSITE)
102         self.website_url = url
103
104     def set_bugtracker(self, url):
105         if self.bugtracker_url is None:
106             self.add_button(_('Report bug'), HeAboutDialog.RESPONSE_BUGTRACKER)
107         self.bugtracker_url = url
108
109     def set_donate_url(self, url):
110         if self.donate_url is None:
111             self.add_button(_('Donate'), HeAboutDialog.RESPONSE_DONATE)
112         self.donate_url = url
113
114     def open_webbrowser(self, url):
115         bus = dbus.SessionBus()
116         proxy = bus.get_object('com.nokia.osso_browser', '/com/nokia/osso_browser/request', 'com.nokia.osso_browser')
117         proxy.load_url(url, dbus_interface='com.nokia.osso_browser')
118
119     @classmethod
120     def present(cls, parent=None, app_name=None, icon_name=None, \
121             version=None, description=None, copyright=None, \
122             website_url=None, bugtracker_url=None, donate_url=None):
123         ad = cls()
124
125         if parent is not None:
126             ad.set_transient_for(parent)
127             ad.set_destroy_with_parent(True)
128
129         if app_name is not None:
130             ad.set_app_name(app_name)
131
132         ad.set_icon_name(icon_name)
133         ad.set_version(version)
134         ad.set_description(description)
135         ad.set_copyright(copyright)
136
137         if website_url is not None:
138             ad.set_website(website_url)
139
140         if bugtracker_url is not None:
141             ad.set_bugtracker(bugtracker_url)
142
143         if donate_url is not None:
144             ad.set_donate_url(donate_url)
145
146         ad.run()
147         ad.destroy()
148