3
3
# Copyright (c) 2004-2008 Canonical
4
4
# 2004 Michiel Sikkes
5
5
# 2005 Martin Willemoes Hansen
6
# 2010 Mohamed Amine IL Idrissi
7
8
# Author: Michiel Sikkes <michiel@eyesopened.nl>
8
9
# Michael Vogt <mvo@debian.org>
9
10
# Martin Willemoes Hansen <mwh@sysrq.dk>
11
# Mohamed Amine IL Idrissi <ilidrissiamine@gmail.com>
11
13
# This program is free software; you can redistribute it and/or
12
14
# modify it under the terms of the GNU General Public License as
73
75
from Core.UpdateList import UpdateList
74
76
from Core.MyCache import MyCache, NotEnoughFreeSpaceError
75
77
from Core.MetaRelease import Dist
78
from Core.AlertWatcher import AlertWatcher
76
79
from SafeGConfClient import SafeGConfClient
78
81
from DistUpgradeFetcher import DistUpgradeFetcherGtk
95
98
# file that signals if we need to reboot
96
99
REBOOT_REQUIRED_FILE = "/var/run/reboot-required"
101
# NetworkManager enums
104
NM_STATE_CONNECTING = 2
105
NM_STATE_CONNECTED = 3
106
NM_STATE_DISCONNECTED = 4
98
108
class UpdateManagerDbusControler(dbus.service.Object):
99
109
""" this is a helper to provide the UpdateManagerIFace """
100
110
def __init__(self, parent, bus_name,
224
234
self.window_main.set_urgency_hint(True)
225
235
self.initial_focus_id = self.window_main.connect(
226
236
"focus-in-event", self.on_initial_focus_in)
228
self.warn_on_battery()
239
self.alert_watcher = AlertWatcher()
240
self.alert_watcher.connect("network-alert", self._on_network_alert)
241
self.alert_watcher.connect("battery-alert", self._on_battery_alert)
230
243
def on_initial_focus_in(self, widget, event):
231
244
"""callback run on initial focus-in (if started unmapped)"""
233
246
widget.set_urgency_hint(False)
234
247
self.window_main.disconnect(self.initial_focus_id)
235
self.warn_on_battery()
238
250
def warn_on_battery(self):
459
471
inst_count = self.cache.installCount
460
472
self.dl_size = self.cache.requiredDownload
461
t = _("Download size: %s\n%s selected.") % (
462
humanize_size(self.dl_size),inst_count)
463
self.label_downsize.set_text(t)
476
count_str = ngettext("%(count)s update has been selected. ",
477
"%(count)s updates have been selected. ",
478
inst_count) % { 'count' : inst_count }
479
if self.dl_size != 0:
480
download_str = _("%s will be downloaded.") % (humanize_size(self.dl_size))
481
self.image_downsize.set_sensitive(True)
482
if self.alert_watcher.network_state != NM_STATE_CONNECTED:
483
self.button_install.set_sensitive(False)
485
self.button_install.set_sensitive(True)
488
download_str = ngettext("The update has already been downloaded, but not installed",
489
"The updates have already been downloaded, but not installed", inst_count)
490
self.button_install.set_sensitive(True)
492
download_str = _("There is no updates to install")
493
self.button_install.set_sensitive(False)
494
self.image_downsize.set_sensitive(False)
495
# TRANSLATORS: this allows to switch the order of the count of
496
# updates and the download size string (if needed)
497
self.label_downsize.set_text(_("%(count_str)s%(download_str)s") % {
498
'count_str' : count_str,
499
'download_str' : download_str})
500
self.hbox_downsize.show()
501
self.vbox_alerts.show()
464
502
except SystemError, e:
465
503
print "requiredDownload could not be calculated: %s" % e
466
self.label_downsize.set_markup(_("Unknown download size"))
504
self.label_downsize.set_markup(_("Unknown download size."))
505
self.image_downsize.set_sensitive(False)
506
self.hbox_downsize.show()
507
self.vbox_alerts.show()
468
509
def _get_last_apt_get_update_text(self):
666
707
self.window_main.set_sensitive(True)
667
708
self.window_main.window.set_cursor(None)
710
def _on_network_alert(self, watcher, state):
711
if state == NM_STATE_CONNECTING:
712
self.label_offline.set_text(_("Connecting..."))
713
self.button_reload.set_sensitive(False)
714
self.refresh_updates_count()
715
self.hbox_offline.show()
716
self.vbox_alerts.show()
717
elif state == NM_STATE_CONNECTED:
718
self.button_reload.set_sensitive(True)
719
self.refresh_updates_count()
720
self.hbox_offline.hide()
722
self.label_offline.set_text(_("You may not be able to check for updates or download new updates."))
723
self.button_reload.set_sensitive(False)
724
self.refresh_updates_count()
725
self.hbox_offline.show()
726
self.vbox_alerts.show()
728
def _on_battery_alert(self, watcher, on_battery):
730
self.hbox_battery.show()
731
self.vbox_alerts.show()
733
self.hbox_battery.hide()
669
735
def row_activated(self, treeview, path, column):
670
736
iter = self.store.get_iter(path)
671
737
pkg = self.store.get_value(iter, LIST_PKG)