phonesettings/cpphonesettingsplugins/barringplugin/src/cpbarringplugingroup.cpp
changeset 30 ebdbd102c78a
parent 27 2f8f8080a020
child 51 f39ed5e045e0
equal deleted inserted replaced
27:2f8f8080a020 30:ebdbd102c78a
    16  */
    16  */
    17 
    17 
    18 #include <hbdataformmodel.h>
    18 #include <hbdataformmodel.h>
    19 #include <hbdataformmodelitem.h>
    19 #include <hbdataformmodelitem.h>
    20 #include <HbCheckBox>
    20 #include <HbCheckBox>
    21 #include <QTranslator>
       
    22 #include <QLocale>
       
    23 #include <QApplication>
       
    24 #include <QTimer>
    21 #include <QTimer>
    25 #include <QValidator>
    22 #include <QValidator>
    26 #include <cpitemdatahelper.h>
    23 #include <cpitemdatahelper.h>
    27 #include <psetwrapper.h>
    24 #include <psetwrapper.h>
    28 #include <psetcallbarringwrapper.h>
    25 #include <psetcallbarringwrapper.h>
    42     :
    39     :
    43     CpSettingFormItemData(
    40     CpSettingFormItemData(
    44         HbDataFormModelItem::GroupItem, 
    41         HbDataFormModelItem::GroupItem, 
    45         hbTrId("txt_phone_subhead_call_barring"), 0),
    42         hbTrId("txt_phone_subhead_call_barring"), 0),
    46     m_helper(helper),
    43     m_helper(helper),
    47     m_translator(0),
       
    48     m_pSetWrapper(0),
    44     m_pSetWrapper(0),
    49     m_barringWrapper(0),
    45     m_barringWrapper(0),
    50     m_editBarringPasswordItem(0),
    46     m_editBarringPasswordItem(0),
    51     m_barringStatusRequestOngoing(false),
    47     m_barringStatusRequestOngoing(false),
    52     m_activeNoteId(0),
    48     m_activeNoteId(0),
    53     m_phoneNotes(0),
    49     m_phoneNotes(0),
    54     m_barringPasswordValidator(0),
    50     m_barringPasswordValidator(0),
    55     m_delayedBarringActivationNote(false)
    51     m_delayedBarringActivationNote(false),
       
    52     m_clickedBarringItem(NULL),
       
    53     m_changeBarringPasswordPhase(NonePhase),
       
    54     m_verifyPasswordValidator(NULL),
       
    55     m_model(0)
    56 {
    56 {
    57     DPRINT << ": IN";
    57     DPRINT << ": IN";
    58     
    58     
    59     // Registration needed, because BarringType is used as a custom meta 
    59     // Registration needed, because BarringType is used as a custom meta 
    60     // information for barring items.
    60     // information for barring items.
    61     qRegisterMetaType<PSetCallBarringWrapper::BarringType>(
    61     qRegisterMetaType<PSetCallBarringWrapper::BarringType>(
    62         "PSetCallBarringWrapper::BarringType");
    62         "PSetCallBarringWrapper::BarringType");
    63     
    63     
    64     setupLocalization();
       
    65     
       
    66     m_pSetWrapper.reset(new PSetWrapper(NULL));
    64     m_pSetWrapper.reset(new PSetWrapper(NULL));
    67     m_barringWrapper = &m_pSetWrapper->callBarringWrapper(); 
    65     m_barringWrapper = &m_pSetWrapper->callBarringWrapper(); 
    68     setupConnectionsToWrapper();
    66     setupConnectionsToWrapper();
    69     
    67     
    70     // itemShown signal is used to trigger barring status query process 
    68     // itemShown signal is used to trigger barring status query process 
    88  */
    86  */
    89 CpBarringPluginGroup::~CpBarringPluginGroup()
    87 CpBarringPluginGroup::~CpBarringPluginGroup()
    90 {
    88 {
    91     DPRINT << ": IN";
    89     DPRINT << ": IN";
    92     
    90     
       
    91     if (m_verifyPasswordValidator) {
       
    92         delete m_verifyPasswordValidator;                    
       
    93     }
       
    94     
    93     DPRINT << ": OUT";
    95     DPRINT << ": OUT";
    94 }
    96 }
    95 
    97 
    96 
    98 
    97 /*!
    99 /*!
   101 {
   103 {
   102     DPRINT << ": IN";
   104     DPRINT << ": IN";
   103     
   105     
   104     CpSettingFormItemData* formItem = 
   106     CpSettingFormItemData* formItem = 
   105         static_cast<CpSettingFormItemData*>(
   107         static_cast<CpSettingFormItemData*>(
   106             qobject_cast<HbDataFormModel*>(model())->itemFromIndex(item));
   108             qobject_cast<const HbDataFormModel*>(item.model())->itemFromIndex(item));
   107     
   109     
   108     if (!formItem->property("barringType").isValid()) {
   110     if (!formItem->property("barringType").isValid()) {
   109         // Shown item does not belong to the barring settings group.
   111         // Shown item does not belong to the barring settings group.
   110         return;
   112         return;
   111         }
   113         }
   112     
   114     
       
   115     m_model = const_cast<HbDataFormModel*>(qobject_cast<const HbDataFormModel*>(item.model()));
       
   116         
   113     if (formItem == m_editBarringPasswordItem) {
   117     if (formItem == m_editBarringPasswordItem) {
   114         return;
   118         return;
   115     }
   119     }
   116     
   120     
   117     if (formItem->isEnabled()) {
   121     if (formItem->isEnabled()) {
   121     }
   125     }
   122     
   126     
   123     // start barring status query
   127     // start barring status query
   124     m_barringRequestQueue.enqueue(formItem);
   128     m_barringRequestQueue.enqueue(formItem);
   125     processBarringStatusRequestQueue();
   129     processBarringStatusRequestQueue();
   126     
       
   127     DPRINT << ": OUT";
       
   128 }
       
   129 
       
   130 
       
   131 /*!
       
   132   CpBarringPluginGroup::setupLocalization.
       
   133  */
       
   134 void CpBarringPluginGroup::setupLocalization()
       
   135 {
       
   136     DPRINT << ": IN";
       
   137     
       
   138     m_translator.reset(new QTranslator);
       
   139     QString lang = QLocale::system().name();
       
   140     QString path = "z:/resource/qt/translations/";
       
   141     QString fullName = path + "telephone_cp_" + lang;
       
   142     
       
   143     DPRINT << ": loading translation:" << fullName;
       
   144     bool translatorLoaded = m_translator->load(fullName);
       
   145     DPRINT << ": translator loaded: " << translatorLoaded; 
       
   146     
       
   147     if (translatorLoaded) {
       
   148         qApp->installTranslator(m_translator.data());
       
   149         DPRINT << ": translator installed"; 
       
   150     }
       
   151     
   130     
   152     DPRINT << ": OUT";
   131     DPRINT << ": OUT";
   153 }
   132 }
   154 
   133 
   155 
   134 
   496   CpBarringPluginGroup::changeBarringStateRequested.
   475   CpBarringPluginGroup::changeBarringStateRequested.
   497  */
   476  */
   498 void CpBarringPluginGroup::changeBarringStateRequested(int checkState)
   477 void CpBarringPluginGroup::changeBarringStateRequested(int checkState)
   499 {
   478 {
   500     DPRINT << ": IN";
   479     DPRINT << ": IN";
   501     
   480     Q_UNUSED(checkState)
   502     // find form item for which user has requested barring status change
   481     // find form item for which user has requested barring status change
   503     QObject *signalSender = sender();
   482     QObject *signalSender = sender();
   504     HbDataFormModel *formModel = qobject_cast<HbDataFormModel*>(model());
   483         
   505     CpSettingFormItemData* barringItem = NULL;
       
   506     int numOfChilds = childCount();
   484     int numOfChilds = childCount();
   507     for (int i = 0; (i < numOfChilds) && (barringItem == NULL); i++) {
   485     for (int i = 0; (i < numOfChilds) && (m_clickedBarringItem == NULL); i++) {
   508         HbDataFormModelItem* itemCandidate = childAt(i);
   486         HbDataFormModelItem* itemCandidate = childAt(i);
   509         QModelIndex modelIndex = formModel->indexFromItem(itemCandidate);
   487         QModelIndex modelIndex = m_model->indexFromItem(itemCandidate);
   510         if (signalSender == m_helper.widgetFromModelIndex(modelIndex)) {
   488         if (signalSender == m_helper.widgetFromModelIndex(modelIndex)) {
   511             barringItem = static_cast<CpSettingFormItemData*>(itemCandidate);
   489             m_clickedBarringItem = static_cast<CpSettingFormItemData*>(itemCandidate);
   512         }
   490         }
   513     }
   491     }
   514     
   492     
   515     if (NULL != barringItem) {
   493     if (NULL != m_clickedBarringItem) {
   516         QString barringPasswordQueryDialogTitle(
   494         QString barringPasswordQueryDialogTitle(
   517             hbTrId("txt_phone_info_barring_password"));
   495             hbTrId("txt_phone_info_barring_password"));
   518         QString barringPassword;
   496         
   519         bool okPressed = false;
   497         QObject::connect(
       
   498             m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   499             this, SLOT(completeBarringStateChangeRequestHandling(QString, bool)));
   520         m_phoneNotes->showPasswordQueryDialog(
   500         m_phoneNotes->showPasswordQueryDialog(
   521             barringPasswordQueryDialogTitle, *m_barringPasswordValidator,
   501             barringPasswordQueryDialogTitle, *m_barringPasswordValidator,
   522             KMaxPasswordLength, barringPassword, okPressed);
   502             KMaxPasswordLength);
   523         if (!okPressed) {
   503     }
   524             revertCheckStateOfItem(barringItem);
   504     
   525             return;
   505     DPRINT << ": OUT";
   526         }
   506 }
   527         
   507 
   528         if (Qt::Checked == checkState) {
   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()) {
   529             m_barringWrapper->enableBarring(
   523             m_barringWrapper->enableBarring(
   530                 ServiceGroupVoice,
   524                 ServiceGroupVoice,
   531                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
   525                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
   532                     barringItem->property("barringType")), 
   526                     m_clickedBarringItem->property("barringType")), 
   533                 barringPassword);
   527                 barringPassword);
   534         } else {
   528         } else {
   535             m_barringWrapper->disableBarring(
   529             m_barringWrapper->disableBarring(
   536                 ServiceGroupVoice,
   530                 ServiceGroupVoice,
   537                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
   531                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
   538                     barringItem->property("barringType")), 
   532                     m_clickedBarringItem->property("barringType")), 
   539                 barringPassword);
   533                 barringPassword);
   540         }
   534         }
   541         
   535         
   542         m_barringRequestQueue.enqueue(barringItem);
   536         m_barringRequestQueue.enqueue(m_clickedBarringItem);
   543         m_phoneNotes->showGlobalProgressNote(
   537         m_phoneNotes->showGlobalProgressNote(
   544             m_activeNoteId, hbTrId("txt_phone_info_requesting"));
   538             m_activeNoteId, hbTrId("txt_phone_info_requesting"));
   545     }
   539     } else {
   546     
   540         revertCheckStateOfItem(m_clickedBarringItem);
   547     DPRINT << ": OUT";
   541     }
   548 }
   542     m_clickedBarringItem = NULL;
   549 
   543         
       
   544     DPRINT << ": OUT";
       
   545 }
   550 
   546 
   551 /*!
   547 /*!
   552   CpBarringPluginGroup::changeBarringPasswordRequested.
   548   CpBarringPluginGroup::changeBarringPasswordRequested.
   553  */
   549  */
   554 void CpBarringPluginGroup::changeBarringPasswordRequested(bool checked)
   550 void CpBarringPluginGroup::changeBarringPasswordRequested(bool checked)
   555 {
   551 {
   556     DPRINT << ": IN";
   552     DPRINT << ": IN";
   557     Q_UNUSED(checked)
   553     Q_UNUSED(checked)
   558     
   554     
   559     bool okPressed = false;
   555     m_changeBarringPasswordPhase = CurrentPasswordPhase;
   560     
       
   561     QString currentPassword;
       
   562     QString currentPasswordQueryDialogTitle(
   556     QString currentPasswordQueryDialogTitle(
   563         hbTrId("txt_phone_info_current_password"));
   557         hbTrId("txt_phone_info_current_password"));
       
   558     QObject::connect(
       
   559         m_phoneNotes, SIGNAL(passwordQueryCompleted(QString, bool)),
       
   560         this, SLOT(changeBarringPasswordPhasesHandling(QString, bool)));
   564     m_phoneNotes->showPasswordQueryDialog(
   561     m_phoneNotes->showPasswordQueryDialog(
   565         currentPasswordQueryDialogTitle, *m_barringPasswordValidator, 
   562         currentPasswordQueryDialogTitle, 
   566         KMaxPasswordLength, currentPassword, okPressed);
   563         *m_barringPasswordValidator, 
   567     if (!okPressed) {
   564         KMaxPasswordLength);
   568         return;
   565     
   569     }
   566     DPRINT << ": OUT";
   570     
   567 }
   571     QString newPassword;
   568 
   572     QString newPasswordQueryDialogTitle(
   569 /*!
   573         hbTrId("txt_phone_info_new_password"));
   570   CpBarringPluginGroup::changeBarringPasswordPhasesHandling.
   574     m_phoneNotes->showPasswordQueryDialog(
   571  */
   575         newPasswordQueryDialogTitle, *m_barringPasswordValidator,
   572 void CpBarringPluginGroup::changeBarringPasswordPhasesHandling(
   576         KMaxPasswordLength, newPassword, okPressed);
   573         QString barringPassword,
   577     if (!okPressed) {
   574         bool okPressed)
   578         return;
   575 {
   579     }
   576     DPRINT << ": IN";
   580     
   577         
   581     QString newPasswordVerifyDialogTitle(
       
   582         hbTrId("txt_phone_info_verify_new_password"));
       
   583     QString newPasswordVerified;
       
   584     QRegExp regExpression(newPassword);
       
   585     QScopedPointer<QValidator> verifyPasswordValidator(
       
   586         new QRegExpValidator(regExpression, NULL));
       
   587     m_phoneNotes->showPasswordQueryDialog(
       
   588         newPasswordVerifyDialogTitle, *verifyPasswordValidator.data(),
       
   589         KMaxPasswordLength, newPasswordVerified, okPressed);
       
   590     
       
   591     if (okPressed) {
   578     if (okPressed) {
   592         m_barringWrapper->changeBarringPassword(
   579         switch (m_changeBarringPasswordPhase) {
   593             currentPassword,
   580             case CurrentPasswordPhase: {
   594             newPassword,
   581                 m_changeBarringPasswordPhase = NewPasswordPhase;
   595             newPasswordVerified);
   582                 m_currentPassword = barringPassword;
   596         
   583                 QString newPasswordQueryDialogTitle(
   597         m_phoneNotes->showGlobalProgressNote(
   584                     hbTrId("txt_phone_info_new_password"));
   598             m_activeNoteId, hbTrId("txt_phone_info_requesting"));
   585                 m_phoneNotes->showPasswordQueryDialog(
   599     }
   586                     newPasswordQueryDialogTitle, 
   600     
   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         
   601     DPRINT << ": OUT";
   635     DPRINT << ": OUT";
   602 }
   636 }
   603 
   637 
   604 
   638 
   605 /*!
   639 /*!
   707 CpSettingFormItemData &CpBarringPluginGroup::barringItemByProgram(
   741 CpSettingFormItemData &CpBarringPluginGroup::barringItemByProgram(
   708     const PSetCallBarringWrapper::BarringType &barringProgram)
   742     const PSetCallBarringWrapper::BarringType &barringProgram)
   709 {
   743 {
   710     DPRINT << ": IN";
   744     DPRINT << ": IN";
   711     
   745     
   712     HbDataFormModel *formModel = qobject_cast<HbDataFormModel*>(model());
       
   713     CpSettingFormItemData *item = NULL;
   746     CpSettingFormItemData *item = NULL;
   714     int numOfChilds = childCount();
   747     int numOfChilds = childCount();
   715     for (int childInd = 0; (childInd < numOfChilds) && (!item); childInd++) {
   748     for (int childInd = 0; (childInd < numOfChilds) && (!item); childInd++) {
   716         CpSettingFormItemData *itemCandidate = 
   749         CpSettingFormItemData *itemCandidate = 
   717             static_cast<CpSettingFormItemData*>(childAt(childInd));
   750             static_cast<CpSettingFormItemData*>(childAt(childInd));