#include "myClass.h"
QString ping_Around;
QStringList arguments;
QStringList arguments1;
QStringList arguments2;
QStringList arguments3;
QProcess myProcess;
QProcess myProcess1;
QProcess myProcess2;
QProcess myProcess3;
int num = 0;
QStringList strlstPingResults;
QStringList strlstPingRes;
QStringList strlstPingResults1;
QStringList strlstPingResults2;
QStringList strlstPingResults3;
QStringList Ss[4];
QGraphicsTextItem* itemText[4];
QString count_Pack[4];
QPushButton* Add_Host;
QPushButton* Delete_Host;
void myClass::timer_overflow() {
myProcess.start(ping_Around, arguments);
myProcess.waitForFinished();
myProcess1.start(ping_Around, arguments1);
myProcess1.waitForFinished();
myProcess2.start(ping_Around, arguments2);
myProcess2.waitForFinished();
myProcess3.start(ping_Around, arguments3);
myProcess3.waitForFinished();
// QStringList<vector_t> strlstPingRes[num];
strlstPingResults.clear();
strlstPingResults<<myProcess.readAll();
Ss[0] = strlstPingResults[0].split('\n');
strlstPingResults1.clear();
strlstPingResults1<<myProcess1.readAll();
Ss[1] = strlstPingResults1[0].split('\n');
strlstPingResults2.clear();
strlstPingResults2<<myProcess2.readAll();
Ss[2] = strlstPingResults2[0].split('\n');
strlstPingResults3.clear();
strlstPingResults3<<myProcess3.readAll();
Ss[3] = strlstPingResults3[0].split('\n');
for (int i = 0; i < 4; i++) {
if (Ss[i].count() > 1) {
count_Pack[i] = Ss[i][4].mid(23, 1);
}
}
for (int i = 0; i < 4; i++) {
if (count_Pack[i].count() > 0) {
if (count_Pack[i] == "1") {
item[i]->setBrush(QBrush(Qt::green));
}
else {
item[i]->setBrush(QBrush(Qt::red));
}
}
else {
item[i]->setBrush(QBrush(Qt::red));
}
}
// itemText[1] = new QGraphicsTextItem(0, this);
// itemText[1]->setPlainText(Ss[0][4]);
}
void myClass::btnClicked_Add() {
bool bOk;
QString str = QInputDialog::getText(0, QString::fromLocal8Bit("Ip-адресс"), QString::fromLocal8Bit("Введите ip-адресс:"), QLineEdit::Normal, "", &bOk);
if (!bOk) {
// Была нажата кнопка Cancel
}
}
void myClass::btnClicked_Del() {
pInputDialog->show();
}
void myClass::slotFinished() {
}
InputDialog::InputDialog(QWidget* pwgt/*= 0*/) : QDialog(pwgt, Qt::WindowTitleHint | Qt::WindowSystemMenuHint) {
List_Ip = new QListWidget;
for (int i = 0; i < 4; i++) {
List_Ip->addItem("10.31." + QString::number(i + 3) + ".130");
}
QPushButton* pcmdOk = new QPushButton("&Delete");
QPushButton* pcmdCancel = new QPushButton("&Cancel");
connect(pcmdOk, SIGNAL(clicked()), SLOT(accept()));
connect(pcmdCancel, SIGNAL(clicked()), SLOT(reject()));
//Layout setup
QGridLayout* ptopLayout = new QGridLayout;
ptopLayout->addWidget(List_Ip, 1, 0);
ptopLayout->addWidget(pcmdOk, 2,0);
ptopLayout->addWidget(pcmdCancel, 2, 1);
setLayout(ptopLayout);
}
myClass::myClass(QObject *parent): QGraphicsScene(parent) {
QFont fontForButton;
fontForButton.setPointSize(7);
D = new QDialog(0);
pInputDialog = new InputDialog(0);
// mediaO = new Phonon::MediaObject;
// QObject::connect(mediaO, SIGNAL(finished()), this, SLOT(slotFinished()));
QString str("/var/www/html/Watch_It_Linux/sounds/Active.wav");
QMessageBox::information(0, "Information", str);
// mediaO->setCurrentSource(str);
// mediaO->play();
Add_Host = new QPushButton("&Add", 0);
Add_Host->setFixedSize(23, 20);
Add_Host->setGeometry(-94, 30, 23, 20);
Add_Host->setFont(fontForButton);
Delete_Host = new QPushButton("&Del", 0);
Delete_Host->setFixedSize(23, 20);
Delete_Host->setGeometry(-94, 53, 23, 20);
Delete_Host->setFont(fontForButton);
QObject::connect(Add_Host, SIGNAL(clicked()), this, SLOT(btnClicked_Add()));
QObject::connect(Delete_Host, SIGNAL(clicked()), this, SLOT(btnClicked_Del()));
QGraphicsProxyWidget * item_Widget = addWidget(Add_Host);
item_Widget = addWidget(Delete_Host);
Add_Host->show();
Delete_Host->show();
ping_Around = "/bin/ping";
arguments << "-c" << "1" << "10.31.3.130";
arguments1 << "-c" << "1" << "10.31.4.130";
arguments2 << "-c" << "1" << "10.31.5.130";
arguments3 << "-c" << "1" << "10.31.6.130";
this->setSceneRect(QRectF(-90, 0, 15, 15));
for (int i = 0; i < 4; i++) {
item[i] = new QGraphicsEllipseItem(0, this);
item[i]->setRect(QRectF(-90, -35 + (i * 16), 15, 15));
item[i]->setBrush(QBrush(Qt::yellow));
item[i]->setAcceptHoverEvents(true);
item[i]->setToolTip("10.31." + QString::number(i + 3) + ".130");
}
itemText[1] = new QGraphicsTextItem(0, this);
timer = new QTimer;
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timer_overflow()));
timer->start(4500);
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
myClass m;
QGraphicsView v(&m);
v.setWindowFlags(Qt::FramelessWindowHint);
v.setWindowFlags(Qt::WindowStaysOnTopHint);
v.setRenderHints(QPainter::Antialiasing);
v.show();
v.setGeometry(1320, 610, 23, 125);
return app.exec();
}