Ejemplo n.º 1
0
static void
message_source_activated(MessagingMenuApp *app, const gchar *id,
		gpointer user_data)
{
	gchar **sections = g_strsplit(id, ":", 0);
	PurpleConversation *conv = NULL;
	PurpleAccount *account;
	PidginConvWindow *purplewin = NULL;

	char *type     = sections[0];
	char *cname    = sections[1];
	char *aname    = sections[2];
	char *protocol = sections[3];

	account = purple_accounts_find(aname, protocol);

	if (g_strcmp0(type, "im") == 0)
		conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(cname, account));
	else if (g_strcmp0(type, "chat") == 0)
		conv = PURPLE_CONVERSATION(purple_conversations_find_chat_with_account(cname, account));
	else
		conv = purple_conversations_find_with_account(cname, account);

	if (conv) {
		unalert(conv);
		purplewin = PIDGIN_CONVERSATION(conv)->win;
		pidgin_conv_window_switch_gtkconv(purplewin, PIDGIN_CONVERSATION(conv));
		gdk_window_focus(gtk_widget_get_window(purplewin->window), time(NULL));
	}
	g_strfreev (sections);
}
Ejemplo n.º 2
0
int irc_cmd_default(struct irc_conn *irc, const char *cmd, const char *target, const char **args)
{
	PurpleConversation *convo = purple_conversations_find_with_account(target, irc->account);
	char *buf;

	if (!convo)
		return 1;

	buf = g_strdup_printf(_("Unknown command: %s"), cmd);
	purple_conversation_write_system_message(convo, buf, PURPLE_MESSAGE_NO_LOG);
	g_free(buf);

	return 1;
}
Ejemplo n.º 3
0
int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args)
{
	PurpleConnection *gc = purple_account_get_connection(irc->account);
	char *action, *escaped, *dst, **newargs;
	const char *src;
	char *msg;
	PurpleConversation *convo;
	PurpleMessage *pmsg;

	if (!args || !args[0] || !gc)
		return 0;

	convo = purple_conversations_find_with_account(target, irc->account);

	msg = g_strdup_printf("/me %s", args[0]);

	/* XXX: we'd prefer to keep this in conversation.c */
	if (PURPLE_IS_IM_CONVERSATION(convo)) {
		pmsg = purple_message_new_outgoing(
			purple_conversation_get_name(convo), msg, 0);

		purple_signal_emit(purple_conversations_get_handle(),
			"sending-im-msg", irc->account, pmsg);
	} else {
		pmsg = purple_message_new_outgoing(NULL, msg, 0);

		purple_signal_emit(purple_conversations_get_handle(),
			"sending-chat-msg", irc->account, pmsg,
			purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(convo)));
	}

	g_free(msg);
	if (purple_message_is_empty(pmsg))
		return 0;
	msg = g_strdup(purple_message_get_contents(pmsg)); /* XXX: is it really necessary? */

	if (strncmp(msg, "/me ", 4) != 0) {
		newargs = g_new0(char *, 2);
		newargs[0] = g_strdup(target);
		newargs[1] = msg;

		irc_cmd_privmsg(irc, cmd, target, (const char **)newargs);

		g_free(newargs[0]);
		g_free(newargs);
	} else {
Ejemplo n.º 4
0
void ggp_image_send(PurpleConnection *gc,
	const struct gg_event_image_request *image_request)
{
	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
	ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
	ggp_image_sent *sent_image;
	PurpleStoredImage *image;
	PurpleConversation *conv;
	uint64_t id;
	gchar *gg_filename;

	purple_debug_info("gg", "ggp_image_send: got image request "
		"[uin=%u, crc=%u, size=%u]\n",
		image_request->sender,
		image_request->crc32,
		image_request->size);

	id = ggp_image_params_to_id(image_request->crc32, image_request->size);

	sent_image = g_hash_table_lookup(sdata->sent_images, &id);

	if (sent_image == NULL && image_request->sender == ggp_str_to_uin(
		purple_account_get_username(purple_connection_get_account(gc))))
	{
		purple_debug_misc("gg", "ggp_image_send: requested image "
			"not found, but this may be another session request\n");
		return;
	}
	if (sent_image == NULL) {
		purple_debug_warning("gg", "ggp_image_send: requested image "
			"not found\n");
		return;
	}

	purple_debug_misc("gg", "ggp_image_send: requested image found "
		"[id=" GGP_IMAGE_ID_FORMAT ", stored id=%d, conv=%s]\n",
		id,
		sent_image->id,
		sent_image->conv_name);

	image = purple_imgstore_find_by_id(sent_image->id);

	if (!image) {
		purple_debug_error("gg", "ggp_image_send: requested image "
			"found, but doesn't exists in image store\n");
		g_hash_table_remove(sdata->sent_images,
			GINT_TO_POINTER(image_request->crc32));
		return;
	}

	/* TODO: check allowed recipients */
	gg_filename = g_strdup_printf(GGP_IMAGE_ID_FORMAT, id);
	gg_image_reply(accdata->session, image_request->sender,
		gg_filename,
		purple_imgstore_get_data(image),
		purple_imgstore_get_size(image));
	g_free(gg_filename);

	conv = purple_conversations_find_with_account(
		sent_image->conv_name,
		purple_connection_get_account(gc));
	if (conv != NULL) {
		gchar *msg = g_strdup_printf(_("Image delivered to %u."),
			image_request->sender);
		purple_conversation_write(conv, "", msg,
			PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_NOTIFY,
			time(NULL));
		g_free(msg);
	}
}