Mercurial > pidgin
comparison console/gntconv.c @ 13971:df8183b7fa2c
[gaim-migrate @ 16529]
Make multi-column trees look nice.
Show the list of users in a chat-room after you join.
Add some commands (eg. /me, /help etc., all Xeroxed from gtkconv.c)
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Thu, 20 Jul 2006 17:38:09 +0000 |
parents | 80cbf6c2d562 |
children | a7b1d2ab9cb0 |
comparison
equal
deleted
inserted
replaced
13970:4a2e9c494bed | 13971:df8183b7fa2c |
---|---|
243 gg_write_im(GaimConversation *conv, const char *who, const char *message, | 243 gg_write_im(GaimConversation *conv, const char *who, const char *message, |
244 GaimMessageFlags flags, time_t mtime) | 244 GaimMessageFlags flags, time_t mtime) |
245 { | 245 { |
246 if (flags & GAIM_MESSAGE_SEND) | 246 if (flags & GAIM_MESSAGE_SEND) |
247 { | 247 { |
248 who = gaim_connection_get_display_name(conv->account->gc); | 248 GaimAccount *account = gaim_conversation_get_account(conv); |
249 who = gaim_connection_get_display_name(gaim_account_get_connection(account)); | |
249 if (!who) | 250 if (!who) |
250 who = gaim_account_get_alias(conv->account); | 251 who = gaim_account_get_alias(account); |
251 if (!who) | 252 if (!who) |
252 who = gaim_account_get_username(conv->account); | 253 who = gaim_account_get_username(account); |
253 } | 254 } |
254 else if (flags & GAIM_MESSAGE_RECV) | 255 else if (flags & GAIM_MESSAGE_RECV) |
255 who = gaim_conversation_get_name(conv); | 256 who = gaim_conversation_get_name(conv); |
256 | 257 |
257 gg_write_common(conv, who, message, flags, mtime); | 258 gg_write_common(conv, who, message, flags, mtime); |
271 | 272 |
272 gg_write_common(conv, name, message, flags, mtime); | 273 gg_write_common(conv, name, message, flags, mtime); |
273 } | 274 } |
274 | 275 |
275 static void | 276 static void |
276 gg_chat_add_users(GaimConversation *conv, GList *users, GList *flags, GList *aliases, gboolean new_arrivals) | 277 gg_chat_add_users(GaimConversation *conv, GList *users, gboolean new_arrivals) |
277 {} | 278 { |
279 if (!new_arrivals) | |
280 { | |
281 /* Print the list of users in the room */ | |
282 GString *string = g_string_new(_("List of users:\n")); | |
283 GList *iter; | |
284 | |
285 for (iter = users; iter; iter = iter->next) | |
286 { | |
287 GaimConvChatBuddy *cbuddy = iter->data; | |
288 char *str; | |
289 | |
290 if ((str = cbuddy->alias) == NULL) | |
291 str = cbuddy->name; | |
292 g_string_append_printf(string, "[ %s ]", str); | |
293 } | |
294 | |
295 gaim_conversation_write(conv, NULL, string->str, | |
296 GAIM_MESSAGE_SYSTEM, time(NULL)); | |
297 g_string_free(string, TRUE); | |
298 } | |
299 /* XXX: Add the names for string completion */ | |
300 } | |
278 | 301 |
279 static void | 302 static void |
280 gg_chat_rename_user(GaimConversation *conv, const char *old, const char *new_n, const char *new_a) | 303 gg_chat_rename_user(GaimConversation *conv, const char *old, const char *new_n, const char *new_a) |
281 {} | 304 { |
305 /* XXX: Update the name for string completion */ | |
306 } | |
282 | 307 |
283 static void | 308 static void |
284 gg_chat_remove_user(GaimConversation *conv, GList *list) | 309 gg_chat_remove_user(GaimConversation *conv, GList *list) |
285 {} | 310 { |
311 /* XXX: Remove the name from string completion */ | |
312 } | |
286 | 313 |
287 static void | 314 static void |
288 gg_chat_update_user(GaimConversation *conv, const char *user) | 315 gg_chat_update_user(GaimConversation *conv, const char *user) |
289 {} | 316 { |
317 /* XXX: This probably will not require updating the string completion */ | |
318 } | |
290 | 319 |
291 static GaimConversationUiOps conv_ui_ops = | 320 static GaimConversationUiOps conv_ui_ops = |
292 { | 321 { |
293 .create_conversation = gg_create_conversation, | 322 .create_conversation = gg_create_conversation, |
294 .destroy_conversation = gg_destroy_conversation, | 323 .destroy_conversation = gg_destroy_conversation, |
307 }; | 336 }; |
308 | 337 |
309 static void | 338 static void |
310 destroy_ggconv(gpointer data) | 339 destroy_ggconv(gpointer data) |
311 { | 340 { |
312 GGConv *conv = data; | 341 GGConv *ggconv = data; |
313 gnt_widget_destroy(conv->window); | 342 gnt_widget_destroy(ggconv->window); |
314 g_free(conv); | 343 g_free(ggconv); |
315 } | 344 } |
316 | 345 |
317 GaimConversationUiOps *gg_conv_get_ui_ops() | 346 GaimConversationUiOps *gg_conv_get_ui_ops() |
318 { | 347 { |
319 return &conv_ui_ops; | 348 return &conv_ui_ops; |
320 } | 349 } |
321 | 350 |
351 /* Xerox */ | |
352 static GaimCmdRet | |
353 say_command_cb(GaimConversation *conv, | |
354 const char *cmd, char **args, char **error, void *data) | |
355 { | |
356 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
357 gaim_conv_im_send(GAIM_CONV_IM(conv), args[0]); | |
358 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
359 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), args[0]); | |
360 | |
361 return GAIM_CMD_RET_OK; | |
362 } | |
363 | |
364 /* Xerox */ | |
365 static GaimCmdRet | |
366 me_command_cb(GaimConversation *conv, | |
367 const char *cmd, char **args, char **error, void *data) | |
368 { | |
369 char *tmp; | |
370 | |
371 tmp = g_strdup_printf("/me %s", args[0]); | |
372 | |
373 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) | |
374 gaim_conv_im_send(GAIM_CONV_IM(conv), tmp); | |
375 else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) | |
376 gaim_conv_chat_send(GAIM_CONV_CHAT(conv), tmp); | |
377 | |
378 g_free(tmp); | |
379 return GAIM_CMD_RET_OK; | |
380 } | |
381 | |
382 /* Xerox */ | |
383 static GaimCmdRet | |
384 debug_command_cb(GaimConversation *conv, | |
385 const char *cmd, char **args, char **error, void *data) | |
386 { | |
387 char *tmp, *markup; | |
388 GaimCmdStatus status; | |
389 | |
390 if (!g_ascii_strcasecmp(args[0], "version")) { | |
391 tmp = g_strdup_printf("me is using %s.", VERSION); | |
392 markup = g_markup_escape_text(tmp, -1); | |
393 | |
394 status = gaim_cmd_do_command(conv, tmp, markup, error); | |
395 | |
396 g_free(tmp); | |
397 g_free(markup); | |
398 return status; | |
399 } else { | |
400 gaim_conversation_write(conv, NULL, _("Supported debug options are: version"), | |
401 GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL)); | |
402 return GAIM_CMD_STATUS_OK; | |
403 } | |
404 } | |
405 | |
406 /* Xerox */ | |
407 static GaimCmdRet | |
408 clear_command_cb(GaimConversation *conv, | |
409 const char *cmd, char **args, char **error, void *data) | |
410 { | |
411 GGConv *ggconv = conv->ui_data; | |
412 gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); | |
413 return GAIM_CMD_STATUS_OK; | |
414 } | |
415 | |
416 /* Xerox */ | |
417 static GaimCmdRet | |
418 help_command_cb(GaimConversation *conv, | |
419 const char *cmd, char **args, char **error, void *data) | |
420 { | |
421 GList *l, *text; | |
422 GString *s; | |
423 | |
424 if (args[0] != NULL) { | |
425 s = g_string_new(""); | |
426 text = gaim_cmd_help(conv, args[0]); | |
427 | |
428 if (text) { | |
429 for (l = text; l; l = l->next) | |
430 if (l->next) | |
431 g_string_append_printf(s, "%s\n", (char *)l->data); | |
432 else | |
433 g_string_append_printf(s, "%s", (char *)l->data); | |
434 } else { | |
435 g_string_append(s, _("No such command (in this context).")); | |
436 } | |
437 } else { | |
438 s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" | |
439 "The following commands are available in this context:\n")); | |
440 | |
441 text = gaim_cmd_list(conv); | |
442 for (l = text; l; l = l->next) | |
443 if (l->next) | |
444 g_string_append_printf(s, "%s, ", (char *)l->data); | |
445 else | |
446 g_string_append_printf(s, "%s.", (char *)l->data); | |
447 g_list_free(text); | |
448 } | |
449 | |
450 gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL)); | |
451 g_string_free(s, TRUE); | |
452 | |
453 return GAIM_CMD_STATUS_OK; | |
454 } | |
455 | |
322 | 456 |
323 void gg_conversation_init() | 457 void gg_conversation_init() |
324 { | 458 { |
325 ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv); | 459 ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv); |
460 | |
461 /* Xerox */ | |
462 gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT, | |
463 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
464 say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); | |
465 gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT, | |
466 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
467 me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); | |
468 gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT, | |
469 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
470 debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); | |
471 gaim_cmd_register("clear", "", GAIM_CMD_P_DEFAULT, | |
472 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, | |
473 clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); | |
474 gaim_cmd_register("help", "w", GAIM_CMD_P_DEFAULT, | |
475 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, | |
476 help_command_cb, _("help <command>: Help on a specific command."), NULL); | |
326 } | 477 } |
327 | 478 |
328 void gg_conversation_uninit() | 479 void gg_conversation_uninit() |
329 { | 480 { |
330 g_hash_table_destroy(ggconvs); | 481 g_hash_table_destroy(ggconvs); |