#include <pv/binding/decoder.hpp>
#include <pv/data/decode/decoder.hpp>
#include <pv/data/decode/row.hpp>
+#include <pv/globalsettings.hpp>
#include <pv/session.hpp>
using std::lock_guard;
settings.setValue("id", decoder->decoder()->id);
+ // Save decoder options
+ const map<string, GVariant*>& options = decoder->options();
+
+ settings.setValue("options", (int)options.size());
+
+ // Note: decode::Decoder::options() returns only the options
+ // that differ from the default. See binding::Decoder::getter()
+ int i = 0;
+ for (auto option : options) {
+ settings.beginGroup("option" + QString::number(i));
+ settings.setValue("name", QString::fromStdString(option.first));
+ GlobalSettings::store_gvariant(settings, option.second);
+ settings.endGroup();
+ i++;
+ }
+
settings.endGroup();
}
settings.endGroup();
}
-
- // TODO Save decoder options
}
void DecodeSignal::restore_settings(QSettings &settings)
continue;
if (QString::fromUtf8(dec->id) == id) {
- stack_.push_back(make_shared<decode::Decoder>(dec));
+ shared_ptr<decode::Decoder> decoder =
+ make_shared<decode::Decoder>(dec);
+
+ stack_.push_back(decoder);
+
+ // Restore decoder options that differ from their default
+ int options = settings.value("options").toInt();
+
+ for (int i = 0; i < options; i++) {
+ settings.beginGroup("option" + QString::number(i));
+ QString name = settings.value("name").toString();
+ GVariant *value = GlobalSettings::restore_gvariant(settings);
+ decoder->set_option(name.toUtf8(), value);
+ settings.endGroup();
+ }
// Include the newly created decode channels in the channel lists
update_channel_list();
}
begin_decode();
-
- // TODO Restore decoder options
}
void DecodeSignal::update_channel_list()
#include "globalsettings.hpp"
+#include <QByteArray>
+#include <QString>
+
using std::function;
using std::map;
using std::multimap;
tracked_changes_.clear();
}
+void GlobalSettings::store_gvariant(QSettings &settings, GVariant *v)
+{
+ const GVariantType *var_type = g_variant_get_type(v);
+ char *var_type_str = g_variant_type_dup_string(var_type);
+
+ QByteArray var_data = QByteArray((const char*)g_variant_get_data(v),
+ g_variant_get_size(v));
+
+ settings.setValue("value", var_data);
+ settings.setValue("type", var_type_str);
+
+ g_free(var_type_str);
+}
+
+GVariant* GlobalSettings::restore_gvariant(QSettings &settings)
+{
+ QString raw_type = settings.value("type").toString();
+ GVariantType *var_type = g_variant_type_new(raw_type.toUtf8());
+
+ QByteArray data = settings.value("value").toByteArray();
+
+ gpointer var_data = g_memdup((gconstpointer)data.constData(),
+ (guint)data.size());
+
+ GVariant *value = g_variant_new_from_data(var_type, var_data,
+ data.size(), false, g_free, var_data);
+
+ g_variant_type_free(var_type);
+
+ return value;
+}
+
+
} // namespace pv