summaryrefslogtreecommitdiff
path: root/src/dialog_settings.py.in
blob: cfa13e38b38f6457975dccbd01d9d232271289da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# dialog_settings.py.in - edit some settings
#  
#  Copyright (c) 2005 Canonical
#  
#  Author: Michael Vogt <mvo@debian.org>
# 
#  This program is free software; you can redistribute it and/or 
#  modify it under the terms of the GNU General Public License as 
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#  USA

import gconf
import apt_pkg
import gtk
import os

periodicAptConfFile = "/etc/apt/apt.conf.d/10periodic"
archiveAptConfFile = "/etc/apt/apt.conf.d/20archive"

class dialog_settings:
  def save_periodic_config(self):
    #print "saving ..."

    # get the new values
    for key in self.conf_map:
        cb = self.gladexml.get_widget("checkbutton_%s"% key)
        sb = self.gladexml.get_widget("spinbutton_%s"% key)
        if cb and not cb.get_active():
            #print "%s=%s" % (self.conf_map[key], "0")
            apt_pkg.Config.Set(self.conf_map[key], "0")
        elif sb:
            value = sb.get_value()
            apt_pkg.Config.Set(self.conf_map[key], str(value))
            #print "%s=%s" % (self.conf_map[key], value)

    # special case for autodownload, it has the same interval as
    # Update-Package-Lists
    cb = self.gladexml.get_widget("checkbutton_autodownload")
    key = "autodownload"
    if cb.get_active():
        autoupdate = str(apt_pkg.Config.FindI("APT::Periodic::Update-Package-Lists"))
        apt_pkg.Config.Set(self.conf_map[key], autoupdate)
    else:
        apt_pkg.Config.Set(self.conf_map[key], "0")
        

    # write both config-prefixes to different files
    for (file, prefix) in ((periodicAptConfFile, "APT::Periodic"),
                           (archiveAptConfFile, "APT::Archives")):

        content = []
        if os.path.isfile(file):
            content=open(file,"r").readlines()

        cnf = apt_pkg.Config.SubTree(prefix)

        f = open(file,"w+")
        for line  in content:
            # don't write the udpated keys
            found = False
            for key in cnf.List():
                #print "%s=%s" % (key, cnf[key])
                if line.find("%s::%s" % (prefix,key)) >= 0:
                    found = True
                    break
            if not found:
                f.write(line)
        # write new keys
        for i in cnf.List():
            f.write("%s::%s \"%s\";\n" % (prefix,i,cnf.FindI((i))))
        f.close()

  def toggle_show_disabled(self, widget, data):
    self.show_disabled = widget.get_active()
    self.gconfclient.set_bool("/apps/gnome-software-properties/show_disabled",\
                              self.show_disabled)

  def toggle_settings_cb(self, widget, data):
    mode = widget.get_active()
    self.gladexml.get_widget(data).set_sensitive(mode)

  def run(self):
    res = self.main_window.run()
    self.save_periodic_config()
    self.main_window.hide()
    return res
    
  def __init__(self, parent, glade):

    self.gladexml = glade
    self.main_window = self.gladexml.get_widget("dialog_settings")
    self.main_window.set_transient_for(parent)
    self.parent = parent
    self.gconfclient = gconf.client_get_default()
        
    # preferences entries
    self.show_disabled = self.gconfclient.get_bool("/apps/gnome-software-properties/show_disabled")

    checkbutton_show_disabled = self.gladexml.get_widget("checkbutton_show_disabled")
    checkbutton_show_disabled.set_active(self.show_disabled)
    checkbutton_show_disabled.connect("toggled", self.toggle_show_disabled, None)


    # apt-config
    
    # set the update stuff
    self.conf_map = {
        "autoupdate"   : "APT::Periodic::Update-Package-Lists",
        "autodownload" : "APT::Periodic::Download-Upgradeable-Packages",
        "autoclean"    : "APT::Periodic::AutocleanInterval",
        "max_size"     : "APT::Archives::MaxSize",
        "max_age"      : "APT::Archives::MaxAge"
        }

    for key in self.conf_map:
        value = apt_pkg.Config.FindI(self.conf_map[key])
        #print "%s=%s" % (key, value)
        cb = self.gladexml.get_widget("checkbutton_%s"% key)
        #if cb == None:
        #    print "checkbutton_%s not found" % key
        sb = self.gladexml.get_widget("spinbutton_%s"% key)
        if sb != None:
            #print "setting %s to %s" % (key, value)
            sb.set_value(value)
        #else:
        #    print "spinbutton_%s not found" % key
        box = self.gladexml.get_widget("vbox_%s"% key)
        #if box == None:
        #    print "vbox_%s not found" % key
        if box and cb:
            cb.connect("toggled", self.toggle_settings_cb, ("vbox_%s" % key))
        if cb:
            cb.set_active(value)