/soc/2013/ankitkv/gobjectification: a27e8b7a2938: Added a callba...
Ankit Vani
a at nevitus.org
Wed Jul 31 17:41:46 EDT 2013
Changeset: a27e8b7a2938c27db537068cdcc2f65dbb153d99
Author: Ankit Vani <a at nevitus.org>
Date: 2013-08-01 03:03 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/a27e8b7a2938
Description:
Added a callback to return preferences frame to plugin info.
* Added purple_plugin_info_set_pref_frame_callback()
* Added purple_plugin_info_get_pref_frame_callback()
diffstat:
finch/gntplugin.c | 57 +++++++++++++++++++++++++++++++++++++-------
finch/gntplugin.h | 67 ++++++++++++++++++++++++++++++++++++++--------------
libpurple/plugins.c | 43 ++++++++++++++++++++++++++++++---
libpurple/plugins.h | 24 +++++++++++++++++-
4 files changed, 158 insertions(+), 33 deletions(-)
diffs (300 lines):
diff --git a/finch/gntplugin.c b/finch/gntplugin.c
--- a/finch/gntplugin.c
+++ b/finch/gntplugin.c
@@ -42,6 +42,14 @@
#include "gntplugin.h"
#include "gntrequest.h"
+#define FINCH_PLUGIN_INFO_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), FINCH_TYPE_PLUGIN_INFO, FinchPluginInfoPrivate))
+
+typedef struct
+{
+ FinchPluginFrame frame;
+} FinchPluginInfoPrivate;
+
static struct
{
GntWidget *tree;
@@ -54,6 +62,31 @@ static GHashTable *confwins;
static GntWidget *process_pref_frame(PurplePluginPrefFrame *frame);
+/* Class initializer function */
+static void finch_plugin_info_class_init(FinchPluginInfoClass *klass)
+{
+ g_type_class_add_private(klass, sizeof(FinchPluginInfoPrivate));
+}
+
+GType
+finch_plugin_info_get_type(void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY(type == 0)) {
+ static const GTypeInfo info = {
+ .class_size = sizeof(FinchPluginInfoClass),
+ .class_init = (GClassInitFunc)finch_plugin_info_class_init,
+ .instance_size = sizeof(FinchPluginInfo),
+ };
+
+ type = g_type_register_static(PURPLE_TYPE_PLUGIN_INFO,
+ "FinchPluginInfo", &info, 0);
+ }
+
+ return type;
+}
+
static void
free_stringlist(GList *list)
{
@@ -62,17 +95,23 @@ free_stringlist(GList *list)
}
static void
-decide_conf_button(PurplePlugin *plugin)
+decide_conf_button(GPluginPlugin *plugin)
{
- if (purple_plugin_is_loaded(plugin) &&
- ((PURPLE_IS_GNT_PLUGIN(plugin) &&
- FINCH_PLUGIN_UI_INFO(plugin) != NULL) ||
- (plugin->info->prefs_info &&
- plugin->info->prefs_info->get_plugin_pref_frame)))
- gnt_widget_set_visible(plugins.conf, TRUE);
- else
- gnt_widget_set_visible(plugins.conf, FALSE);
+ gboolean visible = FALSE;
+ GPluginPluginInfo *info = gplugin_plugin_get_info(plugin);
+ if (purple_plugin_is_loaded(plugin)) {
+ if (FINCH_IS_PLUGIN_INFO(info)) {
+ FinchPluginInfoPrivate *priv = FINCH_PLUGIN_INFO_GET_PRIVATE(info);
+ if (priv->frame)
+ visible = TRUE;
+ } else if (purple_plugin_info_get_pref_frame_callback(PURPLE_PLUGIN_INFO(info))) {
+ visible = TRUE;
+ }
+ }
+ g_object_unref(info);
+
+ gnt_widget_set_visible(plugins.conf, visible);
gnt_box_readjust(GNT_BOX(plugins.window));
gnt_widget_draw(plugins.window);
}
diff --git a/finch/gntplugin.h b/finch/gntplugin.h
--- a/finch/gntplugin.h
+++ b/finch/gntplugin.h
@@ -35,29 +35,60 @@
#include "finch.h"
+#define FINCH_TYPE_PLUGIN_INFO (finch_plugin_info_get_type())
+#define FINCH_PLUGIN_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), FINCH_TYPE_PLUGIN_INFO, FinchPluginInfo))
+#define FINCH_PLUGIN_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), FINCH_TYPE_PLUGIN_INFO, FinchPluginInfoClass))
+#define FINCH_IS_PLUGIN_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), FINCH_TYPE_PLUGIN_INFO))
+#define FINCH_IS_PLUGIN_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), FINCH_TYPE_PLUGIN_INFO))
+#define FINCH_PLUGIN_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), FINCH_TYPE_PLUGIN_INFO, FinchPluginInfoClass))
+
+/** @copydoc _FinchPluginInfo */
+typedef struct _FinchPluginInfo FinchPluginInfo;
+/** @copydoc _FinchPluginInfoClass */
+typedef struct _FinchPluginInfoClass FinchPluginInfoClass;
+
+typedef GntWidget* (*FinchPluginFrame) (void);
+
+/**
+ * Extends #PurplePluginInfo to hold UI information for finch.
+ */
+struct _FinchPluginInfo {
+ /*< private >*/
+ PurplePluginInfo parent;
+};
+
+/**
+ * FinchPluginInfoClass:
+ *
+ * The base class for all #FinchPluginInfo's.
+ */
+struct _FinchPluginInfoClass {
+ /*< private >*/
+ PurplePluginInfoClass parent_class;
+
+ void (*_gnt_reserved1)(void);
+ void (*_gnt_reserved2)(void);
+ void (*_gnt_reserved3)(void);
+ void (*_gnt_reserved4)(void);
+};
+
+/**********************************************************************
+ * @name Plugin Info API
+ **********************************************************************/
+/*@{*/
+
+/**
+ * Returns the GType for the FinchPluginInfo object.
+ */
+GType finch_plugin_info_get_type(void);
+
+/*@}*/
+
/**********************************************************************
* @name GNT Plugins API
**********************************************************************/
/*@{*/
-typedef GntWidget* (*FinchPluginFrame) (void);
-
-/* Guess where these came from */
-#define FINCH_PLUGIN_TYPE FINCH_UI
-
-/**
- * Decide whether a plugin is a GNT-plugin.
- */
-#define PURPLE_IS_GNT_PLUGIN(plugin) \
- ((plugin)->info != NULL && (plugin)->info->ui_info != NULL && \
- !strcmp((plugin)->info->ui_requirement, FINCH_PLUGIN_TYPE))
-
-/**
- * Get the ui-info from GNT-plugins.
- */
-#define FINCH_PLUGIN_UI_INFO(plugin) \
- (FinchPluginFrame)((plugin)->info->ui_info)
-
/**
* Show a list of plugins.
*/
diff --git a/libpurple/plugins.c b/libpurple/plugins.c
--- a/libpurple/plugins.c
+++ b/libpurple/plugins.c
@@ -34,12 +34,16 @@ typedef struct _PurplePluginInfoPrivate
* Plugin info private data
**************************************************************************/
struct _PurplePluginInfoPrivate {
- GList *actions; /**< Actions that the plugin can perform >*/
+ GList *actions; /**< Actions that the plugin can perform >*/
+ PurplePluginPrefFrameCallback get_pref_frame; /**< Callback that returns a
+ preferences frame for a
+ plugin >*/
};
enum
{
PROP_0,
+ PROP_PREF_FRAME_CALLBACK,
PROP_LAST
};
@@ -122,7 +126,7 @@ purple_plugin_is_loaded(const GPluginPlu
* GObject code for PurplePluginInfo
**************************************************************************/
/* GObject Property names */
-#define PROP_S ""
+#define PROP_PREF_FRAME_CALLBACK_S "pref-frame-callback"
/* Set method for GObject properties */
static void
@@ -132,7 +136,9 @@ purple_plugin_info_set_property(GObject
PurplePluginInfo *plugin_info = PURPLE_PLUGIN_INFO(obj);
switch (param_id) {
- case PROP_0: /* TODO remove */
+ case PROP_PREF_FRAME_CALLBACK:
+ purple_plugin_info_set_pref_frame_callback(plugin_info,
+ g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
@@ -148,7 +154,9 @@ purple_plugin_info_get_property(GObject
PurplePluginInfo *plugin_info = PURPLE_PLUGIN_INFO(obj);
switch (param_id) {
- case PROP_0: /* TODO remove */
+ case PROP_PREF_FRAME_CALLBACK:
+ g_value_set_pointer(value,
+ purple_plugin_info_get_pref_frame_callback(plugin_info));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
@@ -198,6 +206,12 @@ static void purple_plugin_info_class_ini
/* Setup properties */
obj_class->get_property = purple_plugin_info_get_property;
obj_class->set_property = purple_plugin_info_set_property;
+
+ g_object_class_install_property(obj_class, PROP_PREF_FRAME_CALLBACK,
+ g_param_spec_pointer(PROP_PREF_FRAME_CALLBACK_S,
+ "Preferences frame callback",
+ "The callback that returns the preferences frame",
+ G_PARAM_READWRITE));
}
/**************************************************************************
@@ -233,6 +247,27 @@ purple_plugin_info_get_actions(PurplePlu
return priv->actions;
}
+void
+purple_plugin_info_set_pref_frame_callback(PurplePluginInfo *plugin_info,
+ PurplePluginPrefFrameCallback callback)
+{
+ PurplePluginInfoPrivate *priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(plugin_info);
+
+ g_return_if_fail(priv != NULL);
+
+ priv->get_pref_frame = callback;
+}
+
+PurplePluginPrefFrameCallback
+purple_plugin_info_get_pref_frame_callback(PurplePluginInfo *plugin_info)
+{
+ PurplePluginInfoPrivate *priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(plugin_info);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->get_pref_frame;
+}
+
/**************************************************************************
* Plugin actions API
**************************************************************************/
diff --git a/libpurple/plugins.h b/libpurple/plugins.h
--- a/libpurple/plugins.h
+++ b/libpurple/plugins.h
@@ -48,9 +48,10 @@ typedef struct _PurplePluginInfoClass Pu
/** @copydoc _PurplePluginAction */
typedef struct _PurplePluginAction PurplePluginAction;
+#include "pluginpref.h"
+
typedef void (*PurplePluginActionCallback)(PurplePluginAction *);
-
-#include "pluginpref.h"
+typedef PurplePluginPrefFrame (*PurplePluginPrefFrameCallback)(GPluginPlugin *);
/**
* Holds information about a plugin.
@@ -147,6 +148,25 @@ GType purple_plugin_info_get_type(void);
*/
GList *purple_plugin_info_get_actions(PurplePluginInfo *plugin_info);
+/**
+ * Sets a callback to be invoked to retrieve the preferences frame for a plugin.
+ *
+ * @param plugin_info The plugin info to set the callback for.
+ * @param callback The callback that returns the preferences frame.
+ */
+void purple_plugin_info_set_pref_frame_callback(PurplePluginInfo *plugin_info,
+ PurplePluginPrefFrameCallback callback);
+
+/**
+ * Returns the callback that retrieves the preferences frame for a plugin.
+ *
+ * @param plugin_info The plugin info to get the callback from.
+ *
+ * @return The callback that returns the preferences frame.
+ */
+PurplePluginPrefFrameCallback
+purple_plugin_info_get_pref_frame_callback(PurplePluginInfo *plugin_info);
+
/*@}*/
/**************************************************************************/
More information about the Commits
mailing list