Example #1
0
PurpleStoredImage *
purple_buddy_icons_find_account_icon(PurpleAccount *account)
{
	PurpleStoredImage *img;
	const char *account_icon_file;
	const char *dirname;
	char *path;
	guchar *data;
	size_t len;

	g_return_val_if_fail(account != NULL, NULL);

	if ((img = g_hash_table_lookup(pointer_icon_cache, account)))
	{
		return purple_imgstore_ref(img);
	}

	account_icon_file = purple_account_get_string(account, "buddy_icon", NULL);

	if (account_icon_file == NULL)
		return NULL;

	dirname = purple_buddy_icons_get_cache_dir();
	path = g_build_filename(dirname, account_icon_file, NULL);

	if (read_icon_file(path, &data, &len))
	{
		g_free(path);
		img = purple_buddy_icons_set_account_icon(account, data, len);
		return purple_imgstore_ref(img);
	}
	g_free(path);

	return NULL;
}
Example #2
0
xmlnode * _h_elim_set_icon ( const char *name , 
                             const char *id   ,
                             SEXP_VALUE *args , 
                             gpointer    data )
{
    ASSERT_ALISTP( args, id, name );

    elim_ping();
    
    const char *aname = ALIST_VAL_STR ( args, "account-name" );
    const char *proto = ALIST_VAL_STR ( args, "im-protocol"  );
    gpointer    auid  = ALIST_VAL_PTR ( args, "account-uid"  );
    const char *file  = ALIST_VAL_STR ( args, "icon-file"    );
    GString    *img   = ALIST_VAL_DATA( args, "icon-data"    );
    gchar      *bytes = NULL;
    gsize       len   = 0;
    gpointer    set   = NULL;
    PurpleAccount *acct =
      auid ? find_acct_by_uid( auid ) : purple_accounts_find( aname, proto );

    if( !acct )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "unknown account" );
    }

    if( !img && file && *file )
    {
        g_file_get_contents( file, &bytes, &len, NULL );
    }
    else if( img )
    {
        bytes = g_memdup( img->str, img->len );
        len   = img->len;
    }

    // the imgstore owns `bytes' after this, don't free it:
    set = purple_buddy_icons_set_account_icon( acct, (guchar *)bytes, len );

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR ( rval, "account-uid" , acct );
    AL_STR ( rval, "account-name", purple_account_get_username   ( acct ) );
    AL_STR ( rval, "im-protocol" , purple_account_get_protocol_id( acct ) );
    AL_BOOL( rval, "has-icon"    , set ? TRUE : FALSE );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Example #3
0
static VALUE set_avatar_from_file( VALUE self, VALUE filepath ) {
  FILE *file = NULL;
  size_t file_len = 0;
  unsigned char *file_data = NULL;
  char *filename = NULL;
  unsigned char *icon_data = NULL;
  PurpleAccount *account = PURPLE_ACCOUNT(self);
  
  filename = RSTRING_PTR( filepath );
  
  file = fopen( filename, "rb" );
  
  if( file != NULL ) {
    // get file size
    fseek( file, 0, SEEK_END );
    file_len = ftell( file );
    fseek( file, 0, SEEK_SET );
    // read data
    file_data = g_malloc( file_len );
    fread( file_data, file_len, 1, file );

    // close file
    fclose( file );
  }
  else {
    rb_raise( rb_eRuntimeError, "Error when opening picture: %s", filename );
  }

  // set filename
  // purple_account_set_buddy_icon_path( account, filename );
  
  // set account icon
  icon_data = g_malloc( file_len );
  memcpy( icon_data, file_data, file_len );
  purple_buddy_icons_set_account_icon( account, icon_data, file_len );
  // purple_account_set_bool( account, "use-global-buddyicon", 1 );
  
  return Qtrue;
}
Example #4
0
void AccountCollector::collectNow(PurpleAccount *account, bool remove) {
	if (account->ui_data == NULL) {
		Log("AccountCollector","freeing account " << purple_account_get_username(account));
		
		if (remove)
			g_hash_table_remove(m_accounts, purple_account_get_username(account));

		purple_account_set_enabled(account, purple_core_get_ui(), FALSE);

		purple_notify_close_with_handle(account);
		purple_request_close_with_handle(account);

		purple_accounts_remove(account);

		GSList *buddies = purple_find_buddies(account, NULL);
		while(buddies) {
			PurpleBuddy *b = (PurpleBuddy *) buddies->data;
			purple_blist_remove_buddy(b);
			buddies = g_slist_delete_link(buddies, buddies);
		}

		/* Remove any open conversation for this account */
		for (GList *it = purple_get_conversations(); it; ) {
			PurpleConversation *conv = (PurpleConversation *) it->data;
			it = it->next;
			if (purple_conversation_get_account(conv) == account)
				purple_conversation_destroy(conv);
		}

		/* Remove this account's pounces */
 			// purple_pounce_destroy_all_by_account(account);

		/* This will cause the deletion of an old buddy icon. */
		purple_buddy_icons_set_account_icon(account, NULL, 0);

		purple_account_destroy(account);
// 		VALGRIND_DO_LEAK_CHECK;
	}
}