phonebookui/pbkcommonui/src/cntsettingsmodel.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 23 Jun 2010 18:02:44 +0300
changeset 46 efe85016a067
parent 37 fd64c38c277d
child 47 7cbcb2896f0e
permissions -rw-r--r--
Revision: 201023 Kit: 2010125

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  
*
*/

#include "cntsettingsmodel.h"
#include <cntuids.h>
#include <qstringlist.h>
#include <xqsettingskey.h>
#include "cntdebug.h"

CntSettingsModel::CntSettingsModel() :
HbDataFormModel()
{
    //create a model class    
    HbDataFormModelItem* ord = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, hbTrId("txt_phob_setlabel_name_display_order"));
    
    QStringList orderList;
    // This order should be maintained as per the UI spec
    orderList.append( hbTrId("txt_phob_setlabel_name_display_order_val_last_name") );
    orderList.append( hbTrId("txt_phob_setlabel_name_display_order_val_last_name_separator") );
    orderList.append( hbTrId("txt_phob_setlabel_name_display_order_val_first_nam") );
    
    ord->setContentWidgetData( "items", orderList );
    appendDataFormItem(ord, invisibleRootItem());
    mNameOrderkey = new XQSettingsKey(XQSettingsKey::TargetCentralRepository,
                             KCRUiContacts.iUid,
                             KCntNameOrdering);
    int settingValue = mSettings.readItemValue(*mNameOrderkey, XQSettingsManager::TypeInt).toInt();

    if (settingValue == CntOrderLastFirst) {
        ord->setContentWidgetData("currentIndex", 0 );
    } else if (settingValue == CntOrderLastCommaFirst) {
        ord->setContentWidgetData("currentIndex", 1 );
    } else if (settingValue == CntOrderFirstLast) {
        ord->setContentWidgetData("currentIndex", 2 );
    }
    
    connect(this, SIGNAL(dataChanged(QModelIndex , QModelIndex)), this, SLOT(handleDataChanged(QModelIndex , QModelIndex)));
}

CntSettingsModel::~CntSettingsModel()
{
    delete mNameOrderkey;
}

void CntSettingsModel::handleDataChanged(QModelIndex topLeft, QModelIndex bottomRight)
{
    Q_UNUSED(bottomRight)
    bool written(true);
            
    if (topLeft.row() == 0) {
        int selected = itemFromIndex(topLeft)->contentWidgetData( "currentIndex" ).toInt();
        if (selected == 0) {
            written = mSettings.writeItemValue(*mNameOrderkey, QVariant(CntOrderLastFirst));
        } else if (selected == 1) {
            written = mSettings.writeItemValue(*mNameOrderkey, QVariant(CntOrderLastCommaFirst));
        } else if (selected == 2) {
            written = mSettings.writeItemValue(*mNameOrderkey, QVariant(CntOrderFirstLast));
        }
        if (!written) {
            CNT_LOG_ARGS(QString("failed writting cenrep key"))
        }
    }
}