Skip to content

Commit 15df7a6

Browse files
andesfreedesignchennes
authored andcommitted
Start: Switch to using QProcess, not std::system
1 parent 0548ada commit 15df7a6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/Mod/Start/App/DisplayedFilesModel.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QDir>
3131
#include <QFile>
3232
#include <QFileInfo>
33+
#include <QProcess>
3334
#include <QStandardPaths>
3435
#include <QUrl>
3536
#endif
@@ -283,12 +284,10 @@ void DisplayedFilesModel::addFile(const QString& filePath)
283284
return;
284285
}
285286

286-
// Check if FreeCAD can open the file by its extension
287287
if (!freecadCanOpen(qfi.suffix())) {
288288
return;
289289
}
290290

291-
// Add file information to cache
292291
_fileInfoCache.emplace_back(getFileInfo(filePath.toStdString()));
293292
if (qfi.suffix().toLower() == QLatin1String("fcstd")) {
294293
auto thumbnail = loadFCStdThumbnail(filePath.toStdString());
@@ -298,20 +297,21 @@ void DisplayedFilesModel::addFile(const QString& filePath)
298297
}
299298
else {
300299
// If it is not a FreeCAD file, generate thumbnail using F3D
301-
QString thumbnailPath = QString(QLatin1String("%1/%2_thumbnail.png"))
302-
.arg(QLatin1String("/tmp"))
303-
.arg(qfi.baseName()); // Temporary path for the thumbnail
304-
305-
QString command =
306-
QString(QLatin1String("f3d --config=thumbnail --load-plugins=occt --verbose=quiet "
307-
"--output=%1 --resolution=%2,%3 %4"))
308-
.arg(thumbnailPath)
309-
.arg(128) // Thumbnail size in X
310-
.arg(128) // Thumbnail size in Y
311-
.arg(filePath); // Input file
300+
QString thumbnailPath = getUniquePNG(filePath.toStdString());
301+
302+
auto f3d = QString::fromLatin1("f3d");
303+
QStringList args;
304+
args << QLatin1String("--config=thumbnail") << QLatin1String("--load-plugins=occt")
305+
<< QLatin1String("--verbose=quiet") << QLatin1String("--output=") + thumbnailPath
306+
<< QLatin1String("--resolution=") + QString::number(128) + QLatin1String(",")
307+
+ QString::number(128)
308+
<< filePath;
312309

313310
// Run the f3d command to generate the thumbnail
314-
int result = std::system(command.toStdString().c_str());
311+
QProcess process;
312+
process.start(f3d, args);
313+
process.waitForFinished();
314+
int result = process.exitCode();
315315

316316
// Check if the thumbnail was generated successfully and exists
317317
if (result == 0 && QFile::exists(thumbnailPath)) {

0 commit comments

Comments
 (0)