Fixed: Search icons under Linux in default directories
This commit is contained in:
parent
eaab558f2a
commit
5a4f7a3757
1 changed files with 69 additions and 33 deletions
|
@ -761,6 +761,35 @@ static void addPackedSheetUpdatePaths(NLMISC::IProgressCallback &progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
||||||
|
static bool addRyzomIconBitmap(const std::string &directory, vector<CBitmap> &bitmaps)
|
||||||
|
{
|
||||||
|
if (CFile::isDirectory(directory))
|
||||||
|
{
|
||||||
|
// build filename from directory and default ryzom client icon name
|
||||||
|
std::string filename = NLMISC::toString("%s/%s.png", directory.c_str(), RYZOM_CLIENT_ICON);
|
||||||
|
|
||||||
|
if (CFile::fileExists(filename))
|
||||||
|
{
|
||||||
|
CIFile file;
|
||||||
|
|
||||||
|
if (file.open(filename))
|
||||||
|
{
|
||||||
|
CBitmap bitmap;
|
||||||
|
|
||||||
|
if (bitmap.load(file))
|
||||||
|
{
|
||||||
|
bitmaps.push_back(bitmap);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// prelogInit :
|
// prelogInit :
|
||||||
// Initialize the application before login
|
// Initialize the application before login
|
||||||
|
@ -1065,50 +1094,57 @@ void prelogInit()
|
||||||
Driver->setWindowTitle(CI18N::get("TheSagaOfRyzom"));
|
Driver->setWindowTitle(CI18N::get("TheSagaOfRyzom"));
|
||||||
|
|
||||||
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
||||||
// add all existing icons
|
// add all existing directory prefixes
|
||||||
vector<string> directories;
|
vector<string> directoryPrefixes;
|
||||||
|
|
||||||
// system directories
|
// user local directory prefix (~/.local)
|
||||||
directories.push_back("/usr/share/icons/hicolor/256x256/apps");
|
const char* homeDirectory = getenv("HOME");
|
||||||
directories.push_back("/usr/share/icons/hicolor/128x128/apps");
|
|
||||||
directories.push_back("/usr/share/icons/hicolor/96x96/apps");
|
|
||||||
directories.push_back("/usr/share/icons/hicolor/48x48/apps");
|
|
||||||
directories.push_back("/usr/share/icons/hicolor/32x32/apps");
|
|
||||||
directories.push_back("/usr/share/icons/hicolor/24x24/apps");
|
|
||||||
directories.push_back("/usr/share/icons/hicolor/22x22/apps");
|
|
||||||
directories.push_back("/usr/share/icons/hicolor/16x16/apps");
|
|
||||||
directories.push_back("/usr/share/pixmaps");
|
|
||||||
|
|
||||||
// local directories
|
if (homeDirectory)
|
||||||
directories.push_back("~/.local/share/icons/hicolor/256x256/apps");
|
directoryPrefixes.push_back(CPath::standardizePath(homeDirectory) + ".local");
|
||||||
directories.push_back("~/.local/share/icons/hicolor/128x128/apps");
|
|
||||||
directories.push_back("~/.local/share/icons/hicolor/96x96/apps");
|
|
||||||
directories.push_back("~/.local/share/icons/hicolor/48x48/apps");
|
|
||||||
directories.push_back("~/.local/share/icons/hicolor/32x32/apps");
|
|
||||||
directories.push_back("~/.local/share/icons/hicolor/24x24/apps");
|
|
||||||
directories.push_back("~/.local/share/icons/hicolor/22x22/apps");
|
|
||||||
directories.push_back("~/.local/share/icons/hicolor/16x16/apps");
|
|
||||||
directories.push_back("~/.local/share/pixmaps");
|
|
||||||
|
|
||||||
// check if an icon is present in registered paths
|
// system local directory prefix (/usr/local)
|
||||||
directories.push_back(".");
|
directoryPrefixes.push_back("/usr/local");
|
||||||
|
|
||||||
|
// system directory prefix (/usr)
|
||||||
|
directoryPrefixes.push_back("/usr");
|
||||||
|
|
||||||
|
// all supported icon sizes
|
||||||
|
vector<uint> iconSizes;
|
||||||
|
iconSizes.push_back(512);
|
||||||
|
iconSizes.push_back(256);
|
||||||
|
iconSizes.push_back(128);
|
||||||
|
iconSizes.push_back(96);
|
||||||
|
iconSizes.push_back(48);
|
||||||
|
iconSizes.push_back(32);
|
||||||
|
iconSizes.push_back(24);
|
||||||
|
iconSizes.push_back(22);
|
||||||
|
iconSizes.push_back(16);
|
||||||
|
|
||||||
vector<CBitmap> bitmaps;
|
vector<CBitmap> bitmaps;
|
||||||
|
|
||||||
for(size_t i = 0; i < directories.size(); ++i)
|
// process all icon sizes
|
||||||
|
for(size_t j = 0; j < iconSizes.size(); ++j)
|
||||||
{
|
{
|
||||||
std::string filename = NLMISC::toString("%s/%s.png", directories[i].c_str(), RYZOM_CLIENT_ICON);
|
// process all directory prefixes
|
||||||
|
for(size_t i = 0; i < directoryPrefixes.size(); ++i)
|
||||||
CIFile file;
|
|
||||||
|
|
||||||
if (CFile::fileExists(filename) && file.open(filename))
|
|
||||||
{
|
{
|
||||||
CBitmap bitmap;
|
uint size = iconSizes[j];
|
||||||
if (bitmap.load(file))
|
|
||||||
bitmaps.push_back(bitmap);
|
// build directory where to look for icon
|
||||||
|
std::string directory = toString("%s/share/icons/hicolor/%ux%u/apps", directoryPrefixes[i].c_str(), size, size);
|
||||||
|
|
||||||
|
// if found, skip other directories for this icon size
|
||||||
|
if (addRyzomIconBitmap(directory, bitmaps)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bitmaps.empty())
|
||||||
|
{
|
||||||
|
// check if an icon is present in current directory
|
||||||
|
addRyzomIconBitmap(".", bitmaps);
|
||||||
|
}
|
||||||
|
|
||||||
Driver->setWindowIcon(bitmaps);
|
Driver->setWindowIcon(bitmaps);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue