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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "anjuta-plugin-handle.h"
23 #include "resources.h"
24 #include "anjuta-debug.h"
34 PROP_USER_ACTIVATABLE
,
36 PROP_DEPENDENCY_NAMES
,
45 struct _AnjutaPluginHandlePriv
51 gboolean user_activatable
;
53 AnjutaPluginDescription
*description
;
55 /* The dependencies listed in the oaf file */
56 GList
*dependency_names
;
58 /* Interfaces exported by this plugin */
61 /* Attributes defined for this plugin */
62 /* GHashTable *attributes; */
64 /* The keys of these tables represent the dependencies and dependents
65 * of the module. The values point back at the plugins */
66 GHashTable
*dependencies
;
67 GHashTable
*dependents
;
72 /* The pass on which the module was resolved, or -1 if
77 static GObjectClass
* parent_class
= NULL
;
80 anjuta_plugin_handle_init (AnjutaPluginHandle
*object
)
82 object
->priv
= g_new0 (AnjutaPluginHandlePriv
, 1);
84 object
->priv
->resolve_pass
= -1;
86 object
->priv
->dependencies
= g_hash_table_new (g_direct_hash
,
88 object
->priv
->dependents
= g_hash_table_new (g_direct_hash
,
93 anjuta_plugin_handle_finalize (GObject
*object
)
95 AnjutaPluginHandlePriv
*priv
;
97 priv
= ANJUTA_PLUGIN_HANDLE (object
)->priv
;
103 g_free (priv
->icon_path
);
104 priv
->icon_path
= NULL
;
106 g_list_foreach (priv
->dependency_names
, (GFunc
)g_free
, NULL
);
107 g_list_free (priv
->dependency_names
);
108 priv
->dependency_names
= NULL
;
110 g_list_foreach (priv
->interfaces
, (GFunc
)g_free
, NULL
);
111 g_list_free (priv
->dependency_names
);
112 priv
->dependency_names
= NULL
;
114 g_hash_table_destroy (priv
->dependencies
);
115 priv
->dependencies
= NULL
;
116 g_hash_table_destroy (priv
->dependents
);
117 priv
->dependents
= NULL
;
121 G_OBJECT_CLASS (parent_class
)->finalize (object
);
125 anjuta_plugin_handle_set_property (GObject
*object
, guint prop_id
,
126 const GValue
*value
, GParamSpec
*pspec
)
128 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (object
));
134 /* TODO: Add setter for "id" property here */
137 /* TODO: Add setter for "name" property here */
140 /* TODO: Add setter for "about" property here */
143 /* TODO: Add setter for "icon-path" property here */
145 case PROP_USER_ACTIVATABLE
:
146 /* TODO: Add setter for "user-activatable" property here */
148 case PROP_DESCRIPTION
:
149 /* TODO: Add setter for "description" property here */
151 case PROP_DEPENDENCY_NAMES
:
152 /* TODO: Add setter for "dependency-names" property here */
154 case PROP_DEPENDENCIES
:
155 /* TODO: Add setter for "dependencies" property here */
157 case PROP_DEPENDENTS
:
158 /* TODO: Add setter for "dependents" property here */
160 case PROP_INTERFACES
:
161 /* TODO: Add setter for "interfaces" property here */
164 /* TODO: Add setter for "can-load" property here */
167 /* TODO: Add setter for "checked" property here */
169 case PROP_RESOLVE_PASS
:
170 /* TODO: Add setter for "resolve-pass" property here */
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
180 anjuta_plugin_handle_get_property (GObject
*object
, guint prop_id
,
181 GValue
*value
, GParamSpec
*pspec
)
183 AnjutaPluginHandlePriv
*priv
;
185 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (object
));
186 priv
= ANJUTA_PLUGIN_HANDLE (object
)->priv
;
190 g_value_set_string (value
, priv
->id
);
193 g_value_set_string (value
, priv
->name
);
196 g_value_set_string (value
, priv
->about
);
199 g_value_set_string (value
, priv
->icon_path
);
201 case PROP_USER_ACTIVATABLE
:
202 g_value_set_boolean (value
, priv
->user_activatable
);
204 case PROP_DESCRIPTION
:
205 g_value_set_pointer (value
, priv
->description
);
207 case PROP_DEPENDENCY_NAMES
:
208 g_value_set_pointer (value
, priv
->dependency_names
);
210 case PROP_DEPENDENCIES
:
211 g_value_set_pointer (value
, priv
->dependencies
);
213 case PROP_DEPENDENTS
:
214 g_value_set_pointer (value
, priv
->dependents
);
216 case PROP_INTERFACES
:
217 g_value_set_pointer (value
, priv
->interfaces
);
220 g_value_set_boolean (value
, priv
->can_load
);
223 g_value_set_boolean (value
, priv
->checked
);
225 case PROP_RESOLVE_PASS
:
226 g_value_set_int (value
, priv
->resolve_pass
);
229 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
235 anjuta_plugin_handle_class_init (AnjutaPluginHandleClass
*klass
)
237 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
238 parent_class
= G_OBJECT_CLASS (g_type_class_peek_parent (klass
));
240 object_class
->finalize
= anjuta_plugin_handle_finalize
;
241 object_class
->set_property
= anjuta_plugin_handle_set_property
;
242 object_class
->get_property
= anjuta_plugin_handle_get_property
;
244 g_object_class_install_property (object_class
,
246 g_param_spec_string ("id",
252 g_object_class_install_property (object_class
,
254 g_param_spec_string ("name",
260 g_object_class_install_property (object_class
,
262 g_param_spec_string ("about",
264 "About description of the plugin",
268 g_object_class_install_property (object_class
,
270 g_param_spec_string ("icon-path",
272 "Icon path of the plugin",
276 g_object_class_install_property (object_class
,
277 PROP_USER_ACTIVATABLE
,
278 g_param_spec_boolean ("user-activatable",
280 "If the plugin is user activatable",
284 g_object_class_install_property (object_class
,
286 g_param_spec_pointer ("description",
288 "Plugin description",
291 g_object_class_install_property (object_class
,
292 PROP_DEPENDENCY_NAMES
,
293 g_param_spec_pointer ("dependency-names",
295 "Plugin dependency names listed in oaf file",
298 g_object_class_install_property (object_class
,
300 g_param_spec_pointer ("dependencies",
302 "Plugin dependencies",
305 g_object_class_install_property (object_class
,
307 g_param_spec_pointer ("dependents",
312 g_object_class_install_property (object_class
,
314 g_param_spec_pointer ("interfaces",
316 "Interfaces exported by the plugin",
319 g_object_class_install_property (object_class
,
321 g_param_spec_boolean ("can-load",
323 "If the plugin can be loaded",
327 g_object_class_install_property (object_class
,
329 g_param_spec_boolean ("checked",
331 "If the plugin is checked in UI",
335 g_object_class_install_property (object_class
,
337 g_param_spec_int ("resolve-pass",
339 "Dependency resolution pass",
340 G_MININT
, /* TODO: Adjust minimum property value */
341 G_MAXINT
, /* TODO: Adjust maximum property value */
347 anjuta_plugin_handle_get_type (void)
349 static GType our_type
= 0;
353 static const GTypeInfo our_info
=
355 sizeof (AnjutaPluginHandleClass
), /* class_size */
356 (GBaseInitFunc
) NULL
, /* base_init */
357 (GBaseFinalizeFunc
) NULL
, /* base_finalize */
358 (GClassInitFunc
) anjuta_plugin_handle_class_init
, /* class_init */
359 (GClassFinalizeFunc
) NULL
, /* class_finalize */
360 NULL
/* class_data */,
361 sizeof (AnjutaPluginHandle
), /* instance_size */
363 (GInstanceInitFunc
) anjuta_plugin_handle_init
, /* instance_init */
364 NULL
/* value_table */
367 our_type
= g_type_register_static (G_TYPE_OBJECT
, "AnjutaPluginHandle",
376 get_icon_path (char *icon_name
)
380 if (g_path_is_absolute (icon_name
)) {
381 ret
= g_strdup (icon_name
);
383 ret
= anjuta_res_get_pixmap_file (icon_name
);
390 property_to_list (const char *value
)
396 split_str
= g_strsplit (value
, ",", -1);
397 for (p
= split_str
; *p
!= NULL
; p
++) {
398 l
= g_list_prepend (l
, g_strdup (g_strstrip (*p
)));
400 g_strfreev (split_str
);
405 anjuta_plugin_handle_new (const gchar
*plugin_desc_path
)
407 AnjutaPluginHandle
*plugin_handle
;
408 AnjutaPluginDescription
*desc
;
411 gboolean success
= TRUE
;
413 /* Load file content */
414 if (g_file_get_contents (plugin_desc_path
, &contents
, NULL
, NULL
)) {
416 desc
= anjuta_plugin_description_new_from_string (contents
, NULL
);
419 g_warning ("Bad plugin file: %s\n", plugin_desc_path
);
428 plugin_handle
= g_object_new (ANJUTA_TYPE_PLUGIN_HANDLE
, NULL
);
430 /* Initialize plugin handle */
431 plugin_handle
->priv
->description
= desc
;
432 plugin_handle
->priv
->user_activatable
= TRUE
;
434 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
436 plugin_handle
->priv
->id
= str
;
438 g_warning ("Couldn't find 'Location'");
442 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
444 plugin_handle
->priv
->name
= str
;
446 g_warning ("couldn't find 'Name' attribute.");
450 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
451 "Description", &str
)) {
452 plugin_handle
->priv
->about
= str
;
454 g_warning ("Couldn't find 'Description' attribute.");
458 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
460 plugin_handle
->priv
->icon_path
= get_icon_path (str
);
464 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
467 plugin_handle
->priv
->dependency_names
= property_to_list (str
);
471 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
474 plugin_handle
->priv
->interfaces
= property_to_list (str
);
478 if (anjuta_plugin_description_get_string (desc
, "Anjuta Plugin",
479 "UserActivatable", &str
)) {
480 if (str
&& strcasecmp (str
, "no") == 0)
482 plugin_handle
->priv
->user_activatable
= FALSE
;
484 DEBUG_PRINT ("Plugin '%s' is not user activatable",
485 plugin_handle->priv->name?
486 plugin_handle->priv->name : "Unknown");
492 g_object_unref (plugin_handle
);
493 plugin_handle
= NULL
;
496 return plugin_handle
;
500 anjuta_plugin_handle_get_id (AnjutaPluginHandle
*plugin_handle
)
502 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
503 return plugin_handle
->priv
->id
;
507 anjuta_plugin_handle_get_name (AnjutaPluginHandle
*plugin_handle
)
509 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
510 return plugin_handle
->priv
->name
;
514 anjuta_plugin_handle_get_about (AnjutaPluginHandle
*plugin_handle
)
516 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
517 return plugin_handle
->priv
->about
;
521 anjuta_plugin_handle_get_icon_path (AnjutaPluginHandle
*plugin_handle
)
523 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
524 return plugin_handle
->priv
->icon_path
;
528 anjuta_plugin_handle_get_user_activatable (AnjutaPluginHandle
*plugin_handle
)
530 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
531 return plugin_handle
->priv
->user_activatable
;
534 AnjutaPluginDescription
*
535 anjuta_plugin_handle_get_description (AnjutaPluginHandle
*plugin_handle
)
537 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
538 return plugin_handle
->priv
->description
;
542 anjuta_plugin_handle_get_dependency_names (AnjutaPluginHandle
*plugin_handle
)
544 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
545 return plugin_handle
->priv
->dependency_names
;
549 anjuta_plugin_handle_get_dependencies (AnjutaPluginHandle
*plugin_handle
)
551 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
552 return plugin_handle
->priv
->dependencies
;
556 anjuta_plugin_handle_get_dependents (AnjutaPluginHandle
*plugin_handle
)
558 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
559 return plugin_handle
->priv
->dependents
;
563 anjuta_plugin_handle_get_interfaces (AnjutaPluginHandle
*plugin_handle
)
565 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), NULL
);
566 return plugin_handle
->priv
->interfaces
;
570 anjuta_plugin_handle_get_can_load (AnjutaPluginHandle
*plugin_handle
)
572 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
573 return plugin_handle
->priv
->can_load
;
577 anjuta_plugin_handle_get_checked (AnjutaPluginHandle
*plugin_handle
)
579 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), FALSE
);
580 return plugin_handle
->priv
->checked
;
584 anjuta_plugin_handle_get_resolve_pass (AnjutaPluginHandle
*plugin_handle
)
586 g_return_val_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
), 0);
587 return plugin_handle
->priv
->resolve_pass
;
591 anjuta_plugin_handle_set_can_load (AnjutaPluginHandle
*plugin_handle
,
594 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
595 plugin_handle
->priv
->can_load
= can_load
;
599 anjuta_plugin_handle_set_checked (AnjutaPluginHandle
*plugin_handle
,
602 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
603 plugin_handle
->priv
->checked
= checked
;
607 anjuta_plugin_handle_set_resolve_pass (AnjutaPluginHandle
*plugin_handle
,
608 gboolean resolve_pass
)
610 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
611 plugin_handle
->priv
->resolve_pass
= resolve_pass
;
615 g_hashtable_foreach_true (gpointer key
, gpointer value
, gpointer user_data
)
621 anjuta_plugin_handle_unresolve_dependencies (AnjutaPluginHandle
*plugin_handle
)
623 AnjutaPluginHandlePriv
*priv
;
625 g_return_if_fail (ANJUTA_IS_PLUGIN_HANDLE (plugin_handle
));
626 priv
= plugin_handle
->priv
;
628 g_hash_table_foreach_remove (priv
->dependencies
, g_hashtable_foreach_true
,
630 g_hash_table_foreach_remove (priv
->dependents
, g_hashtable_foreach_true
,
632 priv
->can_load
= TRUE
;
633 priv
->resolve_pass
= -1;