[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/kleopatra/dialogs
From:       Marc Mutz <mutz () kde ! org>
Date:       2008-03-04 15:31:58
Message-ID: 1204644718.534066.14598.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 782209 by mutz:

Enable/disable Ok button, allow double-click exit of keys

 M  +52 -0     certificateselectiondialog.cpp  
 M  +4 -0      certificateselectiondialog.h  


--- trunk/KDE/kdepim/kleopatra/dialogs/certificateselectiondialog.cpp #782208:782209
@@ -21,6 +21,7 @@
 #include <QLayout>
 #include <QItemSelectionModel>
 #include <QAbstractItemView>
+#include <QPointer>
 
 #include <boost/bind.hpp>
 
@@ -41,8 +42,14 @@
 private:
     void refresh();
     void slotRefreshed();
+    void slotCurrentViewChanged( QAbstractItemView * newView );
+    void slotSelectionChanged();
+    void slotDoubleClicked( const QModelIndex & idx );
 
 private:
+    bool acceptable( const std::vector<Key> & keys ) {
+        return !keys.empty();
+    }
     void filterAllowedKeys( std::vector<Key> & keys );
     void updateLabelText() {
         ui.label.setText( !customLabelText.isEmpty() ? customLabelText :
@@ -52,6 +59,7 @@
     }
 
 private:
+    QPointer<QAbstractItemView> lastView;
     QString customLabelText;
     Options options;
 
@@ -81,6 +89,7 @@
             vlay.addWidget( &buttonBox );
 
             QPushButton * const ok = buttonBox.addButton( QDialogButtonBox::Ok );
+            ok->setEnabled( false );
             QPushButton * const cancel = buttonBox.addButton( \
                QDialogButtonBox::Close );
             QPushButton * const refresh = buttonBox.addButton( i18n("&Refresh \
Certificates"), QDialogButtonBox::ActionRole );  
@@ -100,6 +109,9 @@
     ui.tabWidget.setHierarchicalModel( \
AbstractKeyListModel::createHierarchicalKeyListModel() );  \
ui.tabWidget.connectSearchBar( &ui.searchBar );  
+    connect( &ui.tabWidget, SIGNAL(currentViewChanged(QAbstractItemView*)),
+             q, SLOT(slotCurrentViewChanged(QAbstractItemView*)) );
+
     updateLabelText();
     q->setWindowTitle( i18n( "Certificate Selection" ) );
 }
@@ -242,4 +254,44 @@
     keys.erase( end, keys.end() );
 }
 
+void CertificateSelectionDialog::Private::slotCurrentViewChanged( QAbstractItemView \
* newView ) { +    if ( lastView ) {
+        disconnect( lastView, SIGNAL(doubleClicked(QModelIndex)),
+                    q, SLOT(slotDoubleClicked(QModelIndex)) );
+        assert( lastView->selectionModel() );
+        disconnect( lastView->selectionModel(), \
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), +                    q, \
SLOT(slotSelectionChanged()) ); +    }
+    lastView = newView;
+    if ( newView ) {
+        connect( newView, SIGNAL(doubleClicked(QModelIndex)),
+                 q, SLOT(slotDoubleClicked(QModelIndex)) );
+        assert( newView->selectionModel() );
+        connect( newView->selectionModel(), \
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), +                 q, \
SLOT(slotSelectionChanged()) ); +    }
+    slotSelectionChanged();
+}
+
+void CertificateSelectionDialog::Private::slotSelectionChanged() {
+    if ( QPushButton * const pb = ui.buttonBox.button( QDialogButtonBox::Ok ) )
+        pb->setEnabled( acceptable( q->selectedCertificates() ) );
+}
+
+void CertificateSelectionDialog::Private::slotDoubleClicked( const QModelIndex & idx \
) { +    QAbstractItemView * const view = ui.tabWidget.currentView();
+    assert( view );
+    const KeyListModelInterface * const model = \
dynamic_cast<KeyListModelInterface*>( view->model() ); +    assert( model );
+    QItemSelectionModel * const sm = view->selectionModel();
+    assert( sm );
+    sm->select( idx, QItemSelectionModel::ClearAndSelect );
+    QMetaObject::invokeMethod( q, "accept", Qt::QueuedConnection );
+}
+
+void CertificateSelectionDialog::accept() {
+    if ( d->acceptable( selectedCertificates() ) )
+        QDialog::accept();
+}
+
 #include "moc_certificateselectiondialog.cpp"
--- trunk/KDE/kdepim/kleopatra/dialogs/certificateselectiondialog.h #782208:782209
@@ -63,6 +63,7 @@
     public Q_SLOTS:
         void setStringFilter( const QString & text );
         void setKeyFilter( const boost::shared_ptr<Kleo::KeyFilter> & filter );
+        /* reimp */ void accept();
 
     protected:
         void hideEvent( QHideEvent * );
@@ -72,6 +73,9 @@
         kdtools::pimpl_ptr<Private> d;
         Q_PRIVATE_SLOT( d, void refresh() )
         Q_PRIVATE_SLOT( d, void slotRefreshed() )
+        Q_PRIVATE_SLOT( d, void slotSelectionChanged() )
+        Q_PRIVATE_SLOT( d, void slotDoubleClicked( QModelIndex ) )
+        Q_PRIVATE_SLOT( d, void slotCurrentViewChanged( QAbstractItemView * ) )
     };
 
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic