messagingapp/msgui/unifiedviewer/src/univiewerutils.cpp
changeset 73 ecf6a73a9186
parent 68 e8a69c93c830
child 76 60a8a215b0ec
equal deleted inserted replaced
68:e8a69c93c830 73:ecf6a73a9186
     1 /*
       
     2  * Copyright (c) 2009 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: Utility class for univiewer.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "univiewerutils.h"
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include <xqaiwrequest.h>
       
    22 #include <xqrequestinfo.h>
       
    23 #include <xqappmgr.h>
       
    24 #include <hbglobal.h>
       
    25 
       
    26 // USER INCLUDES
       
    27 #include "msgcontactsutil.h"
       
    28 
       
    29 // LOCAL CONSTANTS
       
    30 #define LOC_TITLE   hbTrId("txt_messaging_title_messaging")
       
    31 
       
    32 const QString IMAGE_MIMETYPE("image");
       
    33 const QString AUDIO_MIMETYPE("audio");
       
    34 const QString VCARD_MIMETYPE("text/X-vCard");
       
    35 const QString VIDEO_MIMETYPE("video");
       
    36 
       
    37 //---------------------------------------------------------------
       
    38 // UniViewerUtils::UniViewerUtils
       
    39 // @see header file
       
    40 //---------------------------------------------------------------
       
    41 UniViewerUtils::UniViewerUtils(QObject *parent) :
       
    42     QObject(parent)
       
    43 {
       
    44 }
       
    45 
       
    46 //---------------------------------------------------------------
       
    47 // UniViewerUtils::~UniViewerUtils
       
    48 // @see header file
       
    49 //---------------------------------------------------------------
       
    50 UniViewerUtils::~UniViewerUtils()
       
    51 {
       
    52 }
       
    53 
       
    54 //---------------------------------------------------------------
       
    55 // UniViewerUtils::addAttachmentWidget
       
    56 // @see header file
       
    57 //---------------------------------------------------------------
       
    58 void UniViewerUtils::launchContentViewer(const QString &mimeType, const QString &filePath)
       
    59 {
       
    60     if (mimeType.contains(VCARD_MIMETYPE, Qt::CaseInsensitive)) {
       
    61         MsgContactsUtil::launchVCardViewer(filePath);
       
    62     }
       
    63     else {
       
    64         launchViaSharableFile(filePath);
       
    65     }
       
    66 }
       
    67 
       
    68 //---------------------------------------------------------------
       
    69 // UniViewerUtils::handleOk
       
    70 // @see header file
       
    71 //---------------------------------------------------------------
       
    72 void UniViewerUtils::handleOk(const QVariant& result)
       
    73 {
       
    74     emit requestOk(result);
       
    75 }
       
    76 
       
    77 //---------------------------------------------------------------
       
    78 // UniViewerUtils::handleError
       
    79 // @see header file
       
    80 //---------------------------------------------------------------
       
    81 void UniViewerUtils::handleError(int errorCode, const QString& errorMessage)
       
    82 {
       
    83     emit requestError(errorCode, errorMessage);
       
    84 }
       
    85 
       
    86 //---------------------------------------------------------------
       
    87 // UniViewerUtils::launchViaSharableFile
       
    88 // @see header file
       
    89 //---------------------------------------------------------------
       
    90 void UniViewerUtils::launchViaSharableFile(const QString &filePath)
       
    91 {
       
    92     XQSharableFile sf;
       
    93     XQAiwRequest* request = 0;
       
    94 
       
    95     if (!sf.open(filePath)) {
       
    96         return;
       
    97     }
       
    98 
       
    99     // Get handlers
       
   100     XQApplicationManager appManager;
       
   101     QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf);
       
   102     if (fileHandlers.count() > 0) {
       
   103         XQAiwInterfaceDescriptor d = fileHandlers.first();
       
   104         request = appManager.create(sf, d);
       
   105 
       
   106         if (!request) {
       
   107             sf.close();
       
   108             return;
       
   109         }
       
   110     }
       
   111     else {
       
   112         sf.close();
       
   113         return;
       
   114     }
       
   115 
       
   116     // Result handlers
       
   117     connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)),
       
   118         Qt::UniqueConnection);
       
   119     connect(request, SIGNAL(requestError(int,const QString&)), this,
       
   120         SLOT(handleError(int,const QString&)), Qt::UniqueConnection);
       
   121 
       
   122     request->setEmbedded(true);
       
   123     request->setSynchronous(true);
       
   124 
       
   125     // Fill args
       
   126     QList<QVariant> args;
       
   127     args << qVariantFromValue(sf);
       
   128     request->setArguments(args);
       
   129 
       
   130     // Fill headers
       
   131     QString key("WindowTitle");
       
   132     QVariant value(QString(LOC_TITLE));
       
   133     XQRequestInfo info;
       
   134     info.setInfo(key, value);
       
   135     request->setInfo(info);
       
   136 
       
   137     request->send();
       
   138 
       
   139     // Cleanup
       
   140     sf.close();
       
   141     delete request;
       
   142 }
       
   143 
       
   144 //EOF