bluetoothengine/btindicator/src/btindicator.cpp
author hgs
Tue, 19 Oct 2010 15:09:34 +0300
changeset 70 f5508c13dfe0
parent 42 b72428996822
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 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:
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
#include "btindicator.h" 
hgs
parents:
diff changeset
    18
#include <QVariant.h>
hgs
parents:
diff changeset
    19
#include "btindicatorconstants.h"
70
hgs
parents: 42
diff changeset
    20
hgs
parents: 42
diff changeset
    21
hgs
parents: 42
diff changeset
    22
#define LOC_BLUETOOTH hbTrId("txt_bt_dblist_bluetooth") 
hgs
parents: 42
diff changeset
    23
hgs
parents: 42
diff changeset
    24
const QString BT_APPLICATION("btcpplugin.dll");
42
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
struct BTIndicatorInfo
70
hgs
parents: 42
diff changeset
    27
{
hgs
parents: 42
diff changeset
    28
    QString DecorationIcon;
hgs
parents: 42
diff changeset
    29
    QString MonoDecorationIcon;
hgs
parents: 42
diff changeset
    30
};
42
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
static const int BTIndicatorCount = 5;
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
static const BTIndicatorInfo IndicatorInfo[BTIndicatorCount] = { 
70
hgs
parents: 42
diff changeset
    36
     { "qtg_large_bluetooth_off", "qtg_status_bluetooth_off" },
hgs
parents: 42
diff changeset
    37
     { "qtg_large_bluetooth","qtg_status_bluetooth" },
hgs
parents: 42
diff changeset
    38
     { "qtg_large_bluetooth_hide","qtg_status_bluetooth_hide" },
hgs
parents: 42
diff changeset
    39
     { "qtg_large_bluetooth_active_connection", "qtg_status_bluetooth_connection"},
hgs
parents: 42
diff changeset
    40
     { "qtg_large_bluetooth_hide_connection", "qtg_status_bluetooth_hide_connection"}
42
hgs
parents:
diff changeset
    41
 };
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    45
// BTIndicator::BTIndicator
hgs
parents:
diff changeset
    46
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    47
BTIndicator::BTIndicator(const QString &indicatorType) :
hgs
parents:
diff changeset
    48
HbIndicatorInterface(indicatorType,
hgs
parents:
diff changeset
    49
        HbIndicatorInterface::SettingCategory ,
70
hgs
parents: 42
diff changeset
    50
        InteractionActivated),mRequest(0),mIndicatorStatus(0),mIndicatorlaunch(false)
hgs
parents: 42
diff changeset
    51
{
hgs
parents: 42
diff changeset
    52
    mSecondaryText << hbTrId("txt_bt_dblist_bluetooth_val_off")
hgs
parents: 42
diff changeset
    53
            << hbTrId("txt_bt_dblist_bluetooth_val_on_and_visible")
hgs
parents: 42
diff changeset
    54
            << hbTrId("txt_bt_dblist_bluetooth_val_on_and_hidden")
hgs
parents: 42
diff changeset
    55
            << hbTrId("txt_bt_dblist_bluetooth_val_visible_and_connected")
hgs
parents: 42
diff changeset
    56
            << hbTrId("txt_bt_dblist_bluetooth_val_hidden_and_connected");
hgs
parents: 42
diff changeset
    57
}
42
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    60
// BTIndicator::~BTIndicator
hgs
parents:
diff changeset
    61
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    62
BTIndicator::~BTIndicator()
70
hgs
parents: 42
diff changeset
    63
{
hgs
parents: 42
diff changeset
    64
	delete mRequest;
hgs
parents: 42
diff changeset
    65
}
42
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
// BTIndicator::handleInteraction
hgs
parents:
diff changeset
    70
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
bool BTIndicator::handleInteraction(InteractionType type)
70
hgs
parents: 42
diff changeset
    72
{
42
hgs
parents:
diff changeset
    73
    if (type == InteractionActivated) 
70
hgs
parents: 42
diff changeset
    74
	{
hgs
parents: 42
diff changeset
    75
 /*       if(!mIndicatorlaunch)
hgs
parents: 42
diff changeset
    76
            {
hgs
parents: 42
diff changeset
    77
            launchBTCpSettingView();
hgs
parents: 42
diff changeset
    78
            mIndicatorlaunch = true;
hgs
parents: 42
diff changeset
    79
            }*/
hgs
parents: 42
diff changeset
    80
        
hgs
parents: 42
diff changeset
    81
	}
42
hgs
parents:
diff changeset
    82
    return true;
70
hgs
parents: 42
diff changeset
    83
}
42
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    86
// BTIndicator::indicatorData
hgs
parents:
diff changeset
    87
// returns the data and icon that needs to be displayed in the universal pop up and indicator menu 
hgs
parents:
diff changeset
    88
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
    89
QVariant BTIndicator::indicatorData(int role) const
hgs
parents:
diff changeset
    90
{
70
hgs
parents: 42
diff changeset
    91
	QVariant data("");
42
hgs
parents:
diff changeset
    92
70
hgs
parents: 42
diff changeset
    93
    if(mIndicatorStatus == 0)
hgs
parents: 42
diff changeset
    94
	{
hgs
parents: 42
diff changeset
    95
		data = QString();
hgs
parents: 42
diff changeset
    96
	}
hgs
parents: 42
diff changeset
    97
    else
hgs
parents: 42
diff changeset
    98
	{
hgs
parents: 42
diff changeset
    99
        switch(role) {
hgs
parents: 42
diff changeset
   100
            case PrimaryTextRole: 
hgs
parents: 42
diff changeset
   101
				data = QString(LOC_BLUETOOTH);
hgs
parents: 42
diff changeset
   102
				break;
hgs
parents: 42
diff changeset
   103
            case SecondaryTextRole:
hgs
parents: 42
diff changeset
   104
				data = mSecondaryText[mIndicatorStatus];
hgs
parents: 42
diff changeset
   105
				break;
hgs
parents: 42
diff changeset
   106
            case DecorationNameRole:
hgs
parents: 42
diff changeset
   107
				data = IndicatorInfo[mIndicatorStatus].DecorationIcon;
hgs
parents: 42
diff changeset
   108
				break;
hgs
parents: 42
diff changeset
   109
            case MonoDecorationNameRole :
hgs
parents: 42
diff changeset
   110
				data =  IndicatorInfo[mIndicatorStatus].MonoDecorationIcon;
hgs
parents: 42
diff changeset
   111
				break;
hgs
parents: 42
diff changeset
   112
            default: 
hgs
parents: 42
diff changeset
   113
                data = QString();      
hgs
parents: 42
diff changeset
   114
				break;
hgs
parents: 42
diff changeset
   115
		}
hgs
parents: 42
diff changeset
   116
	}
hgs
parents: 42
diff changeset
   117
	return data;
42
hgs
parents:
diff changeset
   118
}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   121
// BTIndicator::handleClientRequest
hgs
parents:
diff changeset
   122
// handles client's activate and deactivate request
hgs
parents:
diff changeset
   123
// ----------------------------------------------------------------------------
hgs
parents:
diff changeset
   124
bool BTIndicator::handleClientRequest( RequestType type, 
hgs
parents:
diff changeset
   125
        const QVariant &parameter)
70
hgs
parents: 42
diff changeset
   126
{
42
hgs
parents:
diff changeset
   127
    bool handled(false);
hgs
parents:
diff changeset
   128
    switch (type) {
hgs
parents:
diff changeset
   129
        case RequestActivate:
hgs
parents:
diff changeset
   130
            {
hgs
parents:
diff changeset
   131
            mIndicatorStatus = parameter.toInt();
70
hgs
parents: 42
diff changeset
   132
            if(( !mIndicatorStatus )&&( !mIndicatorlaunch ))
hgs
parents: 42
diff changeset
   133
                {
hgs
parents: 42
diff changeset
   134
	            mSecondaryText = QStringList();
hgs
parents: 42
diff changeset
   135
                emit deactivate();
hgs
parents: 42
diff changeset
   136
                }
hgs
parents: 42
diff changeset
   137
            else
hgs
parents: 42
diff changeset
   138
                {
hgs
parents: 42
diff changeset
   139
                emit dataChanged();
hgs
parents: 42
diff changeset
   140
                }
42
hgs
parents:
diff changeset
   141
            handled =  true;
hgs
parents:
diff changeset
   142
            }
hgs
parents:
diff changeset
   143
            break;
70
hgs
parents: 42
diff changeset
   144
        case RequestDeactivate:
42
hgs
parents:
diff changeset
   145
            {
70
hgs
parents: 42
diff changeset
   146
            mSecondaryText = QStringList();
hgs
parents: 42
diff changeset
   147
            mIndicatorStatus  = 0;
42
hgs
parents:
diff changeset
   148
            emit deactivate();
hgs
parents:
diff changeset
   149
            }
hgs
parents:
diff changeset
   150
            break;
70
hgs
parents: 42
diff changeset
   151
        default:
hgs
parents: 42
diff changeset
   152
            break;
42
hgs
parents:
diff changeset
   153
    }
hgs
parents:
diff changeset
   154
    return handled;
70
hgs
parents: 42
diff changeset
   155
}
42
hgs
parents:
diff changeset
   156
hgs
parents:
diff changeset
   157
70
hgs
parents: 42
diff changeset
   158
void BTIndicator::launchBTCpSettingView()
hgs
parents: 42
diff changeset
   159
{
hgs
parents: 42
diff changeset
   160
    if(!mRequest)
42
hgs
parents:
diff changeset
   161
    {
70
hgs
parents: 42
diff changeset
   162
        mRequest = mAppMgr.create("com.nokia.symbian.ICpPluginLauncher","launchSettingView(QString,QVariant)",false);
hgs
parents: 42
diff changeset
   163
hgs
parents: 42
diff changeset
   164
        if (!mRequest)
hgs
parents: 42
diff changeset
   165
        {
hgs
parents: 42
diff changeset
   166
           qDebug("BTIndicator request returned with NULL");
hgs
parents: 42
diff changeset
   167
            return;
hgs
parents: 42
diff changeset
   168
        }
hgs
parents: 42
diff changeset
   169
        else
hgs
parents: 42
diff changeset
   170
        {
hgs
parents: 42
diff changeset
   171
            connect(mRequest, SIGNAL(requestOk(QVariant)), SLOT(handleReturnValue(QVariant)));
hgs
parents: 42
diff changeset
   172
            connect(mRequest, SIGNAL(requestError(int,QString)), SLOT(handleError(int,QString)));
hgs
parents: 42
diff changeset
   173
            // Set arguments for request 
hgs
parents: 42
diff changeset
   174
            QList<QVariant> args;
hgs
parents: 42
diff changeset
   175
            args << QVariant(BT_APPLICATION);
hgs
parents: 42
diff changeset
   176
            mRequest->setArguments(args);
hgs
parents: 42
diff changeset
   177
            mRequest->setSynchronous(false);
hgs
parents: 42
diff changeset
   178
        }
42
hgs
parents:
diff changeset
   179
    }
70
hgs
parents: 42
diff changeset
   180
        // Make the request
hgs
parents: 42
diff changeset
   181
    if (!mRequest->send())
42
hgs
parents:
diff changeset
   182
    {
hgs
parents:
diff changeset
   183
        //report error  
hgs
parents:
diff changeset
   184
        qDebug("BTIndicator::launchBTCpSettingView request not sent");
hgs
parents:
diff changeset
   185
    }
70
hgs
parents: 42
diff changeset
   186
	
hgs
parents: 42
diff changeset
   187
/*	QString service("com.nokia.symbian.ICpPluginLauncher");
hgs
parents: 42
diff changeset
   188
    QString operation("launchSettingView(QString,QVariant)");
hgs
parents: 42
diff changeset
   189
    QList<QVariant> args;
hgs
parents: 42
diff changeset
   190
    XQAiwRequest* request;
hgs
parents: 42
diff changeset
   191
    XQApplicationManager appManager;
hgs
parents: 42
diff changeset
   192
    request = appManager.create(service, operation, false); // not embedded
hgs
parents: 42
diff changeset
   193
    if ( request == NULL )
hgs
parents: 42
diff changeset
   194
        {
hgs
parents: 42
diff changeset
   195
        //Could not create request because of the arguments passed to the create() API.
hgs
parents: 42
diff changeset
   196
        User::Leave(KErrArgument);       
hgs
parents: 42
diff changeset
   197
        }
hgs
parents: 42
diff changeset
   198
    args << QVariant("btcpplugin.dll");
hgs
parents: 42
diff changeset
   199
    request->setArguments(args);
hgs
parents: 42
diff changeset
   200
    TInt error = KErrNone;
hgs
parents: 42
diff changeset
   201
    if(!request->send())
hgs
parents: 42
diff changeset
   202
        {
hgs
parents: 42
diff changeset
   203
        // The only likely Symbian error code that can be associated is KErrNotSupported
hgs
parents: 42
diff changeset
   204
        
hgs
parents: 42
diff changeset
   205
        }
hgs
parents: 42
diff changeset
   206
    delete request;*/
42
hgs
parents:
diff changeset
   207
    
70
hgs
parents: 42
diff changeset
   208
hgs
parents: 42
diff changeset
   209
}
42
hgs
parents:
diff changeset
   210
hgs
parents:
diff changeset
   211
70
hgs
parents: 42
diff changeset
   212
void BTIndicator::handleReturnValue(const QVariant &returnValue)
42
hgs
parents:
diff changeset
   213
{
70
hgs
parents: 42
diff changeset
   214
    Q_UNUSED(returnValue);
hgs
parents: 42
diff changeset
   215
    mIndicatorlaunch = false;
hgs
parents: 42
diff changeset
   216
    if(!mIndicatorStatus )
hgs
parents: 42
diff changeset
   217
	{
hgs
parents: 42
diff changeset
   218
        emit deactivate();
hgs
parents: 42
diff changeset
   219
	}
42
hgs
parents:
diff changeset
   220
}
hgs
parents:
diff changeset
   221
hgs
parents:
diff changeset
   222
void BTIndicator::handleError(int errorCode,const QString &errorMessage)
70
hgs
parents: 42
diff changeset
   223
{
42
hgs
parents:
diff changeset
   224
    Q_UNUSED(errorCode);
70
hgs
parents: 42
diff changeset
   225
    Q_UNUSED(errorMessage);
hgs
parents: 42
diff changeset
   226
    mIndicatorlaunch = false;
hgs
parents: 42
diff changeset
   227
}