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;\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                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
102                         this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
103                         if (piInfo->fiInfo.nUnpackedSize > 10000)\r
104                         {\r
105                                 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);\r
106                                 this->gFile->SetValue(0);\r
107                         }\r
108                         ::wxSafeYield(this, true);\r
109                         break;\r
110                 case TPI_STATUS_INPROCESS:\r
111                         if (s_nGaugeCounter++ > 100)\r
112                         {\r
113                                 if (piInfo->fiInfo.nUnpackedSize > 10000)\r
114                                 {\r
115                                         this->gFile->SetValue(piInfo->nProcessedSize);\r
116                                 }\r
117                                 ::wxSafeYield(this, true);\r
118                                 s_nGaugeCounter = 0;\r
119                         }\r
120                         break;\r
121                 case TPI_STATUS_ENDPROCESS:\r
122 //                      this->gFile->SetValue(piInfo->fiInfo.nUnpackedSize.ToULong());\r
123                         this->gArchive->SetValue(this->gArchive->GetValue() + 1);\r
124                         break;\r
125                 // 書庫ロード時用の独自仕様。\r
126                 case 0x1000:\r
127                         this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
128                         this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);\r
129                         this->gArchive->SetValue(0);\r
130                         break;\r
131                 case 0x1001:\r
132                         // 更新しすぎると低速なので100ファイル毎に更新する。\r
133                         if (piInfo->nProcessedSize > this->gArchive->GetValue() + 100)\r
134                         {\r
135                                 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
136                                 this->gArchive->SetValue(piInfo->nProcessedSize);\r
137                                 ::wxSafeYield(this, true);\r
138                         }\r
139                         break;\r
140                 }\r
141                 break;\r
142         }\r
143         case TPI_MESSAGE_ASK:\r
144         {\r
145                 switch (piInfo->eStatus)\r
146                 {\r
147                 case TPI_PARAM_PASSWORD:\r
148                         piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);\r
149                         if (piInfo->szParam.IsEmpty())\r
150                         {\r
151                                 this->fCancel = true;\r
152                         }\r
153                         break;\r
154                 case TPI_PARAM_NEXTVOLUME:\r
155                 {\r
156                         wxFileDialog fd(this, _("Select next volume of: ") + piInfo->fiInfo.fnFileName.GetFullName());\r
157                         fd.SetWindowStyleFlag(wxFD_FILE_MUST_EXIST);\r
158                         if (fd.ShowModal() == wxID_CANCEL)\r
159                         {\r
160                                 this->fCancel = true;\r
161                         }\r
162                         piInfo->szParam = fd.GetPath();\r
163                         break;\r
164                 }\r
165                 default:\r
166                         return TPI_CALLBACK_UNSUPPORTED;\r
167                 }\r
168                 break;\r
169         }\r
170         default:\r
171                 return TPI_CALLBACK_UNSUPPORTED;\r
172         }\r
173 \r
174         return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
175 }\r
176 \r
177 //******************************************************************************\r
178 //    ダイアログプロシージャ\r
179 //******************************************************************************\r
180 \r
181 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
182 {\r
183         return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);\r
184 }\r