diff --git a/repos/gems/src/app/mixer_gui_qt/main.cpp b/repos/gems/src/app/mixer_gui_qt/main.cpp index c8f0b41e3..fe67b57f2 100644 --- a/repos/gems/src/app/mixer_gui_qt/main.cpp +++ b/repos/gems/src/app/mixer_gui_qt/main.cpp @@ -44,7 +44,9 @@ struct Report_thread : Genode::Thread void _handle_channels(unsigned) { channels_rom.update(); - _report(channels_rom.local_addr(), channels_rom.size()); + + if (channels_rom.is_valid()) + _report(channels_rom.local_addr(), channels_rom.size()); } Report_thread() diff --git a/repos/gems/src/app/mixer_gui_qt/main_window.cpp b/repos/gems/src/app/mixer_gui_qt/main_window.cpp index fffcea19a..86c5559b8 100644 --- a/repos/gems/src/app/mixer_gui_qt/main_window.cpp +++ b/repos/gems/src/app/mixer_gui_qt/main_window.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -109,7 +110,7 @@ class Channel_widget : public Compound_widget, connect(&_slider, SIGNAL(sliderReleased()), this, SIGNAL(channel_changed())); - connect(&_muted_checkbox, SIGNAL(stateChanged(int)), + connect(&_muted_checkbox, SIGNAL(clicked(bool)), this, SIGNAL(channel_changed())); } @@ -308,15 +309,39 @@ static Client_widget_registry *client_registry() } -static Genode::Reporter config_reporter { "mixer.config" }; +static char const * const config_file = "/config/mixer.config"; + + +static int write_config(char const *file, char const *data, size_t length) +{ + if (length == 0) return 0; + + QFile mixer_file(file); + if (!mixer_file.open(QIODevice::WriteOnly)) { + PERR("could not open '%s'", file); + return -1; + } + + mixer_file.write(data, length); + mixer_file.close(); + + return 0; +} void Main_window::_update_config() { - config_reporter.enabled(true); + char xml_data[2048]; + size_t xml_used = 0; try { - Genode::Reporter::Xml_generator xml(config_reporter, [&] { + Genode::Xml_generator xml(xml_data, sizeof(xml_data), "config", [&] { + + xml.node("default", [&] { + xml.attribute("out_volume", _default_out_volume); + xml.attribute("volume", _default_volume); + xml.attribute("muted", _default_muted); + }); xml.node("channel_list", [&] { for (Client_widget const *c = client_registry()->first(); c; c = c->next()) { @@ -340,11 +365,20 @@ void Main_window::_update_config() xml.attribute("volume", combined ? vol : w->volume()); xml.attribute("muted", combined ? muted : w->muted()); }); + + if (_verbose) + PLOG("label: '%s' volume: %d muted: %d", c->label().string(), + combined ? vol : w->volume(), + combined ? muted : w->muted()); } } }); }); - } catch (...) { PWRN("could not report channels"); } + xml_used = xml.used(); + + } catch (...) { PWRN("could generate 'mixer.config'"); } + + write_config(config_file, xml_data, xml_used); } @@ -401,9 +435,27 @@ void Main_window::report_changed(void *l, void const *p) Main_window::Main_window() +: + _default_out_volume(0), + _default_volume(0), + _default_muted(true) { connect(client_registry(), SIGNAL(registry_changed()), this, SLOT(_update_config())); + + using namespace Genode; + + try { + Xml_node config_node = config()->xml_node(); + _verbose = config_node.attribute("verbose").has_value("yes"); + } catch (...) { _verbose = false; } + + try { + Xml_node node = config()->xml_node().sub_node("default"); + _default_out_volume = node.attribute_value("out_volume", 0); + _default_volume = node.attribute_value("volume", 0); + _default_muted = node.attribute_value("muted", 1); + } catch (...) { PWRN("no node found, fallback is 'muted=1'"); } } diff --git a/repos/gems/src/app/mixer_gui_qt/main_window.h b/repos/gems/src/app/mixer_gui_qt/main_window.h index 72f10c106..dc72afe16 100644 --- a/repos/gems/src/app/mixer_gui_qt/main_window.h +++ b/repos/gems/src/app/mixer_gui_qt/main_window.h @@ -50,6 +50,12 @@ class Main_window : public Compound_widget private: + int _default_out_volume; + int _default_volume; + bool _default_muted; + + bool _verbose; + void _update_clients(Genode::Xml_node &); private Q_SLOTS: diff --git a/repos/gems/src/app/mixer_gui_qt/target.mk b/repos/gems/src/app/mixer_gui_qt/target.mk index 75559f7cd..4d723d2be 100644 --- a/repos/gems/src/app/mixer_gui_qt/target.mk +++ b/repos/gems/src/app/mixer_gui_qt/target.mk @@ -8,4 +8,4 @@ include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc main_window.o: main_window.moc -LIBS += qoost +LIBS += config qoost