~bilalakhtar/update-manager/unity-launcher-progress

« back to all changes in this revision

Viewing changes to src/dialog_settings.py.in

  • Committer: Michael Vogt
  • Date: 2005-11-15 13:18:07 UTC
  • Revision ID: egon@top-20051115131807-12fada324eb74180
* initial revision (after accidently killing it)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# dialog_settings.py.in - edit some settings
 
2
#  
 
3
#  Copyright (c) 2005 Canonical
 
4
#  
 
5
#  Author: Michael Vogt <mvo@debian.org>
 
6
 
7
#  This program is free software; you can redistribute it and/or 
 
8
#  modify it under the terms of the GNU General Public License as 
 
9
#  published by the Free Software Foundation; either version 2 of the
 
10
#  License, or (at your option) any later version.
 
11
 
12
#  This program is distributed in the hope that it will be useful,
 
13
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#  GNU General Public License for more details.
 
16
 
17
#  You should have received a copy of the GNU General Public License
 
18
#  along with this program; if not, write to the Free Software
 
19
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
20
#  USA
 
21
 
 
22
import gconf
 
23
import apt_pkg
 
24
import gtk
 
25
import os
 
26
 
 
27
periodicAptConfFile = "/etc/apt/apt.conf.d/10periodic"
 
28
archiveAptConfFile = "/etc/apt/apt.conf.d/20archive"
 
29
 
 
30
class dialog_settings:
 
31
  def save_periodic_config(self):
 
32
    #print "saving ..."
 
33
 
 
34
    # get the new values
 
35
    for key in self.conf_map:
 
36
        cb = self.gladexml.get_widget("checkbutton_%s"% key)
 
37
        sb = self.gladexml.get_widget("spinbutton_%s"% key)
 
38
        if cb and not cb.get_active():
 
39
            #print "%s=%s" % (self.conf_map[key], "0")
 
40
            apt_pkg.Config.Set(self.conf_map[key], "0")
 
41
        elif sb:
 
42
            value = sb.get_value()
 
43
            apt_pkg.Config.Set(self.conf_map[key], str(value))
 
44
            #print "%s=%s" % (self.conf_map[key], value)
 
45
 
 
46
    # special case for autodownload, it has the same interval as
 
47
    # Update-Package-Lists
 
48
    cb = self.gladexml.get_widget("checkbutton_autodownload")
 
49
    key = "autodownload"
 
50
    if cb.get_active():
 
51
        autoupdate = str(apt_pkg.Config.FindI("APT::Periodic::Update-Package-Lists"))
 
52
        apt_pkg.Config.Set(self.conf_map[key], autoupdate)
 
53
    else:
 
54
        apt_pkg.Config.Set(self.conf_map[key], "0")
 
55
        
 
56
 
 
57
    # write both config-prefixes to different files
 
58
    for (file, prefix) in ((periodicAptConfFile, "APT::Periodic"),
 
59
                           (archiveAptConfFile, "APT::Archives")):
 
60
 
 
61
        content = []
 
62
        if os.path.isfile(file):
 
63
            content=open(file,"r").readlines()
 
64
 
 
65
        cnf = apt_pkg.Config.SubTree(prefix)
 
66
 
 
67
        f = open(file,"w+")
 
68
        for line  in content:
 
69
            # don't write the udpated keys
 
70
            found = False
 
71
            for key in cnf.List():
 
72
                #print "%s=%s" % (key, cnf[key])
 
73
                if line.find("%s::%s" % (prefix,key)) >= 0:
 
74
                    found = True
 
75
                    break
 
76
            if not found:
 
77
                f.write(line)
 
78
        # write new keys
 
79
        for i in cnf.List():
 
80
            f.write("%s::%s \"%s\";\n" % (prefix,i,cnf.FindI((i))))
 
81
        f.close()
 
82
 
 
83
  def toggle_show_disabled(self, widget, data):
 
84
    self.show_disabled = widget.get_active()
 
85
    self.gconfclient.set_bool("/apps/gnome-software-properties/show_disabled",\
 
86
                              self.show_disabled)
 
87
 
 
88
  def toggle_settings_cb(self, widget, data):
 
89
    mode = widget.get_active()
 
90
    self.gladexml.get_widget(data).set_sensitive(mode)
 
91
 
 
92
  def run(self):
 
93
    res = self.main_window.run()
 
94
    self.save_periodic_config()
 
95
    self.main_window.hide()
 
96
    return res
 
97
    
 
98
  def __init__(self, parent, glade):
 
99
 
 
100
    self.gladexml = glade
 
101
    self.main_window = self.gladexml.get_widget("dialog_settings")
 
102
    self.main_window.set_transient_for(parent)
 
103
    self.parent = parent
 
104
    self.gconfclient = gconf.client_get_default()
 
105
        
 
106
    # preferences entries
 
107
    self.show_disabled = self.gconfclient.get_bool("/apps/gnome-software-properties/show_disabled")
 
108
 
 
109
    checkbutton_show_disabled = self.gladexml.get_widget("checkbutton_show_disabled")
 
110
    checkbutton_show_disabled.set_active(self.show_disabled)
 
111
    checkbutton_show_disabled.connect("toggled", self.toggle_show_disabled, None)
 
112
 
 
113
 
 
114
    # apt-config
 
115
    
 
116
    # set the update stuff
 
117
    self.conf_map = {
 
118
        "autoupdate"   : "APT::Periodic::Update-Package-Lists",
 
119
        "autodownload" : "APT::Periodic::Download-Upgradeable-Packages",
 
120
        "autoclean"    : "APT::Periodic::AutocleanInterval",
 
121
        "max_size"     : "APT::Archives::MaxSize",
 
122
        "max_age"      : "APT::Archives::MaxAge"
 
123
        }
 
124
 
 
125
    for key in self.conf_map:
 
126
        value = apt_pkg.Config.FindI(self.conf_map[key])
 
127
        #print "%s=%s" % (key, value)
 
128
        cb = self.gladexml.get_widget("checkbutton_%s"% key)
 
129
        #if cb == None:
 
130
        #    print "checkbutton_%s not found" % key
 
131
        sb = self.gladexml.get_widget("spinbutton_%s"% key)
 
132
        if sb != None:
 
133
            #print "setting %s to %s" % (key, value)
 
134
            sb.set_value(value)
 
135
        #else:
 
136
        #    print "spinbutton_%s not found" % key
 
137
        box = self.gladexml.get_widget("vbox_%s"% key)
 
138
        #if box == None:
 
139
        #    print "vbox_%s not found" % key
 
140
        if box and cb:
 
141
            cb.connect("toggled", self.toggle_settings_cb, ("vbox_%s" % key))
 
142
        if cb:
 
143
            cb.set_active(value)
 
144