Exemplo n.º 1
0
ConnectionItem::ConnectionItem(RemoteActivatable *activatable, ItemType type, QObject *parent) :
    QObject(parent),
    m_activatable(activatable),
    m_hoverEnter(false),
    m_hasDefaultRoute(false),
    m_activationState(QLatin1String("unknown")),
    m_type(type),
    m_showMoreChecked(false),
    m_networkCount(0)
{
    if (m_activatable)
    {
        RemoteInterfaceConnection *remote = interfaceConnection();

        if (remote)
        {
            m_hasDefaultRoute = remote->hasDefaultRoute();
            connect(remote, SIGNAL(hasDefaultRouteChanged(bool)),
                    SLOT(handleHasDefaultRouteChanged(bool)));
            connect(remote, SIGNAL(activationStateChanged(Knm::InterfaceConnection::ActivationState, Knm::InterfaceConnection::ActivationState)),
                    SLOT(activationStateChanged(Knm::InterfaceConnection::ActivationState, Knm::InterfaceConnection::ActivationState)));

            if (remote->activationState() == Knm::InterfaceConnection::Activated)
            {
                m_activationState = "activated";
            }
            else
                if (remote->activationState() == Knm::InterfaceConnection::Activating)
                {
                    m_activationState = "activating";
                }
        }

        switch (m_activatable->activatableType())
        {
            case Knm::Activatable::WirelessNetwork:
                connect(qobject_cast<RemoteWirelessNetwork *>(m_activatable), SIGNAL(strengthChanged(int)), this, SLOT(handlePropertiesChanges()));
                m_typeString = "wirelessNetwork";
                break;
            case Knm::Activatable::WirelessInterfaceConnection:
                connect(qobject_cast<RemoteWirelessInterfaceConnection *>(m_activatable), SIGNAL(strengthChanged(int)), this, SLOT(handlePropertiesChanges()));
                m_typeString = "wireless";
                break;
            case Knm::Activatable::InterfaceConnection:
                m_typeString = "wired";
                break;
            case Knm::Activatable::VpnInterfaceConnection:
                m_typeString = "vpn";
                break;
            case Knm::Activatable::GsmInterfaceConnection:
                connect(qobject_cast<RemoteGsmInterfaceConnection *>(m_activatable), SIGNAL(signalQualityChanged(int)), this, SLOT(handlePropertiesChanges()));
                connect(qobject_cast<RemoteGsmInterfaceConnection *>(m_activatable), SIGNAL(accessTechnologyChanged(int)), this, SLOT(handlePropertiesChanges()));
                m_typeString = "gsm";
                break;
                /* TODO: add HiddenWirelessInterfaceConnection and UnconfiguredInterface, or just get rid of them. */
        }
    }
    else
        if (type == ConnectionItem::HiddenNetwork)
void RemoteInterfaceConnection::icPropertiesChanged(const QVariantMap &changedProperties)
{
    Q_D(RemoteInterfaceConnection);
    QStringList propKeys = changedProperties.keys();
    QLatin1String connectionTypeKey("connectionType"),
                  uuidKey("uuid"),
                  nameKey("name"),
                  iconNameKey("iconName"),
                  activationStateKey("activationState"),
                  hasDefaultRouteKey("hasDefaultRoute");
    QVariantMap::const_iterator it = changedProperties.find(connectionTypeKey);
    if (it != changedProperties.end()) {
        d->connectionType = (Knm::Connection::Type)it->toUInt();
        propKeys.removeOne(connectionTypeKey);
    }
    it = changedProperties.find(uuidKey);
    if (it != changedProperties.end()) {
        d->uuid = it->toString();
        propKeys.removeOne(uuidKey);
    }
    it = changedProperties.find(nameKey);
    if (it != changedProperties.end()) {
        d->name = it->toString();
        propKeys.removeOne(nameKey);
    }
    it = changedProperties.find(iconNameKey);
    if (it != changedProperties.end()) {
        d->iconName = it->toString();
        propKeys.removeOne(iconNameKey);
    }
    it = changedProperties.find(activationStateKey);
    if (it != changedProperties.end()) {
        d->oldActivationState = d->activationState;
        d->activationState = (Knm::InterfaceConnection::ActivationState)it->toUInt();
        emit activationStateChanged(d->oldActivationState, d->activationState);
        propKeys.removeOne(activationStateKey);
    }
    it = changedProperties.find(hasDefaultRouteKey);
    if (it != changedProperties.end()) {
        d->hasDefaultRoute = it->toBool();
        emit hasDefaultRouteChanged(d->hasDefaultRoute);
        propKeys.removeOne(hasDefaultRouteKey);
    }
    /*if (propKeys.count()) {
        kDebug() << "Unhandled properties: " << propKeys;
    }*/
    emit changed();
}