Commit ba92f94f authored by dickelbeck's avatar dickelbeck

ProcessExecute instead of wxExecute

parent 080746ac
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "common.h" #include "common.h"
#include "macros.h" #include "macros.h"
#include "build_version.h" #include "build_version.h"
#include <wx/process.h>
/*****************************/ /*****************************/
wxString GetBuildVersion() wxString GetBuildVersion()
...@@ -30,7 +30,9 @@ Ki_PageDescr::Ki_PageDescr( const wxSize& size, const wxPoint& offset, const wxS ...@@ -30,7 +30,9 @@ Ki_PageDescr::Ki_PageDescr( const wxSize& size, const wxPoint& offset, const wxS
/*********************************************************************************************/ /*********************************************************************************************/
{ {
// All sizes are in 1/1000 inch // All sizes are in 1/1000 inch
m_Size = size; m_Offset = offset, m_Name = name; m_Size = size;
m_Offset = offset;
m_Name = name;
// Adjust the default value for margins to 400 mils (0,4 inch or 10 mm) // Adjust the default value for margins to 400 mils (0,4 inch or 10 mm)
m_LeftMargin = m_RightMargin = m_TopMargin = m_BottomMargin = 400; m_LeftMargin = m_RightMargin = m_TopMargin = m_BottomMargin = 400;
...@@ -205,6 +207,7 @@ wxString GenDate() ...@@ -205,6 +207,7 @@ wxString GenDate()
wxT( "jan" ), wxT( "feb" ), wxT( "mar" ), wxT( "apr" ), wxT( "may" ), wxT( "jun" ), wxT( "jan" ), wxT( "feb" ), wxT( "mar" ), wxT( "apr" ), wxT( "may" ), wxT( "jun" ),
wxT( "jul" ), wxT( "aug" ), wxT( "sep" ), wxT( "oct" ), wxT( "nov" ), wxT( "dec" ) wxT( "jul" ), wxT( "aug" ), wxT( "sep" ), wxT( "oct" ), wxT( "nov" ), wxT( "dec" )
}; };
time_t buftime; time_t buftime;
struct tm* Date; struct tm* Date;
wxString string_date; wxString string_date;
...@@ -241,6 +244,14 @@ void* MyMalloc( size_t nb_octets ) ...@@ -241,6 +244,14 @@ void* MyMalloc( size_t nb_octets )
} }
bool ProcessExecute( const wxString& aCommandLine, int aFlags )
{
wxProcess* process = wxProcess::Open( aCommandLine, aFlags );
return process != NULL;
}
/************************************/ /************************************/
void* MyZMalloc( size_t nb_octets ) void* MyZMalloc( size_t nb_octets )
/************************************/ /************************************/
......
/***************/ /***************/
/* eda_doc.cpp */ /* eda_doc.cpp */
/***************/ /***************/
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
...@@ -24,239 +24,258 @@ ...@@ -24,239 +24,258 @@
/*****************************************/ /*****************************************/
void WinEDA_App::ReadPdfBrowserInfos() void WinEDA_App::ReadPdfBrowserInfos()
/*****************************************/ /*****************************************/
/* Read from Common config the Pdf browser choice /* Read from Common config the Pdf browser choice
*/ */
{ {
if ( m_EDA_CommonConfig ) if( m_EDA_CommonConfig )
{ {
m_PdfBrowserIsDefault = m_EDA_CommonConfig->Read(wxT("PdfBrowserIsDefault"), TRUE); m_PdfBrowserIsDefault = m_EDA_CommonConfig->Read( wxT( "PdfBrowserIsDefault" ), TRUE );
m_PdfBrowser = m_EDA_CommonConfig->Read(wxT("PdfBrowserName"), wxEmptyString); m_PdfBrowser = m_EDA_CommonConfig->Read( wxT( "PdfBrowserName" ), wxEmptyString );
} }
if ( m_PdfBrowser.IsEmpty() ) m_PdfBrowserIsDefault = TRUE; if( m_PdfBrowser.IsEmpty() )
m_PdfBrowserIsDefault = TRUE;
} }
/*****************************************/ /*****************************************/
void WinEDA_App::WritePdfBrowserInfos() void WinEDA_App::WritePdfBrowserInfos()
/*****************************************/ /*****************************************/
/* Write into Common config the Pdf browser choice /* Write into Common config the Pdf browser choice
*/ */
{ {
if ( ! m_EDA_CommonConfig ) return; if( !m_EDA_CommonConfig )
if ( m_PdfBrowser.IsEmpty() ) m_PdfBrowserIsDefault = TRUE; return;
m_EDA_CommonConfig->Write(wxT("PdfBrowserIsDefault"), m_PdfBrowserIsDefault); if( m_PdfBrowser.IsEmpty() )
m_EDA_CommonConfig->Write(wxT("PdfBrowserName"), m_PdfBrowser); m_PdfBrowserIsDefault = TRUE;
m_EDA_CommonConfig->Write( wxT( "PdfBrowserIsDefault" ), m_PdfBrowserIsDefault );
m_EDA_CommonConfig->Write( wxT( "PdfBrowserName" ), m_PdfBrowser );
} }
// Mime type extensions // Mime type extensions
static wxMimeTypesManager * mimeDatabase; static wxMimeTypesManager* mimeDatabase;
static const wxFileTypeInfo EDAfallbacks[] = static const wxFileTypeInfo EDAfallbacks[] =
{ {
wxFileTypeInfo(wxT("text/pdf"), wxFileTypeInfo( wxT( "text/pdf" ),
wxT("xpdf %s"), wxT( "xpdf %s" ),
wxT("xpdf -p %s"), wxT( "xpdf -p %s" ),
wxT("pdf document (from Kicad)"), wxT( "pdf document (from Kicad)" ),
wxT("pdf"), wxT("PDF"), NULL), wxT( "pdf" ), wxT( "PDF" ), NULL ),
wxFileTypeInfo(wxT("text/html"), wxFileTypeInfo( wxT( "text/html" ),
wxT("wxhtml %s"), wxT( "wxhtml %s" ),
wxT("wxhtml %s"), wxT( "wxhtml %s" ),
wxT("html document (from Kicad)"), wxT( "html document (from Kicad)" ),
wxT("htm"), wxT("html"), NULL), wxT( "htm" ), wxT( "html" ), NULL ),
wxFileTypeInfo(wxT("application/sch"), wxFileTypeInfo( wxT( "application/sch" ),
wxT("eeschema %s"), wxT( "eeschema %s" ),
wxT("eeschema -p %s"), wxT( "eeschema -p %s" ),
wxT("sch document (from Kicad)"), wxT( "sch document (from Kicad)" ),
wxT("sch"), wxT("SCH"), NULL), wxT( "sch" ), wxT( "SCH" ), NULL ),
// must terminate the table with this!
wxFileTypeInfo() // must terminate the table with this!
wxFileTypeInfo()
}; };
/********************************************************************/ /********************************************************************/
bool GetAssociatedDocument(wxFrame * frame, const wxString & LibPath, bool GetAssociatedDocument( wxFrame* frame, const wxString& LibPath,
const wxString & DocName) const wxString& DocName )
/*********************************************************************/ /*********************************************************************/
/* Launch the viewer for the doc file DocName (mime type)
LibPath is the doc file search path:
(kicad/library)
DocName is the short filename with ext. Wildcarts are allowed
Seach file is made in LibPath/doc/DocName
if DocName is starting by http: or ftp: or www. the default internet browser is launched /* Launch the viewer for the doc file DocName (mime type)
*/ * LibPath is the doc file search path:
* (kicad/library)
* DocName is the short filename with ext. Wildcarts are allowed
* Seach file is made in LibPath/doc/DocName
*
* if DocName is starting by http: or ftp: or www. the default internet browser is launched
*/
{ {
wxString docpath, fullfilename; wxString docpath, fullfilename;
wxString Line; wxString Line;
wxString command; wxString command;
bool success = FALSE; bool success = FALSE;
// Is an internet url // Is an internet url
wxString url_header[3] = {wxT("http:"), wxT("ftp:"),wxT("www.") }; static const wxString url_header[3] = { wxT( "http:" ), wxT( "ftp:" ), wxT( "www." ) };
for ( int ii = 0; ii < 3; ii ++ )
{ for( int ii = 0; ii < 3; ii++ )
if ( DocName.First(url_header[ii]) == 0 ) //. seems an internet url {
{ if( DocName.First( url_header[ii] ) == 0 ) //. seems an internet url
wxLaunchDefaultBrowser(DocName); {
return TRUE; wxLaunchDefaultBrowser( DocName );
} return TRUE;
} }
}
/* Compute the full file name */
if ( wxIsAbsolutePath(DocName) ) fullfilename = DocName; /* Compute the full file name */
else if( wxIsAbsolutePath( DocName ) )
{ fullfilename = DocName;
docpath = LibPath + wxT("doc/"); else
fullfilename = docpath + DocName; {
} docpath = LibPath + wxT( "doc/" );
fullfilename = docpath + DocName;
}
#ifdef __WINDOWS__ #ifdef __WINDOWS__
fullfilename.Replace(UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP); fullfilename.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
#else #else
fullfilename.Replace(WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP); fullfilename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
#endif #endif
wxString mask(wxT("*")), extension; wxString mask( wxT( "*" ) ), extension;
#ifdef __WINDOWS__ #ifdef __WINDOWS__
mask += wxT(".*"); mask += wxT( ".*" );
extension = wxT(".*"); extension = wxT( ".*" );
#endif #endif
if ( wxIsWild(fullfilename) ) if( wxIsWild( fullfilename ) )
{ {
fullfilename = fullfilename =
EDA_FileSelector(_("Doc Files"), /* Titre de la fenetre */ EDA_FileSelector( _( "Doc Files" ), /* Titre de la fenetre */
wxPathOnly(fullfilename), /* Chemin par defaut */ wxPathOnly( fullfilename ), /* Chemin par defaut */
fullfilename, /* nom fichier par defaut */ fullfilename, /* nom fichier par defaut */
extension, /* extension par defaut */ extension, /* extension par defaut */
mask, /* Masque d'affichage */ mask, /* Masque d'affichage */
frame, /* parent frame */ frame, /* parent frame */
wxFD_OPEN, /* wxSAVE, wxFD_OPEN ..*/ wxFD_OPEN, /* wxSAVE, wxFD_OPEN ..*/
TRUE, /* true = ne change pas le repertoire courant */ TRUE, /* true = ne change pas le repertoire courant */
wxPoint(-1,-1) wxPoint( -1, -1 )
); );
if ( fullfilename.IsEmpty() ) return FALSE; if( fullfilename.IsEmpty() )
} return FALSE;
}
if ( ! wxFileExists(fullfilename) )
{ if( !wxFileExists( fullfilename ) )
Line = _("Doc File ") + fullfilename + _(" not found"); {
DisplayError(frame, Line); Line = _( "Doc File " ) + fullfilename + _( " not found" );
return FALSE; DisplayError( frame, Line );
} return FALSE;
}
/* Try to launch some browser (usefull under linux) */
g_EDA_Appl->ReadPdfBrowserInfos(); /* Try to launch some browser (usefull under linux) */
if ( g_EDA_Appl->m_PdfBrowserIsDefault ) g_EDA_Appl->ReadPdfBrowserInfos();
{ if( g_EDA_Appl->m_PdfBrowserIsDefault )
wxFileType * filetype; {
wxFileName CurrentFileName(fullfilename); wxFileType* filetype;
wxString ext, type; wxFileName CurrentFileName( fullfilename );
ext = CurrentFileName.GetExt();
filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); wxString ext, type;
ext = CurrentFileName.GetExt();
if ( ! filetype ) // 2ieme tentative filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
{
mimeDatabase = new wxMimeTypesManager; if( !filetype ) // 2ieme tentative
mimeDatabase->AddFallbacks(EDAfallbacks); {
filetype = mimeDatabase->GetFileTypeFromExtension(ext); mimeDatabase = new wxMimeTypesManager;
delete mimeDatabase; mimeDatabase->AddFallbacks( EDAfallbacks );
mimeDatabase = NULL; filetype = mimeDatabase->GetFileTypeFromExtension( ext );
} delete mimeDatabase;
mimeDatabase = NULL;
if ( filetype ) }
{
wxFileType::MessageParameters params(fullfilename, type); if( filetype )
success = filetype->GetOpenCommand( &command, params); {
delete filetype; wxFileType::MessageParameters params( fullfilename, type );
if ( success ) wxExecute(command);
} success = filetype->GetOpenCommand( &command, params );
delete filetype;
if ( ! success) if( success )
{ ProcessExecute( command );
#ifdef __LINUX__ }
if ( ext == wxT("pdf") )
{ if( !success )
success = TRUE; command.Empty(); {
if ( wxFileExists( wxT("/usr/bin/xpdf")) ) #ifdef __LINUX__
command = wxT("xpdf ") + fullfilename; if( ext == wxT( "pdf" ) )
else if ( wxFileExists( wxT("/usr/bin/konqueror") )) {
command = wxT("konqueror ") + fullfilename; success = TRUE; command.Empty();
else if ( wxFileExists( wxT("/usr/bin/gpdf") )) if( wxFileExists( wxT( "/usr/bin/kpdf" ) ) )
command = wxT("gpdf ") + fullfilename; command = wxT( "xpdf " ) + fullfilename;
if ( command.IsEmpty() ) // not started else if( wxFileExists( wxT( "/usr/bin/konqueror" ) ) )
{ command = wxT( "konqueror " ) + fullfilename;
DisplayError(frame, else if( wxFileExists( wxT( "/usr/bin/gpdf" ) ) )
_(" Cannot find the PDF viewer (xpdf, gpdf or konqueror) in /usr/bin/") ); command = wxT( "gpdf " ) + fullfilename;
success = FALSE; if( command.IsEmpty() ) // not started
} {
else wxExecute(command); DisplayError( frame,
} _( " Cannot find the PDF viewer (kpdf, gpdf or konqueror) in /usr/bin/" ) );
else success = FALSE;
#endif }
{ else
Line.Printf( _("Unknown MIME type for Doc File [%s] (%s)"), ProcessExecute( command );
fullfilename.GetData(), ext.GetData()); }
DisplayError(frame, Line); else
} #endif
} {
} Line.Printf( _( "Unknown MIME type for Doc File [%s] (%s)" ),
fullfilename.GetData(), ext.GetData() );
else DisplayError( frame, Line );
{ }
command = g_EDA_Appl->m_PdfBrowser; }
if ( wxFileExists(command) ) }
{ else
success = TRUE; {
AddDelimiterString(fullfilename); command = g_EDA_Appl->m_PdfBrowser;
command += wxT(" ") + fullfilename; if( wxFileExists( command ) )
wxExecute(command); {
} success = TRUE;
AddDelimiterString( fullfilename );
else command += wxT( " " ) + fullfilename;
{ ProcessExecute( command );
Line.Printf( _("Cannot find Pdf viewer %s"), command.GetData()); }
DisplayError(frame, Line); else
} {
} Line.Printf( _( "Cannot find Pdf viewer %s" ), command.GetData() );
DisplayError( frame, Line );
return success; }
}
return success;
} }
/******************************************************************/ /******************************************************************/
int KeyWordOk(const wxString & KeyList, const wxString & Database ) int KeyWordOk( const wxString& KeyList, const wxString& Database )
/******************************************************************/ /******************************************************************/
/* Recherche si dans le texte Database on retrouve tous les mots /* Recherche si dans le texte Database on retrouve tous les mots
cles donnes dans KeyList ( KeyList = suite de mots cles * cles donnes dans KeyList ( KeyList = suite de mots cles
separes par des espaces * separes par des espaces
Retourne: * Retourne:
0 si aucun mot cle trouv * 0 si aucun mot cle trouv
1 si mot cle trouv * 1 si mot cle trouv
*/ */
{ {
wxString KeysCopy, DataList; wxString KeysCopy, DataList;
if( KeyList.IsEmpty() ) return(0); if( KeyList.IsEmpty() )
return 0;
KeysCopy = KeyList; KeysCopy.MakeUpper();
DataList = Database; DataList.MakeUpper(); KeysCopy = KeyList; KeysCopy.MakeUpper();
DataList = Database; DataList.MakeUpper();
wxStringTokenizer Token(KeysCopy, wxT(" \n\r"));
while ( Token.HasMoreTokens() ) wxStringTokenizer Token( KeysCopy, wxT( " \n\r" ) );
{
wxString Key = Token.GetNextToken();
// Search Key in Datalist:
wxStringTokenizer Data(DataList, wxT(" \n\r"));
while ( Data.HasMoreTokens() )
{
wxString word = Data.GetNextToken();
if ( word == Key ) return 1; // Key found !
}
}
// keyword not found
return(0);
}
while( Token.HasMoreTokens() )
{
wxString Key = Token.GetNextToken();
// Search Key in Datalist:
wxStringTokenizer Data( DataList, wxT( " \n\r" ) );
while( Data.HasMoreTokens() )
{
wxString word = Data.GetNextToken();
if( word == Key )
return 1; // Key found !
}
}
// keyword not found
return 0;
}
...@@ -533,7 +533,7 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para ...@@ -533,7 +533,7 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para
{ {
if( !param.IsEmpty() ) if( !param.IsEmpty() )
FullFileName += wxT( " " ) + param; FullFileName += wxT( " " ) + param;
wxExecute( FullFileName ); ProcessExecute( FullFileName );
return 0; return 0;
} }
...@@ -748,7 +748,7 @@ void OpenPDF( const wxString& file ) ...@@ -748,7 +748,7 @@ void OpenPDF( const wxString& file )
} }
if( !command.IsEmpty() ) if( !command.IsEmpty() )
wxExecute( command ); ProcessExecute( command );
} }
...@@ -771,5 +771,5 @@ void OpenFile( const wxString& file ) ...@@ -771,5 +771,5 @@ void OpenFile( const wxString& file )
delete filetype; delete filetype;
if( success && !command.IsEmpty() ) if( success && !command.IsEmpty() )
wxExecute( command ); ProcessExecute( command );
} }
...@@ -342,7 +342,7 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, ...@@ -342,7 +342,7 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame,
CommandFile += wxT( " " ) + TmpFullFileName; CommandFile += wxT( " " ) + TmpFullFileName;
CommandFile += wxT( " " ) + FullFileName; CommandFile += wxT( " " ) + FullFileName;
wxExecute( CommandFile, wxEXEC_SYNC ); ProcessExecute( CommandFile, wxEXEC_SYNC );
} }
......
...@@ -354,6 +354,18 @@ class WinEDA_DrawPanel; ...@@ -354,6 +354,18 @@ class WinEDA_DrawPanel;
/* COMMON.CPP */ /* COMMON.CPP */
/**
* Function ProcessExecute
* runs a child process.
* @param aCommandLine The process and any arguments to it all in a single string.
* @param aFlags The same args as allowed for wxExecute()
* @return bool - true if success, else false
*/
bool ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC );
wxString ReturnPcbLayerName( int layer_number, bool is_filename = FALSE ); wxString ReturnPcbLayerName( int layer_number, bool is_filename = FALSE );
/* Return the name of the layer number "layer_number". /* Return the name of the layer number "layer_number".
...@@ -431,10 +443,10 @@ wxString MakeFileName( const wxString& dir, ...@@ -431,10 +443,10 @@ wxString MakeFileName( const wxString& dir,
* dir = prefixe (chemin) * dir = prefixe (chemin)
* shortname = nom avec ou sans chemin ou extension * shortname = nom avec ou sans chemin ou extension
* ext = extension * ext = extension
* *
* si la chaine name possede deja un chemin ou une extension, elles * si la chaine name possede deja un chemin ou une extension, elles
* ne seront pas modifiees * ne seront pas modifiees
* *
* retourne la chaine calculee */ * retourne la chaine calculee */
wxString MakeReducedFileName( const wxString& fullfilename, wxString MakeReducedFileName( const wxString& fullfilename,
...@@ -445,12 +457,12 @@ wxString MakeReducedFileName( const wxString& fullfilename, ...@@ -445,12 +457,12 @@ wxString MakeReducedFileName( const wxString& fullfilename,
* fullfilename = nom complet * fullfilename = nom complet
* default_path = prefixe (chemin) par defaut * default_path = prefixe (chemin) par defaut
* default_ext = extension par defaut * default_ext = extension par defaut
* *
* retourne le nom reduit, c'est a dire: * retourne le nom reduit, c'est a dire:
* sans le chemin si le chemin est default_path * sans le chemin si le chemin est default_path
* avec ./ si si le chemin est le chemin courant * avec ./ si si le chemin est le chemin courant
* sans l'extension si l'extension est default_ext * sans l'extension si l'extension est default_ext
* *
* Renvoie un chemin en notation unix ('/' en separateur de repertoire) * Renvoie un chemin en notation unix ('/' en separateur de repertoire)
*/ */
......
...@@ -305,7 +305,7 @@ void dialog_freeroute_exchange::OnButton5Click( wxCommandEvent& event ) ...@@ -305,7 +305,7 @@ void dialog_freeroute_exchange::OnButton5Click( wxCommandEvent& event )
if( wxFileExists( FullFileName ) ) if( wxFileExists( FullFileName ) )
{ {
command << wxT("javaws") << wxT( " " ) + FullFileName; command << wxT("javaws") << wxT( " " ) + FullFileName;
wxExecute( command ); ProcessExecute( command );
return; return;
} }
......
...@@ -134,7 +134,7 @@ void WinEDA_PcbFrame::GlobalRoute( wxDC* DC ) ...@@ -134,7 +134,7 @@ void WinEDA_PcbFrame::GlobalRoute( wxDC* DC )
Affiche_Message( ExecFileName ); Affiche_Message( ExecFileName );
wxExecute( ExecFileName ); ProcessExecute( ExecFileName );
#else #else
wxMessageBox( wxT( "TODO, currently not available" ) ); wxMessageBox( wxT( "TODO, currently not available" ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment