1
# Miro - an RSS based video player application
2
# Copyright (C) 2009-2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
29
from miro.frontends.widgets.gtk import wrappermap
30
from miro.frontends.widgets.gtk.widgetset import Widget
35
from miro.plat.frontends.widgets import xulrunnerbrowser
36
from miro.plat.frontends.widgets import widgetset
37
from miro.frontends.widgets import dialogs, widgetutil
38
from miro.gtcache import gettext as _
39
from miro import app, config, prefs
41
class UpdateAvailableBrowserWidget(gtk.DrawingArea):
42
# this is partially duplicated from browser.py
43
def __init__(self, url):
44
gtk.DrawingArea.__init__(self)
47
self.set_size_request(200, 300)
48
self.add_events(gtk.gdk.EXPOSURE_MASK)
50
def navigate(self, url):
51
self.browser.load_uri(url)
54
gtk.DrawingArea.do_realize(self)
55
if self.browser is None:
56
self.browser = xulrunnerbrowser.XULRunnerBrowser(self.window.handle,
58
self.browser.set_callback_object(self)
59
self.navigate(self.url)
60
self.browser.resize(0, 0, self.allocation.width,
61
self.allocation.height)
64
def do_unrealize(self):
65
gtk.DrawingArea.do_unrealize(self)
66
self.browser.disable()
69
gtk.DrawingArea.do_destroy(self)
70
# This seems to be able to get called after our browser attribute no
71
# longer exists. Double check to make sure that's not the case.
72
if hasattr(self, 'browser'):
73
self.browser.destroy()
75
def do_focus_in_event(self, event):
76
gtk.DrawingArea.do_focus_in_event(self, event)
79
def do_size_allocate(self, rect):
80
gtk.DrawingArea.do_size_allocate(self, rect)
81
if self.flags() & gtk.REALIZED:
82
self.browser.resize(0, 0, rect.width, rect.height)
84
def on_browser_focus(self, forward):
86
toplevel = self.get_toplevel()
87
toplevel.window.focus()
89
toplevel.emit('move-focus', gtk.DIR_TAB_FORWARD)
91
toplevel.emit('move-focus', gtk.DIR_TAB_BACKWARD)
92
# for some reason we can't change the focus quite yet. Using
93
# idle_add() fixes the problem though
94
gobject.idle_add(change_focus)
96
def on_uri_load(self, uri):
100
app.widgetapp.open_url(uri)
103
def on_net_start(self):
104
wrappermap.wrapper(self).emit('net-start')
106
def on_net_stop(self):
107
wrappermap.wrapper(self).emit('net-stop')
109
gobject.type_register(UpdateAvailableBrowserWidget)
111
class UpdateAvailableBrowser(Widget):
112
def __init__(self, url):
113
Widget.__init__(self)
114
self.set_widget(UpdateAvailableBrowserWidget(url))
115
self._widget.set_property('can-focus', True)
118
# TODO: implement net-start and net-stop signaling on windows.
119
self.create_signal('net-start')
120
self.create_signal('net-stop')
122
def navigate(self, url):
123
self._widget.navigate(url)
125
def get_current_url(self):
128
def can_go_back(self):
129
return self._widget.browser.can_go_back()
131
def can_go_forward(self):
132
return self._widget.browser.can_go_forward()
135
self._widget.browser.go_back()
138
self._widget.browser.go_forward()
141
self._widget.browser.stop()
144
self._widget.browser.reload()
146
class UpdateAvailableDialog(dialogs.MainDialog):
147
def __init__(self, url):
148
dialogs.MainDialog.__init__(self, _("Update Available"))
149
self.browser = UpdateAvailableBrowser(url)
150
label = widgetset.Label()
152
_('A new version of %(appname)s is available for download.',
153
{"appname": config.get(prefs.SHORT_APP_NAME)}))
154
label2 = widgetset.Label()
156
_('Do you want to download it now?'))
157
self.vbox = widgetset.VBox(spacing=6)
158
self.vbox.pack_end(widgetutil.align_center(label2))
159
self.vbox.pack_end(self.browser, expand=True)
160
self.vbox.pack_end(widgetutil.align_center(label))
161
self.set_extra_widget(self.vbox)
162
self.add_button(dialogs.BUTTON_YES.text)
163
self.add_button(dialogs.BUTTON_NO.text)
166
response = dialogs.MainDialog.run(self)
168
return dialogs.BUTTON_NO
170
return dialogs.BUTTON_YES