/pidgin/main: 188423493b57: Request API: actions for datasheet f...

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon Nov 4 15:19:42 EST 2013


Changeset: 188423493b578a474ffb688eff08303d56e6fce2
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-11-04 21:19 +0100
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/188423493b57

Description:

Request API: actions for datasheet field

diffstat:

 libpurple/request-datasheet.c |  113 +++++++++++++++++++++++++++++
 libpurple/request-datasheet.h |  124 ++++++++++++++++++++++++++++++++-
 pidgin/gtkrequest.c           |  160 +++++++++++++++++++++++++++++++++++++++--
 3 files changed, 386 insertions(+), 11 deletions(-)

diffs (truncated from 528 to 300 lines):

diff --git a/libpurple/request-datasheet.c b/libpurple/request-datasheet.c
--- a/libpurple/request-datasheet.c
+++ b/libpurple/request-datasheet.c
@@ -34,6 +34,7 @@ struct _PurpleRequestDatasheet
 	guint col_count;
 	GArray *col_types;
 	GArray *col_titles;
+	GList *actions;
 
 	GList *record_list;
 	GHashTable *record_li_by_key;
@@ -46,6 +47,17 @@ struct _PurpleRequestDatasheetRecord
 	gchar **data; /* at this point, there is only string data possible */
 };
 
+struct _PurpleRequestDatasheetAction
+{
+	gchar *label;
+
+	PurpleRequestDatasheetActionCb cb;
+	gpointer cb_data;
+
+	PurpleRequestDatasheetActionCheckCb sens_cb;
+	gpointer sens_data;
+};
+
 static void
 purple_request_datasheet_record_free(PurpleRequestDatasheetRecord *rec);
 
@@ -95,6 +107,9 @@ purple_request_datasheet_free(PurpleRequ
 	g_array_free(sheet->col_titles, TRUE);
 	g_array_free(sheet->col_types, TRUE);
 
+	g_list_free_full(sheet->actions,
+		(GDestroyNotify)purple_request_datasheet_action_free);
+
 	g_hash_table_destroy(sheet->record_li_by_key);
 	g_list_free_full(sheet->record_list,
 		(GDestroyNotify)purple_request_datasheet_record_free);
@@ -158,6 +173,104 @@ purple_request_datasheet_get_records(Pur
 	return sheet->record_list;
 }
 
+void
+purple_request_datasheet_add_action(PurpleRequestDatasheet *sheet,
+	PurpleRequestDatasheetAction *action)
+{
+	g_return_if_fail(sheet != NULL);
+	g_return_if_fail(action != NULL);
+
+	sheet->actions = g_list_append(sheet->actions, action);
+}
+
+const GList *
+purple_request_datasheet_get_actions(PurpleRequestDatasheet *sheet)
+{
+	g_return_val_if_fail(sheet != NULL, NULL);
+
+	return sheet->actions;
+}
+
+/***** Datasheet actions API **************************************************/
+
+PurpleRequestDatasheetAction *
+purple_request_datasheet_action_new(void)
+{
+	return g_new0(PurpleRequestDatasheetAction, 1);
+}
+
+void
+purple_request_datasheet_action_free(PurpleRequestDatasheetAction *act)
+{
+	g_return_if_fail(act != NULL);
+	g_free(act->label);
+	g_free(act);
+}
+
+void
+purple_request_datasheet_action_set_label(PurpleRequestDatasheetAction *act,
+	const gchar *label)
+{
+	gchar *new_label;
+
+	g_return_if_fail(act != NULL);
+
+	new_label = g_strdup(label);
+	g_free(act->label);
+	act->label = new_label;
+}
+
+const gchar*
+purple_request_datasheet_action_get_label(PurpleRequestDatasheetAction *act)
+{
+	g_return_val_if_fail(act != NULL, NULL);
+
+	return act->label;
+}
+
+void
+purple_request_datasheet_action_set_cb(PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetActionCb cb, gpointer user_data)
+{
+	g_return_if_fail(act != NULL);
+
+	act->cb = cb;
+	act->cb_data = user_data;
+}
+
+void
+purple_request_datasheet_action_call(PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetRecord *rec)
+{
+	g_return_if_fail(act != NULL);
+
+	if (act->cb)
+		act->cb(rec, act->cb_data);
+}
+
+void
+purple_request_datasheet_action_set_sens_cb(
+	PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetActionCheckCb cb, gpointer user_data)
+{
+	g_return_if_fail(act != NULL);
+
+	act->sens_cb = cb;
+	act->sens_data = user_data;
+}
+
+gboolean
+purple_request_datasheet_action_is_sensitive(PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetRecord *rec)
+{
+	g_return_val_if_fail(act != NULL, FALSE);
+
+	if (!act->sens_cb)
+		return (rec != NULL);
+
+	return act->sens_cb(rec, act->cb_data);
+}
+
 /***** Datasheet record API ***************************************************/
 
 static PurpleRequestDatasheetRecord *
diff --git a/libpurple/request-datasheet.h b/libpurple/request-datasheet.h
--- a/libpurple/request-datasheet.h
+++ b/libpurple/request-datasheet.h
@@ -26,8 +26,16 @@
 #ifndef _PURPLE_REQUEST_DATA_H_
 #define _PURPLE_REQUEST_DATA_H_
 
+#include <glib.h>
+
 typedef struct _PurpleRequestDatasheet PurpleRequestDatasheet;
 typedef struct _PurpleRequestDatasheetRecord PurpleRequestDatasheetRecord;
+typedef struct _PurpleRequestDatasheetAction PurpleRequestDatasheetAction;
+
+typedef void (*PurpleRequestDatasheetActionCb)(
+	PurpleRequestDatasheetRecord *rec, gpointer user_data);
+typedef gboolean (*PurpleRequestDatasheetActionCheckCb)(
+	PurpleRequestDatasheetRecord *rec, gpointer user_data);
 
 typedef enum
 {
@@ -35,8 +43,6 @@ typedef enum
 	PURPLE_REQUEST_DATASHEET_COLUMN_IMAGE
 } PurpleRequestDatasheetColumnType;
 
-#include <glib.h>
-
 G_BEGIN_DECLS
 
 /**************************************************************************/
@@ -119,6 +125,120 @@ purple_request_datasheet_get_column_titl
 const GList *
 purple_request_datasheet_get_records(PurpleRequestDatasheet *sheet);
 
+/**
+ * Adds an action to the datasheet.
+ *
+ * Action object is owned by the datasheet since this call.
+ *
+ * @param sheet  The datasheet.
+ * @param action The action.
+ */
+void
+purple_request_datasheet_add_action(PurpleRequestDatasheet *sheet,
+	PurpleRequestDatasheetAction *action);
+
+/**
+ * Returns the list of actions in a datasheet.
+ *
+ * @param sheet The datasheet.
+ *
+ * @constreturn The list of actions.
+ */
+const GList *
+purple_request_datasheet_get_actions(PurpleRequestDatasheet *sheet);
+
+/*@}*/
+
+
+/**************************************************************************/
+/** @name Datasheet actions API                                           */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Creates new datasheet action.
+ *
+ * @return The new action.
+ */
+PurpleRequestDatasheetAction *
+purple_request_datasheet_action_new(void);
+
+/**
+ * Destroys the datasheet action.
+ *
+ * @param act The action.
+ */
+void
+purple_request_datasheet_action_free(PurpleRequestDatasheetAction *act);
+
+/**
+ * Sets the localized label for the action.
+ *
+ * @param act   The action.
+ * @param label The label.
+ */
+void
+purple_request_datasheet_action_set_label(PurpleRequestDatasheetAction *act,
+	const gchar *label);
+
+/**
+ * Gets the label of action.
+ *
+ * @param act The action.
+ *
+ * @return The localized label text.
+ */
+const gchar*
+purple_request_datasheet_action_get_label(PurpleRequestDatasheetAction *act);
+
+/**
+ * Sets the callback for the action.
+ *
+ * @param act       The action.
+ * @param cb        The callback function.
+ * @param user_data The data to be passed to the callback function.
+ */
+void
+purple_request_datasheet_action_set_cb(PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetActionCb cb, gpointer user_data);
+
+/**
+ * Calls the callback of the action.
+ *
+ * @param act The action.
+ * @param rec The user selected record.
+ */
+void
+purple_request_datasheet_action_call(PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetRecord *rec);
+
+/**
+ * Sets the sensitivity checker for the action.
+ *
+ * If there is no callback set, default is used: the action is enabled, if any
+ * record is active.
+ *
+ * @param act       The action.
+ * @param cb        The callback function, may be @c NULL.
+ * @param user_data The data to be passed to the callback function.
+ */
+void
+purple_request_datasheet_action_set_sens_cb(
+	PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetActionCheckCb cb, gpointer user_data);
+
+/**
+ * Checks, if the action is enabled for the active record.
+ *
+ * @param act The action.
+ * @param rec The record.
+ *
+ * @return @c TRUE, if the action is enabled, @c FALSE otherwise.
+ */
+gboolean
+purple_request_datasheet_action_is_sensitive(PurpleRequestDatasheetAction *act,
+	PurpleRequestDatasheetRecord *rec);
+
 /*@}*/
 
 
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -1633,6 +1633,72 @@ static GdkPixbuf*
 	return image;
 }



More information about the Commits mailing list