~gandelman-a/software-properties/lp829109

« back to all changes in this revision

Viewing changes to softwareproperties/gtk/SoftwarePropertiesGtk.py

  • Committer: Michael Vogt
  • Date: 2011-07-18 09:26:55 UTC
  • mfrom: (606.4.6 updates-redesign)
  • mto: This revision was merged to the branch mainline in revision 687.
  • Revision ID: michael.vogt@ubuntu.com-20110718092655-yl78x0yejgv5oyxl
merged from lp:~ilidrissi.amine/software-properties/updates-redesign and apply some cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
from gi.repository import Gdk
34
34
from gi.repository import Gtk
 
35
from gi.repository import Gio
35
36
import gobject
36
37
 
37
38
from SimpleGtkbuilderApp import SimpleGtkbuilderApp
115
116
    if options and options.open_tab:
116
117
      self.notebook_main.set_current_page(int(options.open_tab))
117
118
 
 
119
    # gsettings
 
120
    self.settings = Gio.Settings("com.ubuntu.update-notifier")
 
121
    # we need this for reverting
 
122
    self.initial_auto_launch = self.settings.get_int("regular-auto-launch-interval") 
 
123
    
118
124
    # Show what we have early
119
125
    self.window_main.show()
120
126
 
171
177
 
172
178
  def init_auto_update(self):
173
179
    """ Set up the widgets that allow to configure the update automation """
174
 
    self.combobox_update_interval = Gtk.ComboBoxText.new_with_entry()
175
 
    self.hbox_check_for_updates.pack_start(self.combobox_update_interval, True, True, 0)
176
180
    self.combobox_update_interval.show()
177
 
    
 
181
 
178
182
    # this maps the key (combo-box-index) to the auto-update-interval value
179
 
    # where (-1) means, no key
180
 
    self.combobox_interval_mapping = { 0 : 1,
181
 
                                       1 : 2,
182
 
                                       2 : 7,
183
 
                                       3 : 14 }
184
 
    self.combobox_update_interval.set_active(0)
185
 
 
186
 
    #update_days = apt_pkg.Config.FindI(softwareproperties.CONF_MAP["autoupdate"])
187
 
    self.combobox_update_interval.append_text(_("Daily"))
188
 
    self.combobox_update_interval.append_text(_("Every two days"))
189
 
    self.combobox_update_interval.append_text(_("Weekly"))
190
 
    self.combobox_update_interval.append_text(_("Every two weeks"))
191
 
 
192
 
    model_check_interval = Gtk.ListStore(gobject.TYPE_STRING,
193
 
                                         gobject.TYPE_INT)
 
183
    model = self.combobox_update_interval.get_model()
 
184
    self.combobox_interval_mapping = {}
 
185
    for (i, row) in enumerate(model):
 
186
      # column 1 is the update interval
 
187
      value = model.get_value(row.iter, 1)
 
188
      self.combobox_interval_mapping[i] = value
 
189
 
194
190
    update_days = self.get_update_interval()
195
191
 
196
192
    # If a custom period is defined add a corresponding entry
205
201
        self.combobox_update_interval.set_active(key)
206
202
        break
207
203
 
208
 
    if update_days >= 1:
209
 
      self.checkbutton_auto_update.set_active(True)
210
 
      self.combobox_update_interval.set_sensitive(True)
211
 
      self.vbox_auto_updates.set_sensitive(True)
212
 
    else:
213
 
      self.checkbutton_auto_update.set_active(False)
214
 
      self.combobox_update_interval.set_sensitive(False)
215
 
      self.vbox_auto_updates.set_sensitive(False)
216
 
 
217
 
    self.handlers.append(
218
 
        (self.checkbutton_auto_update,
219
 
         self.checkbutton_auto_update.connect("toggled", 
220
 
                                     self.on_auto_update_toggled)))
221
204
    self.handlers.append(
222
205
        (self.combobox_update_interval,
223
206
         self.combobox_update_interval.connect("changed", 
224
207
                                     self.on_combobox_update_interval_changed)))
225
 
    self.handlers.append(
226
 
        (self.radiobutton_updates_download,
227
 
         self.radiobutton_updates_download.connect("toggled", 
228
 
                                     self.set_update_automation_level,
229
 
                                     softwareproperties.UPDATE_DOWNLOAD)))
230
 
    self.handlers.append(
231
 
        (self.radiobutton_updates_inst_sec,
232
 
         self.radiobutton_updates_inst_sec.connect("toggled", 
233
 
                                     self.set_update_automation_level,
234
 
                                     softwareproperties.UPDATE_INST_SEC)))
235
 
    self.handlers.append(
236
 
        (self.radiobutton_updates_notify,
237
 
         self.radiobutton_updates_notify.connect("toggled", 
238
 
                                     self.set_update_automation_level,
239
 
                                     softwareproperties.UPDATE_NOTIFY)))
 
208
    
 
209
    self.handlers.append(
 
210
        (self.combobox_security_updates,
 
211
         self.combobox_security_updates.connect("changed",
 
212
                                     self.set_sec_update_automation_level)))
 
213
    
 
214
    self.handlers.append(
 
215
        (self.combobox_security_updates,
 
216
         self.combobox_other_updates.connect("changed",
 
217
                                     self.set_other_update_automation_level)))
240
218
 
 
219
  
241
220
  def show_auto_update_level(self):
242
221
    """Represent the level of update automation in the user interface"""
243
 
    level = self.get_update_automation_level()
244
 
    self.block_handlers()
245
 
    if level == None:
246
 
        self.radiobutton_updates_inst_sec.set_inconsistent(True)
247
 
        self.radiobutton_updates_download.set_inconsistent(True)
248
 
        self.radiobutton_updates_notify.set_inconsistent(True)
 
222
    
 
223
    """ Security Updates """
 
224
    level_sec = self.get_update_automation_level()
 
225
    if level_sec == None:
 
226
      self.combobox_security_updates.set_sensitive(False)
249
227
    else:
250
 
        self.radiobutton_updates_inst_sec.set_inconsistent(False)
251
 
        self.radiobutton_updates_download.set_inconsistent(False)
252
 
        self.radiobutton_updates_notify.set_inconsistent(False)
253
 
    if level == softwareproperties.UPDATE_MANUAL or \
254
 
       level == softwareproperties.UPDATE_NOTIFY:
255
 
        self.radiobutton_updates_notify.set_active(True)
256
 
    elif level == softwareproperties.UPDATE_DOWNLOAD:
257
 
        self.radiobutton_updates_download.set_active(True)
258
 
    elif level == softwareproperties.UPDATE_INST_SEC:
259
 
        self.radiobutton_updates_inst_sec.set_active(True)
260
 
    # Unblock the toggle handlers
261
 
    self.unblock_handlers()
 
228
      self.combobox_security_updates.set_sensitive(True)
 
229
          
 
230
    if level_sec == softwareproperties.UPDATE_MANUAL or \
 
231
       level_sec == softwareproperties.UPDATE_NOTIFY:
 
232
      self.combobox_security_updates.set_active(0) # Display immediately
 
233
    elif level_sec == softwareproperties.UPDATE_DOWNLOAD:
 
234
      self.combobox_security_updates.set_active(1) # Download automatically
 
235
    elif level_sec == softwareproperties.UPDATE_INST_SEC:
 
236
      self.combobox_security_updates.set_active(2) # Download and install automatically
 
237
    
 
238
    """ Other Updates """
 
239
    level_other = self.settings.get_int("regular-auto-launch-interval")
 
240
    if level_other == 0:
 
241
      self.combobox_other_updates.set_active(0) # Display immediately
 
242
    elif level_other == 7:
 
243
      self.combobox_other_updates.set_active(1) # Display weekly
 
244
    elif level_other == 14:
 
245
      self.combobox_other_updates.set_active(2) # Display every two weeks
262
246
 
263
247
  def init_distro(self):
264
248
    """Setup the user interface elements to represent the distro"""
265
249
 
266
250
    # TRANS: %s stands for the distribution name e.g. Debian or Ubuntu
267
 
    self.label_updates.set_label("<b>%s</b>" % (_("%s updates") %\
268
 
                                                self.distro.id.encode('UTF-8')))
269
 
    # TRANS: %s stands for the distribution name e.g. Debian or Ubuntu
270
 
    self.label_dist_name.set_label(_("%s Software") % self.distro.id.encode('UTF-8'))
271
 
 
 
251
    self.label_dist_name.set_label(_("%s Software") % self.distro.id)
272
252
 
273
253
    self.handlers.append((self.checkbutton_source_code,
274
254
                          self.checkbutton_source_code.connect("toggled",
425
405
        for source in self.sourceslist_visible:
426
406
            self.print_source_entry(source)
427
407
 
428
 
  def set_update_automation_level(self, widget, state):
429
 
    '''Call the backend to set the update automation level to the given 
430
 
       value'''
431
 
    if widget.get_active() == True:
432
 
        self.vbox_auto_updates.foreach(lambda b, d: b.set_inconsistent(False), None)
433
 
        SoftwareProperties.set_update_automation_level(self, state)
434
 
    self.set_modified_config()
 
408
  def set_sec_update_automation_level(self, widget):
 
409
    """Call the backend to set the security update automation level to the given
 
410
       value"""
 
411
    index = widget.get_active()
 
412
    state = -1
 
413
    if index == 0: # Display immediately
 
414
      state = softwareproperties.UPDATE_NOTIFY
 
415
    elif index == 1: # Download automatically
 
416
      state = softwareproperties.UPDATE_DOWNLOAD
 
417
    elif index == 2: # Download and install automatically
 
418
      state = softwareproperties.UPDATE_INST_SEC
 
419
    SoftwareProperties.set_update_automation_level(self, state)
 
420
    
 
421
  def set_other_update_automation_level(self, widget):
 
422
    """Set the other update automation level to the given value via gconf"""
 
423
    index = widget.get_active()
 
424
    days = 7
 
425
    if index == 0: # Display immediately
 
426
      days = 0
 
427
    elif index == 1: # Display weekly
 
428
      days = 7
 
429
    elif index == 2: # Display every two weeks
 
430
      days = 14
 
431
    self.settings.set_int("regular-auto-launch-interval", days)
 
432
    
435
433
 
436
434
  def is_row_separator(self, model, iter, column=0):
437
435
    ''' Check if a given row is a separator '''
686
684
  def on_button_revert_clicked(self, button):
687
685
    """Restore the source list from the startup of the dialog"""
688
686
    SoftwareProperties.revert(self)
 
687
    self.settings.set_int("regular-auto-launch-interval", self.initial_auto_launch)
689
688
    self.set_modified_sourceslist()
690
689
    self.show_auto_update_level()
691
690
    self.button_revert.set_sensitive(False)
748
747
        value = self.combobox_interval_mapping[i]
749
748
        self.set_update_interval(value)
750
749
 
751
 
  def on_auto_update_toggled(self, widget):
752
 
    """Enable or disable automatic updates and modify the user interface
753
 
       accordingly"""
 
750
  """def on_auto_update_toggled(self, widget):
 
751
       Enable or disable automatic updates and modify the user interface
 
752
       accordingly
754
753
    if self.checkbutton_auto_update.get_active():
755
754
      self.combobox_update_interval.set_sensitive(True)
756
755
      self.vbox_auto_updates.set_sensitive(True)
767
766
      self.vbox_auto_updates.set_sensitive(False)
768
767
      SoftwareProperties.set_update_automation_level(self, None)
769
768
      value = 0
770
 
    self.set_update_interval(str(value))
 
769
    self.set_update_interval(str(value))"""
771
770
 
772
771
  def on_add_clicked(self, widget):
773
772
    """Show a dialog that allows to enter the apt line of a to be used repo"""