OSDN Git Service

処理中にパスワードを求められた際、ダイアログを表示してパスワードを入力できるよう変更。
[tpi/lychee.git] / src / frontend / dlg_process.cpp
1 /*******************************************************************************
2   TPI - flexible but useless plug-in framework.
3   Copyright (C) 2002-2009 Silky
4
5   This library is free software; you can redistribute it and/or modify it under
6   the terms of the GNU Lesser General Public License as published by the Free
7   Software Foundation; either version 2.1 of the License, or (at your option)
8   any later version.
9
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
13   for more details.
14
15   You should have received a copy of the GNU Lesser General Public License along
16   with this library; if not, write to the Free Software Foundation, Inc.,
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
19   $Id: dlg_process.cpp,v 1.6 2009/09/01 12:20:49 sirakaba Exp $
20 *******************************************************************************/
21
22 #include "frontend.h"
23 #include "dlg_process.h"
24
25 ProcessDialog * g_procDlg = NULL;
26
27 //******************************************************************************
28 // ProcessDialog
29 //******************************************************************************
30
31 ProcessDialog::ProcessDialog(): wxDialog()
32 {
33         ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
34         ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));        
35 }
36
37 ProcessDialog::~ProcessDialog()
38 {
39         g_procDlg = NULL;
40 }
41
42 //******************************************************************************
43 // Event table.
44 //******************************************************************************
45
46 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)
47         EVT_INIT_DIALOG(ProcessDialog::OnInit)
48         EVT_CLOSE(      ProcessDialog::OnClose)
49 END_EVENT_TABLE()
50
51 //******************************************************************************
52 // Event handler.
53 //******************************************************************************
54
55 void ProcessDialog::OnInit(wxInitDialogEvent &)
56 {
57         // XRC\82Æ\8c\8b\82Ñ\82Â\82¯\81B
58         this->ebSource          = XRCCTRL(* this, "ebSource",     wxTextCtrl);
59         this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);
60         this->gauge             = XRCCTRL(* this, "gauge",        wxGauge);
61         this->fCancel           = false;
62         g_procDlg = this;
63
64         ::wxXmlResource::Get()->Unload(FE_DIR_S_XRC wxT("dlg_process.xrc"));
65 }
66
67 void ProcessDialog::OnClose(wxCloseEvent & e)
68 {
69         if (e.CanVeto() && ::AskDlg(wxT("Really do you want to cancel this operation?"), this) == wxYES)
70         {
71                 this->fCancel = true;
72         }
73         e.Veto();
74 }
75
76 //******************************************************************************
77 //    \83_\83C\83A\83\8d\83O\83v\83\8d\83V\81[\83W\83\83
78 //******************************************************************************
79
80 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)
81 {
82         if (_uMsg != TPI_NOTIFY_COMMON)
83         {
84                 return TPI_CALLBACK_UNSUPPORTED;
85         }
86
87         TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;
88         if (g_procDlg == NULL || piInfo == NULL || ! g_procDlg->IsShown())
89         {
90                 return TPI_CALLBACK_CONTINUE;
91         }
92
93         switch (piInfo->uMessage)
94         {
95         case TPI_MESSAGE_STATUS:
96         {
97                 static int s_nGaugeCounter = 0;
98                 switch (piInfo->uStatus)
99                 {
100                 case TPI_STATUS_OPENARCHIVE:
101                         g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
102                         break;
103                 case TPI_STATUS_BEGINPROCESS:
104                         g_procDlg->ebTarget->ChangeValue((piInfo->fnDestination.IsOk() ? piInfo->fnDestination : piInfo->fiInfo.fnFileName).GetFullPath());
105                         if (piInfo->fiInfo.llUnpackedSize > 10000)
106                         {
107                                 g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());
108                                 g_procDlg->gauge->SetValue(0);
109                         }
110                         ::wxSafeYield(g_procDlg, true);
111                         break;
112                 case TPI_STATUS_INPROCESS:
113                         if (s_nGaugeCounter++ > 100)
114                         {
115                                 if (piInfo->fiInfo.llUnpackedSize > 10000)
116                                 {
117                                         g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());
118                                 }
119                                 ::wxSafeYield(g_procDlg, true);
120                                 s_nGaugeCounter = 0;
121                         }
122                         break;
123                 case TPI_STATUS_ENDPROCESS:
124 //                      g_procDlg->gauge->SetValue(piInfo->fiInfo.llUnpackedSize.ToULong());
125                         break;
126                 // \8f\91\8cÉ\83\8d\81[\83h\8e\9e\97p\82Ì\93Æ\8e©\8ed\97l\81B
127                 case 0x1000:
128                         g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
129                         g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());
130                         g_procDlg->gauge->SetValue(0);
131                         break;
132                 case 0x1001:
133                         // \8dX\90V\82µ\82·\82¬\82é\82Æ\92á\91¬\82È\82Ì\82Å100\83t\83@\83C\83\8b\96\88\82É\8dX\90V\82·\82é\81B
134                         if (piInfo->llProcessedSize > g_procDlg->gauge->GetValue() + 100)
135                         {
136                                 g_procDlg->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());
137                                 g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());
138                                 ::wxSafeYield(g_procDlg, true);
139                         }
140                         break;
141                 }
142                 break;
143         }
144         case TPI_MESSAGE_ASK:
145         {
146                 switch (piInfo->uStatus)
147                 {
148                 case TPI_PARAM_PASSWORD:
149                         piInfo->szParam = ::wxGetPasswordFromUser(wxT("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Frontend"), wxEmptyString, g_procDlg);
150                         if (piInfo->szParam.IsEmpty())
151                         {
152                                 g_procDlg->fCancel = true;
153                         }
154                         break;
155                 default:
156                         return TPI_CALLBACK_UNSUPPORTED;
157                 }
158                 break;
159         }
160         default:
161                 return TPI_CALLBACK_UNSUPPORTED;
162         }
163
164         return g_procDlg->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;
165 }