Skip to content

Commit

Permalink
[Packages] AudioControl: use icon name parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Bazulin <[email protected]>
  • Loading branch information
baz2142 committed Dec 2, 2024
1 parent 1437bff commit c260b8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 16 additions & 10 deletions packages/ghaf-audio-control/src/app/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ constexpr auto IconSize = 64;
struct AppArgs
{
Glib::ustring pulseServerAddress;
Glib::ustring indicatorIconPath;
Glib::ustring indicatorIconName;
Glib::ustring appVms;
bool isDeamonMode = false;
Glib::ustring isDeamonMode;
};

std::vector<std::string> GetAppVmsList(const std::string& appVms)
Expand All @@ -41,14 +41,13 @@ std::vector<std::string> GetAppVmsList(const std::string& appVms)
return result;
}

std::optional<std::filesystem::path> GetThemeIcon()
std::optional<std::filesystem::path> GetThemeIcon(const Glib::ustring& iconName)
{
auto icon_theme = Gtk::IconTheme::get_default();

if (auto iconInfo = icon_theme->lookup_icon(IconName, IconSize, Gtk::ICON_LOOKUP_USE_BUILTIN))
if (auto iconInfo = icon_theme->lookup_icon(iconName, IconSize, Gtk::ICON_LOOKUP_USE_BUILTIN))
return iconInfo.get_filename().c_str();

Logger::error("App::getThemeIcon: couldn't found an icon");

return std::nullopt;
}
Expand Down Expand Up @@ -79,9 +78,9 @@ App::App(int argc, char** argv)
pulseServerOption.set_long_name("pulseaudio_server");
pulseServerOption.set_description("PulseAudio server address");

Glib::OptionEntry indicatorIconPathOption;
indicatorIconPathOption.set_long_name("indicator_icon_path");
indicatorIconPathOption.set_description("Tray's icon indicator path");
Glib::OptionEntry indicatorIconNameOption;
indicatorIconNameOption.set_long_name("indicator_icon_name");
indicatorIconNameOption.set_description("Tray's icon indicator name");

Glib::OptionEntry appVmsOption;
appVmsOption.set_long_name("app_vms");
Expand All @@ -93,7 +92,7 @@ App::App(int argc, char** argv)

Glib::OptionGroup options("Main", "Main");
options.add_entry(pulseServerOption, appArgs.pulseServerAddress);
options.add_entry(indicatorIconPathOption, appArgs.indicatorIconPath);
options.add_entry(indicatorIconNameOption, appArgs.indicatorIconName);
options.add_entry(appVmsOption, appArgs.appVms);
options.add_entry(deamonModeOption, appArgs.isDeamonMode);

Expand All @@ -106,6 +105,11 @@ App::App(int argc, char** argv)
throw std::runtime_error{"Couldn't parse the command line arguments"};
}

Logger::info("Parsed the option: '{}' = '{}'", pulseServerOption.get_long_name().c_str(), appArgs.pulseServerAddress.c_str());
Logger::info("Parsed the option: '{}' = '{}'", indicatorIconNameOption.get_long_name().c_str(), appArgs.indicatorIconName.c_str());
Logger::info("Parsed the option: '{}' = '{}'", appVmsOption.get_long_name().c_str(), appArgs.appVms.c_str());
Logger::info("Parsed the option: '{}' = '{}'", deamonModeOption.get_long_name().c_str(), appArgs.isDeamonMode.c_str());

m_connections += signal_command_line().connect(
[this]([[maybe_unused]] const Glib::RefPtr<Gio::ApplicationCommandLine>& args)
{
Expand All @@ -114,11 +118,13 @@ App::App(int argc, char** argv)
},
false);

if (const auto iconPath = GetThemeIcon())
if (const auto iconPath = GetThemeIcon(appArgs.indicatorIconName))
{
Logger::info("Got icon path for the indicator: {}", iconPath->c_str());
app_indicator_set_icon(m_indicator.get(), iconPath->filename().c_str());
}
else
Logger::info("Couldn't found an icon for indicator: {}", appArgs.indicatorIconName.c_str());

m_audioControl = std::make_unique<AudioControl>(std::make_unique<Backend::PulseAudio::AudioControlBackend>(appArgs.pulseServerAddress),
GetAppVmsList(appArgs.appVms));
Expand Down
2 changes: 0 additions & 2 deletions packages/ghaf-audio-control/src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "App.hpp"

#include <format>

using namespace ghaf::AudioControl;

int main(int argc, char** argv)
Expand Down

0 comments on commit c260b8b

Please sign in to comment.