Exemplo n.º 1
0
static TwitterConvIcon *twitter_conv_icon_find(PurpleAccount * account, const char *who)
{
    PurpleConnection *gc = purple_account_get_connection(account);
    PurpleBuddyIcon *buddy_icon;
    TwitterConvIcon *conv_icon;
    TwitterConnectionData *twitter;

    if (!gc) {
        return NULL;
    }
    twitter = gc->proto_data;

    if (!twitter) {
        return NULL;
    }

    purple_debug_info(PLUGIN_ID, "Looking up %s\n", who);
    conv_icon = g_hash_table_lookup(twitter->icons, purple_normalize(account, who));
    if ((!conv_icon || !conv_icon->pixbuf) && (buddy_icon = purple_buddy_icons_find(account, who))) {
        if (!conv_icon) {
            if ((conv_icon = buddy_icon_to_conv_icon(buddy_icon)))
                g_hash_table_insert(twitter->icons, g_strdup(purple_normalize(account, who)), conv_icon);
        } else {
            conv_icon_set_buddy_icon_data(conv_icon, buddy_icon);
        }
        purple_buddy_icon_unref(buddy_icon);
    }
    return conv_icon;                            //may be NULL
}
Exemplo n.º 2
0
std::string SpectrumBuddy::getIconHash() {
	char *avatarHash = NULL;
	PurpleBuddyIcon *icon = purple_buddy_icons_find(purple_buddy_get_account(m_buddy), purple_buddy_get_name(m_buddy));
	if (icon) {
		avatarHash = purple_buddy_icon_get_full_path(icon);
		Log(getName(), "avatarHash");
	}

	if (avatarHash) {
		Log(getName(), "Got avatar hash");
		// Check if it's patched libpurple which saves icons to directories
		char *hash = strrchr(avatarHash,'/');
		std::string h;
		if (hash) {
			char *dot;
			hash++;
			dot = strchr(hash, '.');
			if (dot)
				*dot = '\0';

			std::string ret(hash);
			g_free(avatarHash);
			return ret;
		}
		else {
			std::string ret(avatarHash);
			g_free(avatarHash);
			return ret;
		}
	}

	return "";
}
Exemplo n.º 3
0
PurpleBuddyIcon *
purple_buddy_icon_new(PurpleAccount *account, const char *username,
                      void *icon_data, size_t icon_len,
                      const char *checksum)
{
	PurpleBuddyIcon *icon;

	g_return_val_if_fail(account   != NULL, NULL);
	g_return_val_if_fail(username  != NULL, NULL);
	g_return_val_if_fail(icon_data != NULL, NULL);
	g_return_val_if_fail(icon_len  > 0,    NULL);

	/* purple_buddy_icons_find() does allocation, so be
	 * sure to update it as well when members are added. */
	icon = purple_buddy_icons_find(account, username);

	/* purple_buddy_icon_create() sets account & username */
	if (icon == NULL)
		icon = purple_buddy_icon_create(account, username);

	/* purple_buddy_icon_set_data() sets img, but it
	 * references img first, so we need to initialize it */
	icon->img = NULL;
	purple_buddy_icon_set_data(icon, icon_data, icon_len, checksum);

	return icon;
}
Exemplo n.º 4
0
//
// This function updates a given buddy. It first does a lookup the the buddy in
// the internal lookup table of buddies that where defined in the JSON file. If
// the buddy can't be found then no processing is done. Otherwise the buddy's
// name is changed unless if the buddy has already a name. Finally the buddy's
// icon is downloaded unless if the buddy has already an icon. The buddy icon is
// downloaded asynchronously.
//
// Returns a SoupMessage* if the buddy icon has been scheduled for a download.
//
static SoupMessage*
budicons_buddy_update (BudiconsPlugin *plugin, PurpleBuddy *buddy) {
	// Take the next buddy/user to process
	g_print("Buddy %s\n", buddy->name);

	BudiconsUser *user = g_hash_table_lookup(plugin->users, buddy->name);
	if (user == NULL) {return NULL;}

	// Set the buddy's name (alias) if it's still unset
	gboolean force_rename = budicons_prefs_get_force_name_update();
	if (force_rename || buddy->alias == NULL || EQ(buddy->name, buddy->alias)) {
		g_print("Rename %s to %s\n", buddy->alias, user->name);
		purple_blist_alias_buddy(buddy, user->name);
	}

	// Check if the buddy has already an image
	if (user->image == NULL) {return NULL;}
	PurpleBuddyIcon *icon = purple_buddy_icons_find(buddy->account, buddy->name);
	gboolean force_download = budicons_prefs_get_force_icon_download();
	if (icon != NULL) {
		// This buddy has already an icon
		purple_buddy_icon_unref(icon);
		if (!force_download) {
			// Don't redownload the icon once more
			return NULL;
		}
	}

	// Download the buddy's image since it doesn't have one (asynchronous)
	SoupMessage *message = soup_message_new(SOUP_METHOD_GET, user->image);
	if (message == NULL) {
		g_print("Invalid URL %s for buddy %s\n", user->image, buddy->name);
		return NULL;
	}
	g_print("Download of %s\n", user->image);
	return message;
}