8fbcbea98024bfa17d5eb1358e05039c35c3b02f
[multilist] / src / settings.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 This file is part of Multilist.
6
7 Multilist is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Multilist 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 Multilist.  If not, see <http://www.gnu.org/licenses/>.
19
20 Copyright (C) 2008 Christoph Würstle
21 """
22
23 import logging
24
25 import gtk
26
27 import hildonize
28
29
30 try:
31         _
32 except NameError:
33         _ = lambda x: x
34
35
36 _moduleLogger = logging.getLogger(__name__)
37
38
39 class SettingsDialog(object):
40
41         def __init__(self, parent, db, liststorehandler):
42                 self.__listStore = liststorehandler
43
44                 self.__columnsSection = gtk.VBox()
45                 for i, name in enumerate(self._iter_columns()):
46                         checkbutton = gtk.CheckButton(name)
47
48                         if i in [0, 1]:
49                                 default = "1"
50                         else:
51                                 default = "0"
52                         if db.ladeDirekt("showcol_"+name, default) == "1":
53                                 checkbutton.set_active(True)
54
55                         self.__columnsSection.pack_start(checkbutton)
56
57                 columnsFrame = gtk.Frame(_("Choose Columns"))
58                 columnsFrame.add(self.__columnsSection)
59
60                 settingsBox = gtk.VBox()
61                 settingsBox.pack_start(columnsFrame)
62                 settingsView = gtk.Viewport()
63                 settingsView.add(settingsBox)
64                 settingsScrollView = gtk.ScrolledWindow()
65                 settingsScrollView.add(settingsView)
66                 settingsScrollView.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
67                 parent.pack_start(settingsScrollView)
68
69                 settingsScrollView = hildonize.hildonize_scrollwindow(settingsScrollView)
70
71         def is_col_selected(self, icol):
72                 children = self.__columnsSection.get_children()
73                 if icol < len(children):
74                         return children[icol].get_active()
75                 else:
76                         return None
77
78         def save(self, db):
79                 for i, name in enumerate(self._iter_columns()):
80                         if self.is_col_selected(i) == True:
81                                 db.speichereDirekt("showcol_"+name, "1")
82                         else:
83                                 db.speichereDirekt("showcol_"+name, "0")
84
85         def _iter_columns(self):
86                 for i in xrange(self.__listStore.get_colcount()):
87                         name = self.__listStore.get_colname(i)
88                         assert name is not None
89                         if name == "uid":
90                                 continue
91
92                         yield name