src/fileoperator.h \
src/pane.h \
src/dialog.h \
- src/progressbar.h
+ src/progressbar.h \
+ src/style.h \
+ src/utils.h
SOURCES += src/addressbar.cpp \
src/button.cpp \
src/case.cpp \
src/main.cpp \
src/pane.cpp \
src/dialog.cpp \
- src/progressbar.cpp
+ src/progressbar.cpp \
+ src/style.cpp \
+ src/utils.cpp
--- /dev/null
+/* XPM */
+static char * copy_small_xpm[] = {
+"20 20 3 1",
+" c None",
+". c #0000FF",
+"+ c #FFFFFF",
+" ",
+" +++ ",
+" +.+ ",
+" +.+ ",
+" ++++.++++ ",
+" +.......+ ",
+" ++++.++++ ",
+" +.+ ",
+" +.+ ",
+" +++ ++ ",
+" +.+ ",
+" +..+ ",
+"++++++++++++++...+ ",
+"+.................+ ",
+"+..................+",
+"+.................+ ",
+"++++++++++++++...+ ",
+" +..+ ",
+" +.+ ",
+" ++ "};
--- /dev/null
+/* XPM */
+static char * delete_small_xpm[] = {
+"20 20 3 1",
+" c None",
+". c #0000FF",
+"+ c #FFFFFF",
+" ",
+" + + ",
+" +.+ +.+ ",
+" +...+ +...+ ",
+" +.....+ +.....+ ",
+" +.....+ +.....+ ",
+" +.....++.....+ ",
+" +..........+ ",
+" +........+ ",
+" +......+ ",
+" +......+ ",
+" +........+ ",
+" +..........+ ",
+" +.....++.....+ ",
+" +.....+ +.....+ ",
+" +.....+ +.....+ ",
+" +...+ +...+ ",
+" +.+ +.+ ",
+" + + ",
+" "};
--- /dev/null
+/* XPM */
+static char * move_small_xpm[] = {
+"20 20 3 1",
+" c None",
+". c #0000FF",
+"+ c #FFFFFF",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ++ ",
+" +.+ ",
+" +..+ ",
+"++++++++++++++...+ ",
+"+.................+ ",
+"+..................+",
+"+.................+ ",
+"++++++++++++++...+ ",
+" +..+ ",
+" +.+ ",
+" ++ ",
+" ",
+" "};
#include <iostream>
-#define ICON_PATH QString("/usr/share/pixmaps/case/")
-#define ICON_SET "default"
+#include "utils.h"
Button::Button(const QString &name, QWidget *parent, const int maxWidth, const int maxHeight) :
setMaximumWidth(maxWidth);
setMaximumHeight(maxHeight);
- QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
- if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
- if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
-
- iconImage = iconImage.convertToFormat(QImage::Format_Indexed8);
-
- QRgb buttonText = palette().color(QPalette::ButtonText).rgb();
- QRgb highlight = palette().color(QPalette::Highlight).rgb();
- QVector<QRgb> colorTable = iconImage.colorTable();
- for (QVector<QRgb>::iterator it = colorTable.begin(); it != colorTable.end(); ++it) {
- if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | buttonText;
- else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight;
- }
- iconImage.setColorTable(colorTable);
-
- icons[0] = QIcon(QPixmap::fromImage(iconImage));
- icons[1] = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false)));
+ loadMiddleButtonIcons(palette(), name, icons[0], icons[1]);
setIcon(icons[0]);
}
#include <QChar>
#include "dialog.h"
+#include "utils.h"
#include <math.h>
#include <errno.h>
FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
- layout->setSpacing(0);
+ layout->setSpacing(1);
setLayout(layout);
qRegisterMetaType<QFileInfo>("QFileInfo");
+ loadOperationIcons(palette(), "delete_small", deleteIcon, inverseDeleteIcon);
+ loadOperationIcons(palette(), "copy_small", copyIcon, inverseCopyIcon);
+ loadOperationIcons(palette(), "move_small", moveIcon, inverseMoveIcon);
}
);
if(confirm == QMessageBox::Yes) {
- caterNewThread(new DeleteThread(files));
+ DeleteThread *t = new DeleteThread(files);
+ t->progressBar->setIcons(deleteIcon, inverseDeleteIcon);
+ caterNewThread(t);
}
}
);
if(confirm == QMessageBox::Yes) {
- caterNewThread(new CopyThread(files, destination));
+ CopyThread *t = new CopyThread(files, destination);
+ t->progressBar->setIcons(copyIcon, inverseCopyIcon);
+ t->progressBar->fromText = shortenPath(files[0].absolutePath());
+ t->progressBar->toText = FileOperator::shortenPath(destination.absolutePath());
+ caterNewThread(t);
}
}
);
if(confirm == QMessageBox::Yes) {
- caterNewThread(new MoveThread(files, destination));
+ MoveThread *t = new MoveThread(files, destination);
+ t->progressBar->setIcons(moveIcon, inverseMoveIcon);
+ t->progressBar->fromText = shortenPath(files[0].absolutePath());
+ t->progressBar->toText = shortenPath(destination.absolutePath());
+ caterNewThread(t);
}
}
}
+void FileOperator::updateMainText(FileManipulatorThread* manipulator, const QString &text) {
+ manipulator->progressBar->mainText = text;
+ manipulator->progressBar->mainText.remove(0, manipulator->progressBar->fromText.size() + 1);
+ manipulator->progressBar->repaint();
+}
+
+
void FileOperator::showPaused(FileManipulatorThread* manipulator) {
- manipulator->setText(0);
+ manipulator->progressBar->paused = true;
+ manipulator->progressBar->repaint();
}
void FileOperator::togglePauseOperation(FileManipulatorThread* manipulator) {
if (manipulator->pause) {
manipulator->pause = false;
+ manipulator->progressBar->paused = false;
+ manipulator->progressBar->repaint();
manipulator->wake();
} else {
manipulator->pause = true;
if(confirm == QMessageBox::Yes) {
manipulator->abort = true;
manipulator->pause = false;
- manipulator->setText(0);
manipulator->wake();
}
}
this, SLOT(setBarSize(FileManipulatorThread*, unsigned int)));
connect(thread, SIGNAL(updateProgress(FileManipulatorThread*, int)),
this, SLOT(updateProgress(FileManipulatorThread*, int)));
+ connect(thread, SIGNAL(updateFileName(FileManipulatorThread*, QString)),
+ this, SLOT(updateMainText(FileManipulatorThread*, QString)));
connect(thread, SIGNAL(operationPaused(FileManipulatorThread*)),
this, SLOT(showPaused(FileManipulatorThread*)));
connect(thread->progressBar, SIGNAL(abortOperation(FileManipulatorThread*)),
this, SLOT(abortOperation(FileManipulatorThread*)));
- thread->setText(0);
layout()->addWidget(thread->progressBar);
thread->start(QThread::LowestPriority);
}
void FileManipulatorThread::updateFile(const QString &name) {
fileValue = 0;
- fileName = FileOperator::shortenPath(name);
- emit updateProgress(this, 0);
+ emit updateFileName(this, FileOperator::shortenPath(name));
}
<< ") by " << value << std::endl;
}
- if (!fileName.size()) {
- if (pause) {
- progressBar->setFormat(tr("Gathering information...") + " (" + tr("paused") + ")");
- } else {
- progressBar->setFormat(tr("Gathering information..."));
- }
- return;
- }
-
time_t now = time(0);
if (lastTimeUpdate < now) {
lastTimeUpdate = now;
}
}
- QString newFormat = barText.arg(fileName) + "\n%p% ETA " + timeBuf;
- if (pause) newFormat += " (" + tr("paused") + ")";
- progressBar->setFormat(newFormat);
+ progressBar->setFormat(QString("%p% ") + timeBuf);
progressBar->setValue(progressBar->value() + value);
}
void remove(FileManipulatorThread* manipulator);
void setBarSize(FileManipulatorThread* manipulator, unsigned int size);
void updateProgress(FileManipulatorThread* manipulator, int value);
+ void updateMainText(FileManipulatorThread* manipulator, const QString &text);
void showPaused(FileManipulatorThread* manipulator);
void togglePauseOperation(FileManipulatorThread* manipulator);
void caterNewThread(FileManipulatorThread *thread);
QList<FileManipulatorThread*> manipulatorList;
+ QPixmap deleteIcon, inverseDeleteIcon, copyIcon, inverseCopyIcon, moveIcon, inverseMoveIcon;
};
// 1 for a file and file count for dirs (or both for copy&delete)
QMap<QString, qint64> fileSizeMap;
- // the name of the file thats being processed (for progressBar) and the text of the progressBar (the format)
- QString fileName, barText;
+ // the text of the progressBar (the format)
+ QString barText;
// stamp of the last ETA recalculation - done every second
time_t lastTimeUpdate;
time_t startTime, waitTime;
void finished(FileManipulatorThread*);
void setBarSize(FileManipulatorThread*, unsigned int);
void updateProgress(FileManipulatorThread*, int);
+ void updateFileName(FileManipulatorThread*, QString);
void operationPaused(FileManipulatorThread*);
};
#include <QApplication>
#include "case.h"
+#include "style.h"
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
+ app.setStyle(new Style());
+
Case theCase;
theCase.show();
ProgressBar::ProgressBar(FileManipulatorThread *thread, QWidget *parent) :
QProgressBar(parent),
+ paused(false),
contextEvent(false),
thread(thread)
{
barFont.setPointSize(12);
setFont(barFont);
setMinimumHeight(44);
- setStyle(new QPlastiqueStyle);
- //progressBar->setStyle(new QMotifStyle);
+ setFormat("");
+ mainText = tr("gathering information...");
+}
+
+
+void ProgressBar::setIcons(const QPixmap &icon, const QPixmap &inverseIcon) {
+ bgIcon = icon;
+ fgIcon = inverseIcon;
}
#define PROGRESSBAR_H
#include <QProgressBar>
+#include <QIcon>
class FileManipulatorThread;
public:
explicit ProgressBar(FileManipulatorThread *thread, QWidget *parent = 0);
+ void setIcons(const QPixmap &icon, const QPixmap &inverseIcon);
+
+ QString mainText, fromText, toText;
+ QPixmap bgIcon, fgIcon;
+ bool paused;
+
+
protected:
void mouseReleaseEvent(QMouseEvent *);
void contextMenuEvent(QContextMenuEvent *);
--- /dev/null
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+//
+// 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 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "style.h"
+
+#include <QPainter>
+
+#include "progressbar.h"
+
+#include <iostream>
+
+
+void Style::drawControl(ControlElement element,
+ const QStyleOption *opt,
+ QPainter *p,
+ const QWidget *widget) const
+{
+ switch (element) {
+ case CE_ProgressBarGroove:
+ if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
+ p->setPen(opt->palette.color(QPalette::ButtonText).darker());
+ p->drawRoundedRect(pb->rect.adjusted(0, 0, -1, -1), 4, 4);
+ }
+ break;
+
+ case CE_ProgressBarLabel:
+ if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
+ QRect rect = pb->rect;
+ int maximum = pb->maximum;
+ int minimum = pb->minimum;
+ int value = pb->progress;
+
+ const ProgressBar *w = qobject_cast<const ProgressBar*>(widget);
+
+ float perc = (maximum - minimum) ? static_cast<float>(value - minimum) / (maximum - minimum) : 0;
+
+ rect.adjust(2, 2, -2, -2);
+ QRect filledRect = rect, emptyRect = rect;
+ filledRect.setWidth(filledRect.width() * perc);
+ emptyRect.setX(emptyRect.x() + filledRect.width());
+
+ rect.adjust(3, 0, -3, 0);
+ QPoint iconPoint;
+ QRect topRect = rect, mainTextRect, bottomLeftRect = rect, bottomRightRect;
+ topRect.setHeight(topRect.height() / 2);
+ bottomLeftRect.setY(bottomLeftRect.y() + topRect.height());
+
+ int topRightWidth = p->fontMetrics().size(Qt::TextSingleLine, pb->text).width();
+ QRect pauseRect1(topRect.x() + topRect.width() - topRightWidth,
+ topRect.y() + topRect.height() / 2, 0, 0), pauseRect2;
+
+ if (w->paused) {
+ pauseRect1.adjust(-24, -7, -19, 7);
+ pauseRect2 = pauseRect1;
+ pauseRect2.adjust(10, 0, 10, 0);
+ }
+
+ if (w->fromText.size() || w->toText.size()) {
+ iconPoint = bottomLeftRect.center() - QPoint(10, 10);
+
+ mainTextRect = topRect;
+ mainTextRect.setRight(pauseRect1.x() - 10);
+
+ bottomRightRect = bottomLeftRect;
+ bottomLeftRect.setWidth(bottomLeftRect.width() / 2 - 13);
+ bottomRightRect.setX(bottomRightRect.x() + bottomLeftRect.width() + 26);
+ } else {
+ iconPoint = topRect.center() - QPoint(10, 8);
+
+ mainTextRect = bottomLeftRect;
+ }
+
+ QString mainText = shortenTextPath(p, mainTextRect, w->mainText);
+ QString bottomLeftText = shortenTextPath(p, bottomLeftRect, w->fromText);
+ QString bottomRightText = shortenTextPath(p, bottomRightRect, w->toText);
+
+ if (filledRect.width()) {
+ p->setClipRect(filledRect);
+ p->setPen(opt->palette.text().color());
+ p->setBrush(opt->palette.text());
+
+ p->drawPixmap(iconPoint, w->fgIcon);
+
+ p->drawText(mainTextRect, Qt::AlignCenter | Qt::TextSingleLine, mainText);
+ p->drawText(topRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, pb->text);
+ p->drawText(bottomLeftRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, bottomLeftText);
+ p->drawText(bottomRightRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, bottomRightText);
+
+ if (w->paused) {
+ p->drawRect(pauseRect1);
+ p->drawRect(pauseRect2);
+ }
+ }
+
+ if (emptyRect.width()) {
+ p->setClipRect(emptyRect);
+ p->setPen(opt->palette.buttonText().color());
+ p->setBrush(opt->palette.buttonText());
+
+ p->drawPixmap(iconPoint, w->bgIcon);
+
+ p->drawText(mainTextRect, Qt::AlignCenter | Qt::TextSingleLine, mainText);
+ p->drawText(topRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, pb->text);
+ p->drawText(bottomLeftRect, Qt::AlignRight | Qt::AlignVCenter | Qt::TextSingleLine, bottomLeftText);
+ p->drawText(bottomRightRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, bottomRightText);
+
+ if (w->paused) {
+ p->drawRect(pauseRect1);
+ p->drawRect(pauseRect2);
+ }
+ }
+ }
+ break;
+
+ case CE_ProgressBarContents:
+ if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
+ QRect rect = pb->rect;
+ int maximum = pb->maximum;
+ int minimum = pb->minimum;
+ int value = pb->progress;
+
+ QPalette pal = pb->palette;
+ // Correct the highlight color if it is the same as the background
+ if (pal.highlight() == pal.background())
+ pal.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
+ QPalette::Highlight));
+
+ float perc = (maximum - minimum) ? static_cast<float>(value - minimum) / (maximum - minimum) : 0;
+
+ QRect filledRect = rect;
+ filledRect.adjust(2, 2, -2, -2);
+ filledRect.setWidth(filledRect.width() * perc);
+
+ QColor highlight = opt->palette.highlight().color();
+ QColor lighter = highlight.lighter(120);
+ QColor darker = highlight.darker(110);
+
+ QGradientStops stops;
+ stops << QGradientStop(0.00, lighter);
+ stops << QGradientStop(0.15, darker);
+ stops << QGradientStop(0.80, darker);
+ stops << QGradientStop(1.00, lighter);
+ QLinearGradient fillGrad(0, 0, 0, filledRect.height());
+ fillGrad.setStops(stops);
+ QBrush fillBrush(fillGrad);
+
+ p->setPen(lighter);
+ p->setBrush(fillBrush);
+ p->drawRoundedRect(filledRect.adjusted(0, 0, -1, -1), 2, 2);
+ }
+ break;
+
+ default:
+ QMaemo5Style::drawControl(element, opt, p, widget);
+ }
+}
+
+
+QString Style::shortenTextPath(QPainter *p, const QRect &r, QString s) const {
+ QFontMetrics m = p->fontMetrics();
+ int width = r.width();
+ int start = -2, end = 1;
+
+ while (m.size(Qt::TextSingleLine, s).width() > width && s.size() > 7) {
+ if (end <= 0) {
+ start = end + 7;
+ } else {
+ // first pass only
+ if (start == -2) {
+ start = s.lastIndexOf('/', -2);
+ if (start <= 0) start += 4;
+ end = s.lastIndexOf('/', start - 1);
+ } else {
+ start = end + 4;
+ end = s.lastIndexOf('/', end - 1);
+ }
+ }
+
+ s.replace(end + 1, start - end - 1, "...");
+ }
+
+ return s;
+}
--- /dev/null
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+//
+// 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 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef STYLE_H
+#define STYLE_H
+
+#include <QMaemo5Style>
+
+
+class Style : public QMaemo5Style {
+ Q_OBJECT
+
+public:
+ void drawControl(ControlElement element,
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const;
+
+private:
+ QString shortenTextPath(QPainter *p, const QRect &r, QString s) const;
+};
+
+#endif // STYLE_H
--- /dev/null
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+//
+// 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 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "utils.h"
+
+
+void themeImage(const QPalette &p, QImage &image, const bool inverse) {
+ image = image.convertToFormat(QImage::Format_Indexed8);
+
+ QRgb highlight = p.highlight().color().rgb();
+ QRgb second;
+ if (inverse) {
+ second = p.text().color().rgb();
+ } else {
+ second = p.buttonText().color().rgb();
+ }
+
+ QVector<QRgb> colorTable = image.colorTable();
+ for (QVector<QRgb>::iterator it = colorTable.begin(); it != colorTable.end(); ++it) {
+ if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | second;
+ else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight;
+ }
+ image.setColorTable(colorTable);
+}
+
+
+bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse) {
+ QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
+ if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
+ if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
+
+ QImage inverseIconImage = iconImage;
+
+ themeImage(p, iconImage, false);
+ themeImage(p, inverseIconImage, true);
+
+ normal = QPixmap::fromImage(iconImage);
+ inverse = QPixmap::fromImage(inverseIconImage);
+ return true;
+}
+
+
+bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored) {
+ QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
+ if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
+ if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
+
+ themeImage(p, iconImage, false);
+
+ normal = QIcon(QPixmap::fromImage(iconImage));
+ mirrored = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false)));
+ return true;
+}
--- /dev/null
+// case - file manager for N900
+// Copyright (C) 2010 Lukas Hrazky <lukkash@email.cz>
+//
+// 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 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#include <QPalette>
+#include <QPixmap>
+#include <QIcon>
+
+
+#define ICON_PATH QString("/usr/share/pixmaps/case/")
+#define ICON_SET "default"
+
+
+bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse);
+bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored);
+
+#endif // UTILS_H