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