Пример #1
0
void add_chat_icon_stuff(GaimConversation * c)
{

    GtkTreeModel *ls;

    GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(c);
    GaimGtkChatPane *gtkchat = gtkconv->u.chat;
    GaimPluginProtocolInfo *prpl_info = NULL;
    GaimAccount *account = gaim_conversation_get_account(c);
    GaymChatIcon *icon_data = g_new0(GaymChatIcon, 1);

    if (account && account->gc)
        prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl);
    GtkTreeSelection *select =
        gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkchat->list));

    gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);

    ls = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list));

    GtkBox *hbox = GTK_BOX(gtkconv->lower_hbox);

    g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK(changed_cb),
                     c);

    icon_data->icon_container_parent = GTK_WIDGET(hbox);
    icon_data->icon_container = NULL;
    icon_data->icon = NULL;
    icon_data->anim = NULL;
    icon_data->iter = NULL;
    icon_data->show_icon = TRUE;
    icon_data->icon_container = gtk_vbox_new(FALSE, 0);

    gtk_widget_set_size_request(GTK_WIDGET(icon_data->icon_container),
                                prpl_info->icon_spec.max_width,
                                prpl_info->icon_spec.max_height);


    icon_data->frame = gtk_frame_new(NULL);
    gtk_frame_set_shadow_type(GTK_FRAME(icon_data->frame),
                              (GTK_SHADOW_IN));
    gtk_box_pack_start(GTK_BOX(icon_data->icon_container),
                       icon_data->frame, FALSE, FALSE, 0);
    gtk_widget_show(icon_data->icon_container);
    gtk_widget_show(icon_data->frame);
    gtk_box_pack_end(GTK_BOX(icon_data->icon_container_parent),
                     icon_data->icon_container, FALSE, FALSE, 0);

    icon_data->event = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(icon_data->frame), icon_data->event);

    // Maybe add menu functionality later.
    // g_signal_connect(G_OBJECT(icon_data->event), "button-press-event",
    // G_CALLBACK(icon_menu), conv);
    gtk_widget_show(icon_data->event);
    g_hash_table_insert(icons, c, icon_data);


}
Пример #2
0
Файл: chat.c Проект: VoxOx/VoxOx
JabberChat *jabber_chat_find_by_conv(GaimConversation *conv)
{
	GaimAccount *account = gaim_conversation_get_account(conv);
	GaimConnection *gc = gaim_account_get_connection(account);
	JabberStream *js = gc->proto_data;
	int id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));

	return jabber_chat_find_by_id(js, id);
}
Пример #3
0
/* **************** IMWRAPPER/GAIM INTERFACE ****************** */
GaimIMChat *GaimChatMngr::FindIMChatByGaimConv(void *gConv)
{
	GaimAccount *gAccount = gaim_conversation_get_account((GaimConversation *) gConv);
	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);

	return mChat;
}
Пример #4
0
static void
buddy_typing_cb(GaimConversation *conv, void *data)
{
	GaimAccount *account = gaim_conversation_get_account(conv);
	const char *name     = gaim_conversation_get_name(conv);

	if (gaim_find_buddy(account, name) != NULL)
	{
		GaimPounceEvent event;

		event = (gaim_conv_im_get_typing_state(GAIM_CONV_IM(conv)) == GAIM_TYPING
				 ? GAIM_POUNCE_TYPING : GAIM_POUNCE_TYPING_STOPPED);

		gaim_pounce_execute(account, name, event);
	}
}
Пример #5
0
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;
	}
}
Пример #6
0
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;
}
Пример #7
0
void GaimChatMngr::ChatAddUsersCbk(GaimConversation *conv, GList *users, gboolean new_arrivals)
{
	GList *l;
	GaimAccount *gAccount = gaim_conversation_get_account(conv);
	const char *gPrclId = gaim_account_get_protocol_id(gAccount);
	IMAccount *account = _accountMngr->FindIMAccount(gaim_account_get_username(gAccount),
								GaimIMPrcl::GetEnumIMProtocol(gPrclId));
	mConvInfo_t *mConv = NULL;
	IMChatSession *chatSession = NULL;
	GaimIMChat *mChat = FindIMChat(*account);

	if (!mChat)
		LOG_FATAL("Can't find IMChat !");

	mConv = (mConvInfo_t *) conv->ui_data;
	chatSession = (IMChatSession *) mConv->conv_session;

	for (l = users; l != NULL; l = l->next)
	{
		GaimConvChatBuddy *gCCBuddy = (GaimConvChatBuddy *) l->data;

		if (gCCBuddy && strcmp(gaim_account_get_username(gAccount), (char *) gCCBuddy->name))
		{
			std::string buddy((char *) gCCBuddy->name);
			IMContact imContact(*account, buddy);

			if (chatSession->getIMContactSet().find(imContact) != chatSession->getIMContactSet().end())
			{
				LOG_DEBUG("IMContact for " + imContact.getContactId() + " already in IMContactSet");
			}
			else
			{
				((IMContactSet &) chatSession->getIMContactSet()).insert(imContact);

				if (chatSession->getIMContactSet().size() == 1)
					mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);

				LOG_DEBUG("IMContact " + imContact.getContactId() + " added to IMContactSet");
			}
			mChat->contactAddedEvent(*mChat, *chatSession, imContact);
		}
	}
}
Пример #8
0
void GaimChatMngr::UpdateBuddyTyping(GaimConversation *conv, GaimTypingState state)
{
	IMChat::TypingState mState;

	mConvInfo_t *mConv = (mConvInfo_t *)conv->ui_data;
	GaimIMChat *mIMChat = FindIMChatByGaimConv(conv);

	if (!mIMChat)
		return;

	switch (state)
	{
		case GAIM_TYPING:
			mState = IMChat::TypingStateTyping;
			break;

		case GAIM_TYPED:
			mState = IMChat::TypingStateStopTyping;
			break;

		default:
			mState = IMChat::TypingStateNotTyping;
			break;
	}

	// Get contact id. If it's a jabber contact, remove its ressource.
	const char *name = gaim_conversation_get_name(conv);
	GaimAccount *gAccount = gaim_conversation_get_account(conv);
	const char *gPrclId = gaim_account_get_protocol_id(gAccount);
	std::string contactId = cleanContactId(name,
		GaimIMPrcl::GetEnumIMProtocol(gPrclId));

	mIMChat->typingStateChangedEvent(*mIMChat, *((IMChatSession *)(mConv->conv_session)),
									contactId, mState);

}
Пример #9
0
void GaimChatMngr::ChatRemoveUsersCbk(GaimConversation *conv, GList *users)
{
	GList *l;
	GaimAccount *gAccount = gaim_conversation_get_account(conv);
	const char *gPrclId = gaim_account_get_protocol_id(gAccount);
	IMAccount *account = _accountMngr->FindIMAccount(gaim_account_get_username(gAccount),
								GaimIMPrcl::GetEnumIMProtocol(gPrclId));
	mConvInfo_t *mConv = NULL;
	IMChatSession *chatSession = NULL;
	GaimIMChat *mChat = FindIMChat(*account);

	if (!mChat)
		LOG_FATAL("Can't find IMChat !");

	mConv = (mConvInfo_t *) conv->ui_data;
	chatSession = (IMChatSession *) mConv->conv_session;

	for (l = users; l != NULL; l = l->next)
	{
		if (strcmp(gaim_account_get_username(gAccount), (char *) l->data))
		{
			std::string buddy((char *) l->data);
			IMContact imContact(*account, buddy);

			if (chatSession->getIMContactSet().find(imContact) == chatSession->getIMContactSet().end())
			{
				LOG_ERROR("IMContact for " + imContact.getContactId() + " not in IMContactSet");
			}
			else
			{
				LOG_DEBUG("IMContact " + imContact.getContactId() + " removed from IMContactSet");
				mChat->contactRemovedEvent(*mChat, *chatSession, buddy);
			}
		}
	}
}
Пример #10
0
void GaimChatMngr::WriteConvCbk(GaimConversation *conv, const char *name, const char *alias,
							const char *message, GaimMessageFlags flags,
							time_t mtime)
{
	if ((flags & GAIM_MESSAGE_RECV))
	{
		mConvInfo_t *mConv = (mConvInfo_t *)conv->ui_data;
		GaimIMChat *mIMChat = FindIMChatByGaimConv(conv);

		// Prevent from double message during a chat session
		if (strcmp(gaim_account_get_username(conv->account), name) == 0)
			return;

		// Check if it's a jabber contact, and remove his ressource
		GaimAccount *gAccount = gaim_conversation_get_account(conv);
		const char *gPrclId = gaim_account_get_protocol_id(gAccount);
		std::string contactId = cleanContactId(name,
			GaimIMPrcl::GetEnumIMProtocol(gPrclId));

		mIMChat->messageReceivedEvent(*mIMChat, 
			*((IMChatSession *)(mConv->conv_session)),
			contactId, std::string(message));
	}
}
Пример #11
0
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));


}
Пример #12
0
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));


}