~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to windows/plat/frontends/widgets/update.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Miro - an RSS based video player application
 
2
# Copyright (C) 2009-2010 Participatory Culture Foundation
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
#
 
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
 
20
# library.
 
21
#
 
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.
 
28
 
 
29
from miro.frontends.widgets.gtk import wrappermap
 
30
from miro.frontends.widgets.gtk.widgetset import Widget
 
31
 
 
32
import gtk
 
33
import gobject
 
34
 
 
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
 
40
 
 
41
class UpdateAvailableBrowserWidget(gtk.DrawingArea):
 
42
    # this is partially duplicated from browser.py
 
43
    def __init__(self, url):
 
44
        gtk.DrawingArea.__init__(self)
 
45
        self.browser = None
 
46
        self.url = url
 
47
        self.set_size_request(200, 300)
 
48
        self.add_events(gtk.gdk.EXPOSURE_MASK)
 
49
 
 
50
    def navigate(self, url):
 
51
        self.browser.load_uri(url)
 
52
 
 
53
    def do_realize(self):
 
54
        gtk.DrawingArea.do_realize(self)
 
55
        if self.browser is None:
 
56
            self.browser = xulrunnerbrowser.XULRunnerBrowser(self.window.handle,
 
57
                                                             0, 0, 1, 1)
 
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)
 
62
        self.browser.enable()
 
63
 
 
64
    def do_unrealize(self):
 
65
        gtk.DrawingArea.do_unrealize(self)
 
66
        self.browser.disable()
 
67
 
 
68
    def do_destroy(self):
 
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()
 
74
 
 
75
    def do_focus_in_event(self, event):
 
76
        gtk.DrawingArea.do_focus_in_event(self, event)
 
77
        self.browser.focus()
 
78
 
 
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)
 
83
 
 
84
    def on_browser_focus(self, forward):
 
85
        def change_focus():
 
86
            toplevel = self.get_toplevel()
 
87
            toplevel.window.focus()
 
88
            if forward:
 
89
                toplevel.emit('move-focus', gtk.DIR_TAB_FORWARD)
 
90
            else:
 
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)
 
95
 
 
96
    def on_uri_load(self, uri):
 
97
        if uri == self.url:
 
98
            return True
 
99
        else:
 
100
            app.widgetapp.open_url(uri)
 
101
            return False
 
102
 
 
103
    def on_net_start(self):
 
104
        wrappermap.wrapper(self).emit('net-start')
 
105
 
 
106
    def on_net_stop(self):
 
107
        wrappermap.wrapper(self).emit('net-stop')
 
108
 
 
109
gobject.type_register(UpdateAvailableBrowserWidget)
 
110
 
 
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)
 
116
        self.url = url
 
117
 
 
118
        # TODO: implement net-start and net-stop signaling on windows.
 
119
        self.create_signal('net-start')
 
120
        self.create_signal('net-stop')
 
121
 
 
122
    def navigate(self, url):
 
123
        self._widget.navigate(url)
 
124
 
 
125
    def get_current_url(self):
 
126
        return self.url
 
127
 
 
128
    def can_go_back(self):
 
129
        return self._widget.browser.can_go_back()
 
130
 
 
131
    def can_go_forward(self):
 
132
        return self._widget.browser.can_go_forward()
 
133
 
 
134
    def back(self):
 
135
        self._widget.browser.go_back()
 
136
 
 
137
    def forward(self):
 
138
        self._widget.browser.go_forward()
 
139
 
 
140
    def stop(self):
 
141
        self._widget.browser.stop()
 
142
 
 
143
    def reload(self):
 
144
        self._widget.browser.reload()
 
145
 
 
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()
 
151
        label.set_text(
 
152
            _('A new version of %(appname)s is available for download.',
 
153
              {"appname": config.get(prefs.SHORT_APP_NAME)}))
 
154
        label2 = widgetset.Label()
 
155
        label2.set_text(
 
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)
 
164
 
 
165
    def run(self):
 
166
        response = dialogs.MainDialog.run(self)
 
167
        if response:
 
168
            return dialogs.BUTTON_NO
 
169
        else:
 
170
            return dialogs.BUTTON_YES
 
171
 
 
172