33 #include <config-kleopatra.h>
42 #include <gpgme++/key.h>
45 #include <KMessageBox>
46 #include <KLocalizedString>
47 #include <KPushButton>
48 #include <KStandardGuiItem>
49 #include <KGlobalSettings>
55 #include <QVBoxLayout>
56 #include <QHBoxLayout>
61 class DumpCertificateDialog :
public QDialog {
64 explicit DumpCertificateDialog(
QWidget * parent=0 )
71 void updateRequested();
74 void append(
const QString & line ) {
75 ui.logTextWidget.message( line );
78 ui.logTextWidget.clear();
84 KPushButton updateButton, closeButton;
88 explicit Ui( DumpCertificateDialog *
q )
90 updateButton( i18nc(
"@action:button Update the log text widget",
"&Update"), q ),
91 closeButton( KStandardGuiItem::close(), q ),
101 logTextWidget.setFont( KGlobalSettings::fixedFont() );
102 logTextWidget.setMinimumVisibleLines( 25 );
103 logTextWidget.setMinimumVisibleColumns( 80 );
105 vlay.addWidget( &logTextWidget, 1 );
106 vlay.addLayout( &hlay );
108 hlay.addWidget( &updateButton );
109 hlay.addStretch( 1 );
110 hlay.addWidget( &closeButton );
112 connect( &updateButton, SIGNAL(clicked()),
113 q, SIGNAL(updateRequested()) );
114 connect( &closeButton, SIGNAL(clicked()),
121 using namespace Kleo;
122 using namespace Kleo::Commands;
131 friend class ::Kleo::Commands::DumpCertificateCommand;
146 void slotProcessFinished(
int, QProcess::ExitStatus );
148 void slotProcessReadyReadStandardOutput() {
149 while (
process.canReadLine() ) {
152 dialog->append( line );
153 outputBuffer.push_back( line );
157 void slotProcessReadyReadStandardError() {
158 errorBuffer +=
process.readAllStandardError();
161 void slotUpdateRequested() {
162 if (
process.state() == QProcess::NotRunning )
166 void slotDialogDestroyed() {
168 if (
process.state() != QProcess::NotRunning )
183 DumpCertificateCommand::Private * DumpCertificateCommand::d_func() {
return static_cast<Private*
>(
d.
get() ); }
184 const DumpCertificateCommand::Private * DumpCertificateCommand::d_func()
const {
return static_cast<const Private*
>(
d.
get() ); }
197 process.setOutputChannelMode( KProcess::SeparateChannels );
198 process.setReadChannel( KProcess::StandardOutput );
201 DumpCertificateCommand::Private::~Private() {
202 if ( dialog && !dialog->isVisible() )
207 :
Command( new Private( this, c ) )
213 :
Command( v, new Private( this, c ) )
219 :
Command( k, new Private( this, 0 ) )
224 void DumpCertificateCommand::Private::init() {
225 connect( &
process, SIGNAL(finished(
int,QProcess::ExitStatus)),
226 q, SLOT(slotProcessFinished(
int,QProcess::ExitStatus)) );
227 connect( &
process, SIGNAL(readyReadStandardError()),
228 q, SLOT(slotProcessReadyReadStandardError()) );
229 connect( &
process, SIGNAL(readyReadStandardOutput()),
230 q, SLOT(slotProcessReadyReadStandardOutput()) );
231 if ( !key().isNull() )
246 return d->outputBuffer;
249 void DumpCertificateCommand::doStart() {
251 const std::vector<GpgME::Key> keys =
d->keys();
252 if ( keys.size() != 1 || keys.front().protocol() !=
GpgME::CMS ) {
257 if (
d->useDialog ) {
258 d->dialog =
new DumpCertificateDialog;
259 d->dialog->setAttribute( Qt::WA_DeleteOnClose );
260 d->dialog->setWindowTitle( i18n(
"Certificate Dump") );
262 connect(
d->dialog, SIGNAL(updateRequested()),
263 this, SLOT(slotUpdateRequested()) );
265 this, SLOT(slotDialogDestroyed()) );
271 void DumpCertificateCommand::Private::refreshView() {
276 outputBuffer.clear();
280 if (
process.waitForStarted() ) {
284 KMessageBox::error( dialog ? static_cast<QWidget*>( dialog ) : parentWidgetOrView(),
285 i18n(
"Unable to start process gpgsm. "
286 "Please check your installation." ),
287 i18n(
"Dump Certificate Error" ) );
292 void DumpCertificateCommand::doCancel() {
294 if (
d->process.state() != QProcess::NotRunning ) {
295 d->process.terminate();
303 void DumpCertificateCommand::Private::slotProcessFinished(
int code, QProcess::ExitStatus
status ) {
305 if ( status == QProcess::CrashExit )
306 KMessageBox::error( dialog,
307 i18n(
"The GpgSM process that tried to dump the certificate "
308 "ended prematurely because of an unexpected error. "
309 "Please check the output of gpgsm --dump-cert %1 for details.",
311 i18n(
"Dump Certificate Error" ) );
313 KMessageBox::error( dialog,
314 i18n(
"An error occurred while trying to dump the certificate. "
315 "The output from GpgSM was:\n%1", errorString() ),
316 i18n(
"Dump Certificate Error" ) );
319 slotDialogDestroyed();
325 #include "moc_dumpcertificatecommand.cpp"
326 #include "dumpcertificatecommand.moc"
DumpCertificateCommand(QAbstractItemView *view, KeyListController *parent)
A high-speed text display widget.
kdtools::pimpl_ptr< Private > d
VerifyChecksumsDialog::Status status
QString fromLocal8Bit(const char *str, int size)
void setUseDialog(bool on)
QString fromUtf8(const char *str, int size)
static const int PROCESS_TERMINATE_TIMEOUT
static QString process(const Dir &dir, bool *fatal)
~DumpCertificateCommand()
QStringList output() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
static QByteArray chomped(QByteArray ba)
void destroyed(QObject *obj)
bool endsWith(const QByteArray &ba) const
QDialog(QWidget *parent, QFlags< Qt::WindowType > f)