1 // case - file manager for N900
2 // Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "progressbar.h"
22 #include "fileoperator.h"
27 ProgressBar::ProgressBar(const QPixmap &icon, const QPixmap &inverseIcon) :
39 QFont barFont = font();
40 barFont.setPointSize(12);
44 mainText = tr("gathering information...");
48 void ProgressBar::updateProgress(int val) {
49 if (value() + val > maximum()) {
50 std::cout << "WARNING: exceeding progressbar maximum (" << maximum() << ") by " << val << std::endl;
53 setValue(value() + val);
56 if (lastTimeUpdate < now) {
59 time_t elapsed = now - startTime;
60 time_t remaining = (time_t) ((float) elapsed / value() * (maximum() - value()));
61 struct tm *ts = gmtime(&remaining);
65 } else if (remaining < 60) {
66 strftime(timeBuf, sizeof(timeBuf), " %Ss", ts);
67 } else if (remaining < 3600) {
68 strftime(timeBuf, sizeof(timeBuf), " %M:%S", ts);
70 strftime(timeBuf, sizeof(timeBuf), " %H:%M:%S", ts);
74 setFormat(QString("%p%") + timeBuf);
78 void ProgressBar::updateMainText(const QString &text) {
80 if (fromText.size()) {
81 mainText.remove(0, fromText.size() + 1);
87 void ProgressBar::setBottomTexts(const QString &left, const QString &right) {
93 void ProgressBar::setStartTime(time_t t) {
95 lastTimeUpdate = time(0);
100 void ProgressBar::pause() {
106 void ProgressBar::resume(time_t stallTime) {
107 startTime += stallTime;
113 void ProgressBar::showRemoveNotice() {
114 toText = "<" + tr("deleting") + ">";
119 void ProgressBar::mouseReleaseEvent(QMouseEvent *) {
120 if (!contextEvent) emit togglePauseOperation(this);
121 contextEvent = false;
125 void ProgressBar::contextMenuEvent(QContextMenuEvent *) {
127 emit abortOperation(this);