[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : phil
Repository : xara
Revision   : 1137
Date       : Fri May 19 18:29:23 BST 2006

Changed paths:
   M /Trunk/XaraLX/wxOil/camelot.cpp
   M /Trunk/XaraLX/wxOil/camelot.h
   M /Trunk/XaraLX/wxOil/camprocess.cpp
   M /Trunk/XaraLX/wxOil/camprocess.h

Launch Help HTML file into selected HTML browsers.
Note that the browser window does not necessarilly come to the top...


Diff:
Index: Trunk/XaraLX/wxOil/camelot.h
===================================================================
--- Trunk/XaraLX/wxOil/camelot.h	(revision 1136)
+++ Trunk/XaraLX/wxOil/camelot.h	(revision 1137)
@@ -160,6 +160,8 @@
 	wxTimer				m_Timer;
 
 private:
+	BOOL LaunchHelpApp(const wxString& strAppName, wxString strCommand);
+
 	static DialogManager m_DlgMgr; 		// The dialog manager handles all oily dialog functions
 
 	static BOOL InInitOrDeInit;
Index: Trunk/XaraLX/wxOil/camprocess.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camprocess.cpp	(revision 1136)
+++ Trunk/XaraLX/wxOil/camprocess.cpp	(revision 1137)
@@ -335,3 +335,204 @@
 
 	ProcessStdErr();
 }
+
+
+
+
+/*****************************************************************************************
+
+	class CamLaunchProcess implementation
+
+*****************************************************************************************/
+
+/********************************************************************************************
+
+>	CamLaunchProcess::CamLaunchProcess()
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		-
+	Outputs:	-
+	Returns:	-
+	Purpose:	CamLaunchProcess constructor
+
+********************************************************************************************/
+CamLaunchProcess::CamLaunchProcess()
+{
+	m_pid = 0;
+	m_bDead = true;
+	m_ReturnCode = -1;
+	m_bConnected = false;
+}
+
+
+/********************************************************************************************
+
+>	CamLaunchProcess::~CamLaunchProcess()
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		-
+	Outputs:	-
+	Returns:	-
+	Purpose:	CamLaunchProcess destructor
+
+********************************************************************************************/
+CamLaunchProcess::~CamLaunchProcess()
+{
+	if (m_bConnected)
+	{
+		TRACEUSER("Phil", _T("Process still connected in ~CamLaunchProcess"));
+		Disconnect();
+	}
+}
+
+
+/********************************************************************************************
+
+>	virtual BOOL CamLaunchProcess::Execute(const wxString& cmd)
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		cmd - The command string including parameters
+	Outputs:	-
+	Returns:	TRUE if the command was launched successfully
+				FALSE otherwise
+	Purpose:	Execute a command which should launch a long-running process
+
+********************************************************************************************/
+BOOL CamLaunchProcess::Execute(const wxString& cmd)
+{
+	m_ReturnCode = 0;		// Assume success until we find otherwise
+
+	TRACEUSER("Phil", _T("Executing %s
"), (LPCTSTR) cmd);
+	m_pid = wxExecute(cmd, wxEXEC_ASYNC, this);
+	if (m_pid==0)
+	{
+		// Couldn't even create a process for the command!
+		m_bDead = true;
+		return FALSE;
+	}
+
+	// We're now running
+	m_bDead = false;
+	m_bConnected = true;
+
+	// Give the command 100 milliseconds to return an error condition or die...
+	// After that we will either use the return code it passed back to OnTerminate
+	// or assume it is running successfully...
+	MonotonicTime graceperiod;
+	while (!m_bDead && m_ReturnCode==0 && !graceperiod.Elapsed(100))
+	{
+		ProcessStdErr();		// Process any output on stderr
+		wxMilliSleep(1);
+		wxYield();
+	}
+
+	TRACEUSER("Phil", _T("Exiting with %d
"), m_ReturnCode);
+	return (m_ReturnCode==0);
+}
+
+
+/********************************************************************************************
+
+>	UINT32 CamLaunchProcess::Disconnect()
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		-
+	Outputs:	-
+	Returns:	ProcessID of the process we have just allowed to live
+	Purpose:	Allow a process to continue to run after this object is destroyed
+
+********************************************************************************************/
+INT32 CamLaunchProcess::Disconnect()
+{
+	INT32 pid = m_pid;
+
+	m_pid = 0;
+	m_bConnected = false;
+	Detach();
+
+	return pid;
+}
+
+
+/********************************************************************************************
+
+>	wxKillError CamLaunchProcess::Terminate()
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		-
+	Outputs:	-
+	Returns:	wxKillError enum giving result of termination
+	Purpose:	Kill the process
+
+********************************************************************************************/
+wxKillError CamLaunchProcess::Terminate()
+{
+	if (!m_bDead)
+		return Kill(m_pid, wxSIGTERM);
+
+	return wxKILL_OK;
+}
+
+
+/********************************************************************************************
+
+>	void CamLaunchProcess::ProcessStdErr()
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+				Gerry_Iles (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		-
+	Outputs:	-
+	Returns:	-
+	Purpose:	Process anything the process writes to the error stream
+
+********************************************************************************************/
+void CamLaunchProcess::ProcessStdErr()
+{
+	if (IsErrorAvailable())
+	{
+		wxTextInputStream tis(*GetErrorStream());
+
+		// This assumes that the output is always line buffered
+		while (!GetErrorStream()->Eof())
+		{
+			wxString line;
+			line << tis.ReadLine();
+			TRACEUSER("Phil", _T("(stderr):%s
"), line.c_str());
+		}
+
+		m_ReturnCode = 42;		// Signal failure
+	}
+}
+
+
+/********************************************************************************************
+
+>	void CamLaunchProcess::OnTerminate(int pid, int status)
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Inputs:		-
+	Outputs:	-
+	Returns:	-
+	Purpose:	Process anything the process writes to the error stream
+
+********************************************************************************************/
+void CamLaunchProcess::OnTerminate(int /*TYPENOTE: Correct*/ pid, int /*TYPENOTE: Correct*/ status)
+{
+	ProcessStdErr();
+
+	TRACEUSER("Phil", _T("CamProcess::OnTerminate pid = %d  status = %d
"), pid, status);
+	m_bDead = true;
+	m_ReturnCode = status;
+	m_bConnected = false;
+}
+
+
+
+
Index: Trunk/XaraLX/wxOil/camelot.cpp
===================================================================
--- Trunk/XaraLX/wxOil/camelot.cpp	(revision 1136)
+++ Trunk/XaraLX/wxOil/camelot.cpp	(revision 1137)
@@ -132,6 +132,8 @@
 #include "progress.h"
 #include "gbrush.h"
 
+#include "camprocess.h"
+
 //
 // Define FILELIST for recent file list on file menu.
 // Note that this currently seems to be rather unreliable.
@@ -1300,8 +1302,8 @@
 {
 	// Get the locale id
 	wxString	strLocale( setlocale( LC_MESSAGES, NULL ), wxConvUTF8 );
-	INT32			ordSep = strLocale.Find( _T('_' ) );
-	if( -1 != ordSep )
+	INT32		ordSep = strLocale.Find( _T('_' ) );
+	if ( -1 != ordSep )
 		strLocale = strLocale.Left( ordSep );
 	TRACEUSER( "jlh92", _T("Locale = %s
"), PCTSTR(strLocale) );
 	
@@ -1318,37 +1320,97 @@
 	if( wxDir::Exists( strHelpPath + strLocale ) )
 		strHelpPath += strLocale + _T("/");
 	else
-	if( wxDir::Exists( strHelpPath + _T("en") ) )
-		strHelpPath += strLocale + _T("en/");
-	else
 	{
-		// We'll try default location under debug to make life easier
+		if( wxDir::Exists( strHelpPath + _T("en") ) )
+			strHelpPath += _T("en/");
 #if defined(_DEBUG)
-		strHelpPath = _T("/usr/share/xaralx/doc/en/");
-		TRACEUSER( "jlh92", _T("Try = \"%s\"
"), PCTSTR(strHelpPath) );
-		if( !wxDir::Exists( strHelpPath ) )
-#endif
+		else
 		{
-			ERROR1RAW( _R(IDS_MISSING_HELPDIR) );
-			return;
+			// We'll try default location under debug to make life easier
+			strHelpPath = _T("/usr/share/xaralx/doc/en/");
+			TRACEUSER( "jlh92", _T("Try = \"%s\"
"), PCTSTR(strHelpPath) );
 		}
+#endif
 	}
 
 	// Build full path
-	wxString	strUrl;
-	strUrl += strHelpPath;
+	wxString strUrl;
+	strUrl = strHelpPath;
 	strUrl += _T("xaralx.htm");
-	if( !wxFile::Exists( strUrl ) )
+	if (!wxFile::Exists(strUrl))
 	{
-		ERROR1RAW( _R(IDS_MISSING_HELPINDEX) );
-		return;
+		// Complete failure to find any local help files
+		// So go to the web site...
+		strUrl = _T("http://www.xaralx.org";);
 	}
+	else
+	{
+		// Build the complete URL and launch browser
+		strUrl.Prepend(_T("file://"));
+	}
 
-	// Build the complete URL and launch browser
-	strUrl.Prepend( _T("file://") );
+	// --------------------------------------------------------------------------------------
+	// Attempt to launch common browsers to cope with our rich, Javascripted, HTML help files
+	BOOL ok;
+
+	ok = LaunchHelpApp(_T("viewhtml"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("firefox"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("mozilla"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("konqueror"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("gnome-www-default-browser"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("epiphany"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("opera"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("iexplore"), strUrl);
+	if (ok) return;
+
+	ok = LaunchHelpApp(_T("safari"), strUrl);
+	if (ok) return;
+
 	wxLaunchDefaultBrowser( strUrl );
 }
 
+BOOL CCamApp::LaunchHelpApp(const wxString& strAppName, wxString strCommand)
+{
+	strCommand.Prepend(_T(" "));
+	strCommand.Prepend(strAppName);
+
+	CamLaunchProcess* plp = new CamLaunchProcess();
+	if (plp==NULL)
+		return FALSE;
+
+	BOOL ok = plp->Execute(strCommand);
+
+	if (ok)
+	{
+		// Let this process run free!
+		plp->Disconnect();
+//		delete plp;								// This object will allegedly delete itself when the process dies
+	}
+	else
+	{
+		// Make sure we don't leave any zombie processes lying around
+		wxKillError e = plp->Terminate();		// This should result in a call to OnTerminate
+		TRACEUSER("Phil", _T("Terminating bad process returned %d
"), e);
+//		delete plp;								// This object will allegedly delete itself when the process dies
+	}
+
+	return ok;
+}
+
 /***************************************************************************************************************************/
 
 
Index: Trunk/XaraLX/wxOil/camprocess.h
===================================================================
--- Trunk/XaraLX/wxOil/camprocess.h	(revision 1136)
+++ Trunk/XaraLX/wxOil/camprocess.h	(revision 1137)
@@ -132,4 +132,42 @@
 	INT32 m_BytesOut;
 };
 
+
+/********************************************************************************************
+
+>	class CamLaunchProcess : public wxProcess
+
+	Author:		Phil_Martin (Xara Group Ltd) <camelotdev@xxxxxxxx>
+	Created:	19/May/2006
+	Base Class:	wxProcess
+	Purpose:	Launch a long-running asynchronous process
+	SeeAlso:	CamProcess, wxProcess
+
+********************************************************************************************/
+
+class CamLaunchProcess : public wxProcess
+{
+public:
+	CamLaunchProcess();
+	virtual ~CamLaunchProcess();
+
+	BOOL 		Execute(const wxString& cmd);
+	wxKillError Terminate();
+	virtual 	INT32 Disconnect();
+
+	virtual 	void OnTerminate(int /*TYPENOTE: Correct*/ pid, int /*TYPENOTE: Correct*/ status);
+
+protected:
+	// These are called to handle the various streams
+	// StdIn and StdOut are only called when a file isn't being used
+	virtual 	void ProcessStdErr();
+
+protected:
+	bool		m_bDead;
+	bool		m_bConnected;
+	INT32 		m_ReturnCode;
+	INT32 		m_pid;
+};
+
+
 #endif // INC_CAMPROCESS


Xara