Added about dialog.
[drlaunch] / src / about0.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 _ = str
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         self.set_size_request(800,480)
65         pa=hildon.PannableArea()
66         pa.set_property('mov-mode', 
67                 hildon.MOVEMENT_MODE_HORIZ | hildon.MOVEMENT_MODE_VERT )
68         vbox=gtk.VBox()
69         self.vbox.add(pa)
70         pa.add_with_viewport(vbox)
71         content_area = vbox
72
73         self.table_layout.attach(self.image_icon, 0, 1, 0, 2, 0, gtk.EXPAND, 0, 0)
74         self.table_layout.attach(self.label_app_name, 1, 2, 0, 1, 0, gtk.EXPAND | gtk.FILL, 0, 0)
75         self.table_layout.attach(self.label_version, 2, 3, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)
76         self.table_layout.attach(self.label_description, 1, 3, 1, 2, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)
77         self.table_layout.attach(self.label_copyright, 0, 3, 2, 3, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL, 0, 0)
78         content_area.add(self.table_layout)
79         self.connect('response', self._on_response)
80         self.show_all()
81
82     def _on_response(self, dialog, response_id):
83         if response_id == HeAboutDialog.RESPONSE_WEBSITE:
84             self.open_webbrowser(self.website_url)
85         elif response_id == HeAboutDialog.RESPONSE_BUGTRACKER:
86             self.open_webbrowser(self.bugtracker_url)
87         elif response_id == HeAboutDialog.RESPONSE_DONATE:
88             self.open_webbrowser(self.donate_url)
89
90     def set_app_name(self, app_name):
91         self.label_app_name.set_text(app_name)
92         self.set_title(_('About %s') % app_name)
93
94     def set_icon_name(self, icon_name):
95         self.image_icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_DIALOG)
96
97     def set_version(self, version):
98         self.label_version.set_text(version)
99
100     def set_description(self, description):
101         self.label_description.set_text(description)
102
103     def set_copyright(self, copyright):
104         self.label_copyright.set_text(copyright)
105
106     def set_website(self, url):
107         if self.website_url is None:
108             self.add_button(_('Visit website'), HeAboutDialog.RESPONSE_WEBSITE)
109         self.website_url = url
110
111     def set_bugtracker(self, url):
112         if self.bugtracker_url is None:
113             self.add_button(_('Report bug'), HeAboutDialog.RESPONSE_BUGTRACKER)
114         self.bugtracker_url = url
115
116     def set_donate_url(self, url):
117         if self.donate_url is None:
118             self.add_button(_('Donate'), HeAboutDialog.RESPONSE_DONATE)
119         self.donate_url = url
120
121     def open_webbrowser(self, url):
122         bus = dbus.SessionBus()
123         proxy = bus.get_object('com.nokia.osso_browser', '/com/nokia/osso_browser/request', 'com.nokia.osso_browser')
124         proxy.load_url(url, dbus_interface='com.nokia.osso_browser')
125
126     @classmethod
127     def present(cls, parent=None, app_name=None, icon_name=None, \
128             version=None, description=None, copyright=None, \
129             website_url=None, bugtracker_url=None, donate_url=None):
130         ad = cls()
131
132         if parent is not None:
133             ad.set_transient_for(parent)
134             ad.set_destroy_with_parent(True)
135
136         if app_name is not None:
137             ad.set_app_name(app_name)
138
139         ad.set_icon_name(icon_name)
140         ad.set_version(version)
141         ad.set_description(description)
142         ad.set_copyright(copyright)
143
144         if website_url is not None:
145             ad.set_website(website_url)
146
147         if bugtracker_url is not None:
148             ad.set_bugtracker(bugtracker_url)
149
150         if donate_url is not None:
151             ad.set_donate_url(donate_url)
152
153         ad.run()
154         ad.destroy()
155