OSDN Git Service

Linuxでのコンパイルエラーを修正。
[tpi/lychee.git] / src / lychee / dlg_process.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 "dlg_process.h"\r
24 #include "dlg_make.h"\r
25 #include "frm_main.h"\r
26 #include "functions.h"\r
27 \r
28 ProcessDialog * g_procDlg = NULL;\r
29 \r
30 //******************************************************************************\r
31 // ProcessDialog\r
32 //******************************************************************************\r
33 \r
34 ProcessDialog::ProcessDialog(): wxDialog()\r
35 {\r
36         ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
37         ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));        \r
38 }\r
39 \r
40 ProcessDialog::~ProcessDialog()\r
41 {\r
42         g_procDlg = NULL;\r
43 }\r
44 \r
45 //******************************************************************************\r
46 // Event table.\r
47 //******************************************************************************\r
48 \r
49 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)\r
50         EVT_INIT_DIALOG(ProcessDialog::OnInit)\r
51         EVT_CLOSE(ProcessDialog::OnClose)\r
52 END_EVENT_TABLE()\r
53 \r
54 //******************************************************************************\r
55 // Event handler.\r
56 //******************************************************************************\r
57 \r
58 void ProcessDialog::OnInit(wxInitDialogEvent &)\r
59 {\r
60         // XRCと結びつけ。\r
61         this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);\r
62         this->ebSource          = XRCCTRL(* this, "ebSource",     wxTextCtrl);\r
63         this->gFile             = XRCCTRL(* this, "gFile",        wxGauge);\r
64         this->gArchive          = XRCCTRL(* this, "gArchive",     wxGauge);\r
65         this->fCancel           = false;\r
66         g_procDlg = this;\r
67 \r
68         ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
69 }\r
70 \r
71 void ProcessDialog::OnClose(wxCloseEvent & e)\r
72 {\r
73         if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)\r
74         {\r
75                 this->fCancel = true;\r
76         }\r
77         e.Veto();\r
78 }\r
79 \r
80 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)\r
81 {\r
82         if (_uMsg != TPI_NOTIFY_COMMON)\r
83         {\r
84                 return TPI_CALLBACK_UNSUPPORTED;\r
85         }\r
86 \r
87         TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
88         if (piInfo == NULL || ! this->IsShown())\r
89         {\r
90                 return TPI_CALLBACK_CONTINUE;\r
91         }\r
92 \r
93         switch (piInfo->eMessage)\r
94         {\r
95         case TPI_MESSAGE_STATUS:\r
96         {\r
97                 static int s_nGaugeCounter = 0, s_nInterval = 0;\r
98                 switch (piInfo->eStatus)\r
99                 {\r
100                 case TPI_STATUS_OPENARCHIVE:\r
101                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
102                         break;\r
103                 case TPI_STATUS_BEGINPROCESS:\r
104                         // 小さなファイルなら表示しない。\r
105                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
106                         {\r
107                                 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
108                                 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
109                                 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);\r
110                                 this->gFile->SetValue(0);\r
111                                 ::wxSafeYield(this, true);\r
112                         }\r
113                         break;\r
114                 case TPI_STATUS_INPROCESS:\r
115                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
116                         {\r
117                                 this->gFile->SetValue(piInfo->nProcessedSize);\r
118                                 ::wxSafeYield(this, true);\r
119                         }\r
120                         break;\r
121                 case TPI_STATUS_ENDPROCESS:\r
122                         if (s_nGaugeCounter++ > s_nInterval)\r
123                         {\r
124                                 this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);\r
125                                 ::wxSafeYield(this, true);\r
126                                 s_nGaugeCounter = 0;\r
127                         }\r
128                         break;\r
129                 // 書庫ロード時用の独自仕様。\r
130                 case 0x1000:\r
131                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
132                         this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);\r
133                         this->gArchive->SetValue(0);\r
134                         s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;\r
135                         break;\r
136                 case 0x1001:\r
137                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
138                         {\r
139                                 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
140                         }\r
141                         if (s_nGaugeCounter++ > s_nInterval)\r
142                         {\r
143                                 this->gArchive->SetValue(piInfo->nProcessedSize);\r
144                                 ::wxSafeYield(this, true);\r
145                                 s_nGaugeCounter = 0;\r
146                         }\r
147                         break;\r
148                 }\r
149                 break;\r
150         }\r
151         case TPI_MESSAGE_ASK:\r
152         {\r
153                 switch (piInfo->eStatus)\r
154                 {\r
155                 case TPI_PARAM_PASSWORD:\r
156                 {\r
157                         static wxFileName fnFormer;\r
158                         static wxString szFormer;\r
159                         if (piInfo->fiInfo.fnFileName == fnFormer)\r
160                         {\r
161                                 piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);\r
162                                 if (piInfo->szParam.IsEmpty())\r
163                                 {\r
164                                         this->fCancel = true;\r
165                                 }\r
166                                 szFormer = piInfo->szParam;\r
167                         }\r
168                         else\r
169                         {\r
170                                 piInfo->szParam = szFormer;\r
171                                 fnFormer = piInfo->fiInfo.fnFileName;\r
172                         }\r
173                         break;\r
174                 }\r
175                 case TPI_PARAM_NEXTVOLUME:\r
176                 {\r
177                         wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());\r
178                         fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);\r
179                         if (fd.ShowModal() == wxID_CANCEL)\r
180                         {\r
181                                 this->fCancel = true;\r
182                         }\r
183                         piInfo->szParam = fd.GetPath();\r
184                         break;\r
185                 }\r
186                 case TPI_PARAM_DEST:\r
187                         if (piInfo->fnDestination.FileExists() || ::wxDirExists(piInfo->fnDestination.GetFullPath()))\r
188                         {\r
189                                 // 上書き確認を行う。\r
190                                 static int nMode = wxID_OK;\r
191                                 bool bPerm = false;\r
192                                 if (nMode == wxID_OK)\r
193                                 {\r
194                                         OverwriteDialog odDlg;\r
195                                         odDlg.fnExist = & piInfo->fnDestination;\r
196                                         odDlg.tmWrite = & piInfo->fiInfo.tmModified;\r
197                                         odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;\r
198 \r
199                                         nMode = odDlg.ShowModal();\r
200                                         bPerm = odDlg.cbApplyAll->IsChecked();\r
201                                 }\r
202                                 switch (nMode)\r
203                                 {\r
204                                 case wxID_CANCEL:\r
205                                         this->fCancel = true;\r
206                                         break;\r
207                                 case 0:\r
208                                         // 自動上書き。既存のファイルを削除しておく。\r
209                                         if (piInfo->fnDestination.FileExists())\r
210                                         {\r
211                                                 ::wxRemoveFile(piInfo->fnDestination.GetFullPath());\r
212                                         }\r
213                                         else if (::wxDirExists(piInfo->fnDestination.GetFullPath()))\r
214                                         {\r
215                                                 // TODO: 再帰削除。\r
216                                                 ::wxRmdir(piInfo->fnDestination.GetFullPath());\r
217                                         }\r
218                                         break;\r
219                                 case 1:\r
220                                         // 自動スキップ。\r
221                                         piInfo->fnDestination.Clear();\r
222                                         break;\r
223                                 case 2:\r
224                                         // 自動リネーム。\r
225                                         break;\r
226                                 }\r
227                                 if (! bPerm)\r
228                                 {\r
229                                         nMode = wxID_OK;\r
230                                 }\r
231                         }\r
232                         break;\r
233                 default:\r
234                         return TPI_CALLBACK_UNSUPPORTED;\r
235                 }\r
236                 break;\r
237         }\r
238         default:\r
239                 return TPI_CALLBACK_UNSUPPORTED;\r
240         }\r
241 \r
242         return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
243 }\r
244 //******************************************************************************\r
245 // OverwriteDialog\r
246 //******************************************************************************\r
247 \r
248 OverwriteDialog::OverwriteDialog(): wxDialog()\r
249 {\r
250         ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));\r
251         ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_overwrite"));      \r
252 }\r
253 \r
254 //******************************************************************************\r
255 // Event table.\r
256 //******************************************************************************\r
257 \r
258 BEGIN_EVENT_TABLE(OverwriteDialog, wxDialog)\r
259         EVT_INIT_DIALOG(OverwriteDialog::OnInit)\r
260         EVT_BUTTON(XRCID("btnOverwrite"), OverwriteDialog::OnBtnOverwrite)\r
261         EVT_BUTTON(XRCID("btnSkip"), OverwriteDialog::OnBtnSkip)\r
262         EVT_BUTTON(XRCID("btnAuto"), OverwriteDialog::OnBtnAuto)\r
263         EVT_BUTTON(XRCID("btnBrowse"), OverwriteDialog::OnBtnBrowse)\r
264         EVT_CLOSE(OverwriteDialog::OnClose)\r
265 END_EVENT_TABLE()\r
266 \r
267 //******************************************************************************\r
268 // Event handler.\r
269 //******************************************************************************\r
270 \r
271 void OverwriteDialog::OnInit(wxInitDialogEvent &)\r
272 {\r
273         // XRCと結びつけ。\r
274         this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);\r
275         this->cbApplyAll        = XRCCTRL(* this, "cbApplyAll",   wxCheckBox);\r
276         ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_overwrite.xrc"));\r
277 \r
278         // ファイル情報を設定。\r
279         this->ebTarget->SetValue(this->fnExist->GetFullPath());\r
280         XRCCTRL(* this, "stExistTime", wxStaticText)->SetLabel(this->fnExist->GetModificationTime().Format(_("%Y/%m/%d %H:%M:%S modified, ")));\r
281         XRCCTRL(* this, "stExistSize", wxStaticText)->SetLabel(this->fnExist->GetHumanReadableSize());\r
282         XRCCTRL(* this, "stWriteTime", wxStaticText)->SetLabel(this->tmWrite->Format(_("%Y/%m/%d %H:%M:%S modified, ")));\r
283         XRCCTRL(* this, "stWriteSize", wxStaticText)->SetLabel(wxFileName::GetHumanReadableSize((wxULongLong) this->nWriteSize));\r
284         XRCCTRL(* this, "sbIcon", wxStaticBitmap)->SetIcon(GetFileTypeIcon(* this->fnExist));\r
285 }\r
286 \r
287 void OverwriteDialog::OnClose(wxCloseEvent & e)\r
288 {\r
289         if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)\r
290         {\r
291                 this->EndModal(wxID_CANCEL);\r
292         }\r
293         e.Veto();\r
294 }\r
295 \r
296 void OverwriteDialog::OnBtnOverwrite(wxCommandEvent&)\r
297 {\r
298         if (this->fnExist->GetFullPath() != this->ebTarget->GetValue())\r
299         {\r
300                 // 保存先を変えているので、次回もダイアログを表示。\r
301                 this->cbApplyAll->SetValue(false);\r
302                 * this->fnExist = wxFileName(this->ebTarget->GetValue());\r
303         }\r
304         this->EndModal(0);\r
305 }\r
306 \r
307 void OverwriteDialog::OnBtnSkip(wxCommandEvent&)\r
308 {\r
309         this->EndModal(1);\r
310 }\r
311 \r
312 void OverwriteDialog::OnBtnAuto(wxCommandEvent&)\r
313 {\r
314         this->EndModal(2);\r
315 }\r
316 \r
317 void OverwriteDialog::OnBtnBrowse(wxCommandEvent&)\r
318 {\r
319         wxFileDialog fd(this);\r
320         fd.SetWindowStyleFlag(wxFD_SAVE | wxFD_OVERWRITE_PROMPT);\r
321         fd.SetPath(this->ebTarget->GetValue());\r
322         if (fd.ShowModal() == wxID_OK)\r
323         {\r
324                 this->ebTarget->SetValue(fd.GetPath());\r
325         }\r
326 }\r
327 \r
328 //******************************************************************************\r
329 //    ダイアログプロシージャ\r
330 //******************************************************************************\r
331 \r
332 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
333 {\r
334         return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);\r
335 }\r