Commit 04dac810 authored by Lisa's avatar Lisa

Other options added in syncoperation

parent 1f162125
......@@ -102,6 +102,21 @@ void SyncOperation::start()
}
}
bool SyncOperation::isIgnored(Akabei::Package *pkg)
{
if (m_options[APM::Ignore].contains(pkg->name())) {
return true;
}
foreach (Akabei::Group *g, pkg->groups()) {
if (m_options[APM::IgnoreGroup].contains(g->name())) {
return true;
}
}
return false;
}
void SyncOperation::updateDatabases()
{
QTextStream out(stdout);
......@@ -119,7 +134,9 @@ void SyncOperation::updateSystem()
{
QStringList locals;
foreach (Akabei::Package *p, Akabei::Backend::instance()->localDatabase()->packages()) {
locals << p->name();
if (!isIgnored(p)) {
locals << p->name();
}
}
connect(Akabei::Backend::instance(), SIGNAL(queryPackagesCompleted(QUuid,QList<Akabei::Package*>)), SLOT(upgrade(QUuid,QList<Akabei::Package*>)));
......@@ -181,112 +198,6 @@ void SyncOperation::install(QUuid uuid, QList< Akabei::Package* > packages)
return;
}
/*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!
QTextStream out(stdout);
QTextStream err(stderr);
QMap<QString, Akabei::Package*> toBeInstalled;
QMap<QString, Akabei::Package*> toBeUpgraded;
QMap<QString, Akabei::Package*> toBeReinstalled;
QMap<QString, Akabei::Package*> local;
foreach (Akabei::Package * pkg, packages) {
qDebug() << "Found" << pkg->name();
if (pkg->database() == Akabei::Backend::instance()->localDatabase()) {
qDebug() << "Local";
local[pkg->name()] = pkg;
// packages.removeAll(pkg);
}
}
if (packages.isEmpty()) {
err << i18n("No appropriate packages found") << endl;
err.flush();
nextOperation();
return;
}
foreach (Akabei::Package * pkg, packages) {
if (toBeInstalled.contains(pkg->name()) && toBeInstalled[pkg->name()]->version() < pkg->version()) {
toBeInstalled[pkg->name()] = pkg;
} else if (toBeUpgraded.contains(pkg->name()) && toBeUpgraded[pkg->name()]->version() < pkg->version()) {
toBeUpgraded[pkg->name()] = pkg;
} else if (toBeReinstalled.contains(pkg->name()) && toBeReinstalled[pkg->name()]->version() < pkg->version()) {
toBeReinstalled.remove(pkg->name());
toBeUpgraded[pkg->name()] = pkg;
} 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.isEmpty() && toBeUpgraded.isEmpty() && toBeReinstalled.isEmpty()) {
out << i18n("No appropriate packages found") << endl;
out.flush();
nextOperation();
return;
}
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();
std::string input;
getline(std::cin, input);
if (!input.empty() && input != i18n("y").toStdString()) {
nextOperation();
return;
}
}*/
QueueOperation *op = new QueueOperation(APM::Install, m_options, this);
op->start(AkabeiClient::Install, packages);
connect(op, SIGNAL(finished()), SLOT(nextOperation()));
......@@ -321,8 +232,10 @@ void SyncOperation::searchResult(QUuid , QList< Akabei::Package* > packages)
if (installed)
out << ' ' << i18n("[Installed]");
out << endl;
out << " " << p->description() << endl;
if (!m_options.contains(APM::ShowLess)) {
out << endl;
out << " " << p->description() << endl;
}
}
out.flush();
......@@ -345,6 +258,10 @@ void SyncOperation::listRepo(const QString &repo)
QTextStream out(stdout);
foreach (Akabei::Package * pkg, db->database()->packages()) {
if (isIgnored(pkg)) {
continue;
}
Akabei::Package::List installed = Akabei::Backend::instance()->localDatabase()->queryPackages("SELECT * FROM packages WHERE Name LIKE \"" + pkg->name() + "\"");
out << db->name() << ' ' << pkg->name() << ' ' << pkg->version().toByteArray().data();
if (!installed.isEmpty()) {
......
......@@ -21,7 +21,7 @@ class SyncOperation : public QObject
{
Q_OBJECT
public:
explicit SyncOperation(QList<APM::OperationName>& operations, QHash<APM::OptionName, QStringList>& options, QStringList& args, QObject* parent = 0);
explicit SyncOperation(QList<APM::OperationName> operations, QHash<APM::OptionName, QStringList> options, QStringList args, QObject* parent = 0);
virtual ~SyncOperation();
void start();
......@@ -37,8 +37,6 @@ private slots:
void install(QUuid,QList<Akabei::Package*>);
void upgrade(QUuid,QList<Akabei::Package*>);
void nextOperation();
private:
int m_currentDatabasePos;
int m_maxDbNameLenght;
......@@ -46,10 +44,13 @@ private:
void updateDatabases();
void updateSystem();
void updateNextDatabase();
void nextOperation();
bool isIgnored(Akabei::Package *);
QList<APM::OperationName>& m_operations;
QHash<APM::OptionName, QStringList>& m_options;
QStringList& m_args;
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, QStringList> m_options;
QStringList m_args;
QUuid queryId;
signals:
......
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