XDGKit v0.1.0-1
XDG Utilities for C++
Loading...
Searching...
No Matches
🕹️ Examples

Finding Icons

#include <XDGKit/XDGKit.h>
#include <iostream>
using namespace XDG;
int main()
{
// Create an instance of XDGKit.
auto kit = XDGKit::Make();
// Search for an icon
const XDGIcon *firefox =
kit->iconThemeManager().findIcon(
"firefox", // Icon to search for
512, // Desired icon size (unscaled)
2, // Scale factor
XDGIcon::PNG | XDGIcon::SVG | XDGIcon::XMP, // File extensions to consider
{""} // Theme names to search in order, "" as wildcard for all themes
);
// Check if the icon was found
if (firefox)
{
std::cout
<< "Theme: " << firefox->directory().theme().name() << "\n"
<< "Icon: " << firefox->name() << "\n"
<< "Size: " << firefox->directory().size() << "\n"
<< "Scale: " << firefox->directory().scale() << "\n";
if (firefox->extensions() & XDGIcon::PNG)
std::cout << "PNG Path: " << firefox->getPath(XDGIcon::PNG) << "\n";
if (firefox->extensions() & XDGIcon::SVG)
std::cout << "SVG Path: " << firefox->getPath(XDGIcon::SVG) << "\n";
if (firefox->extensions() & XDGIcon::XMP)
std::cout << "XMP Path: " << firefox->getPath(XDGIcon::XMP) << "\n";
return 0;
}
else
{
std::cout << "Could not find an icon named 'firefox'." << "\n";
return 1;
}
}
int32_t scale() const noexcept
Retrieves the scale factor of the icons.
Definition XDGIconDirectory.h:84
XDGIconTheme & theme() const noexcept
Retrieves the theme to which this directory belongs.
Definition XDGIconDirectory.h:138
int32_t size() const noexcept
Retrieves the nominal (unscaled) size of icons in the directory.
Definition XDGIconDirectory.h:63
Properties of an icon.
Definition XDGIcon.h:14
XDGIconDirectory & directory() const noexcept
Retrieves the directory to which this icon belongs.
Definition XDGIcon.h:67
const char * name() const noexcept
Retrieves the name of the icon.
Definition XDGIcon.h:48
std::filesystem::path getPath(Extension ext) const noexcept
Retrieves the absolute path of the icon for a specified file extension.
Definition XDGIcon.cpp:6
uint32_t extensions() const noexcept
Retrieves the bitset of file extensions found for this icon.
Definition XDGIcon.h:41
const std::string & name() const noexcept
Retrieves the theme's directory base name.
Definition XDGIconTheme.h:48
Namespace.
Definition XDGNamespace.h:8