bluetoothengine/btnotif/btdevicedialogplugin/src/btrecvprgrsdialogwidget.cpp
author hgs
Fri, 23 Jul 2010 15:57:13 +0300
changeset 47 9e2a905b887f
parent 42 b72428996822
child 57 5ebadcda06cb
permissions -rw-r--r--
201029_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  BtDeviceDialogWidget class declaration.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
#include "btrecvprgrsdialogwidget.h"
hgs
parents:
diff changeset
    20
#include "bluetoothdevicedialogs.h"
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
const char* DOCML_BT_RECV_PRGRS_DIALOG = ":/docml/bt-recv-progress-dialog.docml";
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
BTRecvPrgrsDialogWidget::BTRecvPrgrsDialogWidget(const QVariantMap &parameters)
hgs
parents:
diff changeset
    26
{
hgs
parents:
diff changeset
    27
    mLoader = 0;
hgs
parents:
diff changeset
    28
    constructDialog(parameters);
hgs
parents:
diff changeset
    29
}
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
BTRecvPrgrsDialogWidget::~BTRecvPrgrsDialogWidget()
hgs
parents:
diff changeset
    32
{
hgs
parents:
diff changeset
    33
    if(mLoader)
hgs
parents:
diff changeset
    34
    {
hgs
parents:
diff changeset
    35
        delete mLoader;
hgs
parents:
diff changeset
    36
        mLoader = NULL;
hgs
parents:
diff changeset
    37
    }
hgs
parents:
diff changeset
    38
}
hgs
parents:
diff changeset
    39
hgs
parents:
diff changeset
    40
bool BTRecvPrgrsDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
hgs
parents:
diff changeset
    41
{
hgs
parents:
diff changeset
    42
    mProgressBar->setMinimum(0);
hgs
parents:
diff changeset
    43
    mProgressBar->setMaximum(mFileSz);
hgs
parents:
diff changeset
    44
    mProgressBar->setProgressValue(parameters.value("progress").toInt());
hgs
parents:
diff changeset
    45
    return true;
hgs
parents:
diff changeset
    46
}
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
int BTRecvPrgrsDialogWidget::deviceDialogError() const
hgs
parents:
diff changeset
    49
{
hgs
parents:
diff changeset
    50
    return 0;
hgs
parents:
diff changeset
    51
}
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
void BTRecvPrgrsDialogWidget::closeDeviceDialog(bool byClient)
hgs
parents:
diff changeset
    54
{
hgs
parents:
diff changeset
    55
    Q_UNUSED(byClient);
hgs
parents:
diff changeset
    56
    mDialog->close();
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
HbPopup* BTRecvPrgrsDialogWidget::deviceDialogWidget() const
hgs
parents:
diff changeset
    60
{
hgs
parents:
diff changeset
    61
    return mDialog;
hgs
parents:
diff changeset
    62
}
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
QObject* BTRecvPrgrsDialogWidget::signalSender() const
hgs
parents:
diff changeset
    65
{
hgs
parents:
diff changeset
    66
    return const_cast<BTRecvPrgrsDialogWidget*>(this);
hgs
parents:
diff changeset
    67
}
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
bool BTRecvPrgrsDialogWidget::constructDialog(const QVariantMap &parameters)
hgs
parents:
diff changeset
    70
{
hgs
parents:
diff changeset
    71
    mLoader = new HbDocumentLoader();
hgs
parents:
diff changeset
    72
    bool ok = false;
hgs
parents:
diff changeset
    73
    
hgs
parents:
diff changeset
    74
    mLoader->load(DOCML_BT_RECV_PRGRS_DIALOG, &ok);
hgs
parents:
diff changeset
    75
    if(ok)
hgs
parents:
diff changeset
    76
    {
hgs
parents:
diff changeset
    77
        mDialog = qobject_cast<HbDialog*>(mLoader->findWidget("senddialog"));
hgs
parents:
diff changeset
    78
        mHeading = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
hgs
parents:
diff changeset
    79
        
hgs
parents:
diff changeset
    80
        mFileName = qobject_cast<HbLabel*>(mLoader->findWidget("fileName"));
hgs
parents:
diff changeset
    81
        mFileSize = qobject_cast<HbLabel*>(mLoader->findWidget("fileSize"));
hgs
parents:
diff changeset
    82
        mFileCount = qobject_cast<HbLabel*>(mLoader->findWidget("fileCount_label"));
hgs
parents:
diff changeset
    83
        mFileCount->setVisible(false);
hgs
parents:
diff changeset
    84
        
hgs
parents:
diff changeset
    85
        //TODO - set icon based on the file icon.
hgs
parents:
diff changeset
    86
        
hgs
parents:
diff changeset
    87
        mHide = qobject_cast<HbAction*>(mLoader->findObject("hideaction"));
hgs
parents:
diff changeset
    88
        mCancel = qobject_cast<HbAction*>(mLoader->findObject("cancelaction"));
hgs
parents:
diff changeset
    89
        
hgs
parents:
diff changeset
    90
        mProgressBar = qobject_cast<HbProgressBar*>(mLoader->findWidget("horizontalProgressBar"));
hgs
parents:
diff changeset
    91
        
hgs
parents:
diff changeset
    92
        int dialogType = parameters.value(QString::number(TBluetoothDialogParams::EDialogTitle)).toInt();
hgs
parents:
diff changeset
    93
        switch(dialogType)
hgs
parents:
diff changeset
    94
        {
hgs
parents:
diff changeset
    95
            case TBluetoothDialogParams::EReceive:
hgs
parents:
diff changeset
    96
            {
hgs
parents:
diff changeset
    97
                QString headingStr(hbTrId("txt_bt_title_receiving_files_from_1"));
hgs
parents:
diff changeset
    98
                QString senderName(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
hgs
parents:
diff changeset
    99
                mHeading->setPlainText(headingStr.arg(senderName));
hgs
parents:
diff changeset
   100
            }break;
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
            default:
hgs
parents:
diff changeset
   103
                break;
hgs
parents:
diff changeset
   104
        }
hgs
parents:
diff changeset
   105
        mDialog->setHeadingWidget(mHeading);
hgs
parents:
diff changeset
   106
        
hgs
parents:
diff changeset
   107
        mFileName->setPlainText(parameters.value(QString::number(TBluetoothDeviceDialog::EReceivingFileName)).toString());
hgs
parents:
diff changeset
   108
        
hgs
parents:
diff changeset
   109
        mFileSz = parameters.value(QString::number(TBluetoothDeviceDialog::EReceivingFileSize)).toInt();
hgs
parents:
diff changeset
   110
        mProgressBar->setMinimum(0);
hgs
parents:
diff changeset
   111
        mProgressBar->setMaximum(mFileSz);
hgs
parents:
diff changeset
   112
        mProgressBar->setProgressValue(0);
hgs
parents:
diff changeset
   113
        
hgs
parents:
diff changeset
   114
        //Format the file size into a more readable format
hgs
parents:
diff changeset
   115
        if ( mFileSz >> 20 )    // size in MB
hgs
parents:
diff changeset
   116
            {       
hgs
parents:
diff changeset
   117
            float sizeInMB = 0;
hgs
parents:
diff changeset
   118
            sizeInMB = ((float)mFileSz ) / (1024*1024);
hgs
parents:
diff changeset
   119
            QString fileSzMb;
hgs
parents:
diff changeset
   120
            fileSzMb.setNum(sizeInMB);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   121
            //TODO - check for localization
42
hgs
parents:
diff changeset
   122
            fileSzMb.append(QString(" Mb"));
hgs
parents:
diff changeset
   123
            mFileSize->setPlainText(fileSzMb);
hgs
parents:
diff changeset
   124
            }
hgs
parents:
diff changeset
   125
        
hgs
parents:
diff changeset
   126
        else if( mFileSz >> 10 )        // size in KB
hgs
parents:
diff changeset
   127
            {
hgs
parents:
diff changeset
   128
            TInt64 sizeInKB = 0;
hgs
parents:
diff changeset
   129
            sizeInKB = mFileSz >> 10;
hgs
parents:
diff changeset
   130
            QString fileSzKb;
hgs
parents:
diff changeset
   131
            fileSzKb.setNum(sizeInKB);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   132
            //TODO - check for localization
42
hgs
parents:
diff changeset
   133
            fileSzKb.append(QString(" Kb"));
hgs
parents:
diff changeset
   134
            mFileSize->setPlainText(fileSzKb);
hgs
parents:
diff changeset
   135
            }
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
        else                              // size is unknown or less than 1K
hgs
parents:
diff changeset
   138
            {
hgs
parents:
diff changeset
   139
            QString fileSzB;
hgs
parents:
diff changeset
   140
            fileSzB.setNum(mFileSz);
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   141
            //TODO - check for localization
42
hgs
parents:
diff changeset
   142
            fileSzB.append(QString(" Bytes"));
hgs
parents:
diff changeset
   143
            mFileSize->setPlainText(fileSzB);
hgs
parents:
diff changeset
   144
            }
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
        //Set the received file count
hgs
parents:
diff changeset
   147
        int fCnt = parameters.value(QString::number(TBluetoothDeviceDialog::EReceivedFileCount)).toInt();
hgs
parents:
diff changeset
   148
        if(fCnt > 0)
hgs
parents:
diff changeset
   149
            {
hgs
parents:
diff changeset
   150
            mFileCount->setVisible(true);  
hgs
parents:
diff changeset
   151
            
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   152
            QString fCntStr(hbTrId("txt_bt_info_ln_files_already_received", fCnt));
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   153
            mFileCount->setPlainText(fCntStr);
42
hgs
parents:
diff changeset
   154
            }
hgs
parents:
diff changeset
   155
    }
hgs
parents:
diff changeset
   156
hgs
parents:
diff changeset
   157
    mDialog->setBackgroundFaded(false);
hgs
parents:
diff changeset
   158
    mDialog->setDismissPolicy(HbPopup::NoDismiss);
hgs
parents:
diff changeset
   159
    mDialog->setTimeout(HbPopup::NoTimeout);
hgs
parents:
diff changeset
   160
     
hgs
parents:
diff changeset
   161
    connect(mHide, SIGNAL(triggered()), this, SLOT(hideClicked()));
hgs
parents:
diff changeset
   162
    connect(mCancel, SIGNAL(triggered()), this, SLOT(cancelClicked()));
hgs
parents:
diff changeset
   163
    
hgs
parents:
diff changeset
   164
    return true;
hgs
parents:
diff changeset
   165
}
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
void BTRecvPrgrsDialogWidget::hideClicked()
hgs
parents:
diff changeset
   168
{
hgs
parents:
diff changeset
   169
    QVariantMap data;
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   170
    data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::EHide));
42
hgs
parents:
diff changeset
   171
    emit deviceDialogData(data);
hgs
parents:
diff changeset
   172
    emit deviceDialogClosed();
hgs
parents:
diff changeset
   173
}
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
void BTRecvPrgrsDialogWidget::cancelClicked()
hgs
parents:
diff changeset
   176
{
hgs
parents:
diff changeset
   177
    QVariantMap data;
47
9e2a905b887f 201029_02
hgs
parents: 42
diff changeset
   178
    data.insert(QString("actionResult"), QVariant(TBluetoothDialogParams::ECancelReceive));
42
hgs
parents:
diff changeset
   179
    emit deviceDialogData(data);
hgs
parents:
diff changeset
   180
    emit deviceDialogClosed();
hgs
parents:
diff changeset
   181
}
hgs
parents:
diff changeset
   182