OSDN Git Service

高速化。
[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 \r
25 ProcessDialog * g_procDlg = NULL;\r
26 \r
27 //******************************************************************************\r
28 // ProcessDialog\r
29 //******************************************************************************\r
30 \r
31 ProcessDialog::ProcessDialog(): wxDialog()\r
32 {\r
33         ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
34         ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));        \r
35 }\r
36 \r
37 ProcessDialog::~ProcessDialog()\r
38 {\r
39         g_procDlg = NULL;\r
40 }\r
41 \r
42 //******************************************************************************\r
43 // Event table.\r
44 //******************************************************************************\r
45 \r
46 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)\r
47         EVT_INIT_DIALOG(ProcessDialog::OnInit)\r
48         EVT_CLOSE(      ProcessDialog::OnClose)\r
49 END_EVENT_TABLE()\r
50 \r
51 //******************************************************************************\r
52 // Event handler.\r
53 //******************************************************************************\r
54 \r
55 void ProcessDialog::OnInit(wxInitDialogEvent &)\r
56 {\r
57         // XRCと結びつけ。\r
58         this->ebSource          = XRCCTRL(* this, "ebSource",     wxTextCtrl);\r
59         this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);\r
60         this->gFile             = XRCCTRL(* this, "gFile",        wxGauge);\r
61         this->gArchive          = XRCCTRL(* this, "gArchive",     wxGauge);\r
62         this->fCancel           = false;\r
63         g_procDlg = this;\r
64 \r
65         ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
66 }\r
67 \r
68 void ProcessDialog::OnClose(wxCloseEvent & e)\r
69 {\r
70         if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)\r
71         {\r
72                 this->fCancel = true;\r
73         }\r
74         e.Veto();\r
75 }\r
76 \r
77 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)\r
78 {\r
79         if (_uMsg != TPI_NOTIFY_COMMON)\r
80         {\r
81                 return TPI_CALLBACK_UNSUPPORTED;\r
82         }\r
83 \r
84         TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
85         if (piInfo == NULL || ! this->IsShown())\r
86         {\r
87                 return TPI_CALLBACK_CONTINUE;\r
88         }\r
89 \r
90         switch (piInfo->eMessage)\r
91         {\r
92         case TPI_MESSAGE_STATUS:\r
93         {\r
94                 static int s_nGaugeCounter = 0, s_nInterval = 0;\r
95                 switch (piInfo->eStatus)\r
96                 {\r
97                 case TPI_STATUS_OPENARCHIVE:\r
98                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
99                         break;\r
100                 case TPI_STATUS_BEGINPROCESS:\r
101                         // 小さなファイルなら表示しない。\r
102                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
103                         {\r
104                                 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
105                                 this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
106                                 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);\r
107                                 this->gFile->SetValue(0);\r
108                                 ::wxSafeYield(this, true);\r
109                         }\r
110                         break;\r
111                 case TPI_STATUS_INPROCESS:\r
112                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
113                         {\r
114                                 this->gFile->SetValue(piInfo->nProcessedSize);\r
115                                 ::wxSafeYield(this, true);\r
116                         }\r
117                         break;\r
118                 case TPI_STATUS_ENDPROCESS:\r
119                         if (s_nGaugeCounter++ > s_nInterval)\r
120                         {\r
121                                 this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);\r
122                                 ::wxSafeYield(this, true);\r
123                                 s_nGaugeCounter = 0;\r
124                         }\r
125                         break;\r
126                 // 書庫ロード時用の独自仕様。\r
127                 case 0x1000:\r
128                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
129                         this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);\r
130                         this->gArchive->SetValue(0);\r
131                         s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;\r
132                         break;\r
133                 case 0x1001:\r
134                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
135                         {\r
136                                 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
137                         }\r
138                         if (s_nGaugeCounter++ > s_nInterval)\r
139                         {\r
140                                 this->gArchive->SetValue(piInfo->nProcessedSize);\r
141                                 ::wxSafeYield(this, true);\r
142                                 s_nGaugeCounter = 0;\r
143                         }\r
144                         break;\r
145                 }\r
146                 break;\r
147         }\r
148         case TPI_MESSAGE_ASK:\r
149         {\r
150                 switch (piInfo->eStatus)\r
151                 {\r
152                 case TPI_PARAM_PASSWORD:\r
153                         piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);\r
154                         if (piInfo->szParam.IsEmpty())\r
155                         {\r
156                                 this->fCancel = true;\r
157                         }\r
158                         break;\r
159                 case TPI_PARAM_NEXTVOLUME:\r
160                 {\r
161                         wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());\r
162                         fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);\r
163                         if (fd.ShowModal() == wxID_CANCEL)\r
164                         {\r
165                                 this->fCancel = true;\r
166                         }\r
167                         piInfo->szParam = fd.GetPath();\r
168                         break;\r
169                 }\r
170                 default:\r
171                         return TPI_CALLBACK_UNSUPPORTED;\r
172                 }\r
173                 break;\r
174         }\r
175         default:\r
176                 return TPI_CALLBACK_UNSUPPORTED;\r
177         }\r
178 \r
179         return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
180 }\r
181 \r
182 //******************************************************************************\r
183 //    ダイアログプロシージャ\r
184 //******************************************************************************\r
185 \r
186 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
187 {\r
188         return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);\r
189 }\r