1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

GCS ConnectionManager: Consolidate the unregistering and registering devices

into one method
This commit is contained in:
James Cotton 2012-09-08 12:53:00 -05:00
parent e6bcf96e2a
commit e5ab9f0fda
2 changed files with 17 additions and 16 deletions

View File

@ -289,10 +289,11 @@ void ConnectionManager::resumePolling()
} }
/** /**
* Unregister all devices from one connection plugin * Synchronize the list of connections displayed with those physically
* \param[in] connection Connection type that you want to forget about :) * present
*/ * @param[in] connection Connection type that you want to forget about :)
void ConnectionManager::unregisterAll(IConnection *connection) */
void ConnectionManager::updateConnectionList(IConnection *connection)
{ {
for (QLinkedList<devListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); ) for (QLinkedList<devListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); )
{ {
@ -309,6 +310,16 @@ void ConnectionManager::unregisterAll(IConnection *connection)
else else
++iter; ++iter;
} }
//and add them back in the list
QList <IConnection::device> availableDev = connection->availableDevices();
foreach (IConnection::device dev, availableDev)
{
QString cbName = connection->shortName() + ": " + dev.name;
QString disp = connection->shortName() + " : " + dev.displayName;
registerDevice(connection,cbName,dev.name,disp);
}
} }
/** /**
@ -344,16 +355,7 @@ void ConnectionManager::devChanged(IConnection *connection)
m_availableDevList->clear(); m_availableDevList->clear();
//remove registered devices of this IConnection from the list //remove registered devices of this IConnection from the list
unregisterAll(connection); updateConnectionList(connection);
//and add them back in the list
QList <IConnection::device> availableDev = connection->availableDevices();
foreach (IConnection::device dev, availableDev)
{
QString cbName = connection->shortName() + ": " + dev.name;
QString disp = connection->shortName() + " : " + dev.displayName;
registerDevice(connection,cbName,dev.name,disp);
}
//add all the list again to the combobox //add all the list again to the combobox
foreach (devListItem d, m_devList) foreach (devListItem d, m_devList)

View File

@ -81,7 +81,7 @@ public:
void resumePolling(); void resumePolling();
protected: protected:
void unregisterAll(IConnection *connection); void updateConnectionList(IConnection *connection);
void registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp); void registerDevice(IConnection *conn, const QString &devN, const QString &name, const QString &disp);
devListItem findDevice(const QString &devName); devListItem findDevice(const QString &devName);
@ -96,7 +96,6 @@ private slots:
void onConnectPressed(); void onConnectPressed();
void devChanged(IConnection *connection); void devChanged(IConnection *connection);
// void onConnectionClosed(QObject *obj);
void onConnectionDestroyed(QObject *obj); void onConnectionDestroyed(QObject *obj);
void connectionsCallBack(); //used to call devChange after all the plugins are loaded void connectionsCallBack(); //used to call devChange after all the plugins are loaded
protected: protected: