Ejemplo n.º 1
0
Archivo: gerror.c Proyecto: Cobinja/cjs
static GIEnumInfo *
find_error_domain_info(GQuark domain)
{
    GIEnumInfo *info;

    /* first an attempt without loading extra libraries */
    info = g_irepository_find_by_error_domain(NULL, domain);
    if (info)
        return info;

    /* load standard stuff */
    g_irepository_require(NULL, "GLib", "2.0", 0, NULL);
    g_irepository_require(NULL, "GObject", "2.0", 0, NULL);
    g_irepository_require(NULL, "Gio", "2.0", 0, NULL);
    info = g_irepository_find_by_error_domain(NULL, domain);
    if (info)
        return info;

    /* last attempt: load GIRepository (for invoke errors, rarely
       needed) */
    g_irepository_require(NULL, "GIRepository", "1.0", 0, NULL);
    info = g_irepository_find_by_error_domain(NULL, domain);

    return info;
}
Ejemplo n.º 2
0
static void
gedit_plugins_engine_init (GeditPluginsEngine *engine)
{
	gchar *typelib_dir;
	GError *error = NULL;

	gedit_debug (DEBUG_PLUGINS);

	engine->priv = gedit_plugins_engine_get_instance_private (engine);

	peas_engine_enable_loader (PEAS_ENGINE (engine), "python3");

	engine->priv->plugin_settings = g_settings_new ("org.gnome.gedit.plugins");

	/* Require gedit's typelib. */
	typelib_dir = g_build_filename (gedit_dirs_get_gedit_lib_dir (),
	                                "girepository-1.0",
	                                NULL);

	if (!g_irepository_require_private (g_irepository_get_default (),
	                                    typelib_dir, "Gedit", "3.0", 0, &error))
	{
		g_warning ("Could not load Gedit repository: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	g_free (typelib_dir);

	/* This should be moved to libpeas */
	if (!g_irepository_require (g_irepository_get_default (),
	                            "Peas", "1.0", 0, &error))
	{
		g_warning ("Could not load Peas repository: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	if (!g_irepository_require (g_irepository_get_default (),
	                            "PeasGtk", "1.0", 0, &error))
	{
		g_warning ("Could not load PeasGtk repository: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	peas_engine_add_search_path (PEAS_ENGINE (engine),
	                             gedit_dirs_get_user_plugins_dir (),
	                             gedit_dirs_get_user_plugins_dir ());

	peas_engine_add_search_path (PEAS_ENGINE (engine),
	                             gedit_dirs_get_gedit_plugins_dir (),
	                             gedit_dirs_get_gedit_plugins_data_dir ());

	g_settings_bind (engine->priv->plugin_settings,
	                 GEDIT_SETTINGS_ACTIVE_PLUGINS,
	                 engine,
	                 "loaded-plugins",
	                 G_SETTINGS_BIND_DEFAULT);
}
Ejemplo n.º 3
0
static void
liferea_plugins_engine_init (LifereaPluginsEngine * engine)
{
  gchar *typelib_dir;
  GError *error = NULL;

  engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine,
                                              LIFEREA_TYPE_PLUGINS_ENGINE,
                                              LifereaPluginsEnginePrivate);

  peas_engine_enable_loader (PEAS_ENGINE (engine), "python");

  engine->priv->plugin_settings = g_settings_new ("net.sf.liferea.plugins");

  /* Require Lifereas's typelib. */
  typelib_dir = g_build_filename (PACKAGE_LIB_DIR,
                                  "girepository-1.0", NULL);

  if (!g_irepository_require_private (g_irepository_get_default (),
	  typelib_dir, "Liferea", "3.0", 0, &error))
    {
      g_warning ("Could not load Liferea repository: %s", error->message);
      g_error_free (error);
      error = NULL;
    }

  g_free (typelib_dir);

  /* This should be moved to libpeas */
  if (!g_irepository_require (g_irepository_get_default (),
                              "Peas", "1.0", 0, &error))
    {
      g_warning ("Could not load Peas repository: %s", error->message);
      g_error_free (error);
      error = NULL;
    }

  if (!g_irepository_require (g_irepository_get_default (),
                              "PeasGtk", "1.0", 0, &error))
    {
      g_warning ("Could not load PeasGtk repository: %s", error->message);
      g_error_free (error);
      error = NULL;
    }

  peas_engine_add_search_path (PEAS_ENGINE (engine),
                               g_build_filename (g_get_user_data_dir (), "liferea", "plugins", NULL),
                               g_build_filename (g_get_user_data_dir (), "liferea", "plugins", NULL));

  peas_engine_add_search_path (PEAS_ENGINE (engine),
                               g_build_filename (PACKAGE_LIB_DIR,  "plugins", NULL),
                               g_build_filename (PACKAGE_DATA_DIR, "plugins", NULL));

  g_settings_bind (engine->priv->plugin_settings,
                   "active-plugins",
                   engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT);
}
Ejemplo n.º 4
0
static PyObject *
_wrap_g_irepository_require (PyGIRepository *self,
                             PyObject       *args,
                             PyObject       *kwargs)
{
    static char *kwlist[] = { "namespace", "version", "lazy", NULL };

    const char *namespace_;
    const char *version = NULL;
    PyObject *lazy = NULL;
    GIRepositoryLoadFlags flags = 0;
    GError *error;

    if (!PyArg_ParseTupleAndKeywords (args, kwargs, "s|zO:Repository.require",
                                      kwlist, &namespace_, &version, &lazy)) {
        return NULL;
    }

    if (lazy != NULL && PyObject_IsTrue (lazy)) {
        flags |= G_IREPOSITORY_LOAD_FLAG_LAZY;
    }

    error = NULL;
    g_irepository_require (self->repository, namespace_, version, flags, &error);
    if (error != NULL) {
        PyErr_SetString (PyGIRepositoryError, error->message);
        g_error_free (error);
        return NULL;
    }

    Py_RETURN_NONE;
}
Ejemplo n.º 5
0
static JSBool
resolve_namespace_object(JSContext  *context,
                         JSObject   *repo_obj,
                         jsid        ns_id,
                         const char *ns_name)
{
    GIRepository *repo;
    GError *error;
    char *version;
    JSObject *override;
    jsval result;
    JSObject *gi_namespace = NULL;
    JSBool ret = JS_FALSE;
    char *check_name = NULL;

    if (g_strcmp0 (ns_name, "GMenu") == 0) {
        check_name = g_strdup ("CMenu");
    } else {
        check_name = g_strdup (ns_name);
    }

    JS_BeginRequest(context);

    if (!get_version_for_ns(context, repo_obj, ns_id, &version))
        goto out;

    repo = g_irepository_get_default();

    error = NULL;
    g_irepository_require(repo, check_name, version, (GIRepositoryLoadFlags) 0, &error);
    if (error != NULL) {
        gjs_throw(context,
                  "Requiring %s, version %s: %s",
                  check_name, version?version:"none", error->message);

        g_error_free(error);
        g_free(version);
        goto out;
    }

    g_free(version);

    /* Defines a property on "obj" (the javascript repo object)
     * with the given namespace name, pointing to that namespace
     * in the repo.
     */
    gi_namespace = gjs_create_ns(context, check_name);
    JS_AddObjectRoot(context, &gi_namespace);

    /* Define the property early, to avoid reentrancy issues if
       the override module looks for namespaces that import this */
    if (!JS_DefineProperty(context, repo_obj,
                           ns_name, OBJECT_TO_JSVAL(gi_namespace),
                           NULL, NULL,
                           GJS_MODULE_PROP_FLAGS))
        g_error("no memory to define ns property");

    override = lookup_override_function(context, ns_id);
Ejemplo n.º 6
0
void
gjs_define_error_class(JSContext    *context,
                       JSObject     *in_object,
                       GIEnumInfo   *info)
{
    const char *constructor_name;
    GIBoxedInfo *glib_error_info;
    JSObject *prototype, *parent_proto;
    JSObject *constructor;
    Error *priv;

    /* See the comment in gjs_define_boxed_class() for an
     * explanation of how this all works; Error is pretty much the
     * same as Boxed (except that we inherit from GLib.Error).
     */

    constructor_name = g_base_info_get_name( (GIBaseInfo*) info);

    g_irepository_require(NULL, "GLib", "2.0", (GIRepositoryLoadFlags) 0, NULL);
    glib_error_info = (GIBoxedInfo*) g_irepository_find_by_name(NULL, "GLib", "Error");
    parent_proto = gjs_lookup_generic_prototype(context, glib_error_info);
    g_base_info_unref((GIBaseInfo*)glib_error_info);

    if (!gjs_init_class_dynamic(context, in_object,
                                parent_proto,
                                g_base_info_get_namespace( (GIBaseInfo*) info),
                                constructor_name,
                                &gjs_error_class,
                                gjs_error_constructor, 1,
                                /* props of prototype */
                                &gjs_error_proto_props[0],
                                /* funcs of prototype */
                                &gjs_error_proto_funcs[0],
                                /* props of constructor, MyConstructor.myprop */
                                NULL,
                                /* funcs of constructor, MyConstructor.myfunc() */
                                &gjs_error_constructor_funcs[0],
                                &prototype,
                                &constructor)) {
        gjs_log_exception(context);
        g_error("Can't init class %s", constructor_name);
    }

    GJS_INC_COUNTER(gerror);
    priv = g_slice_new0(Error);
    priv->info = info;
    g_base_info_ref( (GIBaseInfo*) priv->info);
    priv->domain = g_quark_from_string (g_enum_info_get_error_domain(priv->info));

    JS_SetPrivate(prototype, priv);

    gjs_debug(GJS_DEBUG_GBOXED, "Defined class %s prototype is %p class %p in object %p",
              constructor_name, prototype, JS_GetClass(prototype), in_object);

    gjs_define_enum_values(context, constructor, priv->info);
    gjs_define_enum_static_methods(context, constructor, priv->info);
}
Ejemplo n.º 7
0
int main(void)
{
    GIRepository *repository;
    GError *error = NULL;
    GIBaseInfo *base_info;
    GIArgument in_args[5];
    GIArgument retval;

    g_type_init();

    repository = g_irepository_get_default();
    g_irepository_require(repository, "GLib", "2.0", 0, &error);
    if (error) {
      g_error("ERROR: %s\n", error->message);
      return 1;
    }

    base_info = g_irepository_find_by_name(repository, "GLib", "assertion_message");
    if (!base_info) {
      g_error("ERROR: %s\n", "Could not find GLib.warn_message");
      return 1;
    }

    in_args[0].v_pointer = "domain";
    in_args[1].v_pointer = "glib-print.c";
    in_args[2].v_pointer = "30";
    in_args[3].v_pointer = "main";
    in_args[4].v_pointer = "hello world";

    if (!g_function_info_invoke ((GIFunctionInfo *)base_info,
                                 (const GIArgument*)&in_args,
                                 5,
                                 NULL,
                                 0,
                                 &retval,
                                 &error)) {
      g_error("ERROR: %s\n", error->message);
      return 1;
    }

    g_base_info_unref (base_info);

    return 0;
}
Ejemplo n.º 8
0
int
main(int argc, char **argv)
{
  GIRepository *repo;
  GITypelib *ret;
  GIBaseInfo *info;
  GIArgument in_arg[1];
  GIArgument ret_arg;
  GError *error;
  gboolean invoke_return;

  repo = g_irepository_get_default ();

  error = NULL;
  ret = g_irepository_require (repo, "GLib", NULL, 0, &error);
  g_assert (ret != NULL);
  g_assert (error == NULL);

  info = g_irepository_find_by_name (repo, "GLib", "file_read_link");
  g_assert (info != NULL);
  g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
  g_assert (g_function_info_get_flags ((GIFunctionInfo *)info) & GI_FUNCTION_THROWS);

  in_arg[0].v_string = g_strdup ("non-existent-file/hope");
  error = NULL;
  invoke_return = g_function_info_invoke ((GIFunctionInfo *)info,
                                          in_arg,
                                          1,
                                          NULL,
                                          0,
                                          &ret_arg,
                                          &error);
  g_free(in_arg[0].v_string);

  g_assert (invoke_return == FALSE);
  g_assert (error != NULL);
  g_assert (error->domain == G_FILE_ERROR);
  g_assert (error->code == G_FILE_ERROR_NOENT);

  exit(0);
}
Ejemplo n.º 9
0
/* Force the namespace to be loaded if it isn't already. If namespace is not
 * loaded, this function will search for a ".typelib" file using the repository
 * search path. In addition, a version of namespace may be specified. If version
 * is not specified, the latest will be used.
 * 
 * @param [String] namespace The namespace to load
 * @param [String, nil] version An optional version
 */
static VALUE
rg_require(int argc, VALUE *argv, VALUE self)
{
    VALUE rb_namespace, rb_version, rb_flags;
    const gchar *namespace_, *version;
    GIRepositoryLoadFlags flags = 0;
    GError *error = NULL;

    rb_scan_args(argc, argv, "12", &rb_namespace, &rb_version, &rb_flags);

    namespace_ = RVAL2CSTR(rb_namespace);
    version = RVAL2CSTR_ACCEPT_NIL(rb_version);
    if (!NIL_P(rb_flags)) {
	flags = RVAL2GI_REPOSITORY_LOAD_FLAGS(rb_flags);
    }

    g_irepository_require(SELF(self), namespace_, version, flags, &error);
    if (error) {
	RG_RAISE_ERROR(error);
    }

    return Qnil;
}
Ejemplo n.º 10
0
/* FIXME: scm_flags is currently ignored */
static SCM
scm_g_irepository_require (SCM scm_repository,
                           SCM scm_namespace,
                           SCM scm_version,
                           SCM scm_flags)
{
        GIRepository *repo;
        GTypelib *typelib;
        GError *error;
        const char *version;
        SCM scm_typelib;

        repo = (GIRepository *) SCM_SMOB_DATA (scm_repository);

        if (SCM_UNBNDP (scm_version))
                version = NULL;
        else
                version = scm_to_locale_string (scm_version);

        error = NULL;
        typelib = g_irepository_require (repo,
                                         scm_to_locale_string (scm_namespace),
                                         version,
                                         0,
                                         &error);
        if (error) {
                /* FIXME: Throw Guile error here */
                g_critical ("Failed to load typelib: %s", error->message);
                return SCM_UNSPECIFIED;
        }

        scm_typelib = scm_make_smob (typelib_t);
        SCM_SET_SMOB_DATA (scm_typelib, typelib);

        return scm_typelib;
}
Ejemplo n.º 11
0
Archivo: gerror.c Proyecto: Cobinja/cjs
JSBool
gjs_define_error_class(JSContext    *context,
                       JSObject     *in_object,
                       GIEnumInfo   *info,
                       JSObject    **constructor_p,
                       JSObject    **prototype_p)
{
    const char *constructor_name;
    GIBoxedInfo *glib_error_info;
    JSObject *prototype, *parent_proto;
    JSObject *constructor;
    jsval value;
    Error *priv;

    /* See the comment in gjs_define_boxed_class() for an
     * explanation of how this all works; Error is pretty much the
     * same as Boxed (except that we inherit from GLib.Error).
     */

    constructor_name = g_base_info_get_name( (GIBaseInfo*) info);

    if (gjs_object_get_property(context, in_object, constructor_name, &value)) {
        JSObject *constructor;

        if (!JSVAL_IS_OBJECT(value)) {
            gjs_throw(context, "Existing property '%s' does not look like a constructor",
                         constructor_name);
            return JS_FALSE;
        }

        constructor = JSVAL_TO_OBJECT(value);

        gjs_object_get_property(context, constructor, "prototype", &value);
        if (!JSVAL_IS_OBJECT(value)) {
            gjs_throw(context, "error %s prototype property does not appear to exist or has wrong type", constructor_name);
            return JS_FALSE;
        } else {
            if (prototype_p)
                *prototype_p = JSVAL_TO_OBJECT(value);
            if (constructor_p)
                *constructor_p = constructor;

            return JS_TRUE;
        }
    }

    g_irepository_require(NULL, "GLib", "2.0", 0, NULL);
    glib_error_info = (GIBoxedInfo*) g_irepository_find_by_name(NULL, "GLib", "Error");
    parent_proto = gjs_lookup_boxed_prototype(context, glib_error_info);
    g_base_info_unref((GIBaseInfo*)glib_error_info);

    prototype = gjs_init_class_dynamic(context, in_object,
                                          parent_proto,
                                          g_base_info_get_namespace( (GIBaseInfo*) info),
                                          constructor_name,
                                          &gjs_error_class,
                                          gjs_error_constructor,
                                          /* number of constructor args (less can be passed) */
                                          1,
                                          /* props of prototype */
                                          &gjs_error_proto_props[0],
                                          /* funcs of prototype */
                                          &gjs_error_proto_funcs[0],
                                          /* props of constructor, MyConstructor.myprop */
                                          NULL,
                                          /* funcs of constructor, MyConstructor.myfunc() */
                                          &gjs_error_constructor_funcs[0]);
    if (prototype == NULL) {
        gjs_log_exception(context, NULL);
        gjs_fatal("Can't init class %s", constructor_name);
    }

    g_assert(gjs_object_has_property(context, in_object, constructor_name));

    GJS_INC_COUNTER(gerror);
    priv = g_slice_new0(Error);
    priv->info = info;
    g_base_info_ref( (GIBaseInfo*) priv->info);
    priv->domain = g_quark_from_string (g_enum_info_get_error_domain(priv->info));

    JS_SetPrivate(context, prototype, priv);

    gjs_debug(GJS_DEBUG_GBOXED, "Defined class %s prototype is %p class %p in object %p",
              constructor_name, prototype, JS_GET_CLASS(context, prototype), in_object);

    constructor = NULL;
    gjs_object_get_property(context, in_object, constructor_name, &value);
    if (!JSVAL_IS_VOID(value)) {
        if (!JSVAL_IS_OBJECT(value)) {
            gjs_throw(context, "Property '%s' does not look like a constructor",
                      constructor_name);
            return JS_FALSE;
        }
    }

    constructor = JSVAL_TO_OBJECT(value);

    gjs_define_enum_values(context, constructor, priv->info);

    if (constructor_p)
        *constructor_p = constructor;

    if (prototype_p)
        *prototype_p = prototype;

    return JS_TRUE;
}
int main(int argc, char **argv)
{
	IsApplication *application;
        GSettings *settings;
        IsManager *manager;
	gchar *plugin_dir;
	PeasEngine *engine;
	PeasExtensionSet *set;
	GError *error = NULL;

	gtk_init(&argc, &argv);

	if (!g_irepository_require(g_irepository_get_default(), "Peas", "1.0",
				   0, &error))
	{
		is_warning("main", "Could not load Peas repository: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	engine = peas_engine_get_default();
	g_signal_connect(engine, "notify::plugin-list",
			 G_CALLBACK(on_plugin_list_notify), NULL);

	/* add home dir to search path */
	plugin_dir = g_build_filename(g_get_user_config_dir(), PACKAGE,
				      "plugins", NULL);
	peas_engine_add_search_path(engine, plugin_dir, NULL);
	g_free(plugin_dir);

	/* add system path to search path */
	plugin_dir = g_build_filename(LIBDIR, PACKAGE, "plugins", NULL);
	peas_engine_add_search_path(engine, plugin_dir, NULL);
	g_free(plugin_dir);

        /* init notifications */
        is_notify_init();
	application = is_application_new();
        settings = g_settings_new("indicator-sensors.application");
        g_settings_bind(settings, "temperature-scale",
                        application, "temperature-scale",
                        G_SETTINGS_BIND_DEFAULT);

	/* create extension set and set manager as object */
	set = peas_extension_set_new(engine, PEAS_TYPE_ACTIVATABLE,
				     "object", application, NULL);

	/* activate all activatable extensions */
	peas_extension_set_call(set, "activate");

	/* and make sure to activate any ones which are found in the future */
	g_signal_connect(set, "extension-added",
			 G_CALLBACK(on_extension_added), application);
	g_signal_connect(set, "extension-removed",
			  G_CALLBACK(on_extension_removed), application);

        /* since all plugins are now inited show a notification if we detected
         * sensors but none are enabled - TODO: perhaps just open the pref's
         * dialog?? */
        manager = is_application_get_manager(application);
        GSList *sensors = is_manager_get_all_sensors_list(manager);
        if (sensors) {
                gchar **enabled_sensors = is_manager_get_enabled_sensors(manager);
                if (!g_strv_length(enabled_sensors)) {
                        is_notify(IS_NOTIFY_LEVEL_INFO,
                                  _("No Sensors Enabled For Monitoring"),
                                  _("Sensors detected but none are enabled for monitoring. To enable monitoring of sensors open the Preferences window and select the sensors to monitor"));
                }
                g_strfreev(enabled_sensors);
                g_slist_foreach(sensors, (GFunc)g_object_unref, NULL);
                g_slist_free(sensors);
        }

	gtk_main();

        g_object_unref(application);
        is_notify_uninit();

	return 0;
}
Ejemplo n.º 13
0
void
ide_application_discover_plugins (IdeApplication *self)
{
  PeasEngine *engine = peas_engine_get_default ();
  const GList *list;
  gchar *path;
  g_autoptr(GError) error = NULL;

  g_return_if_fail (IDE_IS_APPLICATION (self));

  if (g_getenv ("GB_IN_TREE_PLUGINS") != NULL)
    {
      GDir *dir;

      g_irepository_prepend_search_path (BUILDDIR"/src/gstyle");
      g_irepository_prepend_search_path (BUILDDIR"/src/libide");

      if ((dir = g_dir_open (BUILDDIR"/src/plugins", 0, NULL)))
        {
          const gchar *name;

          while ((name = g_dir_read_name (dir)))
            {
              path = g_build_filename (BUILDDIR, "src", "plugins", name, NULL);
              peas_engine_prepend_search_path (engine, path, path);
              g_free (path);
            }

          g_dir_close (dir);
        }
    }
  else
    {
      g_irepository_prepend_search_path (PACKAGE_LIBDIR"/gnome-builder/girepository-1.0");

      peas_engine_prepend_search_path (engine,
                                       PACKAGE_LIBDIR"/gnome-builder/plugins",
                                       PACKAGE_DATADIR"/gnome-builder/plugins");
    }

  /*
   * We have access to ~/.local/share/gnome-builder/ for plugins even when we are
   * bundled with flatpak, so might as well use it.
   */
  if (ide_is_flatpak ())
    {
      g_autofree gchar *plugins_dir = g_build_filename (g_get_home_dir (),
                                                        ".local",
                                                        "share",
                                                        "gnome-builder",
                                                        "plugins",
                                                        NULL);
      g_irepository_prepend_search_path (plugins_dir);
      peas_engine_prepend_search_path (engine, plugins_dir, plugins_dir);
    }

  if (!g_irepository_require (NULL, "Ide", "1.0", 0, &error) ||
      !g_irepository_require (NULL, "Gtk", "3.0", 0, &error) ||
      !g_irepository_require (NULL, "Dazzle", "1.0", 0, &error))
    g_warning ("Cannot enable Python 3 plugins: %s", error->message);
  else
    {
      /* Avoid spamming stderr with Ide import tracebacks */
      peas_engine_enable_loader (engine, "python3");
    }

  peas_engine_prepend_search_path (engine, "resource:///org/gnome/builder/plugins/", NULL);

  path = g_build_filename (g_get_user_data_dir (), "gnome-builder", "plugins", NULL);
  peas_engine_prepend_search_path (engine, path, NULL);
  g_free (path);

  list = peas_engine_get_plugin_list (engine);

  for (; list; list = list->next)
    {
      PeasPluginInfo *plugin_info = list->data;

      g_debug ("Discovered plugin \"%s\"",
               peas_plugin_info_get_module_name (plugin_info));
    }
}