src/hbplugins/devicedialogs/devicemessageboxplugin/hbdevicemessageboxplugin.cpp
changeset 0 16d8024aca5e
child 23 e6ad4ef83b23
child 34 ed14f46c0e55
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <QtPlugin>
       
    27 
       
    28 #include <hbdevicedialog.h>
       
    29 #include <hbdevicedialogtrace_p.h>
       
    30 #include "hbdevicemessageboxplugin_p.h"
       
    31 #include "hbdevicemessageboxwidget_p.h"
       
    32 #include "hbdevicemessageboxpluginerrors_p.h"
       
    33 
       
    34 Q_EXPORT_PLUGIN2(devicemessageboxplugin, HbDeviceMessageBoxPlugin)
       
    35 
       
    36 // This plugin implements one device dialog type
       
    37 static const struct {
       
    38     const char *mTypeString;
       
    39 } dialogInfos[] = {
       
    40     {"com.nokia.hb.devicemessagebox/1.0"}
       
    41 };
       
    42 
       
    43 class HbDeviceMessageBoxPluginPrivate
       
    44 {
       
    45 public:
       
    46     HbDeviceMessageBoxPluginPrivate() {mError = NoError;}
       
    47 
       
    48     int mError;
       
    49 };
       
    50 
       
    51 // Constructor
       
    52 HbDeviceMessageBoxPlugin::HbDeviceMessageBoxPlugin()
       
    53 {
       
    54     TRACE_ENTRY
       
    55     d = new HbDeviceMessageBoxPluginPrivate;
       
    56     TRACE_EXIT
       
    57 }
       
    58 
       
    59 // Destructor
       
    60 HbDeviceMessageBoxPlugin::~HbDeviceMessageBoxPlugin()
       
    61 {
       
    62     TRACE_ENTRY
       
    63     delete d;
       
    64     TRACE_EXIT
       
    65 }
       
    66 
       
    67 // Check if client is allowed to use device dialog widget
       
    68 bool HbDeviceMessageBoxPlugin::accessAllowed(const QString &deviceDialogType,
       
    69     const QVariantMap &parameters, const QVariantMap &securityInfo) const
       
    70 {
       
    71     TRACE_ENTRY
       
    72     Q_UNUSED(deviceDialogType)
       
    73     Q_UNUSED(parameters)
       
    74     Q_UNUSED(securityInfo)
       
    75 
       
    76     // This plugin doesn't perform operations that may compromise security.
       
    77     // All clients are allowed to use.
       
    78     return true;
       
    79     TRACE_EXIT
       
    80 }
       
    81 
       
    82 // Create device dialog widget
       
    83 HbDeviceDialogInterface *HbDeviceMessageBoxPlugin::createDeviceDialog(
       
    84     const QString &deviceDialogType, const QVariantMap &parameters)
       
    85 {
       
    86     TRACE_ENTRY
       
    87     d->mError = NoError;
       
    88     QVariantMap params = parameters;
       
    89 
       
    90     HbDeviceDialogInterface *ret(0);
       
    91     int i(0);
       
    92     const int numTypes = sizeof(dialogInfos) / sizeof(dialogInfos[0]);
       
    93     for(i = 0; i < numTypes; i++) {
       
    94         if (dialogInfos[i].mTypeString == deviceDialogType) {
       
    95             break;
       
    96         }
       
    97     }
       
    98     if (i < numTypes) {
       
    99         // Check the type of message box to be built.
       
   100         HbMessageBox::MessageBoxType type = HbMessageBox::MessageTypeInformation;
       
   101         QVariantMap::const_iterator i = params.constBegin();
       
   102         while (i != params.constEnd()) {
       
   103             if (i.key().toAscii() == "type") {
       
   104                 type = static_cast<HbMessageBox::MessageBoxType>(i.value().toInt());
       
   105                 params.remove(QString("type"));
       
   106                 break;
       
   107             }
       
   108             ++i;
       
   109         }
       
   110         HbDeviceMessageBoxWidget *deviceDialog =
       
   111             new HbDeviceMessageBoxWidget(type, params);
       
   112         d->mError = deviceDialog->deviceDialogError();
       
   113         if (d->mError != NoError) {
       
   114             delete deviceDialog;
       
   115             deviceDialog = 0;
       
   116         }
       
   117         ret = deviceDialog;
       
   118     } else {
       
   119         d->mError = UnknownDeviceDialogError;
       
   120         ret = 0;
       
   121     }
       
   122     TRACE_EXIT
       
   123     return ret;
       
   124 }
       
   125 
       
   126 // Return information of device dialog the plugin creates
       
   127 bool HbDeviceMessageBoxPlugin::deviceDialogInfo(const QString &deviceDialogType,
       
   128     const QVariantMap &parameters, DeviceDialogInfo *info) const
       
   129 {
       
   130     TRACE_ENTRY
       
   131     Q_UNUSED(parameters)
       
   132     Q_UNUSED(deviceDialogType)
       
   133 
       
   134     info->group = GenericDeviceDialogGroup;
       
   135     info->flags = NoDeviceDialogFlags;
       
   136     info->priority = DefaultPriority;
       
   137     TRACE_EXIT
       
   138     return true;
       
   139 }
       
   140 
       
   141 // Return device dialog types this plugin implements
       
   142 QStringList HbDeviceMessageBoxPlugin::deviceDialogTypes() const
       
   143 {
       
   144     TRACE_ENTRY
       
   145     QStringList types;
       
   146     const int numTypes = sizeof(dialogInfos) / sizeof(dialogInfos[0]);
       
   147     for(int i = 0; i < numTypes; i++) {
       
   148         types.append(dialogInfos[i].mTypeString);
       
   149     }
       
   150     TRACE_EXIT
       
   151     return types;
       
   152 }
       
   153 
       
   154 // Return plugin flags
       
   155 HbDeviceDialogPlugin::PluginFlags HbDeviceMessageBoxPlugin::pluginFlags() const
       
   156 {
       
   157     TRACE_ENTRY
       
   158     TRACE_EXIT
       
   159     return NoPluginFlags;
       
   160 }
       
   161 
       
   162 // Return last error
       
   163 int HbDeviceMessageBoxPlugin::error() const
       
   164 {
       
   165     TRACE_ENTRY
       
   166     TRACE_EXIT
       
   167     return d->mError;
       
   168 }