diff options
author | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-13 15:42:03 +0000 |
---|---|---|
committer | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-13 15:42:03 +0000 |
commit | 440f3fe87e9adc95f6155b924162e335f2b434e0 (patch) | |
tree | 35aae6cb701552252ced67b7ba7f17bcdc7b8c9b /extractordialog.cpp | |
parent | a3dd54389f7b28431fc9853cd57af231bd6a3c9c (diff) | |
download | SheMov-440f3fe87e9adc95f6155b924162e335f2b434e0.tar.gz SheMov-440f3fe87e9adc95f6155b924162e335f2b434e0.tar.bz2 SheMov-440f3fe87e9adc95f6155b924162e335f2b434e0.zip |
-Finished ConfigurationDialog->paths
-Implemented ExtractorDialog (untested)
-started work on extractor menus
git-svn-id: file:///var/svn/repos2/shemov/trunk@386 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'extractordialog.cpp')
-rw-r--r-- | extractordialog.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/extractordialog.cpp b/extractordialog.cpp new file mode 100644 index 0000000..7897bf4 --- /dev/null +++ b/extractordialog.cpp @@ -0,0 +1,84 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QTextEdit> +#include <QProcess> +#include <QPushButton> +#include <QVBoxLayout> +#include <QSettings> +#include <QFileInfo> +#include <QByteArray> +#include <QApplication> + +#include "extractordialog.h" + +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; + mCancelClose = new QPushButton(tr("Close")); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); + mainLayout->addWidget(mOutput); + mainLayout->addWidget(mCancelClose); + setLayout(mainLayout); + + mExtractor = new QProcess(this); + 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(); + +} + +void ExtractorDialog::processStatusChanged(QProcess::ProcessState 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::killProcess(){ + mExtractor->terminate(); + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); + mCancelClose->setText(tr("Close")); +} + +void ExtractorDialog::writeOutput(){ + QByteArray output = mExtractor->read(mExtractor->bytesAvailable()); + mOutput->append(output); +} + +void ExtractorDialog::start(){ + QSettings s; + QString exe = s.value("paths/archiver").toString(); + if(exe.isEmpty()){ + mOutput->append(tr("No archive program configured!")); + return; + } + QFileInfo info(exe); + if(!info.exists() || !info.isExecutable()){ + QString msg = QString(tr("Unable to call %1")).arg(exe); + mOutput->append(msg); + return; + } + QStringList args = s.value("paths/archiveargs").toStringList(); + 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); + mOutput->append(startmessage); + mExtractor->start(exe, args); +} + |