messagingapp/msgui/unifiededitor/src/msgunieditorutils.cpp
changeset 34 84197e66a4bd
equal deleted inserted replaced
31:ebfee66fde93 34:84197e66a4bd
       
     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 unieditor.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "msgunieditorutils.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 
       
    36 //---------------------------------------------------------------
       
    37 // MsgUnifiedEditorUtils::MsgUnifiedEditorUtils
       
    38 // @see header file
       
    39 //---------------------------------------------------------------
       
    40 MsgUnifiedEditorUtils::MsgUnifiedEditorUtils(QObject *parent) :
       
    41 QObject(parent)
       
    42 {
       
    43 }
       
    44 
       
    45 //---------------------------------------------------------------
       
    46 // MsgUnifiedEditorUtils::~MsgUnifiedEditorUtils
       
    47 // @see header file
       
    48 //---------------------------------------------------------------
       
    49 MsgUnifiedEditorUtils::~MsgUnifiedEditorUtils()
       
    50 {
       
    51 }
       
    52 
       
    53 //---------------------------------------------------------------
       
    54 // MsgUnifiedEditorUtils::addAttachmentWidget
       
    55 // @see header file
       
    56 //---------------------------------------------------------------
       
    57 void MsgUnifiedEditorUtils::launchContentViewer(const QString &mimeType, const QString &filePath)
       
    58 {
       
    59     if (mimeType.contains(IMAGE_MIMETYPE) || mimeType.contains(AUDIO_MIMETYPE)) {
       
    60         launchViaSharableFile(filePath);
       
    61     }
       
    62     else if (mimeType.contains(VCARD_MIMETYPE, Qt::CaseInsensitive)) {
       
    63         MsgContactsUtil::launchVCardViewer(filePath);
       
    64     }
       
    65 }
       
    66 
       
    67 //---------------------------------------------------------------
       
    68 // MsgUnifiedEditorUtils::handleOk
       
    69 // @see header file
       
    70 //---------------------------------------------------------------
       
    71 void MsgUnifiedEditorUtils::handleOk(const QVariant& result)
       
    72 {
       
    73     emit requestOk(result);
       
    74 }
       
    75 
       
    76 //---------------------------------------------------------------
       
    77 // MsgUnifiedEditorUtils::handleError
       
    78 // @see header file
       
    79 //---------------------------------------------------------------
       
    80 void MsgUnifiedEditorUtils::handleError(int errorCode, const QString& errorMessage)
       
    81 {
       
    82     emit requestError(errorCode, errorMessage);
       
    83 }
       
    84 
       
    85 //---------------------------------------------------------------
       
    86 // MsgUnifiedEditorUtils::launchViaSharableFile
       
    87 // @see header file
       
    88 //---------------------------------------------------------------
       
    89 void MsgUnifiedEditorUtils::launchViaSharableFile(const QString &filePath)
       
    90 {
       
    91     XQSharableFile sf;
       
    92     XQAiwRequest* request = 0;
       
    93 
       
    94     if (!sf.open(filePath)) {
       
    95         return;
       
    96     }
       
    97 
       
    98     // Get handlers
       
    99     XQApplicationManager appManager;
       
   100     QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf);
       
   101     if (fileHandlers.count() > 0) {
       
   102         XQAiwInterfaceDescriptor d = fileHandlers.first();
       
   103         request = appManager.create(sf, d);
       
   104 
       
   105         if (!request) {
       
   106             sf.close();
       
   107             return;
       
   108         }
       
   109     }
       
   110     else {
       
   111         sf.close();
       
   112         return;
       
   113     }
       
   114 
       
   115     // Result handlers
       
   116     connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)),
       
   117         Qt::UniqueConnection);
       
   118     connect(request, SIGNAL(requestError(int,const QString&)), this,
       
   119         SLOT(handleError(int,const QString&)), Qt::UniqueConnection);
       
   120 
       
   121     request->setEmbedded(true);
       
   122     request->setSynchronous(true);
       
   123 
       
   124     // Fill args
       
   125     QList<QVariant> args;
       
   126     args << qVariantFromValue(sf);
       
   127     request->setArguments(args);
       
   128 
       
   129     // Fill headers
       
   130     QString key("WindowTitle");
       
   131     QVariant value(QString(LOC_TITLE));
       
   132     XQRequestInfo info;
       
   133     info.setInfo(key, value);
       
   134     request->setInfo(info);
       
   135 
       
   136     request->send();
       
   137 
       
   138     // Cleanup
       
   139     sf.close();
       
   140     delete request;
       
   141 }
       
   142 
       
   143 //EOF