messagingapp/msgsettings/settingsview/src/msgsmscentersettingsform.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 sms message center form view 
       
    15  *
       
    16  */
       
    17 
       
    18 #include "msgsmscentersettingsform.h"
       
    19 #include "msgsettingengine.h"
       
    20 
       
    21 #include <hbdataformviewitem.h>
       
    22 #include <hbdataformmodelitem.h>
       
    23 #include <hbdataformmodel.h>
       
    24 #include <hblineedit.h>
       
    25 #include <hbinputeditorinterface.h>
       
    26 #include "debugtraces.h"
       
    27 
       
    28 //Localized constants
       
    29 #define LOC_NEW_SMS_CENTRE hbTrId("txt_messaging_title_new_sms_message_centre")
       
    30 #define LOC_EDIT_SMS_CENTRE hbTrId("txt_messaging_title_edit_sms_message_centre")
       
    31 #define LOC_SMS_CENTRE_NAME hbTrId("txt_messaging_setlabel_message_centre_name")
       
    32 #define LOC_SMS_CENTRE_NUMBER hbTrId("txt_messaging_setlabel_message_centre_number")
       
    33 
       
    34 
       
    35 MsgSMSCenterSettingsForm::MsgSMSCenterSettingsForm(int view, QGraphicsItem *parent) :
       
    36     HbDataForm(parent), mEdit1(0), mEdit2(0), mView(view)
       
    37 {
       
    38     QString heading;
       
    39     if (mView == -1) {
       
    40         heading = LOC_NEW_SMS_CENTRE;
       
    41     }
       
    42     else {
       
    43         heading = LOC_EDIT_SMS_CENTRE;
       
    44     }
       
    45 
       
    46     this->setHeading(heading);
       
    47 
       
    48     bool b = connect(this,
       
    49                         SIGNAL(itemShown(const QModelIndex&)),
       
    50                         this, SLOT(onItemShown(const QModelIndex&)));
       
    51                         
       
    52     QDEBUG_WRITE_FORMAT("MsgSMSCenterSettingsForm::MsgSMSCenterSettingsForm initialized.. ", b)
       
    53                         
       
    54     mSettingEngine = new MsgSettingEngine();
       
    55 
       
    56     initSettingModel();    
       
    57 }
       
    58 
       
    59 MsgSMSCenterSettingsForm::~MsgSMSCenterSettingsForm()
       
    60 {
       
    61     delete mSettingEngine;
       
    62 }
       
    63 
       
    64 void MsgSMSCenterSettingsForm::initSettingModel()
       
    65 {
       
    66 	  QDEBUG_WRITE("MsgSMSCenterSettingsForm::initSettingModel");
       
    67     HbDataFormModel *settingsmodel = new HbDataFormModel();
       
    68 
       
    69     QString centerName = QString();
       
    70     QString centerNumber = QString();
       
    71 
       
    72     if (mView != -1) {
       
    73         mSettingEngine->smsCenterNameAndNumber(mView, centerName, centerNumber);
       
    74     }
       
    75 
       
    76     messageCenterName = new HbDataFormModelItem(HbDataFormModelItem::TextItem,
       
    77             LOC_SMS_CENTRE_NAME, 0);
       
    78 
       
    79     messageCenterName->setContentWidgetData("text", centerName);
       
    80         
       
    81     settingsmodel->appendDataFormItem(messageCenterName, settingsmodel->invisibleRootItem());
       
    82 
       
    83     messageCenterNumber = new HbDataFormModelItem(
       
    84         HbDataFormModelItem::TextItem, LOC_SMS_CENTRE_NUMBER, 0);
       
    85 
       
    86     messageCenterNumber->setContentWidgetData("text", centerNumber);
       
    87         
       
    88     settingsmodel->appendDataFormItem(messageCenterNumber, settingsmodel->invisibleRootItem());
       
    89 
       
    90     this->setModel(settingsmodel);
       
    91 }
       
    92 
       
    93 
       
    94 void MsgSMSCenterSettingsForm::commitChanges()
       
    95 {
       
    96 	   	   
       
    97 	   //commit changes
       
    98     if(mEdit1)
       
    99      mCenterName = mEdit1->text();
       
   100     
       
   101     if (mEdit2)
       
   102      mCenterNumber = mEdit2->text();
       
   103 
       
   104     if (mCenterName.isEmpty() || mCenterNumber.isEmpty()) {
       
   105         //if mCenterName or mCenterNumber is empty do not commit.
       
   106         return;
       
   107     }
       
   108 
       
   109     QDEBUG_WRITE("MsgSMSCenterSettingsForm::commitChanges");
       
   110     if (mView == -1) {
       
   111         mSettingEngine->addSmsMessageCenter(mCenterName, mCenterNumber);
       
   112     }
       
   113     else {
       
   114         mSettingEngine->editSmsMessageCenter(mCenterName, mCenterNumber, mView);
       
   115     }
       
   116     QDEBUG_WRITE("ex MsgSMSCenterSettingsForm::commitChanges");
       
   117     
       
   118 }
       
   119 
       
   120 void MsgSMSCenterSettingsForm::onItemShown(const QModelIndex& topLeft)
       
   121     {
       
   122     	
       
   123     	QDEBUG_WRITE("DataForm MsgSMSCenterSettingsForm::onItemShown");
       
   124     HbDataFormModelItem *itemData =
       
   125     static_cast<HbDataFormModel *> (model())->itemFromIndex(topLeft);
       
   126 
       
   127     if (itemData && itemData == messageCenterName && !mEdit1)
       
   128         {
       
   129         	QDEBUG_WRITE("messageCenterName updated..");
       
   130     mEdit1 = static_cast<HbLineEdit *>(this->dataFormViewItem(topLeft)->dataItemContentWidget());
       
   131          }
       
   132     else if (itemData && itemData == messageCenterNumber && !mEdit2)
       
   133                 {
       
   134                 	QDEBUG_WRITE("messageCenterNumber updated..");
       
   135     mEdit2 = static_cast<HbLineEdit *>(this->dataFormViewItem(topLeft)->dataItemContentWidget());
       
   136                 HbEditorInterface editorInterface(mEdit2);
       
   137                     editorInterface.setUpAsPhoneNumberEditor();
       
   138 
       
   139                         }
       
   140 
       
   141                     }