phonebookui/cntcommonui/contacteditors/cntaddressviewitem.cpp
changeset 72 6abfb1094884
parent 61 d30183af6ca6
equal deleted inserted replaced
67:59984e68247d 72:6abfb1094884
       
     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:
       
    15 *
       
    16 */
       
    17 #include "cntaddressviewitem.h"
       
    18 #include "cntdetailmodelitem.h"
       
    19 #include "cntdetailconst.h"
       
    20 
       
    21 #include <qcontactdetail.h>
       
    22 #include <qcontactaddress.h>
       
    23 #include <hbdataform.h>
       
    24 #include <hbdataformmodel.h>
       
    25 #include <hbdataformmodelitem.h>
       
    26 #include <hbstyleloader.h>
       
    27 #include <hbpushbutton.h>
       
    28 #include <qgraphicslinearlayout.h>
       
    29 #include <hbwidget.h>
       
    30 #include <hbtextitem.h>
       
    31 
       
    32 #include "qlocationpickeritem.h"
       
    33 #include <xqaiwrequest.h>
       
    34 #include <xqservicerequest.h>
       
    35 #include <xqappmgr.h>
       
    36 CntAddressViewItem::CntAddressViewItem(QGraphicsItem* aParent) :
       
    37     /*CntDetailViewItem(aParent),*/
       
    38     HbDataFormViewItem(aParent),
       
    39     mAppManager(NULL),
       
    40     mRequest(NULL),
       
    41     mRequestPending(false)
       
    42 {
       
    43 }
       
    44 
       
    45 CntAddressViewItem::~CntAddressViewItem()
       
    46 {
       
    47     if(mAppManager)
       
    48     {
       
    49         delete mAppManager;
       
    50         mAppManager = NULL;
       
    51     }
       
    52     if(mRequest)
       
    53     {
       
    54         delete mRequest;
       
    55         mRequest = NULL;
       
    56     }
       
    57 }
       
    58 
       
    59 HbAbstractViewItem* CntAddressViewItem::createItem()
       
    60 {
       
    61     return new CntAddressViewItem(*this);
       
    62 }
       
    63 
       
    64 bool CntAddressViewItem::canSetModelIndex( const QModelIndex &index ) const 
       
    65 { 
       
    66     HbDataFormModelItem::DataItemType itemType = 
       
    67         static_cast<HbDataFormModelItem::DataItemType>( 
       
    68         index.data(HbDataFormModelItem::ItemTypeRole).toInt() ); 
       
    69 
       
    70     if( itemType == HbDataFormModelItem::CustomItemBase )       
       
    71     {  
       
    72         return true; 
       
    73     } 
       
    74     else 
       
    75     { 
       
    76         return false; 
       
    77     } 
       
    78 
       
    79 }
       
    80 
       
    81 HbWidget* CntAddressViewItem::createCustomWidget()
       
    82 {
       
    83     HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( 
       
    84               modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
       
    85     
       
    86     HbWidget* widget = NULL;
       
    87     
       
    88     if( itemType ==  HbDataFormModelItem::CustomItemBase )
       
    89     {
       
    90         HbPushButton* locationButton = new HbPushButton(this);
       
    91         
       
    92         // Naming UI components for automation testability
       
    93         locationButton->setObjectName("Select location button");
       
    94         locationButton->setText( hbTrId("txt_phob_button_select_location") );
       
    95         locationButton->setTextAlignment( Qt::AlignCenter );
       
    96         locationButton->setContentsMargins(0,0,0,0);
       
    97     
       
    98         connect(locationButton, SIGNAL(clicked()), this, SLOT(launchLocationPicker()));
       
    99     
       
   100         widget = locationButton;
       
   101         
       
   102     }
       
   103     return widget;
       
   104 }
       
   105 
       
   106 void CntAddressViewItem::launchLocationPicker()
       
   107 {
       
   108     if( !mAppManager )
       
   109     {
       
   110     	mAppManager = new XQApplicationManager();
       
   111     }
       
   112     if(!mRequest)
       
   113     {	
       
   114     	mRequest = mAppManager->create("com.nokia.symbian", "ILocationPick", "pick()", true);
       
   115     	mRequest->setSynchronous(false);
       
   116     	connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleLocationChange(const QVariant&)));
       
   117     }
       
   118     if(!mRequestPending)
       
   119     {
       
   120         if( mRequest->send() )
       
   121     	{
       
   122             mRequestPending = true;
       
   123     	}
       
   124     }
       
   125 }
       
   126 
       
   127 void CntAddressViewItem::handleLocationChange(const QVariant& aValue)
       
   128 {
       
   129     mRequestPending = false;
       
   130     QLocationPickerItem selectedLocation = aValue.value<QLocationPickerItem>();
       
   131     if( selectedLocation.mIsValid )
       
   132     {
       
   133         HbDataForm* form = static_cast<HbDataForm*>(itemView());
       
   134         HbDataFormModel* model = static_cast<HbDataFormModel*>(form->model());
       
   135     
       
   136         QModelIndex nextIndex = modelIndex().sibling( modelIndex().row() + 1 , modelIndex().column() );
       
   137         HbDataFormModelItem* street = model->itemFromIndex( nextIndex );
       
   138         street->setContentWidgetData( "text", selectedLocation.mStreet );
       
   139         street->setContentWidgetData( "maxLength", CNT_STREET_MAXLENGTH );
       
   140 
       
   141         nextIndex = modelIndex().sibling( modelIndex().row() + 2 , modelIndex().column() );
       
   142 
       
   143         HbDataFormModelItem* postal =  model->itemFromIndex( nextIndex );
       
   144         postal->setContentWidgetData( "text", selectedLocation.mPostalCode );
       
   145         postal->setContentWidgetData( "maxLength", CNT_POSTCODE_MAXLENGTH );
       
   146         
       
   147         nextIndex = modelIndex().sibling( modelIndex().row() + 3 , modelIndex().column() );
       
   148         HbDataFormModelItem* locality =  model->itemFromIndex( nextIndex );
       
   149         locality->setContentWidgetData( "text", selectedLocation.mCity );
       
   150         locality->setContentWidgetData( "maxLength", CNT_LOCALITY_MAXLENGTH );
       
   151         
       
   152         nextIndex = modelIndex().sibling( modelIndex().row() + 4 , modelIndex().column() );
       
   153         HbDataFormModelItem* province =  model->itemFromIndex( nextIndex );
       
   154         province->setContentWidgetData( "text", selectedLocation.mState );
       
   155         province->setContentWidgetData( "maxLength", CNT_REGION_MAXLENGTH );
       
   156         
       
   157         nextIndex = modelIndex().sibling( modelIndex().row() + 5 , modelIndex().column() );
       
   158         HbDataFormModelItem* country =  model->itemFromIndex( nextIndex );
       
   159         country->setContentWidgetData( "text", selectedLocation.mCountry );
       
   160         country->setContentWidgetData( "maxLength", CNT_COUNTRY_MAXLENGTH );
       
   161         
       
   162 
       
   163     }
       
   164    
       
   165 }
       
   166 
       
   167 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem)
       
   168 
       
   169 // End of File