Commit 76c0acee authored by Lisa's avatar Lisa

Astyle used over this branch

parent 384b7dc1
......@@ -23,11 +23,11 @@
#include <QTimer>
OperationManager::OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject * parent)
: QObject(parent),
m_type(type),
m_operation(operation),
m_options(options),
m_args(args)
: QObject(parent),
m_type(type),
m_operation(operation),
m_options(options),
m_args(args)
{
//QTimer::singleShot(0, AkabeiClient::Backend::instance(), SLOT(initialize()));
//QCoreApplication::instance()->quit();
......@@ -36,7 +36,7 @@ OperationManager::OperationManager(APM::OperationType type, APM::OperationName o
QString root;
QString cache;
QString dbs;
if (options.contains(APM::RootDir)) {
root = options[APM::RootDir].args[0];
}
......@@ -46,7 +46,7 @@ OperationManager::OperationManager(APM::OperationType type, APM::OperationName o
if (options.contains(APM::DBPath)) {
dbs = options[APM::DBPath].args[0];
}
AkabeiClient::Backend::instance()->initialize(root, cache, dbs);
}
......@@ -64,28 +64,28 @@ void OperationManager::statusChanged(Akabei::Backend::Status status)
void OperationManager::start()
{
switch (m_type) {
case APM::QueryOperationType: {
QueryOperation * query = new QueryOperation(this);
query->start(m_operation, m_options, m_args);
break;
}
case APM::RemoveOperationType: {
RemoveOperation * remove = new RemoveOperation(this);
remove->start(m_operation, m_options, m_args);
break;
}
case APM::SyncOperationType: {
SyncOperation * sync = new SyncOperation(this);
sync->start(m_operation, m_options, m_args);
break;
}
case APM::UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this);
upgrade->start(m_operation, m_options, m_args);
break;
}
default:
break;
case APM::QueryOperationType: {
QueryOperation * query = new QueryOperation(this);
query->start(m_operation, m_options, m_args);
break;
}
case APM::RemoveOperationType: {
RemoveOperation * remove = new RemoveOperation(this);
remove->start(m_operation, m_options, m_args);
break;
}
case APM::SyncOperationType: {
SyncOperation * sync = new SyncOperation(this);
sync->start(m_operation, m_options, m_args);
break;
}
case APM::UpgradeOperationType: {
UpgradeOperation * upgrade = new UpgradeOperation(this);
upgrade->start(m_operation, m_options, m_args);
break;
}
default:
break;
}
}
......
......@@ -19,15 +19,15 @@
class OperationManager : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit OperationManager(APM::OperationType type, APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args, QObject* parent = 0);
virtual ~OperationManager();
private slots:
void statusChanged(Akabei::Backend::Status);
void start();
private:
APM::OperationType m_type;
APM::OperationName m_operation;
......
This diff is collapsed.
......@@ -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, UpdateDatabaseAndSystem,
Remove, Cascade, Unneeded, SearchLocal,
DatabaseOperation, Upgrade, Help, Version
};
......@@ -53,19 +53,19 @@ typedef enum OperationName OperationName;
class AkabeiOption
{
private:
void init(APM::OptionName, const char *, const char *, const char *, bool, QStringList);
void init(APM::OptionName, const char *, const char *, const char *, bool, QStringList);
public:
APM::OptionName name;
QByteArray commandShort, commandLong;
KLocalizedString description;
bool hasArg;
/*
* Args are required by some options like --ignore or --ignoregroup
*/
QStringList args;
AkabeiOption(APM::OptionName, const char *, const char *, const char *, bool);
AkabeiOption(APM::OptionName, const char *, const char *, const char *, bool, QStringList);
AkabeiOption() {}
......@@ -80,7 +80,7 @@ class AkabeiOperation
{
private:
void init(APM::OperationType, APM::OperationName, const char *, const char *, const char *, bool, QStringList);
public:
APM::OperationType type;
APM::OperationName name;
......@@ -88,22 +88,22 @@ public:
KLocalizedString description;
QHash<APM::OptionName, AkabeiOption> options; /* options that can be associated to this operation */
bool hasFreeArgs;
/*
* An example of free args is the list of packages following an install command
*/
QStringList freeArgs;
AkabeiOperation();
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
*/
......@@ -119,23 +119,23 @@ private:
AkabeiOperation m_operation;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_freeArgs;
/* Database */
QMultiHash<APM::OperationType, AkabeiOperation> acceptedOperations;
AkabeiOptionList acceptedOptions;
QHash<QByteArray, APM::OperationType> typechars;
/* This is for the few operations that we need to access quickly later */
AkabeiOperationList specialOperations;
bool parsed;
void secondParse(QStringList, QList<QByteArray> &);
public:
CmdLine();
void parse(int argc, char **argv);
APM::OperationType type();
APM::OperationName operation();
QHash<APM::OptionName, AkabeiOption> options();
......
......@@ -14,12 +14,13 @@
#include <kdebug.h>
#include "apm.h"
#include "cmdline.h"
#include <akabeilog.h>
int main(int argc, char** argv)
{
{
QCoreApplication app(argc, argv);
CmdLine cmd;
try {
cmd.parse(argc, argv);
} catch (CmdLineException& ex) {
......@@ -27,7 +28,8 @@ int main(int argc, char** argv)
err << "Fatal error parsing command line: " << ex.what() << endl;
return -1;
}
Akabei::logInit("akabei.log");
OperationManager apm(cmd.type(), cmd.operation(), cmd.options(), cmd.freeArgs());
return app.exec();
}
......@@ -24,7 +24,7 @@
#include <QCoreApplication>
QueryOperation::QueryOperation(QObject * parent)
: QObject(parent)
: QObject(parent)
{
}
......@@ -44,8 +44,8 @@ void QueryOperation::start(APM::OperationName operation, QHash<APM::OptionName,
//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*>)));
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() + "\"");
} else if (operation == APM::ShowChangelog) {
if (options.contains(APM::QueryPackageFile)) {
......@@ -101,8 +101,8 @@ void QueryOperation::showInformation(QList<Akabei::Package*> packages)
out << i18n("URL") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->url().toString() << endl;
out << i18n("Licenses") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->license() << endl;
QStringList groups;
foreach (Akabei::Group * g, pkg->groups())
groups << g->name();
foreach(Akabei::Group * g, pkg->groups())
groups << g->name();
out << i18n("Groups") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << groups.join(" ") << endl;
out << i18n("Provides") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->provides().join(" ") << endl;
out << i18n("Depends on") << qSetFieldWidth(2) << ":" << qSetFieldWidth(20) << pkg->dependencies().join(" ") << endl;
......@@ -121,7 +121,7 @@ void QueryOperation::showInformation(QList<Akabei::Package*> packages)
QCoreApplication::instance()->quit();
}
void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
void QueryOperation::showGroup(QUuid uuid, QList<Akabei::Group*> groups)
{
Q_UNUSED(uuid)
if (groups.isEmpty()) {
......@@ -129,13 +129,13 @@ void QueryOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
return;
}
Akabei::Group * group = groups.first();
QTextStream out(stdout);
QMap<QString, Akabei::Package*> sorted;
foreach (Akabei::Package * pkg, group->packages())
sorted[pkg->name()] = pkg;
foreach (Akabei::Package * pkg, sorted.values())
out << group->name() << ' ' << pkg->name() << endl;
foreach(Akabei::Package * pkg, group->packages())
sorted[pkg->name()] = pkg;
foreach(Akabei::Package * pkg, sorted.values())
out << group->name() << ' ' << pkg->name() << endl;
out.flush();
QCoreApplication::instance()->quit();
}
......@@ -161,10 +161,10 @@ void QueryOperation::showInstalledAsDeps(QList<Akabei::Package*> packages)
}
QTextStream out(stdout);
QMap<QString, Akabei::Package*> sorted;
foreach (Akabei::Package * pkg, packages)
sorted[pkg->name()] = pkg;
foreach (Akabei::Package * pkg, sorted.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
foreach(Akabei::Package * pkg, packages)
sorted[pkg->name()] = pkg;
foreach(Akabei::Package * pkg, sorted.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
QCoreApplication::instance()->quit();
}
......@@ -179,7 +179,7 @@ void QueryOperation::checkFiles(QList<Akabei::Package*> packages)
QTextStream out(stdout);
int all = 0;
int missing = 0;
foreach (const QString &file, pkg->retrieveFiles()) {
foreach(const QString & file, pkg->retrieveFiles()) {
all++;
if (!QFile::exists(Akabei::Config::instance()->rootDir().absoluteFilePath(file)))
missing++;
......@@ -190,17 +190,17 @@ void QueryOperation::checkFiles(QList<Akabei::Package*> packages)
}
void QueryOperation::showLocalPackages(const QString &query)
{
{
QTextStream out(stdout);
QList<Akabei::Package*> packages;
if (!query.isEmpty())
packages = Akabei::Backend::instance()->localDatabase()->searchPackages(query);
else
packages = Akabei::Backend::instance()->localDatabase()->packages();
foreach (Akabei::Package* pkg, packages) {
foreach(Akabei::Package * pkg, packages) {
bool found = false;
foreach (Akabei::Database* db, Akabei::Backend::instance()->databases()) {
foreach (Akabei::Package* p, db->searchPackages(pkg->name())) {
foreach(Akabei::Database * db, Akabei::Backend::instance()->databases()) {
foreach(Akabei::Package * p, db->searchPackages(pkg->name())) {
if (p->name() == pkg->name()) {
found = true;
break;
......@@ -225,8 +225,8 @@ void QueryOperation::showOwner(const QString &query)
QCoreApplication::instance()->quit();
return;
}
foreach (Akabei::Package * pkg, Akabei::Backend::instance()->localDatabase()->packages()) {
foreach (const QString &file, pkg->retrieveFiles()) {
foreach(Akabei::Package * pkg, Akabei::Backend::instance()->localDatabase()->packages()) {
foreach(const QString & file, pkg->retrieveFiles()) {
if (Akabei::Config::instance()->rootDir().absoluteFilePath(file) == query) {
out << query << " is owned by " << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
......@@ -244,9 +244,9 @@ void QueryOperation::showLocalQuery(QList<Akabei::Package*> packages)
{
QTextStream out(stdout);
QMap<QString, Akabei::Package*> sorted;
foreach (Akabei::Package * pkg, packages)
sorted[pkg->name()] = pkg;
foreach (Akabei::Package * pkg, sorted.values()) {
foreach(Akabei::Package * pkg, packages)
sorted[pkg->name()] = pkg;
foreach(Akabei::Package * pkg, sorted.values()) {
out << "local/" << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out << "\t" << pkg->description() << endl;
}
......@@ -259,14 +259,14 @@ void QueryOperation::showNotRequired()
QTextStream out(stdout);
QList<Akabei::Package*> packages = Akabei::Backend::instance()->localDatabase()->packages();
QMap<QString, Akabei::Package*> pkgs;
foreach (Akabei::Package* pkg, packages)
pkgs[pkg->name()] = pkg;
foreach (Akabei::Package* pkg, packages) {
foreach (const QString &dep, pkg->dependencies())
pkgs.remove(dep);
foreach(Akabei::Package * pkg, packages)
pkgs[pkg->name()] = pkg;
foreach(Akabei::Package * pkg, packages) {
foreach(const QString & dep, pkg->dependencies())
pkgs.remove(dep);
}
foreach (Akabei::Package * pkg, pkgs.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
foreach(Akabei::Package * pkg, pkgs.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
QCoreApplication::instance()->quit();
}
......@@ -277,11 +277,11 @@ void QueryOperation::showUpgradeable()
QTextStream out(stdout);
QList<Akabei::Package*> packages = Akabei::Backend::instance()->localDatabase()->packages();
QMap<QString, Akabei::Package*> upgradeable;
foreach (Akabei::Package * pkg, packages) {
foreach (Akabei::Database * db, Akabei::Backend::instance()->databases()) {
foreach(Akabei::Package * pkg, packages) {
foreach(Akabei::Database * db, Akabei::Backend::instance()->databases()) {
Akabei::Package::List list = db->queryPackages("SELECT * FROM packages WHERE Name LIKE \"" + pkg->name() + "\"");
if (!list.isEmpty()) {
foreach (Akabei::Package * p, list) {
foreach(Akabei::Package * p, list) {
if (p->version() > pkg->version() && p->name() == pkg->name()) {
if (upgradeable[p->name()] && upgradeable[p->name()]->version() > p->version())
continue;
......@@ -291,9 +291,9 @@ void QueryOperation::showUpgradeable()
}
}
}
foreach (Akabei::Package * pkg, upgradeable.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
foreach(Akabei::Package * pkg, upgradeable.values())
out << pkg->name() << ' ' << pkg->version().toByteArray().data() << endl;
out.flush();
QCoreApplication::instance()->quit();
}
......@@ -20,16 +20,16 @@
class QueryOperation : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit QueryOperation(QObject * parent = 0);
virtual ~QueryOperation();
void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args);
private slots:
void showInformation(QList<Akabei::Package*> packages);
void showGroup(QUuid uuid,QList<Akabei::Group*> groups);
void showGroup(QUuid uuid, QList<Akabei::Group*> groups);
void showChangelog(QList<Akabei::Package*> packages);
void showInstalledAsDeps(QList<Akabei::Package*>);
void checkFiles(QList<Akabei::Package*>);
......
This diff is collapsed.
......@@ -17,27 +17,28 @@
#include "apm.h"
#include <akabeierror.h>
namespace AkabeiClient {
class TransactionQuestion;
namespace AkabeiClient
{
class TransactionQuestion;
}
class QueueOperation : public QObject
{
Q_OBJECT
Q_OBJECT
public:
QueueOperation(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QObject * parent = 0);
virtual ~QueueOperation();
void start(AkabeiClient::PackageAction action, QList<Akabei::Package*> packages);
private slots:
void validationFinished(bool valid, QList<AkabeiClient::TransactionQuestion*> questions);
void showProgress();
void errors(QList<Akabei::Error*>& errors);
void transactionMessage(const QString &message);
void transationFinished();
void packageProgressChanged(Akabei::Package*,int);
void packageProgressChanged(Akabei::Package*, int);
signals:
void finished();
......
......@@ -25,7 +25,7 @@
#include "queueoperation.h"
RemoveOperation::RemoveOperation(QObject * parent)
: QObject(parent)
: QObject(parent)
{
}
......@@ -40,14 +40,14 @@ void RemoveOperation::start(APM::OperationName operation, QHash<APM::OptionName,
m_operation = operation;
m_options = options;
m_args = args;
QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkg, args) {
foreach(const QString & pkg, args) {
query = query + " name=\"" + pkg + "\"";
if (args.last() != pkg)
query = query + " OR";
}
if (operation == APM::Unneeded) {
removeUnneeded(Akabei::Backend::instance()->localDatabase()->packages());
} else if (operation == APM::Remove) {
......@@ -80,8 +80,8 @@ void RemoveOperation::removeRecursive(QList<Akabei::Package*> packages)
}
QList<Akabei::Package*> pkgs;
pkgs << packages;
foreach (Akabei::Package * pkg, packages) {
foreach (Akabei::Package * p, pkg->computeDependencies()) {
foreach(Akabei::Package * pkg, packages) {
foreach(Akabei::Package * p, pkg->computeDependencies()) {
if (p->installReason() == Akabei::Package::InstalledAsDependencyReason) //FIXME: have -ss for removing all packages
pkgs << p;
}
......@@ -99,13 +99,13 @@ void RemoveOperation::removeUnneeded(QList< Akabei::Package* > packages)
}
qDebug() << "APM::Remove" << packages.count() << "unnneeded";
QList<Akabei::Package*> unneeded;
foreach (Akabei::Package * pkg, packages) {
foreach(Akabei::Package * pkg, packages) {
bool required = false;
foreach (Akabei::Package * p, pkg->computeRequiredBy()) {
foreach(Akabei::Package * p, pkg->computeRequiredBy()) {
/* FIXME: isn't this quite useless, since packages contains only the local ones? */
required = required || p->database() == Akabei::Backend::instance()->localDatabase();
if (required)
break;
}
......
......@@ -18,18 +18,18 @@
class RemoveOperation : public QObject
{
Q_OBJECT
Q_OBJECT
public:
RemoveOperation(QObject * parent = 0);
virtual ~RemoveOperation();
void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args);
public slots:
void remove(QList<Akabei::Package*> packages);
void removeRecursive(QList<Akabei::Package*> packages);
void removeUnneeded(QList< Akabei::Package* > packages);
private:
APM::OperationName m_operation;
QHash<APM::OptionName, AkabeiOption> m_options;
......
This diff is collapsed.
......@@ -20,33 +20,33 @@
class SyncOperation : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit SyncOperation(QObject* parent = 0);
virtual ~SyncOperation();
void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args);
private slots:
void searchResult(QUuid,QList<Akabei::Package*>);
void searchResult(QUuid, QList<Akabei::Package*>);
void listRepo(const QString &repo);
void showInformation(QUuid,QList<Akabei::Package*> packages);
void showGroup(QUuid,QList<Akabei::Group*>);
void showInformation(QUuid, QList<Akabei::Package*> packages);
void showGroup(QUuid, QList<Akabei::Group*>);
void databaseStatusChanged(AkabeiClient::DatabaseHandler::Status);
void databaseProgressChanged(int);
void databaseErrorTriggered(int);
void install(QUuid,QList<Akabei::Package*>);
void upgrade(QUuid,QList<Akabei::Package*>);
void install(QUuid, QList<Akabei::Package*>);
void upgrade(QUuid, QList<Akabei::Package*>);
private:
int m_currentDatabasePos;
int m_maxDbNameLenght;
void updateDatabases();
void updateSystem();
void updateNextDatabase();
APM::OperationName m_operation;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_args;
......
......@@ -27,7 +27,7 @@
//FIXME: There is actually a bunch of code duplication with SyncOperation and RemoveOperation... maybe we can create something that is used in all of them :)
UpgradeOperation::UpgradeOperation(QObject * parent)
: QObject(parent)
: QObject(parent)
{
}
......@@ -40,9 +40,9 @@ UpgradeOperation::~UpgradeOperation()
void UpgradeOperation::start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args)
{
QList<Akabei::Package*> pkgs;
foreach (const QString &p, args)
pkgs << Akabei::Backend::instance()->loadPackageFromFile(p);
foreach(const QString & p, args)
pkgs << Akabei::Backend::instance()->loadPackageFromFile(p);
QueueOperation *op = new QueueOperation(operation, options, this);
op->start(AkabeiClient::Install, pkgs);
connect(op, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
......
......@@ -17,11 +17,11 @@
class UpgradeOperation : public QObject
{
Q_OBJECT
Q_OBJECT
public:
UpgradeOperation(QObject * parent = 0);
virtual ~UpgradeOperation();
void start(APM::OperationName operation, QHash<APM::OptionName, AkabeiOption> options, QStringList args);
};
......
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