comparison src/conversation.c @ 10132:f55a64945e77

[gaim-migrate @ 11196] Patch 1037487, from Evan Schoenberg to show more conversation errors in the actually conversation window instead of in a pop-up error window. Thanks Evan! committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 23 Oct 2004 15:46:57 +0000
parents 9f358a718f38
children a66cf83552dc
comparison
equal deleted inserted replaced
10131:a6c3b931214f 10132:f55a64945e77
117 117
118 static void 118 static void
119 common_send(GaimConversation *conv, const char *message) 119 common_send(GaimConversation *conv, const char *message)
120 { 120 {
121 GaimConversationType type; 121 GaimConversationType type;
122 GaimAccount *account;
122 GaimConnection *gc; 123 GaimConnection *gc;
123 GaimConversationUiOps *ops; 124 GaimConversationUiOps *ops;
124 char *displayed = NULL, *sent = NULL; 125 char *displayed = NULL, *sent = NULL;
125 int plugin_return; 126 int plugin_return;
126 int err = 0; 127 int err = 0;
127 128
128 if (strlen(message) == 0) 129 if (strlen(message) == 0)
129 return; 130 return;
130 131
132 account = gaim_conversation_get_account(conv);
131 gc = gaim_conversation_get_gc(conv); 133 gc = gaim_conversation_get_gc(conv);
132 134
135 g_return_if_fail(account != NULL);
133 g_return_if_fail(gc != NULL); 136 g_return_if_fail(gc != NULL);
134 137
135 type = gaim_conversation_get_type(conv); 138 type = gaim_conversation_get_type(conv);
136 ops = gaim_conversation_get_ui_ops(conv); 139 ops = gaim_conversation_get_ui_ops(conv);
137 140
142 145
143 plugin_return = 146 plugin_return =
144 GPOINTER_TO_INT(gaim_signal_emit_return_1( 147 GPOINTER_TO_INT(gaim_signal_emit_return_1(
145 gaim_conversations_get_handle(), 148 gaim_conversations_get_handle(),
146 (type == GAIM_CONV_IM ? "writing-im-msg" : "writing-chat-msg"), 149 (type == GAIM_CONV_IM ? "writing-im-msg" : "writing-chat-msg"),
147 gaim_conversation_get_account(conv), conv, &displayed)); 150 account, conv, &displayed));
148 151
149 if (displayed == NULL) 152 if (displayed == NULL)
150 return; 153 return;
151 154
152 if (plugin_return) { 155 if (plugin_return) {
154 return; 157 return;
155 } 158 }
156 159
157 gaim_signal_emit(gaim_conversations_get_handle(), 160 gaim_signal_emit(gaim_conversations_get_handle(),
158 (type == GAIM_CONV_IM ? "wrote-im-msg" : "wrote-chat-msg"), 161 (type == GAIM_CONV_IM ? "wrote-im-msg" : "wrote-chat-msg"),
159 gaim_conversation_get_account(conv), conv, displayed); 162 account, conv, displayed);
160 163
161 sent = g_strdup(displayed); 164 sent = g_strdup(displayed);
162 165
163 plugin_return = 166 plugin_return =
164 GPOINTER_TO_INT(gaim_signal_emit_return_1( 167 GPOINTER_TO_INT(gaim_signal_emit_return_1(
165 gaim_conversations_get_handle(), (type == GAIM_CONV_IM ? 168 gaim_conversations_get_handle(), (type == GAIM_CONV_IM ?
166 "displaying-im-msg" : "displaying-chat-msg"), 169 "displaying-im-msg" : "displaying-chat-msg"),
167 gaim_conversation_get_account(conv), conv, &displayed)); 170 account, conv, &displayed));
168 171
169 if (plugin_return) { 172 if (plugin_return) {
170 g_free(displayed); 173 g_free(displayed);
171 displayed = NULL; 174 displayed = NULL;
172 } else { 175 } else {
173 gaim_signal_emit(gaim_conversations_get_handle(), 176 gaim_signal_emit(gaim_conversations_get_handle(),
174 (type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"), 177 (type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"),
175 gaim_conversation_get_account(conv), conv, displayed); 178 account, conv, displayed);
176 } 179 }
177 180
178 if (type == GAIM_CONV_IM) { 181 if (type == GAIM_CONV_IM) {
179 GaimConvIm *im = GAIM_CONV_IM(conv); 182 GaimConvIm *im = GAIM_CONV_IM(conv);
180 183
181 gaim_signal_emit(gaim_conversations_get_handle(), "sending-im-msg", 184 gaim_signal_emit(gaim_conversations_get_handle(), "sending-im-msg",
182 gaim_conversation_get_account(conv), 185 account,
183 gaim_conversation_get_name(conv), &sent); 186 gaim_conversation_get_name(conv), &sent);
184 187
185 if (sent != NULL && sent[0] != '\0') { 188 if (sent != NULL && sent[0] != '\0') {
186 GaimMessageFlags msgflags = GAIM_MESSAGE_SEND; 189 GaimMessageFlags msgflags = GAIM_MESSAGE_SEND;
187 190
197 200
198 if ((err > 0) && (displayed != NULL)) 201 if ((err > 0) && (displayed != NULL))
199 gaim_conv_im_write(im, NULL, displayed, msgflags, time(NULL)); 202 gaim_conv_im_write(im, NULL, displayed, msgflags, time(NULL));
200 203
201 gaim_signal_emit(gaim_conversations_get_handle(), "sent-im-msg", 204 gaim_signal_emit(gaim_conversations_get_handle(), "sent-im-msg",
202 gaim_conversation_get_account(conv), 205 account,
203 gaim_conversation_get_name(conv), sent); 206 gaim_conversation_get_name(conv), sent);
204 } 207 }
205 } 208 }
206 else { 209 else {
207 gaim_signal_emit(gaim_conversations_get_handle(), "sending-chat-msg", 210 gaim_signal_emit(gaim_conversations_get_handle(), "sending-chat-msg",
208 gaim_conversation_get_account(conv), &sent, 211 account, &sent,
209 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv))); 212 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)));
210 213
211 if (sent != NULL && sent[0] != '\0') { 214 if (sent != NULL && sent[0] != '\0') {
212 if (gc && gc->flags & GAIM_CONNECTION_HTML) { 215 if (gc && gc->flags & GAIM_CONNECTION_HTML) {
213 err = serv_chat_send(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), sent); 216 err = serv_chat_send(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), sent);
216 err = serv_chat_send(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), tmp); 219 err = serv_chat_send(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), tmp);
217 g_free(tmp); 220 g_free(tmp);
218 } 221 }
219 222
220 gaim_signal_emit(gaim_conversations_get_handle(), "sent-chat-msg", 223 gaim_signal_emit(gaim_conversations_get_handle(), "sent-chat-msg",
221 gaim_conversation_get_account(conv), sent, 224 account, sent,
222 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv))); 225 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)));
223 } 226 }
224 } 227 }
225 228
226 if (err < 0) { 229 if (err < 0) {
230 const char *who;
231 char *msg;
232
233 who = gaim_conversation_get_name(conv);
234
227 if (err == -E2BIG) { 235 if (err == -E2BIG) {
228 gaim_notify_error(NULL, NULL, 236 msg = _("Unable to send message: The message is too large.");
229 _("Unable to send message. The message is " 237
230 "too large."), NULL); 238 if (!gaim_conv_present_error(who, account, msg)) {
239 msg = g_strdup_printf(_("Unable to send message to %s."), who);
240 gaim_notify_error(gc, NULL, msg, _("The message is too large."));
241 g_free(msg);
242 }
231 } 243 }
232 else if (err == -ENOTCONN) { 244 else if (err == -ENOTCONN) {
233 gaim_debug(GAIM_DEBUG_ERROR, "conversation", 245 gaim_debug(GAIM_DEBUG_ERROR, "conversation",
234 "Not yet connected.\n"); 246 "Not yet connected.\n");
235 } 247 }
236 else { 248 else {
237 gaim_notify_error(NULL, NULL, _("Unable to send message."), NULL); 249 msg = _("Unable to send message.");
250
251 if (!gaim_conv_present_error(who, account, msg)) {
252 msg = g_strdup_printf(_("Unable to send messge to %s."), who);
253 gaim_notify_error(gc, NULL, msg, NULL);
254 g_free(msg);
255 }
238 } 256 }
239 } 257 }
240 258
241 g_free(displayed); 259 g_free(displayed);
242 g_free(sent); 260 g_free(sent);