Start: Switch to using QProcess, not std::system
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QStandardPaths>
|
||||
#include <QUrl>
|
||||
#endif
|
||||
@@ -284,12 +285,10 @@ void DisplayedFilesModel::addFile(const QString& filePath)
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if FreeCAD can open the file by its extension
|
||||
if (!freecadCanOpen(qfi.suffix())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add file information to cache
|
||||
_fileInfoCache.emplace_back(getFileInfo(filePath.toStdString()));
|
||||
if (qfi.suffix().toLower() == QLatin1String("fcstd")) {
|
||||
auto thumbnail = loadFCStdThumbnail(filePath.toStdString());
|
||||
@@ -299,20 +298,21 @@ void DisplayedFilesModel::addFile(const QString& filePath)
|
||||
}
|
||||
else {
|
||||
// If it is not a FreeCAD file, generate thumbnail using F3D
|
||||
QString thumbnailPath = QString(QLatin1String("%1/%2_thumbnail.png"))
|
||||
.arg(QLatin1String("/tmp"))
|
||||
.arg(qfi.baseName()); // Temporary path for the thumbnail
|
||||
QString thumbnailPath = getUniquePNG(filePath.toStdString());
|
||||
|
||||
QString command =
|
||||
QString(QLatin1String("f3d --config=thumbnail --load-plugins=occt --verbose=quiet "
|
||||
"--output=%1 --resolution=%2,%3 %4"))
|
||||
.arg(thumbnailPath)
|
||||
.arg(128) // Thumbnail size in X
|
||||
.arg(128) // Thumbnail size in Y
|
||||
.arg(filePath); // Input file
|
||||
auto f3d = QString::fromLatin1("f3d");
|
||||
QStringList args;
|
||||
args << QLatin1String("--config=thumbnail") << QLatin1String("--load-plugins=occt")
|
||||
<< QLatin1String("--verbose=quiet") << QLatin1String("--output=") + thumbnailPath
|
||||
<< QLatin1String("--resolution=") + QString::number(128) + QLatin1String(",")
|
||||
+ QString::number(128)
|
||||
<< filePath;
|
||||
|
||||
// Run the f3d command to generate the thumbnail
|
||||
int result = std::system(command.toStdString().c_str());
|
||||
QProcess process;
|
||||
process.start(f3d, args);
|
||||
process.waitForFinished();
|
||||
int result = process.exitCode();
|
||||
|
||||
// Check if the thumbnail was generated successfully and exists
|
||||
if (result == 0 && QFile::exists(thumbnailPath)) {
|
||||
|
||||
Reference in New Issue
Block a user