| 1 | #ifndef MAINWINDOW_H |
|---|
| 2 | #define MAINWINDOW_H |
|---|
| 3 | |
|---|
| 4 | #define COMMAND "command" |
|---|
| 5 | #define COMMAND_CONFIRM "command+confirm" |
|---|
| 6 | #define COMMAND_WITH_CONFIRMATION "commandwithconfirmation" // Backwards compatibility |
|---|
| 7 | #define COMMAND_OUTPUT "command+output" |
|---|
| 8 | #define COMMAND_CONFIRM_OUTPUT "command+confirm+output" |
|---|
| 9 | #define COMMAND_OUTPUT_CONFIRM "command+output+confirm" |
|---|
| 10 | #define ENVIRONMENT "OGLOGFILE,ogactiveadmin,DEFAULTSPEED" |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <QWidget> |
|---|
| 14 | #include <QProcess> |
|---|
| 15 | #include <QMap> |
|---|
| 16 | #include <QMainWindow> |
|---|
| 17 | #include <QNetworkReply> |
|---|
| 18 | #include <QSslError> |
|---|
| 19 | #include <QProgressBar> |
|---|
| 20 | #include <QLabel> |
|---|
| 21 | #include <QLineEdit> |
|---|
| 22 | #include <QTextEdit> |
|---|
| 23 | #include <QFile> |
|---|
| 24 | #include <QWebEngineView> |
|---|
| 25 | #include <QVector> |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | #include "digitalclock.h" |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | struct PendingCommand { |
|---|
| 33 | QString command = ""; |
|---|
| 34 | bool confirm = false; |
|---|
| 35 | bool returnOutput = false; |
|---|
| 36 | |
|---|
| 37 | QProcess *process = nullptr; |
|---|
| 38 | |
|---|
| 39 | bool operator==(const PendingCommand &other) { |
|---|
| 40 | return other.process == process; |
|---|
| 41 | } |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | class MainWindow : public QMainWindow |
|---|
| 46 | { |
|---|
| 47 | Q_OBJECT |
|---|
| 48 | |
|---|
| 49 | public: |
|---|
| 50 | MainWindow(QWidget *parent = 0); |
|---|
| 51 | void closeEvent(QCloseEvent *event) override; |
|---|
| 52 | |
|---|
| 53 | ~MainWindow(); |
|---|
| 54 | |
|---|
| 55 | public slots: |
|---|
| 56 | // Funcion que maneja los links |
|---|
| 57 | void slotWebLoadStarted(); |
|---|
| 58 | void slotWebLoadFinished(bool ok); |
|---|
| 59 | void slotWebLoadProgress(int progress); |
|---|
| 60 | void slotSslErrors(QNetworkReply* reply); |
|---|
| 61 | void slotCertificateErrors(const QWebEngineCertificateError &certificateError); |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | // Funciones que manejan cada vez que el proceso hace algo |
|---|
| 65 | void slotProcessStarted(); |
|---|
| 66 | void slotProcessFinished(int code,QProcess::ExitStatus status); |
|---|
| 67 | void slotProcessError(QProcess::ProcessError error); |
|---|
| 68 | void slotProcessOutput(); |
|---|
| 69 | void slotProcessErrorOutput(); |
|---|
| 70 | |
|---|
| 71 | // Funcion para crear terminales |
|---|
| 72 | void slotCreateTerminal(); |
|---|
| 73 | void slotDeleteTerminal(); |
|---|
| 74 | |
|---|
| 75 | // Funcion para el webar |
|---|
| 76 | void slotSetUrl(const QUrl &url); |
|---|
| 77 | void slotUrlChanged(const QUrl &url); |
|---|
| 78 | |
|---|
| 79 | void commandQueued(const QString &command, bool confirm, bool returnOutput); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | private: |
|---|
| 83 | bool isAdmin() const { return m_is_admin; } |
|---|
| 84 | bool isKioskMode() const { return m_kiosk_mode; } |
|---|
| 85 | void registerScheme(const QString &name); |
|---|
| 86 | void registerHandler(const QString &name, bool confirm, bool output, const QString baseCommand = ""); |
|---|
| 87 | |
|---|
| 88 | bool m_is_admin{false}; |
|---|
| 89 | bool m_kiosk_mode{false}; |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | //Functions |
|---|
| 93 | protected: |
|---|
| 94 | int readEnvironmentValues(); |
|---|
| 95 | void print(QString s); |
|---|
| 96 | void write(QString s); |
|---|
| 97 | void captureOutputForStatusBar(QString output); |
|---|
| 98 | void startProgressBar(); |
|---|
| 99 | void finishProgressBar(); |
|---|
| 100 | void executeCommand(QString &string); |
|---|
| 101 | QString readSpeed(); |
|---|
| 102 | void showErrorMessage(QString string); |
|---|
| 103 | |
|---|
| 104 | protected: |
|---|
| 105 | QWebEngineView *m_web; |
|---|
| 106 | QTextEdit *m_output; |
|---|
| 107 | QLabel *m_logo; |
|---|
| 108 | QProgressBar *m_progressBar; |
|---|
| 109 | QLabel *m_speedInfo; |
|---|
| 110 | DigitalClock *m_clock; |
|---|
| 111 | QTabWidget *m_tabs; |
|---|
| 112 | QLineEdit *m_webBar; |
|---|
| 113 | |
|---|
| 114 | //QProcess *m_process; |
|---|
| 115 | |
|---|
| 116 | QMap<QString,QString> m_env; |
|---|
| 117 | QFile *m_logfile; |
|---|
| 118 | QTextStream *m_logstream; |
|---|
| 119 | |
|---|
| 120 | PendingCommand m_command; |
|---|
| 121 | //QVector<PendingCommand> m_commands; |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | int m_numberTerminal; |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | #endif // MAINWINDOW_H |
|---|