comparison plugins/raw.c @ 6388:9e49daffac97

[gaim-migrate @ 6893] raw.so's code was so ugly.. I just had to rewrite part of it. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 06 Aug 2003 09:01:26 +0000
parents b9c9f4d6f5d8
children c05c02b6bfc8
comparison
equal deleted inserted replaced
6387:b9c9f4d6f5d8 6388:9e49daffac97
2 2
3 #include "conversation.h" 3 #include "conversation.h"
4 #include "debug.h" 4 #include "debug.h"
5 #include "prpl.h" 5 #include "prpl.h"
6 #include "gtkplugin.h" 6 #include "gtkplugin.h"
7 #include "gtkutils.h"
7 8
8 #ifdef MAX 9 #ifdef MAX
9 # undef MAX 10 # undef MAX
10 # undef MIN 11 # undef MIN
11 #endif 12 #endif
14 #include "protocols/msn/session.h" 15 #include "protocols/msn/session.h"
15 16
16 #define RAW_PLUGIN_ID "gtk-raw" 17 #define RAW_PLUGIN_ID "gtk-raw"
17 18
18 static GtkWidget *window = NULL; 19 static GtkWidget *window = NULL;
19 static GtkWidget *optmenu = NULL; 20 static GaimAccount *account = NULL;
20 static GaimConnection *gc = NULL; 21 static GaimPlugin *my_plugin = NULL;
21 static GaimPlugin *me = NULL;
22 22
23 static int goodbye() 23 static int
24 window_closed_cb()
24 { 25 {
25 gaim_plugin_unload(me); 26 gaim_plugin_unload(my_plugin);
27
26 return FALSE; 28 return FALSE;
27 } 29 }
28 30
29 static void send_it(GtkEntry *entry) 31 static void
32 text_sent_cb(GtkEntry *entry)
30 { 33 {
31 const char *txt; 34 const char *txt;
32 if (!gc) return; 35 GaimConnection *gc;
36
37 if (account == NULL)
38 return;
39
40 gc = gaim_account_get_connection(account);
41
33 txt = gtk_entry_get_text(entry); 42 txt = gtk_entry_get_text(entry);
34 switch (gaim_connection_get_protocol(gc)) { 43
44 switch (gaim_account_get_protocol(account)) {
35 case GAIM_PROTO_TOC: 45 case GAIM_PROTO_TOC:
36 { 46 {
37 int *a = (int *)gc->proto_data; 47 int *a = (int *)gc->proto_data;
38 unsigned short seqno = htons(a[1]++ & 0xffff); 48 unsigned short seqno = htons(a[1]++ & 0xffff);
39 unsigned short len = htons(strlen(txt) + 1); 49 unsigned short len = htons(strlen(txt) + 1);
42 write(*a, &len, 2); 52 write(*a, &len, 2);
43 write(*a, txt, ntohs(len)); 53 write(*a, txt, ntohs(len));
44 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); 54 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt);
45 } 55 }
46 break; 56 break;
57
47 case GAIM_PROTO_MSN: 58 case GAIM_PROTO_MSN:
48 { 59 {
49 MsnSession *session = gc->proto_data; 60 MsnSession *session = gc->proto_data;
50 char buf[strlen(txt) + 3]; 61 char buf[strlen(txt) + 3];
51 62
52 g_snprintf(buf, sizeof(buf), "%s\r\n", txt); 63 g_snprintf(buf, sizeof(buf), "%s\r\n", txt);
53 msn_servconn_write(session->notification_conn, buf, strlen(buf)); 64 msn_servconn_write(session->notification_conn, buf, strlen(buf));
54 } 65 }
55 break; 66 break;
67
56 case GAIM_PROTO_IRC: 68 case GAIM_PROTO_IRC:
57 write(*(int *)gc->proto_data, txt, strlen(txt)); 69 write(*(int *)gc->proto_data, txt, strlen(txt));
58 write(*(int *)gc->proto_data, "\r\n", 2); 70 write(*(int *)gc->proto_data, "\r\n", 2);
59 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); 71 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt);
60 break; 72 break;
73
61 case GAIM_PROTO_JABBER: 74 case GAIM_PROTO_JABBER:
62 jab_send_raw(*(jconn *)gc->proto_data, txt); 75 jab_send_raw(*(jconn *)gc->proto_data, txt);
63 break; 76 break;
77
78 default:
79 break;
64 } 80 }
81
65 gtk_entry_set_text(entry, ""); 82 gtk_entry_set_text(entry, "");
66 } 83 }
67 84
68 static void set_gc(gpointer d, GaimConnection *c) 85 static void
86 account_changed_cb(GtkWidget *dropdown, GaimAccount *new_account,
87 void *user_data)
69 { 88 {
70 gc = c; 89 account = new_account;
71 }
72
73 static void redo_optmenu(GaimConnection *arg, gpointer x)
74 {
75 GtkWidget *menu;
76 GList *g = gaim_connections_get_all();
77 GaimConnection *c;
78 GaimAccount *account;
79 GaimPlugin *plugin;
80
81 menu = gtk_menu_new();
82 gc = NULL;
83
84 while (g) {
85 char buf[256];
86 GtkWidget *opt;
87 c = (GaimConnection *)g->data;
88 g = g->next;
89 if (x && c == arg)
90 continue;
91 if (gaim_connection_get_protocol(c) != GAIM_PROTO_TOC &&
92 gaim_connection_get_protocol(c) != GAIM_PROTO_MSN &&
93 gaim_connection_get_protocol(c) != GAIM_PROTO_IRC &&
94 gaim_connection_get_protocol(c) != GAIM_PROTO_JABBER)
95 continue;
96 if (!gc)
97 gc = c;
98
99 account = gaim_connection_get_account(c);
100
101 plugin = gaim_find_prpl(gaim_account_get_protocol(account));
102
103 g_snprintf(buf, sizeof buf, "%s (%s)",
104 gaim_account_get_username(account),
105 plugin->info->name);
106
107 opt = gtk_menu_item_new_with_label(buf);
108 g_signal_connect(G_OBJECT(opt), "activate", G_CALLBACK(set_gc), c);
109 gtk_widget_show(opt);
110 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
111 }
112
113 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu));
114 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
115 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
116 } 90 }
117 91
118 static gboolean 92 static gboolean
119 plugin_load(GaimPlugin *plugin) 93 plugin_load(GaimPlugin *plugin)
120 { 94 {
121 GtkWidget *hbox; 95 GtkWidget *hbox;
122 GtkWidget *entry; 96 GtkWidget *entry;
97 GtkWidget *dropdown;
123 98
124 gaim_signal_connect(plugin, event_signon, redo_optmenu, NULL); 99 /* Setup the window. */
125 gaim_signal_connect(plugin, event_signoff, redo_optmenu, me); 100 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
126 101
127 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
128 g_signal_connect(G_OBJECT(window), "delete_event", 102 g_signal_connect(G_OBJECT(window), "delete_event",
129 G_CALLBACK(goodbye), NULL); 103 G_CALLBACK(window_closed_cb), NULL);
130 104
131 hbox = gtk_hbox_new(FALSE, 0); 105 /* Main hbox */
106 hbox = gtk_hbox_new(FALSE, 6);
132 gtk_container_add(GTK_CONTAINER(window), hbox); 107 gtk_container_add(GTK_CONTAINER(window), hbox);
133 108
134 optmenu = gtk_option_menu_new(); 109 /* Account drop-down menu. */
135 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 5); 110 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE,
111 G_CALLBACK(account_changed_cb), NULL);
136 112
137 redo_optmenu(NULL, NULL); 113 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0);
138 114
115 /* Entry box */
139 entry = gtk_entry_new(); 116 entry = gtk_entry_new();
140 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); 117 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
141 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(send_it), NULL); 118
119 g_signal_connect(G_OBJECT(entry), "activate",
120 G_CALLBACK(text_sent_cb), NULL);
142 121
143 gtk_widget_show_all(window); 122 gtk_widget_show_all(window);
144 123
145 return TRUE; 124 return TRUE;
146 } 125 }
180 }; 159 };
181 160
182 static void 161 static void
183 init_plugin(GaimPlugin *plugin) 162 init_plugin(GaimPlugin *plugin)
184 { 163 {
185 me = plugin; 164 my_plugin = plugin;
186 } 165 }
187 166
188 GAIM_INIT_PLUGIN(raw, init_plugin, info) 167 GAIM_INIT_PLUGIN(raw, init_plugin, info)