예제 #1
0
void MyWriteMsg::sendMsg()
{
	try
	{
		checkInput();

		QList<Message> & msgs = getMsgs();

		server->sendMessages(msgs);

		MessageService * msgServer = new MessageService;
		for (int i = 0; i < msgs.length(); ++i)
		{
			msgs[i].setSenderNum(server->getPhoneNum());
			msgs[i].setTime(QDateTime::currentDateTime());
			msgs[i].setType(Message::SENT);
			msgServer->saveMsg(msgs[i]);
		}
		delete msgServer;

		msgs.clear();
		delete &msgs;
		this->accept();
	}
	CATCH_BLOCKS
}
예제 #2
0
void MyWriteMsg::reject()
{
	try
	{
		if (self->plainTextEdit->toPlainText().trimmed().isEmpty())
		{
			QDialog::reject();
			return;
		}

		if (QUESTION(utf8("提醒"), utf8("是否存为草稿?")) == QMessageBox::No)
		{
			QDialog::reject();
			return;
		}

		Message msg;
		msg.setContent(self->plainTextEdit->toPlainText());
		msg.setTime(QDateTime::currentDateTime());
		msg.setType(Message::DRAFT);

		MessageService * msgServer = new MessageService;
		msgServer->saveMsg(msg);
		delete msgServer;

		QDialog::reject();
	}
	CATCH_BLOCKS
}
예제 #3
0
void MyWriteMsg::sendTimedMsg()
{
	try
	{
		checkInput();

		MySetTime * setTime = new MySetTime(this);
		if (setTime->exec() != QDialog::Accepted)
		{
			setTime->deleteLater();
			return;
		}
		setTime->deleteLater();
	
		QDateTime chosenTime = setTime->getTime();

		QList<Message> & msgs = getMsgs();
		MessageService * msgServer = new MessageService;
		for (int i = 0; i < msgs.length(); ++i)
		{
			msgs[i].setSenderNum(server->getPhoneNum());
			msgs[i].setTime(chosenTime);
			msgs[i].setType(Message::TIMED);
			msgServer->saveMsg(msgs[i]);
		}
		delete msgServer;

		msgs.clear();
		delete &msgs;
		this->accept();
	}
	CATCH_BLOCKS
}
예제 #4
0
bool MessageService::test() {
    MessageService messages;
    
    bool result = true;
    
    int messageTestA = 0;
    std::string testBString;
    
    messages.subscribe("testA", [&](StringMap p){messageTestA++;});
    messages.subscribe("testB", [&](StringMap p){testBString = p.find("a")->second;});
    
    StringMap emptyParams;
    StringMap testBParams;
    
    testBParams.insert({"a", "paramA"});
    
    messages.publish("testA", emptyParams);
    messages.publish("testB", testBParams);
    messages.publish("testC", emptyParams);
    
    if(messageTestA != 1) {
        printf("Var messageTestA, expected: %d actual: %d\n", 1, messageTestA);
        result = false;
    }
    
    if(testBString.compare("paramA") != 0) {
        printf("Var testBString, expected: %s actual: %s\n", "paramA", testBString.c_str());
        result = false;
    }
    
    return result;
}
예제 #5
0
void MainScreen::workDone()
{
	if(m_worker)
	{
		delete m_worker;
		m_worker = NULL;
	}
	if(!m_cancelled)
	{
		AccountService* as = new AccountService();
		Account account = as->defaultAccount(Service::Messages);

		MessageSearchFilter filter;
		filter.setAccountId(account.id());
		MessageService messageService;

		QList<MessageFolder> folders = messageService.folders(account.id());
		MessageFolder sentFolder;
		for(int i = 0; i < folders.size(); ++i)
		{
			if(folders[i].type() == MessageFolder::Sent)
			{
				sentFolder = folders[i];
				break;
			}
		}

		filter.setFolderId(sentFolder.id());
		filter.addSearchCriteria(SearchFilterCriteria::Subject, m_subject);

		QList<Message> messagesToDelete = messageService.searchLocal(account.id(), filter);
		messagesToDelete.append(messageService.searchRemote(account.id(), filter));

		for(int i = 0; i < messagesToDelete.size(); ++i)
		{
			messageService.remove(account.id(), messagesToDelete[i].id());
		}



		m_mainPage->setProperty("allDone", true);
	}
	m_mainPage->setProperty("workInProgress", false);
}
예제 #6
0
InterfaceItemBase::InterfaceItemBase (IEventReceiver& evtReceiver, IRTObject* parent, std::string name, int localId, int idx, Address ownAddress, Address peerAddress)
: AbstractMessageReceiver(parent, ownAddress, name),
  m_idx(idx),
  m_localId(localId),
  m_actorPath(name),
  m_peerAddress(peerAddress),
  m_ownMsgReceiver(RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(ownAddress.m_threadID)),
  m_peerMsgReceiver(peerAddress.isValid()? RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(peerAddress.m_threadID): 0),
  m_eventReceiver(&evtReceiver)
{
	if (getAddress().isValid() && m_ownMsgReceiver->isMsgService()) {
		MessageService* ms = static_cast<MessageService*>(m_ownMsgReceiver);
		// register at the own dispatcher to receive messages
		ms->getMessageDispatcher().addMessageReceiver(*this);
	}
	if (parent) {
		m_actorPath = parent->getInstancePath();
	}
}
void ApplicationUI::SendSMSMessage(QString ToStr, QString BodyStr) {

	MessageService messageService;
	AccountService accountService;

	//Get the SMS/MMS account
	QList<Account> accountList = accountService.accounts(Service::Messages,
			"sms-mms");
	AccountKey accountId = accountList.first().id();

	//Create a conversation  because sms/mms chats most of the time is a conversation
	ConversationBuilder* conversationBuilder = ConversationBuilder::create();
	conversationBuilder->accountId(accountId);

	// Create a contact to whom you want to send sms/mms.
	int contactKey = -1;
	MessageContact recipient = MessageContact(contactKey, MessageContact::To,
			ToStr, ToStr);
	QList<MessageContact> participants;
	participants.append(recipient);

	//Add the contact to the conversation
	conversationBuilder->participants(participants);
	Conversation conversation = *conversationBuilder;
	ConversationKey conversationId = messageService.save(accountId,
			conversation);

	//Create a message Builder for sms/mms
	MessageBuilder* messageBuilder = MessageBuilder::create(accountId);
	messageBuilder->conversationId(conversationId);
	messageBuilder->addRecipient(recipient);
	messageBuilder->addAttachment(
			Attachment("text/plain", "body.txt", BodyStr));
	Message message;
	message = *messageBuilder;

	//Sending SMS/MMS
	messageService.send(accountId, message);
	ShowToast("SMS sent successfully");
}
예제 #8
0
void MainScreen::doSend()
{
	QList<int> order = randomizeBuyers();
	//QList<Participant> receivers(m_participants.size());

	typedef QPair<Participant, Participant> ParticipantPair;
	QList<ParticipantPair> pairs;

	bool success = false;
	while(!success)
	{
	  bool errorOccurred = false;
	  for(int i = 0; !errorOccurred && i < m_participants.size(); ++i)
	  {
	          // refactor the drafting out into it's own class.  The Input reader
	          // should not know about how drafting occurs
		  	  int j = order[i];

	          Participant buyer(m_participants.value(j)["name"].value<QString>(), m_participants.value(j)["email"].value<QString>(), m_participants.value(j)["exl"].value<QStringList>());
	          Participant receiver(m_participants.value(i)["name"].value<QString>(), m_participants.value(i)["email"].value<QString>(), m_participants.value(i)["exl"].value<QStringList>());
	          if(!IsValidPair(buyer, receiver))
	          {
	            errorOccurred = true;
	          }
	          else
	          {
	        	  pairs.append(ParticipantPair(buyer,receiver));
	          }
	  }

	  if(errorOccurred)
	  {

		  order = randomizeBuyers();
			pairs.clear();
	  }
	  else
	  {
		success = true;
	  }
	}

	AccountService* as = new AccountService();
	Account account = as->defaultAccount(Service::Messages);

	MessageService ms;
	m_subject = m_mainPage->findChild<TextField*>("emailSubject")->text();
	QString body = "<p>" + m_mainPage->findChild<TextArea*>("emailBody")->text() + "</p>";

	for(int i = 0; i < pairs.size(); ++i)
	{
	  QString greeting = "<p>Hi " + pairs[i].first.getName() + "!</p>";
	  QString youGot = "You Received: " + pairs[i].second.getName();
		MessageBuilder* builder = MessageBuilder::create(account.id());
		MessageContact rto = MessageContact(-1,MessageContact::To,pairs[i].first.getName(), pairs[i].first.getEmail());
		QString fullMsg = greeting + body + youGot;
		QByteArray bodyData = fullMsg.toAscii();
		builder->subject(m_subject);
		bool added;
		builder->addRecipient(rto,&added);
		builder->body(MessageBody::Html,bodyData);
		Message message = *builder;

/*
	    connect(&m_messageService, SIGNAL( messageUpdated(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey, bb::pim::message::MessageUpdate) ),
	            &m_ml,
	            SLOT( messageUpdate(bb::pim::account::AccountKey, bb::pim::message::ConversationKey, bb::pim::message::MessageKey, bb::pim::message::MessageUpdate) ) );
*/


		/*MessageKey mk = */ms.send(account.id(), message);
		/*Message sentMessage = ms.message(account.id(), mk);
		m_ml.setAk(account.id());
		m_ml.setMk(sentMessage.id());
		m_ml.setCk(sentMessage.conversationId());
		m_ml.setMsg(sentMessage);*/
		//********************************************************
	    // Set created root object as the application scene
	    //m_navPane->setBackButtonsVisible(false);
	}

	m_worker->exit();

}