1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include <QMessageBox>
4 #include <QFile>
5 #include <DWKeyboard/KeyboardGlobal.h>
6 #include <QPushButton>
7
MainWindow(QWidget * parent)8 MainWindow::MainWindow(QWidget *parent) :
9 QMainWindow(parent),
10 ui(new Ui::MainWindow)
11 {
12 ui->setupUi(this);
13 ui->hostip->setText("www.forlinx.com");
14 setWindowState(Qt::WindowMaximized);
15 setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
16
17
18 GlobalInit();
19 ui->hostip->installEventFilter(this);
20
21 myprocess = new QProcess(this);
22 connect(myprocess, SIGNAL(readyReadStandardOutput()),this, SLOT(result()));
23 connect(myprocess, SIGNAL(readyReadStandardError()),this, SLOT(result()));
24
25 ping_process = new QProcess(this);
26 connect(ping_process, SIGNAL(readyReadStandardOutput()),this, SLOT(ping_result()));
27 connect(ping_process, SIGNAL(readyReadStandardError()),this, SLOT(ping_result()));
28
29 connect(ui->exitBtn, &QPushButton::clicked, this, [=](){
30 close();
31 });
32 }
33
~MainWindow()34 MainWindow::~MainWindow()
35 {
36 delete ui;
37 }
38
eventFilter(QObject * watched,QEvent * event)39 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
40 {
41 static bool mFocusIn = false;
42 if (event->type()==QEvent::FocusIn)
43 {
44 mFocusIn = true;
45 }
46 else if (event->type()==QEvent::FocusOut)
47 {
48 PlatformInputContextBase->FocusOut(watched);
49 mFocusIn = false;
50 }
51
52 if (mFocusIn && event->type() == QEvent::MouseButtonPress) {
53 QMouseEvent *e = (QMouseEvent *)event;
54 PlatformInputContextBase->FocusIn(watched, e->globalPos());
55 }
56
57 return QMainWindow::eventFilter(watched,event);
58 }
59
result()60 void MainWindow::result()
61 {
62 QString abc = myprocess->readAllStandardOutput();
63 if(abc.length()>1)ui->result->append(abc.trimmed());
64 QString efg = myprocess->readAllStandardError();
65 if(efg.length()>1)ui->result->append(efg.trimmed());
66 }
67
ping_result()68 void MainWindow::ping_result()
69 {
70 QString abc = ping_process->readAllStandardOutput();
71 if(abc.length()>1)ui->result->append(abc.trimmed());
72 QString efg = ping_process->readAllStandardError();
73 if(efg.length()>1)ui->result->append(efg.trimmed());
74 }
75
on_connect_clicked()76 void MainWindow::on_connect_clicked()
77 {
78 ui->result->clear();
79 if (ui->comboBox->currentText() == "ME909"){
80 // if (myprocess->state() == QProcess::NotRunning)
81 myprocess->start("/usr/bin/fltest_ec20.sh &");
82 }
83 else{
84 // if (myprocess->state() == QProcess::NotRunning)
85 myprocess->start("/usr/bin/quectelCM &");
86 }
87 }
88
on_ping_clicked()89 void MainWindow::on_ping_clicked()
90 {
91 ui->result->clear();
92 if(ui->hostip->text() == QString(""))
93 {
94 QMessageBox::about(this,"error","hostname cannot be empty!");
95 return;
96 }
97
98 if (ping_process->state() == QProcess::NotRunning){
99 ping_process->start(QString("ping -I usb0 -c 5 ")+ui->hostip->text());
100 ui->result->append(QString("ping -I usb0 -c 5 ")+ui->hostip->text());
101 }
102 }
103
104