QtGStreamer 1.2.0
Loading...
Searching...
No Matches
object.cpp
1/*
2 Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 Copyright (C) 2010 Collabora Ltd.
4 @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
5
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "object.h"
20#include "quark.h"
21#include <glib-object.h>
22
23namespace QGlib {
24namespace Private {
25
26template <class T>
27QList< RefPointer<T> > arrayToList(typename T::CType **array, uint n)
28{
29 QList< RefPointer<T> > result;
30 for(uint i = 0; i<n; ++i) {
31 result.append(RefPointer<T>::wrap(array[i]));
32 }
33 return result;
34}
35
36} //namespace Private
37
38
40{
41 GObjectClass *klass = G_OBJECT_CLASS(g_type_class_ref(Type::fromInstance(object<void>())));
42 GParamSpec *param = g_object_class_find_property(klass, name);
43 g_type_class_unref(klass);
44 if (param) {
45 return ParamSpecPtr::wrap(g_param_spec_ref_sink(param), false);
46 } else {
47 return ParamSpecPtr();
48 }
49}
50
51QList<ParamSpecPtr> ObjectBase::listProperties() const
52{
53 GObjectClass *klass = G_OBJECT_CLASS(g_type_class_ref(Type::fromInstance(object<void>())));
54 uint n;
55 GParamSpec **param = g_object_class_list_properties(klass, &n);
56 g_type_class_unref(klass);
57 QList<ParamSpecPtr> result = QGlib::Private::arrayToList<ParamSpec>(param, n);
58 g_free(param);
59 return result;
60}
61
62Value ObjectBase::property(const char *name) const
63{
64 Value result;
65 ParamSpecPtr param = findProperty(name);
66 if (param && (param->flags() & ParamSpec::Readable)) {
67 result.init(param->valueType());
68 g_object_get_property(object<GObject>(), name, result);
69 }
70 return result;
71}
72
73void ObjectBase::setProperty(const char *name, const Value & value)
74{
75 g_object_set_property(object<GObject>(), name, value);
76}
77
78void *ObjectBase::data(const char *key) const
79{
80 return g_object_get_data(object<GObject>(), key);
81}
82
83void *ObjectBase::stealData(const char *key) const
84{
85 return g_object_steal_data(object<GObject>(), key);
86}
87
88void ObjectBase::setData(const char *key, void *data, void (*destroyCallback)(void*))
89{
90 g_object_set_data_full(object<GObject>(), key, data, destroyCallback);
91}
92
93void *ObjectBase::quarkData(const Quark & quark) const
94{
95 return g_object_get_qdata(object<GObject>(), quark);
96}
97
98void *ObjectBase::stealQuarkData(const Quark & quark) const
99{
100 return g_object_steal_qdata(object<GObject>(), quark);
101}
102
103void ObjectBase::setQuarkData(const Quark & quark, void *data, void (*destroyCallback)(void*))
104{
105 g_object_set_qdata_full(object<GObject>(), quark, data, destroyCallback);
106}
107
108void ObjectBase::ref(bool increaseRef)
109{
110 if (increaseRef) {
111 g_object_ref(m_object);
112 }
113}
114
115void ObjectBase::unref()
116{
117 g_object_unref(m_object);
118}
119
120}
Value property(const char *name) const
Definition object.cpp:62
ParamSpecPtr findProperty(const char *name) const
Definition object.cpp:39
void setProperty(const char *name, const T &value)
Definition object.h:106
QList< ParamSpecPtr > listProperties() const
Definition object.cpp:51
Smart pointer class for working with wrapper classes that support reference counting.
Definition refpointer.h:91
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
Definition refpointer.h:328
Wrapper class for GValue.
Definition value.h:77
void init(Type type)
Definition value.cpp:241
Wrappers for Glib and GObject classes.