OSDN Git Service

上書き確認ダイアログでキャンセルすると書庫を閉じてしまうバグを修正。
[tpi/lychee.git] / src / lychee / dlg_process.cpp
index c95d544..4dfd800 100644 (file)
@@ -31,14 +31,41 @@ ProcessDialog * g_procDlg = NULL;
 // ProcessDialog\r
 //******************************************************************************\r
 \r
-ProcessDialog::ProcessDialog(): wxDialog()\r
+ProcessDialog::ProcessDialog(wxWindow * parent, wxULongLong_t n, wxString szPassword): wxDialog(), nFileCount(n), szPassword(szPassword), fOpen(false)\r
 {\r
        ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
-       ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));        \r
+       ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));\r
+       g_procDlg = this;\r
+       this->hParent = parent;\r
+       this->InitDialog();\r
 }\r
 \r
 ProcessDialog::~ProcessDialog()\r
 {\r
+       // ウインドウの機能を有効化。\r
+       MainFrame * frm_main = (MainFrame *) this->hParent;\r
+       frm_main->tree_ctrl->Thaw();\r
+       frm_main->list_ctrl->Thaw();\r
+       frm_main->menubar->EnableTop(0, true);\r
+       frm_main->menubar->EnableTop(1, true);\r
+       frm_main->menubar->EnableTop(2, true);\r
+       frm_main->toolbar->Enable();\r
+\r
+       // 書庫を開く途中に中断した場合、書庫を閉じる処理を行う。\r
+       if (this->fOpen && this->fCancel)\r
+       {\r
+               wxCommandEvent e;\r
+               frm_main->OnArcClose(e);\r
+       }\r
+\r
+#ifdef __WINDOWS__\r
+       if (this->tlTaskbar != NULL)\r
+       {\r
+               this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_NOPROGRESS);\r
+               this->tlTaskbar->Release();\r
+       }\r
+#endif\r
+       ((MainFrame *) this->hParent)->gFrame->Show(false);\r
        g_procDlg = NULL;\r
 }\r
 \r
@@ -57,6 +84,12 @@ END_EVENT_TABLE()
 \r
 void ProcessDialog::OnInit(wxInitDialogEvent &)\r
 {\r
+       if (this->nOverwriteMode == wxID_OK)\r
+       {\r
+               // 2回目以降は何もせず終了。\r
+               return;\r
+       }\r
+\r
        // XRCと結びつけ。\r
        this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);\r
        this->ebSource          = XRCCTRL(* this, "ebSource",     wxTextCtrl);\r
@@ -64,10 +97,41 @@ void ProcessDialog::OnInit(wxInitDialogEvent &)
        this->gArchive          = XRCCTRL(* this, "gArchive",     wxGauge);\r
        this->fCancel           = false;\r
        this->nOverwriteMode    = wxID_OK;\r
-       this->Update();\r
-       g_procDlg = this;\r
-\r
        ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("dlg_process.xrc"));\r
+\r
+       // コールバックを送信。\r
+       TPI_PROCESSINFO piInfo;\r
+       piInfo.eMessage = TPI_MESSAGE_STATUS;\r
+       piInfo.eStatus = 0x1000;\r
+       piInfo.fiInfo.fnFileName = ((MainFrame *) this->hParent)->fnArchive;\r
+       piInfo.fiInfo.nUnpackedSize = this->nFileCount;\r
+       this->CallbackProc(TPI_NOTIFY_COMMON, & piInfo);\r
+\r
+       if (((MainFrame *) this->hParent)->conf.ReadId(CONF_PROCESS_DLG, false))\r
+       {\r
+               // 旧来の進捗ダイアログを表示。\r
+               // ここでOnInitが呼ばれるので、OnInitの最初で無効化している。\r
+               this->Show();\r
+       }\r
+\r
+       // ウインドウの機能を無効化。\r
+       MainFrame * frm_main = (MainFrame *) this->hParent;\r
+       frm_main->tree_ctrl->Freeze();\r
+       frm_main->list_ctrl->Freeze();\r
+       frm_main->menubar->EnableTop(0, false);\r
+       frm_main->menubar->EnableTop(1, false);\r
+       frm_main->menubar->EnableTop(2, false);\r
+       frm_main->toolbar->Enable(false);\r
+#ifdef __WINDOWS__\r
+       // タスクバー。\r
+       this->hTBWnd = this->hParent->GetHandle();\r
+\r
+       ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void **) & this->tlTaskbar);\r
+       if (this->tlTaskbar != NULL)\r
+       {\r
+               this->tlTaskbar->HrInit();\r
+       }\r
+#endif\r
 }\r
 \r
 void ProcessDialog::OnClose(wxCloseEvent & e)\r
@@ -87,7 +151,7 @@ int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
        }\r
 \r
        TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
-       if (piInfo == NULL || ! this->IsShown())\r
+       if (piInfo == NULL)\r
        {\r
                return TPI_CALLBACK_CONTINUE;\r
        }\r
@@ -96,81 +160,120 @@ int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
        {\r
        case TPI_MESSAGE_STATUS:\r
        {\r
-               static int s_nGaugeCounter = 0, s_nInterval = 0;\r
+               static int s_nProcess;\r
+#ifdef __WINDOWS__\r
+               static int s_nFileCount;\r
+#endif\r
+               static wxStopWatch sw;\r
                switch (piInfo->eStatus)\r
                {\r
                case TPI_STATUS_OPENARCHIVE:\r
                        this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+                       sw.Start();\r
                        break;\r
                case TPI_STATUS_BEGINPROCESS:\r
-                       // 小さなファイルなら表示しない。\r
                        if (piInfo->fiInfo.nUnpackedSize > 10000)\r
                        {\r
-                               this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
-                               this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
                                this->gFile->SetRange(piInfo->fiInfo.nUnpackedSize);\r
-                               this->gFile->SetValue(0);\r
-                               ::wxSafeYield(this, true);\r
                        }\r
-                       break;\r
                case TPI_STATUS_INPROCESS:\r
-                       if (piInfo->fiInfo.nUnpackedSize > 10000)\r
+                       if (sw.Time() > 500)\r
+                       {\r
+                               if (this->IsShownOnScreen())\r
+                               {\r
+                                       sw.Start();\r
+                                       this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+                                       this->ebTarget->ChangeValue(piInfo->fnDestination.GetFullPath());\r
+                                       if (piInfo->fiInfo.nUnpackedSize > 10000)\r
+                                       {\r
+                                               this->gFile->SetValue(piInfo->nProcessedSize);\r
+                                       }\r
+                                       this->gArchive->SetValue(s_nProcess);\r
+                                       this->Update();\r
+                                       ::wxSafeYield(this, true);\r
+                               }\r
+                               else\r
+                               {\r
+                                       ::wxSafeYield(this->hParent, true);\r
+                               }\r
+                               ((MainFrame *) this->hParent)->gFrame->SetValue(s_nProcess);\r
+                       }\r
+#ifdef __WINDOWS__\r
+                       if (this->tlTaskbar != NULL)\r
                        {\r
-                               this->gFile->SetValue(piInfo->nProcessedSize);\r
-                               ::wxSafeYield(this, true);\r
+                               this->tlTaskbar->SetProgressValue(this->hTBWnd, s_nProcess, s_nFileCount);\r
                        }\r
+#endif\r
                        break;\r
                case TPI_STATUS_ENDPROCESS:\r
-                       if (s_nGaugeCounter++ > s_nInterval)\r
-                       {\r
-                               this->gArchive->SetValue(this->gArchive->GetValue() + s_nInterval);\r
-                               ::wxSafeYield(this, true);\r
-                               s_nGaugeCounter = 0;\r
-                       }\r
+                       s_nProcess++;\r
                        break;\r
-               // 書庫ロード時用の独自仕様。\r
-               case 0x1000:\r
+               // Lycheeの独自仕様。\r
+               case 0x1000: // 初期設定。\r
                        this->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
-                       this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);\r
-                       this->gArchive->SetValue(0);\r
                        this->Update();\r
-                       s_nInterval = piInfo->fiInfo.nUnpackedSize / 10;\r
+                       ((MainFrame *) this->hParent)->gFrame->Show();\r
+               case 0x1001: // 閲覧時は最初にファイル数が分からないので、ここで設定。\r
+                       this->gArchive->SetRange(piInfo->fiInfo.nUnpackedSize);\r
+                       ((MainFrame *) this->hParent)->gFrame->SetRange(piInfo->fiInfo.nUnpackedSize);\r
+                       s_nProcess = 0;\r
+#ifdef __WINDOWS__\r
+                       s_nFileCount = piInfo->fiInfo.nUnpackedSize;\r
+#endif\r
+                       sw.Start();\r
+                       if (piInfo->eStatus == 0x1001)\r
+                       {\r
+                               this->fOpen = true;\r
+                       }\r
                        break;\r
-               case 0x1001:\r
-                       if (piInfo->fiInfo.nUnpackedSize > 10000)\r
+               case 0x1002: // 各ファイルの処理を開始。\r
+                       if (sw.Time() > 500)\r
                        {\r
-                               this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+                               if (this->IsShownOnScreen())\r
+                               {\r
+                                       sw.Start();\r
+                                       this->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
+                                       this->gArchive->SetValue(piInfo->nProcessedSize);\r
+                                       this->Update();\r
+                                       ::wxSafeYield(this, true);\r
+                               }\r
+                               ::wxSafeYield(this->hParent, true);\r
                        }\r
-                       if (s_nGaugeCounter++ > s_nInterval)\r
+                       ((MainFrame *) this->hParent)->gFrame->SetValue(piInfo->nProcessedSize);\r
+#ifdef __WINDOWS__\r
+                       if (this->tlTaskbar != NULL)\r
                        {\r
-                               this->gArchive->SetValue(piInfo->nProcessedSize);\r
-                               ::wxSafeYield(this, true);\r
-                               s_nGaugeCounter = 0;\r
+                               this->tlTaskbar->SetProgressValue(this->hTBWnd, piInfo->nProcessedSize, s_nFileCount);\r
                        }\r
+#endif\r
                        break;\r
                }\r
                break;\r
        }\r
        case TPI_MESSAGE_ASK:\r
        {\r
+#ifdef __WINDOWS__\r
+               if (this->tlTaskbar != NULL)\r
+               {\r
+                       this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_PAUSED);\r
+               }\r
+#endif\r
                switch (piInfo->eStatus)\r
                {\r
                case TPI_PARAM_PASSWORD:\r
                {\r
-                       static wxFileName fnFormer;\r
-                       static wxString szFormer;\r
-                       if (piInfo->fiInfo.fnFileName == fnFormer)\r
+                       if (piInfo->fiInfo.fnFileName == fnFormer || this->szPassword.IsEmpty())\r
                        {\r
                                piInfo->szParam = ::wxGetPasswordFromUser(_("Password for:\n") + piInfo->fiInfo.fnFileName.GetFullPath(), wxT("Lychee"), wxEmptyString, this);\r
                                if (piInfo->szParam.IsEmpty())\r
                                {\r
                                        this->fCancel = true;\r
                                }\r
-                               szFormer = piInfo->szParam;\r
+                               this->szPassword = piInfo->szParam;\r
                        }\r
                        else\r
                        {\r
-                               piInfo->szParam = szFormer;\r
+                               piInfo->szParam = this->szPassword;\r
                                fnFormer = piInfo->fiInfo.fnFileName;\r
                        }\r
                        break;\r
@@ -194,7 +297,7 @@ int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
                                {\r
                                        OverwriteDialog odDlg;\r
                                        odDlg.fnExist = & piInfo->fnDestination;\r
-                                       odDlg.tmWrite = & piInfo->fiInfo.tmModified;\r
+                                       odDlg.tmWrite = & piInfo->fiInfo.tmModify;\r
                                        odDlg.nWriteSize = piInfo->fiInfo.nUnpackedSize;\r
 \r
                                        this->nOverwriteMode = odDlg.ShowModal();\r
@@ -238,6 +341,12 @@ int ProcessDialog::CallbackProc(unsigned int _uMsg, void * _pStructure)
                default:\r
                        return TPI_CALLBACK_UNSUPPORTED;\r
                }\r
+#ifdef __WINDOWS__\r
+               if (this->tlTaskbar != NULL)\r
+               {\r
+                       this->tlTaskbar->SetProgressState(this->hTBWnd, TBPF_NORMAL);\r
+               }\r
+#endif\r
                break;\r
        }\r
        default:\r