Skip to content

Commit

Permalink
Will continue to work at home
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpandeyvpz committed Nov 9, 2014
1 parent 0e55e66 commit f98b1f7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 53 deletions.
12 changes: 8 additions & 4 deletions source/async/vpz/apkstudio/async/pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ 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<QString, bool> &files, const QDir &destination, QObject *parent)
: Task(parent), files(files), destination(destination), device(device)
{
}

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++;
}
Expand Down
4 changes: 2 additions & 2 deletions source/async/vpz/apkstudio/async/pull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Pull : public Task
private:
QDir destination;
QString device;
QStringList paths;
QMap<QString, bool> files;
public:
Pull(const QString &, const QStringList &, const QDir &, QObject * = 0);
Pull(const QString &, const QMap<QString, bool> &, const QDir &, QObject * = 0);
void start();
signals:
void finished(QVariant);
Expand Down
56 changes: 28 additions & 28 deletions source/components/vpz/apkstudio/components/storage.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "storage.hpp"

using namespace VPZ::APKStudio::Async;
using namespace VPZ::APKStudio::Helpers;
using namespace VPZ::APKStudio::Resources;

Expand Down Expand Up @@ -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<QTreeWidgetItem *> 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<QString, bool> 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<int, int> pair = result.value<QPair<int, int>>();
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<QTreeWidgetItem *> rows = findItems(path.section('/', -1, -1), Qt::MatchExactly, 1);
if (rows.count() != 1)
continue;
delete rows.first();
}
}

void Storage::onRename()
Expand All @@ -452,6 +456,7 @@ void Storage::onRename()
bool multiple = (files.count() > 1);
int failed = 0;
int successful = 0;
QMap<QString, QString> renameable;
for (int i = 0; i < files.count(); ++i) {
QString newname(name);
if (multiple)
Expand All @@ -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<QTreeWidgetItem *> 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);
Expand All @@ -482,6 +477,11 @@ void Storage::onRename()
void Storage::onRenameFinished(const QVariant &result, const QStringList &a)
{
Q_UNUSED(a)
QPair<int, int> pair = result.value<QPair<int, int>>();
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()
Expand Down
6 changes: 6 additions & 0 deletions source/components/vpz/apkstudio/components/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
#include <QShortcut>
#include <QTreeWidget>
#include <QVBoxLayout>
#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 {
Expand Down
19 changes: 1 addition & 18 deletions source/helpers/vpz/apkstudio/helpers/adb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion source/helpers/vpz/apkstudio/helpers/adb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f98b1f7

Please sign in to comment.