perf(plugins): 调整控制面板界面单网卡显示(story#18148)

This commit is contained in:
zhangyuanyuan1 2023-08-29 11:47:28 +08:00
parent 389ebb35de
commit a771281f6b
4 changed files with 147 additions and 6 deletions

View File

@ -83,6 +83,16 @@ NetConnect::NetConnect() : mFirstLoad(true) {
pluginName = tr("LAN");
pluginType = NETWORK;
m_interface = new QDBusInterface("com.kylin.network",
"/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if(!m_interface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
updatePluginShowSettings();
connect(m_interface, SIGNAL(deviceStatusChanged()), this, SLOT(updatePluginShowSettings()),Qt::QueuedConnection);
}
NetConnect::~NetConnect() {
@ -110,6 +120,7 @@ QWidget *NetConnect::pluginUi() {
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(pluginWidget);
m_interface = new QDBusInterface("com.kylin.network",
"/com/kylin/network",
"com.kylin.network",
@ -117,6 +128,9 @@ QWidget *NetConnect::pluginUi() {
if(!m_interface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
qDBusRegisterMetaType<QVector<QStringList>>();
initSearchText();
initComponent();
}
@ -130,7 +144,54 @@ const QString NetConnect::name() const {
bool NetConnect::isEnable() const
{
return true;
//get isEnable
QDBusInterface dbus("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if (!dbus.isValid()) {
return false;
}
QMap<QString,bool> map;
QDBusReply<QVariantMap> reply = dbus.call(QStringLiteral("getDeviceListAndEnabled"),0);
if(!reply.isValid())
{
qWarning() << "[NetConnect]getWiredDeviceList error:" << reply.error().message();
return false;
}
QVariantMap::const_iterator item = reply.value().cbegin();
while (item != reply.value().cend()) {
map.insert(item.key(), item.value().toBool());
item ++;
}
bool isEnabled = !map.isEmpty();
const QByteArray schema("org.ukui.control-center.plugins");
if (QGSettings::isSchemaInstalled(schema)) {
return isEnabled;
}
//get gsettings
QGSettings *showSettings;
QString path("/org/ukui/control-center/plugins/netconnect/");
showSettings = new QGSettings(schema, path.toUtf8());
QVariant enabledState = showSettings->get("show");
//set gsettings
if (!enabledState.isValid() || enabledState.isNull()) {
qWarning() << "QGSettins get plugin show status error";
} else {
if (enabledState.toBool() != isEnabled) {
showSettings->set("show", isEnabled);
}
}
delete showSettings;
showSettings = nullptr;
return isEnabled;
}
@ -154,7 +215,8 @@ void NetConnect::initSearchText() {
ui->detailBtn->setText(tr("Advanced settings"));
ui->titleLabel->setText(tr("LAN"));
//~ contents_path /netconnect/open
ui->openLabel->setText(tr("open"));
tr("open");
ui->openLabel->setText(tr("LAN"));
}
bool NetConnect::eventFilter(QObject *w, QEvent *e) {
@ -934,3 +996,8 @@ QMap<QString, QList<QStringList>> NetConnect::getWiredList()
}
return map;
}
void NetConnect::updatePluginShowSettings()
{
isEnable();
}

View File

@ -156,6 +156,9 @@ private slots:
void onDeviceStatusChanged();
void onDeviceNameChanged(QString, QString, int);
//更新控制面板插件Gsetting show
void updatePluginShowSettings();
};
Q_DECLARE_METATYPE(QList<QDBusObjectPath>);

View File

@ -139,6 +139,15 @@ WlanConnect::WlanConnect() : m_firstLoad(true) {
pluginName = tr("WLAN");
pluginType = NETWORK;
m_interface = new QDBusInterface("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if(!m_interface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
updatePluginShowSettings();
connect(m_interface, SIGNAL(wirelessDeviceStatusChanged()), this, SLOT(updatePluginShowSettings()), Qt::QueuedConnection);
}
WlanConnect::~WlanConnect()
@ -174,6 +183,7 @@ QWidget *WlanConnect::pluginUi() {
if(!m_interface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
initSearchText();
initComponent();
}
@ -187,7 +197,61 @@ const QString WlanConnect::name() const {
bool WlanConnect::isEnable() const
{
return true;
//get isEnable
QDBusInterface dbus("com.kylin.network", "/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
if (!dbus.isValid()) {
return false;
}
QMap<QString,bool> map;
QDBusReply<QVariantMap> reply = dbus.call(QStringLiteral("getDeviceListAndEnabled"), 1);
if(!reply.isValid())
{
qWarning() << "[NetConnect]getWiredDeviceList error:" << reply.error().message();
return false;
}
QVariantMap::const_iterator item = reply.value().cbegin();
while (item != reply.value().cend()) {
map.insert(item.key(), item.value().toBool());
item ++;
}
//筛选已托管(managed)网卡
QStringList list;
QMap<QString, bool>::iterator iters;
for (iters = map.begin(); iters != map.end(); ++iters) {
if (iters.value() == true) {
list << iters.key();
}
}
bool isEnabled = !list.isEmpty();
const QByteArray schema("org.ukui.control-center.plugins");
if (QGSettings::isSchemaInstalled(schema)) {
return isEnabled;
}
//get gsettings
QGSettings *showSettings;
QString path("/org/ukui/control-center/plugins/wlanconnect/");
showSettings = new QGSettings(schema, path.toUtf8());
QVariant enabledState = showSettings->get("show");
//set gsettings
if (!enabledState.isValid() || enabledState.isNull()) {
qWarning() << "QGSettins get plugin show status error";
} else {
if (enabledState.toBool() != isEnabled) {
showSettings->set("show", isEnabled);
}
}
delete showSettings;
showSettings = nullptr;
return isEnabled;
}
@ -211,7 +275,8 @@ void WlanConnect::initSearchText() {
ui->detailBtn->setText(tr("Advanced settings"));
ui->titleLabel->setText(tr("WLAN"));
//~ contents_path /wlanconnect/open
ui->openLabel->setText(tr("open"));
tr("open");
ui->openLabel->setText(tr("WLAN"));
}
bool WlanConnect::eventFilter(QObject *w, QEvent *e) {
@ -1133,3 +1198,8 @@ QMap<QString, QList<QStringList>> WlanConnect::getWirelessList()
return map;
}
void WlanConnect::updatePluginShowSettings()
{
isEnable();
}

View File

@ -194,6 +194,7 @@ private slots:
void reScan();
//更新控制面板插件Gsetting show
void updatePluginShowSettings();
};
#endif // WLANCONNECT_H