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

Generated on 1 Sep 2015 for Hugintrunk by  doxygen 1.4.7