certmanager

crlview.cpp
1 /*
2  crlview.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the TQt library by Trolltech AS, Norway (or with modified versions
24  of TQt that use the same license as TQt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  TQt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36 
37 #include "crlview.h"
38 
39 #include <tdelocale.h>
40 #include <tdeprocess.h>
41 #include <tdemessagebox.h>
42 #include <kpushbutton.h>
43 #include <kstdguiitem.h>
44 #include <tdeglobalsettings.h>
45 
46 #include <tqlayout.h>
47 #include <tqlabel.h>
48 #include <tqtextedit.h>
49 #include <tqfontmetrics.h>
50 #include <tqtimer.h>
51 
52 CRLView::CRLView( TQWidget* parent, const char* name, bool modal )
53  : TQDialog( parent, name, modal ), _process(0)
54 {
55  TQVBoxLayout* topLayout = new TQVBoxLayout( this, 10, 4 );
56 
57  topLayout->addWidget( new TQLabel( i18n("CRL cache dump:"), this ) );
58 
59  _textView = new TQTextEdit( this );
60  _textView->setFont( TDEGlobalSettings::fixedFont() );
61  _textView->setTextFormat( TQTextEdit::LogText );
62  topLayout->addWidget( _textView );
63 
64  TQHBoxLayout* hbLayout = new TQHBoxLayout( topLayout );
65 
66  _updateButton = new KPushButton( i18n("&Update"), this );
67  _closeButton = new KPushButton( KStdGuiItem::close(), this );
68 
69  hbLayout->addWidget( _updateButton );
70  hbLayout->addStretch();
71  hbLayout->addWidget( _closeButton );
72 
73  // connections:
74  connect( _updateButton, TQ_SIGNAL( clicked() ),
75  this, TQ_SLOT( slotUpdateView() ) );
76  connect( _closeButton, TQ_SIGNAL( clicked() ),
77  this, TQ_SLOT( close() ) );
78 
79  resize( _textView->fontMetrics().width( 'M' ) * 80,
80  _textView->fontMetrics().lineSpacing() * 25 );
81 
82  _timer = new TQTimer( this );
83  connect( _timer, TQ_SIGNAL(timeout()), TQ_SLOT(slotAppendBuffer()) );
84 }
85 
86 CRLView::~CRLView()
87 {
88  delete _process; _process = 0;
89 }
90 
91 void CRLView::closeEvent( TQCloseEvent * e ) {
92  TQDialog::closeEvent( e );
93  delete _process; _process = 0;
94 }
95 
96 void CRLView::slotUpdateView()
97 {
98  _updateButton->setEnabled( false );
99  _textView->clear();
100  _buffer = TQString();
101  if( _process == 0 ) {
102  _process = new TDEProcess();
103  *_process << "gpgsm" << "--call-dirmngr" << "listcrls";
104  connect( _process, TQ_SIGNAL( receivedStdout( TDEProcess*, char*, int) ),
105  this, TQ_SLOT( slotReadStdout( TDEProcess*, char*, int ) ) );
106  connect( _process, TQ_SIGNAL( processExited( TDEProcess* ) ),
107  this, TQ_SLOT( slotProcessExited() ) );
108  }
109  if( _process->isRunning() ) _process->kill();
110  if( !_process->start( TDEProcess::NotifyOnExit, TDEProcess::Stdout ) ) {
111  KMessageBox::error( this, i18n( "Unable to start gpgsm process. Please check your installation." ), i18n( "Certificate Manager Error" ) );
112  slotProcessExited();
113  }
114  _timer->start( 1000 );
115 }
116 
117 void CRLView::slotReadStdout( TDEProcess*, char* buf, int len)
118 {
119  _buffer.append( TQString::fromUtf8( buf, len ) );
120 }
121 
122 void CRLView::slotAppendBuffer() {
123  _textView->append( _buffer );
124  _buffer = TQString();
125 }
126 
127 void CRLView::slotProcessExited()
128 {
129  _timer->stop();
130  slotAppendBuffer();
131  _updateButton->setEnabled( true );
132 
133  if( !_process->normalExit() ) {
134  KMessageBox::error( this, i18n( "The GpgSM process ended prematurely because of an unexpected error." ), i18n( "Certificate Manager Error" ) );
135  }
136 }
137 
138 #include "crlview.moc"