[vlc-commits] Qt: Bookmarks: correctly apply buttons states

Francois Cartegnie git at videolan.org
Sat Aug 18 21:56:13 CEST 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Aug 18 20:58:34 2012 +0200| [1debd1994a95062600ccc4ede5e27616a698b4ed] | committer: Francois Cartegnie

Qt: Bookmarks: correctly apply buttons states

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

 modules/gui/qt4/dialogs/bookmarks.cpp |   19 ++++++++++++++++---
 modules/gui/qt4/dialogs/bookmarks.hpp |    4 ++++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt4/dialogs/bookmarks.cpp b/modules/gui/qt4/dialogs/bookmarks.cpp
index aeff9dc..718a995 100644
--- a/modules/gui/qt4/dialogs/bookmarks.cpp
+++ b/modules/gui/qt4/dialogs/bookmarks.cpp
@@ -45,10 +45,10 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
     QPushButton *addButton = new QPushButton( qtr( "Create" ) );
     addButton->setToolTip( qtr( "Create a new bookmark" ) );
     buttonsBox->addButton( addButton, QDialogButtonBox::ActionRole );
-    QPushButton *delButton = new QPushButton( qtr( "Delete" ) );
+    delButton = new QPushButton( qtr( "Delete" ) );
     delButton->setToolTip( qtr( "Delete the selected item" ) );
     buttonsBox->addButton( delButton, QDialogButtonBox::ActionRole );
-    QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
+    clearButton = new QPushButton( qtr( "Clear" ) );
     clearButton->setToolTip( qtr( "Delete all the bookmarks" ) );
     buttonsBox->addButton( clearButton, QDialogButtonBox::ResetRole );
 #if 0
@@ -85,14 +85,21 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf ):QVLCFrame( _p_intf )
              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( bookmarksList->selectionModel(), selectionChanged( const QItemSelection &, const QItemSelection & ),
+             this, updateButtons() );
     BUTTONACT( addButton, add() );
     BUTTONACT( delButton, del() );
     BUTTONACT( clearButton, clear() );
+
 #if 0
     BUTTONACT( extractButton, extract() );
 #endif
     CONNECT( buttonsBox, rejected(), this, close() );
+    updateButtons();
 
     restoreWidgetPosition( "Bookmarks", QSize( 435, 280 ) );
     updateGeometry();
@@ -103,6 +110,12 @@ BookmarksDialog::~BookmarksDialog()
     saveWidgetPosition( "Bookmarks" );
 }
 
+void BookmarksDialog::updateButtons()
+{
+    clearButton->setEnabled( bookmarksList->model()->rowCount() > 0 );
+    delButton->setEnabled( bookmarksList->selectionModel()->hasSelection() );
+}
+
 void BookmarksDialog::update()
 {
     input_thread_t *p_input = THEMIM->getInput();
diff --git a/modules/gui/qt4/dialogs/bookmarks.hpp b/modules/gui/qt4/dialogs/bookmarks.hpp
index 119960c..db46e00 100644
--- a/modules/gui/qt4/dialogs/bookmarks.hpp
+++ b/modules/gui/qt4/dialogs/bookmarks.hpp
@@ -30,6 +30,7 @@
 #include <QTreeView>
 #include <QTreeWidget>
 #include "util/singleton.hpp"
+class QPushButton;
 
 class BookmarksDialog : public QVLCFrame, public Singleton<BookmarksDialog>
 {
@@ -39,6 +40,8 @@ private:
     virtual ~BookmarksDialog();
 
     QTreeWidget *bookmarksList;
+    QPushButton *clearButton;
+    QPushButton *delButton;
 
 private slots:
     void update();
@@ -48,6 +51,7 @@ private slots:
     void edit( QTreeWidgetItem *item, int column );
     void extract();
     void activateItem( QModelIndex index );
+    void updateButtons();
 
     friend class    Singleton<BookmarksDialog>;
 };



More information about the vlc-commits mailing list