pidgin/plugins/sendbutton.c

changeset 22828
6a1885524a97
child 24598
dcaf0be8d4e6
equal deleted inserted replaced
22827:a73408f0d27b 22828:6a1885524a97
1 /*
2 * SendButton - Add a Send button to the conversation window entry area.
3 * Copyright (C) 2008 Etan Reisner <deryni@pidgin.im>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "internal.h"
25
26 #include "version.h"
27
28 #include "pidgin.h"
29
30 #include "gtkconv.h"
31 #include "gtkplugin.h"
32
33 static void
34 send_button_cb(GtkButton *button, PidginConversation *gtkconv)
35 {
36 g_signal_emit_by_name(gtkconv->entry, "message_send");
37 }
38
39 static void
40 create_send_button_pidgin(PidginConversation *gtkconv)
41 {
42 GtkWidget *send_button;
43
44 send_button = gtk_button_new_with_mnemonic(_("_Send"));
45 g_signal_connect(G_OBJECT(send_button), "clicked",
46 G_CALLBACK(send_button_cb), gtkconv);
47 gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), send_button, FALSE,
48 FALSE, 0);
49 gtk_widget_show(send_button);
50
51 g_object_set_data(G_OBJECT(gtkconv->lower_hbox), "send_button",
52 send_button);
53 }
54
55 static void
56 remove_send_button_pidgin(PidginConversation *gtkconv)
57 {
58 GtkWidget *send_button = NULL;
59
60 send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
61 "send_button");
62 if (send_button != NULL) {
63 gtk_widget_destroy(send_button);
64 }
65 }
66
67 static void
68 conversation_displayed_cb(PidginConversation *gtkconv)
69 {
70 GtkWidget *send_button = NULL;
71
72 send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
73 "send_button");
74 if (send_button == NULL) {
75 create_send_button_pidgin(gtkconv);
76 }
77 }
78
79 static gboolean
80 plugin_load(PurplePlugin *plugin)
81 {
82 GList *convs = purple_get_conversations();
83 void *gtk_conv_handle = pidgin_conversations_get_handle();
84
85 purple_signal_connect(gtk_conv_handle, "conversation-displayed", plugin,
86 PURPLE_CALLBACK(conversation_displayed_cb), NULL);
87 /*
88 purple_signal_connect(gtk_conv_handle, "conversation-hiding", plugin,
89 PURPLE_CALLBACK(conversation_hiding_cb), NULL);
90 */
91
92 while (convs) {
93
94 PurpleConversation *conv = (PurpleConversation *)convs->data;
95
96 /* Setup Send button */
97 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
98 create_send_button_pidgin(PIDGIN_CONVERSATION(conv));
99 }
100
101 convs = convs->next;
102 }
103
104 return TRUE;
105 }
106
107 static gboolean
108 plugin_unload(PurplePlugin *plugin)
109 {
110 GList *convs = purple_get_conversations();
111
112 while (convs) {
113 PurpleConversation *conv = (PurpleConversation *)convs->data;
114
115 /* Remove Send button */
116 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
117 remove_send_button_pidgin(PIDGIN_CONVERSATION(conv));
118 }
119
120 convs = convs->next;
121 }
122
123 return TRUE;
124 }
125
126 static PurplePluginInfo info =
127 {
128 PURPLE_PLUGIN_MAGIC,
129 PURPLE_MAJOR_VERSION, /**< major version */
130 PURPLE_MINOR_VERSION, /**< minor version */
131 PURPLE_PLUGIN_STANDARD, /**< type */
132 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
133 0, /**< flags */
134 NULL, /**< dependencies */
135 PURPLE_PRIORITY_DEFAULT, /**< priority */
136
137 "gtksendbutton", /**< id */
138 N_("Send Button"), /**< name */
139 DISPLAY_VERSION, /**< version */
140 N_("Conversation Window Send Button."), /**< summary */
141 N_("Adds a Send button to the entry area of "
142 "the conversation window. Intended for when "
143 "no physical keyboard is present."), /**< description */
144 "Etan Reisner <deryni@pidgin.im>", /**< author */
145 PURPLE_WEBSITE, /**< homepage */
146 plugin_load, /**< load */
147 plugin_unload, /**< unload */
148 NULL, /**< destroy */
149 NULL, /**< ui_info */
150 NULL, /**< extra_info */
151 NULL, /**< prefs_info */
152 NULL, /**< actions */
153
154 /* padding */
155 NULL,
156 NULL,
157 NULL,
158 NULL
159 };
160
161 static void
162 init_plugin(PurplePlugin *plugin)
163 {
164 }
165
166 PURPLE_INIT_PLUGIN(sendbutton, init_plugin, info)

mercurial