Esempio n. 1
0
 EngineType idType(const QMessageAccountId& id)
 {
     if (id.toString().startsWith(mtmPrefix)) {
         return EngineTypeMTM;
     } else if (id.toString().startsWith(freestylePrefix)) {
         return EngineTypeFreestyle;
     } else {
         return EngineTypeMTM;
     }
 }
bool QMessageAccountId::operator==(const QMessageAccountId& other) const
{
    if (isValid()) {
        if (other.isValid()) {
            return (d_ptr->_id == other.d_ptr->_id);
        }
        return false;
    } else {
        return !other.isValid();
    }
}
Esempio n. 3
0
bool QMessageStore::removeAccount(const QMessageAccountId &id)
{
    bool result = false;
    d_ptr->error = QMessageManager::NoError;

    if (id.isValid() && id.toString().startsWith("QMF_")) {
        qDebug() << __PRETTY_FUNCTION__ << "Removing QMF accountId " << id.toString();
        result = QMFStore::instance()->removeAccount(id, d_ptr->error);
    } else
        d_ptr->error = QMessageManager::NotYetImplemented;

    return result;
}
Esempio n. 4
0
 QMessageAccountId addIdPrefix(const QMessageAccountId& id, const EngineType& type)
 {
     switch (type) {
     case EngineTypeFreestyle:
         Q_ASSERT(!id.toString().startsWith(freestylePrefix));
         return QMessageAccountId(QString(freestylePrefix) + id.toString());
     case EngineTypeMTM:
         Q_ASSERT(!id.toString().startsWith(mtmPrefix));
         return QMessageAccountId(QString(mtmPrefix) + id.toString());
     default:
         return QMessageAccountId(id);
     }
 }
Esempio n. 5
0
bool QMessageService::synchronize(const QMessageAccountId &id)
{
    if (d_ptr->_active) {
        return false;
    }
    
    if (!id.isValid()) {
        d_ptr->_error = QMessageManager::InvalidId;
        return false;
    }
    
    d_ptr->_active = true;
    d_ptr->_error = QMessageManager::NoError;
    
    bool retVal = true;
    d_ptr->_state = QMessageService::ActiveState;
    emit stateChanged(d_ptr->_state);
    
    retVal = d_ptr->synchronize(id);
    if (retVal == false) {
        d_ptr->setFinished(retVal);
    }
    
    return retVal;
}
Esempio n. 6
0
QMessageAccount QMessageStore::account(const QMessageAccountId& id) const
{
    if (!id.isValid()) {
	d_ptr->error = QMessageManager::InvalidId;
	return QMessageAccount();
    }

    d_ptr->error = QMessageManager::NoError;

    if (id.toString().startsWith("QMF_")) {
	return QMFStore::instance()->account(id, d_ptr->error);
    } else {
        return TelepathyEngine::instance()->account(id);
    }

    return QMessageAccount();
}
Esempio n. 7
0
QMessageAccount QMessageStore::account(const QMessageAccountId& id) const
{
    if (id.toString().startsWith("MO_")) {
        return ModestEngine::instance()->account(id);
    } else {
        return  TelepathyEngine::instance()->account(id);
    }
}
QMessageFolderFilter QMessageFolderFilter::byParentAccountId(const QMessageAccountId &id, QMessageDataComparator::EqualityComparator cmp)
{
    QMessageFolderFilter result;
    result.d_ptr->_field = QMessageFolderFilterPrivate::ParentAccountId;
    result.d_ptr->_value = id.toString();
    result.d_ptr->_comparatorType = QMessageFolderFilterPrivate::Equality;
    result.d_ptr->_comparatorValue = static_cast<int>(cmp);
    result.d_ptr->_valid = true;
    return result;
}
Esempio n. 9
0
 QMessageAccountId stripIdPrefix(const QMessageAccountId& id)
 {
     if (id.toString().startsWith(freestylePrefix))
         return QMessageAccountId(id.toString().right(id.toString().length() - QString(freestylePrefix).length()));
     else if (id.toString().startsWith(mtmPrefix))
         return QMessageAccountId(id.toString().right(id.toString().length() - QString(mtmPrefix).length()));
     else
         return QMessageAccountId(id);
 }
Esempio n. 10
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;
}
Esempio n. 11
0
QMailAccountId convert(const QMessageAccountId &id)
{
    return QMailAccountId(stripIdentifierPrefix(id.toString()).toULongLong());
}
uint qHash(const QMessageAccountId &id)
{
    return qHash(id.toString());
}
Esempio n. 13
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;
}