phonebookui/pbkcommonui/src/cntaddressviewitem.cpp
changeset 65 ae724a111993
parent 59 a642906a277a
equal deleted inserted replaced
59:a642906a277a 65:ae724a111993
    33 #include <xqaiwrequest.h>
    33 #include <xqaiwrequest.h>
    34 #include <xqservicerequest.h>
    34 #include <xqservicerequest.h>
    35 #include <xqappmgr.h>
    35 #include <xqappmgr.h>
    36 CntAddressViewItem::CntAddressViewItem(QGraphicsItem* aParent) :
    36 CntAddressViewItem::CntAddressViewItem(QGraphicsItem* aParent) :
    37     /*CntDetailViewItem(aParent),*/
    37     /*CntDetailViewItem(aParent),*/
    38     HbDataFormViewItem(aParent)
    38     HbDataFormViewItem(aParent),
       
    39     mAppManager(NULL),
       
    40     mRequest(NULL),
       
    41     mRequestPending(false)
    39 {
    42 {
    40 }
    43 }
    41 
    44 
    42 CntAddressViewItem::~CntAddressViewItem()
    45 CntAddressViewItem::~CntAddressViewItem()
    43 {
    46 {
       
    47     if(mAppManager)
       
    48     {
       
    49         delete mAppManager;
       
    50         mAppManager = NULL;
       
    51     }
       
    52     if(mRequest)
       
    53     {
       
    54         delete mRequest;
       
    55         mRequest = NULL;
       
    56     }
    44 }
    57 }
    45 
    58 
    46 HbAbstractViewItem* CntAddressViewItem::createItem()
    59 HbAbstractViewItem* CntAddressViewItem::createItem()
    47 {
    60 {
    48     return new CntAddressViewItem(*this);
    61     return new CntAddressViewItem(*this);
    90     return widget;
   103     return widget;
    91 }
   104 }
    92 
   105 
    93 void CntAddressViewItem::launchLocationPicker()
   106 void CntAddressViewItem::launchLocationPicker()
    94 {
   107 {
    95     XQApplicationManager *appManager = new XQApplicationManager();
   108     if( !mAppManager )
    96     XQAiwRequest* request = appManager->create("com.nokia.symbian", "ILocationPick", "pick()", true);
       
    97     if( request )
       
    98     {
   109     {
    99         QVariant retValue;
   110     	mAppManager = new XQApplicationManager();
   100         if( request->send( retValue ) )
       
   101         {
       
   102             handleLocationChange( retValue );
       
   103         }
       
   104         
       
   105         delete request;
       
   106     }
   111     }
   107     delete appManager;
   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     }
   108 }
   125 }
   109 
   126 
   110 void CntAddressViewItem::handleLocationChange(const QVariant& aValue)
   127 void CntAddressViewItem::handleLocationChange(const QVariant& aValue)
   111 {
   128 {
       
   129     mRequestPending = false;
   112     QLocationPickerItem selectedLocation = aValue.value<QLocationPickerItem>();
   130     QLocationPickerItem selectedLocation = aValue.value<QLocationPickerItem>();
   113     if( selectedLocation.mIsValid )
   131     if( selectedLocation.mIsValid )
   114     {
   132     {
   115         HbDataForm* form = static_cast<HbDataForm*>(itemView());
   133         HbDataForm* form = static_cast<HbDataForm*>(itemView());
   116         HbDataFormModel* model = static_cast<HbDataFormModel*>(form->model());
   134         HbDataFormModel* model = static_cast<HbDataFormModel*>(form->model());
   117         HbDataFormModelItem* item = model->itemFromIndex( modelIndex() );
       
   118     
   135     
   119         QModelIndex nextIndex = modelIndex().sibling( modelIndex().row() + 1 , modelIndex().column() );
   136         QModelIndex nextIndex = modelIndex().sibling( modelIndex().row() + 1 , modelIndex().column() );
   120         HbDataFormModelItem* street = model->itemFromIndex( nextIndex );
   137         HbDataFormModelItem* street = model->itemFromIndex( nextIndex );
   121         street->setContentWidgetData( "text", selectedLocation.mStreet );
   138         street->setContentWidgetData( "text", selectedLocation.mStreet );
   122         street->setContentWidgetData( "maxLength", CNT_STREET_MAXLENGTH );
   139         street->setContentWidgetData( "maxLength", CNT_STREET_MAXLENGTH );