phonesettings/cpphonesettingsplugins/barringplugin/src/cpbarringplugingroup.cpp
branchRCL_3
changeset 61 41a7f70b3818
equal deleted inserted replaced
58:40a3f856b14d 61:41a7f70b3818
       
     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 <psuinotes.h>
       
    27 #include "cpbarringplugingroup.h"
       
    28 #include "cpplugincommon.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 = PsUiNotes::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->contentWidgetData("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->setContentWidgetData("barringType", value);
       
   274     
       
   275     DPRINT << ": OUT";
       
   276     return barringItem.take();
       
   277 }
       
   278 
       
   279 
       
   280 /*!
       
   281   CpBarringPluginGroup::barringStatusRequestCompleted.
       
   282  */
       
   283 void CpBarringPluginGroup::barringStatusRequestCompleted(
       
   284     int result,
       
   285     const QList<unsigned char> &basicServiceGroupIds,
       
   286     PSetCallBarringWrapper::BarringStatus status)
       
   287 {
       
   288     DPRINT << ": IN" << ": result:" << result << "status:" << status;
       
   289     Q_UNUSED(result)
       
   290     Q_UNUSED(basicServiceGroupIds)
       
   291     
       
   292     m_barringStatusRequestOngoing = false;
       
   293     
       
   294     if (PSetCallBarringWrapper::BarringErrorNone != result) {
       
   295         // Stop status query process for this time. Statuses are tried to 
       
   296         // query again for uncompleted items when user expands/opens barring 
       
   297         // settings group again.
       
   298         m_phoneNotes->cancelNote(m_activeNoteId);
       
   299         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   300         m_barringRequestQueue.clear();
       
   301         return;
       
   302     }
       
   303 
       
   304     if (!m_barringRequestQueue.isEmpty()) {
       
   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->showNotificationDialog(hbTrId("txt_phone_info_barring_activated"));
       
   330         }
       
   331         
       
   332         // Password editing is enabled only after all barring statuses are 
       
   333         // queried. Otherwise user may be able to issue two requests 
       
   334         // simultaneously by hiding status query progress note and clicking 
       
   335         // edit password.
       
   336         if (!m_editBarringPasswordItem->isEnabled()) {
       
   337             m_editBarringPasswordItem->setEnabled(true);
       
   338             m_helper.addConnection(
       
   339                 m_editBarringPasswordItem, SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),
       
   340                 this, SLOT(changeBarringPasswordRequested()));
       
   341         }
       
   342     } else {
       
   343         processBarringStatusRequestQueue();
       
   344     }
       
   345     
       
   346     DPRINT << ": OUT";
       
   347 }
       
   348 
       
   349 
       
   350 /*!
       
   351   CpBarringPluginGroup::enableBarringRequestCompleted.
       
   352  */
       
   353 void CpBarringPluginGroup::enableBarringRequestCompleted(
       
   354     int result,
       
   355     PSetCallBarringWrapper::BarringType barringType,
       
   356     PSetCallBarringWrapper::BarringStatus barringStatus, 
       
   357     bool plural)
       
   358 {
       
   359     DPRINT << ": IN: result:" << result << "barringType:" << barringType 
       
   360         << "barringStatus:" << barringStatus << "plural:" << plural;
       
   361     Q_UNUSED(barringType)
       
   362     Q_UNUSED(barringStatus)
       
   363     Q_UNUSED(plural)
       
   364     
       
   365     if (!m_barringRequestQueue.isEmpty()) {
       
   366         CpSettingFormItemData *barringItem = m_barringRequestQueue.dequeue();
       
   367         if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   368             if (updateDependentBarringProgramStatuses(*barringItem)) {
       
   369                 // Indicate barring activation completion only when dependent 
       
   370                 // barring items are also updated.
       
   371                 m_delayedBarringActivationNote = true;
       
   372             } else {
       
   373                 m_phoneNotes->cancelNote(m_activeNoteId);
       
   374                 m_phoneNotes->showNotificationDialog(hbTrId("txt_phone_info_barring_activated"));
       
   375             }
       
   376         } else {
       
   377             revertCheckStateOfItem(barringItem);
       
   378         
       
   379             m_phoneNotes->cancelNote(m_activeNoteId);
       
   380             m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   381         }
       
   382     }
       
   383     
       
   384     DPRINT << ": OUT";
       
   385 }
       
   386 
       
   387 
       
   388 /*!
       
   389   CpBarringPluginGroup::disableBarringRequestCompleted.
       
   390  */
       
   391 void CpBarringPluginGroup::disableBarringRequestCompleted(
       
   392     int result,
       
   393     PSetCallBarringWrapper::BarringType barringType,
       
   394     PSetCallBarringWrapper::BarringStatus barringStatus, 
       
   395     bool plural)
       
   396 {
       
   397     DPRINT << ": IN: result:" << result << "barringType:" << barringType 
       
   398         << "barringStatus:" << barringStatus << "plural:" << plural;
       
   399     Q_UNUSED(barringType)
       
   400     Q_UNUSED(barringStatus)
       
   401     Q_UNUSED(plural)
       
   402     
       
   403     m_phoneNotes->cancelNote(m_activeNoteId);
       
   404     
       
   405     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   406         m_phoneNotes->showNotificationDialog(hbTrId("txt_phone_info_barring_deactivated"));
       
   407     } else {
       
   408         if (!m_barringRequestQueue.isEmpty()) {
       
   409             CpSettingFormItemData *barringItem = m_barringRequestQueue.dequeue();
       
   410             revertCheckStateOfItem(barringItem);
       
   411         }
       
   412         
       
   413         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   414     }
       
   415     
       
   416     DPRINT << ": OUT";
       
   417 }
       
   418 
       
   419 
       
   420 /*!
       
   421   CpBarringPluginGroup::barringPasswordChangeRequestCompleted.
       
   422  */
       
   423 void CpBarringPluginGroup::barringPasswordChangeRequestCompleted(int result)
       
   424 {
       
   425     DPRINT << ": IN: result:" << result;
       
   426     
       
   427     m_phoneNotes->cancelNote(m_activeNoteId);
       
   428     
       
   429     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   430         m_phoneNotes->showNotificationDialog(hbTrId("txt_phone_info_password_changed"));
       
   431     } else {
       
   432         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   433     }
       
   434 }
       
   435 
       
   436 
       
   437 /*!
       
   438   CpBarringPluginGroup::processBarringStatusRequestQueue.
       
   439  */
       
   440 void CpBarringPluginGroup::processBarringStatusRequestQueue()
       
   441 {
       
   442     DPRINT << ": IN";
       
   443     
       
   444     if ((m_barringStatusRequestOngoing == false) && 
       
   445         (!m_barringRequestQueue.isEmpty())) {
       
   446         
       
   447         CpSettingFormItemData *item = m_barringRequestQueue.head();
       
   448         PSetCallBarringWrapper::BarringType barringType =
       
   449             qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   450                 item->contentWidgetData("barringType"));
       
   451         m_barringWrapper->barringStatus(ServiceGroupVoice, barringType);
       
   452         
       
   453         m_barringStatusRequestOngoing = true;
       
   454         
       
   455         if (!m_phoneNotes->noteShowing()) {
       
   456             // Launch progress note only once for status update.
       
   457             m_phoneNotes->showGlobalProgressNote(
       
   458                 m_activeNoteId, hbTrId("txt_common_info_requesting"));
       
   459         }
       
   460     }
       
   461     
       
   462     DPRINT << ": OUT";
       
   463 }
       
   464 
       
   465 
       
   466 /*!
       
   467   CpBarringPluginGroup::changeBarringStateRequested.
       
   468  */
       
   469 void CpBarringPluginGroup::changeBarringStateRequested(int checkState)
       
   470 {
       
   471     DPRINT << ": IN";
       
   472     Q_UNUSED(checkState)
       
   473     // find form item for which user has requested barring status change
       
   474     QObject *signalSender = sender();
       
   475         
       
   476     int numOfChilds = childCount();
       
   477     for (int i = 0; (i < numOfChilds) && (m_clickedBarringItem == NULL); i++) {
       
   478         HbDataFormModelItem* itemCandidate = childAt(i);
       
   479         QModelIndex modelIndex = m_model->indexFromItem(itemCandidate);
       
   480         if (signalSender == m_helper.widgetFromModelIndex(modelIndex)) {
       
   481             m_clickedBarringItem = static_cast<CpSettingFormItemData*>(itemCandidate);
       
   482         }
       
   483     }
       
   484     
       
   485     if (NULL != m_clickedBarringItem) {
       
   486         QString barringPasswordQueryDialogTitle(
       
   487             hbTrId("txt_phone_info_barring_password"));
       
   488         
       
   489         QObject::connect(
       
   490             m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   491             this, SLOT(completeBarringStateChangeRequestHandling(QString, bool)));
       
   492         m_phoneNotes->showPasswordQueryDialog(
       
   493             barringPasswordQueryDialogTitle, *m_barringPasswordValidator,
       
   494             KMaxPasswordLength);
       
   495     }
       
   496     
       
   497     DPRINT << ": OUT";
       
   498 }
       
   499 
       
   500 /*!
       
   501   CpBarringPluginGroup::completeBarringStateChangeRequestHandling.
       
   502  */
       
   503 void CpBarringPluginGroup::completeBarringStateChangeRequestHandling(
       
   504         QString barringPassword,
       
   505         bool okPressed)
       
   506 {
       
   507     DPRINT << ": IN";
       
   508     
       
   509 	QObject::disconnect(
       
   510         m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   511         this, SLOT(completeBarringStateChangeRequestHandling(QString, bool)));
       
   512     if (okPressed && m_clickedBarringItem) {
       
   513         QVariant checkState = m_clickedBarringItem->contentWidgetData("checkState");
       
   514         if (Qt::Checked == checkState.toInt()) {
       
   515             m_barringWrapper->enableBarring(
       
   516                 ServiceGroupVoice,
       
   517                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   518                     m_clickedBarringItem->contentWidgetData("barringType")),
       
   519                 barringPassword);
       
   520         } else {
       
   521             m_barringWrapper->disableBarring(
       
   522                 ServiceGroupVoice,
       
   523                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   524                     m_clickedBarringItem->contentWidgetData("barringType")),
       
   525                 barringPassword);
       
   526         }
       
   527         
       
   528         m_barringRequestQueue.enqueue(m_clickedBarringItem);
       
   529         m_phoneNotes->showGlobalProgressNote(
       
   530             m_activeNoteId, hbTrId("txt_common_info_requesting"));
       
   531     } else if (m_clickedBarringItem) {
       
   532         revertCheckStateOfItem(m_clickedBarringItem);
       
   533     }
       
   534     m_clickedBarringItem = NULL;
       
   535         
       
   536     DPRINT << ": OUT";
       
   537 }
       
   538 
       
   539 /*!
       
   540   CpBarringPluginGroup::changeBarringPasswordRequested.
       
   541  */
       
   542 void CpBarringPluginGroup::changeBarringPasswordRequested()
       
   543 {
       
   544     DPRINT << ": IN";
       
   545     
       
   546     m_changeBarringPasswordPhase = CurrentPasswordPhase;
       
   547     QString currentPasswordQueryDialogTitle(
       
   548         hbTrId("txt_phone_info_current_password"));
       
   549     QObject::connect(
       
   550         m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   551         this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
       
   552     m_phoneNotes->showPasswordQueryDialog(
       
   553         currentPasswordQueryDialogTitle, 
       
   554         *m_barringPasswordValidator, 
       
   555         KMaxPasswordLength);
       
   556     
       
   557     DPRINT << ": OUT";
       
   558 }
       
   559 
       
   560 /*!
       
   561   CpBarringPluginGroup::changeBarringPasswordPhasesHandling.
       
   562  */
       
   563 void CpBarringPluginGroup::changeBarringPasswordPhasesHandling(
       
   564         QString barringPassword,
       
   565         bool okPressed)
       
   566 {
       
   567     DPRINT << ": IN";
       
   568         
       
   569     if (okPressed) {
       
   570         switch (m_changeBarringPasswordPhase) {
       
   571             case CurrentPasswordPhase: {
       
   572                 m_changeBarringPasswordPhase = NewPasswordPhase;
       
   573                 m_currentPassword = barringPassword;
       
   574                 QString newPasswordQueryDialogTitle(
       
   575                     hbTrId("txt_phone_info_new_password"));
       
   576                 m_phoneNotes->showPasswordQueryDialog(
       
   577                     newPasswordQueryDialogTitle, 
       
   578                     *m_barringPasswordValidator,
       
   579                     KMaxPasswordLength);
       
   580                 }
       
   581                 break; 
       
   582             case NewPasswordPhase: {
       
   583                 m_changeBarringPasswordPhase = VerifyNewPasswordPhase;
       
   584                 m_newPassword = barringPassword;
       
   585                 QString newPasswordVerifyDialogTitle(
       
   586                     hbTrId("txt_phone_info_verify_new_password"));
       
   587                 QRegExp regExpression(m_newPassword);
       
   588                 if(m_verifyPasswordValidator) {
       
   589                     delete m_verifyPasswordValidator;
       
   590                     m_verifyPasswordValidator = NULL;
       
   591                 }
       
   592                 m_verifyPasswordValidator = new QRegExpValidator(regExpression, NULL);
       
   593                 m_phoneNotes->showPasswordQueryDialog(
       
   594                     newPasswordVerifyDialogTitle, 
       
   595                     *m_verifyPasswordValidator,
       
   596                     KMaxPasswordLength);
       
   597                 }
       
   598                 break; 
       
   599             case VerifyNewPasswordPhase: {
       
   600                 m_changeBarringPasswordPhase = NonePhase;
       
   601                 m_newPasswordVerified = barringPassword;
       
   602                 m_barringWrapper->changeBarringPassword(
       
   603                     m_currentPassword,
       
   604                     m_newPassword,
       
   605                     m_newPasswordVerified);
       
   606                 m_phoneNotes->showGlobalProgressNote(
       
   607                     m_activeNoteId, 
       
   608                     hbTrId("txt_common_info_requesting"));
       
   609                 QObject::disconnect(
       
   610                     m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   611                     this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
       
   612                 }
       
   613                 break;
       
   614             default: 
       
   615                 DPRINT << "Error: unknown enum value";
       
   616                 break; 
       
   617         }
       
   618     }
       
   619     else {
       
   620         QObject::disconnect(
       
   621             m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   622             this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
       
   623         m_changeBarringPasswordPhase = NonePhase;
       
   624     }
       
   625         
       
   626     DPRINT << ": OUT";
       
   627 }
       
   628 
       
   629 
       
   630 /*!
       
   631   CpBarringPluginGroup::updateDependentBarringProgramStatuses.
       
   632   According to the ETSI TS 100 548 v7.0.0 specification only one outgoing 
       
   633   and one incoming barring program can be active at the same time. We must,
       
   634   however, query barring statuses again because some networks do not conform
       
   635   to the standards and allow multiple simultaneous barring programs.
       
   636  */
       
   637 bool CpBarringPluginGroup::updateDependentBarringProgramStatuses(
       
   638     const CpSettingFormItemData &changedBarringItem)
       
   639 {
       
   640     DPRINT << ": IN";
       
   641     
       
   642     CpSettingFormItemData* barringItem = NULL;
       
   643     PSetCallBarringWrapper::BarringType barringType =
       
   644         qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   645             changedBarringItem.contentWidgetData("barringType"));
       
   646     QList<CpSettingFormItemData*> itemCandidatesForUpdate;
       
   647     switch (barringType) {
       
   648         case PSetCallBarringWrapper::BarringTypeAllOutgoing:
       
   649         {
       
   650             barringItem = &barringItemByProgram(
       
   651                 PSetCallBarringWrapper::BarringTypeOutgoingInternational);
       
   652             itemCandidatesForUpdate.append(barringItem);
       
   653             
       
   654             barringItem = &barringItemByProgram(
       
   655                 PSetCallBarringWrapper::
       
   656                     BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   657             itemCandidatesForUpdate.append(barringItem);
       
   658             break;
       
   659         }
       
   660         case PSetCallBarringWrapper::BarringTypeOutgoingInternational:
       
   661         {
       
   662             barringItem = &barringItemByProgram(
       
   663                 PSetCallBarringWrapper::BarringTypeAllOutgoing);
       
   664             itemCandidatesForUpdate.append(barringItem);
       
   665 
       
   666             barringItem = &barringItemByProgram(
       
   667                 PSetCallBarringWrapper::
       
   668                     BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   669             itemCandidatesForUpdate.append(barringItem);
       
   670             break;
       
   671         }
       
   672         case PSetCallBarringWrapper::
       
   673             BarringTypeOutgoingInternationalExceptToHomeCountry:
       
   674         {
       
   675             // ETSI TS 100 548 v7.0.0, 1.1.2.2. BOIC barring will be activated 
       
   676             // instead of BOIC-exHC if roamed network does not suport BOIC-exHC
       
   677             // => we must update statuses for all outgoing barring programs. 
       
   678             barringItem = &barringItemByProgram(
       
   679                 PSetCallBarringWrapper::BarringTypeAllOutgoing);
       
   680             itemCandidatesForUpdate.append(barringItem);
       
   681 
       
   682             barringItem = &barringItemByProgram(
       
   683                 PSetCallBarringWrapper::BarringTypeOutgoingInternational);
       
   684             itemCandidatesForUpdate.append(barringItem);
       
   685             
       
   686             barringItem = &barringItemByProgram(
       
   687                 PSetCallBarringWrapper::
       
   688                     BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   689             itemCandidatesForUpdate.append(barringItem);
       
   690             break;
       
   691         }
       
   692         case PSetCallBarringWrapper::BarringTypeAllIncoming:
       
   693         {
       
   694             barringItem = &barringItemByProgram(
       
   695                 PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming);
       
   696             itemCandidatesForUpdate.append(barringItem);
       
   697             break;
       
   698         }
       
   699         case PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming:
       
   700         {
       
   701             barringItem = &barringItemByProgram(
       
   702                 PSetCallBarringWrapper::BarringTypeAllIncoming);
       
   703             itemCandidatesForUpdate.append(barringItem);
       
   704             break;
       
   705         }
       
   706         default:
       
   707             break;
       
   708     }
       
   709     
       
   710     const int numOfItemCandidates = itemCandidatesForUpdate.count();
       
   711     for (int i = 0; i < numOfItemCandidates; i++) {
       
   712         barringItem = itemCandidatesForUpdate[i];
       
   713         Qt::CheckState checkState = static_cast<Qt::CheckState>
       
   714             (barringItem->contentWidgetData("checkState").toInt());
       
   715         if (Qt::Checked == checkState || 
       
   716             PSetCallBarringWrapper::
       
   717                 BarringTypeOutgoingInternationalExceptToHomeCountry 
       
   718                     == barringType) {
       
   719             m_barringRequestQueue.enqueue(barringItem);
       
   720         }
       
   721     }
       
   722     
       
   723     processBarringStatusRequestQueue();
       
   724     DPRINT << ": OUT";
       
   725     return (0 < m_barringRequestQueue.count());
       
   726 }
       
   727 
       
   728 
       
   729 /*!
       
   730   CpBarringPluginGroup::barringItemByProgram.
       
   731  */
       
   732 CpSettingFormItemData &CpBarringPluginGroup::barringItemByProgram(
       
   733     const PSetCallBarringWrapper::BarringType &barringProgram)
       
   734 {
       
   735     DPRINT << ": IN";
       
   736     
       
   737     CpSettingFormItemData *item = NULL;
       
   738     int numOfChilds = childCount();
       
   739     for (int childInd = 0; (childInd < numOfChilds) && (!item); childInd++) {
       
   740         CpSettingFormItemData *itemCandidate = 
       
   741             static_cast<CpSettingFormItemData*>(childAt(childInd));
       
   742         PSetCallBarringWrapper::BarringType candidateBarringProgram =
       
   743             qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   744                 itemCandidate->contentWidgetData("barringType"));
       
   745         if (candidateBarringProgram == barringProgram) {
       
   746             item = itemCandidate;
       
   747         }
       
   748     }
       
   749     
       
   750     Q_ASSERT(item);
       
   751     DPRINT << ": OUT";
       
   752     return *item;
       
   753 }
       
   754 
       
   755 
       
   756 /*!
       
   757   CpBarringPluginGroup::revertCheckStateOfItem.
       
   758  */
       
   759 void CpBarringPluginGroup::revertCheckStateOfItem(
       
   760     CpSettingFormItemData *barringItem)
       
   761 {
       
   762     DPRINT << ": IN";
       
   763     
       
   764     Qt::CheckState currentCheckState = static_cast<Qt::CheckState>
       
   765         (barringItem->contentWidgetData("checkState").toInt());
       
   766     Qt::CheckState revertedCheckState = 
       
   767         (currentCheckState == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
       
   768     updateCheckStateOfItem(*barringItem, revertedCheckState);
       
   769     
       
   770     DPRINT << ": OUT";
       
   771 }
       
   772 
       
   773 
       
   774 /*!
       
   775   CpBarringPluginGroup::updateCheckStateOfItem.
       
   776  */
       
   777 void CpBarringPluginGroup::updateCheckStateOfItem(
       
   778     CpSettingFormItemData &barringItem, const Qt::CheckState &newState)
       
   779 {
       
   780     DPRINT << ": IN";
       
   781     
       
   782     m_helper.removeConnection(
       
   783         &barringItem, SIGNAL(stateChanged(int)),
       
   784         this, SLOT(changeBarringStateRequested(int)));
       
   785     
       
   786     barringItem.setContentWidgetData("checkState", QVariant(newState));
       
   787     
       
   788     m_helper.addConnection(
       
   789         &barringItem, SIGNAL(stateChanged(int)),
       
   790         this, SLOT(changeBarringStateRequested(int)));
       
   791     
       
   792     DPRINT << ": OUT";
       
   793 }
       
   794 
       
   795 // End of File.