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->gauge             = XRCCTRL(* this, "gauge",        wxGauge);\r
61         this->fCancel           = false;\r
62         g_procDlg = this;\r
63 \r
64         ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
65 }\r
66 \r
67 void ProcessDialog::OnClose(wxCloseEvent & e)\r
68 {\r
69         if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)\r
70         {\r
71                 this->fCancel = true;\r
72         }\r
73         e.Veto();\r
74 }\r
75 \r
76 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)\r
77 {\r
78         if (_uMsg != TPI_NOTIFY_COMMON)\r
79         {\r
80                 return TPI_CALLBACK_UNSUPPORTED;\r
81         }\r
82 \r
83         TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
84         if (piInfo == NULL || ! g_procDlg->IsShown())\r
85         {\r
86                 return TPI_CALLBACK_CONTINUE;\r
87         }\r
88 \r
89         switch (piInfo->uMessage)\r
90         {\r
91         case TPI_MESSAGE_STATUS:\r
92         {\r
93                 static int s_nGaugeCounter = 0;\r
94                 switch (piInfo->uStatus)\r
95                 {\r
96                 case TPI_STATUS_OPENARCHIVE:\r
97                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
98                         break;\r
99                 case TPI_STATUS_BEGINPROCESS:\r
100                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
101                         this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
102                         if (piInfo->fiInfo.llUnpackedSize > 10000)\r
103                         {\r
104                                 this->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());\r
105                                 this->gauge->SetValue(0);\r
106                         }\r
107                         ::wxSafeYield(this, true);\r
108                         break;\r
109                 case TPI_STATUS_INPROCESS:\r
110                         if (s_nGaugeCounter++ > 100)\r
111                         {\r
112                                 if (piInfo->fiInfo.llUnpackedSize > 10000)\r
113                                 {\r
114                                         this->gauge->SetValue(piInfo->llProcessedSize.ToULong());\r
115                                 }\r
116                                 ::wxSafeYield(this, true);\r
117                                 s_nGaugeCounter = 0;\r
118                         }\r
119                         break;\r
120                 case TPI_STATUS_ENDPROCESS:\r
121 //                      this->gauge->SetValue(piInfo->fiInfo.llUnpackedSize.ToULong());\r
122                         break;\r
123                 // 書庫ロード時用の独自仕様。\r
124                 case 0x1000:\r
125                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
126                         this->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());\r
127                         this->gauge->SetValue(0);\r
128                         break;\r
129                 case 0x1001:\r
130                         // 更新しすぎると低速なので100ファイル毎に更新する。\r
131                         if (piInfo->llProcessedSize > this->gauge->GetValue() + 100)\r
132                         {\r
133                                 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
134                                 this->gauge->SetValue(piInfo->llProcessedSize.ToULong());\r
135                                 ::wxSafeYield(this, true);\r
136                         }\r
137                         break;\r
138                 }\r
139                 break;\r
140         }\r
141         case TPI_MESSAGE_ASK:\r
142         {\r
143                 switch (piInfo->uStatus)\r
144                 {\r
145                 case TPI_PARAM_PASSWORD:\r
146                         piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);\r
147                         if (piInfo->szParam.IsEmpty())\r
148                         {\r
149                                 this->fCancel = true;\r
150                         }\r
151                         break;\r
152                 case TPI_PARAM_NEXTVOLUME:\r
153                 {\r
154                         wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());\r
155                         fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);\r
156                         if (fd.ShowModal() == wxID_CANCEL)\r
157                         {\r
158                                 this->fCancel = true;\r
159                         }\r
160                         piInfo->szParam = fd.GetPath();\r
161                         break;\r
162                 }\r
163                 default:\r
164                         return TPI_CALLBACK_UNSUPPORTED;\r
165                 }\r
166                 break;\r
167         }\r
168         default:\r
169                 return TPI_CALLBACK_UNSUPPORTED;\r
170         }\r
171 \r
172         return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
173 }\r
174 \r
175 //******************************************************************************\r
176 //    ダイアログプロシージャ\r
177 //******************************************************************************\r
178 \r
179 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
180 {\r
181         return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);\r
182 }\r