Commit a6c59991 authored by Dario Freddi's avatar Dario Freddi
Browse files

Set library version, remove QObject dependencies and retrieve text correctly from the DB


Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent 68f5dda0
......@@ -14,6 +14,9 @@
#include <sqlite3.h>
#define QSTRING_FROM_DB( a, b ) QString::fromUtf16(static_cast<const ushort *>(sqlite3_column_text16(a, b)), \
sqlite3_column_bytes16(a, b) / sizeof(ushort))
namespace Akabei {
DatabasePrivate::DatabasePrivate(Database *db, const QString &pathToDatabase)
......@@ -39,28 +42,29 @@ DatabasePrivate::~DatabasePrivate()
sqlite3_close(dbHandle);
}
Package *DatabasePrivate::packageFromRow(sqlite3_stmt *statement)
Package *DatabasePrivate::packageFromRow(sqlite3_stmt *stmt)
{
Q_Q(Database);
using namespace Tables::Packages;
// 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);
Package *package = new Package(q, sqlite3_column_int(stmt, ID), QSTRING_FROM_DB(stmt, NAME));
package->d_func()->arch = QSTRING_FROM_DB(stmt, ARCH);
package->d_func()->buildDate = QDateTime::fromTime_t(sqlite3_column_int(stmt, Tables::Packages::BUILDDATE));
package->d_func()->desc = QSTRING_FROM_DB(stmt, DESCRIPTION);
package->d_func()->files = QString(QSTRING_FROM_DB(stmt, FILES)).split(';');
package->d_func()->hasScriptlet = sqlite3_column_int(stmt, Tables::Packages::HASSCRIPTLET) > 0 ? true : false;
package->d_func()->hooks = QSTRING_FROM_DB(stmt, HOOKS).split(';');
package->d_func()->md5sum = QSTRING_FROM_DB(stmt, MD5SUM);
package->d_func()->mimetypes = QSTRING_FROM_DB(stmt, PROVIDESMIMETYPE).split(';');
package->d_func()->packager = QSTRING_FROM_DB(stmt, PACKAGER);
package->d_func()->providers = QSTRING_FROM_DB(stmt, PROVIDES).split(';');;
package->d_func()->size = sqlite3_column_int64(stmt, Tables::Packages::SIZE);
package->d_func()->url = QSTRING_FROM_DB(stmt, URL);
package->d_func()->version = QSTRING_FROM_DB(stmt, VERSION);
// Add the package to the cache
cache[sqlite3_column_int(statement, Tables::Packages::ID)] = package;
cache[sqlite3_column_int(stmt, ID)] = package;
}
Database::Database(const QString &pathToDatabase)
......
......@@ -18,9 +18,8 @@ OperationPrivate::OperationPrivate(const QString &tN)
{
}
Operation::Operation(const QString &targetName, QObject *parent)
: QObject(parent)
, d_ptr(new OperationPrivate(targetName))
Operation::Operation(const QString &targetName)
: d_ptr(new OperationPrivate(targetName))
{
}
......
......@@ -19,9 +19,8 @@ namespace Akabei {
class Error;
class OperationPrivate;
class Operation : public QObject
class Operation
{
Q_OBJECT
Q_DISABLE_COPY(Operation)
Q_DECLARE_PRIVATE(Operation)
public:
......@@ -65,7 +64,7 @@ public:
List subOperations() const;
protected:
explicit Operation(const QString &targetName, QObject *parent = 0);
explicit Operation(const QString &targetName);
virtual void validate() = 0;
virtual void run() = 0;
......@@ -84,10 +83,7 @@ protected:
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);
void setProgress(int percentage);
private:
OperationPrivate * const d_ptr;
......
......@@ -37,15 +37,18 @@ public:
void start();
void cancel();
signals:
Q_SIGNALS:
void phaseValidationStarted(Operation::Phase phase);
void phaseValidationFinished(Operation::Phase phase);
void phaseStarted(Operation::Phase phase);
void phaseFinished(Operation::Phase phase);
void operationStarted(Operation *operation);
void operationProgress(int percentage, Operation *operation);
void operationFinished(Operation *operation);
void operationStarted(Akabei::Operation *operation);
void operationStatusChanged(Akabei::Operation *operation, Akabei::Operation::Status current, Akabei::Operation::Status previous);
void operationProgress(Akabei::Operation *operation, int percentage);
void operationFinished(Akabei::Operation *operation);
void errorOccurred(Akabei::Error *error);
void finished(bool result);
......
......@@ -5,6 +5,7 @@ QT -= gui
TARGET = akabeicore
TEMPLATE = lib
DEFINES += AKABEICORE_LIBRARY
VERSION = 0.0.1
SOURCES += akabeibackend.cpp \
akabeidatabase.cpp \
akabeipackage.cpp \
......
......@@ -14,8 +14,8 @@
namespace Akabei {
PlainInstallOperation::PlainInstallOperation(Package *package, QObject *parent)
: Operation(package->name(), parent)
PlainInstallOperation::PlainInstallOperation(Package *package)
: Operation(package->name())
, d(0)
{
}
......
......@@ -19,10 +19,9 @@ class Package;
class PlainInstallOperation : public Operation
{
Q_OBJECT
Q_DISABLE_COPY(PlainInstallOperation)
public:
explicit PlainInstallOperation(Package *package, QObject *parent = 0);
explicit PlainInstallOperation(Package *package);
protected:
void validate();
......
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