Mercurial > pidgin
annotate console/libgnt/gntbindable.c @ 15609:eba9715548d7
This should prevent the dll resources from being regenerated each time.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sun, 11 Feb 2007 00:17:12 +0000 |
parents | 7a52dce840b4 |
children | c2c2a854f5b3 |
rev | line source |
---|---|
14900
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 #include "gntbindable.h" |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
2 #include "gntstyle.h" |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
3 #include "gnt.h" |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
4 #include "gntutils.h" |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
5 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 static GObjectClass *parent_class = NULL; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
7 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
8 static void |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
9 gnt_bindable_class_init(GntBindableClass *klass) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
10 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
11 parent_class = g_type_class_peek_parent(klass); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
12 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
13 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
14 (GDestroyNotify)gnt_bindable_action_free); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
15 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
16 (GDestroyNotify)gnt_bindable_action_param_free); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
17 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
18 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
19 GNTDEBUG; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
20 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
21 |
15303
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
22 static gpointer |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
23 bindable_clone(GntBindableAction *action) |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
24 { |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
25 GntBindableAction *ret = g_new0(GntBindableAction, 1); |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
26 ret->name = g_strdup(action->name); |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
27 ret->u = action->u; |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
28 return ret; |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
29 } |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
30 |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
31 static gpointer |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
32 binding_clone(GntBindableActionParam *param) |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
33 { |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
34 GntBindableActionParam *p = g_new0(GntBindableActionParam, 1); |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
35 p->list = g_list_copy(param->list); |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
36 p->action = param->action; |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
37 return p; |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
38 } |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
39 |
14900
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
40 static void |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
41 duplicate_hashes(GntBindableClass *klass) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
42 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
43 /* Duplicate the bindings from parent class */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
44 if (klass->actions) { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
45 klass->actions = g_hash_table_duplicate(klass->actions, g_str_hash, |
15303
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
46 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free, |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
47 (GDupFunc)g_strdup, (GDupFunc)bindable_clone); |
14900
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
48 klass->bindings = g_hash_table_duplicate(klass->bindings, g_str_hash, |
15303
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
49 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free, |
7a52dce840b4
[gaim-migrate @ 18094]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15210
diff
changeset
|
50 (GDupFunc)g_strdup, (GDupFunc)binding_clone); |
14900
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
51 } else { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
52 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
53 (GDestroyNotify)gnt_bindable_action_free); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
54 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
55 (GDestroyNotify)gnt_bindable_action_param_free); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
56 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
57 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
58 GNTDEBUG; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
59 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
60 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
61 /****************************************************************************** |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
62 * GntBindable API |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
63 *****************************************************************************/ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
64 GType |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
65 gnt_bindable_get_gtype(void) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
66 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
67 static GType type = 0; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
68 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
69 if(type == 0) { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
70 static const GTypeInfo info = { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
71 sizeof(GntBindableClass), |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
72 (GBaseInitFunc)duplicate_hashes, /* base_init */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
73 NULL, /* base_finalize */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
74 (GClassInitFunc)gnt_bindable_class_init, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
75 NULL, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
76 NULL, /* class_data */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
77 sizeof(GntBindable), |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
78 0, /* n_preallocs */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
79 NULL, /* instance_init */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
80 }; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
81 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
82 type = g_type_register_static(G_TYPE_OBJECT, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
83 "GntBindable", |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
84 &info, G_TYPE_FLAG_ABSTRACT); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
85 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
86 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
87 return type; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
88 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
89 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
90 /** |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
91 * Key Remaps |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
92 */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
93 const char * |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
94 gnt_bindable_remap_keys(GntBindable *bindable, const char *text) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
95 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
96 const char *remap = NULL; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
97 GType type = G_OBJECT_TYPE(bindable); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
98 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
99 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
100 if (klass->remaps == NULL) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
101 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
102 klass->remaps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
103 gnt_styles_get_keyremaps(type, klass->remaps); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
104 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
105 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
106 remap = g_hash_table_lookup(klass->remaps, text); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
107 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
108 return (remap ? remap : text); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
109 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
110 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
111 /** |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
112 * Actions and Bindings |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
113 */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
114 gboolean |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
115 gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
116 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
117 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
118 GList *list = NULL; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
119 va_list args; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
120 GntBindableAction *action; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
121 void *p; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
122 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
123 va_start(args, name); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
124 while ((p = va_arg(args, void *)) != NULL) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
125 list = g_list_append(list, p); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
126 va_end(args); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
127 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
128 action = g_hash_table_lookup(klass->actions, name); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
129 if (action && action->u.action) { |
15210
7d682fc9098f
[gaim-migrate @ 18000]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14976
diff
changeset
|
130 return action->u.action(bindable, list); |
14900
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
131 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
132 return FALSE; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
133 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
134 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
135 gboolean |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
136 gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
137 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
138 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
139 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
140 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
141 if (param && param->action) { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
142 if (param->list) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
143 return param->action->u.action(bindable, param->list); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
144 else |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
145 return param->action->u.action_noparam(bindable); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
146 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
147 return FALSE; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
148 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
149 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
150 static void |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
151 register_binding(GntBindableClass *klass, const char *name, const char *trigger, GList *list) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
152 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
153 GntBindableActionParam *param; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
154 GntBindableAction *action; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
155 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
156 if (name == NULL || *name == '\0') { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
157 g_hash_table_remove(klass->bindings, (char*)trigger); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
158 return; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
159 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
160 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
161 action = g_hash_table_lookup(klass->actions, name); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
162 if (!action) { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
163 g_printerr("GntWidget: Invalid action name %s for %s\n", |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
164 name, g_type_name(G_OBJECT_CLASS_TYPE(klass))); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
165 if (list) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
166 g_list_free(list); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
167 return; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
168 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
169 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
170 param = g_new0(GntBindableActionParam, 1); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
171 param->action = action; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
172 param->list = list; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
173 g_hash_table_replace(klass->bindings, g_strdup(trigger), param); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
174 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
175 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
176 void gnt_bindable_register_binding(GntBindableClass *klass, const char *name, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
177 const char *trigger, ...) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
178 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
179 GList *list = NULL; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
180 va_list args; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
181 void *data; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
182 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
183 va_start(args, trigger); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
184 while ((data = va_arg(args, void *))) { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
185 list = g_list_append(list, data); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
186 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
187 va_end(args); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
188 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
189 register_binding(klass, name, trigger, list); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
190 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
191 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
192 void gnt_bindable_class_register_action(GntBindableClass *klass, const char *name, |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
193 GntBindableActionCallback callback, const char *trigger, ...) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
194 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
195 void *data; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
196 va_list args; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
197 GntBindableAction *action = g_new0(GntBindableAction, 1); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
198 GList *list; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
199 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
200 action->name = g_strdup(name); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
201 action->u.action = callback; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
202 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
203 g_hash_table_replace(klass->actions, g_strdup(name), action); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
204 |
14976
1c0772f7260b
[gaim-migrate @ 17755]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14900
diff
changeset
|
205 if (trigger && *trigger) { |
14900
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
206 list = NULL; |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
207 va_start(args, trigger); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
208 while ((data = va_arg(args, void *))) { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
209 list = g_list_append(list, data); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
210 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
211 va_end(args); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
212 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
213 register_binding(klass, name, trigger, list); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
214 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
215 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
216 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
217 void gnt_bindable_action_free(GntBindableAction *action) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
218 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
219 g_free(action->name); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
220 g_free(action); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
221 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
222 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
223 void gnt_bindable_action_param_free(GntBindableActionParam *param) |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
224 { |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
225 g_list_free(param->list); /* XXX: There may be a leak here for string parameters */ |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
226 g_free(param); |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
227 } |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
228 |
065e7ac30338
[gaim-migrate @ 17672]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
229 |