Пример #1
0
void toConnectionRegistry::removeConnection(toConnection *conn)
{
//	QString const& description = conn->description();

    QList<toConnectionOptions> conns = m_ConnectionsMap.keys(conn);
    if (conns.size() != 1 || !m_ConnectionsList.contains(conn))
    {
        conn->setParent(this);
        throw QString("Unregistered connection for removal: %1").arg(conn->description());
    }

    int pos = m_ConnectionsList.indexOf(conn);

    // TODO if TCP connection is lost this can hang "forever" - preventing application exit
    // There must be some ugly way of doing this asynchronously in bg thread:
    // conn->setParent(NULL); conn->setThread(<something>);
    // emit something and then wait for threads response
    delete conn;

    beginRemoveRows(QModelIndex(), pos, pos);
    int mRemoved = m_ConnectionsMap.remove(conns.at(0));
    Q_UNUSED(mRemoved);
    m_ConnectionsList.removeAt(pos);
    m_currentConnection = index((std::min)(pos, m_ConnectionsList.size()-1));
    endRemoveRows();
    emit activeConnectionChanged(m_currentConnection);
    emit activeConnectionChanged(m_currentConnection.row());
}
Пример #2
0
void toConnectionRegistry::slotViewIndexChanged(int idx)
{
    Q_ASSERT_X(idx < m_ConnectionsList.size(), qPrintable(__QHERE__), qPrintable(QString("Connection index out of range: %1").arg(idx)));

    int oldIdx = m_currentConnection.row();
    if (idx == -1)
    {
        m_currentConnection = QModelIndex();
        Q_ASSERT_X(m_ConnectionsMap.empty() && m_ConnectionsList.empty()
                   , qPrintable(__QHERE__)
                   , "Dangling connection found");
    }
    else
    {
        m_currentConnection = index(idx);
        Q_ASSERT_X(m_ConnectionsMap.contains(data(m_currentConnection, Qt::UserRole).value<toConnectionOptions>())
                   , qPrintable(__QHERE__)
                   , "Can't find active connection");
    }

    if (oldIdx != idx)
    {
        emit activeConnectionChanged(m_currentConnection);
        emit activeConnectionChanged(m_currentConnection.row());
    }
}
Пример #3
0
void toConnectionRegistry::changeConnection(toConnection const&conn)
{
    Q_ASSERT_X(m_ConnectionsMap.contains(conn.connectionOptions())
               , qPrintable(__QHERE__)
               , qPrintable(QString("Unregistered connection(change): %1").arg(conn.connectionOptions().toString())));

    int oldIdx = m_currentConnection.row();
    m_currentConnection = index(m_ConnectionsList.indexOf(const_cast<toConnection*>(&conn)));
    if (oldIdx != m_currentConnection.row())
    {
        emit activeConnectionChanged(m_currentConnection);
        emit activeConnectionChanged(m_currentConnection.row());
    }
}
Пример #4
0
void NetworkManager::reloadActiveConnections()
{
    const QJsonDocument doc = QJsonDocument::fromJson(m_networkInter->activeConnections().toUtf8());
    Q_ASSERT(doc.isObject());
    const QJsonObject obj = doc.object();

    NetworkDevice::NetworkTypes states = NetworkDevice::None;
    QSet<QUuid> activeConnList;
    for (auto info(obj.constBegin()); info != obj.constEnd(); ++info)
    {
        Q_ASSERT(info.value().isObject());
        const QJsonObject infoObj = info.value().toObject();

        const QUuid uuid = infoObj.value("Uuid").toString();
        // if uuid not in device list, its a wireless connection
        const bool isWireless = std::find(m_deviceSet.cbegin(), m_deviceSet.cend(), uuid) == m_deviceSet.cend();

        if (isWireless)
            states |= NetworkDevice::Wireless;
        else
            states |= NetworkDevice::Wired;

        activeConnList.insert(uuid);
    }

    const QSet<QUuid> removedConnList = m_activeConnSet - activeConnList;
    m_activeConnSet = std::move(activeConnList);

    for (auto uuid : removedConnList)
        emit activeConnectionChanged(uuid);

    for (auto uuid : m_activeConnSet)
        emit activeConnectionChanged(uuid);

    if (m_states == states)
        return;

    m_states = states;
    emit networkStateChanged(m_states);

//    qDebug() << "network states: " << m_states;
}
Пример #5
0
void toConnectionRegistry::addConnection(toConnection *conn)
{
    conn->setParent(this);

    if (m_ConnectionsMap.contains(conn->connectionOptions()))
    {
        QString opsStr = conn->connectionOptions().toString();
        delete conn;
        throw QString("Duplicit connection: %1").arg(opsStr);
    }

    //	if(m_ConnectionsList.empty())
    //		m_currentConnection = conn->connectionOptions();

    beginInsertRows(QModelIndex(), m_ConnectionsList.size(), m_ConnectionsList.size());
    m_ConnectionsMap.insert(conn->connectionOptions(), conn);
    m_ConnectionsList.append(conn);
    m_currentConnection = index(m_ConnectionsList.size()-1);
    endInsertRows();
    emit activeConnectionChanged(m_currentConnection);
    emit activeConnectionChanged(m_currentConnection.row());
}