2011-11-07 13:46:58 -06:00
|
|
|
/*
|
2011-11-07 16:52:18 -06:00
|
|
|
* pluma-plugin-info.c
|
|
|
|
* This file is part of pluma
|
2011-11-07 13:46:58 -06:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002-2005 - Paolo Maggi
|
|
|
|
* Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-18 19:54:49 -06:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-11-07 13:46:58 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-11-07 16:52:18 -06:00
|
|
|
* Modified by the pluma Team, 2002-2007. See the AUTHORS file for a
|
|
|
|
* list of people on the pluma Team.
|
2011-11-07 13:46:58 -06:00
|
|
|
* 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 <glib.h>
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
#include "pluma-plugin-info.h"
|
|
|
|
#include "pluma-plugin-info-priv.h"
|
|
|
|
#include "pluma-debug.h"
|
|
|
|
#include "pluma-plugin.h"
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
void
|
2011-11-07 16:52:18 -06:00
|
|
|
_pluma_plugin_info_ref (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_atomic_int_inc (&info->refcount);
|
|
|
|
}
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
static PlumaPluginInfo *
|
|
|
|
pluma_plugin_info_copy (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
_pluma_plugin_info_ref (info);
|
2011-11-07 13:46:58 -06:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-07 16:52:18 -06:00
|
|
|
_pluma_plugin_info_unref (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
if (!g_atomic_int_dec_and_test (&info->refcount))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info->plugin != NULL)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Unref plugin %s", info->name);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
g_object_unref (info->plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (info->file);
|
|
|
|
g_free (info->module_name);
|
|
|
|
g_strfreev (info->dependencies);
|
|
|
|
g_free (info->name);
|
|
|
|
g_free (info->desc);
|
|
|
|
g_free (info->icon_name);
|
|
|
|
g_free (info->website);
|
|
|
|
g_free (info->copyright);
|
|
|
|
g_free (info->loader);
|
|
|
|
g_free (info->version);
|
|
|
|
g_strfreev (info->authors);
|
|
|
|
|
|
|
|
g_free (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-07 16:52:18 -06:00
|
|
|
* pluma_plugin_info_get_type:
|
2011-11-07 13:46:58 -06:00
|
|
|
*
|
2011-11-07 16:52:18 -06:00
|
|
|
* Retrieves the #GType object which is associated with the #PlumaPluginInfo
|
2011-11-07 13:46:58 -06:00
|
|
|
* class.
|
|
|
|
*
|
2011-11-07 16:52:18 -06:00
|
|
|
* Return value: the GType associated with #PlumaPluginInfo.
|
2011-11-07 13:46:58 -06:00
|
|
|
**/
|
|
|
|
GType
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_type (void)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
static GType the_type = 0;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!the_type))
|
|
|
|
the_type = g_boxed_type_register_static (
|
2011-11-07 16:52:18 -06:00
|
|
|
"PlumaPluginInfo",
|
|
|
|
(GBoxedCopyFunc) pluma_plugin_info_copy,
|
|
|
|
(GBoxedFreeFunc) _pluma_plugin_info_unref);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
return the_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-07 16:52:18 -06:00
|
|
|
* pluma_plugin_info_new:
|
2011-11-07 13:46:58 -06:00
|
|
|
* @filename: the filename where to read the plugin information
|
|
|
|
*
|
2011-11-07 16:52:18 -06:00
|
|
|
* Creates a new #PlumaPluginInfo from a file on the disk.
|
2011-11-07 13:46:58 -06:00
|
|
|
*
|
2011-11-07 16:52:18 -06:00
|
|
|
* Return value: a newly created #PlumaPluginInfo.
|
2011-11-07 13:46:58 -06:00
|
|
|
*/
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginInfo *
|
|
|
|
_pluma_plugin_info_new (const gchar *file)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginInfo *info;
|
2011-11-07 13:46:58 -06:00
|
|
|
GKeyFile *plugin_file = NULL;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
g_return_val_if_fail (file != NULL, NULL);
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
info = g_new0 (PlumaPluginInfo, 1);
|
2011-11-07 13:46:58 -06:00
|
|
|
info->refcount = 1;
|
|
|
|
info->file = g_strdup (file);
|
|
|
|
|
|
|
|
plugin_file = g_key_file_new ();
|
|
|
|
if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL))
|
|
|
|
{
|
|
|
|
g_warning ("Bad plugin file: %s", file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_key_file_has_key (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"IAge",
|
|
|
|
NULL))
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS,
|
2011-11-07 13:46:58 -06:00
|
|
|
"IAge key does not exist in file: %s", file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check IAge=2 */
|
|
|
|
if (g_key_file_get_integer (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"IAge",
|
|
|
|
NULL) != 2)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS,
|
2011-11-07 13:46:58 -06:00
|
|
|
"Wrong IAge in file: %s", file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get module name */
|
|
|
|
str = g_key_file_get_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Module",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if ((str != NULL) && (*str != '\0'))
|
|
|
|
{
|
|
|
|
info->module_name = str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Could not find 'Module' in %s", file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the dependency list */
|
|
|
|
info->dependencies = g_key_file_get_string_list (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Depends",
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (info->dependencies == NULL)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Depends' in %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
info->dependencies = g_new0 (gchar *, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the loader for this plugin */
|
|
|
|
str = g_key_file_get_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Loader",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if ((str != NULL) && (*str != '\0'))
|
|
|
|
{
|
|
|
|
info->loader = str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* default to the C loader */
|
|
|
|
info->loader = g_strdup("c");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Name */
|
|
|
|
str = g_key_file_get_locale_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Name",
|
|
|
|
NULL, NULL);
|
|
|
|
if (str)
|
|
|
|
info->name = str;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Could not find 'Name' in %s", file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Description */
|
|
|
|
str = g_key_file_get_locale_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Description",
|
|
|
|
NULL, NULL);
|
|
|
|
if (str)
|
|
|
|
info->desc = str;
|
|
|
|
else
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Description' in %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
/* Get Icon */
|
|
|
|
str = g_key_file_get_locale_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Icon",
|
|
|
|
NULL, NULL);
|
|
|
|
if (str)
|
|
|
|
info->icon_name = str;
|
|
|
|
else
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Icon' in %s, using 'pluma-plugin'", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
|
|
|
|
/* Get Authors */
|
|
|
|
info->authors = g_key_file_get_string_list (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Authors",
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (info->authors == NULL)
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Authors' in %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
|
|
|
|
/* Get Copyright */
|
|
|
|
str = g_key_file_get_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Copyright",
|
|
|
|
NULL);
|
|
|
|
if (str)
|
|
|
|
info->copyright = str;
|
|
|
|
else
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Copyright' in %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
/* Get Website */
|
|
|
|
str = g_key_file_get_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Website",
|
|
|
|
NULL);
|
|
|
|
if (str)
|
|
|
|
info->website = str;
|
|
|
|
else
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Website' in %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
/* Get Version */
|
|
|
|
str = g_key_file_get_string (plugin_file,
|
2011-11-07 16:52:18 -06:00
|
|
|
"Pluma Plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
"Version",
|
|
|
|
NULL);
|
|
|
|
if (str)
|
|
|
|
info->version = str;
|
|
|
|
else
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Version' in %s", file);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
g_key_file_free (plugin_file);
|
|
|
|
|
|
|
|
/* If we know nothing about the availability of the plugin,
|
|
|
|
set it as available */
|
|
|
|
info->available = TRUE;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
|
|
|
error:
|
|
|
|
g_free (info->file);
|
|
|
|
g_free (info->module_name);
|
|
|
|
g_free (info->name);
|
|
|
|
g_free (info->loader);
|
|
|
|
g_free (info);
|
|
|
|
g_key_file_free (plugin_file);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_is_active (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
return info->available && info->plugin != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_is_available (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
return info->available != FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_is_configurable (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_debug_message (DEBUG_PLUGINS, "Is '%s' configurable?", info->name);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
if (info->plugin == NULL || !info->available)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
return pluma_plugin_is_configurable (info->plugin);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_module_name (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
return info->module_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_name (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
return info->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_description (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
return info->desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_icon_name (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
/* use the pluma-plugin icon as a default if the plugin does not
|
2011-11-07 13:46:58 -06:00
|
|
|
have its own */
|
|
|
|
if (info->icon_name != NULL &&
|
|
|
|
gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
|
|
|
|
info->icon_name))
|
|
|
|
return info->icon_name;
|
|
|
|
else
|
2011-11-07 16:52:18 -06:00
|
|
|
return "pluma-plugin";
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar **
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_authors (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, (const gchar **)NULL);
|
|
|
|
|
|
|
|
return (const gchar **) info->authors;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_website (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
return info->website;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_copyright (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
return info->copyright;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_info_get_version (PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
|
|
|
return info->version;
|
|
|
|
}
|