diff --git a/src/basicdownloader.cpp b/src/basicdownloader.cpp index dc9a0e9f..4f91899c 100644 --- a/src/basicdownloader.cpp +++ b/src/basicdownloader.cpp @@ -122,11 +122,7 @@ basicdownloader::basicdownloader( const Context& ctx ) : auto m = this->defaultEngineName() ; - t.engineDefaultDownloadOptions( m,[ this ]( const QString& e ){ - - m_extraOptions.hasExtraOptions = true ; - m_extraOptions.downloadOptions = e ; - } ) ; + t.engineSetDefaultDownloadOptions( m ) ; } ) ; connect( m_ui.pbList,&QPushButton::clicked,[ this ](){ diff --git a/src/batchdownloader.cpp b/src/batchdownloader.cpp index ec2d75f1..2ab7f383 100644 --- a/src/batchdownloader.cpp +++ b/src/batchdownloader.cpp @@ -122,15 +122,7 @@ batchdownloader::batchdownloader( const Context& ctx ) : auto m = this->defaultEngineName() ; - t.engineDefaultDownloadOptions( m,[ this ]( const QString& e ){ - - for( int i = 0 ; i < m_table.rowCount() ; i++ ){ - - auto u = tableWidget::type::DownloadExtendedOptions ; - - m_table.setDownloadingOptions( u,i,e ) ; - } - } ) ; + t.engineSetDefaultDownloadOptions( m ) ; } ) ; m_tableWidgetBDList.setUpHeaderMenu() ; diff --git a/src/configure.cpp b/src/configure.cpp index fe372361..b88b01fa 100644 --- a/src/configure.cpp +++ b/src/configure.cpp @@ -950,6 +950,78 @@ QString configure::engineDefaultDownloadOptions( const QString& engineName ) return options ; } +void configure::engineSetDefaultDownloadOptions( const QString& engineName ) +{ + using mm = configure::downloadDefaultOptions::optsEngines ; + + class opts + { + public: + opts( const mm& m,const QJsonObject& obj ) : + m_jsonObject( obj ), + m_options( m.options ), + m_inUse( m.inuse == "yes" ) + { + } + const QString& opt() const + { + return m_options ; + } + const QJsonObject& json() const + { + return m_jsonObject ; + } + bool inUse() const + { + return m_inUse ; + } + private: + QJsonObject m_jsonObject ; + QString m_options ; + bool m_inUse ; + } ; + + std::vector< opts > options ; + + m_downloadEngineDefaultOptions.forEach( [ & ]( const mm& opts,const QJsonObject& obj ){ + + if( opts.engine == engineName ){ + + options.emplace_back( opts,obj ) ; + } + + return false ; + } ) ; + + QMenu m ; + + for( const auto& it : options ){ + + const auto& e = it.opt() ; + + auto s = m.addAction( e ) ; + + s->setObjectName( e ) ; + s->setCheckable( true ) ; + s->setChecked( it.inUse() ) ; + } + + connect( &m,&QMenu::triggered,[ &options,this ]( QAction * ac ){ + + for( const auto& it : options ){ + + if( it.opt() == ac->objectName() ){ + + m_downloadEngineDefaultOptions.setAsDefault( it.json() ) ; + + break ; + } + } + } ) ; + + m.exec( QCursor::pos() ) ; +} + QString configure::defaultDownloadOption() { return "bestvideo[ext=mp4][vcodec^=avc]+bestaudio[ext=m4a]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio/best[ext=mp4]/best" ; diff --git a/src/configure.h b/src/configure.h index efb8e57b..12897754 100644 --- a/src/configure.h +++ b/src/configure.h @@ -50,37 +50,7 @@ class configure : public QObject void setVisibilityEditConfigFeature( bool ) ; void updateEnginesList( const QStringList& e ) ; QString engineDefaultDownloadOptions( const QString& ) ; - template< typename Function > - void engineDefaultDownloadOptions( const QString& engineName,Function function ) - { - QStringList options ; - - using mm = configure::downloadDefaultOptions::optsEngines ; - - m_downloadEngineDefaultOptions.forEach( [ & ]( const mm& opts,const QJsonObject& ){ - - if( opts.engine == engineName ){ - - options.append( opts.options ) ; - } - - return false ; - } ) ; - - QMenu m ; - - for( const auto& it : options ){ - - m.addAction( it ) ; - } - - connect( &m,&QMenu::triggered,[ &function ]( QAction * ac ){ - - function( ac->text() ) ; - } ) ; - - m.exec( QCursor::pos() ) ; - } + void engineSetDefaultDownloadOptions( const QString& engineName ); QString optionsTranslated( const QString& ) ; void setDownloadOptions( int row,tableWidget& table ) ; struct presetEntry diff --git a/src/engines.cpp b/src/engines.cpp index 72249daa..c7295f97 100644 --- a/src/engines.cpp +++ b/src/engines.cpp @@ -186,13 +186,13 @@ void engines::showBanner() m_logger.add( QObject::tr( "Download Path: %1" ).arg( m_settings.downloadFolder( m_logger ) ),id ) ; m_logger.add( QObject::tr( "App Data Path: %1" ).arg( m_enginePaths.basePath() ),id ) ; - m_logger.add( utility::barLine(),id ) ; - if( m_settings.printMediaPlayers() ){ - for( const auto& it : utility::getMediaPlayers() ){ + m_logger.add( utility::barLine(),id ) ; + + for( const auto& it : utility::getMediaPlayers() ){ - m_logger.add( it.name + ":" + it.exePath,id ) ; + m_logger.add( it.name + ": " + it.exePath,id ) ; } } } diff --git a/src/playlistdownloader.cpp b/src/playlistdownloader.cpp index 87cc8cf7..9c0fba30 100644 --- a/src/playlistdownloader.cpp +++ b/src/playlistdownloader.cpp @@ -117,15 +117,7 @@ playlistdownloader::playlistdownloader( Context& ctx ) : auto m = this->defaultEngineName() ; - t.engineDefaultDownloadOptions( m,[ this ]( const QString& e ){ - - for( int i = 1 ; i < m_table.rowCount() ; i++ ){ - - auto u = tableWidget::type::DownloadExtendedOptions ; - - m_table.setDownloadingOptions( u,i,e ) ; - } - } ) ; + t.engineSetDefaultDownloadOptions( m ) ; } ) ; auto ww = m_ctx.Settings().thumbnailWidth( settings::tabName::playlist ) ;