btobexprofiles/obexreceiveservices/btmsgviewer/src/btmsgviewer.cpp
changeset 41 0b2439c3e397
child 47 9e2a905b887f
equal deleted inserted replaced
40:997690c3397a 41:0b2439c3e397
       
     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:  
       
    15  *
       
    16  */
       
    17 
       
    18 
       
    19 #include "btmsgviewer.h"
       
    20 #include "apmstd.h"
       
    21 #include <xqaiwrequest.h>
       
    22 #include <f32file.h>
       
    23 //#include <documenthandler.h>
       
    24 
       
    25 
       
    26 BTMsgViewer::BTMsgViewer(QObject* parent)
       
    27 : XQServiceProvider("com.nokia.services.btmsgdispservices.displaymsg",parent)
       
    28     {    
       
    29     publishAll();
       
    30     }
       
    31 
       
    32 BTMsgViewer::~BTMsgViewer ()
       
    33     {
       
    34     
       
    35     }
       
    36 
       
    37 int BTMsgViewer::displaymsg( int messageId )
       
    38     {    
       
    39     CBtMsgViewerUtils* btViewerUtils = 0;
       
    40     
       
    41     TRAPD(error, btViewerUtils = CBtMsgViewerUtils::NewL());  
       
    42     if(isError(error))
       
    43         {
       
    44         if(btViewerUtils)
       
    45             delete btViewerUtils;
       
    46         
       
    47         return error;   
       
    48         }
       
    49         
       
    50     HBufC* fileName = 0;
       
    51     fileName = btViewerUtils->GetMessagePath(messageId, error);
       
    52     if(isError(error))
       
    53         {
       
    54         if(fileName)
       
    55             delete fileName;
       
    56         
       
    57         delete btViewerUtils;
       
    58         return error;
       
    59         }
       
    60     
       
    61     QString attachmentFName = QString::fromUtf16(fileName->Ptr(),fileName->Length());    
       
    62     
       
    63     delete fileName;
       
    64     delete btViewerUtils;
       
    65 
       
    66     XQSharableFile sf;
       
    67     XQAiwRequest* request = 0;
       
    68 
       
    69     if (!sf.open(attachmentFName)) {
       
    70         return KErrNotFound;
       
    71     }
       
    72 
       
    73     // Get handlers
       
    74     XQApplicationManager appManager;
       
    75     QList<XQAiwInterfaceDescriptor> fileHandlers = appManager.list(sf);
       
    76     if (fileHandlers.count() > 0) {
       
    77         XQAiwInterfaceDescriptor d = fileHandlers.first();
       
    78         request = appManager.create(sf, d);
       
    79 
       
    80         if (!request) {
       
    81             sf.close();
       
    82             return KErrGeneral;
       
    83         }
       
    84     }
       
    85     else {
       
    86         sf.close();
       
    87         return KErrGeneral;
       
    88     }
       
    89 
       
    90     request->setEmbedded(true);
       
    91     request->setSynchronous(true);
       
    92 
       
    93     // Fill args
       
    94     QList<QVariant> args;
       
    95     args << qVariantFromValue(sf);
       
    96     request->setArguments(args);
       
    97 
       
    98     bool res = request->send();
       
    99     if  (!res) 
       
   100         {
       
   101         QString errMsg = request->lastErrorMessage();
       
   102         }
       
   103 
       
   104     // Cleanup
       
   105     sf.close();
       
   106     delete request;
       
   107     
       
   108     if(!res)
       
   109         return request->lastError();
       
   110     else
       
   111         return KErrNone;
       
   112     }
       
   113 
       
   114 bool BTMsgViewer::isError(int aError)
       
   115     {
       
   116     return ((aError < KErrNone)?true:false);
       
   117     }