phonesettings/cpphonesettingsplugins/barringplugin/src/cpbarringplugingroup.cpp
changeset 37 ba76fc04e6c2
child 45 6b911d05207e
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     1 /*
       
     2  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  
       
    15  *
       
    16  */
       
    17 
       
    18 #include <hbdataformmodel.h>
       
    19 #include <hbdataformmodelitem.h>
       
    20 #include <HbCheckBox>
       
    21 #include <QTimer>
       
    22 #include <QValidator>
       
    23 #include <cpitemdatahelper.h>
       
    24 #include <psetwrapper.h>
       
    25 #include <psetcallbarringwrapper.h>
       
    26 #include "cpbarringplugingroup.h"
       
    27 #include "cpplugincommon.h"
       
    28 #include "cpphonenotes.h"
       
    29 #include "cppluginlogging.h"
       
    30 
       
    31 const int KMaxPasswordLength = 4;
       
    32 
       
    33 Q_DECLARE_METATYPE(PSetCallBarringWrapper::BarringType)
       
    34 
       
    35 /*!
       
    36   CpBarringPluginGroup::CpBarringPluginGroup.
       
    37  */
       
    38 CpBarringPluginGroup::CpBarringPluginGroup(CpItemDataHelper &helper)
       
    39     :
       
    40     CpSettingFormItemData(
       
    41         HbDataFormModelItem::GroupItem, 
       
    42         hbTrId("txt_phone_subhead_call_barring"), 0),
       
    43     m_helper(helper),
       
    44     m_pSetWrapper(0),
       
    45     m_barringWrapper(0),
       
    46     m_editBarringPasswordItem(0),
       
    47     m_barringStatusRequestOngoing(false),
       
    48     m_activeNoteId(0),
       
    49     m_phoneNotes(0),
       
    50     m_barringPasswordValidator(0),
       
    51     m_delayedBarringActivationNote(false),
       
    52     m_clickedBarringItem(NULL),
       
    53     m_changeBarringPasswordPhase(NonePhase),
       
    54     m_verifyPasswordValidator(NULL),
       
    55     m_model(0)
       
    56 {
       
    57     DPRINT << ": IN";
       
    58     
       
    59     // Registration needed, because BarringType is used as a custom meta 
       
    60     // information for barring items.
       
    61     qRegisterMetaType<PSetCallBarringWrapper::BarringType>(
       
    62         "PSetCallBarringWrapper::BarringType");
       
    63     
       
    64     m_pSetWrapper.reset(new PSetWrapper(NULL));
       
    65     m_barringWrapper = &m_pSetWrapper->callBarringWrapper(); 
       
    66     setupConnectionsToWrapper();
       
    67     
       
    68     // itemShown signal is used to trigger barring status query process 
       
    69     helper.connectToForm(
       
    70         SIGNAL(itemShown(QModelIndex)), 
       
    71         this, SLOT(itemShown(QModelIndex)));
       
    72     
       
    73     createBarringItems();
       
    74     
       
    75     m_phoneNotes = CpPhoneNotes::instance();
       
    76     
       
    77     QRegExp regExpression("\\d{4}");
       
    78     m_barringPasswordValidator = new QRegExpValidator(regExpression, this);
       
    79     
       
    80     DPRINT << ": OUT";
       
    81 }
       
    82 
       
    83 
       
    84 /*!
       
    85   CpBarringPluginGroup::~CpBarringPluginGroup.
       
    86  */
       
    87 CpBarringPluginGroup::~CpBarringPluginGroup()
       
    88 {
       
    89     DPRINT << ": IN";
       
    90     
       
    91     if (m_verifyPasswordValidator) {
       
    92         delete m_verifyPasswordValidator;                    
       
    93     }
       
    94     
       
    95     DPRINT << ": OUT";
       
    96 }
       
    97 
       
    98 
       
    99 /*!
       
   100   CpBarringPluginGroup::itemShown.
       
   101  */
       
   102 void CpBarringPluginGroup::itemShown(const QModelIndex& item)
       
   103 {
       
   104     DPRINT << ": IN";
       
   105     
       
   106     CpSettingFormItemData* formItem = 
       
   107         static_cast<CpSettingFormItemData*>(
       
   108             qobject_cast<const HbDataFormModel*>(item.model())->itemFromIndex(item));
       
   109     
       
   110     if (!formItem->property("barringType").isValid()) {
       
   111         // Shown item does not belong to the barring settings group.
       
   112         return;
       
   113         }
       
   114     
       
   115     m_model = const_cast<HbDataFormModel*>(qobject_cast<const HbDataFormModel*>(item.model()));
       
   116         
       
   117     if (formItem == m_editBarringPasswordItem) {
       
   118         return;
       
   119     }
       
   120     
       
   121     if (formItem->isEnabled()) {
       
   122         // Initial status for the barring item is already queried. Do not 
       
   123         // start querying again if user does close/open for the barring group.
       
   124         return;
       
   125     }
       
   126     
       
   127     // start barring status query
       
   128     m_barringRequestQueue.enqueue(formItem);
       
   129     processBarringStatusRequestQueue();
       
   130     
       
   131     DPRINT << ": OUT";
       
   132 }
       
   133 
       
   134 
       
   135 /*!
       
   136   CpBarringPluginGroup::setupConnectionsToWrapper.
       
   137  */
       
   138 void CpBarringPluginGroup::setupConnectionsToWrapper()
       
   139 {
       
   140     DPRINT << ": IN";
       
   141     
       
   142     QObject::connect(
       
   143         m_barringWrapper, 
       
   144         SIGNAL(barringStatusRequestCompleted(
       
   145             int,
       
   146             const QList<unsigned char> &, 
       
   147             PSetCallBarringWrapper::BarringStatus)
       
   148         ),
       
   149         this, 
       
   150         SLOT(barringStatusRequestCompleted(
       
   151             int,
       
   152             const QList<unsigned char> &, 
       
   153             PSetCallBarringWrapper::BarringStatus)
       
   154         )
       
   155     );
       
   156     
       
   157     QObject::connect(
       
   158         m_barringWrapper, 
       
   159         SIGNAL(enableBarringRequestCompleted(
       
   160             int,
       
   161             PSetCallBarringWrapper::BarringType,
       
   162             PSetCallBarringWrapper::BarringStatus,
       
   163             bool)
       
   164         ),
       
   165         this, 
       
   166         SLOT(enableBarringRequestCompleted(
       
   167             int,
       
   168             PSetCallBarringWrapper::BarringType,
       
   169             PSetCallBarringWrapper::BarringStatus,
       
   170             bool)
       
   171         )
       
   172     );
       
   173     
       
   174     QObject::connect(
       
   175         m_barringWrapper, 
       
   176         SIGNAL(disableBarringRequestCompleted(
       
   177             int,
       
   178             PSetCallBarringWrapper::BarringType,
       
   179             PSetCallBarringWrapper::BarringStatus,
       
   180             bool)
       
   181         ),
       
   182         this, 
       
   183         SLOT(disableBarringRequestCompleted(
       
   184             int,
       
   185             PSetCallBarringWrapper::BarringType,
       
   186             PSetCallBarringWrapper::BarringStatus,
       
   187             bool)
       
   188         )
       
   189     );
       
   190     
       
   191     QObject::connect(
       
   192         m_barringWrapper, 
       
   193         SIGNAL(barringPasswordChangeRequestCompleted(int)),
       
   194         this, 
       
   195         SLOT(barringPasswordChangeRequestCompleted(int))
       
   196     );
       
   197     
       
   198     DPRINT << ": OUT";
       
   199 }
       
   200 
       
   201 
       
   202 /*!
       
   203   CpBarringPluginGroup::createBarringItems.
       
   204  */
       
   205 void CpBarringPluginGroup::createBarringItems()
       
   206 {
       
   207     DPRINT << ": IN";
       
   208     
       
   209     createBarringItem(
       
   210         HbDataFormModelItem::CheckBoxItem,
       
   211         QString(""),
       
   212         hbTrId("txt_phone_list_outgoing_calls"),
       
   213         PSetCallBarringWrapper::BarringTypeAllOutgoing);
       
   214     
       
   215     createBarringItem(
       
   216         HbDataFormModelItem::CheckBoxItem,
       
   217         QString(""),
       
   218         hbTrId("txt_phone_list_international_calls"),
       
   219         PSetCallBarringWrapper::BarringTypeOutgoingInternational);
       
   220     
       
   221     createBarringItem(
       
   222         HbDataFormModelItem::CheckBoxItem,
       
   223         QString(""),
       
   224         hbTrId("txt_phone_list_international_calls_except_to_home"),
       
   225         PSetCallBarringWrapper::BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   226     
       
   227     createBarringItem(
       
   228         HbDataFormModelItem::CheckBoxItem,
       
   229         QString(""),
       
   230         hbTrId("txt_phone_list_incoming_calls"),
       
   231         PSetCallBarringWrapper::BarringTypeAllIncoming);
       
   232     
       
   233     createBarringItem(
       
   234         HbDataFormModelItem::CheckBoxItem,
       
   235         QString(""),
       
   236         hbTrId("txt_phone_list_incoming_call_when_abroad"),
       
   237         PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming);
       
   238     
       
   239     // Dummy BarringTypeAllServices is used to indicate that this item belongs 
       
   240     // to the barring settings group. Information is needed in itemShown().
       
   241     m_editBarringPasswordItem = createBarringItem(
       
   242         HbDataFormModelItem::ToggleValueItem,
       
   243         hbTrId("txt_phone_setlabel_edit_barring_password"),
       
   244         hbTrId("txt_phone_setlabel_edit_barring_password_val_edit"),
       
   245         PSetCallBarringWrapper::BarringTypeAllServices);
       
   246     m_editBarringPasswordItem->setContentWidgetData(
       
   247         QString("additionalText"),
       
   248         hbTrId("txt_phone_setlabel_edit_barring_password_val_edit"));
       
   249     
       
   250     DPRINT << ": OUT";
       
   251 }
       
   252 
       
   253 
       
   254 /*!
       
   255   CpBarringPluginGroup::createBarringItem.
       
   256  */
       
   257 CpSettingFormItemData *CpBarringPluginGroup::createBarringItem(
       
   258     const HbDataFormModelItem::DataItemType &itemType,
       
   259     const QString &label,
       
   260     const QString &widgetTextData,
       
   261     const PSetCallBarringWrapper::BarringType &barringType)
       
   262 {
       
   263     DPRINT << ": IN";
       
   264     
       
   265     QScopedPointer<CpSettingFormItemData> barringItem(
       
   266         new CpSettingFormItemData(itemType, label, this));
       
   267     
       
   268     barringItem->setContentWidgetData("text", QVariant(widgetTextData));
       
   269     barringItem->setEnabled(false);
       
   270     
       
   271     QVariant value;
       
   272     value.setValue(barringType);
       
   273     barringItem->setProperty("barringType", value);
       
   274     
       
   275     appendChild(barringItem.data());
       
   276     DPRINT << ": OUT";
       
   277     return barringItem.take();
       
   278 }
       
   279 
       
   280 
       
   281 /*!
       
   282   CpBarringPluginGroup::barringStatusRequestCompleted.
       
   283  */
       
   284 void CpBarringPluginGroup::barringStatusRequestCompleted(
       
   285     int result,
       
   286     const QList<unsigned char> &basicServiceGroupIds,
       
   287     PSetCallBarringWrapper::BarringStatus status)
       
   288 {
       
   289     DPRINT << ": IN" << ": result:" << result << "status:" << status;
       
   290     Q_UNUSED(result)
       
   291     Q_UNUSED(basicServiceGroupIds)
       
   292     
       
   293     m_barringStatusRequestOngoing = false;
       
   294     
       
   295     if (PSetCallBarringWrapper::BarringErrorNone != result) {
       
   296         // Stop status query process for this time. Statuses are tried to 
       
   297         // query again for uncompleted items when user expands/opens barring 
       
   298         // settings group again.
       
   299         m_phoneNotes->cancelNote(m_activeNoteId);
       
   300         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   301         m_barringRequestQueue.clear();
       
   302         return;
       
   303     }
       
   304     
       
   305     CpSettingFormItemData *itemForCompletedRequest = 
       
   306         m_barringRequestQueue.dequeue();
       
   307     
       
   308     if (!itemForCompletedRequest->isEnabled()) {
       
   309         // After enabling setting item here status query will not be started 
       
   310         // again for the item when user collapses and expands the barring 
       
   311         // settings group again.
       
   312         itemForCompletedRequest->setEnabled(true);
       
   313         // start to observe user initiated state changes
       
   314         m_helper.addConnection(
       
   315             itemForCompletedRequest, SIGNAL(stateChanged(int)),
       
   316             this, SLOT(changeBarringStateRequested(int)));
       
   317     }
       
   318     
       
   319     Qt::CheckState checkState = 
       
   320         (PSetCallBarringWrapper::BarringStatusActive == status) 
       
   321             ? Qt::Checked 
       
   322             : Qt::Unchecked;
       
   323     updateCheckStateOfItem(*itemForCompletedRequest, checkState);
       
   324     
       
   325     if (m_barringRequestQueue.isEmpty()) {
       
   326         m_phoneNotes->cancelNote(m_activeNoteId);
       
   327         if (m_delayedBarringActivationNote) {
       
   328             m_delayedBarringActivationNote = false;
       
   329             m_phoneNotes->showGlobalNote(
       
   330                 m_activeNoteId, 
       
   331                 hbTrId("txt_phone_info_barring_activated"),
       
   332                 HbMessageBox::MessageTypeInformation);
       
   333         }
       
   334         
       
   335         // Password editing is enabled only after all barring statuses are 
       
   336         // queried. Otherwise user may be able to issue two requests 
       
   337         // simultaneously by hiding status query progress note and clicking 
       
   338         // edit password.
       
   339         if (!m_editBarringPasswordItem->isEnabled()) {
       
   340             m_editBarringPasswordItem->setEnabled(true);
       
   341             m_helper.addConnection(
       
   342                 m_editBarringPasswordItem, SIGNAL(clicked(bool)),
       
   343                 this, SLOT(changeBarringPasswordRequested(bool)));
       
   344         }
       
   345     } else {
       
   346         processBarringStatusRequestQueue();
       
   347     }
       
   348     
       
   349     DPRINT << ": OUT";
       
   350 }
       
   351 
       
   352 
       
   353 /*!
       
   354   CpBarringPluginGroup::enableBarringRequestCompleted.
       
   355  */
       
   356 void CpBarringPluginGroup::enableBarringRequestCompleted(
       
   357     int result,
       
   358     PSetCallBarringWrapper::BarringType barringType,
       
   359     PSetCallBarringWrapper::BarringStatus barringStatus, 
       
   360     bool plural)
       
   361 {
       
   362     DPRINT << ": IN: result:" << result << "barringType:" << barringType 
       
   363         << "barringStatus:" << barringStatus << "plural:" << plural;
       
   364     Q_UNUSED(barringType)
       
   365     Q_UNUSED(barringStatus)
       
   366     Q_UNUSED(plural)
       
   367     
       
   368     CpSettingFormItemData *barringItem = m_barringRequestQueue.dequeue();
       
   369     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   370         if (updateDependentBarringProgramStatuses(*barringItem)) {
       
   371             // Indicate barring activation completion only when dependent 
       
   372             // barring items are also updated.
       
   373             m_delayedBarringActivationNote = true;
       
   374         } else {
       
   375             m_phoneNotes->cancelNote(m_activeNoteId);
       
   376             m_phoneNotes->showGlobalNote(
       
   377                 m_activeNoteId, 
       
   378                 hbTrId("txt_phone_info_barring_activated"),
       
   379                 HbMessageBox::MessageTypeInformation);
       
   380         }
       
   381     } else {
       
   382         revertCheckStateOfItem(barringItem);
       
   383         
       
   384         m_phoneNotes->cancelNote(m_activeNoteId);
       
   385         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   386     }
       
   387     
       
   388     DPRINT << ": OUT";
       
   389 }
       
   390 
       
   391 
       
   392 /*!
       
   393   CpBarringPluginGroup::disableBarringRequestCompleted.
       
   394  */
       
   395 void CpBarringPluginGroup::disableBarringRequestCompleted(
       
   396     int result,
       
   397     PSetCallBarringWrapper::BarringType barringType,
       
   398     PSetCallBarringWrapper::BarringStatus barringStatus, 
       
   399     bool plural)
       
   400 {
       
   401     DPRINT << ": IN: result:" << result << "barringType:" << barringType 
       
   402         << "barringStatus:" << barringStatus << "plural:" << plural;
       
   403     Q_UNUSED(barringType)
       
   404     Q_UNUSED(barringStatus)
       
   405     Q_UNUSED(plural)
       
   406     
       
   407     m_phoneNotes->cancelNote(m_activeNoteId);
       
   408     
       
   409     CpSettingFormItemData *barringItem = m_barringRequestQueue.dequeue();
       
   410     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   411         m_phoneNotes->showGlobalNote(
       
   412             m_activeNoteId, 
       
   413             hbTrId("txt_phone_info_barring_deactivated"),
       
   414             HbMessageBox::MessageTypeInformation);
       
   415     } else {
       
   416         revertCheckStateOfItem(barringItem);
       
   417         
       
   418         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   419     }
       
   420     
       
   421     DPRINT << ": OUT";
       
   422 }
       
   423 
       
   424 
       
   425 /*!
       
   426   CpBarringPluginGroup::barringPasswordChangeRequestCompleted.
       
   427  */
       
   428 void CpBarringPluginGroup::barringPasswordChangeRequestCompleted(int result)
       
   429 {
       
   430     DPRINT << ": IN: result:" << result;
       
   431     
       
   432     m_phoneNotes->cancelNote(m_activeNoteId);
       
   433     
       
   434     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   435         m_phoneNotes->showGlobalNote(
       
   436             m_activeNoteId, 
       
   437             hbTrId("txt_phone_info_password_changed"),
       
   438             HbMessageBox::MessageTypeInformation);
       
   439     } else {
       
   440         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   441     }
       
   442 }
       
   443 
       
   444 
       
   445 /*!
       
   446   CpBarringPluginGroup::processBarringStatusRequestQueue.
       
   447  */
       
   448 void CpBarringPluginGroup::processBarringStatusRequestQueue()
       
   449 {
       
   450     DPRINT << ": IN";
       
   451     
       
   452     if ((m_barringStatusRequestOngoing == false) && 
       
   453         (!m_barringRequestQueue.isEmpty())) {
       
   454         
       
   455         CpSettingFormItemData *item = m_barringRequestQueue.head();
       
   456         PSetCallBarringWrapper::BarringType barringType =
       
   457             qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   458                 item->property("barringType"));
       
   459         m_barringWrapper->barringStatus(ServiceGroupVoice, barringType);
       
   460         
       
   461         m_barringStatusRequestOngoing = true;
       
   462         
       
   463         if (!m_phoneNotes->noteShowing()) {
       
   464             // Launch progress note only once for status update.
       
   465             m_phoneNotes->showGlobalProgressNote(
       
   466                 m_activeNoteId, hbTrId("txt_phone_info_requesting"));
       
   467         }
       
   468     }
       
   469     
       
   470     DPRINT << ": OUT";
       
   471 }
       
   472 
       
   473 
       
   474 /*!
       
   475   CpBarringPluginGroup::changeBarringStateRequested.
       
   476  */
       
   477 void CpBarringPluginGroup::changeBarringStateRequested(int checkState)
       
   478 {
       
   479     DPRINT << ": IN";
       
   480     Q_UNUSED(checkState)
       
   481     // find form item for which user has requested barring status change
       
   482     QObject *signalSender = sender();
       
   483         
       
   484     int numOfChilds = childCount();
       
   485     for (int i = 0; (i < numOfChilds) && (m_clickedBarringItem == NULL); i++) {
       
   486         HbDataFormModelItem* itemCandidate = childAt(i);
       
   487         QModelIndex modelIndex = m_model->indexFromItem(itemCandidate);
       
   488         if (signalSender == m_helper.widgetFromModelIndex(modelIndex)) {
       
   489             m_clickedBarringItem = static_cast<CpSettingFormItemData*>(itemCandidate);
       
   490         }
       
   491     }
       
   492     
       
   493     if (NULL != m_clickedBarringItem) {
       
   494         QString barringPasswordQueryDialogTitle(
       
   495             hbTrId("txt_phone_info_barring_password"));
       
   496         
       
   497         QObject::connect(
       
   498             m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   499             this, SLOT(completeBarringStateChangeRequestHandling(QString, bool)));
       
   500         m_phoneNotes->showPasswordQueryDialog(
       
   501             barringPasswordQueryDialogTitle, *m_barringPasswordValidator,
       
   502             KMaxPasswordLength);
       
   503     }
       
   504     
       
   505     DPRINT << ": OUT";
       
   506 }
       
   507 
       
   508 /*!
       
   509   CpBarringPluginGroup::completeBarringStateChangeRequestHandling.
       
   510  */
       
   511 void CpBarringPluginGroup::completeBarringStateChangeRequestHandling(
       
   512         QString barringPassword,
       
   513         bool okPressed)
       
   514 {
       
   515     DPRINT << ": IN";
       
   516     
       
   517 	QObject::disconnect(
       
   518         m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   519         this, SLOT(completeBarringStateChangeRequestHandling(QString, bool)));
       
   520     if (okPressed) {
       
   521         QVariant checkState = m_clickedBarringItem->contentWidgetData("checkState");
       
   522         if (Qt::Checked == checkState.toInt()) {
       
   523             m_barringWrapper->enableBarring(
       
   524                 ServiceGroupVoice,
       
   525                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   526                     m_clickedBarringItem->property("barringType")), 
       
   527                 barringPassword);
       
   528         } else {
       
   529             m_barringWrapper->disableBarring(
       
   530                 ServiceGroupVoice,
       
   531                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   532                     m_clickedBarringItem->property("barringType")), 
       
   533                 barringPassword);
       
   534         }
       
   535         
       
   536         m_barringRequestQueue.enqueue(m_clickedBarringItem);
       
   537         m_phoneNotes->showGlobalProgressNote(
       
   538             m_activeNoteId, hbTrId("txt_phone_info_requesting"));
       
   539     } else {
       
   540         revertCheckStateOfItem(m_clickedBarringItem);
       
   541     }
       
   542     m_clickedBarringItem = NULL;
       
   543         
       
   544     DPRINT << ": OUT";
       
   545 }
       
   546 
       
   547 /*!
       
   548   CpBarringPluginGroup::changeBarringPasswordRequested.
       
   549  */
       
   550 void CpBarringPluginGroup::changeBarringPasswordRequested(bool checked)
       
   551 {
       
   552     DPRINT << ": IN";
       
   553     Q_UNUSED(checked)
       
   554     
       
   555     m_changeBarringPasswordPhase = CurrentPasswordPhase;
       
   556     QString currentPasswordQueryDialogTitle(
       
   557         hbTrId("txt_phone_info_current_password"));
       
   558     QObject::connect(
       
   559         m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   560         this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
       
   561     m_phoneNotes->showPasswordQueryDialog(
       
   562         currentPasswordQueryDialogTitle, 
       
   563         *m_barringPasswordValidator, 
       
   564         KMaxPasswordLength);
       
   565     
       
   566     DPRINT << ": OUT";
       
   567 }
       
   568 
       
   569 /*!
       
   570   CpBarringPluginGroup::changeBarringPasswordPhasesHandling.
       
   571  */
       
   572 void CpBarringPluginGroup::changeBarringPasswordPhasesHandling(
       
   573         QString barringPassword,
       
   574         bool okPressed)
       
   575 {
       
   576     DPRINT << ": IN";
       
   577         
       
   578     if (okPressed) {
       
   579         switch (m_changeBarringPasswordPhase) {
       
   580             case CurrentPasswordPhase: {
       
   581                 m_changeBarringPasswordPhase = NewPasswordPhase;
       
   582                 m_currentPassword = barringPassword;
       
   583                 QString newPasswordQueryDialogTitle(
       
   584                     hbTrId("txt_phone_info_new_password"));
       
   585                 m_phoneNotes->showPasswordQueryDialog(
       
   586                     newPasswordQueryDialogTitle, 
       
   587                     *m_barringPasswordValidator,
       
   588                     KMaxPasswordLength);
       
   589                 }
       
   590                 break; 
       
   591             case NewPasswordPhase: {
       
   592                 m_changeBarringPasswordPhase = VerifyNewPasswordPhase;
       
   593                 m_newPassword = barringPassword;
       
   594                 QString newPasswordVerifyDialogTitle(
       
   595                     hbTrId("txt_phone_info_verify_new_password"));
       
   596                 QRegExp regExpression(m_newPassword);
       
   597                 if(m_verifyPasswordValidator) {
       
   598                     delete m_verifyPasswordValidator;
       
   599                     m_verifyPasswordValidator = NULL;
       
   600                 }
       
   601                 m_verifyPasswordValidator = new QRegExpValidator(regExpression, NULL);
       
   602                 m_phoneNotes->showPasswordQueryDialog(
       
   603                     newPasswordVerifyDialogTitle, 
       
   604                     *m_verifyPasswordValidator,
       
   605                     KMaxPasswordLength);
       
   606                 }
       
   607                 break; 
       
   608             case VerifyNewPasswordPhase: {
       
   609                 m_changeBarringPasswordPhase = NonePhase;
       
   610                 m_newPasswordVerified = barringPassword;
       
   611                 m_barringWrapper->changeBarringPassword(
       
   612                     m_currentPassword,
       
   613                     m_newPassword,
       
   614                     m_newPasswordVerified);
       
   615                 m_phoneNotes->showGlobalProgressNote(
       
   616                     m_activeNoteId, 
       
   617                     hbTrId("txt_phone_info_requesting"));
       
   618                 QObject::disconnect(
       
   619                     m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   620                     this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
       
   621                 }
       
   622                 break;
       
   623             default: 
       
   624                 DPRINT << "Error: unknown enum value";
       
   625                 break; 
       
   626         }
       
   627     }
       
   628     else {
       
   629         QObject::disconnect(
       
   630             m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   631             this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
       
   632         m_changeBarringPasswordPhase = NonePhase;
       
   633     }
       
   634         
       
   635     DPRINT << ": OUT";
       
   636 }
       
   637 
       
   638 
       
   639 /*!
       
   640   CpBarringPluginGroup::updateDependentBarringProgramStatuses.
       
   641   According to the ETSI TS 100 548 v7.0.0 specification only one outgoing 
       
   642   and one incoming barring program can be active at the same time. We must,
       
   643   however, query barring statuses again because some networks do not conform
       
   644   to the standards and allow multiple simultaneous barring programs.
       
   645  */
       
   646 bool CpBarringPluginGroup::updateDependentBarringProgramStatuses(
       
   647     const CpSettingFormItemData &changedBarringItem)
       
   648 {
       
   649     DPRINT << ": IN";
       
   650     
       
   651     CpSettingFormItemData* barringItem = NULL;
       
   652     PSetCallBarringWrapper::BarringType barringType =
       
   653         qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   654             changedBarringItem.property("barringType"));
       
   655     QList<CpSettingFormItemData*> itemCandidatesForUpdate;
       
   656     switch (barringType) {
       
   657         case PSetCallBarringWrapper::BarringTypeAllOutgoing:
       
   658         {
       
   659             barringItem = &barringItemByProgram(
       
   660                 PSetCallBarringWrapper::BarringTypeOutgoingInternational);
       
   661             itemCandidatesForUpdate.append(barringItem);
       
   662             
       
   663             barringItem = &barringItemByProgram(
       
   664                 PSetCallBarringWrapper::
       
   665                     BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   666             itemCandidatesForUpdate.append(barringItem);
       
   667             break;
       
   668         }
       
   669         case PSetCallBarringWrapper::BarringTypeOutgoingInternational:
       
   670         {
       
   671             barringItem = &barringItemByProgram(
       
   672                 PSetCallBarringWrapper::BarringTypeAllOutgoing);
       
   673             itemCandidatesForUpdate.append(barringItem);
       
   674 
       
   675             barringItem = &barringItemByProgram(
       
   676                 PSetCallBarringWrapper::
       
   677                     BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   678             itemCandidatesForUpdate.append(barringItem);
       
   679             break;
       
   680         }
       
   681         case PSetCallBarringWrapper::
       
   682             BarringTypeOutgoingInternationalExceptToHomeCountry:
       
   683         {
       
   684             // ETSI TS 100 548 v7.0.0, 1.1.2.2. BOIC barring will be activated 
       
   685             // instead of BOIC-exHC if roamed network does not suport BOIC-exHC
       
   686             // => we must update statuses for all outgoing barring programs. 
       
   687             barringItem = &barringItemByProgram(
       
   688                 PSetCallBarringWrapper::BarringTypeAllOutgoing);
       
   689             itemCandidatesForUpdate.append(barringItem);
       
   690 
       
   691             barringItem = &barringItemByProgram(
       
   692                 PSetCallBarringWrapper::BarringTypeOutgoingInternational);
       
   693             itemCandidatesForUpdate.append(barringItem);
       
   694             
       
   695             barringItem = &barringItemByProgram(
       
   696                 PSetCallBarringWrapper::
       
   697                     BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   698             itemCandidatesForUpdate.append(barringItem);
       
   699             break;
       
   700         }
       
   701         case PSetCallBarringWrapper::BarringTypeAllIncoming:
       
   702         {
       
   703             barringItem = &barringItemByProgram(
       
   704                 PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming);
       
   705             itemCandidatesForUpdate.append(barringItem);
       
   706             break;
       
   707         }
       
   708         case PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming:
       
   709         {
       
   710             barringItem = &barringItemByProgram(
       
   711                 PSetCallBarringWrapper::BarringTypeAllIncoming);
       
   712             itemCandidatesForUpdate.append(barringItem);
       
   713             break;
       
   714         }
       
   715         default:
       
   716             break;
       
   717     }
       
   718     
       
   719     const int numOfItemCandidates = itemCandidatesForUpdate.count();
       
   720     for (int i = 0; i < numOfItemCandidates; i++) {
       
   721         barringItem = itemCandidatesForUpdate[i];
       
   722         Qt::CheckState checkState = static_cast<Qt::CheckState>
       
   723             (barringItem->contentWidgetData("checkState").toInt());
       
   724         if (Qt::Checked == checkState || 
       
   725             PSetCallBarringWrapper::
       
   726                 BarringTypeOutgoingInternationalExceptToHomeCountry 
       
   727                     == barringType) {
       
   728             m_barringRequestQueue.enqueue(barringItem);
       
   729         }
       
   730     }
       
   731     
       
   732     processBarringStatusRequestQueue();
       
   733     DPRINT << ": OUT";
       
   734     return (0 < m_barringRequestQueue.count());
       
   735 }
       
   736 
       
   737 
       
   738 /*!
       
   739   CpBarringPluginGroup::barringItemByProgram.
       
   740  */
       
   741 CpSettingFormItemData &CpBarringPluginGroup::barringItemByProgram(
       
   742     const PSetCallBarringWrapper::BarringType &barringProgram)
       
   743 {
       
   744     DPRINT << ": IN";
       
   745     
       
   746     CpSettingFormItemData *item = NULL;
       
   747     int numOfChilds = childCount();
       
   748     for (int childInd = 0; (childInd < numOfChilds) && (!item); childInd++) {
       
   749         CpSettingFormItemData *itemCandidate = 
       
   750             static_cast<CpSettingFormItemData*>(childAt(childInd));
       
   751         PSetCallBarringWrapper::BarringType candidateBarringProgram =
       
   752             qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   753                 itemCandidate->property("barringType"));
       
   754         if (candidateBarringProgram == barringProgram) {
       
   755             item = itemCandidate;
       
   756         }
       
   757     }
       
   758     
       
   759     Q_ASSERT(item);
       
   760     DPRINT << ": OUT";
       
   761     return *item;
       
   762 }
       
   763 
       
   764 
       
   765 /*!
       
   766   CpBarringPluginGroup::revertCheckStateOfItem.
       
   767  */
       
   768 void CpBarringPluginGroup::revertCheckStateOfItem(
       
   769     CpSettingFormItemData *barringItem)
       
   770 {
       
   771     DPRINT << ": IN";
       
   772     
       
   773     Qt::CheckState currentCheckState = static_cast<Qt::CheckState>
       
   774         (barringItem->contentWidgetData("checkState").toInt());
       
   775     Qt::CheckState revertedCheckState = 
       
   776         (currentCheckState == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
       
   777     updateCheckStateOfItem(*barringItem, revertedCheckState);
       
   778     
       
   779     DPRINT << ": OUT";
       
   780 }
       
   781 
       
   782 
       
   783 /*!
       
   784   CpBarringPluginGroup::updateCheckStateOfItem.
       
   785  */
       
   786 void CpBarringPluginGroup::updateCheckStateOfItem(
       
   787     CpSettingFormItemData &barringItem, const Qt::CheckState &newState)
       
   788 {
       
   789     DPRINT << ": IN";
       
   790     
       
   791     m_helper.removeConnection(
       
   792         &barringItem, SIGNAL(stateChanged(int)),
       
   793         this, SLOT(changeBarringStateRequested(int)));
       
   794     
       
   795     barringItem.setContentWidgetData("checkState", QVariant(newState));
       
   796     
       
   797     m_helper.addConnection(
       
   798         &barringItem, SIGNAL(stateChanged(int)),
       
   799         this, SLOT(changeBarringStateRequested(int)));
       
   800     
       
   801     DPRINT << ": OUT";
       
   802 }
       
   803 
       
   804 // End of File.