homescreenapp/hsutils/src/hsimagefetcherclient.cpp
changeset 39 4e8ebe173323
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Photos image fetcher client.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hsimagefetcherclient.h"
       
    20 
       
    21 #include <QDir>
       
    22 #include <QDebug>
       
    23 #include <QVariant>
       
    24 #ifdef Q_OS_SYMBIAN
       
    25 #include <xqaiwinterfacedescriptor.h>
       
    26 #endif // Q_OS_SYMBIAN
       
    27 
       
    28 namespace
       
    29 {
       
    30     const char gFetcherService[] = "com.nokia.services.media";
       
    31     const char gFetcherInterface[] = "image";
       
    32     const char gFetcherOperation[] = "fetch(QVariantMap,QVariant)";
       
    33 }
       
    34 
       
    35 #ifdef COVERAGE_MEASUREMENT
       
    36 #pragma CTC SKIP
       
    37 #endif //COVERAGE_MEASUREMENT
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 #ifdef Q_OS_SYMBIAN
       
    43 HsImageFetcherClient::HsImageFetcherClient(QObject *parent)
       
    44   : QObject(parent),
       
    45     mReq(0)
       
    46 {
       
    47 }
       
    48 #else
       
    49 HsImageFetcherClient::HsImageFetcherClient(QObject *parent)
       
    50   : QObject(parent)
       
    51 {
       
    52 }
       
    53 #endif // Q_OS_SYMBIAN   
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 HsImageFetcherClient::~HsImageFetcherClient()
       
    59 {
       
    60 #ifdef Q_OS_SYMBIAN
       
    61     delete mReq;
       
    62 #endif // Q_OS_SYMBIAN   
       
    63 }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void HsImageFetcherClient::fetch()
       
    69 {
       
    70 #ifdef Q_OS_SYMBIAN
       
    71     qDebug() << "HsImageFetcherClient::fetch START";    
       
    72   
       
    73     if (mReq) {
       
    74         delete mReq;
       
    75         mReq = 0;
       
    76     }
       
    77   
       
    78     mReq = mAppMgr.create(gFetcherInterface, gFetcherOperation, false);
       
    79     if (mReq) {
       
    80         // Connect signals once
       
    81         connect(mReq, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
       
    82         connect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
       
    83     } else {
       
    84         qCritical() << "HsImageFetcherClient::fetch -> Create request failed";
       
    85         return;
       
    86     } 
       
    87 
       
    88     if (!(mReq)->send()) {
       
    89         qCritical() << "HsImageFetcherClient::fetch -> Send failed" << mReq->lastErrorMessage();;
       
    90     }
       
    91 
       
    92     qDebug() << "HsImageFetcherClient::fetch END";
       
    93 #endif // Q_OS_SYMBIAN        
       
    94 }
       
    95 
       
    96 
       
    97 
       
    98 // Aiw request responses
       
    99 void HsImageFetcherClient::handleOk(const QVariant &result)
       
   100 {
       
   101 #ifdef Q_OS_SYMBIAN
       
   102     // disconnect error signal as it will give -4999 (EConnectionClosed) error afterwards even though image
       
   103     // is fetched successfully
       
   104     disconnect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
       
   105         
       
   106     XQAiwRequest *request = static_cast<XQAiwRequest *>(sender());
       
   107     int implementationId=-1;
       
   108     implementationId = (request->descriptor().property(XQAiwInterfaceDescriptor::ImplementationId)).toInt();
       
   109     
       
   110     if (result.canConvert<QString>()) {
       
   111         qDebug("HsImageFetcherClient::%x:handleOk result=%s,%s",
       
   112                implementationId,
       
   113                result.typeName(),
       
   114                qPrintable(result.value<QString>()));
       
   115             
       
   116         emit fetchCompleted(result.value<QString>());
       
   117     } else if (result.canConvert<QStringList>()) {
       
   118         QStringList resultList = result.value<QStringList>();
       
   119 	    if (resultList.size() > 0) {
       
   120 	        //for debug
       
   121 	        QString msg = QString("HsImageFetcherClient::handleOk, size=")+QString::number( resultList.size() )+QString("\n");
       
   122 	        for (int i(0), size(resultList.size()); i < size; ++i) {
       
   123                 msg += QString::number(i) + QString(":") + resultList[i] + QString("\n");
       
   124 	        }	        
       
   125 	        qDebug()<<msg;
       
   126 		}
       
   127         emit fetchCompleted(resultList[0]);
       
   128 	} else {
       
   129         qCritical("AppMgrClient::%x:handleOk result=%s. Not displayable",
       
   130             implementationId,
       
   131             result.typeName());
       
   132         emit fetchFailed(-1, QString());
       
   133     }
       
   134 #else
       
   135 	Q_UNUSED(result)
       
   136 #endif // Q_OS_SYMBIAN     
       
   137 }
       
   138   
       
   139 void HsImageFetcherClient::handleError(int errorCode, const QString &errorMessage)
       
   140 {
       
   141 #ifdef Q_OS_SYMBIAN
       
   142     XQAiwRequest *request = static_cast<XQAiwRequest *>(sender());
       
   143     int implementationId = -1;
       
   144     implementationId = (request->descriptor().property(XQAiwInterfaceDescriptor::ImplementationId)).toInt();
       
   145     
       
   146     qCritical("HsImageFetcherClient::%x:handleError code=%d, errorMessage:%s",
       
   147         implementationId, errorCode, qPrintable(errorMessage));
       
   148     emit fetchFailed(errorCode, errorMessage);
       
   149 #else
       
   150 	Q_UNUSED(errorCode)
       
   151 	Q_UNUSED(errorMessage)
       
   152 #endif // Q_OS_SYMBIAN     
       
   153 }
       
   154 
       
   155 #ifdef COVERAGE_MEASUREMENT
       
   156 #pragma CTC ENDSKIP
       
   157 #endif //COVERAGE_MEASUREMENT