From c66656c5d4c5a7e1847fe6d3909875fb42cbf763 Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Mon, 8 Feb 2016 20:03:57 -0500 Subject: [PATCH] Open PDF viewer improvements. (fixes lp:1530162) * Fix broken ExecuteCommand() when path contains spaces on OSX. * Only use system defined mime type for PDF files. * Remove system dependent fallback applications for opening PDF files. --- common/gestfich.cpp | 102 ++++++++++---------------------------------- 1 file changed, 22 insertions(+), 80 deletions(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 04f5626af2..3a09576874 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -28,33 +28,26 @@ * @brief Functions for file management */ -// For compilers that support precompilation, includes "wx.h". -#include -#include -#include - -#include -#include -#include - #include #include #include +// For compilers that support precompilation, includes "wx.h". +#include +#include +#include +#include +#include + +#include void AddDelimiterString( wxString& string ) { - wxString text; - if( !string.StartsWith( wxT( "\"" ) ) ) - text = wxT( "\"" ); - - text += string; - - if( (text.Last() != '"' ) || (text.length() <= 1) ) - text += wxT( "\"" ); - - string = text; + { + string.Prepend ( wxT( "\"" ) ); + string.Append ( wxT( "\"" ) ); + } } @@ -227,6 +220,8 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para #ifdef __WXMAC__ else { + AddDelimiterString( fullFileName ); + if( !param.IsEmpty() ) fullFileName += wxT( " " ) + param; @@ -351,8 +346,6 @@ bool OpenPDF( const wxString& file ) { wxString command; wxString filename = file; - wxString type; - bool success = false; Pgm().ReadPdfBrowserInfos(); @@ -363,71 +356,21 @@ bool OpenPDF( const wxString& file ) } else { - wxFileType* filetype = NULL; - wxFileType::MessageParameters params( filename, type ); - filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); + wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) ); if( filetype ) - success = filetype->GetOpenCommand( &command, params ); + command = filetype->GetOpenCommand( filename ); delete filetype; - -#ifndef __WINDOWS__ - - // Bug ? under linux wxWidgets returns acroread as PDF viewer, even if - // it does not exist. - if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround - success = false; -#endif - - if( success && !command.IsEmpty() ) - { - success = ProcessExecute( command ); - - if( success ) - return success; - } - - success = false; - command.clear(); - - if( !success ) - { -#if !defined(__WINDOWS__) - AddDelimiterString( filename ); - - // here is a list of PDF viewers candidates - static const wxChar* tries[] = - { - wxT( "/usr/bin/evince" ), - wxT( "/usr/bin/okular" ), - wxT( "/usr/bin/gpdf" ), - wxT( "/usr/bin/konqueror" ), - wxT( "/usr/bin/kpdf" ), - wxT( "/usr/bin/xpdf" ), - wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener - wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener - }; - - for( unsigned ii = 0; ii" ), GetChars( filename ) ); DisplayError( NULL, msg ); - success = false; } - return success; + return false; }