[vlc-devel] [PATCH 9/9] qt: Reintroduce the bookmark dialog

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Jun 18 17:40:23 CEST 2020


---
 .../gui/qt/dialogs/bookmarks/bookmarks.cpp    | 52 +++++++------------
 .../gui/qt/dialogs/bookmarks/bookmarks.hpp    |  9 ++--
 modules/gui/qt/menus/qml/PlaybackMenu.qml     | 10 ++--
 3 files changed, 26 insertions(+), 45 deletions(-)

diff --git a/modules/gui/qt/dialogs/bookmarks/bookmarks.cpp b/modules/gui/qt/dialogs/bookmarks/bookmarks.cpp
index 8202e388f7..cf91a00418 100644
--- a/modules/gui/qt/dialogs/bookmarks/bookmarks.cpp
+++ b/modules/gui/qt/dialogs/bookmarks/bookmarks.cpp
@@ -26,6 +26,7 @@
 
 #include "bookmarks.hpp"
 #include "player/player_controller.hpp"
+#include "medialibrary/mlbookmarkmodel.hpp"
 
 #include <QHBoxLayout>
 #include <QSpacerItem>
@@ -35,7 +36,6 @@
 
 BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
 {
-    b_ignore_updates = false;
     setWindowFlags( Qt::Tool );
     setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
     setWindowTitle( qtr( "Edit Bookmarks" ) );
@@ -62,35 +62,29 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
     buttonsBox->addButton( new QPushButton( qtr( "&Close" ) ),
                           QDialogButtonBox::RejectRole);
 
-    bookmarksList = new QTreeWidget( this );
+    bookmarksList = new QTreeView( this );
+    m_model = new MLBookmarkModel( vlc_ml_instance_get(_p_intf ),
+                                   _p_intf->p_sys->p_player,
+                                   bookmarksList );
+    bookmarksList->setModel( m_model );
     bookmarksList->setRootIsDecorated( false );
     bookmarksList->setAlternatingRowColors( true );
+    /* Sort by default model order, otherwise column 0 will be used */
+    bookmarksList->sortByColumn( -1, Qt::AscendingOrder );
+    bookmarksList->setSortingEnabled( true );
     bookmarksList->setSelectionMode( QAbstractItemView::ExtendedSelection );
     bookmarksList->setSelectionBehavior( QAbstractItemView::SelectRows );
-    bookmarksList->setEditTriggers( QAbstractItemView::SelectedClicked );
-    bookmarksList->setColumnCount( 3 );
-    bookmarksList->resize( sizeHint() );
+    bookmarksList->setEditTriggers( QAbstractItemView::SelectedClicked |
+                                    QAbstractItemView::DoubleClicked );
 
-    QStringList headerLabels;
-    headerLabels << qtr( "Description" );
-    headerLabels << qtr( "Bytes" );
-    headerLabels << qtr( "Time" );
-    bookmarksList->setHeaderLabels( headerLabels );
+    bookmarksList->resize( sizeHint() );
 
     layout->addWidget( buttonsBox );
     layout->addWidget( bookmarksList );
 
-    CONNECT( THEMIM, bookmarksChanged(),
-             this, update() );
-
     CONNECT( bookmarksList, activated( QModelIndex ), this,
              activateItem( QModelIndex ) );
-    CONNECT( bookmarksList, itemChanged( QTreeWidgetItem*, int ),
-             this, edit( QTreeWidgetItem*, int ) );
-    CONNECT( bookmarksList->model(), rowsInserted( const QModelIndex &, int, int ),
-             this, updateButtons() );
-    CONNECT( bookmarksList->model(), rowsRemoved( const QModelIndex &, int, int ),
-             this, updateButtons() );
+    CONNECT( m_model, modelReset(), this, updateButtons() );
     CONNECT( bookmarksList->selectionModel(), selectionChanged( const QItemSelection &, const QItemSelection & ),
              this, updateButtons() );
     BUTTONACT( addButton, add() );
@@ -118,29 +112,19 @@ void BookmarksDialog::updateButtons()
     delButton->setEnabled( bookmarksList->selectionModel()->hasSelection() );
 }
 
-void BookmarksDialog::update()
-{
-    //FIXME unimplemented
-}
-
 void BookmarksDialog::add()
 {
-    //FIXME unimplemented
+    m_model->add();
 }
 
 void BookmarksDialog::del()
 {
-    //FIXME unimplemented
+    m_model->remove( bookmarksList->selectionModel()->selectedIndexes() );
 }
 
 void BookmarksDialog::clear()
 {
-    //FIXME unimplemented
-}
-
-void BookmarksDialog::edit( QTreeWidgetItem *, int )
-{
-    //FIXME unimplemented
+    m_model->clear();
 }
 
 void BookmarksDialog::extract()
@@ -148,9 +132,9 @@ void BookmarksDialog::extract()
     // TODO
 }
 
-void BookmarksDialog::activateItem( QModelIndex )
+void BookmarksDialog::activateItem( const QModelIndex& index )
 {
-    //FIXME unimplemented
+    m_model->select( index );
 }
 
 void BookmarksDialog::toggleVisible()
diff --git a/modules/gui/qt/dialogs/bookmarks/bookmarks.hpp b/modules/gui/qt/dialogs/bookmarks/bookmarks.hpp
index 52b0e9f402..96506e71a4 100644
--- a/modules/gui/qt/dialogs/bookmarks/bookmarks.hpp
+++ b/modules/gui/qt/dialogs/bookmarks/bookmarks.hpp
@@ -30,6 +30,7 @@
 #include <QTreeWidget>
 #include "util/singleton.hpp"
 class QPushButton;
+class MLBookmarkModel;
 
 class BookmarksDialog : public QVLCFrame, public Singleton<BookmarksDialog>
 {
@@ -40,19 +41,17 @@ private:
     BookmarksDialog( intf_thread_t * );
     virtual ~BookmarksDialog();
 
-    QTreeWidget *bookmarksList;
+    QTreeView *bookmarksList;
     QPushButton *clearButton;
     QPushButton *delButton;
-    bool b_ignore_updates;
+    MLBookmarkModel* m_model;
 
 private slots:
-    void update();
     void add();
     void del();
     void clear();
-    void edit( QTreeWidgetItem *item, int column );
     void extract();
-    void activateItem( QModelIndex index );
+    void activateItem( const QModelIndex& index );
     void updateButtons();
 
     friend class    Singleton<BookmarksDialog>;
diff --git a/modules/gui/qt/menus/qml/PlaybackMenu.qml b/modules/gui/qt/menus/qml/PlaybackMenu.qml
index 20acebd326..33e2bea28e 100644
--- a/modules/gui/qt/menus/qml/PlaybackMenu.qml
+++ b/modules/gui/qt/menus/qml/PlaybackMenu.qml
@@ -45,13 +45,11 @@ Widgets.MenuExt {
         model: player.programs
     }
 
-    /*
-    //FIXME unimplemented
-    Menu {
-        title: i18n.qtr("Custom Bookmarks");
-        enabled: isPlaying
+    Action {
+        text: i18n.qtr("Custom Bookmarks")
+        onTriggered: dialogProvider.bookmarksDialog()
+        enabled: player.isPlaying
     }
-    */
 
     MenuSeparator { }
 
-- 
2.20.1



More information about the vlc-devel mailing list