Better wording
[kdepim.git] / kleopatra / crlview.cpp
blobdd239aca4e91dea226401f69ff4631f3730771f6
1 /*
2 crlview.cpp
4 This file is part of Kleopatra, the KDE keymanager
5 Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB
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.
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.
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
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 Qt library by Trolltech AS, Norway (or with modified versions
24 of Qt that use the same license as Qt), 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 Qt. 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.
33 #include <config-kleopatra.h>
35 #include "crlview.h"
37 #include <klocale.h>
38 #include <kprocess.h>
39 #include <kmessagebox.h>
40 #include <kpushbutton.h>
41 #include <KStandardGuiItem>
42 #include <kglobalsettings.h>
44 #include <QLayout>
45 #include <QLabel>
46 #include <qtextedit.h>
47 #include <QFontMetrics>
48 #include <QTimer>
49 //Added by qt3to4:
50 #include <QVBoxLayout>
51 #include <QHBoxLayout>
52 #include <QCloseEvent>
54 CRLView::CRLView( QWidget* parent )
55 : QDialog( parent ), _process(0)
57 QVBoxLayout* topLayout = new QVBoxLayout( this );
58 topLayout->setSpacing( 4 );
59 topLayout->setMargin( 10 );
61 topLayout->addWidget( new QLabel( i18n("CRL cache dump:"), this ) );
63 _textView = new QTextEdit( this );
64 _textView->setFont( KGlobalSettings::fixedFont() );
65 _textView->setReadOnly(true);
66 topLayout->addWidget( _textView );
68 QHBoxLayout* hbLayout = new QHBoxLayout();
69 topLayout->addItem( hbLayout );
71 _updateButton = new KPushButton( i18n("&Update"), this );
72 _closeButton = new KPushButton( KStandardGuiItem::close(), this );
74 hbLayout->addWidget( _updateButton );
75 hbLayout->addStretch();
76 hbLayout->addWidget( _closeButton );
78 // connections:
79 connect( _updateButton, SIGNAL(clicked()),
80 this, SLOT(slotUpdateView()) );
81 connect( _closeButton, SIGNAL(clicked()),
82 this, SLOT(close()) );
84 resize( _textView->fontMetrics().width( 'M' ) * 80,
85 _textView->fontMetrics().lineSpacing() * 25 );
87 _timer = new QTimer( this );
88 connect( _timer, SIGNAL(timeout()), SLOT(slotAppendBuffer()) );
91 CRLView::~CRLView()
93 delete _process; _process = 0;
96 void CRLView::closeEvent( QCloseEvent * e ) {
97 QDialog::closeEvent( e );
98 delete _process; _process = 0;
101 void CRLView::slotUpdateView()
103 _updateButton->setEnabled( false );
104 _textView->clear();
105 _buffer.clear();
106 if( !_process ) {
107 _process = new KProcess();
108 *_process << "gpgsm" << "--call-dirmngr" << "listcrls";
109 connect( _process, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadStdout()));
110 connect( _process, SIGNAL(finished(int,QProcess::ExitStatus)),
111 this, SLOT(slotProcessExited(int,QProcess::ExitStatus)));
113 if( _process->state() == QProcess::Running ) _process->kill();
114 _process->setOutputChannelMode(KProcess::OnlyStdoutChannel);
115 _process->start();
116 if( !_process->waitForStarted()){
117 KMessageBox::error( this, i18n( "Unable to start gpgsm process. Please check your installation." ), i18n( "Certificate Manager Error" ) );
118 processExited();
120 _timer->start( 1000 );
123 void CRLView::slotReadStdout()
125 _buffer.append( _process->readAllStandardOutput() );
128 void CRLView::slotAppendBuffer() {
129 _textView->append( _buffer );
130 _buffer.clear();
133 void CRLView::processExited()
135 _timer->stop();
136 slotAppendBuffer();
137 _updateButton->setEnabled( true );
141 void CRLView::slotProcessExited(int, QProcess::ExitStatus _status)
143 processExited();
144 if( _status != QProcess::NormalExit ) {
145 KMessageBox::error( this, i18n( "The GpgSM process ended prematurely because of an unexpected error." ), i18n( "Certificate Manager Error" ) );
149 #include "crlview.moc"