Commit 9bb157fe authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

Add an "data-dir" property to plugins that plugin can use to locate data

2008-12-28  Paolo Borelli  <pborelli@katamail.com>

	* plugins/docinfo/gedit-docinfo-plugin.c:
	* plugins/time/gedit-time-plugin.c:
	* plugin-loaders/python/gedit-plugin-loader-python.c:
	* plugin-loaders/python/bindings/gedit.defs:
	* plugin-loaders/c/gedit-plugin-loader-c.c:
	* gedit/gedit-plugin.c:
	* gedit/gedit-plugin.h:
	Add an "data-dir" property to plugins that plugin can use to
	locate data files in a relocable way (so that it works on
	windows). Convert a couple of plugins as a test, eventually all
	plugins need it.


svn path=/trunk/; revision=6739
parent 0062a891
2008-12-28 Paolo Borelli <pborelli@katamail.com>
* plugins/docinfo/gedit-docinfo-plugin.c:
* plugins/time/gedit-time-plugin.c:
* plugin-loaders/python/gedit-plugin-loader-python.c:
* plugin-loaders/python/bindings/gedit.defs:
* plugin-loaders/c/gedit-plugin-loader-c.c:
* gedit/gedit-plugin.c:
* gedit/gedit-plugin.h:
Add an "data-dir" property to plugins that plugin can use to
locate data files in a relocable way (so that it works on
windows). Convert a couple of plugins as a test, eventually all
plugins need it.
2008-12-28 Jesse van den Kieboom <jesse@icecrew.nl>
* plugins/filebrowser/gedit-file-browser-store.c: Fixed small
......
......@@ -344,7 +344,7 @@ dnl Misc
dnl ================================================================
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
GNOME_COMPILE_WARNINGS(yes)
AC_ARG_ENABLE(deprecations,
......
......@@ -33,18 +33,22 @@
#endif
#include "gedit-plugin.h"
#include "gedit-dirs.h"
/* properties */
enum {
PROP_0,
PROP_INSTALL_PATH
PROP_INSTALL_DIR,
PROP_DATA_DIR_NAME,
PROP_DATA_DIR
};
typedef struct _GeditPluginPrivate GeditPluginPrivate;
struct _GeditPluginPrivate
{
gchar *install_path;
gchar *install_dir;
gchar *data_dir_name;
};
#define GEDIT_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_PLUGIN, GeditPluginPrivate))
......@@ -76,12 +80,13 @@ gedit_plugin_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
GeditPluginPrivate *priv = GEDIT_PLUGIN_GET_PRIVATE (object);
switch (prop_id)
{
case PROP_INSTALL_PATH:
g_value_set_string (value, priv->install_path);
case PROP_INSTALL_DIR:
g_value_take_string (value, gedit_plugin_get_install_dir (GEDIT_PLUGIN (object)));
break;
case PROP_DATA_DIR:
g_value_take_string (value, gedit_plugin_get_data_dir (GEDIT_PLUGIN (object)));
break;
default:
g_return_if_reached ();
......@@ -98,8 +103,11 @@ gedit_plugin_set_property (GObject *object,
switch (prop_id)
{
case PROP_INSTALL_PATH:
priv->install_path = g_value_dup_string (value);
case PROP_INSTALL_DIR:
priv->install_dir = g_value_dup_string (value);
break;
case PROP_DATA_DIR_NAME:
priv->data_dir_name = g_value_dup_string (value);
break;
default:
g_return_if_reached ();
......@@ -110,8 +118,9 @@ static void
gedit_plugin_finalize (GObject *object)
{
GeditPluginPrivate *priv = GEDIT_PLUGIN_GET_PRIVATE (object);
g_free (priv->install_path);
g_free (priv->install_dir);
g_free (priv->data_dir_name);
}
static void
......@@ -131,14 +140,31 @@ gedit_plugin_class_init (GeditPluginClass *klass)
object_class->finalize = gedit_plugin_finalize;
g_object_class_install_property (object_class,
PROP_INSTALL_PATH,
g_param_spec_string ("install-path",
"Install Path",
"The path where the plugin is installed",
PROP_INSTALL_DIR,
g_param_spec_string ("install-dir",
"Install Directory",
"The directory where the plugin is installed",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* the basename of the data dir is set at construction time by the plugin loader
* while the full path is constructed on the fly to take into account relocability
* that's why we have a writeonly prop and a readonly prop */
g_object_class_install_property (object_class,
PROP_DATA_DIR_NAME,
g_param_spec_string ("data-dir-name",
"Basename of the data directory",
"The basename of the directory where the plugin should look for its data files",
NULL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_DATA_DIR,
g_param_spec_string ("data-dir",
"Data Directory",
"The full path of the directory where the plugin should look for its data files",
NULL,
G_PARAM_READABLE));
g_type_class_add_private (klass, sizeof (GeditPluginPrivate));
}
......@@ -149,17 +175,70 @@ gedit_plugin_init (GeditPlugin *plugin)
}
/**
* gedit_plugin_get_install_path:
* gedit_plugin_get_install_dir:
* @plugin: a #GeditPlugin
*
* Returns the path where the plugin is installed
* Returns the path of the directory where the plugin is installed
*/
const gchar *
gedit_plugin_get_install_path (GeditPlugin *plugin)
gchar *
gedit_plugin_get_install_dir (GeditPlugin *plugin)
{
g_return_val_if_fail (GEDIT_IS_PLUGIN (plugin), NULL);
return GEDIT_PLUGIN_GET_PRIVATE (plugin)->install_path;
return g_strdup (GEDIT_PLUGIN_GET_PRIVATE (plugin)->install_dir);
}
/**
* gedit_plugin_get_data_dir:
* @plugin: a #GeditPlugin
*
* Returns the path of the directory where the plugin should look for
* its data files
*/
gchar *
gedit_plugin_get_data_dir (GeditPlugin *plugin)
{
GeditPluginPrivate *priv;
gchar *gedit_lib_dir;
gchar *data_dir;
g_return_val_if_fail (GEDIT_IS_PLUGIN (plugin), NULL);
priv = GEDIT_PLUGIN_GET_PRIVATE (plugin);
/* If it's a "user" plugin the data dir is
* install_dir/data_dir_name if instead it's a
* "system" plugin the data dir is under gedit_data_dir,
* so it's under $prefix/share/gedit-2/plugins/data_dir_name
* where data_dir_name usually it's the name of the plugin
*/
gedit_lib_dir = gedit_dirs_get_gedit_lib_dir ();
/* CHECK: is checking the prefix enough or should we be more
* careful about normalizing paths etc? */
if (g_str_has_prefix (priv->install_dir, gedit_lib_dir))
{
gchar *gedit_data_dir;
gedit_data_dir = gedit_dirs_get_gedit_data_dir ();
data_dir = g_build_filename (gedit_data_dir,
"plugins",
priv->data_dir_name,
NULL);
g_free (gedit_data_dir);
}
else
{
data_dir = g_build_filename (priv->install_dir,
priv->data_dir_name,
NULL);
}
g_free (gedit_lib_dir);
return data_dir;
}
/**
......
......@@ -99,7 +99,9 @@ struct _GeditPluginClass
* Public methods
*/
GType gedit_plugin_get_type (void) G_GNUC_CONST;
gchar const *gedit_plugin_get_install_path (GeditPlugin *plugin);
gchar *gedit_plugin_get_install_dir (GeditPlugin *plugin);
gchar *gedit_plugin_get_data_dir (GeditPlugin *plugin);
void gedit_plugin_activate (GeditPlugin *plugin,
GeditWindow *window);
......
......@@ -48,13 +48,15 @@ gedit_plugin_loader_iface_load (GeditPluginLoader *loader,
{
GeditPluginLoaderC *cloader = GEDIT_PLUGIN_LOADER_C (loader);
GeditObjectModule *module;
const gchar *module_name;
GeditPlugin *result;
module = (GeditObjectModule *)g_hash_table_lookup (cloader->priv->loaded_plugins, info);
module_name = gedit_plugin_info_get_module_name (info);
if (module == NULL)
{
module = gedit_object_module_new (gedit_plugin_info_get_module_name (info),
module = gedit_object_module_new (module_name,
path,
"register_gedit_plugin");
......@@ -70,10 +72,15 @@ gedit_plugin_loader_iface_load (GeditPluginLoader *loader,
return NULL;
}
/* create new plugin object */
result = (GeditPlugin *)gedit_object_module_new_object (module, "install-path", path, NULL);
/* TODO: for now we force data-dir-name = module-name... if needed we can
* add a datadir field to the plugin descriptor file.
*/
result = (GeditPlugin *)gedit_object_module_new_object (module,
"install-dir", path,
"data-dir-name", module_name,
NULL);
if (!result)
{
g_warning ("Could not create plugin object: %s", gedit_plugin_info_get_name (info));
......
......@@ -629,6 +629,18 @@
(return-type "GType")
)
(define-method get_install_dir
(of-object "GeditPlugin")
(c-name "gedit_plugin_get_install_dir")
(return-type "gchar*")
)
(define-method get_data_dir
(of-object "GeditPlugin")
(c-name "gedit_plugin_get_data_dir")
(return-type "gchar*")
)
(define-method activate
(of-object "GeditPlugin")
(c-name "gedit_plugin_activate")
......@@ -668,12 +680,6 @@
(return-type "GtkWidget*")
)
(define-method get_install_path
(of-object "GeditPlugin")
(c-name "gedit_plugin_get_install_path")
(return-type "const-gchar*")
)
;; From ../gedit/gedit-plugin-python.h
(define-function gedit_plugin_python_get_type
......
......@@ -128,7 +128,10 @@ new_plugin_from_info (GeditPluginLoaderPython *loader,
*/
if (pyinfo->class_type != GEDIT_TYPE_PLUGIN_PYTHON)
{
GObject *obj = g_object_new (pyinfo->class_type, "install-path", pyinfo->path, NULL);
GObject *obj = g_object_new (pyinfo->class_type,
"install-dir", pyinfo->path,
"data-dir-name", gedit_plugin_info_get_module_name (info),
NULL);
pygobject = (PyGObject *)pygobject_new (obj);
}
else
......@@ -137,8 +140,11 @@ new_plugin_from_info (GeditPluginLoaderPython *loader,
if (pygobject->obj != NULL)
g_error("GObject for plugin is already initialized!");
pygobject_construct(pygobject, "install-path", pyinfo->path, NULL);
pygobject_construct(pygobject,
"install-dir", pyinfo->path,
"data-dir-name", gedit_plugin_info_get_module_name (info),
NULL);
}
if (pygobject == NULL || pygobject->obj == NULL)
......
......@@ -59,6 +59,8 @@ typedef struct
typedef struct
{
GeditPlugin *plugin;
GtkActionGroup *ui_action_group;
guint ui_id;
......@@ -87,6 +89,8 @@ get_docinfo_dialog (GeditWindow *window,
WindowData *data)
{
DocInfoDialog *dialog;
gchar *data_dir;
gchar *ui_file;
GtkWidget *content;
GtkWidget *error_widget;
gboolean ret;
......@@ -95,7 +99,9 @@ get_docinfo_dialog (GeditWindow *window,
dialog = g_new (DocInfoDialog, 1);
ret = gedit_utils_get_ui_objects (GEDIT_UIDIR "docinfo.ui",
data_dir = gedit_plugin_get_data_dir (data->plugin);
ui_file = g_build_filename (data_dir, "docinfo.ui", NULL);
ret = gedit_utils_get_ui_objects (ui_file,
NULL,
&error_widget,
"dialog", &dialog->dialog,
......@@ -114,6 +120,9 @@ get_docinfo_dialog (GeditWindow *window,
"selected_chars_ns_label", &dialog->selected_chars_ns_label,
NULL);
g_free (data_dir);
g_free (ui_file);
if (!ret)
{
const gchar *err_message;
......@@ -423,6 +432,8 @@ free_window_data (WindowData *data)
gedit_debug (DEBUG_PLUGINS);
g_object_unref (data->plugin);
g_object_unref (data->ui_action_group);
if (data->dialog != NULL)
......@@ -478,8 +489,8 @@ impl_activate (GeditPlugin *plugin,
gedit_debug (DEBUG_PLUGINS);
data = g_new (WindowData, 1);
manager = gedit_window_get_ui_manager (window);
data->plugin = g_object_ref (plugin);
data->dialog = NULL;
data->ui_action_group = gtk_action_group_new ("GeditDocInfoPluginActions");
......@@ -490,6 +501,7 @@ impl_activate (GeditPlugin *plugin,
G_N_ELEMENTS (action_entries),
window);
manager = gedit_window_get_ui_manager (window);
gtk_ui_manager_insert_action_group (manager,
data->ui_action_group,
-1);
......
......@@ -741,6 +741,8 @@ static TimeConfigureDialog *
get_configure_dialog (GeditTimePlugin *plugin)
{
TimeConfigureDialog *dialog = NULL;
gchar *data_dir;
gchar *ui_file;
GtkWidget *content;
GtkWidget *viewport;
GeditTimePluginPromptType prompt_type;
......@@ -775,7 +777,9 @@ get_configure_dialog (GeditTimePlugin *plugin)
g_return_val_if_fail (dialog->dialog != NULL, NULL);
ret = gedit_utils_get_ui_objects (GEDIT_UIDIR "time.ui",
data_dir = gedit_plugin_get_data_dir (GEDIT_PLUGIN (plugin));
ui_file = g_build_filename (data_dir, "time.ui", NULL);
ret = gedit_utils_get_ui_objects (ui_file,
root_objects,
&error_widget,
"time_dialog_content", &content,
......@@ -788,6 +792,9 @@ get_configure_dialog (GeditTimePlugin *plugin)
"custom_format_example", &dialog->custom_format_example,
NULL);
g_free (data_dir);
g_free (ui_file);
if (!ret)
{
gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (dialog->dialog)->vbox),
......@@ -917,13 +924,17 @@ get_choose_format_dialog (GtkWindow *parent,
GeditTimePlugin *plugin)
{
ChooseFormatDialog *dialog;
gchar *data_dir;
gchar *ui_file;
GtkWidget *error_widget;
gboolean ret;
gchar *sf, *cf;
dialog = g_new0 (ChooseFormatDialog, 1);
ret = gedit_utils_get_ui_objects (GEDIT_UIDIR "time.ui",
data_dir = gedit_plugin_get_data_dir (GEDIT_PLUGIN (plugin));
ui_file = g_build_filename (data_dir, "time.ui", NULL);
ret = gedit_utils_get_ui_objects (ui_file,
NULL,
&error_widget,
"choose_format_dialog", &dialog->dialog,
......@@ -934,6 +945,9 @@ get_choose_format_dialog (GtkWindow *parent,
"custom_format_example", &dialog->custom_format_example,
NULL);
g_free (data_dir);
g_free (ui_file);
if (!ret)
{
const gchar *err_message;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment