1 /*******************************************************************************
\r
2 TPI - flexible but useless plug-in framework.
\r
3 Copyright (C) 2002-2009 Silky
\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
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
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
20 *******************************************************************************/
\r
23 #include "dlg_process.h"
\r
25 ProcessDialog * g_procDlg = NULL;
\r
27 //******************************************************************************
\r
29 //******************************************************************************
\r
31 ProcessDialog::ProcessDialog(): wxDialog()
\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
37 ProcessDialog::~ProcessDialog()
\r
42 //******************************************************************************
\r
44 //******************************************************************************
\r
46 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)
\r
47 EVT_INIT_DIALOG(ProcessDialog::OnInit)
\r
48 EVT_CLOSE( ProcessDialog::OnClose)
\r
51 //******************************************************************************
\r
53 //******************************************************************************
\r
55 void ProcessDialog::OnInit(wxInitDialogEvent &)
\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
65 ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));
\r
68 void ProcessDialog::OnClose(wxCloseEvent & e)
\r
70 if (e.CanVeto() && ::AskDlg(_("Really do you want to cancel this operation?"), this) == wxYES)
\r
72 this->fCancel = true;
\r
77 int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
\r
79 if (_uMsg != TPI_NOTIFY_COMMON)
\r
81 return TPI_CALLBACK_UNSUPPORTED;
\r
84 TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
\r
85 if (piInfo == NULL || ! this->IsShown())
\r
87 return TPI_CALLBACK_CONTINUE;
\r
90 switch (piInfo->eMessage)
\r
92 case TPI_MESSAGE_STATUS:
\r
94 static int s_nGaugeCounter = 0;
\r
95 switch (piInfo->eStatus)
\r
97 case TPI_STATUS_OPENARCHIVE:
\r
98 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\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
105 this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
106 this->gFile->SetValue(0);
\r
108 ::wxSafeYield(this, true);
\r
110 case TPI_STATUS_INPROCESS:
\r
111 if (s_nGaugeCounter++ > 100)
\r
113 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
115 this->gFile->SetValue(piInfo->nProcessedSize);
\r
117 ::wxSafeYield(this, true);
\r
118 s_nGaugeCounter = 0;
\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
127 this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
128 this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);
\r
129 this->gArchive->SetValue(0);
\r
132 // 更新しすぎると低速なので100ファイル毎に更新する。
\r
133 if (piInfo->nProcessedSize > this->gArchive->GetValue() + 100)
\r
135 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
136 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
137 ::wxSafeYield(this, true);
\r
143 case TPI_MESSAGE_ASK:
\r
145 switch (piInfo->eStatus)
\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
151 this->fCancel = true;
\r
154 case TPI_PARAM_NEXTVOLUME:
\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
160 this->fCancel = true;
\r
162 piInfo->szParam = fd.GetPath();
\r
166 return TPI_CALLBACK_UNSUPPORTED;
\r
171 return TPI_CALLBACK_UNSUPPORTED;
\r
174 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
177 //******************************************************************************
\r
179 //******************************************************************************
\r
181 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
183 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r