certmanager

crlview.cpp

00001 /*
00002     crlview.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra 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 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036 
00037 #include "crlview.h"
00038 
00039 #include <klocale.h>
00040 #include <kprocess.h>
00041 #include <kmessagebox.h>
00042 #include <kpushbutton.h>
00043 #include <kstdguiitem.h>
00044 #include <kglobalsettings.h>
00045 
00046 #include <qlayout.h>
00047 #include <qlabel.h>
00048 #include <qtextedit.h>
00049 #include <qfontmetrics.h>
00050 #include <qtimer.h>
00051 
00052 CRLView::CRLView( QWidget* parent, const char* name, bool modal )
00053   : QDialog( parent, name, modal ), _process(0)
00054 {
00055   QVBoxLayout* topLayout = new QVBoxLayout( this, 10, 4 );
00056 
00057   topLayout->addWidget( new QLabel( i18n("CRL cache dump:"), this ) );
00058 
00059   _textView = new QTextEdit( this );
00060   _textView->setFont( KGlobalSettings::fixedFont() );
00061   _textView->setTextFormat( QTextEdit::LogText );
00062   topLayout->addWidget( _textView );
00063 
00064   QHBoxLayout* hbLayout = new QHBoxLayout( topLayout );
00065 
00066   _updateButton = new KPushButton( i18n("&Update"), this );
00067   _closeButton = new KPushButton( KStdGuiItem::close(), this );
00068 
00069   hbLayout->addWidget( _updateButton );
00070   hbLayout->addStretch();
00071   hbLayout->addWidget( _closeButton );
00072 
00073   // connections:
00074   connect( _updateButton, SIGNAL( clicked() ),
00075        this, SLOT( slotUpdateView() ) );
00076   connect( _closeButton, SIGNAL( clicked() ),
00077        this, SLOT( close() ) );
00078 
00079   resize( _textView->fontMetrics().width( 'M' ) * 80,
00080       _textView->fontMetrics().lineSpacing() * 25 );
00081 
00082   _timer = new QTimer( this );
00083   connect( _timer, SIGNAL(timeout()), SLOT(slotAppendBuffer()) );
00084 }
00085 
00086 CRLView::~CRLView()
00087 {
00088   delete _process; _process = 0;
00089 }
00090 
00091 void CRLView::closeEvent( QCloseEvent * e ) {
00092   QDialog::closeEvent( e );
00093   delete _process; _process = 0;
00094 }
00095 
00096 void CRLView::slotUpdateView()
00097 {
00098   _updateButton->setEnabled( false );
00099   _textView->clear();
00100   _buffer = QString::null;
00101   if( _process == 0 ) {
00102     _process = new KProcess();
00103     *_process << "gpgsm" << "--call-dirmngr" << "listcrls";
00104     connect( _process, SIGNAL( receivedStdout( KProcess*, char*, int) ),
00105          this, SLOT( slotReadStdout( KProcess*, char*, int ) ) );
00106     connect( _process, SIGNAL( processExited( KProcess* ) ),
00107          this, SLOT( slotProcessExited() ) );
00108   }
00109   if( _process->isRunning() ) _process->kill();
00110   if( !_process->start( KProcess::NotifyOnExit, KProcess::Stdout ) ) {
00111     KMessageBox::error( this, i18n( "Unable to start gpgsm process. Please check your installation." ), i18n( "Certificate Manager Error" ) );
00112     slotProcessExited();
00113   }
00114   _timer->start( 1000 );
00115 }
00116 
00117 void CRLView::slotReadStdout( KProcess*, char* buf, int len)
00118 {
00119   _buffer.append( QString::fromUtf8( buf, len ) );
00120 }
00121 
00122 void CRLView::slotAppendBuffer() {
00123   _textView->append( _buffer );
00124   _buffer = QString::null;
00125 }
00126 
00127 void CRLView::slotProcessExited()
00128 {
00129   _timer->stop();
00130   slotAppendBuffer();
00131   _updateButton->setEnabled( true );
00132 
00133   if( !_process->normalExit() ) {
00134     KMessageBox::error( this, i18n( "The GpgSM process ended prematurely because of an unexpected error." ), i18n( "Certificate Manager Error" ) );
00135   }
00136 }
00137 
00138 #include "crlview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys