/* 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 #include #include #include #include #include #include #include #include #include #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; mOutput->setReadOnly(true); mOutput->setFont(QFont("Courier new", 10)); mCancelClose = new QPushButton(tr("Close")); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); mainLayout->addWidget(mOutput); mainLayout->addWidget(mCancelClose); setLayout(mainLayout); mExtractor = new QProcess(this); QString wTitle = QString(tr("%1 - extracting from %2")).arg(qApp->applicationName()).arg(archive); setWindowTitle(wTitle); setMinimumWidth(500); start(); } void ExtractorDialog::extractionFinished(){ mCancelClose->disconnect(SIGNAL(clicked())); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); mCancelClose->setText(tr("Close")); setWindowTitle(tr("Extraction finished")); mOutput->append(tr("\nFinished.\n")); } void ExtractorDialog::killProcess(){ mExtractor->kill(); setClose(); } void ExtractorDialog::writeOutput(){ if(mExtractor->canReadLine()){ mOutput->append(mExtractor->readLine()); } } 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/archiverargs").toStringList(); args << mArchive; mExtractor = new QProcess(this); mExtractor->setWorkingDirectory(mExtractTo); mExtractor->setReadChannel(QProcess::StandardOutput); QString startmessage = QString("Starting %1 %2\n").arg(exe).arg(args.join(" ")); mOutput->append(startmessage); mExtractor->start(exe, args); 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")); }