BatchFrame.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include "BatchFrame.h"
00028 #include <wx/stdpaths.h>
00029 #include "PTBatcherGUI.h"
00030 #include "FindPanoDialog.h"
00031 #include "FailedProjectsDialog.h"
00032 #ifdef __WXMSW__
00033 #include <powrprof.h>
00034 #pragma comment(lib, "PowrProf.lib")
00035 #if wxCHECK_VERSION(3,1,0)
00036 #include <wx/taskbarbutton.h>
00037 #endif
00038 #endif
00039 
00040 /* file drag and drop handler method */
00041 bool BatchDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
00042 {
00043     BatchFrame* MyBatchFrame = wxGetApp().GetFrame();
00044     if (!MyBatchFrame)
00045     {
00046         return false;
00047     }
00048     if(filenames.GetCount()==0)
00049     {
00050         return false;
00051     }
00052     for(unsigned int i=0; i< filenames.GetCount(); i++)
00053     {
00054         wxFileName file(filenames[i]);
00055         if(file.HasExt())
00056         {
00057             if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
00058                     file.GetExt().CmpNoCase(wxT("ptp")) == 0 ||
00059                     file.GetExt().CmpNoCase(wxT("pts")) == 0 )
00060             {
00061                 if(file.FileExists())
00062                 {
00063                     MyBatchFrame->AddToList(filenames[i]);
00064                 }
00065             };
00066         }
00067         else
00068         {
00069             if(file.DirExists())
00070             {
00071                 MyBatchFrame->AddDirToList(filenames[i]);
00072             }
00073         };
00074     };
00075     return true;
00076 };
00077 
00078 enum
00079 {
00080     wxEVT_COMMAND_RELOAD_BATCH,
00081     wxEVT_COMMAND_UPDATE_LISTBOX
00082 };
00083 
00084 BEGIN_EVENT_TABLE(BatchFrame, wxFrame)
00085     EVT_TOOL(XRCID("tool_clear"),BatchFrame::OnButtonClear)
00086     EVT_TOOL(XRCID("tool_open"),BatchFrame::OnButtonOpenBatch)
00087     EVT_TOOL(XRCID("tool_save"),BatchFrame::OnButtonSaveBatch)
00088     EVT_TOOL(XRCID("tool_start"),BatchFrame::OnButtonRunBatch)
00089     EVT_TOOL(XRCID("tool_skip"),BatchFrame::OnButtonSkip)
00090     EVT_TOOL(XRCID("tool_pause"),BatchFrame::OnButtonPause)
00091     EVT_TOOL(XRCID("tool_cancel"),BatchFrame::OnButtonCancel)
00092     EVT_TOOL(XRCID("tool_add"),BatchFrame::OnButtonAddToStitchingQueue)
00093     EVT_TOOL(XRCID("tool_remove"),BatchFrame::OnButtonRemoveFromList)
00094     EVT_TOOL(XRCID("tool_adddir"),BatchFrame::OnButtonAddDir)
00095     EVT_MENU(XRCID("menu_add"),BatchFrame::OnButtonAddToStitchingQueue)
00096     EVT_MENU(XRCID("menu_add_assistant"),BatchFrame::OnButtonAddToAssistantQueue)
00097     EVT_MENU(XRCID("menu_remove"),BatchFrame::OnButtonRemoveFromList)
00098     EVT_MENU(XRCID("menu_adddir"),BatchFrame::OnButtonAddDir)
00099     EVT_MENU(XRCID("menu_searchpano"), BatchFrame::OnButtonSearchPano)
00100     EVT_MENU(XRCID("menu_open"),BatchFrame::OnButtonOpenBatch)
00101     EVT_MENU(XRCID("menu_save"),BatchFrame::OnButtonSaveBatch)
00102     EVT_MENU(XRCID("menu_clear"),BatchFrame::OnButtonClear)
00103     EVT_MENU(XRCID("menu_tray"), BatchFrame::OnMinimizeTrayMenu)
00104     EVT_MENU(XRCID("menu_exit"),BatchFrame::OnUserExit)
00105     EVT_MENU(XRCID("menu_help"),BatchFrame::OnButtonHelp)
00106     EVT_BUTTON(XRCID("button_addcommand"),BatchFrame::OnButtonAddCommand)
00107     EVT_BUTTON(XRCID("button_remove"),BatchFrame::OnButtonRemoveComplete)
00108     EVT_BUTTON(XRCID("button_prefix"),BatchFrame::OnButtonChangePrefix)
00109     EVT_BUTTON(XRCID("button_reset"),BatchFrame::OnButtonReset)
00110     EVT_BUTTON(XRCID("button_resetall"),BatchFrame::OnButtonResetAll)
00111     EVT_BUTTON(XRCID("button_edit"),BatchFrame::OnButtonOpenWithHugin)
00112     EVT_BUTTON(XRCID("button_move_up"),BatchFrame::OnButtonMoveUp)
00113     EVT_BUTTON(XRCID("button_move_down"),BatchFrame::OnButtonMoveDown)
00114     EVT_CHECKBOX(XRCID("cb_overwrite"), BatchFrame::OnCheckOverwrite)
00115     EVT_CHOICE(XRCID("choice_end"), BatchFrame::OnChoiceEnd)
00116     EVT_CHECKBOX(XRCID("cb_verbose"), BatchFrame::OnCheckVerbose)
00117     EVT_CHECKBOX(XRCID("cb_autoremove"), BatchFrame::OnCheckAutoRemove)
00118     EVT_CHECKBOX(XRCID("cb_autostitch"), BatchFrame::OnCheckAutoStitch)
00119     EVT_CHECKBOX(XRCID("cb_savelog"), BatchFrame::OnCheckSaveLog)
00120     EVT_END_PROCESS(-1, BatchFrame::OnProcessTerminate)
00121     EVT_CLOSE(BatchFrame::OnClose)
00122     EVT_MENU(wxEVT_COMMAND_RELOAD_BATCH, BatchFrame::OnReloadBatch)
00123     EVT_MENU(wxEVT_COMMAND_UPDATE_LISTBOX, BatchFrame::OnUpdateListBox)
00124     EVT_COMMAND(wxID_ANY, EVT_BATCH_FAILED, BatchFrame::OnBatchFailed)
00125     EVT_COMMAND(wxID_ANY, EVT_INFORMATION, BatchFrame::OnBatchInformation)
00126     EVT_COMMAND(wxID_ANY, EVT_UPDATE_PARENT, BatchFrame::OnRefillListBox)
00127     EVT_COMMAND(wxID_ANY, EVT_QUEUE_PROGRESS, BatchFrame::OnProgress)
00128     EVT_ICONIZE(BatchFrame::OnMinimize)
00129 END_EVENT_TABLE()
00130 
00131 BatchFrame::BatchFrame(wxLocale* locale, wxString xrc)
00132 {
00133     this->SetLocaleAndXRC(locale,xrc);
00134     m_cancelled = false;
00135     m_closeThread = false;
00136 
00137     //load xrc resources
00138     wxXmlResource::Get()->LoadFrame(this, (wxWindow* )NULL, wxT("batch_frame"));
00139     // load our menu bar
00140 #ifdef __WXMAC__
00141     wxApp::s_macExitMenuItemId = XRCID("menu_exit");
00142     wxApp::s_macHelpMenuTitleName = _("&Help");
00143 #endif
00144     SetMenuBar(wxXmlResource::Get()->LoadMenuBar(this, wxT("batch_menu")));
00145 
00146     // create tool bar
00147     SetToolBar(wxXmlResource::Get()->LoadToolBar(this, wxT("batch_toolbar")));
00148 
00149     int widths[2] = { -1, 150 };
00150     CreateStatusBar(2);
00151     SetStatusWidths(2, widths);
00152     SetStatusText(_("Not doing much..."));
00153 
00154     // set the minimize icon
00155 #ifdef __WXMSW__
00156     m_iconNormal = wxIcon(m_xrcPrefix + wxT("data/ptbatcher.ico"), wxBITMAP_TYPE_ICO);
00157     m_iconRunning = wxIcon(m_xrcPrefix + wxT("data/ptbatcher_running.ico"), wxBITMAP_TYPE_ICO);
00158     m_iconPaused = wxIcon(m_xrcPrefix + wxT("data/ptbatcher_pause.ico"), wxBITMAP_TYPE_ICO);
00159 #else
00160     m_iconNormal = wxIcon(m_xrcPrefix + wxT("data/ptbatcher.png"), wxBITMAP_TYPE_PNG);
00161     m_iconRunning = wxIcon(m_xrcPrefix + wxT("data/ptbatcher_running.png"), wxBITMAP_TYPE_PNG);
00162     m_iconPaused = wxIcon(m_xrcPrefix + wxT("data/ptbatcher_pause.png"), wxBITMAP_TYPE_PNG);
00163 #endif
00164     SetIcon(m_iconNormal);
00165 
00166     m_batch = new Batch(this);
00167     if(wxGetKeyState(WXK_COMMAND))
00168     {
00169 #ifdef __WXMAC__
00170         wxString text(_("You have pressed the Command key."));
00171 #else
00172         wxString text(_("You have pressed the Control key."));
00173 #endif
00174         text.Append(wxT("\n"));
00175         text.Append(_("Should the loading of the batch queue be skipped?"));
00176         if(wxMessageBox(text, 
00177 #ifdef __WXMSW__
00178             wxT("PTBatcherGUI"),
00179 #else
00180             wxEmptyString,
00181 #endif
00182             wxYES_NO | wxICON_EXCLAMATION, NULL)==wxNO)
00183         {
00184             m_batch->LoadTemp();
00185         };
00186     }
00187     else
00188     {
00189         m_batch->LoadTemp();
00190     };
00191     if(m_batch->GetLastFile().length()==0)
00192     {
00193         m_batch->SaveTemp();
00194     }
00195     projListBox = XRCCTRL(*this,"project_listbox",ProjectListBox);
00196     // fill at end list box, check which options are available
00197     m_endChoice = XRCCTRL(*this, "choice_end", wxChoice);
00198     m_endChoice->Clear();
00199     m_endChoice->Append(_("Do nothing"), (void*)Batch::DO_NOTHING);
00200     m_endChoice->Append(_("Close PTBatcherGUI"), (void*)Batch::CLOSE_PTBATCHERGUI);
00201 #if !defined __WXMAC__ && !defined __WXOSX_COCOA__
00202     // there is no wxShutdown for wxMac
00203     m_endChoice->Append(_("Shutdown computer"), (void*)Batch::SHUTDOWN);
00204 #endif
00205 #ifdef __WXMSW__
00206     SYSTEM_POWER_CAPABILITIES pwrCap;
00207     if (GetPwrCapabilities(&pwrCap))
00208     {
00209         if (pwrCap.SystemS3)
00210         {
00211             m_endChoice->Append(_("Suspend computer"), (void*)Batch::SUSPEND);
00212         };
00213         if (pwrCap.SystemS4 && pwrCap.HiberFilePresent)
00214         {
00215             m_endChoice->Append(_("Hibernate computer"), (void*)Batch::HIBERNATE);
00216         };
00217     };
00218 #endif
00219 
00220     this->wxThreadHelper::CreateThread();
00221     this->GetThread()->Run();
00222     //TO-DO: include a batch or project progress gauge?
00223     projListBox->Fill(m_batch);
00224     SetDropTarget(new BatchDropTarget());
00225 
00226     m_tray = NULL;
00227     if (wxTaskBarIcon::IsAvailable())
00228     {
00229         // minimize to tray is by default disabled
00230         // activate only if task bar icon is available
00231         GetMenuBar()->Enable(XRCID("menu_tray"), true);
00232         bool minTray;
00233         // tray icon is disabled by default 
00234         wxConfigBase::Get()->Read(wxT("/BatchFrame/minimizeTray"), &minTray, false);
00235         GetMenuBar()->Check(XRCID("menu_tray"), minTray);
00236         UpdateTrayIcon(minTray);
00237     }
00238 
00239     UpdateTaskBarProgressBar();
00240 }
00241 
00242 void* BatchFrame::Entry()
00243 {
00244     //we constantly poll the working dir for new files and wait a bit on each loop
00245     while(!m_closeThread)
00246     {
00247         //don't access GUI directly in this function (function is running as separate thread)
00248         //check, if ptbt file was changed
00249         wxFileName aFile(m_batch->GetLastFile());
00250         if(!aFile.FileExists())
00251         {
00252             wxQueueEvent(this, new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_RELOAD_BATCH));
00253         }
00254         else
00255         {
00256             wxDateTime create;
00257             aFile.GetTimes(NULL,NULL,&create);
00258             if(create.IsLaterThan(m_batch->GetLastFileDate()))
00259             {
00260                 wxQueueEvent(this, new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_RELOAD_BATCH));
00261             };
00262         };
00263         //update project list box
00264         wxQueueEvent(this, new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_UPDATE_LISTBOX));
00265         GetThread()->Sleep(1000);
00266     }
00267     return 0;
00268 }
00269 
00270 wxStatusBar* BatchFrame::OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name)
00271 {
00272     m_progStatusBar = new ProgressStatusBar(this, id, style, name);
00273     m_progStatusBar->SetFieldsCount(number);
00274     return m_progStatusBar;
00275 }
00276 
00277 bool BatchFrame::IsRunning()
00278 {
00279     return m_batch->IsRunning();
00280 };
00281 
00282 bool BatchFrame::IsPaused()
00283 {
00284     return m_batch->IsPaused();
00285 };
00286 
00287 void BatchFrame::OnUpdateListBox(wxCommandEvent& event)
00288 {
00289     wxFileName tempFile;
00290     bool change = false;
00291     for(int i = 0; i< m_batch->GetProjectCount(); i++)
00292     {
00293         if(m_batch->GetProject(i)->id >= 0 && m_batch->GetStatus(i)!=Project::FINISHED)
00294         {
00295             tempFile.Assign(m_batch->GetProject(i)->path);
00296             if(tempFile.FileExists())
00297             {
00298                 wxDateTime modify;
00299                 modify=tempFile.GetModificationTime();
00300                 if(m_batch->GetProject(i)->skip)
00301                 {
00302                     change = true;
00303                     m_batch->GetProject(i)->skip = false;
00304                     m_batch->SetStatus(i,Project::WAITING);
00305                     projListBox->ReloadProject(projListBox->GetIndex(m_batch->GetProject(i)->id),m_batch->GetProject(i));
00306                 }
00307                 else if(!modify.IsEqualTo(m_batch->GetProject(i)->modDate))
00308                 {
00309                     change = true;
00310                     m_batch->GetProject(i)->modDate = modify;
00311                     m_batch->GetProject(i)->ResetOptions();
00312                     if(m_batch->GetProject(i)->target==Project::STITCHING)
00313                     {
00314                         m_batch->SetStatus(i,Project::WAITING);
00315                     };
00316                     projListBox->ReloadProject(projListBox->GetIndex(m_batch->GetProject(i)->id),m_batch->GetProject(i));
00317                 }
00318             }
00319             else
00320             {
00321                 if(m_batch->GetStatus(i) != Project::MISSING)
00322                 {
00323                     change = true;
00324                     m_batch->GetProject(i)->skip = true;
00325                     m_batch->SetStatus(i,Project::MISSING);
00326                     projListBox->SetMissing(projListBox->GetIndex(m_batch->GetProject(i)->id));
00327                 }
00328             }
00329         }
00330         if(projListBox->UpdateStatus(i,m_batch->GetProject(i)))
00331         {
00332             change = true;
00333         }
00334     }
00335     if(change)
00336     {
00337         m_batch->SaveTemp();
00338     }
00339 };
00340 
00341 void BatchFrame::OnReloadBatch(wxCommandEvent& event)
00342 {
00343     m_batch->ClearBatch();
00344     m_batch->LoadTemp();
00345     projListBox->DeleteAllItems();
00346     projListBox->Fill(m_batch);
00347     SetStatusText(wxT(""));
00348 };
00349 
00350 void BatchFrame::OnUserExit(wxCommandEvent& event)
00351 {
00352     Close(true);
00353 };
00354 
00355 void BatchFrame::OnButtonAddCommand(wxCommandEvent& event)
00356 {
00357     wxTextEntryDialog dlg(this,_("Please enter the command-line application to execute:"),_("Enter application"));
00358     wxTheApp->SetEvtHandlerEnabled(false);
00359     if(dlg.ShowModal() == wxID_OK)
00360     {
00361         wxString line = dlg.GetValue();
00362         m_batch->AddAppToBatch(line);
00363         //SetStatusText(_T("Added application"));
00364         projListBox->AppendProject(m_batch->GetProject(m_batch->GetProjectCount()-1));
00365         m_batch->SaveTemp();
00366     }
00367     wxTheApp->SetEvtHandlerEnabled(true);
00368 }
00369 
00370 void BatchFrame::OnButtonAddDir(wxCommandEvent& event)
00371 {
00372     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/actualPath"),wxT(""));
00373     wxDirDialog dlg(this,
00374                     _("Specify a directory to search for projects in"),
00375                     defaultdir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
00376     dlg.SetPath(wxConfigBase::Get()->Read(wxT("/BatchFrame/actualPath"),wxT("")));
00377     if (dlg.ShowModal() == wxID_OK)
00378     {
00379         wxConfig::Get()->Write(wxT("/BatchFrame/actualPath"), dlg.GetPath());  // remember for later
00380         AddDirToList(dlg.GetPath());
00381     };
00382 }
00383 
00384 void BatchFrame::OnButtonSearchPano(wxCommandEvent& e)
00385 {
00386     FindPanoDialog findpano_dlg(this,m_xrcPrefix);
00387     findpano_dlg.ShowModal();
00388 };
00389 
00390 void BatchFrame::OnButtonAddToStitchingQueue(wxCommandEvent& event)
00391 {
00392     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/actualPath"),wxT(""));
00393     wxFileDialog dlg(0,
00394                      _("Specify project source file(s)"),
00395                      defaultdir, wxT(""),
00396                      _("Project files (*.pto)|*.pto|All files (*)|*"),
00397                      wxFD_OPEN | wxFD_MULTIPLE, wxDefaultPosition);
00398     dlg.SetDirectory(defaultdir);
00399 
00400     if (dlg.ShowModal() == wxID_OK)
00401     {
00402         wxArrayString paths;
00403         dlg.GetPaths(paths);
00404 #ifdef __WXGTK__
00405         //workaround a bug in GTK, see https://bugzilla.redhat.com/show_bug.cgi?id=849692 and http://trac.wxwidgets.org/ticket/14525
00406         wxConfig::Get()->Write(wxT("/BatchFrame/actualPath"), wxPathOnly(paths[0]));  // remember for later
00407 #else
00408         wxConfig::Get()->Write(wxT("/BatchFrame/actualPath"), dlg.GetDirectory());  // remember for later
00409 #endif
00410         for(unsigned int i=0; i<paths.GetCount(); i++)
00411         {
00412             AddToList(paths.Item(i));
00413         }
00414         m_batch->SaveTemp();
00415     };
00416 }
00417 
00418 void BatchFrame::OnButtonAddToAssistantQueue(wxCommandEvent& event)
00419 {
00420     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/actualPath"),wxT(""));
00421     wxFileDialog dlg(0,
00422                      _("Specify project source file(s)"),
00423                      defaultdir, wxT(""),
00424                      _("Project files (*.pto)|*.pto|All files (*)|*"),
00425                      wxFD_OPEN | wxFD_MULTIPLE, wxDefaultPosition);
00426     dlg.SetDirectory(defaultdir);
00427 
00428     if (dlg.ShowModal() == wxID_OK)
00429     {
00430         wxArrayString paths;
00431         dlg.GetPaths(paths);
00432 #ifdef __WXGTK__
00433         //workaround a bug in GTK, see https://bugzilla.redhat.com/show_bug.cgi?id=849692 and http://trac.wxwidgets.org/ticket/14525
00434         wxConfig::Get()->Write(wxT("/BatchFrame/actualPath"), wxPathOnly(paths[0]));  // remember for later
00435 #else
00436         wxConfig::Get()->Write(wxT("/BatchFrame/actualPath"), dlg.GetDirectory());  // remember for later
00437 #endif
00438 
00439         for(unsigned int i=0; i<paths.GetCount(); i++)
00440         {
00441             AddToList(paths.Item(i),Project::DETECTING);
00442         }
00443         m_batch->SaveTemp();
00444     };
00445 }
00446 
00447 void BatchFrame::AddDirToList(wxString aDir)
00448 {
00449     //we traverse all subdirectories of chosen path
00450     DirTraverser traverser;
00451     wxDir dir(aDir);
00452     dir.Traverse(traverser);
00453     wxArrayString projects = traverser.GetProjectFiles();
00454     for(unsigned int i=0; i<projects.GetCount(); i++)
00455     {
00456         m_batch->AddProjectToBatch(projects.Item(i));
00457         Project* proj=m_batch->GetProject(m_batch->GetProjectCount()-1);
00458         if(!proj->isAligned)
00459         {
00460             proj->target=Project::DETECTING;
00461         };
00462         projListBox->AppendProject(proj);
00463     };
00464     m_batch->SaveTemp();
00465     SetStatusText(wxString::Format(_("Added projects from dir %s"), aDir.c_str()));
00466 };
00467 
00468 void BatchFrame::AddToList(wxString aFile,Project::Target target)
00469 {
00470     wxFileName name(aFile);
00471     m_batch->AddProjectToBatch(aFile,wxT(""),target);
00472     wxString s;
00473     switch(target)
00474     {
00475         case Project::STITCHING:
00476             s=wxString::Format(_("Add project %s to stitching queue."),aFile.c_str());
00477             break;
00478         case Project::DETECTING:
00479             s=wxString::Format(_("Add project %s to assistant queue."),aFile.c_str());
00480             break;
00481     };
00482     SetStatusInformation(s);
00483     projListBox->AppendProject(m_batch->GetProject(m_batch->GetProjectCount()-1));
00484     m_batch->SaveTemp();
00485 }
00486 
00487 
00488 void BatchFrame::OnButtonCancel(wxCommandEvent& event)
00489 {
00490     GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00491     m_cancelled = true;
00492     m_batch->CancelBatch();
00493     SetStatusInformation(_("Batch stopped"));
00494     if (m_tray)
00495     {
00496         m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
00497     };
00498 }
00499 
00500 void BatchFrame::OnButtonChangePrefix(wxCommandEvent& event)
00501 {
00502     int selIndex = projListBox->GetSelectedIndex();
00503     if(selIndex != -1)
00504     {
00505         if(projListBox->GetSelectedProjectTarget()==Project::STITCHING)
00506         {
00507             wxFileName prefix(projListBox->GetSelectedProjectPrefix());
00508             wxFileDialog dlg(0,_("Specify output prefix for project ")+projListBox->GetSelectedProject(),
00509                              prefix.GetPath(),
00510                              prefix.GetFullName(), wxT(""),
00511                              wxFD_SAVE, wxDefaultPosition);
00512             if (dlg.ShowModal() == wxID_OK)
00513             {
00514                 while(containsInvalidCharacters(dlg.GetPath()))
00515                 {
00516                     wxArrayString list;
00517                     list.Add(dlg.GetPath());
00518                     ShowFilenameWarning(this, list);
00519                     if(dlg.ShowModal()!=wxID_OK)
00520                     {
00521                         return;
00522                     }
00523                 };
00524                 wxFileName prefix(dlg.GetPath());
00525                 while (!prefix.IsDirWritable())
00526                 {
00527                     wxMessageBox(wxString::Format(_("You have no permissions to write in folder \"%s\".\nPlease select another folder for the final output."), prefix.GetPath().c_str()),
00528 #ifdef __WXMSW__
00529                         wxT("PTBatcherGUI"),
00530 #else
00531                         wxT(""),
00532 #endif
00533                         wxOK | wxICON_INFORMATION);
00534                     if (dlg.ShowModal() != wxID_OK)
00535                     {
00536                         return;
00537                     };
00538                     prefix = dlg.GetPath();
00539                 };
00540 
00541                 wxString outname(dlg.GetPath());
00542                 ChangePrefix(selIndex,outname);
00543                 //SetStatusText(_T("Changed prefix for "+projListBox->GetSelectedProject()));
00544                 m_batch->SaveTemp();
00545             }
00546         }
00547         else
00548         {
00549             SetStatusText(_("The prefix of an assistant target cannot be changed."));
00550             wxBell();
00551         };
00552     }
00553     else
00554     {
00555         SetStatusText(_("Please select a project"));
00556     }
00557 }
00558 
00559 void BatchFrame::ChangePrefix(int index,wxString newPrefix)
00560 {
00561     int i;
00562     if(index!=-1)
00563     {
00564         i=index;
00565     }
00566     else
00567     {
00568         i=m_batch->GetProjectCount()-1;
00569     }
00570     m_batch->ChangePrefix(i,newPrefix);
00571     projListBox->ChangePrefix(i,newPrefix);
00572 }
00573 
00574 void BatchFrame::OnButtonClear(wxCommandEvent& event)
00575 {
00576     int returnCode = m_batch->ClearBatch();
00577     if(returnCode == 0)
00578     {
00579         projListBox->DeleteAllItems();
00580     }
00581     else if(returnCode == 2)
00582     {
00583         m_cancelled = true;
00584         projListBox->DeleteAllItems();
00585         if(GetToolBar()->GetToolState(XRCID("tool_pause")))
00586         {
00587             GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00588         }
00589     }
00590     m_batch->SaveTemp();
00591 }
00592 
00593 void BatchFrame::OnButtonHelp(wxCommandEvent& event)
00594 {
00595     DEBUG_TRACE("");
00596 #if defined __wxMSW__ && !(wxCHECK_VERSION(3,1,1))
00597     // wxWidgets 3.x has a bug, that prevents DisplaySection to work on Win8/10 64 bit
00598     // see: http://trac.wxwidgets.org/ticket/14888
00599     // so using DisplayContents() and our own implementation of HuginCHMHelpController
00600     GetHelpController().DisplayHelpPage(wxT("Hugin_Batch_Processor.html"));
00601 #else
00602     GetHelpController().DisplaySection(wxT("Hugin_Batch_Processor.html"));
00603 #endif
00604 }
00605 
00606 void BatchFrame::OnButtonMoveDown(wxCommandEvent& event)
00607 {
00608     SwapProject(projListBox->GetSelectedIndex());
00609     m_batch->SaveTemp();
00610 }
00611 
00612 void BatchFrame::OnButtonMoveUp(wxCommandEvent& event)
00613 {
00614     SwapProject(projListBox->GetSelectedIndex()-1);
00615     m_batch->SaveTemp();
00616 }
00617 
00618 void BatchFrame::OnButtonOpenBatch(wxCommandEvent& event)
00619 {
00620     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/batchPath"),wxT(""));
00621     wxFileDialog dlg(0,
00622                      _("Specify batch file to open"),
00623                      defaultdir, wxT(""),
00624                      _("Batch files (*.ptb)|*.ptb;|All files (*)|*"),
00625                      wxFD_OPEN, wxDefaultPosition);
00626     if (dlg.ShowModal() == wxID_OK)
00627     {
00628         wxConfig::Get()->Write(wxT("/BatchFrame/batchPath"), dlg.GetDirectory());  // remember for later
00629         int clearCode = m_batch->LoadBatchFile(dlg.GetPath());
00630         //1 is error code for not clearing batch
00631         if(clearCode!=1)
00632         {
00633             /*if(clearCode==2) //we just cancelled the batch, so we need to try loading again
00634                 m_batch->LoadBatchFile(dlg.GetPath());*/
00635             projListBox->DeleteAllItems();
00636             projListBox->Fill(m_batch);
00637             m_batch->SaveTemp();
00638         }
00639     }
00640 }
00641 
00642 void BatchFrame::OnButtonOpenWithHugin(wxCommandEvent& event)
00643 {
00644     const wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
00645     if(projListBox->GetSelectedIndex()!=-1)
00646         if(projListBox->GetText(projListBox->GetSelectedIndex(),0).Cmp(_T(""))!=0)
00647 #ifdef __WXMAC__
00648             wxExecute(_T("open -b net.sourceforge.hugin.hugin \"" + projListBox->GetSelectedProject()+_T("\"")));
00649 #else
00650             wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR)+_T("hugin \"" + projListBox->GetSelectedProject()+_T("\" -notips")));
00651 #endif
00652         else
00653         {
00654             SetStatusText(_("Cannot open app in Hugin."));
00655         }
00656     else
00657     {
00658         //ask user if he/she wants to load an empty project
00659         wxMessageDialog message(this,_("No project selected. Open Hugin without project?"),
00660 #ifdef _WIN32
00661                                 _("PTBatcherGUI"),
00662 #else
00663                                 wxT(""),
00664 #endif
00665                                 wxYES_NO | wxICON_INFORMATION );
00666         if(message.ShowModal() == wxID_YES)
00667         {
00668 #ifdef __WXMAC__
00669             wxExecute(_T("open -b net.sourceforge.hugin.hugin"));
00670 #else
00671             wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR)+_T("hugin"));
00672 #endif
00673         }
00674     }
00675 }
00676 
00677 void BatchFrame::OnButtonPause(wxCommandEvent& event)
00678 {
00679     if(m_batch->GetRunningCount()>0)
00680     {
00681         if(!m_batch->IsPaused())
00682         {
00683             m_batch->PauseBatch();
00684             GetToolBar()->ToggleTool(XRCID("tool_pause"),true);
00685             SetStatusInformation(_("Batch paused"));
00686             if (m_tray)
00687             {
00688                 m_tray->SetIcon(m_iconPaused, _("Pausing processing Hugin's batch queue"));
00689             };
00690         }
00691         else
00692         {
00693             m_batch->PauseBatch();
00694             GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00695             SetStatusInformation(_("Continuing batch..."));
00696             if (m_tray)
00697             {
00698                 m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
00699             };
00700         }
00701     }
00702     else //if no projects are running, we deactivate the button
00703     {
00704         GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00705     }
00706     UpdateTaskBarProgressBar();
00707 }
00708 
00709 void BatchFrame::OnButtonRemoveComplete(wxCommandEvent& event)
00710 {
00711     bool removeErrors=false;
00712     if(!m_batch->NoErrors())
00713     {
00714         wxMessageDialog message(this,_("There are failed projects in the list.\nRemove them too?"),
00715 #ifdef _WIN32
00716                                 _("PTBatcherGUI"),
00717 #else
00718                                 wxT(""),
00719 #endif
00720                                 wxYES_NO | wxICON_INFORMATION );
00721         if(message.ShowModal()==wxID_YES)
00722         {
00723             removeErrors=true;
00724         }
00725     }
00726     for(int i=projListBox->GetItemCount()-1; i>=0; i--)
00727     {
00728         if(m_batch->GetStatus(i)==Project::FINISHED ||
00729                 (removeErrors && m_batch->GetStatus(i)==Project::FAILED))
00730         {
00731             projListBox->Deselect(i);
00732             projListBox->DeleteItem(i);
00733             m_batch->RemoveProjectAtIndex(i);
00734         }
00735     }
00736     m_batch->SaveTemp();
00737 }
00738 
00739 void BatchFrame::OnButtonRemoveFromList(wxCommandEvent& event)
00740 {
00741     int selIndex = projListBox->GetSelectedIndex();
00742     if(selIndex != -1)
00743     {
00744         if(m_batch->GetStatus(selIndex)==Project::RUNNING || m_batch->GetStatus(selIndex)==Project::PAUSED)
00745         {
00746             wxMessageDialog message(this, _("Cannot remove project in progress.\nDo you want to cancel it?"),
00747 #ifdef _WIN32
00748                                     _("PTBatcherGUI"),
00749 #else
00750                                     wxT(""),
00751 #endif
00752                                     wxYES_NO | wxICON_INFORMATION);
00753             if(message.ShowModal()==wxID_YES)
00754             {
00755                 OnButtonSkip(event);
00756             }
00757         }
00758         else
00759         {
00760             SetStatusText(wxString::Format(_("Removed project %s"), projListBox->GetSelectedProject().c_str()));
00761             projListBox->Deselect(selIndex);
00762             projListBox->DeleteItem(selIndex);
00763             m_batch->RemoveProjectAtIndex(selIndex);
00764             m_batch->SaveTemp();
00765         }
00766     }
00767     else
00768     {
00769         SetStatusText(_("Please select a project to remove"));
00770     }
00771 }
00772 
00773 
00774 void BatchFrame::OnButtonReset(wxCommandEvent& event)
00775 {
00776     int selIndex = projListBox->GetSelectedIndex();
00777     if(selIndex != -1)
00778     {
00779         if(m_batch->GetStatus(selIndex)==Project::RUNNING || m_batch->GetStatus(selIndex)==Project::PAUSED)
00780         {
00781             wxMessageDialog message(this, _("Cannot reset project in progress.\nDo you want to cancel it?"),
00782 #ifdef _WIN32
00783                                     _("PTBatcherGUI"),
00784 #else
00785                                     wxT(""),
00786 #endif
00787                                     wxYES_NO | wxICON_INFORMATION);
00788             if(message.ShowModal()==wxID_YES)
00789             {
00790                 OnButtonSkip(event);
00791             }
00792         }
00793         else
00794         {
00795             m_batch->SetStatus(selIndex,Project::WAITING);
00796             SetStatusText(wxString::Format(_("Reset project %s"), projListBox->GetSelectedProject().c_str()));
00797         }
00798     }
00799     else
00800     {
00801         SetStatusText(_("Please select a project to reset"));
00802     }
00803     m_batch->SaveTemp();
00804 }
00805 
00806 void BatchFrame::OnButtonResetAll(wxCommandEvent& event)
00807 {
00808     if(m_batch->GetRunningCount()!=0)
00809     {
00810         wxMessageDialog message(this, _("Cannot reset projects in progress.\nDo you want to cancel the batch?"),
00811 #ifdef _WIN32
00812                                 _("PTBatcherGUI"),
00813 #else
00814                                 wxT(""),
00815 #endif
00816                                 wxYES_NO | wxICON_INFORMATION);
00817         if(message.ShowModal()==wxID_YES)
00818         {
00819             OnButtonCancel(event);
00820         }
00821     }
00822     else
00823     {
00824         for(int i=projListBox->GetItemCount()-1; i>=0; i--)
00825         {
00826             m_batch->SetStatus(i,Project::WAITING);
00827         }
00828     }
00829     m_batch->SaveTemp();
00830 }
00831 
00832 void BatchFrame::OnButtonRunBatch(wxCommandEvent& event)
00833 {
00834     if(m_batch->IsPaused())
00835     {
00836         //m_batch->paused = false;
00837         OnButtonPause(event);
00838     }
00839     else
00840     {
00841         RunBatch();
00842     }
00843 }
00844 
00845 void BatchFrame::OnButtonSaveBatch(wxCommandEvent& event)
00846 {
00847     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/batchPath"),wxT(""));
00848     wxFileDialog dlg(0,
00849                      _("Specify batch file to save"),
00850                      defaultdir, wxT(""),
00851                      _("Batch file (*.ptb)|*.ptb;|All files (*)|*"),
00852                      wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
00853     if (dlg.ShowModal() == wxID_OK)
00854     {
00855         wxConfig::Get()->Write(wxT("/BatchFrame/batchPath"), dlg.GetDirectory());  // remember for later
00856         m_batch->SaveBatchFile(dlg.GetPath());
00857     }
00858 }
00859 
00860 void BatchFrame::OnButtonSkip(wxCommandEvent& event)
00861 {
00862     int selIndex = projListBox->GetSelectedIndex();
00863     if(selIndex != -1)
00864     {
00865         if(m_batch->GetStatus(selIndex)==Project::RUNNING
00866                 ||m_batch->GetStatus(selIndex)==Project::PAUSED)
00867         {
00868             if(m_batch->GetStatus(selIndex)==Project::PAUSED)
00869             {
00870                 if(m_batch->GetRunningCount()==1)
00871                 {
00872                     GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00873                 }
00874                 for(int i=0; i<m_batch->GetRunningCount(); i++)
00875                 {
00876                     if(m_batch->GetStatus(selIndex)==Project::PAUSED
00877                             && m_batch->CompareProjectsInLists(i,selIndex))
00878                     {
00879                         m_batch->CancelProject(i);
00880                     }
00881                 }
00882             }
00883             else
00884             {
00885                 //we go through all running projects to find the one with the same id as chosen one
00886                 for(int i=0; i<m_batch->GetRunningCount(); i++)
00887                 {
00888                     if(m_batch->GetStatus(selIndex)==Project::RUNNING
00889                             && m_batch->CompareProjectsInLists(i,selIndex))
00890                     {
00891                         m_batch->CancelProject(i);
00892                     }
00893                 }
00894             }
00895         }
00896         else
00897         {
00898             m_batch->SetStatus(selIndex,Project::FAILED);
00899         }
00900     }
00901 }
00902 
00903 void SelectEndTask(wxControlWithItems* list, const Batch::EndTask endTask)
00904 {
00905     for (unsigned int i = 0; i<list->GetCount(); i++)
00906     {
00907         if (static_cast<Batch::EndTask>((size_t)list->GetClientData(i)) == endTask)
00908         {
00909             list->SetSelection(i);
00910             return;
00911         };
00912     };
00913     list->SetSelection(0);
00914 };
00915 
00916 void BatchFrame::SetCheckboxes()
00917 {
00918     wxConfigBase* config=wxConfigBase::Get();
00919     int i;
00920     // read older version
00921 #if defined __WXMAC__ || defined __WXOSX_COCOA__
00922     i = 0;
00923 #else
00924     i=config->Read(wxT("/BatchFrame/ShutdownCheck"), 0l);
00925 #endif
00926     if (i != 0)
00927     {
00928         SelectEndTask(m_endChoice, Batch::SHUTDOWN);
00929         m_batch->atEnd = Batch::SHUTDOWN;
00930     };
00931     config->DeleteEntry(wxT("/BatchFrame/ShutdownCheck"));
00932     // now read current version
00933     i = config->Read(wxT("/BatchFrame/AtEnd"), 0l);
00934 #if defined __WXMAC__ || defined __WXOSX_COCOA__
00935     // wxWidgets for MacOS does not support wxShutdown
00936     if (i == Batch::SHUTDOWN)
00937     {
00938         i = 0;
00939     };
00940 #endif
00941     m_batch->atEnd = static_cast<Batch::EndTask>(i);
00942     SelectEndTask(m_endChoice, m_batch->atEnd);
00943     i=config->Read(wxT("/BatchFrame/OverwriteCheck"), 0l);
00944     XRCCTRL(*this,"cb_overwrite",wxCheckBox)->SetValue(i!=0);
00945     m_batch->overwrite=(i!=0);
00946     i=config->Read(wxT("/BatchFrame/VerboseCheck"), 0l);
00947     XRCCTRL(*this,"cb_verbose",wxCheckBox)->SetValue(i!=0);
00948     m_batch->verbose=(i!=0);
00949     i=config->Read(wxT("/BatchFrame/AutoRemoveCheck"), 1l);
00950     XRCCTRL(*this,"cb_autoremove",wxCheckBox)->SetValue(i!=0);
00951     m_batch->autoremove=(i!=0);
00952     i=config->Read(wxT("/BatchFrame/AutoStitchCheck"), 0l);
00953     XRCCTRL(*this,"cb_autostitch",wxCheckBox)->SetValue(i!=0);
00954     m_batch->autostitch=(i!=0);
00955     i=config->Read(wxT("/BatchFrame/SaveLog"), 0l);
00956     XRCCTRL(*this, "cb_savelog",wxCheckBox)->SetValue(i!=0);
00957     m_batch->saveLog=(i!=0);
00958 };
00959 
00960 Batch::EndTask BatchFrame::GetEndTask()
00961 {
00962     return static_cast<Batch::EndTask>((size_t)m_endChoice->GetClientData(m_endChoice->GetSelection()));
00963 };
00964 
00965 bool BatchFrame::GetCheckOverwrite()
00966 {
00967     return XRCCTRL(*this,"cb_overwrite",wxCheckBox)->IsChecked();
00968 };
00969 
00970 bool BatchFrame::GetCheckVerbose()
00971 {
00972     return XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
00973 };
00974 
00975 bool BatchFrame::GetCheckAutoRemove()
00976 {
00977     return XRCCTRL(*this,"cb_autoremove",wxCheckBox)->IsChecked();
00978 };
00979 
00980 bool BatchFrame::GetCheckAutoStitch()
00981 {
00982     return XRCCTRL(*this,"cb_autostitch",wxCheckBox)->IsChecked();
00983 };
00984 
00985 bool BatchFrame::GetCheckSaveLog()
00986 {
00987     return XRCCTRL(*this,"cb_savelog",wxCheckBox)->IsChecked();
00988 };
00989 
00990 void BatchFrame::OnCheckOverwrite(wxCommandEvent& event)
00991 {
00992     if(event.IsChecked())
00993     {
00994         m_batch->overwrite = true;
00995         wxConfigBase::Get()->Write(wxT("/BatchFrame/OverwriteCheck"), 1l);
00996     }
00997     else
00998     {
00999         m_batch->overwrite = false;
01000         wxConfigBase::Get()->Write(wxT("/BatchFrame/OverwriteCheck"), 0l);
01001     }
01002 }
01003 
01004 void BatchFrame::OnChoiceEnd(wxCommandEvent& event)
01005 {
01006     m_batch->atEnd = static_cast<Batch::EndTask>((size_t)m_endChoice->GetClientData(event.GetSelection()));
01007     wxConfigBase::Get()->Write(wxT("/BatchFrame/AtEnd"), static_cast<long>(m_batch->atEnd));
01008 }
01009 
01010 void BatchFrame::OnCheckVerbose(wxCommandEvent& event)
01011 {
01012     if(event.IsChecked())
01013     {
01014         m_batch->verbose = true;
01015         wxConfigBase::Get()->Write(wxT("/BatchFrame/VerboseCheck"), 1l);
01016     }
01017     else
01018     {
01019         m_batch->verbose = false;
01020         wxConfigBase::Get()->Write(wxT("/BatchFrame/VerboseCheck"), 0l);
01021     }
01022     m_batch->ShowOutput(m_batch->verbose);
01023 }
01024 
01025 void BatchFrame::SetInternalVerbose(bool newVerbose)
01026 {
01027     m_batch->verbose=newVerbose;
01028 };
01029 
01030 void BatchFrame::OnCheckAutoRemove(wxCommandEvent& event)
01031 {
01032     m_batch->autoremove=event.IsChecked();
01033     wxConfigBase* config=wxConfigBase::Get();
01034     if(m_batch->autoremove)
01035     {
01036         config->Write(wxT("/BatchFrame/AutoRemoveCheck"), 1l);
01037     }
01038     else
01039     {
01040         config->Write(wxT("/BatchFrame/AutoRemoveCheck"), 0l);
01041     }
01042     config->Flush();
01043 };
01044 
01045 void BatchFrame::OnCheckAutoStitch(wxCommandEvent& event)
01046 {
01047     m_batch->autostitch=event.IsChecked();
01048     wxConfigBase* config=wxConfigBase::Get();
01049     if(m_batch->autostitch)
01050     {
01051         config->Write(wxT("/BatchFrame/AutoStitchCheck"), 1l);
01052     }
01053     else
01054     {
01055         config->Write(wxT("/BatchFrame/AutoStitchCheck"), 0l);
01056     }
01057     config->Flush();
01058 };
01059 
01060 void BatchFrame::OnCheckSaveLog(wxCommandEvent& event)
01061 {
01062     m_batch->saveLog=event.IsChecked();
01063     wxConfigBase* config=wxConfigBase::Get();
01064     if(m_batch->saveLog)
01065     {
01066         config->Write(wxT("/BatchFrame/SaveLog"), 1l);
01067     }
01068     else
01069     {
01070         config->Write(wxT("/BatchFrame/SaveLog"), 0l);
01071     }
01072     config->Flush();
01073 };
01074 
01075 void BatchFrame::OnClose(wxCloseEvent& event)
01076 {
01077     // check size of batch queue
01078     if (m_batch->GetProjectCount() > 500)
01079     {
01080         wxMessageDialog message(this, _("The batch queue contains many items.\nThis can have negative effects on performance.\nShould the batch queue be cleared now?"),
01081 #ifdef __WXMSW__
01082             _("PTBatcherGUI"),
01083 #else
01084             wxT(""),
01085 #endif
01086             wxYES_NO | wxICON_INFORMATION);
01087         message.SetYesNoLabels(_("Clear batch queue now"), _("Keep batch queue"));
01088         if (message.ShowModal() == wxID_YES)
01089         {
01090             m_batch->ClearBatch();
01091             m_batch->SaveTemp();
01092         };
01093     };
01094     //save windows position
01095     wxConfigBase* config=wxConfigBase::Get();
01096     if(IsMaximized())
01097     {
01098         config->Write(wxT("/BatchFrame/Max"), 1l);
01099         config->Write(wxT("/BatchFrame/Minimized"), 0l);
01100     }
01101     else
01102     {
01103         config->Write(wxT("/BatchFrame/Max"), 0l);
01104         if(m_tray!=NULL && !IsShown())
01105         {
01106             config->Write(wxT("/BatchFrame/Minimized"), 1l);
01107         }
01108         else
01109         {
01110             config->Write(wxT("/BatchFrame/Minimized"), 0l);
01111             config->Write(wxT("/BatchFrame/Width"), GetSize().GetWidth());
01112             config->Write(wxT("/BatchFrame/Height"), GetSize().GetHeight());
01113         };
01114     }
01115     config->Flush();
01116     m_closeThread = true;
01117     if (this->GetThread() && this->GetThread()->IsRunning())
01118     {
01119         this->GetThread()->Wait();
01120     };
01121     if(m_tray!=NULL)
01122     {
01123         delete m_tray;
01124         m_tray = NULL;
01125     }
01126     this->Destroy();
01127 }
01128 
01129 void BatchFrame::PropagateDefaults()
01130 {
01131     m_batch->atEnd = GetEndTask();
01132     m_batch->overwrite=GetCheckOverwrite();
01133     m_batch->verbose=GetCheckVerbose();
01134     m_batch->autoremove=GetCheckAutoRemove();
01135     m_batch->autostitch=GetCheckAutoStitch();
01136 }
01137 
01138 void BatchFrame::RunBatch()
01139 {
01140     if(!IsRunning())
01141     {
01142         SetStatusInformation(_("Starting batch"));
01143         if (m_tray)
01144         {
01145             m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
01146         };
01147     }
01148     m_batch->RunBatch();
01149 }
01150 
01151 void BatchFrame::SetLocaleAndXRC(wxLocale* locale, wxString xrc)
01152 {
01153     m_locale = locale;
01154     m_xrcPrefix = xrc;
01155 }
01156 
01157 void BatchFrame::SwapProject(int index)
01158 {
01159     if(index>=0 && index<(projListBox->GetItemCount()-1))
01160     {
01161         projListBox->SwapProject(index);
01162         m_batch->SwapProject(index);
01163         if(projListBox->GetSelectedIndex()==index)
01164         {
01165             projListBox->Select(index+1);
01166         }
01167         else
01168         {
01169             projListBox->Select(index);
01170         }
01171     }
01172 }
01173 
01174 
01175 void BatchFrame::OnProcessTerminate(wxProcessEvent& event)
01176 {
01177     if(m_batch->GetRunningCount()==1)
01178     {
01179         GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
01180         if (m_tray)
01181         {
01182             m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01183         };
01184     }
01185     event.Skip();
01186 }
01187 
01188 void BatchFrame::RestoreSize()
01189 {
01190     //get saved size
01191     wxConfigBase* config=wxConfigBase::Get();
01192     int width = config->Read(wxT("/BatchFrame/Width"), -1l);
01193     int height = config->Read(wxT("/BatchFrame/Height"), -1l);
01194     int max = config->Read(wxT("/BatchFrame/Max"), -1l);
01195     int min = config->Read(wxT("/BatchFrame/Minimized"), -1l);
01196     if((width != -1) && (height != -1))
01197     {
01198         SetSize(width,height);
01199     }
01200     else
01201     {
01202         SetSize(600,400);
01203     }
01204 
01205     if(max==1)
01206     {
01207         Maximize();
01208     };
01209     m_startedMinimized=(m_tray!=NULL) && (min==1);
01210 }
01211 
01212 void BatchFrame::OnBatchFailed(wxCommandEvent& event)
01213 {
01214     if(m_batch->GetFailedProjectsCount()>0)
01215     {
01216         if (m_tray)
01217         {
01218             m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01219         };
01220         FailedProjectsDialog failedProjects_dlg(this, m_batch, m_xrcPrefix);
01221         failedProjects_dlg.ShowModal();
01222     };
01223 };
01224 
01225 void BatchFrame::OnBatchInformation(wxCommandEvent& e)
01226 {
01227     SetStatusInformation(e.GetString());
01228     if (m_tray && e.GetInt() == 1)
01229     {
01230         // batch finished, reset icon in task bar
01231         m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01232     };
01233 };
01234 
01235 void BatchFrame::SetStatusInformation(wxString status)
01236 {
01237     SetStatusText(status);
01238     if(m_tray!=NULL)
01239     {
01240 #if defined __WXMSW__ && wxUSE_TASKBARICON_BALLOONS 
01241         m_tray->ShowBalloon(_("PTBatcherGUI"),status,5000,wxICON_INFORMATION);
01242 #else
01243 #ifndef __WXMAC__
01244         // the balloon does not work correctly on MacOS; it gets the focus
01245         // and can not be closed
01246         if(!IsShown())
01247         {
01248             TaskBarBalloon* balloon=new TaskBarBalloon(_("PTBatcherGUI"),status);
01249             balloon->showBalloon(5000);
01250         };
01251 #endif
01252 #endif
01253     };
01254 };
01255 
01256 void BatchFrame::OnProgress(wxCommandEvent& e)
01257 {
01258     m_progStatusBar->SetProgress(e.GetInt());
01259     UpdateTaskBarProgressBar();
01260 };
01261 
01262 void BatchFrame::UpdateTaskBarProgressBar()
01263 {
01264 #if defined __WXMSW__ && wxCHECK_VERSION(3,1,0)
01265     // provide also a feedback in task bar if available
01266     if (IsShown())
01267     {
01268         wxTaskBarButton* taskBarButton = MSWGetTaskBarButton();
01269         if (taskBarButton != NULL)
01270         {
01271             if (m_progStatusBar->GetProgress() < 0)
01272             {
01273                 taskBarButton->SetProgressValue(wxTASKBAR_BUTTON_NO_PROGRESS);
01274             }
01275             else
01276             {
01277                 taskBarButton->SetProgressRange(100);
01278                 taskBarButton->SetProgressState(m_batch->IsPaused() ? wxTASKBAR_BUTTON_PAUSED : wxTASKBAR_BUTTON_NORMAL);
01279                 taskBarButton->SetProgressValue(m_progStatusBar->GetProgress());
01280             };
01281         };
01282     };
01283 #endif
01284 };
01285 
01286 void BatchFrame::OnMinimize(wxIconizeEvent& e)
01287 {
01288     //hide/show window in taskbar when minimizing
01289     if(m_tray!=NULL)
01290     {
01291         Show(!e.IsIconized());
01292         //switch off verbose output if PTBatcherGUI is in tray/taskbar
01293         if(e.IsIconized())
01294         {
01295             m_batch->verbose=false;
01296         }
01297         else
01298         {
01299             m_batch->verbose=XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
01300             UpdateTaskBarProgressBar();
01301         };
01302         m_batch->ShowOutput(m_batch->verbose);
01303     }
01304     else //don't hide window if no tray icon
01305     {
01306         if (!e.IsIconized())
01307         {
01308             // window is restored, update progress indicators
01309             UpdateTaskBarProgressBar();
01310         };
01311         e.Skip();
01312     };
01313 };
01314 
01315 void BatchFrame::UpdateBatchVerboseStatus()
01316 {
01317     m_batch->verbose=XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
01318     m_batch->ShowOutput(m_batch->verbose);
01319 };
01320 
01321 void BatchFrame::OnRefillListBox(wxCommandEvent& event)
01322 {
01323     int index=projListBox->GetSelectedIndex();
01324     int id=-1;
01325     if(index!=-1)
01326     {
01327         id=projListBox->GetProjectId(index);
01328     };
01329     projListBox->DeleteAllItems();
01330     projListBox->Fill(m_batch);
01331     if(id!=-1)
01332     {
01333         index=projListBox->GetIndex(id);
01334         if(index!=-1)
01335         {
01336             projListBox->Select(index);
01337         };
01338     };
01339 };
01340 
01341 void BatchFrame::OnMinimizeTrayMenu(wxCommandEvent& event)
01342 {
01343     UpdateTrayIcon(event.IsChecked());
01344     wxConfigBase::Get()->Write(wxT("/BatchFrame/minimizeTray"), event.IsChecked());
01345 }
01346 
01347 void BatchFrame::UpdateTrayIcon(const bool createTrayIcon)
01348 {
01349     if (createTrayIcon)
01350     {
01351         // create tray icon only if it not exists
01352         if (m_tray)
01353         {
01354             delete m_tray;
01355             m_tray = NULL;
01356         }
01357         m_tray = new BatchTaskBarIcon();
01358         if (m_batch->IsRunning())
01359         {
01360             m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
01361         }
01362         else
01363         {
01364             if (m_batch->IsPaused())
01365             {
01366                 m_tray->SetIcon(m_iconPaused, _("Pausing processing Hugin's batch queue"));
01367             }
01368             else
01369             {
01370                 m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01371             }
01372         }
01373     }
01374     else
01375     {
01376         // destroy tray icon
01377         if (m_tray)
01378         {
01379             delete m_tray;
01380             m_tray = NULL;
01381         }
01382     }
01383 }

Generated on 6 Dec 2016 for Hugintrunk by  doxygen 1.4.7