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, s_nInterval = 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
102 if (piInfo->fiInfo.nUnpackedSize > 10000)
\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
111 case TPI_STATUS_INPROCESS:
\r
112 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
114 this->gFile->SetValue(piInfo->nProcessedSize);
\r
115 ::wxSafeYield(this, true);
\r
118 case TPI_STATUS_ENDPROCESS:
\r
119 if (s_nGaugeCounter++ > s_nInterval)
\r
121 this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);
\r
122 ::wxSafeYield(this, true);
\r
123 s_nGaugeCounter = 0;
\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
134 if (piInfo->fiInfo.nUnpackedSize > 10000)
\r
136 this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
\r
138 if (s_nGaugeCounter++ > s_nInterval)
\r
140 this->gArchive->SetValue(piInfo->nProcessedSize);
\r
141 ::wxSafeYield(this, true);
\r
142 s_nGaugeCounter = 0;
\r
148 case TPI_MESSAGE_ASK:
\r
150 switch (piInfo->eStatus)
\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
156 this->fCancel = true;
\r
159 case TPI_PARAM_NEXTVOLUME:
\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
165 this->fCancel = true;
\r
167 piInfo->szParam = fd.GetPath();
\r
171 return TPI_CALLBACK_UNSUPPORTED;
\r
176 return TPI_CALLBACK_UNSUPPORTED;
\r
179 return this->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
\r
182 //******************************************************************************
\r
184 //******************************************************************************
\r
186 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
\r
188 return g_procDlg == NULL ? TPI_CALLBACK_CONTINUE : g_procDlg->CallbackProc(_uMsg, _pStructure);
\r