~ubuntu-branches/ubuntu/maverick/update-manager/maverick-updates

« back to all changes in this revision

Viewing changes to UpdateManager/UpdateManager.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt, Mohamed Amine IL Idrissi, Michael Vogt
  • Date: 2010-08-10 15:16:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100810151627-12tnr55qlvtfqjuo
Tags: 1:0.142.6
[ Mohamed Amine IL Idrissi ]
* Implemented battery and network alerts directly in the main window.
  LP: #484249, #426708, #426710, #494772

[ Michael Vogt ]
* UpdateManager/Core/MyCache.py:
  - support looking for the changelog by source version
    (and add tests)
* UpdateManager/Core/utils.py:
  - fix crash when reading the synaptic config (LP: #614170)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#  Copyright (c) 2004-2008 Canonical
4
4
#                2004 Michiel Sikkes
5
5
#                2005 Martin Willemoes Hansen
 
6
#                2010 Mohamed Amine IL Idrissi
6
7
#  
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>
10
12
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
77
80
 
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"
97
100
 
 
101
# NetworkManager enums
 
102
NM_STATE_UNKNOWN = 0
 
103
NM_STATE_ASLEEP = 1
 
104
NM_STATE_CONNECTING = 2
 
105
NM_STATE_CONNECTED = 3
 
106
NM_STATE_DISCONNECTED = 4
 
107
 
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)
227
 
    else:
228
 
        self.warn_on_battery()
 
237
    
 
238
    # Alert watcher
 
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)
229
242
 
230
243
  def on_initial_focus_in(self, widget, event):
231
244
      """callback run on initial focus-in (if started unmapped)"""
232
245
      widget.unstick()
233
246
      widget.set_urgency_hint(False)
234
247
      self.window_main.disconnect(self.initial_focus_id)
235
 
      self.warn_on_battery()
236
248
      return False
237
249
 
238
250
  def warn_on_battery(self):
458
470
      try:
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)
 
473
          count_str = ""
 
474
          download_str = ""
 
475
          if inst_count > 0:
 
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)
 
484
              else:
 
485
                  self.button_install.set_sensitive(True)
 
486
          else:
 
487
              if inst_count > 0:
 
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)
 
491
              else:
 
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()
467
508
 
468
509
  def _get_last_apt_get_update_text(self):
469
510
      """
666
707
    self.window_main.set_sensitive(True)
667
708
    self.window_main.window.set_cursor(None)
668
709
 
 
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()
 
721
      else:
 
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()
 
727
          
 
728
  def _on_battery_alert(self, watcher, on_battery):
 
729
      if on_battery:
 
730
          self.hbox_battery.show()
 
731
          self.vbox_alerts.show()
 
732
      else:
 
733
          self.hbox_battery.hide()    
 
734
 
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)
842
908
    self.update_count()
843
909
    self.setBusy(False)
844
910
    self.check_all_updates_installable()
 
911
    self.refresh_updates_count()
845
912
    return False
846
913
 
847
914
  def dist_no_longer_supported(self, meta_release):
999
1066
 
1000
1067
    self.fillstore()
1001
1068
    self.check_auto_update()
 
1069
    self.alert_watcher.check_alert_state()
1002
1070
    gtk.main()