OSDN Git Service

1f5bcba117a177dc333c97a2ca2a41cefc87eb07
[tpi/lychee.git] / src / lychee / cls_config.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \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
8   any later version.\r
9 \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
13   for more details.\r
14 \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
18 \r
19   $Id$\r
20 *******************************************************************************/\r
21 \r
22 #include "lychee.h"\r
23 #include "cls_config.h"\r
24 \r
25 //******************************************************************************\r
26 // myConfig\r
27 //******************************************************************************\r
28 \r
29 myConfig::myConfig() : wxFileConfig(wxEmptyString, wxEmptyString, L_DIR_BIN wxT("lychee.conf"), wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH)\r
30 {\r
31         // 設定名とIDを対応。\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
39 \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
53 \r
54         this->label[CONF_DEFAULT_EXT]       = wxT("DefaultExt");\r
55         this->label[CONF_DEFAULT_PATH]      = wxT("DefaultPath");\r
56 \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
61 \r
62         // 履歴読み込み。\r
63         for (long i = 0; i < this->ReadId(CONF_HISTORY_COUNT, 7l); i++)\r
64         {\r
65                 this->myReadHistory(CONF_HISTORY_PATH, i);\r
66                 this->myReadHistory(CONF_HISTORY_NAME, i);\r
67                 this->myReadHistory(CONF_HISTORY_FULL, i);\r
68         }\r
69         this->bWriteHistory = false;\r
70 }\r
71 \r
72 myConfig::~myConfig()\r
73 {\r
74         if (this->bWriteHistory)\r
75         {\r
76                 this->myWriteHistoryLoop(CONF_HISTORY_PATH);\r
77                 this->myWriteHistoryLoop(CONF_HISTORY_NAME);\r
78                 this->myWriteHistoryLoop(CONF_HISTORY_FULL);\r
79         }\r
80 }\r
81 \r
82 //******************************************************************************\r
83 // General\r
84 //******************************************************************************\r
85 \r
86 wxString myConfig::ReadId(myConfigId confId, const wxString & defaultVal)\r
87 {\r
88         return this->Read(this->label[confId], defaultVal);\r
89 }\r
90 \r
91 long myConfig::ReadId(myConfigId confId, long defaultVal)\r
92 {\r
93         return this->Read(this->label[confId], defaultVal);\r
94 }\r
95 \r
96 bool myConfig::ReadId(myConfigId confId, bool defaultVal)\r
97 {\r
98         bool b = defaultVal;\r
99         this->Read(this->label[confId], & b, defaultVal);\r
100         return b;\r
101 }\r
102 \r
103 bool myConfig::WriteId(myConfigId confId, const wxString & value)\r
104 {\r
105         return this->Write(this->label[confId], value);\r
106 }\r
107 \r
108 bool myConfig::WriteId(myConfigId confId, int value)\r
109 {\r
110         return this->Write(this->label[confId], value);\r
111 }\r
112 \r
113 bool myConfig::WriteId(myConfigId confId, bool value)\r
114 {\r
115         return this->Write(this->label[confId], value);\r
116 }\r
117 \r
118 //******************************************************************************\r
119 // History\r
120 //******************************************************************************\r
121 \r
122 void myConfig::myReadHistory(myConfigId confId, size_t i)\r
123 {\r
124         wxArrayString * as = & this->asHistory[confId - CONF_HISTORY_PATH];\r
125         wxString sz = this->Read(wxString::Format(this->label[confId], i), wxEmptyString);\r
126         if (! sz.IsEmpty() && as->Index(sz) == wxNOT_FOUND)\r
127         {\r
128                 as->Add(sz);\r
129         }\r
130 }\r
131 \r
132 void myConfig::myWriteHistory(myConfigId confId, size_t i)\r
133 {\r
134         this->Write(wxString::Format(this->label[confId], i), this->asHistory[confId - CONF_HISTORY_PATH][i]);\r
135 }\r
136 \r
137 void myConfig::myWriteHistoryLoop(myConfigId confId)\r
138 {\r
139         for (size_t i = 0; i < (size_t) this->ReadId(CONF_HISTORY_COUNT, 7l) && i < this->GetHistoryCount(confId); i++)\r
140         {\r
141                 this->myWriteHistory(confId, i);\r
142         }\r
143 }\r
144 \r
145 size_t myConfig::GetHistoryCount(myConfigId confId)\r
146 {\r
147         return this->asHistory[confId - CONF_HISTORY_PATH].GetCount();\r
148 }\r
149 \r
150 wxString myConfig::ReadHistory(myConfigId confId, size_t i)\r
151 {\r
152         return i < this->GetHistoryCount(confId) ? this->asHistory[confId - CONF_HISTORY_PATH][i] : (wxString) wxEmptyString;\r
153 }\r
154 \r
155 void myConfig::WriteHistory(myConfigId confId, const wxString & sz)\r
156 {\r
157         if (sz.IsEmpty())\r
158         {\r
159                 return;\r
160         }\r
161         this->bWriteHistory = true;\r
162 \r
163         wxArrayString * as = & this->asHistory[confId - CONF_HISTORY_PATH];\r
164         if (as->Index(sz) != wxNOT_FOUND)\r
165         {\r
166                 as->Remove(sz);\r
167         }\r
168         as->Insert(sz, 0);\r
169 }\r