modify: Optimize code structure and process logic

This commit is contained in:
renpeijia 2021-09-27 17:10:35 +08:00
parent c6cb607a8c
commit 2157b29004
13 changed files with 873 additions and 484 deletions

View File

@ -56,6 +56,31 @@ KyConnectItem *KyActiveConnectResourse::getActiveConnectionItem(NetworkManager::
return activeConnectItem;
}
KyConnectItem *KyActiveConnectResourse::getActiveConnectionByUuid(QString connectUuid)
{
NetworkManager::ActiveConnection::Ptr activeConnectPtr =
m_networkResourceInstance->getActiveConnect(connectUuid);
if (nullptr == activeConnectPtr) {
qWarning()<< "[KyActiveConnectResourse]" <<"it can not find connect "<< connectUuid;
return nullptr;
}
KyConnectItem *activeConnectItem = getActiveConnectionItem(activeConnectPtr);
if (nullptr == activeConnectItem) {
return nullptr;
}
QStringList interfaces = activeConnectPtr->devices();
QString ifaceUni = interfaces.at(0);
NetworkManager::Device:: Ptr devicePtr =
m_networkResourceInstance->findDeviceUni(ifaceUni);
activeConnectItem->m_ifaceName = devicePtr->interfaceName();
activeConnectItem->m_itemType = activeConnectPtr->type();
return activeConnectItem;
}
KyConnectItem *KyActiveConnectResourse::getActiveConnectionByUuid(QString connectUuid,
QString deviceName)
{

View File

@ -17,6 +17,7 @@ public:
~KyActiveConnectResourse();
public:
KyConnectItem *getActiveConnectionByUuid(QString connectUuid);
KyConnectItem *getActiveConnectionByUuid(QString connectUuid, QString deviceName);
void getActiveConnectionList(QString deviceName,
NetworkManager::ConnectionSettings::ConnectionType connectionType,

View File

@ -18,6 +18,11 @@ KyConnectItem::~KyConnectItem()
}
void KyConnectItem::setConnectUuid(QString uuid)
{
m_connectUuid = uuid;
}
void KyConnectItem::dumpInfo()
{
qDebug()<<"wired connection item info:";

View File

@ -14,6 +14,8 @@ public:
public:
void dumpInfo();
void setConnectUuid(QString uuid);
public:
QString m_connectName;
QString m_connectUuid;

View File

@ -47,6 +47,30 @@ KyConnectItem *KyConnectResourse::getConnectionItem(NetworkManager::Connection::
return connectionItem;
}
KyConnectItem * KyConnectResourse::getConnectionItemByUuid(QString connectUuid)
{
NetworkManager::Connection::Ptr connectPtr =
m_networkResourceInstance->getConnect(connectUuid);
if (nullptr == connectPtr) {
qWarning()<< "[KyConnectResourse]" <<"get connect failed, connect uuid"<<connectUuid;
return nullptr;
}
if (m_networkResourceInstance->isActiveConnection(connectPtr->uuid())) {
qDebug()<<"[KyConnectResourse]"<<connectPtr->name()<<"is active connection";
return nullptr;
}
KyConnectItem *connectItem = getConnectionItem(connectPtr);
if (nullptr != connectItem) {
connectItem->dumpInfo();
return connectItem;
}
return nullptr;
}
KyConnectItem * KyConnectResourse::getConnectionItemByUuid(QString connectUuid, QString deviceName)
{
NetworkManager::Connection::Ptr connectPtr =
@ -552,3 +576,53 @@ void KyConnectResourse::getApConnections(QList<KyApConnectItem *> &apConnectItem
return;
}
bool KyConnectResourse::isWiredConnection(QString uuid)
{
NetworkManager::Connection::Ptr connectPtr =
m_networkResourceInstance->getConnect(uuid);
if (connectPtr->isValid()) {
NetworkManager::ConnectionSettings::Ptr connectSettingPtr = connectPtr->settings();
if (connectSettingPtr.isNull()) {
qWarning()<<"[KyConnectResourse]"<<"get connect setting failed, connect uuid"<<uuid;
return false;
}
if (NetworkManager::ConnectionSettings::ConnectionType::Wired ==
connectPtr->settings()->connectionType()) {
return true;
}
}
return false;
}
bool KyConnectResourse::isWirelessConnection(QString uuid)
{
NetworkManager::Connection::Ptr connectPtr =
m_networkResourceInstance->getConnect(uuid);
if (connectPtr->isValid()) {
NetworkManager::ConnectionSettings::Ptr connectSettingPtr = connectPtr->settings();
if (connectSettingPtr.isNull()) {
qWarning()<<"[KyConnectResourse]"<<"get connect setting failed, connect uuid"<<uuid;
return false;
}
if (NetworkManager::ConnectionSettings::ConnectionType::Wireless ==
connectPtr->settings()->connectionType()) {
return true;
}
}
return false;
}
bool KyConnectResourse::isActivatedConnection(QString uuid)
{
return m_networkResourceInstance->isActiveConnection(uuid);
}

View File

@ -18,6 +18,7 @@ public:
~KyConnectResourse();
public:
KyConnectItem *getConnectionItemByUuid(QString connectUuid);
KyConnectItem *getConnectionItemByUuid(QString connectUuid, QString deviceName);
void getConnectionList(QString deviceName,
NetworkManager::ConnectionSettings::ConnectionType connectionType,
@ -30,6 +31,10 @@ public:
bool getInterfaceByUuid(QString &deviceName, NetworkManager::ConnectionSettings::ConnectionType &type, const QString connUuid);
void getConnectivity(NetworkManager::Connectivity &connectivity);
bool isWiredConnection(QString uuid);
bool isWirelessConnection(QString uuid);
bool isActivatedConnection(QString uuid);
private:
KyConnectItem *getConnectionItem(NetworkManager::Connection::Ptr connectPtr);
void getConnectIp(NetworkManager::ConnectionSettings::Ptr settingPtr,

View File

@ -166,7 +166,7 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect
connect(conn.data(), &NetworkManager::ActiveConnection::typeChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
//connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionChanged);
connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
@ -556,6 +556,10 @@ void KyNetworkResourceManager::onActiveConnectionChanged(
if (activeConnect->isValid()) {
qDebug()<<"!New state change activate connect"<<activeConnect->uuid();
qDebug()<<"!New the active connect state"<<state;
while(activeConnect->state() != state) {
qDebug()<<"connect real state"<<activeConnect->state() <<"change state"<<state;
::usleep(10000);
}
emit activeConnectStateChangeReason(activeConnect->uuid(), state,
NetworkManager::ActiveConnection::Reason::UknownReason);
} else {

View File

@ -93,9 +93,11 @@ void LanListItem::onInfoButtonClicked()
void LanListItem::onLanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
{
qDebug() <<"[LanListItem]Connection State Change to:" << state;
qDebug() <<"[LanListItem] Connection State Change to:" << state << uuid;
if (m_data->m_connectUuid == uuid) {
if (state == NetworkManager::ActiveConnection::State::Activating || state == NetworkManager::ActiveConnection::State::Deactivating) {
if (state == NetworkManager::ActiveConnection::State::Activating
|| state == NetworkManager::ActiveConnection::State::Deactivating) {
qDebug() << "[LanListItem]Activating!Loading!" << state;
m_netButton->startLoading();
} else {

View File

@ -21,11 +21,16 @@ ListItem::ListItem(QWidget *parent) : QFrame(parent)
ListItem::~ListItem()
{
if (nullptr != m_netButton) {
delete m_netButton;
m_netButton = NULL;
m_netButton = nullptr;
}
if (nullptr != m_infoButton) {
delete m_infoButton;
m_infoButton = NULL;
m_infoButton = nullptr;
}
}
void ListItem::setName(const QString &name)

File diff suppressed because it is too large Load Diff

View File

@ -30,63 +30,84 @@ public:
void showDetailPage(QString devName, QString uuid);
void setWiredDeviceEnable(const QString& devName, bool enable);
private:
void initDeviceState();
void initUI();
void initLanArea();
void initNetSwitch();
void initDeviceCombox();
void updateDeviceCombox(QString oldDeviceName, QString newDeviceName);
void deleteDeviceFromCombox(QString deviceName);
void addDeviceForCombox(QString deviceName);
QListWidgetItem *addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
void getEnabledDevice(QStringList &enableDeviceList);
void getDisabledDevices(QStringList &disableDeviceList);
void constructConnectionArea();
void constructActiveConnectionArea();
void updateConnectionArea(QString uuid);
void updateActivatedConnectionArea(QString uuid);
void updateActiveConnectionProperty(KyConnectItem *p_connectItem);
void updateConnectionProperty(KyConnectItem *p_connectItem);
void sendLanUpdateSignal(KyConnectItem *p_connectItem);
void sendLanAddSignal(KyConnectItem *p_connectItem);
void addEmptyConnectItem(QMap<KyConnectItem *, QListWidgetItem *> &connectMap,
QListWidget *lanListWidget);
void clearConnectionMap(QMap<KyConnectItem *, QListWidgetItem *> &connectMap,
QListWidget *lanListWidget);
void deleteConnectionMapItem(QMap<KyConnectItem *, QListWidgetItem *> &connectMap,
QListWidget *lanListWidget, QString uuid);
bool connectionItemIsExist(QMap<KyConnectItem *, QListWidgetItem *> &connectMap,
QString uuid);
signals:
void lanAdd(QString devName, QStringList info);
void lanRemove(QString dbusPath);
void lanUpdate(QString devName, QStringList info);
void lanActiveConnectionStateChanged(QString interface, QString uuid, int status);
void lanConnectChanged();
private:
void initDeviceState();
void initDeviceCombox();
void initUI();
void initList(QString m_deviceName);
void addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
void addNUllItem(QListWidget *listWidget);
void initNetSwitch();
private slots:
void onUpdateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
void onAddConnection(QString uuid);
void onRemoveConnection(QString path);
void onUpdateConnection(QString uuid);
void onSwithGsettingsChanged(const QString &key);
void onLanSwitchClicked();
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName);
void onDeviceNameUpdate(QString oldName, QString newName);
void onDeviceComboxIndexChanged(int currentIndex);
private:
QListWidget * m_activatedLanListWidget = nullptr;
QListWidget * m_inactivatedLanListWidget = nullptr;
LanListItem * m_nullLanItem = nullptr;
QListWidgetItem *m_nullItem = nullptr;
QListWidgetItem *m_listWidgetItem = nullptr;
KyNetworkDeviceResourse *m_device = nullptr;
KyNetworkDeviceResourse *m_deviceResource = nullptr;
KyWiredConnectOperation *m_wiredConnectOperation = nullptr;
KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接
KyConnectResourse *m_connectResourse = nullptr; //未激活的连接
QList<KyConnectItem *> m_activedList;
QList<KyConnectItem *> m_deactivedList;
// QMap<QString, QVector<QStringList> > m_deviceMap;
QMap<KyConnectItem *, QListWidgetItem *> m_deactiveMap;
QMap<KyConnectItem *, QListWidgetItem *> m_activeMap;
// QMap<LanListItem *, QListWidgetItem *> m_deactiveMap;
// QMap<LanListItem *, QListWidgetItem *> m_activeMap;
QString m_deviceName;
QString m_currentDeviceName;
QStringList m_devList;
QStringList enableDevice;
QGSettings * m_switchGsettings = nullptr;
QGSettings *m_switchGsettings = nullptr;
private slots:
void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
void addConnectionSlot(QString uuid);
void removeConnectionSlot(QString path);
void connectionUpdateSlot(QString uuid);
void onSwithGsettingsChanged(const QString &key);
void onLanSwitchClicked();
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName);
void onDeviceNameUpdate(QString oldName, QString newName);
void onDeviceComboxIndexChanged(int currentIndex);
// void onLanDataChange(QString uuid);
bool m_wiredSwitch = true;
};
#endif // LANPAGE_H

View File

@ -187,6 +187,18 @@ void saveDeviceEnableState(QString deviceName, bool enable)
return;
}
void deleteDeviceEnableState(QString deviceName)
{
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
m_settings->beginGroup("CARDEABLE");
m_settings->remove(deviceName);
m_settings->endGroup();
m_settings->sync();
delete m_settings;
m_settings = nullptr;
return;
}
void getDeviceEnableState(int type, QMap<QString, bool> &map)
{
map.clear();

View File

@ -42,6 +42,7 @@ const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.c
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName);
void setDefaultDevice(KyDeviceType deviceType, QString deviceName);
void saveDeviceEnableState(QString deviceName, bool enable);
void deleteDeviceEnableState(QString deviceName);
void getDeviceEnableState(int type, QMap<QString, bool> &map);
class TabPage : public QWidget