X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fprogressbar.cpp;h=7780b049b96489282f6b42b1e4dae0b090a5a6f8;hb=2edb4f2f10329116492492b442c2957653381c28;hp=29d68a63bae719d8188f081367d20ac01d722ec1;hpb=55d99074d0b0b5eca3530d0c0f683faee48f10f9;p=case diff --git a/src/progressbar.cpp b/src/progressbar.cpp index 29d68a6..7780b04 100644 --- a/src/progressbar.cpp +++ b/src/progressbar.cpp @@ -23,12 +23,16 @@ #include -ProgressBar::ProgressBar(FileManipulatorThread *thread, QWidget *parent) : - QProgressBar(parent), + +ProgressBar::ProgressBar(const QPixmap &icon, const QPixmap &inverseIcon) : + bgIcon(icon), + fgIcon(inverseIcon), paused(false), contextEvent(false), - thread(thread) + lastTimeUpdate(0), + startTime(0) { + timeBuf[0] = 0; setMaximum(1); setValue(0); setMinimum(0); @@ -41,19 +45,84 @@ ProgressBar::ProgressBar(FileManipulatorThread *thread, QWidget *parent) : } -void ProgressBar::setIcons(const QPixmap &icon, const QPixmap &inverseIcon) { - bgIcon = icon; - fgIcon = inverseIcon; +void ProgressBar::updateProgress(int val) { + if (value() + val > maximum()) { + std::cout << "WARNING: exceeding progressbar maximum (" << maximum() << ") by " << val << std::endl; + } + + setValue(value() + val); + + time_t now = time(0); + if (lastTimeUpdate < now) { + lastTimeUpdate = now; + + time_t elapsed = now - startTime; + time_t remaining = (time_t) ((float) elapsed / value() * (maximum() - value())); + struct tm *ts = gmtime(&remaining); + + if (remaining == 0) { + timeBuf[0] = 0; + } else if (remaining < 60) { + strftime(timeBuf, sizeof(timeBuf), " %Ss", ts); + } else if (remaining < 3600) { + strftime(timeBuf, sizeof(timeBuf), " %M:%S", ts); + } else { + strftime(timeBuf, sizeof(timeBuf), " %H:%M:%S", ts); + } + } + + setFormat(QString("%p%") + timeBuf); +} + + +void ProgressBar::updateMainText(const QString &text) { + mainText = text; + if (fromText.size()) { + mainText.remove(0, fromText.size() + 1); + } + repaint(); +} + + +void ProgressBar::setBottomTexts(const QString &left, const QString &right) { + fromText = left; + toText = right; +} + + +void ProgressBar::setStartTime(time_t t) { + startTime = t; + lastTimeUpdate = time(0); + updateProgress(0); +} + + +void ProgressBar::pause() { + paused = true; + repaint(); +} + + +void ProgressBar::resume(time_t stallTime) { + startTime += stallTime; + paused = false; + repaint(); +} + + +void ProgressBar::showRemoveNotice() { + toText = "<" + tr("deleting") + ">"; + repaint(); } void ProgressBar::mouseReleaseEvent(QMouseEvent *) { - if (!contextEvent) emit togglePauseOperation(thread); + if (!contextEvent) emit togglePauseOperation(this); contextEvent = false; } void ProgressBar::contextMenuEvent(QContextMenuEvent *) { contextEvent = true; - emit abortOperation(thread); + emit abortOperation(this); }