phonebookengines/cntactions/src/cntaction.cpp
changeset 59 a642906a277a
parent 47 7cbcb2896f0e
child 65 ae724a111993
equal deleted inserted replaced
47:7cbcb2896f0e 59:a642906a277a
   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     //QContactType == TypeGroup
   172     m_request = NULL;
   172     if (QContactType::TypeGroup == m_contact.type()) {
   173     m_request = appMng.create(interface, operation, false); // not embedded
   173         QContactPhoneNumber conferenceCall = m_contact.detail<QContactPhoneNumber>();
   174     if (!isCallAction) {
   174         args << conferenceCall.number() << m_contact.localId() << m_contact.displayLabel();
   175         if (!m_request) {
   175         
   176             emitResult(GeneralError, retValue);
   176         // TODO remove once call action works
   177             return;
   177         snd << conferenceCall.number() << m_contact.localId() << m_contact.displayLabel();
   178         }
   178         snd.send(retValue);
       
   179         emitResult(snd.latestError(), retValue);
   179     }
   180     }
   180 	
   181     //QContactType == TypeContact
   181     //detail exist use it
   182     //detail exist use it
   182 	if (m_detail.definitionName() == QContactPhoneNumber::DefinitionName)
   183     else if (m_detail.definitionName() == QContactPhoneNumber::DefinitionName) {
   183 	{
       
   184 		const QContactPhoneNumber &phoneNumber = static_cast<const QContactPhoneNumber &>(m_detail);
   184 		const QContactPhoneNumber &phoneNumber = static_cast<const QContactPhoneNumber &>(m_detail);
   185 		
   185 		
   186 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   186 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   187 	    
   187 	    
   188 		// TODO remove once call action works
   188         snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   189 		if (isCallAction) {
   189         snd.send(retValue);
   190             snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   190         emitResult(snd.latestError(), retValue);
   191             emitResult(snd.send(retValue), retValue);
   191 	}
   192 	    } else {
   192     //QContactType == TypeContact
   193 	       m_request->setArguments(args);
   193     //if no detail, pick preferred
   194 	       m_request->setSynchronous(true);
   194 	else if (m_detail.isEmpty())
   195            emitResult(m_request->send(retValue), retValue);
       
   196 	    }
       
   197 	}
       
   198 	
       
   199 	//if no detail, pick preferred
       
   200 	else if(m_detail.isEmpty())
       
   201 	{
   195 	{
   202 		QContactDetail detail = m_contact.preferredDetail(m_actionName);
   196 		QContactDetail detail = m_contact.preferredDetail(m_actionName);
   203 		QContactPhoneNumber phoneNumber;
   197 		QContactPhoneNumber phoneNumber;
   204 	
   198 	
   205 		//if preferred is empty pick first phonenumber
   199 		//if preferred is empty pick first phonenumber
   206 		if(detail.isEmpty())
   200 		if (detail.isEmpty()) {
   207 		{
       
   208 			phoneNumber = m_contact.detail<QContactPhoneNumber>();
   201 			phoneNumber = m_contact.detail<QContactPhoneNumber>();
   209 		}
   202 		}
   210 		
   203 		
   211 		//if not empty, cast detail to phonenumber
   204 		//if not empty, cast detail to phonenumber
   212 		else
   205 		else {
   213 		{
       
   214 			phoneNumber = static_cast<QContactPhoneNumber>(detail);
   206 			phoneNumber = static_cast<QContactPhoneNumber>(detail);
   215 		}
   207 		}
   216 		
   208 		
   217 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   209 		args << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   218 
   210 
   219         // TODO remove once call action works
   211         snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   220         if (isCallAction) {
   212         snd.send(retValue);
   221             snd << phoneNumber.number() << m_contact.localId() << m_contact.displayLabel();
   213         emitResult(snd.latestError(), retValue);
   222             emitResult(snd.send(retValue), retValue);
   214 	}
   223         } else {
       
   224             m_request->setArguments(args);
       
   225             m_request->setSynchronous(true);
       
   226             emitResult(m_request->send(retValue), retValue);
       
   227         }
       
   228 	}
       
   229 	
       
   230 	//else return an error
   215 	//else return an error
   231 	else
   216 	else {
   232 	{
       
   233 		emitResult(GeneralError, retValue);
   217 		emitResult(GeneralError, retValue);
   234 	}
   218 	}
   235 }
   219 }
   236 
   220 
   237 //emit the result to the client
   221 //emit the result to the client
   242 	m_result.insert("ReturnValue", retValue);
   226 	m_result.insert("ReturnValue", retValue);
   243 	if (m_request) {
   227 	if (m_request) {
   244         m_result.insert("XQAiwRequest Error", m_request->lastError());
   228         m_result.insert("XQAiwRequest Error", m_request->lastError());
   245 	}
   229 	}
   246 	
   230 	
   247 	if (errorCode == 0){
   231 	if (errorCode == 0) {
   248 		m_state = QContactAction::FinishedState;
   232 		m_state = QContactAction::FinishedState;
   249 	}
   233 	}
   250 	
   234 	
   251 	else{
   235 	else {
   252 		m_state = QContactAction::FinishedWithErrorState;
   236 		m_state = QContactAction::FinishedWithErrorState;
   253 	}
   237 	}
   254 	
   238 	
   255 	//emit progress(state, m_result);
   239 	//emit progress(state, m_result);
   256 	emit stateChanged(m_state);
   240 	emit stateChanged(m_state);