Commit 4b9521ad authored by Lisa's avatar Lisa

Multiple operations now supported.

parent 2b13f9a7
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QTimer> #include <QTimer>
OperationManager::OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent) OperationManager::OperationManager(APM::OperationType type, QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
: QObject(parent), : QObject(parent),
m_type(type), m_type(type),
m_operation(operation), m_operations(operations),
m_options(options), m_options(options),
m_args(args) m_args(args)
{ {
...@@ -65,23 +65,23 @@ void OperationManager::start() ...@@ -65,23 +65,23 @@ void OperationManager::start()
{ {
switch (m_type) { switch (m_type) {
case APM::QueryOperationType: { case APM::QueryOperationType: {
QueryOperation * query = new QueryOperation(this); QueryOperation * query = new QueryOperation(m_operations, m_options, m_args, this);
query->start(m_operation, m_options, m_args); query->start();
break; break;
} }
case APM::RemoveOperationType: { case APM::RemoveOperationType: {
RemoveOperation * remove = new RemoveOperation(this); RemoveOperation * remove = new RemoveOperation(m_operations, m_options, m_args, this);
remove->start(m_operation, m_options, m_args); remove->start();
break; break;
} }
case APM::SyncOperationType: { case APM::SyncOperationType: {
SyncOperation * sync = new SyncOperation(this); SyncOperation * sync = new SyncOperation(m_operations, m_options, m_args, this);
sync->start(m_operation, m_options, m_args); sync->start();
break; break;
} }
case APM::UpgradeOperationType: { case APM::UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this); UpgradeOperation * upgrade = new UpgradeOperation(this);
upgrade->start(m_operation, m_options, m_args); upgrade->start(m_operations, m_options, m_args);
break; break;
} }
default: default:
......
...@@ -21,7 +21,7 @@ class OperationManager : public QObject ...@@ -21,7 +21,7 @@ class OperationManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject* parent = 0); explicit OperationManager(APM::OperationType type, QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject* parent = 0);
virtual ~OperationManager(); virtual ~OperationManager();
private slots: private slots:
...@@ -30,7 +30,7 @@ private slots: ...@@ -30,7 +30,7 @@ private slots:
private: private:
APM::OperationType m_type; APM::OperationType m_type;
APM::OperationName m_operation; QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options; QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args; QStringList m_args;
}; };
......
This diff is collapsed.
...@@ -39,7 +39,7 @@ enum OperationName { ...@@ -39,7 +39,7 @@ enum OperationName {
None, None,
ShowChangelog, ShowInstalledAsDeps, ShowInstalledExplicitely, ShowPackagesOfGroup, ShowPackagesOfGroupLocal, ShowInformationLocal, ShowChangelog, ShowInstalledAsDeps, ShowInstalledExplicitely, ShowPackagesOfGroup, ShowPackagesOfGroupLocal, ShowInformationLocal,
ShowInformation, CheckFiles, ShowOwner, ShowNotRequired, ShowUpgradeable, ShowInformation, CheckFiles, ShowOwner, ShowNotRequired, ShowUpgradeable,
Install, RemoveOldFromCache, RemoveAllCache, ListRepo, Search, UpdateDatabases, UpdateSystem, UpdateDatabaseAndSystem, Install, RemoveOldFromCache, RemoveAllCache, ListRepo, Search, UpdateDatabases, UpdateSystem,
Remove, Cascade, Unneeded, SearchLocal, Remove, Cascade, Unneeded, SearchLocal,
DatabaseOperation, Upgrade, Help, Version DatabaseOperation, Upgrade, Help, Version
}; };
...@@ -98,12 +98,6 @@ public: ...@@ -98,12 +98,6 @@ public:
AkabeiOperation(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool); AkabeiOperation(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool);
AkabeiOperation(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool, QStringList); AkabeiOperation(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool, QStringList);
/*
* Checks, with special rules, than no more than one operation is specified on the command line
* see cmdline.cpp for a more detailed explanation
*/
void set(AkabeiOperation &);
/* /*
* Options checking * Options checking
*/ */
...@@ -116,7 +110,8 @@ typedef QList<AkabeiOperation> AkabeiOperationList; ...@@ -116,7 +110,8 @@ typedef QList<AkabeiOperation> AkabeiOperationList;
class CmdLine class CmdLine
{ {
private: private:
AkabeiOperation m_operation; APM::OperationType m_type;
QHash<APM::OperationName, AkabeiOperation> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options; QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_freeArgs; QStringList m_freeArgs;
...@@ -130,14 +125,15 @@ private: ...@@ -130,14 +125,15 @@ private:
bool parsed; bool parsed;
void secondParse(QStringList, QList<QByteArray> &); void secondParse(QStringList, QSet<QByteArray> &);
bool freeArgsRequired();
public: public:
CmdLine(); CmdLine();
void parse(int argc, char **argv); void parse(int argc, char **argv);
APM::OperationType type(); APM::OperationType type();
APM::OperationName operation(); QList<APM::OperationName> operations();
QHash<APM::OptionName, AkabeiOption> options(); QHash<APM::OptionName, AkabeiOption> options();
QStringList freeArgs(); QStringList freeArgs();
}; };
......
...@@ -28,6 +28,6 @@ int main(int argc, char** argv) ...@@ -28,6 +28,6 @@ int main(int argc, char** argv)
return -1; return -1;
} }
OperationManager apm(cmd.type(), cmd.operation(), cmd.options(), cmd.freeArgs()); OperationManager apm(cmd.type(), cmd.operations(), cmd.options(), cmd.freeArgs());
return app.exec(); return app.exec();
} }
...@@ -23,10 +23,12 @@ ...@@ -23,10 +23,12 @@
#include <QDir> #include <QDir>
#include <QCoreApplication> #include <QCoreApplication>
QueryOperation::QueryOperation(QObject * parent) QueryOperation::QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
: QObject(parent) : QObject(parent)
, m_operations(operations)
, m_options(options)
, m_args(args)
{ {
} }
QueryOperation::~QueryOperation() QueryOperation::~QueryOperation()
...@@ -34,49 +36,51 @@ QueryOperation::~QueryOperation() ...@@ -34,49 +36,51 @@ QueryOperation::~QueryOperation()
} }
void QueryOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args) void QueryOperation::start()
{ {
APM::OperationName operation = m_operations.takeFirst();
if (operation == APM::ShowInformationLocal) { if (operation == APM::ShowInformationLocal) {
if (options.contains(APM::QueryPackageFile)) { if (m_options.contains(APM::QueryPackageFile)) {
showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first())); showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} else { } else {
showInformation(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first(), Akabei::SearchNameEqual)); showInformation(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first(), Akabei::SearchNameEqual));
//CHange back to searchPackages when we have sorted results after Name and description //CHange back to searchPackages when we have sorted results after Name and description
} }
} else if (operation == APM::ShowPackagesOfGroupLocal) { } else if (operation == APM::ShowPackagesOfGroupLocal) {
connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)), connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)),
SLOT(showGroup(QUuid,QList<Akabei::Group*>))); SLOT(showGroup(QUuid,QList<Akabei::Group*>)));
Akabei::Backend::instance()->localDatabase()->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + args.first() + "\""); Akabei::Backend::instance()->localDatabase()->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + m_args.first() + "\"");
} else if (operation == APM::ShowChangelog) { } else if (operation == APM::ShowChangelog) {
if (options.contains(APM::QueryPackageFile)) { if (m_options.contains(APM::QueryPackageFile)) {
showChangelog(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first())); showChangelog(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} else { } else {
showChangelog(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first())); showChangelog(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first()));
} }
} else if (operation == APM::ShowInstalledAsDeps || operation == APM::ShowInstalledExplicitely) { } else if (operation == APM::ShowInstalledAsDeps || operation == APM::ShowInstalledExplicitely) {
QString query = "SELECT * FROM packages WHERE"; QString query = "SELECT * FROM packages WHERE";
if (!args.isEmpty()) // TODO: vedi un po' qua che vuol dire if (!m_args.isEmpty())
query = query + " Name LIKE \"" + args.first() + "\" AND"; query = query + " Name LIKE \"" + m_args.first() + "\" AND";
if (operation == APM::ShowInstalledAsDeps) if (operation == APM::ShowInstalledAsDeps)
query = query + " InstallReason LIKE 0";// + QString((int)Akabei::Package::InstalledAsDependencyReason); query = query + " InstallReason LIKE 0";// + QString((int)Akabei::Package::InstalledAsDependencyReason);
else else
query = query + " InstallReason LIKE " + QString::number((int)Akabei::Package::ExplicitlyInstalledReason); query = query + " InstallReason LIKE " + QString::number((int)Akabei::Package::ExplicitlyInstalledReason);
showInstalledAsDeps(Akabei::Backend::instance()->localDatabase()->queryPackages(query)); showInstalledAsDeps(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
} else if (operation == APM::CheckFiles) { } else if (operation == APM::CheckFiles) {
if (options.contains(APM::QueryPackageFile)) { if (m_options.contains(APM::QueryPackageFile)) {
checkFiles(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first())); checkFiles(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} else { } else {
checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first())); checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first()));
} }
} else if (operation == APM::SearchLocal) { } else if (operation == APM::SearchLocal) {
if (args.isEmpty()) if (m_args.isEmpty())
showLocalPackages(QString()); showLocalPackages(QString());
else else
showLocalPackages(args.first()); showLocalPackages(m_args.first());
} else if (operation == APM::ShowOwner) { } else if (operation == APM::ShowOwner) {
showOwner(args.first()); showOwner(m_args.first());
} else if (operation == APM::SearchLocal) { } else if (operation == APM::SearchLocal) {
showLocalQuery(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first(), Akabei::SearchNameEqual)); showLocalQuery(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first(), Akabei::SearchNameEqual));
} else if (operation == APM::ShowNotRequired) { } else if (operation == APM::ShowNotRequired) {
showNotRequired(); showNotRequired();
} else if (operation == APM::ShowUpgradeable) { } else if (operation == APM::ShowUpgradeable) {
...@@ -118,7 +122,7 @@ void QueryOperation::showInformation(QList<Akabei::Package*> packages) ...@@ -118,7 +122,7 @@ void QueryOperation::showInformation(QList<Akabei::Package*> packages)
out << i18n("Installation script") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << (pkg->hasScriptlet() ? i18n("Yes") : i18n("No")) << endl; out << i18n("Installation script") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << (pkg->hasScriptlet() ? i18n("Yes") : i18n("No")) << endl;
out << i18n("Description") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->description() << endl; out << i18n("Description") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->description() << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups) void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
...@@ -137,7 +141,7 @@ void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups) ...@@ -137,7 +141,7 @@ void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
foreach (Akabei::Package * pkg, sorted.values()) foreach (Akabei::Package * pkg, sorted.values())
out << group->name() << ' ' << pkg->name() << endl; out << group->name() << ' ' << pkg->name() << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showChangelog(QList< Akabei::Package* > packages) void QueryOperation::showChangelog(QList< Akabei::Package* > packages)
...@@ -150,7 +154,7 @@ void QueryOperation::showChangelog(QList< Akabei::Package* > packages) ...@@ -150,7 +154,7 @@ void QueryOperation::showChangelog(QList< Akabei::Package* > packages)
QTextStream out(stdout); QTextStream out(stdout);
out << pkg->retrieveChangelog() << endl; out << pkg->retrieveChangelog() << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages) void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
...@@ -166,7 +170,7 @@ void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages) ...@@ -166,7 +170,7 @@ void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
foreach (Akabei::Package * pkg, sorted.values()) foreach (Akabei::Package * pkg, sorted.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl; out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::checkFiles(QList<Akabei::Package*> packages) void QueryOperation::checkFiles(QList<Akabei::Package*> packages)
...@@ -186,7 +190,7 @@ void QueryOperation::checkFiles(QList<Akabei::Package*> packages) ...@@ -186,7 +190,7 @@ void QueryOperation::checkFiles(QList<Akabei::Package*> packages)
} }
out << pkg->name() << ": " << all << " overall files, " << missing << " file(s) missing" << endl; out << pkg->name() << ": " << all << " overall files, " << missing << " file(s) missing" << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showLocalPackages(const QString &query) void QueryOperation::showLocalPackages(const QString &query)
...@@ -213,7 +217,7 @@ void QueryOperation::showLocalPackages(const QString &query) ...@@ -213,7 +217,7 @@ void QueryOperation::showLocalPackages(const QString &query)
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl; out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
} }
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showOwner(const QString &query) void QueryOperation::showOwner(const QString &query)
...@@ -237,7 +241,7 @@ void QueryOperation::showOwner(const QString &query) ...@@ -237,7 +241,7 @@ void QueryOperation::showOwner(const QString &query)
} }
out << "Error: No packages owns " << query << endl; out << "Error: No packages owns " << query << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages) void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages)
...@@ -251,7 +255,7 @@ void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages) ...@@ -251,7 +255,7 @@ void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages)
out << "\t" << pkg->description() << endl; out << "\t" << pkg->description() << endl;
} }
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showNotRequired() void QueryOperation::showNotRequired()
...@@ -268,7 +272,7 @@ void QueryOperation::showNotRequired() ...@@ -268,7 +272,7 @@ void QueryOperation::showNotRequired()
foreach (Akabei::Package * pkg, pkgs.values()) foreach (Akabei::Package * pkg, pkgs.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl; out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
} }
void QueryOperation::showUpgradeable() void QueryOperation::showUpgradeable()
...@@ -295,5 +299,14 @@ void QueryOperation::showUpgradeable() ...@@ -295,5 +299,14 @@ void QueryOperation::showUpgradeable()
foreach (Akabei::Package * pkg, upgradeable.values()) foreach (Akabei::Package * pkg, upgradeable.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl; out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush(); out.flush();
QCoreApplication::instance()->quit(); nextOperation();
}
void QueryOperation::nextOperation()
{
if (m_operations.isEmpty()) {
QCoreApplication::instance()->quit();
return;
}
start();
} }
...@@ -22,10 +22,17 @@ class QueryOperation : public QObject ...@@ -22,10 +22,17 @@ class QueryOperation : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QueryOperation(QObject * parent = 0); explicit QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent = 0);
virtual ~QueryOperation(); virtual ~QueryOperation();
void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args); void start();
private:
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args;
void nextOperation();
private slots: private slots:
void showInformation(QList<Akabei::Package*> packages); void showInformation(QList<Akabei::Package*> packages);
......
...@@ -24,34 +24,33 @@ ...@@ -24,34 +24,33 @@
#include <akabeihelpers.h> #include <akabeihelpers.h>
#include "queueoperation.h" #include "queueoperation.h"
RemoveOperation::RemoveOperation(QObject * parent) RemoveOperation::RemoveOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
: QObject(parent) : QObject(parent)
, m_operations(operations)
, m_options(options)
, m_args(args)
{ {
} }
RemoveOperation::~RemoveOperation() RemoveOperation::~RemoveOperation()
{ {
} }
void RemoveOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args) void RemoveOperation::start()
{ {
m_operation = operation; APM::OperationName operation = m_operations.takeFirst();
m_options = options;
m_args = args;
QString query = "SELECT * FROM packages WHERE"; QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkg, args) { foreach (const QString &pkg, m_args) {
query = query + " name=\"" + pkg + "\""; query = query + " name=\"" + pkg + "\"";
if (args.last() != pkg) if (m_args.last() != pkg)
query = query + " OR"; query = query + " OR";
} }
if (operation == APM::Unneeded) { //TODO: Implement those! if (operation == APM::Unneeded) { //TODO: Implement those!
removeUnneeded(Akabei::Backend::instance()->localDatabase()->packages()); removeUnneeded(Akabei::Backend::instance()->localDatabase()->packages());
} else if (operation == APM::Remove) { } else if (operation == APM::Remove) {
if (options.contains(APM::Recursive)) { if (m_options.contains(APM::Recursive)) {
removeRecursive(Akabei::Backend::instance()->localDatabase()->queryPackages(query)); removeRecursive(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
} else { } else {
remove(Akabei::Backend::instance()->localDatabase()->queryPackages(query)); remove(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
...@@ -67,9 +66,9 @@ void RemoveOperation::remove(QList<Akabei::Package*> packages) ...@@ -67,9 +66,9 @@ void RemoveOperation::remove(QList<Akabei::Package*> packages)
QCoreApplication::instance()->quit(); QCoreApplication::instance()->quit();
return; return;
} }
QueueOperation *operation = new QueueOperation(m_operation, m_options, this); QueueOperation *operation = new QueueOperation(APM::Remove, m_options, this);
operation->start(AkabeiClient::Remove, packages); operation->start(AkabeiClient::Remove, packages);
connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit())); connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(nextOperation()));
} }
void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages) void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages)
...@@ -86,9 +85,9 @@ void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages) ...@@ -86,9 +85,9 @@ void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages)
pkgs << p; pkgs << p;
} }
} }
QueueOperation *operation = new QueueOperation(m_operation, m_options, this); QueueOperation *operation = new QueueOperation(APM::Remove, m_options, this);
operation->start(AkabeiClient::Remove, pkgs); operation->start(AkabeiClient::Remove, pkgs);
connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit())); connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(nextOperation()));
} }
void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages) void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
...@@ -113,7 +112,16 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages) ...@@ -113,7 +112,16 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
QCoreApplication::instance()->quit(); QCoreApplication::instance()->quit();
return; return;
} }
QueueOperation *operation = new QueueOperation(m_operation, m_options, this); QueueOperation *operation = new QueueOperation(APM::Unneeded, m_options, this);
operation->start(AkabeiClient::Remove, unneeded); operation->start(AkabeiClient::Remove, unneeded);
connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit())); connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(nextOperation()));
} }
void RemoveOperation::nextOperation()
{
if (m_operations.isEmpty()) {
QCoreApplication::instance()->quit();
return;
}
start();
}
\ No newline at end of file
...@@ -20,18 +20,19 @@ class RemoveOperation : public QObject ...@@ -20,18 +20,19 @@ class RemoveOperation : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
RemoveOperation(QObject * parent = 0); RemoveOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent = 0);
virtual ~RemoveOperation(); virtual ~RemoveOperation();
void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args); void start();
public slots: public slots:
void remove(QList<Akabei::Package*> packages); void remove(QList<Akabei::Package*> packages);
void removeRecursive(QList<Akabei::Package*> packages); void removeRecursive(QList<Akabei::Package*> packages);
void removeUnneeded(QList< Akabei::Package* > packages); void removeUnneeded(QList< Akabei::Package* > packages);
void nextOperation();
private: private:
APM::OperationName m_operation; QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options; QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args; QStringList m_args;
}; };
......
...@@ -35,9 +35,12 @@ ...@@ -35,9 +35,12 @@
#include <iostream> #include <iostream>
SyncOperation::SyncOperation(QObject* parent) SyncOperation::SyncOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject* parent)
: QObject(parent) : QObject(parent)
, m_maxDbNameLenght(0) , m_maxDbNameLenght(0)
, m_operations(operations)
, m_options(options)
, m_args(args)
{} {}
SyncOperation::~SyncOperation() {} SyncOperation::~SyncOperation() {}
...@@ -45,40 +48,40 @@ SyncOperation::~SyncOperation() {} ...@@ -45,40 +48,40 @@ SyncOperation::~SyncOperation() {}
//TODO: Instead of putting all in operation, we want to split stuff like SkipDependencies into some special flags parameter :) that way //TODO: Instead of putting all in operation, we want to split stuff like SkipDependencies into some special flags parameter :) that way
// we can have proper errorhandling // we can have proper errorhandling
// or let shainer write that CLI parser // or let shainer write that CLI parser
void SyncOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args) void SyncOperation::start()
{ {
QTextStream err(stderr); QTextStream err(stderr);
Akabei::Backend *backend = Akabei::Backend::instance(); Akabei::Backend *backend = Akabei::Backend::instance();
m_operation = operation; APM::OperationName operation = m_operations.takeFirst();
m_options = options; qDebug() << "prossima operazione: " << operation;
m_args = args;
switch(operation) { switch(operation) {
case APM::Search: case APM::Search:
{ {
connect(backend, SIGNAL(queryPackagesCompleted(QUuid, QList<Akabei::Package*>)), SLOT(searchResult(QUuid,QList<Akabei::Package*>))); connect(backend, SIGNAL(queryPackagesCompleted(QUuid, QList<Akabei::Package*>)), SLOT(searchResult(QUuid,QList<Akabei::Package*>)));
backend->searchPackages(args); backend->searchPackages(m_args);
break; break;
} }