Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / coreplugin / connectionmanager.h
blobf46af6a31337e08eca7509c5e7bd1caad00ea483
1 /**
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
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
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
22 * for more details.
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>
35 #include <QWidget>
36 #include <QtCore/QVector>
37 #include <QtCore/QIODevice>
38 #include <QtCore/QLinkedList>
39 #include <QPushButton>
40 #include <QComboBox>
42 #include "core_global.h"
43 #include <QTimer>
45 namespace Core {
46 class IConnection;
48 namespace Internal {
49 class MainWindow;
50 } // namespace Internal
52 class CORE_EXPORT DevListItem {
53 public:
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 {
75 Q_OBJECT
77 public:
78 ConnectionManager(Internal::MainWindow *mainWindow);
79 virtual ~ConnectionManager();
81 void init();
83 DevListItem getCurrentDevice()
85 return m_connectionDevice;
87 DevListItem findDevice(int devNumber);
89 QLinkedList<DevListItem> getAvailableDevices()
91 return m_devList;
94 bool isConnected()
96 return m_ioDev != 0;
99 void addWidget(QWidget *widget);
101 bool connectDevice(DevListItem device);
102 bool disconnectDevice();
103 void suspendPolling();
104 void resumePolling();
106 protected:
107 void updateConnectionList(IConnection *connection);
108 void registerDevice(IConnection *conn, IConnection::device device);
109 void updateConnectionDropdown();
111 signals:
112 void deviceConnected(QIODevice *device);
113 void deviceAboutToDisconnect();
114 void deviceDisconnected();
115 void availableDevicesChanged(const QLinkedList<Core::DevListItem> devices);
117 public slots:
118 void telemetryConnected();
119 void telemetryDisconnected();
121 private slots:
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();
134 protected:
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
144 QIODevice *m_ioDev;
146 private:
147 bool connectDevice();
148 bool polling;
149 Internal::MainWindow *m_mainWindow;
150 QList <IConnection *> connectionBackup;
151 QTimer *reconnect;
152 QTimer *reconnectCheck;
154 } // namespace Core
156 #endif // CONNECTIONMANAGER_H