1 /*******************************************************************************
\r
2 TPI - flexible but useless plug-in framework.
\r
3 Copyright (C) 2002-2009 Silky
\r
5 This library is free software; you can redistribute it and/or modify it under
\r
6 the terms of the GNU Lesser General Public License as published by the Free
\r
7 Software Foundation; either version 2.1 of the License, or (at your option)
\r
10 This library is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
\r
15 You should have received a copy of the GNU Lesser General Public License along
\r
16 with this library; if not, write to the Free Software Foundation, Inc.,
\r
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
\r
20 *******************************************************************************/
\r
23 #include "cls_config.h"
\r
25 //******************************************************************************
\r
27 //******************************************************************************
\r
29 myConfig::myConfig() : wxFileConfig(wxEmptyString, wxEmptyString, L_DIR_BIN wxT("lychee.conf"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH)
\r
32 this->label[CONF_WINDOW_HEIGHT] = wxT("Window-Height");
\r
33 this->label[CONF_WINDOW_WIDTH] = wxT("Window-Width");
\r
34 this->label[CONF_WINDOW_X] = wxT("Window-X");
\r
35 this->label[CONF_WINDOW_Y] = wxT("Window-Y");
\r
36 this->label[CONF_WINDOW_SPLITTER_POS]=wxT("Window-SplitterPos");
\r
37 this->label[CONF_WINDOW_STATUSBAR] = wxT("Window-StatusBar");
\r
38 this->label[CONF_WINDOW_TOOLBAR] = wxT("Window-ToolBar");
\r
40 this->label[CONF_LISTVIEW_SHOWMODE] = wxT("ListView-ShowMode");
\r
41 this->label[CONF_LISTVIEW_C_FILENAME]=wxT("ListView-C-Filename");
\r
42 this->label[CONF_LISTVIEW_C_UNPACKED]=wxT("ListView-C-Unpacked");
\r
43 this->label[CONF_LISTVIEW_C_PACKED] = wxT("ListView-C-Packed");
\r
44 this->label[CONF_LISTVIEW_C_RATIO] = wxT("ListView-C-Ratio");
\r
45 this->label[CONF_LISTVIEW_C_METHOD] = wxT("ListView-C-Method");
\r
46 this->label[CONF_LISTVIEW_C_ATTR] = wxT("ListView-C-Attr");
\r
47 this->label[CONF_LISTVIEW_C_LASTMOD]= wxT("ListView-C-LastMod");
\r
48 this->label[CONF_LISTVIEW_C_PATH] = wxT("ListView-C-Path");
\r
49 this->label[CONF_LISTVIEW_C_TYPE] = wxT("ListView-C-Type");
\r
50 this->label[CONF_LISTVIEW_C_NO] = wxT("ListView-C-No");
\r
51 this->label[CONF_LISTVIEW_S_COLUMN] = wxT("ListView-SortColumn");
\r
52 this->label[CONF_LISTVIEW_S_ASCEND] = wxT("ListView-SortAscend");
\r
54 this->label[CONF_DEFAULT_EXT] = wxT("DefaultExt");
\r
55 this->label[CONF_DEFAULT_PATH] = wxT("DefaultPath");
\r
57 this->label[CONF_HISTORY_PATH] = wxT("History-Path%d");
\r
58 this->label[CONF_HISTORY_NAME] = wxT("History-Name%d");
\r
59 this->label[CONF_HISTORY_FULL] = wxT("History-Full%d");
\r
60 this->label[CONF_HISTORY_COUNT] = wxT("History-Count");
\r
62 this->label[CONF_PROCESS_DLG] = wxT("Process-Dialog");
\r
65 for (long i = 0; i < this->ReadId(CONF_HISTORY_COUNT, 7l); i++)
\r
67 this->myReadHistory(CONF_HISTORY_PATH, i);
\r
68 this->myReadHistory(CONF_HISTORY_NAME, i);
\r
69 this->myReadHistory(CONF_HISTORY_FULL, i);
\r
71 this->bWriteHistory = false;
\r
74 myConfig::~myConfig()
\r
76 if (this->bWriteHistory)
\r
78 this->myWriteHistoryLoop(CONF_HISTORY_PATH);
\r
79 this->myWriteHistoryLoop(CONF_HISTORY_NAME);
\r
80 this->myWriteHistoryLoop(CONF_HISTORY_FULL);
\r
84 //******************************************************************************
\r
86 //******************************************************************************
\r
88 wxString myConfig::ReadId(myConfigId confId, const wxString & defaultVal)
\r
90 return this->Read(this->label[confId], defaultVal);
\r
93 long myConfig::ReadId(myConfigId confId, long defaultVal)
\r
95 return this->Read(this->label[confId], defaultVal);
\r
98 bool myConfig::ReadId(myConfigId confId, bool defaultVal)
\r
100 bool b = defaultVal;
\r
101 this->Read(this->label[confId], & b, defaultVal);
\r
105 bool myConfig::WriteId(myConfigId confId, const wxString & value)
\r
107 return this->Write(this->label[confId], value);
\r
110 bool myConfig::WriteId(myConfigId confId, int value)
\r
112 return this->Write(this->label[confId], value);
\r
115 bool myConfig::WriteId(myConfigId confId, bool value)
\r
117 return this->Write(this->label[confId], value);
\r
120 //******************************************************************************
\r
122 //******************************************************************************
\r
124 void myConfig::myReadHistory(myConfigId confId, size_t i)
\r
126 wxArrayString * as = & this->asHistory[confId - CONF_HISTORY_PATH];
\r
127 wxString sz = this->Read(wxString::Format(this->label[confId], i), wxEmptyString);
\r
128 if (! sz.IsEmpty() && as->Index(sz) == wxNOT_FOUND)
\r
134 void myConfig::myWriteHistory(myConfigId confId, size_t i)
\r
136 this->Write(wxString::Format(this->label[confId], i), this->asHistory[confId - CONF_HISTORY_PATH][i]);
\r
139 void myConfig::myWriteHistoryLoop(myConfigId confId)
\r
141 for (size_t i = 0; i < (size_t) this->ReadId(CONF_HISTORY_COUNT, 7l) && i < this->GetHistoryCount(confId); i++)
\r
143 this->myWriteHistory(confId, i);
\r
147 size_t myConfig::GetHistoryCount(myConfigId confId)
\r
149 return this->asHistory[confId - CONF_HISTORY_PATH].GetCount();
\r
152 wxString myConfig::ReadHistory(myConfigId confId, size_t i)
\r
154 return i < this->GetHistoryCount(confId) ? this->asHistory[confId - CONF_HISTORY_PATH][i] : (wxString) wxEmptyString;
\r
157 void myConfig::WriteHistory(myConfigId confId, const wxString & sz)
\r
163 this->bWriteHistory = true;
\r
165 wxArrayString * as = & this->asHistory[confId - CONF_HISTORY_PATH];
\r
166 if (as->Index(sz) != wxNOT_FOUND)
\r