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

Generated on 29 May 2016 for Hugintrunk by  doxygen 1.4.7