<commit_before>/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2010 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt4/ProtocolParameter>

#include <TelepathyQt4/ManagerFile>

namespace Tp
{

struct TELEPATHY_QT4_NO_EXPORT ProtocolParameter::Private : public QSharedData
{
    Private(const QString &name, const QDBusSignature &dbusSignature, QVariant::Type type,
            const QVariant &defaultValue, ConnMgrParamFlag flags)
        : name(name), dbusSignature(dbusSignature), type(type), defaultValue(defaultValue),
          flags(flags) {}

    QString name;
    QDBusSignature dbusSignature;
    QVariant::Type type;
    QVariant defaultValue;
    ConnMgrParamFlag flags;
};

ProtocolParameter::ProtocolParameter()
{
}

ProtocolParameter::ProtocolParameter(const QString &name,
                                     const QDBusSignature &dbusSignature,
                                     QVariant defaultValue,
                                     ConnMgrParamFlag flags)
    : mPriv(new Private(name, dbusSignature,
                ManagerFile::variantTypeFromDBusSignature(dbusSignature.signature()), defaultValue,
                flags))
{
}

ProtocolParameter::ProtocolParameter(const ProtocolParameter &other)
    : mPriv(other.mPriv)
{
}

ProtocolParameter::~ProtocolParameter()
{
}

ProtocolParameter &ProtocolParameter::operator=(const ProtocolParameter &other)
{
    this->mPriv = other.mPriv;
    return *this;
}

bool ProtocolParameter::operator==(const ProtocolParameter &other) const
{
    if (!isValid()) {
        return false;
    }

    return (mPriv->name == other.name());
}

bool ProtocolParameter::operator==(const QString &name) const
{
    if (!isValid()) {
        return false;
    }

    return (mPriv->name == name);
}

QString ProtocolParameter::name() const
{
    if (!isValid()) {
        return QString();
    }

    return mPriv->name;
}

QDBusSignature ProtocolParameter::dbusSignature() const
{
    if (!isValid()) {
        return QDBusSignature();
    }

    return mPriv->dbusSignature;
}

QVariant::Type ProtocolParameter::type() const
{
    if (!isValid()) {
        return QVariant::Invalid;
    }

    return mPriv->type;
}

QVariant ProtocolParameter::defaultValue() const
{
    if (!isValid()) {
        return QVariant();
    }

    return mPriv->defaultValue;
}

bool ProtocolParameter::isRequired() const
{
    if (!isValid()) {
        return false;
    }

    return mPriv->flags & ConnMgrParamFlagRequired;
}

bool ProtocolParameter::isSecret() const
{
    if (!isValid()) {
        return false;
    }

    return mPriv->flags & ConnMgrParamFlagSecret;
}

bool ProtocolParameter::isRequiredForRegistration() const
{
    if (!isValid()) {
        return false;
    }

    return mPriv->flags & ConnMgrParamFlagRegister;
}

} // Tp
<commit_msg>ProtocolParameter: Return true in operator== if both instances are invalid and false if only one of them is.<commit_after>/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2010 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt4/ProtocolParameter>

#include <TelepathyQt4/ManagerFile>

namespace Tp
{

struct TELEPATHY_QT4_NO_EXPORT ProtocolParameter::Private : public QSharedData
{
    Private(const QString &name, const QDBusSignature &dbusSignature, QVariant::Type type,
            const QVariant &defaultValue, ConnMgrParamFlag flags)
        : name(name), dbusSignature(dbusSignature), type(type), defaultValue(defaultValue),
          flags(flags) {}

    QString name;
    QDBusSignature dbusSignature;
    QVariant::Type type;
    QVariant defaultValue;
    ConnMgrParamFlag flags;
};

ProtocolParameter::ProtocolParameter()
{
}

ProtocolParameter::ProtocolParameter(const QString &name,
                                     const QDBusSignature &dbusSignature,
                                     QVariant defaultValue,
                                     ConnMgrParamFlag flags)
    : mPriv(new Private(name, dbusSignature,
                ManagerFile::variantTypeFromDBusSignature(dbusSignature.signature()), defaultValue,
                flags))
{
}

ProtocolParameter::ProtocolParameter(const ProtocolParameter &other)
    : mPriv(other.mPriv)
{
}

ProtocolParameter::~ProtocolParameter()
{
}

ProtocolParameter &ProtocolParameter::operator=(const ProtocolParameter &other)
{
    this->mPriv = other.mPriv;
    return *this;
}

bool ProtocolParameter::operator==(const ProtocolParameter &other) const
{
    if (!isValid() || !other.isValid()) {
        if (!isValid() && !other.isValid()) {
            return true;
        }
        return false;
    }

    return (mPriv->name == other.name());
}

bool ProtocolParameter::operator==(const QString &name) const
{
    if (!isValid()) {
        return false;
    }

    return (mPriv->name == name);
}

QString ProtocolParameter::name() const
{
    if (!isValid()) {
        return QString();
    }

    return mPriv->name;
}

QDBusSignature ProtocolParameter::dbusSignature() const
{
    if (!isValid()) {
        return QDBusSignature();
    }

    return mPriv->dbusSignature;
}

QVariant::Type ProtocolParameter::type() const
{
    if (!isValid()) {
        return QVariant::Invalid;
    }

    return mPriv->type;
}

QVariant ProtocolParameter::defaultValue() const
{
    if (!isValid()) {
        return QVariant();
    }

    return mPriv->defaultValue;
}

bool ProtocolParameter::isRequired() const
{
    if (!isValid()) {
        return false;
    }

    return mPriv->flags & ConnMgrParamFlagRequired;
}

bool ProtocolParameter::isSecret() const
{
    if (!isValid()) {
        return false;
    }

    return mPriv->flags & ConnMgrParamFlagSecret;
}

bool ProtocolParameter::isRequiredForRegistration() const
{
    if (!isValid()) {
        return false;
    }

    return mPriv->flags & ConnMgrParamFlagRegister;
}

} // Tp

{'fraction_non_alphanumeric': 0.10096930533117932, 'fraction_numerical': 0.006731287022078622, 'mean_word_length': 3.2090651558073655, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5697289', 'n_tokens_mistral': 2078, 'n_tokens_neox': 2028, 'n_words': 611}