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/>.
20 #include <QFSFileEngine>
23 QString shortenPath(const QString &path) {
24 QString homePath = QFSFileEngine::homePath();
26 if (path.indexOf(homePath, 0) == 0) {
27 QString result = path;
29 result.replace(0, homePath.size(), "~");
37 QString unwindPath(const QString &path) {
38 QString result = path;
39 // if ~ is the first character and / or nothing follows it, replace with home dir
40 if (path == "~" || path.indexOf("~/", 0) == 0) {
41 QString homePath = QFSFileEngine::homePath();
42 result.replace(0, 1, homePath);
43 // in case someone wants to enter a dir called ~ in the current dir, he can escape it with \~
44 } else if (path == "\\~" || path.indexOf("\\~/", 0) == 0) {
45 result.replace(0, 2, "~");
52 void themeImage(const QPalette &p, QImage &image, const bool inverse) {
53 image = image.convertToFormat(QImage::Format_Indexed8);
55 QRgb highlight = p.highlight().color().rgb();
58 second = p.text().color().rgb();
60 second = p.buttonText().color().rgb();
63 QVector<QRgb> colorTable = image.colorTable();
64 for (QVector<QRgb>::iterator it = colorTable.begin(); it != colorTable.end(); ++it) {
65 if ((*it & 0xFFFFFF) == 0xFFFFFF) *it = (*it & 0xFF000000) | second;
66 else if ((*it & 0xFFFFFF) == 0x0000FF) *it = (*it & 0xFF000000) | highlight;
68 image.setColorTable(colorTable);
72 bool loadOperationIcons(const QPalette &p, const QString &name, QPixmap &normal, QPixmap &inverse) {
73 QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
74 if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
75 if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
77 QImage inverseIconImage = iconImage;
79 themeImage(p, iconImage, false);
80 themeImage(p, inverseIconImage, true);
82 normal = QPixmap::fromImage(iconImage);
83 inverse = QPixmap::fromImage(inverseIconImage);
88 bool loadMiddleButtonIcons(const QPalette &p, const QString &name, QIcon &normal, QIcon &mirrored) {
89 QImage iconImage(ICON_PATH + ICON_SET + "/" + name + ".xpm", "XPM");
90 if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".png", "PNG");
91 if (iconImage.isNull()) iconImage.load(ICON_PATH + ICON_SET + "/" + name + ".gif", "GIF");
93 themeImage(p, iconImage, false);
95 normal = QIcon(QPixmap::fromImage(iconImage));
96 mirrored = QIcon(QPixmap::fromImage(iconImage.mirrored(true, false)));