Skip to content

Commit

Permalink
"set download options" button now sets default download options
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Feb 11, 2025
1 parent 551ac3e commit 8ccfb61
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 58 deletions.
6 changes: 1 addition & 5 deletions src/basicdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ](){
Expand Down
10 changes: 1 addition & 9 deletions src/batchdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ;
Expand Down
72 changes: 72 additions & 0 deletions src/configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ;
Expand Down
32 changes: 1 addition & 31 deletions src/configure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/engines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ;
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/playlistdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ;
Expand Down

0 comments on commit 8ccfb61

Please sign in to comment.