OSDN Git Service

旧来の進捗ダイアログを表示する設定"Process-Dialog"を追加。
[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         this->label[CONF_PROCESS_DLG]       = wxT("Process-Dialog");\r
63 \r
64         // 履歴読み込み。\r
65         for (long i = 0; i < this->ReadId(CONF_HISTORY_COUNT, 7l); i++)\r
66         {\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
70         }\r
71         this->bWriteHistory = false;\r
72 }\r
73 \r
74 myConfig::~myConfig()\r
75 {\r
76         if (this->bWriteHistory)\r
77         {\r
78                 this->myWriteHistoryLoop(CONF_HISTORY_PATH);\r
79                 this->myWriteHistoryLoop(CONF_HISTORY_NAME);\r
80                 this->myWriteHistoryLoop(CONF_HISTORY_FULL);\r
81         }\r
82 }\r
83 \r
84 //******************************************************************************\r
85 // General\r
86 //******************************************************************************\r
87 \r
88 wxString myConfig::ReadId(myConfigId confId, const wxString & defaultVal)\r
89 {\r
90         return this->Read(this->label[confId], defaultVal);\r
91 }\r
92 \r
93 long myConfig::ReadId(myConfigId confId, long defaultVal)\r
94 {\r
95         return this->Read(this->label[confId], defaultVal);\r
96 }\r
97 \r
98 bool myConfig::ReadId(myConfigId confId, bool defaultVal)\r
99 {\r
100         bool b = defaultVal;\r
101         this->Read(this->label[confId], & b, defaultVal);\r
102         return b;\r
103 }\r
104 \r
105 bool myConfig::WriteId(myConfigId confId, const wxString & value)\r
106 {\r
107         return this->Write(this->label[confId], value);\r
108 }\r
109 \r
110 bool myConfig::WriteId(myConfigId confId, int value)\r
111 {\r
112         return this->Write(this->label[confId], value);\r
113 }\r
114 \r
115 bool myConfig::WriteId(myConfigId confId, bool value)\r
116 {\r
117         return this->Write(this->label[confId], value);\r
118 }\r
119 \r
120 //******************************************************************************\r
121 // History\r
122 //******************************************************************************\r
123 \r
124 void myConfig::myReadHistory(myConfigId confId, size_t i)\r
125 {\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
129         {\r
130                 as->Add(sz);\r
131         }\r
132 }\r
133 \r
134 void myConfig::myWriteHistory(myConfigId confId, size_t i)\r
135 {\r
136         this->Write(wxString::Format(this->label[confId], i), this->asHistory[confId - CONF_HISTORY_PATH][i]);\r
137 }\r
138 \r
139 void myConfig::myWriteHistoryLoop(myConfigId confId)\r
140 {\r
141         for (size_t i = 0; i < (size_t) this->ReadId(CONF_HISTORY_COUNT, 7l) && i < this->GetHistoryCount(confId); i++)\r
142         {\r
143                 this->myWriteHistory(confId, i);\r
144         }\r
145 }\r
146 \r
147 size_t myConfig::GetHistoryCount(myConfigId confId)\r
148 {\r
149         return this->asHistory[confId - CONF_HISTORY_PATH].GetCount();\r
150 }\r
151 \r
152 wxString myConfig::ReadHistory(myConfigId confId, size_t i)\r
153 {\r
154         return i < this->GetHistoryCount(confId) ? this->asHistory[confId - CONF_HISTORY_PATH][i] : (wxString) wxEmptyString;\r
155 }\r
156 \r
157 void myConfig::WriteHistory(myConfigId confId, const wxString & sz)\r
158 {\r
159         if (sz.IsEmpty())\r
160         {\r
161                 return;\r
162         }\r
163         this->bWriteHistory = true;\r
164 \r
165         wxArrayString * as = & this->asHistory[confId - CONF_HISTORY_PATH];\r
166         if (as->Index(sz) != wxNOT_FOUND)\r
167         {\r
168                 as->Remove(sz);\r
169         }\r
170         as->Insert(sz, 0);\r
171 }\r