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

Generated on 14 Feb 2016 for Hugintrunk by  doxygen 1.4.7