diff -r e03a3db4489e -r 9abfd4f00d37 securitysettings/cpwlansecurityuiplugins/cpwepui/src/cpwepui.cpp --- a/securitysettings/cpwlansecurityuiplugins/cpwepui/src/cpwepui.cpp Thu May 13 22:51:27 2010 +0300 +++ b/securitysettings/cpwlansecurityuiplugins/cpwepui/src/cpwepui.cpp Mon May 24 20:32:47 2010 +0300 @@ -17,24 +17,24 @@ */ /* - * %version: 16 % + * %version: 22 % */ //User Includes #include "cpwepui.h" +#include "wepkeyvalidator.h" + // System includes #include -#include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +//Trace Definition #include "OstTraceDefinitions.h" #ifdef OST_TRACE_COMPILER_IN_USE #include "cpwepuiTraces.h" @@ -45,6 +45,23 @@ //security mode static const int UI_ORDER_WEP = 10; +//! Index of first WEP key +static const int KFirstKey = 0; + +//! Index of second WEP key +static const int KSecondKey = 1; + +//! Index of third WEP key +static const int KThirdKey = 2; + +//! Index of fourth WEP key +static const int KFourthKey = 3; + +//!Maximum allowed length for WEP keys, in hex mode +static const int KMaxKeyLength = 26; + + + /*! \class CpWepUi \brief CpWepUi implements the WEP Security Settings Control Panel Plugin @@ -52,15 +69,20 @@ */ //Contructs WEP object CpWepUi::CpWepUi() : - mUi(NULL), mNewKeySelected(0), mTranslator(NULL), mCmCM(NULL), mCmId(0) + mUi(NULL), + mNewKeySelected(0), + mTranslator(new HbTranslator("cpwlansecsettingsplugin")), + mCmCM(NULL), + mCmId(0) { - mTranslator = new QTranslator(this); - mTranslator->load(":/loc/wlan_en_GB.qm"); - qApp->installTranslator(mTranslator); - - /* Install localization - mTranslator = QSharedPointer ( - new HbTranslator("wlan_en_GB"));*/ + //Initialize array members + for(int index=0;indexappendChild(wepKeyInUse); - createWEPKeyOneGroup(dataHelpper); + //Create Ui for all 4 WEP keys + createWEPKeyGroup(KFirstKey); - createWEPKeyTwoGroup(dataHelpper); + createWEPKeyGroup(KSecondKey); - createWEPKeyThreeGroup(dataHelpper); + createWEPKeyGroup(KThirdKey); - createWEPKeyFourGroup(dataHelpper); + createWEPKeyGroup(KFourthKey); + + //Add Connections(signals) + addConnections(dataHelpper); OstTraceFunctionExit1(CPWEPUI_UIINSTANCE_EXIT,this); return mUi; } -/*! - * Create Ui element with text edit for WEP KEY One - * - * \param dataHelper to add Connections - */ -void CpWepUi::createWEPKeyOneGroup(CpItemDataHelper &dataHelpper) - { - OstTraceFunctionEntry1(CPWEPUI_CREATEWEPKEYONEGROUP_ENTRY,this); - mWepKeyText[KFirstKey] = new CpSettingFormItemData( - HbDataFormModelItem::TextItem, - hbTrId("txt_occ_subhead_wep_key_1"), mUi); - - if (mKeyData[KFirstKey].length() != 0) { - mWepKeyText[KFirstKey]->setContentWidgetData("text", - mKeyData[KFirstKey]); - } - mWepKeyText[KFirstKey]->setContentWidgetData("echoMode", 2); - mWepKeyText[KFirstKey]->setContentWidgetData("smileysEnabled", "false"); - - dataHelpper.addConnection(mWepKeyText[KFirstKey], - SIGNAL( editingFinished ()), this, SLOT(wepKeyOneChanged() )); - - mUi->appendChild(mWepKeyText[KFirstKey]); - OstTraceFunctionExit1(CPWEPUI_CREATEWEPKEYONEGROUP_EXIT,this); - } /*! - * Create Ui element with text edit for WEP KEY Two - * \param dataHelper to add Connections - */ -void CpWepUi::createWEPKeyTwoGroup(CpItemDataHelper &dataHelpper) -{ - OstTraceFunctionEntry1(CPWEPUI_CREATEWEPKEYTWOGROUP_ENTRY,this); - mWepKeyText[KSecondKey] = new CpSettingFormItemData( - HbDataFormModelItem::TextItem, - hbTrId("txt_occ_subhead_wep_key_2"), mUi); + Validates current security settings. This function is called whenever + user tries to exit from the settings view. If the plugin determines + that some settings need editing before considered valid, it shall + return false. A dialog will be shown to the user indicating that + settings are still incomplete and asking if he/she wishes to exit + anyway. - if (mKeyData[KSecondKey].length() != 0) { - mWepKeyText[KSecondKey]->setContentWidgetData("text", - mKeyData[KSecondKey]); + \return True if security settings for WEP are valid, false if not. +*/ +bool CpWepUi::validateSettings() +{ + bool ret(false); + //Check the latest string entered for the WEP key in the text box + QVariant keyValue = mWepKeyText[mNewKeySelected]->contentWidgetData("text"); + QString keyString = keyValue.toString(); + + WepKeyValidator::KeyStatus keystatus = WepKeyValidator::validateWepKey(keyString); + + //Check if key is valid and not of zero length + if(keystatus==WepKeyValidator::KeyStatusOk) { + ret = true; } - mWepKeyText[KSecondKey]->setContentWidgetData("echoMode", 2); - mWepKeyText[KSecondKey]->setContentWidgetData("smileysEnabled", "false"); - dataHelpper.addConnection(mWepKeyText[KSecondKey], - SIGNAL( editingFinished ()), this, SLOT(wepKeyTwoChanged() )); - - mUi->appendChild(mWepKeyText[KSecondKey]); - OstTraceFunctionExit1(CPWEPUI_CREATEWEPKEYTWOGROUP_EXIT,this); + return ret; } /*! - * Create Ui element with text edit for WEP KEY Three - * \param dataHelper to add Connections - */ -void CpWepUi::createWEPKeyThreeGroup(CpItemDataHelper &dataHelpper) -{ - OstTraceFunctionEntry1(CPWEPUI_CREATEWEPKEYTHREEGROUP_ENTRY,this); - mWepKeyText[KThirdKey] = new CpSettingFormItemData( + * Create Ui element with text edit for WEP KEYS + * + * \param index of the WEP key + * */ +void CpWepUi::createWEPKeyGroup(int index) + { + OstTraceFunctionEntry1(CPWEPUI_CREATEWEPKEYGROUP_ENTRY,this); + QString textId; + + switch(index) + { + case KFirstKey: + textId = hbTrId("txt_occ_subhead_wep_key_1"); + break; + + + case KSecondKey: + textId = hbTrId("txt_occ_subhead_wep_key_2"); + break; + + case KThirdKey: + textId = hbTrId("txt_occ_subhead_wep_key_3"); + break; + + case KFourthKey: + textId = hbTrId("txt_occ_subhead_wep_key_4"); + break; + } + + + mWepKeyText[index] = new CpSettingFormItemData( HbDataFormModelItem::TextItem, - hbTrId("txt_occ_subhead_wep_key_3"), mUi); + textId, mUi); - if (mKeyData[KThirdKey].length() != 0) { - mWepKeyText[KThirdKey]->setContentWidgetData("text", - mKeyData[KThirdKey]); + if (mKeyData[index].length() != 0) { + mWepKeyText[index]->setContentWidgetData("text", + mKeyData[index]); } - mWepKeyText[KThirdKey]->setContentWidgetData("echoMode", 2); - mWepKeyText[KThirdKey]->setContentWidgetData("smileysEnabled", "false"); - dataHelpper.addConnection(mWepKeyText[KThirdKey], - SIGNAL( editingFinished ()), this, SLOT(wepKeyThreeChanged() )); + mWepKeyText[index]->setContentWidgetData("echoMode",HbLineEdit::PasswordEchoOnEdit); + mWepKeyText[index]->setContentWidgetData("smileysEnabled", "false"); - mUi->appendChild(mWepKeyText[KThirdKey]); - OstTraceFunctionExit1(CPWEPUI_CREATEWEPKEYTHREEGROUP_EXIT,this); -} + + mUi->appendChild(mWepKeyText[index]); + OstTraceFunctionExit1(CPWEPUI_CREATEWEPKEYGROUP_EXIT,this); + } + /*! - * Create Ui element with text edit for WEP KEY Four - * \param dataHelper to add Connections + * Add signals to all the text Edit of WEP key groups. + * + * \param dataHelper ; to add Connections */ -void CpWepUi::createWEPKeyFourGroup(CpItemDataHelper &dataHelpper) -{ - OstTraceFunctionEntry1(CPWEPUI_CREATEWEPKEYFOURGROUP_ENTRY,this); - mWepKeyText[KFourthKey] = new CpSettingFormItemData( - HbDataFormModelItem::TextItem, - hbTrId("txt_occ_subhead_wep_key_4"), mUi); +void CpWepUi::addConnections(CpItemDataHelper &dataHelpper) + { + OstTraceFunctionEntry1( CPWEPUI_ADDCONNECTIONS_ENTRY, this ); + + dataHelpper.addConnection(mWepKeyText[KFirstKey], + SIGNAL( editingFinished ()), this, SLOT(wepKeyOneChanged() )); + + dataHelpper.addConnection(mWepKeyText[KSecondKey], + SIGNAL( editingFinished ()), this, SLOT(wepKeyTwoChanged() )); + + dataHelpper.addConnection(mWepKeyText[KThirdKey], + SIGNAL( editingFinished ()), this, SLOT(wepKeyThreeChanged() )); + + dataHelpper.addConnection(mWepKeyText[KFourthKey], + SIGNAL( editingFinished ()), this, SLOT(wepKeyFourChanged() )); + + dataHelpper.connectToForm(SIGNAL(itemShown (const QModelIndex &) ), + this, SLOT(setEditorPreferences(const QModelIndex &))); + + OstTraceFunctionExit1( CPWEPUI_ADDCONNECTIONS_EXIT, this ); + } - if (mKeyData[KFourthKey].length() != 0) { - mWepKeyText[KFourthKey]->setContentWidgetData("text", - mKeyData[KFourthKey]); - } - mWepKeyText[KFourthKey]->setContentWidgetData("echoMode", 2); - mWepKeyText[KFourthKey]->setContentWidgetData("smileysEnabled", "false"); - dataHelpper.addConnection(mWepKeyText[KFourthKey], - SIGNAL( editingFinished ()), this, SLOT(wepKeyFourChanged() )); - - mUi->appendChild(mWepKeyText[KFourthKey]); - OstTraceFunctionExit1(CPWEPUI_CREATEWEPKEYFOURGROUP_EXIT,this); -} /*! * Slot to handle , if a different wep key (index) @@ -295,6 +327,9 @@ OstTrace1( TRACE_ERROR, CPWEPUI_WEPKEYINUSECHANGED, "Error wepKeyInUse returned %d", err ); } tryUpdate(); + + //Store the wep key in use + mNewKeySelected = wepKeyInUse; OstTraceFunctionExit1(CPWEPUI_WEPKEYINUSECHANGED_EXIT,this); } @@ -400,6 +435,7 @@ commitWEPkeys(index); } else { + OstTrace0( TRACE_ERROR, CPWEPUI_WEPKEYTEXTCHANGED_ERROR, "CpWepUi::wepKeyTextChanged Invalid WEP Key Input" ); showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId( "txt_occ_info_invalid_input")); } @@ -407,6 +443,29 @@ } /*! + * Slot that configures the editor settings for all WEP key fields. + * This slot is invoked whenever a new item(s) are shown in the current view + * + * \param modelIndex Index of the current item in the model + */ +void CpWepUi::setEditorPreferences(const QModelIndex &modelIndex) +{ + + HbDataFormModelItem *item = mItemDataHelper->modelItemFromModelIndex(modelIndex); + + HbSmileyTheme smiley; + /* Configure settings only for text fields*/ + if(item->type() == HbDataFormModelItem::TextItem) { + HbLineEdit *edit = qobject_cast(mItemDataHelper->widgetFromModelIndex(modelIndex)); + HbEditorInterface editInterface(edit); + editInterface.setInputConstraints(HbEditorConstraintLatinAlphabetOnly); + edit->setInputMethodHints(Qt::ImhNoPredictiveText); + edit->setMaxLength(KMaxKeyLength); + } +} + + +/*! * Store the WEP key in Comms * \enumValue the right field represented by the enum value * \key the WEP key String to store @@ -508,7 +567,7 @@ mKeyData.insert(KFirstKey, mCmCM->getString8Attribute( CMManagerShim::WlanWepKey1InHex)); - mKeyData.insert(KSecondKey, mCmCM->getString8Attribute( + mKeyData.insert(KSecondKey,mCmCM->getString8Attribute( CMManagerShim::WlanWepKey2InHex)); mKeyData.insert(KThirdKey, mCmCM->getString8Attribute(