1 import gtk
, os
, gobject
, sys
3 from zeroinstall
.injector
.iface_cache
import iface_cache
4 from zeroinstall
.injector
.policy
import Policy
5 from zeroinstall
.injector
import download
, handler
6 from zeroinstall
.injector
.model
import SafeException
7 from zeroinstall
.injector
.reader
import InvalidInterface
8 from zeroinstall
.support
import tasks
, pretty_size
13 class GUIHandler(handler
.Handler
):
14 dl_callbacks
= None # Download -> [ callback ]
18 def downloads_changed(self
):
19 if self
.monitored_downloads
and self
.pulse
is None:
21 progress
= self
.mainwindow
.progress
24 done
= total
= self
.total_bytes_downloaded
# Completed downloads
25 n_downloads
= self
.n_completed_downloads
26 # Now add downloads in progress...
27 for x
in self
.monitored_downloads
.values():
28 if x
.status
!= download
.download_fetching
: continue
32 so_far
= x
.get_bytes_downloaded_so_far()
33 total
+= x
.expected_size
or max(4096, so_far
) # Guess about 4K for feeds/icons
36 progress_text
= '%s / %s' % (pretty_size(done
), pretty_size(total
))
38 progress
.set_text('Downloading one file (%s)' % progress_text
)
40 progress
.set_text('Downloading %d files (%s)' % (n_downloads
, progress_text
))
42 if total
== 0 or (n_downloads
< 2 and not any_known
):
45 progress
.set_fraction(float(done
) / total
)
49 self
.pulse
= gobject
.timeout_add(50, pulse
)
50 self
.mainwindow
.progress
.show()
51 elif len(self
.monitored_downloads
) == 0:
53 self
.n_completed_downloads
= 0
54 self
.total_bytes_downloaded
= 0
58 gobject
.source_remove(self
.pulse
)
59 self
.mainwindow
.progress
.hide()
62 def confirm_trust_keys(self
, interface
, sigs
, iface_xml
):
64 return trust_box
.confirm_trust(interface
, sigs
, iface_xml
, parent
= self
.mainwindow
.window
)
66 def report_error(self
, ex
):
67 dialog
.alert(None, str(ex
))