policymanagement/policyengine/policyengineui/src/PolicyEngineUi.cpp
changeset 55 1c556dee8eb1
parent 54 085438c28042
child 60 eb6690d0d439
equal deleted inserted replaced
54:085438c28042 55:1c556dee8eb1
     1 /*
       
     2 * Copyright (c) 2000 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: Implementation of policymanagement components
       
    15 *
       
    16 */
       
    17 
       
    18 #include "PolicyEngineUI.h"
       
    19 #include <hbpopup.h>
       
    20 #include <hbinputdialog.h>
       
    21 #include <hbdocumentloader.h>
       
    22 #include <hbdialog.h>
       
    23 #include <hblabel.h>
       
    24 #include <hbaction.h>
       
    25 #include <hbnotificationdialog.h>
       
    26 #include <HbMessageBox.h>
       
    27 #include <hbdevicenotificationdialog.h>
       
    28 #include "Logger.h"
       
    29 
       
    30 const int KMaxTries = 4;
       
    31 const int KMaxCodeLength = 4;
       
    32 
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // PolicyEngineUI::PolicyEngineUI()
       
    36 // -----------------------------------------------------------------------------
       
    37 PolicyEngineUI::PolicyEngineUI(const QVariantMap& parameters)
       
    38     {
       
    39     estbTrustCount = KMaxTries;
       
    40     DisplayNotificationDialog(parameters);
       
    41     }
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // PolicyEngineUI::~PolicyEngineUI()
       
    46 // -----------------------------------------------------------------------------
       
    47 PolicyEngineUI::~PolicyEngineUI()
       
    48     {
       
    49 
       
    50     }
       
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // PolicyEngineUI::DisplayNotificationDialog()
       
    55 // Read the parameters sent from client
       
    56 // -----------------------------------------------------------------------------
       
    57 void PolicyEngineUI::DisplayNotificationDialog(const QVariantMap& parameters)
       
    58     {
       
    59     LOGSTRING( "+ DisplayNotificationDialog +" );
       
    60     QVariantMap::const_iterator i = parameters.constBegin();
       
    61 
       
    62     while (i != parameters.constEnd())
       
    63         {
       
    64         if (i.key().toAscii() == "serverdisplayname")
       
    65             {
       
    66             iServerName = i.value().toString();
       
    67             }
       
    68         else if (i.key().toAscii() == "fingerprint")
       
    69             {
       
    70             iFingerprint = i.value().toString();
       
    71             }
       
    72         ++i;
       
    73         }
       
    74     
       
    75     TBuf<50> server(iServerName.utf16());
       
    76     TBuf<10> buffer(iFingerprint.utf16());
       
    77 
       
    78     LOGSTRING2( "serverdisplayname %S", &server );
       
    79     LOGSTRING2( "fingerprint %S", &buffer );
       
    80 
       
    81     ShowInputDialog();
       
    82     LOGSTRING( "- DisplayNotificationDialog -" );
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // PolicyEngineUI::ShowInputDialog()
       
    88 // Show the accept control dialog
       
    89 // -----------------------------------------------------------------------------
       
    90 void PolicyEngineUI::ShowInputDialog()
       
    91     {
       
    92     LOGSTRING( "+ ShowInputDialog +" );
       
    93     HbDocumentLoader loader;
       
    94     bool ok = false;
       
    95     loader.load(":/xml/dialog.docml", &ok);
       
    96     if (!ok)
       
    97         {
       
    98         return;
       
    99         }
       
   100 
       
   101     HbDialog *dialog1 =
       
   102             qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   103 
       
   104     //set heading content
       
   105     HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   106             "qtl_dialog_pri_heading"));
       
   107     QString heading(hbTrId("txt_device_update_title_security_information"));
       
   108     contentheading->setPlainText(heading);
       
   109 
       
   110     //set body content
       
   111     HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
       
   112             "qtl_dialog_pri5"));
       
   113 
       
   114     QString body(
       
   115             (hbTrId("txt_device_update_info_1_server_wants_to_contro").arg(
       
   116                     iServerName)));
       
   117     contentbody->setTextWrapping(Hb::TextWordWrap);
       
   118     contentbody->setPlainText(body);
       
   119 
       
   120     HbAction *primaryAction = qobject_cast<HbAction *> (
       
   121             dialog1->actions().at(0));
       
   122     HbAction *secondaryAction = qobject_cast<HbAction *> (
       
   123             dialog1->actions().at(1));
       
   124 
       
   125     //set dialog properties
       
   126     dialog1->setTimeout(HbPopup::NoTimeout);
       
   127     dialog1->setDismissPolicy(HbPopup::NoDismiss);
       
   128 
       
   129     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   130             SLOT(onOKSelected()));
       
   131     QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   132             SLOT(onCancelSelected()));
       
   133 
       
   134     if (dialog1)
       
   135         dialog1->show();
       
   136 
       
   137     LOGSTRING( "- ShowInputDialog -" );
       
   138     }
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // PolicyEngineUI::onOKSelected()
       
   143 // Show the user input dialog once control is accepted
       
   144 // -----------------------------------------------------------------------------
       
   145 void PolicyEngineUI::onOKSelected()
       
   146     {
       
   147 
       
   148     LOGSTRING( "+ onOKSelected +" );
       
   149 
       
   150     HbDocumentLoader loader;
       
   151     bool ok = false;
       
   152     loader.load(":/xml/InputDialog.docml", &ok);
       
   153     if (!ok)
       
   154         {
       
   155         return;
       
   156         }
       
   157 
       
   158     mdialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   159 
       
   160     //set heading content
       
   161     HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   162             "qtl_dialog_pri_heading"));
       
   163     QString heading(hbTrId("txt_device_update_title_security_information"));
       
   164     contentheading->setPlainText(heading);
       
   165 
       
   166     //set label
       
   167     HbLabel *contentlabel = qobject_cast<HbLabel *> (loader.findWidget(
       
   168             "HeadingLabel"));
       
   169     contentlabel->setTextWrapping(Hb::TextWordWrap);
       
   170     QString label(
       
   171                 (hbTrId("txt_device_update_info_enter_first_4_characters_of").arg(
       
   172                         iServerName)));
       
   173     contentlabel ->setPlainText(label);
       
   174 
       
   175     //set length for editline
       
   176     mContentEdit = qobject_cast<HbLineEdit*> (loader.findWidget("InputLine"));
       
   177     mContentEdit->setMaxLength(KMaxCodeLength);
       
   178 
       
   179     //set dialog properties
       
   180     mdialog->setTimeout(HbPopup::NoTimeout);
       
   181     mdialog->setDismissPolicy(HbPopup::NoDismiss);
       
   182     
       
   183     HbAction* primaryAction = (HbAction*) (mdialog->actions().at(0));
       
   184     HbAction *secondaryAction = (HbAction*) (mdialog->actions().at(1));
       
   185     primaryAction->setEnabled(false);
       
   186 
       
   187     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   188             SLOT(establishTrust()));
       
   189     QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   190             SLOT(cancelTrust()));
       
   191     QObject::connect(mContentEdit, SIGNAL(contentsChanged()), this,
       
   192             SLOT(codeTextChanged()));
       
   193 
       
   194     if (mdialog)
       
   195         mdialog->show();
       
   196 
       
   197     LOGSTRING( "- onOKSelected -" );
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // PolicyEngineUI::onCancelSelected()
       
   203 // -----------------------------------------------------------------------------
       
   204 void PolicyEngineUI::onCancelSelected()
       
   205     {
       
   206     LOGSTRING( "+ onCancelSelected +" );
       
   207 
       
   208     QVariantMap result;
       
   209 
       
   210     result.insert("keyResponse", -1);
       
   211     emit
       
   212     deviceDialogData(result);
       
   213 
       
   214     emit
       
   215     deviceDialogClosed();
       
   216 
       
   217     LOGSTRING( "- onCancelSelected -" );
       
   218     }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // PolicyEngineUI::onTrustCreation()
       
   223 // -----------------------------------------------------------------------------
       
   224 void PolicyEngineUI::onTrustCreation()
       
   225     {
       
   226     LOGSTRING( "+ onTrustCreation +" );
       
   227     QVariantMap result;
       
   228 
       
   229     result.insert("keyResponse", 0);
       
   230     emit
       
   231     deviceDialogData(result);
       
   232 
       
   233     emit
       
   234     deviceDialogClosed();
       
   235 
       
   236     LOGSTRING( "- onTrustCreation -" );
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // PolicyEngineUI::establishTrust()
       
   242 // -----------------------------------------------------------------------------
       
   243 void PolicyEngineUI::establishTrust()
       
   244     {
       
   245     LOGSTRING( "+ establishTrust +" );
       
   246     bool retVal; // return value from code verification API.
       
   247     estbTrustCount--;
       
   248     retVal = verifyFingerPrint();
       
   249 
       
   250     if (retVal)
       
   251         {
       
   252         LOGSTRING( "Trust Created" );
       
   253         //Reset the counter.
       
   254         estbTrustCount = 0;
       
   255         onTrustCreation();
       
   256 
       
   257         }
       
   258     else
       
   259         {
       
   260         //check the number of tries.
       
   261         if (estbTrustCount == 0)
       
   262             {
       
   263             //Access denied.
       
   264             LOGSTRING( "Access Denied" );
       
   265             HbMessageBox *msgBox = new HbMessageBox();
       
   266             msgBox->setHeadingWidget(new HbLabel(hbTrId(
       
   267                     "txt_device_update_title_security_information")));
       
   268 
       
   269             msgBox->setText(hbTrId(
       
   270                     "txt_device_update_info_security_info_access_denied"));
       
   271             msgBox->setTimeout(HbDialog::NoTimeout);
       
   272             msgBox->setDismissPolicy(HbDialog::NoDismiss);
       
   273 
       
   274             HbAction *action = (HbAction*) (msgBox->actions().at(0));
       
   275             QObject::connect(action, SIGNAL(triggered()), this,
       
   276                     SLOT(onCancelSelected()));
       
   277 
       
   278             msgBox->show();
       
   279             }
       
   280         else
       
   281             {
       
   282             LOGSTRING2( "tries left %i", estbTrustCount );
       
   283             //Code didnot match.
       
   284             HbDocumentLoader loader;
       
   285             bool ok = false;
       
   286             loader.load(":/xml/InputDialog.docml", &ok);
       
   287             if (!ok)
       
   288                 {
       
   289                 return;
       
   290                 }
       
   291 
       
   292             mdialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   293 
       
   294             //set heading content
       
   295             HbLabel *contentheading = qobject_cast<HbLabel *> (
       
   296                     loader.findWidget("qtl_dialog_pri_heading"));
       
   297             contentheading->setTextWrapping(Hb::TextWordWrap);
       
   298             QString heading(hbTrId(
       
   299                     "txt_device_update_title_security_information"));
       
   300             contentheading->setPlainText(heading);
       
   301 
       
   302             //set label
       
   303             HbLabel *contentlabel = qobject_cast<HbLabel *> (
       
   304                     loader.findWidget("HeadingLabel"));
       
   305             QString
       
   306                     label(
       
   307                             (hbTrId(
       
   308                                     "txt_device_update_info_security_information_did_no").arg(
       
   309                                     estbTrustCount)));
       
   310 
       
   311             contentlabel->setTextWrapping(Hb::TextWordWrap);
       
   312             contentlabel->setPlainText(label);
       
   313 
       
   314             mContentEdit = qobject_cast<HbLineEdit*> (loader.findWidget(
       
   315                     "InputLine"));
       
   316             mContentEdit->setMaxLength(KMaxCodeLength);
       
   317 
       
   318             mdialog->setTimeout(HbPopup::NoTimeout);
       
   319             mdialog->setDismissPolicy(HbPopup::NoDismiss);
       
   320 
       
   321             HbAction* primaryAction = qobject_cast<HbAction*> (
       
   322                     mdialog->actions().at(0));
       
   323             HbAction *secondaryAction = qobject_cast<HbAction*> (
       
   324                     mdialog->actions().at(1));
       
   325             primaryAction->setEnabled(false);
       
   326 
       
   327             QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   328                     SLOT(establishTrust()));
       
   329             QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   330                     SLOT(cancelTrust()));
       
   331             QObject::connect(mContentEdit, SIGNAL(contentsChanged()), this,
       
   332                     SLOT(codeTextChanged()));
       
   333 
       
   334             if (mdialog)
       
   335                 mdialog->show();
       
   336             }
       
   337         }
       
   338     LOGSTRING( "- establishTrust -" );
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // PolicyEngineUI::cancelTrust()
       
   344 // -----------------------------------------------------------------------------
       
   345 void PolicyEngineUI::cancelTrust()
       
   346     {
       
   347     LOGSTRING( "+ cancelTrust +" );
       
   348     //Reset the counter.
       
   349     estbTrustCount = 0;
       
   350 
       
   351     QVariantMap result;
       
   352     result.insert("keyResponse", -1);
       
   353     emit
       
   354     deviceDialogData(result);
       
   355 
       
   356     emit
       
   357     deviceDialogClosed();
       
   358     LOGSTRING( "- cancelTrust -" );
       
   359     }
       
   360 
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // PolicyEngineUI::setDeviceDialogParameters()
       
   364 // -----------------------------------------------------------------------------
       
   365 bool PolicyEngineUI::setDeviceDialogParameters(const QVariantMap &parameters)
       
   366     {
       
   367 	Q_UNUSED(parameters);
       
   368     LOGSTRING( "+ setDeviceDialogParameters +" );
       
   369     return true;
       
   370     }
       
   371 
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // PolicyEngineUI::deviceDialogError()
       
   375 // Get error
       
   376 // -----------------------------------------------------------------------------
       
   377 int PolicyEngineUI::deviceDialogError() const
       
   378     {
       
   379     LOGSTRING( "+ deviceDialogError +" );
       
   380     return 0;
       
   381     }
       
   382 
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // PolicyEngineUI::PolicyEngineUI()
       
   386 // Close device dialog
       
   387 // -----------------------------------------------------------------------------
       
   388 void PolicyEngineUI::closeDeviceDialog(bool byClient)
       
   389     {
       
   390 	Q_UNUSED(byClient);
       
   391     LOGSTRING( "+ closeDeviceDialog +" );
       
   392     close();
       
   393     }
       
   394 
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // PolicyEngineUI::PolicyEngineUI()
       
   398 // Return display widget
       
   399 // -----------------------------------------------------------------------------
       
   400 HbDialog *PolicyEngineUI::deviceDialogWidget() const
       
   401     {
       
   402     LOGSTRING( "+ deviceDialogWidget +" );
       
   403     return const_cast<PolicyEngineUI*> (this);
       
   404     }
       
   405 
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // PolicyEngineUI::PolicyEngineUI()
       
   409 // Verify the user entered code
       
   410 // -----------------------------------------------------------------------------
       
   411 bool PolicyEngineUI::verifyFingerPrint()
       
   412     {
       
   413     LOGSTRING( "+ verifyFingerPrint +" );
       
   414 
       
   415     QString enteredCode = mContentEdit->text();
       
   416     TBuf<10> buffer(enteredCode.utf16());
       
   417 
       
   418     LOGSTRING2( "User entered code %i", &buffer);
       
   419     LOGSTRING2( "User entered code %S", &buffer);
       
   420 
       
   421     if (enteredCode.compare(iFingerprint, Qt::CaseInsensitive) == 0)
       
   422     {
       
   423         LOGSTRING( "+ fingerprint MATCH !!!! +" );
       
   424         return true;
       
   425     }
       
   426     else
       
   427     {
       
   428         LOGSTRING( "+  fingerprint DOESNOT MATCH  +" );
       
   429         return false;
       
   430     }
       
   431     }
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // PolicyEngineUI::codeTextChanged()
       
   436 // checks the entered text length and enables the OK option accordingly.
       
   437 // -----------------------------------------------------------------------------
       
   438 void PolicyEngineUI::codeTextChanged()
       
   439     {
       
   440     QString str = mContentEdit->text();
       
   441 
       
   442     if (str.length() >= KMaxCodeLength)
       
   443         mdialog->actions().at(0)->setEnabled(true);
       
   444     else
       
   445         mdialog->actions().at(0)->setEnabled(false);
       
   446     }