Commit e2579890 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa
Browse files

More solid error detection in batch extraction.

Files that do not exist aren't added to the input list, and the
extraction job isn't started if there are no valid input files.
A list of files that could not be extracted is presented at the end of
the execution.

BUG: 198516

svn path=/trunk/KDE/kdeutils/ark/; revision=998151
parent b8936280
......@@ -32,7 +32,7 @@
#include <QByteArray>
#include <QFileInfo>
#include <QEventLoop>
#include <QTimer>
using Kerfuffle::AddToArchive;
using Kerfuffle::BatchExtract;
......@@ -133,7 +133,7 @@ int main(int argc, char **argv)
if (args->isSet("add") || args->isSet("add-to")) {
AddToArchive *addToArchiveJob = new AddToArchive;
application.connect(addToArchiveJob, SIGNAL(result(KJob*)), SLOT(quit()));
application.connect(addToArchiveJob, SIGNAL(result(KJob*)), SLOT(quit()), Qt::QueuedConnection);
if (args->isSet("changetofirstpath")) {
addToArchiveJob->setChangeToFirstPath(true);
......@@ -160,10 +160,8 @@ int main(int argc, char **argv)
addToArchiveJob->start();
} else if (args->isSet("batch")) {
//once the job has been started this interface can be safely
//deleted
BatchExtract *batchJob = new BatchExtract;
application.connect(batchJob, SIGNAL(result(KJob*)), SLOT(quit()));
application.connect(batchJob, SIGNAL(result(KJob*)), SLOT(quit()), Qt::QueuedConnection);
for (int i = 0; i < args->count(); ++i) {
batchJob->addInput(args->url(i));
......
......@@ -45,15 +45,17 @@ namespace Kerfuffle
BatchExtract::BatchExtract()
: m_autoSubfolders(false),
m_preservePaths(true)
{
setCapabilities(KJob::Killable);
connect(this, SIGNAL(result(KJob*)), SLOT(showFailedFiles()));
}
BatchExtract::~BatchExtract()
{
kDebug() << "Dying";
KIO::getJobTracker()->unregisterJob(this);
if (!m_inputs.isEmpty()) {
KIO::getJobTracker()->unregisterJob(this);
}
}
void BatchExtract::addExtraction(Kerfuffle::Archive* archive, bool preservePaths, QString destinationFolder)
......@@ -108,7 +110,11 @@ void BatchExtract::setAutoSubfolder(bool value)
void BatchExtract::start()
{
kDebug();
// If none of the archives could be loaded, there is no subjob to run
if (m_inputs.isEmpty()) {
emitResult();
return;
}
if (!m_subfolder.isEmpty()) {
kDebug() << "Creating subfolder" << m_subfolder;
......@@ -137,13 +143,19 @@ void BatchExtract::start()
);
m_initialJobCount = subjobs().size();
if (!m_initialJobCount) return;
kDebug() << "Starting first job";
subjobs().at(0)->start();
}
void BatchExtract::showFailedFiles()
{
if (!m_failedFiles.isEmpty()) {
KMessageBox::informationList(0, i18n("The following files could not be extracted:"), m_failedFiles);
}
}
void BatchExtract::slotResult(KJob *job)
{
kDebug();
......@@ -189,11 +201,15 @@ void BatchExtract::forwardProgress(KJob *job, unsigned long percent)
bool BatchExtract::addInput(const KUrl& url)
{
kDebug();
Kerfuffle::Archive *archive = Kerfuffle::factory(url.path());
if (archive == NULL) return false;
m_inputs << archive;
if ((archive == NULL) || (!QFileInfo(url.path()).exists())) {
m_failedFiles.append(url.fileName());
return false;
}
m_inputs.append(archive);
return true;
}
......
......@@ -27,6 +27,7 @@
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <kcompositejob.h>
......@@ -57,6 +58,7 @@ public:
private slots:
void forwardProgress(KJob *job, unsigned long percent);
void showFailedFiles();
void slotResult(KJob *job);
void slotUserQuery(Query *query);
......@@ -67,6 +69,7 @@ private:
QList<Archive*> m_inputs;
QString m_destinationFolder;
QStringList m_failedFiles;
QString m_subfolder;
bool m_preservePaths;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment