Skip to content

Commit

Permalink
add a context menu entry in batch downloader to rename already downlo…
Browse files Browse the repository at this point in the history
…aded media
  • Loading branch information
mhogomchungu committed Aug 26, 2024
1 parent 97f9d73 commit 864e351
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 60 deletions.
189 changes: 135 additions & 54 deletions src/batchdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ batchdownloader::batchdownloader( const Context& ctx ) :

m_table.setCurrentItemChanged( m_table.startPosition() ) ;

this->setVisibleMediaSectionCut( false ) ;
this->setVisibleWidgetOverMainTable( false ) ;

m_ui.pbBDDownload->setEnabled( false ) ;

Expand Down Expand Up @@ -258,52 +258,19 @@ batchdownloader::batchdownloader( const Context& ctx ) :

connect( m_ui.pbSetTimeIntervals,&QPushButton::clicked,[ this ](){

auto row = m_table.currentRow() ;

if( row != -1 ){

auto a = m_ui.lineEditStartTimeInterval->text() ;
auto b = m_ui.lineEditEndTimeInterval->text() ;
auto c = m_ui.lineEditChapters->text() ;

if( !a.isEmpty() && !b.isEmpty() ){

auto u = tableWidget::type::DownloadTimeInterval ;
if( m_widgetOverMainTable.showRenameUi() ){

m_table.setDownloadingOptions( u,row,a + "-" + b ) ;

}else if( a.isEmpty() && b.isEmpty() ){

//Left empty on purpose
}else{
return ;
}

if( !c.isEmpty() ){

auto u = tableWidget::type::DownloadChapters ;

m_table.setDownloadingOptions( u,row,c ) ;
}

if( m_ui.cbSplitByChapters->isChecked() ){

auto u = tableWidget::type::SplitByChapters ;

m_table.setDownloadingOptions( u,row,"Yes" ) ;
}else{
auto u = tableWidget::type::SplitByChapters ;

m_table.setDownloadingOptions( u,row,"No" ) ;
}
this->renameFile( m_widgetOverMainTable.row() ) ;
}else{
this->setTimeIntervals( m_widgetOverMainTable.row() ) ;
}

this->setVisibleMediaSectionCut( false ) ;
this->setVisibleWidgetOverMainTable( false ) ;
} ) ;

connect( m_ui.pbCancelSetTimeInterval,&QPushButton::clicked,[ this ](){

this->setVisibleMediaSectionCut( false ) ;
this->setVisibleWidgetOverMainTable( false ) ;
} ) ;

connect( m_ui.pbBDPasteClipboard,&QPushButton::clicked,[ this ](){
Expand Down Expand Up @@ -457,6 +424,19 @@ void batchdownloader::showCustomContext()
}
} ) ;

ac = m.addAction( tr( "Rename" ) ) ;

auto canRename = m_table.entryAt( row ).fileNames.size() == 1 ;

ac->setEnabled( m_table.finishedWithSuccess( row ) && canRename ) ;

connect( ac,&QAction::triggered,[ this,row ](){

m_widgetOverMainTable = { true,row } ;

this->setVisibleWidgetOverMainTable( true ) ;
} ) ;

ac = m.addAction( tr( "Remove" ) ) ;

ac->setEnabled( m_table.noneAreRunning() ) ;
Expand Down Expand Up @@ -521,9 +501,11 @@ void batchdownloader::showCustomContext()
ac = m.addAction( tr( "Download Media Part" ) ) ;
ac->setEnabled( !finishSuccess && engine.canDownloadMediaPart() ) ;

connect( ac,&QAction::triggered,[ this ](){
connect( ac,&QAction::triggered,[ this,row ](){

m_widgetOverMainTable = { false,row } ;

this->setVisibleMediaSectionCut( true ) ;
this->setVisibleWidgetOverMainTable( true ) ;
} ) ;

utility::addDownloadContextMenu( running,finishSuccess,m,row,[ this ]( int row ){
Expand All @@ -544,7 +526,7 @@ void batchdownloader::showCustomContext()

for( int row = 0 ; row < m_table.rowCount() ; row++ ){

auto e = m_table.runningState( row ) ;
const auto& e = m_table.runningState( row ) ;

auto visible = m_table.rowIsVisible( row ) ;
auto highlighted = m_table.rowIsSelected( row ) ;
Expand Down Expand Up @@ -1102,25 +1084,124 @@ void batchdownloader::normalizeFilePath( QString& e )
}
}

void batchdownloader::setVisibleMediaSectionCut( bool e )
void batchdownloader::setVisibleWidgetOverMainTable( bool e )
{
if( e ){

m_ui.lineEditStartTimeInterval->setFocus() ;
this->disableAll() ;
}else{
m_ui.lineEditBDUrl->setFocus() ;
this->enableAll() ;
}

m_ui.labelSetTimeIntervals->setVisible( e ) ;
m_ui.labelWidgetOverMainTable->setVisible( e ) ;

m_ui.pbCancelSetTimeInterval->setVisible( e ) ;
m_ui.pbSetTimeIntervals->setVisible( e ) ;
m_ui.lineEditChapters->setVisible( e ) ;
m_ui.lineEditStartTimeInterval->setVisible( e ) ;
m_ui.lineEditEndTimeInterval->setVisible( e ) ;
m_ui.cbSplitByChapters->setVisible( e ) ;
m_ui.label_7->setVisible( e ) ;
m_ui.label_8->setVisible( e ) ;
m_ui.label_9->setVisible( e ) ;

if( m_widgetOverMainTable.showRenameUi() ){

m_ui.labelBDSetNewFileName->setVisible( e ) ;
m_ui.plainTextEditBD->setVisible( e ) ;

if( e ){

const auto& m = m_table.entryAt( m_widgetOverMainTable.row() ).fileNames ;

if( m.size() ){

m_ui.plainTextEditBD->clear() ;

m_ui.plainTextEditBD->appendPlainText( m[ 0 ] ) ;
}

m_ui.plainTextEditBD->setFocus() ;
}

m_ui.lineEditChapters->setVisible( false ) ;
m_ui.lineEditStartTimeInterval->setVisible( false ) ;
m_ui.lineEditEndTimeInterval->setVisible( false ) ;
m_ui.cbSplitByChapters->setVisible( false ) ;
m_ui.label_7->setVisible( false ) ;
m_ui.label_8->setVisible( false ) ;
m_ui.label_9->setVisible( false ) ;
}else{
if( e ){

m_ui.lineEditStartTimeInterval->setFocus() ;
}else{
m_ui.lineEditBDUrl->setFocus() ;
}

m_ui.lineEditChapters->setVisible( e ) ;
m_ui.lineEditStartTimeInterval->setVisible( e ) ;
m_ui.lineEditEndTimeInterval->setVisible( e ) ;
m_ui.cbSplitByChapters->setVisible( e ) ;
m_ui.label_7->setVisible( e ) ;
m_ui.label_8->setVisible( e ) ;
m_ui.label_9->setVisible( e ) ;
m_ui.labelBDSetNewFileName->setVisible( false ) ;
m_ui.plainTextEditBD->setVisible( false ) ;
}
}

void batchdownloader::renameFile( int row )
{
const auto& df = m_ctx.Settings().downloadFolder() ;
const auto& fn = m_table.entryAt( row ).fileNames ;
const auto& nn = m_ui.plainTextEditBD->toPlainText() ;

if( fn.size() ){

auto& item = m_table.item( row,m_table.startPosition() ) ;

auto m = utility::rename( item,df,nn,fn[ 0 ] ) ;

if( !m.isEmpty() ){

m_table.setFileNames( row,{ m } ) ;
}
}
}

void batchdownloader::setTimeIntervals( int row )
{
if( row != -1 ){

auto a = m_ui.lineEditStartTimeInterval->text() ;
auto b = m_ui.lineEditEndTimeInterval->text() ;
auto c = m_ui.lineEditChapters->text() ;

if( !a.isEmpty() && !b.isEmpty() ){

auto u = tableWidget::type::DownloadTimeInterval ;

m_table.setDownloadingOptions( u,row,a + "-" + b ) ;

}else if( a.isEmpty() && b.isEmpty() ){

//Left empty on purpose
}else{
return ;
}

if( !c.isEmpty() ){

auto u = tableWidget::type::DownloadChapters ;

m_table.setDownloadingOptions( u,row,c ) ;
}

if( m_ui.cbSplitByChapters->isChecked() ){

auto u = tableWidget::type::SplitByChapters ;

m_table.setDownloadingOptions( u,row,"Yes" ) ;
}else{
auto u = tableWidget::type::SplitByChapters ;

m_table.setDownloadingOptions( u,row,"No" ) ;
}
}
}

void batchdownloader::showSubtitles( const QByteArray& e )
Expand Down
28 changes: 27 additions & 1 deletion src/batchdownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ private
void sortComments() ;
bool saveSubtitles( const QString& url,const QString& ext,const QString& title ) ;
void normalizeFilePath( QString& ) ;
void setVisibleMediaSectionCut( bool ) ;
void setVisibleWidgetOverMainTable( bool ) ;
void renameFile( int ) ;
void setTimeIntervals( int ) ;
QString setSubtitleString( const QJsonObject&,const QString& ) ;
void parseDataFromFile( const QByteArray& ) ;
void parseDataFromObject( const QJsonObject&,const QJsonArray& ) ;
Expand Down Expand Up @@ -285,6 +287,30 @@ private
batchdownloader::listType m_listType ;
utility::Terminator m_terminator ;

class widgetOverMainTable
{
public:
widgetOverMainTable()
{
}
widgetOverMainTable( bool b,int r ) : m_row( r ),m_show( b )
{
}
int row() const
{
return m_row ;
}
bool showRenameUi() const
{
return m_show ;
}
private:
int m_row ;
bool m_show ;
} ;

widgetOverMainTable m_widgetOverMainTable ;

downloadManager m_ccmd ;
downloadManager m_ccmd_metadata ;

Expand Down
6 changes: 3 additions & 3 deletions src/downloadmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class downloadManager
{
return finishedWithSuccess() == e ;
}
static bool finishedCancelled( tableWidget& e,int row )
static bool finishedCancelled( const tableWidget& e,int row )
{
return finishedCancelled( e.runningState( row ) ) ;
}
static bool finishedWithError( tableWidget& e,int row )
static bool finishedWithError( const tableWidget& e,int row )
{
return finishedWithError( e.runningState( row ) ) ;
}
static bool finishedWithSuccess( tableWidget& e,int row )
static bool finishedWithSuccess( const tableWidget& e,int row )
{
return finishedWithSuccess( e.runningState( row ) ) ;
}
Expand Down
33 changes: 31 additions & 2 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</rect>
</property>
<property name="currentIndex">
<number>4</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabBasickDownloader">
<attribute name="title">
Expand Down Expand Up @@ -635,7 +635,7 @@
</property>
</widget>
</widget>
<widget class="QLabel" name="labelSetTimeIntervals">
<widget class="QLabel" name="labelWidgetOverMainTable">
<property name="geometry">
<rect>
<x>100</x>
Expand Down Expand Up @@ -777,6 +777,35 @@
<string>Split By Chapters</string>
</property>
</widget>
<widget class="QLabel" name="labelBDSetNewFileName">
<property name="geometry">
<rect>
<x>110</x>
<y>190</y>
<width>571</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Set New File Name Below</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEditBD">
<property name="geometry">
<rect>
<x>110</x>
<y>230</y>
<width>571</width>
<height>71</height>
</rect>
</property>
<property name="placeholderText">
<string notr="true"/>
</property>
</widget>
</widget>
<widget class="QWidget" name="tabPlayListDownloader">
<attribute name="title">
Expand Down
9 changes: 9 additions & 0 deletions src/playlistdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ void playlistdownloader::customContextMenuRequested()
m_terminator.terminate( row ) ;
} ) ;

//ac = m.addAction( tr( "Rename" ) ) ;

//ac->setEnabled( m_table.finishedWithSuccess( row ) ) ;

//connect( ac,&QAction::triggered,[ this,row ](){


//} ) ;

ac = m.addAction( tr( "Remove" ) ) ;

ac->setEnabled( m_table.noneAreRunning() && !m_networkRunning ) ;
Expand Down
5 changes: 5 additions & 0 deletions src/tableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ int tableWidget::addItem( tableWidget::entry e,tableWidget::sizeHint s )
return row ;
}

bool tableWidget::finishedWithSuccess( int row ) const
{
return downloadManager::finishedStatus::finishedWithSuccess( *this,row ) ;
}

void tableWidget::selectRow( QTableWidgetItem * current,QTableWidgetItem * previous,int firstColumnNumber )
{
auto _update_table_row = [ & ]( QTableWidgetItem * item,bool setSelected ){
Expand Down
1 change: 1 addition & 0 deletions src/tableWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class tableWidget
{
return this->item( row ).runningState ;
}
bool finishedWithSuccess( int row ) const ;
QByteArray mediaEntry( int row ) const
{
auto obj = this->entryAt( row ).uiJson ;
Expand Down
Loading

0 comments on commit 864e351

Please sign in to comment.