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