Exemplo n.º 1
0
bool QMessageService::send(QMessage &message)
{
	if (d_ptr->_active) {
		return false;
	}
	
	d_ptr->_active = true;
	d_ptr->_error = QMessageManager::NoError;
	
    bool retVal = true;	
    
    d_ptr->_state = QMessageService::ActiveState;
    emit stateChanged(d_ptr->_state);
    
    QMessageAccountId accountId = message.parentAccountId();
    QMessage::Type msgType = QMessage::NoType;

    // Check message type
    if (message.type() == QMessage::AnyType || message.type() == QMessage::NoType) {
        QMessage::TypeFlags types = QMessage::NoType;
        if (accountId.isValid()) {
            // ParentAccountId was defined => Message type can be read
            // from parent account
            QMessageAccount account = QMessageAccount(accountId);
            QMessage::TypeFlags types = account.messageTypes();
            if (types & QMessage::Sms) {
                msgType = QMessage::Sms;
            } else if (types & QMessage::Mms) {
                msgType = QMessage::Mms;
            } else if (types & QMessage::Email) {
                msgType = QMessage::Email;
            }
        }
        if (msgType == QMessage::NoType) {
            d_ptr->_error = QMessageManager::ConstraintFailure;
            retVal = false;
        }
    }

    if (retVal) {
        // Check account
        if (!accountId.isValid()) {
            accountId = QMessageAccount::defaultAccount(message.type());
            if (!accountId.isValid()) {
                d_ptr->_error = QMessageManager::InvalidId;
                retVal = false;
            }
        }
    }

    QMessageAccount account(accountId);
    if (retVal) {
        // Check account/message type compatibility
        if (!(account.messageTypes() & message.type()) && (msgType == QMessage::NoType)) {
            d_ptr->_error = QMessageManager::ConstraintFailure;
            retVal = false;
        }
    }
    
    if (retVal) {
        // Check recipients
        QMessageAddressList recipients = message.to() + message.bcc() + message.cc();
        if (recipients.isEmpty()) {
            d_ptr->_error = QMessageManager::ConstraintFailure;
            return false;
        }
    }
    
    if (retVal) {
        QMessage outgoing(message);

        // Set default account if unset
        if (!outgoing.parentAccountId().isValid()) {
            outgoing.setParentAccountId(accountId);
        }

        if (outgoing.type() == QMessage::AnyType || outgoing.type() == QMessage::NoType) {
            outgoing.setType(msgType);
        }

        if (account.messageTypes() & QMessage::Sms) {
            retVal = d_ptr->sendSMS(outgoing);
        } else if (account.messageTypes() & QMessage::Mms) {
            retVal = d_ptr->sendMMS(outgoing);
        } else if (account.messageTypes() & QMessage::Email) {
            retVal = d_ptr->sendEmail(outgoing);
        }

        QMessagePrivate* privateMessage = QMessagePrivate::implementation(message);
        privateMessage->_id = outgoing.id();
    }
    
    if (retVal == false) {
        d_ptr->setFinished(retVal);
    }
    return retVal;
}
Exemplo n.º 2
0
bool QMessageStore::addMessage(QMessage *m)
{
    bool retVal = true;

    QMessageAccountId accountId = m->parentAccountId();
    QMessage::Type msgType = QMessage::NoType;

    // Check message type
    if (m->type() == QMessage::AnyType || m->type() == QMessage::NoType) {
        if (accountId.isValid()) {
            // ParentAccountId was defined => Message type can be read
            // from parent account
            QMessageAccount account = QMessageAccount(accountId);
            QMessage::TypeFlags types = account.messageTypes();
            if (types & QMessage::Sms) {
                msgType = QMessage::Sms;
            } else if (account.messageTypes() & QMessage::InstantMessage) {
                msgType = QMessage::InstantMessage;
            } else if (types & QMessage::Mms) {
                msgType = QMessage::Mms;
            } else if (types & QMessage::Email) {
                msgType = QMessage::Email;
            }
        }
        if (msgType == QMessage::NoType) {
            retVal = false;
	    d_ptr->error = QMessageManager::ConstraintFailure;
        }
    }

    if (retVal) {
        // Check account
        if (!accountId.isValid()) {
            accountId = QMessageAccount::defaultAccount(m->type());
            if (!accountId.isValid()) {
		d_ptr->error = QMessageManager::ConstraintFailure;
                retVal = false;
            }
        }
    }

    QMessageAccount account(accountId);
    if (retVal) {
        // Check account/message type compatibility
        if (!(account.messageTypes() & m->type()) && (msgType == QMessage::NoType)) {
            retVal = false;
	    d_ptr->error = QMessageManager::ConstraintFailure;
        }
    }

    if (retVal) {
        // Set default account if unset
        if (!m->parentAccountId().isValid()) {
            m->setParentAccountId(accountId);
        }
        if (account.messageTypes() & QMessage::Sms) {
	    retVal = StorageEngine::instance()->addMessage(*m);
        } else if (account.messageTypes() & QMessage::InstantMessage) {
            retVal = false; //TODO:
	    d_ptr->error = QMessageManager::NotYetImplemented;
            qWarning() << "QMessageManager::add not yet implemented for Instant Message";
        } else if (account.messageTypes() & QMessage::Mms) {
            retVal = false; //TODO:
	    d_ptr->error = QMessageManager::NotYetImplemented;
            qWarning() << "QMessageManager::add not yet implemented for MMS";
        } else if (account.messageTypes() & QMessage::Email) {
            retVal = QMFStore::instance()->addMessage(*m, d_ptr->error);
	}
    }

    return retVal;
}