messagingapp/msgsettings/msgsettingsplugin.deprecated/src/msgsettingsform.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     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 #include "msgsettingsviewmanager.h"
       
    21 
       
    22 #include <hbdataformmodelitem.h>
       
    23 #include <hbdataformmodel.h>
       
    24 #include <hbcombobox.h>
       
    25 #include <hbpushbutton.h>
       
    26 
       
    27 #include "debugtraces.h"
       
    28 
       
    29 //Localized constants
       
    30 #define LOC_DELIVERY_REPORTS hbTrId("txt_messaging_setlabel_delivery_reports")
       
    31 #define LOC_ON hbTrId("txt_messaging_setlabel_val_on")
       
    32 #define LOC_OFF hbTrId("txt_messaging_setlabel_val_off")
       
    33 #define LOC_REDUCED_SUPPORT hbTrId("txt_messaging_setlabel_val_reduced_support")
       
    34 #define LOC_FULL_SUPPORT hbTrId("txt_messaging_setlabel_val_full_support")
       
    35 #define LOC_ADVANCED hbTrId("txt_messaging_button_advanced")
       
    36 #define LOC_CHAR_ENCODING hbTrId("txt_messaging_setlabel_character_encoding")
       
    37 
       
    38 
       
    39 MsgSettingsForm::MsgSettingsForm(QGraphicsItem *parent) :
       
    40     HbDataForm(parent)
       
    41 {
       
    42     mSettingsViewManager = new MsgSettingsViewManager(0);
       
    43 
       
    44     this->setHeading(tr("Application settings: Messaging"));
       
    45 
       
    46     mSettingEngine = new MsgSettingEngine();
       
    47 
       
    48     //initialize the form model
       
    49     initSettingModel();
       
    50 
       
    51     connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(onItemActivated(QModelIndex)));
       
    52 
       
    53 }
       
    54 
       
    55 MsgSettingsForm::~MsgSettingsForm()
       
    56 {
       
    57     delete mSettingsViewManager;
       
    58     delete mSettingEngine;
       
    59 }
       
    60 
       
    61 void MsgSettingsForm::initSettingModel()
       
    62 {
       
    63     HbDataFormModel *model = new HbDataFormModel(0);
       
    64 
       
    65     mDeliverReports = new HbDataFormModelItem(HbDataFormModelItem::ToggleValueItem, 
       
    66             LOC_DELIVERY_REPORTS, 0);
       
    67 
       
    68     bool deliveryReoprt = false;
       
    69     MsgSettingEngine::CharacterEncoding charEncoding = MsgSettingEngine::ReducedSupport;
       
    70 
       
    71     mSettingEngine->settingsDeliverReportAndCharEncoding(deliveryReoprt, charEncoding);
       
    72 
       
    73     QStringList deliveryReoprtList;
       
    74     deliveryReoprtList << LOC_OFF << LOC_ON;
       
    75 
       
    76     int index = int(deliveryReoprt);
       
    77     int otherIndex = (deliveryReoprt + 1) % deliveryReoprtList.count();
       
    78 
       
    79     mDeliverReports->setContentWidgetData("text", deliveryReoprtList.at(index));
       
    80     mDeliverReports->setContentWidgetData("additionalText", deliveryReoprtList.at(otherIndex));
       
    81 
       
    82     model->appendDataFormItem(mDeliverReports, model->invisibleRootItem());
       
    83 
       
    84     // Character encoding
       
    85     mCharacterEncoding = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, 
       
    86             LOC_CHAR_ENCODING, 0);
       
    87     QStringList charEncodingList;
       
    88     charEncodingList << LOC_REDUCED_SUPPORT << LOC_FULL_SUPPORT;
       
    89 
       
    90     index = int(charEncoding);
       
    91 
       
    92     mCharacterEncoding->setContentWidgetData("items", charEncodingList);
       
    93     mCharacterEncoding->setContentWidgetData("currentIndex", index);
       
    94 
       
    95     model->appendDataFormItem(mCharacterEncoding, model->invisibleRootItem());
       
    96 
       
    97     //CUSTOM SETTING ITEM HbButton
       
    98     HbDataFormModelItem::DataItemType customItem =
       
    99         static_cast<HbDataFormModelItem::DataItemType> (HbDataFormModelItem::CustomItemBase + 1);
       
   100 
       
   101     mAdvancedSettings
       
   102         = model->appendDataFormItem(customItem, QString(), model->invisibleRootItem());
       
   103     this->setModel(model);
       
   104 }
       
   105 
       
   106 // On Item activated
       
   107 void MsgSettingsForm::onItemActivated(const QModelIndex &index)
       
   108 {
       
   109     HbDataFormModelItem *itemData = static_cast<HbDataFormModelItem *> (index.internalPointer());
       
   110     // to deal with orbit change temparialy
       
   111     if (itemData->type() > HbDataFormModelItem::GroupPageItem) {
       
   112         HbDataFormModelItem *pageItemData = const_cast<HbDataFormModelItem *> (itemData->parent());
       
   113         //get the widget of setting item
       
   114         HbWidget* widget = this->dataFormViewItem(index)->dataItemContentWidget();
       
   115 
       
   116         if (itemData == mDeliverReports) {
       
   117             activateDeliveryReports(widget);
       
   118         }
       
   119         else if (itemData == mCharacterEncoding) {
       
   120             activateCharacterEncoding(widget);
       
   121         }
       
   122         else if (itemData == mAdvancedSettings) {
       
   123             activateAdvanced(widget);
       
   124         }
       
   125     }
       
   126 }
       
   127 
       
   128 void MsgSettingsForm::activateAdvanced(HbWidget* widget)
       
   129 {
       
   130     HbPushButton *advanced = qobject_cast<HbPushButton *> (widget);
       
   131 
       
   132     if (advanced) {
       
   133         advanced->setText(LOC_ADVANCED);
       
   134         //TODO Issue in DataForm Calling the itemActivated twice
       
   135         disconnect(advanced, SIGNAL(clicked()), this, SLOT(onPressedAdvanced()));
       
   136 
       
   137         connect(advanced, SIGNAL(clicked()), this, SLOT(onPressedAdvanced()));
       
   138     }
       
   139 }
       
   140 
       
   141 void MsgSettingsForm::activateDeliveryReports(HbWidget* widget)
       
   142 {
       
   143     HbPushButton *delReports = qobject_cast<HbPushButton *> (widget);
       
   144 
       
   145     if (delReports) {
       
   146         //TODO Issue in DataForm Calling the itemActivated twice
       
   147         disconnect(delReports, SIGNAL(clicked()), this, SLOT(onPressedDelReports()));
       
   148 
       
   149         connect(delReports, SIGNAL(clicked()), this, SLOT(onPressedDelReports()));
       
   150     }
       
   151 }
       
   152 
       
   153 void MsgSettingsForm::activateCharacterEncoding(HbWidget* widget)
       
   154 {
       
   155     HbComboBox *charEncoding = qobject_cast<HbComboBox *> (widget);
       
   156 
       
   157     if (charEncoding) {
       
   158         //TODO Issue in DataForm Calling the itemActivated twice
       
   159         disconnect(charEncoding, SIGNAL(currentIndexChanged(int)), this,
       
   160             SLOT(changeCharEncoding(int)));
       
   161 
       
   162         connect(charEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCharEncoding(int)));
       
   163     }
       
   164 }
       
   165 
       
   166 void MsgSettingsForm::onPressedAdvanced()
       
   167 {
       
   168     //tell view manager to open advanced view
       
   169     mSettingsViewManager->openAdvancedView();
       
   170 }
       
   171 
       
   172 void MsgSettingsForm::onPressedDelReports()
       
   173 {
       
   174     HbPushButton *btn = qobject_cast<HbPushButton *> (sender());
       
   175 
       
   176     if (btn) {
       
   177         QString btnText = btn->text();
       
   178 
       
   179         //check if the button pressed was On or Off
       
   180         if (LOC_OFF == btnText) {
       
   181             mSettingEngine->setDeliveryReport(false);
       
   182         }
       
   183         else {
       
   184             mSettingEngine->setDeliveryReport(true);
       
   185         }
       
   186     }
       
   187 }
       
   188 
       
   189 void MsgSettingsForm::changeCharEncoding(int index)
       
   190 {
       
   191     //set the character encoding
       
   192     mSettingEngine->setCharacterEncoding(MsgSettingEngine::CharacterEncoding(index));
       
   193 }
       
   194 //EOF