Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

add glib.Object.GetProperty and glib.Object.SetProperty #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions glib/glib.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,55 @@ func (v *Object) Set(name string, value interface{}) error {
return nil
}

func (v *Object) GetPropertyType(name string) (Type, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here for godoc.

cstr := C.CString(name)
defer C.free(unsafe.Pointer(cstr))

paramSpec := C.g_object_class_find_property(C._g_object_get_class(v.native()), (*C.gchar)(cstr))
if paramSpec == nil {
return TYPE_INVALID, errors.New("couldn't find Property")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this whitespace.

}
return Type(paramSpec.value_type), nil

}

// Wrapper around g_object_get_property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be in the from "// FuncName ..." and end with a period.

func (v *Object) GetProperty(name string) (interface{}, error) {
cstr := C.CString(name)
defer C.free(unsafe.Pointer(cstr))

t, err := v.GetPropertyType(name)
if err != nil {
return nil, err
}

p, err := ValueInit(t)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this whitespace.

if err != nil {
return nil, errors.New("Unable to allocate value")
}
C.g_object_get_property(v.GObject, (*C.gchar)(cstr), p.native())
return p.GoValue()
}

// Wrapper around g_object_set_property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be in the from "// FuncName ..." and end with a period.

func (v *Object) SetProperty(name string, value interface{}) error {
cstr := C.CString(name)
defer C.free(unsafe.Pointer(cstr))

if _, ok := value.(Object); ok {
value = value.(Object).GObject
}

p, err := GValue(value)
if err != nil {
return errors.New("Unable to perform type conversion")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not capitalize error strings.

}
C.g_object_set_property(v.GObject, (*C.gchar)(cstr), p.native())
return nil
}

// pointerVal attempts to return an unsafe.Pointer for value.
// Not all types are understood, in which case a nil Pointer
// is returned.
Expand Down
6 changes: 6 additions & 0 deletions glib/glib.go.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ _g_value_fundamental(GType type)
return (G_TYPE_FUNDAMENTAL(type));
}

static GObjectClass *
_g_object_get_class (GObject *object)
{
return (G_OBJECT_GET_CLASS(object));
}

/*
* Closure support
*/
Expand Down