User-visible rotation config and persistence of rotation config
[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(_("Visible Columns"))
58                 columnsFrame.add(self.__columnsSection)
59
60                 self.__rotationSection = gtk.VBox()
61
62                 self.__isPortraitCheckbutton = gtk.CheckButton(_("Portrait Mode"))
63                 self.__rotationSection.pack_start(self.__isPortraitCheckbutton)
64
65                 rotationFrame = gtk.Frame(_("Rotation"))
66                 rotationFrame.add(self.__rotationSection)
67
68                 settingsBox = gtk.VBox()
69                 settingsBox.pack_start(rotationFrame)
70                 settingsBox.pack_start(columnsFrame)
71                 settingsView = gtk.Viewport()
72                 settingsView.add(settingsBox)
73                 settingsScrollView = gtk.ScrolledWindow()
74                 settingsScrollView.add(settingsView)
75                 settingsScrollView.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
76                 parent.pack_start(settingsScrollView)
77
78                 settingsScrollView = hildonize.hildonize_scrollwindow(settingsScrollView)
79
80         def set_portrait_state(self, isPortrait):
81                 self.__isPortraitCheckbutton.set_active(isPortrait)
82
83         def is_portrait(self):
84                 return self.__isPortraitCheckbutton.get_active()
85
86         def is_col_selected(self, icol):
87                 children = self.__columnsSection.get_children()
88                 if icol < len(children):
89                         return children[icol].get_active()
90                 else:
91                         return None
92
93         def save(self, db):
94                 for i, name in enumerate(self._iter_columns()):
95                         if self.is_col_selected(i) == True:
96                                 db.speichereDirekt("showcol_"+name, "1")
97                         else:
98                                 db.speichereDirekt("showcol_"+name, "0")
99
100         def _iter_columns(self):
101                 for i in xrange(self.__listStore.get_colcount()):
102                         name = self.__listStore.get_colname(i)
103                         assert name is not None
104                         if name == "uid":
105                                 continue
106
107                         yield name