From f98b1f7aa967d8e84c51ba7624fd38a2bdeccd6a Mon Sep 17 00:00:00 2001 From: "Vaibhav Pandey a.k.a VPZ" Date: Sun, 9 Nov 2014 13:32:09 +0530 Subject: [PATCH] Will continue to work at home --- source/async/vpz/apkstudio/async/pull.cpp | 12 ++-- source/async/vpz/apkstudio/async/pull.hpp | 4 +- .../vpz/apkstudio/components/storage.cpp | 56 +++++++++---------- .../vpz/apkstudio/components/storage.hpp | 6 ++ source/helpers/vpz/apkstudio/helpers/adb.cpp | 19 +------ source/helpers/vpz/apkstudio/helpers/adb.hpp | 1 - 6 files changed, 45 insertions(+), 53 deletions(-) diff --git a/source/async/vpz/apkstudio/async/pull.cpp b/source/async/vpz/apkstudio/async/pull.cpp index 0730376..3f23c80 100644 --- a/source/async/vpz/apkstudio/async/pull.cpp +++ b/source/async/vpz/apkstudio/async/pull.cpp @@ -6,8 +6,8 @@ namespace VPZ { namespace APKStudio { namespace Async { -Pull::Pull(const QString &device, const QStringList &paths, const QDir &destination, QObject *parent) - : Task(parent), paths(paths), destination(destination), device(device) +Pull::Pull(const QString &device, const QMap &files, const QDir &destination, QObject *parent) + : Task(parent), files(files), destination(destination), device(device) { } @@ -15,10 +15,14 @@ void Pull::start() { int failed = 0; int successful = 0; - foreach (const QString &path, paths) { + foreach(const QString &path, files.keys()) { if (ADB::instance()->pull(device, path, destination.absolutePath())) { - if (QFile::exists(destination.absoluteFilePath(path.section('/', -1, -1)))) + if (files[path]) successful++; + else if (destination.exists(path.section('/', -1, -1))) + successful++; + else + failed++; } else failed++; } diff --git a/source/async/vpz/apkstudio/async/pull.hpp b/source/async/vpz/apkstudio/async/pull.hpp index 0137f8e..9cc27da 100644 --- a/source/async/vpz/apkstudio/async/pull.hpp +++ b/source/async/vpz/apkstudio/async/pull.hpp @@ -15,9 +15,9 @@ class Pull : public Task private: QDir destination; QString device; - QStringList paths; + QMap files; public: - Pull(const QString &, const QStringList &, const QDir &, QObject * = 0); + Pull(const QString &, const QMap &, const QDir &, QObject * = 0); void start(); signals: void finished(QVariant); diff --git a/source/components/vpz/apkstudio/components/storage.cpp b/source/components/vpz/apkstudio/components/storage.cpp index dc88d32..fad193b 100644 --- a/source/components/vpz/apkstudio/components/storage.cpp +++ b/source/components/vpz/apkstudio/components/storage.cpp @@ -1,5 +1,6 @@ #include "storage.hpp" +using namespace VPZ::APKStudio::Async; using namespace VPZ::APKStudio::Helpers; using namespace VPZ::APKStudio::Resources; @@ -420,24 +421,27 @@ void Storage::onRemove() int result = QMessageBox::question(this, translate("title_remove"), translate("message_remove").arg(QString::number(files.count())), QMessageBox::No | QMessageBox::Yes); if (result != QMessageBox::Yes) return; - int failed = 0; - int successful = 0; - foreach (const File &file, files) { - if (ADB::instance()->remove(device, file.path, ((file.type == File::FOLDER) ||(file.type == File::SYMLINK_FOLDER)))) { - successful++; - QList rows = tree->findItems(file.name, Qt::MatchExactly, 0); - if (rows.count() != 1) - continue; - delete rows.first(); - } else - failed++; - } - if (failed >= 1) - QMessageBox::critical(this, translate("title_failure"), translate("message_remove_failed").arg(QString::number(successful), QString::number(failed)), QMessageBox::Close); + QMap removeable; + foreach (const File &file, files) + removeable[file.path] = ((file.type == File::FOLDER) ||(file.type == File::SYMLINK_FOLDER)); + Remove *remove = new Remove(device, renameable); + connections.append(connect(remove, SIGNAL(finished(QVariant, QStringList)), this, SLOT(onRemoveFinished(QVariant, QStringList)), Qt::QueuedConnection)); + Tasks::instance()->add(translate("task_remove").arg(QString::number(removeable.count())), remove); } void Storage::onRemoveFinished(const QVariant &result, const QStringList &removed) { + QPair pair = result.value>(); + if (pair.second >= 1) + QMessageBox::critical(this, translate("title_failure"), translate("message_remove_failed").arg(QString::number(pair.first), QString::number(pair.second)), QMessageBox::Close); + if (removed.isEmpty()) + return; + foreach (const QString &path, removed) { + QList rows = findItems(path.section('/', -1, -1), Qt::MatchExactly, 1); + if (rows.count() != 1) + continue; + delete rows.first(); + } } void Storage::onRename() @@ -452,6 +456,7 @@ void Storage::onRename() bool multiple = (files.count() > 1); int failed = 0; int successful = 0; + QMap renameable; for (int i = 0; i < files.count(); ++i) { QString newname(name); if (multiple) @@ -460,20 +465,10 @@ void Storage::onRename() QString newpath(file.path.section('/', 0, -2)); newpath.append('/'); newpath.append(newname); - if (ADB::instance()->rename(device, file.path, newpath)) { - successful++; - QList rows = tree->findItems(file.name, Qt::MatchExactly, 0); - if (rows.count() != 1) - continue; - file.name = newname; - file.path = newpath; - QTreeWidgetItem *row = rows.first(); - for (int i = 0; i < 6; ++i) - row->setData(i, ROLE_STRUCT, QVariant::fromValue(file)); - row->setText(0, newname); - row->setToolTip(0, newpath); - } else - failed++; + renameable[file.path] = newpath; + Move *rename = new Move(device, renameable); + connections.append(connect(rename, SIGNAL(finished(QVariant, QStringList)), this, SLOT(onRenameFinished(QVariant, QStringList)), Qt::QueuedConnection)); + Tasks::instance()->add(translate("task_rename").arg(QString::number(renameable.count())), rename); } if (failed >= 1) QMessageBox::critical(this, translate("title_failure"), translate("message_rename_failed").arg(QString::number(successful), QString::number(failed)), QMessageBox::Close); @@ -482,6 +477,11 @@ void Storage::onRename() void Storage::onRenameFinished(const QVariant &result, const QStringList &a) { Q_UNUSED(a) + QPair pair = result.value>(); + if (pair.second >= 1) + QMessageBox::critical(this, translate("title_failure"), translate("message_rename_failed").arg(QString::number(pair.first), QString::number(pair.second)), QMessageBox::Close); + if (pair.first >= 1) + onRefresh(); } void Storage::onReturn() diff --git a/source/components/vpz/apkstudio/components/storage.hpp b/source/components/vpz/apkstudio/components/storage.hpp index 878a569..ad37782 100644 --- a/source/components/vpz/apkstudio/components/storage.hpp +++ b/source/components/vpz/apkstudio/components/storage.hpp @@ -8,11 +8,17 @@ #include #include #include +#include "async/copy.hpp" +#include "async/move.hpp" +#include "async/pull.hpp" +#include "async/push.hpp" +#include "async/remove.hpp" #include "helpers/adb.hpp" #include "helpers/format.hpp" #include "helpers/text.hpp" #include "resources/variant.hpp" #include "clearable.hpp" +#include "tasks.hpp" #include "treewidget.hpp" namespace VPZ { diff --git a/source/helpers/vpz/apkstudio/helpers/adb.cpp b/source/helpers/vpz/apkstudio/helpers/adb.cpp index bddd367..b4298be 100644 --- a/source/helpers/vpz/apkstudio/helpers/adb.cpp +++ b/source/helpers/vpz/apkstudio/helpers/adb.cpp @@ -708,23 +708,6 @@ bool ADB::remove(const QString &device, const QString &path, bool recurse) const return execute(arguments).isEmpty(); } -bool ADB::rename(const QString &device, const QString &source, const QString &destination) const -{ - QStringList arguments("-s"); - arguments << device; - arguments << "shell"; - if (Settings::rootShell()) { - arguments << "su"; - arguments << "-c"; - arguments << QString("mv %1 %2").arg(quote(source), quote(destination)); - } else { - arguments << "mv"; - arguments << source; - arguments << destination; - } - return execute(arguments).isEmpty(); -} - void ADB::screenshot(const QString &device, const QString &saveas) { QString binary(Settings::javaHome()); @@ -784,7 +767,7 @@ bool ADB::uninstall(const QString &device, const QString &package) const QStringList lines = execute(arguments); if (lines.size() != 1) return false; - return (lines.first().trimmed() == "Success"); + return (QString::compare(lines.first().trimmed(), "Success") == 0); } bool ADB::unmount(const QString &device, const Partition &partition) const diff --git a/source/helpers/vpz/apkstudio/helpers/adb.hpp b/source/helpers/vpz/apkstudio/helpers/adb.hpp index 27afec7..13f679b 100644 --- a/source/helpers/vpz/apkstudio/helpers/adb.hpp +++ b/source/helpers/vpz/apkstudio/helpers/adb.hpp @@ -59,7 +59,6 @@ class ADB : public CLI void reboot(const QString &, const int); bool remount(const QString &, const Resources::Partition &); bool remove(const QString &, const QString &, bool = false) const; - bool rename(const QString &, const QString &, const QString &) const; void screenshot(const QString &, const QString &); void shell(const QString &); void start();