securitysettings/cpwlansecurityuiplugins/cpwepui/src/cpwepui.cpp
branchRCL_3
changeset 19 c74b3d9f6b9e
parent 18 bad0cc58d154
equal deleted inserted replaced
18:bad0cc58d154 19:c74b3d9f6b9e
     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: 
       
    15  *    Control Panel QT UI for WEP configuration
       
    16  *
       
    17  */
       
    18 
       
    19 /*
       
    20  * %version: tr1cfwln#24 %
       
    21  */
       
    22 
       
    23 //User Includes
       
    24 #include "cpwepui.h"
       
    25 #include "wepkeyvalidator.h"
       
    26 
       
    27 
       
    28 // System includes
       
    29 #include <QStringList>
       
    30 #include <cpitemdatahelper.h>
       
    31 #include <cmconnectionmethod_shim.h>
       
    32 #include <cmmanagerdefines_shim.h>
       
    33 #include <HbLineEdit>
       
    34 #include <HbTranslator>
       
    35 #include <HbEditorInterface>
       
    36 
       
    37 //Trace Definition
       
    38 #include "OstTraceDefinitions.h"
       
    39 #ifdef OST_TRACE_COMPILER_IN_USE
       
    40 #include "cpwepuiTraces.h"
       
    41 #endif
       
    42 
       
    43 // Constants
       
    44 //The order in which WEP only mode appears in the list of available 
       
    45 //security mode
       
    46 static const int UI_ORDER_WEP = 10;
       
    47 
       
    48 //! Index of first WEP key
       
    49 static const int KFirstKey = 0;
       
    50 
       
    51 //! Index of second WEP key
       
    52 static const int KSecondKey = 1;
       
    53 
       
    54 //! Index of third WEP key
       
    55 static const int KThirdKey = 2;
       
    56 
       
    57 //! Index of fourth WEP key
       
    58 static const int KFourthKey = 3;
       
    59 
       
    60 //!Maximum allowed length for WEP keys, in hex mode
       
    61 static const int KMaxKeyLength  = 26;
       
    62 
       
    63 
       
    64 
       
    65 /*!
       
    66  \class CpWepUi
       
    67  \brief CpWepUi implements the WEP Security Settings Control Panel Plugin
       
    68  which will allow viewing/editing of WEP Security Settings.
       
    69  */
       
    70 //Contructs WEP object
       
    71 CpWepUi::CpWepUi() :
       
    72     mUi(NULL),
       
    73     mNewKeySelected(0), 
       
    74     mTranslator(new HbTranslator("cpwlansecsettingsplugin")),
       
    75     mCmCM(NULL), 
       
    76     mCmId(0)    
       
    77 {
       
    78     //Initialize array members
       
    79     for(int index=0;index<KMaxNumberofKeys;index++)
       
    80     {
       
    81         mWepKey[index] = NULL;
       
    82         mWepKeyText[index] = NULL;   
       
    83         mkeyFormat[index] = EFormatHex;
       
    84     }
       
    85       
       
    86 }
       
    87 
       
    88 //Deletes all objects WEP owns
       
    89 CpWepUi::~CpWepUi()
       
    90 {
       
    91     OstTraceFunctionEntry1(CPWEPUI_CPWEPUI_ENTRY,this);
       
    92     //Elements like mUi and components that belong to it
       
    93     //, are taken care by the parent
       
    94     delete mTranslator;
       
    95     OstTraceFunctionExit1(CPWEPUI_CPWEPUI_EXIT,this);
       
    96 }
       
    97 
       
    98 // ======== MEMBER FUNCTIONS ========
       
    99 
       
   100 
       
   101 /*!
       
   102  Getter for security mode.
       
   103 
       
   104  \return Security mode identifier
       
   105  */
       
   106 CMManagerShim::WlanSecMode CpWepUi::securityMode() const
       
   107 {
       
   108     OstTraceFunctionEntry1(CPWEPUI_SECURITYMODE_ENTRY,this);
       
   109     OstTraceFunctionExit1(CPWEPUI_SECURITYMODE_EXIT,this);
       
   110     //return security mode
       
   111     return CMManagerShim::WlanSecModeWep;
       
   112 }
       
   113 
       
   114 /*!
       
   115  Getter for localization text identifier for the security mode,
       
   116  f.ex. "txt_occ_setlabel_wlan_security_mode_val_wep". This localized
       
   117  text will be shown in the UI.
       
   118  
       
   119  \return Localization text ID
       
   120  */
       
   121 QString CpWepUi::securityModeTextId() const
       
   122 {
       
   123     OstTraceFunctionEntry1( CPWEPUI_SECURITYMODETEXTID_ENTRY, this );
       
   124     OstTraceFunctionExit1( CPWEPUI_SECURITYMODETEXTID_EXIT, this );
       
   125     return "txt_occ_setlabel_wlan_security_mode_val_wep";
       
   126 }
       
   127 
       
   128 /*! 
       
   129  Sets the database reference Iap id.
       
   130 
       
   131  \param id Database reference
       
   132  */
       
   133 void CpWepUi::setReference(CmConnectionMethodShim *cmCm, uint id)
       
   134 {
       
   135     OstTraceFunctionEntry1(CPWEPUI_SETREFERENCE_ENTRY,this);
       
   136     mCmId = id;
       
   137 
       
   138     //mCmCM is not deleted assuming CmManager owns it.
       
   139     mCmCM = cmCm;
       
   140     OstTraceFunctionExit1(CPWEPUI_SETREFERENCE_EXIT,this);
       
   141 }
       
   142 
       
   143 /*!
       
   144  Getter for order number. This order number is used by the client of
       
   145  this interface to put the security modes in correct order in the list.
       
   146 
       
   147  \return An order number
       
   148  */
       
   149 int CpWepUi::orderNumber() const
       
   150 {
       
   151     OstTraceFunctionEntry1(CPWEPUI_ORDERNUMBER_ENTRY,this);
       
   152     OstTraceFunctionExit1(CPWEPUI_ORDERNUMBER_EXIT,this);
       
   153     return UI_ORDER_WEP;
       
   154 }
       
   155 
       
   156 /*!
       
   157  * Returns the fully constructed Ui Group , for WEP security plugin
       
   158  * 
       
   159  * \param dataHelper to add Connections
       
   160  * 
       
   161  * \return The WEP UI
       
   162  */
       
   163 CpSettingFormItemData* CpWepUi::uiInstance(CpItemDataHelper &dataHelpper)
       
   164 {
       
   165     int err;
       
   166     OstTraceFunctionEntry1(CPWEPUI_UIINSTANCE_ENTRY,this);
       
   167 
       
   168     //Read values From CommsDatbase
       
   169     QT_TRYCATCH_ERROR(err, loadFieldsFromDataBase());
       
   170     if (err != KErrNone) {
       
   171         OstTrace1( TRACE_ERROR, CPWEPUI_UIINSTANCE, "LoadFromDataBase returned %d", err );
       
   172     }
       
   173     
       
   174     //Store the address of the Data Helper
       
   175     mItemDataHelper = &dataHelpper;
       
   176 
       
   177     mUi = new CpSettingFormItemData(HbDataFormModelItem::GroupItem, hbTrId(
       
   178             "txt_occ_subhead_security_settings"));
       
   179 
       
   180     CpSettingFormItemData *wepKeyInUse = new CpSettingFormItemData(
       
   181             HbDataFormModelItem::ComboBoxItem, hbTrId(
       
   182                     "txt_occ_setlabel_wep_key_in_use"), mUi);
       
   183     QStringList wepKeys;
       
   184     wepKeys.append(hbTrId("txt_occ_setlabel_wep_key_in_val_1"));
       
   185     wepKeys.append(hbTrId("txt_occ_setlabel_wep_key_in_val_2"));
       
   186     wepKeys.append(hbTrId("txt_occ_setlabel_wep_key_in_val_3"));
       
   187     wepKeys.append(hbTrId("txt_occ_setlabel_wep_key_in_val_4"));
       
   188 
       
   189     wepKeyInUse->setContentWidgetData("items", wepKeys);
       
   190     wepKeyInUse->setContentWidgetData("currentIndex", mNewKeySelected);
       
   191     dataHelpper.addConnection(wepKeyInUse, SIGNAL(currentIndexChanged(int)),
       
   192             this, SLOT(wepKeyInUseChanged(int)));
       
   193     mUi->appendChild(wepKeyInUse);
       
   194 
       
   195     //Create Ui for all 4 WEP keys
       
   196     createWEPKeyGroup(KFirstKey);
       
   197 
       
   198     createWEPKeyGroup(KSecondKey);
       
   199 
       
   200     createWEPKeyGroup(KThirdKey);
       
   201 
       
   202     createWEPKeyGroup(KFourthKey);
       
   203     
       
   204     //Add Connections(signals)
       
   205     addConnections(dataHelpper);
       
   206 
       
   207     OstTraceFunctionExit1(CPWEPUI_UIINSTANCE_EXIT,this);
       
   208     return mUi;
       
   209 }
       
   210 
       
   211 
       
   212 /*!
       
   213    Validates current security settings. This function is called whenever
       
   214    user tries to exit from the settings view. If the plugin determines
       
   215    that some settings need editing before considered valid, it shall
       
   216    return false. A dialog will be shown to the user indicating that
       
   217    settings are still incomplete and asking if he/she wishes to exit
       
   218    anyway.
       
   219 
       
   220    \return True if security settings for WEP are valid, false if not.
       
   221 */
       
   222 bool CpWepUi::validateSettings()
       
   223 {
       
   224     bool ret(false);
       
   225     //Check the latest string entered for the WEP key in the text box
       
   226     QVariant keyValue = mWepKeyText[mNewKeySelected]->contentWidgetData("text");
       
   227     QString keyString = keyValue.toString();
       
   228     
       
   229     WepKeyValidator::KeyStatus keystatus = WepKeyValidator::validateWepKey(keyString);
       
   230     
       
   231     //Check if key is  valid and not of zero length 
       
   232     if(keystatus==WepKeyValidator::KeyStatusOk) {
       
   233         ret = true;
       
   234     }
       
   235     return ret;
       
   236 }
       
   237 
       
   238 /*!
       
   239  * Create Ui element with text edit for WEP KEYS
       
   240  * 
       
   241  * \param index of the WEP key
       
   242  * */
       
   243 void CpWepUi::createWEPKeyGroup(int index)
       
   244     {
       
   245     OstTraceFunctionEntry1(CPWEPUI_CREATEWEPKEYGROUP_ENTRY,this);
       
   246     QString textId;
       
   247     
       
   248     switch(index)
       
   249         {
       
   250         case KFirstKey:
       
   251             textId  = hbTrId("txt_occ_setlabel_wep_key_1");
       
   252             break;
       
   253             
       
   254         case KSecondKey:
       
   255             textId  = hbTrId("txt_occ_setlabel_wep_key_2");
       
   256             break;
       
   257             
       
   258         case KThirdKey:
       
   259             textId  = hbTrId("txt_occ_setlabel_wep_key_3");
       
   260             break;
       
   261             
       
   262         case KFourthKey:
       
   263             textId  = hbTrId("txt_occ_setlabel_wep_key_4");
       
   264             break;
       
   265         }
       
   266         
       
   267     mWepKeyText[index] = new CpSettingFormItemData(
       
   268             HbDataFormModelItem::TextItem,
       
   269             textId, mUi);
       
   270 
       
   271     if (mKeyData[index].length() != 0) {
       
   272         mWepKeyText[index]->setContentWidgetData("text",
       
   273                 mKeyData[index]);
       
   274     }
       
   275     mWepKeyText[index]->setContentWidgetData("echoMode",HbLineEdit::PasswordEchoOnEdit);
       
   276     mWepKeyText[index]->setContentWidgetData("smileysEnabled", "false");
       
   277 
       
   278     
       
   279     mUi->appendChild(mWepKeyText[index]);
       
   280     OstTraceFunctionExit1(CPWEPUI_CREATEWEPKEYGROUP_EXIT,this);
       
   281     }
       
   282 
       
   283 
       
   284 /*!
       
   285  * Add signals to all the text Edit of WEP key groups.
       
   286  *  
       
   287  *  \param dataHelper ; to add Connections
       
   288  */
       
   289 void CpWepUi::addConnections(CpItemDataHelper &dataHelpper)
       
   290     {
       
   291     OstTraceFunctionEntry1( CPWEPUI_ADDCONNECTIONS_ENTRY, this );
       
   292     
       
   293     dataHelpper.addConnection(mWepKeyText[KFirstKey],
       
   294                 SIGNAL( editingFinished ()), this, SLOT(wepKeyOneChanged() ));
       
   295     
       
   296     dataHelpper.addConnection(mWepKeyText[KSecondKey],
       
   297                SIGNAL( editingFinished ()), this, SLOT(wepKeyTwoChanged() ));
       
   298     
       
   299     dataHelpper.addConnection(mWepKeyText[KThirdKey],
       
   300                SIGNAL( editingFinished ()), this, SLOT(wepKeyThreeChanged() ));
       
   301     
       
   302     dataHelpper.addConnection(mWepKeyText[KFourthKey],
       
   303                 SIGNAL( editingFinished ()), this, SLOT(wepKeyFourChanged() ));
       
   304     
       
   305     dataHelpper.connectToForm(SIGNAL(itemShown (const QModelIndex &) ), 
       
   306             this, SLOT(setEditorPreferences(const QModelIndex &)));
       
   307  
       
   308     OstTraceFunctionExit1( CPWEPUI_ADDCONNECTIONS_EXIT, this );
       
   309     }
       
   310 
       
   311 
       
   312 /*!
       
   313  * Slot to handle , if a different wep key (index) 
       
   314  * is made active
       
   315  * \param wepKeyInUse index of the chosen wep key
       
   316  */
       
   317 void CpWepUi::wepKeyInUseChanged(int wepKeyInUse)
       
   318 {
       
   319     OstTraceFunctionEntry1(CPWEPUI_WEPKEYINUSECHANGED_ENTRY,this);
       
   320 
       
   321     int err;
       
   322     //Update CommsDat
       
   323     QT_TRYCATCH_ERROR(err, mCmCM->setIntAttribute(CMManagerShim::WlanWepKeyIndex, wepKeyInUse));
       
   324     if (err != KErrNone) {
       
   325         OstTrace1( TRACE_ERROR, CPWEPUI_WEPKEYINUSECHANGED, "Error wepKeyInUse returned %d", err );
       
   326     }
       
   327     tryUpdate();
       
   328     
       
   329     //Store the wep key in use
       
   330     mNewKeySelected = wepKeyInUse;
       
   331     OstTraceFunctionExit1(CPWEPUI_WEPKEYINUSECHANGED_EXIT,this);
       
   332 }
       
   333 
       
   334 /*!
       
   335  * Slot to handle ,when the  
       
   336  *   wep key one string gets changed
       
   337  * 
       
   338  * 
       
   339  */
       
   340 void CpWepUi::wepKeyOneChanged()
       
   341 {
       
   342     int err;
       
   343     OstTraceFunctionEntry1(CPWEPUI_WEPKEY1STRINGCHANGED_ENTRY,this);
       
   344     QT_TRYCATCH_ERROR(err, wepKeyTextChanged(KFirstKey));
       
   345     if (err != KErrNone) {
       
   346         OstTrace1( TRACE_ERROR,CPWEPUI_WEPKEYONECHANGED, "Error wepKeyOneChanged returned %d", err );
       
   347         }
       
   348     OstTraceFunctionExit1(CPWEPUI_WEPKEY1STRINGCHANGED_EXIT,this);
       
   349 }
       
   350 
       
   351 /*!
       
   352  * Slot to handle ,when the  
       
   353  *   wep key two string gets changed
       
   354  * 
       
   355  * 
       
   356  */
       
   357 void CpWepUi::wepKeyTwoChanged()
       
   358 {
       
   359     int err;
       
   360     OstTraceFunctionEntry1(CPWEPUI_WEPKEY2STRINGCHANGED_ENTRY,this);
       
   361     QT_TRYCATCH_ERROR(err, wepKeyTextChanged(KSecondKey));
       
   362     if (err != KErrNone) {
       
   363         OstTrace1( TRACE_ERROR, CPWEPUI_WEPKEYTWOCHANGED, "Error wepKeyTwoChanged returned %d", err );
       
   364     }
       
   365     OstTraceFunctionExit1(CPWEPUI_WEPKEY2STRINGCHANGED_EXIT,this);
       
   366 }
       
   367 
       
   368 /*!
       
   369  * Slot to handle ,when the  
       
   370  *   wep key three string gets changed
       
   371  * 
       
   372  * 
       
   373  */
       
   374 void CpWepUi::wepKeyThreeChanged()
       
   375 {
       
   376     int err;
       
   377     OstTraceFunctionEntry1(CPWEPUI_WEPKEY3STRINGCHANGED_ENTRY,this);
       
   378     QT_TRYCATCH_ERROR(err, wepKeyTextChanged(KThirdKey));
       
   379     if (err != KErrNone) {
       
   380         OstTrace1( TRACE_ERROR,CPWEPUI_WEPKEYTHREECHANGED, "Error wepKeyThreeChanged returned %d", err );
       
   381     }
       
   382     OstTraceFunctionExit1(CPWEPUI_WEPKEY3STRINGCHANGED_EXIT,this);
       
   383 }
       
   384 
       
   385 /*!
       
   386  * Slot to handle ,when the  
       
   387  *   wep key four string gets changed
       
   388  * 
       
   389  * 
       
   390  */
       
   391 void CpWepUi::wepKeyFourChanged()
       
   392 {
       
   393     int err;
       
   394     OstTraceFunctionEntry1(CPWEPUI_WEPKEY4STRINGCHANGED_ENTRY,this);
       
   395     QT_TRYCATCH_ERROR(err, wepKeyTextChanged(KFourthKey));
       
   396     if (err != KErrNone) {
       
   397         OstTrace1( TRACE_ERROR, CPWEPUI_WEPKEYFOURCHANGED, "Error wepKeyFourChanged returned %d", err );
       
   398     }OstTraceFunctionExit1(CPWEPUI_WEPKEY4STRINGCHANGED_EXIT,this);
       
   399 }
       
   400 
       
   401 /*!
       
   402  * Slot to handle change in either of the 4 WEP key strings
       
   403  * 
       
   404  * \param index of the WEP key that changed
       
   405  */
       
   406 void CpWepUi::wepKeyTextChanged(int index)
       
   407 {
       
   408     OstTraceFunctionEntry1(CPWEPUI_WEPKEYTEXTCHANGED_ENTRY,this);
       
   409 
       
   410     QVariant value = mWepKeyText[index]->contentWidgetData("text");
       
   411     QString key = value.toString();
       
   412 
       
   413     WepKeyValidator::KeyStatus keystatus = WepKeyValidator::validateWepKey(key);
       
   414 
       
   415     // allow storing an empty key to enable clearing WEP keys
       
   416     if (keystatus == WepKeyValidator::KeyStatusOk || key.length() == 0) {
       
   417 
       
   418         //If key is valid set the format of the key
       
   419         setKeyFormat(key, index);
       
   420 
       
   421         //Get the right field to store
       
   422         CMManagerShim::ConnectionMethodAttribute keyEnum = getWEPKeyEnum(index);
       
   423 
       
   424         //Store the WEP key
       
   425         storeWEPKey(keyEnum, key);
       
   426 
       
   427         //Update the latest key into array
       
   428         mKeyData[index] = key;
       
   429 
       
   430         /*
       
   431          * Commit All 4 WEP keys , anyways
       
   432          */
       
   433         commitWEPkeys(index);
       
   434     }
       
   435     else {
       
   436         OstTrace0( TRACE_ERROR, CPWEPUI_WEPKEYTEXTCHANGED_ERROR, "CpWepUi::wepKeyTextChanged Invalid WEP Key Input" );        
       
   437         showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId(
       
   438                 "txt_occ_info_invalid_input"));
       
   439     }
       
   440     OstTraceFunctionExit1(CPWEPUI_WEPKEYTEXTCHANGED_EXIT,this);
       
   441 }
       
   442 
       
   443 /*!
       
   444  * Slot that configures the editor settings for all WEP key fields.
       
   445  * This slot is invoked whenever a new item(s) are shown in the current view 
       
   446  * 
       
   447  * \param modelIndex Index of the current item in the  model
       
   448  */
       
   449 void CpWepUi::setEditorPreferences(const QModelIndex &modelIndex)
       
   450 {
       
   451     
       
   452     HbDataFormModelItem *item = mItemDataHelper->modelItemFromModelIndex(modelIndex);
       
   453 
       
   454     HbSmileyTheme smiley;
       
   455     /* Configure settings only for text fields*/
       
   456     if(item->type() == HbDataFormModelItem::TextItem) {
       
   457         HbLineEdit *edit = qobject_cast<HbLineEdit*>(mItemDataHelper->widgetFromModelIndex(modelIndex));           
       
   458         HbEditorInterface editInterface(edit);    
       
   459         editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly);
       
   460         edit->setInputMethodHints(Qt::ImhNoPredictiveText);    
       
   461         edit->setMaxLength(KMaxKeyLength);
       
   462         }
       
   463 }
       
   464 
       
   465 
       
   466 /*!
       
   467  * Store the WEP key in Comms
       
   468  * \enumValue the right field represented by the enum value
       
   469  * \key the WEP key String to store
       
   470  */
       
   471 void CpWepUi::storeWEPKey(CMManagerShim::ConnectionMethodAttribute enumValue,
       
   472         QString& key)
       
   473 {
       
   474     mCmCM->setString8Attribute(enumValue, key);
       
   475     tryUpdate();
       
   476 }
       
   477 
       
   478 /*!
       
   479  * Set the WEP key format
       
   480  * \key string to identify format
       
   481  * \index of the WEP key
       
   482  */
       
   483 void CpWepUi::setKeyFormat(QString& key, int index)
       
   484 {
       
   485     if (key.length() == WepKeyValidator::WepHex64BitMaxLength || key.length()
       
   486             == WepKeyValidator::WepHex128BitMaxLength) {
       
   487         mkeyFormat[index] = EFormatHex;
       
   488     }
       
   489 
       
   490     else if (key.length() == WepKeyValidator::WepAscii64BitMaxLength
       
   491             || key.length() == WepKeyValidator::WepAscii128BitMaxLength) {
       
   492         mkeyFormat[index] = EFormatAscii;
       
   493     }
       
   494 }
       
   495 
       
   496 /*!Get the right field in DB
       
   497  * \index of the WEP key
       
   498  */
       
   499 CMManagerShim::ConnectionMethodAttribute CpWepUi::getWEPKeyEnum(int index)
       
   500 {
       
   501     CMManagerShim::ConnectionMethodAttribute keyenum(
       
   502             CMManagerShim::WlanWepKey1InHex);
       
   503     switch (index)
       
   504         {
       
   505         case KFirstKey:
       
   506             {
       
   507                 if (mkeyFormat[index] == EFormatHex) {
       
   508                     keyenum = CMManagerShim::WlanWepKey1InHex;
       
   509                 }
       
   510                 else {
       
   511                     keyenum = CMManagerShim::WlanWepKey1InAscii;
       
   512                 }
       
   513             }
       
   514             break;
       
   515 
       
   516         case KSecondKey:
       
   517             {
       
   518                 if (mkeyFormat[index] == EFormatHex) {
       
   519                     keyenum = CMManagerShim::WlanWepKey2InHex;
       
   520                 }
       
   521                 else {
       
   522                     keyenum = CMManagerShim::WlanWepKey2InAscii;
       
   523                 }
       
   524             }
       
   525             break;
       
   526 
       
   527         case KThirdKey:
       
   528             {
       
   529                 if (mkeyFormat[index] == EFormatHex) {
       
   530                     keyenum = CMManagerShim::WlanWepKey3InHex;
       
   531                 }
       
   532                 else {
       
   533                     keyenum = CMManagerShim::WlanWepKey3InAscii;
       
   534                 }
       
   535             }
       
   536             break;
       
   537 
       
   538         case KFourthKey:
       
   539             {
       
   540                 if (mkeyFormat[index] == EFormatHex) {
       
   541                     keyenum = CMManagerShim::WlanWepKey4InHex;
       
   542                 }
       
   543                 else {
       
   544                     keyenum = CMManagerShim::WlanWepKey4InAscii;
       
   545                 }
       
   546             }
       
   547             break;
       
   548 
       
   549         default:
       
   550             break;
       
   551         }
       
   552     return keyenum;
       
   553 }
       
   554 /*
       
   555  * Read all security settings from the Comms 
       
   556  */
       
   557 void CpWepUi::loadFieldsFromDataBase()
       
   558 {
       
   559     OstTraceFunctionEntry1(CPWEPUI_LOADFIELDSFROMDATABASE_ENTRY,this);
       
   560 
       
   561     //Wep Key in Use 
       
   562     mNewKeySelected = mCmCM->getIntAttribute(CMManagerShim::WlanWepKeyIndex);
       
   563 
       
   564     //All data fetched in Hex Format
       
   565     mKeyData.insert(KFirstKey, mCmCM->getString8Attribute(
       
   566             CMManagerShim::WlanWepKey1InHex));
       
   567 
       
   568     mKeyData.insert(KSecondKey,mCmCM->getString8Attribute(
       
   569             CMManagerShim::WlanWepKey2InHex));
       
   570 
       
   571     mKeyData.insert(KThirdKey, mCmCM->getString8Attribute(
       
   572             CMManagerShim::WlanWepKey3InHex));
       
   573 
       
   574     mKeyData.insert(KFourthKey, mCmCM->getString8Attribute(
       
   575             CMManagerShim::WlanWepKey4InHex));
       
   576 
       
   577     /*Set all key formats to Hex by default; because all keys are read in Hex from DB*/
       
   578     for (int count = 0; count < KMaxNumberofKeys; count++)
       
   579         {
       
   580         mkeyFormat[count] = EFormatHex;
       
   581         }
       
   582 
       
   583     OstTraceFunctionExit1(CPWEPUI_LOADFIELDSFROMDATABASE_EXIT,this);
       
   584 }
       
   585 
       
   586 /*!
       
   587  Tries to update connection method changes to CommsDat.
       
   588  Returns "true" if success, "false" if some error happened. 
       
   589  */
       
   590 bool CpWepUi::tryUpdate()
       
   591 {
       
   592     OstTraceFunctionEntry1(CPWEPUI_TRYUPDATE_ENTRY,this);
       
   593 
       
   594     bool ret(true);
       
   595     // Try update
       
   596     try {
       
   597         mCmCM->update();
       
   598     }
       
   599     catch (const std::exception&) {
       
   600         // Handle error
       
   601         handleUpdateError();
       
   602         ret = false;
       
   603     }
       
   604 
       
   605     OstTraceFunctionExit1(DUP1_CPWEPUI_TRYUPDATE_EXIT,this);
       
   606     return ret;
       
   607 }
       
   608 
       
   609 /*!
       
   610  Handles failed CommsDat update.
       
   611  */
       
   612 void CpWepUi::handleUpdateError()
       
   613 {
       
   614     OstTraceFunctionEntry1(CPWEPUI_HANDLEUPDATEERROR_ENTRY,this);
       
   615 
       
   616     // Show error note to user
       
   617     showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId(
       
   618             "txt_occ_info_unable_to_save_setting"));
       
   619     // Reload settings from CommsDat and update UI
       
   620     try {
       
   621         mCmCM->refresh();
       
   622     }
       
   623     catch (const std::exception&) {
       
   624         // Ignore error from refresh. Most likely this will not happen, but
       
   625         // if it does, there isn't very much we can do.
       
   626         OstTrace0(
       
   627                 TRACE_ERROR,
       
   628                 CPWEPPLUGIN_HANDLEUPDATEERROR,
       
   629                 "Refresh failed");
       
   630     };
       
   631     updateWepSettings();
       
   632 
       
   633     OstTraceFunctionExit1(CPWEPUI_HANDLEUPDATEERROR_EXIT,this);
       
   634 }
       
   635 
       
   636 /*!
       
   637  Shows message box with "OK" button using given text.
       
   638  */
       
   639 void CpWepUi::showMessageBox(HbMessageBox::MessageBoxType type,
       
   640         const QString &text)
       
   641 {
       
   642     OstTraceFunctionEntry1(CPWEPUI_SHOWMESSAGEBOX_ENTRY,this);
       
   643 
       
   644     // Create a message box
       
   645     mMessageBox = QSharedPointer<HbMessageBox> (new HbMessageBox(type));
       
   646     mMessageBox->setText(text);
       
   647     mMessageBox->open();
       
   648 
       
   649     OstTraceFunctionExit1(CPWEPUI_SHOWMESSAGEBOX_EXIT,this);
       
   650 }
       
   651 
       
   652 /*!
       
   653  * Reset the Key Items on the Ui, by reading the previously set value from Comms
       
   654  */
       
   655 void CpWepUi::updateWepSettings()
       
   656     {
       
   657     OstTraceFunctionEntry1(CPWEPUI_UPDATEWEPSETTINGS_ENTRY,this);
       
   658     //Read values from Comms and update the Ui items; 
       
   659     loadFieldsFromDataBase();
       
   660 
       
   661     mWepKeyText[KFirstKey]->setContentWidgetData("text", mKeyData[KFirstKey]);
       
   662 
       
   663     mWepKeyText[KSecondKey]->setContentWidgetData("text",
       
   664             mKeyData[KSecondKey]);
       
   665 
       
   666     mWepKeyText[KThirdKey]->setContentWidgetData("text", mKeyData[KThirdKey]);
       
   667 
       
   668     mWepKeyText[KFourthKey]->setContentWidgetData("text",
       
   669             mKeyData[KFourthKey]);
       
   670 
       
   671     OstTraceFunctionExit1(CPWEPUI_UPDATEWEPSETTINGS_EXIT,this);
       
   672     }
       
   673 
       
   674 /*!
       
   675  * Commit all WEP keys , except the one which was just set
       
   676  * 
       
   677  * \param index ; the index of the key that was just set
       
   678  */
       
   679 void CpWepUi::commitWEPkeys(int index)
       
   680     {
       
   681     OstTraceFunctionEntry1(CPWEPUI_COMMITWEPKEYS_ENTRY,this);
       
   682     //We have all data in Hex, so setting all WEP keys in hex
       
   683 
       
   684     if (index != KFirstKey) {
       
   685         //Get the right field to store
       
   686         CMManagerShim::ConnectionMethodAttribute keyEnumOne = getWEPKeyEnum(
       
   687                 KFirstKey);
       
   688 
       
   689         //Store the WEP key
       
   690         storeWEPKey(keyEnumOne, mKeyData[KFirstKey]);
       
   691     }
       
   692 
       
   693     if (index != KSecondKey) {
       
   694         //Get the right field to store
       
   695         CMManagerShim::ConnectionMethodAttribute keyEnumTwo = getWEPKeyEnum(
       
   696                 KSecondKey);
       
   697 
       
   698         //Store the WEP key
       
   699         storeWEPKey(keyEnumTwo, mKeyData[KSecondKey]);
       
   700     }
       
   701 
       
   702     if (index != KThirdKey) {
       
   703         //Get the right field to store
       
   704         CMManagerShim::ConnectionMethodAttribute keyEnumThree =
       
   705                 getWEPKeyEnum(KThirdKey);
       
   706 
       
   707         //Store the WEP key
       
   708         storeWEPKey(keyEnumThree, mKeyData[KThirdKey]);
       
   709     }
       
   710 
       
   711     if (index != KFourthKey) {
       
   712         //Get the right field to store
       
   713         CMManagerShim::ConnectionMethodAttribute keyEnumFour = getWEPKeyEnum(
       
   714                 KFourthKey);
       
   715 
       
   716         //Store the WEP key
       
   717         storeWEPKey(keyEnumFour, mKeyData[KFourthKey]);
       
   718     }
       
   719 
       
   720     OstTraceFunctionExit1(CPWEPUI_COMMITWEPKEYS_EXIT,this);
       
   721 }
       
   722 
       
   723 Q_EXPORT_PLUGIN2(CpWepUi, CpWepUi)
       
   724 ;