comparison src/conversation.c @ 3033:1143524a2eaf

[gaim-migrate @ 3046] Laying the ground work for image send. Also an IRC fix. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 12 Mar 2002 17:21:46 +0000
parents 5f6ddad12b1d
children 0f1766887ddd
comparison
equal deleted inserted replaced
3032:d3536105d581 3033:1143524a2eaf
925 925
926 926
927 void send_callback(GtkWidget *widget, struct conversation *c) 927 void send_callback(GtkWidget *widget, struct conversation *c)
928 { 928 {
929 char *buf, *buf2; 929 char *buf, *buf2;
930 int limit; 930 int limit, length=0;
931 int err = 0; 931 int err = 0;
932 932
933 if (!c->gc) 933 if (!c->gc)
934 return; 934 return;
935 935
1031 plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0); 1031 plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0);
1032 if (buffy) { 1032 if (buffy) {
1033 int imflags = 0; 1033 int imflags = 0;
1034 if (c->check && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->check))) 1034 if (c->check && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(c->check)))
1035 imflags = IM_FLAG_CHECKBOX; 1035 imflags = IM_FLAG_CHECKBOX;
1036 err = serv_send_im(c->gc, c->name, buffy, imflags); 1036 if (c->images) {
1037 int id, offset;
1038 char *bigbuf;
1039 GSList *tmplist = c->images;
1040 id = 1;
1041 length = strlen(buffy) + strlen("<BINARY></BINARY>");
1042 bigbuf = g_malloc(length);
1043 g_snprintf(bigbuf, strlen(buffy)+strlen("<BINARY> "), "%s<BINARY>", buffy);
1044 offset = strlen(buffy) + strlen("<BINARY>");
1045 while (tmplist) {
1046 FILE *imgfile;
1047 struct stat st;
1048 char imgtag[1024];
1049 if (stat(tmplist->data, &st) != 0) {
1050 debug_printf("Could not stat %s\n", tmplist->data);
1051 break;
1052 }
1053 g_snprintf(imgtag, sizeof(imgtag),
1054 "<DATA ID=\"%d\" SIZE=\"%d\">",
1055 id, st.st_size);
1056 length = length + strlen(imgtag) + st.st_size;
1057 bigbuf = realloc(bigbuf, length);
1058 if (!(imgfile = fopen(c->images->data, "r"))) {
1059 debug_printf("Could not open %s\n", tmplist->data);
1060 break;
1061 }
1062 g_snprintf(bigbuf + offset, strlen(imgtag) + 1, "%s", imgtag);
1063 offset = offset + strlen(imgtag);
1064 fread(bigbuf + offset, 1, st.st_size, imgfile);
1065 offset = offset + st.st_size;
1066 g_snprintf(bigbuf + offset, strlen("</DATA>"), "</DATA>");
1067 offset= offset + strlen("</DATA>");
1068 id++;
1069 tmplist = tmplist->next;
1070 }
1071
1072 g_snprintf(bigbuf + offset, strlen("</BINARY>"), "</BINARY>");
1073 if (serv_send_im(c->gc, c->name, bigbuf, length, imflags) > 0) {
1074 write_to_conv(c, bigbuf, WFLAG_SEND, NULL, time(NULL), length);
1075 if (c->makesound && (sound_options & OPT_SOUND_SEND))
1076 play_sound(SEND);
1077 if (im_options & OPT_IM_POPDOWN)
1078 gtk_widget_hide(c->window);
1079
1080 }
1081 g_free(bigbuf);
1082 } else {
1083 if (serv_send_im(c->gc, c->name, buffy, -1, imflags) > 0)
1084 write_to_conv(c, buf, WFLAG_SEND, NULL, time(NULL), -1);
1085 if (c->makesound && (sound_options & OPT_SOUND_SEND))
1086 play_sound(SEND);
1087 if (im_options & OPT_IM_POPDOWN)
1088 gtk_widget_hide(c->window);
1089 }
1037 g_free(buffy); 1090 g_free(buffy);
1038 } 1091 }
1039 1092
1040
1041 if (err > 0) {
1042 write_to_conv(c, buf, WFLAG_SEND, NULL, time(NULL), -1);
1043
1044 if (c->makesound && (sound_options & OPT_SOUND_SEND))
1045 play_sound(SEND);
1046
1047 if (im_options & OPT_IM_POPDOWN)
1048 gtk_widget_hide(c->window);
1049 }
1050 } else { 1093 } else {
1051 err = serv_chat_send(c->gc, c->id, buf); 1094 err = serv_chat_send(c->gc, c->id, buf);
1052 1095
1053 /* no sound because we do that when we receive our message */ 1096 /* no sound because we do that when we receive our message */
1054 } 1097 }