bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.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:  BtDeviceDialogPlugin class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "btdevicedialogplugin.h"
       
    20 #include "btdevicedialogplugintrace.h"
       
    21 #include <bluetoothdevicedialogs.h>
       
    22 #include <QtPlugin>
       
    23 #include <hbdevicedialog.h>
       
    24 #include "btdevicedialoginputwidget.h"
       
    25 #include "btdevicedialogquerywidget.h"
       
    26 #include "btdevicedialognotifwidget.h"
       
    27 #include "btrecvprgrsdialogwidget.h"
       
    28 
       
    29 #include "btdevicedialogpluginerrors.h"
       
    30 #include "btdevicesearchdialogwidget.h"
       
    31 #include "btmoredevicesdialogwidget.h"
       
    32 #include "btsenddialogwidget.h"
       
    33 #include "btdevicedialogrecvquerywidget.h"
       
    34 #include "btrecvcompleteddialogwidget.h"
       
    35 #include <hbtranslator.h>
       
    36 
       
    37 Q_EXPORT_PLUGIN2(btdevicedialogplugin, BtDeviceDialogPlugin)
       
    38 
       
    39 const char* BTDIALOG_TRANSLATION = "btdialogs";
       
    40 const char* BTVIEW_TRANSLATION = "btviews";        
       
    41 
       
    42 // This plugin implements one device dialog type
       
    43 static const struct {
       
    44     const char *mTypeString;
       
    45 } noteInfos[] = {
       
    46     {"com.nokia.hb.btdevicedialog/1.0"}
       
    47 };
       
    48 
       
    49 class BtDeviceDialogPluginPrivate
       
    50 {
       
    51 public:
       
    52     BtDeviceDialogPluginPrivate();
       
    53 public:
       
    54     int mError;
       
    55 };
       
    56 /*! 
       
    57     BtDeviceDialogPluginPrivate Constructor
       
    58  */
       
    59 BtDeviceDialogPluginPrivate::BtDeviceDialogPluginPrivate()
       
    60 {
       
    61     mError = NoError;
       
    62 }
       
    63 
       
    64 /*! 
       
    65     BtDeviceDialogPlugin Constructor
       
    66  */
       
    67 BtDeviceDialogPlugin::BtDeviceDialogPlugin():
       
    68  mDialogTranslator(0),mViewTranslator(0)
       
    69 {
       
    70     d = new BtDeviceDialogPluginPrivate;
       
    71 }
       
    72 
       
    73 /*!
       
    74     Destructor
       
    75  */
       
    76 BtDeviceDialogPlugin::~BtDeviceDialogPlugin()
       
    77 {
       
    78     delete d;
       
    79     delete mDialogTranslator;
       
    80     delete mViewTranslator;
       
    81 }
       
    82 
       
    83 /*! 
       
    84     Check if client is allowed to use device dialog widget
       
    85  */
       
    86 bool BtDeviceDialogPlugin::accessAllowed(const QString &deviceDialogType,
       
    87     const QVariantMap &parameters, const QVariantMap &securityInfo) const
       
    88 {
       
    89     Q_UNUSED(deviceDialogType)
       
    90     Q_UNUSED(parameters)
       
    91     Q_UNUSED(securityInfo)
       
    92 
       
    93     // This plugin doesn't perform operations that may compromise security.
       
    94     // All clients are allowed to use.
       
    95     return true;
       
    96 }
       
    97 
       
    98 /*! 
       
    99     From interface class.
       
   100     Use the dialog type in the parameter to create widget.    
       
   101  */
       
   102 HbDeviceDialogInterface *BtDeviceDialogPlugin::createDeviceDialog(
       
   103     const QString &deviceDialogType, const QVariantMap &parameters)
       
   104 {
       
   105     d->mError = NoError;
       
   106 
       
   107     int i;
       
   108     
       
   109     if(!mDialogTranslator)
       
   110         {
       
   111         mDialogTranslator = new HbTranslator(BTDIALOG_TRANSLATION);
       
   112         }
       
   113     if(!mViewTranslator)
       
   114         {
       
   115         mViewTranslator = new HbTranslator(BTVIEW_TRANSLATION);
       
   116         }
       
   117     // verify that requested dialog type is supported
       
   118     const int numTypes = sizeof(noteInfos) / sizeof(noteInfos[0]);
       
   119     for(i = 0; i < numTypes; i++) {
       
   120         if (noteInfos[i].mTypeString == deviceDialogType) {
       
   121             break;
       
   122         }
       
   123     }
       
   124     // dialog type was found
       
   125     if (i < numTypes) {
       
   126         return checkDialogType( parameters );
       
   127     } 
       
   128     else {
       
   129         // unknown dialog type, return error
       
   130         d->mError = UnknownDeviceDialogError;
       
   131         return 0;
       
   132     }
       
   133 }
       
   134 
       
   135 /*! 
       
   136     Return information of device dialog the plugin creates
       
   137     Currently only supporting 1 device dialog type, so no need to check the type.
       
   138  */
       
   139 bool BtDeviceDialogPlugin::deviceDialogInfo(const QString &deviceDialogType,
       
   140     const QVariantMap &parameters, DeviceDialogInfo *info) const
       
   141 {
       
   142     Q_UNUSED(parameters)
       
   143     Q_UNUSED(deviceDialogType)
       
   144     // set return values
       
   145     info->group = GenericDeviceDialogGroup;
       
   146     info->flags = NoDeviceDialogFlags;
       
   147     info->priority = DefaultPriority;
       
   148     return true;
       
   149 }
       
   150 
       
   151 /*! 
       
   152     Return device dialog types this plugin implements
       
   153     Function will work fine (unchanged) when new dialogs are added.
       
   154  */
       
   155 QStringList BtDeviceDialogPlugin::deviceDialogTypes() const
       
   156 {
       
   157     QStringList types;
       
   158     // read supported types from noteInfos
       
   159     const int numTypes = sizeof(noteInfos) / sizeof(noteInfos[0]);
       
   160     for(int i = 0; i < numTypes; i++) {
       
   161         types.append(noteInfos[i].mTypeString);
       
   162     }
       
   163     return types;
       
   164 }
       
   165 
       
   166 /*! 
       
   167     Return plugin flags
       
   168  */
       
   169 HbDeviceDialogPlugin::PluginFlags BtDeviceDialogPlugin::pluginFlags() const
       
   170 {
       
   171     return NoPluginFlags;
       
   172 }
       
   173 
       
   174 /*! 
       
   175     Return last error
       
   176  */
       
   177 int BtDeviceDialogPlugin::error() const
       
   178 {
       
   179     return d->mError;
       
   180 }
       
   181 
       
   182 /*!
       
   183     Check the device dialog type to decide which widget to be used. 
       
   184     And create the specified widget.
       
   185  */
       
   186 HbDeviceDialogInterface *BtDeviceDialogPlugin::checkDialogType( const QVariantMap &parameters )
       
   187 {
       
   188     // Construct the key of EDialogType
       
   189     QString keyStr;
       
   190     keyStr.setNum( TBluetoothDialogParams::EDialogType );
       
   191     // Find the const iterator with key EDialogType
       
   192     QVariantMap::const_iterator i = parameters.constFind( keyStr );
       
   193 
       
   194     // item with key EDialogType is not found
       
   195     if ( i == parameters.constEnd() ) {
       
   196         d->mError = UnknownDeviceDialogError;
       
   197         return NULL;
       
   198     }
       
   199     
       
   200     // item with key EDialogType is found
       
   201     // generate specified widget based on the dialog type value.
       
   202     HbDeviceDialogInterface *deviceDialog = NULL;
       
   203     switch ( i.value().toInt() ) {
       
   204         case TBluetoothDialogParams::ENote:
       
   205             deviceDialog =
       
   206                 new BtDeviceDialogNotifWidget(parameters);
       
   207             break;
       
   208         case TBluetoothDialogParams::EQuery:
       
   209             deviceDialog =
       
   210                 new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeWarning,parameters);
       
   211             break;
       
   212         case TBluetoothDialogParams::EInput:
       
   213             deviceDialog = new BtDeviceDialogInputWidget(parameters);
       
   214             break;
       
   215         case TBluetoothDialogParams::EMoreDevice:
       
   216             deviceDialog = new BTMoreDevicesDialogWidget(parameters);
       
   217             break;
       
   218         case TBluetoothDialogParams::EDeviceSearch:
       
   219             deviceDialog = new BTDeviceSearchDialogWidget(parameters);
       
   220             break;
       
   221         case TBluetoothDialogParams::ESend:
       
   222             deviceDialog = new BTSendDialogWidget(parameters);
       
   223             break;
       
   224         case TBluetoothDialogParams::EGlobalNotif:
       
   225             deviceDialog = new BtDeviceDialogNotifWidget(parameters);
       
   226             break;
       
   227         case TBluetoothDialogParams::EUserAuthorization:
       
   228             deviceDialog = new BTRecvQueryDialogWidget(parameters);
       
   229             break;
       
   230         case TBluetoothDialogParams::EReceiveProgress:
       
   231             deviceDialog = new BTRecvPrgrsDialogWidget(parameters);
       
   232             break;
       
   233         case TBluetoothDialogParams::EReceiveDone:
       
   234             deviceDialog = new BTRecvcompletedDialogWidget(parameters);
       
   235             break;
       
   236         default:
       
   237             d->mError = UnknownDeviceDialogError;
       
   238             break;
       
   239     }
       
   240     if ( deviceDialog ) {
       
   241         // verify no error has occurred
       
   242         d->mError = deviceDialog->deviceDialogError();
       
   243         if ( d->mError ) {
       
   244             // Do not continue if an error occurred
       
   245             delete deviceDialog;
       
   246             deviceDialog = NULL;
       
   247         }
       
   248         else {
       
   249             d->mError = UnknownDeviceDialogError;
       
   250         }
       
   251     }
       
   252     return deviceDialog;
       
   253 }