4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "preferences.h"
25 #include "file_utils.h"
26 #include "wx/tokenzr.h"
31 Preferences::Preferences(const wxChar
*filename
) {
32 cfgFile
= wxFileName(wxGetCwd(), filename
).GetFullPath();
34 kanjidicOptions
= KDO_ALL
| KDO_UNHANDLED
;
35 kanjidicDictionaries
= 0; /* KDD_ALL */
37 if(ReadEncodedFile(filename
, _T("utf-8"), s
)==REF_SUCCESS
) {
38 /* Split into strings for each line */
39 wxStringTokenizer
t(s
, _T("\n"));
40 wxString token
, subToken
;
42 while(t
.HasMoreTokens()) {
43 token
= t
.GetNextToken();
44 if( (token
.length()>0) && (token
[0]!=_T('#')) ) {
45 /* We only want to split the string into two subtokens, so we'll
47 index
= token
.find_first_of(_T(" \t"));
48 if(index
!=wxString::npos
) {
49 subToken
= token
.substr(0, index
);
50 subToken
= subToken
.MakeLower();
51 if(subToken
==_T("kanjidicoptionmask")) {
52 subToken
= token
.substr(index
+1);
53 subToken
= subToken
.Trim(false).Trim(true);
54 subToken
.ToULong(&kanjidicOptions
, 0);
55 } else if(subToken
==_T("kanjidicdictionarymask")) {
56 subToken
= token
.substr(index
+1);
57 subToken
= subToken
.Trim(false).Trim(true);
58 subToken
.ToULong(&kanjidicDictionaries
, 0);
59 } else if(subToken
==_T("kanjilist")) {
60 subToken
= token
.substr(index
+1);
61 subToken
= subToken
.Trim(false).Trim(true);
62 jben
->kanjiList
->AddFromString(subToken
);
63 } else if(subToken
==_T("vocablist")) {
64 subToken
= token
.substr(index
+1);
65 subToken
= subToken
.Trim(false).Trim(true);
67 printf("String to parse: [%ls]\n", subToken
.c_str());
69 wxStringTokenizer
tSub(subToken
, _T(";"));
70 while(tSub
.HasMoreTokens()) {
71 subToken
= tSub
.GetNextToken();
73 printf("Subtoken: [%ls]\n", subToken
.c_str());
75 if(subToken
.length()>0) {
76 jben
->vocabList
->Add(subToken
);
80 /* Unhandled - do nothing*/
83 /* No space/tab was found. Check no-arg options */
84 /* Currently there are none. There might never be any again, actually. */
86 token
= token
.MakeLower().Trim(false).Trim(true);
87 /*if(token==_T("vocablist")) ReadingVocabList=true;*/ /* Sets KanjiList-reading mode */
90 } /* if(tokenlen>0, token[0]!=# */
91 } /* while(hasmoretokens) */
92 } /* if(file opened) */
95 Preferences::~Preferences() {
96 wxCSConv
transcoder(_T("utf-8"));
98 wxFFile
out(cfgFile
, _T("w"));
100 out
.Write(GetPreferences(), transcoder
);
105 wxString
Preferences::GetPreferences() {
107 prefs
.Printf(_T("KanjidicOptionMask 0x%08lX\n"), kanjidicOptions
);
108 prefs
.append(wxString::Format(_T("KanjidicDictionaryMask 0x%08lX\n"), kanjidicDictionaries
));
109 prefs
.append(wxString::Format(_T("KanjiList %ls\n"), jben
->kanjiList
->ToString().c_str()));
110 prefs
.append(wxString::Format(_T("VocabList %ls\n"), jben
->vocabList
->ToString(_T(';')).c_str()));