From 95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df Mon Sep 17 00:00:00 2001 From: am Date: Wed, 15 Jul 2009 19:16:26 +0000 Subject: -finished calling extractor -QProcess doesn't work as promised in the docs, dunno how to do it yet, but we need a thread to keep the GUI responsive... -fixed some bugs with the extractionpaths git-svn-id: file:///var/svn/repos2/shemov/trunk@387 f440f766-f032-0410-8965-dc7d17de2ca0 --- extractordialog.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'extractordialog.cpp') diff --git a/extractordialog.cpp b/extractordialog.cpp index 7897bf4..cf2c18d 100644 --- a/extractordialog.cpp +++ b/extractordialog.cpp @@ -14,11 +14,16 @@ #include #include +#include + #include "extractordialog.h" +//Well, f**king doc of QProcess... The extraction has to be a Thread, otherwise GUI will block + ExtractorDialog::ExtractorDialog(const QString &archive, const QString &extractTo, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mArchive(archive), mExtractTo(extractTo){ QVBoxLayout *mainLayout = new QVBoxLayout; mOutput = new QTextEdit; + mOutput->setReadOnly(true); mCancelClose = new QPushButton(tr("Close")); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); mainLayout->addWidget(mOutput); @@ -26,16 +31,19 @@ ExtractorDialog::ExtractorDialog(const QString &archive, const QString &extractT setLayout(mainLayout); mExtractor = new QProcess(this); - connect(mExtractor, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStatusChanged(QProcess::ProcessState))); + connect(mExtractor, SIGNAL(started()), this, SLOT(extractionStarted())); + connect(mExtractor, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(extractionFinished())); + //connect(mExtractor, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStatusChanged(QProcess::ProcessState))); QString wTitle = QString(tr("%1 - extracting from %2")).arg(qApp->applicationName()).arg(archive); setWindowTitle(wTitle); start(); - + qDebug() << "state" << mExtractor->state(); } void ExtractorDialog::processStatusChanged(QProcess::ProcessState newState){ + qDebug() << "State changed to" << newState; if((newState == QProcess::Running) || (newState == QProcess::Starting)){ mCancelClose->disconnect(SIGNAL(clicked())); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess())); @@ -48,6 +56,18 @@ void ExtractorDialog::processStatusChanged(QProcess::ProcessState newState){ } } +void ExtractorDialog::extractionStarted(){ + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess())); + mCancelClose->setText(tr("Cancel")); +} + +void ExtractorDialog::extractionFinished(){ + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); + mCancelClose->setText(tr("Close")); +} + void ExtractorDialog::killProcess(){ mExtractor->terminate(); mCancelClose->disconnect(SIGNAL(clicked())); @@ -56,6 +76,7 @@ void ExtractorDialog::killProcess(){ } void ExtractorDialog::writeOutput(){ + qDebug() << "writing" << mExtractor->state(); QByteArray output = mExtractor->read(mExtractor->bytesAvailable()); mOutput->append(output); } @@ -73,12 +94,14 @@ void ExtractorDialog::start(){ mOutput->append(msg); return; } - QStringList args = s.value("paths/archiveargs").toStringList(); + QStringList args = s.value("paths/archiverargs").toStringList(); + args << mArchive; mExtractor = new QProcess(this); mExtractor->setWorkingDirectory(mExtractTo); connect(mExtractor, SIGNAL(readyRead()), this, SLOT(writeOutput())); - QString startmessage = QString("Starting %1 %2 %3\n").arg(exe).arg(args.join(" ")).arg(mArchive); + QString startmessage = QString("Starting %1 %2\n").arg(exe).arg(args.join(" ")); mOutput->append(startmessage); mExtractor->start(exe, args); + mExtractor->waitForStarted(); } -- cgit v1.2.3-70-g09d2