Commit 11d5643e authored by Lukas Appelhans's avatar Lukas Appelhans

Starting to get the installed together now... pretty spaghetti... but what can you do bout this?

parent c50ca042
......@@ -21,6 +21,10 @@
#include <akabeigroup.h>
#include <kdebug.h>
#include <QCoreApplication>
#include <akabeiclientqueue.h>
#include <akabeiclienttransactionhandler.h>
#include <iostream>
#include <kio/global.h>
SyncOperation::SyncOperation(QObject* parent)
: QObject(parent),
......@@ -68,7 +72,94 @@ void SyncOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Oper
}
currentDatabasePos = 0;
updateNextDatabase();
} else {
QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkg, args) {
query = query + " Name LIKE \"" + pkg + "\"";
if (args.last() != pkg)
query = query + " OR";
}
connect(Akabei::Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)), SLOT(install(QUuid,QList<Akabei::Package*>)));
Akabei::Backend::instance()->queryPackages(query);
}
}
void SyncOperation::install(QUuid , QList< Akabei::Package* > packages)
{
QTextStream out(stdout);
QList<Akabei::Package*> toBeInstalled;
QMap<QString, Akabei::Package*> local;
foreach (Akabei::Package * pkg, packages) {
if (pkg->database() == Akabei::Backend::instance()->localDatabase())
local[pkg->name()] = pkg;
}
foreach (Akabei::Package * pkg, packages) {
if (pkg->database() != Akabei::Backend::instance()->localDatabase()) {
if (local[pkg->name()])
toBeInstalled << local[pkg->name()];
else
toBeInstalled << pkg;
}
}
if (!toBeInstalled.count())
return;
if (local.count() >= 1) {
if (local.count() > 1) {
out << "The following packages were already installed on your system:";
foreach (Akabei::Package* pkg, local.values()) {
out << " " << pkg->name() << " (" << pkg->version().toByteArray().data() << ")";
if (pkg != local.values().last())
out << ",";
}
out << "." << endl;
out << "Do you want to reinstall them?[y/n]";
} else {
out << "The package " << local.values().first()->name() << " (" << local.values().first()->version().toByteArray().data() << ") is already installed." << endl;
out << "Do you want to reinstall it?[y/n]";
}
out.flush();
std::string input;
getline(std::cin, input);
out << QLatin1String(input.c_str()) << endl;
if (input != "y")
return;
}
kDebug() << "Let's do this";
foreach (Akabei::Package * pkg, toBeInstalled) {
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, AkabeiClient::Install);
}
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
AkabeiClient::Backend::instance()->transactionHandler()->validate();
}
void SyncOperation::validationFinished(bool valid)
{
int downloadSize = 0;
int installSize = 0;
QTextStream out(stdout);
out << "Packages: ";
foreach (AkabeiClient::QueueItem * item, AkabeiClient::Backend::instance()->queue()->items()) {
if (item != AkabeiClient::Backend::instance()->queue()->items().first())
out << ", ";
out << item->package()->name();
if (item->package()->database() != Akabei::Backend::instance()->localDatabase())
downloadSize += item->package()->size();
installSize += item->package()->installedSize();
if (item->action() == AkabeiClient::Install) {
foreach (Akabei::Package * dep, item->dependencyTree()) {
out << ", " << dep->name();
if (dep->database() != Akabei::Backend::instance()->localDatabase())
downloadSize += dep->size();
installSize += dep->installedSize();
}
}
}
out << endl << endl;
out << "Download size: " << KIO::convertSize(downloadSize) << endl;
out << "Installed size: " << KIO::convertSize(installSize) << endl;
out.flush();
}
void SyncOperation::searchResult(QUuid , QList< Akabei::Package* > packages)
......
......@@ -33,6 +33,8 @@ private slots:
void databaseStatusChanged(AkabeiClient::DatabaseHandler::Status);
void databaseProgressChanged(int);
void databaseErrorTriggered(int);
void install(QUuid,QList<Akabei::Package*>);
void validationFinished(bool valid);
private:
int currentDatabasePos;
......
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