Mercurial > pidgin
changeset 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 |
files | plugins/raw.c |
diffstat | 1 files changed, 46 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/raw.c Wed Aug 06 08:39:56 2003 +0000 +++ b/plugins/raw.c Wed Aug 06 09:01:26 2003 +0000 @@ -4,6 +4,7 @@ #include "debug.h" #include "prpl.h" #include "gtkplugin.h" +#include "gtkutils.h" #ifdef MAX # undef MAX @@ -16,22 +17,31 @@ #define RAW_PLUGIN_ID "gtk-raw" static GtkWidget *window = NULL; -static GtkWidget *optmenu = NULL; -static GaimConnection *gc = NULL; -static GaimPlugin *me = NULL; +static GaimAccount *account = NULL; +static GaimPlugin *my_plugin = NULL; -static int goodbye() +static int +window_closed_cb() { - gaim_plugin_unload(me); + gaim_plugin_unload(my_plugin); + return FALSE; } -static void send_it(GtkEntry *entry) +static void +text_sent_cb(GtkEntry *entry) { const char *txt; - if (!gc) return; + GaimConnection *gc; + + if (account == NULL) + return; + + gc = gaim_account_get_connection(account); + txt = gtk_entry_get_text(entry); - switch (gaim_connection_get_protocol(gc)) { + + switch (gaim_account_get_protocol(account)) { case GAIM_PROTO_TOC: { int *a = (int *)gc->proto_data; @@ -44,6 +54,7 @@ gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); } break; + case GAIM_PROTO_MSN: { MsnSession *session = gc->proto_data; @@ -53,66 +64,29 @@ msn_servconn_write(session->notification_conn, buf, strlen(buf)); } break; + case GAIM_PROTO_IRC: write(*(int *)gc->proto_data, txt, strlen(txt)); write(*(int *)gc->proto_data, "\r\n", 2); gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); break; + case GAIM_PROTO_JABBER: jab_send_raw(*(jconn *)gc->proto_data, txt); break; + + default: + break; } + gtk_entry_set_text(entry, ""); } -static void set_gc(gpointer d, GaimConnection *c) -{ - gc = c; -} - -static void redo_optmenu(GaimConnection *arg, gpointer x) +static void +account_changed_cb(GtkWidget *dropdown, GaimAccount *new_account, + void *user_data) { - GtkWidget *menu; - GList *g = gaim_connections_get_all(); - GaimConnection *c; - GaimAccount *account; - GaimPlugin *plugin; - - menu = gtk_menu_new(); - gc = NULL; - - while (g) { - char buf[256]; - GtkWidget *opt; - c = (GaimConnection *)g->data; - g = g->next; - if (x && c == arg) - continue; - if (gaim_connection_get_protocol(c) != GAIM_PROTO_TOC && - gaim_connection_get_protocol(c) != GAIM_PROTO_MSN && - gaim_connection_get_protocol(c) != GAIM_PROTO_IRC && - gaim_connection_get_protocol(c) != GAIM_PROTO_JABBER) - continue; - if (!gc) - gc = c; - - account = gaim_connection_get_account(c); - - plugin = gaim_find_prpl(gaim_account_get_protocol(account)); - - g_snprintf(buf, sizeof buf, "%s (%s)", - gaim_account_get_username(account), - plugin->info->name); - - opt = gtk_menu_item_new_with_label(buf); - g_signal_connect(G_OBJECT(opt), "activate", G_CALLBACK(set_gc), c); - gtk_widget_show(opt); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); - } - - gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); - gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); + account = new_account; } static gboolean @@ -120,25 +94,30 @@ { GtkWidget *hbox; GtkWidget *entry; + GtkWidget *dropdown; - gaim_signal_connect(plugin, event_signon, redo_optmenu, NULL); - gaim_signal_connect(plugin, event_signoff, redo_optmenu, me); - + /* Setup the window. */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(goodbye), NULL); + G_CALLBACK(window_closed_cb), NULL); - hbox = gtk_hbox_new(FALSE, 0); + /* Main hbox */ + hbox = gtk_hbox_new(FALSE, 6); gtk_container_add(GTK_CONTAINER(window), hbox); - optmenu = gtk_option_menu_new(); - gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 5); + /* Account drop-down menu. */ + dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, + G_CALLBACK(account_changed_cb), NULL); + + gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); - redo_optmenu(NULL, NULL); - + /* Entry box */ entry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); - g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(send_it), NULL); + gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(text_sent_cb), NULL); gtk_widget_show_all(window); @@ -182,7 +161,7 @@ static void init_plugin(GaimPlugin *plugin) { - me = plugin; + my_plugin = plugin; } GAIM_INIT_PLUGIN(raw, init_plugin, info)