2 ******************************************************************************
4 * @file connectionmanager.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup CorePlugin Core Plugin
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef CONNECTIONMANAGER_H
30 #define CONNECTIONMANAGER_H
32 #include "mainwindow.h"
33 #include "generalsettings.h"
34 #include <coreplugin/iconnection.h>
36 #include <QtCore/QVector>
37 #include <QtCore/QIODevice>
38 #include <QtCore/QLinkedList>
39 #include <QPushButton>
42 #include "core_global.h"
50 } // namespace Internal
52 class CORE_EXPORT DevListItem
{
54 DevListItem(IConnection
*c
, IConnection::device d
) :
55 connection(c
), device(d
) {}
57 DevListItem() : connection(NULL
) {}
59 QString
getConName() const;
61 QString
getConDescription() const;
63 bool operator==(const DevListItem
&rhs
)
65 return connection
== rhs
.connection
&& device
== rhs
.device
;
68 int displayNumber
= -1;
69 IConnection
*connection
;
70 IConnection::device device
;
74 class CORE_EXPORT ConnectionManager
: public QWidget
{
78 ConnectionManager(Internal::MainWindow
*mainWindow
);
79 virtual ~ConnectionManager();
83 DevListItem
getCurrentDevice()
85 return m_connectionDevice
;
87 DevListItem
findDevice(int devNumber
);
89 QLinkedList
<DevListItem
> getAvailableDevices()
99 void addWidget(QWidget
*widget
);
101 bool connectDevice(DevListItem device
);
102 bool disconnectDevice();
103 void suspendPolling();
104 void resumePolling();
107 void updateConnectionList(IConnection
*connection
);
108 void registerDevice(IConnection
*conn
, IConnection::device device
);
109 void updateConnectionDropdown();
112 void deviceConnected(QIODevice
*device
);
113 void deviceAboutToDisconnect();
114 void deviceDisconnected();
115 void availableDevicesChanged(const QLinkedList
<Core::DevListItem
> devices
);
118 void telemetryConnected();
119 void telemetryDisconnected();
122 void objectAdded(QObject
*obj
);
123 void aboutToRemoveObject(QObject
*obj
);
125 void onConnectClicked();
126 void onDeviceSelectionChanged(int index
);
127 void devChanged(IConnection
*connection
);
129 void onConnectionDestroyed(QObject
*obj
);
130 void connectionsCallBack(); // used to call devChange after all the plugins are loaded
131 void reconnectSlot();
132 void reconnectCheckSlot();
135 QComboBox
*m_availableDevList
;
136 QPushButton
*m_connectBtn
;
137 QLinkedList
<DevListItem
> m_devList
;
138 QList
<IConnection
*> m_connectionsList
;
140 // currently connected connection plugin
141 DevListItem m_connectionDevice
;
143 // currently connected QIODevice
147 bool connectDevice();
149 Internal::MainWindow
*m_mainWindow
;
150 QList
<IConnection
*> connectionBackup
;
152 QTimer
*reconnectCheck
;
156 #endif // CONNECTIONMANAGER_H