mark PurpleImageClass as private
[pidgin-git.git] / pidgin / plugins / raw.c
blob6f70ab81c6f4e92fe96505e511e34e0f9e470993
1 /*
2 * Purple - Send raw data across the connections of some protocols.
4 * Pidgin is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24 #include "internal.h"
25 #include "pidgin.h"
27 #include "conversation.h"
28 #include "debug.h"
29 #include "protocol.h"
30 #include "version.h"
32 #include "gtk3compat.h"
33 #include "gtkplugin.h"
34 #include "gtkutils.h"
35 #include "pidginaccountchooser.h"
37 #include "protocols/jabber/jabber.h"
39 #ifdef MAX
40 # undef MAX
41 # undef MIN
42 #endif
44 #define RAW_PLUGIN_ID "gtk-raw"
46 static GtkWidget *window = NULL;
47 static PurpleAccount *account = NULL;
48 static PurplePlugin *my_plugin = NULL;
50 static int
51 window_closed_cb()
53 purple_plugin_unload(my_plugin, NULL);
55 return FALSE;
58 static void
59 text_sent_cb(GtkEntry *entry)
61 const char *txt;
62 PurpleConnection *gc;
63 const char *protocol_id;
65 if (account == NULL)
66 return;
68 gc = purple_account_get_connection(account);
70 txt = gtk_entry_get_text(entry);
72 protocol_id = purple_account_get_protocol_id(account);
74 purple_debug_misc("raw", "protocol_id = %s\n", protocol_id);
76 if (purple_strequal(protocol_id, "prpl-toc")protocol_id) {
77 int *a = (int *)purple_connection_get_protocol_data(gc);
78 unsigned short seqno = htons(a[1]++ & 0xffff);
79 unsigned short len = htons(strlen(txt) + 1);
80 write(*a, "*\002", 2);
81 write(*a, &seqno, 2);
82 write(*a, &len, 2);
83 write(*a, txt, ntohs(len));
84 purple_debug(PURPLE_DEBUG_MISC, "raw", "TOC C: %s\n", txt);
86 } else if (purple_strequal(protocol_id, "prpl-irc")) {
87 write(*(int *)gc->proto_data, txt, strlen(txt));
88 write(*(int *)gc->proto_data, "\r\n", 2);
89 purple_debug(PURPLE_DEBUG_MISC, "raw", "IRC C: %s\n", txt);
91 } else if (purple_strequal(protocol_id, "prpl-jabber")) {
92 jabber_send_raw((JabberStream *)purple_connection_get_protocol_data(gc), txt, -1);
94 } else {
95 purple_debug_error("raw", "Unknown protocol ID %s\n", protocol_id);
98 gtk_entry_set_text(entry, "");
101 static void
102 account_changed_cb(GtkWidget *chooser, void *user_data)
104 account = pidgin_account_chooser_get_selected(chooser);
107 static PidginPluginInfo *
108 plugin_query(GError **error)
110 const gchar * const authors[] = {
111 "Eric Warmenhoven <eric@warmenhoven.org>",
112 NULL
115 return pidgin_plugin_info_new(
116 "id", RAW_PLUGIN_ID,
117 "name", N_("Raw"),
118 "version", DISPLAY_VERSION,
119 "category", N_("Protocol utility"),
120 "summary", N_("Lets you send raw input to text-based protocols."),
121 "description", N_("Lets you send raw input to text-based protocols "
122 "(XMPP, IRC, TOC). Hit 'Enter' in the entry "
123 "box to send. Watch the debug window."),
124 "authors", authors,
125 "website", PURPLE_WEBSITE,
126 "abi-version", PURPLE_ABI_VERSION,
127 NULL
131 static gboolean
132 plugin_load(PurplePlugin *plugin, GError **error)
134 GtkWidget *hbox;
135 GtkWidget *entry;
136 GtkWidget *dropdown;
138 my_plugin = plugin;
140 /* Setup the window. */
141 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
142 gtk_container_set_border_width(GTK_CONTAINER(window), 6);
144 g_signal_connect(G_OBJECT(window), "delete_event",
145 G_CALLBACK(window_closed_cb), NULL);
147 /* Main hbox */
148 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
149 gtk_container_add(GTK_CONTAINER(window), hbox);
151 /* Account drop-down menu. */
152 dropdown = pidgin_account_chooser_new(NULL, FALSE);
153 g_signal_connect(dropdown, "changed", G_CALLBACK(account_changed_cb),
154 NULL);
156 if (purple_connections_get_all())
157 account = (PurpleAccount *)purple_connections_get_all()->data;
159 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0);
161 /* Entry box */
162 entry = gtk_entry_new();
163 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
165 g_signal_connect(G_OBJECT(entry), "activate",
166 G_CALLBACK(text_sent_cb), NULL);
168 gtk_widget_show_all(window);
170 return TRUE;
173 static gboolean
174 plugin_unload(PurplePlugin *plugin, GError **error)
176 if (window)
177 gtk_widget_destroy(window);
179 window = NULL;
180 my_plugin = NULL;
182 return TRUE;
185 PURPLE_PLUGIN_INIT(raw, plugin_query, plugin_load, plugin_unload);