Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /src/hugin1/ptbatcher/PTBatcherGUI.cpp [261128] .. [fa20a7] Maximize Restore

  Switch to side-by-side view

--- a/src/hugin1/ptbatcher/PTBatcherGUI.cpp
+++ b/src/hugin1/ptbatcher/PTBatcherGUI.cpp
@@ -39,7 +39,12 @@
 	// Required to access the preferences of hugin
     SetAppName(wxT("hugin"));
 
+#if defined __WXMSW__
+	int localeID = wxConfigBase::Get()->Read(wxT("language"), (long) wxLANGUAGE_DEFAULT);
+	m_locale.Init(localeID);
+#else
     m_locale.Init(wxLANGUAGE_DEFAULT);
+#endif
 
     // setup the environment for the different operating systems
 #if defined __WXMSW__
@@ -86,20 +91,27 @@
     // set the name of locale recource to look for
     m_locale.AddCatalog(wxT("hugin"));
 
-    if ( ! wxFile::Exists(m_xrcPrefix + wxT("/batch_frame.xrc")) ) {
-        wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
-        return false;
-    }
-    // initialize image handlers
-    wxInitAllImageHandlers();
-
-    // Initialize all the XRC handlers.
-    wxXmlResource::Get()->InitAllHandlers();
-    wxXmlResource::Get()->AddHandler(new ProjectListBoxXmlHandler());
-    // load XRC files
-    wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_frame.xrc"));
-    wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_toolbar.xrc"));
-    wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_menu.xrc"));
+	const wxString name = wxString::Format(_T("PTBatcherGUI-%s"), wxGetUserId().c_str());
+	m_checker = new wxSingleInstanceChecker(name+wxT(".lock"),wxFileName::GetTempDir());
+	bool IsFirstInstance=(!m_checker->IsAnotherRunning());
+
+	if(IsFirstInstance)
+	{
+		if ( ! wxFile::Exists(m_xrcPrefix + wxT("/batch_frame.xrc")) ) {
+			wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:") + m_xrcPrefix , _("Fatal Error"));
+			return false;
+		}
+		// initialize image handlers
+		wxInitAllImageHandlers();
+
+		// Initialize all the XRC handlers.
+		wxXmlResource::Get()->InitAllHandlers();
+		wxXmlResource::Get()->AddHandler(new ProjectListBoxXmlHandler());
+		// load XRC files
+		wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_frame.xrc"));
+		wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_toolbar.xrc"));
+		wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_menu.xrc"));
+	};
 
 	// parse arguments
     static const wxCmdLineEntryDesc cmdLineDesc[] =
@@ -151,10 +163,33 @@
     } */
 #endif
 
-	m_frame = new BatchFrame(&m_locale,m_xrcPrefix);
-	m_frame->RestoreSize();
-	SetTopWindow(m_frame);
-	m_frame->Show(true);
+	wxClient client;
+	wxConnectionBase *conn;
+	wxString servername;
+#ifdef __WINDOWS__
+	servername=name;
+#else
+	servername=wxFileName::GetTempDir()+wxFileName::GetPathSeparator()+name+wxT(".ipc");
+#endif
+	if(IsFirstInstance)
+	{
+		m_frame = new BatchFrame(&m_locale,m_xrcPrefix);
+		m_frame->RestoreSize();
+		SetTopWindow(m_frame);
+		m_frame->Show(true);
+		m_server = new BatchIPCServer();
+		if (!m_server->Create(servername))
+		{
+			delete m_server;
+			m_server = NULL;
+		};
+	}
+	else
+	{
+		conn=client.MakeConnection(wxEmptyString, servername, IPC_START);
+		if(!conn)
+			return false;
+	};
 	//m_frame->SetLocaleAndXRC(&m_locale,m_xrcPrefix);
 	//projectsRunning=0;
 	unsigned int count = 0;
@@ -167,20 +202,23 @@
 		if(!projectSpecified)	//next parameter must be new script file
 		{
 			wxFileName name(param);
-			Project *proj = new Project(param,name.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + name.GetName());
-			projList.Add(proj);
-			m_frame->SetStatusText(_("Added project ")+param);
-			
-			m_frame->projListBox->AppendProject(proj);
+			name.MakeAbsolute();
+			if(IsFirstInstance)
+				m_frame->AddToList(name.GetFullPath());
+			else
+				conn->Request(wxT("A ")+name.GetFullPath());
 			projectSpecified = true;
 		}
 		else	//parameter could be previous project's output prefix
 		{
 			wxFileName fn(param);
+			fn.MakeAbsolute();
 			if(!fn.HasExt())	//if there is no extension we have a prefix
 			{
-				projList.Last().prefix = param;
-				m_frame->projListBox->ReloadProject(m_frame->projListBox->GetItemCount()-1,((Project*)&projList.Last()));
+				if(IsFirstInstance)
+					m_frame->ChangePrefix(-1,fn.GetFullPath());
+				else
+					conn->Request(wxT("P ")+fn.GetFullPath());
 				projectSpecified = false;
 			}
 			else
@@ -193,8 +231,10 @@
 					ext.CmpNoCase(wxT("pnm")) == 0 || ext.CmpNoCase(wxT("hdr")) == 0) 
 				{
 					//extension will be removed before stitch, so there is no need to do it now
-					projList.Last().prefix = param;
-					m_frame->projListBox->ReloadProject(m_frame->projListBox->GetItemCount()-1,((Project*)&projList.Last()));
+					if(IsFirstInstance)
+						m_frame->ChangePrefix(-1,fn.GetFullPath());
+					else
+						conn->Request(wxT("P ")+fn.GetFullPath());
 					projectSpecified = false;
 				}
 				else //if parameter has a different extension we presume it is a new script file
@@ -223,72 +263,52 @@
 					m_frame->projListBox->Deselect(m_frame->projListBox->GetItemCount()-1);*/
 
 					//we add the new project
-					wxFileName name(param);
-					Project *proj = new Project(param,name.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + name.GetName());
-					projList.Add(proj);
-					m_frame->SetStatusText(_("Added project ")+param);
-					m_frame->projListBox->AppendProject(proj);
+					if(IsFirstInstance)
+						m_frame->AddToList(fn.GetFullPath());
+					else
+						conn->Request(wxT("A ")+fn.GetFullPath());
 					projectSpecified = true;
 				}
 			} //else of if(!fn.HasExt())
 		}
 	}
 
-	if (parser.Found(wxT("d")) ) {
-		XRCCTRL(*m_frame,"cb_delete",wxCheckBox)->SetValue(true);
-		wxConfigBase::Get()->Write(wxT("/BatchFrame/DeleteCheck"), 1);
-    }
-	else{
-		int del = wxConfigBase::Get()->Read(wxT("/BatchFrame/DeleteCheck"), (long)0);
-		if(del==0)
-			XRCCTRL(*m_frame,"cb_delete",wxCheckBox)->SetValue(false);
-		else
-			XRCCTRL(*m_frame,"cb_delete",wxCheckBox)->SetValue(true);
-    }
-	if (parser.Found(wxT("p")) ) {
-		XRCCTRL(*m_frame,"cb_parallel",wxCheckBox)->SetValue(true);
-		wxConfigBase::Get()->Write(wxT("/BatchFrame/ParallelCheck"), 1);
-    }
-	else{
-		int par = wxConfigBase::Get()->Read(wxT("/BatchFrame/ParallelCheck"), (long)0);
-		if(par==0)
-			XRCCTRL(*m_frame,"cb_parallel",wxCheckBox)->SetValue(false);
-		else
-			XRCCTRL(*m_frame,"cb_parallel",wxCheckBox)->SetValue(true);
+	if(IsFirstInstance)
+	{
+		wxConfigBase *config=wxConfigBase::Get();
+		if (parser.Found(wxT("d")))
+			config->Write(wxT("/BatchFrame/DeleteCheck"), 1l);
+		if (parser.Found(wxT("p")))
+			config->Write(wxT("/BatchFrame/ParallelCheck"), 1l);
+		if (parser.Found(wxT("s")))
+			config->Write(wxT("/BatchFrame/ShutdownCheck"), 1l);
+		if (parser.Found(wxT("o")))
+			config->Write(wxT("/BatchFrame/OverwriteCheck"), 1l);
+		if (parser.Found(wxT("v")))
+			config->Write(wxT("/BatchFrame/VerboseCheck"), 1l);
+		config->Flush();
 	}
-	if (parser.Found(wxT("s")) ) {
-		XRCCTRL(*m_frame,"cb_shutdown",wxCheckBox)->SetValue(true);
-		wxConfigBase::Get()->Write(wxT("/BatchFrame/ShutdownCheck"), 1);
-    }
-	else{
-		int shtdwn = wxConfigBase::Get()->Read(wxT("/BatchFrame/ShutdownCheck"), (long)0);
-		if(shtdwn==0)
-			XRCCTRL(*m_frame,"cb_shutdown",wxCheckBox)->SetValue(false);
-		else
-			XRCCTRL(*m_frame,"cb_shutdown",wxCheckBox)->SetValue(true);
-	}
-	if (parser.Found(wxT("o")) ) {
-		XRCCTRL(*m_frame,"cb_overwrite",wxCheckBox)->SetValue(true);
-		wxConfigBase::Get()->Write(wxT("/BatchFrame/OverwriteCheck"), 1);
-    }
-	else{
-		int overwrite = wxConfigBase::Get()->Read(wxT("/BatchFrame/OverwriteCheck"), (long)0);
-		if(overwrite==0)
-			XRCCTRL(*m_frame,"cb_overwrite",wxCheckBox)->SetValue(false);
-		else
-			XRCCTRL(*m_frame,"cb_overwrite",wxCheckBox)->SetValue(true);
-	}
-	if (parser.Found(wxT("v")) ) {
-		XRCCTRL(*m_frame,"cb_verbose",wxCheckBox)->SetValue(true);
-		wxConfigBase::Get()->Write(wxT("/BatchFrame/VerboseCheck"), 1);
-    }
-	else{
-		int overwrite = wxConfigBase::Get()->Read(wxT("/BatchFrame/VerboseCheck"), (long)0);
-		if(overwrite==0)
-			XRCCTRL(*m_frame,"cb_verbose",wxCheckBox)->SetValue(false);
-		else
-			XRCCTRL(*m_frame,"cb_verbose",wxCheckBox)->SetValue(true);
-	}
+	else
+	{
+		if (parser.Found(wxT("d")))
+			conn->Request(wxT("SetDeleteCheck"));
+		if (parser.Found(wxT("p")))
+			conn->Request(wxT("SetParallelCheck"));
+		if (parser.Found(wxT("s")))
+			conn->Request(wxT("SetShutdownCheck"));
+		if (parser.Found(wxT("o")))
+			conn->Request(wxT("SetOverwriteCheck"));
+		if (parser.Found(wxT("v")))
+			conn->Request(wxT("SetVerboseCheck"));
+		conn->Request(wxT("BringWindowToTop"));
+		if(parser.Found(wxT("b")))
+			conn->Request(wxT("RunBatch"));
+		conn->Disconnect();
+		delete conn;
+		delete m_checker;
+		return false;
+	};
+	m_frame->SetCheckboxes();
 	m_frame->PropagateDefaults();
 	if (parser.Found(wxT("b")) ) {
 		m_frame->RunBatch();
@@ -296,6 +316,13 @@
 	return true;
 }
 
+int PTBatcherGUI::OnExit()
+{
+	delete m_checker;
+	delete m_server;
+	return 0;
+}
+
 void PTBatcherGUI::OnItemActivated(wxListEvent &event)
 {
 	wxCommandEvent dummy;
@@ -309,15 +336,12 @@
 	{
 	case WXK_DELETE:	
 		m_frame->OnButtonRemoveFromList(dummy);
-		event.Skip();
 		break;
 	case WXK_INSERT:
 		m_frame->OnButtonAddToList(dummy);
-		event.Skip();
 		break;
 	case WXK_ESCAPE:
 		m_frame->OnButtonCancel(dummy);
-		event.Skip();
 		break;
 	default:
 		event.Skip();
@@ -327,9 +351,65 @@
 }
 
 #ifdef __WXMAC__
-// wx calls this method when the app gets "Open file" AppleEvent 
+// wx calls this method when the app gets "Open file" AppleEvent
 void PTBatcherGUI::MacOpenFile(const wxString &fileName)
 {
     m_macFileNameToOpenOnStart = fileName;
 }
 #endif
+
+wxChar* BatchIPCConnection::OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format)
+{
+	BatchFrame *MyBatchFrame=wxGetApp().GetFrame();
+	if(item.Left(1)==wxT("A"))
+		MyBatchFrame->AddToList(item.Mid(2));
+	if(item.Left(1)==wxT("P"))
+		MyBatchFrame->ChangePrefix(-1,item.Mid(2));
+	wxCommandEvent event;
+	event.SetInt(1);
+	if(item==wxT("SetDeleteCheck"))
+		if(!MyBatchFrame->GetCheckDelete())
+		{
+			MyBatchFrame->OnCheckDelete(event);
+			MyBatchFrame->SetCheckboxes();
+		};
+	if(item==wxT("SetParallelCheck"))
+		if(!MyBatchFrame->GetCheckParallel())
+		{
+			MyBatchFrame->OnCheckParallel(event);
+			MyBatchFrame->SetCheckboxes();
+		};
+	if(item==wxT("SetShutdownCheck"))
+		if(!MyBatchFrame->GetCheckShutdown())
+		{
+			MyBatchFrame->OnCheckShutdown(event);
+			MyBatchFrame->SetCheckboxes();
+		};
+	if(item==wxT("SetOverwriteCheck"))
+		if(!MyBatchFrame->GetCheckOverwrite())
+		{
+			MyBatchFrame->OnCheckOverwrite(event);
+			MyBatchFrame->SetCheckboxes();
+		};
+	if(item==wxT("SetVerboseCheck"))
+		if(!MyBatchFrame->GetCheckVerbose())
+		{
+			MyBatchFrame->OnCheckVerbose(event);
+			MyBatchFrame->SetCheckboxes();
+		};
+	if(item==wxT("BringWindowToTop"))
+		MyBatchFrame->RequestUserAttention();
+	if(item==wxT("RunBatch"))
+	{
+		wxCommandEvent myEvent(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_start"));
+		MyBatchFrame->AddPendingEvent(myEvent);
+	};
+	return wxT("");
+};
+
+wxConnectionBase* BatchIPCServer::OnAcceptConnection (const wxString& topic)
+{
+	if(topic==IPC_START)
+		return new BatchIPCConnection;
+	return NULL;
+};