securitysettings/cpwlansecurityuiplugins/cpwpaui/src/cpwpaui.cpp
changeset 26 9abfd4f00d37
parent 22 093cf0757204
child 34 ad1f037f1ac2
equal deleted inserted replaced
25:e03a3db4489e 26:9abfd4f00d37
    15  *    Control Panel QT UI for WPA/WPA2 configuration
    15  *    Control Panel QT UI for WPA/WPA2 configuration
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 /*
    19 /*
    20  * %version: tr1cfwln#21.1.1 %
    20  * %version: 27 %
    21  */
    21  */
    22 //User Includes
    22 //User Includes
    23 #include "cpwpaui.h"
    23 #include "cpwpaui.h"
    24 #include "cpwpacmnui.h"
    24 #include "cpwpacmnui.h"
    25 #include "wpakeyvalidator.h"
       
    26 
    25 
    27 // System includes
    26 // System includes
    28 #include <QStringList>
    27 #include <QStringList>
    29 #include <HbDeviceNotificationDialog>
       
    30 #include <QLocale>
       
    31 #include <qtranslator.h>
       
    32 #include <QCoreApplication>
       
    33 #include <cmconnectionmethod_shim.h>
    28 #include <cmconnectionmethod_shim.h>
    34 #include <cmmanagerdefines_shim.h>
    29 #include <cmmanagerdefines_shim.h>
    35 #include <eapqtconfiginterface.h>
    30 #include <eapqtconfiginterface.h>
       
    31 #include <HbTranslator>
    36 
    32 
       
    33 //Trace Definition
    37 #include "OstTraceDefinitions.h"
    34 #include "OstTraceDefinitions.h"
    38 #ifdef OST_TRACE_COMPILER_IN_USE
    35 #ifdef OST_TRACE_COMPILER_IN_USE
    39 #include "cpwpauiTraces.h"
    36 #include "cpwpauiTraces.h"
    40 #endif
    37 #endif
    41 
    38 
    42 //Constants
    39 //Constants
    43 //The order in which WPA/WPA2 only mode appears in the list of available 
    40 //The order in which WPA/WPA2 only mode appears in the list of available 
    44 //security modes
    41 //security modes
    45 const int UI_ORDER_WPA_WPA2 = 40;
    42 const int UI_ORDER_WPA_WPA2 = 20;
    46 /*!
    43 /*!
    47  \class CpWpaUi
    44  \class CpWpaUi
    48  \brief CpWpaUi implements the common Ui for WPA/WPA2 
    45  \brief CpWpaUi implements the common Ui for WPA/WPA2 
    49  Security Settings Control Panel Plugins,
    46  Security Settings Control Panel Plugins,
    50  which will allow viewing/editing of WPA/WPA2 Security Settings.
    47  which will allow viewing/editing of WPA/WPA2 Security Settings.
    51  */
    48  */
    52 //Contructs WPA/WPA2 object
    49 /*!
       
    50  * Constructor
       
    51  */
    53 CpWpaUi::CpWpaUi() :
    52 CpWpaUi::CpWpaUi() :
    54     mUi(NULL), mCmCM(NULL), mEapQtConfigInterface(NULL)
    53    mUi(NULL), 
       
    54    mTranslator(new HbTranslator("cpwlansecsettingsplugin")),
       
    55    mCmCM(NULL),
       
    56    mEapQtConfigInterface(NULL),
       
    57    mWpaUi(NULL)
    55 {
    58 {
    56     mTranslator = new QTranslator(this);
    59     
    57     mTranslator->load(":/loc/wlan_en_GB.qm");
       
    58 
       
    59     qApp->installTranslator(mTranslator);
       
    60 
    60 
    61 }
    61 }
    62 
    62 
    63 //Deletes all objects WPA/WPA2 owns
    63 //Destructor
    64 CpWpaUi::~CpWpaUi()
    64 CpWpaUi::~CpWpaUi()
    65 {
    65 {
    66     OstTraceFunctionEntry1(CPWPAUI_CPWPAUI_ENTRY,this);
    66     OstTraceFunctionEntry1(CPWPAUI_CPWPAUI_ENTRY,this);
    67     //delete mEapQtConfigInterface;
    67     delete mEapQtConfigInterface;
       
    68     delete mTranslator;
    68     OstTraceFunctionExit1(CPWPAUI_CPWPAUI_EXIT,this);
    69     OstTraceFunctionExit1(CPWPAUI_CPWPAUI_EXIT,this);
    69 }
    70 }
    70 
    71 
    71 // ======== MEMBER FUNCTIONS ========
    72 // ======== MEMBER FUNCTIONS ========
    72 
    73 
    75 
    76 
    76  \return Security mode identifier
    77  \return Security mode identifier
    77  */
    78  */
    78 CMManagerShim::WlanSecMode CpWpaUi::securityMode() const
    79 CMManagerShim::WlanSecMode CpWpaUi::securityMode() const
    79 {
    80 {
    80     OstTraceFunctionEntry1(CPWPAUI_MODE_ENTRY,this);
    81     OstTraceFunctionEntry1(CPWPAUI_SECURITYMODE_ENTRY,this);
    81     OstTraceFunctionExit1(CPWPAUI_MODE_EXIT,this);
    82     OstTraceFunctionExit1(CPWPAUI_SECURITYMODE_EXIT,this);
    82     //return security mode
    83     //return security mode
    83     return CMManagerShim::WlanSecModeWpa;
    84     return CMManagerShim::WlanSecModeWpa;
    84 }
    85 }
    85 
    86 
    86 /*!
    87 /*!
    90  
    91  
    91  \return Localization text ID
    92  \return Localization text ID
    92  */
    93  */
    93 QString CpWpaUi::securityModeTextId() const
    94 QString CpWpaUi::securityModeTextId() const
    94 {
    95 {
    95     OstTraceFunctionEntry1(CPWPAUI_LOCALIZATIONID_ENTRY,this); 
    96     OstTraceFunctionEntry1( CPWPAUI_SECURITYMODETEXTID_ENTRY, this );
    96     OstTraceFunctionExit1(CPWPAUI_LOCALIZATIONID_EXIT,this);
    97     OstTraceFunctionExit1( CPWPAUI_SECURITYMODETEXTID_EXIT, this );
    97     return "txt_occ_setlabel_wlan_security_mode_val_wpawpa2";
    98     return "txt_occ_setlabel_wlan_security_mode_val_wpawpa2";
    98 }
    99 }
    99 
   100 
   100 /*! 
   101 /*! 
   101  Sets the database reference (WLAN Service Table ID).
   102  Sets the database reference IAP id.
   102 
   103 
   103  \param id Database reference
   104  \param id Database reference
   104  */
   105  */
   105 void CpWpaUi::setReference(CmConnectionMethodShim *cmCm, uint id)
   106 void CpWpaUi::setReference(CmConnectionMethodShim *cmCm, uint id)
   106 {
   107 {
   107     OstTraceFunctionEntry1(CPWPAUI_SETREFERENCE_ENTRY,this);
   108     OstTraceFunctionEntry1(CPWPAUI_SETREFERENCE_ENTRY,this);
   108     // Assuming that id is the connection method Id/IAP Id.
   109     if (!mEapQtConfigInterface) {
   109     mCmId = id;
   110        mEapQtConfigInterface = new EapQtConfigInterface(
   110 
   111                EapQtConfigInterface::EapBearerTypeWlan, id);
   111     /*if (!mEapQtConfigInterface) {
   112     } 
   112      mEapQtConfigInterface = new EapQtConfigInterface(
   113     else {
   113      EapQtConfigInterface::EapBearerTypeWlan, mCmId);
   114        mEapQtConfigInterface->setConfigurationReference(id);     
   114      // fix, hangs
   115     }
   115      }*/
       
   116 
   116 
   117     //mCmCM is not deleted assuming mCmManager owns it.
   117     //mCmCM is not deleted assuming mCmManager owns it.
   118     mCmCM = cmCm;
   118     mCmCM = cmCm;
   119     OstTraceFunctionExit1(CPWPAUI_SETREFERENCE_EXIT,this);
   119     OstTraceFunctionExit1(CPWPAUI_SETREFERENCE_EXIT,this);
   120 }
   120 }
   144 
   144 
   145 		//reset the Common Ui Ptr
   145 		//reset the Common Ui Ptr
   146     mWpaUi.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa, dataHelper));
   146     mWpaUi.reset(new CpWpaCmnUi(CMManagerShim::WlanSecModeWpa, dataHelper));
   147 
   147 
   148     mUi = mWpaUi->createUi(mEapQtConfigInterface, mCmCM);
   148     mUi = mWpaUi->createUi(mEapQtConfigInterface, mCmCM);
   149 
   149     
   150     connect(mWpaUi.data(), SIGNAL(keyChanged(QString&)), this, SLOT(pskKeyChanged(QString&)));
       
   151 
       
   152     connect(mWpaUi.data(), SIGNAL(pskEapModeToggled(int)), this, SLOT(wpaTypeChanged(int)));
       
   153 
       
   154     connect(mWpaUi.data(), SIGNAL(eapPluginChanged(int)), this, SLOT(currentEapPlugin(int)));
       
   155     //}
       
   156     OstTraceFunctionExit1(CPWPAUI_UIINSTANCE_EXIT,this);
   150     OstTraceFunctionExit1(CPWPAUI_UIINSTANCE_EXIT,this);
   157     return mUi;
   151     return mUi;
   158 }
   152 }
   159 
   153 
       
   154 /*!
       
   155    Validates current security settings. This function is called whenever
       
   156    user tries to exit from the settings view. If the plugin determines
       
   157    that some settings need editing before considered valid, it shall
       
   158    return false. A dialog will be shown to the user indicating that
       
   159    settings are still incomplete and asking if he/she wishes to exit
       
   160    anyway.
   160 
   161 
   161 // ======== LOCAL FUNCTIONS ========
   162    \return True if security settings for WPA/WPA2 are valid, false if not.
   162 
   163 */
   163 /*!
   164 bool CpWpaUi::validateSettings()
   164  Slot to handle change in wpa mode :- PSK /EAP
       
   165 
       
   166  \param pskEnable the current mode chosen
       
   167  */
       
   168 /*void CpWpaUi::wpaTypeChanged(int pskEnable)
       
   169 {
   165 {
   170     int err;
   166     return mWpaUi->validateSettings();
   171     OstTraceFunctionEntry1(CPWPAUI_WPATYPECHANGED_ENTRY,this);
       
   172 
       
   173     bool PskEnable = pskEnable ? ETrue : EFalse;
       
   174 
       
   175     QT_TRYCATCH_ERROR(err,mCmCM->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk, PskEnable));
       
   176     
       
   177     if(err !=KErrNone) {
       
   178               OstTrace1( TRACE_ERROR, CPWPAUI_WPATYPECHANGED, "ERROR WPA/WPA2 wpatypereturned returned %d", err );
       
   179     }
       
   180     tryUpdate();
       
   181     OstTraceFunctionExit1(CPWPAUI_WPATYPECHANGED_EXIT,this);
       
   182 }*/
       
   183 
       
   184 /*!
       
   185  Slot to handle change in pre-shared key string
       
   186 
       
   187  \param key changed string for PSK
       
   188  */
       
   189 void CpWpaUi::pskKeyChanged(QString &key)
       
   190 {
       
   191     int err;
       
   192     OstTraceFunctionEntry1(CPWPAUI_PSKKEYCHANGED_ENTRY,this);
       
   193     //Store to native s60 type for validation 
       
   194     TPtrC ptrName(reinterpret_cast<const TText*> (key.constData()));
       
   195 
       
   196     //Check for Validity of Pre-shared Key
       
   197     WpaKeyValidator::KeyStatus keystatus = WpaKeyValidator::validateWpaKey(key);
       
   198 
       
   199     if (keystatus == WpaKeyValidator::KeyStatusOk) {
       
   200 
       
   201         QT_TRYCATCH_ERROR(err,mCmCM->setString8Attribute(CMManagerShim::WlanWpaPreSharedKey, key));
       
   202         if(err !=KErrNone) {
       
   203           OstTrace1( TRACE_ERROR,CPWPAUI_PSKKEYCHANGED, "ERROR WPA/WPA2: pskKeyChanged returned %d", err );
       
   204         }
       
   205         tryUpdate();
       
   206     }
       
   207     else {
       
   208     showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId(
       
   209                       "txt_occ_info_invalid_input"));
       
   210     }
       
   211     OstTraceFunctionExit1(CPWPAUI_PSKKEYCHANGED_EXIT,this);
       
   212 }
       
   213 
       
   214 /*!
       
   215  Slot to handle change in eap method in use
       
   216  \param currentplugin plugin number to indicate the
       
   217  eap method in use
       
   218  */
       
   219 /*void CpWpaUi::currentEapPlugin(int  plugin )
       
   220 {
       
   221     OstTraceFunctionEntry1(CPWPAUI_CURRENTEAPPLUGIN_ENTRY,this);
       
   222 
       
   223     //define enum to store the current EAP type
       
   224     //mCmCM->setIntAttribute( use appropriate enum to get the eap plugin index );
       
   225     OstTraceFunctionExit1(CPWPAUI_CURRENTEAPPLUGIN_EXIT,this);
       
   226 }*/
       
   227 
       
   228 bool CpWpaUi::tryUpdate()
       
   229 {
       
   230     OstTraceFunctionEntry1(CPWPAUI_TRYUPDATE_ENTRY,this);
       
   231 
       
   232     // Try update
       
   233     try {
       
   234         mCmCM->update();
       
   235     } catch (const std::exception&) {
       
   236         // Handle error
       
   237         handleUpdateError();
       
   238 
       
   239         OstTraceFunctionExit1(CPWPAUI_TRYUPDATE_EXIT,this);
       
   240         return false;
       
   241     }
       
   242 
       
   243     OstTraceFunctionExit1(DUP1_CPWPAUI_TRYUPDATE_EXIT,this);
       
   244     return true;
       
   245 }
       
   246 
       
   247 /*!
       
   248  Handles failed CommsDat update.
       
   249  */
       
   250 void CpWpaUi::handleUpdateError()
       
   251 {
       
   252     OstTraceFunctionEntry1(CPWPAUI_HANDLEUPDATEERROR_ENTRY,this);
       
   253 
       
   254     // Show error note to user
       
   255     showMessageBox(HbMessageBox::MessageTypeWarning, hbTrId("txt_occ_info_unable_to_save_setting"));
       
   256     // Reload settings from CommsDat and update UI
       
   257     try {
       
   258         mCmCM->refresh();
       
   259     } catch (const std::exception&) {
       
   260         // Ignore error from refresh. Most likely this will not happen, but
       
   261         // if it does, there isn't very much we can do.
       
   262         OstTrace0(
       
   263             TRACE_ERROR,
       
   264             CPWPAUI_HANDLEUPDATEERROR,
       
   265             "Refresh failed");
       
   266     };
       
   267     updateWpaSettings();
       
   268 
       
   269     OstTraceFunctionExit1(CPWPAUI_HANDLEUPDATEERROR_EXIT,this);
       
   270 }
       
   271 
       
   272 /*!
       
   273  Shows message box with "OK" button using given text.
       
   274  */
       
   275 void CpWpaUi::showMessageBox(HbMessageBox::MessageBoxType type, const QString &text)
       
   276 {
       
   277     OstTraceFunctionEntry1(CPWPAUI_SHOWMESSAGEBOX_ENTRY,this);
       
   278 
       
   279     // Create a message box
       
   280     mMessageBox = QSharedPointer<HbMessageBox> (new HbMessageBox(type));
       
   281     mMessageBox->setText(text);
       
   282     mMessageBox->open();
       
   283 
       
   284     OstTraceFunctionExit1(CPWPAUI_SHOWMESSAGEBOX_EXIT,this);
       
   285 }
       
   286 
       
   287 void CpWpaUi::updateWpaSettings()
       
   288 {
       
   289     OstTraceFunctionEntry1(CPWPAUI_UPDATEWPASETTINGS_ENTRY,this);
       
   290     mWpaUi->reset();
       
   291     OstTraceFunctionExit1(CPWPAUI_UPDATEWPASETTINGS_EXIT,this);
       
   292 }
   167 }
   293 
   168 
   294 Q_EXPORT_PLUGIN2(CpWpaUi, CpWpaUi)
   169 Q_EXPORT_PLUGIN2(CpWpaUi, CpWpaUi)
   295 ;
   170 ;