annotate finch/libgnt/gntbindable.c @ 18717:d3542cffbb42

Allow un/setting flags for widgets.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 29 Jul 2007 16:36:05 +0000
parents fd01bac27b79
children c8f9584e3221
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18049
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
1 /**
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
2 * GNT - The GLib Ncurses Toolkit
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
3 *
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
6 * source distribution.
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
7 *
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
8 * This library is free software; you can redistribute it and/or modify
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
9 * it under the terms of the GNU General Public License as published by
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
11 * (at your option) any later version.
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
12 *
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
13 * This program is distributed in the hope that it will be useful,
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
16 * GNU General Public License for more details.
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
17 *
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
18 * You should have received a copy of the GNU General Public License
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
19 * along with this program; if not, write to the Free Software
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
21 */
1cedd520cd18 Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15818
diff changeset
22
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include "gntbindable.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include "gntstyle.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include "gnt.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include "gntutils.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 static GObjectClass *parent_class = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 gnt_bindable_class_init(GntBindableClass *klass)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 parent_class = g_type_class_peek_parent(klass);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 (GDestroyNotify)gnt_bindable_action_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 (GDestroyNotify)gnt_bindable_action_param_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 static gpointer
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 bindable_clone(GntBindableAction *action)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 GntBindableAction *ret = g_new0(GntBindableAction, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 ret->name = g_strdup(action->name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 ret->u = action->u;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 return ret;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 static gpointer
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 binding_clone(GntBindableActionParam *param)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 GntBindableActionParam *p = g_new0(GntBindableActionParam, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 p->list = g_list_copy(param->list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 p->action = param->action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 return p;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 duplicate_hashes(GntBindableClass *klass)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 /* Duplicate the bindings from parent class */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 if (klass->actions) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 klass->actions = g_hash_table_duplicate(klass->actions, g_str_hash,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 (GDupFunc)g_strdup, (GDupFunc)bindable_clone);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 klass->bindings = g_hash_table_duplicate(klass->bindings, g_str_hash,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 (GDupFunc)g_strdup, (GDupFunc)binding_clone);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 } else {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 (GDestroyNotify)gnt_bindable_action_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 (GDestroyNotify)gnt_bindable_action_param_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 /******************************************************************************
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 * GntBindable API
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 *****************************************************************************/
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 GType
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 gnt_bindable_get_gtype(void)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 static GType type = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 if(type == 0) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 static const GTypeInfo info = {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 sizeof(GntBindableClass),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 (GBaseInitFunc)duplicate_hashes, /* base_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 NULL, /* base_finalize */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 (GClassInitFunc)gnt_bindable_class_init,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 NULL,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 NULL, /* class_data */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 sizeof(GntBindable),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 0, /* n_preallocs */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 NULL, /* instance_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 NULL /* value_table */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 type = g_type_register_static(G_TYPE_OBJECT,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 "GntBindable",
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 &info, G_TYPE_FLAG_ABSTRACT);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 return type;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 /**
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 * Key Remaps
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 const char *
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 gnt_bindable_remap_keys(GntBindable *bindable, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 const char *remap = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 GType type = G_OBJECT_TYPE(bindable);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 if (klass->remaps == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 klass->remaps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 gnt_styles_get_keyremaps(type, klass->remaps);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 remap = g_hash_table_lookup(klass->remaps, text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 return (remap ? remap : text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 /**
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 * Actions and Bindings
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 GList *list = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 va_list args;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 GntBindableAction *action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 void *p;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 va_start(args, name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 while ((p = va_arg(args, void *)) != NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 list = g_list_append(list, p);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 va_end(args);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 action = g_hash_table_lookup(klass->actions, name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 if (action && action->u.action) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 return action->u.action(bindable, list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 if (param && param->action) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 if (param->list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 return param->action->u.action(bindable, param->list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 else
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 return param->action->u.action_noparam(bindable);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 register_binding(GntBindableClass *klass, const char *name, const char *trigger, GList *list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 GntBindableActionParam *param;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 GntBindableAction *action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 if (name == NULL || *name == '\0') {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 g_hash_table_remove(klass->bindings, (char*)trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 gnt_keys_del_combination(trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 action = g_hash_table_lookup(klass->actions, name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 if (!action) {
18680
fd01bac27b79 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18049
diff changeset
187 g_printerr("GntBindable: Invalid action name %s for %s\n",
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 name, g_type_name(G_OBJECT_CLASS_TYPE(klass)));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 if (list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 g_list_free(list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 param = g_new0(GntBindableActionParam, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 param->action = action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 param->list = list;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 g_hash_table_replace(klass->bindings, g_strdup(trigger), param);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 gnt_keys_add_combination(trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 void gnt_bindable_register_binding(GntBindableClass *klass, const char *name,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 const char *trigger, ...)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 GList *list = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 va_list args;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 void *data;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 va_start(args, trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 while ((data = va_arg(args, void *))) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 list = g_list_append(list, data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 va_end(args);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 register_binding(klass, name, trigger, list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 void gnt_bindable_class_register_action(GntBindableClass *klass, const char *name,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 GntBindableActionCallback callback, const char *trigger, ...)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 void *data;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 va_list args;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 GntBindableAction *action = g_new0(GntBindableAction, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 GList *list;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 action->name = g_strdup(name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 action->u.action = callback;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 g_hash_table_replace(klass->actions, g_strdup(name), action);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 if (trigger && *trigger) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 list = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 va_start(args, trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 while ((data = va_arg(args, void *))) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 list = g_list_append(list, data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 va_end(args);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 register_binding(klass, name, trigger, list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 void gnt_bindable_action_free(GntBindableAction *action)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 g_free(action->name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 g_free(action);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 void gnt_bindable_action_param_free(GntBindableActionParam *param)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 g_list_free(param->list); /* XXX: There may be a leak here for string parameters */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 g_free(param);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254