[gst-debugger/refactor-v1.0] refactor: restore enum and flags gvalue
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gst-debugger/refactor-v1.0] refactor: restore enum and flags gvalue
- Date: Sat, 3 Oct 2015 10:02:56 +0000 (UTC)
commit 542408629b318ce6fae1333cc43c223178fe2e27
Author: Marcin Kolny <marcin kolny gmail com>
Date: Sat Oct 3 11:46:07 2015 +0200
refactor: restore enum and flags gvalue
src/gst-debugger/Makefile.am | 6 +-
src/gst-debugger/controller/controller.cpp | 20 +++-
src/gst-debugger/gvalue-converter/gvalue_base.cpp | 19 +++-
src/gst-debugger/gvalue-converter/gvalue_base.h | 2 +
.../gvalue-converter/gvalue_boolean.cpp | 1 -
src/gst-debugger/gvalue-converter/gvalue_caps.cpp | 2 +-
src/gst-debugger/gvalue-converter/gvalue_enum.cpp | 126 +++++---------------
src/gst-debugger/gvalue-converter/gvalue_enum.h | 10 +-
src/gst-debugger/gvalue-converter/gvalue_flags.cpp | 117 ++++++++++++++++++
src/gst-debugger/gvalue-converter/gvalue_flags.h | 46 +++++++
.../gvalue-converter/gvalue_numeric.cpp | 1 -
.../gvalue-converter/gvalue_string.cpp | 2 +-
src/gst-debugger/modules/gst_properties_module.cpp | 2 +-
13 files changed, 240 insertions(+), 114 deletions(-)
---
diff --git a/src/gst-debugger/Makefile.am b/src/gst-debugger/Makefile.am
index cfad0a9..f33893a 100644
--- a/src/gst-debugger/Makefile.am
+++ b/src/gst-debugger/Makefile.am
@@ -81,7 +81,11 @@ gst_debugger_ GST_API_VERSION@_SOURCES = \
gvalue-converter/gvalue_caps.cpp \
gvalue-converter/gvalue_caps.h \
gvalue-converter/gvalue_string.cpp \
- gvalue-converter/gvalue_string.h
+ gvalue-converter/gvalue_string.h \
+ gvalue-converter/gvalue_enum.cpp \
+ gvalue-converter/gvalue_enum.h \
+ gvalue-converter/gvalue_flags.cpp \
+ gvalue-converter/gvalue_flags.h
gst_debugger_ GST_API_VERSION@_LDFLAGS = $(GTKMM_LIBS) $(GSTMM_LIBS) $(GVC_LIBS) $(PROTOBUF_LIBS) -lX11
diff --git a/src/gst-debugger/controller/controller.cpp b/src/gst-debugger/controller/controller.cpp
index 043c26c..12c8282 100644
--- a/src/gst-debugger/controller/controller.cpp
+++ b/src/gst-debugger/controller/controller.cpp
@@ -9,6 +9,9 @@
#include "ui_utils.h"
#include "element_path_processor.h"
+#include "gvalue-converter/gvalue_enum.h"
+#include "gvalue-converter/gvalue_flags.h"
+
#include "common/common.h"
#include "common/deserializer.h"
@@ -168,7 +171,8 @@ void Controller::set_selected_object(const std::string &name)
void Controller::update_enum_model(const GstDebugger::EnumFlagsType &enum_type)
{
- GstEnumType et(enum_type.type_name(), G_TYPE_ENUM); // todo G_TYPE_FLAGS
+ GstEnumType et(enum_type.type_name(),
+ enum_type.kind() == GstDebugger::EnumFlagsType_EnumFlagsKind_ENUM ? G_TYPE_ENUM :
G_TYPE_FLAGS);
for (int i = 0; i < enum_type.values_size(); i++)
{
et.add_value(enum_type.values(i).name(), enum_type.values(i).value(),
enum_type.values(i).nick());
@@ -265,6 +269,20 @@ void Controller::add_property(const GstDebugger::PropertyValue &value)
this->send_set_property_command(obj, name, vb->get_gvalue());
});
}
+
+ if (G_TYPE_IS_ENUM(g_val->g_type) || G_TYPE_IS_FLAGS(g_val->g_type))
+ {
+ auto enum_type = get_enum_type(value.value().type_name());
+ if (enum_type)
+ {
+ if (G_TYPE_IS_ENUM(g_val->g_type))
+ std::dynamic_pointer_cast<GValueEnum>(vb)->set_type(enum_type.get());
+ else
+ std::dynamic_pointer_cast<GValueFlags>(vb)->set_type(enum_type.get());
+ }
+ else
+ send_data_type_request_command(value.value().type_name(),
GstDebugger::TypeDescriptionRequest_Type_ENUM_FLAGS);
+ }
}
void Controller::log(const std::string &message)
diff --git a/src/gst-debugger/gvalue-converter/gvalue_base.cpp
b/src/gst-debugger/gvalue-converter/gvalue_base.cpp
index 2c57ce9..2964a81 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_base.cpp
+++ b/src/gst-debugger/gvalue-converter/gvalue_base.cpp
@@ -11,8 +11,8 @@
#include "gvalue_boolean.h"
#include "gvalue_caps.h"
#include "gvalue_string.h"
-/*#include "gvalue_enum.h"
-*/
+#include "gvalue_enum.h"
+#include "gvalue_flags.h"
#include <gst/gst.h>
@@ -64,11 +64,16 @@ GValueBase* GValueBase::build_gvalue(GValue* gobj)
break;
}
- /*if (G_TYPE_IS_ENUM(G_VALUE_TYPE(gobj)) || G_TYPE_IS_FLAGS(G_VALUE_TYPE(gobj)))
+ if (G_TYPE_IS_ENUM(G_VALUE_TYPE(gobj)))
{
return new GValueEnum(gobj);
}
-*/
+
+ if (G_TYPE_IS_FLAGS(G_VALUE_TYPE(gobj)))
+ {
+ return new GValueFlags(gobj);
+ }
+
if (G_VALUE_TYPE(gobj) == GST_TYPE_CAPS)
{
@@ -96,6 +101,7 @@ Gtk::Widget* GValueBase::get_widget()
widgets.push_back(widget);
widget->set_data("is-gvalue-widget", GINT_TO_POINTER(1));
+ update_widget(widget);
return widget;
}
@@ -112,3 +118,8 @@ void GValueBase::update_gvalue(GValue* gobj)
update_widget(widget);
}
+void GValueBase::set_sensitive(bool sensitive)
+{
+ for (auto widget : widgets)
+ widget->set_sensitive(sensitive);
+}
diff --git a/src/gst-debugger/gvalue-converter/gvalue_base.h b/src/gst-debugger/gvalue-converter/gvalue_base.h
index c5fa17e..39e8aeb 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_base.h
+++ b/src/gst-debugger/gvalue-converter/gvalue_base.h
@@ -48,6 +48,8 @@ public:
void update_gvalue(GValue* gobj);
sigc::signal<void> widget_value_changed;
+
+ virtual void set_sensitive(bool sensitive);
};
#endif /* SRC_GST_DEBUGGER_GVALUE_CONVERTER_GVALUE_BASE_H_ */
diff --git a/src/gst-debugger/gvalue-converter/gvalue_boolean.cpp
b/src/gst-debugger/gvalue-converter/gvalue_boolean.cpp
index b231d9b..7c73dd5 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_boolean.cpp
+++ b/src/gst-debugger/gvalue-converter/gvalue_boolean.cpp
@@ -34,7 +34,6 @@ Gtk::Widget* GValueBoolean::create_widget()
cb->signal_toggled().connect([this, cb]{ g_value_set_boolean(g_value, cb->get_active()); });
cb->signal_toggled().connect(widget_value_changed);
- update_widget(cb);
return cb;
}
diff --git a/src/gst-debugger/gvalue-converter/gvalue_caps.cpp
b/src/gst-debugger/gvalue-converter/gvalue_caps.cpp
index c1d15f9..a13f9cd 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_caps.cpp
+++ b/src/gst-debugger/gvalue-converter/gvalue_caps.cpp
@@ -33,7 +33,7 @@ Gtk::Widget* GValueCaps::create_widget()
});
entry->signal_activate().connect(widget_value_changed);
- update_widget(entry);
+
return entry;
}
diff --git a/src/gst-debugger/gvalue-converter/gvalue_enum.cpp
b/src/gst-debugger/gvalue-converter/gvalue_enum.cpp
index 220ee93..856facf 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_enum.cpp
+++ b/src/gst-debugger/gvalue-converter/gvalue_enum.cpp
@@ -17,137 +17,67 @@ GValueEnum::GValueEnum(GValue *gobj)
gint GValueEnum::get_value() const
{
- return G_TYPE_IS_ENUM(G_VALUE_TYPE(g_value)) ? g_value_get_enum(g_value) : g_value_get_flags(g_value);
-}
-
-void GValueEnum::set_type(GstEnumType type)
-{
- this->type = type;
-}
-
-template<typename T>
-void append_to_vector(std::vector<std::pair<int, std::string>>& values, T *enum_values)
-{
- int i = 0;
-
- while (enum_values[i].value_name)
- {
- values.push_back(std::make_pair(enum_values[i].value, enum_values[i].value_nick));
- i++;
- }
+ return g_value_get_enum(g_value);
}
std::string GValueEnum::to_string() const
{
- if (G_VALUE_TYPE(g_value) == gst_utils_get_virtual_enum_type() || G_VALUE_TYPE(g_value) ==
gst_utils_get_virtual_flags_type())
+ gint value = get_value();
+ if (!type)
{
- gint value = get_value();
- if (!type)
- {
- return std::to_string(value);
- }
- try
- {
- return type.get().get_values().at(value).nick;
- }
- catch (const std::out_of_range&)
- {
- return std::to_string(value);
- }
+ return std::to_string(value) + " (press 'refresh' button)";
}
-
- gpointer ptr = g_type_class_ref(G_VALUE_TYPE(g_value));
- if (G_IS_ENUM_CLASS(ptr))
+ try
{
- Glib::Value_Enum<int> v;
- v.init(g_value);
- return G_ENUM_CLASS (ptr)->values[v.get()].value_nick;
+ return type.get().get_values().at(value).nick;
}
- else
+ catch (const std::out_of_range&)
{
- Glib::Value_Flags<int> v;
- v.init(g_value);
- return G_FLAGS_CLASS (ptr)->values[v.get()].value_nick;
+ return std::to_string(value);
}
}
-std::vector<std::pair<int, std::string>> GValueEnum::get_values(GType type)
+Gtk::Widget* GValueEnum::create_widget()
{
- std::vector<std::pair<int, std::string>> values;
- gpointer ptr = g_type_class_ref(type);
-
- if (G_IS_ENUM_CLASS (ptr))
+ if (type)
{
- append_to_vector(values, G_ENUM_CLASS (ptr)->values);
+ Gtk::ComboBoxText *widget = new Gtk::ComboBoxText();
+ widget->signal_changed().connect([this, widget]{
+ g_value_set_enum(g_value, gtk_combo_box_get_active(GTK_COMBO_BOX(widget->gobj())));
+ });
+ widget->signal_changed().connect(widget_value_changed);
+
+ for (auto entry : type.get().get_values())
+ {
+ widget->append(entry.second.nick);
+ }
+
+ return widget;
}
else
{
- append_to_vector(values, G_FLAGS_CLASS (ptr)->values);
+ return new Gtk::Label();
}
-
- return values;
}
-Gtk::Widget* GValueEnum::get_widget() const
+void GValueEnum::update_widget(Gtk::Widget* widget)
{
- if (type && G_VALUE_TYPE(g_value) == gst_utils_get_virtual_enum_type())
+ if (dynamic_cast<Gtk::ComboBoxText*>(widget))
{
- Gtk::ComboBoxText *cb;
- if (widget == nullptr || !dynamic_cast<Gtk::ComboBoxText*>(widget))
- {
- delete widget;
- widget = cb = new Gtk::ComboBoxText();
- cb->signal_changed().connect([this]{ g_value_set_enum(g_value,
gtk_combo_box_get_active(GTK_COMBO_BOX(dynamic_cast<Gtk::ComboBoxText*>(widget)->gobj())));} );
- cb->signal_changed().connect(widget_value_changed);
- }
- else
- {
- cb = dynamic_cast<Gtk::ComboBoxText*>(widget);
- }
gint pos = 0;
gint value = get_value();
for (auto entry : type.get().get_values())
{
- cb->append(entry.second.nick);
if (entry.first == value)
{
- cb->set_active(pos);
+ dynamic_cast<Gtk::ComboBoxText*>(widget)->set_active(pos);
+ break;
}
pos++;
}
-
- return widget;
- }
- else if (type && G_VALUE_TYPE(g_value) == gst_utils_get_virtual_flags_type())
- {
- if (widget == nullptr)
- {
- widget = new Gtk::ScrolledWindow();
- Gtk::Viewport *vp = Gtk::manage(new Gtk::Viewport(Gtk::Adjustment::create(10, 0, 20),
Gtk::Adjustment::create(10, 0, 50)));
- vp->show();
- Gtk::Box *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0));
- gint fv = get_value();
- auto values = type->get_values();
- for (auto val : values)
- {
- auto cb = Gtk::manage(new Gtk::CheckButton(val.second.nick));
- cb->set_active(val.first & fv);
- cb->show();
- box->pack_start(*cb, false, 5);
- }
- box->show();
- vp->add(*box);
- dynamic_cast<Gtk::ScrolledWindow*>(widget)->add(*vp);
- }
- return widget;
}
else
{
- if (widget == nullptr)
- {
- widget = new Gtk::Entry();
- }
- dynamic_cast<Gtk::Entry*>(widget)->set_text(to_string());
- return widget;
+ dynamic_cast<Gtk::Label*>(widget)->set_text(to_string());
}
}
diff --git a/src/gst-debugger/gvalue-converter/gvalue_enum.h b/src/gst-debugger/gvalue-converter/gvalue_enum.h
index 000340e..1e334c9 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_enum.h
+++ b/src/gst-debugger/gvalue-converter/gvalue_enum.h
@@ -21,18 +21,18 @@ class GValueEnum : public GValueBase
{
boost::optional<GstEnumType> type;
+ Gtk::Widget* create_widget() override;
+
+ void update_widget(Gtk::Widget* widget) override;
+
public:
GValueEnum(GValue* gobj);
- void set_type(GstEnumType type);
+ void set_type(GstEnumType type) { this->type = type; }
std::string to_string() const override;
gint get_value() const;
-
- static std::vector<std::pair<int, std::string>> get_values(GType type);
-
- Gtk::Widget* get_widget() const override;
};
#endif /* SRC_GST_DEBUGGER_GVALUE_CONVERTER_GVALUE_ENUM_H_ */
diff --git a/src/gst-debugger/gvalue-converter/gvalue_flags.cpp
b/src/gst-debugger/gvalue-converter/gvalue_flags.cpp
new file mode 100644
index 0000000..3fb004f
--- /dev/null
+++ b/src/gst-debugger/gvalue-converter/gvalue_flags.cpp
@@ -0,0 +1,117 @@
+/*
+ * gvalue_flags.cpp
+ *
+ * Created on: Oct 2, 2015
+ * Author: loganek
+ */
+
+#include "gvalue_flags.h"
+#include "ui_utils.h"
+
+#include "common/gst-utils.h"
+
+#include <glibmm.h>
+
+GValueFlags::GValueFlags(GValue *gobj)
+: GValueBase(gobj)
+{}
+
+gint GValueFlags::get_value() const
+{
+ return g_value_get_flags(g_value);
+}
+
+std::string GValueFlags::to_string() const
+{
+ gint value = get_value();
+ if (!type)
+ {
+ return flags_value_to_string(value) + " (press 'refresh' button)";
+ }
+ try
+ {
+ return type.get().get_values().at(value).nick;
+ }
+ catch (const std::out_of_range&)
+ {
+ return std::to_string(value);
+ }
+}
+
+Gtk::Widget* GValueFlags::create_widget()
+{
+ if (type)
+ {
+ auto widget = new Gtk::ScrolledWindow();
+ Gtk::Viewport *vp = Gtk::manage(new Gtk::Viewport(Gtk::Adjustment::create(10, 0, 20),
Gtk::Adjustment::create(10, 0, 50)));
+ Gtk::Box *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0));
+ for (auto val : type->get_values())
+ {
+ if (val.first == -1) continue;
+ auto cb = Gtk::manage(new Gtk::CheckButton(val.second.nick));
+ cb->signal_clicked().connect([this, cb]{
+ if (!emit_m.try_lock()) return;
+ if (cb->get_active())
+ g_value_set_flags(g_value, get_value() |
GPOINTER_TO_INT(cb->get_data("flags-data-value")));
+ else
+ g_value_set_flags(g_value, get_value() &
~GPOINTER_TO_INT(cb->get_data("flags-data-value")));
+ widget_value_changed();
+ emit_m.unlock();
+ });
+ cb->set_data("flags-data-value", GINT_TO_POINTER(val.first));
+ box->pack_start(*cb, false, 5);
+ }
+ update_widget(widget);
+ vp->add(*box);
+ widget->add(*vp);
+ widget->show_all();
+
+ return widget;
+ }
+ else
+ {
+ return new Gtk::Label();
+ }
+}
+
+Gtk::Box* GValueFlags::get_internal_box(Gtk::Widget *widget)
+{
+ auto vp = dynamic_cast<Gtk::ScrolledWindow*>(widget)->get_child();
+ if (!vp) return nullptr;
+ auto bx = dynamic_cast<Gtk::Viewport*>(vp)->get_child();
+ return dynamic_cast<Gtk::Box*>(bx);
+}
+
+void GValueFlags::update_widget(Gtk::Widget* widget)
+{
+ if (dynamic_cast<Gtk::ScrolledWindow*>(widget))
+ {
+ auto box = get_internal_box(widget);
+ if (!box) return;
+ gint value = get_value();
+ for (auto w : box->get_children())
+ {
+ auto cb = dynamic_cast<Gtk::CheckButton*>(w);
+ if (!cb) continue;
+ int val = GPOINTER_TO_INT(cb->get_data("flags-data-value"));
+ emit_m.lock();
+ cb->set_active(val & value);
+ emit_m.unlock();
+ }
+ }
+ else
+ {
+ dynamic_cast<Gtk::Label*>(widget)->set_text(to_string());
+ }
+}
+
+void GValueFlags::set_sensitive(bool sensitive)
+{
+ for (auto widget : widgets)
+ {
+ auto box = get_internal_box(widget);
+ if (!box) continue;
+ for (auto w : box->get_children())
+ w->set_sensitive(sensitive);
+ }
+}
diff --git a/src/gst-debugger/gvalue-converter/gvalue_flags.h
b/src/gst-debugger/gvalue-converter/gvalue_flags.h
new file mode 100644
index 0000000..33f25a9
--- /dev/null
+++ b/src/gst-debugger/gvalue-converter/gvalue_flags.h
@@ -0,0 +1,46 @@
+/*
+ * gvalue_flags.h
+ *
+ * Created on: Oct 2, 2015
+ * Author: loganek
+ */
+
+#ifndef SRC_GST_DEBUGGER_GVALUE_CONVERTER_GVALUE_FLAGS_H_
+#define SRC_GST_DEBUGGER_GVALUE_CONVERTER_GVALUE_FLAGS_H_
+
+#include "gvalue_base.h"
+
+#include "../models/gst_enum_model.h"
+
+#include <boost/optional/optional.hpp>
+#include <mutex>
+
+#include <vector>
+#include <utility>
+
+class GValueFlags : public GValueBase
+{
+ std::mutex emit_m;
+ boost::optional<GstEnumType> type;
+
+ Gtk::Widget* create_widget() override;
+
+ void update_widget(Gtk::Widget* widget) override;
+
+ Gtk::Box* get_internal_box(Gtk::Widget* widget);
+
+public:
+ GValueFlags(GValue* gobj);
+
+ void set_type(GstEnumType type) { this->type = type; }
+
+ std::string to_string() const override;
+
+ gint get_value() const;
+
+ void set_sensitive(bool sensitive) override;
+
+ static std::vector<std::pair<int, std::string>> get_values(GType type);
+};
+
+#endif /* SRC_GST_DEBUGGER_GVALUE_CONVERTER_GVALUE_FLAGS_H_ */
diff --git a/src/gst-debugger/gvalue-converter/gvalue_numeric.cpp
b/src/gst-debugger/gvalue-converter/gvalue_numeric.cpp
index 3d67a4e..0dc2d18 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_numeric.cpp
+++ b/src/gst-debugger/gvalue-converter/gvalue_numeric.cpp
@@ -49,7 +49,6 @@ Gtk::Widget* GValueNumeric<T>::create_widget()
});
entry->signal_activate().connect(widget_value_changed);
- update_widget(entry);
return entry;
}
diff --git a/src/gst-debugger/gvalue-converter/gvalue_string.cpp
b/src/gst-debugger/gvalue-converter/gvalue_string.cpp
index e143a33..68ded51 100644
--- a/src/gst-debugger/gvalue-converter/gvalue_string.cpp
+++ b/src/gst-debugger/gvalue-converter/gvalue_string.cpp
@@ -30,7 +30,7 @@ Gtk::Widget* GValueString::create_widget()
});
entry->signal_activate().connect(widget_value_changed);
- update_widget(entry);
+
return entry;
}
diff --git a/src/gst-debugger/modules/gst_properties_module.cpp
b/src/gst-debugger/modules/gst_properties_module.cpp
index 405bbc5..44d81a1 100644
--- a/src/gst-debugger/modules/gst_properties_module.cpp
+++ b/src/gst-debugger/modules/gst_properties_module.cpp
@@ -138,7 +138,7 @@ void GstPropertiesModule::append_property(const std::shared_ptr<GValueBase>& val
btn->signal_clicked().connect([this, prop_name] {request_selected_element_property(prop_name);});
hbox->pack_start(*lbl, false, false);
auto value_widget = value_base->get_widget();
- value_widget->set_sensitive(prop.get().get_flags() & G_PARAM_WRITABLE);
+ value_base->set_sensitive(prop.get().get_flags() & G_PARAM_WRITABLE);
hbox->pack_start(*value_widget, true, true);
hbox->pack_start(*btn, false, false);
properties_box->pack_start(*hbox);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]