diff -r f05641c183ff -r 43824b19ee35 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogplugin.cpp Fri May 14 16:01:46 2010 +0300 @@ -0,0 +1,217 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogPlugin class implementation. +* +*/ + + +#include "btdevicedialogplugin.h" +#include "btdevicedialogplugintrace.h" +#include +#include +#include +#include "btdevicedialoginputwidget.h" +#include "btdevicedialogquerywidget.h" +#include "btdevicedialognotifwidget.h" + +#include "btdevicedialogpluginerrors.h" +#include "btdevicesearchdialogwidget.h" + +Q_EXPORT_PLUGIN2(btdevicedialogplugin, BtDeviceDialogPlugin) + +// This plugin implements one device dialog type +static const struct { + const char *mTypeString; +} noteInfos[] = { + {"com.nokia.hb.btdevicedialog/1.0"} +}; + +class BtDeviceDialogPluginPrivate +{ +public: + BtDeviceDialogPluginPrivate(); +public: + int mError; +}; +/*! + BtDeviceDialogPluginPrivate Constructor + */ +BtDeviceDialogPluginPrivate::BtDeviceDialogPluginPrivate() +{ + mError = NoError; +} + +/*! + BtDeviceDialogPlugin Constructor + */ +BtDeviceDialogPlugin::BtDeviceDialogPlugin() +{ + d = new BtDeviceDialogPluginPrivate; +} + +/*! + Destructor + */ +BtDeviceDialogPlugin::~BtDeviceDialogPlugin() +{ + delete d; +} + +/*! + Check if client is allowed to use device dialog widget + */ +bool BtDeviceDialogPlugin::accessAllowed(const QString &deviceDialogType, + const QVariantMap ¶meters, const QVariantMap &securityInfo) const +{ + Q_UNUSED(deviceDialogType) + Q_UNUSED(parameters) + Q_UNUSED(securityInfo) + + // This plugin doesn't perform operations that may compromise security. + // All clients are allowed to use. + return true; +} + +/*! + From interface class. + Use the dialog type in the parameter to create widget. + */ +HbDeviceDialogInterface *BtDeviceDialogPlugin::createDeviceDialog( + const QString &deviceDialogType, const QVariantMap ¶meters) +{ + d->mError = NoError; + + int i; + // verify that requested dialog type is supported + const int numTypes = sizeof(noteInfos) / sizeof(noteInfos[0]); + for(i = 0; i < numTypes; i++) { + if (noteInfos[i].mTypeString == deviceDialogType) { + break; + } + } + // dialog type was found + if (i < numTypes) { + return checkDialogType( parameters ); + } + else { + // unknown dialog type, return error + d->mError = UnknownDeviceDialogError; + return 0; + } +} + +/*! + Return information of device dialog the plugin creates + Currently only supporting 1 device dialog type, so no need to check the type. + */ +bool BtDeviceDialogPlugin::deviceDialogInfo(const QString &deviceDialogType, + const QVariantMap ¶meters, DeviceDialogInfo *info) const +{ + Q_UNUSED(parameters) + Q_UNUSED(deviceDialogType) + // set return values + info->group = GenericDeviceDialogGroup; + info->flags = NoDeviceDialogFlags; + info->priority = DefaultPriority; + return true; +} + +/*! + Return device dialog types this plugin implements + Function will work fine (unchanged) when new dialogs are added. + */ +QStringList BtDeviceDialogPlugin::deviceDialogTypes() const +{ + QStringList types; + // read supported types from noteInfos + const int numTypes = sizeof(noteInfos) / sizeof(noteInfos[0]); + for(int i = 0; i < numTypes; i++) { + types.append(noteInfos[i].mTypeString); + } + return types; +} + +/*! + Return plugin flags + */ +HbDeviceDialogPlugin::PluginFlags BtDeviceDialogPlugin::pluginFlags() const +{ + return NoPluginFlags; +} + +/*! + Return last error + */ +int BtDeviceDialogPlugin::error() const +{ + return d->mError; +} + +/*! + Check the device dialog type to decide which widget to be used. + And create the specified widget. + */ +HbDeviceDialogInterface *BtDeviceDialogPlugin::checkDialogType( const QVariantMap ¶meters ) +{ + // Construct the key of EDialogType + QString keyStr; + keyStr.setNum( TBluetoothDialogParams::EDialogType ); + // Find the const iterator with key EDialogType + QVariantMap::const_iterator i = parameters.constFind( keyStr ); + + // item with key EDialogType is not found + if ( i == parameters.constEnd() ) { + d->mError = UnknownDeviceDialogError; + return NULL; + } + + // item with key EDialogType is found + // generate specified widget based on the dialog type value. + HbDeviceDialogInterface *deviceDialog = NULL; + switch ( i.value().toInt() ) { + case TBluetoothDialogParams::ENote: + deviceDialog = + new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeInformation, parameters); + break; + case TBluetoothDialogParams::EQuery: + deviceDialog = + new BtDeviceDialogQueryWidget(HbMessageBox::MessageTypeQuestion, parameters); + break; + case TBluetoothDialogParams::EInput: + deviceDialog = new BtDeviceDialogInputWidget(parameters); + break; + case TBluetoothDialogParams::EDeviceSearch: + deviceDialog = new BTDeviceSearchDialogWidget(parameters); + break; + case TBluetoothDialogParams::EGlobalNotif: + deviceDialog = new BtDeviceDialogNotifWidget(parameters); + break; + default: + d->mError = UnknownDeviceDialogError; + break; + } + if ( deviceDialog ) { + // verify no error has occurred + d->mError = deviceDialog->deviceDialogError(); + if ( d->mError ) { + // Do not continue if an error occurred + delete deviceDialog; + deviceDialog = NULL; + } + else { + d->mError = UnknownDeviceDialogError; + } + } + return deviceDialog; +}