comparison plugins/gestures/gestures.c @ 4390:16540914c963

[gaim-migrate @ 4656] Added a mouse gestures plugin. Yes, you heard me. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 22 Jan 2003 13:57:27 +0000
parents
children 2308397639df
comparison
equal deleted inserted replaced
4389:e23a59b62700 4390:16540914c963
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 #ifndef GAIM_PLUGINS
24 #define GAIM_PLUGINS
25 #endif
26
27 #include "gaim.h"
28 #include "gstroke.h"
29
30 static GModule *handle = NULL;
31 struct gaim_plugin_description desc;
32
33 static void
34 stroke_close(GtkWidget *widget, void *data)
35 {
36 struct gaim_conversation *conv;
37 struct gaim_gtk_conversation *gtkconv;
38
39 conv = (struct gaim_conversation *)data;
40
41 /* Double-check */
42 if (!GAIM_IS_GTK_CONVERSATION(conv))
43 return;
44
45 gtkconv = GAIM_GTK_CONVERSATION(conv);
46
47 gstroke_cleanup(gtkconv->imhtml);
48 gaim_conversation_destroy(conv);
49 }
50
51 static void
52 stroke_prev_tab(GtkWidget *widget, void *data)
53 {
54 struct gaim_conversation *conv;
55 struct gaim_window *win;
56 unsigned int index;
57
58 conv = (struct gaim_conversation *)data;
59 win = gaim_conversation_get_window(conv);
60 index = gaim_conversation_get_index(conv);
61
62 if (index == 0)
63 index = gaim_window_get_conversation_count(win) - 1;
64 else
65 index--;
66
67 gaim_window_switch_conversation(win, index);
68 }
69
70 static void
71 stroke_next_tab(GtkWidget *widget, void *data)
72 {
73 struct gaim_conversation *conv;
74 struct gaim_window *win;
75 unsigned int index;
76
77 conv = (struct gaim_conversation *)data;
78 win = gaim_conversation_get_window(conv);
79 index = gaim_conversation_get_index(conv);
80
81 if (index == gaim_window_get_conversation_count(win) - 1)
82 index = 0;
83 else
84 index++;
85
86 gaim_window_switch_conversation(win, index);
87 }
88
89 void
90 stroke_new_win(GtkWidget *widget, void *data)
91 {
92 struct gaim_window *new_win, *old_win;
93 struct gaim_conversation *conv;
94
95 conv = (struct gaim_conversation *)data;
96 old_win = gaim_conversation_get_window(conv);
97
98 if (gaim_window_get_conversation_count(old_win) <= 1)
99 return;
100
101 new_win = gaim_window_new();
102
103 gaim_window_remove_conversation(old_win, gaim_conversation_get_index(conv));
104 gaim_window_add_conversation(new_win, conv);
105
106 gaim_window_show(new_win);
107 }
108
109 static void
110 attach_signals(struct gaim_conversation *conv)
111 {
112 struct gaim_gtk_conversation *gtkconv;
113
114 gtkconv = GAIM_GTK_CONVERSATION(conv);
115
116 gstroke_enable(gtkconv->imhtml);
117 gstroke_signal_connect(gtkconv->imhtml, "14789", stroke_close, conv);
118 gstroke_signal_connect(gtkconv->imhtml, "1456", stroke_close, conv);
119 gstroke_signal_connect(gtkconv->imhtml, "74123", stroke_next_tab, conv);
120 gstroke_signal_connect(gtkconv->imhtml, "7456", stroke_next_tab, conv);
121 gstroke_signal_connect(gtkconv->imhtml, "96321", stroke_prev_tab, conv);
122 gstroke_signal_connect(gtkconv->imhtml, "9654", stroke_prev_tab, conv);
123 gstroke_signal_connect(gtkconv->imhtml, "25852", stroke_new_win, conv);
124 }
125
126 static void
127 new_conv_cb(char *who)
128 {
129 struct gaim_conversation *conv;
130
131 conv = gaim_find_conversation(who);
132
133 if (conv == NULL || !GAIM_IS_GTK_CONVERSATION(conv))
134 return;
135
136 attach_signals(conv);
137 }
138
139 #if 0
140 static void
141 mouse_button_menu_cb(GtkMenuItem *item, gpointer data)
142 {
143 int button = (int)data;
144
145 gstroke_set_mouse_button(button + 2);
146 }
147 #endif
148
149 static void
150 toggle_draw_cb(GtkToggleButton *toggle, gpointer data)
151 {
152 gstroke_set_draw_strokes(!gstroke_draw_strokes());
153 }
154
155 char *
156 gaim_plugin_init(GModule *h)
157 {
158 struct gaim_conversation *conv;
159 GList *l;
160
161 handle = h;
162
163 for (l = gaim_get_conversations(); l != NULL; l = l->next) {
164 conv = (struct gaim_conversation *)l->data;
165
166 if (!GAIM_IS_GTK_CONVERSATION(conv))
167 continue;
168
169 attach_signals(conv);
170 }
171
172 gaim_signal_connect(handle, event_new_conversation, new_conv_cb, NULL);
173
174 return NULL;
175 }
176
177 void
178 gaim_plugin_remove(void)
179 {
180 struct gaim_conversation *conv;
181 struct gaim_gtk_conversation *gtkconv;
182 GList *l;
183
184 for (l = gaim_get_conversations(); l != NULL; l = l->next) {
185 conv = (struct gaim_conversation *)l->data;
186
187 if (!GAIM_IS_GTK_CONVERSATION(conv))
188 continue;
189
190 gtkconv = GAIM_GTK_CONVERSATION(conv);
191
192 gstroke_cleanup(gtkconv->imhtml);
193 }
194 }
195
196 GtkWidget *
197 gaim_plugin_config_gtk(void)
198 {
199 GtkWidget *ret;
200 GtkWidget *vbox;
201 GtkWidget *toggle;
202 #if 0
203 GtkWidget *opt;
204 GtkWidget *menu, *item;
205 #endif
206
207 /* Outside container */
208 ret = gtk_vbox_new(FALSE, 18);
209 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
210
211 /* Configuration frame */
212 vbox = make_frame(ret, _("Mouse Gestures Configuration"));
213
214 #if 0
215 /* Mouse button drop-down menu */
216 menu = gtk_menu_new();
217 opt = gtk_option_menu_new();
218
219 item = gtk_menu_item_new_with_label(_("Middle mouse button"));
220 g_signal_connect(G_OBJECT(item), "activate",
221 G_CALLBACK(mouse_button_menu_cb), opt);
222 gtk_menu_append(menu, item);
223
224 item = gtk_menu_item_new_with_label(_("Right mouse button"));
225 g_signal_connect(G_OBJECT(item), "activate",
226 G_CALLBACK(mouse_button_menu_cb), opt);
227 gtk_menu_append(menu, item);
228
229 gtk_box_pack_start(GTK_BOX(vbox), opt, FALSE, FALSE, 0);
230 gtk_option_menu_set_menu(GTK_OPTION_MENU(opt), menu);
231 gtk_option_menu_set_history(GTK_OPTION_MENU(opt),
232 gstroke_get_mouse_button() - 2);
233 #endif
234
235 /* "Visual gesture display" checkbox */
236 toggle = gtk_check_button_new_with_mnemonic(_("_Visual gesture display"));
237 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
238 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle),
239 gstroke_draw_strokes());
240 g_signal_connect(G_OBJECT(toggle), "toggled",
241 G_CALLBACK(toggle_draw_cb), NULL);
242
243 gtk_widget_show_all(ret);
244
245 return ret;
246 }
247
248 struct gaim_plugin_description *
249 gaim_plugin_desc()
250 {
251 desc.api_version = PLUGIN_API_VERSION;
252 desc.name = g_strdup(_("Mouse Gestures"));
253 desc.version = g_strdup(VERSION);
254 desc.description = g_strdup(
255 _("Allows support for mouse gestures in conversation windows.\n\n"
256 "Drag down and then to the right to close a conversation.\n"
257 "Drag up and then to the left to switch to the previous "
258 "conversation.\n"
259 "Drag up and then to the right to switch to the next "
260 "conversation."));
261 desc.authors = g_strdup("Christian Hammond &lt;chipx86@gnupdate.org&gt;");
262 desc.url = g_strdup(WEBSITE);
263
264 return &desc;
265 }
266
267 char *
268 name(void)
269 {
270 return _("Mouse Gestures");
271 }
272
273 char *
274 description(void)
275 {
276 return _("Allows support for mouse gestures in conversation windows.\n\n"
277 "Drag down and then to the right to close a conversation.\n"
278 "Drag up and then to the left to switch to the previous "
279 "conversation.\n"
280 "Drag up and then to the right to switch to the next "
281 "conversation.");
282 }