messagingapp/msgsettings/settingsview/src/msgsettingsform.cpp
changeset 31 ebfee66fde93
child 44 36f374c67aa8
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     1 /*
       
     2  * Copyright (c) 2009 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:  This class is for first form view for msg settings
       
    15  *
       
    16  */
       
    17 
       
    18 #include "msgsettingsform.h"
       
    19 #include "msgsettingsdataformcustomitem.h"
       
    20 
       
    21 #include <hbdataformmodelitem.h>
       
    22 #include <hbdataformmodel.h>
       
    23 #include <hbcombobox.h>
       
    24 #include <hbpushbutton.h>
       
    25 
       
    26 #include "debugtraces.h"
       
    27 
       
    28 //Localized constants
       
    29 #define LOC_RECEIVING_SERVICE_MESSAGES hbTrId("txt_messaging_setlabel_receiving_service_messages")
       
    30 #define LOC_ON hbTrId("txt_messaging_setlabel_val_on")
       
    31 #define LOC_OFF hbTrId("txt_messaging_setlabel_val_off")
       
    32 #define LOC_REDUCED_SUPPORT hbTrId("txt_messaging_setlabel_val_reduced_support")
       
    33 #define LOC_FULL_SUPPORT hbTrId("txt_messaging_setlabel_val_full_support")
       
    34 #define LOC_ADVANCED hbTrId("txt_messaging_button_advanced")
       
    35 #define LOC_CHAR_ENCODING hbTrId("txt_messaging_setlabel_character_encoding")
       
    36 #define LOC_MMS_SETTINGS hbTrId("txt_messaging_subhead_mms_settings")
       
    37 #define LOC_SMS_CENTRE_SETTINGS hbTrId("txt_messaging_subhead_sms_message_centre_settings")
       
    38 
       
    39 #define LOC_MMS_CREATION_MODE hbTrId("txt_messaging_setlabel_mms_creation_mode")
       
    40 #define LOC_MMS_RETRIEVAL hbTrId("txt_messaging_setlabel_mms_retrieval")
       
    41 #define LOC_ALLOW_ANONYMOUS_MMS hbTrId("txt_messaging_setlabel_allow_anonymous_mms_message")
       
    42 #define LOC_RECEIVE_MMS_ADVERTS hbTrId("txt_messaging_setlabel_receive_mms_adverts")
       
    43 #define LOC_MMS_AP_IN_USE hbTrId("txt_messaging_setlabel_mms_access_point_in_use")
       
    44 #define LOC_SMS_CENTRE_IN_USE hbTrId("txt_messaging_setlabel_sms_message_centre_in_use")
       
    45 #define LOC_ADD_NEW hbTrId("txt_messaging_button_add_new")
       
    46 #define LOC_ALWAYS_AUTOMATIC hbTrId("txt_messaging_setlabel_val_always_automatic")
       
    47 #define LOC_AUTO_HOME_NETWORK hbTrId("txt_messaging_setlabel_val_auto_home_network")
       
    48 #define LOC_MANUAL hbTrId("txt_messaging_setlabel_val_mannual")
       
    49 #define LOC_MMS_YES hbTrId("txt_messaging_setlabel_allow_anonymous_mms_val_yes")
       
    50 #define LOC_MMS_NO hbTrId("txt_messaging_setlabel_allow_anonymous_mms_val_no")
       
    51 
       
    52 MsgSettingsForm::MsgSettingsForm(
       
    53         MsgSettingsView::SettingsView settingsView,
       
    54         QGraphicsItem *parent) :
       
    55     HbDataForm(parent)
       
    56 {
       
    57     mSettingEngine = new MsgSettingEngine();
       
    58 
       
    59     //custom prototype
       
    60     MsgSettingsDataFormCustomItem* customPrototype =
       
    61             new MsgSettingsDataFormCustomItem(this);
       
    62 
       
    63     QList<HbAbstractViewItem*> protos = this->itemPrototypes();
       
    64     protos.append(customPrototype);
       
    65     this->setItemPrototypes(protos);
       
    66 
       
    67     mSmsMCSettingsGroup << LOC_SMS_CENTRE_IN_USE << LOC_ADD_NEW;
       
    68 
       
    69     //initialize the form model
       
    70     initSettingModel(settingsView);
       
    71 }
       
    72 
       
    73 MsgSettingsForm::~MsgSettingsForm()
       
    74 {
       
    75     delete mSettingEngine;
       
    76 }
       
    77 
       
    78 void MsgSettingsForm::initSettingModel(
       
    79         MsgSettingsView::SettingsView settingsView)
       
    80 {
       
    81     settingsModel = new HbDataFormModel(0);
       
    82 
       
    83     MsgSettingEngine::CharacterEncoding charEncoding =
       
    84             MsgSettingEngine::ReducedSupport;
       
    85 
       
    86     bool receiveServiceMessages = false;
       
    87 
       
    88     mSettingEngine->settingsServiceMessagesAndCharEncoding(
       
    89             receiveServiceMessages,
       
    90             charEncoding);
       
    91 
       
    92     // 1. Character encoding
       
    93     HbDataFormModelItem *characterEncoding =
       
    94             new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
       
    95                                     LOC_CHAR_ENCODING,
       
    96                                     0);
       
    97     QStringList charEncodingList;
       
    98     charEncodingList << LOC_REDUCED_SUPPORT << LOC_FULL_SUPPORT;
       
    99 
       
   100     int index = int (charEncoding);
       
   101 
       
   102     characterEncoding->setContentWidgetData("items", charEncodingList);
       
   103     characterEncoding->setContentWidgetData("currentIndex", index);
       
   104 
       
   105     settingsModel->appendDataFormItem(characterEncoding,
       
   106                                       settingsModel->invisibleRootItem());
       
   107     this->addConnection(characterEncoding,
       
   108                         SIGNAL(currentIndexChanged(int)),
       
   109                         this,
       
   110                         SLOT(changeCharEncoding(int)));
       
   111 
       
   112     //2. receiving service messages
       
   113     QStringList serviceMessagesList;
       
   114     serviceMessagesList << LOC_OFF << LOC_ON;
       
   115 
       
   116     index = int (receiveServiceMessages);
       
   117     int otherIndex = (receiveServiceMessages + 1) % serviceMessagesList.count();
       
   118 
       
   119     HbDataFormModelItem *serviceMessagesItem =
       
   120             new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
       
   121                                     LOC_RECEIVING_SERVICE_MESSAGES,
       
   122                                     0);
       
   123 
       
   124     serviceMessagesItem->setContentWidgetData("items", serviceMessagesList);
       
   125     serviceMessagesItem->setContentWidgetData("currentIndex", index);
       
   126 
       
   127     settingsModel->appendDataFormItem(serviceMessagesItem,
       
   128                                       settingsModel->invisibleRootItem());
       
   129     this->addConnection(serviceMessagesItem,
       
   130                         SIGNAL(clicked()),
       
   131                         this,
       
   132                         SLOT(onPressedServiceMessages()));
       
   133 
       
   134     // 3. MMS Settings
       
   135     HbDataFormModelItem* mmsGroup =
       
   136             new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
       
   137                                     LOC_MMS_SETTINGS,
       
   138                                     0);
       
   139 
       
   140     settingsModel->appendDataFormItem(mmsGroup,
       
   141                                       settingsModel->invisibleRootItem());
       
   142 
       
   143     addMMSGroupItem(mmsGroup);
       
   144 
       
   145     // 4. SMS Settings
       
   146     mSmsMCGroup = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
       
   147                                           LOC_SMS_CENTRE_SETTINGS,
       
   148                                           0);
       
   149 
       
   150     settingsModel->appendDataFormItem(mSmsMCGroup,
       
   151                                       settingsModel->invisibleRootItem());
       
   152 
       
   153     addSmsMCGroupItem(mSmsMCGroup);
       
   154 
       
   155     this->setModel(settingsModel);
       
   156     
       
   157     if (settingsView == MsgSettingsView::MMSView)
       
   158     {
       
   159         //set MMS Settings as expanded
       
   160         QModelIndex index_mms = settingsModel->indexFromItem(mmsGroup);
       
   161         //TODO: dataform issue on expanding one group item
       
   162         //this->setExpanded(index_mms, true);
       
   163     }
       
   164     else if(settingsView == MsgSettingsView::SMSView)
       
   165     {
       
   166         //expandSMSSettings();
       
   167     }
       
   168         
       
   169 }
       
   170 
       
   171 void MsgSettingsForm::refreshViewForm()
       
   172 {
       
   173     updateSmsMCGroupItem(mSmsMCGroup);
       
   174 }
       
   175 
       
   176 void MsgSettingsForm::updateSmsMCGroupItem(HbDataFormModelItem* parent)
       
   177 {
       
   178     //1. update the combobox model item
       
   179     int defaultServiceCenter = -1;
       
   180     mSmsServiceList.clear();
       
   181     mSettingEngine->allSMSMessageCenter(mSmsServiceList, defaultServiceCenter);
       
   182 
       
   183     //set the content widget data again    
       
   184     smsMessageCenter->setContentWidgetData("items", mSmsServiceList);
       
   185     if(defaultServiceCenter > 0)
       
   186     {
       
   187     smsMessageCenter->setContentWidgetData("currentIndex",
       
   188                                                defaultServiceCenter);
       
   189     }
       
   190     
       
   191     //2. refresh all the custom buttons again
       
   192     int childCount = parent->childCount();
       
   193     int totalServices = mSmsServiceList.count();
       
   194 
       
   195     //custom buttons start from index 1 till childCount-2
       
   196     int list_index = 0, child_index = 1;
       
   197     for (; list_index < totalServices && child_index <= childCount - 2; list_index++, child_index++)
       
   198     {
       
   199         //get the existing custom item instance
       
   200         HbDataFormModelItem* customItem = parent->childAt(child_index);
       
   201         customItem->setContentWidgetData("text", mSmsServiceList.at(list_index));
       
   202     }
       
   203 
       
   204     //if extra child items are remaining then delete those from parent
       
   205     for(;child_index <= childCount - 2;
       
   206             child_index++)
       
   207     {
       
   208         parent->removeChild(child_index);
       
   209     }
       
   210     
       
   211     //create all new custom items if new are added in list
       
   212     //CUSTOM SETTING ITEM HbButton
       
   213     HbDataFormModelItem::DataItemType
       
   214             customButtonGeneral =
       
   215                     static_cast<HbDataFormModelItem::DataItemType> (HbDataFormModelItem::CustomItemBase
       
   216                             + 1);
       
   217     for (; list_index < totalServices; list_index++, child_index++)
       
   218     {
       
   219         HbDataFormModelItem* newChild =
       
   220                 new HbDataFormModelItem(customButtonGeneral);
       
   221 
       
   222         newChild->setContentWidgetData("text", mSmsServiceList.at(list_index));
       
   223         parent->insertChild(child_index, newChild);
       
   224 
       
   225         this->addConnection(newChild,
       
   226                             SIGNAL(clicked()),
       
   227                             this,
       
   228                             SLOT(onPressedCustomButton()));
       
   229     }    
       
   230 }
       
   231 
       
   232 void MsgSettingsForm::addMMSGroupItem(HbDataFormModelItem* parent)
       
   233 {
       
   234     //read settings
       
   235     MsgSettingEngine::MmsRetrieval retrieval =
       
   236             MsgSettingEngine::AlwaysAutomatic;
       
   237     bool allowAnonymous = true;
       
   238     bool allowAdverts = true;
       
   239 
       
   240     mSettingEngine->advanceMmsSettings(retrieval, 
       
   241                                        allowAnonymous, 
       
   242                                        allowAdverts);
       
   243 
       
   244     // add all the mms group item
       
   245 
       
   246     HbDataFormModelItem *mmsRetrieval =
       
   247             new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
       
   248                                     LOC_MMS_RETRIEVAL,
       
   249                                     0);
       
   250 
       
   251     QStringList mmsRetrievalList;
       
   252     mmsRetrievalList << LOC_ALWAYS_AUTOMATIC << LOC_AUTO_HOME_NETWORK
       
   253             << LOC_MANUAL << LOC_OFF;
       
   254 
       
   255     mmsRetrieval->setContentWidgetData("items", mmsRetrievalList);
       
   256     mmsRetrieval->setContentWidgetData("currentIndex", int (retrieval));
       
   257     this->addConnection(mmsRetrieval,
       
   258                         SIGNAL(currentIndexChanged(int)),
       
   259                         this,
       
   260                         SLOT(changeMMSRetrievalMode(int)));
       
   261 
       
   262     HbDataFormModelItem *anonymousMMS =
       
   263             new HbDataFormModelItem(HbDataFormModelItem::ToggleValueItem,
       
   264                                     LOC_ALLOW_ANONYMOUS_MMS,
       
   265                                     0);
       
   266 
       
   267     QStringList anonymousMMSList;
       
   268     anonymousMMSList << LOC_MMS_NO << LOC_MMS_YES;
       
   269 
       
   270     int defaultIndex = int (allowAnonymous);
       
   271     int alternateIndex = (defaultIndex + 1) % anonymousMMSList.count();
       
   272 
       
   273     anonymousMMS->setContentWidgetData("text",
       
   274                                        anonymousMMSList.at(defaultIndex));
       
   275     anonymousMMS->setContentWidgetData("additionalText",
       
   276                                        anonymousMMSList.at(alternateIndex));
       
   277     this->addConnection(anonymousMMS,
       
   278                         SIGNAL(clicked()),
       
   279                         this,
       
   280                         SLOT(allowAnonymousMMS()));
       
   281 
       
   282     HbDataFormModelItem *mmsAdverts =
       
   283             new HbDataFormModelItem(HbDataFormModelItem::ToggleValueItem,
       
   284                                     LOC_RECEIVE_MMS_ADVERTS,
       
   285                                     0);
       
   286 
       
   287     QStringList mmsAdvertsList;
       
   288     mmsAdvertsList << LOC_MMS_NO << LOC_MMS_YES;
       
   289 
       
   290     defaultIndex = int (allowAdverts);
       
   291     alternateIndex = (defaultIndex + 1) % mmsAdvertsList.count();
       
   292 
       
   293     mmsAdverts->setContentWidgetData("text", mmsAdvertsList.at(defaultIndex));
       
   294     mmsAdverts->setContentWidgetData("additionalText",
       
   295                                      mmsAdvertsList.at(alternateIndex));
       
   296 
       
   297     this->addConnection(mmsAdverts,
       
   298                         SIGNAL(clicked()),
       
   299                         this,
       
   300                         SLOT(allowMMSAdverts()));
       
   301 
       
   302     HbDataFormModelItem *accessPoint =
       
   303             new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
       
   304                                     LOC_MMS_AP_IN_USE,
       
   305                                     0);
       
   306 
       
   307     QStringList mmsList;
       
   308     int defaultAccessPointIndex = -1;
       
   309 
       
   310     mSettingEngine->allMMsAcessPoints(mmsList, defaultAccessPointIndex);
       
   311     accessPoint->setContentWidgetData("items", mmsList);
       
   312     if (defaultAccessPointIndex >= 0)
       
   313     {
       
   314         accessPoint->setContentWidgetData("currentIndex",
       
   315                                           defaultAccessPointIndex);
       
   316     }
       
   317     QDEBUG_WRITE_FORMAT("Settings: adding accesspoints..", defaultAccessPointIndex);
       
   318     this->addConnection(accessPoint,
       
   319                         SIGNAL(currentIndexChanged(int)),
       
   320                         this,
       
   321                         SLOT(changeAccessPoint(int)));
       
   322 
       
   323     parent->appendChild(mmsRetrieval);
       
   324     parent->appendChild(anonymousMMS);
       
   325     parent->appendChild(mmsAdverts);
       
   326     parent->appendChild(accessPoint);
       
   327 }
       
   328 
       
   329 void MsgSettingsForm::addSmsMCGroupItem(HbDataFormModelItem* parent)
       
   330 {
       
   331     // add all the sms message center group item
       
   332     smsMessageCenter
       
   333             = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
       
   334                                       mSmsMCSettingsGroup.at(0),
       
   335                                       0);
       
   336 
       
   337     int defaultServiceCenter = -1;
       
   338     mSmsServiceList.clear();
       
   339     
       
   340     mSettingEngine->allSMSMessageCenter(mSmsServiceList, defaultServiceCenter);
       
   341     smsMessageCenter->setContentWidgetData("items", mSmsServiceList);
       
   342     if (defaultServiceCenter >= 0)
       
   343     {
       
   344         smsMessageCenter->setContentWidgetData("currentIndex",
       
   345                                                defaultServiceCenter);
       
   346     }
       
   347 
       
   348     this->addConnection(smsMessageCenter,
       
   349                         SIGNAL(currentIndexChanged(int)),
       
   350                         this,
       
   351                         SLOT(onSMSCurrentIndexChanged(int)));
       
   352 
       
   353     parent->appendChild(smsMessageCenter);
       
   354 
       
   355     //CUSTOM SETTING ITEM HbButton
       
   356     HbDataFormModelItem::DataItemType
       
   357             customButtonGeneral =
       
   358                     static_cast<HbDataFormModelItem::DataItemType> (HbDataFormModelItem::CustomItemBase
       
   359                             + 1);
       
   360 
       
   361     int totalServices = mSmsServiceList.count();
       
   362     for (int index = 0; index < totalServices; index++)
       
   363     {
       
   364         HbDataFormModelItem *newMessageCenters =
       
   365                 settingsModel->appendDataFormItem(customButtonGeneral,
       
   366                                                   QString(""),
       
   367                                                   parent);
       
   368 
       
   369         newMessageCenters->setContentWidgetData("text",
       
   370                                                 mSmsServiceList.at(index));
       
   371         this->addConnection(newMessageCenters,
       
   372                             SIGNAL(clicked()),
       
   373                             this,
       
   374                             SLOT(onPressedCustomButton()));
       
   375     }
       
   376 
       
   377     HbDataFormModelItem *newMessageCenters =
       
   378             settingsModel->appendDataFormItem(customButtonGeneral,
       
   379                                               QString(""),
       
   380                                               parent);
       
   381 
       
   382     newMessageCenters->setContentWidgetData("text", mSmsMCSettingsGroup.at(1));
       
   383     this->addConnection(newMessageCenters,
       
   384                         SIGNAL(clicked()),
       
   385                         this,
       
   386                         SLOT(onPressedCustomButton()));
       
   387 }
       
   388 
       
   389 void MsgSettingsForm::onPressedServiceMessages()
       
   390 {
       
   391     HbPushButton *btn = qobject_cast<HbPushButton *> (sender());
       
   392 
       
   393     if (btn)
       
   394     {
       
   395         QString btnText = btn->text();
       
   396 
       
   397         //check if the button pressed was On or Off
       
   398         if (LOC_OFF == btnText)
       
   399         {
       
   400             mSettingEngine->setReceiveSerivceMessages(false);
       
   401         }
       
   402         else
       
   403         {
       
   404             mSettingEngine->setReceiveSerivceMessages(true);
       
   405         }
       
   406     }
       
   407 }
       
   408 
       
   409 void MsgSettingsForm::changeCharEncoding(int index)
       
   410 {
       
   411     //set the character encoding
       
   412     mSettingEngine->setCharacterEncoding(MsgSettingEngine::CharacterEncoding(index));
       
   413 }
       
   414 
       
   415 void MsgSettingsForm::changeMMSRetrievalMode(int index)
       
   416 {
       
   417     mSettingEngine->setMMSRetrieval(MsgSettingEngine::MmsRetrieval(index));
       
   418 }
       
   419 
       
   420 void MsgSettingsForm::allowAnonymousMMS()
       
   421 {
       
   422     HbPushButton *btn = qobject_cast<HbPushButton *> (sender());
       
   423 
       
   424     if (btn)
       
   425     {
       
   426         QString btnText = btn->text();
       
   427 
       
   428         //check if the button pressed was Yes or NO
       
   429         if (LOC_MMS_YES == btnText)
       
   430         {
       
   431             mSettingEngine->setAnonymousMessages(true);
       
   432         }
       
   433         else
       
   434         {
       
   435             mSettingEngine->setAnonymousMessages(false);
       
   436         }
       
   437     }
       
   438 }
       
   439 
       
   440 void MsgSettingsForm::allowMMSAdverts()
       
   441 {
       
   442     HbPushButton *btn = qobject_cast<HbPushButton *> (sender());
       
   443 
       
   444     if (btn)
       
   445     {
       
   446         QString btnText = btn->text();
       
   447 
       
   448         //check if the button pressed was Yes or NO
       
   449         if (LOC_MMS_NO == btnText)
       
   450         {
       
   451             mSettingEngine->setReceiveMMSAdverts(true);
       
   452         }
       
   453         else
       
   454         {
       
   455             mSettingEngine->setReceiveMMSAdverts(false);
       
   456         }
       
   457     }
       
   458 }
       
   459 
       
   460 void MsgSettingsForm::changeAccessPoint(int index)
       
   461 {
       
   462     // save to the mms settings
       
   463     mSettingEngine->setMMSAccesspoint(index);
       
   464 }
       
   465 
       
   466 void MsgSettingsForm::onPressedCustomButton()
       
   467 {
       
   468     HbPushButton *btn = qobject_cast<HbPushButton *> (sender());
       
   469 
       
   470     if (btn)
       
   471     {
       
   472         QString btnText = btn->text();
       
   473         if (btnText == mSmsMCSettingsGroup.at(1))
       
   474         {
       
   475             // emit the signal to open add view 
       
   476             emit newSMSCCenterClicked(-1);
       
   477         }
       
   478         else
       
   479         {
       
   480             int index = mSmsServiceList.indexOf(btnText);
       
   481             emit newSMSCCenterClicked(index);
       
   482         }
       
   483     }
       
   484 }
       
   485 
       
   486 void MsgSettingsForm::onSMSCurrentIndexChanged(int index)
       
   487 {
       
   488     //set into msg settings
       
   489     mSettingEngine->setSMSMessageCenter(index);
       
   490 }
       
   491 
       
   492 void MsgSettingsForm::expandSMSSettings()
       
   493 {
       
   494     QModelIndex index_sms = settingsModel->indexFromItem(mSmsMCGroup);
       
   495 
       
   496     this->setExpanded(index_sms, true);
       
   497 }
       
   498 //EOF