2022-07-05 10:13:48 +08:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2023-04-21 10:03:57 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2022-07-05 10:13:48 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
2022-07-04 13:45:35 +08:00
|
|
|
#include "connectdevpage.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#define CONTENTS_MARGINS 0, 0, 0, 0
|
|
|
|
#define FRAME_MIN_SIZE 550, 60
|
|
|
|
#define FRAME_MAX_SIZE 16777215, 16777215
|
|
|
|
#define LINE_MAX_SIZE 16777215, 1
|
|
|
|
#define LINE_MIN_SIZE 0, 1
|
|
|
|
|
2022-11-09 15:14:18 +08:00
|
|
|
#define LOG_HEAD "[ConnectdevPage]"
|
|
|
|
|
2022-07-04 13:45:35 +08:00
|
|
|
ConnectdevPage::ConnectdevPage(QWidget *parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
QVBoxLayout *Vlayout = new QVBoxLayout(this);
|
|
|
|
Vlayout->setContentsMargins(CONTENTS_MARGINS);
|
|
|
|
Vlayout->setSpacing(0);
|
|
|
|
|
2023-04-06 14:09:59 +08:00
|
|
|
m_staistFrame = new QFrame(this);
|
|
|
|
m_staistFrame->setMinimumSize(FRAME_MIN_SIZE);
|
|
|
|
m_staistFrame->setMaximumSize(FRAME_MAX_SIZE);
|
|
|
|
m_staistFrame->setFrameShape(QFrame::Box);
|
2022-07-04 13:45:35 +08:00
|
|
|
|
2023-04-06 14:09:59 +08:00
|
|
|
m_staListLayout = new QVBoxLayout(m_staistFrame);
|
2022-07-04 13:45:35 +08:00
|
|
|
m_staListLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
m_staListLayout->setSpacing(0);
|
|
|
|
|
|
|
|
m_titleLabel = new TitleLabel(this);
|
|
|
|
m_titleLabel->setText(tr("Connect device"));
|
|
|
|
|
|
|
|
Vlayout->addWidget(m_titleLabel);
|
|
|
|
Vlayout->addSpacing(8);
|
2023-04-06 14:09:59 +08:00
|
|
|
Vlayout->addWidget(m_staistFrame);
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QFrame* ConnectdevPage::myLine()
|
|
|
|
{
|
|
|
|
QFrame *line = new QFrame(this);
|
|
|
|
line->setMinimumSize(QSize(LINE_MIN_SIZE));
|
|
|
|
line->setMaximumSize(QSize(LINE_MAX_SIZE));
|
|
|
|
line->setLineWidth(0);
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectdevPage::getConnectStaDevice(QMap<QString, QString> &staMap)
|
|
|
|
{
|
|
|
|
staMap.clear();
|
2022-07-15 11:19:12 +08:00
|
|
|
if (m_activePathInterface == nullptr || !m_activePathInterface->isValid()) {
|
2022-11-09 15:14:18 +08:00
|
|
|
qDebug() << LOG_HEAD << "dbus interface m_activePathInterface is invaild";
|
2022-07-05 10:23:21 +08:00
|
|
|
return;
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|
|
|
|
|
2022-07-15 11:19:12 +08:00
|
|
|
QDBusMessage reply = m_activePathInterface->call("Getstainfo");
|
2022-07-04 13:45:35 +08:00
|
|
|
if(reply.type() == QDBusMessage::ErrorMessage)
|
|
|
|
{
|
2022-11-09 15:14:18 +08:00
|
|
|
qWarning() << LOG_HEAD << "Getstainfo error:" << reply.errorMessage();
|
2022-07-04 13:45:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2022-07-15 11:19:12 +08:00
|
|
|
|
2022-07-04 13:45:35 +08:00
|
|
|
if (reply.arguments().isEmpty()
|
|
|
|
|| reply.arguments().at(0).toString() == ""
|
|
|
|
|| reply.arguments().at(0).toString() == "[Invalid UTF-8]"
|
|
|
|
|| reply.arguments().at(1).toString() == "") {
|
2022-11-09 15:14:18 +08:00
|
|
|
qDebug() << LOG_HEAD << "Dbus interface call Getstainfo return is empty!";
|
2022-07-05 10:23:21 +08:00
|
|
|
return;
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList macList = reply.arguments().at(0).toString().split(";");
|
|
|
|
QStringList hostNameList = reply.arguments().at(1).toString().split(";");
|
|
|
|
for (int index = 0; index < macList.count() && macList.at(index) != nullptr; index ++) {
|
2023-04-06 14:09:59 +08:00
|
|
|
if (!staMap.contains(macList.at(index)) && hostNameList.at(index) != nullptr) {
|
2022-07-04 13:45:35 +08:00
|
|
|
staMap[macList.at(index)] = hostNameList.at(index);
|
|
|
|
}
|
|
|
|
}
|
2022-07-15 11:19:12 +08:00
|
|
|
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectdevPage::initStaDev()
|
|
|
|
{
|
|
|
|
QMap<QString, QString>::const_iterator item = m_staMap.cbegin();
|
|
|
|
while (item != m_staMap.cend()) {
|
|
|
|
addStaDevFrame(item.key(), item.value());
|
|
|
|
item ++;
|
|
|
|
if (item != m_staMap.cend()) {
|
|
|
|
m_staListLayout->addWidget(myLine());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectdevPage::addStaDevFrame(QString staMac, QString staName)
|
|
|
|
{
|
|
|
|
ConnectDevListItem *itemFrame = new ConnectDevListItem(staMac, staName, m_staListLayout->widget());
|
|
|
|
m_staListLayout->addWidget(itemFrame);
|
|
|
|
connect(itemFrame, &ConnectDevListItem::onBtnClicked, this, &ConnectdevPage::onDropIntoBlacklistBtnClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectdevPage::clearStaListLayout()
|
|
|
|
{
|
2022-07-22 17:48:57 +08:00
|
|
|
|
2022-07-04 13:45:35 +08:00
|
|
|
if (m_staListLayout->layout() != NULL) {
|
|
|
|
QLayoutItem* layoutItem;
|
|
|
|
while ((layoutItem = m_staListLayout->layout()->takeAt(0)) != NULL) {
|
|
|
|
delete layoutItem->widget();
|
|
|
|
delete layoutItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectdevPage::onStaDevAdded(bool istrue, QString staMac, QString staName)
|
|
|
|
{
|
2022-07-22 17:48:57 +08:00
|
|
|
if (!m_staMap.contains(staMac)) {
|
|
|
|
m_staMap.insert(staMac, staName);
|
|
|
|
clearStaListLayout();
|
|
|
|
initStaDev();
|
|
|
|
resetLayoutHight();
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectdevPage::onStaDevRemoved(bool istrue, QString staMac, QString staName)
|
|
|
|
{
|
2022-07-22 17:48:57 +08:00
|
|
|
if (m_staMap.contains(staMac)) {
|
|
|
|
if (m_staMap.remove(staMac)) {
|
|
|
|
clearStaListLayout();
|
|
|
|
initStaDev();
|
|
|
|
resetLayoutHight();
|
|
|
|
}
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:48:57 +08:00
|
|
|
void ConnectdevPage::resetLayoutHight()
|
2022-07-04 13:45:35 +08:00
|
|
|
{
|
|
|
|
int height = 0;
|
|
|
|
for (int i = 0; i < m_staListLayout->count(); i ++) {
|
|
|
|
QWidget *w = m_staListLayout->itemAt(i)->widget();
|
|
|
|
if (w != nullptr) {
|
|
|
|
height += w->height();
|
|
|
|
}
|
|
|
|
}
|
2023-04-06 14:09:59 +08:00
|
|
|
m_staistFrame->setFixedHeight(height);
|
2022-07-04 13:45:35 +08:00
|
|
|
|
|
|
|
if (m_staMap.isEmpty()) {
|
|
|
|
this->hide();
|
|
|
|
} else {
|
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:48:57 +08:00
|
|
|
void ConnectdevPage::refreshStalist()
|
|
|
|
{
|
|
|
|
m_staMap.clear();
|
|
|
|
getConnectStaDevice(m_staMap);
|
|
|
|
clearStaListLayout();
|
|
|
|
initStaDev();
|
|
|
|
resetLayoutHight();
|
|
|
|
}
|
|
|
|
|
2022-11-09 15:14:18 +08:00
|
|
|
void ConnectdevPage::onDropIntoBlacklistBtnClicked(QString staMac, QString staName)
|
2022-07-04 13:45:35 +08:00
|
|
|
{
|
2022-11-09 15:14:18 +08:00
|
|
|
if (staMac.isNull()
|
|
|
|
|| staMac.isEmpty()
|
|
|
|
|| staName.isNull()
|
|
|
|
|| staName.isEmpty()) {
|
|
|
|
qDebug() << LOG_HEAD <<"On drop into blacklist button clicked error! sta mac or name is empty!";
|
2022-07-04 13:45:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-09 15:14:18 +08:00
|
|
|
emit setStaIntoBlacklist(staMac, staName);
|
2022-07-04 13:45:35 +08:00
|
|
|
}
|