Ejemplo n.º 1
0
int
main (int    argc,
      char **argv)
{
    GOptionContext *option_context;
    GError *error = NULL;
    gchar *plugin_dir;
    PeasEngine *engine;

    option_context = g_option_context_new (_("- libpeas demo application"));
    g_option_context_add_main_entries (option_context, demo_args, GETTEXT_PACKAGE);
    g_option_context_add_group (option_context, gtk_get_option_group (TRUE));

    if (!g_option_context_parse (option_context, &argc, &argv, &error))
    {
        g_warning ("Error while parsing arguments: %s", error->message);
        g_error_free (error);
        return -1;
    }

    g_option_context_free (option_context);

    /* Ensure we pick the uninstalled plugin loaders if we're running from build dir */
    if (run_from_build_dir)
    {
        g_debug ("Running from build dir.");
        g_irepository_prepend_search_path ("../libpeas");
        g_irepository_prepend_search_path ("../libpeas-gtk");
        g_setenv ("PEAS_PLUGIN_LOADERS_DIR", "../loaders", TRUE);
    }

    engine = peas_engine_get_default ();
    plugin_dir = g_build_filename (g_get_user_config_dir (), "peas-demo/plugins", NULL);
    peas_engine_add_search_path (engine, plugin_dir, plugin_dir);
    g_free (plugin_dir);

    peas_engine_enable_loader (engine, "gjs");
    peas_engine_enable_loader (engine, "python3");
    peas_engine_enable_loader (engine, "seed");

    if (run_from_build_dir)
        peas_engine_add_search_path (engine, "./plugins", NULL);
    else
        peas_engine_add_search_path (engine,
                                     PEAS_LIBDIR "/peas-demo/plugins/",
                                     PEAS_PREFIX "/share/peas-demo/plugins");

    n_windows = 0;
    main_window = create_main_window ();
    gtk_widget_show_all (main_window);

    gtk_main ();

    gtk_widget_destroy (main_window);

    g_object_unref (engine);

    return 0;
}
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
irc_application_load_plugins (IrcApplication *self)
{
	IrcApplicationPrivate *priv = irc_application_get_instance_private (IRC_APPLICATION(self));
	PeasEngine *engine = peas_engine_get_default();
	peas_engine_enable_loader (engine, "python3");
	g_autofree char *custom_path = get_custom_plugin_dir ();
	if (custom_path)
	{
		peas_engine_add_search_path (engine, custom_path, NULL);
	}
	else
	{
		g_autofree char *plugin_path = g_build_filename (LIBDIR, "irc", NULL);
		g_autofree char *user_plugin_path = g_build_filename (g_get_home_dir (), ".local", "lib", "irc", NULL);

		peas_engine_add_search_path (engine, user_plugin_path, NULL);
		peas_engine_add_search_path (engine, plugin_path, NULL);
	}
	priv->extensions = peas_extension_set_new (engine, PEAS_TYPE_ACTIVATABLE,
												"object", self, NULL);

  	g_settings_bind (priv->settings, "enabled-plugins", engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT);
	peas_extension_set_foreach (priv->extensions, on_extension_added, self);
	g_signal_connect (priv->extensions, "extension-added", G_CALLBACK(on_extension_added), self);
	g_signal_connect (priv->extensions, "extension-removed", G_CALLBACK(on_extension_removed), self);
}
Ejemplo n.º 4
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.º 5
0
static void consort_shell_init (ConsortShell *object) {
    ConsortShellPrivate *priv = CONSORT_SHELL_GET_PRIVATE (object);
    struct desktop *desktop;

    /* Set up the PeasEngine */
    priv->engine = peas_engine_get_default ();
    priv->extensions = peas_extension_set_new (peas_engine_get_default (), PEAS_TYPE_ACTIVATABLE, "object", object, NULL);
    peas_engine_add_search_path (priv->engine, CONSORT_SHELL_PLUGIN_DATA_DIR, CONSORT_SHELL_PLUGIN_DIR);
    peas_engine_enable_loader (priv->engine, "python3");
    
    /* Plugin manager */
    priv->plugin_manager = peas_gtk_plugin_manager_new (priv->engine);
    priv->plugin_window = plugin_window_create (priv);
    gtk_window_set_title (priv->plugin_window, "Consort2 Plugin Manager");
    gtk_widget_show_all (priv->plugin_window);
    
    /* Preload any plugins */
    peas_extension_set_foreach (priv->extensions, (PeasExtensionSetForeachFunc) on_extension_added, object);

    g_signal_connect (priv->extensions, "extension-added", G_CALLBACK (on_extension_added), object);
    g_signal_connect (priv->extensions, "extension-removed", G_CALLBACK (on_extension_removed), object);
    
    desktop = malloc(sizeof *desktop);
    desktop->output = NULL;
    desktop->shell = NULL;

    desktop->gdk_display = gdk_display_get_default();
    desktop->display =
        gdk_wayland_display_get_wl_display(desktop->gdk_display);
    if (desktop->display == NULL) {
        fprintf(stderr, "failed to get display: %m\n");
        return -1;
    }

    desktop->registry = wl_display_get_registry(desktop->display);
    wl_registry_add_listener(desktop->registry,
            &registry_listener, desktop);

    /* Wait until we have been notified about the compositor and shell
     * objects */
    while (!desktop->output || !desktop->shell)
        wl_display_roundtrip (desktop->display);
        
    priv->desktop = desktop;
}
Ejemplo n.º 6
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));
    }
}
Ejemplo n.º 7
0
void
gb_plugins_init (void)
{
  PeasEngine *engine;
  const GList *list;

  /*
   * Ensure plugin-extensible types are registered.
   * This allows libgnome-builder.la to be linked and not drop
   * important symbols.
   */
  g_type_ensure (GB_TYPE_APPLICATION);
  g_type_ensure (GB_TYPE_DOCUMENT);
  g_type_ensure (GB_TYPE_TREE);
  g_type_ensure (GB_TYPE_TREE_BUILDER);
  g_type_ensure (GB_TYPE_TREE_NODE);
  g_type_ensure (GB_TYPE_VIEW);
  g_type_ensure (GB_TYPE_VIEW_GRID);
  g_type_ensure (GB_TYPE_WORKBENCH);
  g_type_ensure (GB_TYPE_WORKSPACE);

  engine = peas_engine_get_default ();

  peas_engine_enable_loader (engine, "python3");

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

      g_irepository_require_private (g_irepository_get_default (),
                                     BUILDDIR"/libide",
                                     "Ide", "1.0", 0, NULL);

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

          while ((name = g_dir_read_name (dir)))
            {
              gchar *path;

              path = g_build_filename (BUILDDIR, "plugins", name, NULL);
              peas_engine_prepend_search_path (engine, path, path);
              g_free (path);
            }

          g_dir_close (dir);
        }
    }
  else
    {
      peas_engine_prepend_search_path (engine,
                                       PACKAGE_LIBDIR"/gnome-builder/plugins",
                                       PACKAGE_DATADIR"/gnome-builder/plugins");
    }

  list = peas_engine_get_plugin_list (engine);

  for (; list; list = list->next)
    {
      if (peas_plugin_info_is_builtin (list->data))
        peas_engine_load_plugin (engine, list->data);
    }
}