Commit b919153d authored by Lukas Appelhans's avatar Lukas Appelhans

This should give us some more appropriate output

parent cc5b3379
...@@ -150,37 +150,95 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages) ...@@ -150,37 +150,95 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
{ {
if (queryId != uuid) if (queryId != uuid)
return; return;
if (packages.isEmpty()) {
QCoreApplication::instance()->quit();
return;
}
disconnect(Akabei::Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)), this, SLOT(install(QUuid,QList<Akabei::Package*>))); disconnect(Akabei::Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)), this, SLOT(install(QUuid,QList<Akabei::Package*>)));
//FIXME: Cleanup and show all the packages and what is going to be done with them! //FIXME: Cleanup and show all the packages and what is going to be done with them!
QTextStream out(stdout); QTextStream out(stdout);
QMap<QString, Akabei::Package*> toBeInstalled; QMap<QString, Akabei::Package*> toBeInstalled;
QMap<QString, Akabei::Package*> toBeUpgraded;
QMap<QString, Akabei::Package*> toBeReinstalled;
QMap<QString, Akabei::Package*> local; QMap<QString, Akabei::Package*> local;
foreach (Akabei::Package * pkg, packages) { foreach (Akabei::Package * pkg, packages) {
qDebug() << "Queried" << pkg->name(); qDebug() << "Queried" << pkg->name();
if (pkg->database() == Akabei::Backend::instance()->localDatabase()) if (pkg->database() == Akabei::Backend::instance()->localDatabase()) {
qDebug() << "It's a local package";
local[pkg->name()] = pkg; local[pkg->name()] = pkg;
packages.removeAll(pkg);
}
}
if (packages.isEmpty()) {
out << i18n("No appropriate packages found") << endl;
out.flush();
QCoreApplication::instance()->quit();
return;
} }
foreach (Akabei::Package * pkg, packages) { foreach (Akabei::Package * pkg, packages) {
if (pkg->database() != Akabei::Backend::instance()->localDatabase()) { if (toBeInstalled.contains(pkg->name()) && toBeInstalled[pkg->name()]->version() < pkg->version()) {
//if (local[pkg->name()]) toBeInstalled[pkg->name()] = pkg;
// toBeInstalled << local[pkg->name()]; } else if (toBeUpgraded.contains(pkg->name()) && toBeUpgraded[pkg->name()]->version() < pkg->version()) {
//else toBeUpgraded[pkg->name()] = pkg;
if (!toBeInstalled[pkg->name()] || toBeInstalled[pkg->name()]->version() < pkg->version()) { } else if (toBeReinstalled.contains(pkg->name()) && toBeReinstalled[pkg->name()]->version() < pkg->version()) {
toBeInstalled[pkg->name()] = pkg; toBeReinstalled.remove(pkg->name());
if (local.contains(pkg->name()) && (pkg->version() > local[pkg->name()]->version())) { toBeUpgraded[pkg->name()] = pkg;
local.remove(pkg->name()); } else if (local.contains(pkg->name())) {
} if (local[pkg->name()]->version() == pkg->version()) {
toBeReinstalled[pkg->name()] = pkg;
} else if (local[pkg->name()]->version() < pkg->version()) {
toBeUpgraded[pkg->name()] = pkg;
} }
} else {
toBeInstalled[pkg->name()] = pkg;
} }
/* if (!toBeInstalled[pkg->name()] || toBeInstalled[pkg->name()]->version() < pkg->version()) {
toBeInstalled[pkg->name()] = pkg;
if (local.contains(pkg->name()) && (pkg->version() > local[pkg->name()]->version())) {
local.remove(pkg->name());
}
}*/
} }
if (!toBeInstalled.count()) if (toBeInstalled.isEmpty() && toBeUpgraded.isEmpty() && toBeReinstalled.isEmpty()) {
out << i18n("No appropriate packages found") << endl;
out.flush();
QCoreApplication::instance()->quit();
return; return;
if (local.count() >= 1) { }
if (local.count() > 1) { if (!toBeReinstalled.isEmpty() || !toBeUpgraded.isEmpty()) {
Akabei::Package::List pkgs = toBeReinstalled.values();
pkgs << toBeUpgraded.values();
if (pkgs.count() == 1) { //It's only one package
Akabei::Package * pkg = pkgs.first();
out << i18n("The following package was already found on your system: ")
<< pkg->name() << " (" << local[pkg->name()]->version().toByteArray() << ")" << endl;
if (!toBeReinstalled.isEmpty()) {
out << i18n("Do you want to reinstall it?[Y/n]");
} else {
out << i18n("Do you want to upgrade it to version %1?[Y/n]").arg(QString(pkg->version().toByteArray()));
}
} else { //Multiple packages
out << i18n("Some packages were already found on your system.") << endl;
if (!toBeUpgraded.isEmpty()) {
out << i18n("The following packages are going to be upgraded:");
foreach (Akabei::Package * p, toBeUpgraded.values()) {
out << " " << p->name() << " (" << local[p->name()]->version().toByteArray().data() << " -> " << p->version().toByteArray() << ")";
if (p != toBeUpgraded.values().last())
out << ",";
else
out << endl;
}
}
if (!toBeReinstalled.isEmpty()) {
out << i18n("The following packages are going to be reinstalled:");
foreach (Akabei::Package * p, toBeReinstalled.values()) {
out << " " << p->name() << " (" << p->version().toByteArray().data() << ")";
if (p != toBeReinstalled.values().last())
out << ",";
else
out << endl;
}
}
out << i18n("Do you want to continue?[Y/n]");
}
out.flush();
/*if (local.count() > 1) {
out << i18n("The following packages were already installed on your system:"); out << i18n("The following packages were already installed on your system:");
foreach (Akabei::Package* pkg, local.values()) { foreach (Akabei::Package* pkg, local.values()) {
out << " " << pkg->name() << " (" << pkg->version().toByteArray().data() << ")"; out << " " << pkg->name() << " (" << pkg->version().toByteArray().data() << ")";
...@@ -190,10 +248,14 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages) ...@@ -190,10 +248,14 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
out << "." << endl; out << "." << endl;
out << i18n("Do you want to reinstall them?[Y/n]"); out << i18n("Do you want to reinstall them?[Y/n]");
} else { } else {
out << i18n("The package %1 (%2) is already installed.", local.values().first()->name(), local.values().first()->version().toByteArray().data()) << endl; Akabei::Package * pkg = local.values().first();
out << i18n("Do you want to reinstall it?[Y/n]"); out << i18n("The package %1 (%2) is already installed.", pkg->name(), pkg->version().toByteArray().data()) << endl;
if (pkg->version() == toBeInstalled[pkg->name()]->version())
out << i18n("Do you want to reinstall it?[Y/n]");
else
out << i18n("Do you want to upgrade it to %1?[Y/n]").arg(QString(toBeInstalled[pkg->name()]->version().toByteArray()));
} }
out.flush(); out.flush();*/
std::string input; std::string input;
getline(std::cin, input); getline(std::cin, input);
...@@ -204,7 +266,7 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages) ...@@ -204,7 +266,7 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
} }
QueueOperation *op = new QueueOperation(m_operations, m_options, this); QueueOperation *op = new QueueOperation(m_operations, m_options, this);
op->start(AkabeiClient::Install, toBeInstalled.values()); op->start(AkabeiClient::Install, toBeInstalled.values() + toBeUpgraded.values() + toBeReinstalled.values());
connect(op, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit())); connect(op, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
} }
......
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