Commit 7706e56a authored by Lukas Appelhans's avatar Lukas Appelhans

More fixes

parent 1f441d9b
......@@ -63,6 +63,7 @@ akabeicache.h
akabeicore_global.h
SQLiteConnection.h
PolKitSQLiteConnection.h
SQLInterface.h
md5.h
)
......
......@@ -10,6 +10,7 @@
#ifndef SQLINTERFACE_H
#define SQLINTERFACE_H
#include <akabeicore_global.h>
#include <QVariantMap>
#include <QSharedDataPointer>
......@@ -21,7 +22,7 @@ typedef QVariantMap Row;
* @class SQLResource
* @brief Used by SQLInterface to store the result of a query
*/
class SQLResource
class AKABEICORESHARED_EXPORT SQLResource
{
typedef QVariant Value;
public:
......
......@@ -124,9 +124,14 @@ void PolkitInstallOperation::Private::__k__installFinished(const QString &archiv
}
delete iface;
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlie", QDBusConnection::systemBus());
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusMessage reply = iface->call("movePackage", package->databaseId(), package->database()->name(), (int)reason);
QDBusMessage reply;
if (package->databaseId()) {
reply = iface->call("movePackage", package->databaseId(), package->database()->name(), (int)reason);
} else {
reply = iface->call("movePackage", package->pathToArchive(), package->databaseId(), (int)reason);
}
if (reply.arguments().isEmpty()) {
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("DBus did not return yet!"), q));
q->setFinished(false);
......
......@@ -159,9 +159,14 @@ void PolkitReInstallOperation::Private::__k__polkitFinished(const QString &archi
reason = Package::InstalledAsDependencyReason;
}
iface->deleteLater();
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlie", QDBusConnection::systemBus());
QDBusMessage reply = iface->call("updatePackage", package->databaseId(), package->database()->name(), package->databaseId(), (int)reason);
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusMessage reply;
if (package->databaseId() != -1) {
reply = iface->call("updatePackage", package->databaseId(), package->database()->name(), package->databaseId(), (int)reason);
} else {
reply = iface->call("updatePackage", package->pathToArchive(), package->databaseId(), (int)reason);
}
if (reply.arguments().isEmpty()) {
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("DBus did not return yet!"), q));
q->setFinished(false);
......
......@@ -101,7 +101,7 @@ void PolkitRemoveOperation::Private::__k__removalErrors(const QStringList& error
void PolkitRemoveOperation::Private::__k__removalFinished()
{
delete iface;
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlie", QDBusConnection::systemBus());
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusMessage reply = iface->call("removePackage", package->databaseId());
if (reply.arguments().isEmpty()) {
......
......@@ -168,9 +168,14 @@ void PolkitUpgradeOperation::Private::__k__polkitFinished(const QString &archive
reason = Package::ExplicitlyInstalledReason;
}
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlie", QDBusConnection::systemBus());
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/sqlite", "org.chakraproject.akabeicorehelper.sqlite", QDBusConnection::systemBus());
QDBusMessage reply = iface->call("updatePackage", from->databaseId(), from->database()->name(), to->databaseId(), (int)reason);
QDBusMessage reply;
if (to->databaseId() != -1) {
reply = iface->call("updatePackage", to->databaseId(), to->database()->name(), from->databaseId(), (int)reason);
} else {
reply = iface->call("updatePackage", to->pathToArchive(), from->databaseId(), (int)reason);
}
if (reply.arguments().isEmpty()) {
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("DBus did not return yet!"), q));
q->setFinished(false);
......
......@@ -20,6 +20,7 @@
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDateTime>
#include <akabeibackend.h>
#include <PolkitQt1/Authority>
......@@ -133,6 +134,12 @@ qint64 SQLiteHelper::lastRowId()
return -1;
}
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::movePackage(const QString &pathToArchive, int installReason)
{
Akabei::Package * p = Akabei::Backend::instance()->loadPackageFromFile(pathToArchive);//TODO: Use the new package loader class
return movePackage(p, installReason);
}
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::movePackage(int packageId, const QString &fromDatabase, int installReason)
{
if (m_connections[fromDatabase] == 0) {
......@@ -146,6 +153,11 @@ SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::movePackage(int packageId, con
if (package->databaseId() != packageId)
return SQL_ERROR_PACKAGE_NOT_FOUND;
return movePackage(package, installReason);
}
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::movePackage(Akabei::Package * package, int installReason)
{
// Create a new package.
Akabei::Package *p = package->generateInstalledPackage((Akabei::Package::InstallReason)installReason, QDateTime::currentDateTime());
......@@ -201,22 +213,12 @@ SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::movePackage(int packageId, con
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::updatePackage(const QString &pathToArchive, int updatePackageId, int installReason)
{
//TODO:
Akabei::Package * p = Akabei::Backend::instance()->loadPackageFromFile(pathToArchive);//TODO: Use the new package loader class
return updatePackage(p, updatePackageId, installReason);
}
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::updatePackage(int withPackageId, const QString &fromDatabase, int updatePackageId, int installReason)
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::updatePackage(Akabei::Package * package, int updatePackageId, int installReason)
{
if (m_connections[fromDatabase] == 0) {
m_connections[fromDatabase] = new Akabei::Database(fromDatabase);
}
Akabei::Database * database = m_connections[fromDatabase];
Akabei::Package::List packages = database->queryPackages(Akabei::Queries::selectPackages("Id", "=", QString::number(withPackageId)));
if (packages.isEmpty())
return SQL_ERROR_PACKAGE_NOT_FOUND;
Akabei::Package * package = packages.first();
if (package->databaseId() != withPackageId)
return SQL_ERROR_PACKAGE_NOT_FOUND;
// Create a new package.
Akabei::Package *p = package->generateInstalledPackage((Akabei::Package::InstallReason)installReason, QDateTime::currentDateTime());
......@@ -294,6 +296,22 @@ SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::updatePackage(int withPackageI
return SQL_OK;
}
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::updatePackage(int withPackageId, const QString &fromDatabase, int updatePackageId, int installReason)
{
qDebug() << "Called with" << withPackageId << fromDatabase << updatePackageId << installReason;
if (m_connections[fromDatabase] == 0) {
m_connections[fromDatabase] = new Akabei::Database(fromDatabase);
}
Akabei::Database * database = m_connections[fromDatabase];
Akabei::Package::List packages = database->queryPackages(Akabei::Queries::selectPackages("Id", "=", QString::number(withPackageId)));
if (packages.isEmpty())
return SQL_ERROR_PACKAGE_NOT_FOUND;
Akabei::Package * package = packages.first();
if (package->databaseId() != withPackageId)
return SQL_ERROR_PACKAGE_NOT_FOUND;
return updatePackage(package, updatePackageId, installReason);
}
SQLiteHelper::SQLiteHelperErrorCode SQLiteHelper::removePackage(int packageId)
{
// Now, db handling. Let's start
......
......@@ -59,12 +59,14 @@ public slots:
qint64 lastRowId();
//FIXME: What happens with local packages without database? There will still need to do the old way of doing things
SQLiteHelperErrorCode movePackage(int packageId, const QString &fromDatabase, int installReason);
SQLiteHelperErrorCode movePackage(const QString &pathToArchive);
SQLiteHelperErrorCode movePackage(const QString &pathToArchive, int installReason);
SQLiteHelperErrorCode updatePackage(int withPackageId, const QString &fromDatabase, int updatePackageId, int installReason);
SQLiteHelperErrorCode updatePackage(const QString &pathToArchive, int updatePackageId, int installReason);
SQLiteHelperErrorCode removePackage(int packageId);
private:
SQLiteHelperErrorCode movePackage(Akabei::Package * package, int installReason);
SQLiteHelperErrorCode updatePackage(Akabei::Package * package, int updatePackageId, int installReason);
QString m_filename;
SQLiteConnection m_localConnection;
QMap<QString, Akabei::Database*> m_connections;//FIXME: We can optimize this by forcing Akabei::Database to use SQLiteConnection here
......
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