Commit 32b20fbb authored by Dario Freddi's avatar Dario Freddi

Start inserting some logic (and sqlite as well), and hey, it compiles

Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent 36950f29
......@@ -4,3 +4,8 @@
*.moc
moc_*
build/
*.o
*.so
*.so.*
Makefile
*.pro.user
......@@ -19,4 +19,37 @@
# define AKABEICORESHARED_EXPORT Q_DECL_IMPORT
#endif
// Define column numbers
namespace Akabei {
namespace Tables {
namespace Packages {
const int ID = 0;
const int NAME = 1;
const int VERSION = 2;
const int DESCRIPTION = 3;
const int GROUPS = 4;
const int SIZE = 5;
const int HASSCRIPTLET = 6;
const int HOOKS = 7;
const int MD5SUM = 8;
const int URL = 9;
const int BUILDDATE = 10;
const int ARCH = 11;
const int PACKAGER = 12;
const int PROVIDES = 13;
const int CONFLICTS = 14;
const int DEPENDS = 15;
const int PROVIDESMIMETYPE = 16;
const int FLAGS = 17;
const int FILES = 18;
const int INSTALLREASON = 19;
}
}
}
#endif // AKABEICORE_GLOBAL_H
......@@ -8,12 +8,99 @@
version 2 of the License, or (at your option) any later version.
*/
#include "akabeidatabase.h"
#include "akabeidatabase_p.h"
#include "akabeipackage_p.h"
#include <sqlite3.h>
namespace Akabei {
Database::Database()
DatabasePrivate::DatabasePrivate(Database *db, const QString &pathToDatabase)
: q_ptr(db)
, pathToDb(pathToDatabase)
, dbHandle(0)
{
// Try opening the db read only
int result = sqlite3_open_v2(pathToDb.toUtf8().data(), &dbHandle, SQLITE_OPEN_READONLY, NULL);
switch (result) {
case SQLITE_OK:
// Everything went fine and the handle is ready
break;
default:
// Errors. Set the handle to 0
dbHandle = 0;
break;
}
}
DatabasePrivate::~DatabasePrivate()
{
sqlite3_close(dbHandle);
}
Package *DatabasePrivate::packageFromRow(sqlite3_stmt *statement)
{
Q_Q(Database);
// We suppose the statement is actually valid. So let's create our package.
Package *package = new Package(q, sqlite3_column_int(statement, Tables::Packages::ID),
(const char*)sqlite3_column_text(statement, Tables::Packages::NAME));
package->d_func()->arch = (const char*)sqlite3_column_text(statement, Tables::Packages::ARCH);
package->d_func()->buildDate = QDateTime::fromTime_t(sqlite3_column_int(statement, Tables::Packages::BUILDDATE));
package->d_func()->desc = (const char*)sqlite3_column_text(statement, Tables::Packages::DESCRIPTION);
package->d_func()->files = QString((const char*)sqlite3_column_text(statement, Tables::Packages::FILES)).split(';');
package->d_func()->hasScriptlet = sqlite3_column_int(statement, Tables::Packages::HASSCRIPTLET) > 0 ? true : false;
package->d_func()->hooks = QString((const char*)sqlite3_column_text(statement, Tables::Packages::HOOKS)).split(';');
package->d_func()->md5sum = (const char*)sqlite3_column_text(statement, Tables::Packages::MD5SUM);
package->d_func()->mimetypes = QString((const char*)sqlite3_column_text(statement, Tables::Packages::PROVIDESMIMETYPE)).split(';');
package->d_func()->packager = (const char*)sqlite3_column_text(statement, Tables::Packages::PACKAGER);
package->d_func()->providers = QString((const char*)sqlite3_column_text(statement, Tables::Packages::PROVIDES)).split(';');;
package->d_func()->size = sqlite3_column_int64(statement, Tables::Packages::SIZE);
package->d_func()->url = (const char*)sqlite3_column_text(statement, Tables::Packages::URL);
package->d_func()->version = (const char*)sqlite3_column_text(statement, Tables::Packages::VERSION);
// Add the package to the cache
cache[sqlite3_column_int(statement, Tables::Packages::ID)] = package;
}
Database::Database(const QString &pathToDatabase)
: d_ptr(new DatabasePrivate(this, pathToDatabase))
{
}
Database::~Database()
{
delete d_ptr;
}
bool Database::isValid() const
{
Q_D(const Database);
return d->dbHandle != 0;
}
QList<Package*> Database::packages()
{
Q_D(Database);
QString query = "SELECT * FROM packages";
sqlite3_stmt *statement = 0;
const char *unused = 0;
int result = sqlite3_prepare_v2(d->dbHandle, query.toUtf8().data(), query.length() + 1, &statement, &unused);
switch (result) {
case SQLITE_OK:
// Everything went fine and the handle is ready
break;
default:
// Errors. Take action here
break;
}
while (sqlite3_step(statement) == SQLITE_ROW) {
d->packageFromRow(statement);
}
return d->cache.values();
}
}
......@@ -11,6 +11,8 @@
#ifndef AKABEIDATABASE_H
#define AKABEIDATABASE_H
#include "akabeicore_global.h"
#include <QtCore/QObject>
namespace Akabei {
......@@ -18,7 +20,7 @@ namespace Akabei {
class Package;
class DatabasePrivate;
class Database
class AKABEICORESHARED_EXPORT Database
{
Q_DISABLE_COPY(Database)
Q_DECLARE_PRIVATE(Database)
......@@ -27,11 +29,11 @@ public:
bool isValid() const;
QString name() const;
QList<Package*> packages() const;
QList<Package*> packages();
QList<Package*> search(const QString &exp) const;
private:
DatabasePrivate * const d;
DatabasePrivate * const d_ptr;
Database(const QString &pathToDatabase);
......
/* This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEIDATABASE_P_H
#define AKABEIDATABASE_P_H
#include "akabeidatabase.h"
#include <QtCore/QHash>
#include <sqlite3.h>
namespace Akabei {
class Package;
class DatabasePrivate
{
Q_DECLARE_PUBLIC(Database)
Database * const q_ptr;
public:
explicit DatabasePrivate(Database *db, const QString &pathToDatabase);
virtual ~DatabasePrivate();
Package *packageFromRow(sqlite3_stmt *statement);
QString pathToDb;
sqlite3 *dbHandle;
QHash<int, Package*> cache;
};
}
#endif // AKABEIDATABASE_P_H
......@@ -29,10 +29,112 @@ Operation::~Operation()
delete d_ptr;
}
QUuid Operation::uuid() const
{
Q_D(const Operation);
return d->uuid;
}
QString Operation::targetName() const
{
Q_D(const Operation);
return d->targetName;
}
QStringList Operation::conflictingTargets() const
{
Q_D(const Operation);
return d->conflictingTargets;
}
Operation::Phase Operation::phase() const
{
Q_D(const Operation);
return d->phase;
}
int Operation::priority() const
{
Q_D(const Operation);
return d->priority;
}
Operation::Status Operation::status() const
{
Q_D(const Operation);
return d->status;
}
QStringList Operation::fileSystemAdditions() const
{
Q_D(const Operation);
return d->fileSystemAdditions;
}
QStringList Operation::fileSystemRemovals() const
{
Q_D(const Operation);
return d->fileSystemRemovals;
}
bool Operation::canBeConcurrent() const
{
Q_D(Operation);
Q_D(const Operation);
return d->canBeConcurrent;
}
Operation::List Operation::subOperations() const
{
Q_D(const Operation);
return d->children;
}
void Operation::setCanBeConcurrent(bool concurrent)
{
Q_D(Operation);
d->canBeConcurrent = concurrent;
}
void Operation::setPhase(Phase phase)
{
Q_D(Operation);
d->phase = phase;
}
void Operation::setPriority(int priority)
{
Q_D(Operation);
d->priority = priority;
}
void Operation::setFileSystemAdditions(const QStringList &targets)
{
Q_D(Operation);
d->fileSystemAdditions = targets;
}
void Operation::setFileSystemRemovals(const QStringList &targets)
{
Q_D(Operation);
d->fileSystemRemovals = targets;
}
void Operation::setConflictingTargets(const QStringList &targets)
{
Q_D(Operation);
d->conflictingTargets = targets;
}
void Operation::setError(Error *error)
{
Q_D(Operation);
d->error = error;
}
void Operation::setSubOperations(const List &operations)
{
Q_D(Operation);
d->children = operations;
}
}
......@@ -13,16 +13,20 @@
#include <QtCore/QObject>
#include <QtCore/QUuid>
#include <QtCore/QStringList>
namespace Akabei {
class Error;
class OperationPrivate;
class Operation : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(Operation)
Q_DECLARE_PRIVATE(Operation)
public:
typedef QList<Operation*> List;
enum Phase {
NoPhase = 0,
Phase1 = 1, /// Early preparation - download, stuff
......@@ -33,13 +37,13 @@ public:
};
enum Status {
Idle = 0, /// Ready to be validated
Validating = 1, /// The operation is being validated
Ready = 2, /// The operation is ready to be run
NotReady = 3, /// Validation failed, the operation is not ready
Running = 4, /// The operation is running
Performed = 5, /// The operation has been performed
Error = 6 /// There was an error while performing the operation
StatusIdle = 0, /// Ready to be validated
StatusValidating = 1, /// The operation is being validated
StatusReady = 2, /// The operation is ready to be run
StatusNotReady = 3, /// Validation failed, the operation is not ready
StatusRunning = 4, /// The operation is running
StatusPerformed = 5, /// The operation has been performed
StatusError = 6 /// There was an error while performing the operation
};
virtual ~Operation();
......@@ -56,13 +60,15 @@ public:
Status status() const;
QStringList fileSystemAdditions() const;
QStringList fileSystemRemoval() const;
QStringList fileSystemRemovals() const;
List subOperations() const;
protected:
explicit Operation(const QString &targetName, QObject *parent = 0);
void validate() = 0;
void run() = 0;
virtual void validate() = 0;
virtual void run() = 0;
void setCanBeConcurrent(bool concurrent);
......@@ -76,13 +82,15 @@ protected:
void setError(Error *error);
void setSubOperations(const List &operations);
signals:
void statusChanged(Akabei::Operation::Status current, Akabei::Operation::Status previous);
void progress(int percentage);
void errorOccurred(Akabei::Error *error);
private:
OperationPrivate * const d;
OperationPrivate * const d_ptr;
friend class OperationRunner;
};
......
......@@ -30,6 +30,7 @@ public:
QStringList fileSystemRemovals;
Operation::Status status;
Error *error;
Operation::List children;
};
}
......
......@@ -8,9 +8,20 @@
version 2 of the License, or (at your option) any later version.
*/
#include "akabeioperationrunner.h"
#include "akabeioperationrunner_p.h"
OperationRunner::OperationRunner(QObject *parent) :
QObject(parent)
namespace Akabei
{
OperationRunner::OperationRunner(QObject *parent)
: QObject(parent)
, d_ptr(new OperationRunnerPrivate)
{
}
OperationRunner::~OperationRunner()
{
delete d_ptr;
}
}
......@@ -51,7 +51,7 @@ public slots:
private:
explicit OperationRunner(QObject *parent = 0);
OperationRunnerPrivate * const d;
OperationRunnerPrivate * const d_ptr;
};
......
/* This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEIOPERATIONRUNNER_P_H
#define AKABEIOPERATIONRUNNER_P_H
#include "akabeioperationrunner.h"
namespace Akabei
{
class OperationRunnerPrivate
{
public:
OperationRunnerPrivate() {}
~OperationRunnerPrivate() {}
};
}
#endif // AKABEIOPERATIONRUNNER_P_H
......@@ -8,11 +8,12 @@
version 2 of the License, or (at your option) any later version.
*/
#include "akabeipackage.h"
#include "akabeipackage_p.h"
namespace Akabei {
Package::Package()
Package::Package(Database *db, int databaseId, const QString &name)
: d_ptr(new PackagePrivate(db, databaseId, name))
{
}
......
......@@ -11,6 +11,8 @@
#ifndef AKABEIPACKAGE_H
#define AKABEIPACKAGE_H
#include "akabeicore_global.h"
#include <QtCore/QObject>
#include <QtCore/QDateTime>
......@@ -20,7 +22,7 @@ class Group;
class Database;
class PackagePrivate;
class Package
class AKABEICORESHARED_EXPORT Package
{
Q_DISABLE_COPY(Package)
Q_DECLARE_PRIVATE(Package)
......@@ -31,8 +33,16 @@ public:
// More flags here.
};
enum InstallReason {
NoReason = 0,
ExplicitlyInstalledReason = 1,
InstalledAsDependencyReason = 2
};
virtual ~Package();
int databaseId() const;
typedef QList<Package*> List;
QString name() const;
QString filename() const;
......@@ -46,6 +56,7 @@ public:
QDateTime buildDate() const;
qint32 size() const;
QStringList files() const;
QStringList hooks() const;
List computeDependsOn();
List computeRequiredBy();
......@@ -59,11 +70,16 @@ public:
QStringList mimetypes() const;
QString pathToArchive() const;
void setPathToArchive(const QString &path);
private:
PackagePrivate * const d;
PackagePrivate * const d_ptr;
Package(Database *db, int databaseId, const QString &name);
Package();
friend class Database;
friend class DatabasePrivate;
};
}
......
/* This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEIPACKAGE_P_H
#define AKABEIPACKAGE_P_H
#include "akabeipackage.h"
#include <QtCore/QStringList>
namespace Akabei {
class PackagePrivate
{
public:
PackagePrivate(Database *db, int id, const QString& n) : database(db), databaseId(id), name(n) {}
virtual ~PackagePrivate() {}
Database *database;
int databaseId;
QString name;
QString filename;
QString version;
QString desc;
QString url;
QString packager;
QString md5sum;
QString arch;
bool hasScriptlet;
QDateTime buildDate;
qint32 size;
QStringList files;
QStringList providers;
QStringList mimetypes;
QStringList hooks;
QString archive;
};
}
#endif // AKABEIPACKAGE_P_H
......@@ -18,4 +18,7 @@ HEADERS += akabeibackend.h \
akabeioperation.h \
akabeioperationrunner.h \
operations/akabeiplaininstalloperation.h \
akabeioperation_p.h
akabeioperation_p.h \
akabeidatabase_p.h \
akabeipackage_p.h \
akabeioperationrunner_p.h
......@@ -10,10 +10,13 @@
#include "akabeiplaininstalloperation.h"
#include "akabeipackage.h"
namespace Akabei {
PlainInstallOperation::PlainInstallOperation(QObject *parent) :
Operation(parent)
PlainInstallOperation::PlainInstallOperation(Package *package, QObject *parent)
: Operation(package->name(), parent)
, d(0)
{
}
......
......@@ -17,12 +17,10 @@ namespace Akabei {
class Package;
class PlainInstallOperationPrivate;
class PlainInstallOperation : public Operation
{
Q_OBJECT
Q_DISABLE_COPY(PlainInstallOperation)
Q_DECLARE_PRIVATE(PlainInstallOperation)
public:
explicit PlainInstallOperation(Package *package, QObject *parent = 0);
......@@ -35,7 +33,8 @@ signals:
public slots:
private:
PlainInstallOperationPrivate * const d;
class Private;
Private * const d;
};
......
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