/**
 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * For the applicable distribution terms see the license.txt -file, included in
 * the distribution.
 */

#include "drmfile.h"
#include "drmfile_p.h"

DRMFile::DRMFile(QObject *parent) :
        QObject(parent), d_ptr(new DRMFilePrivate())
{
	
}

DRMFile::~DRMFile()
{
    delete d_ptr;
}

int DRMFile::open(const QString & name)
{
    Q_D(DRMFile);
    return d_ptr->open(name);
}

int DRMFile::read(uchar*& data, int length, int index)
{
    Q_D(DRMFile);
    return d_ptr->read(data, length, index);
}

void DRMFile::close()
{
    Q_D(DRMFile);
    d_ptr->close();
}

int DRMFile::size(int index)
{
    Q_D(DRMFile);
    return d_ptr->size(index);
}


int DRMFile::count()
{
    return d_ptr->count();
}

QString DRMFile::getName(int index)
{
    int len = 0;
    QString result;
    
    if (const ushort *buf = d_ptr->getStringAttr(index, len)){
        result.setUtf16(buf, len); // NOTE: it copies buffer to QString,
                                   // thus it is needed to release allocated memory
        delete buf;
    }

    return result;
}

