Mercurial > pidgin.yaz
annotate plugins/raw.c @ 10293:77aad37391b9
[gaim-migrate @ 11471]
i didn't realize i had a displayable version of this name as well
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 02 Dec 2004 12:47:11 +0000 |
parents | a9fb4493ae22 |
children | 5cda52915a1f |
rev | line source |
---|---|
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1 #include "conversation.h" |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
2 #include "debug.h" |
2495 | 3 #include "prpl.h" |
9954 | 4 #include "version.h" |
9821 | 5 |
6 #include "gtkgaim.h" | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
7 #include "gtkplugin.h" |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
8 #include "gtkutils.h" |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
9 |
2495 | 10 #ifdef MAX |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
11 # undef MAX |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
12 # undef MIN |
2495 | 13 #endif |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
14 |
2824
2c39e70dd07c
[gaim-migrate @ 2837]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2495
diff
changeset
|
15 #include "protocols/jabber/jabber.h" |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
16 #include "protocols/msn/session.h" |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
17 |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
18 #define RAW_PLUGIN_ID "gtk-raw" |
2495 | 19 |
20 static GtkWidget *window = NULL; | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
21 static GaimAccount *account = NULL; |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
22 static GaimPlugin *my_plugin = NULL; |
2495 | 23 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
24 static int |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
25 window_closed_cb() |
2495 | 26 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
27 gaim_plugin_unload(my_plugin); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
28 |
2495 | 29 return FALSE; |
30 } | |
31 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
32 static void |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
33 text_sent_cb(GtkEntry *entry) |
2495 | 34 { |
4655 | 35 const char *txt; |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
36 GaimConnection *gc; |
9460 | 37 const char *prpl_id; |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
38 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
39 if (account == NULL) |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
40 return; |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
41 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
42 gc = gaim_account_get_connection(account); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
43 |
2495 | 44 txt = gtk_entry_get_text(entry); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
45 |
9460 | 46 prpl_id = gaim_account_get_protocol_id(account); |
47 | |
48 gaim_debug_misc("raw", "prpl_id = %s\n", prpl_id); | |
49 | |
50 if (strcmp(prpl_id, "prpl-toc") == 0) { | |
51 int *a = (int *)gc->proto_data; | |
52 unsigned short seqno = htons(a[1]++ & 0xffff); | |
53 unsigned short len = htons(strlen(txt) + 1); | |
54 write(*a, "*\002", 2); | |
55 write(*a, &seqno, 2); | |
56 write(*a, &len, 2); | |
57 write(*a, txt, ntohs(len)); | |
58 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); | |
59 | |
60 } else if (strcmp(prpl_id, "prpl-msn") == 0) { | |
61 MsnSession *session = gc->proto_data; | |
62 char buf[strlen(txt) + 3]; | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
63 |
9460 | 64 g_snprintf(buf, sizeof(buf), "%s\r\n", txt); |
65 msn_servconn_write(session->notification->servconn, buf, strlen(buf)); | |
66 | |
67 } else if (strcmp(prpl_id, "prpl-irc") == 0) { | |
68 write(*(int *)gc->proto_data, txt, strlen(txt)); | |
69 write(*(int *)gc->proto_data, "\r\n", 2); | |
70 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
71 |
9460 | 72 } else if (strcmp(prpl_id, "prpl-jabber") == 0) { |
73 jabber_send_raw((JabberStream *)gc->proto_data, txt, -1); | |
74 } else { | |
75 gaim_debug_error("raw", "Unknown protocol ID %s\n", prpl_id); | |
2495 | 76 } |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
77 |
2495 | 78 gtk_entry_set_text(entry, ""); |
79 } | |
80 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
81 static void |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
82 account_changed_cb(GtkWidget *dropdown, GaimAccount *new_account, |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
83 void *user_data) |
2495 | 84 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
85 account = new_account; |
2495 | 86 } |
87 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
88 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
89 plugin_load(GaimPlugin *plugin) |
2495 | 90 { |
91 GtkWidget *hbox; | |
92 GtkWidget *entry; | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
93 GtkWidget *dropdown; |
2495 | 94 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
95 /* Setup the window. */ |
2495 | 96 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
6389
c05c02b6bfc8
[gaim-migrate @ 6894]
Christian Hammond <chipx86@chipx86.com>
parents:
6388
diff
changeset
|
97 gtk_container_set_border_width(GTK_CONTAINER(window), 6); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
98 |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
99 g_signal_connect(G_OBJECT(window), "delete_event", |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
100 G_CALLBACK(window_closed_cb), NULL); |
2495 | 101 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
102 /* Main hbox */ |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
103 hbox = gtk_hbox_new(FALSE, 6); |
2495 | 104 gtk_container_add(GTK_CONTAINER(window), hbox); |
105 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
106 /* Account drop-down menu. */ |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
107 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
6647
ed89cd0c675e
[gaim-migrate @ 7172]
Christian Hammond <chipx86@chipx86.com>
parents:
6390
diff
changeset
|
108 G_CALLBACK(account_changed_cb), NULL, NULL); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
109 |
6390
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
110 if (gaim_connections_get_all()) |
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
111 account = (GaimAccount *)gaim_connections_get_all()->data; |
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
112 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
113 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
2495 | 114 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
115 /* Entry box */ |
2495 | 116 entry = gtk_entry_new(); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
117 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
118 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
119 g_signal_connect(G_OBJECT(entry), "activate", |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
120 G_CALLBACK(text_sent_cb), NULL); |
2495 | 121 |
122 gtk_widget_show_all(window); | |
123 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
124 return TRUE; |
2495 | 125 } |
126 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
127 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
128 plugin_unload(GaimPlugin *plugin) |
2495 | 129 { |
130 if (window) | |
131 gtk_widget_destroy(window); | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
132 |
2495 | 133 window = NULL; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
134 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
135 return TRUE; |
2495 | 136 } |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
137 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
138 static GaimPluginInfo info = |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
139 { |
9954 | 140 GAIM_PLUGIN_MAGIC, |
141 GAIM_MAJOR_VERSION, | |
142 GAIM_MINOR_VERSION, | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
143 GAIM_PLUGIN_STANDARD, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
144 GAIM_GTK_PLUGIN_TYPE, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
145 0, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
146 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
147 GAIM_PRIORITY_DEFAULT, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
148 RAW_PLUGIN_ID, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
149 N_("Raw"), |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
150 VERSION, |
5424 | 151 N_("Lets you send raw input to text-based protocols."), |
152 N_("Lets you send raw input to text-based protocols (Jabber, MSN, IRC, " | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
153 "TOC). Hit 'Enter' in the entry box to send. Watch the debug window."), |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
154 "Eric Warmenhoven <eric@warmenhoven.org>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6063
diff
changeset
|
155 GAIM_WEBSITE, |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
156 plugin_load, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
157 plugin_unload, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
158 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
159 NULL, |
8993 | 160 NULL, |
161 NULL, | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
162 NULL |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
163 }; |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
164 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
165 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5424
diff
changeset
|
166 init_plugin(GaimPlugin *plugin) |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
167 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
168 my_plugin = plugin; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
169 } |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
170 |
6063 | 171 GAIM_INIT_PLUGIN(raw, init_plugin, info) |