mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Use desktop services to open all types of files but the audio ones.
This commit is contained in:
parent
e3bb365473
commit
71c736f35f
|
@ -168,7 +168,6 @@ void ArticleView::linkClicked( QUrl const & url )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
QString contentType;
|
||||
|
||||
if ( !found && !articleNetMgr.getResource( url, data, contentType ) )
|
||||
|
@ -177,10 +176,6 @@ void ArticleView::linkClicked( QUrl const & url )
|
|||
return;
|
||||
}
|
||||
|
||||
// Decide the viewer
|
||||
|
||||
QString program, extension;
|
||||
|
||||
if ( url.scheme() == "gdau" )
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
|
@ -194,34 +189,12 @@ void ArticleView::linkClicked( QUrl const & url )
|
|||
|
||||
PlaySoundA( &winWavData.front(), 0,
|
||||
SND_ASYNC | SND_MEMORY | SND_NODEFAULT | SND_NOWAIT );
|
||||
#else
|
||||
|
||||
return;
|
||||
#endif
|
||||
|
||||
program = "mplayer";
|
||||
extension = "wav";
|
||||
}
|
||||
else
|
||||
if ( url.path().endsWith( ".pdf", Qt::CaseInsensitive ) )
|
||||
{
|
||||
program = "evince";
|
||||
extension = "pdf";
|
||||
}
|
||||
else
|
||||
if ( url.path().endsWith( ".rtf", Qt::CaseInsensitive ) )
|
||||
{
|
||||
program = "oowriter";
|
||||
extension = "rtf";
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical( this, tr( "GoldenDict" ), tr( "Don't know how to handle the specified resource." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// Use external viewer to play the file
|
||||
try
|
||||
{
|
||||
ExternalViewer * viewer = new ExternalViewer( this, data, extension, program );
|
||||
ExternalViewer * viewer = new ExternalViewer( this, data, ".wav", "play" );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -237,8 +210,33 @@ void ArticleView::linkClicked( QUrl const & url )
|
|||
}
|
||||
catch( ExternalViewer::Ex & e )
|
||||
{
|
||||
printf( "%s\n", e.what() );
|
||||
QMessageBox::critical( this, tr( "GoldenDict" ), tr( "Failed to run a player to play sound file: %1" ).arg( e.what() ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a temporary file
|
||||
|
||||
desktopOpenedTempFile.reset();
|
||||
|
||||
desktopOpenedTempFile = new QTemporaryFile( QDir::temp().filePath( "XXXXXX-" + url.path().section( '/', -1 ) ), this );
|
||||
|
||||
if ( !desktopOpenedTempFile->open() || desktopOpenedTempFile->write( &data.front(), data.size() ) != data.size() )
|
||||
{
|
||||
QMessageBox::critical( this, tr( "GoldenDict" ), tr( "Failed to create temporary file." ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// For some reason it loses it after it was closed()
|
||||
QString tempFileName = desktopOpenedTempFile->fileName();
|
||||
|
||||
desktopOpenedTempFile->close();
|
||||
|
||||
if ( !QDesktopServices::openUrl( QUrl::fromLocalFile( tempFileName ) ) )
|
||||
QMessageBox::critical( this, tr( "GoldenDict" ), tr( "Failed to auto-open resource file, try opening manually: %1." ).arg( tempFileName ) );
|
||||
}
|
||||
else
|
||||
if ( url.scheme() == "http" || url.scheme() == "https" ||
|
||||
|
|
|
@ -27,6 +27,9 @@ class ArticleView: public QFrame
|
|||
vector< char > winWavData;
|
||||
#endif
|
||||
|
||||
// For resources opened via desktop services
|
||||
sptr< QTemporaryFile > desktopOpenedTempFile;
|
||||
|
||||
public:
|
||||
/// The popupView flag influences contents of the context menus to be
|
||||
/// appropriate to the context of the view.
|
||||
|
|
Loading…
Reference in a new issue