bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialognotifwidget.cpp
changeset 70 f5508c13dfe0
parent 57 5ebadcda06cb
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include "btdevicedialognotifwidget.h"
    19 #include "btdevicedialognotifwidget.h"
    20 #include "btdevicedialogplugintrace.h"
    20 #include "btdevicedialogplugintrace.h"
    21 #include <bluetoothdevicedialogs.h>
    21 #include <bluetoothdevicedialogs.h>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbdialog.h>
    23 #include <hbdialog.h>
       
    24 #include <hbparameterlengthlimiter.h>
    24 #include "btdevicedialogpluginerrors.h"
    25 #include "btdevicedialogpluginerrors.h"
    25 #include <btuiiconutil.h>
    26 #include <btuiiconutil.h>
    26 #include <btnotif.h>
    27 #include <btnotif.h>
    27 
    28 
    28 /*!
    29 /*!
   124     Take parameter values and generate relevant property of this widget
   125     Take parameter values and generate relevant property of this widget
   125  */
   126  */
   126 void BtDeviceDialogNotifWidget::processParam(const QVariantMap &parameters)
   127 void BtDeviceDialogNotifWidget::processParam(const QVariantMap &parameters)
   127 {
   128 {
   128     TRACE_ENTRY
   129     TRACE_ENTRY
   129     QString keyStr, prompt,title;
   130     QString keyStr,prompt,title,devName;
   130     QVariant classOfDevice, notifType;
   131     QVariant classOfDevice, notifType, param;
       
   132     HbIcon icon;
       
   133     
   131     keyStr.setNum( TBluetoothDialogParams::EResource );
   134     keyStr.setNum( TBluetoothDialogParams::EResource );
   132     // Validate if the resource item exists.
   135     // Validate if the resource item exists.
   133     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   136     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   134     // item of ResourceId is not found, can't continue.
   137     // item of ResourceId is not found, can't continue.
   135     if ( i == parameters.constEnd() ) {
   138     if ( i == parameters.constEnd() ) {
   136         mLastError = UnknownDeviceDialogError;
   139         mLastError = UnknownDeviceDialogError;
   137         return;
   140         return;
   138     }
   141     }
   139     HbIcon icon;
   142     param = parameters.value( keyStr );
   140     QString textStr;
       
   141     QString devName;
       
   142     QVariant param = parameters.value( keyStr );
       
   143     int key = param.toInt();
   143     int key = param.toInt();
       
   144     
       
   145     keyStr.setNum( TBluetoothDeviceDialog::EDeviceName );
       
   146     i = parameters.constFind( keyStr );
       
   147     if ( i != parameters.constEnd() )
       
   148         {
       
   149         devName = QString(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
       
   150         }
       
   151 
   144     switch ( key ) {
   152     switch ( key ) {
   145         case EPairingSuccess:
   153         case EPairingSuccess:
   146             title = QString(hbTrId( "txt_bt_dpophead_paired" ));
   154             title = QString(hbTrId( "txt_bt_dpophead_paired" ));
   147             prompt = QString( hbTrId( "txt_bt_dpopinfo_paired_to_1" ) );
   155             prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dpopinfo_paired_to_1" )).arg(devName);
   148             classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   156             classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   149             icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   157             icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   150             mNotificationDialog->setIcon(icon);
   158             mNotificationDialog->setIcon(icon);
   151             break;
   159             break;
   152         // todo: remove this Unpaired notification if not used
   160         // todo: remove this Unpaired notification if not used
   153         case EUnpairedDevice:
   161         case EUnpairedDevice:
   154             title = QString(hbTrId( "txt_bt_dpophead_unpaired" ));
   162             title = QString(hbTrId( "txt_bt_dpophead_unpaired" ));
   155             prompt = QString( hbTrId( "txt_bt_dpopinfo_with_1" ) );
   163             prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dpopinfo_with_1" )).arg(devName);
   156             classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   164             classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   157             icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   165             icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   158             mNotificationDialog->setIcon(icon);
   166             mNotificationDialog->setIcon(icon);
   159             break;
   167             break;
   160         case EVisibilityTimeout:
   168         case EVisibilityTimeout:
   168             int type = notifType.toInt();
   176             int type = notifType.toInt();
   169             switch (notifType.toInt())
   177             switch (notifType.toInt())
   170                 {
   178                 {
   171                 case EBTConnected:
   179                 case EBTConnected:
   172                     title = QString(hbTrId( "txt_bt_dpophead_connected" ));
   180                     title = QString(hbTrId( "txt_bt_dpophead_connected" ));
   173                     prompt = QString( hbTrId( "txt_bt_dpopinfo_connected_to_1" ) );
   181                     prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dpopinfo_connected_to_1" )).arg(devName);
   174                     classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   182                     classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   175                     icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   183                     icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   176                     mNotificationDialog->setIcon(icon);
   184                     mNotificationDialog->setIcon(icon);
   177                     break;
   185                     break;
   178                 case EBTClosed:
   186                 case EBTClosed:
   179                     title = QString(hbTrId( "txt_bt_dpophead_disconnected" ));
   187                     title = QString(hbTrId( "txt_bt_dpophead_disconnected" ));
   180                     prompt = QString( hbTrId( "txt_bt_dpopinfo_disconnected_from_1" ) );
   188                     prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dpopinfo_disconnected_from_1" )).arg(devName);
   181                     classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   189                     classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
   182                     icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   190                     icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
   183                     mNotificationDialog->setIcon(icon);
   191                     mNotificationDialog->setIcon(icon);
   184                     break;
   192                     break;
       
   193                 case EBTSapOk:
       
   194                     title = QString(hbTrId( "txt_bt_dpophead_sim_access_profile" ));
       
   195                     prompt = QString( hbTrId( "txt_bt_dpopinfo_in_use" ) );
       
   196                     classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
       
   197                     icon = QString("qtg_large_bluetooth");
       
   198                     mNotificationDialog->setIcon(icon);
       
   199                     break;
       
   200                 case EBTSwitchedOn:
       
   201                     title = QString(hbTrId("txt_bt_dpophead_bluetooth"));
       
   202                     prompt = QString(hbTrId("txt_bt_dpopinfo_is_now_on"));
       
   203                     icon = QString("qtg_large_bluetooth");
       
   204                     mNotificationDialog->setIcon(icon);
       
   205                     break;
       
   206                 case EBTSwitchedOff:
       
   207                     title = QString(hbTrId("txt_bt_dpophead_bluetooth"));
       
   208                     prompt = QString(hbTrId("txt_bt_dpopinfo_is_now_off"));
       
   209                     icon = QString("qtg_large_bluetooth");
       
   210                     mNotificationDialog->setIcon(icon);
       
   211                     break;
       
   212                 // not used anymore?
       
   213                 case EBTEnterSap:
       
   214                 // EnterSAP is handled in another dialog type
       
   215                 case EBTSapNoSim:
       
   216                 case EBTSapFailed:
       
   217                 // SapNoSIM and SAP Failed handled in another dialog type
       
   218                 case EIRNotSupported:
       
   219                 case EBTVisibilityTimeout:                    
       
   220                 case EBTAudioAccessory:
       
   221                 case EBTAudioHandset:
   185                 case EBTDisconnected:
   222                 case EBTDisconnected:
   186                 case EBTDeviceNotAvailable:
   223                 case EBTDeviceNotAvailable:
   187                 case EBTOfflineDisabled:
   224                 case EBTOfflineDisabled:
   188                 case EBTEnterSap:
       
   189                 case EBTSapOk:
       
   190                 case EBTSapFailed:
       
   191                 case EBTSapNoSim:
       
   192                 case EBTDeviceBusy:
   225                 case EBTDeviceBusy:
   193                 case ECmdShowBtBatteryLow:
   226                 case ECmdShowBtBatteryLow:
   194                 case ECmdShowBtBatteryCritical:
   227                 case ECmdShowBtBatteryCritical:
   195                 case EBTStayPowerOn:
   228                 case EBTStayPowerOn:
   196                     break;
       
   197                 case EBTSwitchedOn:
       
   198                     title = QString(hbTrId("txt_bt_dpophead_bluetooth"));
       
   199                     prompt = QString(hbTrId("txt_bt_dpopinfo_is_now_on"));
       
   200                     icon = QString("qtg_large_bluetooth");
       
   201                     mNotificationDialog->setIcon(icon);
       
   202                     break;
       
   203                 case EBTSwitchedOff:
       
   204                     title = QString(hbTrId("txt_bt_dpophead_bluetooth"));
       
   205                     prompt = QString(hbTrId("txt_bt_dpopinfo_is_now_off"));
       
   206                     icon = QString("qtg_large_bluetooth");
       
   207                     mNotificationDialog->setIcon(icon);
       
   208                     break;
       
   209                 // not used anymore?
       
   210                 case EIRNotSupported:
       
   211                 case EBTVisibilityTimeout:                    
       
   212                 case EBTAudioAccessory:
       
   213                 case EBTAudioHandset:
       
   214                 default:
   229                 default:
       
   230                     mLastError = ParameterError;
   215                     break;
   231                     break;
   216                 }
   232                 }
   217             break;
   233             break;
   218             }
   234             }
   219         case EBluetoothTestMode:
   235         case EBluetoothTestMode:
   223             mNotificationDialog->setIcon(icon);
   239             mNotificationDialog->setIcon(icon);
   224             break;
   240             break;
   225             
   241             
   226         case ESendCompleted:
   242         case ESendCompleted:
   227             title = QString(hbTrId("txt_bt_dpophead_all_files_sent"));
   243             title = QString(hbTrId("txt_bt_dpophead_all_files_sent"));
   228             textStr = QString(hbTrId("txt_bt_dpopinfo_sent_to_1"));
   244             prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dpopinfo_sent_to_1")).arg(devName);
   229             devName = QString(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
       
   230             prompt = QString(textStr.arg(devName));
       
   231             icon = getBadgedDeviceTypeIcon(parameters.value(
   245             icon = getBadgedDeviceTypeIcon(parameters.value(
   232                     QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble());
   246                     QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble());
   233             mNotificationDialog->setIcon(icon);
   247             mNotificationDialog->setIcon(icon);
   234             break;
   248             break;
   235         
   249         
   236         /*case ESendCancelled:
   250         /*case ESendCancelled:
   237             title = QString(hbTrId("txt_bt_dpophead_sending_cancelled"));
   251             title = QString(hbTrId("txt_bt_dpophead_sending_cancelled"));
   238             textStr = QString(hbTrId("txt_bt_dpopinfo_sent_to_1"));
   252             prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dpopinfo_sent_to_1")).arg(devName);
   239             devName = QString(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString());
       
   240             prompt = QString(textStr.arg(devName));
       
   241             icon = getBadgedDeviceTypeIcon(parameters.value(QString::number(
   253             icon = getBadgedDeviceTypeIcon(parameters.value(QString::number(
   242                     TBluetoothDeviceDialog::EDeviceClass)).toDouble());
   254                     TBluetoothDeviceDialog::EDeviceClass)).toDouble());
   243             mNotificationDialog->setIcon(icon);
   255             mNotificationDialog->setIcon(icon);
   244             break;*/
   256             break;*/
   245 
   257 
   246         default:
   258         default:
   247             mLastError = ParameterError;
   259             mLastError = ParameterError;
   248             break;
   260             break;
   249     }
       
   250     int repls = prompt.count( QString( "%" ) );
       
   251     if ( repls > 0 ) {
       
   252         QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
       
   253         prompt = prompt.arg( name.toString() );
       
   254     }
   261     }
   255     mNotificationDialog->setTitle( title );
   262     mNotificationDialog->setTitle( title );
   256     mNotificationDialog->setText( prompt );
   263     mNotificationDialog->setText( prompt );
   257     TRACE_EXIT
   264     TRACE_EXIT
   258 }
   265 }