00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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"