securitysettings/cpwlansecurityuiplugins/cpwpacmnui/src/cpwpacmnui.cpp
changeset 22 093cf0757204
child 26 9abfd4f00d37
equal deleted inserted replaced
20:8b3129ac4c0f 22:093cf0757204
       
     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 the License "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 WPA/WPA2/802_Dot_1x configuration
       
    16  *
       
    17  */
       
    18 
       
    19 /*
       
    20  * %version: 17 %
       
    21  */
       
    22 
       
    23 // System includes
       
    24 #include <QStringList>
       
    25 #include <eapqtconfiginterface.h>
       
    26 #include <cmconnectionmethod_shim.h>
       
    27 #include <cmmanagerdefines_shim.h>
       
    28 
       
    29 // User includes
       
    30 #include "cpwpacmnui.h"
       
    31 //#include "cpwpacmneapui.h"
       
    32 
       
    33 #include "OstTraceDefinitions.h"
       
    34 #ifdef OST_TRACE_COMPILER_IN_USE
       
    35 #include "cpwpacmnuiTraces.h"
       
    36 #endif
       
    37 
       
    38 /*!
       
    39  \class CpWpaCmnUi
       
    40  \brief CpWpaCmnUi implements the common Ui for WPA/WPA2/802.1x/WPA2 only 
       
    41  Security Settings Control Panel Plugins,
       
    42  which will allow viewing/editing of WPA/WPA2/802.1x/WPA2 Security Settings.
       
    43  */
       
    44 //Contructs Common Ui (WPA/WPA2/802.1x/WPA2only) object
       
    45 CpWpaCmnUi::CpWpaCmnUi(CMManagerShim::WlanSecMode securityMode, CpItemDataHelper &dataHelpper) :
       
    46     mCmnUi(NULL), mDataHelper(dataHelpper), mPskKeyText(NULL), mEapPlugins(
       
    47             NULL), mWpaEapItem(NULL), mEapEntry(NULL)
       
    48 {
       
    49     mSecurityMode = securityMode;
       
    50     mEnablePskMode = true;
       
    51 }
       
    52 //Deletes objects owned by Common Ui
       
    53 CpWpaCmnUi::~CpWpaCmnUi()
       
    54 {
       
    55     //delete all dynamically allocated objects
       
    56     OstTraceFunctionEntry1(CPWPACMNUI_CPWPACMNUI_ENTRY,this);
       
    57 
       
    58     mCmnUi = NULL;
       
    59     
       
    60     mConnMethod = NULL;
       
    61 
       
    62     OstTraceFunctionExit1(CPWPACMNUI_CPWPACMNUI_EXIT,this);
       
    63 }
       
    64 
       
    65 // ======== MEMBER FUNCTIONS ========
       
    66 
       
    67 /*!
       
    68  * Creates the Ui instance based on the security mode;WPAWPA2/802.1x/WPA2 only 
       
    69  * Owns the Ui instance
       
    70  * 
       
    71  * \param eapQtConfigInterface to list all eap plugins
       
    72  * \param mCmCM Connection MethoD Qt interface
       
    73  * 
       
    74  * \return Ui instance for the security mode set
       
    75  */
       
    76 
       
    77 CpSettingFormItemData* CpWpaCmnUi::createUi(
       
    78         EapQtConfigInterface *eapQtConfigInterface,
       
    79         CmConnectionMethodShim *cmCM)
       
    80 {
       
    81 
       
    82     OstTraceFunctionEntry1(CPWPACMNUI_CREATEUI_ENTRY,this);
       
    83     int err;
       
    84 
       
    85     mConnMethod = cmCM;
       
    86 
       
    87     //Read values From CommsDatbase
       
    88     QT_TRYCATCH_ERROR(err, ( readValues()));
       
    89     if(err !=KErrNone) {
       
    90           OstTrace1( TRACE_ERROR, CPWPACMNUI_CREATEUI, "CPWPACMNUI ReadValues returned %d", err );
       
    91     }
       
    92 
       
    93     mCmnUi = new CpSettingFormItemData(HbDataFormModelItem::GroupItem,
       
    94             hbTrId("txt_occ_subhead_security_settings"));
       
    95 
       
    96     mEapQtConfigInterface = eapQtConfigInterface;
       
    97     //mPlugins.append(mEapQtConfigInterface->supportedOuterTypes());
       
    98 
       
    99     //PSK / EAP ?
       
   100     mWpaEapItem = new CpSettingFormItemData(
       
   101             HbDataFormModelItem::ComboBoxItem, hbTrId(
       
   102                     "txt_occ_setlabel_wpawpa2"),mCmnUi);
       
   103     QStringList wpatype;
       
   104     //wpatype.append(hbTrId("txt_occ_setlabel_wpawpa2_val_eap"));
       
   105     wpatype.append(hbTrId("txt_occ_setlabel_wpawpa2_val_preshared_key"));
       
   106 
       
   107     mWpaEapItem->setContentWidgetData("items", wpatype);
       
   108     mWpaEapItem->setContentWidgetData("currentIndex",0/*To use mEnablePskMode when both modes are available*/);
       
   109 
       
   110     mDataHelper.addConnection(mWpaEapItem,
       
   111             SIGNAL(currentIndexChanged(int)), this,
       
   112             SLOT(wpaTypeChanged(int)));
       
   113 
       
   114     //1.Pre-Shared Key
       
   115     mPskKeyText = new CpSettingFormItemData(
       
   116             HbDataFormModelItem::TextItem, hbTrId(
       
   117                     "txt_occ_setlabel_preshared_key"),mCmnUi);
       
   118 
       
   119     mPskKeyText->setContentWidgetData("text", mKeyData);
       
   120     mPskKeyText->setContentWidgetData("echoMode", 2);
       
   121 
       
   122     mPskKeyText->setContentWidgetData("smileysEnabled", "false");
       
   123     mDataHelper.addConnection(mPskKeyText, SIGNAL( editingFinished ()),
       
   124             this, SLOT(pskKeyChanged() ));
       
   125 
       
   126     //2.EAP
       
   127     /*  mEapPlugins = new CpSettingFormItemData(
       
   128                 HbDataFormModelItem::ComboBoxItem, hbTrId(
       
   129                         "txt_occ_setlabel_eap_type"));
       
   130 
       
   131         QStringList items;
       
   132         for (int i = 0; i < mPlugins.length(); ++i)
       
   133             {
       
   134             items << mPlugins.at(i)->localizationId();
       
   135             }
       
   136         mPluginCurrent = 0;
       
   137         mEapPlugins->setContentWidgetData("items", items);
       
   138         //Set the last EAP chosen , by reading from CommsDb
       
   139         mDataHelper.addConnection(mEapPlugins,
       
   140                 SIGNAL(currentIndexChanged(int)), this,
       
   141                 SLOT(eapTypeChanged(int)));
       
   142 
       
   143         mEapEntry = new EapEntyItemData(this, mDataHelper, hbTrId(
       
   144                 "txt_occ_button_eap_type_settings"), QString(""));*/
       
   145 
       
   146     mUnencryptedConnection = new CpSettingFormItemData(
       
   147             HbDataFormModelItem::CheckBoxItem, hbTrId(
       
   148                     "txt_occ_setlabel_unencrypted_connection"),mCmnUi);
       
   149 
       
   150     mUnencryptedConnection->setContentWidgetData("text", hbTrId(
       
   151             "txt_occ_setlabel_unencrypted_connection_val_allowe"));
       
   152 
       
   153     //Kept Unchecked by default , but to be read from Comms DB
       
   154     mUnencryptedConnection->setContentWidgetData("checkState",
       
   155             "Unchecked");
       
   156 
       
   157     mDataHelper.addConnection(mUnencryptedConnection,
       
   158             SIGNAL( stateChanged(int)), this,
       
   159             SLOT(unencryptConnStateChanged(int)));
       
   160 
       
   161     //LoadUi based on the security mode 
       
   162     loadUi();
       
   163 
       
   164     OstTraceFunctionExit1(CPWPACMNUI_CREATEUI_EXIT,this);
       
   165     return mCmnUi;
       
   166 
       
   167 }
       
   168 
       
   169 // ======== LOCAL FUNCTIONS ========
       
   170 
       
   171 /*! 
       
   172  Load the CpSettingFormItemData components, based on the security 
       
   173  mode chosen. Only those components that are required by that security
       
   174  mode are loaded
       
   175  */
       
   176 void CpWpaCmnUi::loadUi()
       
   177 {
       
   178     OstTraceFunctionEntry1(CPWPACMNUI_LOADUI_ENTRY,this);
       
   179     int secMode = mSecurityMode;
       
   180     switch (secMode)
       
   181         {
       
   182         case CMManagerShim::WlanSecModeWpa:
       
   183         case CMManagerShim::WlanSecModeWpa2:
       
   184             {
       
   185                 if (mEnablePskMode) {
       
   186                     mCmnUi->appendChild(mWpaEapItem);
       
   187                     mCmnUi->appendChild(mPskKeyText);
       
   188                 }
       
   189                 /*else {
       
   190                     //do nothing, no EAP 
       
   191                     mCmnUi->appendChild(mWpaEapItem);
       
   192                     mCmnUi->appendChild(mEapPlugins);
       
   193                     mCmnUi->appendChild(mEapEntry);
       
   194                 }*/
       
   195 
       
   196             }
       
   197             break;
       
   198 
       
   199         /*case CMManagerShim::WlanSecMode802_1x:
       
   200             {
       
   201             mCmnUi->appendChild(mEapPlugins);
       
   202             mCmnUi->appendChild(mEapEntry);
       
   203             mCmnUi->appendChild(mUnencryptedConnection);
       
   204             }
       
   205             break;*/
       
   206         default:
       
   207             break;
       
   208         } 
       
   209     OstTraceFunctionExit1(CPWPACMNUI_LOADUI_EXIT,this);
       
   210 }
       
   211 
       
   212 /*! 
       
   213  Load the CpSettingFormItemData components,for the
       
   214  Pre-Shared key mode
       
   215  */
       
   216 /*void CpWpaCmnUi::loadWPAPskView()
       
   217 {
       
   218     OstTraceFunctionEntry1(CPWPACMNUI_LOADWPAPSKVIEW_ENTRY,this);
       
   219     mCmnUi->appendChild(mPskKeyText);
       
   220     OstTraceFunctionExit1(CPWPACMNUI_LOADWPAPSKVIEW_EXIT,this);
       
   221 }*/
       
   222 
       
   223 /*! 
       
   224  Load the CpSettingFormItemData components,for the
       
   225  EAP  mode
       
   226  */
       
   227 /*void CpWpaCmnUi::loadWPAEapView()
       
   228 {
       
   229     OstTraceFunctionEntry1(CPWPACMNUI_LOADWPAEAPVIEW_ENTRY,this);
       
   230     mCmnUi->appendChild(mEapPlugins);
       
   231     mCmnUi->appendChild(mEapEntry);
       
   232     OstTraceFunctionExit1(CPWPACMNUI_LOADWPAEAPVIEW_EXIT,this);
       
   233 }*/
       
   234 
       
   235 /*! 
       
   236  Load the CpSettingFormItemData components,for the
       
   237  EAP  mode
       
   238  */
       
   239 /*CpBaseSettingView* CpWpaCmnUi::eapUiInstance()
       
   240 {
       
   241     OstTraceFunctionEntry1(CPWPACMNUI_EAPUIINSTANCE_ENTRY,this); 
       
   242     OstTraceFunctionExit1(CPWPACMNUI_EAPUIINSTANCE_EXIT,this);
       
   243 
       
   244     return mEapQtConfigInterface->uiInstance(
       
   245             mPlugins.at(mPluginCurrent)->pluginHandle());
       
   246     return NULL;
       
   247 }*/
       
   248 
       
   249 /*!
       
   250  Slot to handle change in wpa mode :- PSK /EAP
       
   251  Emits a mode change signal to the  security plugin 
       
   252  to indicate the change
       
   253 
       
   254  \param pskEnable the current mode chosen
       
   255  */
       
   256 /*void CpWpaCmnUi::wpaTypeChanged(int pskEnable)
       
   257 {
       
   258     OstTraceFunctionEntry1(CPWPACMNUI_WPATYPECHANGED_ENTRY,this);
       
   259     switch (pskEnable)
       
   260         {
       
   261         case 0:
       
   262             {
       
   263             RemovePskView();
       
   264             LoadWPAEapView();
       
   265             }
       
   266             break;
       
   267 
       
   268         case 1:
       
   269             {
       
   270             RemoveEapView();
       
   271             LoadWPAPskView();
       
   272             }
       
   273             break;
       
   274         } //do nothing , only PSK mode, no EAP
       
   275     OstTraceFunctionExit1(CPWPACMNUI_WPATYPECHANGED_EXIT,this);
       
   276     //Emit signal back to plugin
       
   277     emit pskEapModeToggled(pskEnable);
       
   278 }*/
       
   279 
       
   280 /*!
       
   281  * Unload components related to Pre-Shared key mode
       
   282  */
       
   283 /*void CpWpaCmnUi::removePskView()
       
   284 {
       
   285     OstTraceFunctionEntry1(CPWPACMNUI_REMOVEPSKVIEW_ENTRY,this);
       
   286     int indexOfPsk = mCmnUi->indexOf(mPskKeyText);
       
   287     mCmnUi->removeChild(indexOfPsk);
       
   288     OstTraceFunctionExit1(CPWPACMNUI_REMOVEPSKVIEW_EXIT,this);
       
   289 }*/
       
   290 
       
   291 /*!
       
   292  * Unload components related to EAP mode
       
   293  */
       
   294 /*void CpWpaCmnUi::removeEapView()
       
   295 {
       
   296     OstTraceFunctionEntry1(CPWPACMNUI_REMOVEEAPVIEW_ENTRY,this);
       
   297     int indexOfEapPlugin = mCmnUi->indexOf(mEapPlugins);
       
   298     mCmnUi->removeChild(indexOfEapPlugin);
       
   299 
       
   300     int indexOfEapEntry = mCmnUi->indexOf(mEapEntry);
       
   301     mCmnUi->removeChild(indexOfEapEntry);
       
   302     OstTraceFunctionExit1(CPWPACMNUI_REMOVEEAPVIEW_EXIT,this);
       
   303 }*/
       
   304 
       
   305 /*!
       
   306  Slot to handle change in eap method in use.
       
   307  Emits signal back to the security plugin to indicate 
       
   308  the change
       
   309  \param currentplugin plugin number to indicate the
       
   310  eap method in use
       
   311  */
       
   312 /*void CpWpaCmnUi::eapTypeChanged(int eapPlugin)
       
   313 {
       
   314     OstTraceFunctionEntry1(CPWPACMNUI_EAPTYPECHANGED_ENTRY,this);
       
   315     mPluginCurrent = eapPlugin;
       
   316     OstTraceFunctionExit1(CPWPACMNUI_EAPTYPECHANGED_EXIT,this);
       
   317     emit eapPluginChanged(mPluginCurrent);
       
   318 }*/
       
   319 
       
   320 /*!
       
   321  Slot to handle change in pre-shared key string
       
   322  Emits signal back to the security plugin to indicate 
       
   323  the change
       
   324 
       
   325  */
       
   326 void CpWpaCmnUi::pskKeyChanged()
       
   327 {
       
   328     OstTraceFunctionEntry1(CPWPACMNUI_PSKKEYCHANGED_ENTRY,this);
       
   329     QVariant keyValue = mPskKeyText->contentWidgetData("text");
       
   330     QString keyString = keyValue.toString();
       
   331     OstTraceFunctionExit1(CPWPACMNUI_PSKKEYCHANGED_EXIT,this);
       
   332     //Emit signal back to plugin
       
   333     emit keyChanged(keyString);
       
   334 }
       
   335 
       
   336 /*!
       
   337  Slot to handle change in the state of unencrypted connection;
       
   338  to indicate if such a connection is allowed.
       
   339  Emits signal back to the security plugin to indicate 
       
   340  the change
       
   341  \param state checked-Allowed / Unchecked-Not allowed 
       
   342  */
       
   343 /*void CpWpaCmnUi::unencryptConnStateChanged(int state)
       
   344 {
       
   345     OstTraceFunctionEntry1(CPWPACMNUI_UNENCRYPTCONNSTATECHANGED_ENTRY,this); emit
       
   346     connectionStateChanged(state);
       
   347     OstTraceFunctionExit1(CPWPACMNUI_UNENCRYPTCONNSTATECHANGED_EXIT,this);
       
   348 }*/
       
   349 
       
   350 /*!
       
   351  * Reads the wlan security fields from CommsDb 
       
   352  */
       
   353 void CpWpaCmnUi::readValues()
       
   354 {
       
   355     OstTraceFunctionEntry1(CPWPACMNUI_READVALUES_ENTRY,this);
       
   356     switch (mSecurityMode)
       
   357         {
       
   358         case CMManagerShim::WlanSecModeWpa:
       
   359         case CMManagerShim::WlanSecModeWpa2:
       
   360             {
       
   361             loadWPA_WPA2Fields();
       
   362             }
       
   363             break;
       
   364 
       
   365        /* case CMManagerShim::WlanSecMode802_1x:
       
   366             {
       
   367             load802Dot1xFields();
       
   368             }
       
   369             break;*/
       
   370 
       
   371         default:
       
   372             break;
       
   373         } 
       
   374     OstTraceFunctionExit1(CPWPACMNUI_READVALUES_EXIT,this);
       
   375 }
       
   376 
       
   377 /*!
       
   378  * Reads the wlan security wpa/wpa2 related fields from CommsDb 
       
   379  */
       
   380 void CpWpaCmnUi::loadWPA_WPA2Fields()
       
   381 {
       
   382     OstTraceFunctionEntry1(CPWPACMNUI_LOADWPAFIELDS_ENTRY,this);
       
   383     /*mEnablePskMode = mConnMethod->getIntAttribute(
       
   384             CMManagerShim::WlanEnableWpaPsk);*/
       
   385 			
       
   386 	 //only PSK mode enabled(temporary);to be read from Comms later
       
   387     mEnablePskMode = true ; 		
       
   388     
       
   389     //set the same to Comms(temporary) ; the mode to be set , depends on what user chooses 
       
   390     //between PSK & EAP
       
   391      mConnMethod->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk,mEnablePskMode);
       
   392 			
       
   393     if (mEnablePskMode) {
       
   394         mKeyData = mConnMethod->getString8Attribute(
       
   395                 CMManagerShim::WlanWpaPreSharedKey);
       
   396     }
       
   397    /* else {
       
   398         //mcurrentEapPlugin = mCMExtShim->GetIntAttribute( use appropriate enum to get the eap plugin index );
       
   399     } */
       
   400     OstTraceFunctionExit1(CPWPACMNUI_LOADWPAFIELDS_EXIT,this);
       
   401 }
       
   402 
       
   403 /*!
       
   404  * Reads the wlan security eap related fields from CommsDb 
       
   405  */
       
   406 /*void CpWpaCmnUi::load802Dot1xFields()
       
   407 {
       
   408     OstTraceFunctionEntry1(CPWPACMNUI_LOAD802DOT1XFIELDS_ENTRY,this);
       
   409     //mcurrentEapPlugin = mCMExtShim->GetIntAttribute(use appropriate enum to get the eap plugin index);
       
   410 
       
   411     //unencryptStateChanged = mConnMethod->getIntAttribute(CMManagerShim::EWlan802_1xAllowUnencrypted);
       
   412     OstTraceFunctionExit1(CPWPACMNUI_LOAD802DOT1XFIELDS_EXIT,this);
       
   413 }*/
       
   414 
       
   415 /*!
       
   416  * Reset the values on the corresponding Ui elements
       
   417  */
       
   418 void CpWpaCmnUi::reset()
       
   419     {
       
   420     OstTraceFunctionEntry1(CPWPACMNUI_RESET_ENTRY,this);
       
   421     //Read values from Comms and update the Ui items
       
   422     readValues();
       
   423     
       
   424     switch (mSecurityMode)
       
   425           {
       
   426           case CMManagerShim::WlanSecModeWpa:
       
   427           case CMManagerShim::WlanSecModeWpa2:
       
   428               {
       
   429                   if(mEnablePskMode) {
       
   430                       mPskKeyText->setContentWidgetData("text", mKeyData);
       
   431                   }
       
   432               }
       
   433               break;
       
   434 
       
   435           /*case CMManagerShim::WlanSecMode802_1x:
       
   436               {
       
   437               //Set appropriate value in widget for 802.1x
       
   438               if(mEnablePskMode) {
       
   439               mPskKeyText->setContentWidgetData("checkState", mKeyData);
       
   440               }
       
   441               break;*/
       
   442 
       
   443           default:
       
   444               break;
       
   445           }
       
   446     OstTraceFunctionExit1(CPWPACMNUI_RESET_EXIT,this);
       
   447     }
       
   448