securitysettings/cpwlansecurityuiplugins/cpwpa2ui/src/cpwpa2ui.cpp
changeset 22 093cf0757204
child 26 9abfd4f00d37
equal deleted inserted replaced
20:8b3129ac4c0f 22:093cf0757204
       
     1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2  * All rights reserved.
       
     3  * This component and the accompanying materials are made available
       
     4  * under the terms of the License "Eclipse Public License v1.0"
       
     5  * which accompanies this distribution, and is available
       
     6  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7  *
       
     8  * Initial Contributors:
       
     9  * Nokia Corporation - initial contribution.
       
    10  *
       
    11  * Contributors:
       
    12  *
       
    13  * Description: 
       
    14  *    Control Panel QT UI for WPA2 only configuration
       
    15  *
       
    16  */
       
    17 
       
    18 /*
       
    19  * %version: 17 %
       
    20  */
       
    21 
       
    22 // User includes
       
    23 #include "cpwpa2ui.h"
       
    24 #include "cpwpacmnui.h"
       
    25 #include "wpa2keyvalidator.h"
       
    26 
       
    27 // System includes
       
    28 #include <HbDeviceNotificationDialog>
       
    29 #include <cmmanagerdefines_shim.h>
       
    30 #include <cmconnectionmethod_shim.h>
       
    31 #include <eapqtconfiginterface.h>
       
    32 #include <QStringList>
       
    33 #include <QLocale>
       
    34 #include <QCoreApplication>
       
    35 
       
    36 #include "OstTraceDefinitions.h"
       
    37 #ifdef OST_TRACE_COMPILER_IN_USE
       
    38 #include "cpwpa2uiTraces.h"
       
    39 #endif
       
    40 
       
    41 
       
    42 // Constants
       
    43 //The order in which WPA2 only mode appears in the list of available 
       
    44 //security mode
       
    45 const int UI_ORDER_WPA2_ONLY = 50;
       
    46 
       
    47 /*!
       
    48  \class CpWpa2Ui
       
    49  \brief CpWpa2Ui implements the  Ui for WPA2 only 
       
    50  Security Settings Control Panel Plugin,
       
    51  which will allow viewing/editing of WPA2 only Security Settings.
       
    52  */
       
    53 //Contructs WPA2 object
       
    54 CpWpa2Ui::CpWpa2Ui() :
       
    55     mUi(NULL),  mCmCM(NULL), mEapQtConfigInterface(NULL),
       
    56             mWpa2Ui(NULL)
       
    57 {
       
    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 
       
    66 }
       
    67 
       
    68 //Deletes all objects WPA2 owns
       
    69 CpWpa2Ui::~CpWpa2Ui()
       
    70 {
       
    71     OstTraceFunctionEntry1(CPWPA2UI_CPWPA2UI_ENTRY,this);
       
    72     //delete mEapQtConfigInterface;
       
    73     OstTraceFunctionExit1(CPWPA2UI_CPWPA2UI_EXIT,this);
       
    74 }
       
    75 
       
    76 // ======== MEMBER FUNCTIONS ========
       
    77 
       
    78 /*!
       
    79  Getter for security mode.
       
    80 
       
    81  \return Security mode identifier
       
    82  */
       
    83 CMManagerShim::WlanSecMode CpWpa2Ui::securityMode() const
       
    84 {
       
    85     OstTraceFunctionEntry1(CPWPA2UI_MODE_ENTRY,this);
       
    86     OstTraceFunctionExit1(CPWPA2UI_MODE_EXIT,this);
       
    87     //return security mode
       
    88     return CMManagerShim::WlanSecModeWpa2;
       
    89 }
       
    90 
       
    91 /*!
       
    92  Getter for localization text identifier for the security mode,
       
    93  f.ex. "txt_occ_setlabel_wlan_security_mode_val_wpa2_only". This localized
       
    94  text will be shown in the UI.
       
    95  
       
    96  \return Localization text ID
       
    97  */
       
    98 QString CpWpa2Ui::securityModeTextId() const
       
    99 {
       
   100     OstTraceFunctionEntry1(CPWPA2UI_LOCALIZATIONID_ENTRY,this);
       
   101     OstTraceFunctionExit1(CPWPA2UI_LOCALIZATIONID_EXIT,this);
       
   102     return "txt_occ_setlabel_wlan_security_mode_val_wpa2_only";
       
   103 }
       
   104 
       
   105 /*! 
       
   106  Sets the database reference (WLAN Service Table ID).
       
   107 
       
   108  \param id Database reference
       
   109  */
       
   110 void CpWpa2Ui::setReference(CmConnectionMethodShim *cmCm, uint id)
       
   111 {
       
   112     OstTraceFunctionEntry1(CPWPA2UI_SETREFERENCE_ENTRY,this);
       
   113     // Assuming that id is the connection method Id/IAP Id.
       
   114 
       
   115     mCmId = id;
       
   116 
       
   117     /*if (!mEapQtConfigInterface) {
       
   118         mEapQtConfigInterface = new EapQtConfigInterface(
       
   119                 EapQtConfigInterface::EapBearerTypeWlan, mCmId);
       
   120         //fix, hangs
       
   121     }*/
       
   122 
       
   123     //mCmCM is not deleted assuming mCmManager owns it.
       
   124     mCmCM = cmCm;
       
   125     OstTraceFunctionExit1(CPWPA2UI_SETREFERENCE_EXIT,this);
       
   126 }
       
   127 
       
   128 /*!
       
   129  Getter for order number. This order number is used by the client of
       
   130  this interface to put the security modes in correct order in the list.
       
   131 
       
   132  \return An order number
       
   133  */
       
   134 int CpWpa2Ui::orderNumber() const
       
   135 {
       
   136     OstTraceFunctionEntry1(CPWPA2UI_ORDERNUMBER_ENTRY,this);
       
   137     OstTraceFunctionExit1(CPWPA2UI_ORDERNUMBER_EXIT,this);
       
   138     return UI_ORDER_WPA2_ONLY;
       
   139 }
       
   140 
       
   141 /*!
       
   142  Creates an UI instance. Caller owns the object.
       
   143  
       
   144  \param dataHelper Item data helper
       
   145  \return Pointer to an UI object
       
   146  */
       
   147 CpSettingFormItemData* CpWpa2Ui::uiInstance(CpItemDataHelper &dataHelpper)
       
   148 {
       
   149     OstTraceFunctionEntry1(CPWPA2UI_UIINSTANCE_ENTRY,this);
       
   150 
       
   151 		//reset the Common Ui Ptr
       
   152     mWpa2Ui.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa2, dataHelpper));
       
   153 
       
   154     mUi = mWpa2Ui->createUi(mEapQtConfigInterface, mCmCM);
       
   155 
       
   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);
       
   166     return mUi;
       
   167 }
       
   168 
       
   169 // ======== LOCAL FUNCTIONS ========
       
   170 /*!
       
   171  Slot to handle change in wpa mode :- PSK /EAP
       
   172 
       
   173  \param pskEnable the current mode chosen
       
   174  */
       
   175 /*void CpWpa2Ui::wpaTypeChanged(int pskEnable)
       
   176 {
       
   177     int err;
       
   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 }
       
   297 
       
   298 
       
   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)
       
   307 ;