File indexing completed on 2024-05-12 15:27:52

0001 /***************************************************************************
0002 File                 : MQTTConnectionManagerWidget.h
0003 Project              : LabPlot
0004 Description          : widget for managing MQTT connections
0005 --------------------------------------------------------------------
0006 Copyright            : (C) 2018 Ferencz Kovacs (kferike98@gmail.com)
0007 Copyright            : (C) 2018-2019 Alexander Semke (alexander.semke@web.de)
0008 
0009  ***************************************************************************/
0010 
0011 /***************************************************************************
0012  *                                                                         *
0013  *  This program is free software; you can redistribute it and/or modify   *
0014  *  it under the terms of the GNU General Public License as published by   *
0015  *  the Free Software Foundation; either version 2 of the License, or      *
0016  *  (at your option) any later version.                                    *
0017  *                                                                         *
0018  *  This program is distributed in the hope that it will be useful,        *
0019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0021  *  GNU General Public License for more details.                           *
0022  *                                                                         *
0023  *   You should have received a copy of the GNU General Public License     *
0024  *   along with this program; if not, write to the Free Software           *
0025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0026  *   Boston, MA  02110-1301  USA                                           *
0027  *                                                                         *
0028  ***************************************************************************/
0029 #ifndef MQTTCONNECTIONMANAGERWIDGET_H
0030 #define MQTTCONNECTIONMANAGERWIDGET_H
0031 
0032 #include "ui_mqttconnectionmanagerwidget.h"
0033 
0034 class QMqttClient;
0035 class QTimer;
0036 
0037 class MQTTConnectionManagerWidget : public QWidget {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit MQTTConnectionManagerWidget(QWidget*, const QString&);
0042     ~MQTTConnectionManagerWidget() override;
0043 
0044     struct MQTTConnection {
0045         QString name;
0046         int port;
0047         QString hostName;
0048         bool useAuthentication;
0049         QString userName;
0050         QString password;
0051         bool useID;
0052         QString clientID;
0053         bool retain;
0054     };
0055 
0056     QString connection() const;
0057     void setCurrentConnection(const QString&);
0058     void saveConnections();
0059     bool checkConnections();
0060 
0061 private:
0062     Ui::MQTTConnectionManagerWidget ui;
0063     QList<MQTTConnection> m_connections;
0064     MQTTConnection* m_currentConnection = nullptr;
0065     bool m_initializing{false};
0066     QString m_configPath;
0067     QString m_initConnName;
0068     QMqttClient* m_client{nullptr};
0069     bool m_testing{false};
0070     QTimer* m_testTimer{nullptr};
0071 
0072     QString uniqueName();
0073     void loadConnection();
0074     void dataChanged();
0075 
0076 private slots:
0077     void testConnection();
0078     void loadConnections();
0079     void addConnection();
0080     void deleteConnection();
0081     void connectionChanged(int);
0082     void nameChanged(const QString&);
0083     void hostChanged(const QString&);
0084     void portChanged(const QString&);
0085     void userNameChanged(const QString&);
0086     void passwordChanged(const QString&);
0087     void clientIdChanged(const QString&);
0088     void authenticationChecked(int);
0089     void idChecked(int);
0090     void retainChecked(int);
0091     void onConnect();
0092     void onDisconnect();
0093     void testTimeout();
0094 
0095 signals:
0096     void changed();
0097 };
0098 
0099 #endif  // MQTTCONNECTIONMANAGERWIDGET_H