1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
6 from zeroinstall
.support
import tasks
7 from zeroinstall
.injector
import handler
, download
11 class GUIHandler(handler
.Handler
):
12 dl_callbacks
= None # Download -> [ callback ]
16 def _reset_counters(self
):
17 if not self
.monitored_downloads
:
18 self
.n_completed_downloads
= 0
19 self
.total_bytes_downloaded
= 0
22 def abort_all_downloads(self
):
23 for dl
in self
.monitored_downloads
.values():
26 def downloads_changed(self
):
27 if self
.monitored_downloads
and self
.pulse
is None:
29 self
.mainwindow
.update_download_status()
32 self
.pulse
= gobject
.timeout_add(200, pulse
)
33 elif len(self
.monitored_downloads
) == 0:
34 # Delay before resetting, in case we start a new download quickly
35 gobject
.timeout_add(500, self
._reset
_counters
)
39 gobject
.source_remove(self
.pulse
)
41 self
.mainwindow
.update_download_status()
43 def impl_added_to_store(self
, impl
):
44 self
.mainwindow
.update_download_status()
47 def _switch_to_main_window(self
, reason
):
48 if self
.mainwindow
.systray_icon
:
49 self
.mainwindow
.systray_icon
.set_tooltip(reason
)
50 self
.mainwindow
.systray_icon
.set_blinking(True)
52 # Wait for the user to click the icon, then continue
53 yield self
.mainwindow
.systray_icon_blocker
54 yield tasks
.TimeoutBlocker(0.5, 'Delay')
57 def confirm_import_feed(self
, pending
, valid_sigs
):
58 yield self
._switch
_to
_main
_window
(_('Need to confirm a new GPG key'))
60 from zeroinstall
.gtkui
import trust_box
61 box
= trust_box
.TrustBox(pending
, valid_sigs
, parent
= self
.mainwindow
.window
)
66 def confirm_install(self
, message
):
67 yield self
._switch
_to
_main
_window
(_('Need to confirm installation of distribution packages'))
69 from zeroinstall
.injector
.download
import DownloadAborted
70 from zeroinstall
.gtkui
import gtkutils
73 box
= gtk
.MessageDialog(self
.mainwindow
.window
,
74 gtk
.DIALOG_DESTROY_WITH_PARENT
,
75 gtk
.MESSAGE_QUESTION
, gtk
.BUTTONS_CANCEL
,
77 box
.set_position(gtk
.WIN_POS_CENTER
)
79 install
= dialog
.MixedButton(_('Install'), gtk
.STOCK_OK
)
80 install
.set_flags(gtk
.CAN_DEFAULT
)
81 box
.add_action_widget(install
, gtk
.RESPONSE_OK
)
83 box
.set_default_response(gtk
.RESPONSE_OK
)
86 response
= dialog
.DialogResponse(box
)
90 if response
.response
!= gtk
.RESPONSE_OK
:
91 raise DownloadAborted()
93 def report_error(self
, ex
, tb
= None):
94 if isinstance(ex
, download
.DownloadAborted
):
95 return # No need to tell the user about this, since they caused it
96 self
.mainwindow
.report_exception(ex
, tb
= tb
)