Commit da744267 authored by Lukas Appelhans's avatar Lukas Appelhans

Okay have a QueueOperation class which handles all those queue operation stuff

parent 18fa8fd9
......@@ -15,7 +15,7 @@ include_directories(${QT_INCLUDES}
${AKABEICLIENT_INCLUDE_DIR}
${AKABEICORE_INCLUDE_DIR})
set(apm_SRCS upgradeoperation.cpp removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp main.cpp)
set(apm_SRCS queueoperation.cpp upgradeoperation.cpp removeoperation.cpp syncoperation.cpp apm.cpp queryoperation.cpp main.cpp)
#qt4_automoc(${guzuta_SRCS})
kde4_add_executable(akabei ${apm_SRCS})
target_link_libraries(akabei ${KDE4_KDEUI_LIBRARY} ${KDE4_KIO_LIBRARY} ${AKABEICLIENT_LIBRARIES})
......
/* This file is part of the Chakra project
Copyright (C) 2011 Lukas Appelhans
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "queueoperation.h"
#include <akabeiclientbackend.h>
#include <akabeiclienttransactionhandler.h>
#include <akabeiclientqueue.h>
#include <QTextStream>
#include <kio/global.h>
#include <akabeiconfig.h>
#include <klocale.h>
#include <QFile>
#include <QDir>
#include <akabeioperationrunner.h>
#include <iostream>
#include <kdebug.h>
QueueOperation::QueueOperation(QList<APM::Operation> operations, QMultiHash< APM::Operation, QString > options, QObject * parent)
: QObject(parent)
{
if (operations.contains(APM::Force))
m_processingOptions |= Akabei::Force;
if (operations.contains(APM::AsDeps))
m_processingOptions |= Akabei::InstallAsDependencies;
if (operations.contains(APM::AsExplicit))
m_processingOptions |= Akabei::InstallAsExplicit;
if (operations.contains(APM::SkipDependencyCheck))
m_processingOptions |= Akabei::SkipDependencies;
if (operations.contains(APM::DownloadOnly))
m_processingOptions |= Akabei::DownloadOnly;
}
QueueOperation::~QueueOperation()
{
}
void QueueOperation::start(AkabeiClient::PackageAction action, QList<Akabei::Package*> packages)
{
m_action = action;
foreach (Akabei::Package * pkg, packages) {
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, action);
}
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(errorsOccurred(QList<Akabei::Error*>&)), SLOT(errors(QList<Akabei::Error*>&)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(newTransactionMessage(QString)), SLOT(transactionMessage(QString)));
AkabeiClient::Backend::instance()->transactionHandler()->validate(m_processingOptions);
}
void QueueOperation::validationFinished(bool valid)
{
QTextStream out(stdout);
if (!valid) {
out << i18n("The transaction could not be validated") << endl;
out.flush();
return;
}
int downloadSize = 0;
int installSize = 0;
out << i18n("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() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(item->package()->filename())))
downloadSize += item->package()->size();
installSize += item->package()->installedSize();
if (item->action() == AkabeiClient::Install && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) { //FIXME: Why this?
foreach (Akabei::Package * dep, item->dependencyTree()) {
out << ", " << dep->name();
if (dep->database() != Akabei::Backend::instance()->localDatabase() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(dep->filename())))
downloadSize += dep->size();
installSize += dep->installedSize();
}
}
}
out << endl << endl;
if (m_action == AkabeiClient::Install) {
out << i18n("Download size: %1", KIO::convertSize(downloadSize)) << endl;
out << i18n("Installed size: %1", KIO::convertSize(installSize)) << endl;
} else {
out << i18n("Size of packages about to be removed: %1", KIO::convertSize(installSize)) << endl;
}
out.flush();
out << i18n("Continue with processing?[Y/n]");
out.flush();
std::string input;
getline(std::cin, input);
if (!input.empty() && input != i18n("y").toStdString()) {
emit finished();
return;
}
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(progressChanged(int)), SLOT(showProgress(int)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(finished()), SLOT(transationFinished()));
AkabeiClient::Backend::instance()->transactionHandler()->process();
}
void QueueOperation::showProgress(int progress)
{
QTextStream out(stdout);
out.reset();
switch (AkabeiClient::Backend::instance()->transactionHandler()->phase()) {
case AkabeiClient::TransactionHandler::Validating:
out << i18n("Validating");
break;
case AkabeiClient::TransactionHandler::RunningPreHooks:
out << i18n("Running PreHooks");
break;
case AkabeiClient::TransactionHandler::Downloading:
out << i18n("Downloading");
break;
case AkabeiClient::TransactionHandler::Processing:
out << i18n("Processing");
break;
case AkabeiClient::TransactionHandler::RunningScriptlets:
out << i18n("Running Scriplets");
break;
case AkabeiClient::TransactionHandler::RunningPostHooks:
out << i18n("Running PostHooks");
break;
case AkabeiClient::TransactionHandler::Cleaning:
out << i18n("Cleaning");
break;
default:
out << i18n("Finished");
break;
};
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
out << "#";
} else {
out << "-";
}
}
out << "] " << progress << "%";//FIXME
if (progress == 100) {
out << endl;
} else {
out << "\r";
}
out.flush();
}
void QueueOperation::transationFinished()
{
QTextStream out(stdout);
if (Akabei::Backend::instance()->operationRunner()->errors().isEmpty()) {
out << i18n("The transaction finished successfully!") << endl;
} else {
out << i18np("There has been an error during the transaction.", "There have been errors during the transaction.", Akabei::Backend::instance()->operationRunner()->errors().count());
}
emit finished();
//QCoreApplication::instance()->quit();
}
void QueueOperation::errors(QList<Akabei::Error*>& errors)
{
kDebug() << "yoyoyo";
QTextStream out(stdout);
out << i18n("Errors occurred: ") << endl;
foreach (Akabei::Error * err, errors) {
out << err->description() << endl;
}
out.flush();
}
void QueueOperation::transactionMessage(const QString& message)
{
QTextStream out(stdout);
out << message << endl;
}
\ No newline at end of file
/* This file is part of the Chakra project
Copyright (C) 2011 Lukas Appelhans
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef QUEUEOPERATION_H
#define QUEUEOPERATION_H
#include <QtCore/QObject>
#include <akabeiclient_global.h>
#include <akabeicore_global.h>
#include "apm.h"
#include <akabeierror.h>
class QueueOperation : public QObject
{
Q_OBJECT
public:
QueueOperation(QList<APM::Operation> operations, QMultiHash< APM::Operation, QString > options, QObject * parent = 0);
virtual ~QueueOperation();
void start(AkabeiClient::PackageAction action, QList<Akabei::Package*> packages);
private slots:
void validationFinished(bool valid);
void showProgress(int);
void errors(QList<Akabei::Error*>& errors);
void transactionMessage(const QString &message);
void transationFinished();
signals:
void finished();
private:
AkabeiClient::PackageAction m_action;
Akabei::ProcessingOptions m_processingOptions;
};
#endif // QUEUEOPERATION_H
......@@ -22,6 +22,7 @@
#include <klocale.h>
#include <iostream>
#include <akabeihelpers.h>
#include "queueoperation.h"
RemoveOperation::RemoveOperation(QObject * parent)
: QObject(parent)
......@@ -44,7 +45,7 @@ void RemoveOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Op
operation = operations.first();
if (operation == APM::Unneeded) { //TODO: Implement those!
} else if (operation == APM::Cascade) {
QString query = "SELECT * FROM packages WHERE";
QString query = "SELECT * FROM packages WHERE";//FIXME: I don't think we need this as this is normal AkabeiClient behavior
foreach (const QString &pkg, args) {
query = query + " Name LIKE \"" + pkg + "\" OR Depends LIKE \"%" + pkg + "%\"";
if (args.last() != pkg)
......@@ -89,124 +90,7 @@ void RemoveOperation::remove(QList<Akabei::Package*> packages)
QCoreApplication::instance()->quit();
return;
}
QTextStream out(stdout);
foreach (Akabei::Package * pkg, packages) {
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, AkabeiClient::Remove);
}
Akabei::ProcessingOptions options;
if (m_operations.contains(APM::SkipDependencyCheck))
options |= Akabei::SkipDependencies;
if (m_operations.contains(APM::RemoveConfig))
options |= Akabei::RemoveConfigs;
if (m_operations.contains(APM::DatabaseOnly))
options |= Akabei::DatabaseOnly;
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(errorsOccurred(QList<Akabei::Error*>&)), SLOT(errors(QList<Akabei::Error*>&)));
AkabeiClient::Backend::instance()->transactionHandler()->validate(options);
}
void RemoveOperation::errors(QList<Akabei::Error*>& errors)
{
QTextStream out(stdout);
out << i18n("Errors occurred: ") << endl;
foreach (Akabei::Error * err, errors) {
out << err->description() << endl;
}
out.flush();
}
void RemoveOperation::validationFinished(bool valid)
{
QTextStream out(stdout);
if (!valid) {
//foreach (Akabei::Operation * op, Akabei::Backend::instance()->operationRunner()->operations()) {
//kDebug() << op->fileSystemRemovals();
//}
out << i18n("Queue not valid") << endl;
out.flush();
return;
}
int removeSize = 0;
out << i18n("Packages: ");
foreach (AkabeiClient::QueueItem * item, AkabeiClient::Backend::instance()->queue()->items()) {
if (item != AkabeiClient::Backend::instance()->queue()->items().first())
out << ", ";
out << item->package()->name();
removeSize += item->package()->installedSize();
if (item->action() == AkabeiClient::Remove && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) { //FIXME: Why this?
foreach (Akabei::Package * dep, item->requiredByTree()) {
out << ", " << dep->name();
removeSize += dep->installedSize();
}
}
}
out << endl << endl;
out << i18n("Size of packages about to be removed: %1", KIO::convertSize(removeSize)) << endl;
out.flush();
out << i18n("Continue with installation?[Y/n]");
out.flush();
std::string input;
getline(std::cin, input);
if (!input.empty() && input != i18n("y").toStdString()) {
QCoreApplication::instance()->quit();
return;
}
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(progressChanged(int)), SLOT(showProgress(int)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(finished()), SLOT(finished()));
AkabeiClient::Backend::instance()->transactionHandler()->process();
}
void RemoveOperation::showProgress(int progress)
{
QTextStream out(stdout);
out.reset();
switch (AkabeiClient::Backend::instance()->transactionHandler()->phase()) {
case AkabeiClient::TransactionHandler::Validating:
out << i18n("Validating");
break;
case AkabeiClient::TransactionHandler::RunningPreHooks:
out << i18n("Running PreHooks");
break;
case AkabeiClient::TransactionHandler::Downloading:
out << i18n("Downloading");
break;
case AkabeiClient::TransactionHandler::Processing:
out << i18n("Processing");
break;
case AkabeiClient::TransactionHandler::RunningScriptlets:
out << i18n("Running Scriplets");
break;
case AkabeiClient::TransactionHandler::RunningPostHooks:
out << i18n("Running PostHooks");
break;
case AkabeiClient::TransactionHandler::Cleaning:
out << i18n("Cleaning");
break;
default:
out << i18n("Finished");
break;
};
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
out << "#";
} else {
out << "-";
}
}
out << "] " << progress << "%";//FIXME
if (progress == 100) {
out << endl;
} else {
out << "\r";
}
out.flush();
}
void RemoveOperation::finished()
{
QTextStream out(stdout);
out << i18n("The transaction finished!") << endl;
QCoreApplication::instance()->quit();
QueueOperation *operation = new QueueOperation(m_operations, m_options, this);
operation->start(AkabeiClient::Remove, packages);
connect(operation, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
}
......@@ -24,12 +24,8 @@ public:
void start(QList<APM::Operation> operations, QMultiHash<APM::Operation, QString> options, QStringList args);
public slots:
void remove(QList<Akabei::Package*>);
void remove(QList<Akabei::Package*> packages);
void removeCascade(const QStringList &args, QList<Akabei::Package*> packages);
void validationFinished(bool valid);
void errors(QList<Akabei::Error*>& errors);
void showProgress(int progress);
void finished();
private:
QList<APM::Operation> m_operations;
......
......@@ -30,6 +30,7 @@
#include <kio/global.h>
#include <akabeioperation.h>
#include <akabeioperationrunner.h>
#include "queueoperation.h"
SyncOperation::SyncOperation(QObject* parent)
: QObject(parent),
......@@ -134,24 +135,9 @@ void SyncOperation::upgrade(QUuid , QList< Akabei::Package* > packages)
}
}
}
foreach (Akabei::Package * pkg, toBeUpgraded) {
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, AkabeiClient::Update);
}
Akabei::ProcessingOptions options;
if (m_operations.contains(APM::Force))
options |= Akabei::Force;
if (m_operations.contains(APM::AsDeps))
options |= Akabei::InstallAsDependencies;
if (m_operations.contains(APM::AsExplicit))
options |= Akabei::InstallAsExplicit;
if (m_operations.contains(APM::SkipDependencyCheck))
options |= Akabei::SkipDependencies;
if (m_operations.contains(APM::DownloadOnly))
options |= Akabei::DownloadOnly;
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(errorsOccurred(QList<Akabei::Error*>&)), SLOT(errors(QList<Akabei::Error*>&)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(newTransactionMessage(QString)), SLOT(transactionMessage(QString)));
AkabeiClient::Backend::instance()->transactionHandler()->validate(options);
QueueOperation *op = new QueueOperation(m_operations, m_options, this);
op->start(AkabeiClient::Update, toBeUpgraded);
connect(op, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
}
void SyncOperation::install(QUuid , QList< Akabei::Package* > packages)
......@@ -198,144 +184,9 @@ void SyncOperation::install(QUuid , QList< Akabei::Package* > packages)
}
}
foreach (Akabei::Package * pkg, toBeInstalled.values()) {
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, AkabeiClient::Install);
}
Akabei::ProcessingOptions options;
if (m_operations.contains(APM::Force))
options |= Akabei::Force;
if (m_operations.contains(APM::AsDeps))
options |= Akabei::InstallAsDependencies;
if (m_operations.contains(APM::AsExplicit))
options |= Akabei::InstallAsExplicit;
if (m_operations.contains(APM::SkipDependencyCheck))
options |= Akabei::SkipDependencies;
if (m_operations.contains(APM::DownloadOnly))
options |= Akabei::DownloadOnly;
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(errorsOccurred(QList<Akabei::Error*>&)), SLOT(errors(QList<Akabei::Error*>&)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(newTransactionMessage(QString)), SLOT(transactionMessage(QString)));
AkabeiClient::Backend::instance()->transactionHandler()->validate(options);
}
void SyncOperation::validationFinished(bool valid)
{
QTextStream out(stdout);
if (!valid) {
out << i18n("The transaction could not be validated") << endl;
out.flush();
return;
}
int downloadSize = 0;
int installSize = 0;
out << i18n("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() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(item->package()->filename())))
downloadSize += item->package()->size();
installSize += item->package()->installedSize();
if (item->action() == AkabeiClient::Install && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) { //FIXME: Why this?
foreach (Akabei::Package * dep, item->dependencyTree()) {
out << ", " << dep->name();
if (dep->database() != Akabei::Backend::instance()->localDatabase() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(dep->filename())))
downloadSize += dep->size();
installSize += dep->installedSize();
}
}
}
out << endl << endl;
out << i18n("Download size: %1", KIO::convertSize(downloadSize)) << endl;
out << i18n("Installed size: %1", KIO::convertSize(installSize)) << endl;
out.flush();
out << i18n("Continue with installation?[Y/n]");
out.flush();
std::string input;
getline(std::cin, input);
if (!input.empty() && input != i18n("y").toStdString()) {
QCoreApplication::instance()->quit();
return;
}
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(progressChanged(int)), SLOT(showProgress(int)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(finished()), SLOT(finished()));
AkabeiClient::Backend::instance()->transactionHandler()->process();
}
void SyncOperation::showProgress(int progress)
{
QTextStream out(stdout);
out.reset();
switch (AkabeiClient::Backend::instance()->transactionHandler()->phase()) {
case AkabeiClient::TransactionHandler::Validating:
out << i18n("Validating");
break;
case AkabeiClient::TransactionHandler::RunningPreHooks:
out << i18n("Running PreHooks");
break;
case AkabeiClient::TransactionHandler::Downloading:
out << i18n("Downloading");
break;
case AkabeiClient::TransactionHandler::Processing:
out << i18n("Processing");
break;
case AkabeiClient::TransactionHandler::RunningScriptlets:
out << i18n("Running Scriplets");
break;
case AkabeiClient::TransactionHandler::RunningPostHooks:
out << i18n("Running PostHooks");
break;
case AkabeiClient::TransactionHandler::Cleaning:
out << i18n("Cleaning");
break;
default:
out << i18n("Finished");
break;
};
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
out << "#";
} else {
out << "-";
}
}
out << "] " << progress << "%";//FIXME
if (progress == 100) {
out << endl;
} else {
out << "\r";
}
out.flush();
}
void SyncOperation::finished()
{
QTextStream out(stdout);
if (Akabei::Backend::instance()->operationRunner()->errors().isEmpty()) {
out << i18n("The transaction finished successfully!") << endl;
} else {
out << i18np("There has been an error during the transaction.", "There have been errors during the transaction.", Akabei::Backend::instance()->operationRunner()->errors().count());
}
QCoreApplication::instance()->quit();
}
void SyncOperation::errors(QList<Akabei::Error*>& errors)
{
kDebug() << "yoyoyo";
QTextStream out(stdout);
out << i18n("Errors occurred: ") << endl;
foreach (Akabei::Error * err, errors) {
out << err->description() << endl;
}
out.flush();
}
void SyncOperation::transactionMessage(const QString& message)
{
QTextStream out(stdout);
out << message << endl;
QueueOperation *op = new QueueOperation(m_operations, m_options, this);
op->start(AkabeiClient::Install, toBeInstalled.values());
connect(op, SIGNAL(finished()), QCoreApplication::instance(), SLOT(quit()));
}
void SyncOperation::searchResult(QUuid , QList< Akabei::Package* > packages)
......
......@@ -35,11 +35,6 @@ private slots:
void databaseProgressChanged(int);
void databaseErrorTriggered(int);
void install(QUuid,QList<Akabei::Package*>);
void validationFinished(bool valid);
void showProgress(int);
void errors(QList<Akabei::Error*>& errors);
void transactionMessage(const QString &message);
void finished();
void upgrade(QUuid,QList<Akabei::Package*>);
private:
......
......@@ -22,6 +22,7 @@
#include <akabeioperationrunner.h>
#include <QCoreApplication>
#include <iostream>
#include "queueoperation.h"
//FIXME: There is actually a bunch of code duplication with SyncOperation and RemoveOperation... maybe we can create something that is used in all of them :)
......@@ -45,143 +46,7 @@ void UpgradeOperation::start(QList< APM::Operation > operations, QMultiHash< APM
foreach (const QString &p, args)
pkgs << Akabei::Backend::instance()->loadPackageFromFile(p);
foreach (Akabei::Package * pkg, pkgs)
AkabeiClient::Backend::instance()->queue()->addPackage(pkg, AkabeiClient::Install);
Akabei::ProcessingOptions processingOpts;
if (operations.contains(APM::Force))
processingOpts |= Akabei::Force;
if (operations.contains(APM::AsDeps))
processingOpts |= Akabei::InstallAsDependencies;
if (operations.contains(APM::AsExplicit))
processingOpts |= Akabei::InstallAsExplicit;
if (operations.contains(APM::SkipDependencyCheck))
processingOpts |= Akabei::SkipDependencies;
if (operations.contains(APM::DownloadOnly))
processingOpts |= Akabei::DownloadOnly;
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(validationFinished(bool)), SLOT(validationFinished(bool)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(errorsOccurred(QList<Akabei::Error*>&)), SLOT(errors(QList<Akabei::Error*>&)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(newTransactionMessage(QString)), SLOT(transactionMessage(QString)));
AkabeiClient::Backend::instance()->transactionHandler()->validate(processingOpts);
}
void UpgradeOperation::validationFinished(bool valid)
{
QTextStream out(stdout);
if (!valid) {
out << i18n("The transaction could not be validated") << endl;
out.flush();
return;
}
int downloadSize = 0;
int installSize = 0;
out << i18n("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() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(item->package()->filename())))
downloadSize += item->package()->size();
installSize += item->package()->installedSize();
if (item->action() == AkabeiClient::Install && !(Akabei::Backend::instance()->operationRunner()->processingOptions() & Akabei::SkipDependencies)) { //FIXME: Why this?
foreach (Akabei::Package * dep, item->dependencyTree()) {
out << ", " << dep->name();
if (dep->database() != Akabei::Backend::instance()->localDatabase() && !QFile::exists(Akabei::Config::instance()->cacheDir().absoluteFilePath(dep->filename())))
downloadSize += dep->size();
installSize += dep->installedSize();
}
}
}
out << endl << endl;
out << i18n("Download size: %1", KIO::convertSize(downloadSize)) << endl;
out << i18n("Installed size: %1", KIO::convertSize(installSize)) << endl;
out.flush();
out << i18n("Continue with installation?[Y/n]");
out.flush();
std::string input;
getline(std::cin, input);
if (!input.empty() && input != i18n("y").toStdString()) {
QCoreApplication::instance()->quit();
return;
}
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(progressChanged(int)), SLOT(showProgress(int)));
connect(AkabeiClient::Backend::instance()->transactionHandler(), SIGNAL(finished()), SLOT(finished()));
AkabeiClient::Backend::instance()->transactionHandler()->process();
}
void UpgradeOperation::showProgress(int progress)
{
QTextStream out(stdout);
out.reset();
switch (AkabeiClient::Backend::instance()->transactionHandler()->phase()) {
case AkabeiClient::TransactionHandler::Validating:
out << i18n("Validating");
break;
case AkabeiClient::TransactionHandler::RunningPreHooks:
out << i18n("Running PreHooks");
break;
case AkabeiClient::TransactionHandler::Downloading:
out << i18n("Downloading");
break;
case AkabeiClient::TransactionHandler::Processing:
out << i18n("Processing");
break;
case AkabeiClient::TransactionHandler::RunningScriptlets:
out << i18n("Running Scriplets");
break;
case AkabeiClient::TransactionHandler::RunningPostHooks:
out << i18n("Running PostHooks");
break;
case AkabeiClient::TransactionHandler::Cleaning:
out << i18n("Cleaning");
break;
default:
out << i18n("Finished");
break;
};
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
out << "#";
} else {
out << "-";
}