summaryrefslogtreecommitdiffstats
path: root/extractordialog.cpp
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-15 19:16:26 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-15 19:16:26 +0000
commit95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df (patch)
tree59dec9ad30bbb5457ae66eddbe59b3348dd1feec /extractordialog.cpp
parent440f3fe87e9adc95f6155b924162e335f2b434e0 (diff)
downloadSheMov-95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df.tar.gz
SheMov-95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df.tar.bz2
SheMov-95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df.zip
-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
Diffstat (limited to 'extractordialog.cpp')
-rw-r--r--extractordialog.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/extractordialog.cpp b/extractordialog.cpp
index 7897bf4..cf2c18d 100644
--- a/extractordialog.cpp
+++ b/extractordialog.cpp
@@ -14,11 +14,16 @@
#include <QByteArray>
#include <QApplication>
+#include <QDebug>
+
#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();
}