securitysettings/cpwlansecurityuiplugins/cpwpa2ui/src/cpwpa2ui.cpp
branchGCC_SURGE
changeset 40 60f08993dad0
parent 39 fe6b6762fccd
equal deleted inserted replaced
29:77618ad58aba 40:60f08993dad0
     1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * All rights reserved.
     3  * All rights reserved.
     3  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     4  * under the terms of the License "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     5  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     6  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  *
     8  *
     8  * Initial Contributors:
     9  * Initial Contributors:
     9  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    14  *    Control Panel QT UI for WPA2 only configuration
    15  *    Control Panel QT UI for WPA2 only configuration
    15  *
    16  *
    16  */
    17  */
    17 
    18 
    18 /*
    19 /*
    19  * %version: 17 %
    20  * %version: tr1cfwln#23 %
    20  */
    21  */
    21 
    22 
    22 // User includes
    23 // User includes
    23 #include "cpwpa2ui.h"
    24 #include "cpwpa2ui.h"
    24 #include "cpwpacmnui.h"
    25 #include "cpwpacmnui.h"
    25 #include "wpa2keyvalidator.h"
       
    26 
    26 
    27 // System includes
    27 // System includes
    28 #include <HbDeviceNotificationDialog>
       
    29 #include <cmmanagerdefines_shim.h>
    28 #include <cmmanagerdefines_shim.h>
    30 #include <cmconnectionmethod_shim.h>
    29 #include <cmconnectionmethod_shim.h>
    31 #include <eapqtconfiginterface.h>
    30 #include <eapqtconfiginterface.h>
    32 #include <QStringList>
    31 #include <QStringList>
    33 #include <QLocale>
    32 #include <HbTranslator>
    34 #include <QCoreApplication>
       
    35 
    33 
       
    34 //Trace Definition
    36 #include "OstTraceDefinitions.h"
    35 #include "OstTraceDefinitions.h"
    37 #ifdef OST_TRACE_COMPILER_IN_USE
    36 #ifdef OST_TRACE_COMPILER_IN_USE
    38 #include "cpwpa2uiTraces.h"
    37 #include "cpwpa2uiTraces.h"
    39 #endif
    38 #endif
    40 
    39 
    41 
    40 
    42 // Constants
    41 // Constants
    43 //The order in which WPA2 only mode appears in the list of available 
    42 //The order in which WPA2 only mode appears in the list of available 
    44 //security mode
    43 //security mode
    45 const int UI_ORDER_WPA2_ONLY = 50;
    44 const int UI_ORDER_WPA2_ONLY = 30;
    46 
    45 
    47 /*!
    46 /*!
    48  \class CpWpa2Ui
    47  \class CpWpa2Ui
    49  \brief CpWpa2Ui implements the  Ui for WPA2 only 
    48  \brief CpWpa2Ui implements the  Ui for WPA2 only 
    50  Security Settings Control Panel Plugin,
    49  Security Settings Control Panel Plugin,
    51  which will allow viewing/editing of WPA2 only Security Settings.
    50  which will allow viewing/editing of WPA2 only Security Settings.
    52  */
    51  */
    53 //Contructs WPA2 object
    52 /*!
       
    53  * Constructor
       
    54  * 
       
    55  */
    54 CpWpa2Ui::CpWpa2Ui() :
    56 CpWpa2Ui::CpWpa2Ui() :
    55     mUi(NULL),  mCmCM(NULL), mEapQtConfigInterface(NULL),
    57     mUi(NULL), 
    56             mWpa2Ui(NULL)
    58     mTranslator(new HbTranslator("cpwlansecsettingsplugin")),
       
    59     mCmCM(NULL),
       
    60     mEapQtConfigInterface(NULL),
       
    61     mWpa2Ui(NULL)
    57 {
    62 {
    58     mTranslator = new QTranslator(this);
       
    59     mTranslator->load(":/loc/wlan_en_GB.qm");
       
    60 
       
    61     qApp->installTranslator(mTranslator);
       
    62     
       
    63     /*mTranslator = QSharedPointer<HbTranslator> (
       
    64                new HbTranslator("wlan_en_GB"));*/
       
    65 
    63 
    66 }
    64 }
    67 
    65 
    68 //Deletes all objects WPA2 owns
    66 //Destructor
    69 CpWpa2Ui::~CpWpa2Ui()
    67 CpWpa2Ui::~CpWpa2Ui()
    70 {
    68 {
    71     OstTraceFunctionEntry1(CPWPA2UI_CPWPA2UI_ENTRY,this);
    69     OstTraceFunctionEntry1(CPWPA2UI_CPWPA2UI_ENTRY,this);
    72     //delete mEapQtConfigInterface;
    70     delete mEapQtConfigInterface;
       
    71     delete mTranslator;
    73     OstTraceFunctionExit1(CPWPA2UI_CPWPA2UI_EXIT,this);
    72     OstTraceFunctionExit1(CPWPA2UI_CPWPA2UI_EXIT,this);
    74 }
    73 }
    75 
    74 
    76 // ======== MEMBER FUNCTIONS ========
    75 // ======== MEMBER FUNCTIONS ========
    77 
    76 
    80 
    79 
    81  \return Security mode identifier
    80  \return Security mode identifier
    82  */
    81  */
    83 CMManagerShim::WlanSecMode CpWpa2Ui::securityMode() const
    82 CMManagerShim::WlanSecMode CpWpa2Ui::securityMode() const
    84 {
    83 {
    85     OstTraceFunctionEntry1(CPWPA2UI_MODE_ENTRY,this);
    84     OstTraceFunctionEntry1(CPWPA2UI_SECURITYMODE_ENTRY,this);
    86     OstTraceFunctionExit1(CPWPA2UI_MODE_EXIT,this);
    85     OstTraceFunctionExit1(CPWPA2UI_SECURITYMODE_EXIT,this);
    87     //return security mode
    86     //return security mode
    88     return CMManagerShim::WlanSecModeWpa2;
    87     return CMManagerShim::WlanSecModeWpa2;
    89 }
    88 }
    90 
    89 
    91 /*!
    90 /*!
    95  
    94  
    96  \return Localization text ID
    95  \return Localization text ID
    97  */
    96  */
    98 QString CpWpa2Ui::securityModeTextId() const
    97 QString CpWpa2Ui::securityModeTextId() const
    99 {
    98 {
   100     OstTraceFunctionEntry1(CPWPA2UI_LOCALIZATIONID_ENTRY,this);
    99     OstTraceFunctionEntry1(CPWPA2UI_SECURITYMODETEXTID_ENTRY,this);
   101     OstTraceFunctionExit1(CPWPA2UI_LOCALIZATIONID_EXIT,this);
   100     OstTraceFunctionExit1(CPWPA2UI_SECURITYMODETEXTID_EXIT,this);
   102     return "txt_occ_setlabel_wlan_security_mode_val_wpa2_only";
   101     return "txt_occ_setlabel_wlan_security_mode_val_wpa2_only";
   103 }
   102 }
   104 
   103 
   105 /*! 
   104 /*! 
   106  Sets the database reference (WLAN Service Table ID).
   105  Sets the database reference IAP id.
   107 
   106 
   108  \param id Database reference
   107  \param id Database reference
   109  */
   108  */
   110 void CpWpa2Ui::setReference(CmConnectionMethodShim *cmCm, uint id)
   109 void CpWpa2Ui::setReference(CmConnectionMethodShim *cmCm, uint id)
   111 {
   110 {
   112     OstTraceFunctionEntry1(CPWPA2UI_SETREFERENCE_ENTRY,this);
   111     OstTraceFunctionEntry1(CPWPA2UI_SETREFERENCE_ENTRY,this);
   113     // Assuming that id is the connection method Id/IAP Id.
   112     if (!mEapQtConfigInterface) {
   114 
       
   115     mCmId = id;
       
   116 
       
   117     /*if (!mEapQtConfigInterface) {
       
   118         mEapQtConfigInterface = new EapQtConfigInterface(
   113         mEapQtConfigInterface = new EapQtConfigInterface(
   119                 EapQtConfigInterface::EapBearerTypeWlan, mCmId);
   114             EapQtConfigInterface::EapBearerTypeWlan, id);
   120         //fix, hangs
   115     } else {
   121     }*/
   116         mEapQtConfigInterface->setConfigurationReference(id);     
       
   117     }
   122 
   118 
   123     //mCmCM is not deleted assuming mCmManager owns it.
   119     //mCmCM is not deleted assuming mCmManager owns it.
   124     mCmCM = cmCm;
   120     mCmCM = cmCm;
   125     OstTraceFunctionExit1(CPWPA2UI_SETREFERENCE_EXIT,this);
   121     OstTraceFunctionExit1(CPWPA2UI_SETREFERENCE_EXIT,this);
   126 }
   122 }
   146  */
   142  */
   147 CpSettingFormItemData* CpWpa2Ui::uiInstance(CpItemDataHelper &dataHelpper)
   143 CpSettingFormItemData* CpWpa2Ui::uiInstance(CpItemDataHelper &dataHelpper)
   148 {
   144 {
   149     OstTraceFunctionEntry1(CPWPA2UI_UIINSTANCE_ENTRY,this);
   145     OstTraceFunctionEntry1(CPWPA2UI_UIINSTANCE_ENTRY,this);
   150 
   146 
   151 		//reset the Common Ui Ptr
   147 	//reset the Common Ui Ptr
   152     mWpa2Ui.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa2, dataHelpper));
   148     mWpa2Ui.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa2, dataHelpper));
   153 
   149 
   154     mUi = mWpa2Ui->createUi(mEapQtConfigInterface, mCmCM);
   150     mUi = mWpa2Ui->createUi(mEapQtConfigInterface, mCmCM);
   155 
   151     
   156     connect(mWpa2Ui.data(), SIGNAL(keyChanged(QString&)), this,
       
   157             SLOT(pskKeyChanged(QString&)));
       
   158 
       
   159     connect(mWpa2Ui.data(), SIGNAL(pskEapModeToggled(int)), this,
       
   160             SLOT(wpaTypeChanged(int)));
       
   161 
       
   162     connect(mWpa2Ui.data(), SIGNAL(eapPluginChanged(int)), this,
       
   163             SLOT(currentEapPlugin(int)));
       
   164 
       
   165     OstTraceFunctionExit1(CPWPA2UI_UIINSTANCE_EXIT,this);
   152     OstTraceFunctionExit1(CPWPA2UI_UIINSTANCE_EXIT,this);
   166     return mUi;
   153     return mUi;
   167 }
   154 }
   168 
   155 
   169 // ======== LOCAL FUNCTIONS ========
       
   170 /*!
   156 /*!
   171  Slot to handle change in wpa mode :- PSK /EAP
   157    Validates current security settings. This function is called whenever
       
   158    user tries to exit from the settings view. If the plugin determines
       
   159    that some settings need editing before considered valid, it shall
       
   160    return false. A dialog will be shown to the user indicating that
       
   161    settings are still incomplete and asking if he/she wishes to exit
       
   162    anyway.
   172 
   163 
   173  \param pskEnable the current mode chosen
   164    \return True if security settings for WPA2 only are valid, false if not.
   174  */
   165 */
   175 /*void CpWpa2Ui::wpaTypeChanged(int pskEnable)
   166 bool CpWpa2Ui::validateSettings()
   176 {
   167 {
   177     int err;
   168     return mWpa2Ui->validateSettings();
   178     OstTraceFunctionEntry1(CPWPA2UI_WPATYPECHANGED_ENTRY,this);
       
   179 
       
   180     bool PskEnable = pskEnable ? ETrue : EFalse;
       
   181 
       
   182     QT_TRYCATCH_ERROR(err,mCmCM->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk, PskEnable));
       
   183 
       
   184     if(err !=KErrNone) {
       
   185           OstTrace1( TRACE_ERROR, CPWPA2UI_WPATYPECHANGED, "ERROR WPA2 only:wpatypereturned returned %d", err );
       
   186     }
       
   187     tryUpdate();
       
   188     OstTraceFunctionExit1(CPWPA2UI_WPATYPECHANGED_EXIT,this);
       
   189 }*/
       
   190 
       
   191 /*!
       
   192  Slot to handle change in pre-shared key string
       
   193 
       
   194  \param key changed string for PSK
       
   195  */
       
   196 void CpWpa2Ui::pskKeyChanged(QString &key)
       
   197 {
       
   198     int err;
       
   199     OstTraceFunctionEntry1(CPWPA2UI_PSKKEYCHANGED_ENTRY,this);
       
   200 
       
   201     //Check for Validity of Pre-shared Key
       
   202     Wpa2KeyValidator::KeyStatus keystatus = Wpa2KeyValidator::validateWpa2Key(key);
       
   203     
       
   204     if (keystatus == Wpa2KeyValidator::KeyStatusOk) {
       
   205         QT_TRYCATCH_ERROR(err, mCmCM->setString8Attribute(CMManagerShim::WlanWpaPreSharedKey, key));
       
   206         if(err !=KErrNone) {
       
   207                  OstTrace1( TRACE_ERROR, CPWPA2UI_PSKKEYCHANGED, "ERROR WPA2 only: pskKeyChanged returned %d", err );
       
   208         }
       
   209         tryUpdate();
       
   210     }
       
   211     
       
   212     else {
       
   213     showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId(
       
   214                    "txt_occ_info_invalid_input"));
       
   215     }
       
   216     OstTraceFunctionExit1(CPWPA2UI_PSKKEYCHANGED_EXIT,this);
       
   217 }
       
   218 
       
   219 /*!
       
   220  Slot to handle change in eap method in use
       
   221  \param currentplugin plugin number to indicate the
       
   222  eap method in use
       
   223  */
       
   224 /*void CpWpa2Ui::currentEapPlugin(int  currentPlugin  )
       
   225 {
       
   226     OstTraceFunctionEntry1(CPWPA2UI_CURRENTEAPPLUGIN_ENTRY,this);
       
   227 
       
   228     // define enum to store the current EAP type
       
   229     //mCmCM->setIntAttribute( use appropriate enum to get the eap plugin index );
       
   230     OstTraceFunctionExit1(CPWPA2UI_CURRENTEAPPLUGIN_EXIT,this);
       
   231 }*/
       
   232 
       
   233 bool CpWpa2Ui::tryUpdate()
       
   234 {
       
   235     OstTraceFunctionEntry1(CPWPA2UI_TRYUPDATE_ENTRY,this);
       
   236     
       
   237     // Try update
       
   238     try {
       
   239         mCmCM->update();
       
   240     }
       
   241     catch (const std::exception&) {
       
   242         // Handle error
       
   243         handleUpdateError();
       
   244         
       
   245         OstTraceFunctionExit1(CPWPA2UI_TRYUPDATE_EXIT,this);
       
   246         return false;
       
   247     }
       
   248 
       
   249     OstTraceFunctionExit1(DUP1_CPWPA2UI_TRYUPDATE_EXIT,this);
       
   250     return true;
       
   251 }
       
   252 
       
   253 /*!
       
   254     Handles failed CommsDat update.
       
   255  */
       
   256 void CpWpa2Ui::handleUpdateError()
       
   257 {
       
   258     OstTraceFunctionEntry1(CPWPA2UI_HANDLEUPDATEERROR_ENTRY,this);
       
   259     
       
   260     // Show error note to user
       
   261     showMessageBox(
       
   262         HbMessageBox::MessageTypeWarning,
       
   263         hbTrId("txt_occ_info_unable_to_save_setting"));
       
   264     // Reload settings from CommsDat and update UI
       
   265     try {
       
   266         mCmCM->refresh();
       
   267     }
       
   268     catch (const std::exception&) {
       
   269         // Ignore error from refresh. Most likely this will not happen, but
       
   270         // if it does, there isn't very much we can do.
       
   271         OstTrace0(
       
   272             TRACE_ERROR,
       
   273             CPWPA2UI_HANDLEUPDATEERROR,
       
   274             "Refresh failed");
       
   275     };
       
   276     updateWpaSettings();
       
   277     
       
   278     OstTraceFunctionExit1(CPWPA2UI_HANDLEUPDATEERROR_EXIT,this);
       
   279 }
       
   280 
       
   281 /*!
       
   282     Shows message box with "OK" button using given text.
       
   283 */
       
   284 void CpWpa2Ui::showMessageBox(
       
   285     HbMessageBox::MessageBoxType type,
       
   286     const QString &text)
       
   287 {
       
   288     OstTraceFunctionEntry1(CPWPA2UI_SHOWMESSAGEBOX_ENTRY,this);
       
   289     
       
   290     // Create a message box
       
   291     mMessageBox = QSharedPointer<HbMessageBox>(new HbMessageBox(type));
       
   292     mMessageBox->setText(text);
       
   293     mMessageBox->open();
       
   294     
       
   295     OstTraceFunctionExit1(CPWPA2UI_SHOWMESSAGEBOX_EXIT,this);
       
   296 }
   169 }
   297 
   170 
   298 
   171 
   299 void CpWpa2Ui::updateWpaSettings()
       
   300     {
       
   301     OstTraceFunctionEntry1(CPWPA2UI_UPDATEWPASETTINGS_ENTRY,this);
       
   302     mWpa2Ui->reset();
       
   303     OstTraceFunctionExit1(CPWPA2UI_UPDATEWPASETTINGS_EXIT,this);
       
   304     }
       
   305 
       
   306 Q_EXPORT_PLUGIN2(CpWpa2Ui, CpWpa2Ui)
   172 Q_EXPORT_PLUGIN2(CpWpa2Ui, CpWpa2Ui)
   307 ;
   173 ;