MCPcopy Create free account
hub / github.com/TheAssassin/AppImageLauncher / loadIconWithFallback

Function loadIconWithFallback

src/shared/shared.cpp:1270–1310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1268}
1269
1270QIcon loadIconWithFallback(const QString& iconName) {
1271 const QString subdirName("fallback-icons");
1272 const auto binaryDir = QApplication::applicationDirPath();
1273
1274 // first we check the directory that would be expected with in the build environment
1275 QDir fallbackIconDirectory = QDir(binaryDir + "/../../resources/" + subdirName);
1276
1277 // if that doesn't work, we check the private data directory, which should work when AppImageLauncher is installed
1278 // through the packages or in Lite's AppImage
1279 if (!fallbackIconDirectory.exists()) {
1280 auto privateDataDir = pathToPrivateDataDirectory();
1281
1282 if (privateDataDir.length() > 0 && QDir(privateDataDir).exists()) {
1283 fallbackIconDirectory = QDir(pathToPrivateDataDirectory() + "/" + subdirName);
1284 }
1285 }
1286
1287 // fallback icons aren't critical enough to exit the application if they can't be found
1288 // after all, the theme icons may work just as well
1289 if (!fallbackIconDirectory.exists()) {
1290 std::cerr << "[AppImageLauncher] Warning:"
1291 << "fallback icons could not be loaded: directory could not be found" << std::endl;
1292 return QIcon{};
1293 }
1294
1295 qDebug() << "Loading fallback for icon" << iconName;
1296
1297 const auto iconFilename = iconName + ".svg";
1298 const auto iconPath = fallbackIconDirectory.filePath(iconFilename);
1299
1300 if (!QFileInfo(iconPath).isFile()) {
1301 std::cerr << "[AppImageLauncher] Warning: can't find fallback icon for name"
1302 << iconName.toStdString() << std::endl;
1303 return QIcon{};
1304 }
1305
1306 const auto fallbackIcon = QIcon(iconPath);
1307 qDebug() << fallbackIcon;
1308
1309 return fallbackIcon;
1310}
1311
1312void setUpFallbackIconPaths(QWidget* parent) {
1313 /**

Callers 2

setUpFallbackIconPathsFunction · 0.85

Calls 1

Tested by

no test coverage detected