static VALUE gobj_s_property(VALUE self, VALUE property_name) { GObjectClass* oclass; const char* name; GParamSpec* prop; VALUE result; if (SYMBOL_P(property_name)) name = rb_id2name(SYM2ID(property_name)); else name = StringValuePtr(property_name); oclass = g_type_class_ref(CLASS2GTYPE(self)); prop = g_object_class_find_property(oclass, name); if (!prop){ g_type_class_unref(oclass); rb_raise(eNoPropertyError, "No such property: %s", name); } result = GOBJ2RVAL(prop); g_type_class_unref(oclass); return result; }
static VALUE rg_prepend_type(VALUE self, VALUE type) { gtk_widget_path_prepend_type(_SELF(self), CLASS2GTYPE(type)); return self; }
static VALUE interface_s_property(VALUE self, VALUE property_name) { gpointer ginterface; const char* name; GParamSpec* prop; VALUE result; GType gtype = CLASS2GTYPE(self); if (SYMBOL_P(property_name)) name = rb_id2name(SYM2ID(property_name)); else name = StringValuePtr(property_name); if (!G_TYPE_IS_INTERFACE(gtype)) rb_raise(rb_eTypeError, "%s isn't interface module", rb_class2name(self)); /* XXX: g_type_default_interface_ref(G_TYPE_INTERFACE) causes SEGV. */ if (gtype == G_TYPE_INTERFACE) { rb_raise(rb_const_get(mGLib, rb_intern("NoPropertyError")), "No such property: %s", name); } ginterface = g_type_default_interface_ref(gtype); prop = g_object_interface_find_property(ginterface, name); if (!prop){ g_type_default_interface_unref(ginterface); rb_raise(rb_const_get(mGLib, rb_intern("NoPropertyError")), "No such property: %s", name); } result = GOBJ2RVAL(prop); g_type_default_interface_unref(ginterface); return result; }
void rbgobj_init_object_class(VALUE klass) { rbgobj_define_property_accessors(klass); if (G_TYPE_IS_ABSTRACT(CLASS2GTYPE(klass))) rb_define_method(klass, "initialize", dummy_init, -1); }
/* * Method: get_child(index) * Method: get_child(name, recurse=false) * Method: get_child(interface) * index: an index. * name: a name. * recurse: search recursively. * interface: an interface (Ruby class). * * 1st: Gets the index-th element. * * 2nd: Gets the element with the given name from the * bin, as a reference to a Gst::Element object. If the * element is not found and recurse is true, a recursion is * performed on the parent bin. * * 3nd: Looks for the first element inside the bin that implements the * given interface. If such an element is found, it returns the element. * If you want all elements that implement the interface, use * Gst::Bin#get_all_by_interface. The method recurses bins inside bins. * * Returns: a Gst::Element reference, or nil if the bin does not contain * an element with the given name nor implementing the interface. */ static VALUE rb_gst_bin_get(int argc, VALUE *argv, VALUE self) { VALUE index_or_name_or_interface, recurse; GstElement *element = NULL; rb_scan_args(argc, argv, "11", &index_or_name_or_interface, &recurse); if (RVAL2CBOOL(rb_obj_is_kind_of(index_or_name_or_interface, rb_cInteger))) { int index; GList *node; index = NUM2INT(index_or_name_or_interface); node = g_list_nth(GST_BIN_CHILDREN(SELF(self)), index); if (node) element = node->data; } else if (RVAL2CBOOL(rb_obj_is_kind_of(index_or_name_or_interface, rb_cString))) { char *name; name = RVAL2CSTR(index_or_name_or_interface); if (RVAL2CBOOL(recurse)) { element = gst_bin_get_by_name_recurse_up(SELF(self), name); } else { element = gst_bin_get_by_name(SELF(self), name); } } else { GType iface; iface = CLASS2GTYPE(index_or_name_or_interface); element = gst_bin_get_by_interface(SELF(self), iface); } return GST_ELEMENT2RVAL(element); }
static VALUE interface_s_properties(int argc, VALUE* argv, VALUE self) { guint n_properties; GParamSpec** props; VALUE inherited_too; VALUE ary = rb_ary_new(); guint i; gpointer ginterface; GType gtype = CLASS2GTYPE(self); if (rb_scan_args(argc, argv, "01", &inherited_too) == 0) inherited_too = Qtrue; if (!G_TYPE_IS_INTERFACE(gtype)) rb_raise(rb_eTypeError, "%s isn't interface module", rb_class2name(self)); /* XXX: g_type_default_interface_ref(G_TYPE_INTERFACE) causes SEGV. */ if (gtype == G_TYPE_INTERFACE) return ary; ginterface = g_type_default_interface_ref(gtype); props = g_object_interface_list_properties(ginterface, &n_properties); for (i = 0; i < n_properties; i++){ if (RVAL2CBOOL(inherited_too) || GTYPE2CLASS(props[i]->owner_type) == self) rb_ary_push(ary, rb_str_new2(props[i]->name)); } g_free(props); g_type_default_interface_unref(ginterface); return ary; }
void _rbgst_define_class_if_need(VALUE klass, GType type, const gchar *prefix) { VALUE parent; const gchar *type_name; gchar *class_name = NULL; static ID id_gtype = 0; if (rb_class2name(klass)[0] != '#') return; type_name = g_type_name(type); if (g_str_has_prefix(type_name, "Gst")) type_name += 3; if (prefix) class_name = g_strconcat(prefix, type_name, NULL); G_DEF_CLASS(type, class_name ? class_name : type_name, mGst); g_free(class_name); parent = rb_ary_entry(rb_mod_ancestors(klass), 1); if (!id_gtype) id_gtype = rb_intern("gtype"); if (rb_respond_to(parent, id_gtype)) _rbgst_define_class_if_need(parent, CLASS2GTYPE(parent), prefix); }
static VALUE rg_m_get_style_by_paths(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self) { VALUE settings, widget_path, class_path, klass; GtkStyle* style; GType gtype; const gchar* name; rb_scan_args(argc, argv, "13", &settings, &widget_path, &class_path, &klass); style = gtk_rc_get_style_by_paths(GTK_SETTINGS(RVAL2GOBJ(settings)), NIL_P(widget_path) ? NULL : RVAL2CSTR(widget_path), NIL_P(class_path) ? NULL : RVAL2CSTR(class_path), NIL_P(klass) ? G_TYPE_NONE : CLASS2GTYPE(klass)); if (style){ gtype = G_OBJECT_TYPE(style); name = G_OBJECT_TYPE_NAME(style); if (! rb_const_defined_at(mGtk, rb_intern(name))){ G_DEF_CLASS(gtype, (gchar*)name, mGtk); } return GOBJ2RVAL(style); } return Qnil; }
/* * Method: add(id, *args) * id: the ID of the index writer. * args: additional parameters, see below. * * Adds an entry into the index. The type of the entry depends of * the number and kind of additional parameters. * * * For an ID type, args must be a String. * * For a FORMAT type, args must be a Gst::Format. * * For an ASSOCIATION type, args must contains an association flag (see Gst::Index::AssocFlags), a Gst::Format and a value for the format. * * For an OBJECT type, well you must wait, because it is not yet implemented. * * Returns: a reference to the newly allocated entry in the index, as a Gst::EntryIndex object. */ static VALUE rb_gst_index_add (int argc, VALUE * argv, VALUE self) { GstIndexEntry *index_entry; VALUE id; if (argc == 2) { VALUE var; rb_scan_args (argc, argv, "2", &id, &var); index_entry = CLASS2GTYPE (CLASS_OF (var)) == GST_TYPE_FORMAT2 ? gst_index_add_format (RGST_INDEX (self), FIX2INT (id), *RGST_FORMAT (var)) : gst_index_add_id (RGST_INDEX (self), FIX2INT (id), RVAL2CSTR (var)); } else { VALUE flags, format, value; rb_scan_args (argc, argv, "4", &id, &flags, &format, &value); index_entry = gst_index_add_association (RGST_INDEX (self), FIX2INT (id), RVAL2GFLAGS (flags, GST_TYPE_ASSOC_FLAGS), *RGST_FORMAT (format), NUM2ULL (value)); } return index_entry != NULL ? RGST_INDEX_ENTRY_NEW (index_entry) : Qnil; }
static VALUE rg_s_style_property(VALUE self, VALUE property_name) { GtkWidgetClass* oclass; const char* name; GParamSpec* prop; VALUE result; if (SYMBOL_P(property_name)) { name = rb_id2name(SYM2ID(property_name)); } else { name = RVAL2CSTR(property_name); } oclass = (GtkWidgetClass*)g_type_class_ref(CLASS2GTYPE(self)); prop = gtk_widget_class_find_style_property(oclass, name); if (!prop){ g_type_class_unref(oclass); rb_raise(rb_eval_string("GLib::NoPropertyError"), "no such property: %s", name); } result = GOBJ2RVAL(prop); g_type_class_unref(oclass); return result; }
static VALUE rg_s_style_properties(int argc, VALUE *argv, VALUE self) { GtkWidgetClass* oclass = g_type_class_ref(CLASS2GTYPE(self)); guint n_properties; GParamSpec** props; VALUE inherited_too; VALUE ary; guint i; if (rb_scan_args(argc, argv, "01", &inherited_too) == 0) inherited_too = Qtrue; props = gtk_widget_class_list_style_properties(oclass, &n_properties); ary = rb_ary_new(); for (i = 0; i < n_properties; i++){ if (RVAL2CBOOL(inherited_too) || GTYPE2CLASS(props[i]->owner_type) == self) rb_ary_push(ary, CSTR2RVAL(props[i]->name)); } g_free(props); g_type_class_unref(oclass); return ary; }
static VALUE rg_iter_set_object_type(VALUE self, VALUE pos, VALUE type) { gtk_widget_path_iter_set_object_type(_SELF(self), NUM2INT(pos), CLASS2GTYPE(type)); return self; }
/* * Method: get_features(feature_type_or_plugin_name) * feature_type_or_plugin_name: a feature type or plugin name. * * Gets a list of all plugin features of the given type in the pool. * * Valid features types are Gst::AutoplugFactory, Gst::ElementFactory, * Gst::IndexFactory, Gst::SchedulerFactory and Gst::TypeFactory. * * Returns: an array of Gst::PluginFeature objects. */ static VALUE rb_gst_registry_get_features(VALUE self, VALUE type_or_plugin_name) { GList *list, *node; GType gtype; VALUE arr; if (RVAL2CBOOL(rb_obj_is_kind_of(type_or_plugin_name, rb_cString))) { list = gst_registry_get_feature_list_by_plugin(RGST_REGISTRY(self), RVAL2CSTR(type_or_plugin_name)); } else { gtype = CLASS2GTYPE(type_or_plugin_name); if (!is_valid_pluginfeature_type(gtype)) rb_raise (rb_eArgError, "Invalid feature type."); list = gst_registry_get_feature_list(RGST_REGISTRY(self), gtype); } arr = rb_ary_new(); for (node = list; node != NULL; node = g_list_next(node)) { rb_ary_push(arr, instanciate_pluginfeature(GST_PLUGIN_FEATURE(node->data))); } g_list_free (list); return arr; }
void rbgobj_init_flags_class(VALUE klass) { GFlagsClass* gclass = g_type_class_ref(CLASS2GTYPE(klass)); GString* source = g_string_new(NULL); guint i; for (i = 0; i < gclass->n_values; i++) { GFlagsValue* entry = &(gclass->values[i]); gchar* nick; gchar* p; gchar* replace_nick; replace_nick = rg_obj_constant_lookup(entry->value_nick); if (replace_nick){ nick = g_strdup(replace_nick); } else { nick = g_strdup(entry->value_nick); } for (p = nick; *p; p++) if (*p == '-' || *p == ' ') *p = '_'; else *p = tolower(*p); g_string_append_printf( source, "def %s%s?; self >= self.class.new(%d); end\n", g_ascii_isdigit(nick[0]) ? "_" : "", nick, entry->value); for (p = nick; *p; p++) *p = g_ascii_toupper(*p); #if 0 { ID id = rb_intern(nick); if (rb_is_const_id(id)) { rb_define_const(klass, nick, make_flags(entry->value, klass)); } } #else { rbgobj_define_const(klass, nick, make_flags(entry->value, klass)); } #endif g_free(nick); } rb_funcall(klass, id_module_eval, 3, rb_str_new2(source->str), rb_str_new2(__FILE__), INT2NUM(__LINE__)); g_string_free(source, TRUE); g_type_class_unref(gclass); }
static VALUE rg_s_mask(VALUE klass) { GFlagsClass* gclass = g_type_class_ref(CLASS2GTYPE(klass)); VALUE result = UINT2NUM(gclass->mask); g_type_class_unref(gclass); return result; }
static VALUE rg_append_type(VALUE self, VALUE type) { gint pos; pos = gtk_widget_path_append_type(_SELF(self), CLASS2GTYPE(type)); return INT2NUM(pos); }
static VALUE dummy_init(int argc, VALUE *argv, VALUE self) { GType gtype = CLASS2GTYPE(CLASS_OF(self)); if (G_TYPE_IS_ABSTRACT(gtype)) rb_raise(rb_eTypeError, "initializing abstract class"); else return rb_call_super(argc, argv); }
GType rbgobj_gtype_get(VALUE self) { if (RVAL2CBOOL(rb_obj_is_kind_of(self, RG_TARGET_NAMESPACE))) { return NUM2ULONG(rb_ivar_get(self, id_gtype)); } else { return CLASS2GTYPE(self); } rb_raise(rb_eTypeError, "Not a GLib::Type"); }
void rbgobj_init_interface(VALUE interf) { static VALUE rb_mGLibInterface = Qnil; rb_extend_object(interf, mMetaInterface); if (CLASS2GTYPE(interf) == G_TYPE_INTERFACE) { rb_mGLibInterface = interf; } else { rb_extend_object(interf, rb_mGLibInterface); rb_include_module(interf, rb_mGLibInterface); rbgobj_define_property_accessors(interf); } }
static VALUE rbclt_model_do_set_types (VALUE arg) { SetColumnsData *data = (SetColumnsData *) arg; ClutterModel *model = CLUTTER_MODEL (RVAL2GOBJ (data->self)); int i; for (i = 0; i < data->argc; i++) data->types[i] = CLASS2GTYPE (data->argv[i]); clutter_model_set_types (model, data->argc, data->types); return data->self; }
/* * Method: find_feature(feature_name, feature_type) * feature_name: a feature name. * feature_type: a feature type. * * Finds the plugin feature with the given name and type in the registry. * * Valid features types are Gst::AutoplugFactory, Gst::ElementFactory, * Gst::IndexFactory, Gst::SchedulerFactory and Gst::TypeFactory. * * Returns: a reference to a Gst::PluginFeature on success, or nil if the * named plugin feature is not found. */ static VALUE rb_gst_registry_find_feature(VALUE self, VALUE name, VALUE type) { GstPluginFeature *feature; GType gtype; gtype = CLASS2GTYPE (type); if (!is_valid_pluginfeature_type (gtype)) rb_raise (rb_eArgError, "Invalid feature type."); feature = gst_registry_find_feature (RGST_REGISTRY (self), RVAL2CSTR (name), gtype); return feature != NULL ? instanciate_pluginfeature (feature) : Qnil; }
static VALUE rg_set_column_types(int argc, VALUE *argv, VALUE self) { gint cnt; GType* buf; if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type."); buf = ALLOCA_N(GType, argc); for (cnt = 0; cnt < argc; cnt++) { buf[cnt] = CLASS2GTYPE(argv[cnt]); } gtk_tree_store_set_column_types(_SELF(self), argc, buf); return self; }
static VALUE flags_s_allocate(VALUE self) { GType gtype = CLASS2GTYPE(self); if (G_TYPE_IS_ABSTRACT(gtype)) { rb_raise(rb_eTypeError, "abstract class"); } else { flags_holder* p; VALUE result = Data_Make_Struct(self, flags_holder, NULL, flags_free, p); p->gclass = g_type_class_ref(gtype); p->value = 0; p->info = NULL; return result; } }
static VALUE rg_s_values(VALUE klass) { GFlagsClass *gclass; VALUE result; guint i; gclass = g_type_class_ref(CLASS2GTYPE(klass)); result = rb_ary_new(); for (i = 0; i < gclass->n_values; i++) { GFlagsValue *p = &(gclass->values[i]); rb_ary_push(result, make_flags(p->value, klass)); } g_type_class_unref(gclass); return result; }
static VALUE rbclt_list_model_do_initialize (VALUE arg) { InitializeData *data = (InitializeData *) arg; int i; for (i = 0; i < data->argc / 2; i++) { data->types[i] = CLASS2GTYPE (data->argv[i * 2]); data->names[i] = StringValuePtr (data->argv[i * 2 + 1]); } G_INITIALIZE (data->self, clutter_list_model_newv (data->argc / 2, data->types, data->names)); return Qnil; }
static VALUE rg_initialize(int argc, VALUE *argv, VALUE self) { gint cnt; GtkTreeStore* store; GType* buf; if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type."); buf = ALLOCA_N(GType, argc); for (cnt = 0; cnt < argc; cnt++) { buf[cnt] = CLASS2GTYPE(argv[cnt]); } store = gtk_tree_store_newv(argc, buf); G_INITIALIZE(self, store); return Qnil; }
/* type: String, Integer, Gdk::Color. */ static VALUE gdkevent_s_setting_get(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self) { VALUE name, type; GType gtype; GValue val = G_VALUE_INIT; gboolean ret; VALUE value; rb_scan_args(argc, argv, "11", &name, &type); if (NIL_P(type)) gtype = G_TYPE_STRING; else gtype = CLASS2GTYPE(type); g_value_init(&val, gtype); ret = gdk_setting_get(RVAL2CSTR(name), &val); value = ret ? GVAL2RVAL(&val) : Qnil; g_value_unset(&val); return value; }
/* * Should return value * * e.g. * filter.set_modify_func(String) do |model, iter, column| * "foo" * end */ static VALUE rg_set_modify_func(int argc, VALUE *argv, VALUE self) { VALUE func = rb_block_proc(); gint i; GType* types; if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type."); types = ALLOCA_N(GType, argc); G_RELATIVE(self, func); for (i = 0; i < argc; i++){ types[i] = CLASS2GTYPE(argv[i]); } gtk_tree_model_filter_set_modify_func(_SELF(self), argc, types, (GtkTreeModelFilterModifyFunc)modify_func, (gpointer)func, NULL); return self; }
/* * Method: children(interface=nil) * interface: an interface (Ruby class). * * Returns: If interface is nil, an array of all * Gst::Element objects in the container. Otherwise, an * array of Gst::Element objects in the container that * implements the interface. */ static VALUE rb_gst_bin_get_children(int argc, VALUE *argv, VALUE self) { VALUE children, iface; rb_scan_args(argc, argv, "01", &iface); if (NIL_P(iface)) { const GList *node; children = rb_ary_new(); for (node = GST_BIN_CHILDREN(SELF(self)); node; node = g_list_next(node)) { rb_ary_push(children, GST_ELEMENT2RVAL(node->data)); } } else { GstIterator *iter; iter = gst_bin_iterate_all_by_interface(SELF(self), CLASS2GTYPE(iface)); children = _rbgst_collect_elements(iter); } return children; }
void rbgobj_gobject_initialize(VALUE obj, gpointer cobj) { gobj_holder* holder = g_object_get_qdata((GObject*)cobj, RUBY_GOBJECT_OBJ_KEY); if (holder) rb_raise(rb_eRuntimeError, "ruby wrapper for this GObject* already exists."); Data_Get_Struct(obj, gobj_holder, holder); holder->cinfo = RVAL2CINFO(obj); holder->gobj = (GObject*)cobj; holder->destroyed = FALSE; g_object_set_qdata((GObject*)cobj, RUBY_GOBJECT_OBJ_KEY, (gpointer)holder); g_object_weak_ref((GObject*)cobj, (GWeakNotify)weak_notify, holder); { GType t1 = G_TYPE_FROM_INSTANCE(cobj); GType t2 = CLASS2GTYPE(CLASS_OF(obj)); if (t1 != t2) { if (!g_type_is_a(t1, t2)) rb_raise(rb_eTypeError, "%s is not subtype of %s", g_type_name(t1), g_type_name(t2)); } } }