1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * lapiz-plugins-engine.c
 * This file is part of lapiz
 *
 * Copyright (C) 2002-2005 Paolo Maggi
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

/*
 * Modified by the lapiz Team, 2002-2005. See the AUTHORS file for a
 * list of people on the lapiz Team.
 * See the ChangeLog files for a list of changes.
 *
 * $Id$
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>

#include <glib/gi18n.h>
#include <girepository.h>

#include "lapiz-plugins-engine.h"
#include "lapiz-debug.h"
#include "lapiz-app.h"
#include "lapiz-prefs-manager.h"
#include "lapiz-dirs.h"

struct _LapizPluginsEnginePrivate
{
	GSettings *plugin_settings;
};

G_DEFINE_TYPE_WITH_PRIVATE (LapizPluginsEngine, lapiz_plugins_engine, BEAN_TYPE_ENGINE)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.

LapizPluginsEngine *default_engine = NULL;

static void
lapiz_plugins_engine_init (LapizPluginsEngine *engine)
{
	gchar *private_path;
	GError *error = NULL;

	lapiz_debug (DEBUG_PLUGINS);

	bean_engine_enable_loader (BEAN_ENGINE (engine), "python3");

	engine->priv = lapiz_plugins_engine_get_instance_private (engine);

	engine->priv->plugin_settings = g_settings_new (LAPIZ_SCHEMA);

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

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

	private_path = g_build_filename (LIBDIR, "girepository-1.0", NULL);

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

	g_free (private_path);

	bean_engine_add_search_path (BEAN_ENGINE (engine),
	                             lapiz_dirs_get_user_plugins_dir (),
	                             lapiz_dirs_get_user_plugins_dir ());

	bean_engine_add_search_path (BEAN_ENGINE (engine),
	                             lapiz_dirs_get_lapiz_plugins_dir (),
	                             lapiz_dirs_get_lapiz_plugins_data_dir ());

	g_settings_bind (engine->priv->plugin_settings,
	                 GPM_ACTIVE_PLUGINS,
	                 engine,
	                 "loaded-plugins",
	                 G_SETTINGS_BIND_DEFAULT);
}

static void
lapiz_plugins_engine_dispose (GObject *object)
{
	LapizPluginsEngine *engine = LAPIZ_PLUGINS_ENGINE (object);

	if (engine->priv->plugin_settings != NULL)
	{
		g_object_unref (engine->priv->plugin_settings);
		engine->priv->plugin_settings = NULL;
	}

	G_OBJECT_CLASS (lapiz_plugins_engine_parent_class)->dispose (object);
}

static void
lapiz_plugins_engine_class_init (LapizPluginsEngineClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->dispose = lapiz_plugins_engine_dispose;
}

LapizPluginsEngine *
lapiz_plugins_engine_get_default (void)
{
	if (default_engine != NULL)
		return default_engine;

	default_engine = LAPIZ_PLUGINS_ENGINE (g_object_new (LAPIZ_TYPE_PLUGINS_ENGINE, NULL));
	g_object_add_weak_pointer (G_OBJECT (default_engine),
	                           (gpointer) &default_engine);

	return default_engine;
}