Translated using Weblate.
[wammu.git] / Wammu / WammuSettings.py
blob0e5635c08158de51ce8d91c111304406b6e68bda
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Config handler wrapper with various defaults, which might be platform dependant.
7 @var DEFAULT_CONFIG: Dictionary of default values.
8 @var EXPANDABLE_CONFIGS: List of variables where path expansion should happen.
9 '''
10 __author__ = 'Michal Čihař'
11 __email__ = 'michal@cihar.com'
12 __license__ = '''
13 Copyright © 2003 - 2010 Michal Čihař
15 This program is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License version 2 as published by
17 the Free Software Foundation.
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 more details.
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc.,
26 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 '''
29 import os
30 import wx
31 import Wammu.GammuSettings
32 import Wammu.OSUtils
34 DEFAULT_CONFIG = {
35 '/Main/X': 0,
36 '/Main/Y': 0,
37 '/Main/Split': 160,
38 '/Main/SplitRight': -200,
39 '/Main/Width': 640,
40 '/Main/Height': 480,
41 '/Defaults/SearchType': 0,
42 '/Defaults/Type-contact-MemoryType': 'SM',
43 '/Defaults/Type-calendar-Type': 'MEETING',
44 '/Defaults/Type-todo-Priority': 'Medium',
45 '/Defaults/Entry-contact-0': 'Text_Name',
46 '/Defaults/Entry-contact-1': 'Number_General',
47 '/Defaults/Entry-todo-0': 'TEXT',
48 '/Defaults/Entry-calendar-0': 'TEXT',
49 '/Defaults/Entry-calendar-1': 'START_DATETIME',
50 '/Defaults/Entry-calendar-2': 'END_DATETIME',
51 '/Wammu/AutoConnect': 'no',
52 '/Gammu/LockDevice': False,
53 '/Debug/Show': 'no',
54 '/Wammu/PhonePrefix': 'Auto',
55 '/Wammu/LastPhonePrefix': '',
56 '/Wammu/RefreshState': 30000,
57 '/Debug/X': 0,
58 '/Debug/Y': 0,
59 '/Debug/Width': 400,
60 '/Debug/Height': 200,
61 '/Message/ScaleImage': 1,
62 '/Message/Format': 'yes',
63 '/Message/Concatenated': 'yes',
64 '/Message/Unicode': 'no',
65 '/Message/DeliveryReport': 'no',
66 '/Message/16bitId': 'yes',
67 '/Gammu/SyncTime': True,
68 '/Gammu/StartInfo': True,
69 '/Wammu/ConfirmDelete': 'yes',
70 '/Wammu/DefaultTime': '09:00:00',
71 '/Wammu/DefaultDateOffset': 1,
72 '/Wammu/DefaultEntries': 3,
73 '/Wammu/FirstRun': -1,
74 '/Wammu/RunCounter': 0,
75 '/Wammu/TalkbackDone': 'no',
76 '/Wammu/NameFormat': 'auto',
77 '/Wammu/NameFormatString': '%(FirstName)s %(LastName)s (%(Company)s)',
78 '/IMAP/Server': '',
79 '/IMAP/Port': '',
80 '/IMAP/Login': '',
81 '/IMAP/Password': '',
82 '/IMAP/RememberPassword': 'no',
83 '/IMAP/UseSSL': 'yes',
84 '/IMAP/OnlyNewMessages': 'yes',
85 '/IMAP/BackupStateRead': 'yes',
86 '/IMAP/BackupStateSent': 'yes',
87 '/IMAP/BackupStateUnread': 'yes',
88 '/IMAP/BackupStateUnsent': 'yes',
89 '/MessageExport/From': 'Wammu <wammu@wammu.sms>',
90 '/Gammu/Section': 0,
91 '/User/Name': Wammu.OSUtils.GetUserFullName(),
92 '/Gammu/Gammurc': os.path.join(u'~', u'.gammurc'),
93 '/Hacks/MaxEmptyGuess': 50,
94 '/Hacks/MaxEmptyKnown': 100,
98 EXPANDABLE_CONFIGS = [
99 '/Gammu/Gammurc',
102 class WammuConfig:
104 Wrapper class for wx.Config, which handles automatically defaults
105 and allows some automatic conversion of read values (like expanding
106 ~ in path).
108 def __init__(self):
109 # We don't want to subclass from wx.Config to hide it's API
110 self.cfg = wx.Config(appName = 'Wammu',
111 style = wx.CONFIG_USE_LOCAL_FILE)
112 self.gammu = None
113 self.InitGammu()
115 def Flush(self):
116 self.cfg.Flush()
118 def InitGammu(self, path = None):
120 Initializes gammu configuration as sub part of this class.
122 self.gammu = Wammu.GammuSettings.GammuSettings(self, path)
124 def Read(self, path, expand = True):
126 Reads string option from configuration.
128 try:
129 result = self.cfg.Read(path, DEFAULT_CONFIG[path])
130 except KeyError:
131 # Following line is for debugging purposes only
132 #print 'Warning: no default value for %s' % path
133 result = self.cfg.Read(path, '')
134 if expand and path in EXPANDABLE_CONFIGS:
135 result = Wammu.OSUtils.ExpandPath(result)
136 return result
138 def ReadInt(self, path):
140 Reads integer option from configuration.
142 try:
143 result = self.cfg.ReadInt(path, DEFAULT_CONFIG[path])
144 except KeyError:
145 # Following line is for debugging purposes only
146 #print 'Warning: no default value for %s' % path
147 result = self.cfg.ReadInt(path, 0)
148 return result
150 def ReadFloat(self, path):
152 Reads float option from configuration.
154 try:
155 result = self.cfg.ReadFloat(path, DEFAULT_CONFIG[path])
156 except KeyError:
157 # Following line is for debugging purposes only
158 #print 'Warning: no default value for %s' % path
159 result = self.cfg.ReadFloat(path, 0)
160 return result
162 def ReadBool(self, path):
164 Reads boolean option from configuration.
166 try:
167 result = self.cfg.ReadBool(path, DEFAULT_CONFIG[path])
168 except KeyError:
169 # Following line is for debugging purposes only
170 #print 'Warning: no default value for %s' % path
171 result = self.cfg.ReadBool(path, 0)
172 return result
174 def Write(self, path, value):
176 Writes string option to configuration.
178 self.cfg.Write(path, value)
180 def WriteInt(self, path, value):
182 Writes integer option to configuration.
184 self.cfg.WriteInt(path, value)
186 def WriteFloat(self, path, value):
188 Writes float option to configuration.
190 self.cfg.WriteFloat(path, value)
192 def WriteBool(self, path, value):
194 Writes boolean option to configuration.
196 self.cfg.WriteBool(path, value)
198 def HasEntry(self, path):
200 Checks whether configuration has some entry.
202 return self.cfg.HasEntry(path)