phonebookui/pbkcommonui/src/cntaddressviewitem.cpp
changeset 61 d30183af6ca6
parent 53 e6aff7b69165
--- a/phonebookui/pbkcommonui/src/cntaddressviewitem.cpp	Wed Aug 11 09:06:35 2010 +0300
+++ b/phonebookui/pbkcommonui/src/cntaddressviewitem.cpp	Mon Aug 23 16:06:28 2010 +0300
@@ -35,12 +35,25 @@
 #include <xqappmgr.h>
 CntAddressViewItem::CntAddressViewItem(QGraphicsItem* aParent) :
     /*CntDetailViewItem(aParent),*/
-    HbDataFormViewItem(aParent)
+    HbDataFormViewItem(aParent),
+    mAppManager(NULL),
+    mRequest(NULL),
+    mRequestPending(false)
 {
 }
 
 CntAddressViewItem::~CntAddressViewItem()
 {
+    if(mAppManager)
+    {
+        delete mAppManager;
+        mAppManager = NULL;
+    }
+    if(mRequest)
+    {
+        delete mRequest;
+        mRequest = NULL;
+    }
 }
 
 HbAbstractViewItem* CntAddressViewItem::createItem()
@@ -92,29 +105,33 @@
 
 void CntAddressViewItem::launchLocationPicker()
 {
-    XQApplicationManager *appManager = new XQApplicationManager();
-    XQAiwRequest* request = appManager->create("com.nokia.symbian", "ILocationPick", "pick()", true);
-    if( request )
+    if( !mAppManager )
     {
-        QVariant retValue;
-        if( request->send( retValue ) )
-        {
-            handleLocationChange( retValue );
-        }
-        
-        delete request;
+    	mAppManager = new XQApplicationManager();
+    }
+    if(!mRequest)
+    {	
+    	mRequest = mAppManager->create("com.nokia.symbian", "ILocationPick", "pick()", true);
+    	mRequest->setSynchronous(false);
+    	connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleLocationChange(const QVariant&)));
     }
-    delete appManager;
+    if(!mRequestPending)
+    {
+        if( mRequest->send() )
+    	{
+            mRequestPending = true;
+    	}
+    }
 }
 
 void CntAddressViewItem::handleLocationChange(const QVariant& aValue)
 {
+    mRequestPending = false;
     QLocationPickerItem selectedLocation = aValue.value<QLocationPickerItem>();
     if( selectedLocation.mIsValid )
     {
         HbDataForm* form = static_cast<HbDataForm*>(itemView());
         HbDataFormModel* model = static_cast<HbDataFormModel*>(form->model());
-        HbDataFormModelItem* item = model->itemFromIndex( modelIndex() );
     
         QModelIndex nextIndex = modelIndex().sibling( modelIndex().row() + 1 , modelIndex().column() );
         HbDataFormModelItem* street = model->itemFromIndex( nextIndex );