/soc/2013/ankitkv/gobjectification: d402ca995746: Added a boxed ...
Ankit Vani
a at nevitus.org
Wed Jul 31 09:41:01 EDT 2013
Changeset: d402ca995746464dad0c0785fab0d1a9df585889
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-31 16:55 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/d402ca995746
Description:
Added a boxed type PurplePluginAction with purple_plugin_actions_add() to add an action to a plugin.
diffstat:
libpurple/plugins.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
libpurple/plugins.h | 46 +++++++++++++++++++++++++++++-
2 files changed, 124 insertions(+), 2 deletions(-)
diffs (186 lines):
diff --git a/libpurple/plugins.c b/libpurple/plugins.c
--- a/libpurple/plugins.c
+++ b/libpurple/plugins.c
@@ -34,6 +34,7 @@ typedef struct _PurplePluginInfoPrivate
* Plugin info private data
**************************************************************************/
struct _PurplePluginInfoPrivate {
+ GList *actions; /**< Actions that the plugin can perform >*/
};
enum
@@ -172,6 +173,13 @@ purple_plugin_info_dispose(GObject *obje
static void
purple_plugin_info_finalize(GObject *object)
{
+ PurplePluginInfoPrivate *priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(object);
+
+ while (priv->actions) {
+ g_boxed_free(PURPLE_TYPE_PLUGIN_ACTION, priv->actions->data);
+ priv->actions = g_list_delete_link(priv->actions, priv->actions);
+ }
+
G_OBJECT_CLASS(parent_class)->finalize(object);
}
@@ -216,6 +224,74 @@ purple_plugin_info_get_type(void)
}
/**************************************************************************
+ * PluginAction API
+ **************************************************************************/
+static void
+purple_plugin_action_free(PurplePluginAction *action)
+{
+ g_return_if_fail(action != NULL);
+
+ g_free(action->label);
+ g_free(action);
+}
+
+static PurplePluginAction *
+purple_plugin_action_copy(PurplePluginAction *action)
+{
+ PurplePluginAction *action_copy;
+
+ g_return_val_if_fail(action != NULL, NULL);
+
+ action_copy = g_new(PurplePluginAction, 1);
+
+ action_copy->label = g_strdup(action->label);
+ action_copy->callback = action->callback;
+
+ return action_copy;
+}
+
+GType
+purple_plugin_action_get_type(void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY(type == 0)) {
+ type = g_boxed_type_register_static("PurplePluginAction",
+ (GBoxedCopyFunc)purple_plugin_action_copy,
+ (GBoxedFreeFunc)purple_plugin_action_free);
+ }
+
+ return type;
+}
+
+/**************************************************************************
+ * Actions API
+ **************************************************************************/
+void
+purple_plugin_actions_add(GPluginPlugin *plugin, const char* label,
+ PurplePluginActionCallback callback)
+{
+ GPluginPluginInfo *plugin_info;
+ PurplePluginInfoPrivate *priv;
+ PurplePluginAction *action;
+
+ g_return_if_fail(plugin != NULL);
+ g_return_if_fail(label != NULL && callback != NULL);
+
+ plugin_info = gplugin_plugin_get_info(plugin);
+ priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(plugin_info);
+
+ action = g_new0(PurplePluginAction, 1);
+
+ action->label = g_strdup(label);
+ action->callback = callback;
+
+ priv->actions = g_list_append(priv->actions, action);
+
+ g_object_unref(plugin_info);
+}
+
+/**************************************************************************
* Plugins API
**************************************************************************/
GList *
@@ -290,9 +366,11 @@ purple_plugins_load_saved(const char *ke
} else {
purple_debug_error("plugins", "Unable to find saved plugin %s\n", id);
}
+
+ g_free(l->data);
}
- g_list_free_full(ids, (GDestroyNotify)g_free);
+ g_list_free(ids);
}
void
diff --git a/libpurple/plugins.h b/libpurple/plugins.h
--- a/libpurple/plugins.h
+++ b/libpurple/plugins.h
@@ -40,10 +40,17 @@ typedef struct _PurplePluginInfo PurpleP
/** @copydoc _PurplePluginInfoClass */
typedef struct _PurplePluginInfoClass PurplePluginInfoClass;
+#define PURPLE_TYPE_PLUGIN_ACTION (purple_plugin_action_get_type())
+
+/** @copydoc _PurplePluginAction */
+typedef struct _PurplePluginAction PurplePluginAction;
+
+typedef void (*PurplePluginActionCallback)(GPluginPlugin *);
+
#include "pluginpref.h"
/**
- * Detailed information about a plugin.
+ * Holds information about a plugin.
*/
struct _PurplePluginInfo {
/*< private >*/
@@ -65,6 +72,15 @@ struct _PurplePluginInfoClass {
void (*_purple_reserved4)(void);
};
+/**
+ * Represents an action that the plugin can perform. This shows up in the Tools
+ * menu, under a submenu with the name of the plugin.
+ */
+struct _PurplePluginAction {
+ char *label;
+ PurplePluginActionCallback callback;
+};
+
G_BEGIN_DECLS
/**************************************************************************/
@@ -118,6 +134,34 @@ GType purple_plugin_info_get_type(void);
/*@}*/
/**************************************************************************/
+/** @name PluginAction API */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Returns the GType for the PurplePluginAction boxed structure.
+ */
+GType purple_plugin_action_get_type(void);
+
+/*@}*/
+
+/**************************************************************************/
+/** @name Actions API */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Adds a new action to a plugin.
+ *
+ * @param label The description of the action to show to the user.
+ * @param callback The callback to call when the user selects this action.
+ */
+void purple_plugin_actions_add(GPluginPlugin *plugin, const char* label,
+ PurplePluginActionCallback callback);
+
+/*@}*/
+
+/**************************************************************************/
/** @name Plugins API */
/**************************************************************************/
/*@{*/
More information about the Commits
mailing list