[vlc-commits] qt: allow banning folders in preferences

Prince Gupta git at videolan.org
Mon Mar 1 10:40:19 UTC 2021


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Tue Feb 23 15:54:03 2021 +0530| [7f529f3aa64d4720cdedf8460b49de0b3abb9749] | committer: Pierre Lamot

qt: allow banning folders in preferences

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7f529f3aa64d4720cdedf8460b49de0b3abb9749
---

 .../qt/dialogs/preferences/simple_preferences.cpp  | 40 ++++++----
 .../qt/dialogs/preferences/simple_preferences.hpp  | 12 +--
 .../qt/dialogs/preferences/sprefs_medialibrary.ui  | 90 +++++++++++++++++-----
 3 files changed, 102 insertions(+), 40 deletions(-)

diff --git a/modules/gui/qt/dialogs/preferences/simple_preferences.cpp b/modules/gui/qt/dialogs/preferences/simple_preferences.cpp
index 477d258345..e3436c55b6 100644
--- a/modules/gui/qt/dialogs/preferences/simple_preferences.cpp
+++ b/modules/gui/qt/dialogs/preferences/simple_preferences.cpp
@@ -977,18 +977,21 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
 
                 if ( vlc_ml_instance_get( p_intf ) != NULL )
                 {
-                    mlModel = new ProxyColumnModel<MLFoldersModel>(1, {{0, qtr("Path")}, {1, qtr("Remove")}}, this );
-                    mlModel->setMl( vlc_ml_instance_get( p_intf ) );
+                    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 ); } );
 
-                    mlTableView = ui.entryPointsTV;
+                    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 ); } );
 
-                    mlTableView->setModel( mlModel );
+                    BUTTONACT( ui.addButton , MLaddNewFolder() );
+                    BUTTONACT( ui.banButton , MLBanFolder() );
 
-                    connect( mlModel , &QAbstractItemModel::modelReset , this , &SPrefsPanel::MLdrawControls );
-
-                    BUTTONACT( ui.addButton , MLaddNewEntryPoint() );
-
-                    MLdrawControls( );
+                    MLdrawControls( ui.entryPoints );
+                    MLdrawControls( ui.bannedEntryPoints );
                 }
                 else
                 {
@@ -1557,15 +1560,23 @@ void SPrefsPanel::saveAsso()
 
 #endif /* _WIN32 */
 
-void SPrefsPanel::MLaddNewEntryPoint( ){
+void SPrefsPanel::MLaddNewFolder() {
     QUrl newEntryPoints = QFileDialog::getExistingDirectoryUrl( this , qtr("Please choose an entry point folder") ,
                                              QUrl( QDir::homePath( ) ) );
 
     if(! newEntryPoints.isEmpty() )
-        mlModel->add( newEntryPoints );
+        mlFoldersModel->add( newEntryPoints );
 }
 
-QWidget *SPrefsPanel::MLgenerateWidget( QModelIndex index , MLFoldersModel *mlf , QWidget *parent){
+void SPrefsPanel::MLBanFolder( ) {
+    QUrl newEntryPoints = 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 );
 
@@ -1588,15 +1599,14 @@ QWidget *SPrefsPanel::MLgenerateWidget( QModelIndex index , MLFoldersModel *mlf
     return nullptr;
 }
 
-void SPrefsPanel::MLdrawControls( ) {
-
+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, mlModel,
+            mlTableView->setIndexWidget( index, MLgenerateWidget ( index, qobject_cast<MLFoldersBaseModel *>(model),
                                        mlTableView ) );
         }
     }
diff --git a/modules/gui/qt/dialogs/preferences/simple_preferences.hpp b/modules/gui/qt/dialogs/preferences/simple_preferences.hpp
index da7a4e9a0d..f1ed7bcd3a 100644
--- a/modules/gui/qt/dialogs/preferences/simple_preferences.hpp
+++ b/modules/gui/qt/dialogs/preferences/simple_preferences.hpp
@@ -115,9 +115,8 @@ private:
     QButtonGroup *radioGroup;
 
     char *lang;
-
-    MLFoldersModel *mlModel;
-    QTableView * mlTableView;
+    MLFoldersModel *mlFoldersModel;
+    MLBannedFoldersModel *mlBannedFoldersModel;
 
 #ifdef _WIN32
     QList<QTreeWidgetItem *> listAsso;
@@ -136,9 +135,10 @@ private slots:
     void updateCheckBoxes( QTreeWidgetItem*, int );
     void saveAsso();
 #endif
-    void MLaddNewEntryPoint( );
-    QWidget * MLgenerateWidget( QModelIndex index , MLFoldersModel *mlf , QWidget *parent );
-    void MLdrawControls( );
+    void MLaddNewFolder( );
+    void MLBanFolder( );
+    QWidget * MLgenerateWidget(QModelIndex index , MLFoldersBaseModel *mlf , QWidget *parent );
+    void MLdrawControls( QTableView *mlView );
 
     void configML();
     void changeStyle( QString );
diff --git a/modules/gui/qt/dialogs/preferences/sprefs_medialibrary.ui b/modules/gui/qt/dialogs/preferences/sprefs_medialibrary.ui
index 282f39f0d8..896887eb60 100644
--- a/modules/gui/qt/dialogs/preferences/sprefs_medialibrary.ui
+++ b/modules/gui/qt/dialogs/preferences/sprefs_medialibrary.ui
@@ -26,8 +26,21 @@
      <property name="title">
       <string>Folders</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout_5">
-      <item row="0" column="2">
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="1" colspan="2">
+       <spacer name="horizontalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>627</width>
+          <height>17</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="0" column="3">
        <widget class="QPushButton" name="addButton">
         <property name="maximumSize">
          <size>
@@ -40,8 +53,48 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="0" colspan="3">
-       <widget class="QTableView" name="entryPointsTV">
+      <item row="3" column="3">
+       <widget class="QPushButton" name="banButton">
+        <property name="maximumSize">
+         <size>
+          <width>16</width>
+          <height>16</height>
+         </size>
+        </property>
+        <property name="text">
+         <string>+</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_2">
+        <property name="text">
+         <string>Folders scanned by the Media Library:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1" rowspan="2">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="2" column="0" rowspan="2">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Banned Folders:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="0" colspan="4">
+       <widget class="QTableView" name="bannedEntryPoints">
         <property name="editTriggers">
          <set>QAbstractItemView::AllEditTriggers</set>
         </property>
@@ -59,24 +112,23 @@
         </attribute>
        </widget>
       </item>
-      <item row="0" column="1">
-       <spacer name="horizontalSpacer_2">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
+      <item row="1" column="0" colspan="4">
+       <widget class="QTableView" name="entryPoints">
+        <property name="editTriggers">
+         <set>QAbstractItemView::AllEditTriggers</set>
         </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>627</width>
-          <height>17</height>
-         </size>
+        <property name="alternatingRowColors">
+         <bool>true</bool>
         </property>
-       </spacer>
-      </item>
-      <item row="0" column="0">
-       <widget class="QLabel" name="label_2">
-        <property name="text">
-         <string>Folders scanned by the Media Library:</string>
+        <property name="showGrid">
+         <bool>false</bool>
         </property>
+        <attribute name="horizontalHeaderVisible">
+         <bool>true</bool>
+        </attribute>
+        <attribute name="verticalHeaderVisible">
+         <bool>false</bool>
+        </attribute>
        </widget>
       </item>
      </layout>



More information about the vlc-commits mailing list