1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * anjuta-plugin-handle.c
4 * Copyright (C) Naba Kumar <naba@gnome.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * SECTION:anjuta-plugin-handle
23 * @short_description: Handle used by plugin manager to keep track of plugins.
24 * @see_also: #AnjutaPluginManager, #AnjutaPluginDescription, #AnjutaPlugin
25 * @stability: Unstable
26 * @include: libanjuta/anjuta-plugin-handle.h
28 * Plugin handle is wrapper for installed plugins. For each installed plugin
29 * there will be one corresponding plugin handle. It is mainly used by
30 * plugin manager to keep track of loading and unloading of plugins.
34 #include <glib/gi18n.h>
35 #include "anjuta-plugin-handle.h"
36 #include "resources.h"
37 #include "anjuta-debug.h"
47 PROP_USER_ACTIVATABLE
,
51 PROP_DEPENDENCY_NAMES
,
62 struct _AnjutaPluginHandlePriv
69 gboolean user_activatable
;
73 AnjutaPluginDescription
*description
;
75 /* The dependencies listed in the oaf file */
76 GList
*dependency_names
;
78 /* Interfaces exported by this plugin */
81 /* Attributes defined for this plugin */
82 /* GHashTable *attributes; */
84 /* The keys of these tables represent the dependencies and dependents
85 * of the module. The values point back at the plugins */
86 GHashTable
*dependencies
;
87 GHashTable
*dependents
;
93 /* The pass on which the module was resolved, or -1 if
98 static GObjectClass
* parent_class
= NULL
;
101 anjuta_plugin_handle_init (AnjutaPluginHandle
*object
)
103 object
->priv
= g_new0 (AnjutaPluginHandlePriv
, 1);
105 object
->priv
->resolve_pass
= -1;
106 object
->priv
->can_unload
= TRUE
;
108 object
->priv
->dependencies
= g_hash_table_new (g_direct_hash
,
110 object
->priv
->dependents
= g_hash_table_new (g_direct_hash
,
115 anjuta_plugin_handle_finalize (GObject
*object
)
117 AnjutaPluginHandlePriv
*priv
;
119 priv
= ANJUTA_PLUGIN_HANDLE (object
)->priv
;
125 g_free (priv
->icon_path
);
126 priv
->icon_path
= NULL
;
129 g_free (priv
->language
);
130 priv
->language
= NULL
;
132 g_list_foreach (priv
->dependency_names
, (GFunc
)g_free
, NULL
);
133 g_list_free (priv
->dependency_names
);
134 priv
->dependency_names
= NULL
;
136 g_list_foreach (priv
->interfaces
, (GFunc
)g_free
, NULL
);
137 g_list_free (priv
->dependency_names
);
138 priv
->dependency_names
= NULL
;
140 g_hash_table_destroy (priv
->dependencies
);
141 priv
->dependencies
= NULL
;
142 g_hash_table_destroy (priv
->dependents
);
143 priv
->dependents
= NULL
;
147 G_OBJECT_CLASS (parent_class
)->finalize (object
);
151 anjuta_plugin_handle_set_property (GObject
*object
, guint prop_id
,
152 const GValue
*value
, GParamSpec
*pspec
)
154 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (object
));
160 /* TODO: Add setter for "id" property here */
163 /* TODO: Add setter for "name" property here */
166 /* TODO: Add setter for "about" property here */
169 /* TODO: Add setter for "icon-path" property here */
172 /* TODO: Add setter for "path" property here */
174 case PROP_USER_ACTIVATABLE
:
175 /* TODO: Add setter for "user-activatable" property here */
178 /* TODO: Add setter for "resident" property here */
181 /* TODO: Add setter for "language" property here */
183 case PROP_DESCRIPTION
:
184 /* TODO: Add setter for "description" property here */
186 case PROP_DEPENDENCY_NAMES
:
187 /* TODO: Add setter for "dependency-names" property here */
189 case PROP_DEPENDENCIES
:
190 /* TODO: Add setter for "dependencies" property here */
192 case PROP_DEPENDENTS
:
193 /* TODO: Add setter for "dependents" property here */
195 case PROP_INTERFACES
:
196 /* TODO: Add setter for "interfaces" property here */
199 /* TODO: Add setter for "can-load" property here */
201 case PROP_CAN_UNLOAD
:
202 /* TODO: Add setter for "can-unload" property here */
205 /* TODO: Add setter for "checked" property here */
207 case PROP_RESOLVE_PASS
:
208 /* TODO: Add setter for "resolve-pass" property here */
212 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
218 anjuta_plugin_handle_get_property (GObject
*object
, guint prop_id
,
219 GValue
*value
, GParamSpec
*pspec
)
221 AnjutaPluginHandlePriv
*priv
;
223 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (object
));
224 priv
= ANJUTA_PLUGIN_HANDLE (object
)->priv
;
228 g_value_set_string (value
, priv
->id
);
231 g_value_set_string (value
, priv
->name
);
234 g_value_set_string (value
, priv
->about
);
237 g_value_set_string (value
, priv
->icon_path
);
240 g_value_set_string (value
, priv
->path
);
242 case PROP_USER_ACTIVATABLE
:
243 g_value_set_boolean (value
, priv
->user_activatable
);
246 g_value_set_boolean (value
, priv
->resident
);
249 g_value_set_string (value
, priv
->language
);
251 case PROP_DESCRIPTION
:
252 g_value_set_pointer (value
, priv
->description
);
254 case PROP_DEPENDENCY_NAMES
:
255 g_value_set_pointer (value
, priv
->dependency_names
);
257 case PROP_DEPENDENCIES
:
258 g_value_set_pointer (value
, priv
->dependencies
);
260 case PROP_DEPENDENTS
:
261 g_value_set_pointer (value
, priv
->dependents
);
263 case PROP_INTERFACES
:
264 g_value_set_pointer (value
, priv
->interfaces
);
267 g_value_set_boolean (value
, priv
->can_load
);
269 case PROP_CAN_UNLOAD
:
270 g_value_set_boolean (value
, priv
->can_unload
);
273 g_value_set_boolean (value
, priv
->checked
);
275 case PROP_RESOLVE_PASS
:
276 g_value_set_int (value
, priv
->resolve_pass
);
279 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
285 anjuta_plugin_handle_class_init (AnjutaPluginHandleClass
*klass
)
287 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
288 parent_class
= G_OBJECT_CLASS (g_type_class_peek_parent (klass
));
290 object_class
->finalize
= anjuta_plugin_handle_finalize
;
291 object_class
->set_property
= anjuta_plugin_handle_set_property
;
292 object_class
->get_property
= anjuta_plugin_handle_get_property
;
294 g_object_class_install_property (object_class
,
296 g_param_spec_string ("id",
302 g_object_class_install_property (object_class
,
304 g_param_spec_string ("name",
310 g_object_class_install_property (object_class
,
312 g_param_spec_string ("about",
314 "About description of the plugin",
318 g_object_class_install_property (object_class
,
320 g_param_spec_string ("icon-path",
322 "Icon path of the plugin",
326 g_object_class_install_property (object_class
,
328 g_param_spec_string ("path",
330 "Path of the plugin",
334 g_object_class_install_property (object_class
,
335 PROP_USER_ACTIVATABLE
,
336 g_param_spec_boolean ("user-activatable",
338 "If the plugin is user activatable",
342 g_object_class_install_property (object_class
,
344 g_param_spec_boolean ("resident",
346 "If the plugin cannot be unloaded",
350 g_object_class_install_property (object_class
,
352 g_param_spec_string ("language",
354 "Language used to write the plugin",
358 g_object_class_install_property (object_class
,
360 g_param_spec_pointer ("description",
362 "Plugin description",
365 g_object_class_install_property (object_class
,
366 PROP_DEPENDENCY_NAMES
,
367 g_param_spec_pointer ("dependency-names",
369 "Plugin dependency names listed in oaf file",
372 g_object_class_install_property (object_class
,
374 g_param_spec_pointer ("dependencies",
376 "Plugin dependencies",
379 g_object_class_install_property (object_class
,
381 g_param_spec_pointer ("dependents",
386 g_object_class_install_property (object_class
,
388 g_param_spec_pointer ("interfaces",
390 "Interfaces exported by the plugin",
393 g_object_class_install_property (object_class
,
395 g_param_spec_boolean ("can-load",
397 "If the plugin can be loaded",
401 g_object_class_install_property (object_class
,
403 g_param_spec_boolean ("can-unload",
405 "If the plugin can be unloaded",
409 g_object_class_install_property (object_class
,
411 g_param_spec_boolean ("checked",
413 "If the plugin is checked in UI",
417 g_object_class_install_property (object_class
,
419 g_param_spec_int ("resolve-pass",
421 "Dependency resolution pass",
422 G_MININT
, /* TODO: Adjust minimum property value */
423 G_MAXINT
, /* TODO: Adjust maximum property value */
429 anjuta_plugin_handle_get_type (void)
431 static GType our_type
= 0;
435 static const GTypeInfo our_info
=
437 sizeof (AnjutaPluginHandleClass
), /* class_size */
438 (GBaseInitFunc
) NULL
, /* base_init */
439 (GBaseFinalizeFunc
) NULL
, /* base_finalize */
440 (GClassInitFunc
) anjuta_plugin_handle_class_init
, /* class_init */
441 (GClassFinalizeFunc
) NULL
, /* class_finalize */
442 NULL
/* class_data */,
443 sizeof (AnjutaPluginHandle
), /* instance_size */
445 (GInstanceInitFunc
) anjuta_plugin_handle_init
, /* instance_init */
446 NULL
/* value_table */
449 our_type
= g_type_register_static (G_TYPE_OBJECT
, "AnjutaPluginHandle",
458 get_icon_path (char *icon_name
)
462 if (g_path_is_absolute (icon_name
)) {
463 ret
= g_strdup (icon_name
);
465 ret
= anjuta_res_get_pixmap_file (icon_name
);
472 property_to_list (const char *value
)
478 split_str
= g_strsplit (value
, ",", -1);
479 for (p
= split_str
; *p
!= NULL
; p
++) {
480 l
= g_list_prepend (l
, g_strdup (g_strstrip (*p
)));
482 g_strfreev (split_str
);
487 anjuta_plugin_handle_new (const gchar
*plugin_desc_path
)
489 AnjutaPluginHandle
*plugin_handle
;
490 AnjutaPluginDescription
*desc
;
493 gchar
*contents
= NULL
;
494 gboolean success
= TRUE
;
496 /* Load file content */
497 if (g_file_get_contents (plugin_desc_path
, &contents
, NULL
, NULL
)) {
499 desc
= anjuta_plugin_description_new_from_string (contents
, NULL
);
502 g_warning ("Bad plugin file: %s\n", plugin_desc_path
);
511 plugin_handle
= g_object_new (ANJUTA_TYPE_PLUGIN_HANDLE
, NULL
);
513 /* Initialize plugin handle */
514 plugin_handle
->priv
->description
= desc
;
515 plugin_handle
->priv
->user_activatable
= TRUE
;
516 plugin_handle
->priv
->resident
= TRUE
;
517 plugin_handle
->priv
->path
= g_path_get_dirname (plugin_desc_path
);
519 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
521 plugin_handle
->priv
->id
= str
;
523 g_warning ("Couldn't find 'Location'");
527 if (anjuta_plugin_description_get_locale_string (desc
, "Anjuta Plugin",
529 plugin_handle
->priv
->name
= str
;
531 g_warning ("couldn't find 'Name' attribute.");
535 if (anjuta_plugin_description_get_locale_string (desc
, "Anjuta Plugin",
536 "Description", &str
)) {
537 plugin_handle
->priv
->about
= str
;
539 g_warning ("Couldn't find 'Description' attribute.");
543 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
545 plugin_handle
->priv
->icon_path
= get_icon_path (str
);
549 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
552 plugin_handle
->priv
->dependency_names
= property_to_list (str
);
556 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
559 plugin_handle
->priv
->interfaces
= property_to_list (str
);
563 if (anjuta_plugin_description_get_boolean (desc
, "Anjuta Plugin",
564 "UserActivatable", &enable
)) {
565 plugin_handle
->priv
->user_activatable
= enable
;
567 DEBUG_PRINT ("Plugin '%s' is not user activatable",
568 plugin_handle->priv->name?
569 plugin_handle->priv->name : "Unknown");
573 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
575 if (str
&& strcasecmp (str
, "no") == 0)
577 plugin_handle
->priv
->resident
= FALSE
;
582 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
584 plugin_handle
->priv
->language
= str
;
588 g_object_unref (plugin_handle
);
589 plugin_handle
= NULL
;
592 return plugin_handle
;
596 anjuta_plugin_handle_get_id (AnjutaPluginHandle
*plugin_handle
)
598 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
599 return plugin_handle
->priv
->id
;
603 anjuta_plugin_handle_get_name (AnjutaPluginHandle
*plugin_handle
)
605 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
606 return plugin_handle
->priv
->name
;
610 anjuta_plugin_handle_get_about (AnjutaPluginHandle
*plugin_handle
)
612 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
613 return _(plugin_handle
->priv
->about
);
617 anjuta_plugin_handle_get_icon_path (AnjutaPluginHandle
*plugin_handle
)
619 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
620 return plugin_handle
->priv
->icon_path
;
624 anjuta_plugin_handle_get_path (AnjutaPluginHandle
*plugin_handle
)
626 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
627 return plugin_handle
->priv
->path
;
631 anjuta_plugin_handle_get_user_activatable (AnjutaPluginHandle
*plugin_handle
)
633 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
634 return plugin_handle
->priv
->user_activatable
;
638 anjuta_plugin_handle_get_resident (AnjutaPluginHandle
*plugin_handle
)
640 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
641 return plugin_handle
->priv
->resident
;
645 anjuta_plugin_handle_get_language (AnjutaPluginHandle
*plugin_handle
)
647 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
648 return plugin_handle
->priv
->language
;
651 AnjutaPluginDescription
*
652 anjuta_plugin_handle_get_description (AnjutaPluginHandle
*plugin_handle
)
654 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
655 return plugin_handle
->priv
->description
;
659 anjuta_plugin_handle_get_dependency_names (AnjutaPluginHandle
*plugin_handle
)
661 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
662 return plugin_handle
->priv
->dependency_names
;
666 anjuta_plugin_handle_get_dependencies (AnjutaPluginHandle
*plugin_handle
)
668 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
669 return plugin_handle
->priv
->dependencies
;
673 anjuta_plugin_handle_get_dependents (AnjutaPluginHandle
*plugin_handle
)
675 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
676 return plugin_handle
->priv
->dependents
;
680 anjuta_plugin_handle_get_interfaces (AnjutaPluginHandle
*plugin_handle
)
682 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
683 return plugin_handle
->priv
->interfaces
;
687 anjuta_plugin_handle_get_can_load (AnjutaPluginHandle
*plugin_handle
)
689 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
690 return plugin_handle
->priv
->can_load
;
694 anjuta_plugin_handle_get_can_unload (AnjutaPluginHandle
*plugin_handle
)
696 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
697 return plugin_handle
->priv
->can_unload
;
701 anjuta_plugin_handle_get_checked (AnjutaPluginHandle
*plugin_handle
)
703 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
704 return plugin_handle
->priv
->checked
;
708 anjuta_plugin_handle_get_resolve_pass (AnjutaPluginHandle
*plugin_handle
)
710 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), 0);
711 return plugin_handle
->priv
->resolve_pass
;
715 anjuta_plugin_handle_set_can_load (AnjutaPluginHandle
*plugin_handle
,
718 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
719 plugin_handle
->priv
->can_load
= can_load
;
723 anjuta_plugin_handle_set_can_unload (AnjutaPluginHandle
*plugin_handle
,
726 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
727 plugin_handle
->priv
->can_unload
= can_unload
;
731 anjuta_plugin_handle_set_checked (AnjutaPluginHandle
*plugin_handle
,
734 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
735 plugin_handle
->priv
->checked
= checked
;
739 anjuta_plugin_handle_set_resolve_pass (AnjutaPluginHandle
*plugin_handle
,
740 gboolean resolve_pass
)
742 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
743 plugin_handle
->priv
->resolve_pass
= resolve_pass
;
747 anjuta_plugin_handle_unresolve_dependencies (AnjutaPluginHandle
*plugin_handle
)
749 AnjutaPluginHandlePriv
*priv
;
751 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
752 priv
= plugin_handle
->priv
;
754 g_hash_table_remove_all (priv
->dependencies
);
755 g_hash_table_remove_all (priv
->dependents
);
757 priv
->can_load
= TRUE
;
758 priv
->resolve_pass
= -1;