src/conversation.c

changeset 2123
4cfdde0aa3f1
parent 2111
34615a640c59
child 2124
7b91bd0ce3ef
equal deleted inserted replaced
2122:95b41c0f938e 2123:4cfdde0aa3f1
27 #include <sys/types.h> 27 #include <sys/types.h>
28 #include <sys/stat.h> 28 #include <sys/stat.h>
29 #include <unistd.h> 29 #include <unistd.h>
30 #include <stdio.h> 30 #include <stdio.h>
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include <errno.h>
32 #include <ctype.h> 33 #include <ctype.h>
33 #include <gtk/gtk.h> 34 #include <gtk/gtk.h>
34 #include "gtkimhtml.h" 35 #include "gtkimhtml.h"
35 #include <gdk/gdkkeysyms.h> 36 #include <gdk/gdkkeysyms.h>
36 #include "convo.h" 37 #include "convo.h"
750 751
751 void send_callback(GtkWidget *widget, struct conversation *c) 752 void send_callback(GtkWidget *widget, struct conversation *c)
752 { 753 {
753 char *buf, *buf2; 754 char *buf, *buf2;
754 int limit; 755 int limit;
756 int err = 0;
755 757
756 if (!c->gc) 758 if (!c->gc)
757 return; 759 return;
758 760
759 buf2 = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, -1); 761 buf2 = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, -1);
760 /* uncomment this if you want no limit on outgoing messages. 762 limit = 32 * 1024; /* you shouldn't be sending more than 32k in your messages. that's a book. */
761 * if you uncomment this, you'll probably get kicked off if
762 * you send one that's too big.
763 limit = strlen(buf2) * 2;
764 */
765 limit = 7985 << 2;
766 buf = g_malloc(limit); 763 buf = g_malloc(limit);
767 g_snprintf(buf, limit, "%s", buf2); 764 g_snprintf(buf, limit, "%s", buf2);
768 g_free(buf2); 765 g_free(buf2);
769 gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1);
770 if (!strlen(buf)) { 766 if (!strlen(buf)) {
771 g_free(buf); 767 g_free(buf);
772 return; 768 return;
773 } 769 }
774 770
856 write_to_conv(c, buf, WFLAG_SEND, NULL, time((time_t)NULL)); 852 write_to_conv(c, buf, WFLAG_SEND, NULL, time((time_t)NULL));
857 853
858 buffy = g_strdup(buf); 854 buffy = g_strdup(buf);
859 plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0); 855 plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0);
860 if (buffy) { 856 if (buffy) {
861 serv_send_im(c->gc, c->name, buffy, 0); 857 err = serv_send_im(c->gc, c->name, buffy, 0);
862 g_free(buffy); 858 g_free(buffy);
863 } 859 }
864 860
865 861
866 if (c->makesound && (sound_options & OPT_SOUND_SEND)) 862 if (c->makesound && (sound_options & OPT_SOUND_SEND))
869 serv_chat_send(c->gc, c->id, buf); 865 serv_chat_send(c->gc, c->id, buf);
870 866
871 /* no sound because we do that when we receive our message */ 867 /* no sound because we do that when we receive our message */
872 } 868 }
873 869
874 if (general_options & OPT_GEN_BACK_ON_IM) {
875 if (awaymessage != NULL) {
876 do_im_back();
877 } else if (c->gc->away) {
878 serv_set_away(c->gc, GAIM_AWAY_CUSTOM, NULL);
879 }
880 }
881
882 g_free(buf2); 870 g_free(buf2);
883 g_free(buf); 871 g_free(buf);
872
873 if (err < 0) {
874 if (err == -E2BIG)
875 do_error_dialog(_("Unable to send message: too large"), _("Message Error"));
876 else
877 do_error_dialog(_("Unable to send message: Unknown reason"), _("Message Error"));
878 } else {
879 gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1);
880
881 if (general_options & OPT_GEN_BACK_ON_IM) {
882 if (awaymessage != NULL) {
883 do_im_back();
884 } else if (c->gc->away) {
885 serv_set_away(c->gc, GAIM_AWAY_CUSTOM, NULL);
886 }
887 }
888 }
884 } 889 }
885 890
886 int entry_key_pressed(GtkWidget *w, GtkWidget *entry) 891 int entry_key_pressed(GtkWidget *w, GtkWidget *entry)
887 { 892 {
888 check_everything(w); 893 check_everything(w);

mercurial