1 /* 2 * Copyright (c) 2023 Unionman Technology Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef STBITEMWIDGET_H 17 #define STBITEMWIDGET_H 18 19 #include <QWidget> 20 21 #include <QFile> 22 #include <QMutex> 23 #include <QNetworkReply> 24 #include <QTcpSocket> 25 #include <logtextwidget.h> 26 27 #include <QFileDialog> 28 #include <QInputDialog> 29 #include <QPlainTextEdit> 30 #include <QProcess> 31 #include <QPushButton> 32 #include <QThread> 33 #include <QVBoxLayout> 34 35 namespace Ui { 36 class StbItemWidget; 37 } 38 39 typedef enum { 40 DEV_STATUS_IDEL = 0, 41 DEV_STATUS_UPGRADE_DOWNLOADING, 42 DEV_STATUS_UPGRADE_CHECKING, 43 DEV_STATUS_UPGRADE_UPDATING, 44 45 DEV_STATUS_UPGRADE_ERR = 100, 46 DEV_STATUS_UPGRADE_ERR_DOWNLOAD = DEV_STATUS_UPGRADE_ERR, 47 DEV_STATUS_UPGRADE_ERR_CHECK, 48 DEV_STATUS_UPGRADE_ERR_UPDATE, 49 50 DEV_STATUS_OFFLINE = 1000, 51 } DEV_STATUS_E; 52 53 class FilePusherThread : public QThread { 54 Q_OBJECT 55 56 public: 57 explicit FilePusherThread(QObject* parent = nullptr) 58 { 59 } SetFilePath(const QString & filePath)60 void SetFilePath(const QString& filePath) 61 { 62 this->m_filePath = filePath; 63 } SetTargetPath(const QString & targetPath)64 void SetTargetPath(const QString& targetPath) 65 { 66 this->m_targetPath = targetPath; 67 } SetIp(const QString & ip)68 void SetIp(const QString& ip) 69 { 70 this->m_ip = ip; 71 } 72 void CancelPush(); 73 74 signals: 75 void PushMessage(const QString& result); 76 void PushFinished(const QString& result); 77 78 protected: 79 void Run() override; 80 81 private: 82 QProcess pushProcess; 83 QString m_filePath; 84 QString m_targetPath; 85 QString m_ip; 86 bool pushProcessCancal = false; 87 }; 88 89 class FilePusher : public QWidget { 90 Q_OBJECT 91 92 public: 93 FilePusher(QWidget* parent = nullptr) QWidget(parent)94 : QWidget(parent) 95 { 96 setFixedSize(400L, 200L); 97 98 selectButton = new QPushButton("选择文件", this); 99 connect(selectButton, &QPushButton::clicked, this, &FilePusher::selectFile); 100 selectButton->setFixedSize(80L, 30L); 101 102 filePathLineEdit = new QLineEdit(this); 103 filePathLineEdit->setPlaceholderText("选择文件路径"); 104 filePathLineEdit->setFixedSize(280L, 25L); 105 106 QHBoxLayout* fileLayout = new QHBoxLayout(); 107 fileLayout->addWidget(selectButton); 108 fileLayout->addWidget(filePathLineEdit); 109 110 targetPathLineEdit = new QLineEdit(this); 111 targetPathLineEdit->setPlaceholderText("设备目标路径"); 112 targetPathLineEdit->setFixedSize(280L, 25L); 113 114 pushButton = new QPushButton("推送", this); 115 connect(pushButton, &QPushButton::clicked, this, &FilePusher::pushFile); 116 connect(&m_filePusherThread, &FilePusherThread::PushMessage, this, &FilePusher::handlePushMessage); 117 connect(&m_filePusherThread, &FilePusherThread::PushFinished, this, &FilePusher::handlePushFinished); 118 119 pushButton->setFixedSize(80L, 30L); 120 121 QHBoxLayout* pushLayout = new QHBoxLayout(); 122 pushLayout->addWidget(pushButton); 123 pushLayout->addWidget(targetPathLineEdit); 124 125 resultTextEdit = new QPlainTextEdit(this); 126 resultTextEdit->setFrameStyle(QFrame::NoFrame); 127 resultTextEdit->setReadOnly(true); 128 129 QVBoxLayout* layout = new QVBoxLayout(this); 130 layout->addLayout(fileLayout); 131 layout->addLayout(pushLayout); 132 layout->addWidget(resultTextEdit); 133 } 134 void setIp(QString ip); 135 136 private slots: 137 void selectFile(); 138 void pushFile(); 139 void handlePushMessage(const QString& result); 140 void handlePushFinished(const QString& result); 141 142 private: 143 QLineEdit* filePathLineEdit; 144 QLineEdit* targetPathLineEdit; 145 QPlainTextEdit* resultTextEdit; 146 QPushButton* selectButton; 147 QPushButton* pushButton; 148 FilePusherThread m_filePusherThread; 149 QString ip; 150 }; 151 152 class StbItemWidget : public QWidget { 153 Q_OBJECT 154 155 public: 156 explicit StbItemWidget(QWidget* parent = nullptr); 157 ~StbItemWidget(); 158 void setIndex(int index); 159 void setMainInfo(QString mac, QString sn, QString hwv, QString swv, QString dm); 160 void setIp(QString ip, bool isStatic = false); 161 void setStatus(DEV_STATUS_E status); 162 void setStatusCase1(); 163 void setStatusCase2(); 164 void setStatusCase3(); 165 void setStatusCase4(); 166 void setStatusCase5(); 167 void setStatusCase6(); 168 void setStatusCase7(); 169 void setUptime(QString uptime); 170 void setTemperature(QString temperature); 171 void setIpcameraPss(QString ipcameraPss); 172 void writeLog(QString info); 173 DEV_STATUS_E getStatus(); 174 qint64 updateTime; 175 QTcpSocket* socket = nullptr; getIp()176 QString getIp() 177 { 178 return ip; 179 } getTemperature()180 QString getTemperature() 181 { 182 return temperature; 183 } 184 QString getLogHead(); 185 QString getLogPath(); 186 QString generateLogInfo(); 187 void logMutexLock(); 188 void logMutexUnlock(); 189 190 protected: 191 void mouseDoubleClickEvent(QMouseEvent* event); 192 protected slots: 193 void requestFinished(QNetworkReply* reply); 194 void openMenu(const QPoint& pos); 195 void playVideo(); 196 void openADBShell(); 197 void checkLog(); 198 void openLogDirectory(); 199 void burnSN(); 200 void reboot(); 201 void enterFactoryMode(); 202 void restoreFactorySetting(); 203 void pushFile(); 204 void openConfigWeb(); 205 206 private: 207 int httpRequest(QString req); 208 Ui::StbItemWidget* ui; 209 QWidget* parent; 210 DEV_STATUS_E status = DEV_STATUS_IDEL; 211 QString ip; 212 QString sn; 213 QString mac; 214 QString hwv; 215 QString swv; 216 QString temperature; 217 QString ipcameraPss; 218 QString deviceModel; 219 QString upTime; 220 bool isStaticIP = false; 221 QMutex logMutex; 222 FilePusher filePusher; 223 }; 224 225 #endif // STBITEMWIDGET_H 226