Commit 4b9521ad authored by Lisa's avatar Lisa

Multiple operations now supported.

parent 2b13f9a7
......@@ -22,10 +22,10 @@
#include <QCoreApplication>
#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),
m_type(type),
m_operation(operation),
m_operations(operations),
m_options(options),
m_args(args)
{
......@@ -65,23 +65,23 @@ void OperationManager::start()
{
switch (m_type) {
case APM::QueryOperationType: {
QueryOperation * query = new QueryOperation(this);
query->start(m_operation, m_options, m_args);
QueryOperation * query = new QueryOperation(m_operations, m_options, m_args, this);
query->start();
break;
}
case APM::RemoveOperationType: {
RemoveOperation * remove = new RemoveOperation(this);
remove->start(m_operation, m_options, m_args);
RemoveOperation * remove = new RemoveOperation(m_operations, m_options, m_args, this);
remove->start();
break;
}
case APM::SyncOperationType: {
SyncOperation * sync = new SyncOperation(this);
sync->start(m_operation, m_options, m_args);
SyncOperation * sync = new SyncOperation(m_operations, m_options, m_args, this);
sync->start();
break;
}
case APM::UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this);
upgrade->start(m_operation, m_options, m_args);
upgrade->start(m_operations, m_options, m_args);
break;
}
default:
......
......@@ -21,7 +21,7 @@ class OperationManager : public QObject
{
Q_OBJECT
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();
private slots:
......@@ -30,7 +30,7 @@ private slots:
private:
APM::OperationType m_type;
APM::OperationName m_operation;
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args;
};
......
......@@ -13,6 +13,8 @@
#include <kaboutdata.h>
#include <klocalizedstring.h>
#include <QSet>
/*
* Build our database of accepted operations and options with the right properties and associations
*/
......@@ -141,11 +143,6 @@ CmdLine::CmdLine()
updatesys.addOption(ignore);
updatesys.addOption(ignoregroup);
AkabeiOperation updatedbandsys(APM::SyncOperationType, APM::UpdateDatabaseAndSystem, "", "", "Refresh database and update system", false);
updatedbandsys.addOption(downloadonly);
updatedbandsys.addOption(ignore);
updatedbandsys.addOption(ignoregroup);
AkabeiOperation upgrade(APM::UpgradeOperationType, APM::Upgrade, "U", "", "Upgrade operation", true);
upgrade.addOption(downloadonly);
upgrade.addOption(ignore);
......@@ -156,13 +153,13 @@ CmdLine::CmdLine()
AkabeiOperation version(APM::NoType, APM::Version, "v", "version", "Shows Akabei version", false);
QList<AkabeiOperation *> tmp;
tmp << &removeallcache << &help << &version << &install << &remove << &database << &changelog << &installedasdeps << &installedexp;
tmp << &updatedb << &removeallcache << &help << &version << &install << &remove << &database;
tmp << &checkfiles << &showowner << &notrequired << &upgradeable << &cascade << &unneeded;
tmp << &removeold << &groups << &info << &listrepo << &groupsl << &searchl << &infol;
tmp << &search << &updatedb << &updatesys << &updatedbandsys << &upgrade;
tmp << &search << &updatesys << &upgrade << &changelog << &installedasdeps << &installedexp;
/*
* It has to be pointers otherwise the changes in this foreach
* They have to be pointers otherwise the changes in this foreach
* aren't reflected in specialOperations below
*/
foreach (AkabeiOperation *op, tmp) {
......@@ -215,37 +212,6 @@ AkabeiOperation::AkabeiOperation()
init(APM::NoType, APM::None, "", "", "", false, QStringList());
}
/*
* This requires some explanation
* 0: APM::None means no operation has still been set, so no problem here.
* 1: -S is Install, but for example -Ss is Search. Same for most removing operations. This overlapping is fine.
* 2: the elements in a hash aren't sorted, so "s" may be found before "S".
* 3: for -Scc, both "cc" and "c" are found. Only the first one is good.
* 4: -Sy is UpdateDatabases, -Su is UpdateSystem, but -Syu is APM::UpdateDatabaseAndSystem (only linked operations accepted).
* 5: All the rest is invalid
*/
void AkabeiOperation::set(AkabeiOperation& other)
{
if ((this->type == APM::SyncOperationType && other.name == APM::Install) || (this->type == APM::RemoveOperationType && other.name == APM::Remove)) {
return;
}
if (this->name == APM::None || this->name == APM::Remove || this->name == APM::Install || (this->commandShort == "c" && other.name == APM::RemoveAllCache)) {
this->name = other.name;
this->type = other.type;
this->options = other.options;
this->commandLong = other.commandLong;
this->commandShort = other.commandShort;
this->hasFreeArgs = other.hasFreeArgs;
} else if ((this->name == APM::UpdateDatabases && other.name == APM::UpdateSystem) || (this->name == APM::UpdateSystem && other.name == APM::UpdateDatabases)) {
this->name = APM::UpdateDatabaseAndSystem;
this->type = APM::SyncOperationType;
this->hasFreeArgs = false;
} else {
throw CmdLineException("multiple operations present.");
}
}
void AkabeiOperation::init(APM::OperationType t, APM::OperationName n, const char *cs, const char *cl, const char *desc, bool hasFreeArgs, QStringList args)
{
type = t;
......@@ -326,29 +292,28 @@ void CmdLine::parse(int argc, char** argv)
KCmdLineArgs::addCmdLineOptions(koptions);
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
APM::OperationType type = APM::NoType;
m_operation.name = APM::None;
QList<QByteArray> found;
m_type = APM::NoType;
QSet<QByteArray> found;
/*
* These are considered separately and when found, they surpass any other operation that may be present.
*/
if (args->isSet("h")) {
AkabeiOperation help = specialOperations[1];
m_operation.set(help);
m_operations.insert(APM::Help, help);
} else if (args->isSet("v")) {
AkabeiOperation version = specialOperations[2];
m_operation.set(version);
m_operations.insert(APM::Version, version);
}
else {
for (QHash<QByteArray, APM::OperationType>::iterator it = typechars.begin(); it != typechars.end(); it++) {
if (args->isSet(it.key())) {
if (type != APM::NoType) {
if (m_type != APM::NoType) {
throw CmdLineException("multiple types present.");
}
type = it.value();
m_type = it.value();
if (type == APM::QueryOperationType) {
if (m_type == APM::QueryOperationType) {
found << "Q";
}
......@@ -356,20 +321,12 @@ void CmdLine::parse(int argc, char** argv)
* We look only for the acceptable operations
* all the others, if present, will be spotted later
*/
foreach (AkabeiOperation op, acceptedOperations.values(type)) {
/*
* This eliminates the only "dummy" operation with no commands at all
* every other operation has got at least the short command
*/
if (op.commandShort.isEmpty()) {
continue;
}
foreach (AkabeiOperation op, acceptedOperations.values(m_type)) {
/*
* Saves up the commands for later inspection
*/
if (args->isSet(op.commandShort)) {
m_operation.set(op);
m_operations.insert(op.name, op);
found << op.commandShort;
if (!op.commandLong.isEmpty()) {
found << op.commandLong;
......@@ -383,17 +340,29 @@ void CmdLine::parse(int argc, char** argv)
*/
if (KCmdLineArgs::allArguments().contains("-Scc")) {
AkabeiOperation special = specialOperations.first();
m_operation.set(special);
m_operations.insert(special.name, special);
found << special.commandShort;
}
}
}
}
if (m_operation.name == APM::None) {
if (m_operations.isEmpty()) {
throw CmdLineException("no operation specified.");
}
/*
* Now we need some adjustments!
*/
if (m_operations.size() > 1 && (m_operations.contains(APM::Remove) || m_operations.contains(APM::Install))) {
m_operations.remove(APM::Remove);
m_operations.remove(APM::Install);
}
if (m_operations.contains(APM::RemoveAllCache)) {
m_operations.remove(APM::RemoveOldFromCache);
m_operations.remove(APM::Cascade);
}
foreach (AkabeiOption opt, acceptedOptions) {
QByteArray command = (opt.commandShort.isEmpty()) ? opt.commandLong : opt.commandShort;
......@@ -406,9 +375,18 @@ void CmdLine::parse(int argc, char** argv)
condition &= args->isSet(command); /* normal check */
}
if (condition) {
if (!m_operation.isOptionSupported(opt.name)) {
throw CmdLineException("invalid option for this operation");
if (condition) {
/* If at least one operation supports the option, it's fine */
bool supported = false;
foreach (AkabeiOperation op, m_operations.values()) {
if (op.isOptionSupported(opt.name)) {
supported = true;
break;
}
}
if (!supported) {
throw CmdLineException("invalid option");
}
if (!opt.commandShort.isEmpty()) {
......@@ -423,18 +401,11 @@ void CmdLine::parse(int argc, char** argv)
*/
QStringList optargs = args->getOptionList(command);
/*
* Remember, if it's not an option args it can be an argument to the operation
* so we're not really sure an error has been made, unless the operation doesn't admit any argument
*/
if (!optargs.isEmpty() && !opt.hasArg && !m_operation.hasFreeArgs) {
if (!optargs.isEmpty() && !opt.hasArg) {
QString message = "the option \"" + command + "\" must not have an argument.";
throw CmdLineException(message.toUtf8().data());
}
/*
* In this case, we're sure :)
*/
if (optargs.isEmpty() && opt.hasArg) {
QString message = "missing argument for the option \"" + command + "\"";
throw CmdLineException(message.toUtf8().data());
......@@ -446,6 +417,7 @@ void CmdLine::parse(int argc, char** argv)
}
secondParse(KCmdLineArgs::allArguments(), found);
/*
* Gets all the other arguments around
*/
......@@ -453,15 +425,16 @@ void CmdLine::parse(int argc, char** argv)
m_freeArgs << args->arg(i);
}
if (!m_freeArgs.isEmpty() && !m_operation.hasFreeArgs) {
if (!m_freeArgs.isEmpty() && !freeArgsRequired()) {
throw CmdLineException("unexpected free arguments.");
}
if (m_freeArgs.isEmpty() && m_operation.hasFreeArgs) {
if (m_freeArgs.isEmpty() && freeArgsRequired()) {
throw CmdLineException("free arguments required but not present.");
}
args->clear(); /* frees up memory */
parsed = true;
}
......@@ -471,7 +444,7 @@ void CmdLine::parse(int argc, char** argv)
* * if the operation is repeated more than once (not accepted)
* * if there's something "out of context" in the command line (like, some meaningless command)
*/
void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds)
void CmdLine::secondParse(QStringList args, QSet<QByteArray>& foundCmds)
{
QList<QByteArray> cmdline;
......@@ -502,7 +475,7 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds)
/* The only short commands with two letters is treated separately to avoid problems */
if (part.contains("cc")) {
if (part.count("cc") > 1) {
throw CmdLineException("can't accept linked operations.");
throw CmdLineException("can't accept the same operation twice.");
} else {
part.remove("cc");
cmdline << "cc";
......@@ -527,11 +500,13 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds)
}
/*
* Counts the occurrence of the operation
* Counts the occurrences of each operation
*/
int occurrences = cmdline.count(m_operation.commandLong) + cmdline.count(m_operation.commandShort);
if (occurrences > 1) {
throw CmdLineException("can't accept linked operations.");
foreach (const AkabeiOperation& op, m_operations.values()) {
int occurrences = cmdline.count(op.commandLong) + cmdline.count(op.commandShort);
if (occurrences > 1) {
throw CmdLineException("can't accept the same operation twice.");
}
}
/*
......@@ -544,29 +519,44 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds)
continue;
}
occurrences = cmdline.count(opt.commandLong) + cmdline.count(opt.commandShort);
int occurrences = cmdline.count(opt.commandLong) + cmdline.count(opt.commandShort);
if (occurrences > 1) {
throw CmdLineException("can't repeat this option twice.");
}
}
}
/*
* If at least one operation in the chain requires free args, they're required
*/
bool CmdLine::freeArgsRequired()
{
foreach (const AkabeiOperation& op, m_operations.values()) {
if (op.hasFreeArgs) {
return true;
}
}
return false;
}
APM::OperationType CmdLine::type()
{
if (!parsed) {
throw CmdLineException("Command line not parsed.");
}
return m_operation.type;
return m_type;
}
APM::OperationName CmdLine::operation()
QList<APM::OperationName> CmdLine::operations()
{
if (!parsed) {
throw CmdLineException("Command line not parsed.");
}
return m_operation.name;
return m_operations.keys();
}
QStringList CmdLine::freeArgs()
......
......@@ -39,7 +39,7 @@ enum OperationName {
None,
ShowChangelog, ShowInstalledAsDeps, ShowInstalledExplicitely, ShowPackagesOfGroup, ShowPackagesOfGroupLocal, ShowInformationLocal,
ShowInformation, CheckFiles, ShowOwner, ShowNotRequired, ShowUpgradeable,
Install, RemoveOldFromCache, RemoveAllCache, ListRepo, Search, UpdateDatabases, UpdateSystem, UpdateDatabaseAndSystem,
Install, RemoveOldFromCache, RemoveAllCache, ListRepo, Search, UpdateDatabases, UpdateSystem,
Remove, Cascade, Unneeded, SearchLocal,
DatabaseOperation, Upgrade, Help, Version
};
......@@ -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, 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
*/
......@@ -116,7 +110,8 @@ typedef QList<AkabeiOperation> AkabeiOperationList;
class CmdLine
{
private:
AkabeiOperation m_operation;
APM::OperationType m_type;
QHash<APM::OperationName, AkabeiOperation> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_freeArgs;
......@@ -130,14 +125,15 @@ private:
bool parsed;
void secondParse(QStringList, QList<QByteArray> &);
void secondParse(QStringList, QSet<QByteArray> &);
bool freeArgsRequired();
public:
CmdLine();
void parse(int argc, char **argv);
APM::OperationType type();
APM::OperationName operation();
QList<APM::OperationName> operations();
QHash<APM::OptionName, AkabeiOption> options();
QStringList freeArgs();
};
......
......@@ -28,6 +28,6 @@ int main(int argc, char** argv)
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();
}
......@@ -23,10 +23,12 @@
#include <QDir>
#include <QCoreApplication>
QueryOperation::QueryOperation(QObject * parent)
QueryOperation::QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
: QObject(parent)
, m_operations(operations)
, m_options(options)
, m_args(args)
{
}
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 (options.contains(APM::QueryPackageFile)) {
showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first()));
if (m_options.contains(APM::QueryPackageFile)) {
showInformation(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} 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
}
} else if (operation == APM::ShowPackagesOfGroupLocal) {
connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(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) {
if (options.contains(APM::QueryPackageFile)) {
showChangelog(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first()));
if (m_options.contains(APM::QueryPackageFile)) {
showChangelog(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} 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) {
QString query = "SELECT * FROM packages WHERE";
if (!args.isEmpty()) // TODO: vedi un po' qua che vuol dire
query = query + " Name LIKE \"" + args.first() + "\" AND";
if (!m_args.isEmpty())
query = query + " Name LIKE \"" + m_args.first() + "\" AND";
if (operation == APM::ShowInstalledAsDeps)
query = query + " InstallReason LIKE 0";// + QString((int)Akabei::Package::InstalledAsDependencyReason);
else
query = query + " InstallReason LIKE " + QString::number((int)Akabei::Package::ExplicitlyInstalledReason);
showInstalledAsDeps(Akabei::Backend::instance()->localDatabase()->queryPackages(query));
} else if (operation == APM::CheckFiles) {
if (options.contains(APM::QueryPackageFile)) {
checkFiles(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(args.first()));
if (m_options.contains(APM::QueryPackageFile)) {
checkFiles(QList<Akabei::Package*>() << Akabei::Backend::instance()->loadPackageFromFile(m_args.first()));
} else {
checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(args.first()));
checkFiles(Akabei::Backend::instance()->localDatabase()->searchPackages(m_args.first()));
}
} else if (operation == APM::SearchLocal) {
if (args.isEmpty())
if (m_args.isEmpty())
showLocalPackages(QString());
else
showLocalPackages(args.first());
showLocalPackages(m_args.first());
} else if (operation == APM::ShowOwner) {
showOwner(args.first());
showOwner(m_args.first());
} 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) {
showNotRequired();
} else if (operation == APM::ShowUpgradeable) {
......@@ -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("Description") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->description() << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
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())
out << group->name() << ' ' << pkg->name() << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
void QueryOperation::showChangelog(QList< Akabei::Package* > packages)
......@@ -150,7 +154,7 @@ void QueryOperation::showChangelog(QList< Akabei::Package* > packages)
QTextStream out(stdout);
out << pkg->retrieveChangelog() << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
......@@ -166,7 +170,7 @@ void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
foreach (Akabei::Package * pkg, sorted.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
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.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
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.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
void QueryOperation::showOwner(const QString &query)
......@@ -237,7 +241,7 @@ void QueryOperation::showOwner(const QString &query)
}
out << "Error: No packages owns " << query << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages)
......@@ -251,7 +255,7 @@ void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages)
out << "\t" << pkg->description() << endl;
}
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
void QueryOperation::showNotRequired()
......@@ -268,7 +272,7 @@ void QueryOperation::showNotRequired()
foreach (Akabei::Package * pkg, pkgs.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
QCoreApplication::instance()->quit();
nextOperation();
}
void QueryOperation::showUpgradeable()
......@@ -295,5 +299,14 @@ void QueryOperation::showUpgradeable()
foreach (Akabei::Package * pkg, upgradeable.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
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
{
Q_OBJECT
public:
explicit QueryOperation(QObject * parent = 0);
explicit QueryOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent = 0);
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:
void showInformation(QList<Akabei::Package*> packages);
......
......@@ -24,34 +24,33 @@
#include <akabeihelpers.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)
, m_operations(operations)
, m_options(options)
, m_args(args)
{
}
RemoveOperation::~RemoveOperation()
{
}
void RemoveOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args)
void RemoveOperation::start()
{
m_operation = operation;
m_options = options;
m_args = args;
APM::OperationName operation = m_operations.takeFirst();
QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkg, args) {
foreach (const QString &pkg, m_args) {
query = query + " name=\"" + pkg + "\"";
if (args.last() != pkg)
if (m_args.last() != pkg)
query = query + " OR";
}
if (operation == APM::Unneeded) { //TODO: Implement those!
removeUnneeded(Akabei::Backend::instance()->localDatabase()->packages());