bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialognotifwidget.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:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     3
* All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
* Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
* Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
* Description:  BtDeviceDialogWidget class implementation.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
#include "btdevicedialognotifwidget.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
#include "btdevicedialogplugintrace.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
#include <bluetoothdevicedialogs.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
#include <hbaction.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
#include <hbdialog.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include "btdevicedialogpluginerrors.h"
42
hgs
parents: 29
diff changeset
    25
#include <btuiiconutil.h>
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    26
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
    class Constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    28
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    29
BtDeviceDialogNotifWidget::BtDeviceDialogNotifWidget( const QVariantMap &parameters )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    30
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
    // set properties
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
    mLastError = NoError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
    mShowEventReceived = false;
42
hgs
parents: 29
diff changeset
    35
    mNotificationDialog = new HbNotificationDialog();
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    36
    resetProperties();
42
hgs
parents: 29
diff changeset
    37
    constructNotifDialog(parameters);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
/*!
42
hgs
parents: 29
diff changeset
    42
    class Constructor
hgs
parents: 29
diff changeset
    43
 */
hgs
parents: 29
diff changeset
    44
BtDeviceDialogNotifWidget::~BtDeviceDialogNotifWidget()
hgs
parents: 29
diff changeset
    45
{
hgs
parents: 29
diff changeset
    46
    TRACE_ENTRY
hgs
parents: 29
diff changeset
    47
    delete mNotificationDialog;
hgs
parents: 29
diff changeset
    48
    return;
hgs
parents: 29
diff changeset
    49
}
hgs
parents: 29
diff changeset
    50
hgs
parents: 29
diff changeset
    51
/*!
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
    Set parameters, implementation of interface
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
    Invoked when HbDeviceDialog::update calls.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    55
bool BtDeviceDialogNotifWidget::setDeviceDialogParameters(
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    const QVariantMap &parameters)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
    mLastError = NoError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
    processParam(parameters);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
    return true;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
    Get error, implementation of interface
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
int BtDeviceDialogNotifWidget::deviceDialogError() const
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
    return mLastError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
    Close notification, implementation of interface
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
 */ 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
void BtDeviceDialogNotifWidget::closeDeviceDialog(bool byClient)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
    Q_UNUSED(byClient);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
    // Closed by client or internally by server -> no action to be transmitted.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
    mSendAction = false;
42
hgs
parents: 29
diff changeset
    84
    mNotificationDialog->close();
hgs
parents: 29
diff changeset
    85
     // If show event has been received, close is signalled from hide event. If not,
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
    // hide event does not come and close is signalled from here.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
    if (!mShowEventReceived) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
        emit deviceDialogClosed();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
    Return display widget, implementation of interface
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
 */
42
hgs
parents: 29
diff changeset
    96
HbPopup *BtDeviceDialogNotifWidget::deviceDialogWidget() const
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
    TRACE_EXIT
42
hgs
parents: 29
diff changeset
   100
    return mNotificationDialog;
hgs
parents: 29
diff changeset
   101
}
hgs
parents: 29
diff changeset
   102
hgs
parents: 29
diff changeset
   103
QObject* BtDeviceDialogNotifWidget::signalSender() const
hgs
parents: 29
diff changeset
   104
    {
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
    return const_cast<BtDeviceDialogNotifWidget*>(this);
42
hgs
parents: 29
diff changeset
   106
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    Construct display widget
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
 */
42
hgs
parents: 29
diff changeset
   111
bool BtDeviceDialogNotifWidget::constructNotifDialog(const QVariantMap &parameters)
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   113
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
    // analyze the parameters to compose the properties of the message box widget 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
    processParam(parameters);
42
hgs
parents: 29
diff changeset
   116
    connect(mNotificationDialog, SIGNAL(finished(HbAction*)), this, SLOT(NotifClosed(HbAction*)));
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   117
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
    return true;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   120
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   121
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   122
    Take parameter values and generate relevant property of this widget
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   123
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
void BtDeviceDialogNotifWidget::processParam(const QVariantMap &parameters)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   125
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   126
    TRACE_ENTRY
42
hgs
parents: 29
diff changeset
   127
    QString keyStr, prompt,title;
hgs
parents: 29
diff changeset
   128
    QVariant classOfDevice;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   129
    keyStr.setNum( TBluetoothDialogParams::EResource );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   130
    // Validate if the resource item exists.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   131
    QVariantMap::const_iterator i = parameters.constFind( keyStr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   132
    // item of ResourceId is not found, can't continue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   133
    if ( i == parameters.constEnd() ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   134
        mLastError = UnknownDeviceDialogError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   135
        return;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
    }
42
hgs
parents: 29
diff changeset
   137
    HbIcon icon;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
    QVariant param = parameters.value( keyStr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
    int key = param.toInt();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
    switch ( key ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   141
        case EPairingSuccess:
42
hgs
parents: 29
diff changeset
   142
            title = QString(hbTrId( "txt_bt_dpophead_paired" ));
hgs
parents: 29
diff changeset
   143
            prompt = QString( hbTrId( "txt_bt_dpopinfo_paired_to_1" ) );
hgs
parents: 29
diff changeset
   144
            classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
hgs
parents: 29
diff changeset
   145
            icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
hgs
parents: 29
diff changeset
   146
            mNotificationDialog->setIcon(icon);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
            break;
42
hgs
parents: 29
diff changeset
   148
        // todo: remove this Unpaired notification if not used
hgs
parents: 29
diff changeset
   149
        case EUnpairedDevice:
hgs
parents: 29
diff changeset
   150
            title = QString(hbTrId( "txt_bt_dpophead_unpaired" ));
hgs
parents: 29
diff changeset
   151
            prompt = QString( hbTrId( "txt_bt_dpopinfo_with_1" ) );
hgs
parents: 29
diff changeset
   152
            classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
hgs
parents: 29
diff changeset
   153
            icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
hgs
parents: 29
diff changeset
   154
            mNotificationDialog->setIcon(icon);
hgs
parents: 29
diff changeset
   155
            break;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
        case EVisibilityTimeout:
42
hgs
parents: 29
diff changeset
   157
            title = QString(hbTrId( "txt_bt_dpophead_bluetooth" ));
hgs
parents: 29
diff changeset
   158
            prompt = QString( hbTrId( "txt_bt_dpopinfo_is_now_hidden" ) );
hgs
parents: 29
diff changeset
   159
            mNotificationDialog->setIcon(HbIcon("qtg_large_bluetooth"));
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   160
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   161
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   162
            mLastError = ParameterError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   163
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   164
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
    int repls = prompt.count( QString( "%" ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   166
    if ( repls > 0 ) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   167
        QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   168
        prompt = prompt.arg( name.toString() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
    }
42
hgs
parents: 29
diff changeset
   170
    mNotificationDialog->setTitle( title );
hgs
parents: 29
diff changeset
   171
    mNotificationDialog->setText( prompt );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
    Reset properties to default values
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   177
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
void BtDeviceDialogNotifWidget::resetProperties()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   180
    TRACE_ENTRY
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
    mSendAction = true;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
    TRACE_EXIT
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
    return;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
42
hgs
parents: 29
diff changeset
   186
void BtDeviceDialogNotifWidget::NotifClosed(HbAction *action)
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
{
42
hgs
parents: 29
diff changeset
   188
    Q_UNUSED(action);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
    emit deviceDialogClosed();
42
hgs
parents: 29
diff changeset
   190
    mSendAction = false;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   191
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   192