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 TQt library by Trolltech AS, Norway (or with modified versions 00024 of TQt that use the same license as TQt), 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 TQt. 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 <tdelocale.h> 00040 #include <kprocess.h> 00041 #include <tdemessagebox.h> 00042 #include <kpushbutton.h> 00043 #include <kstdguiitem.h> 00044 #include <tdeglobalsettings.h> 00045 00046 #include <tqlayout.h> 00047 #include <tqlabel.h> 00048 #include <tqtextedit.h> 00049 #include <tqfontmetrics.h> 00050 #include <tqtimer.h> 00051 00052 CRLView::CRLView( TQWidget* parent, const char* name, bool modal ) 00053 : TQDialog( parent, name, modal ), _process(0) 00054 { 00055 TQVBoxLayout* topLayout = new TQVBoxLayout( this, 10, 4 ); 00056 00057 topLayout->addWidget( new TQLabel( i18n("CRL cache dump:"), this ) ); 00058 00059 _textView = new TQTextEdit( this ); 00060 _textView->setFont( TDEGlobalSettings::fixedFont() ); 00061 _textView->setTextFormat( TQTextEdit::LogText ); 00062 topLayout->addWidget( _textView ); 00063 00064 TQHBoxLayout* hbLayout = new TQHBoxLayout( 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, TQT_SIGNAL( clicked() ), 00075 this, TQT_SLOT( slotUpdateView() ) ); 00076 connect( _closeButton, TQT_SIGNAL( clicked() ), 00077 this, TQT_SLOT( close() ) ); 00078 00079 resize( _textView->fontMetrics().width( 'M' ) * 80, 00080 _textView->fontMetrics().lineSpacing() * 25 ); 00081 00082 _timer = new TQTimer( this ); 00083 connect( _timer, TQT_SIGNAL(timeout()), TQT_SLOT(slotAppendBuffer()) ); 00084 } 00085 00086 CRLView::~CRLView() 00087 { 00088 delete _process; _process = 0; 00089 } 00090 00091 void CRLView::closeEvent( TQCloseEvent * e ) { 00092 TQDialog::closeEvent( e ); 00093 delete _process; _process = 0; 00094 } 00095 00096 void CRLView::slotUpdateView() 00097 { 00098 _updateButton->setEnabled( false ); 00099 _textView->clear(); 00100 _buffer = TQString(); 00101 if( _process == 0 ) { 00102 _process = new TDEProcess(); 00103 *_process << "gpgsm" << "--call-dirmngr" << "listcrls"; 00104 connect( _process, TQT_SIGNAL( receivedStdout( TDEProcess*, char*, int) ), 00105 this, TQT_SLOT( slotReadStdout( TDEProcess*, char*, int ) ) ); 00106 connect( _process, TQT_SIGNAL( processExited( TDEProcess* ) ), 00107 this, TQT_SLOT( slotProcessExited() ) ); 00108 } 00109 if( _process->isRunning() ) _process->kill(); 00110 if( !_process->start( TDEProcess::NotifyOnExit, TDEProcess::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( TDEProcess*, char* buf, int len) 00118 { 00119 _buffer.append( TQString::fromUtf8( buf, len ) ); 00120 } 00121 00122 void CRLView::slotAppendBuffer() { 00123 _textView->append( _buffer ); 00124 _buffer = TQString(); 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"