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.
This commit is contained in:
parent
14363262c2
commit
c66656c5d4
|
@ -28,33 +28,26 @@
|
||||||
* @brief Functions for file management
|
* @brief Functions for file management
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
|
||||||
#include <fctsys.h>
|
|
||||||
#include <pgm_base.h>
|
|
||||||
#include <confirm.h>
|
|
||||||
|
|
||||||
#include <common.h>
|
|
||||||
#include <macros.h>
|
|
||||||
#include <gestfich.h>
|
|
||||||
|
|
||||||
#include <wx/mimetype.h>
|
#include <wx/mimetype.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include <fctsys.h>
|
||||||
|
#include <pgm_base.h>
|
||||||
|
#include <confirm.h>
|
||||||
|
#include <common.h>
|
||||||
|
#include <macros.h>
|
||||||
|
|
||||||
|
#include <gestfich.h>
|
||||||
|
|
||||||
void AddDelimiterString( wxString& string )
|
void AddDelimiterString( wxString& string )
|
||||||
{
|
{
|
||||||
wxString text;
|
|
||||||
|
|
||||||
if( !string.StartsWith( wxT( "\"" ) ) )
|
if( !string.StartsWith( wxT( "\"" ) ) )
|
||||||
text = wxT( "\"" );
|
{
|
||||||
|
string.Prepend ( wxT( "\"" ) );
|
||||||
text += string;
|
string.Append ( wxT( "\"" ) );
|
||||||
|
}
|
||||||
if( (text.Last() != '"' ) || (text.length() <= 1) )
|
|
||||||
text += wxT( "\"" );
|
|
||||||
|
|
||||||
string = text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,6 +220,8 @@ int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& para
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
AddDelimiterString( fullFileName );
|
||||||
|
|
||||||
if( !param.IsEmpty() )
|
if( !param.IsEmpty() )
|
||||||
fullFileName += wxT( " " ) + param;
|
fullFileName += wxT( " " ) + param;
|
||||||
|
|
||||||
|
@ -351,8 +346,6 @@ bool OpenPDF( const wxString& file )
|
||||||
{
|
{
|
||||||
wxString command;
|
wxString command;
|
||||||
wxString filename = file;
|
wxString filename = file;
|
||||||
wxString type;
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
Pgm().ReadPdfBrowserInfos();
|
Pgm().ReadPdfBrowserInfos();
|
||||||
|
|
||||||
|
@ -363,71 +356,21 @@ bool OpenPDF( const wxString& file )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxFileType* filetype = NULL;
|
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) );
|
||||||
wxFileType::MessageParameters params( filename, type );
|
|
||||||
filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) );
|
|
||||||
|
|
||||||
if( filetype )
|
if( filetype )
|
||||||
success = filetype->GetOpenCommand( &command, params );
|
command = filetype->GetOpenCommand( filename );
|
||||||
|
|
||||||
delete filetype;
|
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<DIM(tries); ii++ )
|
|
||||||
{
|
|
||||||
if( wxFileExists( tries[ii] ) )
|
|
||||||
{
|
|
||||||
command = tries[ii];
|
|
||||||
command += wxT( ' ' );
|
|
||||||
command += filename;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !command.IsEmpty() )
|
if( !command.IsEmpty() )
|
||||||
{
|
{
|
||||||
success = ProcessExecute( command );
|
if( ProcessExecute( command ) )
|
||||||
|
{
|
||||||
if( !success )
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ),
|
msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ),
|
||||||
|
@ -440,10 +383,9 @@ bool OpenPDF( const wxString& file )
|
||||||
wxString msg;
|
wxString msg;
|
||||||
msg.Printf( _( "Unable to find a PDF viewer for <%s>" ), GetChars( filename ) );
|
msg.Printf( _( "Unable to find a PDF viewer for <%s>" ), GetChars( filename ) );
|
||||||
DisplayError( NULL, msg );
|
DisplayError( NULL, msg );
|
||||||
success = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue