cmmanager/cppacketdataapplugin/src/cppacketdataapadvancedview.cpp
changeset 27 489cf6208544
parent 23 7ec726f93df1
child 44 a0c4ceac30d0
equal deleted inserted replaced
23:7ec726f93df1 27:489cf6208544
    15 * Control Panel packet data AP advanced settings view implementation.  
    15 * Control Panel packet data AP advanced settings view implementation.  
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 // System includes
    19 // System includes
       
    20 #include <QHostAddress>
       
    21 #include <HbCheckBox>
       
    22 #include <HbLineEdit>
       
    23 #include <HbDataFormViewItem>
       
    24 #include <HbWidget>
       
    25 #include <HbEditorInterface>
       
    26 #include <HbUrlFilter>
       
    27 #include <HbInputDialog>
    20 #include <HbDataForm>
    28 #include <HbDataForm>
    21 #include <HbDataFormModel>
    29 #include <HbDataFormModel>
       
    30 #include <cmconnectionmethod_shim.h>
       
    31 #include <cmmanagerdefines_shim.h>
    22 #include <cpsettingformitemdata.h>
    32 #include <cpsettingformitemdata.h>
    23 #include <cmconnectionmethod_shim.h>
    33 #include <etelpckt.h>
    24 
    34 
    25 // User includes
    35 // User includes
       
    36 #include "cpipv4filter.h"
       
    37 #include "cpipv6filter.h"
    26 #include "cppacketdataapadvancedview.h"
    38 #include "cppacketdataapadvancedview.h"
       
    39 
       
    40 #include "OstTraceDefinitions.h"
       
    41 #ifdef OST_TRACE_COMPILER_IN_USE
       
    42 #include "cppacketdataapadvancedviewTraces.h"
       
    43 #endif
    27 
    44 
    28 /*!
    45 /*!
    29     \class CpPacketDataApAdvancedView
    46     \class CpPacketDataApAdvancedView
    30     \brief Implements the advanced settings view for packet data bearer
    47     \brief Implements the advanced settings view for packet data bearer
    31            access points.
    48            access points.
    46     CmConnectionMethodShim *cmConnectionMethod,
    63     CmConnectionMethodShim *cmConnectionMethod,
    47     QGraphicsItem *parent) :
    64     QGraphicsItem *parent) :
    48         CpBaseSettingView(0, parent),
    65         CpBaseSettingView(0, parent),
    49         mForm(0),
    66         mForm(0),
    50         mModel(0),
    67         mModel(0),
    51         mCmConnectionMethod(cmConnectionMethod)
    68         mCmConnectionMethod(cmConnectionMethod),
    52 {
    69         mIpGroup(0),
    53     // Construct packet data AP settings UI
    70         mNetworkType(0),
       
    71         mIpv4Automatic(0),
       
    72         mIpv4Address(0),
       
    73         mIpv4DnsAutomatic(0),
       
    74         mIpv4DnsAddress1(0),
       
    75         mIpv4DnsAddress2(0),
       
    76         mIpv6DnsAutomatic(0),
       
    77         mIpv6DnsAddress1(0),
       
    78         mIpv6DnsAddress2(0),
       
    79         mProxyGroup(0),
       
    80         mProxyServer(0),
       
    81         mProxyPort(0),
       
    82         mMessageBox(0),
       
    83         mIpv6Supported(false),
       
    84         mCurrentNetworkType(NetworkTypeIpv4)
       
    85 {
       
    86     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CPPACKETDATAAPADVANCEDVIEW_ENTRY);
       
    87     
       
    88     // Construct packet data AP advanced settings UI
    54     mForm = new HbDataForm();
    89     mForm = new HbDataForm();
    55     this->setWidget(mForm);
    90     this->setWidget(mForm);
    56     mModel = new HbDataFormModel(mForm);
    91     mModel = new HbDataFormModel(mForm);
    57     mForm->setModel(mModel);
    92     mForm->setModel(mModel);
    58     
    93 
       
    94     mIpv6Supported = mCmConnectionMethod->getBoolAttribute(
       
    95         CMManagerShim::CmIPv6Supported);
       
    96         
    59     // Add advanced settings groups
    97     // Add advanced settings groups
    60     createAdvancedSettings();
    98     createAdvancedSettings();
       
    99     
       
   100     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CPPACKETDATAAPADVANCEDVIEW_EXIT);
    61 }
   101 }
    62 
   102 
    63 /*!
   103 /*!
    64     Destructor.
   104     Destructor.
    65 */
   105 */
    66 CpPacketDataApAdvancedView::~CpPacketDataApAdvancedView()
   106 CpPacketDataApAdvancedView::~CpPacketDataApAdvancedView()
    67 {
   107 {
    68 }
   108     OstTraceFunctionEntry0(DUP1_CPPACKETDATAAPADVANCEDVIEW_CPPACKETDATAAPADVANCEDVIEW_ENTRY);
    69 
   109     
    70 /*!
   110     OstTraceFunctionExit0(DUP1_CPPACKETDATAAPADVANCEDVIEW_CPPACKETDATAAPADVANCEDVIEW_EXIT);
    71     Adds settings items to the model.
   111 }
       
   112 
       
   113 /*!
       
   114     Creates all advanced settings groups.
    72 */
   115 */
    73 void CpPacketDataApAdvancedView::createAdvancedSettings()
   116 void CpPacketDataApAdvancedView::createAdvancedSettings()
    74 {
   117 {
    75     // TODO: Implement the advanced settings view.
   118     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CREATEADVANCEDSETTINGS_ENTRY);
    76 }
   119     
       
   120     // Create settings groups
       
   121     createIpGroup();
       
   122     createProxyGroup();
       
   123     
       
   124     // Read values and update UI
       
   125     updateIpGroup();
       
   126     updateProxyGroup();
       
   127     
       
   128     // Connect signal to initialize settings item widgets
       
   129     bool status = connect(
       
   130         mForm,
       
   131         SIGNAL(itemShown(const QModelIndex)),
       
   132         this,
       
   133         SLOT(setEditorPreferences(const QModelIndex)));
       
   134     Q_ASSERT(status);
       
   135     
       
   136     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CREATEADVANCEDSETTINGS_EXIT);
       
   137 }
       
   138 
       
   139 /*!
       
   140     Creates the IP settings group.
       
   141 */
       
   142 void CpPacketDataApAdvancedView::createIpGroup()
       
   143 {
       
   144     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CREATEIPGROUP_ENTRY);
       
   145     
       
   146     // IP settings group
       
   147     mIpGroup = new CpSettingFormItemData(
       
   148         HbDataFormModelItem::GroupItem,
       
   149         hbTrId("txt_occ_subhead_ip_settings"));
       
   150     mModel->appendDataFormItem(mIpGroup);
       
   151     
       
   152     if (mIpv6Supported) {
       
   153         // IPv6 supported
       
   154         // Network type
       
   155         mNetworkType = new CpSettingFormItemData(
       
   156             HbDataFormModelItem::ComboBoxItem,
       
   157             hbTrId("txt_occ_setlabel_network_type"));
       
   158         QStringList networkTypeList;
       
   159         networkTypeList
       
   160             << hbTrId("txt_occ_setlabel_network_type_val_ipv4")
       
   161             << hbTrId("txt_occ_setlabel_network_type_val_ipv6");
       
   162         mNetworkType->setContentWidgetData("items", networkTypeList);
       
   163         mForm->addConnection(
       
   164             mNetworkType,
       
   165             SIGNAL(currentIndexChanged(int)),
       
   166             this,
       
   167             SLOT(changeNetworkType(int)));
       
   168         mIpGroup->appendChild(mNetworkType);
       
   169         
       
   170         mCurrentNetworkType = getNetworkType();
       
   171         if (mCurrentNetworkType == NetworkTypeIpv4) {
       
   172             // IPv4
       
   173             createIpv4SettingItems();
       
   174         } else {
       
   175             // IPv6
       
   176             createIpv6SettingItems();
       
   177         }
       
   178     } else {
       
   179         // IPv6 not supported, create IPv4 settings items
       
   180         createIpv4SettingItems();
       
   181     }
       
   182     
       
   183     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CREATEIPGROUP_EXIT);
       
   184 }
       
   185 
       
   186 /*!
       
   187     Reads attribute values and updates the IP settings group.
       
   188 */
       
   189 void CpPacketDataApAdvancedView::updateIpGroup()
       
   190 {
       
   191     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_UPDATEIPGROUP_ENTRY);
       
   192     
       
   193     // Network type
       
   194     if (mNetworkType) {
       
   195         // Every time update is called we check if network type (IPv4/IPv6)
       
   196         // has changed and update items on UI if necessary.
       
   197     
       
   198         // Get network type from CommsDat
       
   199         NetworkType newNetworkType = getNetworkType();
       
   200         if (newNetworkType != mCurrentNetworkType) {
       
   201             // Network type has changed, update UI
       
   202             if (newNetworkType == NetworkTypeIpv6) {
       
   203                 // IPv4 -> IPv6
       
   204                 deleteIpv4SettingItems();
       
   205                 createIpv6SettingItems();
       
   206             } else {
       
   207                 // IPv6 -> IPv4
       
   208                 deleteIpv6SettingItems();
       
   209                 createIpv4SettingItems();
       
   210             }
       
   211             mCurrentNetworkType = newNetworkType;
       
   212         }
       
   213         mNetworkType->setContentWidgetData("currentIndex", newNetworkType);
       
   214     }
       
   215     
       
   216     // Phone IP address (IPv4)
       
   217     // "Automatic" checkbox
       
   218     if (mIpv4Automatic) {
       
   219         bool ipAddressFromServer = mCmConnectionMethod->getBoolAttribute(
       
   220             CMManagerShim::PacketDataIPAddrFromServer);
       
   221         Qt::CheckState state = Qt::Unchecked;
       
   222         if (ipAddressFromServer) {
       
   223             state = Qt::Checked;
       
   224         }
       
   225         mIpv4Automatic->setContentWidgetData("checkState", state);
       
   226 
       
   227         // Enable/disable user defined IP address fields
       
   228         enableIpv4AddressFields(state);
       
   229     }
       
   230 
       
   231     // Phone IP address (IPv4)
       
   232     if (mIpv4Address) {
       
   233         QString string = getIpAddress(CMManagerShim::CmIPAddress);
       
   234         mIpv4Address->setContentWidgetData("text", string);
       
   235     }
       
   236     
       
   237     // IPv4 DNS addresses
       
   238     // "Automatic" checkbox
       
   239     if (mIpv4DnsAutomatic) {
       
   240         Qt::CheckState state = Qt::Unchecked;
       
   241         if (mCmConnectionMethod->getBoolAttribute(
       
   242             CMManagerShim::CmIPDNSAddrFromServer)) {
       
   243             state = Qt::Checked;
       
   244         }
       
   245         mIpv4DnsAutomatic->setContentWidgetData("checkState", state);
       
   246 
       
   247         // Enable/disable user defined DNS address fields
       
   248         enableIpv4DnsFields(state);
       
   249     }
       
   250     
       
   251     // IPv4 primary DNS address
       
   252     if (mIpv4DnsAddress1) {
       
   253         QString string = getIpAddress(CMManagerShim::CmIPNameServer1);
       
   254         mIpv4DnsAddress1->setContentWidgetData("text", string);
       
   255     }
       
   256     
       
   257     // IPv4 secondary DNS address
       
   258     if (mIpv4DnsAddress2) {
       
   259         QString string = getIpAddress(CMManagerShim::CmIPNameServer2);
       
   260         mIpv4DnsAddress2->setContentWidgetData("text", string);
       
   261     }
       
   262     
       
   263     // IPv6 DNS addresses
       
   264     // Automatic/well-known/user defined combobox
       
   265     if (mIpv6DnsAutomatic) {
       
   266         uint type = getIpv6DnsType();
       
   267         mIpv6DnsAutomatic->setContentWidgetData("currentIndex", type);
       
   268 
       
   269         // Enable/disable user defined DNS address fields
       
   270         enableIpv6DnsFields(type);
       
   271     }
       
   272     
       
   273     // IPv6 primary DNS address
       
   274     if (mIpv6DnsAddress1) {
       
   275         QString string = getIpAddress(CMManagerShim::CmIP6NameServer1);
       
   276         mIpv6DnsAddress1->setContentWidgetData("text", string);
       
   277     }
       
   278     
       
   279     // IPv6 secondary DNS address
       
   280     if (mIpv6DnsAddress2) {
       
   281         QString string = getIpAddress(CMManagerShim::CmIP6NameServer2);
       
   282         mIpv6DnsAddress2->setContentWidgetData("text", string);
       
   283     }
       
   284     
       
   285     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_UPDATEIPGROUP_EXIT);
       
   286 }
       
   287 
       
   288 /*!
       
   289     Creates the IPv4 setting items.
       
   290 */
       
   291 void CpPacketDataApAdvancedView::createIpv4SettingItems()
       
   292 {
       
   293     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CREATEIPV4SETTINGITEMS_ENTRY);
       
   294 
       
   295     // Phone IP address
       
   296     // "Automatic" checkbox
       
   297     mIpv4Automatic = new CpSettingFormItemData(
       
   298         HbDataFormModelItem::CheckBoxItem,
       
   299         hbTrId("txt_occ_setlabel_phone_ip_address"));
       
   300     mIpv4Automatic->setContentWidgetData(
       
   301         "text",
       
   302         hbTrId("txt_occ_setlabel_val_automatic"));
       
   303     mForm->addConnection(
       
   304         mIpv4Automatic,
       
   305         SIGNAL(stateChanged(int)),
       
   306         this,
       
   307         SLOT(changeIpv4AddressMode(int)));
       
   308     mIpGroup->appendChild(mIpv4Automatic);
       
   309     
       
   310     // Phone IP address
       
   311     mIpv4Address = new CpSettingFormItemData(
       
   312         HbDataFormModelItem::TextItem,
       
   313         hbTrId("txt_occ_setlabel_phone_ip_address"));
       
   314     mForm->addConnection(
       
   315         mIpv4Address,
       
   316         SIGNAL(editingFinished()),
       
   317         this,
       
   318         SLOT(changeIpv4Address()));
       
   319     mIpGroup->appendChild(mIpv4Address);
       
   320     
       
   321     // DNS addresses
       
   322     // "Automatic" checkbox
       
   323     mIpv4DnsAutomatic = new CpSettingFormItemData(
       
   324         HbDataFormModelItem::CheckBoxItem,
       
   325         hbTrId("txt_occ_setlabel_dns_addresses"));
       
   326     mIpv4DnsAutomatic->setContentWidgetData(
       
   327         "text",
       
   328         hbTrId("txt_occ_setlabel_val_automatic"));
       
   329     mForm->addConnection(
       
   330         mIpv4DnsAutomatic,
       
   331         SIGNAL(stateChanged(int)), 
       
   332         this,
       
   333         SLOT(changeIpv4DnsMode(int)));
       
   334     mIpGroup->appendChild(mIpv4DnsAutomatic);
       
   335     
       
   336     // Primary DNS address
       
   337     mIpv4DnsAddress1 = new CpSettingFormItemData(
       
   338         HbDataFormModelItem::TextItem,
       
   339         hbTrId("txt_occ_setlabel_primary_name_server"));
       
   340     mForm->addConnection(
       
   341         mIpv4DnsAddress1,
       
   342         SIGNAL(editingFinished()), 
       
   343         this,
       
   344         SLOT(changeIpv4PrimaryDnsAddress()));
       
   345     mIpGroup->appendChild(mIpv4DnsAddress1);
       
   346     
       
   347     // Secondary DNS address
       
   348     mIpv4DnsAddress2 = new CpSettingFormItemData(
       
   349         HbDataFormModelItem::TextItem,
       
   350         hbTrId("txt_occ_setlabel_secondary_name_server"));
       
   351     mForm->addConnection(
       
   352         mIpv4DnsAddress2,
       
   353         SIGNAL(editingFinished()), 
       
   354         this,
       
   355         SLOT(changeIpv4SecondaryDnsAddress()));
       
   356     mIpGroup->appendChild(mIpv4DnsAddress2);
       
   357     
       
   358     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CREATEIPV4SETTINGITEMS_EXIT);
       
   359 }
       
   360 
       
   361 /*!
       
   362     Deletes the IPv4 setting items.
       
   363 */
       
   364 void CpPacketDataApAdvancedView::deleteIpv4SettingItems()
       
   365 {
       
   366     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_DELETEIPV4SETTINGITEMS_ENTRY);
       
   367 
       
   368     // Phone IP address
       
   369     // "Automatic" checkbox
       
   370     if (mIpv4Automatic) {
       
   371         mIpGroup->removeChild(mIpGroup->indexOf(mIpv4Automatic));
       
   372         mIpv4Automatic = NULL;
       
   373     }
       
   374     
       
   375     // Phone IP address
       
   376     if (mIpv4Address) {
       
   377         mIpGroup->removeChild(mIpGroup->indexOf(mIpv4Address));
       
   378         mIpv4Address = NULL;
       
   379     }
       
   380     
       
   381     // DNS addresses
       
   382     // "Automatic" checkbox
       
   383     if (mIpv4DnsAutomatic) {
       
   384         mIpGroup->removeChild(mIpGroup->indexOf(mIpv4DnsAutomatic));
       
   385         mIpv4DnsAutomatic = NULL;
       
   386     }
       
   387     
       
   388     // Primary DNS address
       
   389     if (mIpv4DnsAddress1) {
       
   390         mIpGroup->removeChild(mIpGroup->indexOf(mIpv4DnsAddress1));
       
   391         mIpv4DnsAddress1 = NULL;
       
   392     }
       
   393     
       
   394     // Secondary DNS address
       
   395     if (mIpv4DnsAddress2) {
       
   396         mIpGroup->removeChild(mIpGroup->indexOf(mIpv4DnsAddress2));
       
   397         mIpv4DnsAddress2 = NULL;
       
   398     }
       
   399     
       
   400     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_DELETEIPV4SETTINGITEMS_EXIT);
       
   401 }
       
   402 
       
   403 /*!
       
   404     Creates the IPv6 setting items.
       
   405 */
       
   406 void CpPacketDataApAdvancedView::createIpv6SettingItems()
       
   407 {
       
   408     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CREATEIPV6SETTINGITEMS_ENTRY);
       
   409     
       
   410     // DNS addresses
       
   411     // Automatic/well-known/user defined combobox
       
   412     mIpv6DnsAutomatic = new CpSettingFormItemData(
       
   413         HbDataFormModelItem::ComboBoxItem,
       
   414         hbTrId("txt_occ_setlabel_dns_addresses"));
       
   415     QStringList dnsModeList;
       
   416     // Order of the list must match the Ipv6DnsType enum
       
   417     dnsModeList
       
   418         << hbTrId("txt_occ_setlabel_val_automatic")
       
   419         << hbTrId("txt_occ_setlabel_dns_addresses_val_wellknown")
       
   420         << hbTrId("txt_occ_setlabel_dns_addresses_val_user_defined");
       
   421     mIpv6DnsAutomatic->setContentWidgetData("items", dnsModeList);
       
   422     mForm->addConnection(
       
   423         mIpv6DnsAutomatic,
       
   424         SIGNAL(currentIndexChanged(int)),
       
   425         this,
       
   426         SLOT(changeIpv6DnsMode(int)));
       
   427     mIpGroup->appendChild(mIpv6DnsAutomatic);
       
   428     
       
   429     // Primary DNS address
       
   430     mIpv6DnsAddress1 = new CpSettingFormItemData(
       
   431         HbDataFormModelItem::TextItem,
       
   432         hbTrId("txt_occ_setlabel_primary_name_server"));
       
   433     mForm->addConnection(
       
   434         mIpv6DnsAddress1,
       
   435         SIGNAL(editingFinished()),
       
   436         this,
       
   437         SLOT(changeIpv6PrimaryDnsAddress()));
       
   438     mIpGroup->appendChild(mIpv6DnsAddress1);
       
   439     
       
   440     // Secondary DNS address
       
   441     mIpv6DnsAddress2 = new CpSettingFormItemData(
       
   442         HbDataFormModelItem::TextItem,
       
   443         hbTrId("txt_occ_setlabel_secondary_name_server"));
       
   444     mForm->addConnection(
       
   445         mIpv6DnsAddress2,
       
   446         SIGNAL(editingFinished()),
       
   447         this,
       
   448         SLOT(changeIpv6SecondaryDnsAddress()));  
       
   449     mIpGroup->appendChild(mIpv6DnsAddress2);
       
   450     
       
   451     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CREATEIPV6SETTINGITEMS_EXIT);
       
   452 }
       
   453 
       
   454 /*!
       
   455     Deletes the IPv6 setting items.
       
   456 */
       
   457 void CpPacketDataApAdvancedView::deleteIpv6SettingItems()
       
   458 {
       
   459     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_DELETEIPV6SETTINGITEMS_ENTRY);
       
   460     
       
   461     // DNS addresses
       
   462     // Automatic/well-known/user defined combobox
       
   463     if (mIpv6DnsAutomatic) {
       
   464         mIpGroup->removeChild(mIpGroup->indexOf(mIpv6DnsAutomatic));
       
   465         mIpv6DnsAutomatic = NULL;
       
   466     }
       
   467     
       
   468     // Primary DNS address
       
   469     if (mIpv6DnsAddress1) {
       
   470         mIpGroup->removeChild(mIpGroup->indexOf(mIpv6DnsAddress1));
       
   471         mIpv6DnsAddress1 = NULL;
       
   472     }
       
   473     
       
   474     // Secondary DNS address
       
   475     if (mIpv6DnsAddress2) {
       
   476         mIpGroup->removeChild(mIpGroup->indexOf(mIpv6DnsAddress2));
       
   477         mIpv6DnsAddress2 = NULL;
       
   478     }
       
   479     
       
   480     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_DELETEIPV6SETTINGITEMS_EXIT);
       
   481 }
       
   482 
       
   483 /*!
       
   484     Creates the proxy settings group.
       
   485 */
       
   486 void CpPacketDataApAdvancedView::createProxyGroup()
       
   487 {
       
   488     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CREATEPROXYGROUP_ENTRY);
       
   489     
       
   490     // Proxy settings group
       
   491     mProxyGroup = new CpSettingFormItemData(
       
   492         HbDataFormModelItem::GroupItem, 
       
   493         hbTrId("txt_occ_subhead_proxy_settings"));
       
   494     mModel->appendDataFormItem(mProxyGroup);
       
   495     
       
   496     // Proxy server address
       
   497     mProxyServer = new CpSettingFormItemData(
       
   498         HbDataFormModelItem::TextItem,
       
   499         hbTrId("txt_occ_setlabel_proxy_server_address"));
       
   500     mForm->addConnection(
       
   501         mProxyServer,
       
   502         SIGNAL(editingFinished()),
       
   503         this,
       
   504         SLOT(changeProxyServer()));
       
   505     mProxyGroup->appendChild(mProxyServer);
       
   506     
       
   507     // Proxy port number
       
   508     mProxyPort = new CpSettingFormItemData(
       
   509         HbDataFormModelItem::TextItem,
       
   510         hbTrId("txt_occ_setlabel_proxy_port_number"));
       
   511     mForm->addConnection(
       
   512         mProxyPort,
       
   513         SIGNAL(editingFinished()),
       
   514         this,
       
   515         SLOT(changeProxyPort()));
       
   516     mProxyGroup->appendChild(mProxyPort);
       
   517     
       
   518     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CREATEPROXYGROUP_EXIT);
       
   519 }
       
   520 
       
   521 /*!
       
   522     Reads attribute values and updates the proxy settings group.
       
   523 */
       
   524 void CpPacketDataApAdvancedView::updateProxyGroup()
       
   525 {
       
   526     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_UPDATEPROXYGROUP_ENTRY);
       
   527     
       
   528     // Proxy server address
       
   529     QString serverAddress = mCmConnectionMethod->getStringAttribute(
       
   530         CMManagerShim::CmProxyServerName);
       
   531     mProxyServer->setContentWidgetData("text", serverAddress);
       
   532     
       
   533     // Proxy port number
       
   534     uint portNumber = mCmConnectionMethod->getIntAttribute(
       
   535         CMManagerShim::CmProxyPortNumber);
       
   536     if (portNumber > 0) {
       
   537         mProxyPort->setContentWidgetData("text", QVariant(portNumber));
       
   538     } else {
       
   539         mProxyPort->setContentWidgetData("text", "");
       
   540     }
       
   541     
       
   542     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_UPDATEPROXYGROUP_EXIT);
       
   543 }
       
   544 
       
   545 /*!
       
   546     Reads network type (IPv4/IPv6) from CommsDat.
       
   547 */
       
   548 CpPacketDataApAdvancedView::NetworkType CpPacketDataApAdvancedView::getNetworkType()
       
   549 {
       
   550     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_GETNETWORKTYPE_ENTRY);
       
   551 
       
   552     uint networkType = mCmConnectionMethod->getIntAttribute(
       
   553         CMManagerShim::PacketDataPDPType);
       
   554     
       
   555     if (networkType == RPacketContext::EPdpTypeIPv6) {
       
   556         OstTraceFunctionExit0(DUP1_CPPACKETDATAAPADVANCEDVIEW_GETNETWORKTYPE_EXIT);
       
   557         return NetworkTypeIpv6;
       
   558     }
       
   559 
       
   560     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_GETNETWORKTYPE_EXIT);
       
   561     return NetworkTypeIpv4;
       
   562 }
       
   563 
       
   564 /*!
       
   565     Reads an IP address from CommsDat with given attribute. If string is
       
   566     empty, a zero address (0.0.0.0 or 0:0:0:0:0:0:0:0) is returned.
       
   567 */
       
   568 QString CpPacketDataApAdvancedView::getIpAddress(
       
   569     CMManagerShim::ConnectionMethodAttribute attribute)
       
   570 {
       
   571     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_GETIPADDRESS_ENTRY);
       
   572     
       
   573     QString ipAddress = mCmConnectionMethod->getStringAttribute(attribute);
       
   574     
       
   575     if (ipAddress.isEmpty()) {
       
   576         // String is empty, return a zero address instead
       
   577         switch (attribute) {
       
   578             case CMManagerShim::CmIPAddress:
       
   579             case CMManagerShim::CmIPNameServer1:
       
   580             case CMManagerShim::CmIPNameServer2:
       
   581                 // IPv4 address
       
   582                 ipAddress = CMManagerShim::UnspecifiedIpv4Address; 
       
   583                 break;
       
   584             
       
   585             case CMManagerShim::CmIP6NameServer1:
       
   586             case CMManagerShim::CmIP6NameServer2:
       
   587                 // IPv6 address
       
   588                 ipAddress = CMManagerShim::DynamicIpv6Address;
       
   589                 break;
       
   590         }
       
   591     }
       
   592     
       
   593     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_GETIPADDRESS_EXIT);
       
   594     return ipAddress;
       
   595 }
       
   596 
       
   597 /*!
       
   598     Resolves IPv6 DNS address type.
       
   599 */
       
   600 CpPacketDataApAdvancedView::Ipv6DnsType CpPacketDataApAdvancedView::getIpv6DnsType()
       
   601 {
       
   602     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_GETIPV6DNSTYPE_ENTRY);
       
   603     
       
   604     // Read "DNS address from server" flag
       
   605     bool dnsAddressFromServer = mCmConnectionMethod->getBoolAttribute(
       
   606         CMManagerShim::CmIP6DNSAddrFromServer);
       
   607     
       
   608     // Read IPv6 DNS addresses from CommsDat
       
   609     QString primaryAddress = mCmConnectionMethod->getStringAttribute(
       
   610         CMManagerShim::CmIP6NameServer1);
       
   611     QString secondaryAddress = mCmConnectionMethod->getStringAttribute(
       
   612         CMManagerShim::CmIP6NameServer2);
       
   613 
       
   614     // Resolve IPv6 DNS address type
       
   615     Ipv6DnsType type = Ipv6DnsTypeUserDefined;
       
   616     if (dnsAddressFromServer) {
       
   617         // Automatic
       
   618         type = Ipv6DnsTypeAutomatic;
       
   619     } else if (primaryAddress.toLower() == CMManagerShim::KnownIpv6NameServer1
       
   620         && secondaryAddress.toLower() == CMManagerShim::KnownIpv6NameServer2) {
       
   621         // Well-known IPv6 DNS addresses
       
   622         type = Ipv6DnsTypeWellKnown;
       
   623     }
       
   624 
       
   625     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_GETIPV6DNSTYPE_EXIT);
       
   626     return type;
       
   627 }
       
   628 
       
   629 /*!
       
   630     Sets IPv4 address field enabled/disabled.
       
   631 */
       
   632 void CpPacketDataApAdvancedView::enableIpv4AddressFields(int state)
       
   633 {
       
   634     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_ENABLEIPV4ADDRESSFIELDS_ENTRY);
       
   635     
       
   636     if (state == Qt::Checked) {
       
   637         // Automatic, disable text field
       
   638         if (mIpv4Address) {
       
   639             mIpv4Address->setEnabled(false);
       
   640         }
       
   641     } else {
       
   642         // User defined, enable text field
       
   643         if (mIpv4Address) {
       
   644             mIpv4Address->setEnabled(true);
       
   645         }
       
   646     }
       
   647     
       
   648     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_ENABLEIPV4ADDRESSFIELDS_EXIT);
       
   649 }
       
   650 
       
   651 /*!
       
   652     Sets IPv4 DNS address fields enabled/disabled.
       
   653 */
       
   654 void CpPacketDataApAdvancedView::enableIpv4DnsFields(int state)
       
   655 {
       
   656     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_ENABLEIPV4DNSFIELDS_ENTRY);
       
   657     
       
   658     if (state == Qt::Checked) {
       
   659         // Automatic, disable text fields
       
   660         if (mIpv4DnsAddress1) {
       
   661             mIpv4DnsAddress1->setEnabled(false);
       
   662         }
       
   663         if (mIpv4DnsAddress2) {
       
   664             mIpv4DnsAddress2->setEnabled(false);
       
   665         }
       
   666     } else {
       
   667         // User defined, enable text fields
       
   668         if (mIpv4DnsAddress1) {
       
   669             mIpv4DnsAddress1->setEnabled(true);
       
   670         }
       
   671         if (mIpv4DnsAddress2) {
       
   672             mIpv4DnsAddress2->setEnabled(true);
       
   673         }
       
   674     }
       
   675     
       
   676     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_ENABLEIPV4DNSFIELDS_EXIT);
       
   677 }
       
   678 
       
   679 /*!
       
   680     Sets IPv6 DNS address fields enabled/disabled.
       
   681 */
       
   682 void CpPacketDataApAdvancedView::enableIpv6DnsFields(int selectionIndex)
       
   683 {
       
   684     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_ENABLEIPV6DNSFIELDS_ENTRY);
       
   685     
       
   686     // Check combobox value
       
   687     if (selectionIndex == Ipv6DnsTypeUserDefined) {
       
   688         // User-defined, enable text fields
       
   689         if (mIpv6DnsAddress1) {
       
   690             mIpv6DnsAddress1->setEnabled(true);
       
   691         }
       
   692         if (mIpv6DnsAddress2) {
       
   693             mIpv6DnsAddress2->setEnabled(true);
       
   694         }
       
   695     } else {
       
   696         // Automatic or well-known, disable text fields
       
   697         if (mIpv6DnsAddress1) {
       
   698             mIpv6DnsAddress1->setEnabled(false);
       
   699         }
       
   700         if (mIpv6DnsAddress2) {
       
   701             mIpv6DnsAddress2->setEnabled(false);
       
   702         }
       
   703     }
       
   704     
       
   705     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_ENABLEIPV6DNSFIELDS_EXIT);
       
   706 }
       
   707 
       
   708 /*!
       
   709     Validates an IP address and saves it to CommsDat in case it was a valid
       
   710     address or an empty string. In case the address is not valid, an error
       
   711     note is shown to the user and previous setting is restored to the UI.
       
   712 */
       
   713 bool CpPacketDataApAdvancedView::validateAndSaveIpAddress(
       
   714     HbDataFormModelItem *item,
       
   715     CMManagerShim::ConnectionMethodAttribute attribute,
       
   716     QAbstractSocket::NetworkLayerProtocol protocol)
       
   717 {
       
   718     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_VALIDATEANDSAVEIPADDRESS_ENTRY);
       
   719     
       
   720     bool success = false;
       
   721     
       
   722     // Check address
       
   723     QString address = item->contentWidgetData("text").toString();
       
   724     QHostAddress hostAddress;
       
   725     if (hostAddress.setAddress(address)
       
   726         && hostAddress.protocol() == protocol) {
       
   727         // Proper address, convert to lower case (IPv6)
       
   728         address = hostAddress.toString().toLower();
       
   729     } else if (address.isEmpty()) {
       
   730         // Empty string, replace with 0.0.0.0 or 0:0:0:0:0:0:0:0
       
   731         if (protocol == QAbstractSocket::IPv4Protocol) {
       
   732             address = CMManagerShim::UnspecifiedIpv4Address;
       
   733         } else {
       
   734             address = CMManagerShim::DynamicIpv6Address;
       
   735         }
       
   736     } else {
       
   737         // Invalid address
       
   738         address.clear();
       
   739     }
       
   740 
       
   741     if (!address.isEmpty()) {
       
   742         // Save to CommsDat
       
   743         mCmConnectionMethod->setStringAttribute(attribute, address);
       
   744         if (tryUpdate()) {
       
   745             success = true;
       
   746             item->setContentWidgetData("text", address);
       
   747         }
       
   748     } else {
       
   749         // Inform user of invalid name
       
   750         showMessageBox(
       
   751             HbMessageBox::MessageTypeInformation,
       
   752             hbTrId("txt_occ_info_invalid_input"));
       
   753         // Restore previous setting
       
   754         address = getIpAddress(attribute);
       
   755         item->setContentWidgetData("text", address);
       
   756     }
       
   757     
       
   758     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_VALIDATEANDSAVEIPADDRESS_EXIT);
       
   759     return success;
       
   760 }
       
   761 
       
   762 /*!
       
   763     Shows message box with "OK" button using given text.
       
   764 */
       
   765 void CpPacketDataApAdvancedView::showMessageBox(
       
   766     HbMessageBox::MessageBoxType type,
       
   767     const QString &text)
       
   768 {
       
   769     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_SHOWMESSAGEBOX_ENTRY);
       
   770     
       
   771     // Create a message box
       
   772     mMessageBox = QSharedPointer<HbMessageBox>(new HbMessageBox(type));
       
   773     mMessageBox->setText(text);
       
   774     mMessageBox->setModal(true);
       
   775     mMessageBox->setTimeout(HbPopup::NoTimeout);
       
   776     mMessageBox->open();
       
   777     
       
   778     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_SHOWMESSAGEBOX_EXIT);
       
   779 }
       
   780 
       
   781 /*!
       
   782     Tries to update connection method changes to CommsDat.
       
   783     Returns "true" if success, "false" if some error happened. 
       
   784 */
       
   785 bool CpPacketDataApAdvancedView::tryUpdate()
       
   786 {
       
   787     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_TRYUPDATE_ENTRY);
       
   788     
       
   789     // Try update
       
   790     try {
       
   791         mCmConnectionMethod->update();
       
   792     }
       
   793     catch (const std::exception&) {
       
   794         // Handle error
       
   795         handleUpdateError();
       
   796         
       
   797         OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_TRYUPDATE_EXIT);
       
   798         return false;
       
   799     }
       
   800 
       
   801     OstTraceFunctionExit0(DUP1_CPPACKETDATAAPADVANCEDVIEW_TRYUPDATE_EXIT);
       
   802     return true;
       
   803 }
       
   804 
       
   805 /*!
       
   806     Handles failed CommsDat update.
       
   807  */
       
   808 void CpPacketDataApAdvancedView::handleUpdateError()
       
   809 {
       
   810     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_HANDLEUPDATEERROR_ENTRY);
       
   811     
       
   812     // Show error note to user
       
   813     showMessageBox(
       
   814         HbMessageBox::MessageTypeWarning,
       
   815         hbTrId("txt_occ_info_unable_to_save_setting"));
       
   816     // Reload settings from CommsDat and update UI
       
   817     try {
       
   818         mCmConnectionMethod->refresh();
       
   819     }
       
   820     catch (const std::exception&) {
       
   821         // Ignore error from refresh. Most likely this will not happen, but
       
   822         // if it does, there isn't very much we can do.
       
   823         OstTrace0(
       
   824             TRACE_ERROR,
       
   825             CPPACKETDATAAPPADVANCEDVIEW_HANDLEUPDATEERROR,
       
   826             "Refresh failed");
       
   827     };
       
   828     updateIpGroup();
       
   829     updateProxyGroup();
       
   830     
       
   831     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_HANDLEUPDATEERROR_EXIT);
       
   832 }
       
   833 
       
   834 /*!
       
   835     Initializes all settings groups.
       
   836 */
       
   837 void CpPacketDataApAdvancedView::setEditorPreferences(const QModelIndex index)
       
   838 {
       
   839     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_SETEDITORPREFERENCES_ENTRY);
       
   840     
       
   841     HbDataFormViewItem *viewItem = qobject_cast<HbDataFormViewItem *>
       
   842         (mForm->itemByIndex(index));
       
   843     HbDataFormModelItem *modelItem = mModel->itemFromIndex(index);
       
   844 
       
   845     if (modelItem == mIpv4Address
       
   846         || modelItem == mIpv4DnsAddress1
       
   847         || modelItem == mIpv4DnsAddress2
       
   848         || modelItem == mIpv6DnsAddress1
       
   849         || modelItem == mIpv6DnsAddress2
       
   850         || modelItem == mProxyServer
       
   851         || modelItem == mProxyPort) {
       
   852         // HbLineEdit items, get editor and editor interface
       
   853         HbLineEdit *edit = qobject_cast<HbLineEdit *>
       
   854             (viewItem->dataItemContentWidget());
       
   855         HbEditorInterface editorInterface(edit);
       
   856 
       
   857         if (modelItem == mIpv4Address
       
   858             || modelItem == mIpv4DnsAddress1
       
   859             || modelItem == mIpv4DnsAddress2) {
       
   860                 // IPv4 IP address
       
   861                 editorInterface.setMode(HbInputModeNumeric);
       
   862                 editorInterface.setFilter(CpIpv4Filter::instance());
       
   863                 edit->setMaxLength(CMManagerShim::CmIP4AddressLength);
       
   864         } else if (modelItem == mIpv6DnsAddress1
       
   865             || modelItem == mIpv6DnsAddress2) {
       
   866                 // IPv6 IP address
       
   867                 editorInterface.setInputConstraints(
       
   868                     HbEditorConstraintLatinAlphabetOnly);
       
   869                 editorInterface.setFilter(CpIpv6Filter::instance());
       
   870                 edit->setInputMethodHints(
       
   871                     Qt::ImhNoPredictiveText
       
   872                     | Qt::ImhPreferLowercase);
       
   873                 edit->setMaxLength(CMManagerShim::CmIP6NameServerLength);
       
   874         } else if (modelItem == mProxyServer) {                
       
   875                 // Proxy server address
       
   876                 editorInterface.setMode(HbInputModeNone);
       
   877                 editorInterface.setInputConstraints(
       
   878                     HbEditorConstraintLatinAlphabetOnly);
       
   879                 editorInterface.setFilter(HbUrlFilter::instance());
       
   880                 editorInterface.setEditorClass(HbInputEditorClassUrl);
       
   881                 editorInterface.setDigitType(HbDigitTypeNone);
       
   882                 edit->setInputMethodHints(
       
   883                     Qt::ImhNoPredictiveText
       
   884                     | Qt::ImhPreferLowercase);
       
   885                 edit->setMaxLength(CMManagerShim::CmProxyServerNameLength);
       
   886         } else { /* mProxyPort */                
       
   887                 // Proxy port number
       
   888                 editorInterface.setMode(HbInputModeNumeric);
       
   889                 edit->setInputMethodHints(Qt::ImhDigitsOnly);
       
   890                 edit->setMaxLength(CMManagerShim::CmProxyPortNumberLength);
       
   891         }
       
   892     }
       
   893     
       
   894     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_SETEDITORPREFERENCES_EXIT);
       
   895 }
       
   896 
       
   897 /*!
       
   898     Handles change to network type (IPv4/IPv6).
       
   899 */
       
   900 void CpPacketDataApAdvancedView::changeNetworkType(int type)
       
   901 {
       
   902     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGENETWORKTYPE_ENTRY);
       
   903 
       
   904     // Save network type to CommsDat
       
   905     int pdpType;
       
   906     if (type == NetworkTypeIpv6) {
       
   907         pdpType = RPacketContext::EPdpTypeIPv6;
       
   908     } else {
       
   909         pdpType = RPacketContext::EPdpTypeIPv4;
       
   910     }
       
   911     mCmConnectionMethod->setIntAttribute(
       
   912         CMManagerShim::PacketDataPDPType,
       
   913         pdpType);
       
   914     if (tryUpdate())
       
   915         {
       
   916         // This will handle updating the UI with correct setting items 
       
   917         updateIpGroup();
       
   918         }
       
   919     
       
   920     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGENETWORKTYPE_EXIT);
       
   921 }
       
   922 
       
   923 /*!
       
   924     Handles change to IPv4 address mode (automatic/user defined).
       
   925 */
       
   926 void CpPacketDataApAdvancedView::changeIpv4AddressMode(int state)
       
   927 {
       
   928     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4ADDRESSMODE_ENTRY);
       
   929     
       
   930     bool ipv4AddressFromServer;
       
   931     if (state == Qt::Checked) {
       
   932         ipv4AddressFromServer = true;
       
   933     } else {
       
   934         ipv4AddressFromServer = false;
       
   935     }
       
   936     
       
   937     if (!ipv4AddressFromServer
       
   938         && getIpAddress(CMManagerShim::CmIPAddress) ==
       
   939             CMManagerShim::UnspecifiedIpv4Address) {
       
   940         // User defined IP address selected, but no valid address is stored.
       
   941         // Just enable the UI IP editors, because CMManager will update the
       
   942         // "IP address from server" flag by itself when a valid IP address
       
   943         // is stored.
       
   944         enableIpv4AddressFields(state);
       
   945     } else {
       
   946         // Save setting to CommsDat
       
   947         mCmConnectionMethod->setBoolAttribute(
       
   948             CMManagerShim::CmIPAddrFromServer,
       
   949             ipv4AddressFromServer);
       
   950         if (tryUpdate()) {
       
   951             enableIpv4AddressFields(state);
       
   952         }
       
   953     }
       
   954     
       
   955     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4ADDRESSMODE_EXIT);
       
   956 }
       
   957 
       
   958 /*!
       
   959     Saves IPv4 address to CommsDat.
       
   960 */
       
   961 void CpPacketDataApAdvancedView::changeIpv4Address()
       
   962 {
       
   963     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4ADDRESS_ENTRY);
       
   964     
       
   965     if (validateAndSaveIpAddress(
       
   966         mIpv4Address,
       
   967         CMManagerShim::CmIPAddress,
       
   968         QAbstractSocket::IPv4Protocol)) {
       
   969         // In case the IP address is empty or 0.0.0.0, CMManager changes the
       
   970         // "IP address from server" flag to true. We need to refresh the UI to
       
   971         // make sure we are in sync.
       
   972         updateIpGroup();
       
   973     }
       
   974 
       
   975     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4ADDRESS_EXIT);
       
   976 }
       
   977 
       
   978 /*!
       
   979     Handles change to IPv4 DNS mode (automatic/user defined).
       
   980 */
       
   981 void CpPacketDataApAdvancedView::changeIpv4DnsMode(int state)
       
   982 {
       
   983     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4DNSMODE_ENTRY);
       
   984     
       
   985     bool dnsAddressFromServer;
       
   986     if (state == Qt::Checked) {
       
   987         dnsAddressFromServer = true;
       
   988     } else {
       
   989         dnsAddressFromServer = false;
       
   990     }
       
   991     // Save setting to CommsDat
       
   992     mCmConnectionMethod->setBoolAttribute(
       
   993         CMManagerShim::CmIPDNSAddrFromServer,
       
   994         dnsAddressFromServer);
       
   995     if (tryUpdate()) {
       
   996         enableIpv4DnsFields(state);
       
   997     }
       
   998     
       
   999     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4DNSMODE_EXIT);
       
  1000 }
       
  1001 
       
  1002 /*!
       
  1003     Saves IPv4 primary DNS address to CommsDat.
       
  1004 */
       
  1005 void CpPacketDataApAdvancedView::changeIpv4PrimaryDnsAddress()
       
  1006 {
       
  1007     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4PRIMARYDNSADDRESS_ENTRY);
       
  1008     
       
  1009     if (validateAndSaveIpAddress(
       
  1010         mIpv4DnsAddress1,
       
  1011         CMManagerShim::CmIPNameServer1,
       
  1012         QAbstractSocket::IPv4Protocol)) {
       
  1013         // Address saved successfully, update "DNS address from server" flag
       
  1014         mCmConnectionMethod->setBoolAttribute(
       
  1015             CMManagerShim::CmIPDNSAddrFromServer,
       
  1016             false);
       
  1017         if (tryUpdate()) {
       
  1018             // In case primary DNS address is empty or 0.0.0.0, CMManager will
       
  1019             // check secondary DNS address and in case it is a valid address,
       
  1020             // move it to the primary DNS address. We need to refresh the
       
  1021             // UI to make sure we are in sync. If tryUpdate() fails it does
       
  1022             // the refresh automatically, so only success case is handled
       
  1023             // here.
       
  1024             updateIpGroup();            
       
  1025         }
       
  1026     }
       
  1027     
       
  1028     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4PRIMARYDNSADDRESS_EXIT);
       
  1029 }
       
  1030 
       
  1031 /*!
       
  1032     Saves IPv4 secondary DNS address to CommsDat.
       
  1033 */
       
  1034 void CpPacketDataApAdvancedView::changeIpv4SecondaryDnsAddress()
       
  1035 {
       
  1036     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4SECONDARYDNSADDRESS_ENTRY);
       
  1037     
       
  1038     if (validateAndSaveIpAddress(
       
  1039         mIpv4DnsAddress2,
       
  1040         CMManagerShim::CmIPNameServer2,
       
  1041         QAbstractSocket::IPv4Protocol)) {
       
  1042         // Address saved successfully, update "DNS address from server" flag
       
  1043         mCmConnectionMethod->setBoolAttribute(
       
  1044             CMManagerShim::CmIPDNSAddrFromServer,
       
  1045             false);
       
  1046         if (tryUpdate()) {
       
  1047             // In case primary DNS address is empty or 0.0.0.0, CMManager will
       
  1048             // write the address there instead of secondary DNS address, so we
       
  1049             // need to refresh the UI to make sure we are in sync. If
       
  1050             // tryUpdate() fails it does the refresh automatically, so only
       
  1051             // success case is handled here.
       
  1052             updateIpGroup();
       
  1053         }
       
  1054     }
       
  1055     
       
  1056     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV4SECONDARYDNSADDRESS_EXIT);
       
  1057 }
       
  1058 
       
  1059 /*!
       
  1060     Handles change to IPv6 DNS mode (automatic/well-known/user defined).
       
  1061 */
       
  1062 void CpPacketDataApAdvancedView::changeIpv6DnsMode(int state)
       
  1063 {
       
  1064     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV6DNSMODE_ENTRY);
       
  1065     
       
  1066     // Update "DNS address from server" flag
       
  1067     if (state == Ipv6DnsTypeAutomatic) {
       
  1068         // Automatic
       
  1069         mCmConnectionMethod->setBoolAttribute(
       
  1070             CMManagerShim::CmIP6DNSAddrFromServer,
       
  1071             true);
       
  1072     } else {
       
  1073         // User defined or well-known address
       
  1074         mCmConnectionMethod->setBoolAttribute(
       
  1075             CMManagerShim::CmIP6DNSAddrFromServer,
       
  1076             false);
       
  1077         
       
  1078         if (state == Ipv6DnsTypeWellKnown) {
       
  1079             // Well-known address, set DNS addresses and update UI
       
  1080             mCmConnectionMethod->setStringAttribute(
       
  1081                 CMManagerShim::CmIP6NameServer1,
       
  1082                 CMManagerShim::KnownIpv6NameServer1);
       
  1083             mIpv6DnsAddress1->setContentWidgetData(
       
  1084                 "text",
       
  1085                 CMManagerShim::KnownIpv6NameServer1);
       
  1086             mCmConnectionMethod->setStringAttribute(
       
  1087                 CMManagerShim::CmIP6NameServer2,
       
  1088                 CMManagerShim::KnownIpv6NameServer2);
       
  1089             mIpv6DnsAddress2->setContentWidgetData(
       
  1090                 "text",
       
  1091                 CMManagerShim::KnownIpv6NameServer2);        
       
  1092         }
       
  1093     }
       
  1094 
       
  1095     if (tryUpdate()) {
       
  1096         enableIpv6DnsFields(state);
       
  1097     }
       
  1098     
       
  1099     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV6DNSMODE_EXIT);
       
  1100 }
       
  1101 
       
  1102 /*!
       
  1103     Saves IPv6 primary DNS address to CommsDat.
       
  1104 */
       
  1105 void CpPacketDataApAdvancedView::changeIpv6PrimaryDnsAddress()
       
  1106 {
       
  1107     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV6PRIMARYDNSADDRESS_ENTRY);
       
  1108     
       
  1109     if (validateAndSaveIpAddress(
       
  1110         mIpv6DnsAddress1,
       
  1111         CMManagerShim::CmIP6NameServer1,
       
  1112         QAbstractSocket::IPv6Protocol)) {
       
  1113         // Address saved successfully, update "DNS address from server" flag
       
  1114         mCmConnectionMethod->setBoolAttribute(
       
  1115             CMManagerShim::CmIP6DNSAddrFromServer,
       
  1116             false);
       
  1117         if (tryUpdate()) {
       
  1118             // In case primary DNS address is empty or 0:0:0:0:0:0:0:0,
       
  1119             // CMManager will check secondary DNS address and in case it is a
       
  1120             // valid address, move it to the primary DNS address. We need to
       
  1121             // refresh the UI to make sure we are in sync. If tryUpdate()
       
  1122             // fails it does the refresh automatically, so only success case
       
  1123             // is handled here.
       
  1124             updateIpGroup();            
       
  1125         }
       
  1126     }
       
  1127     
       
  1128     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV6PRIMARYDNSADDRESS_EXIT);
       
  1129 }
       
  1130 
       
  1131 /*!
       
  1132     Saves IPv6 secondary DNS address to CommsDat.
       
  1133 */
       
  1134 void CpPacketDataApAdvancedView::changeIpv6SecondaryDnsAddress()
       
  1135 {
       
  1136     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV6SECONDARYDNSADDRESS_ENTRY);
       
  1137     
       
  1138     if (validateAndSaveIpAddress(
       
  1139         mIpv6DnsAddress2,
       
  1140         CMManagerShim::CmIP6NameServer2,
       
  1141         QAbstractSocket::IPv6Protocol)) {
       
  1142         // Address saved successfully, update "DNS address from server" flag
       
  1143         mCmConnectionMethod->setBoolAttribute(
       
  1144             CMManagerShim::CmIP6DNSAddrFromServer,
       
  1145             false);
       
  1146         if (tryUpdate()) {
       
  1147             // In case primary DNS address is empty or 0:0:0:0:0:0:0:0,
       
  1148             // CMManager will write the address there instead of secondary DNS
       
  1149             // address, so we need to refresh the UI to make sure we are in
       
  1150             // sync. If tryUpdate() fails it does the refresh automatically,
       
  1151             // so only success case is handled here.
       
  1152             updateIpGroup();
       
  1153         }
       
  1154     }
       
  1155     
       
  1156     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEIPV6SECONDARYDNSADDRESS_EXIT);
       
  1157 }
       
  1158 
       
  1159 /*!
       
  1160     Saves proxy server address to CommsDat.
       
  1161 */
       
  1162 void CpPacketDataApAdvancedView::changeProxyServer()
       
  1163 {
       
  1164     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEPROXYSERVER_ENTRY);
       
  1165     
       
  1166     QString proxyServer = mProxyServer->contentWidgetData("text").toString();
       
  1167     mCmConnectionMethod->setStringAttribute(
       
  1168         CMManagerShim::CmProxyServerName,
       
  1169         proxyServer);
       
  1170     (void)tryUpdate();
       
  1171     
       
  1172     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEPROXYSERVER_EXIT);
       
  1173 }
       
  1174 
       
  1175 /*!
       
  1176     Saves proxy port to CommsDat.
       
  1177 */
       
  1178 void CpPacketDataApAdvancedView::changeProxyPort()
       
  1179 {
       
  1180     OstTraceFunctionEntry0(CPPACKETDATAAPADVANCEDVIEW_CHANGEPROXYPORT_ENTRY);
       
  1181     
       
  1182     uint proxyPort = mProxyPort->contentWidgetData("text").toInt();
       
  1183     if (proxyPort <= 65535) {
       
  1184         if (proxyPort == 0) {
       
  1185             // Don't show zero
       
  1186             mProxyPort->setContentWidgetData("text", "");
       
  1187         }
       
  1188         mCmConnectionMethod->setIntAttribute(
       
  1189             CMManagerShim::CmProxyPortNumber,
       
  1190             proxyPort);
       
  1191         (void)tryUpdate();
       
  1192     } else {
       
  1193         // Inform user of invalid value
       
  1194         showMessageBox(
       
  1195             HbMessageBox::MessageTypeInformation,
       
  1196             hbTrId("txt_occ_info_invalid_input"));
       
  1197         // Restore previous setting
       
  1198         proxyPort = mCmConnectionMethod->getIntAttribute(
       
  1199             CMManagerShim::CmProxyPortNumber);
       
  1200         if (proxyPort > 0) {
       
  1201             mProxyPort->setContentWidgetData("text", QVariant(proxyPort));
       
  1202         } else {
       
  1203             mProxyPort->setContentWidgetData("text", "");
       
  1204         }
       
  1205     }
       
  1206     
       
  1207     OstTraceFunctionExit0(CPPACKETDATAAPADVANCEDVIEW_CHANGEPROXYPORT_EXIT);
       
  1208 }