15817
|
1 /**
|
|
2 * @file gntconv.c GNT Conversation API
|
|
3 * @ingroup gntui
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25 #include <string.h>
|
|
26
|
|
27 #include <cmds.h>
|
|
28 #include <idle.h>
|
|
29 #include <prefs.h>
|
|
30 #include <util.h>
|
|
31
|
|
32 #include "gntgaim.h"
|
|
33 #include "gntaccount.h"
|
|
34 #include "gntblist.h"
|
|
35 #include "gntconv.h"
|
|
36 #include "gntdebug.h"
|
|
37 #include "gntplugin.h"
|
|
38 #include "gntprefs.h"
|
|
39 #include "gntstatus.h"
|
|
40
|
|
41 #include "gnt.h"
|
|
42 #include "gntbox.h"
|
|
43 #include "gntentry.h"
|
|
44 #include "gnttextview.h"
|
|
45
|
|
46 #define PREF_ROOT "/gaim/gnt/conversations"
|
|
47
|
|
48 #include "config.h"
|
|
49
|
|
50 static void
|
|
51 send_typing_notification(GntWidget *w, FinchConv *ggconv)
|
|
52 {
|
|
53 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
|
|
54 gboolean empty = (!text || !*text);
|
|
55 if (gaim_prefs_get_bool("/gaim/gnt/conversations/notify_typing")) {
|
|
56 GaimConversation *conv = ggconv->active_conv;
|
|
57 GaimConvIm *im = GAIM_CONV_IM(conv);
|
|
58 if (!empty) {
|
|
59 gboolean send = (gaim_conv_im_get_send_typed_timeout(im) == 0);
|
|
60
|
|
61 gaim_conv_im_stop_send_typed_timeout(im);
|
|
62 gaim_conv_im_start_send_typed_timeout(im);
|
|
63 if (send || (gaim_conv_im_get_type_again(im) != 0 &&
|
|
64 time(NULL) > gaim_conv_im_get_type_again(im))) {
|
|
65 unsigned int timeout;
|
|
66 timeout = serv_send_typing(gaim_conversation_get_gc(conv),
|
|
67 gaim_conversation_get_name(conv),
|
|
68 GAIM_TYPING);
|
|
69 gaim_conv_im_set_type_again(im, timeout);
|
|
70 }
|
|
71 } else {
|
|
72 gaim_conv_im_stop_send_typed_timeout(im);
|
|
73
|
|
74 serv_send_typing(gaim_conversation_get_gc(conv),
|
|
75 gaim_conversation_get_name(conv),
|
|
76 GAIM_NOT_TYPING);
|
|
77 }
|
|
78 }
|
|
79 }
|
|
80
|
|
81 static gboolean
|
|
82 entry_key_pressed(GntWidget *w, const char *key, FinchConv *ggconv)
|
|
83 {
|
|
84 if (key[0] == '\r' && key[1] == 0)
|
|
85 {
|
|
86 const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
|
|
87 if (*text == '/')
|
|
88 {
|
|
89 GaimConversation *conv = ggconv->active_conv;
|
|
90 GaimCmdStatus status;
|
|
91 const char *cmdline = text + 1;
|
|
92 char *error = NULL, *escape;
|
|
93
|
|
94 escape = g_markup_escape_text(cmdline, -1);
|
|
95 status = gaim_cmd_do_command(conv, cmdline, escape, &error);
|
|
96 g_free(escape);
|
|
97
|
|
98 switch (status)
|
|
99 {
|
|
100 case GAIM_CMD_STATUS_OK:
|
|
101 break;
|
|
102 case GAIM_CMD_STATUS_NOT_FOUND:
|
|
103 gaim_conversation_write(conv, "", _("No such command."),
|
|
104 GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
105 break;
|
|
106 case GAIM_CMD_STATUS_WRONG_ARGS:
|
|
107 gaim_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments "
|
|
108 "to that command."),
|
|
109 GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
110 break;
|
|
111 case GAIM_CMD_STATUS_FAILED:
|
|
112 gaim_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."),
|
|
113 GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
114 break;
|
|
115 case GAIM_CMD_STATUS_WRONG_TYPE:
|
|
116 if(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
|
|
117 gaim_conversation_write(conv, "", _("That command only works in chats, not IMs."),
|
|
118 GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
119 else
|
|
120 gaim_conversation_write(conv, "", _("That command only works in IMs, not chats."),
|
|
121 GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
122 break;
|
|
123 case GAIM_CMD_STATUS_WRONG_PRPL:
|
|
124 gaim_conversation_write(conv, "", _("That command doesn't work on this protocol."),
|
|
125 GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
126 break;
|
|
127 }
|
|
128 g_free(error);
|
|
129 #if 0
|
|
130 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
|
|
131 _("Commands are not supported yet. Message was NOT sent."),
|
|
132 GNT_TEXT_FLAG_DIM | GNT_TEXT_FLAG_UNDERLINE);
|
|
133 gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv));
|
|
134 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0);
|
|
135 #endif
|
|
136 }
|
|
137 else
|
|
138 {
|
|
139 char *escape = g_markup_escape_text(text, -1);
|
|
140 char *apos = gaim_strreplace(escape, "'", "'");
|
|
141 g_free(escape);
|
|
142 escape = apos;
|
|
143 switch (gaim_conversation_get_type(ggconv->active_conv))
|
|
144 {
|
|
145 case GAIM_CONV_TYPE_IM:
|
|
146 gaim_conv_im_send_with_flags(GAIM_CONV_IM(ggconv->active_conv), escape, GAIM_MESSAGE_SEND);
|
|
147 break;
|
|
148 case GAIM_CONV_TYPE_CHAT:
|
|
149 gaim_conv_chat_send(GAIM_CONV_CHAT(ggconv->active_conv), escape);
|
|
150 break;
|
|
151 default:
|
|
152 g_free(escape);
|
|
153 g_return_val_if_reached(FALSE);
|
|
154 }
|
|
155 g_free(escape);
|
|
156 gaim_idle_touch();
|
|
157 }
|
|
158 gnt_entry_add_to_history(GNT_ENTRY(ggconv->entry), text);
|
|
159 gnt_entry_clear(GNT_ENTRY(ggconv->entry));
|
|
160 return TRUE;
|
|
161 }
|
|
162 else if (key[0] == 27)
|
|
163 {
|
|
164 if (strcmp(key, GNT_KEY_DOWN) == 0)
|
|
165 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 1);
|
|
166 else if (strcmp(key, GNT_KEY_UP) == 0)
|
|
167 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), -1);
|
|
168 else if (strcmp(key, GNT_KEY_PGDOWN) == 0)
|
|
169 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), ggconv->tv->priv.height - 2);
|
|
170 else if (strcmp(key, GNT_KEY_PGUP) == 0)
|
|
171 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), -(ggconv->tv->priv.height - 2));
|
|
172 else
|
|
173 return FALSE;
|
|
174 return TRUE;
|
|
175 }
|
|
176 else
|
|
177 {
|
|
178 }
|
|
179
|
|
180 return FALSE;
|
|
181 }
|
|
182
|
|
183 static void
|
|
184 closing_window(GntWidget *window, FinchConv *ggconv)
|
|
185 {
|
|
186 GList *list = ggconv->list;
|
|
187 ggconv->window = NULL;
|
|
188 while (list) {
|
|
189 GaimConversation *conv = list->data;
|
|
190 list = list->next;
|
|
191 gaim_conversation_destroy(conv);
|
|
192 }
|
|
193 }
|
|
194
|
|
195 static void
|
|
196 size_changed_cb(GntWidget *widget, int width, int height)
|
|
197 {
|
|
198 int w, h;
|
|
199 gnt_widget_get_size(widget, &w, &h);
|
|
200 gaim_prefs_set_int(PREF_ROOT "/size/width", w);
|
|
201 gaim_prefs_set_int(PREF_ROOT "/size/height", h);
|
|
202 }
|
|
203
|
|
204 static void
|
|
205 save_position_cb(GntWidget *w, int x, int y)
|
|
206 {
|
|
207 gaim_prefs_set_int(PREF_ROOT "/position/x", x);
|
|
208 gaim_prefs_set_int(PREF_ROOT "/position/y", y);
|
|
209 }
|
|
210
|
|
211 static GaimConversation *
|
|
212 find_conv_with_contact(GaimConversation *conv)
|
|
213 {
|
|
214 GaimBlistNode *node;
|
|
215 GaimBuddy *buddy = gaim_find_buddy(conv->account, conv->name);
|
|
216 GaimConversation *ret = NULL;
|
|
217
|
|
218 if (!buddy)
|
|
219 return NULL;
|
|
220
|
|
221 for (node = ((GaimBlistNode*)buddy)->parent->child; node; node = node->next) {
|
|
222 if (node == (GaimBlistNode*)buddy)
|
|
223 continue;
|
|
224 if ((ret = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
|
|
225 ((GaimBuddy*)node)->name, ((GaimBuddy*)node)->account)) != NULL)
|
|
226 break;
|
|
227 }
|
|
228 return ret;
|
|
229 }
|
|
230
|
|
231 static char *
|
|
232 get_conversation_title(GaimConversation *conv, GaimAccount *account)
|
|
233 {
|
|
234 return g_strdup_printf(_("%s (%s -- %s)"), gaim_conversation_get_title(conv),
|
|
235 gaim_account_get_username(account), gaim_account_get_protocol_name(account));
|
|
236 }
|
|
237
|
|
238 static void
|
|
239 update_buddy_typing(GaimAccount *account, const char *who, gpointer null)
|
|
240 {
|
|
241 GaimConversation *conv;
|
|
242 FinchConv *ggc;
|
|
243 GaimConvIm *im = NULL;
|
|
244 char *title, *str;
|
|
245
|
|
246 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, who, account);
|
|
247
|
|
248 if (!conv)
|
|
249 return;
|
|
250
|
|
251 im = GAIM_CONV_IM(conv);
|
|
252 ggc = conv->ui_data;
|
|
253
|
|
254 if (gaim_conv_im_get_typing_state(im) == GAIM_TYPING) {
|
|
255 int scroll;
|
|
256 str = get_conversation_title(conv, account);
|
|
257 title = g_strdup_printf(_("%s [%s]"), str,
|
|
258 gnt_ascii_only() ? "T" : "\342\243\277");
|
|
259 g_free(str);
|
|
260
|
|
261 scroll = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc->tv));
|
|
262 str = g_strdup_printf(_("\n%s is typing..."), gaim_conversation_get_name(conv));
|
|
263 /* Updating is a little buggy. So just remove and add a new one */
|
|
264 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE);
|
|
265 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc->tv),
|
|
266 str, GNT_TEXT_FLAG_DIM, "typing");
|
|
267 g_free(str);
|
|
268 if (scroll <= 1)
|
|
269 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc->tv), 0);
|
|
270 } else {
|
|
271 title = get_conversation_title(conv, account);
|
|
272 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE);
|
|
273 }
|
|
274 gnt_screen_rename_widget(ggc->window, title);
|
|
275 g_free(title);
|
|
276 }
|
|
277
|
|
278 static gpointer
|
|
279 finch_conv_get_handle()
|
|
280 {
|
|
281 static int handle;
|
|
282 return &handle;
|
|
283 }
|
|
284
|
|
285 static void
|
|
286 finch_create_conversation(GaimConversation *conv)
|
|
287 {
|
|
288 FinchConv *ggc = conv->ui_data;
|
|
289 char *title;
|
|
290 GaimConversationType type;
|
|
291 GaimConversation *cc;
|
|
292 GaimAccount *account;
|
|
293
|
|
294 if (ggc)
|
|
295 return;
|
|
296
|
|
297 cc = find_conv_with_contact(conv);
|
|
298 if (cc && cc->ui_data)
|
|
299 ggc = cc->ui_data;
|
|
300 else
|
|
301 ggc = g_new0(FinchConv, 1);
|
|
302
|
|
303 ggc->list = g_list_prepend(ggc->list, conv);
|
|
304 ggc->active_conv = conv;
|
|
305 conv->ui_data = ggc;
|
|
306
|
|
307 if (cc && cc->ui_data) {
|
|
308 finch_conversation_set_active(conv);
|
|
309 return;
|
|
310 }
|
|
311
|
|
312 account = gaim_conversation_get_account(conv);
|
|
313 type = gaim_conversation_get_type(conv);
|
|
314 title = get_conversation_title(conv, account);
|
|
315
|
|
316 ggc->window = gnt_box_new(FALSE, TRUE);
|
|
317 gnt_box_set_title(GNT_BOX(ggc->window), title);
|
|
318 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE);
|
|
319 gnt_box_set_pad(GNT_BOX(ggc->window), 0);
|
|
320 gnt_widget_set_name(ggc->window, "conversation-window");
|
|
321
|
|
322 ggc->tv = gnt_text_view_new();
|
|
323 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv);
|
|
324 gnt_widget_set_name(ggc->tv, "conversation-window-textview");
|
|
325 gnt_widget_set_size(ggc->tv, gaim_prefs_get_int(PREF_ROOT "/size/width"),
|
|
326 gaim_prefs_get_int(PREF_ROOT "/size/height"));
|
|
327
|
|
328 ggc->entry = gnt_entry_new(NULL);
|
|
329 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry);
|
|
330 gnt_widget_set_name(ggc->entry, "conversation-window-entry");
|
|
331 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1);
|
|
332 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE);
|
|
333 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE);
|
|
334
|
|
335 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc);
|
|
336 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc);
|
|
337
|
|
338 gnt_widget_set_position(ggc->window, gaim_prefs_get_int(PREF_ROOT "/position/x"),
|
|
339 gaim_prefs_get_int(PREF_ROOT "/position/y"));
|
|
340 gnt_widget_show(ggc->window);
|
|
341
|
|
342 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL);
|
|
343 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL);
|
|
344
|
|
345 if (type == GAIM_CONV_TYPE_IM) {
|
|
346 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc);
|
|
347 gaim_signal_connect(gaim_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(),
|
|
348 GAIM_CALLBACK(update_buddy_typing), NULL);
|
|
349 gaim_signal_connect(gaim_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(),
|
|
350 GAIM_CALLBACK(update_buddy_typing), NULL);
|
|
351 }
|
|
352
|
|
353 g_free(title);
|
|
354 }
|
|
355
|
|
356 static void
|
|
357 finch_destroy_conversation(GaimConversation *conv)
|
|
358 {
|
|
359 /* do stuff here */
|
|
360 FinchConv *ggc = conv->ui_data;
|
|
361 ggc->list = g_list_remove(ggc->list, conv);
|
|
362 if (ggc->list && conv == ggc->active_conv)
|
|
363 ggc->active_conv = ggc->list->data;
|
|
364
|
|
365 if (ggc->list == NULL) {
|
|
366 gnt_widget_destroy(ggc->window);
|
|
367 g_free(ggc);
|
|
368 }
|
|
369 }
|
|
370
|
|
371 static void
|
|
372 finch_write_common(GaimConversation *conv, const char *who, const char *message,
|
|
373 GaimMessageFlags flags, time_t mtime)
|
|
374 {
|
|
375 FinchConv *ggconv = conv->ui_data;
|
|
376 char *strip, *newline;
|
|
377 GntTextFormatFlags fl = 0;
|
|
378 int pos;
|
|
379 gboolean notify;
|
|
380
|
|
381 g_return_if_fail(ggconv != NULL);
|
|
382
|
|
383 if (ggconv->active_conv != conv) {
|
|
384 if (flags & (GAIM_MESSAGE_SEND | GAIM_MESSAGE_RECV))
|
|
385 finch_conversation_set_active(conv);
|
|
386 else
|
|
387 return;
|
|
388 }
|
|
389
|
|
390 pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv->tv));
|
|
391
|
|
392 notify = !!gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv->tv), "typing", NULL, TRUE);
|
|
393 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), "\n", GNT_TEXT_FLAG_NORMAL);
|
|
394
|
|
395 /* Unnecessary to print the timestamp for delayed message */
|
|
396 if (!(flags & GAIM_MESSAGE_DELAYED) &&
|
|
397 gaim_prefs_get_bool("/gaim/gnt/conversations/timestamps"))
|
|
398 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
|
|
399 gaim_utf8_strftime("(%H:%M:%S) ", localtime(&mtime)), GNT_TEXT_FLAG_DIM);
|
|
400
|
|
401 if (flags & GAIM_MESSAGE_AUTO_RESP)
|
|
402 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
|
|
403 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD);
|
|
404
|
|
405 if (who && *who && (flags & (GAIM_MESSAGE_SEND | GAIM_MESSAGE_RECV)))
|
|
406 {
|
|
407 char * name = NULL;
|
|
408
|
|
409 if (gaim_message_meify((char*)message, -1))
|
|
410 name = g_strdup_printf("*** %s ", who);
|
|
411 else
|
|
412 name = g_strdup_printf("%s: ", who);
|
|
413
|
|
414 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
|
|
415 name, GNT_TEXT_FLAG_BOLD);
|
|
416 g_free(name);
|
|
417 }
|
|
418 else
|
|
419 fl = GNT_TEXT_FLAG_DIM;
|
|
420
|
|
421 if (flags & GAIM_MESSAGE_ERROR)
|
|
422 fl |= GNT_TEXT_FLAG_BOLD;
|
|
423 if (flags & GAIM_MESSAGE_NICK)
|
|
424 fl |= GNT_TEXT_FLAG_UNDERLINE;
|
|
425
|
|
426 /* XXX: Remove this workaround when textview can parse messages. */
|
|
427 newline = gaim_strdup_withhtml(message);
|
|
428 strip = gaim_markup_strip_html(newline);
|
|
429 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
|
|
430 strip, fl);
|
|
431
|
|
432 g_free(newline);
|
|
433 g_free(strip);
|
|
434
|
|
435 if (notify) {
|
|
436 strip = g_strdup_printf(_("\n%s is typing..."), gaim_conversation_get_name(conv));
|
|
437 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv->tv),
|
|
438 strip, GNT_TEXT_FLAG_DIM, "typing");
|
|
439 g_free(strip);
|
|
440 }
|
|
441
|
|
442 if (pos <= 1)
|
|
443 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0);
|
|
444
|
|
445 if (flags & (GAIM_MESSAGE_RECV | GAIM_MESSAGE_NICK | GAIM_MESSAGE_ERROR))
|
|
446 gnt_widget_set_urgent(ggconv->tv);
|
|
447 }
|
|
448
|
|
449 static void
|
|
450 finch_write_chat(GaimConversation *conv, const char *who, const char *message,
|
|
451 GaimMessageFlags flags, time_t mtime)
|
|
452 {
|
|
453 gaim_conversation_write(conv, who, message, flags, mtime);
|
|
454 }
|
|
455
|
|
456 static void
|
|
457 finch_write_im(GaimConversation *conv, const char *who, const char *message,
|
|
458 GaimMessageFlags flags, time_t mtime)
|
|
459 {
|
|
460 GaimAccount *account = gaim_conversation_get_account(conv);
|
|
461 if (flags & GAIM_MESSAGE_SEND)
|
|
462 {
|
|
463 who = gaim_connection_get_display_name(gaim_account_get_connection(account));
|
|
464 if (!who)
|
|
465 who = gaim_account_get_alias(account);
|
|
466 if (!who)
|
|
467 who = gaim_account_get_username(account);
|
|
468 }
|
|
469 else if (flags & GAIM_MESSAGE_RECV)
|
|
470 {
|
|
471 GaimBuddy *buddy;
|
|
472 who = gaim_conversation_get_name(conv);
|
|
473 buddy = gaim_find_buddy(account, who);
|
|
474 if (buddy)
|
|
475 who = gaim_buddy_get_contact_alias(buddy);
|
|
476 }
|
|
477
|
|
478 gaim_conversation_write(conv, who, message, flags, mtime);
|
|
479 }
|
|
480
|
|
481 static void
|
|
482 finch_write_conv(GaimConversation *conv, const char *who, const char *alias,
|
|
483 const char *message, GaimMessageFlags flags, time_t mtime)
|
|
484 {
|
|
485 const char *name;
|
|
486 if (alias && *alias)
|
|
487 name = alias;
|
|
488 else if (who && *who)
|
|
489 name = who;
|
|
490 else
|
|
491 name = NULL;
|
|
492
|
|
493 finch_write_common(conv, name, message, flags, mtime);
|
|
494 }
|
|
495
|
|
496 static void
|
|
497 finch_chat_add_users(GaimConversation *conv, GList *users, gboolean new_arrivals)
|
|
498 {
|
|
499 FinchConv *ggc = conv->ui_data;
|
|
500 GntEntry *entry = GNT_ENTRY(ggc->entry);
|
|
501
|
|
502 if (!new_arrivals)
|
|
503 {
|
|
504 /* Print the list of users in the room */
|
|
505 GString *string = g_string_new(_("List of users:\n"));
|
|
506 GList *iter;
|
|
507
|
|
508 for (iter = users; iter; iter = iter->next)
|
|
509 {
|
|
510 GaimConvChatBuddy *cbuddy = iter->data;
|
|
511 char *str;
|
|
512
|
|
513 if ((str = cbuddy->alias) == NULL)
|
|
514 str = cbuddy->name;
|
|
515 g_string_append_printf(string, "[ %s ]", str);
|
|
516 }
|
|
517
|
|
518 gaim_conversation_write(conv, NULL, string->str,
|
|
519 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
520 g_string_free(string, TRUE);
|
|
521 }
|
|
522
|
|
523 for (; users; users = users->next)
|
|
524 {
|
|
525 GaimConvChatBuddy *cbuddy = users->data;
|
|
526 gnt_entry_add_suggest(entry, cbuddy->name);
|
|
527 gnt_entry_add_suggest(entry, cbuddy->alias);
|
|
528 }
|
|
529 }
|
|
530
|
|
531 static void
|
|
532 finch_chat_rename_user(GaimConversation *conv, const char *old, const char *new_n, const char *new_a)
|
|
533 {
|
|
534 /* Update the name for string completion */
|
|
535 FinchConv *ggc = conv->ui_data;
|
|
536 GntEntry *entry = GNT_ENTRY(ggc->entry);
|
|
537 gnt_entry_remove_suggest(entry, old);
|
|
538 gnt_entry_add_suggest(entry, new_n);
|
|
539 gnt_entry_add_suggest(entry, new_a);
|
|
540 }
|
|
541
|
|
542 static void
|
|
543 finch_chat_remove_user(GaimConversation *conv, GList *list)
|
|
544 {
|
|
545 /* Remove the name from string completion */
|
|
546 FinchConv *ggc = conv->ui_data;
|
|
547 GntEntry *entry = GNT_ENTRY(ggc->entry);
|
|
548 for (; list; list = list->next)
|
|
549 gnt_entry_remove_suggest(entry, list->data);
|
|
550 }
|
|
551
|
|
552 static void
|
|
553 finch_chat_update_user(GaimConversation *conv, const char *user)
|
|
554 {
|
|
555 }
|
|
556
|
|
557 static GaimConversationUiOps conv_ui_ops =
|
|
558 {
|
|
559 .create_conversation = finch_create_conversation,
|
|
560 .destroy_conversation = finch_destroy_conversation,
|
|
561 .write_chat = finch_write_chat,
|
|
562 .write_im = finch_write_im,
|
|
563 .write_conv = finch_write_conv,
|
|
564 .chat_add_users = finch_chat_add_users,
|
|
565 .chat_rename_user = finch_chat_rename_user,
|
|
566 .chat_remove_users = finch_chat_remove_user,
|
|
567 .chat_update_user = finch_chat_update_user,
|
|
568 .present = NULL,
|
|
569 .has_focus = NULL,
|
|
570 .custom_smiley_add = NULL,
|
|
571 .custom_smiley_write = NULL,
|
|
572 .custom_smiley_close = NULL
|
|
573 };
|
|
574
|
|
575 GaimConversationUiOps *finch_conv_get_ui_ops()
|
|
576 {
|
|
577 return &conv_ui_ops;
|
|
578 }
|
|
579
|
|
580 /* Xerox */
|
|
581 static GaimCmdRet
|
|
582 say_command_cb(GaimConversation *conv,
|
|
583 const char *cmd, char **args, char **error, void *data)
|
|
584 {
|
|
585 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
|
|
586 gaim_conv_im_send(GAIM_CONV_IM(conv), args[0]);
|
|
587 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT)
|
|
588 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), args[0]);
|
|
589
|
|
590 return GAIM_CMD_RET_OK;
|
|
591 }
|
|
592
|
|
593 /* Xerox */
|
|
594 static GaimCmdRet
|
|
595 me_command_cb(GaimConversation *conv,
|
|
596 const char *cmd, char **args, char **error, void *data)
|
|
597 {
|
|
598 char *tmp;
|
|
599
|
|
600 tmp = g_strdup_printf("/me %s", args[0]);
|
|
601
|
|
602 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
|
|
603 gaim_conv_im_send(GAIM_CONV_IM(conv), tmp);
|
|
604 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT)
|
|
605 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), tmp);
|
|
606
|
|
607 g_free(tmp);
|
|
608 return GAIM_CMD_RET_OK;
|
|
609 }
|
|
610
|
|
611 /* Xerox */
|
|
612 static GaimCmdRet
|
|
613 debug_command_cb(GaimConversation *conv,
|
|
614 const char *cmd, char **args, char **error, void *data)
|
|
615 {
|
|
616 char *tmp, *markup;
|
|
617 GaimCmdStatus status;
|
|
618
|
|
619 if (!g_ascii_strcasecmp(args[0], "version")) {
|
|
620 tmp = g_strdup_printf("me is using %s.", VERSION);
|
|
621 markup = g_markup_escape_text(tmp, -1);
|
|
622
|
|
623 status = gaim_cmd_do_command(conv, tmp, markup, error);
|
|
624
|
|
625 g_free(tmp);
|
|
626 g_free(markup);
|
|
627 return status;
|
|
628 } else {
|
|
629 gaim_conversation_write(conv, NULL, _("Supported debug options are: version"),
|
|
630 GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL));
|
|
631 return GAIM_CMD_STATUS_OK;
|
|
632 }
|
|
633 }
|
|
634
|
|
635 /* Xerox */
|
|
636 static GaimCmdRet
|
|
637 clear_command_cb(GaimConversation *conv,
|
|
638 const char *cmd, char **args, char **error, void *data)
|
|
639 {
|
|
640 FinchConv *ggconv = conv->ui_data;
|
|
641 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv));
|
|
642 return GAIM_CMD_STATUS_OK;
|
|
643 }
|
|
644
|
|
645 /* Xerox */
|
|
646 static GaimCmdRet
|
|
647 help_command_cb(GaimConversation *conv,
|
|
648 const char *cmd, char **args, char **error, void *data)
|
|
649 {
|
|
650 GList *l, *text;
|
|
651 GString *s;
|
|
652
|
|
653 if (args[0] != NULL) {
|
|
654 s = g_string_new("");
|
|
655 text = gaim_cmd_help(conv, args[0]);
|
|
656
|
|
657 if (text) {
|
|
658 for (l = text; l; l = l->next)
|
|
659 if (l->next)
|
|
660 g_string_append_printf(s, "%s\n", (char *)l->data);
|
|
661 else
|
|
662 g_string_append_printf(s, "%s", (char *)l->data);
|
|
663 } else {
|
|
664 g_string_append(s, _("No such command (in this context)."));
|
|
665 }
|
|
666 } else {
|
|
667 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n"
|
|
668 "The following commands are available in this context:\n"));
|
|
669
|
|
670 text = gaim_cmd_list(conv);
|
|
671 for (l = text; l; l = l->next)
|
|
672 if (l->next)
|
|
673 g_string_append_printf(s, "%s, ", (char *)l->data);
|
|
674 else
|
|
675 g_string_append_printf(s, "%s.", (char *)l->data);
|
|
676 g_list_free(text);
|
|
677 }
|
|
678
|
|
679 gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL));
|
|
680 g_string_free(s, TRUE);
|
|
681
|
|
682 return GAIM_CMD_STATUS_OK;
|
|
683 }
|
|
684
|
|
685 static GaimCmdRet
|
|
686 cmd_show_window(GaimConversation *conv, const char *cmd, char **args, char **error, gpointer data)
|
|
687 {
|
|
688 void (*callback)() = data;
|
|
689 callback();
|
|
690 return GAIM_CMD_STATUS_OK;
|
|
691 }
|
|
692
|
|
693 void finch_conversation_init()
|
|
694 {
|
|
695 gaim_prefs_add_none(PREF_ROOT);
|
|
696 gaim_prefs_add_none(PREF_ROOT "/size");
|
|
697 gaim_prefs_add_int(PREF_ROOT "/size/width", 70);
|
|
698 gaim_prefs_add_int(PREF_ROOT "/size/height", 20);
|
|
699 gaim_prefs_add_none(PREF_ROOT "/position");
|
|
700 gaim_prefs_add_int(PREF_ROOT "/position/x", 0);
|
|
701 gaim_prefs_add_int(PREF_ROOT "/position/y", 0);
|
|
702
|
|
703 /* Xerox the commands */
|
|
704 gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT,
|
|
705 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
706 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL);
|
|
707 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT,
|
|
708 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
709 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL);
|
|
710 gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT,
|
|
711 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
712 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL);
|
|
713 gaim_cmd_register("clear", "", GAIM_CMD_P_DEFAULT,
|
|
714 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
715 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL);
|
|
716 gaim_cmd_register("help", "w", GAIM_CMD_P_DEFAULT,
|
|
717 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, NULL,
|
|
718 help_command_cb, _("help <command>: Help on a specific command."), NULL);
|
|
719
|
|
720 /* Now some commands to bring up some other windows */
|
|
721 gaim_cmd_register("plugins", "", GAIM_CMD_P_DEFAULT,
|
|
722 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
723 cmd_show_window, _("plugins: Show the plugins window."), finch_plugins_show_all);
|
|
724 gaim_cmd_register("buddylist", "", GAIM_CMD_P_DEFAULT,
|
|
725 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
726 cmd_show_window, _("buddylist: Show the buddylist."), finch_blist_show);
|
|
727 gaim_cmd_register("accounts", "", GAIM_CMD_P_DEFAULT,
|
|
728 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
729 cmd_show_window, _("accounts: Show the accounts window."), finch_accounts_show_all);
|
|
730 gaim_cmd_register("debugwin", "", GAIM_CMD_P_DEFAULT,
|
|
731 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
732 cmd_show_window, _("debugwin: Show the debug window."), finch_debug_window_show);
|
|
733 gaim_cmd_register("prefs", "", GAIM_CMD_P_DEFAULT,
|
|
734 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
735 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all);
|
|
736 gaim_cmd_register("status", "", GAIM_CMD_P_DEFAULT,
|
|
737 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL,
|
|
738 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all);
|
|
739 }
|
|
740
|
|
741 void finch_conversation_uninit()
|
|
742 {
|
|
743 }
|
|
744
|
|
745 void finch_conversation_set_active(GaimConversation *conv)
|
|
746 {
|
|
747 FinchConv *ggconv = conv->ui_data;
|
|
748 GaimAccount *account;
|
|
749 char *title;
|
|
750
|
|
751 g_return_if_fail(ggconv);
|
|
752 g_return_if_fail(g_list_find(ggconv->list, conv));
|
|
753
|
|
754 ggconv->active_conv = conv;
|
|
755 account = gaim_conversation_get_account(conv);
|
|
756 title = get_conversation_title(conv, account);
|
|
757 gnt_screen_rename_widget(ggconv->window, title);
|
|
758 g_free(title);
|
|
759 }
|
|
760
|