Commit 42ebcb34 authored by Lukas Appelhans's avatar Lukas Appelhans

Make it completely adjustable to size changes

parent f0a71ae3
......@@ -152,12 +152,11 @@ void QueueOperation::validationFinished(bool valid)
void QueueOperation::showProgress()
{
//I'm sorry that this method looks a bit complicated, but I really see no other way for this... :/
int progress = AkabeiClient::Backend::instance()->transactionHandler()->progress();
unsigned int hashlen = getcols();
QTextStream out(stdout);
out.reset();
const unsigned int hashlen = getcols();
QString status;
switch (AkabeiClient::Backend::instance()->transactionHandler()->phase()) {
case AkabeiClient::TransactionHandler::Validating:
......@@ -185,39 +184,75 @@ void QueueOperation::showProgress()
status = i18n("Finished!");
break;
};
hashlen = hashlen - status.length();
out << status;
QHash<Akabei::Package*, int>::iterator i = m_progresses.begin();
QHash<Akabei::Package*, int>::iterator end = m_progresses.end();
QStringList additional;
int counter = 1;
int additionalLenght = 0;
QString pkgs;
for (; i != end; i++) {
QString output = " | " + i.key()->name() + ' ' + i.key()->version().toByteArray().data() + " (" + QString::number(i.value()) + "%)";
hashlen = hashlen - output.length();
out << output;
QString pkgOutput = " | " + i.key()->name() + "%" + QString::number(counter);
additional << QString(" " + QString(i.key()->version().toByteArray().data()) + " (" + QString::number(i.value()) + "%)");
additionalLenght = additionalLenght + additional.last().length();
pkgs += pkgOutput;
counter++;
}
QString totalOut = " | " + i18n("Total progress:") + " [";
out << totalOut;
QString startOut = " | " + i18n("Total progress:") + " [";
QString endOut = "] " + QString::number(progress) + "%";
hashlen = hashlen - totalOut.length() - endOut.length();
int pBarLength = startOut.length() + endOut.length() + 10;
const unsigned int hash = progress * hashlen / 100;
for (unsigned int i = hashlen; i > 1; --i) {
/* if special progress bar enabled */
if (i > hashlen - hash) {
out << "#";
} else {
out << "-";
bool showPBar = false;
QString output;
output += status;
int length = output.length();
if ((output.length() + pBarLength) < hashlen) {
length = length + pBarLength;
showPBar = true;
}
if ((length + pkgs.length() - (additional.count() * 2)) <= hashlen) {
counter = 1;
foreach (const QString &add, additional) {
if ((length + pkgs.length() + add.length() - 2) <= hashlen) { //-2 is the argument e.g. "%1"
pkgs.replace("%" + QString::number(counter), add);
} else {
pkgs.replace("%" + QString::number(counter), QString());
}
counter++;
}
output += pkgs;
}
out << endOut;//FIXME
if (showPBar) {
QString pBarOut = startOut;
int pBar = qMax(10, (int)(hashlen - output.length() - endOut.length() - startOut.length()));
const unsigned int hash = progress * pBar / 100;
for (unsigned int i = pBar; i > 1; --i) {
/* if special progress bar enabled */
if (i > pBar - hash) {
pBarOut += "#";
} else {
pBarOut += "-";
}
}
pBarOut += endOut;
output += pBarOut;
}
QTextStream out(stdout);
out.reset();
out << output;
out.flush();
if (progress == 100) {
out << endl;
} else {
out << "\r";
}
out.flush();
}
void QueueOperation::packageProgressChanged(Akabei::Package* package, int progress)
......
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