Commit 995b74f4 authored by Prince Gupta's avatar Prince Gupta Committed by Jean-Baptiste Kempf
Browse files

qt/preferences: use MLFoldersEditor for ml folders list

doesn't applies changes till save
ref #25584
parent 2152fe55
......@@ -1025,21 +1025,18 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
if ( vlc_ml_instance_get( p_intf ) != NULL )
{
mlFoldersModel = new ProxyColumnModel<MLFoldersModel>(1, {{0, qtr("Path")}, {1, qtr("Remove")}}, this );
mlFoldersModel->setMl( vlc_ml_instance_get( p_intf ) );
ui.entryPoints->setModel( mlFoldersModel );
connect( mlFoldersModel , &QAbstractItemModel::modelReset , this, [this, view = ui.entryPoints]() { MLdrawControls( view ); } );
auto foldersModel = new MLFoldersModel( this );
foldersModel->setMl( vlc_ml_instance_get( p_intf ) );
ui.entryPoints->setMLFoldersModel( foldersModel );
mlFoldersEditor = ui.entryPoints;
mlBannedFoldersModel = new ProxyColumnModel<MLBannedFoldersModel>(1, {{0, qtr("Path")}, {1, qtr("Remove")}}, this );
mlBannedFoldersModel->setMl( vlc_ml_instance_get( p_intf ));
ui.bannedEntryPoints->setModel( mlBannedFoldersModel );
connect( mlBannedFoldersModel , &QAbstractItemModel::modelReset , this, [this, view = ui.bannedEntryPoints]() { MLdrawControls( view ); } );
auto bannedFoldersModel = new MLBannedFoldersModel( this );
bannedFoldersModel->setMl( vlc_ml_instance_get( p_intf ));
ui.bannedEntryPoints->setMLFoldersModel( bannedFoldersModel );
mlBannedFoldersEditor = ui.bannedEntryPoints;
BUTTONACT( ui.addButton , MLaddNewFolder() );
BUTTONACT( ui.banButton , MLBanFolder() );
MLdrawControls( ui.entryPoints );
MLdrawControls( ui.bannedEntryPoints );
}
else
{
......@@ -1276,7 +1273,13 @@ void SPrefsPanel::apply()
else if (!b_checked ) {
config_PutInt( "freetype-background-opacity", 0 );
}
break;
}
case SPrefsMediaLibrary:
{
mlFoldersEditor->commit();
mlBannedFoldersEditor->commit();
}
}
}
......@@ -1617,59 +1620,17 @@ void SPrefsPanel::saveAsso()
#endif /* _WIN32 */
void SPrefsPanel::MLaddNewFolder() {
QUrl newEntryPoints = QFileDialog::getExistingDirectoryUrl( this , qtr("Please choose an entry point folder") ,
QUrl newEntryPoint = QFileDialog::getExistingDirectoryUrl( this , qtr("Please choose an entry point folder") ,
QUrl( QDir::homePath( ) ) );
if(! newEntryPoints.isEmpty() )
mlFoldersModel->add( newEntryPoints );
if(! newEntryPoint.isEmpty() )
mlFoldersEditor->add( newEntryPoint );
}
void SPrefsPanel::MLBanFolder( ) {
QUrl newEntryPoints = QFileDialog::getExistingDirectoryUrl( this , qtr("Please choose an entry point folder") ,
QUrl newEntryPoint = QFileDialog::getExistingDirectoryUrl( this , qtr("Please choose an entry point folder") ,
QUrl( QDir::homePath( ) ) );
if(! newEntryPoints.isEmpty() )
mlBannedFoldersModel->add( newEntryPoints );
}
QWidget *SPrefsPanel::MLgenerateWidget( QModelIndex index , MLFoldersBaseModel *mlf , QWidget *parent){
if ( index.column( ) == 1 ){
QWidget *wid = new QWidget( parent );
QBoxLayout* layout = new QBoxLayout( QBoxLayout::LeftToRight , wid );
QPushButton *pb = new QPushButton( "-" , wid );
pb->setFixedSize( 16 , 16 );
layout->addWidget( pb , Qt::AlignCenter );
wid->setLayout( layout );
connect( pb , &QPushButton::clicked , [=]() {
mlf->removeAt(index.row());
} );
return wid;
}
return nullptr;
}
void SPrefsPanel::MLdrawControls(QTableView *mlTableView) {
const auto model = mlTableView->model();
for ( int col = 0 ; col < model->columnCount( model->index(0, 0) ) ; col++ )
{
for (int row = 0 ; row < model->rowCount() ; row++ )
{
QModelIndex index = model->index ( row , col );
mlTableView->setIndexWidget( index, MLgenerateWidget ( index, qobject_cast<MLFoldersBaseModel *>(model),
mlTableView ) );
}
}
mlTableView->resizeColumnsToContents( );
mlTableView->horizontalHeader()->setMinimumSectionSize( 100 );
mlTableView->horizontalHeader()->setSectionResizeMode( 0 , QHeaderView::Stretch );
mlTableView->horizontalHeader()->setFixedHeight( 24 );
if(! newEntryPoint.isEmpty() )
mlBannedFoldersEditor->add( newEntryPoint );
}
......@@ -42,7 +42,8 @@
#include <QDialogButtonBox>
#include <QTableView>
#include <QFileDialog>
#include "medialibrary/mlfoldersmodel.hpp"
class MLFoldersEditor;
#ifdef _WIN32
# include "util/registry.hpp"
......@@ -114,8 +115,8 @@ private:
QButtonGroup *radioGroup;
char *lang;
MLFoldersModel *mlFoldersModel;
MLBannedFoldersModel *mlBannedFoldersModel;
MLFoldersEditor *mlFoldersEditor {};
MLFoldersEditor *mlBannedFoldersEditor {};
#ifdef _WIN32
QList<QTreeWidgetItem *> listAsso;
......@@ -140,8 +141,6 @@ private slots:
#endif
void MLaddNewFolder( );
void MLBanFolder( );
QWidget * MLgenerateWidget(QModelIndex index , MLFoldersBaseModel *mlf , QWidget *parent );
void MLdrawControls( QTableView *mlView );
void configML();
void changeStyle( );
......
......@@ -94,7 +94,7 @@
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="QTableView" name="bannedEntryPoints">
<widget class="MLFoldersEditor" name="bannedEntryPoints">
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
......@@ -104,16 +104,17 @@
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<property name="rowCount">
<number>1</number>
</property>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>false</bool>
</attribute>
<row/>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTableView" name="entryPoints">
<widget class="MLFoldersEditor" name="entryPoints">
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
......@@ -123,12 +124,13 @@
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<property name="rowCount">
<number>1</number>
</property>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>false</bool>
</attribute>
<row/>
</widget>
</item>
</layout>
......@@ -149,6 +151,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MLFoldersEditor</class>
<extends>QTableWidget</extends>
<header>widgets/native/mlfolderseditor.hpp</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment