Mercurial > pidgin
annotate plugins/raw.c @ 3348:dd34e0b40fed
[gaim-migrate @ 3367]
Support for server-side synchronization on group rename. (Thanks, Mark
Doliner)
committer: Tailor Script <tailor@pidgin.im>
author | Jim Seymour <jseymour> |
---|---|
date | Sun, 07 Jul 2002 14:31:57 +0000 |
parents | 2c39e70dd07c |
children | cd938f18f3f8 |
rev | line source |
---|---|
2495 | 1 #define GAIM_PLUGINS |
2 #include "gaim.h" | |
3 #include "prpl.h" | |
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" |
2495 | 9 |
10 static GtkWidget *window = NULL; | |
11 static GtkWidget *optmenu = NULL; | |
12 static struct gaim_connection *gc = NULL; | |
13 static GModule *me = NULL; | |
14 | |
15 /* this is an evil hack. | |
16 * gc->proto_data for Jabber connections can be cast to a jconn *. | |
17 * gc->proto_data for MSN, TOC, and IRC connections can be cast to an int *. | |
18 */ | |
19 | |
20 char *name() | |
21 { | |
22 return "Raw"; | |
23 } | |
24 | |
25 char *description() | |
26 { | |
27 return "Lets you send raw XML to Jabber, or raw commands to MSN, IRC, and TOC." | |
28 " Not very useful except for debugging. Hit 'enter' in the entry to send." | |
29 " Watch the debug window."; | |
30 } | |
31 | |
32 static int goodbye() | |
33 { | |
34 gaim_plugin_unload(me); | |
35 return FALSE; | |
36 } | |
37 | |
38 static void send_it(GtkEntry *entry) | |
39 { | |
40 char *txt; | |
41 if (!gc) return; | |
42 txt = gtk_entry_get_text(entry); | |
43 switch (gc->protocol) { | |
44 case PROTO_TOC: | |
45 { | |
46 int *a = (int *)gc->proto_data; | |
47 unsigned short seqno = htons(a[1]++ & 0xffff); | |
48 unsigned short len = htons(strlen(txt) + 1); | |
49 write(*a, "*\002", 2); | |
50 write(*a, &seqno, 2); | |
51 write(*a, &len, 2); | |
52 write(*a, txt, ntohs(len)); | |
53 debug_printf("TOC C: %s\n", txt); | |
54 } | |
55 break; | |
56 case PROTO_MSN: | |
57 write(*(int *)gc->proto_data, txt, strlen(txt)); | |
58 write(*(int *)gc->proto_data, "\r\n", 2); | |
59 debug_printf("MSN C: %s\n", txt); | |
60 break; | |
61 case PROTO_IRC: | |
62 write(*(int *)gc->proto_data, txt, strlen(txt)); | |
63 write(*(int *)gc->proto_data, "\r\n", 2); | |
64 debug_printf("IRC C: %s\n", txt); | |
65 break; | |
66 case PROTO_JABBER: | |
67 jab_send_raw(*(jconn *)gc->proto_data, txt); | |
68 break; | |
69 } | |
70 gtk_entry_set_text(entry, ""); | |
71 } | |
72 | |
73 static void set_gc(gpointer d, struct gaim_connection *c) | |
74 { | |
75 gc = c; | |
76 } | |
77 | |
78 static void redo_optmenu(struct gaim_connection *arg, gpointer x) | |
79 { | |
80 GtkWidget *menu; | |
81 GSList *g = connections; | |
82 struct gaim_connection *c; | |
83 | |
84 menu = gtk_menu_new(); | |
85 gc = NULL; | |
86 | |
87 while (g) { | |
88 char buf[256]; | |
89 GtkWidget *opt; | |
90 c = (struct gaim_connection *)g->data; | |
91 g = g->next; | |
92 if (x && c == arg) | |
93 continue; | |
94 if (c->protocol != PROTO_TOC && c->protocol != PROTO_MSN && | |
95 c->protocol != PROTO_IRC && c->protocol != PROTO_JABBER) | |
96 continue; | |
97 if (!gc) | |
98 gc = c; | |
99 g_snprintf(buf, sizeof buf, "%s (%s)", c->username, (*c->prpl->name)()); | |
100 opt = gtk_menu_item_new_with_label(buf); | |
101 gtk_signal_connect(GTK_OBJECT(opt), "activate", GTK_SIGNAL_FUNC(set_gc), c); | |
102 gtk_widget_show(opt); | |
103 gtk_menu_append(GTK_MENU(menu), opt); | |
104 } | |
105 | |
106 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); | |
107 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
108 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); | |
109 } | |
110 | |
111 char *gaim_plugin_init(GModule *h) | |
112 { | |
113 GtkWidget *hbox; | |
114 GtkWidget *entry; | |
115 | |
116 me = h; | |
117 | |
118 gaim_signal_connect(h, event_signon, redo_optmenu, NULL); | |
119 gaim_signal_connect(h, event_signoff, redo_optmenu, me); | |
120 | |
121 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
122 gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(goodbye), NULL); | |
123 | |
124 hbox = gtk_hbox_new(FALSE, 0); | |
125 gtk_container_add(GTK_CONTAINER(window), hbox); | |
126 | |
127 optmenu = gtk_option_menu_new(); | |
128 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 5); | |
129 | |
130 redo_optmenu(NULL, NULL); | |
131 | |
132 entry = gtk_entry_new(); | |
133 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); | |
134 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(send_it), NULL); | |
135 | |
136 gtk_widget_show_all(window); | |
137 | |
138 return NULL; | |
139 } | |
140 | |
141 void gaim_plugin_remove() | |
142 { | |
143 if (window) | |
144 gtk_widget_destroy(window); | |
145 window = NULL; | |
146 me = NULL; | |
147 } |