forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
de_web_widget.cpp
121 lines (99 loc) · 3.11 KB
/
de_web_widget.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright (c) 2013-2017 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#include <QLabel>
#include <QNetworkInterface>
#include "de_web_plugin.h"
#include "de_web_widget.h"
#include "ui_de_web_widget.h"
/*! Constructor. */
DeRestWidget::DeRestWidget(QWidget *parent) :
QDialog(parent),
ui(new Ui::DeWebWidget)
{
ui->setupUi(this);
setWindowTitle(tr("DE REST API"));
deCONZ::ApsController *apsCtrl = deCONZ::ApsController::instance();
quint16 httpPort = apsCtrl ? deCONZ::ApsController::instance()->getParameter(deCONZ::ParamHttpPort) : 0;
ui->ipAddressesLabel->setTextFormat(Qt::RichText);
ui->ipAddressesLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui->ipAddressesLabel->setOpenExternalLinks(true);
QString str;
QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
QList<QNetworkInterface>::Iterator ifi = ifaces.begin();
QList<QNetworkInterface>::Iterator ifend = ifaces.end();
for (; ifi != ifend; ++ifi)
{
QString name = ifi->humanReadableName();
// filter
if (name.contains("vm", Qt::CaseInsensitive) ||
name.contains("virtual", Qt::CaseInsensitive) ||
name.contains("loop", Qt::CaseInsensitive))
{
continue;
}
QList<QNetworkAddressEntry> addr = ifi->addressEntries();
QList<QNetworkAddressEntry>::Iterator i = addr.begin();
QList<QNetworkAddressEntry>::Iterator end = addr.end();
for (; i != end; ++i)
{
QHostAddress a = i->ip();
if (a.protocol() == QAbstractSocket::IPv4Protocol)
{
QString url = QString("http://%1:%2").arg(a.toString()).arg(httpPort);
str.append("<b>");
str.append(ifi->humanReadableName());
str.append("</b> ");
str.append(QString("<a href=\"%1\">%2</a><br/>").arg(url).arg(url));
}
}
}
if (httpPort == 0)
{
str = tr("No HTTP server is running");
}
ui->ipAddressesLabel->setText(str);
}
/*! Deconstructor. */
DeRestWidget::~DeRestWidget()
{
delete ui;
}
/*! Returns true if the plugin is active. */
bool DeRestWidget::pluginActive() const
{
if (ui)
{
return ui->pluginActiveCheckBox->isChecked();
}
return false;
}
void DeRestWidget::showEvent(QShowEvent *)
{
deCONZ::ApsController *apsCtrl = deCONZ::ApsController::instance();
if (!apsCtrl)
{
return;
}
QByteArray sec0 = apsCtrl->getParameter(deCONZ::ParamSecurityMaterial0);
if (!sec0.isEmpty())
{
QByteArray installCode;
for (int i = 0; i < 4; i++)
{
installCode += sec0.mid(i * 4, 4);
if (i < 3) { installCode += ' '; }
}
ui->labelInstallCode->setText(installCode);
}
else
{
ui->labelInstallCode->setText(tr("not available"));
}
}