kleopatra
certificaterequester.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "certificaterequester.h"
00023
00024 #include <libkleopatraclient/core/selectcertificatecommand.h>
00025
00026 #include <QPointer>
00027 #include <QPushButton>
00028 #include <QLabel>
00029 #include <QLineEdit>
00030 #include <QLayout>
00031 #include <QMessageBox>
00032
00033 #include <memory>
00034
00035 using namespace KLEOPATRACLIENT_NAMESPACE;
00036 using namespace KLEOPATRACLIENT_NAMESPACE::Gui;
00037
00038 class CertificateRequester::Private {
00039 friend class ::KLEOPATRACLIENT_NAMESPACE::Gui::CertificateRequester;
00040 CertificateRequester * const q;
00041 public:
00042 explicit Private( CertificateRequester * qq )
00043 : q( qq ),
00044 selectedCertificates(),
00045 command(),
00046 multipleCertificatesAllowed(),
00047 onlySigningCertificatesAllowed(),
00048 onlyEncryptionCertificatesAllowed(),
00049 onlyOpenPGPCertificatesAllowed(),
00050 onlyX509CertificatesAllowed(),
00051 onlySecretKeysAllowed(),
00052 ui( q )
00053 {
00054
00055 }
00056
00057 private:
00058 void updateLineEdit() {
00059 ui.lineEdit.setText( selectedCertificates.join( QLatin1String( " " ) ) );
00060 }
00061 void createCommand() {
00062 std::auto_ptr<SelectCertificateCommand> cmd( new SelectCertificateCommand );
00063
00064 cmd->setMultipleCertificatesAllowed( multipleCertificatesAllowed );
00065 cmd->setOnlySigningCertificatesAllowed( onlySigningCertificatesAllowed );
00066 cmd->setOnlyEncryptionCertificatesAllowed( onlyEncryptionCertificatesAllowed );
00067 cmd->setOnlyOpenPGPCertificatesAllowed( onlyOpenPGPCertificatesAllowed );
00068 cmd->setOnlyX509CertificatesAllowed( onlyX509CertificatesAllowed );
00069 cmd->setOnlySecretKeysAllowed( onlySecretKeysAllowed );
00070
00071 cmd->setSelectedCertificates( selectedCertificates );
00072
00073 if ( const QWidget * const window = q->window() )
00074 #if QT_VERSION < 0x040400
00075 cmd->setParentWId( window->winId() );
00076 #else
00077 cmd->setParentWId( window->effectiveWinId() );
00078 #endif
00079
00080 connect( cmd.get(), SIGNAL(finished()), q, SLOT(slotCommandFinished()) );
00081
00082 command = cmd.release();
00083 }
00084
00085 void slotButtonClicked();
00086 void slotCommandFinished();
00087
00088 private:
00089 QStringList selectedCertificates;
00090
00091 QPointer<SelectCertificateCommand> command;
00092
00093 bool multipleCertificatesAllowed : 1;
00094 bool onlySigningCertificatesAllowed : 1;
00095 bool onlyEncryptionCertificatesAllowed : 1;
00096 bool onlyOpenPGPCertificatesAllowed : 1;
00097 bool onlyX509CertificatesAllowed : 1;
00098 bool onlySecretKeysAllowed : 1;
00099
00100 struct Ui {
00101 QLineEdit lineEdit;
00102 QPushButton button;
00103 QHBoxLayout hlay;
00104
00105 explicit Ui( CertificateRequester * qq )
00106 : lineEdit( qq ),
00107 button( tr("Change..."), qq ),
00108 hlay( qq )
00109 {
00110 lineEdit.setObjectName( QLatin1String( "lineEdit" ) );
00111 button.setObjectName( QLatin1String( "button" ) );
00112 hlay.setObjectName( QLatin1String( "hlay" ) );
00113
00114 hlay.addWidget( &lineEdit, 1 );
00115 hlay.addWidget( &button );
00116
00117 lineEdit.setReadOnly( true );
00118
00119 connect( &button, SIGNAL(clicked()),
00120 qq, SLOT(slotButtonClicked()) );
00121 }
00122
00123 } ui;
00124 };
00125
00126 CertificateRequester::CertificateRequester( QWidget * p, Qt::WindowFlags f )
00127 : QWidget( p, f ), d( new Private( this ) )
00128 {
00129
00130 }
00131
00132 CertificateRequester::~CertificateRequester() {
00133 delete d; d = 0;
00134 }
00135
00136
00137
00138 void CertificateRequester::setMultipleCertificatesAllowed( bool allow ) {
00139 if ( allow == d->multipleCertificatesAllowed )
00140 return;
00141 d->multipleCertificatesAllowed = allow;
00142 }
00143
00144 bool CertificateRequester::multipleCertificatesAllowed() const {
00145 return d->multipleCertificatesAllowed;
00146 }
00147
00148
00149 void CertificateRequester::setOnlySigningCertificatesAllowed( bool allow ) {
00150 if ( allow == d->onlySigningCertificatesAllowed )
00151 return;
00152 d->onlySigningCertificatesAllowed = allow;
00153 }
00154
00155 bool CertificateRequester::onlySigningCertificatesAllowed() const {
00156 return d->onlySigningCertificatesAllowed;
00157 }
00158
00159
00160 void CertificateRequester::setOnlyEncryptionCertificatesAllowed( bool allow ) {
00161 if ( allow == d->onlyEncryptionCertificatesAllowed )
00162 return;
00163 d->onlyEncryptionCertificatesAllowed = allow;
00164 }
00165
00166 bool CertificateRequester::onlyEncryptionCertificatesAllowed() const {
00167 return d->onlyEncryptionCertificatesAllowed;
00168 }
00169
00170
00171 void CertificateRequester::setOnlyOpenPGPCertificatesAllowed( bool allow ) {
00172 if ( allow == d->onlyOpenPGPCertificatesAllowed )
00173 return;
00174 d->onlyOpenPGPCertificatesAllowed = allow;
00175 }
00176
00177 bool CertificateRequester::onlyOpenPGPCertificatesAllowed() const {
00178 return d->onlyOpenPGPCertificatesAllowed;
00179 }
00180
00181
00182 void CertificateRequester::setOnlyX509CertificatesAllowed( bool allow ) {
00183 if ( allow == d->onlyX509CertificatesAllowed )
00184 return;
00185 d->onlyX509CertificatesAllowed = allow;
00186 }
00187
00188 bool CertificateRequester::onlyX509CertificatesAllowed() const {
00189 return d->onlyX509CertificatesAllowed;
00190 }
00191
00192
00193 void CertificateRequester::setOnlySecretKeysAllowed( bool allow ) {
00194 if ( allow == d->onlySecretKeysAllowed )
00195 return;
00196 d->onlySecretKeysAllowed = allow;
00197 }
00198
00199 bool CertificateRequester::onlySecretKeysAllowed() const {
00200 return d->onlySecretKeysAllowed;
00201 }
00202
00203
00204 void CertificateRequester::setSelectedCertificates( const QStringList & certs ) {
00205 if ( certs == d->selectedCertificates )
00206 return;
00207 d->selectedCertificates = certs;
00208 d->updateLineEdit();
00209 selectedCertificatesChanged( certs );
00210 }
00211
00212 QStringList CertificateRequester::selectedCertificates() const {
00213 return d->selectedCertificates;
00214 }
00215
00216
00217 void CertificateRequester::setSelectedCertificate( const QString & cert ) {
00218 setSelectedCertificates( QStringList( cert ) );
00219 }
00220
00221 QString CertificateRequester::selectedCertificate() const {
00222 return d->selectedCertificates.empty() ? QString() : d->selectedCertificates.front() ;
00223 }
00224
00225 void CertificateRequester::Private::slotButtonClicked() {
00226 if ( command )
00227 return;
00228 createCommand();
00229 command->start();
00230 ui.button.setEnabled( false );
00231 }
00232
00233 void CertificateRequester::Private::slotCommandFinished() {
00234 if ( command->wasCanceled() )
00235 ;
00236 else if ( command->error() )
00237 QMessageBox::information( q,
00238 tr("Kleopatra Error"),
00239 tr("There was an error while connecting to Kleopatra: %1" )
00240 .arg( command->errorString() ) );
00241 else
00242 q->setSelectedCertificates( command->selectedCertificates() );
00243 ui.button.setEnabled( true );
00244 delete command;
00245 }
00246
00247 #include "moc_certificaterequester.cpp"