Mercurial > pidgin
annotate finch/gntconv.c @ 16490:15f79c0cd0b9
Finally fix SILC fully, now that i have HAVE_SILCMIME_H defined.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 27 Apr 2007 04:04:04 +0000 |
parents | 4999bbc52881 |
children | 373466e3151a |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntconv.c GNT Conversation API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
16128
diff
changeset
|
3 * @ingroup finch |
15817 | 4 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 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 | |
15822 | 32 #include "finch.h" |
15817 | 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 | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
46 #define PREF_ROOT "/finch/conversations" |
15817 | 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); | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
55 if (purple_prefs_get_bool("/finch/conversations/notify_typing")) { |
15822 | 56 PurpleConversation *conv = ggconv->active_conv; |
57 PurpleConvIm *im = PURPLE_CONV_IM(conv); | |
15817 | 58 if (!empty) { |
15822 | 59 gboolean send = (purple_conv_im_get_send_typed_timeout(im) == 0); |
15817 | 60 |
15822 | 61 purple_conv_im_stop_send_typed_timeout(im); |
62 purple_conv_im_start_send_typed_timeout(im); | |
63 if (send || (purple_conv_im_get_type_again(im) != 0 && | |
64 time(NULL) > purple_conv_im_get_type_again(im))) { | |
15817 | 65 unsigned int timeout; |
15822 | 66 timeout = serv_send_typing(purple_conversation_get_gc(conv), |
67 purple_conversation_get_name(conv), | |
68 PURPLE_TYPING); | |
69 purple_conv_im_set_type_again(im, timeout); | |
15817 | 70 } |
71 } else { | |
15822 | 72 purple_conv_im_stop_send_typed_timeout(im); |
15817 | 73 |
15822 | 74 serv_send_typing(purple_conversation_get_gc(conv), |
75 purple_conversation_get_name(conv), | |
76 PURPLE_NOT_TYPING); | |
15817 | 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 { | |
15822 | 89 PurpleConversation *conv = ggconv->active_conv; |
90 PurpleCmdStatus status; | |
15817 | 91 const char *cmdline = text + 1; |
92 char *error = NULL, *escape; | |
93 | |
94 escape = g_markup_escape_text(cmdline, -1); | |
15822 | 95 status = purple_cmd_do_command(conv, cmdline, escape, &error); |
15817 | 96 g_free(escape); |
97 | |
98 switch (status) | |
99 { | |
15822 | 100 case PURPLE_CMD_STATUS_OK: |
15817 | 101 break; |
15822 | 102 case PURPLE_CMD_STATUS_NOT_FOUND: |
103 purple_conversation_write(conv, "", _("No such command."), | |
104 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 105 break; |
15822 | 106 case PURPLE_CMD_STATUS_WRONG_ARGS: |
107 purple_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " | |
15817 | 108 "to that command."), |
15822 | 109 PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15817 | 110 break; |
15822 | 111 case PURPLE_CMD_STATUS_FAILED: |
112 purple_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), | |
113 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 114 break; |
15822 | 115 case PURPLE_CMD_STATUS_WRONG_TYPE: |
116 if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) | |
117 purple_conversation_write(conv, "", _("That command only works in chats, not IMs."), | |
118 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 119 else |
15822 | 120 purple_conversation_write(conv, "", _("That command only works in IMs, not chats."), |
121 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 122 break; |
15822 | 123 case PURPLE_CMD_STATUS_WRONG_PRPL: |
124 purple_conversation_write(conv, "", _("That command doesn't work on this protocol."), | |
125 PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
15817 | 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); | |
15822 | 140 char *apos = purple_strreplace(escape, "'", "'"); |
15817 | 141 g_free(escape); |
142 escape = apos; | |
15822 | 143 switch (purple_conversation_get_type(ggconv->active_conv)) |
15817 | 144 { |
15822 | 145 case PURPLE_CONV_TYPE_IM: |
146 purple_conv_im_send_with_flags(PURPLE_CONV_IM(ggconv->active_conv), escape, PURPLE_MESSAGE_SEND); | |
15817 | 147 break; |
15822 | 148 case PURPLE_CONV_TYPE_CHAT: |
149 purple_conv_chat_send(PURPLE_CONV_CHAT(ggconv->active_conv), escape); | |
15817 | 150 break; |
151 default: | |
152 g_free(escape); | |
153 g_return_val_if_reached(FALSE); | |
154 } | |
155 g_free(escape); | |
15822 | 156 purple_idle_touch(); |
15817 | 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 | |
163 return FALSE; | |
164 } | |
165 | |
166 static void | |
167 closing_window(GntWidget *window, FinchConv *ggconv) | |
168 { | |
169 GList *list = ggconv->list; | |
170 ggconv->window = NULL; | |
171 while (list) { | |
15822 | 172 PurpleConversation *conv = list->data; |
15817 | 173 list = list->next; |
15822 | 174 purple_conversation_destroy(conv); |
15817 | 175 } |
176 } | |
177 | |
178 static void | |
179 size_changed_cb(GntWidget *widget, int width, int height) | |
180 { | |
181 int w, h; | |
182 gnt_widget_get_size(widget, &w, &h); | |
15822 | 183 purple_prefs_set_int(PREF_ROOT "/size/width", w); |
184 purple_prefs_set_int(PREF_ROOT "/size/height", h); | |
15817 | 185 } |
186 | |
187 static void | |
188 save_position_cb(GntWidget *w, int x, int y) | |
189 { | |
15822 | 190 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
191 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15817 | 192 } |
193 | |
15822 | 194 static PurpleConversation * |
195 find_conv_with_contact(PurpleConversation *conv) | |
15817 | 196 { |
15822 | 197 PurpleBlistNode *node; |
198 PurpleBuddy *buddy = purple_find_buddy(conv->account, conv->name); | |
199 PurpleConversation *ret = NULL; | |
15817 | 200 |
201 if (!buddy) | |
202 return NULL; | |
203 | |
15822 | 204 for (node = ((PurpleBlistNode*)buddy)->parent->child; node; node = node->next) { |
205 if (node == (PurpleBlistNode*)buddy) | |
15817 | 206 continue; |
15822 | 207 if ((ret = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
208 ((PurpleBuddy*)node)->name, ((PurpleBuddy*)node)->account)) != NULL) | |
15817 | 209 break; |
210 } | |
211 return ret; | |
212 } | |
213 | |
214 static char * | |
15822 | 215 get_conversation_title(PurpleConversation *conv, PurpleAccount *account) |
15817 | 216 { |
15822 | 217 return g_strdup_printf(_("%s (%s -- %s)"), purple_conversation_get_title(conv), |
218 purple_account_get_username(account), purple_account_get_protocol_name(account)); | |
15817 | 219 } |
220 | |
221 static void | |
15822 | 222 update_buddy_typing(PurpleAccount *account, const char *who, gpointer null) |
15817 | 223 { |
15822 | 224 PurpleConversation *conv; |
15817 | 225 FinchConv *ggc; |
15822 | 226 PurpleConvIm *im = NULL; |
15817 | 227 char *title, *str; |
228 | |
15822 | 229 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account); |
15817 | 230 |
231 if (!conv) | |
232 return; | |
233 | |
15822 | 234 im = PURPLE_CONV_IM(conv); |
15817 | 235 ggc = conv->ui_data; |
236 | |
15822 | 237 if (purple_conv_im_get_typing_state(im) == PURPLE_TYPING) { |
15817 | 238 int scroll; |
239 str = get_conversation_title(conv, account); | |
240 title = g_strdup_printf(_("%s [%s]"), str, | |
241 gnt_ascii_only() ? "T" : "\342\243\277"); | |
242 g_free(str); | |
243 | |
244 scroll = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggc->tv)); | |
15822 | 245 str = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15817 | 246 /* Updating is a little buggy. So just remove and add a new one */ |
247 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE); | |
248 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggc->tv), | |
249 str, GNT_TEXT_FLAG_DIM, "typing"); | |
250 g_free(str); | |
251 if (scroll <= 1) | |
252 gnt_text_view_scroll(GNT_TEXT_VIEW(ggc->tv), 0); | |
253 } else { | |
254 title = get_conversation_title(conv, account); | |
255 gnt_text_view_tag_change(GNT_TEXT_VIEW(ggc->tv), "typing", NULL, TRUE); | |
256 } | |
257 gnt_screen_rename_widget(ggc->window, title); | |
258 g_free(title); | |
259 } | |
260 | |
261 static gpointer | |
262 finch_conv_get_handle() | |
263 { | |
264 static int handle; | |
265 return &handle; | |
266 } | |
267 | |
268 static void | |
15822 | 269 finch_create_conversation(PurpleConversation *conv) |
15817 | 270 { |
271 FinchConv *ggc = conv->ui_data; | |
272 char *title; | |
15822 | 273 PurpleConversationType type; |
274 PurpleConversation *cc; | |
275 PurpleAccount *account; | |
15817 | 276 |
277 if (ggc) | |
278 return; | |
279 | |
280 cc = find_conv_with_contact(conv); | |
281 if (cc && cc->ui_data) | |
282 ggc = cc->ui_data; | |
283 else | |
284 ggc = g_new0(FinchConv, 1); | |
285 | |
286 ggc->list = g_list_prepend(ggc->list, conv); | |
287 ggc->active_conv = conv; | |
288 conv->ui_data = ggc; | |
289 | |
290 if (cc && cc->ui_data) { | |
291 finch_conversation_set_active(conv); | |
292 return; | |
293 } | |
294 | |
15822 | 295 account = purple_conversation_get_account(conv); |
296 type = purple_conversation_get_type(conv); | |
15817 | 297 title = get_conversation_title(conv, account); |
298 | |
299 ggc->window = gnt_box_new(FALSE, TRUE); | |
300 gnt_box_set_title(GNT_BOX(ggc->window), title); | |
301 gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE); | |
302 gnt_box_set_pad(GNT_BOX(ggc->window), 0); | |
303 gnt_widget_set_name(ggc->window, "conversation-window"); | |
304 | |
305 ggc->tv = gnt_text_view_new(); | |
306 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv); | |
307 gnt_widget_set_name(ggc->tv, "conversation-window-textview"); | |
15822 | 308 gnt_widget_set_size(ggc->tv, purple_prefs_get_int(PREF_ROOT "/size/width"), |
309 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
15817 | 310 |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
311 ggc->info = gnt_vbox_new(FALSE); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
312 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->info); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
313 |
15817 | 314 ggc->entry = gnt_entry_new(NULL); |
315 gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry); | |
316 gnt_widget_set_name(ggc->entry, "conversation-window-entry"); | |
317 gnt_entry_set_history_length(GNT_ENTRY(ggc->entry), -1); | |
318 gnt_entry_set_word_suggest(GNT_ENTRY(ggc->entry), TRUE); | |
319 gnt_entry_set_always_suggest(GNT_ENTRY(ggc->entry), FALSE); | |
320 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
321 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(ggc->tv), ggc->entry); |
15817 | 322 g_signal_connect_after(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc); |
323 g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc); | |
324 | |
15822 | 325 gnt_widget_set_position(ggc->window, purple_prefs_get_int(PREF_ROOT "/position/x"), |
326 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15817 | 327 gnt_widget_show(ggc->window); |
328 | |
329 g_signal_connect(G_OBJECT(ggc->tv), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
330 g_signal_connect(G_OBJECT(ggc->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
331 | |
15822 | 332 if (type == PURPLE_CONV_TYPE_IM) { |
15817 | 333 g_signal_connect(G_OBJECT(ggc->entry), "text_changed", G_CALLBACK(send_typing_notification), ggc); |
15822 | 334 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", finch_conv_get_handle(), |
335 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
336 purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", finch_conv_get_handle(), | |
337 PURPLE_CALLBACK(update_buddy_typing), NULL); | |
15817 | 338 } |
339 | |
340 g_free(title); | |
341 } | |
342 | |
343 static void | |
15822 | 344 finch_destroy_conversation(PurpleConversation *conv) |
15817 | 345 { |
346 /* do stuff here */ | |
347 FinchConv *ggc = conv->ui_data; | |
348 ggc->list = g_list_remove(ggc->list, conv); | |
349 if (ggc->list && conv == ggc->active_conv) | |
350 ggc->active_conv = ggc->list->data; | |
351 | |
352 if (ggc->list == NULL) { | |
353 gnt_widget_destroy(ggc->window); | |
354 g_free(ggc); | |
355 } | |
356 } | |
357 | |
358 static void | |
15822 | 359 finch_write_common(PurpleConversation *conv, const char *who, const char *message, |
360 PurpleMessageFlags flags, time_t mtime) | |
15817 | 361 { |
362 FinchConv *ggconv = conv->ui_data; | |
363 char *strip, *newline; | |
364 GntTextFormatFlags fl = 0; | |
365 int pos; | |
366 gboolean notify; | |
367 | |
368 g_return_if_fail(ggconv != NULL); | |
369 | |
370 if (ggconv->active_conv != conv) { | |
15822 | 371 if (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV)) |
15817 | 372 finch_conversation_set_active(conv); |
373 else | |
374 return; | |
375 } | |
376 | |
377 pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(ggconv->tv)); | |
378 | |
379 notify = !!gnt_text_view_tag_change(GNT_TEXT_VIEW(ggconv->tv), "typing", NULL, TRUE); | |
380 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), "\n", GNT_TEXT_FLAG_NORMAL); | |
381 | |
382 /* Unnecessary to print the timestamp for delayed message */ | |
15822 | 383 if (!(flags & PURPLE_MESSAGE_DELAYED) && |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16194
diff
changeset
|
384 purple_prefs_get_bool("/finch/conversations/timestamps")) |
15817 | 385 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
15822 | 386 purple_utf8_strftime("(%H:%M:%S) ", localtime(&mtime)), GNT_TEXT_FLAG_DIM); |
15817 | 387 |
15822 | 388 if (flags & PURPLE_MESSAGE_AUTO_RESP) |
15817 | 389 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
390 _("<AUTO-REPLY> "), GNT_TEXT_FLAG_BOLD); | |
391 | |
15822 | 392 if (who && *who && (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV))) |
15817 | 393 { |
394 char * name = NULL; | |
395 | |
15822 | 396 if (purple_message_meify((char*)message, -1)) |
15817 | 397 name = g_strdup_printf("*** %s ", who); |
398 else | |
399 name = g_strdup_printf("%s: ", who); | |
400 | |
401 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), | |
402 name, GNT_TEXT_FLAG_BOLD); | |
403 g_free(name); | |
404 } | |
405 else | |
406 fl = GNT_TEXT_FLAG_DIM; | |
407 | |
15822 | 408 if (flags & PURPLE_MESSAGE_ERROR) |
15817 | 409 fl |= GNT_TEXT_FLAG_BOLD; |
15822 | 410 if (flags & PURPLE_MESSAGE_NICK) |
15817 | 411 fl |= GNT_TEXT_FLAG_UNDERLINE; |
412 | |
413 /* XXX: Remove this workaround when textview can parse messages. */ | |
15822 | 414 newline = purple_strdup_withhtml(message); |
415 strip = purple_markup_strip_html(newline); | |
15817 | 416 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), |
417 strip, fl); | |
418 | |
419 g_free(newline); | |
420 g_free(strip); | |
421 | |
422 if (notify) { | |
15822 | 423 strip = g_strdup_printf(_("\n%s is typing..."), purple_conversation_get_name(conv)); |
15817 | 424 gnt_text_view_append_text_with_tag(GNT_TEXT_VIEW(ggconv->tv), |
425 strip, GNT_TEXT_FLAG_DIM, "typing"); | |
426 g_free(strip); | |
427 } | |
428 | |
429 if (pos <= 1) | |
430 gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); | |
431 | |
15822 | 432 if (flags & (PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_NICK | PURPLE_MESSAGE_ERROR)) |
15817 | 433 gnt_widget_set_urgent(ggconv->tv); |
434 } | |
435 | |
436 static void | |
15822 | 437 finch_write_chat(PurpleConversation *conv, const char *who, const char *message, |
438 PurpleMessageFlags flags, time_t mtime) | |
15817 | 439 { |
15822 | 440 purple_conversation_write(conv, who, message, flags, mtime); |
15817 | 441 } |
442 | |
443 static void | |
15822 | 444 finch_write_im(PurpleConversation *conv, const char *who, const char *message, |
445 PurpleMessageFlags flags, time_t mtime) | |
15817 | 446 { |
15822 | 447 PurpleAccount *account = purple_conversation_get_account(conv); |
448 if (flags & PURPLE_MESSAGE_SEND) | |
15817 | 449 { |
15822 | 450 who = purple_connection_get_display_name(purple_account_get_connection(account)); |
15817 | 451 if (!who) |
15822 | 452 who = purple_account_get_alias(account); |
15817 | 453 if (!who) |
15822 | 454 who = purple_account_get_username(account); |
15817 | 455 } |
15822 | 456 else if (flags & PURPLE_MESSAGE_RECV) |
15817 | 457 { |
15822 | 458 PurpleBuddy *buddy; |
459 who = purple_conversation_get_name(conv); | |
460 buddy = purple_find_buddy(account, who); | |
15817 | 461 if (buddy) |
15822 | 462 who = purple_buddy_get_contact_alias(buddy); |
15817 | 463 } |
464 | |
15822 | 465 purple_conversation_write(conv, who, message, flags, mtime); |
15817 | 466 } |
467 | |
468 static void | |
15822 | 469 finch_write_conv(PurpleConversation *conv, const char *who, const char *alias, |
470 const char *message, PurpleMessageFlags flags, time_t mtime) | |
15817 | 471 { |
472 const char *name; | |
473 if (alias && *alias) | |
474 name = alias; | |
475 else if (who && *who) | |
476 name = who; | |
477 else | |
478 name = NULL; | |
479 | |
480 finch_write_common(conv, name, message, flags, mtime); | |
481 } | |
482 | |
483 static void | |
15822 | 484 finch_chat_add_users(PurpleConversation *conv, GList *users, gboolean new_arrivals) |
15817 | 485 { |
486 FinchConv *ggc = conv->ui_data; | |
487 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
488 | |
489 if (!new_arrivals) | |
490 { | |
491 /* Print the list of users in the room */ | |
492 GString *string = g_string_new(_("List of users:\n")); | |
493 GList *iter; | |
494 | |
495 for (iter = users; iter; iter = iter->next) | |
496 { | |
15822 | 497 PurpleConvChatBuddy *cbuddy = iter->data; |
15817 | 498 char *str; |
499 | |
500 if ((str = cbuddy->alias) == NULL) | |
501 str = cbuddy->name; | |
502 g_string_append_printf(string, "[ %s ]", str); | |
503 } | |
504 | |
15822 | 505 purple_conversation_write(conv, NULL, string->str, |
506 PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
15817 | 507 g_string_free(string, TRUE); |
508 } | |
509 | |
510 for (; users; users = users->next) | |
511 { | |
15822 | 512 PurpleConvChatBuddy *cbuddy = users->data; |
15817 | 513 gnt_entry_add_suggest(entry, cbuddy->name); |
514 gnt_entry_add_suggest(entry, cbuddy->alias); | |
515 } | |
516 } | |
517 | |
518 static void | |
15822 | 519 finch_chat_rename_user(PurpleConversation *conv, const char *old, const char *new_n, const char *new_a) |
15817 | 520 { |
521 /* Update the name for string completion */ | |
522 FinchConv *ggc = conv->ui_data; | |
523 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
524 gnt_entry_remove_suggest(entry, old); | |
525 gnt_entry_add_suggest(entry, new_n); | |
526 gnt_entry_add_suggest(entry, new_a); | |
527 } | |
528 | |
529 static void | |
15822 | 530 finch_chat_remove_user(PurpleConversation *conv, GList *list) |
15817 | 531 { |
532 /* Remove the name from string completion */ | |
533 FinchConv *ggc = conv->ui_data; | |
534 GntEntry *entry = GNT_ENTRY(ggc->entry); | |
535 for (; list; list = list->next) | |
536 gnt_entry_remove_suggest(entry, list->data); | |
537 } | |
538 | |
539 static void | |
15822 | 540 finch_chat_update_user(PurpleConversation *conv, const char *user) |
15817 | 541 { |
542 } | |
543 | |
15822 | 544 static PurpleConversationUiOps conv_ui_ops = |
15817 | 545 { |
546 .create_conversation = finch_create_conversation, | |
547 .destroy_conversation = finch_destroy_conversation, | |
548 .write_chat = finch_write_chat, | |
549 .write_im = finch_write_im, | |
550 .write_conv = finch_write_conv, | |
551 .chat_add_users = finch_chat_add_users, | |
552 .chat_rename_user = finch_chat_rename_user, | |
553 .chat_remove_users = finch_chat_remove_user, | |
554 .chat_update_user = finch_chat_update_user, | |
555 .present = NULL, | |
556 .has_focus = NULL, | |
557 .custom_smiley_add = NULL, | |
558 .custom_smiley_write = NULL, | |
559 .custom_smiley_close = NULL | |
560 }; | |
561 | |
15822 | 562 PurpleConversationUiOps *finch_conv_get_ui_ops() |
15817 | 563 { |
564 return &conv_ui_ops; | |
565 } | |
566 | |
567 /* Xerox */ | |
15822 | 568 static PurpleCmdRet |
569 say_command_cb(PurpleConversation *conv, | |
15817 | 570 const char *cmd, char **args, char **error, void *data) |
571 { | |
15822 | 572 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
573 purple_conv_im_send(PURPLE_CONV_IM(conv), args[0]); | |
574 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
575 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), args[0]); | |
15817 | 576 |
15822 | 577 return PURPLE_CMD_RET_OK; |
15817 | 578 } |
579 | |
580 /* Xerox */ | |
15822 | 581 static PurpleCmdRet |
582 me_command_cb(PurpleConversation *conv, | |
15817 | 583 const char *cmd, char **args, char **error, void *data) |
584 { | |
585 char *tmp; | |
586 | |
587 tmp = g_strdup_printf("/me %s", args[0]); | |
588 | |
15822 | 589 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) |
590 purple_conv_im_send(PURPLE_CONV_IM(conv), tmp); | |
591 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) | |
592 purple_conv_chat_send(PURPLE_CONV_CHAT(conv), tmp); | |
15817 | 593 |
594 g_free(tmp); | |
15822 | 595 return PURPLE_CMD_RET_OK; |
15817 | 596 } |
597 | |
598 /* Xerox */ | |
15822 | 599 static PurpleCmdRet |
600 debug_command_cb(PurpleConversation *conv, | |
15817 | 601 const char *cmd, char **args, char **error, void *data) |
602 { | |
603 char *tmp, *markup; | |
15822 | 604 PurpleCmdStatus status; |
15817 | 605 |
606 if (!g_ascii_strcasecmp(args[0], "version")) { | |
607 tmp = g_strdup_printf("me is using %s.", VERSION); | |
608 markup = g_markup_escape_text(tmp, -1); | |
609 | |
15822 | 610 status = purple_cmd_do_command(conv, tmp, markup, error); |
15817 | 611 |
612 g_free(tmp); | |
613 g_free(markup); | |
614 return status; | |
615 } else { | |
15822 | 616 purple_conversation_write(conv, NULL, _("Supported debug options are: version"), |
617 PURPLE_MESSAGE_NO_LOG|PURPLE_MESSAGE_ERROR, time(NULL)); | |
618 return PURPLE_CMD_STATUS_OK; | |
15817 | 619 } |
620 } | |
621 | |
622 /* Xerox */ | |
15822 | 623 static PurpleCmdRet |
624 clear_command_cb(PurpleConversation *conv, | |
15817 | 625 const char *cmd, char **args, char **error, void *data) |
626 { | |
627 FinchConv *ggconv = conv->ui_data; | |
628 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); | |
15822 | 629 return PURPLE_CMD_STATUS_OK; |
15817 | 630 } |
631 | |
632 /* Xerox */ | |
15822 | 633 static PurpleCmdRet |
634 help_command_cb(PurpleConversation *conv, | |
15817 | 635 const char *cmd, char **args, char **error, void *data) |
636 { | |
637 GList *l, *text; | |
638 GString *s; | |
639 | |
640 if (args[0] != NULL) { | |
641 s = g_string_new(""); | |
15822 | 642 text = purple_cmd_help(conv, args[0]); |
15817 | 643 |
644 if (text) { | |
645 for (l = text; l; l = l->next) | |
646 if (l->next) | |
647 g_string_append_printf(s, "%s\n", (char *)l->data); | |
648 else | |
649 g_string_append_printf(s, "%s", (char *)l->data); | |
650 } else { | |
651 g_string_append(s, _("No such command (in this context).")); | |
652 } | |
653 } else { | |
654 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
655 "The following commands are available in this context:\n")); | |
656 | |
15822 | 657 text = purple_cmd_list(conv); |
15817 | 658 for (l = text; l; l = l->next) |
659 if (l->next) | |
660 g_string_append_printf(s, "%s, ", (char *)l->data); | |
661 else | |
662 g_string_append_printf(s, "%s.", (char *)l->data); | |
663 g_list_free(text); | |
664 } | |
665 | |
15822 | 666 purple_conversation_write(conv, NULL, s->str, PURPLE_MESSAGE_NO_LOG, time(NULL)); |
15817 | 667 g_string_free(s, TRUE); |
668 | |
15822 | 669 return PURPLE_CMD_STATUS_OK; |
15817 | 670 } |
671 | |
15822 | 672 static PurpleCmdRet |
673 cmd_show_window(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer data) | |
15817 | 674 { |
675 void (*callback)() = data; | |
676 callback(); | |
15822 | 677 return PURPLE_CMD_STATUS_OK; |
15817 | 678 } |
679 | |
680 void finch_conversation_init() | |
681 { | |
15822 | 682 purple_prefs_add_none(PREF_ROOT); |
683 purple_prefs_add_none(PREF_ROOT "/size"); | |
684 purple_prefs_add_int(PREF_ROOT "/size/width", 70); | |
685 purple_prefs_add_int(PREF_ROOT "/size/height", 20); | |
686 purple_prefs_add_none(PREF_ROOT "/position"); | |
687 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
688 purple_prefs_add_int(PREF_ROOT "/position/y", 0); | |
15817 | 689 |
690 /* Xerox the commands */ | |
15822 | 691 purple_cmd_register("say", "S", PURPLE_CMD_P_DEFAULT, |
692 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 693 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); |
15822 | 694 purple_cmd_register("me", "S", PURPLE_CMD_P_DEFAULT, |
695 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 696 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); |
15822 | 697 purple_cmd_register("debug", "w", PURPLE_CMD_P_DEFAULT, |
698 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 699 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); |
15822 | 700 purple_cmd_register("clear", "", PURPLE_CMD_P_DEFAULT, |
701 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 702 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); |
15822 | 703 purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, |
704 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
15817 | 705 help_command_cb, _("help <command>: Help on a specific command."), NULL); |
706 | |
707 /* Now some commands to bring up some other windows */ | |
15822 | 708 purple_cmd_register("plugins", "", PURPLE_CMD_P_DEFAULT, |
709 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 710 cmd_show_window, _("plugins: Show the plugins window."), finch_plugins_show_all); |
15822 | 711 purple_cmd_register("buddylist", "", PURPLE_CMD_P_DEFAULT, |
712 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 713 cmd_show_window, _("buddylist: Show the buddylist."), finch_blist_show); |
15822 | 714 purple_cmd_register("accounts", "", PURPLE_CMD_P_DEFAULT, |
715 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 716 cmd_show_window, _("accounts: Show the accounts window."), finch_accounts_show_all); |
15822 | 717 purple_cmd_register("debugwin", "", PURPLE_CMD_P_DEFAULT, |
718 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 719 cmd_show_window, _("debugwin: Show the debug window."), finch_debug_window_show); |
15822 | 720 purple_cmd_register("prefs", "", PURPLE_CMD_P_DEFAULT, |
721 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 722 cmd_show_window, _("prefs: Show the preference window."), finch_prefs_show_all); |
15822 | 723 purple_cmd_register("status", "", PURPLE_CMD_P_DEFAULT, |
724 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL, | |
15817 | 725 cmd_show_window, _("statuses: Show the savedstatuses window."), finch_savedstatus_show_all); |
726 } | |
727 | |
728 void finch_conversation_uninit() | |
729 { | |
730 } | |
731 | |
15822 | 732 void finch_conversation_set_active(PurpleConversation *conv) |
15817 | 733 { |
734 FinchConv *ggconv = conv->ui_data; | |
15822 | 735 PurpleAccount *account; |
15817 | 736 char *title; |
737 | |
738 g_return_if_fail(ggconv); | |
739 g_return_if_fail(g_list_find(ggconv->list, conv)); | |
740 | |
741 ggconv->active_conv = conv; | |
15822 | 742 account = purple_conversation_get_account(conv); |
15817 | 743 title = get_conversation_title(conv, account); |
744 gnt_screen_rename_widget(ggconv->window, title); | |
745 g_free(title); | |
746 } | |
747 | |
16128
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
748 void finch_conversation_set_info_widget(PurpleConversation *conv, GntWidget *widget) |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
749 { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
750 FinchConv *fc = conv->ui_data; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
751 int height, width; |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
752 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
753 gnt_box_remove_all(GNT_BOX(fc->info)); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
754 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
755 if (widget) { |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
756 gnt_box_add_widget(GNT_BOX(fc->info), widget); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
757 gnt_box_readjust(GNT_BOX(fc->info)); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
758 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
759 |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
760 gnt_widget_get_size(fc->window, &width, &height); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
761 gnt_box_readjust(GNT_BOX(fc->window)); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
762 gnt_screen_resize_widget(fc->window, width, height); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
763 gnt_box_give_focus_to_child(GNT_BOX(fc->window), fc->entry); |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
764 } |
7a2ffa981c1a
Allow adding information widgets in the conversation window.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
765 |