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

Generated on 29 Jun 2016 for Hugintrunk by  doxygen 1.4.7