Skip to content

Commit

Permalink
Track icons version.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaurycyLiebner committed Feb 25, 2021
1 parent b0eb3c2 commit ce2e6b0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/app/iconloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,39 @@ void generateButtons(const int minWidgetDim, const int buttonDim) {
}

void IconLoader::generateAll(const int minWidgetDim, const int buttonDim) {
const QString minDimStr = QString::number(minWidgetDim);
const QDir eDir(eSettings::sSettingsDir());
QDir iconsDir(eSettings::sSettingsDir() + "/icons");
#ifdef QT_DEBUG
iconsDir.removeRecursively();
#endif
const QString mkPath = "icons/" + QString::number(minWidgetDim);
const QString mkPath = "icons/" + minDimStr;
if(!eDir.mkpath(mkPath)) RuntimeThrow("Failed to mkpath '" + mkPath + "'");
QDir iconsSizeDir(eSettings::sIconsDir());

const int enveIconsVersion = 0;
QFile verFile(iconsSizeDir.filePath("ver"));
bool removeIcons = false;
if(!verFile.exists()) {
removeIcons = true;
} else {
const auto verData = verFile.readAll();
const int foundVersion = verData.toInt();
if(enveIconsVersion != foundVersion) {
removeIcons = true;
}
}
if(removeIcons) {
iconsSizeDir.removeRecursively();
if(!eDir.mkpath(mkPath)) RuntimeThrow("Failed to mkpath '" + mkPath + "'");
}

if(verFile.open(QIODevice::WriteOnly)) {
const auto verIntData = reinterpret_cast<const char*>(&enveIconsVersion);
const auto verData = QByteArray::fromRawData(verIntData, sizeof(int));
verFile.write(verData);
verFile.close();
}

QDirIterator noInterIt(":/icons/noInterpolation");
while(noInterIt.hasNext()) {
Expand All @@ -120,15 +146,15 @@ void IconLoader::generateAll(const int minWidgetDim, const int buttonDim) {
int targetWidth = qCeil(img.width()*minWidgetDim/22.);
if(qAbs(targetWidth - img.width()) % 2 == 1) targetWidth--;
const auto scaled = img.scaledToWidth(targetWidth, Qt::TransformationMode::SmoothTransformation);
scaled.save(iconsDir.filePath(QString::number(minWidgetDim) + "/" + fileName));
scaled.save(iconsSizeDir.filePath(fileName));
}

QDirIterator baseIt(":/icons");
while(baseIt.hasNext()) {
const auto path = baseIt.next();
if(baseIt.fileInfo().isDir()) continue;
const auto fileName = baseIt.fileName().chopped(4);
const auto pngPath = iconsDir.filePath(QString::number(minWidgetDim) + "/" + fileName + ".png");
const auto pngPath = iconsSizeDir.filePath(fileName + ".png");
generate(path, minWidgetDim/22., pngPath);
}
generateButtons(minWidgetDim, buttonDim);
Expand Down

1 comment on commit ce2e6b0

@irwant
Copy link

@irwant irwant commented on ce2e6b0 Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, this update looks beautiful. great job

stay health

Please sign in to comment.