certmanager/lib

passphrasedialog.cpp

00001 /*  -*- c++ -*-
00002     passphrasedialog.cpp
00003 
00004     This file is part of libkleopatra, the KDE keymanagement library
00005     Copyright (c) 2004 Klarälvdalens Datakonsult AB
00006 
00007     Libkleopatra is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License as
00009     published by the Free Software Foundation; either version 2 of the
00010     License, or (at your option) any later version.
00011 
00012     Libkleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 
00032 
00033     Based on kpgpui.cpp
00034     Copyright (C) 2001,2002 the KPGP authors
00035     See file libkdenetwork/AUTHORS.kpgp for details
00036 
00037     This file is part of KPGP, the KDE PGP/GnuPG support library.
00038 
00039     KPGP is free software; you can redistribute it and/or modify
00040     it under the terms of the GNU General Public License as published by
00041     the Free Software Foundation; either version 2 of the License, or
00042     (at your option) any later version.
00043 
00044     You should have received a copy of the GNU General Public License
00045     along with this program; if not, write to the Free Software Foundation,
00046     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00047 */
00048 
00049 #ifndef HAVE_CONFIG_H
00050 #include <config.h>
00051 #endif
00052 
00053 #include "passphrasedialog.h"
00054 
00055 #include <kpassdlg.h>
00056 #include <kiconloader.h>
00057 #include <klocale.h>
00058 
00059 #include <qlabel.h>
00060 #include <qlayout.h>
00061 #include <qfontmetrics.h>
00062 
00063 struct Kleo::PassphraseDialog::Private {
00064   KPasswordEdit * lineedit;
00065 };
00066 
00067 
00068 Kleo::PassphraseDialog::PassphraseDialog( const QString & msg, const QString & caption,
00069                       QWidget * parent, const char * name, bool modal )
00070   : KDialogBase( parent, name, modal, caption, Ok|Cancel, Ok ), d( 0 )
00071 {
00072   d = new Private();
00073 
00074   QWidget * w = new QWidget( this );
00075   setMainWidget( w );
00076 
00077   QHBoxLayout * hlay = new QHBoxLayout( w, 0, spacingHint() );
00078 
00079   QLabel * label = new QLabel( w );
00080   label->setPixmap( DesktopIcon( "pgp-keys", KIcon::SizeMedium ) );
00081   hlay->addWidget( label, 0, AlignTop );
00082 
00083   QVBoxLayout * vlay = new QVBoxLayout( hlay ); // inherits spacing
00084 
00085   vlay->addWidget( new QLabel( msg.isEmpty() ? i18n("Please enter your passphrase:") : msg, w ) );
00086 
00087   d->lineedit = new KPasswordEdit( KPasswordEdit::OneStar, w, "d->lineedit" );
00088   d->lineedit->setMinimumWidth( fontMetrics().width("*") * 20 );
00089   d->lineedit->setFocus();
00090 
00091   vlay->addWidget( d->lineedit );
00092 
00093   connect( d->lineedit, SIGNAL(returnPressed()), SLOT(slotOk()) );
00094 
00095   disableResize();
00096 }
00097 
00098 
00099 Kleo::PassphraseDialog::~PassphraseDialog() {
00100   delete d; d = 0;
00101 }
00102 
00103 const char * Kleo::PassphraseDialog::passphrase() const {
00104   return d->lineedit->password();
00105 }
00106 
00107 void Kleo::PassphraseDialog::slotOk() {
00108   const char * pass = passphrase();
00109   emit finished( pass ? pass : "" );
00110   KDialogBase::slotOk();
00111 }
00112 
00113 void Kleo::PassphraseDialog::slotCancel() {
00114   emit canceled();
00115   KDialogBase::slotCancel();
00116 }
00117 
00118   
00119 void Kleo::PassphraseDialog::virtual_hook( int id, void * data ) {
00120   return KDialogBase::virtual_hook( id, data );
00121 }
00122 
00123 #include "passphrasedialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys