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     const HuginBase::UIntSet selected(projListBox->GetSelectedProjects());
00503     if(selected.size()== 1)
00504     {
00505         Project* project = m_batch->GetProject(*selected.begin());
00506         if (project->target == Project::STITCHING)
00507         {
00508             wxFileName prefix(project->prefix);
00509             wxFileDialog dlg(0,_("Specify output prefix for project ")+project->path,
00510                              prefix.GetPath(),
00511                              prefix.GetFullName(), wxT(""),
00512                              wxFD_SAVE, wxDefaultPosition);
00513             if (dlg.ShowModal() == wxID_OK)
00514             {
00515                 while(containsInvalidCharacters(dlg.GetPath()))
00516                 {
00517                     wxArrayString list;
00518                     list.Add(dlg.GetPath());
00519                     ShowFilenameWarning(this, list);
00520                     if(dlg.ShowModal()!=wxID_OK)
00521                     {
00522                         return;
00523                     }
00524                 };
00525                 wxFileName prefix(dlg.GetPath());
00526                 while (!prefix.IsDirWritable())
00527                 {
00528                     wxMessageBox(wxString::Format(_("You have no permissions to write in folder \"%s\".\nPlease select another folder for the final output."), prefix.GetPath().c_str()),
00529 #ifdef __WXMSW__
00530                         wxT("PTBatcherGUI"),
00531 #else
00532                         wxT(""),
00533 #endif
00534                         wxOK | wxICON_INFORMATION);
00535                     if (dlg.ShowModal() != wxID_OK)
00536                     {
00537                         return;
00538                     };
00539                     prefix = dlg.GetPath();
00540                 };
00541 
00542                 wxString outname(dlg.GetPath());
00543                 ChangePrefix(*selected.begin(), outname);
00544                 //SetStatusText(_T("Changed prefix for "+projListBox->GetSelectedProject()));
00545                 m_batch->SaveTemp();
00546             }
00547         }
00548         else
00549         {
00550             SetStatusText(_("The prefix of an assistant target cannot be changed."));
00551             wxBell();
00552         };
00553     }
00554     else
00555     {
00556         if (selected.empty())
00557         {
00558             SetStatusText(_("Please select a project"));
00559         }
00560         else
00561         {
00562             wxBell();
00563             SetStatusText(_("Please select only one project"));
00564         };
00565     };
00566 }
00567 
00568 void BatchFrame::ChangePrefix(int index,wxString newPrefix)
00569 {
00570     int i;
00571     if(index!=-1)
00572     {
00573         i=index;
00574     }
00575     else
00576     {
00577         i=m_batch->GetProjectCount()-1;
00578     }
00579     m_batch->ChangePrefix(i,newPrefix);
00580     projListBox->ChangePrefix(i,newPrefix);
00581 }
00582 
00583 void BatchFrame::OnButtonClear(wxCommandEvent& event)
00584 {
00585     int returnCode = m_batch->ClearBatch();
00586     if(returnCode == 0)
00587     {
00588         projListBox->DeleteAllItems();
00589     }
00590     else if(returnCode == 2)
00591     {
00592         m_cancelled = true;
00593         projListBox->DeleteAllItems();
00594         if(GetToolBar()->GetToolState(XRCID("tool_pause")))
00595         {
00596             GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00597         }
00598     }
00599     m_batch->SaveTemp();
00600 }
00601 
00602 void BatchFrame::OnButtonHelp(wxCommandEvent& event)
00603 {
00604     DEBUG_TRACE("");
00605 #if defined __wxMSW__ && !(wxCHECK_VERSION(3,1,1))
00606     // wxWidgets 3.x has a bug, that prevents DisplaySection to work on Win8/10 64 bit
00607     // see: http://trac.wxwidgets.org/ticket/14888
00608     // so using DisplayContents() and our own implementation of HuginCHMHelpController
00609     GetHelpController().DisplayHelpPage(wxT("Hugin_Batch_Processor.html"));
00610 #else
00611     GetHelpController().DisplaySection(wxT("Hugin_Batch_Processor.html"));
00612 #endif
00613 }
00614 
00615 void BatchFrame::OnButtonMoveDown(wxCommandEvent& event)
00616 {
00617     const HuginBase::UIntSet selected(projListBox->GetSelectedProjects());
00618     if (selected.size() == 1)
00619     {
00620         SwapProject(*selected.begin(), true);
00621         m_batch->SaveTemp();
00622     }
00623     else
00624     {
00625         wxBell();
00626     };
00627 }
00628 
00629 void BatchFrame::OnButtonMoveUp(wxCommandEvent& event)
00630 {
00631     const HuginBase::UIntSet selected(projListBox->GetSelectedProjects());
00632     if (selected.size() == 1)
00633     {
00634         SwapProject(*selected.begin() - 1, false);
00635         m_batch->SaveTemp();
00636     }
00637     else
00638     {
00639         wxBell();
00640     };
00641 }
00642 
00643 void BatchFrame::OnButtonOpenBatch(wxCommandEvent& event)
00644 {
00645     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/batchPath"),wxT(""));
00646     wxFileDialog dlg(0,
00647                      _("Specify batch file to open"),
00648                      defaultdir, wxT(""),
00649                      _("Batch files (*.ptb)|*.ptb;|All files (*)|*"),
00650                      wxFD_OPEN, wxDefaultPosition);
00651     if (dlg.ShowModal() == wxID_OK)
00652     {
00653         wxConfig::Get()->Write(wxT("/BatchFrame/batchPath"), dlg.GetDirectory());  // remember for later
00654         int clearCode = m_batch->LoadBatchFile(dlg.GetPath());
00655         //1 is error code for not clearing batch
00656         if(clearCode!=1)
00657         {
00658             /*if(clearCode==2) //we just cancelled the batch, so we need to try loading again
00659                 m_batch->LoadBatchFile(dlg.GetPath());*/
00660             projListBox->DeleteAllItems();
00661             projListBox->Fill(m_batch);
00662             m_batch->SaveTemp();
00663         }
00664     }
00665 }
00666 
00667 void BatchFrame::OnButtonOpenWithHugin(wxCommandEvent& event)
00668 {
00669     const wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
00670     const HuginBase::UIntSet selected(projListBox->GetSelectedProjects());
00671     if (selected.size() == 1)
00672     {
00673         if (projListBox->GetText(*selected.begin(), 0).Cmp(_T("")) != 0)
00674 #ifdef __WXMAC__
00675             wxExecute(_T("open -b net.sourceforge.Hugin \"" + m_batch->GetProject(*selected.begin())->path + _T("\"")));
00676 #else
00677             wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + _T("hugin \"" + m_batch->GetProject(*selected.begin())->path + _T("\" -notips")));
00678 #endif
00679         else
00680         {
00681             SetStatusText(_("Cannot open app in Hugin."));
00682         };
00683     }
00684     else
00685     {
00686         if (selected.empty())
00687         {
00688             //ask user if he/she wants to load an empty project
00689             wxMessageDialog message(this, _("No project selected. Open Hugin without project?"),
00690 #ifdef _WIN32
00691                 _("PTBatcherGUI"),
00692 #else
00693                 wxT(""),
00694 #endif
00695                 wxYES_NO | wxICON_INFORMATION);
00696             if (message.ShowModal() == wxID_YES)
00697             {
00698 #ifdef __WXMAC__
00699                 wxExecute(_T("open -b net.sourceforge.Hugin"));
00700 #else
00701                 wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + _T("hugin"));
00702 #endif
00703             }
00704         }
00705         else
00706         {
00707             wxBell();
00708             SetStatusText(_("Please select only one project"));
00709         };
00710     };
00711 }
00712 
00713 void BatchFrame::OnButtonPause(wxCommandEvent& event)
00714 {
00715     if(m_batch->GetRunningCount()>0)
00716     {
00717         if(!m_batch->IsPaused())
00718         {
00719             m_batch->PauseBatch();
00720             GetToolBar()->ToggleTool(XRCID("tool_pause"),true);
00721             SetStatusInformation(_("Batch paused"));
00722             if (m_tray)
00723             {
00724                 m_tray->SetIcon(m_iconPaused, _("Pausing processing Hugin's batch queue"));
00725             };
00726         }
00727         else
00728         {
00729             m_batch->PauseBatch();
00730             GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00731             SetStatusInformation(_("Continuing batch..."));
00732             if (m_tray)
00733             {
00734                 m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
00735             };
00736         }
00737     }
00738     else //if no projects are running, we deactivate the button
00739     {
00740         GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
00741     }
00742     UpdateTaskBarProgressBar();
00743 }
00744 
00745 void BatchFrame::OnButtonRemoveComplete(wxCommandEvent& event)
00746 {
00747     bool removeErrors=false;
00748     if(!m_batch->NoErrors())
00749     {
00750         wxMessageDialog message(this,_("There are failed projects in the list.\nRemove them too?"),
00751 #ifdef _WIN32
00752                                 _("PTBatcherGUI"),
00753 #else
00754                                 wxT(""),
00755 #endif
00756                                 wxYES_NO | wxICON_INFORMATION );
00757         if(message.ShowModal()==wxID_YES)
00758         {
00759             removeErrors=true;
00760         }
00761     }
00762     for(int i=projListBox->GetItemCount()-1; i>=0; i--)
00763     {
00764         if(m_batch->GetStatus(i)==Project::FINISHED ||
00765                 (removeErrors && m_batch->GetStatus(i)==Project::FAILED))
00766         {
00767             projListBox->Deselect(i);
00768             projListBox->DeleteItem(i);
00769             m_batch->RemoveProjectAtIndex(i);
00770         }
00771     }
00772     m_batch->SaveTemp();
00773 }
00774 
00775 void BatchFrame::OnButtonRemoveFromList(wxCommandEvent& event)
00776 {
00777     
00778     const HuginBase::UIntSet selected = projListBox->GetSelectedProjects();
00779     if(!selected.empty())
00780     {
00781         for (auto i = selected.rbegin(); i != selected.rend(); ++i)
00782         {
00783             const int selIndex = *i;
00784             if (m_batch->GetStatus(selIndex) == Project::RUNNING || m_batch->GetStatus(selIndex) == Project::PAUSED)
00785             {
00786                 wxMessageDialog message(this, _("Cannot remove project in progress.\nDo you want to cancel it?"),
00787 #ifdef _WIN32
00788                     _("PTBatcherGUI"),
00789 #else
00790                     wxT(""),
00791 #endif
00792                     wxYES_NO | wxICON_INFORMATION);
00793                 if (message.ShowModal() == wxID_YES)
00794                 {
00795                     OnButtonSkip(event);
00796                 };
00797             }
00798             else
00799             {
00800                 SetStatusText(wxString::Format(_("Removed project %s"), m_batch->GetProject(selIndex)->path.c_str()));
00801                 projListBox->Deselect(selIndex);
00802                 projListBox->DeleteItem(selIndex);
00803                 m_batch->RemoveProjectAtIndex(selIndex);
00804                 m_batch->SaveTemp();
00805             };
00806         };
00807     }
00808     else
00809     {
00810         SetStatusText(_("Please select a project to remove"));
00811     }
00812 }
00813 
00814 
00815 void BatchFrame::OnButtonReset(wxCommandEvent& event)
00816 {
00817     const HuginBase::UIntSet selected(projListBox->GetSelectedProjects());
00818     if(!selected.empty())
00819     {
00820         for (auto selIndex : selected)
00821         {
00822             if (m_batch->GetStatus(selIndex) == Project::RUNNING || m_batch->GetStatus(selIndex) == Project::PAUSED)
00823             {
00824                 wxMessageDialog message(this, _("Cannot reset project in progress.\nDo you want to cancel it?"),
00825 #ifdef _WIN32
00826                     _("PTBatcherGUI"),
00827 #else
00828                     wxT(""),
00829 #endif
00830                     wxYES_NO | wxICON_INFORMATION);
00831                 if (message.ShowModal() == wxID_YES)
00832                 {
00833                     OnButtonSkip(event);
00834                 }
00835             }
00836             else
00837             {
00838                 m_batch->SetStatus(selIndex, Project::WAITING);
00839                 SetStatusText(wxString::Format(_("Reset project %s"), m_batch->GetProject(selIndex)->path.c_str()));
00840             };
00841         };
00842     }
00843     else
00844     {
00845         SetStatusText(_("Please select a project to reset"));
00846     }
00847     m_batch->SaveTemp();
00848 }
00849 
00850 void BatchFrame::OnButtonResetAll(wxCommandEvent& event)
00851 {
00852     if(m_batch->GetRunningCount()!=0)
00853     {
00854         wxMessageDialog message(this, _("Cannot reset projects in progress.\nDo you want to cancel the batch?"),
00855 #ifdef _WIN32
00856                                 _("PTBatcherGUI"),
00857 #else
00858                                 wxT(""),
00859 #endif
00860                                 wxYES_NO | wxICON_INFORMATION);
00861         if(message.ShowModal()==wxID_YES)
00862         {
00863             OnButtonCancel(event);
00864         }
00865     }
00866     else
00867     {
00868         for(int i=projListBox->GetItemCount()-1; i>=0; i--)
00869         {
00870             m_batch->SetStatus(i,Project::WAITING);
00871         }
00872     }
00873     m_batch->SaveTemp();
00874 }
00875 
00876 void BatchFrame::OnButtonRunBatch(wxCommandEvent& event)
00877 {
00878     if(m_batch->IsPaused())
00879     {
00880         //m_batch->paused = false;
00881         OnButtonPause(event);
00882     }
00883     else
00884     {
00885         RunBatch();
00886     }
00887 }
00888 
00889 void BatchFrame::OnButtonSaveBatch(wxCommandEvent& event)
00890 {
00891     wxString defaultdir = wxConfigBase::Get()->Read(wxT("/BatchFrame/batchPath"),wxT(""));
00892     wxFileDialog dlg(0,
00893                      _("Specify batch file to save"),
00894                      defaultdir, wxT(""),
00895                      _("Batch file (*.ptb)|*.ptb;|All files (*)|*"),
00896                      wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
00897     if (dlg.ShowModal() == wxID_OK)
00898     {
00899         wxConfig::Get()->Write(wxT("/BatchFrame/batchPath"), dlg.GetDirectory());  // remember for later
00900         m_batch->SaveBatchFile(dlg.GetPath());
00901     }
00902 }
00903 
00904 void BatchFrame::OnButtonSkip(wxCommandEvent& event)
00905 {
00906     const HuginBase::UIntSet selected(projListBox->GetSelectedProjects());
00907     if(!selected.empty())
00908     {
00909         for (auto selIndex : selected)
00910         {
00911             if (m_batch->GetStatus(selIndex) == Project::RUNNING
00912                 || m_batch->GetStatus(selIndex) == Project::PAUSED)
00913             {
00914                 if (m_batch->GetStatus(selIndex) == Project::PAUSED)
00915                 {
00916                     if (m_batch->GetRunningCount() == 1)
00917                     {
00918                         GetToolBar()->ToggleTool(XRCID("tool_pause"), false);
00919                     }
00920                     for (int i = 0; i < m_batch->GetRunningCount(); i++)
00921                     {
00922                         if (m_batch->GetStatus(selIndex) == Project::PAUSED
00923                             && m_batch->CompareProjectsInLists(i, selIndex))
00924                         {
00925                             m_batch->CancelProject(i);
00926                         }
00927                     }
00928                 }
00929                 else
00930                 {
00931                     //we go through all running projects to find the one with the same id as chosen one
00932                     for (int i = 0; i < m_batch->GetRunningCount(); i++)
00933                     {
00934                         if (m_batch->GetStatus(selIndex) == Project::RUNNING
00935                             && m_batch->CompareProjectsInLists(i, selIndex))
00936                         {
00937                             m_batch->CancelProject(i);
00938                         }
00939                     }
00940                 }
00941             }
00942             else
00943             {
00944                 m_batch->SetStatus(selIndex, Project::FAILED);
00945             };
00946         };
00947     }
00948 }
00949 
00950 void SelectEndTask(wxControlWithItems* list, const Batch::EndTask endTask)
00951 {
00952     for (unsigned int i = 0; i<list->GetCount(); i++)
00953     {
00954         if (static_cast<Batch::EndTask>((size_t)list->GetClientData(i)) == endTask)
00955         {
00956             list->SetSelection(i);
00957             return;
00958         };
00959     };
00960     list->SetSelection(0);
00961 };
00962 
00963 void BatchFrame::SetCheckboxes()
00964 {
00965     wxConfigBase* config=wxConfigBase::Get();
00966     int i;
00967     // read older version
00968 #if defined __WXMAC__ || defined __WXOSX_COCOA__
00969     i = 0;
00970 #else
00971     i=config->Read(wxT("/BatchFrame/ShutdownCheck"), 0l);
00972 #endif
00973     if (i != 0)
00974     {
00975         SelectEndTask(m_endChoice, Batch::SHUTDOWN);
00976         m_batch->atEnd = Batch::SHUTDOWN;
00977     };
00978     config->DeleteEntry(wxT("/BatchFrame/ShutdownCheck"));
00979     // now read current version
00980     i = config->Read(wxT("/BatchFrame/AtEnd"), 0l);
00981 #if defined __WXMAC__ || defined __WXOSX_COCOA__
00982     // wxWidgets for MacOS does not support wxShutdown
00983     if (i == Batch::SHUTDOWN)
00984     {
00985         i = 0;
00986     };
00987 #endif
00988     m_batch->atEnd = static_cast<Batch::EndTask>(i);
00989     SelectEndTask(m_endChoice, m_batch->atEnd);
00990     i=config->Read(wxT("/BatchFrame/OverwriteCheck"), 0l);
00991     XRCCTRL(*this,"cb_overwrite",wxCheckBox)->SetValue(i!=0);
00992     m_batch->overwrite=(i!=0);
00993     i=config->Read(wxT("/BatchFrame/VerboseCheck"), 0l);
00994     XRCCTRL(*this,"cb_verbose",wxCheckBox)->SetValue(i!=0);
00995     m_batch->verbose=(i!=0);
00996     i=config->Read(wxT("/BatchFrame/AutoRemoveCheck"), 1l);
00997     XRCCTRL(*this,"cb_autoremove",wxCheckBox)->SetValue(i!=0);
00998     m_batch->autoremove=(i!=0);
00999     i=config->Read(wxT("/BatchFrame/AutoStitchCheck"), 0l);
01000     XRCCTRL(*this,"cb_autostitch",wxCheckBox)->SetValue(i!=0);
01001     m_batch->autostitch=(i!=0);
01002     i=config->Read(wxT("/BatchFrame/SaveLog"), 0l);
01003     XRCCTRL(*this, "cb_savelog",wxCheckBox)->SetValue(i!=0);
01004     m_batch->saveLog=(i!=0);
01005 };
01006 
01007 Batch::EndTask BatchFrame::GetEndTask()
01008 {
01009     return static_cast<Batch::EndTask>((size_t)m_endChoice->GetClientData(m_endChoice->GetSelection()));
01010 };
01011 
01012 bool BatchFrame::GetCheckOverwrite()
01013 {
01014     return XRCCTRL(*this,"cb_overwrite",wxCheckBox)->IsChecked();
01015 };
01016 
01017 bool BatchFrame::GetCheckVerbose()
01018 {
01019     return XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
01020 };
01021 
01022 bool BatchFrame::GetCheckAutoRemove()
01023 {
01024     return XRCCTRL(*this,"cb_autoremove",wxCheckBox)->IsChecked();
01025 };
01026 
01027 bool BatchFrame::GetCheckAutoStitch()
01028 {
01029     return XRCCTRL(*this,"cb_autostitch",wxCheckBox)->IsChecked();
01030 };
01031 
01032 bool BatchFrame::GetCheckSaveLog()
01033 {
01034     return XRCCTRL(*this,"cb_savelog",wxCheckBox)->IsChecked();
01035 };
01036 
01037 void BatchFrame::OnCheckOverwrite(wxCommandEvent& event)
01038 {
01039     if(event.IsChecked())
01040     {
01041         m_batch->overwrite = true;
01042         wxConfigBase::Get()->Write(wxT("/BatchFrame/OverwriteCheck"), 1l);
01043     }
01044     else
01045     {
01046         m_batch->overwrite = false;
01047         wxConfigBase::Get()->Write(wxT("/BatchFrame/OverwriteCheck"), 0l);
01048     }
01049 }
01050 
01051 void BatchFrame::OnChoiceEnd(wxCommandEvent& event)
01052 {
01053     m_batch->atEnd = static_cast<Batch::EndTask>((size_t)m_endChoice->GetClientData(event.GetSelection()));
01054     wxConfigBase::Get()->Write(wxT("/BatchFrame/AtEnd"), static_cast<long>(m_batch->atEnd));
01055 }
01056 
01057 void BatchFrame::OnCheckVerbose(wxCommandEvent& event)
01058 {
01059     if(event.IsChecked())
01060     {
01061         m_batch->verbose = true;
01062         wxConfigBase::Get()->Write(wxT("/BatchFrame/VerboseCheck"), 1l);
01063     }
01064     else
01065     {
01066         m_batch->verbose = false;
01067         wxConfigBase::Get()->Write(wxT("/BatchFrame/VerboseCheck"), 0l);
01068     }
01069     m_batch->ShowOutput(m_batch->verbose);
01070 }
01071 
01072 void BatchFrame::SetInternalVerbose(bool newVerbose)
01073 {
01074     m_batch->verbose=newVerbose;
01075 };
01076 
01077 void BatchFrame::OnCheckAutoRemove(wxCommandEvent& event)
01078 {
01079     m_batch->autoremove=event.IsChecked();
01080     wxConfigBase* config=wxConfigBase::Get();
01081     if(m_batch->autoremove)
01082     {
01083         config->Write(wxT("/BatchFrame/AutoRemoveCheck"), 1l);
01084     }
01085     else
01086     {
01087         config->Write(wxT("/BatchFrame/AutoRemoveCheck"), 0l);
01088     }
01089     config->Flush();
01090 };
01091 
01092 void BatchFrame::OnCheckAutoStitch(wxCommandEvent& event)
01093 {
01094     m_batch->autostitch=event.IsChecked();
01095     wxConfigBase* config=wxConfigBase::Get();
01096     if(m_batch->autostitch)
01097     {
01098         config->Write(wxT("/BatchFrame/AutoStitchCheck"), 1l);
01099     }
01100     else
01101     {
01102         config->Write(wxT("/BatchFrame/AutoStitchCheck"), 0l);
01103     }
01104     config->Flush();
01105 };
01106 
01107 void BatchFrame::OnCheckSaveLog(wxCommandEvent& event)
01108 {
01109     m_batch->saveLog=event.IsChecked();
01110     wxConfigBase* config=wxConfigBase::Get();
01111     if(m_batch->saveLog)
01112     {
01113         config->Write(wxT("/BatchFrame/SaveLog"), 1l);
01114     }
01115     else
01116     {
01117         config->Write(wxT("/BatchFrame/SaveLog"), 0l);
01118     }
01119     config->Flush();
01120 };
01121 
01122 void BatchFrame::OnClose(wxCloseEvent& event)
01123 {
01124     // check size of batch queue
01125     if (m_batch->GetProjectCount() > 500)
01126     {
01127         wxMessageDialog message(this, _("The batch queue contains many items.\nThis can have negative effects on performance.\nShould the batch queue be cleared now?"),
01128 #ifdef __WXMSW__
01129             _("PTBatcherGUI"),
01130 #else
01131             wxT(""),
01132 #endif
01133             wxYES_NO | wxICON_INFORMATION);
01134         message.SetYesNoLabels(_("Clear batch queue now"), _("Keep batch queue"));
01135         if (message.ShowModal() == wxID_YES)
01136         {
01137             m_batch->ClearBatch();
01138             m_batch->SaveTemp();
01139         };
01140     };
01141     //save windows position
01142     wxConfigBase* config=wxConfigBase::Get();
01143     if(IsMaximized())
01144     {
01145         config->Write(wxT("/BatchFrame/Max"), 1l);
01146         config->Write(wxT("/BatchFrame/Minimized"), 0l);
01147     }
01148     else
01149     {
01150         config->Write(wxT("/BatchFrame/Max"), 0l);
01151         if(m_tray!=NULL && !IsShown())
01152         {
01153             config->Write(wxT("/BatchFrame/Minimized"), 1l);
01154         }
01155         else
01156         {
01157             config->Write(wxT("/BatchFrame/Minimized"), 0l);
01158             config->Write(wxT("/BatchFrame/Width"), GetSize().GetWidth());
01159             config->Write(wxT("/BatchFrame/Height"), GetSize().GetHeight());
01160         };
01161     }
01162     config->Flush();
01163     m_closeThread = true;
01164     if (this->GetThread() && this->GetThread()->IsRunning())
01165     {
01166         this->GetThread()->Wait();
01167     };
01168     if(m_tray!=NULL)
01169     {
01170         delete m_tray;
01171         m_tray = NULL;
01172     }
01173     this->Destroy();
01174 }
01175 
01176 void BatchFrame::PropagateDefaults()
01177 {
01178     m_batch->atEnd = GetEndTask();
01179     m_batch->overwrite=GetCheckOverwrite();
01180     m_batch->verbose=GetCheckVerbose();
01181     m_batch->autoremove=GetCheckAutoRemove();
01182     m_batch->autostitch=GetCheckAutoStitch();
01183 }
01184 
01185 void BatchFrame::RunBatch()
01186 {
01187     if(!IsRunning())
01188     {
01189         SetStatusInformation(_("Starting batch"));
01190         if (m_tray)
01191         {
01192             m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
01193         };
01194     }
01195     m_batch->RunBatch();
01196 }
01197 
01198 void BatchFrame::SetLocaleAndXRC(wxLocale* locale, wxString xrc)
01199 {
01200     m_locale = locale;
01201     m_xrcPrefix = xrc;
01202 }
01203 
01204 void BatchFrame::SwapProject(int index, bool down)
01205 {
01206     if(index>=0 && index<(projListBox->GetItemCount()-1))
01207     {
01208         projListBox->SwapProject(index);
01209         m_batch->SwapProject(index);
01210         if(down)
01211         {
01212             projListBox->Deselect(index);
01213             projListBox->Select(index + 1);
01214         }
01215         else
01216         {
01217             projListBox->Select(index);
01218             projListBox->Deselect(index + 1);
01219         };
01220     }
01221 }
01222 
01223 
01224 void BatchFrame::OnProcessTerminate(wxProcessEvent& event)
01225 {
01226     if(m_batch->GetRunningCount()==1)
01227     {
01228         GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
01229         if (m_tray)
01230         {
01231             m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01232         };
01233     }
01234     event.Skip();
01235 }
01236 
01237 void BatchFrame::RestoreSize()
01238 {
01239     //get saved size
01240     wxConfigBase* config=wxConfigBase::Get();
01241     int width = config->Read(wxT("/BatchFrame/Width"), -1l);
01242     int height = config->Read(wxT("/BatchFrame/Height"), -1l);
01243     int max = config->Read(wxT("/BatchFrame/Max"), -1l);
01244     int min = config->Read(wxT("/BatchFrame/Minimized"), -1l);
01245     if((width != -1) && (height != -1))
01246     {
01247         SetSize(width,height);
01248     }
01249     else
01250     {
01251         SetSize(600,400);
01252     }
01253 
01254     if(max==1)
01255     {
01256         Maximize();
01257     };
01258     m_startedMinimized=(m_tray!=NULL) && (min==1);
01259 }
01260 
01261 void BatchFrame::OnBatchFailed(wxCommandEvent& event)
01262 {
01263     if(m_batch->GetFailedProjectsCount()>0)
01264     {
01265         if (m_tray)
01266         {
01267             m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01268         };
01269         FailedProjectsDialog failedProjects_dlg(this, m_batch, m_xrcPrefix);
01270         failedProjects_dlg.ShowModal();
01271     };
01272 };
01273 
01274 void BatchFrame::OnBatchInformation(wxCommandEvent& e)
01275 {
01276     SetStatusInformation(e.GetString());
01277     if (m_tray && e.GetInt() == 1)
01278     {
01279         // batch finished, reset icon in task bar
01280         m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01281     };
01282 };
01283 
01284 void BatchFrame::SetStatusInformation(wxString status)
01285 {
01286     SetStatusText(status);
01287     if(m_tray!=NULL)
01288     {
01289 #if defined __WXMSW__ && wxUSE_TASKBARICON_BALLOONS 
01290         m_tray->ShowBalloon(_("PTBatcherGUI"),status,5000,wxICON_INFORMATION);
01291 #else
01292 #ifndef __WXMAC__
01293         // the balloon does not work correctly on MacOS; it gets the focus
01294         // and can not be closed
01295         if(!IsShown())
01296         {
01297             TaskBarBalloon* balloon=new TaskBarBalloon(_("PTBatcherGUI"),status);
01298             balloon->showBalloon(5000);
01299         };
01300 #endif
01301 #endif
01302     };
01303 };
01304 
01305 void BatchFrame::OnProgress(wxCommandEvent& e)
01306 {
01307     m_progStatusBar->SetProgress(e.GetInt());
01308     UpdateTaskBarProgressBar();
01309 };
01310 
01311 void BatchFrame::UpdateTaskBarProgressBar()
01312 {
01313 #if defined __WXMSW__ && wxCHECK_VERSION(3,1,0)
01314     // provide also a feedback in task bar if available
01315     if (IsShown())
01316     {
01317         wxTaskBarButton* taskBarButton = MSWGetTaskBarButton();
01318         if (taskBarButton != NULL)
01319         {
01320             if (m_progStatusBar->GetProgress() < 0)
01321             {
01322                 taskBarButton->SetProgressValue(wxTASKBAR_BUTTON_NO_PROGRESS);
01323             }
01324             else
01325             {
01326                 taskBarButton->SetProgressRange(100);
01327                 taskBarButton->SetProgressState(m_batch->IsPaused() ? wxTASKBAR_BUTTON_PAUSED : wxTASKBAR_BUTTON_NORMAL);
01328                 taskBarButton->SetProgressValue(m_progStatusBar->GetProgress());
01329             };
01330         };
01331     };
01332 #endif
01333 };
01334 
01335 void BatchFrame::OnMinimize(wxIconizeEvent& e)
01336 {
01337     //hide/show window in taskbar when minimizing
01338     if(m_tray!=NULL)
01339     {
01340         Show(!e.IsIconized());
01341         //switch off verbose output if PTBatcherGUI is in tray/taskbar
01342         if(e.IsIconized())
01343         {
01344             m_batch->verbose=false;
01345         }
01346         else
01347         {
01348             m_batch->verbose=XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
01349             UpdateTaskBarProgressBar();
01350         };
01351         m_batch->ShowOutput(m_batch->verbose);
01352     }
01353     else //don't hide window if no tray icon
01354     {
01355         if (!e.IsIconized())
01356         {
01357             // window is restored, update progress indicators
01358             UpdateTaskBarProgressBar();
01359         };
01360         e.Skip();
01361     };
01362 };
01363 
01364 void BatchFrame::UpdateBatchVerboseStatus()
01365 {
01366     m_batch->verbose=XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
01367     m_batch->ShowOutput(m_batch->verbose);
01368 };
01369 
01370 void BatchFrame::OnRefillListBox(wxCommandEvent& event)
01371 {
01372     const HuginBase::UIntSet selected = projListBox->GetSelectedProjects();
01373     std::set<long> selectedID;
01374     for (auto index : selected)
01375     {
01376         selectedID.insert(m_batch->GetProject(index)->id);
01377     };
01378     projListBox->DeleteAllItems();
01379     projListBox->Fill(m_batch);
01380     for(auto id:selectedID)
01381     {
01382         int index=projListBox->GetIndex(id);
01383         if(index!=-1)
01384         {
01385             projListBox->Select(index);
01386         };
01387     };
01388 };
01389 
01390 void BatchFrame::OnMinimizeTrayMenu(wxCommandEvent& event)
01391 {
01392     UpdateTrayIcon(event.IsChecked());
01393     wxConfigBase::Get()->Write(wxT("/BatchFrame/minimizeTray"), event.IsChecked());
01394 }
01395 
01396 void BatchFrame::UpdateTrayIcon(const bool createTrayIcon)
01397 {
01398     if (createTrayIcon)
01399     {
01400         // create tray icon only if it not exists
01401         if (m_tray)
01402         {
01403             delete m_tray;
01404             m_tray = NULL;
01405         }
01406         m_tray = new BatchTaskBarIcon();
01407         if (m_batch->IsRunning())
01408         {
01409             m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
01410         }
01411         else
01412         {
01413             if (m_batch->IsPaused())
01414             {
01415                 m_tray->SetIcon(m_iconPaused, _("Pausing processing Hugin's batch queue"));
01416             }
01417             else
01418             {
01419                 m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
01420             }
01421         }
01422     }
01423     else
01424     {
01425         // destroy tray icon
01426         if (m_tray)
01427         {
01428             delete m_tray;
01429             m_tray = NULL;
01430         }
01431     }
01432 }

Generated on 29 Apr 2017 for Hugintrunk by  doxygen 1.4.7