phonebookengines/cntactions/src/cntaction.cpp
changeset 50 77bc263e1626
parent 47 7cbcb2896f0e
child 53 e6aff7b69165
equal deleted inserted replaced
49:74b30151afd6 50:77bc263e1626
   114     ret.setImplementationVersion(m_implementationVersion);
   114     ret.setImplementationVersion(m_implementationVersion);
   115     return ret;
   115     return ret;
   116 }
   116 }
   117 
   117 
   118 
   118 
   119 bool CntAction::invokeAction(const QContact& contact, const QContactDetail& detail, const QVariantMap& /*parameters*/)
   119 bool CntAction::invokeAction(const QContact& contact, const QContactDetail& detail, const QVariantMap& data)
   120 {
   120 {
   121 	m_contact = contact;
   121 	m_contact = contact;
   122 	m_detail  = detail;
   122 	m_detail  = detail;
       
   123 	m_data = data;
   123 	
   124 	
   124 	QTimer::singleShot(1, this, SLOT(performAction()));
   125 	QTimer::singleShot(1, this, SLOT(performAction()));
   125 	m_state = QContactAction::ActiveState;
   126 	m_state = QContactAction::ActiveState;
   126 	return true;
   127 	return true;
   127 }
   128 }
   157 }
   158 }
   158 
   159 
   159 //common code to perform a call, videocall and message action
   160 //common code to perform a call, videocall and message action
   160 void CntAction::performNumberAction(const QString &interface, const QString &operation)
   161 void CntAction::performNumberAction(const QString &interface, const QString &operation)
   161 {
   162 {
   162     XQApplicationManager appMng;
       
   163     QVariantList args;
   163     QVariantList args;
   164     QVariant retValue;
   164     QVariant retValue;
   165     
   165     
   166     // TODO: Using XQApplicationManager is not working with calls
   166     // TODO: Using XQApplicationManager is not working with calls
   167     // The factory method cannot create a request. Find out why
   167     // The factory method cannot create a request. Find out why
   168     bool isCallAction = m_actionName == "call";
   168     bool isCallAction = (m_actionName == "call" || m_actionName == "videocall");
   169     XQServiceRequest snd(interface, operation, false);
   169     XQServiceRequest snd(interface, operation, false);
   170 
   170 
   171     delete m_request;
   171     delete m_request;
   172     m_request = NULL;
   172     m_request = NULL;
   173     m_request = appMng.create(interface, operation, false); // not embedded
   173     m_request = m_AppManager.create(interface, operation, false); // not embedded
       
   174     
   174     if (!isCallAction) {
   175     if (!isCallAction) {
   175         if (!m_request) {
   176         if (!m_request) {
   176             emitResult(GeneralError, retValue);
   177             emitResult(GeneralError, retValue);
   177             return;
   178             return;
   178         }
   179         }
   179     }
   180     }
   180 	
   181     
       
   182     //QContactType == TypeGroup
       
   183     if (QContactType::TypeGroup == m_contact.type()) {
       
   184         QContactPhoneNumber conferenceCall = m_contact.detail<QContactPhoneNumber>();
       
   185         args << conferenceCall.number() << m_contact.localId() << m_contact.displayLabel();
       
   186         
       
   187         // TODO remove once call action works
       
   188         snd << conferenceCall.number() << m_contact.localId() << m_contact.displayLabel();
       
   189         snd.send(retValue);
       
   190         emitResult(snd.latestError(), retValue);
       
   191     }
       
   192     //QContactType == TypeContact
   181     //detail exist use it
   193     //detail exist use it
   182 	if (m_detail.definitionName() == QContactPhoneNumber::DefinitionName)
   194     else if (m_detail.definitionName() == QContactPhoneNumber::DefinitionName) {
   183 	{
       
   184 		const QContactPhoneNumber &phoneNumber = static_cast<const QContactPhoneNumber &>(m_detail);
   195 		const QContactPhoneNumber &phoneNumber = static_cast<const QContactPhoneNumber &>(m_detail);
   185 		
   196 		
   186 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   197 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   187 	    
   198 	    
   188 		// TODO remove once call action works
   199 		// TODO remove once call action works
   189 		if (isCallAction) {
   200 		if (isCallAction) {
   190             snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   201             snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   191             emitResult(snd.send(retValue), retValue);
   202             snd.send(retValue);
   192 	    } else {
   203             emitResult(snd.latestError(), retValue);
       
   204 	    } 
       
   205 		else {
   193 	       m_request->setArguments(args);
   206 	       m_request->setArguments(args);
   194 	       m_request->setSynchronous(true);
   207 	       m_request->send(retValue);
   195            emitResult(m_request->send(retValue), retValue);
   208            emitResult(m_request->lastError(), retValue);
   196 	    }
   209 	    }
   197 	}
   210 	}
   198 	
   211     //QContactType == TypeContact
   199 	//if no detail, pick preferred
   212     //if no detail, pick preferred
   200 	else if(m_detail.isEmpty())
   213 	else if (m_detail.isEmpty())
   201 	{
   214 	{
   202 		QContactDetail detail = m_contact.preferredDetail(m_actionName);
   215 		QContactDetail detail = m_contact.preferredDetail(m_actionName);
   203 		QContactPhoneNumber phoneNumber;
   216 		QContactPhoneNumber phoneNumber;
   204 	
   217 	
   205 		//if preferred is empty pick first phonenumber
   218 		//if preferred is empty pick first phonenumber
   206 		if(detail.isEmpty())
   219 		if (detail.isEmpty()) {
   207 		{
       
   208 			phoneNumber = m_contact.detail<QContactPhoneNumber>();
   220 			phoneNumber = m_contact.detail<QContactPhoneNumber>();
   209 		}
   221 		}
   210 		
   222 		
   211 		//if not empty, cast detail to phonenumber
   223 		//if not empty, cast detail to phonenumber
   212 		else
   224 		else {
   213 		{
       
   214 			phoneNumber = static_cast<QContactPhoneNumber>(detail);
   225 			phoneNumber = static_cast<QContactPhoneNumber>(detail);
   215 		}
   226 		}
   216 		
   227 		
   217 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   228 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   218 
   229 
   219         // TODO remove once call action works
   230         // TODO remove once call action works
   220         if (isCallAction) {
   231         if (isCallAction) {
   221             snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   232             snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   222             emitResult(snd.send(retValue), retValue);
   233             snd.send(retValue);
   223         } else {
   234             emitResult(snd.latestError(), retValue);
       
   235         }
       
   236         else {
   224             m_request->setArguments(args);
   237             m_request->setArguments(args);
   225             m_request->setSynchronous(true);
   238             m_request->send(retValue);
   226             emitResult(m_request->send(retValue), retValue);
   239             emitResult(m_request->lastError(), retValue);
   227         }
   240         }
   228 	}
   241 	}
   229 	
       
   230 	//else return an error
   242 	//else return an error
   231 	else
   243 	else {
   232 	{
       
   233 		emitResult(GeneralError, retValue);
   244 		emitResult(GeneralError, retValue);
   234 	}
   245 	}
   235 }
   246 }
   236 
   247 
   237 //emit the result to the client
   248 //emit the result to the client
   242 	m_result.insert("ReturnValue", retValue);
   253 	m_result.insert("ReturnValue", retValue);
   243 	if (m_request) {
   254 	if (m_request) {
   244         m_result.insert("XQAiwRequest Error", m_request->lastError());
   255         m_result.insert("XQAiwRequest Error", m_request->lastError());
   245 	}
   256 	}
   246 	
   257 	
   247 	if (errorCode == 0){
   258 	if (errorCode == 0) {
   248 		m_state = QContactAction::FinishedState;
   259 		m_state = QContactAction::FinishedState;
   249 	}
   260 	}
   250 	
   261 	
   251 	else{
   262 	else {
   252 		m_state = QContactAction::FinishedWithErrorState;
   263 		m_state = QContactAction::FinishedWithErrorState;
   253 	}
   264 	}
   254 	
   265 	
   255 	//emit progress(state, m_result);
   266 	//emit progress(state, m_result);
   256 	emit stateChanged(m_state);
   267 	emit stateChanged(m_state);