dde-dock/plugins/network/item/deviceitem.cpp
曹威 b342f6f884 feat: 增加集中管控相关功能,所有功能可通过全局一个配置启用或禁用。
1. 模块可配置显示隐藏,能打开控制中心的右键菜单全屏蔽。
2. gsettings最终生效的设置在各个用户之间是互相隔离的,而且root用户读取不到普通用户的gsettings配置。
3. 集中管控版本右下解关机按钮右菜菜单的锁定功能改为调用SwitchTTYAndShow

Log: 引用头文件分类规范化
Task: https://pms.uniontech.com/zentao/task-view-30817.html
Change-Id: I5ae833f61864ba1874c8ceb75351d569614ab235
Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/2377
Reviewed-by: <mailman@uniontech.com>
Reviewed-by: niecheng <niecheng@uniontech.com>
Reviewed-by: wangwei <wangwei@uniontech.com>
Tested-by: <mailman@uniontech.com>
2020-08-28 14:20:32 +08:00

112 lines
2.7 KiB
C++

/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "deviceitem.h"
#include "../frame/util/utils.h"
#include <DDBusSender>
#include <QJsonDocument>
#include <QGSettings>
#include <QFile>
using namespace dde::network;
DeviceItem::DeviceItem(dde::network::NetworkDevice *device, QWidget *parent)
: QWidget(parent),
m_device(device),
m_path(device->path())
{
}
QSize DeviceItem::sizeHint() const
{
return QSize(26, 26);
}
const QString DeviceItem::itemCommand() const
{
return QString();
}
const QString DeviceItem::itemContextMenu()
{
if (m_device.isNull()) {
return QString();
}
QList<QVariant> items;
items.reserve(2);
QMap<QString, QVariant> enable;
enable["itemId"] = "enable";
if (!m_device->enabled())
enable["itemText"] = tr("Enable network");
else
enable["itemText"] = tr("Disable network");
enable["isActive"] = true;
items.push_back(enable);
if (!QFile::exists(ICBC_CONF_FILE)) {
QMap<QString, QVariant> settings;
settings["itemId"] = "settings";
settings["itemText"] = tr("Network settings");
settings["isActive"] = true;
items.push_back(settings);
}
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
return QJsonDocument::fromVariant(menu).toJson();
}
QWidget *DeviceItem::itemTips()
{
return nullptr;
}
void DeviceItem::invokeMenuItem(const QString &menuId)
{
if (m_device.isNull()) {
return;
}
if (menuId == "settings")
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter")
.method("ShowPage")
.arg(QString("network"))
.arg(m_path)
.call();
else if (menuId == "enable")
Q_EMIT requestSetDeviceEnable(m_path, !m_device->enabled());
}
QWidget *DeviceItem::itemApplet()
{
return nullptr;
}