/*
 * Copyright (c) 2010 Nokia Corporation.
 */

#include "imageloader.h"
#include <QDesktopServices>
#include <QDir>
#include <QImageReader>


ImageLoader::ImageLoader(QObject *parent) :
    QObject(parent)
{
}


ImageLoader::~ImageLoader()
{
}

QPixmap ImageLoader::loadImage(QString path, QSize size)
{
    QImageReader* reader = new QImageReader();
    reader->setFileName(path);

    QSize imageSize = reader->size();
    imageSize.scale(size, Qt::KeepAspectRatio);
    reader->setScaledSize(imageSize);

    QImage* image = new QImage();
    reader->read(image);
    delete reader;

    QPixmap pixmap;
    pixmap = QPixmap::fromImage(*image);
    delete image;

    return pixmap;
}

QString ImageLoader::imageName(QString path)
{
    return path.mid(path.lastIndexOf("/")+1);
}



