qthighway/xqservice/src/xqaiwfiledriver.cpp
branchRCL_3
changeset 10 cd2778e5acfe
parent 9 5d007b20cfd0
child 11 19a54be74e5e
equal deleted inserted replaced
9:5d007b20cfd0 10:cd2778e5acfe
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #include <QObject>
       
    23 #include <qglobal.h>
       
    24 
       
    25 #include "xqservicelog.h"
       
    26 #include "xqaiwutils.h"
       
    27 #include "xqaiwfiledriver.h"
       
    28 
       
    29 XQAiwFileDriver::XQAiwFileDriver(const QFile &file, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
       
    30     : XQAiwRequestDriver(),
       
    31       mUtilities(NULL)
       
    32 {
       
    33 
       
    34     mErrorMsg = "";
       
    35     mDescr = descriptor; 
       
    36     mOperation = operation;
       
    37     mFile = file.fileName();
       
    38     
       
    39     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::XQAiwFileDriver: %s",
       
    40                           qPrintable(file.fileName()));
       
    41     
       
    42 }
       
    43 
       
    44 XQAiwFileDriver::XQAiwFileDriver(const XQSharableFile &file, const XQAiwInterfaceDescriptor& descriptor, const QString &operation)
       
    45     : XQAiwRequestDriver(),
       
    46       mUtilities(NULL)
       
    47 {
       
    48 
       
    49     mErrorMsg = "";
       
    50     mDescr = descriptor; 
       
    51     mOperation = operation;
       
    52     mFile = qVariantFromValue(file);
       
    53 
       
    54     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::XQAiwFileDriver: sharable %s",
       
    55                           qPrintable(file.fileName()));
       
    56 
       
    57 }
       
    58 
       
    59 
       
    60 XQAiwFileDriver::~XQAiwFileDriver()
       
    61 {
       
    62     XQSERVICE_DEBUG_PRINT("~XQAiwFileDriver::XQAiwFileDriver");
       
    63     delete mUtilities;
       
    64     
       
    65 }
       
    66 
       
    67 QAction *XQAiwFileDriver::createAction()
       
    68 {
       
    69     return NULL;  //  Not supported
       
    70 }
       
    71 
       
    72 void XQAiwFileDriver::setArguments(const QList<QVariant> &arguments)
       
    73 {
       
    74     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::setArguments");
       
    75     mArguments =  arguments;
       
    76 }
       
    77 
       
    78 
       
    79 bool XQAiwFileDriver::send(QVariant& retValue)
       
    80 {
       
    81     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::send");
       
    82 
       
    83     if (mUtilities == NULL)
       
    84         mUtilities = new XQAiwUtils();
       
    85     if (mUtilities == NULL)
       
    86     {
       
    87         XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::Can not create aiw utils");
       
    88         return false;
       
    89     }
       
    90     QVariant applicationId =  mDescr.property(XQAiwInterfaceDescriptor::ImplementationId);
       
    91     XQSERVICE_DEBUG_PRINT("Application id %x", applicationId.toInt());
       
    92 
       
    93     mErrorCode = mUtilities->launchFile(applicationId.toInt(), mFile);
       
    94     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::errorCode %d", mErrorCode);
       
    95     QVariant ret(!mErrorCode);
       
    96     retValue = ret;
       
    97     return (!mErrorCode);
       
    98 }
       
    99 
       
   100 const QString& XQAiwFileDriver::lastErrorMessage() const
       
   101 {
       
   102     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::lastErrorMessage: %s", qPrintable(mErrorMsg));
       
   103     return mErrorMsg;
       
   104 }
       
   105 
       
   106 int XQAiwFileDriver::lastError() const
       
   107 {
       
   108     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::lastError %d", mErrorCode);
       
   109     return mErrorCode;
       
   110 }
       
   111 
       
   112 const XQAiwInterfaceDescriptor &XQAiwFileDriver::descriptor() const 
       
   113 {
       
   114     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::descriptor");
       
   115     return mDescr; 
       
   116 }
       
   117 
       
   118 void XQAiwFileDriver::setEmbedded(bool embedded)
       
   119 {
       
   120     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::setEmbedded");
       
   121     mEmbedded = embedded;
       
   122 }
       
   123 bool XQAiwFileDriver::isEmbedded() const
       
   124 {
       
   125     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::isEmbedded");
       
   126     return mEmbedded;
       
   127 }
       
   128 
       
   129 void XQAiwFileDriver::setOperation(const QString &operation)
       
   130 {
       
   131     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::setOperation");
       
   132     mOperation = operation;
       
   133 }
       
   134 const QString &XQAiwFileDriver::operation() const
       
   135 {
       
   136     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::operation");
       
   137     return mOperation;
       
   138 }
       
   139 
       
   140 void XQAiwFileDriver::setSynchronous(bool synchronous)
       
   141 {
       
   142     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::setSynchronous");
       
   143     mSynchronous = synchronous;
       
   144 }
       
   145 bool XQAiwFileDriver::isSynchronous() const
       
   146 {
       
   147     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::isSynchronous");
       
   148     return mSynchronous;
       
   149 }
       
   150 
       
   151 void XQAiwFileDriver::handleAsyncResponse(const QVariant& value)
       
   152 {
       
   153     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::handleAsyncResponse");
       
   154     emit requestOk(value);
       
   155 }
       
   156 
       
   157 void XQAiwFileDriver::handleAsyncError(int err)
       
   158 {
       
   159     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::handleAsyncError");
       
   160 
       
   161    mErrorCode = err;
       
   162    mErrorMsg = XQAiwUtils::createErrorMessage(mErrorCode, "XQAiwFileDriver");
       
   163    emit requestError(mErrorCode, mErrorMsg);
       
   164 }
       
   165 
       
   166 void XQAiwFileDriver::setBackground(bool background )
       
   167 {
       
   168     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::setBackground");
       
   169     mBackground = background;
       
   170 }
       
   171 bool XQAiwFileDriver::isBackground() const
       
   172 {
       
   173     XQSERVICE_DEBUG_PRINT("XQAiwFileDriver::isBackground");
       
   174     return mBackground;
       
   175 }
       
   176