annotate finch/libgnt/gntbindable.c @ 26279:bdb34fc5d889

Fix a crash when creating an account with a prpl with no protocol_options. Fixes #8747.
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 23 Mar 2009 02:10:44 +0000
parents e2e57d3c0578
children a8cc50c2279f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17718
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
1 /**
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
2 * GNT - The GLib Ncurses Toolkit
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
3 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
6 * source distribution.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
7 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
8 * This library is free software; you can redistribute it and/or modify
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
9 * it under the terms of the GNU General Public License as published by
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
11 * (at your option) any later version.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
12 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
13 * This program is distributed in the hope that it will be useful,
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
16 * GNU General Public License for more details.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
17 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
18 * You should have received a copy of the GNU General Public License
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
19 * along with this program; if not, write to the Free Software
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19179
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17718
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
21 */
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 15818
diff changeset
22
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
23 #include <string.h>
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
24
24503
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22871
diff changeset
25 #include "gntinternal.h"
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22871
diff changeset
26 #undef GNT_LOG_DOMAIN
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22871
diff changeset
27 #define GNT_LOG_DOMAIN "Bindable"
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22871
diff changeset
28
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "gntbindable.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include "gntstyle.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "gnt.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "gntutils.h"
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
33 #include "gnttextview.h"
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
34 #include "gnttree.h"
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
35 #include "gntbox.h"
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
36 #include "gntbutton.h"
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
37 #include "gntwindow.h"
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
38 #include "gntlabel.h"
15818
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 static GObjectClass *parent_class = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
42 static struct
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
43 {
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
44 char * okeys; /* Old keystrokes */
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
45 char * keys; /* New Keystrokes being bound to the action */
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
46 GntBindableClass * klass; /* Class of the object that's getting keys rebound */
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
47 char * name; /* The name of the action */
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
48 GList * params; /* The list of paramaters */
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
49 } rebind_info;
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
50
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
51 static void
22007
c38d72677c8a Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents: 19680
diff changeset
52 gnt_bindable_free_rebind_info(void)
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
53 {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
54 g_free(rebind_info.name);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
55 g_free(rebind_info.keys);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
56 g_free(rebind_info.okeys);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
57 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
58
19130
d5a0b09470ee Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents: 17724
diff changeset
59 static void
d5a0b09470ee Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents: 17724
diff changeset
60 gnt_bindable_rebinding_cancel(GntWidget *button, gpointer data)
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
61 {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
62 gnt_bindable_free_rebind_info();
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
63 gnt_widget_destroy(GNT_WIDGET(data));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
64 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
65
19130
d5a0b09470ee Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents: 17724
diff changeset
66 static void
d5a0b09470ee Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents: 17724
diff changeset
67 gnt_bindable_rebinding_rebind(GntWidget *button, gpointer data)
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
68 {
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
69 if (rebind_info.keys) {
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
70 gnt_bindable_register_binding(rebind_info.klass,
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
71 NULL,
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
72 rebind_info.okeys,
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
73 rebind_info.params);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
74 gnt_bindable_register_binding(rebind_info.klass,
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
75 rebind_info.name,
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
76 rebind_info.keys,
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
77 rebind_info.params);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
78 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
79 gnt_bindable_free_rebind_info();
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
80 gnt_widget_destroy(GNT_WIDGET(data));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
81 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
82
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
83 static gboolean
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
84 gnt_bindable_rebinding_grab_key(GntBindable *bindable, const char *text, gpointer data)
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
85 {
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
86 GntTextView *textview = GNT_TEXT_VIEW(data);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
87 char *new_text;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
88 const char *tmp;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
89
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
90 if (text && *text) {
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
91 /* Rebinding tab or enter for something is probably not that great an idea */
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
92 if (!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)) {
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
93 return FALSE;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
94 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
95
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
96 tmp = gnt_key_lookup(text);
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
97 new_text = g_strdup_printf("KEY: \"%s\"", tmp);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
98 gnt_text_view_clear(textview);
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
99 gnt_text_view_append_text_with_flags(textview, new_text, GNT_TEXT_FLAG_NORMAL);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
100 g_free(new_text);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
101
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
102 g_free(rebind_info.keys);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
103 rebind_info.keys = g_strdup(text);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
104
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
105 return TRUE;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
106 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
107 return FALSE;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
108 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
109 static void
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
110 gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable)
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
111 {
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
112 const char *widget_name = g_type_name(G_OBJECT_TYPE(bindable));
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
113 char *keys;
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
114 GntWidget *key_textview;
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
115 GntWidget *label;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
116 GntWidget *bind_button, *cancel_button;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
117 GntWidget *button_box;
19177
19a4594e939c Fix a memory leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19176
diff changeset
118 GList *current_row_data;
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
119 char *tmp;
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
120 GntWidget *win = gnt_window_new();
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
121 GntTree *tree = GNT_TREE(data);
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
122 GntWidget *vbox = gnt_box_new(FALSE, TRUE);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
123
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
124 rebind_info.klass = GNT_BINDABLE_GET_CLASS(bindable);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
125
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
126 current_row_data = gnt_tree_get_selection_text_list(tree);
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
127 rebind_info.name = g_strdup(g_list_nth_data(current_row_data, 1));
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
128
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
129 keys = gnt_tree_get_selection_data(tree);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
130 rebind_info.okeys = g_strdup(gnt_key_translate(keys));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
131
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
132 rebind_info.params = NULL;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
133
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
134 g_list_foreach(current_row_data, (GFunc)g_free, NULL);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
135 g_list_free(current_row_data);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
136
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
137 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
138
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
139 gnt_box_set_title(GNT_BOX(win), "Key Capture");
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
140
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
141 tmp = g_strdup_printf("Type the new bindings for %s in a %s.", rebind_info.name, widget_name);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
142 label = gnt_label_new(tmp);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
143 g_free(tmp);
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
144 gnt_box_add_widget(GNT_BOX(vbox), label);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
145
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
146 tmp = g_strdup_printf("KEY: \"%s\"", keys);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
147 key_textview = gnt_text_view_new();
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
148 gnt_widget_set_size(key_textview, key_textview->priv.x, 2);
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
149 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(key_textview), tmp, GNT_TEXT_FLAG_NORMAL);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
150 g_free(tmp);
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
151 gnt_widget_set_name(key_textview, "keystroke");
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
152 gnt_box_add_widget(GNT_BOX(vbox), key_textview);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
153
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
154 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(gnt_bindable_rebinding_grab_key), key_textview);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
155
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
156 button_box = gnt_box_new(FALSE, FALSE);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
157
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
158 bind_button = gnt_button_new("BIND");
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
159 gnt_widget_set_name(bind_button, "bind");
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
160 gnt_box_add_widget(GNT_BOX(button_box), bind_button);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
161
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
162 cancel_button = gnt_button_new("Cancel");
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
163 gnt_widget_set_name(cancel_button, "cancel");
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
164 gnt_box_add_widget(GNT_BOX(button_box), cancel_button);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
165
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
166 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(gnt_bindable_rebinding_rebind), win);
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
167 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(gnt_bindable_rebinding_cancel), win);
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
168
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
169 gnt_box_add_widget(GNT_BOX(vbox), button_box);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
170
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
171 gnt_box_add_widget(GNT_BOX(win), vbox);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
172 gnt_widget_show(win);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
173 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
174
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
175 typedef struct
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
176 {
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
177 GHashTable *hash;
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
178 GntTree *tree;
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
179 } BindingView;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
180
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
181 static void
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
182 add_binding(gpointer key, gpointer value, gpointer data)
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
183 {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
184 BindingView *bv = data;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
185 GntBindableActionParam *act = value;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
186 const char *name = g_hash_table_lookup(bv->hash, act->action);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
187 if (name && *name) {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
188 const char *k = gnt_key_lookup(key);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
189 if (!k)
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
190 k = key;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
191 gnt_tree_add_row_after(bv->tree, (gpointer)k,
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
192 gnt_tree_create_row(bv->tree, k, name), NULL, NULL);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
193 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
194 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
195
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
196 static void
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
197 add_action(gpointer key, gpointer value, gpointer data)
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
198 {
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
199 BindingView *bv = data;
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
200 g_hash_table_insert(bv->hash, value, key);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
201 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
202
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 gnt_bindable_class_init(GntBindableClass *klass)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 parent_class = g_type_class_peek_parent(klass);
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 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
209 (GDestroyNotify)gnt_bindable_action_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 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
211 (GDestroyNotify)gnt_bindable_action_param_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 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
214 GNTDEBUG;
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 static gpointer
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 bindable_clone(GntBindableAction *action)
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 GntBindableAction *ret = g_new0(GntBindableAction, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 ret->name = g_strdup(action->name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 ret->u = action->u;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 return ret;
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
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 static gpointer
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 binding_clone(GntBindableActionParam *param)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 GntBindableActionParam *p = g_new0(GntBindableActionParam, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 p->list = g_list_copy(param->list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 p->action = param->action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 return p;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 duplicate_hashes(GntBindableClass *klass)
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 /* Duplicate the bindings from parent class */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 if (klass->actions) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 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
241 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 (GDupFunc)g_strdup, (GDupFunc)bindable_clone);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 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
244 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
245 (GDupFunc)g_strdup, (GDupFunc)binding_clone);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 } else {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 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
248 (GDestroyNotify)gnt_bindable_action_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 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
250 (GDestroyNotify)gnt_bindable_action_param_free);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 }
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 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 /******************************************************************************
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 * GntBindable API
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 *****************************************************************************/
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 GType
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 gnt_bindable_get_gtype(void)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 static GType type = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263
19176
33201366bcd4 Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19130
diff changeset
264 if (type == 0) {
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 static const GTypeInfo info = {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 sizeof(GntBindableClass),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 (GBaseInitFunc)duplicate_hashes, /* base_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 NULL, /* base_finalize */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 (GClassInitFunc)gnt_bindable_class_init,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 NULL,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 NULL, /* class_data */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 sizeof(GntBindable),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 0, /* n_preallocs */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274 NULL, /* instance_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 NULL /* value_table */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 type = g_type_register_static(G_TYPE_OBJECT,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 "GntBindable",
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 &info, G_TYPE_FLAG_ABSTRACT);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 return type;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 /**
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 * Key Remaps
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 const char *
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 gnt_bindable_remap_keys(GntBindable *bindable, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 const char *remap = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 GType type = G_OBJECT_TYPE(bindable);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 if (klass->remaps == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 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
299 gnt_styles_get_keyremaps(type, klass->remaps);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 remap = g_hash_table_lookup(klass->remaps, text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 return (remap ? remap : text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 /**
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 * Actions and Bindings
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 GList *list = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 va_list args;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 GntBindableAction *action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 void *p;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 va_start(args, name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 while ((p = va_arg(args, void *)) != NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 list = g_list_append(list, p);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 va_end(args);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 action = g_hash_table_lookup(klass->actions, name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 if (action && action->u.action) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 return action->u.action(bindable, list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 if (param && param->action) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 if (param->list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 return param->action->u.action(bindable, param->list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 else
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 return param->action->u.action_noparam(bindable);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345
22871
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
346 gboolean
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
347 gnt_bindable_check_key(GntBindable *bindable, const char *keys) {
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
348 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable));
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
349 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys);
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
350 return (param && param->action);
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
351 }
24dfef623410 Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents: 22007
diff changeset
352
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 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
355 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 GntBindableActionParam *param;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 GntBindableAction *action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 if (name == NULL || *name == '\0') {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 g_hash_table_remove(klass->bindings, (char*)trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 gnt_keys_del_combination(trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 action = g_hash_table_lookup(klass->actions, name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 if (!action) {
24503
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22871
diff changeset
367 gnt_warning("Invalid action name %s for %s",
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 name, g_type_name(G_OBJECT_CLASS_TYPE(klass)));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 if (list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 g_list_free(list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 param = g_new0(GntBindableActionParam, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 param->action = action;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 param->list = list;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 g_hash_table_replace(klass->bindings, g_strdup(trigger), param);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 gnt_keys_add_combination(trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 void gnt_bindable_register_binding(GntBindableClass *klass, const char *name,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 const char *trigger, ...)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 GList *list = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385 va_list args;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 void *data;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 va_start(args, trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 while ((data = va_arg(args, void *))) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 list = g_list_append(list, data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 va_end(args);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394 register_binding(klass, name, trigger, list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397 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
398 GntBindableActionCallback callback, const char *trigger, ...)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 void *data;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 va_list args;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 GntBindableAction *action = g_new0(GntBindableAction, 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 GList *list;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 action->name = g_strdup(name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 action->u.action = callback;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 g_hash_table_replace(klass->actions, g_strdup(name), action);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 if (trigger && *trigger) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 list = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 va_start(args, trigger);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 while ((data = va_arg(args, void *))) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 list = g_list_append(list, data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 va_end(args);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 register_binding(klass, name, trigger, list);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 void gnt_bindable_action_free(GntBindableAction *action)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 g_free(action->name);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 g_free(action);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 void gnt_bindable_action_param_free(GntBindableActionParam *param)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 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
431 g_free(param);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
434 GntBindable * gnt_bindable_bindings_view(GntBindable *bind)
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
435 {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
436 GntBindable *tree = GNT_BINDABLE(gnt_tree_new_with_columns(2));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
437 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
438 GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
439 BindingView bv = {hash, GNT_TREE(tree)};
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
441 gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
442 g_hash_table_foreach(klass->actions, add_action, &bv);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
443 g_hash_table_foreach(klass->bindings, add_binding, &bv);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
444 if (GNT_TREE(tree)->list == NULL) {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
445 gnt_widget_destroy(GNT_WIDGET(tree));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
446 tree = NULL;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
447 } else
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
448 gnt_tree_adjust_columns(bv.tree);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
449 g_hash_table_destroy(hash);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
450
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
451 return tree;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
452 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
453
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
454 static void
17724
d7cd0afd3c36 FIX: The help_window pointer wasn't being set to null properly in the destroy callback.
Eric Polino <aluink@pidgin.im>
parents: 17722
diff changeset
455 reset_binding_window(GntBindableClass *window, gpointer k)
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
456 {
17724
d7cd0afd3c36 FIX: The help_window pointer wasn't being set to null properly in the destroy callback.
Eric Polino <aluink@pidgin.im>
parents: 17722
diff changeset
457 GntBindableClass *klass = GNT_BINDABLE_CLASS(k);
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
458 klass->help_window = NULL;
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
459 }
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
460
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
461 gboolean
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
462 gnt_bindable_build_help_window(GntBindable *bindable)
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
463 {
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
464 GntWidget *tree;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
465 GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable);
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
466 char *title;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
467
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
468 tree = GNT_WIDGET(gnt_bindable_bindings_view(bindable));
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
469
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
470 klass->help_window = GNT_BINDABLE(gnt_window_new());
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
471 title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(bindable)));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
472 gnt_box_set_title(GNT_BOX(klass->help_window), title);
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
473 if (tree) {
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
474 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(gnt_bindable_rebinding_activate), bindable);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
475 gnt_box_add_widget(GNT_BOX(klass->help_window), tree);
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
476 } else
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
477 gnt_box_add_widget(GNT_BOX(klass->help_window), gnt_label_new("This widget has no customizable bindings."));
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
478
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
479 g_signal_connect(G_OBJECT(klass->help_window), "destroy", G_CALLBACK(reset_binding_window), klass);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
480 gnt_widget_show(GNT_WIDGET(klass->help_window));
17722
15988e2bd270 Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17721
diff changeset
481 g_free(title);
17721
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
482
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
483 return TRUE;
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
484 }
3ee6ea8a66f8 Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents: 17718
diff changeset
485