4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "StatusMessage.hpp"
25 #include "Profile/Profile.hpp"
26 #include "LocalPath.hpp"
27 #include "Util/EscapeBackslash.hpp"
28 #include "Util/StringUtil.hpp"
29 #include "Util/NumberParser.hpp"
30 #include "IO/ConfiguredFile.hpp"
35 static constexpr StatusMessage default_status_messages
[] = {
36 #include "Status_defaults.cpp"
40 StatusMessageList::StatusMessageList()
43 // DEFAULT - 0 is loaded as default, and assumed to exist
44 StatusMessage
&first
= list
.append();
45 first
.key
= _T("DEFAULT");
47 first
.sound
= _T("IDR_WAV_DRIP");
48 first
.delay_ms
= 2500; // 2.5 s
50 // Load up other defaults - allow overwrite in config file
51 const StatusMessage
*src
= &default_status_messages
[0];
52 while (src
->key
!= NULL
)
57 StatusMessageList::LoadFile()
59 std::unique_ptr
<TLineReader
> reader(OpenConfiguredTextFile(ProfileKeys::StatusFile
));
65 parse_assignment(TCHAR
*buffer
, const TCHAR
*&key
, const TCHAR
*&value
)
67 TCHAR
*separator
= _tcschr(buffer
, '=');
68 if (separator
== NULL
|| separator
== buffer
)
71 *separator
= _T('\0');
74 value
= separator
+ 1;
80 StatusMessageList::LoadFile(TLineReader
&reader
)
83 StatusMessage current
;
86 /* Read from the file */
88 const TCHAR
*key
, *value
;
89 while ((buffer
= reader
.ReadLine()) != NULL
) {
90 // Check valid line? If not valid, assume next record (primative, but works ok!)
91 if (*buffer
== _T('#') || !parse_assignment(buffer
, key
, value
)) {
92 // Global counter (only if the last entry had some data)
93 if (!current
.IsEmpty()) {
101 if (_tcscmp(key
, _T("key")) == 0) {
102 if (current
.key
== NULL
)
103 current
.key
= UnescapeBackslash(value
);
104 } else if (_tcscmp(key
, _T("sound")) == 0) {
105 if (current
.sound
== NULL
)
106 current
.sound
= UnescapeBackslash(value
);
107 } else if (_tcscmp(key
, _T("delay")) == 0) {
109 unsigned ms
= ParseUnsigned(value
, &endptr
);
111 current
.delay_ms
= ms
;
112 } else if (_tcscmp(key
, _T("hide")) == 0) {
113 if (_tcscmp(value
, _T("yes")) == 0)
114 current
.visible
= false;
119 if (!current
.IsEmpty())
120 list
.append(current
);
124 StatusMessageList::Startup(bool first
)
127 // NOTE: Must show errors AFTER all windows ready
128 old_delay
= list
[0].delay_ms
;
129 list
[0].delay_ms
= 20000; // 20 seconds
131 list
[0].delay_ms
= old_delay
;
135 const StatusMessage
*
136 StatusMessageList::Find(const TCHAR
*key
) const
138 for (int i
= list
.size() - 1; i
> 0; i
--)
139 if (_tcscmp(key
, list
[i
].key
) == 0)