Mercurial > pidgin.yaz
annotate plugins/gestures/gestures.c @ 5277:d7771fe33cbd
[gaim-migrate @ 5649]
paco-paco made group counts of online and total buddies O(1) a while back also
since we haven't seen any problems with it, this is now going in.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 01 May 2003 18:24:17 +0000 |
parents | fefad67de2c7 |
children | 2c4c975620f0 |
rev | line source |
---|---|
4390 | 1 /* |
2 * Mouse gestures plugin for Gaim | |
3 * | |
4 * Copyright (C) 2003 Christian Hammond. | |
5 * | |
6 * This program is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation; either version 2 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 * 02111-1307, USA. | |
20 */ | |
21 #include "config.h" | |
22 | |
23 #include "gaim.h" | |
24 #include "gstroke.h" | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
25 #include "gtkconv.h" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
26 #include "gtkplugin.h" |
4390 | 27 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
28 #define GESTURES_PLUGIN_ID "gtk-gestures" |
4390 | 29 |
30 static void | |
31 stroke_close(GtkWidget *widget, void *data) | |
32 { | |
33 struct gaim_conversation *conv; | |
34 struct gaim_gtk_conversation *gtkconv; | |
35 | |
36 conv = (struct gaim_conversation *)data; | |
37 | |
38 /* Double-check */ | |
39 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
40 return; | |
41 | |
42 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
43 | |
44 gstroke_cleanup(gtkconv->imhtml); | |
45 gaim_conversation_destroy(conv); | |
46 } | |
47 | |
48 static void | |
49 stroke_prev_tab(GtkWidget *widget, void *data) | |
50 { | |
51 struct gaim_conversation *conv; | |
52 struct gaim_window *win; | |
53 unsigned int index; | |
54 | |
55 conv = (struct gaim_conversation *)data; | |
56 win = gaim_conversation_get_window(conv); | |
57 index = gaim_conversation_get_index(conv); | |
58 | |
59 if (index == 0) | |
60 index = gaim_window_get_conversation_count(win) - 1; | |
61 else | |
62 index--; | |
63 | |
64 gaim_window_switch_conversation(win, index); | |
65 } | |
66 | |
67 static void | |
68 stroke_next_tab(GtkWidget *widget, void *data) | |
69 { | |
70 struct gaim_conversation *conv; | |
71 struct gaim_window *win; | |
72 unsigned int index; | |
73 | |
74 conv = (struct gaim_conversation *)data; | |
75 win = gaim_conversation_get_window(conv); | |
76 index = gaim_conversation_get_index(conv); | |
77 | |
78 if (index == gaim_window_get_conversation_count(win) - 1) | |
79 index = 0; | |
80 else | |
81 index++; | |
82 | |
83 gaim_window_switch_conversation(win, index); | |
84 } | |
85 | |
86 void | |
87 stroke_new_win(GtkWidget *widget, void *data) | |
88 { | |
89 struct gaim_window *new_win, *old_win; | |
90 struct gaim_conversation *conv; | |
91 | |
92 conv = (struct gaim_conversation *)data; | |
93 old_win = gaim_conversation_get_window(conv); | |
94 | |
95 if (gaim_window_get_conversation_count(old_win) <= 1) | |
96 return; | |
97 | |
98 new_win = gaim_window_new(); | |
99 | |
100 gaim_window_remove_conversation(old_win, gaim_conversation_get_index(conv)); | |
101 gaim_window_add_conversation(new_win, conv); | |
102 | |
103 gaim_window_show(new_win); | |
104 } | |
105 | |
106 static void | |
107 attach_signals(struct gaim_conversation *conv) | |
108 { | |
109 struct gaim_gtk_conversation *gtkconv; | |
110 | |
111 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
112 | |
113 gstroke_enable(gtkconv->imhtml); | |
114 gstroke_signal_connect(gtkconv->imhtml, "14789", stroke_close, conv); | |
115 gstroke_signal_connect(gtkconv->imhtml, "1456", stroke_close, conv); | |
5016
ae7760945ef2
[gaim-migrate @ 5352]
Christian Hammond <chipx86@chipx86.com>
parents:
4843
diff
changeset
|
116 gstroke_signal_connect(gtkconv->imhtml, "1489", stroke_close, conv); |
4390 | 117 gstroke_signal_connect(gtkconv->imhtml, "74123", stroke_next_tab, conv); |
118 gstroke_signal_connect(gtkconv->imhtml, "7456", stroke_next_tab, conv); | |
119 gstroke_signal_connect(gtkconv->imhtml, "96321", stroke_prev_tab, conv); | |
120 gstroke_signal_connect(gtkconv->imhtml, "9654", stroke_prev_tab, conv); | |
121 gstroke_signal_connect(gtkconv->imhtml, "25852", stroke_new_win, conv); | |
122 } | |
123 | |
124 static void | |
125 new_conv_cb(char *who) | |
126 { | |
127 struct gaim_conversation *conv; | |
128 | |
129 conv = gaim_find_conversation(who); | |
130 | |
131 if (conv == NULL || !GAIM_IS_GTK_CONVERSATION(conv)) | |
132 return; | |
133 | |
134 attach_signals(conv); | |
135 } | |
136 | |
137 #if 0 | |
138 static void | |
139 mouse_button_menu_cb(GtkMenuItem *item, gpointer data) | |
140 { | |
141 int button = (int)data; | |
142 | |
143 gstroke_set_mouse_button(button + 2); | |
144 } | |
145 #endif | |
146 | |
147 static void | |
148 toggle_draw_cb(GtkToggleButton *toggle, gpointer data) | |
149 { | |
150 gstroke_set_draw_strokes(!gstroke_draw_strokes()); | |
151 } | |
152 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
153 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
154 plugin_load(GaimPlugin *plugin) |
4390 | 155 { |
156 struct gaim_conversation *conv; | |
157 GList *l; | |
158 | |
159 for (l = gaim_get_conversations(); l != NULL; l = l->next) { | |
160 conv = (struct gaim_conversation *)l->data; | |
161 | |
162 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
163 continue; | |
164 | |
165 attach_signals(conv); | |
166 } | |
167 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
168 gaim_signal_connect(plugin, event_new_conversation, new_conv_cb, NULL); |
4390 | 169 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
170 return TRUE; |
4390 | 171 } |
172 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
173 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
174 plugin_unload(GaimPlugin *plugin) |
4390 | 175 { |
176 struct gaim_conversation *conv; | |
177 struct gaim_gtk_conversation *gtkconv; | |
178 GList *l; | |
179 | |
180 for (l = gaim_get_conversations(); l != NULL; l = l->next) { | |
181 conv = (struct gaim_conversation *)l->data; | |
182 | |
183 if (!GAIM_IS_GTK_CONVERSATION(conv)) | |
184 continue; | |
185 | |
186 gtkconv = GAIM_GTK_CONVERSATION(conv); | |
187 | |
188 gstroke_cleanup(gtkconv->imhtml); | |
189 } | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
190 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
191 return TRUE; |
4390 | 192 } |
193 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
194 static GtkWidget * |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
195 get_config_frame(GaimPlugin *plugin) |
4390 | 196 { |
197 GtkWidget *ret; | |
198 GtkWidget *vbox; | |
199 GtkWidget *toggle; | |
200 #if 0 | |
201 GtkWidget *opt; | |
202 GtkWidget *menu, *item; | |
203 #endif | |
204 | |
205 /* Outside container */ | |
206 ret = gtk_vbox_new(FALSE, 18); | |
207 gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
208 | |
209 /* Configuration frame */ | |
210 vbox = make_frame(ret, _("Mouse Gestures Configuration")); | |
211 | |
212 #if 0 | |
213 /* Mouse button drop-down menu */ | |
214 menu = gtk_menu_new(); | |
215 opt = gtk_option_menu_new(); | |
216 | |
217 item = gtk_menu_item_new_with_label(_("Middle mouse button")); | |
218 g_signal_connect(G_OBJECT(item), "activate", | |
219 G_CALLBACK(mouse_button_menu_cb), opt); | |
220 gtk_menu_append(menu, item); | |
221 | |
222 item = gtk_menu_item_new_with_label(_("Right mouse button")); | |
223 g_signal_connect(G_OBJECT(item), "activate", | |
224 G_CALLBACK(mouse_button_menu_cb), opt); | |
225 gtk_menu_append(menu, item); | |
226 | |
227 gtk_box_pack_start(GTK_BOX(vbox), opt, FALSE, FALSE, 0); | |
228 gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu); | |
229 gtk_option_menu_set_history(GTK_OPTION_MENU(opt), | |
230 gstroke_get_mouse_button() - 2); | |
231 #endif | |
232 | |
233 /* "Visual gesture display" checkbox */ | |
234 toggle = gtk_check_button_new_with_mnemonic(_("_Visual gesture display")); | |
235 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
236 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
237 gstroke_draw_strokes()); | |
238 g_signal_connect(G_OBJECT(toggle), "toggled", | |
239 G_CALLBACK(toggle_draw_cb), NULL); | |
240 | |
241 gtk_widget_show_all(ret); | |
242 | |
243 return ret; | |
244 } | |
245 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
246 static GaimGtkPluginUiInfo ui_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
247 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
248 get_config_frame |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
249 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
250 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
251 static GaimPluginInfo info = |
4390 | 252 { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
253 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
254 GAIM_PLUGIN_STANDARD, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
255 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
256 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
257 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
258 GAIM_PRIORITY_DEFAULT, /**< priority */ |
4390 | 259 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
260 GESTURES_PLUGIN_ID, /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
261 N_("Mouse Gestures"), /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
262 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
263 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
264 N_("Provides support for mouse gestures"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
265 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
266 N_("Allows support for mouse gestures in conversation windows.\n" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
267 "Drag the middle mouse button to perform certain actions:\n\n" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
268 "Drag down and then to the right to close a conversation.\n" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
269 "Drag up and then to the left to switch to the previous " |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
270 "conversation.\n" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
271 "Drag up and then to the right to switch to the next " |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
272 "conversation."), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
273 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
274 WEBSITE, /**< homepage */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
275 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
276 plugin_load, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
277 plugin_unload, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
278 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
279 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
280 &ui_info, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
281 NULL /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
282 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
283 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
284 static void |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
285 __init_plugin(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
286 { |
4390 | 287 } |
288 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5016
diff
changeset
|
289 GAIM_INIT_PLUGIN(gestures, __init_plugin, info); |