mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 00:03:45 +08:00
C2: display ip address in network panel (#23215)
* display ipv4 address * refactor to class * only display ip address old-commit-hash: 084ef394891360d05b272f502029f9e7e23886db
This commit is contained in:
@@ -286,15 +286,14 @@ void SoftwarePanel::updateLabels() {
|
||||
osVersionLbl->setText(QString::fromStdString(Hardware::get_os_version()).trimmed());
|
||||
}
|
||||
|
||||
QWidget * network_panel(QWidget * parent) {
|
||||
#ifdef QCOM
|
||||
QWidget *w = new QWidget(parent);
|
||||
QVBoxLayout *layout = new QVBoxLayout(w);
|
||||
C2NetworkPanel::C2NetworkPanel(QWidget *parent) : QWidget(parent) {
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(50, 0, 50, 0);
|
||||
|
||||
ListWidget *list = new ListWidget();
|
||||
list->setSpacing(30);
|
||||
// wifi + tethering buttons
|
||||
#ifdef QCOM
|
||||
auto wifiBtn = new ButtonControl("Wi-Fi Settings", "OPEN");
|
||||
QObject::connect(wifiBtn, &ButtonControl::clicked, [=]() { HardwareEon::launch_wifi(); });
|
||||
list->addItem(wifiBtn);
|
||||
@@ -302,17 +301,42 @@ QWidget * network_panel(QWidget * parent) {
|
||||
auto tetheringBtn = new ButtonControl("Tethering Settings", "OPEN");
|
||||
QObject::connect(tetheringBtn, &ButtonControl::clicked, [=]() { HardwareEon::launch_tethering(); });
|
||||
list->addItem(tetheringBtn);
|
||||
#endif
|
||||
ipaddress = new LabelControl("IP Address", "");
|
||||
list->addItem(ipaddress);
|
||||
|
||||
// SSH key management
|
||||
list->addItem(new SshToggle());
|
||||
list->addItem(new SshControl());
|
||||
|
||||
layout->addWidget(list);
|
||||
layout->addStretch(1);
|
||||
}
|
||||
|
||||
void C2NetworkPanel::showEvent(QShowEvent *event) {
|
||||
ipaddress->setText(getIPAddress());
|
||||
}
|
||||
|
||||
QString C2NetworkPanel::getIPAddress() {
|
||||
std::string result = util::check_output("ifconfig wlan0");
|
||||
if (result.empty()) return "";
|
||||
|
||||
const std::string inetaddrr = "inet addr:";
|
||||
std::string::size_type begin = result.find(inetaddrr);
|
||||
if (begin == std::string::npos) return "";
|
||||
|
||||
begin += inetaddrr.length();
|
||||
std::string::size_type end = result.find(' ', begin);
|
||||
if (end == std::string::npos) return "";
|
||||
|
||||
return result.substr(begin, end - begin).c_str();
|
||||
}
|
||||
|
||||
QWidget *network_panel(QWidget *parent) {
|
||||
#ifdef QCOM
|
||||
return new C2NetworkPanel(parent);
|
||||
#else
|
||||
Networking *w = new Networking(parent);
|
||||
return new Networking(parent);
|
||||
#endif
|
||||
return w;
|
||||
}
|
||||
|
||||
void SettingsWindow::showEvent(QShowEvent *event) {
|
||||
|
||||
@@ -77,3 +77,14 @@ private:
|
||||
Params params;
|
||||
QFileSystemWatcher *fs_watch;
|
||||
};
|
||||
|
||||
class C2NetworkPanel: public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit C2NetworkPanel(QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
QString getIPAddress();
|
||||
LabelControl *ipaddress;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user