diff --git a/debian/deepin-service-plugin-network.install b/debian/deepin-service-plugin-network.install index 27c0c125..e0ebad54 100644 --- a/debian/deepin-service-plugin-network.install +++ b/debian/deepin-service-plugin-network.install @@ -1,7 +1,6 @@ /usr/share/deepin-service-manager/system/plugin-system-network.json /usr/share/deepin-service-manager/user/plugin-session-network.json -/usr/share/dbus-1/system.d/org.deepin.service.SessionNetwork.conf -/usr/share/dbus-1/system.d/org.deepin.service.SystemNetwork.conf +/usr/share/dbus-1/system.d/*.conf /usr/lib/*/deepin-service-manager/libnetwork-service.so /usr/share/deepin-service-manager/network-service/translations /usr/lib/deepin-daemon/dde-network-secret-dialog diff --git a/net-view/operation/netitem.h b/net-view/operation/netitem.h index 00c568d2..681dfcae 100644 --- a/net-view/operation/netitem.h +++ b/net-view/operation/netitem.h @@ -63,6 +63,9 @@ public Q_SLOTS: void childAdded(const NetItem *child); void childAboutToBeRemoved(const NetItem *parent, int pos); void childRemoved(const NetItem *child); + // Move过程中,会有对应的Added、Removed,使用model时需要过虑掉 + void childAboutToBeMoved(const NetItem *parent, int pos, const NetItem *newParent, int newPos); + void childMoved(const NetItem *child); void childrenChanged(); protected: diff --git a/net-view/operation/netmanager.cpp b/net-view/operation/netmanager.cpp index c8647d5a..a279dc57 100644 --- a/net-view/operation/netmanager.cpp +++ b/net-view/operation/netmanager.cpp @@ -625,8 +625,8 @@ void NetManagerPrivate::onDataChanged(int dataType, const QString &id, const QVa item->updateapMode(value.toBool()); } break; case NetManagerThreadPrivate::AvailableConnectionsChanged: { - NetWirelessDeviceItemPrivate *item = NetItemPrivate::toItem(findItem(id)); - if (item) { + NetWirelessDeviceItemPrivate *devItem = NetItemPrivate::toItem(findItem(id)); + if (devItem) { const QStringList &connList = value.toStringList(); NetItemPrivate *mine = findItem(id + ":Mine"); NetItemPrivate *other = findItem(id + ":Other"); @@ -638,24 +638,25 @@ void NetManagerPrivate::onDataChanged(int dataType, const QString &id, const QVa if (connList.contains(wirelessItem->id())) { wirelessItem->updatehasConnection(true); if (wirelessItem->getParentPrivate() == other) { - other->removeChild(wirelessItem); - } - if (wirelessItem->getParentPrivate() != mine) { + if (!mine->getParent()) { + devItem->addChild(mine); + } + other->moveChild(wirelessItem, mine); + } else if (wirelessItem->getParentPrivate() != mine) { mine->addChild(wirelessItem); } } else { wirelessItem->updatehasConnection(false); if (wirelessItem->getParentPrivate() == mine) { - mine->removeChild(wirelessItem); - } - if (wirelessItem->getParentPrivate() != other) { + mine->moveChild(wirelessItem, other); + } else if (wirelessItem->getParentPrivate() != other) { other->addChild(wirelessItem); } } } } if (!mine->getParent() && mine->getChildrenNumber() != 0) { - findItem(id)->addChild(mine); + devItem->addChild(mine); } else if (mine->getParent() && mine->getChildrenNumber() == 0) { mine->getParentPrivate()->removeChild(mine); } diff --git a/net-view/operation/private/netitemprivate.cpp b/net-view/operation/private/netitemprivate.cpp index f61bdbb6..c028e923 100644 --- a/net-view/operation/private/netitemprivate.cpp +++ b/net-view/operation/private/netitemprivate.cpp @@ -107,14 +107,8 @@ NetItem *NetItemPrivate::getChild(int childPos) const int NetItemPrivate::getChildIndex(const NetItem *child) const { - int index = 0; - for (auto it = m_children.cbegin(); it != m_children.cend(); it++, index++) { - if (*it == child) { - return index; - } - } - - return -1; + auto it = std::find(m_children.begin(), m_children.end(), child); + return it == m_children.end() ? -1 : it - m_children.begin(); } bool NetItemPrivate::addChild(NetItemPrivate *child, int index) @@ -134,19 +128,35 @@ bool NetItemPrivate::addChild(NetItemPrivate *child, int index) return true; } -void NetItemPrivate::removeChild(NetItemPrivate *child) +bool NetItemPrivate::removeChild(NetItemPrivate *child) { - int index = 0; - for (auto it = m_children.begin(); it != m_children.end(); it++, index++) { - if (*it == child->item()) { - Q_EMIT m_item->childAboutToBeRemoved(m_item, index); - m_children.erase(it); - child->m_parent = nullptr; - Q_EMIT m_item->childRemoved(child->item()); - Q_EMIT m_item->childrenChanged(); - break; - } + auto it = std::find(m_children.begin(), m_children.end(), child->item()); + if (it == m_children.end()) { + return false; + } + Q_EMIT m_item->childAboutToBeRemoved(m_item, it - m_children.begin()); + m_children.erase(it); + child->m_parent = nullptr; + Q_EMIT m_item->childRemoved(child->item()); + Q_EMIT m_item->childrenChanged(); + return true; +} + +bool NetItemPrivate::moveChild(NetItemPrivate *child, NetItemPrivate *newParent) +{ + if (!child || !newParent || child->m_parent == newParent->item()) { + return false; } + auto it = std::find(m_children.begin(), m_children.end(), child->item()); + if (it == m_children.end()) { + return false; + } + + Q_EMIT m_item->childAboutToBeMoved(m_item, it - m_children.begin(), newParent->item(), newParent->getChildrenNumber()); + removeChild(child); + newParent->addChild(child); + Q_EMIT m_item->childMoved(child->item()); + return true; } // UPDATEFUN(NetItem, const QString &, name) diff --git a/net-view/operation/private/netitemprivate.h b/net-view/operation/private/netitemprivate.h index 166b8986..7c214149 100644 --- a/net-view/operation/private/netitemprivate.h +++ b/net-view/operation/private/netitemprivate.h @@ -52,7 +52,8 @@ class NetItemPrivate public: virtual ~NetItemPrivate(); virtual bool addChild(NetItemPrivate *child, int index = -1); - void removeChild(NetItemPrivate *child); + bool removeChild(NetItemPrivate *child); + bool moveChild(NetItemPrivate *child, NetItemPrivate *newParent); void updatename(const QString &name); void updateid(const QString &id); diff --git a/net-view/operation/private/netmanagerthreadprivate.h b/net-view/operation/private/netmanagerthreadprivate.h index 77b397e7..16bc3b77 100644 --- a/net-view/operation/private/netmanagerthreadprivate.h +++ b/net-view/operation/private/netmanagerthreadprivate.h @@ -10,8 +10,8 @@ #include #include -#include #include +#include class QTimer; @@ -51,9 +51,9 @@ class NetManagerThreadPrivate : public QObject static QVariantMap CheckParamValid(const QVariantMap ¶m); static bool CheckPasswordValid(const QString &key, const QString &password); - inline bool NetCheckAvailable() { return m_netCheckAvailable; } + inline bool NetCheckAvailable() const { return m_netCheckAvailable; } - inline bool AirplaneModeEnabled() { return m_airplaneModeEnabled; } + inline bool AirplaneModeEnabled() const { return m_airplaneModeEnabled; } void setEnabled(bool enabled); void setAutoScanInterval(int ms); @@ -286,7 +286,7 @@ protected Q_SLOTS: bool m_airplaneModeEnabled; bool m_isSleeping; QString m_serverKey; - QMap m_detailsItemsMap; // 存储 NetworkDetails 指针到唯一ID的映射 + QMap m_detailsItemsMap; // 存储 NetworkDetails 指针到唯一ID的映射 QString m_showPageCmd; QTimer *m_showPageTimer; QString m_newVPNuuid; diff --git a/net-view/window/private/netmodel.cpp b/net-view/window/private/netmodel.cpp index d9791c85..855878f8 100644 --- a/net-view/window/private/netmodel.cpp +++ b/net-view/window/private/netmodel.cpp @@ -14,6 +14,7 @@ namespace network { NetModel::NetModel(QObject *parent) : QAbstractItemModel(parent) , m_treeRoot(nullptr) + , m_moving(false) { } @@ -147,10 +148,12 @@ void NetModel::connectObject(const NetItem *obj) const NetItem *o = objs.takeFirst(); connect(o, &NetItem::dataChanged, this, &NetModel::updateObject); - connect(o, &NetItem::childAboutToBeAdded, this, &NetModel::AboutToAddObject); + connect(o, &NetItem::childAboutToBeAdded, this, &NetModel::aboutToAddObject); connect(o, &NetItem::childAdded, this, &NetModel::addObject); - connect(o, &NetItem::childAboutToBeRemoved, this, &NetModel::AboutToRemoveObject); + connect(o, &NetItem::childAboutToBeRemoved, this, &NetModel::aboutToRemoveObject); connect(o, &NetItem::childRemoved, this, &NetModel::removeObject); + connect(o, &NetItem::childAboutToBeMoved, this, &NetModel::aboutToBeMoveObject); + connect(o, &NetItem::childMoved, this, &NetModel::moveObject); int i = o->getChildrenNumber(); while (i--) { objs.append(o->getChild(i)); @@ -181,29 +184,55 @@ void NetModel::updateObject() } } -void NetModel::AboutToAddObject(const NetItem *parent, int pos) +void NetModel::aboutToAddObject(const NetItem *parent, int pos) { + if (m_moving) { + return; + } QModelIndex i = index(parent); beginInsertRows(i, pos, pos); } void NetModel::addObject(const NetItem *child) { + if (m_moving) { + return; + } endInsertRows(); connectObject(child); } -void NetModel::AboutToRemoveObject(const NetItem *parent, int pos) +void NetModel::aboutToRemoveObject(const NetItem *parent, int pos) { + if (m_moving) { + return; + } QModelIndex i = index(parent); beginRemoveRows(i, pos, pos); } void NetModel::removeObject(const NetItem *child) { + if (m_moving) { + return; + } endRemoveRows(); disconnectObject(child); } +void NetModel::aboutToBeMoveObject(const NetItem *parent, int pos, const NetItem *newParent, int newPos) +{ + m_moving = true; + QModelIndex i = index(parent); + QModelIndex newI = index(newParent); + beginMoveRows(i, pos, pos, newI, newPos); +} + +void NetModel::moveObject(const NetItem *child) +{ + endMoveRows(); + m_moving = false; +} + } // namespace network } // namespace dde diff --git a/net-view/window/private/netmodel.h b/net-view/window/private/netmodel.h index 023905f3..ae17e681 100644 --- a/net-view/window/private/netmodel.h +++ b/net-view/window/private/netmodel.h @@ -40,15 +40,18 @@ class NetModel : public QAbstractItemModel void connectObject(const NetItem *obj); void disconnectObject(const NetItem *obj); -public Q_SLOTS: +protected Q_SLOTS: void updateObject(); - void AboutToAddObject(const NetItem *parent, int pos); + void aboutToAddObject(const NetItem *parent, int pos); void addObject(const NetItem *child); - void AboutToRemoveObject(const NetItem *parent, int pos); + void aboutToRemoveObject(const NetItem *parent, int pos); void removeObject(const NetItem *child); + void aboutToBeMoveObject(const NetItem *parent, int pos, const NetItem *newParent, int newPos); + void moveObject(const NetItem *child); private: NetItem *m_treeRoot; + bool m_moving; }; } // namespace network diff --git a/network-service-plugin/CMakeLists.txt b/network-service-plugin/CMakeLists.txt index ae0e2680..92e65166 100644 --- a/network-service-plugin/CMakeLists.txt +++ b/network-service-plugin/CMakeLists.txt @@ -76,8 +76,7 @@ else() endif() install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/system/deepin.dde.daemon.conf DESTINATION /etc/NetworkManager/conf.d/) -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/system/org.deepin.service.SystemNetwork.conf DESTINATION share/dbus-1/system.d/) -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/session/org.deepin.service.SessionNetwork.conf DESTINATION share/dbus-1/system.d/) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/system/org.deepin.dde.Network1.conf DESTINATION share/dbus-1/system.d/) # dde-network-secret-dialog属于network-service-plugin项目,翻译文件放一起 file(GLOB_RECURSE ALL_SRCS "*.h" "*.cpp") diff --git a/network-service-plugin/src/session/networksecretagent.cpp b/network-service-plugin/src/session/networksecretagent.cpp index 7352c345..cf098744 100644 --- a/network-service-plugin/src/session/networksecretagent.cpp +++ b/network-service-plugin/src/session/networksecretagent.cpp @@ -63,7 +63,11 @@ NetworkSecretAgent::NetworkSecretAgent(QObject *parent) : NetworkManager::SecretAgent(QStringLiteral("com.deepin.system.network.SecretAgent"), parent) , m_callNextId(0) , m_secretService(new SecretService(this)) + , m_waitClientTimer(new QTimer(this)) { + m_waitClientTimer->setSingleShot(true); + m_waitClientTimer->setInterval(5000); + connect(m_waitClientTimer, &QTimer::timeout, this, &NetworkSecretAgent::waitClientTimeOut); m_server = new QLocalServer(this); connect(m_server, &QLocalServer::newConnection, this, &NetworkSecretAgent::newConnectionHandler); m_server->setSocketOptions(QLocalServer::WorldAccessOption); @@ -203,24 +207,12 @@ void NetworkSecretAgent::askPasswords(SecretsRequest &request, const QStringList QString reqJSON = QJsonDocument(req).toJson(QJsonDocument::Compact); qCDebug(DSM()) << "reqJSON:" << reqJSON; request.inputCache = reqJSON.toUtf8(); - // 无线网密码拉起任务栏网络面板,其他使用密码输入弹窗 - if (connType == "802-11-wireless" && !m_clients.isEmpty()) { - for (auto &&client : m_clients) { - client->write("\nrequestSecrets:" + reqJSON.toUtf8() + "\n"); - } + if (connType == "802-11-wireless" && m_clients.isEmpty()) { + // 启动定时器,等待 + request.status = SecretsRequest::WaitClient; + m_waitClientTimer->start(); } else { - // run auth dialog - qCInfo(DSM()) << "run auth dialog:" << NMSecretDialogBin; - QProcess *process = new QProcess(this); - process->setProperty("callId", request.callId); - request.process = process; - connect(process, &QProcess::finished, this, &NetworkSecretAgent::authDialogFinished); - connect(process, &QProcess::readyReadStandardOutput, this, &NetworkSecretAgent::authDialogReadOutput); - connect(process, &QProcess::readyReadStandardError, this, &NetworkSecretAgent::authDialogReadError); - connect(process, &QProcess::errorOccurred, this, &NetworkSecretAgent::authDialogError); - connect(process, &QProcess::started, this, &NetworkSecretAgent::authDialogStarted); - QTimer::singleShot(GET_SECRETS_TIMEOUT, process, &QProcess::kill); - process->start(NMSecretDialogBin); + runAuthDialog(request); } } @@ -231,6 +223,8 @@ void NetworkSecretAgent::newConnectionHandler() connect(socket, &QLocalSocket::disconnected, this, &NetworkSecretAgent::disconnectedHandler); QTimer::singleShot(GET_SECRETS_TIMEOUT, socket, &QLocalSocket::disconnectFromServer); m_clients.append(socket); + m_waitClientTimer->stop(); + waitClientTimeOut(); } void NetworkSecretAgent::disconnectedHandler() @@ -537,6 +531,42 @@ void NetworkSecretAgent::doSecretsResult(QString callId, const QByteArray &data, m_calls.removeAll(*request); } +void NetworkSecretAgent::runAuthDialog(SecretsRequest &request) +{ + const QString &connType = request.connection.value("connection").value("type").toString(); + request.status = SecretsRequest::WaitDialog; + // 无线网密码拉起任务栏网络面板,其他使用密码输入弹窗 + if (connType == "802-11-wireless" && !m_clients.isEmpty()) { + for (auto &&client : m_clients) { + client->write("\nrequestSecrets:" + request.inputCache + "\n"); + } + } else { + // run auth dialog + qCInfo(DSM()) << "run auth dialog:" << NMSecretDialogBin; + QProcess *process = new QProcess(this); + process->setProperty("callId", request.callId); + request.process = process; + connect(process, &QProcess::finished, this, &NetworkSecretAgent::authDialogFinished); + connect(process, &QProcess::readyReadStandardOutput, this, &NetworkSecretAgent::authDialogReadOutput); + connect(process, &QProcess::readyReadStandardError, this, &NetworkSecretAgent::authDialogReadError); + connect(process, &QProcess::errorOccurred, this, &NetworkSecretAgent::authDialogError); + connect(process, &QProcess::started, this, &NetworkSecretAgent::authDialogStarted); + QTimer::singleShot(GET_SECRETS_TIMEOUT, process, &QProcess::kill); + process->start(NMSecretDialogBin); + } +} + +void NetworkSecretAgent::waitClientTimeOut() +{ + auto it = std::find_if(m_calls.begin(), m_calls.end(), [](const SecretsRequest &req) { + return req.status == SecretsRequest::WaitClient; + }); + + if (it != m_calls.end()) { + runAuthDialog(*it); + } +} + QString NetworkSecretAgent::nextId() { return QString::number(0xFFFFFFFF & m_callNextId++, 16); diff --git a/network-service-plugin/src/session/networksecretagent.h b/network-service-plugin/src/session/networksecretagent.h index 2aa86608..580fd573 100644 --- a/network-service-plugin/src/session/networksecretagent.h +++ b/network-service-plugin/src/session/networksecretagent.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace network { namespace sessionservice { @@ -26,7 +27,7 @@ class SecretsRequest DeleteSecrets, }; - enum Status { Begin, WaitDialog, End }; + enum Status { Begin, WaitClient, WaitDialog, End }; explicit SecretsRequest(Type _type) : type(_type) @@ -110,6 +111,9 @@ private Q_SLOTS: void authDialogStarted(); void authDialogReadAllOutput(bool isEnd); void doSecretsResult(QString callId, const QByteArray &data, bool isEnd); + void runAuthDialog(SecretsRequest &request); + + void waitClientTimeOut(); private: QString nextId(); @@ -144,6 +148,7 @@ private Q_SLOTS: QList m_clients; QByteArray m_lastData; SecretService *m_secretService; + QTimer *m_waitClientTimer; }; } // namespace sessionservice } // namespace network diff --git a/network-service-plugin/src/session/org.deepin.service.SessionNetwork.conf b/network-service-plugin/src/session/org.deepin.service.SessionNetwork.conf deleted file mode 100644 index cf4903b4..00000000 --- a/network-service-plugin/src/session/org.deepin.service.SessionNetwork.conf +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/network-service-plugin/src/system/org.deepin.service.SystemNetwork.conf b/network-service-plugin/src/system/org.deepin.dde.Network1.conf similarity index 100% rename from network-service-plugin/src/system/org.deepin.service.SystemNetwork.conf rename to network-service-plugin/src/system/org.deepin.dde.Network1.conf