1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
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.
10 __author__
= 'Michal Čihař'
11 __email__
= 'michal@cihar.com'
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
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
31 import Wammu
.GammuSettings
38 '/Main/SplitRight': -200,
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,
54 '/Wammu/PhonePrefix': 'Auto',
55 '/Wammu/LastPhonePrefix': '',
56 '/Wammu/RefreshState': 30000,
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)',
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>',
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
= [
104 Wrapper class for wx.Config, which handles automatically defaults
105 and allows some automatic conversion of read values (like expanding
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
)
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.
129 result
= self
.cfg
.Read(path
, DEFAULT_CONFIG
[path
])
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
)
138 def ReadInt(self
, path
):
140 Reads integer option from configuration.
143 result
= self
.cfg
.ReadInt(path
, DEFAULT_CONFIG
[path
])
145 # Following line is for debugging purposes only
146 #print 'Warning: no default value for %s' % path
147 result
= self
.cfg
.ReadInt(path
, 0)
150 def ReadFloat(self
, path
):
152 Reads float option from configuration.
155 result
= self
.cfg
.ReadFloat(path
, DEFAULT_CONFIG
[path
])
157 # Following line is for debugging purposes only
158 #print 'Warning: no default value for %s' % path
159 result
= self
.cfg
.ReadFloat(path
, 0)
162 def ReadBool(self
, path
):
164 Reads boolean option from configuration.
167 result
= self
.cfg
.ReadBool(path
, DEFAULT_CONFIG
[path
])
169 # Following line is for debugging purposes only
170 #print 'Warning: no default value for %s' % path
171 result
= self
.cfg
.ReadBool(path
, 0)
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
)