-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainframe.cpp
100 lines (80 loc) · 2.92 KB
/
mainframe.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "mainframe.h"
MainFrame::MainFrame(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
{
setupUi(this);
// liste des adresse Ip
QStringList items;
QStandardItemModel * modelIp;
modelIp = new QStandardItemModel();
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
{
if (interface.flags().testFlag(QNetworkInterface::IsRunning))
foreach (QNetworkAddressEntry entry, interface.addressEntries())
{
if ( interface.hardwareAddress() != "00:00:00:00:00:00" && entry.ip().toString().contains("."))
{
//items << interface.name() + entry.ip().toString();
QStandardItem *itemIp;
itemIp = new QStandardItem();
itemIp->setData( QString("interface[%1] %2 ").arg(interface.name()).arg(entry.ip().toString()), Qt::DisplayRole );
itemIp->setData( QImage("image/station.png"), Qt::DecorationRole );
itemIp->setEditable( false );
listeInterface.append(entry.ip());
modelIp->appendRow( itemIp );
}
}
}
ipList->setModel(modelIp);
// =========================================
hello = new HelloModule();
manageS = new ManageStation( hello );
model = new QStandardItemModel();
listeStation->setModel( model);
updateList();
connect(sendButton,SIGNAL(clicked()),this,SLOT(SendBCast()));
connect(hello,SIGNAL(getSomthing(QByteArray &)),manageS,SLOT(processMessage(QByteArray &))); // lien entre hello module et manage station
connect(manageS,SIGNAL(updateListeEvent()),this, SLOT(updateList()));
connect(appliquerIpLocale,SIGNAL(clicked()),this,SLOT(setLocalIp()));
connect(ipList,SIGNAL(activated(QModelIndex)),this,SLOT(setInterface(QModelIndex)));
connect(addStation,SIGNAL(clicked()),this,SLOT(addStationIp())); // ajout de station par IP
}
MainFrame::~MainFrame(){}
void MainFrame::SendBCast()
{
hello->SendHelloBCast();
}
/*void MainFrame::showStationInfo(int index)// mise a jour de l affichage
{
ip->setText( "sdsqd");//manageS.getStation(index).ip.toString());
port->setText( QString(manageS->getStation(index).port));
//etat.setText( manageS.getStation(index).etat);
}
*/
void MainFrame::updateList()
{
model->clear();
int nb = manageS->getNbStation();
for (int i = 0; i < nb; ++i)
{
QStandardItem *item;
item = new QStandardItem();
item->setData( QString("Station %1 [%2] {port: %3} == %4 ").arg(i).arg(manageS->getStation(i).ip.toString()).arg(manageS->getStation(i).port).arg(manageS->getStation(i).etat), Qt::DisplayRole );
item->setData( QImage("image/station.png"), Qt::DecorationRole );
item->setEditable( false );
model->appendRow( item );
}
}
void MainFrame::setLocalIp()
{
hello->setLocalIP(ipLocal->text());
}
void MainFrame::setInterface(QModelIndex index)
{
ipLocal->setText(listeInterface.at(index.row()).toString());
setLocalIp();
}
void MainFrame::addStationIp()
{
//cout << " Ajout de station par IP" << endl;
hello->SendHelloIP(ipStation->text());
}