devicemgmtdialogsplugin/src/omacppinquerydialog.cpp
author hgs
Tue, 13 Jul 2010 03:48:30 +0530
changeset 45 0f9fc722d255
child 41 c742e1129640
permissions -rw-r--r--
201021_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     1
/*
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     3
 * All rights reserved.
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     8
 *
0f9fc722d255 201021_01
hgs
parents:
diff changeset
     9
 * Initial Contributors:
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    11
 *
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    12
 * Contributors:
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    13
 *
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    14
 * Description: omacppinquerydialog class implementation
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    15
 *
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    16
 */
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    17
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    18
#include <e32Property.h>
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    19
#include <qdebug.h>
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    20
#include <qtranslator.h>
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    21
#include <qcoreapplication.h>
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    22
#include <HbAction.h>
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    23
#include <devicedialogconsts.h>
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    24
#include "omacppinquerydialog.h"
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    25
#include "pnputillogger.h"
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    26
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    27
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    28
// omacppinquerydialog ::omacppinquerydialog
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    29
// Initialization of member variables; Create Pin query
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    30
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    31
//
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    32
omacppinquerydialog::omacppinquerydialog(const QVariantMap &parameters) :
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    33
    devicemanagementnotifierwidget(parameters)
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    34
    {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    35
    qDebug("omacppinquerydialog omacppinquerydialog() start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    36
    mlineedit = 0;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    37
    mactionok = 0;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    38
    createcppinquery(parameters);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    39
    qDebug("omacppinquerydialog omacppinquerydialog() end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    40
    }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    41
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    42
HbDialog *omacppinquerydialog::deviceDialogWidget() const
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    43
    {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    44
    return const_cast<omacppinquerydialog*> (this);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    45
    }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    46
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    47
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    48
// omacppinquerydialog ::createcppinquery
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    49
// Create Pin query dialog from docml; Connect the signals to slots
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    50
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    51
//
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    52
void omacppinquerydialog::createcppinquery(const QVariantMap &parameters)
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    53
    {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    54
    qDebug("omacppinquerydialog createcppinquery() start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    55
    HbDocumentLoader loader;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    56
    bool ok = false;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    57
    loader.load(":/xml/resources/pin.docml", &ok);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    58
    if (!ok)
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    59
        {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    60
        return;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    61
        }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    62
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    63
    HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    64
    dialog->setDismissPolicy(HbPopup::NoDismiss);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    65
    dialog->setTimeout(HbPopup::NoTimeout);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    66
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    67
    int tries = -1;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    68
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    69
    //Get the reties left
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    70
    QVariantMap::const_iterator i = parameters.find(keyparam1);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    71
    if (i != parameters.end())
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    72
        {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    73
        tries = i.value().toInt();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    74
        }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    75
    // In the first trial, show label without tries
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    76
    HbLabel *label = qobject_cast<HbLabel *> (loader.findObject("label"));
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    77
    QString labelstring = hbTrId(
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    78
            "txt_device_update_dialog_enter_the_configuration_p");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    79
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    80
    // In the second and third trials, show label with tries left
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    81
    if ((tries >= 1) && (tries <= (KPinRetries - 1)))
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    82
        {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    83
        labelstring = hbTrId(
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    84
                "txt_device_update_dialog_enter_the_config_trial");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    85
        label->setNumber(tries);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    86
        }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    87
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    88
    label->setPlainText(labelstring);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    89
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    90
    mactionok = (HbAction *) dialog->actions().first();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    91
    QString softkeyok = hbTrId("txt_common_button_ok");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    92
    mactionok->setText(softkeyok);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    93
    mactionok->setEnabled(false);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    94
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    95
    HbAction *actioncancel = (HbAction *) dialog->actions().at(1);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    96
    QString softkeyCancel = hbTrId("txt_common_button_cancel");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    97
    actioncancel->setText(softkeyCancel);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    98
0f9fc722d255 201021_01
hgs
parents:
diff changeset
    99
    mlineedit = qobject_cast<HbLineEdit *> (loader.findObject("lineEdit"));
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   100
    mlineedit->setEchoMode(HbLineEdit::Password);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   101
    mlineedit->setMaxLength(KCPPinMaxLength);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   102
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   103
    mlineedit->setInputMethodHints(Qt::ImhDigitsOnly);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   104
    HbEditorInterface editorInterface(mlineedit);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   105
    editorInterface.setMode(HbInputModeNumeric);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   106
    editorInterface.setInputConstraints(HbEditorConstraintFixedInputMode);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   107
    dialog->setTimeout(HbPopup::NoTimeout);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   108
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   109
    bool bconnect = false;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   110
    // Connection to the slot when PIN text is changed
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   111
    bconnect = QObject::connect(mlineedit, SIGNAL(contentsChanged()), this,
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   112
            SLOT( pintextChanged()));
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   113
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   114
    qDebug("omacppinquerydialog::createcppinquery() bconnect value ");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   115
    qDebug() << bconnect;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   116
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   117
    // Connections to the slot when Ok and Cancel buttons are clicked
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   118
    QObject::connect(mactionok, SIGNAL(triggered()), this, SLOT(okSelected()));
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   119
    QObject::connect(actioncancel, SIGNAL(triggered()), this,
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   120
            SLOT(cancelSelected()));
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   121
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   122
    if (dialog)
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   123
        dialog->show();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   124
        
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   125
    
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   126
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   127
    qDebug("omacppinquerydialog createcppinquery() end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   128
    }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   129
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   130
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   131
// omacppinquerydialog ::pintextChanged
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   132
// Slot to enable/disable Ok button when text is entered/deleted
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   133
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   134
//
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   135
void omacppinquerydialog::pintextChanged()
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   136
    {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   137
    qDebug("omacppinquerydialog::pintextChanged start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   138
    LOGSTRING("omacppinquerydialog::pintextChanged start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   139
    int textlength = 0;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   140
    textlength = mlineedit->text().length();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   141
    LOGSTRING2("omacppinquerydialog::pintextChanged start %d", textlength);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   142
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   143
    if (textlength > 0)
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   144
        {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   145
        //If text length is positive, enable Ok button
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   146
        qDebug("omacppinquerydialog::pintextChanged text is entered");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   147
        LOGSTRING("omacppinquerydialog::pintextChanged text is entered");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   148
        mactionok->setEnabled(true);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   149
        }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   150
    else if (textlength == 0)
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   151
        {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   152
        //If text length is zero, disable Ok button
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   153
        qDebug("omacppinquerydialog::pintextChanged zero text");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   154
        LOGSTRING("omacppinquerydialog::pintextChanged zero text");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   155
        mactionok->setEnabled(false);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   156
        }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   157
    qDebug("omacppinquerydialog::pintextChanged end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   158
    }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   159
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   160
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   161
// omacppinquerydialog ::okSelected
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   162
// Slot to emit signals when Ok is selected
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   163
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   164
//
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   165
void omacppinquerydialog::okSelected()
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   166
    {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   167
    qDebug("omacppinquerydialog::okSelected() start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   168
    LOGSTRING("omacppinquerydialog::okSelected() start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   169
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   170
    QString stringpin = mlineedit->text();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   171
    QVariantMap resultMap;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   172
    resultMap.insert(pinquery, stringpin);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   173
    resultMap.insert(returnkey, EHbLSK);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   174
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   175
    //Emit signals with the data
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   176
    emit
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   177
    deviceDialogData(resultMap);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   178
    emit deviceDialogClosed();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   179
    qDebug("omacppinquerydialog::okSelected() end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   180
    LOGSTRING("omacppinquerydialog::okSelected() end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   181
    }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   182
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   183
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   184
// omacppinquerydialog ::cancelSelected
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   185
// Slot to emit signals when Cancel is selected
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   186
// ----------------------------------------------------------------------------
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   187
//
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   188
void omacppinquerydialog::cancelSelected()
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   189
    {
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   190
    qDebug("omacppinquerydialog::cancelSelected() start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   191
    LOGSTRING("omacppinquerydialog::cancelSelected() start");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   192
    QVariantMap resultMap;
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   193
    resultMap.insert(returnkey, EHbRSK);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   194
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   195
    //Emit signals with the data
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   196
    emit
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   197
    deviceDialogData(resultMap);
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   198
    emit deviceDialogClosed();
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   199
    
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   200
    LOGSTRING("omacppinquerydialog::cancelSelected() end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   201
    qDebug("omacppinquerydialog::cancelSelected() end");
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   202
    }
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   203
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   204
//  End of File
0f9fc722d255 201021_01
hgs
parents:
diff changeset
   205