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