This repository was archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
71 lines (68 loc) · 1.71 KB
/
mainwindow.cpp
File metadata and controls
71 lines (68 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<thread>
#include <QTimer>
using namespace std;
bool connected = false;
string labletext ;
string GetStdoutFromCommand(string cmd) {
string data;
FILE * stream;
const int max_buffer = 256;
char buffer[max_buffer];
cmd.append(" 2>&1");
stream = popen(cmd.c_str(), "r");
if (stream) {
while (!feof(stream))
if (fgets(buffer, max_buffer, stream) != NULL) data.append(buffer);
pclose(stream);
}
return data;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->BtnConDis, SIGNAL(clicked(bool)), this, SLOT(onButtonClicked()));
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &MainWindow::TimerSlot );
ConnectStatus();
}
void MainWindow::ConnectStatus(){
ui->label->setText(GetStdoutFromCommand("hotspotshield status").c_str());
if(ui->label->text().contains("disconnected")){
ui->BtnConDis->setText("Connect");
connected = false;
}
else {
ui->BtnConDis->setText("Disconnect");
connected = true;
}
timer->start(1000);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onButtonClicked()
{
if(connected == false){
string location = "hotspotshield connect " + ui->Location->currentText().toStdString();
const char *lc = location.c_str();
system(lc);
}
else {
string location = "hotspotshield disconnect";
const char *lc = location.c_str();
system(lc);
}
ConnectStatus();
}
void MainWindow::TimerSlot()
{
ConnectStatus();
}