phonesettings/cpphonesettingsplugins/barringplugin/src/cpbarringplugingroup.cpp
changeset 22 6bb1b21d2484
parent 21 92ab7f8d0eab
child 27 2f8f8080a020
equal deleted inserted replaced
21:92ab7f8d0eab 22:6bb1b21d2484
     1 /*
     1 /*
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13  *
    13  *
    14  * Description:  
    14  * Description:  
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <hbdataformmodel.h>
    18 #include <hbdataformmodelitem.h>
    19 #include <hbdataformmodelitem.h>
       
    20 #include <HbCheckBox>
    19 #include <QTranslator>
    21 #include <QTranslator>
    20 #include <QLocale>
    22 #include <QLocale>
    21 #include <QApplication>
    23 #include <QApplication>
       
    24 #include <QTimer>
    22 #include <cpitemdatahelper.h>
    25 #include <cpitemdatahelper.h>
       
    26 #include <psetwrapper.h>
       
    27 #include <psetcallbarringwrapper.h>
    23 #include "cpbarringplugingroup.h"
    28 #include "cpbarringplugingroup.h"
    24 #include "cpplugincommon.h"
    29 #include "cpplugincommon.h"
    25 #include "cpphonenotes.h"
    30 #include "cpphonenotes.h"
    26 #include "cppluginlogging.h"
    31 #include "cppluginlogging.h"
    27 
    32 
       
    33 Q_DECLARE_METATYPE(PSetCallBarringWrapper::BarringType)
       
    34 
       
    35 // TODO: use logical identifiers for texts
       
    36 // TODO: barring password implementation
       
    37 
    28 /*!
    38 /*!
    29   CpBarringPluginGroup::CpBarringPluginGroup.
    39   CpBarringPluginGroup::CpBarringPluginGroup.
    30  */
    40  */
    31 CpBarringPluginGroup::CpBarringPluginGroup(CpItemDataHelper &helper)
    41 CpBarringPluginGroup::CpBarringPluginGroup(CpItemDataHelper &helper)
    32      :CpSettingFormItemData(HbDataFormModelItem::GroupItem, hbTrId("Call barring"),0),
    42     :
    33        m_helper(helper)
    43     CpSettingFormItemData(
    34 {
    44         HbDataFormModelItem::GroupItem, hbTrId("Call barring"), 0),
    35     DPRINT << ": IN";
    45     m_helper(helper),
    36     
    46     m_pSetWrapper(0),
    37     // Localization file loading
    47     m_barringWrapper(0),
       
    48     m_allOutgoingBarringItem(0),
       
    49     m_outgoingInternationalBarringItem(0),
       
    50     m_outgoingInternationalExceptToHomeCountryBarringItem(0),
       
    51     m_allIncomingBarringItem(0),
       
    52     m_incomingWhenRoamingBarringItem(0),
       
    53     m_barringStatusRequestOngoing(false),
       
    54     m_activeNoteId(0),
       
    55     m_phoneNotes(NULL)
       
    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     setupLocalization();
       
    65     
       
    66     m_pSetWrapper = new PSetWrapper(this); 
       
    67     m_barringWrapper = &m_pSetWrapper->callBarringWrapper(); 
       
    68     connectToWrapper();
       
    69     
       
    70     // itemShown signal is used to trigger barring status query process 
       
    71     helper.connectToForm(
       
    72         SIGNAL(itemShown(QModelIndex)), 
       
    73         this, SLOT(itemShown(QModelIndex)));
       
    74     
       
    75     createAllOutgoingBarringItem();
       
    76     createOutgoingInternationalBarringItem();
       
    77     createOutgoingInternationalExceptToHomeCountryBarringItem();
       
    78     createAllIncomingBarringItem();
       
    79     createIncomingWhenRoamingBarringItem();
       
    80     
       
    81     m_phoneNotes = CpPhoneNotes::instance();
       
    82     
       
    83     DPRINT << ": OUT";
       
    84 }
       
    85 
       
    86 
       
    87 /*!
       
    88   CpBarringPluginGroup::~CpBarringPluginGroup.
       
    89  */
       
    90 CpBarringPluginGroup::~CpBarringPluginGroup()
       
    91 {
       
    92     DPRINT << ": IN";
       
    93     
       
    94     DPRINT << ": OUT";
       
    95 }
       
    96 
       
    97 
       
    98 /*!
       
    99   CpBarringPluginGroup::itemShown.
       
   100  */
       
   101 void CpBarringPluginGroup::itemShown(const QModelIndex& item)
       
   102 {
       
   103     DPRINT << ": IN";
       
   104     
       
   105     CpSettingFormItemData* formItem = 
       
   106         static_cast<CpSettingFormItemData*>(
       
   107             qobject_cast<HbDataFormModel*>(model())->itemFromIndex(item));
       
   108     
       
   109     if (formItem->contentWidgetData("checkState").isValid()) {
       
   110         // Initial status for the barring item is already queried. Do not 
       
   111         // start querying again if user does close/open for the barring group.
       
   112         return;
       
   113     }
       
   114     
       
   115     // start barring status query
       
   116     m_barringRequestQueue.enqueue(formItem);
       
   117     processBarringStatusRequestQueue();
       
   118 }
       
   119 
       
   120 
       
   121 /*!
       
   122   CpBarringPluginGroup::setupLocalization.
       
   123  */
       
   124 void CpBarringPluginGroup::setupLocalization()
       
   125 {
       
   126     DPRINT << ": IN";
       
   127     
    38     QTranslator translator; 
   128     QTranslator translator; 
    39     QString lang = QLocale::system().name();
   129     QString lang = QLocale::system().name();
    40     QString path = "z:/resource/qt/translations/";
   130     QString path = "z:/resource/qt/translations/";
    41     DPRINT << ": loading translation: " << QString(path + "telephone_cp_" + lang);
   131     QString fullName = path + "telephone_cp_" + lang;
    42     bool translatorLoaded = translator.load(path + "telephone_cp_" + lang);
   132     
       
   133     DPRINT << ": loading translation:" << fullName;
       
   134     bool translatorLoaded = translator.load(fullName);
    43     DPRINT << ": translator loaded: " << translatorLoaded; 
   135     DPRINT << ": translator loaded: " << translatorLoaded; 
       
   136     
    44     if (translatorLoaded) {
   137     if (translatorLoaded) {
    45         qApp->installTranslator(&translator);
   138         qApp->installTranslator(&translator);
    46         DPRINT << ": translator installed"; 
   139         DPRINT << ": translator installed"; 
    47     }
   140     }
    48     
   141 }
    49     DPRINT << ": OUT";
   142 
    50 }
   143 
    51 
   144 /*!
    52 /*!
   145   CpBarringPluginGroup::connectToWrapper.
    53   CpBarringPluginGroup::~CpBarringPluginGroup.
   146  */
    54  */
   147 void CpBarringPluginGroup::connectToWrapper()
    55 CpBarringPluginGroup::~CpBarringPluginGroup()
   148 {
    56 {
   149     DPRINT << ": IN";
    57     DPRINT << ": IN";
   150     
    58     DPRINT << ": OUT";
   151     QObject::connect(
       
   152         m_barringWrapper, 
       
   153         SIGNAL(barringStatusRequestCompleted(
       
   154             int,
       
   155             const QList<unsigned char> &, 
       
   156             PSetCallBarringWrapper::BarringStatus)
       
   157         ),
       
   158         this, 
       
   159         SLOT(barringStatusRequestCompleted(
       
   160             int,
       
   161             const QList<unsigned char> &, 
       
   162             PSetCallBarringWrapper::BarringStatus)
       
   163         )
       
   164     );
       
   165     
       
   166     QObject::connect(
       
   167         m_barringWrapper, 
       
   168         SIGNAL(enableBarringRequestCompleted(
       
   169             int,
       
   170             PSetCallBarringWrapper::BarringType,
       
   171             PSetCallBarringWrapper::BarringStatus,
       
   172             bool)
       
   173         ),
       
   174         this, 
       
   175         SLOT(enableBarringRequestCompleted(
       
   176             int,
       
   177             PSetCallBarringWrapper::BarringType,
       
   178             PSetCallBarringWrapper::BarringStatus,
       
   179             bool)
       
   180         )
       
   181     );
       
   182     
       
   183     QObject::connect(
       
   184         m_barringWrapper, 
       
   185         SIGNAL(disableBarringRequestCompleted(
       
   186             int,
       
   187             PSetCallBarringWrapper::BarringType,
       
   188             PSetCallBarringWrapper::BarringStatus,
       
   189             bool)
       
   190         ),
       
   191         this, 
       
   192         SLOT(disableBarringRequestCompleted(
       
   193             int,
       
   194             PSetCallBarringWrapper::BarringType,
       
   195             PSetCallBarringWrapper::BarringStatus,
       
   196             bool)
       
   197         )
       
   198     );
       
   199 }
       
   200 
       
   201 
       
   202 /*!
       
   203   CpBarringPluginGroup::createAllOutgoingBarringItem.
       
   204  */
       
   205 void CpBarringPluginGroup::createAllOutgoingBarringItem()
       
   206 {
       
   207     DPRINT << ": IN";
       
   208     
       
   209     m_allOutgoingBarringItem = new CpSettingFormItemData(
       
   210         HbDataFormModelItem::CheckBoxItem, hbTrId(""), this);
       
   211     
       
   212     m_allOutgoingBarringItem->setContentWidgetData(
       
   213         "text", QVariant(hbTrId("Outgoing calls")));
       
   214     
       
   215     QVariant value;
       
   216     value.setValue(PSetCallBarringWrapper::BarringTypeAllOutgoing);
       
   217     m_allOutgoingBarringItem->setProperty("barringType", value);
       
   218     
       
   219     appendChild(m_allOutgoingBarringItem);
       
   220 }
       
   221 
       
   222 
       
   223 /*!
       
   224   CpBarringPluginGroup::createOutgoingInternationalBarringItem.
       
   225  */
       
   226 void CpBarringPluginGroup::createOutgoingInternationalBarringItem()
       
   227 {
       
   228     DPRINT << ": IN";
       
   229     
       
   230     m_outgoingInternationalBarringItem = new CpSettingFormItemData(
       
   231         HbDataFormModelItem::CheckBoxItem, hbTrId(""), this);
       
   232     
       
   233     m_outgoingInternationalBarringItem->setContentWidgetData(
       
   234         "text", QVariant(hbTrId("International calls")));
       
   235     
       
   236     QVariant value;
       
   237     value.setValue(PSetCallBarringWrapper::BarringTypeOutgoingInternational);
       
   238     m_outgoingInternationalBarringItem->setProperty("barringType", value);
       
   239     
       
   240     appendChild(m_outgoingInternationalBarringItem);
       
   241 }
       
   242 
       
   243 
       
   244 /*!
       
   245   CpBarringPluginGroup::
       
   246       createOutgoingInternationalExceptToHomeCountryBarringItem.
       
   247  */
       
   248 void CpBarringPluginGroup::
       
   249     createOutgoingInternationalExceptToHomeCountryBarringItem()
       
   250 {
       
   251     DPRINT << ": IN";
       
   252     
       
   253     m_outgoingInternationalExceptToHomeCountryBarringItem = 
       
   254         new CpSettingFormItemData(
       
   255             HbDataFormModelItem::CheckBoxItem, hbTrId(""), this);
       
   256     
       
   257     m_outgoingInternationalExceptToHomeCountryBarringItem->setContentWidgetData(
       
   258         "text", QVariant(hbTrId("International calls except to home country")));
       
   259     
       
   260     QVariant value;
       
   261     value.setValue(PSetCallBarringWrapper::BarringTypeOutgoingInternationalExceptToHomeCountry);
       
   262     m_outgoingInternationalExceptToHomeCountryBarringItem->setProperty(
       
   263         "barringType", value);
       
   264     
       
   265     appendChild(m_outgoingInternationalExceptToHomeCountryBarringItem);
       
   266     
       
   267 }
       
   268 
       
   269 
       
   270 /*!
       
   271   CpBarringPluginGroup::createAllIncomingBarringItem.
       
   272  */
       
   273 void CpBarringPluginGroup::createAllIncomingBarringItem()
       
   274 {
       
   275     DPRINT << ": IN";
       
   276     
       
   277     m_allIncomingBarringItem = new CpSettingFormItemData(
       
   278         HbDataFormModelItem::CheckBoxItem, hbTrId(""), this);
       
   279     
       
   280     m_allIncomingBarringItem->setContentWidgetData(
       
   281         "text", QVariant(hbTrId("Incoming calls")));
       
   282     
       
   283     QVariant value;
       
   284     value.setValue(PSetCallBarringWrapper::BarringTypeAllIncoming);
       
   285     m_allIncomingBarringItem->setProperty("barringType", value);
       
   286     
       
   287     appendChild(m_allIncomingBarringItem);
       
   288 }
       
   289 
       
   290 
       
   291 /*!
       
   292   CpBarringPluginGroup::createIncomingWhenRoamingBarringItem.
       
   293  */
       
   294 void CpBarringPluginGroup::createIncomingWhenRoamingBarringItem()
       
   295 {
       
   296     DPRINT << ": IN";
       
   297     
       
   298     m_incomingWhenRoamingBarringItem = new CpSettingFormItemData(
       
   299         HbDataFormModelItem::CheckBoxItem, hbTrId(""), this);
       
   300     
       
   301     m_incomingWhenRoamingBarringItem->setContentWidgetData(
       
   302         "text", QVariant(hbTrId("Incoming calls when abroad")));
       
   303     
       
   304     QVariant value;
       
   305     value.setValue(PSetCallBarringWrapper::BarringTypeIncomingWhenRoaming);
       
   306     m_incomingWhenRoamingBarringItem->setProperty("barringType", value);
       
   307     
       
   308     appendChild(m_incomingWhenRoamingBarringItem);
       
   309 }
       
   310 
       
   311 
       
   312 /*!
       
   313   CpBarringPluginGroup::barringStatusRequestCompleted.
       
   314  */
       
   315 void CpBarringPluginGroup::barringStatusRequestCompleted(
       
   316     int result,
       
   317     const QList<unsigned char> & basicServiceGroupIds,
       
   318     PSetCallBarringWrapper::BarringStatus status)
       
   319 {
       
   320     DPRINT << ": IN";
       
   321     Q_UNUSED(result)
       
   322     Q_UNUSED(basicServiceGroupIds)
       
   323     
       
   324     m_barringStatusRequestOngoing = false;
       
   325     
       
   326     if (PSetCallBarringWrapper::BarringErrorNone != result) {
       
   327         // Stop status query process for this time. Statuses are tried to 
       
   328         // query again for uncompleted items when user expands/opens barring 
       
   329         // view again.
       
   330         m_phoneNotes->cancelNote(m_activeNoteId);
       
   331         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   332         m_barringRequestQueue.clear();
       
   333         return;
       
   334     }
       
   335     
       
   336     // Update check state to correct value. After setting valid value here
       
   337     // status query will not be started again for the item when user collapses
       
   338     // and expands view again.
       
   339     Qt::CheckState checkState = 
       
   340         (PSetCallBarringWrapper::BarringStatusActive == status) 
       
   341             ? Qt::Checked 
       
   342             : Qt::Unchecked;
       
   343     CpSettingFormItemData *itemForCompletedRequest = 
       
   344         m_barringRequestQueue.dequeue();
       
   345     itemForCompletedRequest->setContentWidgetData(
       
   346         "checkState", QVariant(checkState));
       
   347     
       
   348     // start to observe user initiated state changes
       
   349     m_helper.addConnection(
       
   350         itemForCompletedRequest, SIGNAL(stateChanged(int)),
       
   351         this, SLOT(changeBarringStateRequested(int)));
       
   352     
       
   353     if (m_barringRequestQueue.isEmpty()) {
       
   354         m_phoneNotes->cancelNote(m_activeNoteId);
       
   355     } else {
       
   356         processBarringStatusRequestQueue();
       
   357     }
       
   358 }
       
   359 
       
   360 
       
   361 /*!
       
   362   CpBarringPluginGroup::enableBarringRequestCompleted.
       
   363  */
       
   364 void CpBarringPluginGroup::enableBarringRequestCompleted(
       
   365     int result,
       
   366     PSetCallBarringWrapper::BarringType barringType,
       
   367     PSetCallBarringWrapper::BarringStatus barringStatus, 
       
   368     bool plural)
       
   369 {
       
   370     DPRINT << ": IN";
       
   371     Q_UNUSED(barringType)
       
   372     Q_UNUSED(barringStatus)
       
   373     Q_UNUSED(plural)
       
   374     
       
   375     m_phoneNotes->cancelNote(m_activeNoteId);
       
   376     
       
   377     CpSettingFormItemData *barringItem = m_barringRequestQueue.dequeue();
       
   378     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   379         m_phoneNotes->showGlobalNote(
       
   380             m_activeNoteId, 
       
   381             hbTrId("Barring activated"),
       
   382             HbMessageBox::MessageTypeInformation);
       
   383     } else {
       
   384         revertCheckStateForItem(barringItem);
       
   385         
       
   386         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   387     }
       
   388 }
       
   389 
       
   390 
       
   391 /*!
       
   392   CpBarringPluginGroup::disableBarringRequestCompleted.
       
   393  */
       
   394 void CpBarringPluginGroup::disableBarringRequestCompleted(
       
   395     int result,
       
   396     PSetCallBarringWrapper::BarringType barringType,
       
   397     PSetCallBarringWrapper::BarringStatus barringStatus, 
       
   398     bool plural)
       
   399 {
       
   400     DPRINT << ": IN";
       
   401     Q_UNUSED(barringType)
       
   402     Q_UNUSED(barringStatus)
       
   403     Q_UNUSED(plural)
       
   404     
       
   405     m_phoneNotes->cancelNote(m_activeNoteId);
       
   406     
       
   407     CpSettingFormItemData *barringItem = m_barringRequestQueue.dequeue();
       
   408     if (PSetCallBarringWrapper::BarringErrorNone == result) {
       
   409         m_phoneNotes->showGlobalNote(
       
   410             m_activeNoteId, 
       
   411             hbTrId("Barring cancelled"),
       
   412             HbMessageBox::MessageTypeInformation);
       
   413     } else {
       
   414         revertCheckStateForItem(barringItem);
       
   415         
       
   416         m_phoneNotes->showGlobalErrorNote(m_activeNoteId, result);
       
   417     }
       
   418 }
       
   419 
       
   420 
       
   421 /*!
       
   422   CpBarringPluginGroup::processBarringStatusRequestQueue.
       
   423  */
       
   424 void CpBarringPluginGroup::processBarringStatusRequestQueue()
       
   425 {
       
   426     DPRINT << ": IN";
       
   427 
       
   428     if ((m_barringStatusRequestOngoing == false) && 
       
   429         (!m_barringRequestQueue.isEmpty())) {
       
   430         
       
   431         CpSettingFormItemData *item = m_barringRequestQueue.head();
       
   432         PSetCallBarringWrapper::BarringType barringType =
       
   433             qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   434                 item->property("barringType"));
       
   435         m_barringWrapper->barringStatus(ServiceGroupVoice, barringType);
       
   436         
       
   437         m_barringStatusRequestOngoing = true;
       
   438         
       
   439         if (0 == m_activeNoteId) {
       
   440             // Status request note is very first note to show. Launch progress
       
   441             // note only once for status update.
       
   442             m_phoneNotes->showGlobalProgressNote(
       
   443                 m_activeNoteId, hbTrId("Requesting..."));
       
   444         }
       
   445     }
       
   446 }
       
   447 
       
   448 
       
   449 /*!
       
   450   CpBarringPluginGroup::revertCheckStateForItem.
       
   451  */
       
   452 void CpBarringPluginGroup::revertCheckStateForItem(
       
   453     CpSettingFormItemData *barringItem)
       
   454 {
       
   455     m_helper.removeConnection(
       
   456         barringItem, SIGNAL(stateChanged(int)),
       
   457         this, SLOT(changeBarringStateRequested(int)));
       
   458     
       
   459     HbDataFormModel *formModel = qobject_cast<HbDataFormModel*>(model());
       
   460     QModelIndex modelIndex = formModel->indexFromItem(barringItem);
       
   461     HbCheckBox *checkBox = static_cast<HbCheckBox*>(
       
   462         m_helper.widgetFromModelIndex(modelIndex));
       
   463     Qt::CheckState revertedCheckState = 
       
   464         (checkBox->checkState() == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
       
   465     checkBox->setCheckState(revertedCheckState);
       
   466     
       
   467     m_helper.addConnection(
       
   468         barringItem, SIGNAL(stateChanged(int)),
       
   469         this, SLOT(changeBarringStateRequested(int)));
       
   470 }
       
   471 
       
   472 
       
   473 /*!
       
   474   CpBarringPluginGroup::changeBarringStateRequested.
       
   475  */
       
   476 void CpBarringPluginGroup::changeBarringStateRequested(int checkState)
       
   477 {
       
   478     QObject *signalSender = sender();
       
   479     
       
   480     // find form item for which user has requested barring status change
       
   481     HbDataFormModel *formModel = qobject_cast<HbDataFormModel*>(model());
       
   482     CpSettingFormItemData* barringItem = NULL;
       
   483     int numOfChilds = childCount();
       
   484     for (int i = 0; (i < numOfChilds) && (barringItem == NULL); i++) {
       
   485         HbDataFormModelItem* itemCandidate = childAt(i);
       
   486         QModelIndex modelIndex = formModel->indexFromItem(itemCandidate);
       
   487         if (signalSender == m_helper.widgetFromModelIndex(modelIndex)) {
       
   488             barringItem = static_cast<CpSettingFormItemData*>(itemCandidate);
       
   489         }
       
   490     }
       
   491     
       
   492     // TODO: remove hardcoded password when setting of password is implemented
       
   493     if (NULL != barringItem) {
       
   494         if (Qt::Checked == checkState) {
       
   495             m_barringWrapper->enableBarring(
       
   496                 ServiceGroupVoice,
       
   497                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   498                     barringItem->property("barringType")), 
       
   499                 QString("1234"));
       
   500         } else {
       
   501             m_barringWrapper->disableBarring(
       
   502                 ServiceGroupVoice,
       
   503                 qvariant_cast<PSetCallBarringWrapper::BarringType>(
       
   504                     barringItem->property("barringType")), 
       
   505                 QString("1234"));
       
   506         }
       
   507         
       
   508         m_barringRequestQueue.enqueue(barringItem);
       
   509         m_phoneNotes->showGlobalProgressNote(
       
   510             m_activeNoteId, hbTrId("Requesting..."));
       
   511     }
    59 }
   512 }
    60 
   513 
    61 // End of File. 
   514 // End of File.