Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / pidgin / plugins / sendbutton.c
blob03a8fc8351652fd9febd07a02d3334c8c779433d
1 /*
2 * SendButton - Add a Send button to the conversation window entry area.
3 * Copyright (C) 2008 Etan Reisner <deryni@pidgin.im>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
24 #include "internal.h"
26 #include "version.h"
28 #include "pidgin.h"
30 #include "gtkconv.h"
31 #include "gtkplugin.h"
33 static void
34 send_button_cb(GtkButton *button, PidginConversation *gtkconv)
36 g_signal_emit_by_name(gtkconv->entry, "message_send");
39 static void
40 input_buffer_changed(GtkTextBuffer *text_buffer, GtkWidget *send_button)
42 if (gtk_text_buffer_get_char_count(text_buffer) != 0)
43 gtk_widget_set_sensitive(send_button, TRUE);
44 else
45 gtk_widget_set_sensitive(send_button, FALSE);
48 static void
49 create_send_button_pidgin(PidginConversation *gtkconv)
51 GtkWidget *send_button;
52 GtkTextBuffer *buf;
53 guint signal_id;
55 send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
56 "send_button");
58 if (send_button != NULL)
59 return;
61 send_button = gtk_button_new_with_mnemonic(_("_Send"));
62 g_signal_connect(G_OBJECT(send_button), "clicked",
63 G_CALLBACK(send_button_cb), gtkconv);
64 gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), send_button, FALSE,
65 FALSE, 0);
66 gtk_widget_show(send_button);
68 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
69 if (buf) {
70 signal_id = g_signal_connect(G_OBJECT(buf), "changed",
71 G_CALLBACK(input_buffer_changed),
72 send_button);
73 g_object_set_data(G_OBJECT(send_button), "buffer-signal",
74 GINT_TO_POINTER(signal_id));
75 input_buffer_changed(buf, send_button);
78 g_object_set_data(G_OBJECT(gtkconv->lower_hbox), "send_button",
79 send_button);
82 static void
83 remove_send_button_pidgin(PidginConversation *gtkconv)
85 GtkWidget *send_button = NULL;
87 send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
88 "send_button");
89 if (send_button != NULL) {
90 GtkTextBuffer *buf;
91 guint signal_id;
93 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
94 signal_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(send_button),
95 "buffer-signal"));
96 if (buf && signal_id)
97 g_signal_handler_disconnect(G_OBJECT(buf), signal_id);
99 gtk_widget_destroy(send_button);
100 g_object_set_data(G_OBJECT(gtkconv->lower_hbox),
101 "send_button", NULL);
105 static void
106 conversation_displayed_cb(PidginConversation *gtkconv)
108 GtkWidget *send_button = NULL;
110 send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
111 "send_button");
112 if (send_button == NULL) {
113 create_send_button_pidgin(gtkconv);
117 static PidginPluginInfo *
118 plugin_query(GError **error)
120 const gchar * const authors[] = {
121 "Etan Reisner <deryni@pidgin.im>",
122 NULL
125 return pidgin_plugin_info_new(
126 "id", "gtksendbutton",
127 "name", N_("Send Button"),
128 "version", DISPLAY_VERSION,
129 "category", N_("User interface"),
130 "summary", N_("Conversation Window Send Button."),
131 "description", N_("Adds a Send button to the entry area of the "
132 "conversation window. Intended for use when no "
133 "physical keyboard is present."),
134 "authors", authors,
135 "website", PURPLE_WEBSITE,
136 "abi-version", PURPLE_ABI_VERSION,
137 NULL
141 static gboolean
142 plugin_load(PurplePlugin *plugin, GError **error)
144 GList *convs = purple_conversations_get_all();
145 void *gtk_conv_handle = pidgin_conversations_get_handle();
147 purple_signal_connect(gtk_conv_handle, "conversation-displayed", plugin,
148 PURPLE_CALLBACK(conversation_displayed_cb), NULL);
150 purple_signal_connect(gtk_conv_handle, "conversation-hiding", plugin,
151 PURPLE_CALLBACK(conversation_hiding_cb), NULL);
154 while (convs) {
156 PurpleConversation *conv = (PurpleConversation *)convs->data;
158 /* Setup Send button */
159 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
160 create_send_button_pidgin(PIDGIN_CONVERSATION(conv));
163 convs = convs->next;
166 return TRUE;
169 static gboolean
170 plugin_unload(PurplePlugin *plugin, GError **error)
172 GList *convs = purple_conversations_get_all();
174 while (convs) {
175 PurpleConversation *conv = (PurpleConversation *)convs->data;
177 /* Remove Send button */
178 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
179 remove_send_button_pidgin(PIDGIN_CONVERSATION(conv));
182 convs = convs->next;
185 return TRUE;
188 PURPLE_PLUGIN_INIT(sendbutton, plugin_query, plugin_load, plugin_unload);