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
29 #include "gtk3compat.h"
31 #include "gtkplugin.h"
36 #define GESTURES_PLUGIN_ID "gtk-x11-gestures"
39 stroke_close(GtkWidget
*widget
, void *data
)
41 PurpleConversation
*conv
;
42 PidginConversation
*gtkconv
;
44 conv
= (PurpleConversation
*)data
;
47 if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv
))
50 gtkconv
= PIDGIN_CONVERSATION(conv
);
52 gstroke_cleanup(gtkconv
->webview
);
57 switch_page(PidginConvWindow
*win
, GtkDirectionType dir
)
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);
73 gtk_notebook_set_current_page(GTK_NOTEBOOK(win
->notebook
), current
+ 1);
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
);
88 switch_page(win
, GTK_DIR_LEFT
);
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
);
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)
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
);
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
);
142 new_conv_cb(PurpleConversation
*conv
)
144 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv
))
145 attach_signals(conv
);
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);
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
));
166 visual_pref_cb(const char *name
, PurplePrefType type
, gconstpointer value
,
169 gstroke_set_draw_strokes((gboolean
) GPOINTER_TO_INT(value
) );
173 get_config_frame(PurplePlugin
*plugin
)
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"));
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);
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
);
216 static PidginPluginInfo
*
217 plugin_query(GError
**error
)
219 const gchar
* const authors
[] = {
220 "Christian Hammond <chipx86@gnupdate.org>",
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 "
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."),
241 "website", PURPLE_WEBSITE
,
242 "abi-version", PURPLE_ABI_VERSION
,
243 "gtk-config-frame-cb", get_config_frame
,
249 plugin_load(PurplePlugin
*plugin
, GError
**error
)
251 PurpleConversation
*conv
;
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
))
270 attach_signals(conv
);
273 purple_signal_connect(purple_conversations_get_handle(),
274 "conversation-created",
275 plugin
, PURPLE_CALLBACK(new_conv_cb
), NULL
);
281 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
283 PurpleConversation
*conv
;
284 PidginConversation
*gtkconv
;
287 for (l
= purple_conversations_get_all(); l
!= NULL
; l
= l
->next
) {
288 conv
= (PurpleConversation
*)l
->data
;
290 if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv
))
293 gtkconv
= PIDGIN_CONVERSATION(conv
);
295 gstroke_cleanup(gtkconv
->webview
);
296 gstroke_disable(gtkconv
->webview
);
302 PURPLE_PLUGIN_INIT(gestures
, plugin_query
, plugin_load
, plugin_unload
);