Commit 9cf67a7c authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

eta basics for operations

parent 4158a722
......@@ -24,6 +24,7 @@ OperationPrivate::OperationPrivate(Operation *op, const QString &tN)
, targetName(tN)
, uuid(QUuid::createUuid())
, processingOptions(NoProcessingOption)
, eta(0)
{
runner = Backend::instance()->operationRunner();
}
......@@ -184,6 +185,12 @@ ProcessingOptions Operation::processingOptions() const
return d->processingOptions;
}
int Operation::eta() const
{
Q_D(const Operation);
return d->eta;
}
void Operation::setCanBeConcurrent(bool concurrent)
{
Q_D(Operation);
......@@ -274,6 +281,7 @@ void Operation::setFinished(bool result)
} else {
d->setStatus(StatusError);
}
setEta(0);
if (d->runner) {
d->runner->d_func()->emitFinished(this, result);
}
......@@ -316,4 +324,13 @@ void Operation::addMessage(const QString& message)
log() << message;
}
void Operation::setEta(int eta)
{
Q_D(Operation);
d->eta = eta;
if (d->runner) {
d->runner->d_func()->emitEtaChanged(this, eta);
}
}
}
......@@ -78,7 +78,7 @@ class OperationPrivate;
class Operation
{
friend class ArchiveHandler;
Q_DISABLE_COPY(Operation)
Q_DECLARE_PRIVATE(Operation)
public:
......@@ -213,6 +213,12 @@ public:
*/
ProcessingOptions processingOptions() const;
/**
* @returns the estimated time left for the operation to complete processing
* This will be zero if the operation is in a finished state.
*/
int eta() const;
protected:
/**
* Constructs an operation
......@@ -323,9 +329,9 @@ protected:
* Sets a list of errors which occurred during validation or processing.
* @param errors the list of errors which occurred
*/
void setErrors(Error::List const& errors);
/**
* This method can be used to indicate at what point of processing we current are.
* Should be a value between 0 and 100.
......@@ -337,7 +343,7 @@ protected:
* @param message the message to show
*/
void addMessage(const QString &message);
/**
* Sets a list of operations which are going to be processed right before
* this one.
......@@ -367,13 +373,19 @@ protected:
*/
void setDescription(const QString &string);
/**
* Sets the estimated time left for the operation to complete processing
* @param eta the estimated time left in seconds
*/
void setEta(int eta);
private:
OperationPrivate * const d_ptr;
friend class OperationRunner;
friend class RunnerRunnable;
friend class ValidatorRunnable;
/* This is needed by the libarchive interface to perform its tasks */
friend class InstallFunctor;
friend class ReinstallUpgradeFunctor;
......
......@@ -50,6 +50,7 @@ public:
Operation::Status status;
Error::List errors;
ProcessingOptions processingOptions;
int eta;
Operation::List preOps;
Operation::List postOps;
......
......@@ -75,6 +75,17 @@ void OperationRunnerPrivate::emitStatus(Akabei::Operation* op, Operation::Status
emit q->operationStatusChanged(op, status);
}
void OperationRunnerPrivate::emitEtaChanged(Akabei::Operation* op, int eta)
{
if (etaFlicker.elapsed() <= 300 && eta > 0) {
return;
}
etaFlicker.restart();
Q_Q(OperationRunner);
emit q->operationEtaChanged(op, eta);
}
/////////
OperationRunner::OperationRunner(QObject *parent)
......
......@@ -152,6 +152,12 @@ Q_SIGNALS:
* @param percentage the current progress in percent
*/
void operationProgress(Akabei::Operation *operation, int percentage);
/**
* The estimated time left for an operation changed
* @param operation the operation which has now roughly
* @param eta seconds to get finished
*/
void operationEtaChanged(Akabei::Operation* operation, int eta);
/**
* An operation wants to show a message to the user.
* @param operation the operation which wants to show the message
......
......@@ -45,11 +45,13 @@ public:
ProcessingOptions processingOptions;
QTime antiFlicker;
QTime etaFlicker;
void emitProgress(Akabei::Operation* op, int progress);
void emitFinished(Akabei::Operation* op, bool success);
void emitMessage(Akabei::Operation* op, const QString &message);
void emitStatus(Akabei::Operation* op, Operation::Status status);
void emitEtaChanged(Akabei::Operation* op, int eta);
void __k__errorsOccurred(Error::List const&);
void __k__validationFinished(bool, const OpsHash&);
......
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