Logo Search packages:      
Sourcecode: gaim version File versions

void gaim_conversation_destroy ( GaimConversation conv  ) 

Destroys the specified conversation and removes it from the parent window.

If this conversation is the only one contained in the parent window, that window is also destroyed.

Parameters:
conv The conversation to destroy.

Definition at line 867 of file conversation.c.

References _GaimConversation::chat, _GaimPluginProtocolInfo::convo_closed, _GaimConversation::data, _GaimConversationUiOps::destroy_conversation, GAIM_CONV_CHAT, GAIM_CONV_IM, gaim_log_free(), GAIM_NOT_TYPING, gaim_signal_emit(), _GaimConversation::history, _GaimConvIm::icon, _GaimConvChat::ignored, _GaimConversation::im, _GaimConvChat::in_room, _GaimConversation::log, _GaimConversation::name, _GaimConvChat::nick, _GaimConversation::send_history, _GaimConversation::title, _GaimConvChat::topic, _GaimConversation::type, _GaimConversation::u, and _GaimConvChat::who.

{
      GaimPluginProtocolInfo *prpl_info = NULL;
      GaimConvWindow *win;
      GaimConversationUiOps *ops;
      GaimConnection *gc;
      const char *name;
      GList *node;

      g_return_if_fail(conv != NULL);

      win  = gaim_conversation_get_window(conv);
      ops  = gaim_conversation_get_ui_ops(conv);
      gc   = gaim_conversation_get_gc(conv);
      name = gaim_conversation_get_name(conv);

      if (gc != NULL)
      {
            /* Still connected */
            prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);

            if (gaim_conversation_get_type(conv) == GAIM_CONV_IM)
            {
                  if (gaim_prefs_get_bool("/core/conversations/im/send_typing"))
                        serv_send_typing(gc, name, GAIM_NOT_TYPING);

                  if (gc && prpl_info->convo_closed != NULL)
                        prpl_info->convo_closed(gc, name);
            }
            else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
            {
                  int chat_id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
#if 0
                  /*
                   * This is unfortunately necessary, because calling
                   * serv_chat_leave() calls this gaim_conversation_destroy(),
                   * which leads to two calls here.. We can't just return after
                   * this, because then it'll return on the next pass. So, since
                   * serv_got_chat_left(), which is eventually called from the
                   * prpl that serv_chat_leave() calls, removes this conversation
                   * from the gc's buddy_chats list, we're going to check to see
                   * if this exists in the list. If so, we want to return after
                   * calling this, because it'll be called again. If not, fall
                   * through, because it'll have already been removed, and we'd
                   * be on the 2nd pass.
                   *
                   * Long paragraph. <-- Short sentence.
                   *
                   *   -- ChipX86
                   */

                  if (gc && g_slist_find(gc->buddy_chats, conv) != NULL) {
                        serv_chat_leave(gc, chat_id);

                        return;
                  }
#endif
                  /*
                   * Instead of all of that, lets just close the window when
                   * the user tells us to, and let the prpl deal with the
                   * internals on it's own time. Don't do this if the prpl already
                   * knows it left the chat.
                   */
                  if (!gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)))
                        serv_chat_leave(gc, chat_id);

                  /*
                   * If they didn't call serv_got_chat_left by now, it's too late.
                   * So we better do it for them before we destroy the thing.
                   */
                  if (!gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)))
                        serv_got_chat_left(gc, chat_id);
            }
      }

      gaim_signal_emit(gaim_conversations_get_handle(),
                               "deleting-conversation", conv);

      if (conv->name  != NULL) g_free(conv->name);
      if (conv->title != NULL) g_free(conv->title);

      conv->name = NULL;
      conv->title = NULL;

      for (node = g_list_first(conv->send_history);
             node != NULL;
             node = g_list_next(node)) {

            if (node->data != NULL)
                  g_free(node->data);

            node->data = NULL;
      }

      g_list_free(g_list_first(conv->send_history));

      if (conv->history != NULL)
            g_string_free(conv->history, TRUE);
      conv->history = NULL;

      conversations = g_list_remove(conversations, conv);

      if (conv->type == GAIM_CONV_IM) {
            gaim_conv_im_stop_typing_timeout(conv->u.im);
            gaim_conv_im_stop_type_again_timeout(conv->u.im);

            if (conv->u.im->icon != NULL)
                  gaim_buddy_icon_unref(conv->u.im->icon);

            conv->u.im->icon = NULL;

            g_free(conv->u.im);
            conv->u.im = NULL;

            ims = g_list_remove(ims, conv);
      }
      else if (conv->type == GAIM_CONV_CHAT) {

            for (node = conv->u.chat->in_room; node != NULL; node = node->next) {
                  if (node->data != NULL)
                        gaim_conv_chat_cb_destroy((GaimConvChatBuddy *)node->data);
                  node->data = NULL;
            }

            for (node = conv->u.chat->ignored; node != NULL; node = node->next) {
                  if (node->data != NULL)
                        g_free(node->data);
                  node->data = NULL;
            }

            g_list_free(conv->u.chat->in_room);
            g_list_free(conv->u.chat->ignored);

            conv->u.chat->in_room = NULL;
            conv->u.chat->ignored = NULL;

            if (conv->u.chat->who != NULL)
                  g_free(conv->u.chat->who);
            conv->u.chat->who = NULL;

            if (conv->u.chat->topic != NULL)
                  g_free(conv->u.chat->topic);
            conv->u.chat->topic = NULL;

            if(conv->u.chat->nick)
                  g_free(conv->u.chat->nick);

            g_free(conv->u.chat);
            conv->u.chat = NULL;

            chats = g_list_remove(chats, conv);
      }

      g_hash_table_destroy(conv->data);
      conv->data = NULL;

      if (win != NULL) {
            gaim_conv_window_remove_conversation(win,
                  gaim_conversation_get_index(conv));
      }

      if (ops != NULL && ops->destroy_conversation != NULL)
            ops->destroy_conversation(conv);

      gaim_log_free(conv->log);
      g_free(conv);
      conv = NULL;
}


Generated by  Doxygen 1.6.0   Back to index