33 #include <config-kleopatra.h>
43 #include <KMessageBox>
45 #include <KWindowSystem>
48 #include <QStringList>
52 #include <QDialogButtonBox>
53 #include <QPushButton>
54 #include <QVBoxLayout>
60 using namespace Kleo::Commands;
64 class OutputDialog :
public QDialog {
67 explicit OutputDialog(
QWidget * parent=0 )
70 logTextWidget(
this ),
71 buttonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Close, Qt::Horizontal,
this )
77 logTextWidget.setMinimumVisibleLines( 20 );
78 logTextWidget.setMinimumVisibleColumns( 80 );
80 vlay.addWidget( &logTextWidget, 1 );
81 vlay.addWidget( &buttonBox );
83 connect( closeButton(), SIGNAL(clicked()),
this, SLOT(close()) );
84 connect( cancelButton(), SIGNAL(clicked()),
this, SLOT(slotCancelClicked()) );
88 void cancelRequested();
91 void message(
const QString & s ) {
92 logTextWidget.message( s );
94 void setComplete(
bool complete ) {
95 cancelButton()->setVisible( !complete );
99 void slotCancelClicked() {
100 cancelButton()->hide();
101 emit cancelRequested();
105 QAbstractButton * closeButton()
const {
return buttonBox.button( QDialogButtonBox::Close ); }
106 QAbstractButton * cancelButton()
const {
return buttonBox.button( QDialogButtonBox::Cancel ); }
111 QDialogButtonBox buttonBox;
117 friend class ::Kleo::Commands::GnuPGProcessCommand;
125 void ensureDialogCreated() {
129 dialog =
new OutputDialog;
130 dialog->setAttribute( Qt::WA_DeleteOnClose );
132 connect(
dialog, SIGNAL(cancelRequested()),
q, SLOT(
cancel()) );
133 dialog->setWindowTitle( i18n(
"Subprocess Diagnostics") );
136 void ensureDialogVisible() {
139 ensureDialogCreated();
140 if (
dialog->isVisible() )
145 KWindowSystem::forceActiveWindow(
dialog->winId() );
148 void message(
const QString & msg ) {
156 void slotProcessFinished(
int, QProcess::ExitStatus );
157 void slotProcessReadyReadStandardError();
161 QPointer<OutputDialog>
dialog;
162 QStringList arguments;
163 QByteArray errorBuffer;
169 GnuPGProcessCommand::Private * GnuPGProcessCommand::d_func() {
return static_cast<Private*
>(
d.
get() ); }
170 const GnuPGProcessCommand::Private * GnuPGProcessCommand::d_func()
const {
return static_cast<const Private*
>(
d.
get() ); }
180 ignoresSuccessOrFailure( false ),
181 showsOutputWindow( false ),
184 process.setOutputChannelMode( KProcess::OnlyStderrChannel );
185 process.setReadChannel( KProcess::StandardError );
188 GnuPGProcessCommand::Private::~Private() {}
191 :
Command( new Private( this, c ) )
197 :
Command( v, new Private( this, c ) )
203 :
Command( key, new Private( this, 0 ) )
208 void GnuPGProcessCommand::Private::init() {
209 connect( &
process, SIGNAL(finished(
int,QProcess::ExitStatus)),
210 q, SLOT(slotProcessFinished(
int,QProcess::ExitStatus)) );
211 connect( &
process, SIGNAL(readyReadStandardError()),
212 q, SLOT(slotProcessReadyReadStandardError()) );
221 bool GnuPGProcessCommand::preStartHook(
QWidget * )
const {
225 void GnuPGProcessCommand::postSuccessHook(
QWidget * ) {
229 void GnuPGProcessCommand::doStart() {
231 if ( !preStartHook(
d->parentWidgetOrView() ) ) {
236 d->arguments = arguments();
238 d->process <<
d->arguments;
242 if ( !
d->process.waitForStarted() ) {
243 d->error( i18n(
"Unable to start process %1. "
244 "Please check your installation.",
d->arguments[0] ),
248 d->ensureDialogVisible();
249 d->message( i18n(
"Starting %1...",
d->arguments.join(QLatin1String(
" ")) ) );
253 void GnuPGProcessCommand::doCancel() {
255 if (
d->process.state() != QProcess::NotRunning ) {
256 d->process.terminate();
261 void GnuPGProcessCommand::Private::slotProcessFinished(
int code, QProcess::ExitStatus
status ) {
263 if ( status == QProcess::CrashExit ) {
264 error(
q->crashExitMessage( arguments ),
q->errorCaption() );
265 }
else if ( ignoresSuccessOrFailure ) {
267 message( i18n(
"Process finished") );
272 error(
q->errorExitMessage( arguments ),
q->errorCaption() );
274 q->postSuccessHook( parentWidgetOrView() );
275 const QString successMessage =
q->successMessage( arguments );
277 message( successMessage );
279 information( successMessage,
q->successCaption() );
283 dialog->setComplete(
true );
287 void GnuPGProcessCommand::Private::slotProcessReadyReadStandardError() {
288 while (
process.canReadLine() ) {
289 QByteArray ba =
process.readLine();
291 while ( ba.endsWith(
'\n') || ba.endsWith(
'\r') )
293 message( QString::fromLocal8Bit( ba.constData(), ba.size() ) );
298 return QString::fromLocal8Bit(
d->errorBuffer );
302 d->ignoresSuccessOrFailure = ignores;
306 return d->ignoresSuccessOrFailure;
310 if ( show ==
d->showsOutputWindow )
312 d->showsOutputWindow = show;
314 d->ensureDialogCreated();
317 d->dialog->deleteLater();
323 return d->showsOutputWindow;
329 #include "moc_gnupgprocesscommand.cpp"
330 #include "gnupgprocesscommand.moc"
GnuPGProcessCommand(QAbstractItemView *view, KeyListController *parent)
QString errorString() const
A high-speed text display widget.
bool ignoresSuccessOrFailure() const
void setIgnoresSuccessOrFailure(bool ignore)
kdtools::pimpl_ptr< Private > d
VerifyChecksumsDialog::Status status
static QString process(const Dir &dir, bool *fatal)
bool showsOutputWindow() const
void setShowsOutputWindow(bool show)
static const int PROCESS_TERMINATE_TIMEOUT