diff -r 6bb1b21d2484 -r 2f8f8080a020 phoneuis/bubblemanager2/bubblecore/src/bubbleimagemanager_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/phoneuis/bubblemanager2/bubblecore/src/bubbleimagemanager_p.cpp Mon May 03 12:31:11 2010 +0300 @@ -0,0 +1,171 @@ +/*! +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include +#include "bubbleimagemanager_p.h" +#include "bubbleimagemanager.h" +#include + +//#define BUBBLE_IMAGEMANAGER_DEBUG +#if defined(BUBBLE_IMAGEMANAGER_DEBUG) + #define BUBBLE_QDEBUG( a ) + #define BUBBLE_QDEBUG_2( a, b) +#else + #define BUBBLE_QDEBUG( a )\ + qDebug() << a; + + #define BUBBLE_QDEBUG_2( a, b)\ + qDebug() << a << b; +#endif + +BubbleImageManagerPrivate::BubbleImageManagerPrivate( + BubbleImageManager* parent) + : q_ptr(parent), + mInitialized(false) +{ +} + +BubbleImageManagerPrivate::~BubbleImageManagerPrivate() +{ +} + +void BubbleImageManagerPrivate::initialize() +{ + mThumbnailManager = new ThumbnailManager(this); + + mThumbnailManager->setMode(ThumbnailManager::Default); + + mThumbnailManager->setQualityPreference( + ThumbnailManager::OptimizeForPerformance); + + mThumbnailManager->setThumbnailSize( + ThumbnailManager::ThumbnailLarge); + + connect(mThumbnailManager, + SIGNAL(thumbnailReady(QPixmap, void *, int, int)), + this, + SLOT(thumbnailReady(QPixmap, void *, int, int))); + + mInitialized = true; +} + +const QPixmap* BubbleImageManagerPrivate::pixmap( + const QString& imageFileName) +{ + if (mImageCache.contains(imageFileName)) { + return mImageCache.value(imageFileName); + } else { + return 0; + } +} + +void BubbleImageManagerPrivate::loadImage(const QString& imageFileName) +{ + if (mImageCache.contains(imageFileName) || + isLoading(imageFileName)) { + return; + } + + if (!mInitialized) { + // connect to thumbnail server + initialize(); + } + + BUBBLE_QDEBUG_2("loading image: ", imageFileName); + + QString* data = new QString(imageFileName); + int reqId = mThumbnailManager->getThumbnail(imageFileName, data); + mRequestQueue.enqueue(qMakePair(imageFileName,reqId)); +} + +void BubbleImageManagerPrivate::unloadImage(const QString& imageFileName) +{ + BUBBLE_QDEBUG_2("unloading image: ", imageFileName); + + // returns null, if key doesn't exists + QPixmap* pixmap = mImageCache.take(imageFileName); + delete pixmap; + + // cancel possible outstanding request + QMutableListIterator< QPair > requests(mRequestQueue); + while(requests.hasNext()) { + QPair& request = requests.next(); + + if (request.first==imageFileName) { + BUBBLE_QDEBUG_2("cancelling request: ", imageFileName); + mThumbnailManager->cancelRequest(request.second); + requests.remove(); + break; + } + } +} + +void BubbleImageManagerPrivate::releasePixmaps() +{ + BUBBLE_QDEBUG_2("releasing all pixmaps: ", mImageCache.count()); + + // release all cached pixmaps + QList pixmaps = mImageCache.values(); + qDeleteAll(pixmaps); + mImageCache.clear(); +} + +void BubbleImageManagerPrivate::thumbnailReady( + const QPixmap& pixmap, void *data, int id, int error) +{ + QString* fileName = (QString*)data; + + if (error==0 && fileName) { + QPixmap *p = new QPixmap(pixmap); + mImageCache.insert(*fileName,p); + emit q_ptr->pixmapReady(*fileName); + BUBBLE_QDEBUG_2("thumbnailReady: ", *fileName); + } + + // request complete, remove it from queue + QMutableListIterator< QPair > requests(mRequestQueue); + while(requests.hasNext()) { + QPair& request = requests.next(); + if (request.second==id) { + BUBBLE_QDEBUG_2("deleting completed request: ", *fileName); + requests.remove(); + break; + } + } + + delete fileName; +} + +void BubbleImageManagerPrivate::thumbnailReady() +{ +} + +bool BubbleImageManagerPrivate::isLoading(const QString& imageFileName) const +{ + bool loading = false; + + QListIterator< QPair > requests(mRequestQueue); + while(requests.hasNext()) { + if (requests.next().first==imageFileName) { + loading = true; + break; + } + } + + return loading; +} +