void gaim_buddy_icon_update(GaimBuddyIcon *icon) { GaimConversation *conv; GaimAccount *account; const char *username; GSList *sl; g_return_if_fail(icon != NULL); account = gaim_buddy_icon_get_account(icon); username = gaim_buddy_icon_get_username(icon); for (sl = gaim_find_buddies(account, username); sl != NULL; sl = sl->next) { GaimBuddy *buddy = (GaimBuddy *)sl->data; gaim_buddy_set_icon(buddy, icon); } conv = gaim_find_conversation_with_account(username, account); if (conv != NULL && gaim_conversation_get_type(conv) == GAIM_CONV_IM) gaim_im_set_icon(GAIM_IM(conv), icon); }
void GaimChatMngr::CreateConversationCbk(GaimConversation *conv, bool userCreated) { GaimAccount *gAccount = gaim_conversation_get_account(conv); GaimConversationType chatType = gaim_conversation_get_type(conv); const char *gPrclId = gaim_account_get_protocol_id(gAccount); IMAccount *account = _accountMngr->FindIMAccount(gaim_account_get_username(gAccount), GaimIMPrcl::GetEnumIMProtocol(gPrclId)); GaimIMChat *mChat = FindIMChat(*account); mConvInfo_t *mConv; if (chatType == GAIM_CONV_TYPE_IM) { IMChatSession *chatSession = NULL; // Check if it's a jabber contact, and remove his ressource std::string contactId = cleanContactId(std::string(gaim_conversation_get_name(conv)), GaimIMPrcl::GetEnumIMProtocol(gPrclId)); IMContact imContact(*account, contactId); mConv = mChat->CreateChatSession(userCreated, *mChat); mConv->gaim_conv_session = conv; conv->ui_data = mConv; chatSession = (IMChatSession *) mConv->conv_session; ((IMContactSet &) chatSession->getIMContactSet()).insert(imContact); mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession); mChat->contactAddedEvent(*mChat, *chatSession, imContact); } else if (chatType == GAIM_CONV_TYPE_CHAT) { int id = GetGaimConversationId(gaim_conversation_get_name(conv)); if ((mConv = mChat->FindChatStructById(id)) == NULL) { mConv = mChat->CreateChatSession(userCreated, *mChat); } if (mConv->gaim_conv_session) gaim_conversation_destroy((GaimConversation *)mConv->gaim_conv_session); mConv->gaim_conv_session = conv; conv->ui_data = mConv; } }
static void gaym_get_photo_info(GaimConversation * conv) { char *buf; char *name; gaim_debug_misc("gaym", "Got conversation-created signal\n"); if (strncmp(conv->account->protocol_id, "prpl-gaym", 9) == 0 && gaim_conversation_get_type(conv) == GAIM_CONV_IM) { /** * First check to see if we already have the photo via * the buddy list process. */ struct gaym_conn *gaym; GaimConnection *gc = gaim_conversation_get_gc(conv); gaym = (struct gaym_conn *) gc->proto_data; if (!gaym) { return; } struct gaym_buddy *ib = g_hash_table_lookup(gaym->buddies, conv->name); if (ib) { return; } /** * Since this person isn't in our buddy list, go ahead * with the WHOIS to get the photo for the IM thumbnail */ name = gaym_nick_to_gcom_strdup(conv->name); buf = gaym_format(gaym, "vn", "WHOIS", name); gaim_debug_misc("gaym", "Conversation triggered command: %s\n", buf); gaym_send(gaym, buf); gaym_get_channel_member_reference(gaym, name); g_free(name); g_free(buf); // Opens a reference in channel_members. } }
GaimConversation * jabber_find_unnormalized_conv(const char *name, GaimAccount *account) { GaimConversation *c = NULL; GList *cnv; g_return_val_if_fail(name != NULL, NULL); for(cnv = gaim_get_conversations(); cnv; cnv = cnv->next) { c = (GaimConversation*)cnv->data; if(gaim_conversation_get_type(c) == GAIM_CONV_TYPE_IM && !gaim_utf8_strcasecmp(name, gaim_conversation_get_name(c)) && account == gaim_conversation_get_account(c)) return c; } return NULL; }
static void bye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) { MsnSwitchBoard *swboard; const char *user; swboard = cmdproc->data; user = cmd->params[0]; /* cmdproc->data is set to NULL when the switchboard is destroyed; * we may get a bye shortly thereafter. */ g_return_if_fail(swboard != NULL); if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL)) gaim_debug_error("msn_switchboard", "bye_cmd: helper bug\n"); if (swboard->conv == NULL) { /* This is a helper switchboard */ msn_switchboard_destroy(swboard); } else if ((swboard->current_users > 1) || (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT)) { /* This is a switchboard used for a chat */ gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->conv), user, NULL); swboard->current_users--; if (swboard->current_users == 0) msn_switchboard_destroy(swboard); } else { /* This is a switchboard used for a im session */ msn_switchboard_destroy(swboard); } }
/************************************************************************** * Message Handlers **************************************************************************/ static void plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { GaimConnection *gc; MsnSwitchBoard *swboard; const char *body; char *body_str; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = cmdproc->session->account->gc; swboard = cmdproc->data; body = msn_message_get_bin_data(msg, &body_len); body_str = g_strndup(body, body_len); body_enc = g_markup_escape_text(body_str, -1); g_free(body_str); passport = msg->remote_user; if (!strcmp(passport, "*****@*****.**") && strstr(body, "immediate security update")) { return; } #if 0 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { gaim_debug_misc("msn", "User-Agent = '%s'\n", value); } #endif if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) { char *pre, *post; msn_parse_format(value, &pre, &post); body_final = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(pre); g_free(post); g_free(body_enc); } else { body_final = body_enc; } swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1 || ((swboard->conv != NULL) && gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT)) { /* If current_users is always ok as it should then there is no need to * check if this is a chat. */ if (swboard->current_users <= 1) gaim_debug_misc("msn", "plain_msg: current_users(%d)\n", swboard->current_users); serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_chat(gc, swboard->chat_id); swboard->flag |= MSN_SB_FLAG_IM; } } else { serv_got_im(gc, passport, body_final, 0, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, gaim_connection_get_account(gc)); swboard->flag |= MSN_SB_FLAG_IM; } } g_free(body_final); }
static void msn_switchboard_add_user(MsnSwitchBoard *swboard, const char *user) { MsnCmdProc *cmdproc; GaimAccount *account; g_return_if_fail(swboard != NULL); cmdproc = swboard->cmdproc; account = cmdproc->session->account; swboard->users = g_list_prepend(swboard->users, g_strdup(user)); swboard->current_users++; swboard->empty = FALSE; #ifdef MSN_DEBUG_CHAT gaim_debug_info("msn", "user=[%s], total=%d\n", user, swboard->current_users); #endif if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL)) { /* This is a helper switchboard. */ gaim_debug_error("msn", "switchboard_add_user: conv != NULL\n"); return; } if ((swboard->conv != NULL) && (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT)) { gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL, GAIM_CBFLAGS_NONE, TRUE); } else if (swboard->current_users > 1 || swboard->total_users > 1) { if (swboard->conv == NULL || gaim_conversation_get_type(swboard->conv) != GAIM_CONV_TYPE_CHAT) { GList *l; #ifdef MSN_DEBUG_CHAT gaim_debug_info("msn", "[chat] Switching to chat.\n"); #endif #if 0 /* this is bad - it causes msn_switchboard_close to be called on the * switchboard we're in the middle of using :( */ if (swboard->conv != NULL) gaim_conversation_destroy(swboard->conv); #endif swboard->chat_id = cmdproc->session->conv_seq++; swboard->flag |= MSN_SB_FLAG_IM; swboard->conv = serv_got_joined_chat(account->gc, swboard->chat_id, "MSN Chat"); for (l = swboard->users; l != NULL; l = l->next) { const char *tmp_user; tmp_user = l->data; #ifdef MSN_DEBUG_CHAT gaim_debug_info("msn", "[chat] Adding [%s].\n", tmp_user); #endif gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE); } #ifdef MSN_DEBUG_CHAT gaim_debug_info("msn", "[chat] We add ourselves.\n"); #endif gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), gaim_account_get_username(account), NULL, GAIM_CBFLAGS_NONE, TRUE); g_free(swboard->im_user); swboard->im_user = NULL; } } else if (swboard->conv == NULL) { swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, user, account); } else { gaim_debug_warning("msn", "switchboard_add_user: This should not happen!\n"); } }
void gaym_gtkconv_update_thumbnail(GaimConversation * conv, struct fetch_thumbnail_data *thumbnail_data) { GaimGtkConversation *gtkconv; char filename[256]; FILE *file; GError *err = NULL; size_t len; GdkPixbuf *buf; GdkPixbuf *scale; GdkPixmap *pm; GdkBitmap *bm; int scale_width, scale_height; GaimAccount *account; GaimPluginProtocolInfo *prpl_info = NULL; g_return_if_fail(conv != NULL); g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv)); g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_CHAT); gtkconv = GAIM_GTK_CONVERSATION(conv); GaymChatIcon *icon_data = g_hash_table_lookup(icons, conv); if (!thumbnail_data) return; if (!icon_data->show_icon) return; const char *data = thumbnail_data->pic_data; len = thumbnail_data->pic_data_len; account = gaim_conversation_get_account(conv); if (account && account->gc) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); if (icon_data->anim != NULL) g_object_unref(G_OBJECT(icon_data->anim)); icon_data->anim = NULL; if (icon_data->icon_timer != 0) g_source_remove(icon_data->icon_timer); icon_data->icon_timer = 0; if (icon_data->iter != NULL) g_object_unref(G_OBJECT(icon_data->iter)); icon_data->iter = NULL; if (!gaim_prefs_get_bool ("/gaim/gtk/conversations/im/show_buddy_icons")) return; if (gaim_conversation_get_gc(conv) == NULL) return; /* this is such an evil hack, i don't know why i'm even considering it. we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */ /* gdk-pixbuf-loader was leaky? is it still? */ g_snprintf(filename, sizeof(filename), "%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d", g_get_tmp_dir(), thumbnail_data->who, getpid()); if (!(file = g_fopen(filename, "wb"))) return; fwrite(data, 1, len, file); fclose(file); icon_data->anim = gdk_pixbuf_animation_new_from_file(filename, &err); /* make sure we remove the file as soon as possible */ g_unlink(filename); if (err) { gaim_debug(GAIM_DEBUG_ERROR, "gtkconv", "Buddy icon error: %s\n", err->message); g_error_free(err); } if (!icon_data->anim) return; if (gdk_pixbuf_animation_is_static_image(icon_data->anim)) { icon_data->iter = NULL; buf = gdk_pixbuf_animation_get_static_image(icon_data->anim); } else { icon_data->iter = gdk_pixbuf_animation_get_iter(icon_data->anim, NULL); /* LEAK */ buf = gdk_pixbuf_animation_iter_get_pixbuf(icon_data->iter); } get_icon_scale_size(icon_data->anim, prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height); scale = gdk_pixbuf_scale_simple(buf, MAX(gdk_pixbuf_get_width(buf) * scale_width / gdk_pixbuf_animation_get_width (icon_data->anim), 1), MAX(gdk_pixbuf_get_height(buf) * scale_height / gdk_pixbuf_animation_get_height (icon_data->anim), 1), GDK_INTERP_NEAREST); gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); g_object_unref(G_OBJECT(scale)); icon_data->event = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(icon_data->frame), icon_data->event); gtk_widget_set_size_request(GTK_WIDGET(icon_data->frame), scale_width, scale_height); // g_signal_connect(G_OBJECT(icon_data->event), "button-press-event", // G_CALLBACK(icon_menu), conv); gtk_widget_show(icon_data->event); icon_data->icon = gtk_image_new_from_pixmap(pm, bm); gtk_container_add(GTK_CONTAINER(icon_data->event), icon_data->icon); gtk_widget_show(icon_data->icon); g_object_unref(G_OBJECT(pm)); if (bm) g_object_unref(G_OBJECT(bm)); }
void gaym_update_thumbnail(GaimConversation * conv, GdkPixbuf * pixbuf) { GaimGtkConversation *gtkconv; GdkPixbuf *scale; GdkPixmap *pm = NULL; GdkBitmap *bm = NULL; int scale_width = 0, scale_height = 0; GaimAccount *account; GaimPluginProtocolInfo *prpl_info = NULL; g_return_if_fail(conv != NULL); g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv)); g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_CHAT); gtkconv = GAIM_GTK_CONVERSATION(conv); GaymChatIcon *icon_data = g_hash_table_lookup(icons, conv); if (!icon_data->show_icon) return; account = gaim_conversation_get_account(conv); if (account && account->gc) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); if (!gaim_prefs_get_bool ("/gaim/gtk/conversations/im/show_buddy_icons")) return; if (gaim_conversation_get_gc(conv) == NULL) return; get_icon_scale_size(pixbuf, prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height); // double // aspect=(double)gdk_pixbuf_get_width(pixbuf)/(double)gdk_pixbuf_get_height(pixbuf); // // scale = gdk_pixbuf_scale_simple(pixbuf, scale_width, scale_height, GDK_INTERP_BILINEAR); gdk_pixbuf_render_pixmap_and_mask(scale, &pm, &bm, 100); g_object_unref(G_OBJECT(scale)); icon_data->event = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(icon_data->frame), icon_data->event); gtk_widget_set_size_request(GTK_WIDGET(icon_data->frame), 57, 77); // g_signal_connect(G_OBJECT(icon_data->event), "button-press-event", // G_CALLBACK(icon_menu), conv); gtk_widget_show(icon_data->event); icon_data->icon = gtk_image_new_from_pixmap(pm, bm); gtk_container_add(GTK_CONTAINER(icon_data->event), icon_data->icon); gtk_widget_show(icon_data->icon); if (pm) g_object_unref(G_OBJECT(pm)); if (bm) g_object_unref(G_OBJECT(bm)); }