[glibmm] tests/glibmm_interface_implementation: Use the new base class order
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] tests/glibmm_interface_implementation: Use the new base class order
- Date: Tue, 10 Jun 2014 08:21:57 +0000 (UTC)
commit 99d79453da0630cf2eb205658bdeef0131b1026f
Author: José Alburquerque <jaalburquerque gmail com>
Date: Tue Jun 10 10:12:54 2014 +0200
tests/glibmm_interface_implementation: Use the new base class order
* tests/glibmm_interface_implementation/main.cc: Interface before
Glib::Object in the list of base classes. Test a custom property and
an interface with properties.
This patch is almost identical to the attachment in bug 697229 comment 14.
tests/glibmm_interface_implementation/main.cc | 53 ++++++++++++++++++-------
1 files changed, 38 insertions(+), 15 deletions(-)
---
diff --git a/tests/glibmm_interface_implementation/main.cc b/tests/glibmm_interface_implementation/main.cc
index dfbb716..bc8253b 100644
--- a/tests/glibmm_interface_implementation/main.cc
+++ b/tests/glibmm_interface_implementation/main.cc
@@ -2,30 +2,34 @@
#include <giomm.h> //There are no Interfaces in glibmm, but there are in giomm.
#include <iostream>
-//TODO: I also tried Glib::Action, but that needs us to implement interface properties. murrayc
-class CustomConverter :
- public Glib::Object,
- public Gio::Converter
+class CustomAction :
+ public Gio::Action,
+ public Glib::Object
{
public:
- CustomConverter();
+ CustomAction();
+
+ // A custom property.
+ Glib::Property<Glib::ustring> property;
protected:
//Implement a vfunc:
- virtual void reset_vfunc();
+ virtual Glib::ustring get_name_vfunc() const;
};
-CustomConverter::CustomConverter()
-: Glib::ObjectBase( typeid(CustomConverter) ),
- Glib::Object()
+CustomAction::CustomAction()
+: Glib::ObjectBase( typeid(CustomAction) ),
+ Glib::Object(),
+ property(*this, "custom_property", "Initial value.")
{
}
-static bool reset_called = false;
+static bool get_name_called = false;
-void CustomConverter::reset_vfunc()
+Glib::ustring CustomAction::get_name_vfunc() const
{
- reset_called = true;
+ get_name_called = true;
+ return "custom-name";
}
@@ -33,9 +37,28 @@ int main(int, char**)
{
Glib::init();
- CustomConverter converter;
- converter.reset();
- g_assert(reset_called);
+ CustomAction action;
+ Glib::ustring name = action.get_name();
+ std::cout << "The name is '" << name << "'." << std::endl;
+ std::cout << "The name property of the implemented interface is '"
+ << action.property_name().get_value() << "'." << std::endl;
+ std::cout << "The custom string property is '"
+ << action.property.get_value() << "'." << std::endl;
+
+ action.property = "A new value.";
+ std::cout << "The custom string property (after changing it) is '"
+ << action.property.get_value() << "'." << std::endl;
+
+ gchar* prop_value = 0;
+ g_object_set(action.gobj(), "custom_property", "Another value", NULL);
+ g_object_get(action.gobj(), "custom_property", &prop_value, NULL);
+ std::cout << "The custom property after g_object_get/set() is '"
+ << prop_value << "'." << std::endl;
+ std::cout << "The custom property through the Glib::Property<> is '"
+ << action.property.get_value() << "'." << std::endl;
+ std::cout << "The name property of the implemented interface is '"
+ << action.property_name().get_value() << "'." << std::endl;
+ g_assert(get_name_called);
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]