QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
object.cpp
00001 /*
00002     Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
00003     Copyright (C) 2010 Collabora Ltd.
00004       @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
00005 
00006     This library is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published
00008     by the Free Software Foundation; either version 2.1 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #include "object.h"
00020 #include "quark.h"
00021 #include <glib-object.h>
00022 
00023 namespace QGlib {
00024 namespace Private {
00025 
00026 template <class T>
00027 QList< RefPointer<T> > arrayToList(typename T::CType **array, uint n)
00028 {
00029     QList< RefPointer<T> > result;
00030     for(uint i = 0; i<n; ++i) {
00031         result.append(RefPointer<T>::wrap(array[i]));
00032     }
00033     return result;
00034 }
00035 
00036 } //namespace Private
00037 
00038 
00039 ParamSpecPtr ObjectBase::findProperty(const char *name) const
00040 {
00041     GObjectClass *klass = G_OBJECT_CLASS(g_type_class_ref(Type::fromInstance(object<void>())));
00042     GParamSpec *param = g_object_class_find_property(klass, name);
00043     g_type_class_unref(klass);
00044     if (param) {
00045         return ParamSpecPtr::wrap(g_param_spec_ref_sink(param), false);
00046     } else {
00047         return ParamSpecPtr();
00048     }
00049 }
00050 
00051 QList<ParamSpecPtr> ObjectBase::listProperties() const
00052 {
00053     GObjectClass *klass = G_OBJECT_CLASS(g_type_class_ref(Type::fromInstance(object<void>())));
00054     uint n;
00055     GParamSpec **param = g_object_class_list_properties(klass, &n);
00056     g_type_class_unref(klass);
00057     QList<ParamSpecPtr> result = QGlib::Private::arrayToList<ParamSpec>(param, n);
00058     g_free(param);
00059     return result;
00060 }
00061 
00062 Value ObjectBase::property(const char *name) const
00063 {
00064     Value result;
00065     ParamSpecPtr param = findProperty(name);
00066     if (param && (param->flags() & ParamSpec::Readable)) {
00067         result.init(param->valueType());
00068         g_object_get_property(object<GObject>(), name, result);
00069     }
00070     return result;
00071 }
00072 
00073 void ObjectBase::setProperty(const char *name, const Value & value)
00074 {
00075     g_object_set_property(object<GObject>(), name, value);
00076 }
00077 
00078 void *ObjectBase::data(const char *key) const
00079 {
00080     return g_object_get_data(object<GObject>(), key);
00081 }
00082 
00083 void *ObjectBase::stealData(const char *key) const
00084 {
00085     return g_object_steal_data(object<GObject>(), key);
00086 }
00087 
00088 void ObjectBase::setData(const char *key, void *data, void (*destroyCallback)(void*))
00089 {
00090     g_object_set_data_full(object<GObject>(), key, data, destroyCallback);
00091 }
00092 
00093 void *ObjectBase::quarkData(const Quark & quark) const
00094 {
00095     return g_object_get_qdata(object<GObject>(), quark);
00096 }
00097 
00098 void *ObjectBase::stealQuarkData(const Quark & quark) const
00099 {
00100     return g_object_steal_qdata(object<GObject>(), quark);
00101 }
00102 
00103 void ObjectBase::setQuarkData(const Quark & quark, void *data, void (*destroyCallback)(void*))
00104 {
00105     g_object_set_qdata_full(object<GObject>(), quark, data, destroyCallback);
00106 }
00107 
00108 void ObjectBase::ref(bool increaseRef)
00109 {
00110     if (increaseRef) {
00111         g_object_ref(m_object);
00112     }
00113 }
00114 
00115 void ObjectBase::unref()
00116 {
00117     g_object_unref(m_object);
00118 }
00119 
00120 }