bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvcompleteddialogwidget.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     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:  BTRecvcompletedDialogWidget class declaration.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <xqaiwrequest.h>
       
    19 #include <xqappmgr.h>
       
    20 #include <QThreadPool>
       
    21 #include "btrecvcompleteddialogwidget.h"
       
    22 #include "bluetoothdevicedialogs.h"
       
    23 
       
    24 const char* DOCML_BT_RECV_CMPLTD_DIALOG = ":/docml/bt-receive-done-dialog.docml";
       
    25 const qint64 KBluetoothMsgsConversationId = 0x01;
       
    26 
       
    27 
       
    28 CoversationViewServiceStarter::CoversationViewServiceStarter(qint64 conversationId)
       
    29 :mCnvId(conversationId)
       
    30     {
       
    31     
       
    32     }
       
    33 
       
    34 CoversationViewServiceStarter::~CoversationViewServiceStarter()
       
    35     {
       
    36     
       
    37     }
       
    38 
       
    39 void CoversationViewServiceStarter::run()
       
    40     {
       
    41     QList<QVariant> args;
       
    42     QString serviceName("com.nokia.services.hbserviceprovider");
       
    43     QString operation("open(qint64)");
       
    44     XQAiwRequest* request;
       
    45     XQApplicationManager appManager;
       
    46     request = appManager.create(serviceName, "conversationview", operation, false); // not embedded
       
    47     if ( request == NULL )
       
    48         {
       
    49         return;       
       
    50         }
       
    51     args << QVariant(mCnvId);
       
    52     request->setArguments(args);
       
    53     request->send();
       
    54     delete request;
       
    55     }
       
    56 
       
    57 
       
    58 BTRecvcompletedDialogWidget::BTRecvcompletedDialogWidget(const QVariantMap &parameters)
       
    59 {
       
    60     mLoader = 0;
       
    61     constructDialog(parameters);
       
    62 }
       
    63 
       
    64 BTRecvcompletedDialogWidget::~BTRecvcompletedDialogWidget()
       
    65 {
       
    66     if(mLoader)
       
    67     {
       
    68         delete mLoader;
       
    69         mLoader = NULL;
       
    70     }
       
    71 }
       
    72 
       
    73 bool BTRecvcompletedDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
       
    74 {
       
    75     return true;
       
    76 }
       
    77 
       
    78 int BTRecvcompletedDialogWidget::deviceDialogError() const
       
    79 {
       
    80     return 0;
       
    81 }
       
    82 
       
    83 void BTRecvcompletedDialogWidget::closeDeviceDialog(bool byClient)
       
    84 {
       
    85     Q_UNUSED(byClient);
       
    86     mDialog->close();
       
    87 }
       
    88 
       
    89 HbPopup* BTRecvcompletedDialogWidget::deviceDialogWidget() const
       
    90 {
       
    91     return mDialog;
       
    92 }
       
    93 
       
    94 QObject* BTRecvcompletedDialogWidget::signalSender() const
       
    95 {
       
    96     return const_cast<BTRecvcompletedDialogWidget*>(this);
       
    97 }
       
    98 
       
    99 bool BTRecvcompletedDialogWidget::constructDialog(const QVariantMap &parameters)
       
   100 {
       
   101     mLoader = new HbDocumentLoader();
       
   102     bool ok = false;
       
   103     
       
   104     mLoader->load(DOCML_BT_RECV_CMPLTD_DIALOG, &ok);
       
   105     if(ok)
       
   106     {
       
   107         mDialog = qobject_cast<HbDialog*>(mLoader->findWidget("recvCompleteddialog"));
       
   108         mHeading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
       
   109         
       
   110         mFileName = qobject_cast<HbLabel*>(mLoader->findWidget("fileName"));
       
   111         mFileSize = qobject_cast<HbLabel*>(mLoader->findWidget("fileSize"));
       
   112         mFileCount = qobject_cast<HbLabel*>(mLoader->findWidget("fileCount_label"));
       
   113         mFileCount->setVisible(false);
       
   114         
       
   115         //TODO - set icon based on the file icon.
       
   116         
       
   117         mShow = qobject_cast<HbAction*>(mLoader->findObject("showaction"));
       
   118         mCancel = qobject_cast<HbAction*>(mLoader->findObject("cancelaction"));
       
   119         
       
   120         QString headingStr(hbTrId("txt_bt_title_received_from_1"));
       
   121         QString senderName(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
       
   122         mHeading->setPlainText(headingStr.arg(senderName));
       
   123         mDialog->setHeadingWidget(mHeading);
       
   124         
       
   125         mFileName->setPlainText(parameters.value(QString::number(TBluetoothDeviceDialog::EReceivingFileName)).toString());
       
   126         
       
   127         mFileSz = parameters.value(QString::number(TBluetoothDeviceDialog::EReceivingFileSize)).toInt();
       
   128         
       
   129         //Format the file size into a more readable format
       
   130         if ( mFileSz >> 20 )    // size in MB
       
   131             {       
       
   132             float sizeInMB = 0;
       
   133             sizeInMB = ((float)mFileSz ) / (1024*1024);
       
   134             QString fileSzMb;
       
   135             fileSzMb.setNum(sizeInMB);
       
   136             //TODO - check for localization
       
   137             fileSzMb.append(QString(" Mb"));
       
   138             mFileSize->setPlainText(fileSzMb);
       
   139             }
       
   140         
       
   141         else if( mFileSz >> 10 )        // size in KB
       
   142             {
       
   143             TInt64 sizeInKB = 0;
       
   144             sizeInKB = mFileSz >> 10;
       
   145             QString fileSzKb;
       
   146             fileSzKb.setNum(sizeInKB);
       
   147             //TODO - check for localization
       
   148             fileSzKb.append(QString(" Kb"));
       
   149             mFileSize->setPlainText(fileSzKb);
       
   150             }
       
   151 
       
   152         else                              // size is unknown or less than 1K
       
   153             {
       
   154             QString fileSzB;
       
   155             fileSzB.setNum(mFileSz);
       
   156             //TODO - check for localization
       
   157             fileSzB.append(QString(" Bytes"));
       
   158             mFileSize->setPlainText(fileSzB);
       
   159             }
       
   160 
       
   161         //Set the received file count
       
   162         int fCnt = parameters.value(QString::number(TBluetoothDeviceDialog::EReceivedFileCount)).toInt();
       
   163         if(fCnt > 1)
       
   164             {
       
   165             mFileCount->setVisible(true);  
       
   166             
       
   167             QString fCntStr(hbTrId("txt_bt_info_ln_other_files_received", (fCnt-1)));
       
   168             mFileCount->setPlainText(fCntStr);
       
   169             }
       
   170     }
       
   171 
       
   172     mDialog->setBackgroundFaded(false);
       
   173     mDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   174     mDialog->setTimeout(HbPopup::NoTimeout);
       
   175      
       
   176     connect(mShow, SIGNAL(triggered()), this, SLOT(showClicked()));
       
   177     connect(mCancel, SIGNAL(triggered()), this, SLOT(cancelClicked()));
       
   178     
       
   179     return true;
       
   180 }
       
   181 
       
   182 void BTRecvcompletedDialogWidget::showClicked()
       
   183 {   
       
   184     CoversationViewServiceStarter* service = new CoversationViewServiceStarter(KBluetoothMsgsConversationId);
       
   185     service->setAutoDelete(true);
       
   186     
       
   187     QThreadPool::globalInstance()->start(service);
       
   188           
       
   189     QVariantMap data;
       
   190     data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::EShow));
       
   191     emit deviceDialogData(data);
       
   192     emit deviceDialogClosed();
       
   193 }
       
   194 
       
   195 void BTRecvcompletedDialogWidget::cancelClicked()
       
   196 {
       
   197     QVariantMap data;
       
   198     data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::ECancelShow));
       
   199     emit deviceDialogData(data);
       
   200     emit deviceDialogClosed();
       
   201 }
       
   202