SNI: Allow IconPath to be empty

Fixes network-manager-applet
This commit is contained in:
scorpion-26 2023-07-04 12:18:56 +02:00
parent 7567465454
commit 18f3e123ed
2 changed files with 26 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#include <iostream>
#include <unistd.h>
#include <string>
#include <filesystem>
#include "Log.h"
@ -82,6 +83,20 @@ namespace Utils
snprintf(buf, sizeof(buf), fmt, bytes, "B");
return buf;
}
inline std::string FindFileWithName(const std::string& directory, const std::string& name, const std::string& extension)
{
for (auto& path : std::filesystem::recursive_directory_iterator(directory))
{
if (path.is_directory())
continue;
if (path.path().filename().string().find(name) != std::string::npos && path.path().extension().string() == extension)
{
return path.path().string();
}
}
return "";
}
}
struct Process

View file

@ -2,6 +2,7 @@
#include "Log.h"
#include "Widget.h"
#include "Config.h"
#include "Common.h"
#ifdef WITH_SNI
@ -136,7 +137,16 @@ namespace SNI
const char* themePath = g_variant_get_string(themePathStr, nullptr);
const char* iconName = g_variant_get_string(iconNameStr, nullptr);
if (strlen(themePath) == 0)
{
// Nothing defined, look in /usr/share/icons
// network-manager-applet does this
iconPath = Utils::FindFileWithName("/usr/share/icons", iconName, ".png");
}
else
{
iconPath = std::string(themePath) + "/" + iconName + ".png"; // TODO: Find out if this is always png
}
g_variant_unref(themePathVariant);
g_variant_unref(themePathStr);