phonesettings/cpphonesettingsplugins/divertplugin/src/cpdivertplugingroup.cpp
changeset 30 ebdbd102c78a
parent 27 2f8f8080a020
child 51 f39ed5e045e0
equal deleted inserted replaced
27:2f8f8080a020 30:ebdbd102c78a
    13  *
    13  *
    14  * Description:  
    14  * Description:  
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <QEventLoop>
    18 #include <hbdataformmodel.h>
    19 #include <hbdataformmodel.h>
    19 #include <hbdataformmodelitem.h>
    20 #include <hbdataformmodelitem.h>
    20 #include <hblineedit.h>
    21 #include <hblineedit.h>
    21 #include <hbinputeditorinterface.h>
    22 #include <hbinputeditorinterface.h>
    22 #include <hbcombobox.h>
    23 #include <hbcombobox.h>
    25 #include <psetwrapper.h>
    26 #include <psetwrapper.h>
    26 #include <hbaction.h>
    27 #include <hbaction.h>
    27 #include <hblistwidget.h>
    28 #include <hblistwidget.h>
    28 #include <hblistwidgetitem.h>
    29 #include <hblistwidgetitem.h>
    29 #include <hblabel.h>
    30 #include <hblabel.h>
    30 #include <QApplication>
       
    31 #include <QLocale>
       
    32 #include <QTranslator>
       
    33 #include <cpitemdatahelper.h>
    31 #include <cpitemdatahelper.h>
    34 #include "cpdivertselectionitem.h"
    32 #include "cpdivertselectionitem.h"
    35 #include "cpdivertplugingroup.h"
    33 #include "cpdivertplugingroup.h"
    36 #include "cpplugincommon.h"
    34 #include "cpplugincommon.h"
    37 #include "cpphonenotes.h"
    35 #include "cpphonenotes.h"
    39 #include "cpdivertitemdata.h"
    37 #include "cpdivertitemdata.h"
    40 #include "cpdivertselectioncustomitem.h"
    38 #include "cpdivertselectioncustomitem.h"
    41 
    39 
    42 Q_DECLARE_METATYPE(PsCallDivertingCondition)
    40 Q_DECLARE_METATYPE(PsCallDivertingCondition)
    43 Q_DECLARE_METATYPE(PsServiceGroup)
    41 Q_DECLARE_METATYPE(PsServiceGroup)
       
    42 
       
    43 // CONSTANTS 
       
    44 const QString KVoiceMail("voiceMail");
       
    45 const QString KVideoMail("voiceMail");
       
    46 const QString KOtherNumber("otherNumber");
    44 
    47 
    45 /*!
    48 /*!
    46   CpDivertPluginGroup::CpDivertPluginGroup.
    49   CpDivertPluginGroup::CpDivertPluginGroup.
    47  */
    50  */
    48 CpDivertPluginGroup::CpDivertPluginGroup(CpItemDataHelper &helper)
    51 CpDivertPluginGroup::CpDivertPluginGroup(CpItemDataHelper &helper)
    59        m_DataItemVideoIfOutOfReach(NULL),
    62        m_DataItemVideoIfOutOfReach(NULL),
    60        m_DataItemVideoIfNotAvailable(NULL),
    63        m_DataItemVideoIfNotAvailable(NULL),
    61        m_activeNoteId(0),
    64        m_activeNoteId(0),
    62        m_activeProgressNoteId(0),
    65        m_activeProgressNoteId(0),
    63        m_divertToVoiceMailBox(false),
    66        m_divertToVoiceMailBox(false),
    64        m_helper(helper)
    67        m_helper(helper),
       
    68        m_divertTimeout(0)
    65 {
    69 {
    66     DPRINT << ": IN";
    70     DPRINT << ": IN";
    67     
    71     
    68     // Registration needed, because PsCallDivertingCondition and PsServiceGroup
    72     // Registration needed, because PsCallDivertingCondition and PsServiceGroup
    69     // is used as a custom meta information for barring items.
    73     // is used as a custom meta information for barring items.
    70     qRegisterMetaType<PsCallDivertingCondition>(
    74     qRegisterMetaType<PsCallDivertingCondition>(
    71         "PsCallDivertingCondition");
    75         "PsCallDivertingCondition");
    72     
    76     
    73     qRegisterMetaType<PsServiceGroup>(
    77     qRegisterMetaType<PsServiceGroup>(
    74         "PsServiceGroup");
    78         "PsServiceGroup");
    75     
       
    76     // Localization file loading
       
    77     QTranslator translator; 
       
    78     QString lang = QLocale::system().name();
       
    79     QString path = "z:/resource/qt/translations/";
       
    80     DPRINT << ": loading translation: " << QString(path + "telephone_cp_" + lang);
       
    81     bool translatorLoaded = translator.load(path + "telephone_cp_" + lang);
       
    82     DPRINT << ": translator loaded: " << translatorLoaded; 
       
    83     if (translatorLoaded) {
       
    84         qApp->installTranslator(&translator);
       
    85         DPRINT << ": translator installed"; 
       
    86     }
       
    87     
    79     
    88     m_pSetWrapper = new PSetWrapper; 
    80     m_pSetWrapper = new PSetWrapper; 
    89     DPRINT << ": PSetWrapper created";
    81     DPRINT << ": PSetWrapper created";
    90     
    82     
    91     m_ssSettingsWrapper = new SsSettingsWrapper; 
    83     m_ssSettingsWrapper = new SsSettingsWrapper; 
   122             SIGNAL(itemShown(QModelIndex)), this, SLOT(itemShown(QModelIndex)));
   114             SIGNAL(itemShown(QModelIndex)), this, SLOT(itemShown(QModelIndex)));
   123     
   115     
   124     // Create grouped setting items
   116     // Create grouped setting items
   125     createVoiceCallItems(this);
   117     createVoiceCallItems(this);
   126     createVideoCallItems(this);
   118     createVideoCallItems(this);
       
   119     
       
   120     m_eventLoop = new QEventLoop(this); 
       
   121     
   127     DPRINT << ": OUT";
   122     DPRINT << ": OUT";
   128 }
   123 }
   129 
   124 
   130 /*!
   125 /*!
   131   CpDivertPluginGroup::~CpDivertPluginGroup.
   126   CpDivertPluginGroup::~CpDivertPluginGroup.
   287  */
   282  */
   288 void CpDivertPluginGroup::itemShown(const QModelIndex& item)
   283 void CpDivertPluginGroup::itemShown(const QModelIndex& item)
   289 {
   284 {
   290     DPRINT << ": IN";
   285     DPRINT << ": IN";
   291     DPRINT << "item:" << item;
   286     DPRINT << "item:" << item;
       
   287     
   292     HbDataFormModelItem* modelItem = 
   288     HbDataFormModelItem* modelItem = 
   293             qobject_cast<HbDataFormModel*>(model())->itemFromIndex(item);
   289             qobject_cast<const HbDataFormModel*>(item.model())->itemFromIndex(item);
   294     
   290     
   295     if (!modelItem->contentWidgetData("number").isValid() &&
   291     if (!modelItem->contentWidgetData("number").isValid() &&
   296         (static_cast<HbDataFormModelItem::DataItemType>
   292         (static_cast<HbDataFormModelItem::DataItemType>
   297             (CpDivertSelectionItem::CpDivertSelectionItemId == modelItem->type()))){
   293             (CpDivertSelectionItem::CpDivertSelectionItemId == modelItem->type()))){
   298         CpDivertItemData *item = static_cast<CpDivertItemData*>(modelItem); 
   294         CpDivertItemData *item = static_cast<CpDivertItemData*>(modelItem); 
   710  */
   706  */
   711 bool CpDivertPluginGroup::popUpVoiceNumberListQuery(
   707 bool CpDivertPluginGroup::popUpVoiceNumberListQuery(
   712         const QString& heading, QString& result, PsServiceGroup serviceGroup)
   708         const QString& heading, QString& result, PsServiceGroup serviceGroup)
   713 {
   709 {
   714     DPRINT << ": IN";
   710     DPRINT << ": IN";
   715     const QString KVoiceMail("voiceMail");
       
   716     const QString KVideoMail("voiceMail");
       
   717     const QString KOtherNumber("otherNumber");
       
   718     
   711     
   719     bool requestOK(false);
   712     bool requestOK(false);
   720     m_divertToVoiceMailBox = false;
   713 
   721     QStringList defNumbers;
   714     if (!m_eventLoop->isRunning()){
   722     HbDialog *dialog = createDialog(heading);
   715         m_divertNumber = ""; 
   723     HbListWidget *list = new HbListWidget(dialog);
   716         m_divertToVoiceMailBox = false;
   724     if (serviceGroup == ServiceGroupVoice) {
   717         QStringList defNumbers;
   725         addItemToListWidget(
   718         HbDialog *dialog = createDialog(heading);
   726             list, hbTrId("txt_phone_setlabel_voice_mbx"), KVoiceMail );
   719         m_voiceNumberList = new HbListWidget(dialog);
   727     } else if(serviceGroup == ServiceGroupData) {
   720         if (serviceGroup == ServiceGroupVoice) {
   728         // TODO: Implement video voicemail
   721             addItemToListWidget(
   729     }
   722                     m_voiceNumberList, hbTrId("txt_phone_setlabel_voice_mbx"), KVoiceMail );
   730 
   723         } else if(serviceGroup == ServiceGroupData) {
   731     // Add "old" divert number to list
   724             // TODO: Implement video voicemail
   732     m_callDivertingWrapper->getDefaultNumbers(defNumbers);
   725         }
   733     int count(defNumbers.count());
   726     
   734     for (int i = 0; i < count; i++) {
   727         // Add "old" divert number to list
   735         addItemToListWidget(list, defNumbers[i], defNumbers[i]);
   728         m_callDivertingWrapper->getDefaultNumbers(defNumbers);
   736     }
   729         int count(defNumbers.count());
   737     addItemToListWidget(list, hbTrId("txt_phone_list_enter_number_manually"), KOtherNumber );
   730         for (int i = 0; i < count; i++) {
   738     // Connect list item activation signal to close the popup
   731             addItemToListWidget(m_voiceNumberList, defNumbers[i], defNumbers[i]);
   739     connect(
   732         }
   740         list, SIGNAL(activated(HbListWidgetItem*)), 
   733         addItemToListWidget(m_voiceNumberList, hbTrId("txt_phone_list_enter_number_manually"), KOtherNumber );
   741         dialog, SLOT(close()));
   734         dialog->setContentWidget(m_voiceNumberList);
   742     // Sets the "Cancel"-action/button
   735         
   743     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
   736         // Connect list item activation signal to close the popup
   744     dialog->setPrimaryAction(cancelAction);
   737         QObject::connect(m_voiceNumberList, 
   745     dialog->setContentWidget(list);
   738                 SIGNAL(activated(HbListWidgetItem*)), 
   746     // Launch popup and handle the response
   739                 dialog, 
   747     if (dialog->exec() != cancelAction) {
   740                 SLOT(close()), 
       
   741                 Qt::UniqueConnection);
       
   742         
       
   743         // Sets the "Cancel"-action/button
       
   744         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   745         dialog->addAction(cancelAction);
       
   746         QObject::connect(cancelAction, 
       
   747                 SIGNAL(triggered(bool)), 
       
   748                 dialog, 
       
   749                 SLOT(close()));
       
   750         
       
   751         dialog->open(this, SLOT(voiceNumberListQueryClosed(HbAction *))); 
       
   752         
       
   753         QPointer<QObject> guard = this;
       
   754         m_eventLoop->exec(); 
       
   755         if (guard.isNull()) {
       
   756             requestOK = false;
       
   757         } else if (!m_divertNumber.isEmpty()) {
       
   758             result = m_divertNumber;
       
   759             requestOK = true;
       
   760         }    
       
   761     }
       
   762     
       
   763     DPRINT << ": OUT : result:" << result;
       
   764     DPRINT << ": OUT : requestOK :" << requestOK;
       
   765     return requestOK;
       
   766 }
       
   767 
       
   768 /*!
       
   769     CpDivertPluginGroup::voiceNumberListQueryClosed()
       
   770 */
       
   771 void CpDivertPluginGroup::voiceNumberListQueryClosed(HbAction* action)
       
   772 {
       
   773     DPRINT << ": IN";
       
   774     
       
   775     bool exitLoop(true); 
       
   776     
       
   777     // Enter if cancel wasn't selected 
       
   778     if (!action) {  
   748         // Update the view with selected text
   779         // Update the view with selected text
   749         QString data = list->currentItem()->data().toString();
   780         QString data = m_voiceNumberList->currentItem()->data().toString();
       
   781         DPRINT << ": data: " << data; 
       
   782         
   750         if (data == KVoiceMail) {
   783         if (data == KVoiceMail) {
   751             m_callDivertingWrapper->getVoiceMailBoxNumber(result);
   784             m_callDivertingWrapper->getVoiceMailBoxNumber(m_divertNumber);
   752             if (result.size()) {
   785             if (!m_divertNumber.isEmpty()) {
   753                 // voicemailboxnumber found
   786                 DPRINT << ": voicemailboxnumber found";
   754                 m_divertToVoiceMailBox = true;
   787             }
   755                 requestOK = true;
   788             
   756             }
   789             m_eventLoop->quit();
       
   790             
   757         } else if (data == KOtherNumber) {
   791         } else if (data == KOtherNumber) {
   758             requestOK = popUpNumberEditor(hbTrId("txt_phone_info_number"), result);
   792                 // Event loop is terminated by popUpNumberEditorClosed
       
   793                 exitLoop = false;
       
   794                 
       
   795                 DPRINT << ": open popUpNumberEditor";                
       
   796                 popUpNumberEditor(hbTrId("txt_phone_info_number"), m_divertNumber);
   759         } else {
   797         } else {
   760             //TODO if matched contact name not work
   798             //TODO if matched contact name not work
   761             result = data;
   799             DPRINT << ": else";
   762             requestOK = true;
   800             m_divertNumber = data;
   763         }
   801         }        
   764     }
   802         
   765     else {
   803     }
   766         DPRINT << ": Cancel";
   804     
   767     }
   805     if (exitLoop) {
   768     disconnect(
   806         DPRINT << ": quit eventloop";
   769         list, SIGNAL(activated(HbListWidgetItem*)), 
   807         m_eventLoop->quit();
   770         dialog, SLOT(close()));
   808     }
   771     delete dialog;
   809     
   772     
   810     DPRINT << ": OUT";
   773     DPRINT << ": OUT : requestOK :" << requestOK;
       
   774     return requestOK;
       
   775 }
   811 }
   776 
   812 
   777 /*!
   813 /*!
   778   CpDivertPluginGroup::popUpNumberEditor.
   814   CpDivertPluginGroup::popUpNumberEditor.
   779  */
   815  */
   780 bool CpDivertPluginGroup::popUpNumberEditor(
   816 void CpDivertPluginGroup::popUpNumberEditor(
   781         const QString& heading, QString& result)
   817         const QString& heading, QString& result)
   782 {
   818 {
   783     DPRINT << ": IN";
   819     DPRINT << ": IN";
   784 
   820 
   785     bool requestOK(false);
   821     Q_UNUSED(result); 
       
   822     
   786     HbDialog *dialog = createDialog(heading);
   823     HbDialog *dialog = createDialog(heading);
   787     HbLineEdit *editor = new HbLineEdit(dialog);
   824 
   788     HbEditorInterface editorInterface(editor);
   825     m_voiceNumberEditor = new HbLineEdit(dialog);
   789     editorInterface.setUpAsPhoneNumberEditor();
   826     m_voiceNumberEditor->setInputMethodHints(Qt::ImhDialableCharactersOnly);    
   790     dialog->setContentWidget(editor);
   827     dialog->setContentWidget(m_voiceNumberEditor);
       
   828     
   791     HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   829     HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   792     dialog->addAction(okAction);
   830     dialog->addAction(okAction);
       
   831     
   793     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
   832     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
   794     dialog->setSecondaryAction(cancelAction);
   833     dialog->addAction(cancelAction);
   795     
   834     
   796     HbAction *resultAction = dialog->exec();
   835     dialog->open(this, SLOT(popUpNumberEditorClosed(HbAction*)));
   797     if (resultAction == cancelAction) {
   836     
   798         DPRINT << ": canceled";
   837     DPRINT << ": OUT";
   799     }
   838 }
   800     else {
   839 
   801         result = editor->text();
   840 /*!
   802         DPRINT << ": number "
   841   CpDivertPluginGroup::popUpNumberEditorClosed.
   803             << result;
   842  */
   804         if (result.count()) {
   843 void CpDivertPluginGroup::popUpNumberEditorClosed(HbAction* action)
   805             requestOK = true;
   844 {
   806         }
   845     DPRINT << ": IN";
   807         else {
   846     
   808             CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId, 
   847     bool cancelled(true); 
   809                 hbTrId("txt_phone_info_invalid_phone_number"), HbMessageBox::MessageTypeWarning);
   848     if (action) {
   810         }
   849         if (action->text() == hbTrId("txt_common_button_ok")) 
   811     }
   850             {
   812     delete dialog;
   851             cancelled = false;  
   813     
   852             DPRINT << ": ok selected";
   814     DPRINT << ": OUT : requestOK :" << requestOK;
   853             }
   815     return requestOK;
   854     }
       
   855     
       
   856     if (!cancelled) {
       
   857         m_divertNumber = m_voiceNumberEditor->text();
       
   858             DPRINT << ": m_divertNumber "
       
   859                 << m_divertNumber;
       
   860             if (m_divertNumber.isEmpty()) {
       
   861                 CpPhoneNotes::instance()->showGlobalNote(m_activeNoteId, 
       
   862                     hbTrId("txt_phone_info_invalid_phone_number"), HbMessageBox::MessageTypeWarning);
       
   863             }
       
   864     }
       
   865     
       
   866     if (m_voiceNumberEditor) {
       
   867         delete m_voiceNumberEditor;
       
   868         m_voiceNumberEditor = NULL; 
       
   869     } 
       
   870     
       
   871     m_eventLoop->quit();
       
   872     DPRINT << ": OUT";
   816 }
   873 }
   817 
   874 
   818 /*!
   875 /*!
   819   CpDivertPluginGroup::setCallDiverting.
   876   CpDivertPluginGroup::setCallDiverting.
   820  */
   877  */
   843 }
   900 }
   844 
   901 
   845 /*!
   902 /*!
   846   CpDivertPluginGroup::popUpTimerQuery.
   903   CpDivertPluginGroup::popUpTimerQuery.
   847  */
   904  */
   848 bool CpDivertPluginGroup::popUpTimerQuery(int &timeout) const
   905 bool CpDivertPluginGroup::popUpTimerQuery(int &timeout) 
   849 {
   906 {
   850     DPRINT << ": IN";
   907     DPRINT << ": IN";
       
   908     Q_UNUSED(timeout); 
   851     
   909     
   852     bool requestOK(false);
   910     bool requestOK(false);
   853     HbDialog *dialog = createDialog(hbTrId("Time out"));
   911     m_divertTimeout = 0; 
   854     HbListWidget *list = new HbListWidget(dialog);
   912     
   855     addItemToListWidget(list, hbTrId("5 second"), 5 );
   913     if (!m_eventLoop->isRunning()) {
   856     addItemToListWidget(list, hbTrId("10 second"), 10);
   914         HbDialog *dialog = createDialog(hbTrId("txt_phone_title_delay"));
   857     addItemToListWidget(list, hbTrId("15 second"), 15);
   915         
   858     addItemToListWidget(list, hbTrId("20 second"), 20);
   916         if (m_popupTimerList) {
   859     addItemToListWidget(list, hbTrId("25 second"), 25);
   917             m_popupTimerList = new HbListWidget(dialog);
   860     addItemToListWidget(list, hbTrId("30 second"), 30);
   918             
   861     // Connect list item activation signal to close the popup
   919             addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_5_seconds"), 5 );
   862     connect(
   920             addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_10_seconds"), 10);
   863         list, SIGNAL(activated(HbListWidgetItem*)), 
   921             addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_15_seconds"), 15);
   864         dialog, SLOT(close()));
   922             addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_20_seconds"), 20);
   865     // Sets the "Cancel"-action/button
   923             addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_25_seconds"), 25);
   866     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
   924             addItemToListWidget(m_popupTimerList, hbTrId("txt_phone_list_30_seconds"), 30);
   867     dialog->setPrimaryAction(cancelAction);
   925             
   868     dialog->setContentWidget(list);
   926             // Connect list item activation signal to close the popup
   869     // Launch popup and handle the response
   927             QObject::connect(
   870     if (dialog->exec() != cancelAction) {
   928                     m_popupTimerList, SIGNAL(activated(HbListWidgetItem*)), 
       
   929                     dialog, SLOT(close()), 
       
   930                     Qt::UniqueConnection);
       
   931         }
       
   932         
       
   933         // Sets the "Cancel"-action/button
       
   934         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   935         dialog->addAction(cancelAction);
       
   936         dialog->setContentWidget(m_popupTimerList);
       
   937     
       
   938         dialog->open(this, SLOT(popUpTimerQueryClosed(HbAction *))); 
       
   939         
       
   940         QPointer<QObject> guard = this;
       
   941         m_eventLoop->exec(); 
       
   942         if (guard.isNull()) {
       
   943             requestOK = false;
       
   944         } else if (m_divertTimeout > 0) {
       
   945             requestOK = true;
       
   946         }
       
   947     }
       
   948     
       
   949     DPRINT << ": OUT : requestOK :" << requestOK;
       
   950     return requestOK;
       
   951 }
       
   952 
       
   953 /*!
       
   954   CpDivertPluginGroup::popUpTimerQueryClosed.
       
   955  */
       
   956 void CpDivertPluginGroup::popUpTimerQueryClosed(HbAction* action)
       
   957 {
       
   958     // If not cancel action selected 
       
   959     if (!action) {
   871         // Update the view with selected text
   960         // Update the view with selected text
   872         if (list->currentItem()) {
   961         if (m_popupTimerList->currentItem()) {
   873             timeout = list->currentItem()->data().toInt();
   962             m_divertTimeout = 
   874         }
   963                     m_popupTimerList->currentItem()->data().toInt();
   875         requestOK = true;
   964         }
   876     }
   965     }
   877     else {
   966     else {
   878         DPRINT << ": Cancel";
   967         DPRINT << ": Cancel";
   879     }
   968     }
   880 
   969 
   881     disconnect(
   970     DPRINT << ": quit eventloop";
   882         list, SIGNAL(activated(HbListWidgetItem*)), 
   971     m_eventLoop->quit();
   883         dialog, SLOT(close()));
   972 
   884     delete dialog;
   973     DPRINT << ": OUT: timeout: " << m_divertTimeout;
   885     
   974 }
   886     DPRINT << ": OUT : requestOK :" << requestOK;
   975 
   887     return requestOK;
   976 
   888 }
   977 /*!
   889 
   978   CpDivertPluginGroup::bscParam.
   890 /*!
       
   891   CpDivertPluginGroup::setbscParam.
       
   892  */
   979  */
   893 int CpDivertPluginGroup::bscParam(PsServiceGroup serviceGroup)
   980 int CpDivertPluginGroup::bscParam(PsServiceGroup serviceGroup)
   894 {
   981 {
   895     DPRINT << ": IN";
   982     DPRINT << ": IN";
   896 
   983