mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Compare commits
1 commit
1c842a06c2
...
b0de4e1d5d
Author | SHA1 | Date | |
---|---|---|---|
b0de4e1d5d |
2
.github/workflows/PR-check-cmake.yml
vendored
2
.github/workflows/PR-check-cmake.yml
vendored
|
@ -67,7 +67,7 @@ jobs:
|
|||
libzim \
|
||||
qt
|
||||
|
||||
wget https://github.com/mistydemeo/eb/releases/download/v4.4.3/eb-4.4.3.tar.bz2
|
||||
wget ftp://ftp.sra.co.jp/pub/misc/eb/eb-4.4.3.tar.bz2
|
||||
tar xvjf eb-4.4.3.tar.bz2
|
||||
cd eb-4.4.3 && ./configure && make -j 8 && sudo make install && cd ..
|
||||
|
||||
|
|
|
@ -3,39 +3,34 @@
|
|||
|
||||
#include <QScopedPointer>
|
||||
#include <QObject>
|
||||
#include <utility>
|
||||
#include "audioplayerfactory.hh"
|
||||
#include "ffmpegaudioplayer.hh"
|
||||
#include "multimediaaudioplayer.hh"
|
||||
#include "externalaudioplayer.hh"
|
||||
#include "gddebug.hh"
|
||||
|
||||
AudioPlayerFactory::AudioPlayerFactory( bool useInternalPlayer,
|
||||
InternalPlayerBackend internalPlayerBackend,
|
||||
QString audioPlaybackProgram ):
|
||||
useInternalPlayer( useInternalPlayer ),
|
||||
internalPlayerBackend( std::move( internalPlayerBackend ) ),
|
||||
audioPlaybackProgram( std::move( audioPlaybackProgram ) )
|
||||
AudioPlayerFactory::AudioPlayerFactory( Config::Preferences const & p ):
|
||||
useInternalPlayer( p.useInternalPlayer ),
|
||||
internalPlayerBackend( p.internalPlayerBackend ),
|
||||
audioPlaybackProgram( p.audioPlaybackProgram )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void AudioPlayerFactory::setPreferences( bool new_useInternalPlayer,
|
||||
const InternalPlayerBackend & new_internalPlayerBackend,
|
||||
const QString & new_audioPlaybackProgram )
|
||||
void AudioPlayerFactory::setPreferences( Config::Preferences const & p )
|
||||
{
|
||||
if ( useInternalPlayer != new_useInternalPlayer ) {
|
||||
useInternalPlayer = new_useInternalPlayer;
|
||||
internalPlayerBackend = new_internalPlayerBackend;
|
||||
audioPlaybackProgram = new_audioPlaybackProgram;
|
||||
if ( p.useInternalPlayer != useInternalPlayer ) {
|
||||
useInternalPlayer = p.useInternalPlayer;
|
||||
internalPlayerBackend = p.internalPlayerBackend;
|
||||
audioPlaybackProgram = p.audioPlaybackProgram;
|
||||
reset();
|
||||
}
|
||||
else if ( useInternalPlayer && internalPlayerBackend != new_internalPlayerBackend ) {
|
||||
internalPlayerBackend = new_internalPlayerBackend;
|
||||
else if ( useInternalPlayer && p.internalPlayerBackend != internalPlayerBackend ) {
|
||||
internalPlayerBackend = p.internalPlayerBackend;
|
||||
reset();
|
||||
}
|
||||
else if ( !useInternalPlayer && new_audioPlaybackProgram != audioPlaybackProgram ) {
|
||||
audioPlaybackProgram = new_audioPlaybackProgram;
|
||||
else if ( !useInternalPlayer && p.audioPlaybackProgram != audioPlaybackProgram ) {
|
||||
audioPlaybackProgram = p.audioPlaybackProgram;
|
||||
ExternalAudioPlayer * const externalPlayer = qobject_cast< ExternalAudioPlayer * >( playerPtr.data() );
|
||||
if ( externalPlayer ) {
|
||||
setAudioPlaybackProgram( *externalPlayer );
|
||||
|
@ -55,7 +50,7 @@ void AudioPlayerFactory::reset()
|
|||
// another object of the same type.
|
||||
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
Q_ASSERT( InternalPlayerBackend::defaultBackend().isFfmpeg()
|
||||
Q_ASSERT( Config::InternalPlayerBackend::defaultBackend().isFfmpeg()
|
||||
&& "Adjust the code below after changing the default backend." );
|
||||
|
||||
if ( !internalPlayerBackend.isQtmultimedia() ) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "audioplayerinterface.hh"
|
||||
#include "internalplayerbackend.hh"
|
||||
#include "config.hh"
|
||||
|
||||
class ExternalAudioPlayer;
|
||||
|
||||
|
@ -13,12 +13,8 @@ class AudioPlayerFactory
|
|||
Q_DISABLE_COPY( AudioPlayerFactory )
|
||||
|
||||
public:
|
||||
explicit AudioPlayerFactory( bool useInternalPlayer,
|
||||
InternalPlayerBackend internalPlayerBackend,
|
||||
QString audioPlaybackProgram );
|
||||
void setPreferences( bool new_useInternalPlayer,
|
||||
const InternalPlayerBackend & new_internalPlayerBackend,
|
||||
const QString & new_audioPlaybackProgram );
|
||||
explicit AudioPlayerFactory( Config::Preferences const & );
|
||||
void setPreferences( Config::Preferences const & );
|
||||
/// The returned reference to a smart pointer is valid as long as this object
|
||||
/// exists. The pointer to the owned AudioPlayerInterface may change after the
|
||||
/// call to setPreferences(), but it is guaranteed to never be null.
|
||||
|
@ -32,7 +28,7 @@ private:
|
|||
void setAudioPlaybackProgram( ExternalAudioPlayer & externalPlayer );
|
||||
|
||||
bool useInternalPlayer;
|
||||
InternalPlayerBackend internalPlayerBackend;
|
||||
Config::InternalPlayerBackend internalPlayerBackend;
|
||||
QString audioPlaybackProgram;
|
||||
AudioPlayerPtr playerPtr;
|
||||
};
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
#include "internalplayerbackend.hh"
|
||||
|
||||
bool InternalPlayerBackend::anyAvailable()
|
||||
{
|
||||
#if defined( MAKE_FFMPEG_PLAYER ) || defined( MAKE_QTMULTIMEDIA_PLAYER )
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
InternalPlayerBackend InternalPlayerBackend::defaultBackend()
|
||||
{
|
||||
#if defined( MAKE_FFMPEG_PLAYER )
|
||||
return ffmpeg();
|
||||
#elif defined( MAKE_QTMULTIMEDIA_PLAYER )
|
||||
return qtmultimedia();
|
||||
#else
|
||||
return InternalPlayerBackend( QString() );
|
||||
#endif
|
||||
}
|
||||
|
||||
QStringList InternalPlayerBackend::nameList()
|
||||
{
|
||||
QStringList result;
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
result.push_back( ffmpeg().uiName() );
|
||||
#endif
|
||||
#ifdef MAKE_QTMULTIMEDIA_PLAYER
|
||||
result.push_back( qtmultimedia().uiName() );
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
bool InternalPlayerBackend::isFfmpeg() const
|
||||
{
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
return *this == ffmpeg();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool InternalPlayerBackend::isQtmultimedia() const
|
||||
{
|
||||
#ifdef MAKE_QTMULTIMEDIA_PLAYER
|
||||
return *this == qtmultimedia();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#pragma once
|
||||
#include <QStringList>
|
||||
|
||||
/// Overly engineered dummy/helper/wrapper "backend", which is not, to manage backends.
|
||||
class InternalPlayerBackend
|
||||
{
|
||||
public:
|
||||
/// Returns true if at least one backend is available.
|
||||
static bool anyAvailable();
|
||||
/// Returns the default backend or null backend if none is available.
|
||||
static InternalPlayerBackend defaultBackend();
|
||||
/// Returns the name list of supported backends.
|
||||
static QStringList nameList();
|
||||
|
||||
/// Returns true if built with FFmpeg player support and the name matches.
|
||||
bool isFfmpeg() const;
|
||||
/// Returns true if built with Qt Multimedia player support and the name matches.
|
||||
bool isQtmultimedia() const;
|
||||
|
||||
QString const & uiName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void setUiName( QString const & name_ )
|
||||
{
|
||||
name = name_;
|
||||
}
|
||||
|
||||
bool operator==( InternalPlayerBackend const & other ) const
|
||||
{
|
||||
return name == other.name;
|
||||
}
|
||||
|
||||
bool operator!=( InternalPlayerBackend const & other ) const
|
||||
{
|
||||
return !operator==( other );
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
static InternalPlayerBackend ffmpeg()
|
||||
{
|
||||
return InternalPlayerBackend( "FFmpeg" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MAKE_QTMULTIMEDIA_PLAYER
|
||||
static InternalPlayerBackend qtmultimedia()
|
||||
{
|
||||
return InternalPlayerBackend( "Qt Multimedia" );
|
||||
}
|
||||
#endif
|
||||
|
||||
explicit InternalPlayerBackend( QString const & name_ ):
|
||||
name( name_ )
|
||||
{
|
||||
}
|
||||
|
||||
QString name;
|
||||
};
|
|
@ -119,6 +119,57 @@ QKeySequence HotKey::toKeySequence() const
|
|||
;
|
||||
}
|
||||
|
||||
|
||||
bool InternalPlayerBackend::anyAvailable()
|
||||
{
|
||||
#if defined( MAKE_FFMPEG_PLAYER ) || defined( MAKE_QTMULTIMEDIA_PLAYER )
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
InternalPlayerBackend InternalPlayerBackend::defaultBackend()
|
||||
{
|
||||
#if defined( MAKE_FFMPEG_PLAYER )
|
||||
return ffmpeg();
|
||||
#elif defined( MAKE_QTMULTIMEDIA_PLAYER )
|
||||
return qtmultimedia();
|
||||
#else
|
||||
return InternalPlayerBackend( QString() );
|
||||
#endif
|
||||
}
|
||||
|
||||
QStringList InternalPlayerBackend::nameList()
|
||||
{
|
||||
QStringList result;
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
result.push_back( ffmpeg().uiName() );
|
||||
#endif
|
||||
#ifdef MAKE_QTMULTIMEDIA_PLAYER
|
||||
result.push_back( qtmultimedia().uiName() );
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
bool InternalPlayerBackend::isFfmpeg() const
|
||||
{
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
return *this == ffmpeg();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool InternalPlayerBackend::isQtmultimedia() const
|
||||
{
|
||||
#ifdef MAKE_QTMULTIMEDIA_PLAYER
|
||||
return *this == qtmultimedia();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
QString Preferences::sanitizeInputPhrase( QString const & inputWord ) const
|
||||
{
|
||||
QString result = inputWord;
|
||||
|
|
|
@ -3,20 +3,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "audio/internalplayerbackend.hh"
|
||||
#include "ex.hh"
|
||||
#include <QDateTime>
|
||||
#include <QDomDocument>
|
||||
#include <QKeySequence>
|
||||
#include <QList>
|
||||
#include <QLocale>
|
||||
#include <QMetaType>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QSize>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
#include <QSize>
|
||||
#include <QDateTime>
|
||||
#include <QKeySequence>
|
||||
#include <QSet>
|
||||
#include <QMetaType>
|
||||
#include "ex.hh"
|
||||
#include <QDomDocument>
|
||||
#include <QLocale>
|
||||
#include <optional>
|
||||
#include <QThread>
|
||||
|
||||
/// Special group IDs
|
||||
enum GroupId : unsigned {
|
||||
|
@ -270,6 +269,66 @@ struct CustomFonts
|
|||
}
|
||||
};
|
||||
|
||||
/// This class encapsulates supported backend preprocessor logic,
|
||||
/// discourages duplicating backend names in code, which is error-prone.
|
||||
class InternalPlayerBackend
|
||||
{
|
||||
public:
|
||||
/// Returns true if at least one backend is available.
|
||||
static bool anyAvailable();
|
||||
/// Returns the default backend or null backend if none is available.
|
||||
static InternalPlayerBackend defaultBackend();
|
||||
/// Returns the name list of supported backends.
|
||||
static QStringList nameList();
|
||||
|
||||
/// Returns true if built with FFmpeg player support and the name matches.
|
||||
bool isFfmpeg() const;
|
||||
/// Returns true if built with Qt Multimedia player support and the name matches.
|
||||
bool isQtmultimedia() const;
|
||||
|
||||
QString const & uiName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void setUiName( QString const & name_ )
|
||||
{
|
||||
name = name_;
|
||||
}
|
||||
|
||||
bool operator==( InternalPlayerBackend const & other ) const
|
||||
{
|
||||
return name == other.name;
|
||||
}
|
||||
|
||||
bool operator!=( InternalPlayerBackend const & other ) const
|
||||
{
|
||||
return !operator==( other );
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef MAKE_FFMPEG_PLAYER
|
||||
static InternalPlayerBackend ffmpeg()
|
||||
{
|
||||
return InternalPlayerBackend( "FFmpeg" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MAKE_QTMULTIMEDIA_PLAYER
|
||||
static InternalPlayerBackend qtmultimedia()
|
||||
{
|
||||
return InternalPlayerBackend( "Qt Multimedia" );
|
||||
}
|
||||
#endif
|
||||
|
||||
explicit InternalPlayerBackend( QString const & name_ ):
|
||||
name( name_ )
|
||||
{
|
||||
}
|
||||
|
||||
QString name;
|
||||
};
|
||||
|
||||
/// Various user preferences
|
||||
struct Preferences
|
||||
{
|
||||
|
|
|
@ -167,8 +167,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
cfg.preferences.disallowContentFromOtherSites,
|
||||
cfg.preferences.hideGoldenDictHeader ),
|
||||
dictNetMgr( this ),
|
||||
audioPlayerFactory(
|
||||
cfg.preferences.useInternalPlayer, cfg.preferences.internalPlayerBackend, cfg.preferences.audioPlaybackProgram ),
|
||||
audioPlayerFactory( cfg.preferences ),
|
||||
wordFinder( this ),
|
||||
wordListSelChanged( false ),
|
||||
wasMaximized( false ),
|
||||
|
@ -2357,9 +2356,7 @@ void MainWindow::editPreferences()
|
|||
#endif
|
||||
}
|
||||
|
||||
audioPlayerFactory.setPreferences( cfg.preferences.useInternalPlayer,
|
||||
cfg.preferences.internalPlayerBackend,
|
||||
cfg.preferences.audioPlaybackProgram );
|
||||
audioPlayerFactory.setPreferences( cfg.preferences );
|
||||
|
||||
trayIconUpdateOrInit();
|
||||
applyProxySettings();
|
||||
|
|
|
@ -295,7 +295,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
ui.pronounceOnLoadMain->setChecked( p.pronounceOnLoadMain );
|
||||
ui.pronounceOnLoadPopup->setChecked( p.pronounceOnLoadPopup );
|
||||
|
||||
ui.internalPlayerBackend->addItems( InternalPlayerBackend::nameList() );
|
||||
ui.internalPlayerBackend->addItems( Config::InternalPlayerBackend::nameList() );
|
||||
|
||||
// Make sure that exactly one radio button in the group is checked and that
|
||||
// on_useExternalPlayer_toggled() is called.
|
||||
|
@ -307,7 +307,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
|
||||
int index = ui.internalPlayerBackend->findText( p.internalPlayerBackend.uiName() );
|
||||
if ( index < 0 ) { // The specified backend is unavailable.
|
||||
index = ui.internalPlayerBackend->findText( InternalPlayerBackend::defaultBackend().uiName() );
|
||||
index = ui.internalPlayerBackend->findText( Config::InternalPlayerBackend::defaultBackend().uiName() );
|
||||
}
|
||||
Q_ASSERT( index >= 0 && "Logic error: the default backend must be present in the backend name list." );
|
||||
ui.internalPlayerBackend->setCurrentIndex( index );
|
||||
|
|
Loading…
Reference in a new issue