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 - 2008 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': 'no',
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': 'yes',
68 '/Gammu/StartInfo': 'no',
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)',
81 '/MesageExport/From': 'Wammu <wammu@wammu.sms>',
83 '/User/Name': Wammu
.OSUtils
.GetUserFullName(),
84 '/Gammu/Gammurc': os
.path
.join(u
'~', u
'.gammurc'),
85 '/Hacks/MaxEmptyGuess': 50,
86 '/Hacks/MaxEmptyKnown': 100,
90 EXPANDABLE_CONFIGS
= [
96 Wrapper class for wx.Config, which handles automatically defaults
97 and allows some automatic conversion of read values (like expanding
101 # We don't want to subclass from wx.Config to hide it's API
102 self
.cfg
= wx
.Config(appName
= 'Wammu',
103 style
= wx
.CONFIG_USE_LOCAL_FILE
)
110 def InitGammu(self
, path
= None):
112 Initializes gammu configuration as sub part of this class.
114 self
.gammu
= Wammu
.GammuSettings
.GammuSettings(self
, path
)
116 def Read(self
, path
, expand
= True):
118 Reads string option from configuration.
121 result
= self
.cfg
.Read(path
, DEFAULT_CONFIG
[path
])
123 # Following line is for debugging purposes only
124 #print 'Warning: no default value for %s' % path
125 result
= self
.cfg
.Read(path
, '')
126 if expand
and path
in EXPANDABLE_CONFIGS
:
127 result
= Wammu
.OSUtils
.ExpandPath(result
)
130 def ReadInt(self
, path
):
132 Reads integer option from configuration.
135 result
= self
.cfg
.ReadInt(path
, DEFAULT_CONFIG
[path
])
137 # Following line is for debugging purposes only
138 #print 'Warning: no default value for %s' % path
139 result
= self
.cfg
.ReadInt(path
, 0)
142 def ReadFloat(self
, path
):
144 Reads float option from configuration.
147 result
= self
.cfg
.ReadFloat(path
, DEFAULT_CONFIG
[path
])
149 # Following line is for debugging purposes only
150 #print 'Warning: no default value for %s' % path
151 result
= self
.cfg
.ReadFloat(path
, 0)
154 def Write(self
, path
, value
):
156 Writes string option to configuration.
158 self
.cfg
.Write(path
, value
)
160 def WriteInt(self
, path
, value
):
162 Writes integer option to configuration.
164 self
.cfg
.WriteInt(path
, value
)
166 def WriteFloat(self
, path
, value
):
168 Writes float option to configuration.
170 self
.cfg
.WriteFloat(path
, value
)
172 def HasEntry(self
, path
):
174 Checks whether configuration has some entry.
176 return self
.cfg
.HasEntry(path
)