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
12 class GUIHandler(handler
.Handler
):
13 dl_callbacks
= None # Download -> [ callback ]
17 def _reset_counters(self
):
18 if not self
.monitored_downloads
:
19 self
.n_completed_downloads
= 0
20 self
.total_bytes_downloaded
= 0
23 def abort_all_downloads(self
):
24 for dl
in self
.monitored_downloads
.values():
27 def downloads_changed(self
):
28 if self
.monitored_downloads
and self
.pulse
is None:
30 self
.mainwindow
.update_download_status()
33 self
.pulse
= gobject
.timeout_add(200, pulse
)
34 elif len(self
.monitored_downloads
) == 0:
35 # Delay before resetting, in case we start a new download quickly
36 gobject
.timeout_add(500, self
._reset
_counters
)
40 gobject
.source_remove(self
.pulse
)
42 self
.mainwindow
.update_download_status()
44 def impl_added_to_store(self
, impl
):
45 self
.mainwindow
.update_download_status()
48 def confirm_import_feed(self
, pending
, valid_sigs
):
49 if self
.mainwindow
.systray_icon
:
50 self
.mainwindow
.systray_icon
.set_tooltip(_('Need to confirm a new GPG key'))
51 self
.mainwindow
.systray_icon
.set_blinking(True)
53 # Wait for the user to click the icon, then continue
54 yield self
.mainwindow
.systray_icon_blocker
55 yield tasks
.TimeoutBlocker(0.5, 'Delay')
57 from zeroinstall
.gtkui
import trust_box
58 box
= trust_box
.TrustBox(pending
, valid_sigs
, parent
= self
.mainwindow
.window
)
62 def report_error(self
, ex
, tb
= None):
63 if isinstance(ex
, download
.DownloadAborted
):
64 return # No need to tell the user about this, since they caused it
65 self
.mainwindow
.report_exception(ex
)