summaryrefslogtreecommitdiff
path: root/libpurple/action.c
blob: 1beb94b52fea0550c0e6ffda3dbf1cc03bf38b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Purple is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 */

#include "action.h"

struct _PurpleActionMenu {
	gchar *label;
	GCallback callback;
	gpointer data;
	GList *children;
};

/******************************************************************************
 * ActionMenu API
 *****************************************************************************/
PurpleActionMenu *
purple_action_menu_new(const gchar *label, GCallback callback, gpointer data,
                       GList *children)
{
	PurpleActionMenu *act = g_new(PurpleActionMenu, 1);

	act->label = g_strdup(label);
	act->callback = callback;
	act->data = data;
	act->children = children;

	return act;
}

void
purple_action_menu_free(PurpleActionMenu *act) {
	g_return_if_fail(act != NULL);

	purple_action_menu_set_children(act, NULL);

	g_free(act->label);
	g_free(act);
}

const gchar *
purple_action_menu_get_label(const PurpleActionMenu *act) {
	g_return_val_if_fail(act != NULL, NULL);

	return act->label;
}

GCallback
purple_action_menu_get_callback(const PurpleActionMenu *act) {
	g_return_val_if_fail(act != NULL, NULL);

	return act->callback;
}

gpointer
purple_action_menu_get_data(const PurpleActionMenu *act) {
	g_return_val_if_fail(act != NULL, NULL);

	return act->data;
}

GList *
purple_action_menu_get_children(const PurpleActionMenu *act) {
	g_return_val_if_fail(act != NULL, NULL);

	return act->children;
}

void
purple_action_menu_set_label(PurpleActionMenu *act, const gchar *label) {
	g_return_if_fail(act != NULL);

	g_free(act->label);

	act->label = g_strdup(label);
}

void
purple_action_menu_set_callback(PurpleActionMenu *act, GCallback callback) {
	g_return_if_fail(act != NULL);

	act->callback = callback;
}

void
purple_action_menu_set_data(PurpleActionMenu *act, gpointer data) {
	g_return_if_fail(act != NULL);

	act->data = data;
}

void
purple_action_menu_set_children(PurpleActionMenu *act, GList *children) {
	g_return_if_fail(act != NULL);

	g_list_free_full(act->children, (GDestroyNotify)purple_action_menu_free);

	act->children = children;
}

/******************************************************************************
 * Protocol Action API
 *****************************************************************************/
PurpleProtocolAction *
purple_protocol_action_new(const gchar* label, PurpleProtocolActionCallback callback) {
	PurpleProtocolAction *action;

	g_return_val_if_fail(label != NULL, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	action = g_new0(PurpleProtocolAction, 1);

	action->label    = g_strdup(label);
	action->callback = callback;

	return action;
}

void
purple_protocol_action_free(PurpleProtocolAction *action) {
	g_return_if_fail(action != NULL);

	g_free(action->label);
	g_free(action);
}

PurpleProtocolAction *
purple_protocol_action_copy(PurpleProtocolAction *action) {
	g_return_val_if_fail(action != NULL, NULL);

	return purple_protocol_action_new(action->label, action->callback);
}

G_DEFINE_BOXED_TYPE(
	PurpleProtocolAction,
	purple_protocol_action,
	purple_protocol_action_copy,
	purple_protocol_action_free
);