Mercurial > pidgin.yaz
annotate plugins/raw.c @ 5972:c36b3c654761
[gaim-migrate @ 6419]
I might as well commit it right this instant.
This makes Gaim not output silly gtk error things when importing a
buddy pounce on an account that no longer exists.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 29 Jun 2003 06:16:16 +0000 |
parents | 7d385de2f9cd |
children | 5239a3b4ab33 |
rev | line source |
---|---|
2495 | 1 #include "gaim.h" |
2 #include "prpl.h" | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
3 #include "gtkplugin.h" |
2495 | 4 #ifdef MAX |
5 #undef MAX | |
6 #undef MIN | |
7 #endif | |
2824
2c39e70dd07c
[gaim-migrate @ 2837]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2495
diff
changeset
|
8 #include "protocols/jabber/jabber.h" |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
9 #include "protocols/msn/session.h" |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
10 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
11 #define RAW_PLUGIN_ID "raw" |
2495 | 12 |
13 static GtkWidget *window = NULL; | |
14 static GtkWidget *optmenu = NULL; | |
15 static struct gaim_connection *gc = NULL; | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
16 static GaimPlugin *me = NULL; |
2495 | 17 |
18 static int goodbye() | |
19 { | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
20 gaim_plugin_unload(me); |
2495 | 21 return FALSE; |
22 } | |
23 | |
24 static void send_it(GtkEntry *entry) | |
25 { | |
4655 | 26 const char *txt; |
2495 | 27 if (!gc) return; |
28 txt = gtk_entry_get_text(entry); | |
29 switch (gc->protocol) { | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
30 case GAIM_PROTO_TOC: |
2495 | 31 { |
32 int *a = (int *)gc->proto_data; | |
33 unsigned short seqno = htons(a[1]++ & 0xffff); | |
34 unsigned short len = htons(strlen(txt) + 1); | |
35 write(*a, "*\002", 2); | |
36 write(*a, &seqno, 2); | |
37 write(*a, &len, 2); | |
38 write(*a, txt, ntohs(len)); | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
39 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); |
2495 | 40 } |
41 break; | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
42 case GAIM_PROTO_MSN: |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
43 { |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
44 MsnSession *session = gc->proto_data; |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
45 char buf[strlen(txt) + 3]; |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
46 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
47 g_snprintf(buf, sizeof(buf), "%s\r\n", txt); |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
48 msn_servconn_write(session->notification_conn, buf, strlen(buf)); |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
49 } |
2495 | 50 break; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
51 case GAIM_PROTO_IRC: |
2495 | 52 write(*(int *)gc->proto_data, txt, strlen(txt)); |
53 write(*(int *)gc->proto_data, "\r\n", 2); | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
54 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); |
2495 | 55 break; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
56 case GAIM_PROTO_JABBER: |
2495 | 57 jab_send_raw(*(jconn *)gc->proto_data, txt); |
58 break; | |
59 } | |
60 gtk_entry_set_text(entry, ""); | |
61 } | |
62 | |
63 static void set_gc(gpointer d, struct gaim_connection *c) | |
64 { | |
65 gc = c; | |
66 } | |
67 | |
68 static void redo_optmenu(struct gaim_connection *arg, gpointer x) | |
69 { | |
70 GtkWidget *menu; | |
71 GSList *g = connections; | |
72 struct gaim_connection *c; | |
73 | |
74 menu = gtk_menu_new(); | |
75 gc = NULL; | |
76 | |
77 while (g) { | |
78 char buf[256]; | |
79 GtkWidget *opt; | |
80 c = (struct gaim_connection *)g->data; | |
81 g = g->next; | |
82 if (x && c == arg) | |
83 continue; | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
84 if (c->protocol != GAIM_PROTO_TOC && c->protocol != GAIM_PROTO_MSN && |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
85 c->protocol != GAIM_PROTO_IRC && c->protocol != GAIM_PROTO_JABBER) |
2495 | 86 continue; |
87 if (!gc) | |
88 gc = c; | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
89 g_snprintf(buf, sizeof buf, "%s (%s)", c->username, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
90 c->prpl->info->name); |
2495 | 91 opt = gtk_menu_item_new_with_label(buf); |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
92 g_signal_connect(G_OBJECT(opt), "activate", G_CALLBACK(set_gc), c); |
2495 | 93 gtk_widget_show(opt); |
4655 | 94 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
2495 | 95 } |
96 | |
97 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
98 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
99 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); | |
100 } | |
101 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
102 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
103 plugin_load(GaimPlugin *plugin) |
2495 | 104 { |
105 GtkWidget *hbox; | |
106 GtkWidget *entry; | |
107 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
108 gaim_signal_connect(plugin, event_signon, redo_optmenu, NULL); |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
109 gaim_signal_connect(plugin, event_signoff, redo_optmenu, me); |
2495 | 110 |
111 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
112 g_signal_connect(G_OBJECT(window), "delete_event", |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
113 G_CALLBACK(goodbye), NULL); |
2495 | 114 |
115 hbox = gtk_hbox_new(FALSE, 0); | |
116 gtk_container_add(GTK_CONTAINER(window), hbox); | |
117 | |
118 optmenu = gtk_option_menu_new(); | |
119 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 5); | |
120 | |
121 redo_optmenu(NULL, NULL); | |
122 | |
123 entry = gtk_entry_new(); | |
124 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); | |
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
125 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(send_it), NULL); |
2495 | 126 |
127 gtk_widget_show_all(window); | |
128 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
129 return TRUE; |
2495 | 130 } |
131 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
132 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
133 plugin_unload(GaimPlugin *plugin) |
2495 | 134 { |
135 if (window) | |
136 gtk_widget_destroy(window); | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
137 |
2495 | 138 window = NULL; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
139 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
140 return TRUE; |
2495 | 141 } |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
142 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
143 static GaimPluginInfo info = |
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 2, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
146 GAIM_PLUGIN_STANDARD, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
147 GAIM_GTK_PLUGIN_TYPE, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
148 0, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
149 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
150 GAIM_PRIORITY_DEFAULT, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
151 RAW_PLUGIN_ID, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
152 N_("Raw"), |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
153 VERSION, |
5424 | 154 N_("Lets you send raw input to text-based protocols."), |
155 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
|
156 "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
|
157 "Eric Warmenhoven <eric@warmenhoven.org>", |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
158 WEBSITE, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
159 plugin_load, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
160 plugin_unload, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
161 NULL, |
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 NULL |
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 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
166 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5424
diff
changeset
|
167 init_plugin(GaimPlugin *plugin) |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
168 { |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
169 me = plugin; |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
170 } |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
171 |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5424
diff
changeset
|
172 GAIM_INIT_PLUGIN(raw, init_plugin, info); |