Mercurial > pidgin
comparison finch/libgnt/gntbindable.c @ 19176:33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 11 Aug 2007 10:22:37 +0000 |
parents | d5a0b09470ee |
children | 19a4594e939c |
comparison
equal
deleted
inserted
replaced
19175:c79177766e13 | 19176:33201366bcd4 |
---|---|
35 | 35 |
36 static GObjectClass *parent_class = NULL; | 36 static GObjectClass *parent_class = NULL; |
37 | 37 |
38 static struct | 38 static struct |
39 { | 39 { |
40 char * okeys; /* Old keystrokes */ | 40 char * okeys; /* Old keystrokes */ |
41 char * keys; /* New Keystrokes being bound to the action */ | 41 char * keys; /* New Keystrokes being bound to the action */ |
42 GntBindableClass * klass; /* Class of the object that's getting keys rebound */ | 42 GntBindableClass * klass; /* Class of the object that's getting keys rebound */ |
43 char * name; /* The name of the action */ | 43 char * name; /* The name of the action */ |
44 GList * params; /* The list of paramaters */ | 44 GList * params; /* The list of paramaters */ |
45 | 45 } rebind_info; |
46 } rebind_info = {NULL,NULL,NULL,NULL,NULL}; | |
47 | 46 |
48 static void | 47 static void |
49 gnt_bindable_free_rebind_info() | 48 gnt_bindable_free_rebind_info() |
50 { | 49 { |
51 g_free(rebind_info.name); | 50 g_free(rebind_info.name); |
61 } | 60 } |
62 | 61 |
63 static void | 62 static void |
64 gnt_bindable_rebinding_rebind(GntWidget *button, gpointer data) | 63 gnt_bindable_rebinding_rebind(GntWidget *button, gpointer data) |
65 { | 64 { |
66 | 65 if (rebind_info.keys) { |
67 if(rebind_info.keys) { | |
68 gnt_bindable_register_binding(rebind_info.klass, | 66 gnt_bindable_register_binding(rebind_info.klass, |
69 NULL, | 67 NULL, |
70 rebind_info.okeys, | 68 rebind_info.okeys, |
71 rebind_info.params); | 69 rebind_info.params); |
72 gnt_bindable_register_binding(rebind_info.klass, | 70 gnt_bindable_register_binding(rebind_info.klass, |
73 rebind_info.name, | 71 rebind_info.name, |
74 rebind_info.keys, | 72 rebind_info.keys, |
75 rebind_info.params); | 73 rebind_info.params); |
76 } | 74 } |
77 gnt_bindable_free_rebind_info(); | 75 gnt_bindable_free_rebind_info(); |
78 | |
79 gnt_widget_destroy(GNT_WIDGET(data)); | 76 gnt_widget_destroy(GNT_WIDGET(data)); |
80 } | 77 } |
81 | 78 |
82 static gboolean | 79 static gboolean |
83 gnt_bindable_rebinding_grab_key(GntBindable *bindable, const char *text, gpointer *data) | 80 gnt_bindable_rebinding_grab_key(GntBindable *bindable, const char *text, gpointer data) |
84 { | 81 { |
85 | 82 GntTextView *textview = GNT_TEXT_VIEW(data); |
86 GntTextView *textview= GNT_TEXT_VIEW(data); | |
87 char *new_text; | 83 char *new_text; |
88 const char *tmp; | 84 const char *tmp; |
89 | 85 |
90 if(text && *text){ | 86 if (text && *text) { |
91 | 87 /* Rebinding tab or enter for something is probably not that great an idea */ |
92 if(!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)){ | 88 if (!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)) { |
93 return FALSE; | 89 return FALSE; |
94 } | 90 } |
95 | 91 |
96 tmp = gnt_key_lookup(text); | 92 tmp = gnt_key_lookup(text); |
97 new_text = g_strdup_printf("KEY: \"%s\"",tmp); | 93 new_text = g_strdup_printf("KEY: \"%s\"", tmp); |
98 gnt_text_view_clear(textview); | 94 gnt_text_view_clear(textview); |
99 gnt_text_view_append_text_with_flags(textview,new_text,GNT_TEXT_FLAG_NORMAL); | 95 gnt_text_view_append_text_with_flags(textview, new_text, GNT_TEXT_FLAG_NORMAL); |
100 g_free(new_text); | 96 g_free(new_text); |
101 | 97 |
102 g_free(rebind_info.keys); | 98 g_free(rebind_info.keys); |
103 rebind_info.keys = g_strdup(text); | 99 rebind_info.keys = g_strdup(text); |
104 | 100 |
105 | |
106 return TRUE; | 101 return TRUE; |
107 } | 102 } |
108 return FALSE; | 103 return FALSE; |
109 } | 104 } |
110 static void | 105 static void |
111 gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable) | 106 gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable) |
112 { | 107 { |
113 | 108 const char *widget_name = g_type_name(G_OBJECT_TYPE(bindable)); |
114 GntTree * tree = GNT_TREE(data); | 109 char *keys; |
115 | 110 GntWidget *key_textview; |
116 GntWidget *vbox = gnt_box_new(FALSE,TRUE); | |
117 | |
118 GntWidget *label; | 111 GntWidget *label; |
119 const char * widget_name = g_type_name(G_OBJECT_TYPE(bindable)); | |
120 char * keys; | |
121 | |
122 GntWidget *key_textview; | |
123 | |
124 GntWidget *bind_button, *cancel_button; | 112 GntWidget *bind_button, *cancel_button; |
125 GntWidget *button_box; | 113 GntWidget *button_box; |
126 | 114 GList *current_row_data, *itr; |
115 char *tmp; | |
127 GntWidget *win = gnt_window_new(); | 116 GntWidget *win = gnt_window_new(); |
128 GList * current_row_data,*itr; | 117 GntTree *tree = GNT_TREE(data); |
129 char * tmp; | 118 GntWidget *vbox = gnt_box_new(FALSE, TRUE); |
130 | 119 |
131 rebind_info.klass = GNT_BINDABLE_GET_CLASS(bindable); | 120 rebind_info.klass = GNT_BINDABLE_GET_CLASS(bindable); |
132 | 121 |
133 current_row_data = gnt_tree_get_selection_text_list(tree); | 122 current_row_data = gnt_tree_get_selection_text_list(tree); |
134 rebind_info.name = g_strdup(g_list_nth_data(current_row_data,1)); | 123 rebind_info.name = g_strdup(g_list_nth_data(current_row_data, 1)); |
135 | 124 |
136 keys = gnt_tree_get_selection_data(tree); | 125 keys = gnt_tree_get_selection_data(tree); |
137 rebind_info.okeys = g_strdup(gnt_key_translate(keys)); | 126 rebind_info.okeys = g_strdup(gnt_key_translate(keys)); |
138 | 127 |
139 rebind_info.params = NULL; | 128 rebind_info.params = NULL; |
140 | 129 |
141 itr = current_row_data; | 130 g_list_foreach(current_row_data, (GFunc)g_free, NULL); |
142 while(itr){ | |
143 g_free(itr->data); | |
144 itr = itr->next; | |
145 } | |
146 g_list_free(current_row_data); | 131 g_list_free(current_row_data); |
147 | 132 |
148 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); | 133 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); |
149 | 134 |
150 gnt_box_set_title(GNT_BOX(win),"Key Capture"); | 135 gnt_box_set_title(GNT_BOX(win), "Key Capture"); |
151 | 136 |
152 tmp = g_strdup_printf("Type the new bindings for %s in a %s.",rebind_info.name,widget_name); | 137 tmp = g_strdup_printf("Type the new bindings for %s in a %s.", rebind_info.name, widget_name); |
153 label = gnt_label_new(tmp); | 138 label = gnt_label_new(tmp); |
154 g_free(tmp); | 139 g_free(tmp); |
155 gnt_box_add_widget(GNT_BOX(vbox),label); | 140 gnt_box_add_widget(GNT_BOX(vbox), label); |
156 | 141 |
157 tmp = g_strdup_printf("KEY: \"%s\"",keys); | 142 tmp = g_strdup_printf("KEY: \"%s\"", keys); |
158 key_textview = gnt_text_view_new(); | 143 key_textview = gnt_text_view_new(); |
159 gnt_widget_set_size(key_textview,key_textview->priv.x,2); | 144 gnt_widget_set_size(key_textview, key_textview->priv.x, 2); |
160 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(key_textview),tmp,GNT_TEXT_FLAG_NORMAL); | 145 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(key_textview), tmp, GNT_TEXT_FLAG_NORMAL); |
161 g_free(tmp); | 146 g_free(tmp); |
162 gnt_widget_set_name(key_textview,"keystroke"); | 147 gnt_widget_set_name(key_textview, "keystroke"); |
163 gnt_box_add_widget(GNT_BOX(vbox),key_textview); | 148 gnt_box_add_widget(GNT_BOX(vbox), key_textview); |
164 | 149 |
165 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(gnt_bindable_rebinding_grab_key),key_textview); | 150 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(gnt_bindable_rebinding_grab_key), key_textview); |
166 | 151 |
167 button_box = gnt_box_new(FALSE,FALSE); | 152 button_box = gnt_box_new(FALSE, FALSE); |
168 | 153 |
169 bind_button = gnt_button_new("BIND"); | 154 bind_button = gnt_button_new("BIND"); |
170 gnt_widget_set_name(bind_button,"bind"); | 155 gnt_widget_set_name(bind_button, "bind"); |
171 gnt_box_add_widget(GNT_BOX(button_box), bind_button); | 156 gnt_box_add_widget(GNT_BOX(button_box), bind_button); |
172 | 157 |
173 cancel_button = gnt_button_new("Cancel"); | 158 cancel_button = gnt_button_new("Cancel"); |
174 gnt_widget_set_name(cancel_button,"cancel"); | 159 gnt_widget_set_name(cancel_button, "cancel"); |
175 gnt_box_add_widget(GNT_BOX(button_box),cancel_button); | 160 gnt_box_add_widget(GNT_BOX(button_box), cancel_button); |
176 | 161 |
177 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(gnt_bindable_rebinding_rebind),win); | 162 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(gnt_bindable_rebinding_rebind), win); |
178 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(gnt_bindable_rebinding_cancel),win); | 163 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(gnt_bindable_rebinding_cancel), win); |
179 | 164 |
180 | 165 gnt_box_add_widget(GNT_BOX(vbox), button_box); |
181 gnt_box_add_widget(GNT_BOX(vbox),button_box); | 166 |
182 | 167 gnt_box_add_widget(GNT_BOX(win), vbox); |
183 gnt_box_add_widget(GNT_BOX(win),vbox); | |
184 gnt_widget_show(win); | 168 gnt_widget_show(win); |
185 | 169 } |
186 } | 170 |
187 | 171 typedef struct |
188 typedef struct { | 172 { |
189 GHashTable *hash; | 173 GHashTable *hash; |
190 GntTree *tree; | 174 GntTree *tree; |
191 } BindingView; | 175 } BindingView; |
192 | 176 |
193 static void | 177 static void |
271 GType | 255 GType |
272 gnt_bindable_get_gtype(void) | 256 gnt_bindable_get_gtype(void) |
273 { | 257 { |
274 static GType type = 0; | 258 static GType type = 0; |
275 | 259 |
276 if(type == 0) { | 260 if (type == 0) { |
277 static const GTypeInfo info = { | 261 static const GTypeInfo info = { |
278 sizeof(GntBindableClass), | 262 sizeof(GntBindableClass), |
279 (GBaseInitFunc)duplicate_hashes, /* base_init */ | 263 (GBaseInitFunc)duplicate_hashes, /* base_init */ |
280 NULL, /* base_finalize */ | 264 NULL, /* base_finalize */ |
281 (GClassInitFunc)gnt_bindable_class_init, | 265 (GClassInitFunc)gnt_bindable_class_init, |