summaryrefslogtreecommitdiffstats
path: root/extractordialog.cpp
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-16 19:34:57 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-16 19:34:57 +0000
commit1b1e48aa11c4518e100004dac594540e6024fa68 (patch)
tree0a44ad1d42f463960a045c9207d0fb2188309e57 /extractordialog.cpp
parent95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df (diff)
downloadSheMov-1b1e48aa11c4518e100004dac594540e6024fa68.tar.gz
SheMov-1b1e48aa11c4518e100004dac594540e6024fa68.tar.bz2
SheMov-1b1e48aa11c4518e100004dac594540e6024fa68.zip
-Fixed extractor... Just look at the examples for QProcess :)
-Beautified extractor output for unrar -Added User interface configuration options -So, there are Usability fixes git-svn-id: file:///var/svn/repos2/shemov/trunk@388 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'extractordialog.cpp')
-rw-r--r--extractordialog.cpp78
1 files changed, 41 insertions, 37 deletions
diff --git a/extractordialog.cpp b/extractordialog.cpp
index cf2c18d..7bb2f81 100644
--- a/extractordialog.cpp
+++ b/extractordialog.cpp
@@ -12,18 +12,17 @@
#include <QSettings>
#include <QFileInfo>
#include <QByteArray>
+#include <QFont>
+#include <QRegExp>
#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);
+ mOutput->setFont(QFont("Courier new", 10));
mCancelClose = new QPushButton(tr("Close"));
connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept()));
mainLayout->addWidget(mOutput);
@@ -31,35 +30,12 @@ ExtractorDialog::ExtractorDialog(const QString &archive, const QString &extractT
setLayout(mainLayout);
mExtractor = new QProcess(this);
- 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);
+ setMinimumWidth(500);
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()));
- mCancelClose->setText(tr("Cancel"));
- }
- if(newState == QProcess::NotRunning){
- mCancelClose->disconnect(SIGNAL(clicked()));
- connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept()));
- mCancelClose->setText(tr("Close"));
- }
-}
-
-void ExtractorDialog::extractionStarted(){
- mCancelClose->disconnect(SIGNAL(clicked()));
- connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess()));
- mCancelClose->setText(tr("Cancel"));
}
void ExtractorDialog::extractionFinished(){
@@ -69,16 +45,26 @@ void ExtractorDialog::extractionFinished(){
}
void ExtractorDialog::killProcess(){
- mExtractor->terminate();
- mCancelClose->disconnect(SIGNAL(clicked()));
- connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept()));
- mCancelClose->setText(tr("Close"));
+ mExtractor->kill();
+ setClose();
}
void ExtractorDialog::writeOutput(){
- qDebug() << "writing" << mExtractor->state();
- QByteArray output = mExtractor->read(mExtractor->bytesAvailable());
- mOutput->append(output);
+ if(mExtractor->canReadLine()){
+ QString line = mExtractor->readLine();
+ QRegExp dots("^...\\s+");
+ if(dots.indexIn(line) != -1){
+ line.replace(dots, "File: ");
+ mOutput->append(line);
+ return;
+ }
+ QRegExp extracting("/.*/");
+ if(extracting.indexIn(line) != -1){
+ line.replace(extracting, "");
+ mOutput->append(line);
+ }
+
+ }
}
void ExtractorDialog::start(){
@@ -98,10 +84,28 @@ void ExtractorDialog::start(){
args << mArchive;
mExtractor = new QProcess(this);
mExtractor->setWorkingDirectory(mExtractTo);
- connect(mExtractor, SIGNAL(readyRead()), this, SLOT(writeOutput()));
+ mExtractor->setReadChannel(QProcess::StandardOutput);
QString startmessage = QString("Starting %1 %2\n").arg(exe).arg(args.join(" "));
mOutput->append(startmessage);
mExtractor->start(exe, args);
- mExtractor->waitForStarted();
+ if(!mExtractor->waitForStarted()){
+ mOutput->append(tr("Failed to start extraction!\n"));
+ return;
+ }
+ connect(mExtractor, SIGNAL(readyRead()), this, SLOT(writeOutput()));
+ connect(mExtractor, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(extractionFinished()));
+ setCancel();
+}
+
+void ExtractorDialog::setClose(){
+ mCancelClose->disconnect(SIGNAL(clicked()));
+ connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept()));
+ mCancelClose->setText(tr("Close"));
+}
+
+void ExtractorDialog::setCancel(){
+ mCancelClose->disconnect(SIGNAL(clicked()));
+ connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess()));
+ mCancelClose->setText(tr("Cancel"));
}