Skip to content

Commit cdf4210

Browse files
committed
Start: Add extensions to ignore for thumbnails
1 parent ba04f2f commit cdf4210

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

src/Mod/Start/App/DisplayedFilesModel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,21 @@ void DisplayedFilesModel::addFile(const QString& filePath)
228228
}
229229

230230
_fileInfoCache.emplace_back(getFileInfo(filePath.toStdString()));
231-
if (qfi.suffix().toLower() == QLatin1String("fcstd")) {
231+
const auto lowercaseExtension = qfi.suffix().toLower();
232+
const QStringList ignoredExtensions {QLatin1String("fcmacro"),
233+
QLatin1String("py"),
234+
QLatin1String("pyi"),
235+
QLatin1String("csv"),
236+
QLatin1String("txt")};
237+
if (lowercaseExtension == QLatin1String("fcstd")) {
232238
if (const auto thumbnail = loadFCStdThumbnail(filePath); !thumbnail.isEmpty()) {
233239
_imageCache.insert(filePath, thumbnail);
234240
}
235241
}
242+
else if (ignoredExtensions.contains(lowercaseExtension)) {
243+
// Don't try to generate a thumbnail for things like this: FreeCAD can read them, but
244+
// there's not much point in showing anything besides a generic icon
245+
}
236246
else {
237247
const auto runner = new ThumbnailSource(filePath);
238248
connect(runner->signals(),

src/Mod/Start/App/FileUtilities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "PreCompiled.h"
2525
#ifndef _PreComp_
2626
#include <QCryptographicHash>
27+
#include <QDateTime>
2728
#include <QDir>
2829
#include <QFileInfo>
2930
#include <QStandardPaths>

src/Mod/Start/App/ThumbnailSource.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,22 @@ void ThumbnailSource::run()
7676
args << QLatin1String("--output=") + thumbnailPath << _file;
7777

7878
_process = std::make_unique<QProcess>();
79+
Base::Console().Log("Creating thumbnail for %s...\n", _file.toStdString());
7980
_process->start(f3d, args);
80-
81-
// Since this is running on a non-GUI thread, poll for an interruption request while running
82-
// so that external code can kill the process if necessary.
8381
constexpr int checkEveryMs {50};
84-
while (_process->waitForFinished(checkEveryMs)) {
82+
while (!_process->waitForFinished(checkEveryMs)) {
8583
if (QThread::currentThread()->isInterruptionRequested()) {
8684
_process->kill();
85+
break;
8786
}
8887
}
8988
if (_process->exitCode() != 0) {
89+
Base::Console().Log("Creating thumbnail for %s failed\n", _file.toStdString());
9090
return;
9191
}
92+
Base::Console().Log("Creating thumbnail for %s succeeded, wrote to %s\n",
93+
_file.toStdString(),
94+
thumbnailPath.toStdString());
9295
}
9396

9497
if (QFile thumbnailFile(thumbnailPath); thumbnailFile.exists()) {
@@ -132,7 +135,7 @@ QStringList getF3DOptions(const QString& f3d)
132135
QStringLiteral("--load-plugins=occt"),
133136
QStringLiteral("--config=thumbnail"),
134137
QStringLiteral("--verbose=quiet"),
135-
QStringLiteral("--resolution=128,128"),
138+
QStringLiteral("--resolution=256,256"),
136139
QStringLiteral("--filename=0"),
137140
QStringLiteral("--grid=0"),
138141
QStringLiteral("--no-background"),

src/Mod/Start/App/ThumbnailSource.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ class ThumbnailSource: public QRunnable
5757
ThumbnailSource operator=(const ThumbnailSource&) = delete;
5858
ThumbnailSource operator=(ThumbnailSource&&) = delete;
5959

60-
// Don't make copies of a ThumbnailSource (it's probably running a process, what would it mean
61-
// to copy it?):
62-
ThumbnailSource(ThumbnailSource&) = delete;
63-
ThumbnailSource(ThumbnailSource&&) = delete;
64-
ThumbnailSource operator=(const ThumbnailSource&) = delete;
65-
ThumbnailSource operator=(ThumbnailSource&&) = delete;
66-
6760
void run() override;
6861

6962
ThumbnailSourceSignals* signals();

src/Mod/Start/Gui/FileCardDelegate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ QPixmap FileCardDelegate::generateThumbnail(const QString& path) const
208208
auto thumbnailSize =
209209
static_cast<int>(_parameterGroup->GetInt("FileThumbnailIconsSize", 128)); // NOLINT
210210
if (path.endsWith(QLatin1String(".fcstd"), Qt::CaseSensitivity::CaseInsensitive)) {
211+
// This is a fallback, the model will have pulled the thumbnail out of the FCStd file if it
212+
// existed.
211213
QImageReader reader(QLatin1String(":/icons/freecad-doc.svg"));
212214
reader.setScaledSize({thumbnailSize, thumbnailSize});
213215
return QPixmap::fromImage(reader.read());

0 commit comments

Comments
 (0)