Replace functions which called once with their bodies
[pidgin-git.git] / pidgin / plugins / gestures / gestures.c
blobd28b692e093dd4c91aad294b709a6fb0b83694bf
1 /*
2 * Mouse gestures plugin for Purple
4 * Copyright (C) 2003 Christian Hammond.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02111-1301, USA.
21 #include "internal.h"
22 #include "pidgin.h"
24 #include "debug.h"
25 #include "prefs.h"
26 #include "signals.h"
27 #include "version.h"
29 #include "gtk3compat.h"
30 #include "gtkconv.h"
31 #include "gtkplugin.h"
32 #include "gtkutils.h"
34 #include "gstroke.h"
36 #define GESTURES_PLUGIN_ID "gtk-x11-gestures"
38 static void
39 stroke_close(GtkWidget *widget, void *data)
41 PurpleConversation *conv;
42 PidginConversation *gtkconv;
44 conv = (PurpleConversation *)data;
46 /* Double-check */
47 if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv))
48 return;
50 gtkconv = PIDGIN_CONVERSATION(conv);
52 gstroke_cleanup(gtkconv->webview);
53 g_object_unref(conv);
56 static void
57 switch_page(PidginConvWindow *win, GtkDirectionType dir)
59 int count, current;
61 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(win->notebook));
62 current = gtk_notebook_get_current_page(GTK_NOTEBOOK(win->notebook));
64 if (dir == GTK_DIR_LEFT)
66 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), current - 1);
68 else if (dir == GTK_DIR_RIGHT)
70 if (current == count - 1)
71 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), 0);
72 else
73 gtk_notebook_set_current_page(GTK_NOTEBOOK(win->notebook), current + 1);
77 static void
78 stroke_prev_tab(GtkWidget *widget, void *data)
80 PurpleConversation *conv;
81 PidginConversation *gtkconv;
82 PidginConvWindow *win;
84 conv = (PurpleConversation *)data;
85 gtkconv = PIDGIN_CONVERSATION(conv);
86 win = gtkconv->win;
88 switch_page(win, GTK_DIR_LEFT);
91 static void
92 stroke_next_tab(GtkWidget *widget, void *data)
94 PurpleConversation *conv;
95 PidginConvWindow *win;
97 conv = (PurpleConversation *)data;
98 win = PIDGIN_CONVERSATION(conv)->win;
100 switch_page(win, GTK_DIR_RIGHT);
103 static void
104 stroke_new_win(GtkWidget *widget, void *data)
106 PidginConvWindow *new_win, *old_win;
107 PurpleConversation *conv;
109 conv = (PurpleConversation *)data;
110 old_win = PIDGIN_CONVERSATION(conv)->win;
112 if (pidgin_conv_window_get_gtkconv_count(old_win) <= 1)
113 return;
115 new_win = pidgin_conv_window_new();
117 pidgin_conv_window_remove_gtkconv(old_win, PIDGIN_CONVERSATION(conv));
118 pidgin_conv_window_add_gtkconv(new_win, PIDGIN_CONVERSATION(conv));
120 pidgin_conv_window_show(new_win);
123 static void
124 attach_signals(PurpleConversation *conv)
126 PidginConversation *gtkconv;
128 gtkconv = PIDGIN_CONVERSATION(conv);
130 gstroke_enable(gtkconv->webview);
131 gstroke_signal_connect(gtkconv->webview, "14789", stroke_close, conv);
132 gstroke_signal_connect(gtkconv->webview, "1456", stroke_close, conv);
133 gstroke_signal_connect(gtkconv->webview, "1489", stroke_close, conv);
134 gstroke_signal_connect(gtkconv->webview, "74123", stroke_next_tab, conv);
135 gstroke_signal_connect(gtkconv->webview, "7456", stroke_next_tab, conv);
136 gstroke_signal_connect(gtkconv->webview, "96321", stroke_prev_tab, conv);
137 gstroke_signal_connect(gtkconv->webview, "9654", stroke_prev_tab, conv);
138 gstroke_signal_connect(gtkconv->webview, "25852", stroke_new_win, conv);
141 static void
142 new_conv_cb(PurpleConversation *conv)
144 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
145 attach_signals(conv);
148 #if 0
149 static void
150 mouse_button_menu_cb(GtkComboBox *opt, gpointer data)
152 int button = gtk_combo_box_get_active(opt);
154 gstroke_set_mouse_button(button + 2);
156 #endif
158 static void
159 toggle_draw_cb(GtkToggleButton *toggle, gpointer data)
161 purple_prefs_set_bool("/plugins/gtk/X11/gestures/visual",
162 gtk_toggle_button_get_active(toggle));
165 static void
166 visual_pref_cb(const char *name, PurplePrefType type, gconstpointer value,
167 gpointer data)
169 gstroke_set_draw_strokes((gboolean) GPOINTER_TO_INT(value) );
172 static GtkWidget *
173 get_config_frame(PurplePlugin *plugin)
175 GtkWidget *ret;
176 GtkWidget *vbox;
177 GtkWidget *toggle;
178 #if 0
179 GtkWidget *opt;
180 #endif
182 /* Outside container */
183 ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 18);
184 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
186 /* Configuration frame */
187 vbox = pidgin_make_frame(ret, _("Mouse Gestures Configuration"));
189 #if 0
190 /* Mouse button drop-down menu */
191 opt = gtk_combo_box_new_text();
193 gtk_combo_box_append_text(_("Middle mouse button"));
194 gtk_combo_box_append_text(_("Right mouse button"));
195 g_signal_connect(G_OBJECT(opt), "changed",
196 G_CALLBACK(mouse_button_menu_cb), NULL);
198 gtk_box_pack_start(GTK_BOX(vbox), opt, FALSE, FALSE, 0);
199 gtk_combo_box_set_active(GTK_COMBO_BOX(opt),
200 gstroke_get_mouse_button() - 2);
201 #endif
203 /* "Visual gesture display" checkbox */
204 toggle = gtk_check_button_new_with_mnemonic(_("_Visual gesture display"));
205 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
206 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle),
207 purple_prefs_get_bool("/plugins/gtk/X11/gestures/visual"));
208 g_signal_connect(G_OBJECT(toggle), "toggled",
209 G_CALLBACK(toggle_draw_cb), NULL);
211 gtk_widget_show_all(ret);
213 return ret;
216 static PidginPluginInfo *
217 plugin_query(GError **error)
219 const gchar * const authors[] = {
220 "Christian Hammond <chipx86@gnupdate.org>",
221 NULL
224 return pidgin_plugin_info_new(
225 "id", GESTURES_PLUGIN_ID,
226 "name", N_("Mouse Gestures"),
227 "version", DISPLAY_VERSION,
228 "category", N_("User interface"),
229 "summary", N_("Provides support for mouse gestures"),
230 "description", N_("Allows support for mouse gestures in "
231 "conversation windows. Drag the middle "
232 "mouse button to perform certain "
233 "actions:\n"
234 " • Drag down and then to the right to "
235 "close a conversation.\n"
236 " • Drag up and then to the left to "
237 "switch to the previous conversation.\n"
238 " • Drag up and then to the right to "
239 "switch to the next conversation."),
240 "authors", authors,
241 "website", PURPLE_WEBSITE,
242 "abi-version", PURPLE_ABI_VERSION,
243 "gtk-config-frame-cb", get_config_frame,
244 NULL
248 static gboolean
249 plugin_load(PurplePlugin *plugin, GError **error)
251 PurpleConversation *conv;
252 GList *l;
254 purple_prefs_add_none("/plugins/gtk");
255 purple_prefs_add_none("/plugins/gtk/X11");
256 purple_prefs_add_none("/plugins/gtk/X11/gestures");
257 purple_prefs_add_bool("/plugins/gtk/X11/gestures/visual", FALSE);
259 purple_prefs_connect_callback(plugin,
260 "/plugins/gtk/X11/gestures/visual", visual_pref_cb, NULL);
261 gstroke_set_draw_strokes(purple_prefs_get_bool(
262 "/plugins/gtk/X11/gestures/visual"));
264 for (l = purple_conversations_get_all(); l != NULL; l = l->next) {
265 conv = (PurpleConversation *)l->data;
267 if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv))
268 continue;
270 attach_signals(conv);
273 purple_signal_connect(purple_conversations_get_handle(),
274 "conversation-created",
275 plugin, PURPLE_CALLBACK(new_conv_cb), NULL);
277 return TRUE;
280 static gboolean
281 plugin_unload(PurplePlugin *plugin, GError **error)
283 PurpleConversation *conv;
284 PidginConversation *gtkconv;
285 GList *l;
287 for (l = purple_conversations_get_all(); l != NULL; l = l->next) {
288 conv = (PurpleConversation *)l->data;
290 if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv))
291 continue;
293 gtkconv = PIDGIN_CONVERSATION(conv);
295 gstroke_cleanup(gtkconv->webview);
296 gstroke_disable(gtkconv->webview);
299 return TRUE;
302 PURPLE_PLUGIN_INIT(gestures, plugin_query, plugin_load, plugin_unload);