feat: sync code

Description: sync code

Log: 同步tablet分支代码
This commit is contained in:
zhoubin 2022-12-30 11:20:02 +08:00
parent e934a4c8b3
commit b4192b88ce
112 changed files with 4777 additions and 2202 deletions

BIN
data/faces/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
data/faces/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
data/faces/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
data/faces/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
data/faces/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
data/faces/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
data/faces/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
data/faces/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
data/faces/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
data/faces/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 11 KiB

1
data/faces/default.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 256 256"><defs><style>.cls-1{fill:none;}.cls-2{clip-path:url(#clip-path);}.cls-3{opacity:0.15;}.cls-4{fill:#fff;}</style><clipPath id="clip-path"><rect class="cls-1" width="256" height="256"/></clipPath></defs><title>avatar</title><g class="cls-2"><g class="cls-2"><g class="cls-3"><g class="cls-2"><path d="M256,128A128,128,0,1,1,128,0,128,128,0,0,1,256,128"/></g></g><path class="cls-4" d="M164,143H92a30,30,0,0,0-30,30v12a18,18,0,0,0,18,18h96a18,18,0,0,0,18-18V173a30,30,0,0,0-30-30"/><path class="cls-4" d="M128,123A35,35,0,1,0,93,88a35,35,0,0,0,35,35"/></g></g></svg>

After

Width:  |  Height:  |  Size: 703 B

View File

@ -1,7 +1,7 @@
<schemalist gettext-domain="ukui-control-center">
<schema id="org.ukui.control-center" path="/org/ukui/control-center/">
<key name="fonts-list" type="as">
<default>['CESI仿宋-GB13000', 'CESI仿宋-GB18030', 'CESI仿宋-GB2312', 'CESI宋体-GB13000', 'CESI宋体-GB18030', 'CESI宋体-GB2312', 'CESI小标宋-GB13000', 'CESI小标宋-GB18030', 'CESI小标宋-GB2312', 'CESI楷体-GB13000', 'CESI楷体-GB18030', 'CESI楷体-GB2312', 'CESI黑体-GB13000', 'CESI黑体-GB18030', 'CESI黑体-GB2312', '仿宋', '黑体', '楷体', '宋体', '华文彩云', '华文仿宋', '华文琥珀', '华文楷体', '华文隶书', '华文宋体', '华文细黑', '华文行楷', '华文新魏', 'Noto Sans CJK SC', 'Noto Sans CJK SC Black', 'Noto Sans Mono CJK SC', 'Noto Sans CJK SC DemiLight', 'Noto Sans CJK SC Light', 'Noto Sans CJK SC Medium', 'Noto Sans CJK SC', 'Noto Sans CJK SC Thin','Dotted Songti Square']</default>
<default>['CESI仿宋-GB13000','CESI_FS_GB13000', 'CESI仿宋-GB18030','CESI_FS_GB18030', 'CESI仿宋-GB2312','CESI_FS_GB2312', 'CESI宋体-GB13000','CESI_SS_GB13000', 'CESI宋体-GB18030','CESI_SS_GB18030', 'CESI宋体-GB2312','CESI_SS_GB2312', 'CESI小标宋-GB13000','CESI_XBS_GB13000', 'CESI小标宋-GB18030','CESI_XBS_GB18030', 'CESI小标宋-GB2312','CESI_XBS_GB2312', 'CESI楷体-GB13000','CESI_KT_GB13000', 'CESI楷体-GB18030','CESI_KT_GB18030', 'CESI楷体-GB2312','CESI_KT_GB2312', 'CESI黑体-GB13000','CESI_HT_GB13000', 'CESI黑体-GB18030','CESI_HT_GB18030', 'CESI黑体-GB2312','CESI_HT_GB2312', '仿宋', '黑体', '楷体', '宋体', '华文彩云','STCaiyun', '华文仿宋','STFangsong', '华文琥珀','STHupo', '华文楷体','STKaiti', '华文隶书','STLiti', '华文宋体','STSong', '华文细黑','STXihei', '华文行楷','STXingkai', '华文新魏','STXinwei', 'Noto Sans CJK SC', 'Noto Sans CJK SC Black', 'Noto Sans Mono CJK SC', 'Noto Sans CJK SC DemiLight', 'Noto Sans CJK SC Light', 'Noto Sans CJK SC Medium', 'Noto Sans CJK SC', 'Noto Sans CJK SC Thin','Dotted Songti Square','WenQuanYi Bitmap Song']</default>
<summary>Control panel default font list</summary>
<description>Control panel default font list</description>
</key>

View File

@ -606,10 +606,83 @@ Kylin-OS与Kylin-OS连接过程
## 常见问题
#### 点击开始菜单上的设置按钮,无反应
在键盘上按下 Ctrl + Alt + T 组合键打开命令行终端输入“ukui-control-center”后按下Enter查看错误输出。
#### 点击开始菜单上的设置按钮,无反应
在键盘上按下 Ctrl + Alt + T 组合键打开命令行终端输入“ukui-control-center”后按下Enter查看错误输出。
#### 修改控件状态后,控件立刻还原到修改前状态
大概率是因为权限问题。
#### 激活问题
- 如何激活银河麒麟桌面操作系统V10
##### 产品密钥激活
产品密钥通常在配套DVD包装盒中由20位数字和大写字母组成连通网络输入产品密钥后点击激活提示激活成功后重启系统即可成功激活。
##### 二维码激活
二维码激活需要首先在移动设备上绑定对应的服务序列号激活权限,绑定权限后即可使用微信扫描系统二维码激活,可分为系统联网激活和系统离线激活两种情况:
系统联网的激活操作步骤如下
1. 先通过移动设备的微信扫描系统激活界面中的二维码,进入移动端授权激活界面。
2. 在移动端授权激活界面,输入服务序列号,点击“检查激活情况”,进入检查激活情况界面。
3. 在检查激活情况界面,点击“获取激活码”按钮进入确认激活界面。
4. 在确认激活界面,输入验证码,点击“获取激活码”按钮,完成移动端扫码激活操作。
5. 在系统激活界面上点击“激活”,系统即自动刷新为激活成功状态。
系统离线的激活操作步骤如下
1. 先通过移动设备的微信扫描系统激活界面中的二维码,进入移动端授权激活界面。
2. 离线二维码的移动端授权激活与联网相同,参考联网二维码移动端授权激活的步骤即可。
3. 移动端授权激活完成后,在系统二维码激活界面的“序列号”和“激活码”文本框内输入移动端扫码获取到的序列号和激活码,再点击“激活”按钮,即可完成系统激活。
##### 场地授权激活
如使用场地授权方式激活,点击“添加”选择或直接拖拽对应的“.kyinfo”和“LICENSE”文件到添加区域点击“激活”即可激活成功。
##### UKey激活
如以Ukey方式激活首先插入Ukey然后选择Ukey方式激活等待系统完成激活弹出激活成功弹窗后即可激活成功。
##### 修改授权文件
如需要修改或替换其他授权文件,可点击“修改授权文件”,将新的授权文件“添加”或“拖拽”至虚线框中,点击“导入”后,通过上述激活方式进行激活。
- 第三方软件怎么激活?
请咨询第三方软件客服,购买相关软件服务。
- 系统服务过期了会有什么影响吗?
对使用无影响,但是会有服务到期提示,不能再享受售后服务。
- 点击“激活”按钮,激活界面一直出不来怎么办?
打开终端执行命令kylin-activation 或者执行命令sudo kylin-system-verify再重新尝试激活。
- 打开激活窗口显示“系统文件检测失败”,且没有二维码怎么办?
打开终端执行命令sudo rm -rf /etc/.kyhwid再重新尝试激活。
- 如何查看系统服务到期时间?
请右键点击任务栏空白区域,点击关于麒麟即可查看到服务到期时间。
- 系统已经激活,重装之后还需要再次激活吗?
若重装时未更换主机箱内的硬件如主板、CPU、内存、显卡等可以使用之前的激活码再次对系统进行激活。
- 一个服务序列号能激活几台机器?
一个服务序列号能激活几台机器是取决于所签订的合同。
- 之前使用Ukey激活Ukey丢了可以使用二维码激活吗
不可以建议找商务重新申请Ukey。
- 激活系统报“文件检测失败错误码#0014”错误了怎么办
请检查的系统时间是否准确,若不准确,请修改系统时间后,再次尝试激活。
- 系统已经激活的系统如何看本机的注册码呢?
打开终端执行指令sudo kylin_gen_register。
- 系统服务过期提示能不能隐藏?
系统服务过期提示是无法隐藏的。
#### 权限问题
- 没有激活系统,输入命令经常提醒权限不够,无法通过管理员安装软件或运行有执行权限的脚本怎么办?
打开终端执行命令sudo setstatus softmode -p即可解决是默认开了安全导致可用命令解除安全限制
- 替换授权文件提示权限不足?
可使用命令替换在授权文件的目录下打开终端依次执行命令sudo cp .kyinfo /etc/.kyinfosudo cp LICENSE /etc/LICENSE。
#### 版本问题
- 如何查看系统版本?
可右键状态栏空白区域,选择关于麒麟查看系统版本。
- 如何查看服务序列号?
可右键任务栏空白区域,选择关于麒麟查看服务序列号。
- 如何区别哪个光盘是对应哪个版本的系统?
挂载光盘后打开挂载目录下的LICENSE或.kyinfo文件可查看版本相关信息。
- 在麒麟软件官网上申请的试用版本使用期限是多久?
在麒麟软件官网上申请的试用版本可以一直使用,但是不享受售后服务。
- 怎么查看内核版本?
可右键任务栏空白区域,选择关于麒麟查看系统内核版本。
- 银河麒麟桌面操作系统有什么版本?
目前有银河麒麟桌面操作系统V4、银河麒麟桌面操作系统V10银河麒麟桌面操作系统V7.0三个大版本。
- 银河麒麟桌面操作系统不同大版本之间有什么区别?
不同大版本之间会有内核或者其他的层面的不同,具体可咨询商务或者参考官网对不同版本的系统介绍。
- 电脑装了Windows 10和银河麒麟桌面操作系统V10双系统数据盘可以共用吗
可以共用。
#### 显示问题
- Ctrl+alt+T无法打开终端怎么办
通过开始菜单打开终端执行ukui-settings-daemon看是否会报错。
- 开始菜单无法打开了怎么办?
可通过删除./face文件解决打开终端执行指令sudo rm -f~/.face。
- 在哪里关闭锁屏并且设置锁屏时间?
打开开始菜单-设置-个性化-锁屏来设置锁屏时间。
在键盘上按下 Ctrl + Alt + T 组合键打开命令行终端输入“rm ~/.config/dconf/user”后按下Enter。
<br>

17
debian/changelog vendored
View File

@ -1,3 +1,20 @@
ukui-control-center (3.22.1.25-ok3)yangtze; urgency=medium
* bug#150500接HDMI第一次打开设置窗口无法调节亮度
* 任务号task#123628内置系统和应用中文图文用户手册要包括使用说明、示例、常见故障处理
* bug#149658控制面板中的显示器界面会闪现多屏显示横
* bug#123876控制面板支持设置文泉驿点阵宋体
* bug#150057输入为空修改用户昵称失败
* bug#150087删除用户组页面按钮 标语不准确
* bug#119449控制面板切换分辨率成功实际未生效
* bug#148048账户信息中的修改密码功能不生效
* bug#149641按钮的宽度显示未按规范
* bug#149642通知更多操作被截断
* 需求:无
* 其他改动影响:无
-- zhoubin <zhoubin@kylinos.cn> Fri, 30 Dec 2022 09:27:40 +0800
ukui-control-center (3.22.1.25-ok2) yangtze; urgency=medium
* 提交commitdbaebd

1
debian/control vendored
View File

@ -41,6 +41,7 @@ Build-Depends: debhelper-compat (= 12),
libkysdk-sysinfo-dev,
libkysdk-waylandhelper-dev,
libkysdk-diagnostics-dev,
libkf5service-dev,
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: https://github.com/ukui/ukui-control-center

View File

@ -44,7 +44,7 @@ enum FunType {
SECURITY,
APPLICATION,
SEARCH_F,
CURRENCY,
COMMONINFO,
TOTALMODULES,
};

View File

@ -93,3 +93,8 @@ void SwitchWidget::insertWidget(int index, QWidget *widget, int stretch, Qt::Ali
mainLayout->insertWidget(index, widget, stretch, alignment);
}
KSwitchButton *SwitchWidget::switchButton() const
{
return m_switchButton;
}

View File

@ -107,6 +107,14 @@ public:
*/
void insertWidget(int index, QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());
/**
* @brief m_slider
* @return KSlider: m_slider
*/
KSwitchButton *switchButton() const;
private:
void init();

View File

@ -193,7 +193,7 @@ void changeUserGroup::initUI()
mCancelButton = new QPushButton(tr("Cancel"), this);
mCancelButton->setFixedSize(110, 40);
mConfirmButton = new QPushButton(tr("Confirm"), this);
mConfirmButton = new QPushButton(tr("Save"), this);
mConfirmButton->setFixedSize(110, 40);
cancelAndConfirmHLayout->addStretch();
@ -608,7 +608,7 @@ void changeUserGroup::addUserGroupSlot()
void changeUserGroup::delUserGroupSlot()
{
QMessageBox *delUserGroupMessage = new QMessageBox(this);
delUserGroupMessage->setWindowModality(Qt::WindowModal);
delUserGroupMessage->setWindowModality(Qt::ApplicationModal);
delUserGroupMessage->setIcon(QMessageBox::Warning);
delUserGroupMessage->setText(tr("Whether delete the group: “%1” ?").arg(mAllUserGroupModel->index(currentRow,0).data().toString()));
delUserGroupMessage->setInformativeText(tr("which will make some file components in the file system invalid!"));

View File

@ -55,8 +55,8 @@ ChangeUserLogo::~ChangeUserLogo()
void ChangeUserLogo::loadSystemLogo(){
logosFlowLayout = new FlowLayout(10, -1, -1);
logosFlowLayout->setContentsMargins(0, 0, 0, 10);
logosFlowLayout = new FlowLayout(0, 8, 8);
logosFlowLayout->setContentsMargins(0, 0, 0, 0);
// 遍历头像目录
QDir facesDir = QDir(FACEPATH);
@ -75,6 +75,11 @@ void ChangeUserLogo::loadSystemLogo(){
continue;
}
// 2107头像资源保留但不在弹窗显示
if (!fullface.contains("-")) {
continue;
}
QPushButton *button = new QPushButton;
button->setCheckable(true);
button->setAttribute(Qt::WA_DeleteOnClose);
@ -98,8 +103,8 @@ void ChangeUserLogo::loadSystemLogo(){
}
logosFrame = new QFrame;
logosFrame->setMinimumSize(QSize(352, 142));
logosFrame->setMaximumSize(QSize(16777215, 142));
logosFrame->setMinimumSize(QSize(355, 138));
logosFrame->setMaximumSize(QSize(16777215, 138));
logosFrame->setFrameShape(QFrame::Box);
logosFrame->setFrameShadow(QFrame::Plain);
logosFrame->setLayout(logosFlowLayout);
@ -178,32 +183,39 @@ void ChangeUserLogo::initUI()
setLayout(culMainVerLayout);
}
QPixmap ChangeUserLogo::makeRoundLogo(QString logo, int wsize, int hsize, int radius){
QPixmap ChangeUserLogo::makeRoundLogo(QString logo, int wsize, int hsize, int radius)
{
QPixmap rectPixmap;
QPixmap iconcop = QPixmap(logo);
qreal dpi = culLogoLabel->devicePixelRatioF();
if (dpi > 1.0) {
wsize = wsize * dpi;
hsize = hsize * dpi;
}
if (iconcop.width() > iconcop.height()) {
QPixmap iconPixmap = iconcop.copy((iconcop.width() - iconcop.height())/2, 0, iconcop.height(), iconcop.height());
// 根据label高度等比例缩放图片
rectPixmap = iconPixmap.scaledToHeight(hsize);
rectPixmap = iconPixmap.scaledToHeight(hsize, Qt::SmoothTransformation);
} else {
QPixmap iconPixmap = iconcop.copy(0, (iconcop.height() - iconcop.width())/2, iconcop.width(), iconcop.width());
// 根据label宽度等比例缩放图片
rectPixmap = iconPixmap.scaledToWidth(wsize);
rectPixmap = iconPixmap.scaledToWidth(wsize, Qt::SmoothTransformation);
}
if (rectPixmap.isNull()) {
return QPixmap();
}
QPixmap pixmapa(rectPixmap);
QPixmap pixmap(radius*2,radius*2);
QPixmap pixmap(radius * 2 * dpi, radius * 2 * dpi);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QPainterPath path;
path.addEllipse(0, 0, radius*2, radius*2);
path.addEllipse(0, 0, radius * 2 * dpi, radius * 2 * dpi);
painter.setClipPath(path);
painter.drawPixmap(0, 0, radius*2, radius*2, pixmapa);
painter.drawPixmap(0, 0, radius * 2 * dpi, radius * 2 * dpi, pixmapa);
pixmap.setDevicePixelRatio(dpi);
return pixmap;
}

View File

@ -38,7 +38,6 @@ ChangeUserNickname::ChangeUserNickname(QString nn, QStringList ns, QString op, Q
initUI();
setConnect();
setupStatus();
}
ChangeUserNickname::~ChangeUserNickname()
@ -76,8 +75,6 @@ void ChangeUserNickname::initUI(){
tipLabel->setFont(ft);
tipLabel->setFixedSize(QSize(300, 36));
tipLabel->setStyleSheet("color:red;");
QString tipinfo = tr("nickName already in use.");
setTextDynamicInNick(tipLabel, tipinfo);
nickNameLineEdit = new QLineEdit();
nickNameLineEdit->setFixedSize(QSize(300, 36));
@ -138,28 +135,9 @@ void ChangeUserNickname::initUI(){
void ChangeUserNickname::setConnect(){
nickNameLineEdit->installEventFilter(this);
connect(nickNameLineEdit, &QLineEdit::editingFinished, this, [=]{
if (nickNameLineEdit->text().isEmpty()){
nickNameLineEdit->setText(QString(g_get_real_name()));
}
});
oldName = nickNameLineEdit->text();
connect(nickNameLineEdit, &QLineEdit::textEdited, this, [=](QString txt){
if (namesIsExists.contains(txt)){
tipLabel->show();
confirmBtn->setEnabled(false);
} else if(nickNameLineEdit->text().length() > NICKNAME_LENGTH) {
nickNameLineEdit->setText(oldName);
QString tipinfo = tr("The length must be 1~%1 characters!").arg(NICKNAME_LENGTH);
setTextDynamicInNick(tipLabel, tipinfo);
tipLabel->show();
confirmBtn->setEnabled(true);
} else {
oldName = txt;
tipLabel->hide();
confirmBtn->setEnabled(true);
}
nameLegalityCheck(txt);
refreshConfirmBtnStatus();
});
connect(confirmBtn, &QPushButton::clicked, this, [=]{
@ -172,6 +150,36 @@ void ChangeUserNickname::setConnect(){
});
}
void ChangeUserNickname::nameLegalityCheck(QString nickname)
{
if (nickname.isEmpty()){
tipString = tr("NickName's length must between 1~%1 characters!").arg(NICKNAME_LENGTH);
} else if (namesIsExists.contains(nickname)){
tipString = tr("nickName already in use.");
} else if (nickNameLineEdit->text().contains(":")) {
tipString = tr("Can't contains ':'.");
} else if(nickname.length() > NICKNAME_LENGTH) {
nickNameLineEdit->setText(oldNickName);
} else {
oldNickName = nickname;
tipString = tr("");
}
setTextDynamicInNick(tipLabel, tipString);
refreshConfirmBtnStatus();
}
void ChangeUserNickname::refreshConfirmBtnStatus()
{
if (!tipLabel->text().isEmpty() || nickNameLineEdit->text().isEmpty()) {
confirmBtn->setEnabled(false);
} else {
confirmBtn->setEnabled(true);
}
}
void ChangeUserNickname::setupStatus(){
tipLabel->hide();
}
@ -222,6 +230,7 @@ bool ChangeUserNickname::eventFilter(QObject *watched, QEvent *event){
if (watched == nickNameLineEdit){
if (QString::compare(nickNameLineEdit->text(), g_get_real_name()) == 0){
nickNameLineEdit->setText("");
refreshConfirmBtnStatus();
}
}
}

View File

@ -56,11 +56,14 @@ protected:
private:
bool setTextDynamicInNick(QLabel * label, QString string);
void nameLegalityCheck(QString nickname);
void refreshConfirmBtnStatus();
private:
QString realname;
QString oldName;
QStringList namesIsExists;
QString tipString;
QString oldNickName;
QDBusInterface * cniface;

View File

@ -380,8 +380,30 @@ void ChangeUserPwd::setupConnect(){
} else {
//修改密码
QString output;
QString currentPwd = currentPwdLineEdit->text();
int ci = 0;
for (ci = 0; ci < currentPwd.count(); ci++){
if (!(int(currentPwd.at(ci).toLatin1() >= 48 && int(currentPwd.at(ci).toLatin1()) <= 57) ||
int(currentPwd.at(ci).toLatin1() >= 65 && int(currentPwd.at(ci).toLatin1()) <= 90) ||
int(currentPwd.at(ci).toLatin1() >= 97 && int(currentPwd.at(ci).toLatin1()) <= 122))){
char * cmd = g_strdup_printf("/usr/bin/changeuserpwd '%s' '%s'", currentPwdLineEdit->text().toLatin1().data(), newPwdLineEdit->text().toLatin1().data());
currentPwd = currentPwd.insert(ci, QString("\\"));
ci++;
}
}
QString newPwd = newPwdLineEdit->text();
int i = 0;
for (i = 0; i < newPwd.count(); i++){
if (!(int(newPwd.at(i).toLatin1() >= 48 && int(newPwd.at(i).toLatin1()) <= 57) ||
int(newPwd.at(i).toLatin1() >= 65 && int(newPwd.at(i).toLatin1()) <= 90) ||
int(newPwd.at(i).toLatin1() >= 97 && int(newPwd.at(i).toLatin1()) <= 122))){
newPwd = newPwd.insert(i, QString("\\"));
i++;
}
}
char * cmd = g_strdup_printf("/usr/bin/changeuserpwd %s %s", currentPwd.toLatin1().data(), newPwd.toLatin1().data());
FILE *stream = NULL;
char buf[256] = {0};
@ -546,11 +568,8 @@ void ChangeUserPwd::refreshConfirmBtnStatus(){
}
}
bool ChangeUserPwd::isContainLegitimacyChar(QString word){
//需要用'在shell解释中做强引用
if (word.contains("'"))
return false;
bool ChangeUserPwd::isContainLegitimacyChar(QString word)
{
foreach (QChar ch, word){
if (int(ch.toLatin1() <= 0 || int(ch.toLatin1()) > 127)){
return false;

View File

@ -23,6 +23,8 @@
#include "closebutton.h"
#include "changeusergroup.h"
#define GROUPNAME_LENGTH 32
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
CreateGroupDialog::CreateGroupDialog(QWidget *parent) :
@ -52,6 +54,7 @@ void CreateGroupDialog::initUI()
mGroupNameLabel = new QLabel(tr("Name"), this);
mGroupNameLabel->setFixedSize(62, 36);
mGroupNameEdit = new QLineEdit(this);
mGroupNameEdit->installEventFilter(this);
mGroupNameEdit->setFixedSize(370, 36);
mGroupNameHLayout = new QHBoxLayout(this);
@ -60,6 +63,18 @@ void CreateGroupDialog::initUI()
mGroupNameHLayout->addWidget(mGroupNameLabel);
mGroupNameHLayout->addWidget(mGroupNameEdit);
mGroupNameTipLabel = new FixLabel();
mGroupNameTipLabel->setFixedWidth(370);
QFont ft;
ft.setPixelSize(14);
mGroupNameTipLabel->setFont(ft);
mGroupNameTipLabel->setFixedSize(QSize(370, 24));
mGroupNameTipLabel->setStyleSheet("color:red;");
mGroupNameTipHLayout = new QHBoxLayout();
mGroupNameTipHLayout->setContentsMargins(0,0,0,0);
mGroupNameTipHLayout->addStretch();
mGroupNameTipHLayout->addWidget(mGroupNameTipLabel);
mGroupIdLabel = new QLabel(tr("Id"), this);
mGroupIdLabel->setFixedSize(62, 36);
mGroupIdEdit = new QLineEdit(this);
@ -85,7 +100,7 @@ void CreateGroupDialog::initUI()
vlayout->addStretch();
vlayout->addSpacing(20);
vlayout->addLayout(mGroupNameHLayout);
vlayout->addSpacing(16);
vlayout->addLayout(mGroupNameTipHLayout);
vlayout->addLayout(mGroupIdHLayout);
vlayout->addSpacing(40);
vlayout->addLayout(mConfirmHLaout);
@ -166,9 +181,9 @@ void CreateGroupDialog::signalsBind()
}
}
});
connect(mGroupNameEdit, &QLineEdit::textEdited, [=](){
connect(mGroupNameEdit, &QLineEdit::textEdited, [=](QString txt){
for (int j=0; j < cgDialog->groupList->size(); j++) {
if (mGroupIdEdit->text() == cgDialog->groupList->at(j)->groupname) {
if (mGroupNameEdit->text() == cgDialog->groupList->at(j)->groupname) {
_nameHasModified = false;
break;
} else {
@ -177,6 +192,30 @@ void CreateGroupDialog::signalsBind()
}
}
}
});
if (mGroupNameEdit->text().length() > GROUPNAME_LENGTH) {
mGroupNameEdit->setText(oldGroupName);
} else {
oldGroupName = txt;
}
if(mGroupNameEdit->text().isEmpty()) {
mGroupNameTip = tr("GroupName's length must be between 1 and %1 characters!").arg(GROUPNAME_LENGTH);
} else {
mGroupNameTip = "";
}
mGroupNameTipLabel->setText(mGroupNameTip);
});
}
bool CreateGroupDialog::eventFilter(QObject *watched, QEvent *event){
if (event->type() == QEvent::FocusOut) {
if (watched == mGroupNameEdit) {
if (mGroupNameEdit->text().isEmpty()) {
mGroupNameTip = tr("GroupName's length must be between 1 and %1 characters!").arg(GROUPNAME_LENGTH);
mGroupNameTipLabel->setText(mGroupNameTip);
}
}
}
return QObject::eventFilter(watched, event);
}

View File

@ -34,6 +34,8 @@
#include <QLabel>
#include <QPushButton>
#include "widgets/Label/fixlabel.h"
class changeUserGroup;
namespace Ui {
class CreateGroupDialog;
@ -74,12 +76,20 @@ private:
QHBoxLayout *mGroupNameHLayout;
QHBoxLayout *mGroupIdHLayout;
QHBoxLayout *mConfirmHLaout;
QHBoxLayout *mGroupNameTipHLayout;
bool _nameHasModified;
bool _idHasModified;
QString oldGroupName;
FixLabel *mGroupNameTipLabel;
QString mGroupNameTip;
void initUI();
void signalsBind();
protected:
bool eventFilter(QObject *watched, QEvent *event);
};
#endif // CREATEGROUPDIALOG_H

View File

@ -330,8 +330,8 @@ void CreateUserNew::setConnect(){
usernameLineEdit->setText(oldName);
} else {
oldName = txt;
nameLegalityCheck(txt);
}
nameLegalityCheck(txt);
});
connect(nicknameLineEdit, &QLineEdit::textEdited, this, [=](QString txt){
@ -500,12 +500,11 @@ bool CreateUserNew::nameTraverse(QString username){
void CreateUserNew::nameLegalityCheck2(QString nickname){
if (nickname.isEmpty()){
nickNameTip = tr("The nick name cannot be empty");
nickNameTip = tr("NickName's length must between 1~%1 characters!").arg(NICKNAME_LENGTH);
} else if (_allNames.contains(nickname)){
nickNameTip = tr("nickName already in use.");
} else if(nickname.length() > NICKNAME_LENGTH) {
nicknameLineEdit->setText(oldNickName);
nickNameTip = tr("nickName length must less than %1 letters!").arg(NICKNAME_LENGTH);
} else {
oldNickName = nickname;
nickNameTip = tr("");
@ -656,7 +655,7 @@ bool CreateUserNew::eventFilter(QObject *watched, QEvent *event){
}
} else if (watched == nicknameLineEdit) {
if (nicknameLineEdit->text().isEmpty()) {
nickNameTip = tr("The nick name cannot be empty");
nickNameTip = tr("NickName's length must between 1~%1 characters!");
setCunTextDynamic(nicknameTipLabel, nickNameTip);
}
} else if (watched == newPwdLineEdit) {

View File

@ -45,7 +45,7 @@ void ElipseMaskWidget::paintEvent(QPaintEvent *e){
Q_UNUSED(e)
QPainterPath cPath;
cPath.addRect(0, 0, pWidth, pHeigh);
cPath.addRect(-1, -1, pWidth+2, pHeigh+2);
cPath.addEllipse(0, 0, pWidth, pHeigh);
QPainter painter(this);

View File

@ -25,14 +25,20 @@ void PwdCheckThread::run(){
QByteArray ba1 = uname.toLatin1();
//
if (upwd.contains("'")){
snprintf(command, 128, "/usr/bin/checkUserPwd %s \"%s\"", ba1.data(), upwd.toLatin1().data());
} else {
QString currentPwd = upwd;
int ci = 0;
for (ci = 0; ci < currentPwd.count(); ci++){
if (!(int(currentPwd.at(ci).toLatin1() >= 48 && int(currentPwd.at(ci).toLatin1()) <= 57) ||
int(currentPwd.at(ci).toLatin1() >= 65 && int(currentPwd.at(ci).toLatin1()) <= 90) ||
int(currentPwd.at(ci).toLatin1() >= 97 && int(currentPwd.at(ci).toLatin1()) <= 122))){
snprintf(command, 128, "/usr/bin/checkUserPwd %s '%s'", ba1.data(), upwd.toLatin1().data());
currentPwd = currentPwd.insert(ci, QString("\\"));
ci++;
}
}
snprintf(command, 128, "/usr/bin/checkUserPwd %s %s", ba1.data(), currentPwd.toLatin1().data());
if ((stream = popen(command, "r")) != NULL){
while(fgets(output, 256, stream) != NULL){

View File

@ -620,29 +620,34 @@ QPixmap UserInfo::makeRoundLogo(QString logo, int wsize, int hsize, int radius)
{
QPixmap rectPixmap;
QPixmap iconcop = QPixmap(logo);
qreal dpi = currentUserlogoBtn->devicePixelRatioF();
if (dpi > 1.0) {
wsize = wsize * dpi;
hsize = hsize * dpi;
}
if (iconcop.width() > iconcop.height()) {
QPixmap iconPixmap = iconcop.copy((iconcop.width() - iconcop.height())/2, 0, iconcop.height(), iconcop.height());
// 根据label高度等比例缩放图片
rectPixmap = iconPixmap.scaledToHeight(hsize);
rectPixmap = iconPixmap.scaledToHeight(hsize, Qt::SmoothTransformation);
} else {
QPixmap iconPixmap = iconcop.copy(0, (iconcop.height() - iconcop.width())/2, iconcop.width(), iconcop.width());
// 根据label宽度等比例缩放图片
rectPixmap = iconPixmap.scaledToWidth(wsize);
rectPixmap = iconPixmap.scaledToWidth(wsize, Qt::SmoothTransformation);
}
if (rectPixmap.isNull()) {
return QPixmap();
}
QPixmap pixmapa(rectPixmap);
QPixmap pixmap(radius*2,radius*2);
QPixmap pixmap(radius * 2 * dpi, radius * 2 * dpi);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QPainterPath path;
path.addEllipse(0, 0, radius*2, radius*2);
path.addEllipse(0, 0, radius * 2 * dpi, radius * 2 * dpi);
painter.setClipPath(path);
painter.drawPixmap(0, 0, radius*2, radius*2, pixmapa);
painter.drawPixmap(0, 0, radius * 2 * dpi, radius * 2 * dpi, pixmapa);
pixmap.setDevicePixelRatio(dpi);
return pixmap;
}

View File

@ -37,6 +37,7 @@ PKGCONFIG += gio-2.0 \
gsettings-qt \
kysdk-qtwidgets \
kysdk-sysinfo \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -220,7 +220,6 @@ void AutoBoot::initItem(AutoApp &it)
deBtn->setStyleSheet("QToolButton:!checked{background-color: palette(base)}");
deBtn->setProperty("useButtonPalette", true);
deBtn->setPopupMode(QToolButton::InstantPopup);
deBtn->setFixedSize(QSize(36, 36));
deBtn->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic"));
RMenu *pMenu = new RMenu(deBtn);

View File

@ -30,7 +30,8 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

View File

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
@ -21,6 +21,11 @@
#include <QDebug>
#include <QVBoxLayout>
#include <QApplication>
#include <KSycoca>
#include <KApplicationTrader>
#include <KSharedConfig>
#include <KConfigGroup>
#include "defaultapp.h"
#include "common.h"
@ -31,11 +36,14 @@
#define VIDEOTYPE "video/mp4"
#define TEXTTYPE "text/plain"
#define DESKTOPPATH "/usr/share/applications/"
#define UKCC_EXENAME "ukui-control-center"
#define LOCAL_CONFIG_DIR "/.config/"
#define LOCAL_APP_DIR "/.local/share/applications/"
#define SYSTEM_CONFIG_DIR "/usr/share/applications/"
static bool mimeTypeLessThan(const QMimeType &m1, const QMimeType &m2)
{
return m1.name() < m2.name();
}
DefaultApp::DefaultApp() : mFirstLoad(true)
{
@ -62,15 +70,12 @@ QWidget *DefaultApp::pluginUi() {
mFirstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
mDefaultString = tr("No program available");
mSelectString = tr("Choose default app");
initUi(pluginWidget);
setupCompenent();
initUi(pluginWidget);
initSearchText();
initDefaultUI();
initSlots();
connectToServer();
// watchFileChange();
}
return pluginWidget;
}
@ -139,45 +144,47 @@ void DefaultApp::initSlots() {
connect(mVideoFrame, &ComboxWidget::currentIndexChanged, this, &DefaultApp::videoComBoBox_changed_cb);
connect(mTextFrame, &ComboxWidget::currentIndexChanged, this, &DefaultApp::textComBoBox_changed_cb);
connect(mResetFrame, &PushButtonWidget::clicked, this, &DefaultApp::reset);
connect(KSycoca::self(), static_cast<void(KSycoca::*)()>(&KSycoca::databaseChanged), this, [=]() {
if (qAppName() == QLatin1String(UKCC_EXENAME))
return;
initDefaultUI();
});
}
/* 初始化各默认应用 */
void DefaultApp::initDefaultUI() {
// 若默认应用被卸载,显示"选择默认应用",若不存在其它应用,则显示"无可用程序"
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
mBrowserFrame->blockSignals(true);
mImageFrame->blockSignals(true);
mMailFrame->blockSignals(true);
mAudioFrame->blockSignals(true);
mVideoFrame->blockSignals(true);
mTextFrame->blockSignals(true);
// 删除之后,在获取时更新缓存配置文件
QFile::remove(KSycoca::absoluteFilePath());
KSycoca::self()->ensureCacheValid();
// BROWSER
initDefaultAppInfo(BROWSERTYPE,mBrowserFrame);
load(mBrowserFrame, BROWSERTYPE);
// IMAGE
initDefaultAppInfo(IMAGETYPE,mImageFrame);
load(mImageFrame, IMAGETYPE);
// MAIL
initDefaultAppInfo(MAILTYPE,mMailFrame);
load(mMailFrame, MAILTYPE);
// AUDIO
initDefaultAppInfo(AUDIOTYPE,mAudioFrame);
load(mAudioFrame, AUDIOTYPE);
// VIDEO
initDefaultAppInfo(VIDEOTYPE,mVideoFrame);
load(mVideoFrame, VIDEOTYPE);
// TEXT
initDefaultAppInfo(TEXTTYPE,mTextFrame);
load(mTextFrame, TEXTTYPE);
}
mBrowserFrame->blockSignals(false);
mImageFrame->blockSignals(false);
mMailFrame->blockSignals(false);
mAudioFrame->blockSignals(false);
mVideoFrame->blockSignals(false);
mTextFrame->blockSignals(false);
void DefaultApp::setupCompenent()
{
mDefaultString = tr("No program available");
mSelectString = tr("Choose default app");
mLocalMimefile = QDir::homePath() + LOCAL_CONFIG_DIR + "mimeapps.list";
mBrowserMimeTypeList << "x-scheme-handler/http" << "x-scheme-handler/https" << "x-scheme-handler/about" << "text/html";
mMailMimeTypeList << "x-scheme-handler/mailto" << "application/x-extension-eml" << "message/rfc822";
mTextMimeTypeList << "text/plain";
getSystemDefaultAppList();
}
/* 添加搜索索引 */
@ -190,106 +197,29 @@ void DefaultApp::initSearchText() {
//~ contents_path /Defaultapp/Text Editor
}
/* 设置各默认应用初始状态 */
void DefaultApp::initDefaultAppInfo(const char* type, ComboxWidget *widget)
{
widget->comboBox()->clear();
QString currentapp(getDefaultAppId(type));
if (!currentapp.isEmpty()) {
QByteArray ba = QString(DESKTOPPATH + currentapp).toUtf8();
GDesktopAppInfo * info = g_desktop_app_info_new_from_filename(ba.constData());
QString appname = g_app_info_get_name(G_APP_INFO(info));
const char * iconname = g_icon_to_string(g_app_info_get_icon(G_APP_INFO(info)));
QIcon appicon;
appicon = QIcon::fromTheme(QString(QLatin1String(iconname)),
QIcon(QString("/usr/share/pixmaps/"+QString(QLatin1String(iconname))
+".png")));
widget->comboBox()->addItem(appicon, appname, currentapp);
} else {
widget->comboBox()->addItem(mSelectString);
widget->setCurrentText(mSelectString);
mAppCount++;
}
// 将可用程序加入列表
QtConcurrent::run([=]() {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QString current(getDefaultAppId(type));
QVector<AppList> list = getAppIdList(type);
if (!list.isEmpty()) {
for (int i = 0; i < list.size(); i++) {
QString single(list[i].strAppid);
if (type == VIDEOTYPE && single == "kylin-music.desktop") //屏蔽视频播放器里面的音乐
continue;
QByteArray ba = QString(DESKTOPPATH + single).toUtf8();
GDesktopAppInfo * info = g_desktop_app_info_new_from_filename(ba.constData());
QString appname = g_app_info_get_name(G_APP_INFO(info));
const char * iconname = g_icon_to_string(g_app_info_get_icon(G_APP_INFO(info)));
QIcon appicon;
appicon = QIcon::fromTheme(QString(QLatin1String(iconname)),
QIcon(QString("/usr/share/pixmaps/"+QString(QLatin1String(iconname))
+".png")));
if (current == single) {
continue;
}
if (appname.isEmpty())
continue;
widget->comboBox()->addItem(appicon, appname, single);
}
}
if (widget->comboBox()->count() == 1 && currentapp.isEmpty()) {
mAppCount--;
widget->comboBox()->clear();
widget->comboBox()->addItem(mDefaultString);
widget->setCurrentText(mDefaultString);
}
});
}
/* 重构界面 */
void DefaultApp::resetUi()
{
mBrowserFrame->blockSignals(true);
mAudioFrame->blockSignals(true);
mImageFrame->blockSignals(true);
mTextFrame->blockSignals(true);
mMailFrame->blockSignals(true);
mVideoFrame->blockSignals(true);
initDefaultUI();
mBrowserFrame->blockSignals(false);
mAudioFrame->blockSignals(false);
mImageFrame->blockSignals(false);
mTextFrame->blockSignals(false);
mMailFrame->blockSignals(false);
mVideoFrame->blockSignals(false);
}
/* BROWSER SLOT */
void DefaultApp::browserComBoBox_changed_cb(int index) {
QtConcurrent::run([=] {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QTime timedebuge;
timedebuge.start();
QString appid = mBrowserFrame->comboBox()->itemData(index).toString();
QByteArray ba = appid.toUtf8(); // QString to char *
setWebBrowsersDefaultProgram(ba.data());
setDefaultApp(appid, BROWSERTYPE);
findSelectItem(mBrowserFrame->comboBox());
Common::buriedSettings(name(), "the default browser", QString("settings"), ba.data());
qDebug()<<"browserComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";//输出计时
Common::buriedSettings(name(), "the default browser", QString("settings"), appid);
qDebug()<<"browserComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";
});
}
/* MAIL SLOT */
void DefaultApp::mailComBoBox_changed_cb(int index) {
QtConcurrent::run([=] {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QTime timedebuge;
timedebuge.start();
QString appid = mMailFrame->comboBox()->itemData(index).toString();
QByteArray ba = appid.toUtf8(); // QString to char *
setMailReadersDefaultProgram(ba.data());
setDefaultApp(appid, MAILTYPE);
findSelectItem(mMailFrame->comboBox());
Common::buriedSettings(name(), "the defaultapp to open mail", QString("settings"), ba.data());
qDebug()<<"mailComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";//输出计时
Common::buriedSettings(name(), "the defaultapp to open mail", QString("settings"), appid);
qDebug()<<"mailComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";
});
}
@ -297,14 +227,13 @@ void DefaultApp::mailComBoBox_changed_cb(int index) {
void DefaultApp::imageComBoBox_changed_cb(int index) {
QtConcurrent::run([=] {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QTime timedebuge;
timedebuge.start();
QString appid = mImageFrame->comboBox()->itemData(index).toString();
QByteArray ba = appid.toUtf8(); // QString to char *
setImageViewersDefaultProgram(ba.data());
setDefaultApp(appid, IMAGETYPE);
findSelectItem(mImageFrame->comboBox());
Common::buriedSettings(name(), "the defaultapp to open image", QString("settings"), ba.data());
qDebug()<<"imageComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";//输出计时
Common::buriedSettings(name(), "the defaultapp to open image", QString("settings"), appid);
qDebug()<<"imageComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";
});
}
@ -312,14 +241,13 @@ void DefaultApp::imageComBoBox_changed_cb(int index) {
void DefaultApp::audioComBoBox_changed_cb(int index) {
QtConcurrent::run([=] {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QTime timedebuge;
timedebuge.start();
QString appid = mAudioFrame->comboBox()->itemData(index).toString();
QByteArray ba = appid.toUtf8(); // QString to char *
setAudioPlayersDefaultProgram(ba.data());
setDefaultApp(appid, AUDIOTYPE);
findSelectItem(mAudioFrame->comboBox());
Common::buriedSettings(name(), "the defaultapp to play audio", QString("settings"), ba.data());
qDebug()<<"audioComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";//输出计时
Common::buriedSettings(name(), "the defaultapp to play audio", QString("settings"), appid);
qDebug()<<"audioComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";
});
}
@ -327,14 +255,13 @@ void DefaultApp::audioComBoBox_changed_cb(int index) {
void DefaultApp::videoComBoBox_changed_cb(int index) {
QtConcurrent::run([=] {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QTime timedebuge;
timedebuge.start();
QString appid = mVideoFrame->comboBox()->itemData(index).toString();
QByteArray ba = appid.toUtf8(); // QString to char *
setVideoPlayersDefaultProgram(ba.data());
setDefaultApp(appid, VIDEOTYPE);
findSelectItem(mVideoFrame->comboBox());
Common::buriedSettings(name(), "the defaultapp to play video", QString("settings"), ba.data());
qDebug()<<"videoComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";//输出计时
Common::buriedSettings(name(), "the defaultapp to play video", QString("settings"), appid);
qDebug()<<"videoComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";
});
}
@ -342,381 +269,184 @@ void DefaultApp::videoComBoBox_changed_cb(int index) {
void DefaultApp::textComBoBox_changed_cb(int index) {
QtConcurrent::run([=] {
QTime timedebuge;//声明一个时钟对象
timedebuge.start();//开始计时
QTime timedebuge;
timedebuge.start();
QString appid = mTextFrame->comboBox()->itemData(index).toString();
QByteArray ba = appid.toUtf8(); // QString to char *
setTextEditorsDefautlProgram(ba.data());
setDefaultApp(appid, TEXTTYPE);
findSelectItem(mTextFrame->comboBox());
Common::buriedSettings(name(), "the defaultapp to open text", QString("settings"), ba.data());
qDebug()<<"textComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";//输出计时
Common::buriedSettings(name(), "the defaultapp to open text", QString("settings"), appid);
qDebug()<<"textComBoBox_changed_cb线程耗时"<<timedebuge.elapsed()<<"ms";
});
}
/* 获取默认应用的应用名 */
QString DefaultApp::getDefaultAppId(const char *contentType) {
QString localfile = QDir::homePath() + LOCAL_CONFIG_DIR + "mimeapps.list";
QString systemfile = SYSTEM_CONFIG_DIR + QString("ukui-mimeapps.list");
if (QFile(localfile).exists()) {
QSettings* mimeappFile = new QSettings(localfile, QSettings::IniFormat);
mimeappFile->setIniCodec("utf-8");
QString str = mimeappFile->value(QString("Default Applications/%1").arg(contentType)).toString();
if (!str.isEmpty()) {
if (QFile(SYSTEM_CONFIG_DIR +str).exists()) {
return str;
} else if (QFile(QDir::homePath() + LOCAL_APP_DIR + str).exists()) {
QDBusInterface ukccDbus("com.control.center.qt.systemdbus",
"/",
"com.control.center.interface",
QDBusConnection::systemBus());
QDBusReply<bool> reply = ukccDbus.call("copyFile", QDir::homePath() + LOCAL_APP_DIR + str, SYSTEM_CONFIG_DIR +str);
if (reply)
return str;
}
}
delete mimeappFile;
mimeappFile = nullptr;
}
if (QFile(systemfile).exists()) {
QSettings* mimeappFile = new QSettings(systemfile, QSettings::IniFormat);
mimeappFile->setIniCodec("utf-8");
QString str = mimeappFile->value(QString("Default Applications/%1").arg(contentType)).toString();
if (!str.isEmpty()) {
if (QFile(SYSTEM_CONFIG_DIR +str).exists()) {
return str;
} else if (QFile(QDir::homePath() + LOCAL_APP_DIR + str).exists()) {
QDBusInterface ukccDbus("com.control.center.qt.systemdbus",
"/",
"com.control.center.interface",
QDBusConnection::systemBus());
QDBusReply<bool> reply = ukccDbus.call("copyFile", QDir::homePath() + LOCAL_APP_DIR + str, SYSTEM_CONFIG_DIR +str);
if (reply)
return str;
}
}
delete mimeappFile;
mimeappFile = nullptr;
}
return QString("");
QStringList DefaultApp::getMimeAppsDir()
{
return QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation) + QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
}
/* 获取可用应用列表 */
QVector<AppList> DefaultApp::getAppIdList(const char *contentType) {
QVector<AppList> appList;
appList.clear();
QVector<Appinfo> appinfo = _getAppList(contentType);
if (!appinfo.isEmpty()) {
for(int j = 0; j < appinfo.size(); j++) {
const char *id = g_app_info_get_id(appinfo[j].item);
if (id != NULL) {
AppList al;
al.strAppid = QString(id);
appList.append(al);
}
}
}
return appList;
}
void DefaultApp::load(ComboxWidget *widget, const char *mimeType, const QString &type)
{
widget->comboBox()->blockSignals(true);
widget->comboBox()->clear();
KService::Ptr defaultservice = getDefaultApp(mimeType);
/* 获取可用应用信息列表 */
QVector<Appinfo> DefaultApp::_getAppList(const char *contentType) {
GList *applist;
applist = g_app_info_get_all_for_type(contentType);
GAppInfo * item;
QVector<Appinfo> appinfo;
appinfo.clear();
if (applist != NULL) {
int len = g_list_length(applist);
//获取应用列表
for (int index=0; index < len; index++) {
item = (GAppInfo*) g_list_nth_data(applist, index);
Appinfo ai;
ai.item = item;
appinfo.append(ai);
}
}
return appinfo;
}
/* Set Default Browser */
bool DefaultApp::setWebBrowsersDefaultProgram(char * appid) {
qDebug() << __func__ << __LINE__;
const char * content_type = "x-scheme-handler/http";
QVector<Appinfo> appinfo = _getAppList(content_type);
bool judge = false;
if (!appinfo.isEmpty()) {
for(int i = 0; i < appinfo.size(); i++) {
const char *id = g_app_info_get_id(appinfo[i].item);
int result = strcmp(id,appid);
if (0 == result) {
GAppInfo *appitem=appinfo[i].item;
gboolean ret1=g_app_info_set_as_default_for_type(appitem, "x-scheme-handler/http", NULL);
gboolean ret2=g_app_info_set_as_default_for_type(appitem, "x-scheme-handler/https", NULL);
gboolean ret3=g_app_info_set_as_default_for_type(appitem, "x-scheme-handler/about", NULL);
gboolean ret4=g_app_info_set_as_default_for_type(appitem, "text/html", NULL);
if(ret1 && ret2 && ret3 && ret4)
judge=true;
break;
}
}
}
qDebug() << __func__ << __LINE__;
return judge;
}
/* Set Default Mail */
bool DefaultApp::setMailReadersDefaultProgram(char *appid) {
const char *content_type="x-scheme-handler/mailto";
QVector<Appinfo> appinfo = _getAppList(content_type);
bool judge = false;
if (!appinfo.isEmpty()) {
for (int i = 0; i < appinfo.size(); i++) {
const char * id = g_app_info_get_id(appinfo[i].item);
int result=strcmp(id,appid);
if (0 == result) {
GAppInfo *appitem=appinfo[i].item;
gboolean ret1=g_app_info_set_as_default_for_type(appitem, "x-scheme-handler/mailto", NULL);
gboolean ret2=g_app_info_set_as_default_for_type(appitem, "application/x-extension-eml", NULL);
gboolean ret3=g_app_info_set_as_default_for_type(appitem, "message/rfc822", NULL);
if(ret1 && ret2 && ret3)
judge=true;
break;
}
}
}
return judge;
}
/* Set Default Image */
bool DefaultApp::setImageViewersDefaultProgram(char *appid) {
const char *content_type="image/png";
QVector<Appinfo> appinfo = _getAppList(content_type);
bool judge = false;
if (!appinfo.isEmpty()) {
for (int i=0; i < appinfo.size();i++){
const char *id = g_app_info_get_id(appinfo[i].item);
int result = strcmp(id, appid);
if (0 == result) {
GAppInfo *appitem=appinfo[i].item;
gboolean ret1 = g_app_info_set_as_default_for_type(appitem, "image/bmp", NULL);
gboolean ret2 = g_app_info_set_as_default_for_type(appitem, "image/gif", NULL);
gboolean ret3 = g_app_info_set_as_default_for_type(appitem, "image/jpeg", NULL);
gboolean ret4 = g_app_info_set_as_default_for_type(appitem, "image/png", NULL);
gboolean ret5 = g_app_info_set_as_default_for_type(appitem, "image/tiff", NULL);
gboolean ret6 = g_app_info_set_as_default_for_type(appitem, "image/webp", NULL);
gboolean ret7 = g_app_info_set_as_default_for_type(appitem, "image/x-xbitmap", NULL);
gboolean ret8 = g_app_info_set_as_default_for_type(appitem, "image/x-xpixmap", NULL);
gboolean ret9 = g_app_info_set_as_default_for_type(appitem, "image/x-icon", NULL);
if(ret1 && ret2 && ret3 && ret4 && ret5 && ret6 && ret7 && ret8 && ret9)
judge=true;
break;
}
}
// 若默认应用被卸载,显示"选择默认应用",若不存在其它应用,则显示"无可用程序"
if (!defaultservice) {
widget->comboBox()->addItem(mSelectString);
} else {
widget->comboBox()->addItem(QIcon::fromTheme(defaultservice->icon(),
QIcon(QString("/usr/share/pixmaps/" + defaultservice->icon()+ ".png"))),
defaultservice->name(), defaultservice->storageId());
}
return judge;
}
KApplicationTrader::queryByMimeType(mimeType, [=](const KService::Ptr &service) {
if (service->exec().isEmpty() || (!type.isEmpty() && !service->categories().contains(type)) || (!service->serviceTypes().contains(mimeType)))
return false;
// 视频播放器屏蔽音乐
if (mimeType == VIDEOTYPE && service->storageId().contains("kylin-music.desktop"))
return false;
if (defaultservice && service->storageId() == defaultservice->storageId())
return false;
widget->comboBox()->addItem(QIcon::fromTheme(service->icon(),
QIcon(QString("/usr/share/pixmaps/" + service->icon() + ".png"))),
service->name(), service->storageId());
return false;
});
/* Set Default Video */
bool DefaultApp::setVideoPlayersDefaultProgram(char *appid) {
const char *content_type = "video/x-ogm+ogg";
QVector<Appinfo> appinfo = _getAppList(content_type);
bool judge = false;
if (!appinfo.isEmpty()) {
for(int i = 0; i < appinfo.size(); i++) {
const char *id = g_app_info_get_id(appinfo[i].item);
int result = strcmp(id,appid);
if (0 == result) {
GAppInfo *appitem = appinfo[i].item;
gboolean ret1 = g_app_info_set_as_default_for_type(appitem, "video/mp4", NULL);
gboolean ret2 = g_app_info_set_as_default_for_type(appitem, "video/mpeg", NULL);
gboolean ret3 = g_app_info_set_as_default_for_type(appitem, "video/mp2t", NULL);
gboolean ret4 = g_app_info_set_as_default_for_type(appitem, "video/msvideo", NULL);
gboolean ret5 = g_app_info_set_as_default_for_type(appitem, "video/quicktime", NULL);
gboolean ret6 = g_app_info_set_as_default_for_type(appitem, "video/webm", NULL);
gboolean ret7 = g_app_info_set_as_default_for_type(appitem, "video/x-avi", NULL);
gboolean ret8 = g_app_info_set_as_default_for_type(appitem, "video/x-flv", NULL);
gboolean ret9 = g_app_info_set_as_default_for_type(appitem, "video/x-matroska", NULL);
gboolean ret10 = g_app_info_set_as_default_for_type(appitem, "video/x-mpeg", NULL);
gboolean ret11 = g_app_info_set_as_default_for_type(appitem, "video/x-ogm+ogg", NULL);
gboolean ret12 = g_app_info_set_as_default_for_type(appitem, "video/rm", NULL);
gboolean ret13 = g_app_info_set_as_default_for_type(appitem, "video/3pg", NULL);
gboolean ret14 = g_app_info_set_as_default_for_type(appitem, "video/asf", NULL);
gboolean ret15 = g_app_info_set_as_default_for_type(appitem, "video/3gp", NULL);
gboolean ret16 = g_app_info_set_as_default_for_type(appitem, "video/3gpp", NULL);
gboolean ret17 = g_app_info_set_as_default_for_type(appitem, "video/3gpp2", NULL);
gboolean ret18 = g_app_info_set_as_default_for_type(appitem, "video/x-ms-afs", NULL);
gboolean ret19 = g_app_info_set_as_default_for_type(appitem, "video/x-ms-asf", NULL);
gboolean ret20 = g_app_info_set_as_default_for_type(appitem, "video/x-mpeg2", NULL);
gboolean ret21 = g_app_info_set_as_default_for_type(appitem, "video/x-mpeg3", NULL);
gboolean ret22 = g_app_info_set_as_default_for_type(appitem, "video/mp4v-es", NULL);
gboolean ret23 = g_app_info_set_as_default_for_type(appitem, "video/x-m4v", NULL);
gboolean ret24 = g_app_info_set_as_default_for_type(appitem, "video/divx", NULL);
gboolean ret25 = g_app_info_set_as_default_for_type(appitem, "video/vnd.divx", NULL);
gboolean ret26 = g_app_info_set_as_default_for_type(appitem, "video/x-msvideo", NULL);
gboolean ret27 = g_app_info_set_as_default_for_type(appitem, "video/ogg", NULL);
gboolean ret28 = g_app_info_set_as_default_for_type(appitem, "video/vnd.rn-realvideo", NULL);
gboolean ret29 = g_app_info_set_as_default_for_type(appitem, "video/x-ms-wmv", NULL);
gboolean ret30 = g_app_info_set_as_default_for_type(appitem, "video/x-ms-wmx", NULL);
gboolean ret31 = g_app_info_set_as_default_for_type(appitem, "video/x-ms-wvxvideo", NULL);
gboolean ret32 = g_app_info_set_as_default_for_type(appitem, "video/avi", NULL);
gboolean ret33 = g_app_info_set_as_default_for_type(appitem, "video/x-flic", NULL);
gboolean ret34 = g_app_info_set_as_default_for_type(appitem, "video/fli", NULL);
gboolean ret35 = g_app_info_set_as_default_for_type(appitem, "video/x-flc", NULL);
gboolean ret36 = g_app_info_set_as_default_for_type(appitem, "video/flv", NULL);
gboolean ret37 = g_app_info_set_as_default_for_type(appitem, "video/x-theora", NULL);
gboolean ret38 = g_app_info_set_as_default_for_type(appitem, "video/x-theora+ogg", NULL);
gboolean ret39 = g_app_info_set_as_default_for_type(appitem, "video/mkv", NULL);
gboolean ret40 = g_app_info_set_as_default_for_type(appitem, "video/x-ogm", NULL);
gboolean ret41 = g_app_info_set_as_default_for_type(appitem, "video/vnd.mpegurl", NULL);
gboolean ret42 = g_app_info_set_as_default_for_type(appitem, "video/dv", NULL);
gboolean ret43 = g_app_info_set_as_default_for_type(appitem, "application/vnd.rn-realmedia", NULL);
gboolean ret44 = g_app_info_set_as_default_for_type(appitem, "application/vnd.rn-realmedia-vbr", NULL);
if (ret1 && ret2 && ret3 && ret4 && ret5 && ret6 && ret7 && ret8 && ret9 && ret10 && ret11 && \
ret12 && ret13 && ret14 && ret15 && ret16 && ret17 && ret18 && ret19 && ret20 && ret21 && \
ret22 && ret23 && ret24 && ret25 && ret26 && ret27 && ret28 && ret29 && ret30 && \
ret31 && ret32 && ret33 && ret34 && ret35 && ret36 && ret37 && ret38 && ret39 && \
ret40 && ret41 && ret42 && ret43 && ret44)
judge=true;
break;
}
}
if (!defaultservice && widget->comboBox()->count() == 1) {
widget->comboBox()->clear();
widget->comboBox()->addItem(mDefaultString);
}
return judge;
}
/* Set Default Audio */
bool DefaultApp::setAudioPlayersDefaultProgram(char *appid) {
const char *content_type = "audio/x-vorbis+ogg";
QVector<Appinfo> appinfo = _getAppList(content_type);
bool judge = false;
if (!appinfo.isEmpty()) {
for(int i = 0; i < appinfo.size() ;i++) {
const char *id = g_app_info_get_id(appinfo[i].item);
int result = strcmp(id,appid);
if (0 == result) {
GAppInfo *appitem=appinfo[i].item;
gboolean ret1 = g_app_info_set_as_default_for_type(appitem, "audio/mpeg", NULL);
gboolean ret2 = g_app_info_set_as_default_for_type(appitem, "audio/x-mpegurl", NULL);
gboolean ret3 = g_app_info_set_as_default_for_type(appitem, "audio/x-scpls", NULL);
gboolean ret4 = g_app_info_set_as_default_for_type(appitem, "audio/x-vorbis+ogg", NULL);
gboolean ret5 = g_app_info_set_as_default_for_type(appitem, "audio/x-wav", NULL);
gboolean ret6 = g_app_info_set_as_default_for_type(appitem, "audio/x-ms-wma", NULL);
gboolean ret7 = g_app_info_set_as_default_for_type(appitem, "audio/x-flac", NULL);
gboolean ret8 = g_app_info_set_as_default_for_type(appitem, "audio/ac3", NULL);
gboolean ret9 = g_app_info_set_as_default_for_type(appitem, "audio/acc", NULL);
gboolean ret10 = g_app_info_set_as_default_for_type(appitem, "audio/aac", NULL);
gboolean ret11 = g_app_info_set_as_default_for_type(appitem, "audio/AMR", NULL);
gboolean ret12 = g_app_info_set_as_default_for_type(appitem, "audio/x-m4r", NULL);
gboolean ret13 = g_app_info_set_as_default_for_type(appitem, "audio/midi", NULL);
gboolean ret14 = g_app_info_set_as_default_for_type(appitem, "audio/mp2", NULL);
gboolean ret15 = g_app_info_set_as_default_for_type(appitem, "audio/x-wavpack", NULL);
gboolean ret16 = g_app_info_set_as_default_for_type(appitem, "audio/x-ape", NULL);
gboolean ret17 = g_app_info_set_as_default_for_type(appitem, "audio/x-mmf", NULL);
gboolean ret18 = g_app_info_set_as_default_for_type(appitem, "audio/mp3", NULL);
gboolean ret19 = g_app_info_set_as_default_for_type(appitem, "audio/flac", NULL);
gboolean ret20 = g_app_info_set_as_default_for_type(appitem, "audio/wma", NULL);
gboolean ret21 = g_app_info_set_as_default_for_type(appitem, "audio/amr", NULL);
gboolean ret22 = g_app_info_set_as_default_for_type(appitem, "audio/vnd.dts", NULL);
gboolean ret23 = g_app_info_set_as_default_for_type(appitem, "audio/basic", NULL);
gboolean ret24 = g_app_info_set_as_default_for_type(appitem, "audio/x-aiff", NULL);
gboolean ret25 = g_app_info_set_as_default_for_type(appitem, "audio/x-matroska", NULL);
gboolean ret26 = g_app_info_set_as_default_for_type(appitem, "audio/x-voc", NULL);
gboolean ret27 = g_app_info_set_as_default_for_type(appitem, "application/x-smaf", NULL);
if(ret1 && ret2 && ret3 && ret4 && ret5 && ret6 && ret7 && ret8 && ret9 && ret10 && ret11 && ret12 && ret13 && ret14
&& ret15 && ret16 && ret17 && ret18 && ret19 && ret20 && ret21 && ret22 && ret23 && ret24 && ret25 && ret26
&& ret27) {
judge=true;
}
break;
}
}
}
return judge;
}
/* Set Default Text */
bool DefaultApp::setTextEditorsDefautlProgram(char *appid) {
const char * content_type = "text/plain";
QVector<Appinfo> appinfo = _getAppList(content_type);
bool judge = false;
if (!appinfo.isEmpty()) {
for (int i = 0;i < appinfo.size(); i++) {
const char * id = g_app_info_get_id(appinfo[i].item);
int result = strcmp(id,appid);
if (0 == result) {
GAppInfo *appitem = appinfo[i].item;
gboolean ret1 = g_app_info_set_as_default_for_type(appitem, "text/plain", NULL);
if(ret1)
judge=true;
break;
}
}
}
return judge;
widget->comboBox()->blockSignals(false);
}
void DefaultApp::connectToServer()
{
QThread *NetThread = new QThread;
MThread *NetWorker = new MThread;
NetWorker->moveToThread(NetThread);
connect(NetThread, &QThread::started, NetWorker, &MThread::run);
connect(NetWorker,&MThread::keychangedsignal,this,&DefaultApp::keyChangedSlot);
connect(NetThread, &QThread::finished, NetWorker, &MThread::deleteLater);
NetThread->start();
QThread *netThread = new QThread;
MThread *netWorker = new MThread;
netWorker->moveToThread(netThread);
connect(netThread, &QThread::started, netWorker, &MThread::run);
connect(netWorker,&MThread::keychangedsignal,this,&DefaultApp::keyChangedSlot);
connect(netThread, &QThread::finished, netWorker, &MThread::deleteLater);
netThread->start();
}
/* 监听默认应用的改变刷新界面 */
void DefaultApp::watchFileChange()
void DefaultApp::getSystemDefaultAppList()
{
watchfile = QDir::homePath() + "/.config/mimeapps.list";
mConfigFileWatcher = new QFileSystemWatcher(this);
mConfigFileWatcher->addPath(watchfile);
connect(mConfigFileWatcher, &QFileSystemWatcher::fileChanged, this, [=](){
if (!mComboChange)
resetUi();
mComboChange = false;
mConfigFileWatcher->removePath(watchfile);
mConfigFileWatcher->addPath(watchfile);
});
QStringList mimeappsFileNames;
const QString desktops = QString::fromLocal8Bit(qgetenv("XDG_CURRENT_DESKTOP"));
const auto list = desktops.split(QLatin1Char(':'));
for (const QString &desktop : list) {
mimeappsFileNames.append(desktop.toLower() + QLatin1String("-mimeapps.list"));
}
const QStringList mimeappsDirs = getMimeAppsDir();
for (const QString &dir : mimeappsDirs) {
for (QString file : mimeappsFileNames) {
// 系统目录配置文件
QString filePath = dir + QLatin1Char('/') + file;
if (QFile::exists(filePath)) {
QSettings* mimeappFile = new QSettings(filePath, QSettings::IniFormat);
mimeappFile->setIniCodec("utf-8");
mSysDefaultList[BROWSERTYPE] = mimeappFile->value(QString("Default Applications/%1").arg(BROWSERTYPE)).toString();
mSysDefaultList[AUDIOTYPE] = mimeappFile->value(QString("Default Applications/%1").arg(AUDIOTYPE)).toString();
mSysDefaultList[VIDEOTYPE] = mimeappFile->value(QString("Default Applications/%1").arg(VIDEOTYPE)).toString();
mSysDefaultList[IMAGETYPE] = mimeappFile->value(QString("Default Applications/%1").arg(IMAGETYPE)).toString();
mSysDefaultList[TEXTTYPE] = mimeappFile->value(QString("Default Applications/%1").arg(TEXTTYPE)).toString();
mSysDefaultList[MAILTYPE] = mimeappFile->value(QString("Default Applications/%1").arg(MAILTYPE)).toString();
delete mimeappFile;
mimeappFile = nullptr;
return;
}
}
}
}
void DefaultApp::findSelectItem(QComboBox *combox)
{
if (mAppCount == 0)
return;
for (int i = 0; i < combox->count(); i++) {
if (combox->itemText(i) == mSelectString) {
combox->removeItem(i);
mAppCount--;
break;
}
}
}
void DefaultApp::keyChangedSlot(const QString &key) {
if(key == "default-open") {
resetUi();
void DefaultApp::setDefaultApp(const QString &storageId, const char *mimeType)
{
if (mimeType == BROWSERTYPE) {
for (const QString str : mBrowserMimeTypeList)
saveMimeTypeAssociation(str, storageId);
} else if (mimeType == TEXTTYPE) {
for (const QString str : mTextMimeTypeList)
saveMimeTypeAssociation(str, storageId);
} else if (mimeType == MAILTYPE) {
for (const QString str : mMailMimeTypeList)
saveMimeTypeAssociation(str, storageId);
} else {
QMimeDatabase datebase;
auto list = datebase.allMimeTypes();
const QString maj = QString(mimeType).left(QString(mimeType).indexOf(QLatin1Char('/')));
std::sort(list.begin(), list.end(), mimeTypeLessThan);
for (auto it = list.constBegin(); it != list.constEnd(); ++it) {
const QString mimetype = it->name();
if (maj == mimetype.left(mimetype.indexOf(QLatin1Char('/')))) {
saveMimeTypeAssociation(mimetype, storageId);
}
}
}
}
void DefaultApp::saveMimeTypeAssociation(const QString &mime, const QString &storageId)
{
KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation);
if (profile->isConfigWritable(true)) {
KConfigGroup defaultApp(profile, "Default Applications");
defaultApp.writeEntry(mime, QStringList(storageId));
KConfigGroup addedApps(profile, QStringLiteral("Added Associations"));
QStringList apps = addedApps.readXdgListEntry(mime);
apps.removeAll(storageId);
apps.prepend(storageId);
addedApps.writeXdgListEntry(mime, apps);
profile->sync();
}
}
KService::Ptr DefaultApp::getDefaultApp(const char *mimeType)
{
KService::Ptr currentService;
KService::Ptr preferredService = KApplicationTrader::preferredService(mimeType);
if (QFile(mLocalMimefile).exists()) {
QSettings* mimeappFile = new QSettings(mLocalMimefile, QSettings::IniFormat);
mimeappFile->setIniCodec("utf-8");
QString desktopFile = mimeappFile->value(QString("Added Associations/%1").arg(mimeType)).toString();
if (!desktopFile.isEmpty()) {
if (preferredService)
currentService = preferredService;
}
delete mimeappFile;
mimeappFile = nullptr;
}
if(preferredService && preferredService->storageId().contains(mSysDefaultList[mimeType])) {
currentService = preferredService;
}
return currentService;
}
void DefaultApp::keyChangedSlot(const QString &key) {
if(key == "default-open")
initDefaultUI();
}
void DefaultApp::reset()
{
Common::buriedSettings(name(), "reset defaultapp", QString("clicked"));
QString localfile = QDir::homePath() + LOCAL_CONFIG_DIR + "mimeapps.list";
QFile(localfile).remove();
mAppCount = 0;
if (!QFile(mLocalMimefile).exists())
return;
QFile(mLocalMimefile).remove();
initDefaultUI();
}

View File

@ -31,6 +31,8 @@
#include <QIcon>
#include <QFileSystemWatcher>
#include <QDBusInterface>
#include <QMap>
#include <KService>
#include "shell/interface.h"
@ -86,26 +88,20 @@ public:
void initUi(QWidget *widget);
void initDefaultUI();
void setupCompenent();
void initSlots();
void initSearchText();
void initDefaultAppInfo(const char*type, ComboxWidget *widget);
void resetUi();
bool setWebBrowsersDefaultProgram(char *appid);
bool setMailReadersDefaultProgram(char *appid);
bool setImageViewersDefaultProgram(char *appid);
bool setAudioPlayersDefaultProgram(char *appid);
bool setVideoPlayersDefaultProgram(char *appid);
bool setTextEditorsDefautlProgram(char *appid);
void load(ComboxWidget *widget, const char *mimeType, const QString &type = NULL);
void connectToServer();
void watchFileChange();
void findSelectItem(QComboBox *combox);
void setDefaultApp(const QString &storageId, const char *mimeType);
void saveMimeTypeAssociation(const QString &mime, const QString &storageId);
private:
QString getDefaultAppId(const char *contentType);
QVector<AppList> getAppIdList(const char *contentType);
static QVector<Appinfo> _getAppList(const char *contentType);
void getSystemDefaultAppList();
KService::Ptr getDefaultApp(const char *mimeType);
QStringList getMimeAppsDir();
private:
Ui::DefaultAppWindow *ui;
@ -124,25 +120,17 @@ private:
int pluginType;
QDBusInterface *m_cloudInterface;
QString mDefaultBrowser;
QString mDefaultMail;
QString mDefaultPic;
QString mDefaultAdudio;
QString mDefaultVideonum;
QString mDefaultText;
QString mDefaultString;
QString mSelectString;
QStringList browserList;
QString watchfile;
QString mLocalMimefile;
bool mFirstLoad;
bool mComboChange = false;
int mAppCount = 0; // 用作记录缺少默认应用的选项数目
QStringList mBrowserMimeTypeList;
QStringList mMailMimeTypeList;
QStringList mTextMimeTypeList;
QFileSystemWatcher *mConfigFileWatcher;
QMap <const char *, QString> mSysDefaultList;
public slots:
void browserComBoBox_changed_cb(int index);

View File

@ -9,7 +9,7 @@ include($$PROJECT_ROOTDIR/libukcc/widgets/Label/label.pri)
include($$PROJECT_ROOTDIR/libukcc/widgets/SettingWidget/settingwidget.pri)
include($$PROJECT_ROOTDIR/libukcc/interface.pri)
QT += widgets dbus concurrent
QT += widgets dbus concurrent KService KCoreAddons
TEMPLATE = lib
CONFIG += plugin
@ -25,7 +25,7 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets \
kysdk-diagnostics \
INCLUDEPATH += \
$$PROJECT_ROOTDIR \

View File

@ -0,0 +1,277 @@
#include "boot.h"
#include <QDebug>
Boot::Boot() : mFirstLoad(true)
{
pluginName = tr("Boot");
pluginType = COMMONINFO;
}
Boot::~Boot()
{
}
QString Boot::plugini18nName()
{
return pluginName;
}
int Boot::pluginTypes()
{
return pluginType;
}
QWidget *Boot::pluginUi()
{
if (mFirstLoad) {
mFirstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
initUI(pluginWidget);
mSystemDbus = new QDBusInterface("com.control.center.qt.systemdbus",
"/",
"com.control.center.interface",
QDBusConnection::systemBus(), this);
if (!mSystemDbus->isValid()){
qCritical() << "Create Client Interface Failed:" << QDBusConnection::systemBus().lastError();
}
initConnection();
}
return pluginWidget;
}
const QString Boot::name() const
{
return QStringLiteral("Boot");
}
bool Boot::isShowOnHomePage() const
{
return true;
}
QIcon Boot::icon() const
{
return QIcon::fromTheme("ukui-bootmenu-symbolic");
}
bool Boot::isEnable() const
{
return true;
}
void Boot::initUI(QWidget *widget)
{
mVlayout = new QVBoxLayout(widget);
mVlayout->setContentsMargins(0, 0, 0, 0);
mBootTitleLabel = new TitleLabel(pluginWidget);
mBootTitleLabel->setText(tr("boot"));
mBootTitleLabel->setContentsMargins(14,0,0,0);
mBootFrame = new QFrame(pluginWidget);
mBootFrame->setFrameShape(QFrame::Shape::Box);
mBootFrame->setMinimumSize(550, 80);
mBootFrame->setMaximumSize(16777215, 80);
QHBoxLayout *bootHLayout = new QHBoxLayout();
QVBoxLayout *leftVlayout = new QVBoxLayout();
//~ contents_path /Boot/Grub verify
mGrubLabel = new QLabel(tr("Grub verify"));
mGrubLabel->setAlignment(Qt::AlignBottom);
mGrubLabel->setMinimumWidth(140);
mNeedPasswdLabel = new LightLabel(tr("Password required for Grub editing after enabling"), pluginWidget);
mNeedPasswdLabel->setAlignment(Qt::AlignTop);
mResetPasswdBtn = new QPushButton(tr("Reset password"));
mGrubBtn = new KSwitchButton();
leftVlayout->addWidget(mGrubLabel);
leftVlayout->addWidget(mNeedPasswdLabel);
leftVlayout->setContentsMargins(0, 0, 0, 0);
bootHLayout->addLayout(leftVlayout);
bootHLayout->addStretch();
bootHLayout->addWidget(mResetPasswdBtn);
bootHLayout->addSpacing(7);
bootHLayout->addWidget(mGrubBtn);
bootHLayout->setContentsMargins(12, 0, 14, 0);
mBootFrame->setLayout(bootHLayout);
mVlayout->addWidget(mBootTitleLabel);
mVlayout->addWidget(mBootFrame);
mVlayout->addStretch();
}
void Boot::initConnection()
{
initEnableStatus();
connect(mGrubBtn, &KSwitchButton::stateChanged, this, &Boot::bootSlot);
connect(mResetPasswdBtn, &QPushButton::clicked, this, &Boot::resetPasswdSlot);
}
void Boot::initEnableStatus()
{
if (mSystemDbus != nullptr) {
QDBusReply<bool> ret = mSystemDbus->call("getGrupPasswdStatus");
mGrubBtn->blockSignals(true);
mGrubBtn->setChecked(ret);
mGrubBtn->blockSignals(false);
}
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
}
void Boot::bootSlot(bool checked)
{
if (checked) {
GrubVerify *dia = new GrubVerify(pluginWidget);
QPushButton *confirmBtn = dia->getConfirmBtn();
connect(confirmBtn, &QPushButton::clicked, this, [=](){
inhibit("shutdown", "com.control.center.qt.systemdbus", "update-grub", "block");
QDBusPendingCall call = mSystemDbus->asyncCall("setGrupPasswd", "root", dia->getPwd(), true);
if (!call.isValid()) {
qDebug() << "setGrupPasswd";
}
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call,this);
connect(watcher,&QDBusPendingCallWatcher::finished,this, [=](QDBusPendingCallWatcher *call){
QDBusPendingReply<bool> reply = *call;
if (!reply.isValid()) {
qDebug() << "setGrupPasswd:" << "iserror";
uninhibit();
mGrubBtn->blockSignals(true);
mGrubBtn->setChecked(!checked);
mGrubBtn->blockSignals(false);
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
} else {
bool status = reply.value();
qDebug() << "setGrupPasswd:" << status;
if (status) {
uninhibit();
} else {
uninhibit();
mGrubBtn->blockSignals(true);
mGrubBtn->setChecked(!checked);
mGrubBtn->blockSignals(false);
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
}
}
});
});
if (dia->exec() != QDialog::Accepted) {
mGrubBtn->blockSignals(true);
mGrubBtn->setChecked(!checked);
mGrubBtn->blockSignals(false);
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
}
} else {
inhibit("shutdown", "com.control.center.qt.systemdbus", "update-grub", "block");
QDBusPendingCall call = mSystemDbus->asyncCall("setGrupPasswd", "", "", false);
if (!call.isValid()) {
qDebug() << "setGrupPasswd";
}
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call,this);
connect(watcher,&QDBusPendingCallWatcher::finished,this, [=](QDBusPendingCallWatcher *call){
QDBusPendingReply<bool> reply = *call;
if (!reply.isValid()) {
qDebug() << "setGrupPasswd:" << "iserror";
uninhibit();
mGrubBtn->blockSignals(true);
mGrubBtn->setChecked(!checked);
mGrubBtn->blockSignals(false);
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
} else {
bool status = reply.value();
qDebug() << "setGrupPasswd:" << status;
if (status) {
uninhibit();
} else {
uninhibit();
mGrubBtn->blockSignals(true);
mGrubBtn->setChecked(!checked);
mGrubBtn->blockSignals(false);
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
}
}
});
}
mResetPasswdBtn->setVisible(mGrubBtn->isChecked());
}
bool Boot::inhibit(QString what, QString who, QString why, QString mode)
{
QDBusMessage message;
message = QDBusMessage::createMethodCall("org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
QStringLiteral("Inhibit"));
message.setArguments(QVariantList({what, who, why, mode}));
QDBusPendingReply<QDBusUnixFileDescriptor> reply = QDBusConnection::systemBus().call(message);
if (!reply.isValid()) {
qDebug() << "inhibit failed!";
return false;
}
reply.value().swap(m_inhibitFileDescriptor);
qDebug() << "inhibit success!";
return true;
}
void Boot::uninhibit()
{
if (!m_inhibitFileDescriptor.isValid()) {
return;
}
qDebug() << "uninhibit success!";
m_inhibitFileDescriptor = QDBusUnixFileDescriptor();
}
void Boot::resetPasswdSlot()
{
GrubVerify *dia = new GrubVerify(pluginWidget);
QPushButton *confirmBtn = dia->getConfirmBtn();
connect(confirmBtn, &QPushButton::clicked, this, [=](){
inhibit("shutdown", "com.control.center.qt.systemdbus", "update-grub", "block");
QDBusPendingCall call = mSystemDbus->asyncCall("setGrupPasswd", "root", dia->getPwd(), true);
if (!call.isValid()) {
qDebug() << "setGrupPasswd";
}
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call,this);
connect(watcher,&QDBusPendingCallWatcher::finished,this, [=](QDBusPendingCallWatcher *call){
QDBusPendingReply<bool> reply = *call;
if (!reply.isValid()) {
qDebug() << "setGrupPasswd:" << "iserror";
uninhibit();
} else {
bool status = reply.value();
qDebug() << "setGrupPasswd:" << status;
if (status) {
uninhibit();
} else {
uninhibit();
}
}
});
});
dia->exec();
}

View File

@ -0,0 +1,67 @@
#ifndef BOOT_H
#define BOOT_H
#include <QObject>
#include <QVBoxLayout>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusUnixFileDescriptor>
#include <unistd.h>
#include "titlelabel.h"
#include "lightlabel.h"
#include <kysdk/applications/kswitchbutton.h>
using namespace kdk;
#include "shell/interface.h"
#include "grubverifydialog.h"
class Boot : public QObject, CommonInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
Q_INTERFACES(CommonInterface)
public:
Boot();
~Boot() Q_DECL_OVERRIDE;
QString plugini18nName() Q_DECL_OVERRIDE;
int pluginTypes() Q_DECL_OVERRIDE;
QWidget *pluginUi() Q_DECL_OVERRIDE;
const QString name() const Q_DECL_OVERRIDE;
bool isShowOnHomePage() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE;
private:
QWidget *pluginWidget;
int pluginType;
QString pluginName;
bool mFirstLoad;
private:
QVBoxLayout *mVlayout;
TitleLabel *mBootTitleLabel;
QFrame *mBootFrame;
QLabel *mGrubLabel;
KSwitchButton *mGrubBtn;
QPushButton *mResetPasswdBtn;
LightLabel *mNeedPasswdLabel;
QDBusInterface *mSystemDbus = nullptr;
QDBusUnixFileDescriptor m_inhibitFileDescriptor;
private:
void initUI(QWidget *widget);
void initConnection();
void gsettingConnection();
void initEnableStatus();
bool inhibit(QString what, QString who, QString why, QString mode);
void uninhibit();
private Q_SLOTS:
void bootSlot(bool checked);
void resetPasswdSlot();
};
#endif // BOOT_H

View File

@ -0,0 +1,44 @@
include(../../../env.pri)
include($$PROJECT_ROOTDIR/libukcc/widgets/Label/label.pri)
include($$PROJECT_ROOTDIR/libukcc/interface.pri)
QT += core gui dbus
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
TEMPLATE = lib
CONFIG += plugin \
link_pkgconfig
PKGCONFIG += gsettings-qt
TARGET = $$qtLibraryTarget(boot)
DESTDIR = ../..
target.path = $${PLUGIN_INSTALL_DIRS}
INCLUDEPATH += \
$$PROJECT_ROOTDIR \
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
boot.cpp \
grubverifydialog.cpp
HEADERS += \
boot.h \
grubverifydialog.h
# Default rules for deployment.
INSTALLS += target

View File

@ -0,0 +1,329 @@
#include "grubverifydialog.h"
#include <QRegExpValidator>
#include <QDebug>
#include <QDBusInterface>
#include <QDBusReply>
GrubVerify::GrubVerify(QWidget *parent) : QDialog(parent)
{
initUI();
setupConnect();
refreshConfirmBtnStatus();
}
GrubVerify::~GrubVerify()
{
}
void GrubVerify::initUI()
{
setFixedSize(QSize(480, 266));
setWindowTitle(tr("Grub verify"));
// 用户
userLabel = new QLabel();
userLabel->setFixedSize(100,36);
setTextDynamicInPwd(userLabel, tr("User:"));
usernameLabel = new QLabel("root");
usernameLabel->setFixedSize(QSize(322, 36));
userHorLayout = new QHBoxLayout;
userHorLayout->setSpacing(8);
userHorLayout->setContentsMargins(0, 0, 0, 0);
userHorLayout->addWidget(userLabel);
userHorLayout->addWidget(usernameLabel);
//新密码
newPwdLabel = new QLabel();
newPwdLabel->setFixedSize(100,24);
setTextDynamicInPwd(newPwdLabel, tr("Pwd"));
newTipLabel = new QLabel();
QFont ft;
ft.setPixelSize(14);
newTipLabel->setFont(ft);
newTipLabel->setFixedSize(QSize(322, 24));
newTipLabel->setStyleSheet("color:red;");
newTipHorLayout = new QHBoxLayout;
newTipHorLayout->setContentsMargins(110, 0, 0, 0);
newTipHorLayout->addStretch();
newTipHorLayout->addWidget(newTipLabel);
newPwdLineEdit = new QLineEdit();
QRegExp inputRegExp("^[A-Za-z0-9`~!@#$%^&*()_-+=<>,.\\\/?:;\"'|\{\}]+$");
QRegExpValidator *inputLimits = new QRegExpValidator(inputRegExp, this);
newPwdLineEdit->setValidator(inputLimits);
newPwdLineEdit->setFixedSize(QSize(322, 36));
newPwdLineEdit->setEchoMode(QLineEdit::Password);
newPwdLineEdit->setTextMargins(0,0,30,0);
newPwdLineEdit->setContextMenuPolicy(Qt::NoContextMenu);
newPwdLineEdit->installEventFilter(this);
newPwdEyeBtn = new QPushButton;
newPwdEyeBtn->setFixedSize(QSize(24, 24));
newPwdEyeBtn->setIcon(QIcon::fromTheme("ukui-eye-hidden-symbolic"));
newPwdEyeBtn->setCursor(Qt::PointingHandCursor);
newPwdEyeBtn->setFlat(true);
newPwdEyeBtn->setStyleSheet("QPushButton::pressed{border:none;background-color:transparent}"
"QPushButton::hover::!pressed{border:none;background-color:transparent}");
newPwdEyeBtn->setFocusPolicy(Qt::FocusPolicy::NoFocus);
QHBoxLayout *newPwdEyeBtnHLayout = new QHBoxLayout;
newPwdEyeBtnHLayout->addStretch();
newPwdEyeBtnHLayout->addWidget(newPwdEyeBtn);
newPwdEyeBtnHLayout->setContentsMargins(0,0,8,0);
newPwdLineEdit->setLayout(newPwdEyeBtnHLayout);
newPwdHorLayout = new QHBoxLayout;
newPwdHorLayout->setSpacing(8);
newPwdHorLayout->setContentsMargins(0, 0, 0, 0);
newPwdHorLayout->addWidget(newPwdLabel);
newPwdHorLayout->addWidget(newPwdLineEdit);
//确认密码
surePwdLabel = new QLabel();
surePwdLabel->setFixedSize(100,24);
setTextDynamicInPwd(surePwdLabel, tr("Sure Pwd"));
surePwdLineEdit = new QLineEdit();
surePwdLineEdit->setValidator(inputLimits);
surePwdLineEdit->setFixedSize(QSize(322, 36));
surePwdLineEdit->setEchoMode(QLineEdit::Password);
surePwdLineEdit->setTextMargins(0,0,30,0);
surePwdLineEdit->setContextMenuPolicy(Qt::NoContextMenu);
surePwdLineEdit->installEventFilter(this);
surePwdEyeBtn = new QPushButton;
surePwdEyeBtn->setFixedSize(QSize(24, 24));
surePwdEyeBtn->setIcon(QIcon::fromTheme("ukui-eye-hidden-symbolic"));
surePwdEyeBtn->setCursor(Qt::PointingHandCursor);
surePwdEyeBtn->setFlat(true);
surePwdEyeBtn->setStyleSheet("QPushButton::pressed{border:none;background-color:transparent}"
"QPushButton::hover::!pressed{border:none;background-color:transparent}");
surePwdEyeBtn->setFocusPolicy(Qt::FocusPolicy::NoFocus);
QHBoxLayout *surePwdEyeBtnHLayout = new QHBoxLayout;
surePwdEyeBtnHLayout->addStretch();
surePwdEyeBtnHLayout->addWidget(surePwdEyeBtn);
surePwdEyeBtnHLayout->setContentsMargins(0,0,8,0);
surePwdLineEdit->setLayout(surePwdEyeBtnHLayout);
surePwdHorLayout = new QHBoxLayout;
surePwdHorLayout->setSpacing(8);
surePwdHorLayout->setContentsMargins(0, 0, 0, 0);
surePwdHorLayout->addWidget(surePwdLabel);
surePwdHorLayout->addWidget(surePwdLineEdit);
sureTipLabel = new QLabel();
sureTipLabel->setFont(ft);
sureTipLabel->setFixedSize(QSize(322, 30));
sureTipLabel->setStyleSheet("color:red;");
sureTipHorLayout = new QHBoxLayout;
sureTipHorLayout->setSpacing(0);
sureTipHorLayout->setContentsMargins(110, 0, 0, 0);
sureTipHorLayout->addStretch();
sureTipHorLayout->addWidget(sureTipLabel);
//中部输入区域
contentVerLayout = new QVBoxLayout;
contentVerLayout->setSpacing(0);
contentVerLayout->setContentsMargins(24, 0, 35, 0);
contentVerLayout->addLayout(userHorLayout);
contentVerLayout->addLayout(newPwdHorLayout);
contentVerLayout->addLayout(newTipHorLayout);
contentVerLayout->addLayout(surePwdHorLayout);
contentVerLayout->addLayout(sureTipHorLayout);
//底部“取消”、“确定”按钮
cancelBtn = new QPushButton();
cancelBtn->setMinimumWidth(96);
cancelBtn->setText(tr("Cancel"));
cancelBtn->setFocusPolicy(Qt::FocusPolicy::NoFocus);
confirmBtn = new QPushButton();
confirmBtn->setMinimumWidth(96);
confirmBtn->setText(tr("Confirm"));
confirmBtn->setFocusPolicy(Qt::FocusPolicy::NoFocus);
bottomBtnsHorLayout = new QHBoxLayout;
bottomBtnsHorLayout->setSpacing(16);
bottomBtnsHorLayout->setContentsMargins(0, 0, 25, 0);
bottomBtnsHorLayout->addStretch();
bottomBtnsHorLayout->addWidget(cancelBtn);
bottomBtnsHorLayout->addWidget(confirmBtn);
mainVerLayout = new QVBoxLayout;
mainVerLayout->setContentsMargins(0, 10, 0, 24);
mainVerLayout->addLayout(contentVerLayout);
mainVerLayout->addStretch();
mainVerLayout->addLayout(bottomBtnsHorLayout);
setLayout(mainVerLayout);
}
void GrubVerify::setupConnect()
{
//通用的connect
connect(cancelBtn, &QPushButton::clicked, this, [=]{
close();
});
connect(newPwdEyeBtn, &QPushButton::clicked, this, [=](){
if (newPwdLineEdit->echoMode() == QLineEdit::Password) {
newPwdLineEdit->setEchoMode(QLineEdit::Normal);
newPwdEyeBtn->setIcon(QIcon::fromTheme("ukui-eye-display-symbolic"));
} else {
newPwdLineEdit->setEchoMode(QLineEdit::Password);
newPwdEyeBtn->setIcon(QIcon::fromTheme("ukui-eye-hidden-symbolic"));
}
});
connect(surePwdEyeBtn, &QPushButton::clicked, this, [=](){
if (surePwdLineEdit->echoMode() == QLineEdit::Password) {
surePwdLineEdit->setEchoMode(QLineEdit::Normal);
surePwdEyeBtn->setIcon(QIcon::fromTheme("ukui-eye-display-symbolic"));
} else {
surePwdLineEdit->setEchoMode(QLineEdit::Password);
surePwdEyeBtn->setIcon(QIcon::fromTheme("ukui-eye-hidden-symbolic"));
}
});
connect(newPwdLineEdit, &QLineEdit::textEdited, this, [=](){
checkPwdLegality();
refreshConfirmBtnStatus();
});
connect(surePwdLineEdit, &QLineEdit::textEdited, this, [=](QString txt){
if (!txt.isEmpty() && txt != newPwdLineEdit->text()){
surePwdTip = tr("Inconsistency with pwd");
} else {
surePwdTip = "";
}
updateTipLableInfo(sureTipLabel, surePwdTip);
refreshConfirmBtnStatus();
});
connect(confirmBtn, &QPushButton::clicked, this, [=](){
accept();
});
}
QPushButton *GrubVerify::getConfirmBtn()
{
return confirmBtn;
}
QString GrubVerify::getPwd()
{
return newPwdLineEdit->text();
}
void GrubVerify::checkPwdLegality()
{
if (newPwdLineEdit->text().isEmpty()) {
newPwdTip = tr("pwd cannot be empty!");
} else {
newPwdTip = tr("");
}
//防止先输入确认密码再输入密码后tipLabel无法刷新
if (!surePwdLineEdit->text().isEmpty()){
if (QString::compare(newPwdLineEdit->text(), surePwdLineEdit->text()) == 0){
surePwdTip = "";
} else {
surePwdTip = tr("Inconsistency with pwd");
}
}
//设置新密码的提示
updateTipLableInfo(newTipLabel,newPwdTip);
updateTipLableInfo(sureTipLabel,surePwdTip);
}
void GrubVerify::updateTipLableInfo(QLabel *Label,QString info)
{
if (setTextDynamicInPwd(Label, info)){
Label->setToolTip(info);
} else {
Label->setToolTip("");
}
}
void GrubVerify::refreshConfirmBtnStatus()
{
if (newPwdLineEdit->text().isEmpty() || surePwdLineEdit->text().isEmpty() || \
!newPwdTip.isEmpty() || !surePwdTip.isEmpty()) {
confirmBtn->setEnabled(false);
} else {
confirmBtn->setEnabled(true);
}
}
bool GrubVerify::setTextDynamicInPwd(QLabel *label, QString string){
bool isOverLength = false;
QFontMetrics fontMetrics(label->font());
int fontSize = fontMetrics.width(string);
QString str = string;
int pSize = label->width();
if (fontSize > pSize) {
str = fontMetrics.elidedText(string, Qt::ElideRight, pSize);
isOverLength = true;
label->setToolTip(string);
} else {
label->setToolTip("");
}
label->setText(str);
return isOverLength;
}
bool GrubVerify::eventFilter(QObject *target, QEvent *event)
{
if (target == newPwdLineEdit || target == surePwdLineEdit) {
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->matches(QKeySequence::Copy) || keyEvent->matches(QKeySequence::Cut))
{
qDebug() <<"Copy || Cut";
return true;
}
}
}
if (event->type() == QEvent::FocusOut) {
if (target == newPwdLineEdit) {
if (newPwdLineEdit->text().isEmpty()) {
newPwdTip = tr("pwd cannot be empty!");
updateTipLableInfo(newTipLabel, newPwdTip);
}
}
}
return QWidget::eventFilter(target, event);
//继续传递该事件到被观察者,由其本身调用相应的事件。
}
void GrubVerify::keyPressEvent(QKeyEvent * event){
switch (event->key())
{
case Qt::Key_Escape:
break;
case Qt::Key_Enter:
if (confirmBtn->isEnabled())
confirmBtn->clicked();
break;
case Qt::Key_Return:
if (confirmBtn->isEnabled())
confirmBtn->clicked();
break;
default:
QDialog::keyPressEvent(event);
}
}

View File

@ -0,0 +1,69 @@
#ifndef GRUBVERIFY_H
#define GRUBVERIFY_H
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QPushButton>
#include <QEvent>
#include <QKeyEvent>
class GrubVerify : public QDialog
{
Q_OBJECT
public:
explicit GrubVerify(QWidget *parent = nullptr);
~GrubVerify();
QPushButton *getConfirmBtn();
QString getPwd();
private:
QVBoxLayout * mainVerLayout;
QVBoxLayout * contentVerLayout;
QHBoxLayout * userHorLayout;
QHBoxLayout * newPwdHorLayout;
QHBoxLayout * surePwdHorLayout;
QHBoxLayout * bottomBtnsHorLayout;
QHBoxLayout *newTipHorLayout;
QHBoxLayout *sureTipHorLayout;
QString newPwdTip;
QString surePwdTip;
QPushButton *cancelBtn;
QPushButton *confirmBtn;
QLabel *userLabel;
QLabel *curTipLabel;
QLabel *newPwdLabel;
QLabel *newTipLabel;
QLabel *surePwdLabel;
QLabel *sureTipLabel;
QLabel * usernameLabel;
QLineEdit * newPwdLineEdit;
QLineEdit * surePwdLineEdit;
QPushButton *currentPwdEyeBtn;
QPushButton *newPwdEyeBtn;
QPushButton *surePwdEyeBtn;
private:
void initUI();
void setupConnect();
bool setTextDynamicInPwd(QLabel * label, QString string);
void checkPwdLegality();
void updateTipLableInfo(QLabel *Label,QString info);
void refreshConfirmBtnStatus();
protected:
bool eventFilter(QObject *target, QEvent *event);
void keyPressEvent(QKeyEvent *);
signals:
};
#endif // GRUBVERIFY_H

View File

@ -10,7 +10,7 @@ include($$PROJECT_ROOTDIR/libukcc/widgets/CloseButton/closebutton.pri)
include($$PROJECT_ROOTDIR/libukcc/widgets/SettingWidget/settingwidget.pri)
include($$PROJECT_ROOTDIR/libukcc/interface.pri)
QT += widgets x11extras KWindowSystem xml KGuiAddons KCoreAddons concurrent KConfigCore KConfigGui KI18n
QT += widgets
#greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = lib
CONFIG += plugin
@ -21,30 +21,26 @@ target.path = $${PLUGIN_INSTALL_DIRS}
INCLUDEPATH += \
$$PROJECT_ROOTDIR \
/usr/include/KF5 \
/usr/include/xcb \
LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt -lX11
LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt
CONFIG += link_pkgconfig \
C++11
PKGCONFIG += libmatekbd \
gsettings-qt \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
kbdlayoutmanager.cpp \
keyboardmain.cpp \
keyboardui.cpp
HEADERS += \
kbdlayoutmanager.h \
keyboardmain.h \
keyboardui.h
FORMS += \
kbdlayoutmanager.ui \
layoutmanager.ui
INSTALLS += target

View File

@ -43,12 +43,29 @@ QWidget *KeyboardMain::pluginUi()
{
if (mFirstLoad) {
mFirstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
initUI(pluginWidget);
initConnection();
keyBoardWidget = new KeyboardUi;
keyBoardWidget->delayFrame()->slider()->installEventFilter(this);
keyBoardWidget->speedFrame()->slider()->installEventFilter(this);
keyBoardDbus = new QDBusInterface("org.ukui.ukcc.session",
"/KeyBoard",
"org.ukui.ukcc.session.KeyBoard",
QDBusConnection::sessionBus(), this);
if (!keyBoardDbus->isValid()) {
qCritical() << "org.ukui.ukcc.session.KeyBoard DBus error:" << keyBoardDbus->lastError();
} else {
initKeyboardStatus();
initConnection();
QDBusConnection::sessionBus().connect("org.ukui.ukcc.session",
"/KeyBoard",
"org.ukui.ukcc.session.KeyBoard",
"changed",
this,
SLOT(dataChanged(QString)));
}
}
return pluginWidget;
return keyBoardWidget;
}
const QString KeyboardMain::name() const
@ -71,201 +88,117 @@ bool KeyboardMain::isEnable() const
return !Common::isWayland();
}
void KeyboardMain::initUI(QWidget *widget)
{
mVlayout = new QVBoxLayout(widget);
mVlayout->setContentsMargins(0, 0, 0, 0);;
mKeyboardFrame = new SettingGroup(this);
mKeyboardSetTitleLabel = new TitleLabel(this);
mKeyboardSetTitleLabel->setText(tr("Key board settings"));
mKeyboardSetTitleLabel->setContentsMargins(16, 0, 0, 0);
setKeyRepeatFrame();
setDelayFrame();
setSpeedFrame();
setInputTestFrame();
setKeyTipsFrame();
/* Input method */
mInputMethodSetBtn = new QPushButton(this);
//~ contents_path /Keyboard/Input settings
mInputMethodSetBtn->setText(tr("Input settings"));
mInputMethodSetBtn->setObjectName("Input settings");
mInputMethodSetBtn->setFixedSize(QSize(160, 36));
/* add widget */
mKeyboardFrame->insertWidget(0, mKeyRepeatFrame);
mKeyboardFrame->insertWidget(1, mDelayFrame);
mKeyboardFrame->insertWidget(2, mSpeedFrame);
mKeyboardFrame->insertWidget(3, mInputTestFrame);
mKeyboardFrame->insertWidget(4, mKeyTipsFrame);
mVlayout->addWidget(mKeyboardSetTitleLabel);
mVlayout->setSpacing(8);
mVlayout->addWidget(mKeyboardFrame);
mVlayout->addWidget(mInputMethodSetBtn);
mVlayout->addStretch();
}
void KeyboardMain::setKeyRepeatFrame()
{
/* Key Repeat */
//~ contents_path /Keyboard/Key repeat
mKeyRepeatFrame = new SwitchWidget(tr("Key repeat"), this, UkccFrame::None);
mKeyRepeatFrame->setObjectName("Key repeat");
}
void KeyboardMain::setDelayFrame()
{
/* delay */
//~ contents_path /Keyboard/Delay
mDelayFrame = new SliderWidget(tr("Delay"), false, this);
mDelayFrame->setObjectName("Delay");
mDelayFrame->setLeftText(tr("Short"));
mDelayFrame->setRightText(tr("Long"));
mDelayFrame->slider()->setMinimum(200);
mDelayFrame->slider()->setMaximum(2100);
mDelayFrame->slider()->setPageStep(20);
mDelayFrame->slider()->setSingleStep(20);
mDelayFrame->slider()->installEventFilter(this);
}
void KeyboardMain::setSpeedFrame()
{
/* Speed */
//~ contents_path /Keyboard/Speed
mSpeedFrame = new SliderWidget(tr("Speed"), false, this);
mSpeedFrame->setObjectName("Speed");
mSpeedFrame->setLeftText(tr("Slow"));
mSpeedFrame->setRightText(tr("Fast"));
mSpeedFrame->slider()->setMinimum(10);
mSpeedFrame->slider()->setMaximum(110);
mSpeedFrame->slider()->setPageStep(1);
mSpeedFrame->slider()->installEventFilter(this);
}
void KeyboardMain::setInputTestFrame()
{
/* Input test */
//~ contents_path /Keyboard/Input test
mInputTestFrame = new LineEditWidget(tr("Input test"), this);
}
void KeyboardMain::setKeyTipsFrame()
{
/* key tips */
//~ contents_path /Keyboard/Key tips
mKeyTipsFrame = new SwitchWidget(tr("Key tips"), this, UkccFrame::None);
mKeyTipsFrame->setObjectName("Key tips");
}
void KeyboardMain::initConnection()
{
// 初始化键盘通用设置GSettings
QByteArray keyBoardId(kKeyboardSchamas);
// 初始化键盘按键提示GSettings 控制面板自带 不再判断是否安装
QByteArray keyBoardOsdId(kKeyboardOsdSchemas);
if (QGSettings::isSchemaInstalled(keyBoardId)) {
mKeyboardGsettings = new QGSettings(kKeyboardSchamas, QByteArray(), this);
mKeyboardOsdGsetting = new QGSettings(keyBoardOsdId);
// 界面设置发生变化
connect(keyBoardWidget->keyRepeatFrame(), &SwitchWidget::stateChanged, this, &KeyboardMain::keyRepeatSlot);
initKeyboardStatus();
connect(keyBoardWidget->delayFrame(), &SliderWidget::valueChanged, this, &KeyboardMain::keyDelaySlot);
//将界面设置改动的key值写入GSettings
connect(mKeyRepeatFrame, &SwitchWidget::stateChanged, this, &KeyboardMain::keyRepeatSlot);
connect(keyBoardWidget->speedFrame(), &SliderWidget::valueChanged, this, &KeyboardMain::keySpeedSlot);
connect(mDelayFrame, &SliderWidget::valueChanged, this, &KeyboardMain::keyDelaySlot);
connect(keyBoardWidget->keyTipsFrame(), &SwitchWidget::stateChanged, this, &KeyboardMain::keyTipsSlot);
connect(mSpeedFrame, &SliderWidget::valueChanged, this, &KeyboardMain::keySpeedSlot);
connect(keyBoardWidget->inputMethodPushButton(), &QPushButton::clicked, this, &KeyboardMain::inputMethodSetSlot);
connect(mKeyTipsFrame, &SwitchWidget::stateChanged, this, &KeyboardMain::keyTipsSlot);
connect(mInputMethodSetBtn, &QPushButton::clicked, this, &KeyboardMain::inputMethodSetSlot);
gsettingConnectUi();
}
}
void KeyboardMain::initKeyboardStatus()
{
initKeyRepeat();
initDelay();
initSpeed();
initKeyTips();
}
void KeyboardMain::initKeyRepeat()
{
//设置按键重复状态
mKeyRepeatFrame->setChecked(mKeyboardGsettings->get(kKeyRepeatKey).toBool());
setKeyboardVisible(mKeyRepeatFrame->isChecked());
keyBoardWidget->keyRepeatFrame()->blockSignals(true);
bool checked = keyBoardDbus->property("repeat").toBool();
keyBoardWidget->keyRepeatFrame()->setChecked(checked);
keyBoardWidget->keyRepeatFrame()->blockSignals(false);
setKeyboardVisible(keyBoardWidget->keyRepeatFrame()->isChecked());
}
void KeyboardMain::initDelay()
{
//设置按键重复的延时
mDelayFrame->setValue(mKeyboardGsettings->get(kDelayKey).toInt());
keyBoardWidget->delayFrame()->slider()->blockSignals(true);
int value = keyBoardDbus->property("delay").toInt();
keyBoardWidget->delayFrame()->setValue(value);
keyBoardWidget->delayFrame()->slider()->blockSignals(false);
}
void KeyboardMain::initSpeed()
{
//设置按键重复的速度
mSpeedFrame->setValue(mKeyboardGsettings->get(kSpeedKey).toInt());
keyBoardWidget->speedFrame()->slider()->blockSignals(true);
int value = keyBoardDbus->property("rate").toInt();
keyBoardWidget->speedFrame()->setValue(value);
keyBoardWidget->speedFrame()->slider()->blockSignals(false);
}
void KeyboardMain::initKeyTips()
{
//设置按键提示状态
mKeyTipsFrame->blockSignals(true);
mKeyTipsFrame->setChecked(mKeyboardOsdGsetting->get(kKeyTipsKey).toBool());
mKeyTipsFrame->blockSignals(false);
keyBoardWidget->keyTipsFrame()->blockSignals(true);
bool checked = keyBoardDbus->property("showLockTip").toBool();
keyBoardWidget->keyTipsFrame()->setChecked(checked);
keyBoardWidget->keyTipsFrame()->blockSignals(false);
}
void KeyboardMain::setKeyboardVisible(bool checked)
{
mDelayFrame->setVisible(checked);
mSpeedFrame->setVisible(checked);
mInputTestFrame->setVisible(checked);
keyBoardWidget->delayFrame()->setVisible(checked);
keyBoardWidget->speedFrame()->setVisible(checked);
keyBoardWidget->inputTestFrame()->setVisible(checked);
}
void KeyboardMain::gsettingConnectUi()
void KeyboardMain::dataChanged(QString key)
{
//命令行 set key 值,界面设置做出相应的变化
connect(mKeyboardGsettings, &QGSettings::changed, this, [=](const QString &key) {
if(key == "repeat") {
mKeyRepeatFrame->setChecked(mKeyboardGsettings->get(kKeyRepeatKey).toBool());
setKeyboardVisible(mKeyRepeatFrame->isChecked());
} else if(key == "delay") {
mDelayFrame->setValue(mKeyboardGsettings->get(kDelayKey).toInt());
} else if(key == "rate") {
mSpeedFrame->setValue(mKeyboardGsettings->get(kSpeedKey).toInt());
}
});
connect(mKeyboardOsdGsetting, &QGSettings::changed,this, [=](const QString &key) {
if(key == "showLockTip") {
mKeyTipsFrame->blockSignals(true);
mKeyTipsFrame->setChecked(mKeyboardOsdGsetting->get(kKeyTipsKey).toBool());
mKeyTipsFrame->blockSignals(false);
}
});
if (key == QString("repeat")) {
initKeyRepeat();
} else if (key == QString("delay")) {
initDelay();
} else if (key == QString("rate")) {
initSpeed();
}else if (key == QString("show-lock-tip")) {
initKeyTips();
}
}
/* Slot */
void KeyboardMain::keyRepeatSlot(bool checked)
{
setKeyboardVisible(checked);
mKeyboardGsettings->set(kKeyRepeatKey, checked);
Common::buriedSettings(name(), mKeyRepeatFrame->objectName(), QString("setting"), checked ? "true":"false");
keyBoardDbus->call("setKeyRepeat", checked);
Common::buriedSettings(name(), keyBoardWidget->keyRepeatFrame()->objectName(), QString("setting"), checked ? "true":"false");
}
void KeyboardMain::keyDelaySlot(int value)
{
mKeyboardGsettings->set(kDelayKey, value);
keyBoardDbus->call("setDelay", value);
}
void KeyboardMain::keySpeedSlot(int value)
{
mKeyboardGsettings->set(kSpeedKey, value);
keyBoardDbus->call("setSpeed", value);
}
void KeyboardMain::keyTipsSlot(bool checked)
{
mKeyboardOsdGsetting->set(kKeyTipsKey, checked);
Common::buriedSettings(name(), mKeyTipsFrame->objectName(), QString("setting"), checked ? "true":"false");
keyBoardDbus->call("setKeyTips", checked);
Common::buriedSettings(name(), keyBoardWidget->keyTipsFrame()->objectName(), QString("setting"), checked ? "true":"false");
}
void KeyboardMain::inputMethodSetSlot()
{
Common::buriedSettings(name(), mInputMethodSetBtn->objectName(), QString("setting"));
Common::buriedSettings(name(), keyBoardWidget->inputMethodPushButton()->objectName(), QString("setting"));
QProcess process;
process.startDetached("fcitx5-config-qt");
@ -274,12 +207,12 @@ void KeyboardMain::inputMethodSetSlot()
bool KeyboardMain::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::FocusOut) {
if (watched == mDelayFrame->slider()) {
int value = mDelayFrame->value();
Common::buriedSettings(name(), mDelayFrame->objectName(), QString("setting"), QString::number(value));
} else if (watched == mSpeedFrame->slider()) {
int value = mSpeedFrame->value();
Common::buriedSettings(name(), mSpeedFrame->objectName(), QString("setting"), QString::number(value));
if (watched == keyBoardWidget->delayFrame()->slider()) {
int value = keyBoardWidget->delayFrame()->value();
Common::buriedSettings(name(), keyBoardWidget->delayFrame()->objectName(), QString("setting"), QString::number(value));
} else if (watched == keyBoardWidget->speedFrame()->slider()) {
int value = keyBoardWidget->speedFrame()->value();
Common::buriedSettings(name(), keyBoardWidget->speedFrame()->objectName(), QString("setting"), QString::number(value));
}
}
return QObject::eventFilter(watched, event);

View File

@ -13,22 +13,10 @@
#include <QDebug>
#include <QtDBus/QDBusInterface>
#include "shell/interface.h"
#include "titlelabel.h"
#include "lineeditwidget.h"
#include "switchwidget.h"
#include "sliderwidget.h"
#include "settinggroup.h"
#include "keyboardui.h"
#include "common.h"
const QByteArray kKeyboardSchamas = "org.ukui.peripherals-keyboard";
const QString kKeyRepeatKey = "repeat";
const QString kDelayKey = "delay";
const QString kSpeedKey = "rate";
const QByteArray kKeyboardOsdSchemas = "org.ukui.control-center.osd";
const QString kKeyTipsKey = "show-lock-tip";
class KeyboardMain : public QWidget, CommonInterface
{
@ -48,42 +36,25 @@ public:
bool isEnable() const Q_DECL_OVERRIDE;
private:
QString pluginName;
int pluginType;
QWidget *pluginWidget;
bool mFirstLoad;
bool mFirstLoad = true;
QString pluginName = "";
int pluginType = 0;
KeyboardUi *keyBoardWidget = nullptr;
QDBusInterface *keyBoardDbus = nullptr;
private:
SwitchWidget *mKeyRepeatFrame; //按键重复
SliderWidget *mDelayFrame; //延迟
SliderWidget *mSpeedFrame; //速度
LineEditWidget *mInputTestFrame; //输入测试
SwitchWidget *mKeyTipsFrame; //按键提示
SettingGroup *mKeyboardFrame;
TitleLabel *mKeyboardSetTitleLabel;
QPushButton *mInputMethodSetBtn; //输入法设置
QVBoxLayout *mVlayout;
QGSettings *mKeyboardGsettings;
QGSettings *mKeyboardOsdGsetting;
private:
void initUI(QWidget *widget);
void setKeyRepeatFrame();
void setDelayFrame();
void setSpeedFrame();
void setInputTestFrame();
void setKeyTipsFrame();
void initConnection();
void initKeyboardStatus();
void initKeyRepeat();
void initDelay();
void initSpeed();
void initKeyTips();
void setKeyboardVisible(bool checked);
void gsettingConnectUi();
protected:
bool eventFilter(QObject *watched, QEvent *event);
public Q_SLOTS:
void keyRepeatSlot(bool checked);
void keyDelaySlot(int value);
void keySpeedSlot(int value);
@ -91,7 +62,6 @@ private:
void keyTipsSlot(bool checked);
void inputMethodSetSlot();
bool eventFilter(QObject *watched, QEvent *event);
void dataChanged(QString key);
};
#endif // KEYBOARDMAIN_H

View File

@ -0,0 +1,106 @@
#include "keyboardui.h"
KeyboardUi::KeyboardUi(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
setAttribute(Qt::WA_DeleteOnClose);
mVlayout = new QVBoxLayout(this);
mVlayout->setContentsMargins(0, 0, 0, 0);
mVlayout->setSpacing(8);
initUI();
}
KeyboardUi::~KeyboardUi()
{
}
void KeyboardUi::initUI()
{
mKeyboardFrame = new SettingGroup(this);
mKeyboardSetTitleLabel = new TitleLabel(this);
//~ contents_path /Keyboard/Key board settings
mKeyboardSetTitleLabel->setText(tr("Key board settings"));
mKeyboardSetTitleLabel->setContentsMargins(16, 0, 0, 0);
setKeyRepeatFrame();
setDelayFrame();
setSpeedFrame();
setInputTestFrame();
setKeyTipsFrame();
setInputMethodFrame();
/* add widget */
mKeyboardFrame->insertWidget(0, mKeyRepeatFrame);
mKeyboardFrame->insertWidget(1, mDelayFrame);
mKeyboardFrame->insertWidget(2, mSpeedFrame);
mKeyboardFrame->insertWidget(3, mInputTestFrame);
mKeyboardFrame->insertWidget(4, mKeyTipsFrame);
mVlayout->addWidget(mKeyboardSetTitleLabel);
mVlayout->addWidget(mKeyboardFrame);
mVlayout->addWidget(mInputMethodSetBtn);
mVlayout->addStretch();
}
void KeyboardUi::setKeyRepeatFrame()
{
/* Key Repeat */
//~ contents_path /Keyboard/Key repeat
mKeyRepeatFrame = new SwitchWidget(tr("Key repeat"), this, UkccFrame::None);
mKeyRepeatFrame->setObjectName("Key repeat");
}
void KeyboardUi::setDelayFrame()
{
/* delay */
//~ contents_path /Keyboard/Delay
mDelayFrame = new SliderWidget(tr("Delay"), false, this);
mDelayFrame->setObjectName("Delay");
mDelayFrame->setLeftText(tr("Short"));
mDelayFrame->setRightText(tr("Long"));
mDelayFrame->slider()->setMinimum(200);
mDelayFrame->slider()->setMaximum(2100);
mDelayFrame->slider()->setPageStep(20);
mDelayFrame->slider()->setSingleStep(20);
mDelayFrame->slider()->installEventFilter(this);
}
void KeyboardUi::setSpeedFrame()
{
/* Speed */
//~ contents_path /Keyboard/Speed
mSpeedFrame = new SliderWidget(tr("Speed"), false, this);
mSpeedFrame->setObjectName("Speed");
mSpeedFrame->setLeftText(tr("Slow"));
mSpeedFrame->setRightText(tr("Fast"));
mSpeedFrame->slider()->setMinimum(10);
mSpeedFrame->slider()->setMaximum(110);
mSpeedFrame->slider()->setPageStep(1);
mSpeedFrame->slider()->installEventFilter(this);
}
void KeyboardUi::setInputTestFrame()
{
/* Input test */
//~ contents_path /Keyboard/Input test
mInputTestFrame = new LineEditWidget(tr("Input test"), this);
}
void KeyboardUi::setKeyTipsFrame()
{
/* key tips */
//~ contents_path /Keyboard/Key tips
mKeyTipsFrame = new SwitchWidget(tr("Key tips"), this, UkccFrame::None);
mKeyTipsFrame->setObjectName("Key tips");
}
void KeyboardUi::setInputMethodFrame()
{
/* Input method */
mInputMethodSetBtn = new QPushButton(this);
//~ contents_path /Keyboard/Input settings
mInputMethodSetBtn->setText(tr("Input settings"));
mInputMethodSetBtn->setObjectName("Input settings");
mInputMethodSetBtn->setFixedSize(QSize(160, 36));
}

View File

@ -0,0 +1,80 @@
#ifndef KEYBOARDUI_H
#define KEYBOARDUI_H
#include <QWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include "settinggroup.h"
#include "titlelabel.h"
#include "switchwidget.h"
#include "sliderwidget.h"
#include "lineeditwidget.h"
class KeyboardUi : public QWidget
{
Q_OBJECT
public:
explicit KeyboardUi(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
virtual ~KeyboardUi();
public:
inline SwitchWidget *keyRepeatFrame()
{
return mKeyRepeatFrame;
}
inline SliderWidget *delayFrame()
{
return mDelayFrame;
}
inline SliderWidget *speedFrame()
{
return mSpeedFrame;
}
inline LineEditWidget *inputTestFrame()
{
return mInputTestFrame;
}
inline SwitchWidget *keyTipsFrame()
{
return mKeyTipsFrame;
}
inline QPushButton *inputMethodPushButton()
{
if (mKeyTipsFrame) {
return mKeyTipsFrame->switchButton();
} else {
return nullptr;
}
}
private:
QVBoxLayout *mVlayout = nullptr;
SettingGroup *mKeyboardFrame = nullptr;
TitleLabel *mKeyboardSetTitleLabel = nullptr;
SwitchWidget *mKeyRepeatFrame = nullptr; //按键重复
SliderWidget *mDelayFrame = nullptr; //延迟
SliderWidget *mSpeedFrame = nullptr; //速度
LineEditWidget *mInputTestFrame = nullptr; //输入测试
SwitchWidget *mKeyTipsFrame = nullptr; //按键提示
QPushButton *mInputMethodSetBtn = nullptr; //输入法设置
private:
void initUI();
void setKeyRepeatFrame();
void setDelayFrame();
void setSpeedFrame();
void setInputTestFrame();
void setKeyTipsFrame();
void setInputMethodFrame();
};
#endif // KEYBOARDUI_H

View File

@ -0,0 +1,359 @@
#include "mouse.h"
Mouse::Mouse() : mFirstLoad(true)
{
pluginName = tr("Mouse");
pluginType = DEVICES;
}
Mouse::~Mouse()
{
}
QString Mouse::plugini18nName()
{
return pluginName;
}
int Mouse::pluginTypes()
{
return pluginType;
}
QWidget *Mouse::pluginUi()
{
if (mFirstLoad) {
mFirstLoad = false;
mouseWidget = new MouseUI;
mouseWidget->wheelSpeedWidget()->slider()->installEventFilter(this);
mouseWidget->doubleClickIntervalWidget()->slider()->installEventFilter(this);
mouseWidget->pointerSpeedWidget()->slider()->installEventFilter(this);
mouseWidget->cursorSpeedWidget()->slider()->installEventFilter(this);
mouseWidget->setAttribute(Qt::WA_DeleteOnClose);
mouseDbus = new QDBusInterface("org.ukui.ukcc.session",
"/Mouse",
"org.ukui.ukcc.session.Mouse",
QDBusConnection::sessionBus(), this);
if (!mouseDbus->isValid()) {
qCritical() << "org.ukui.ukcc.session.KeyBoard DBus error:" << mouseDbus->lastError();
} else {
initMouseStatus();
initConnection();
QDBusConnection::sessionBus().connect("org.ukui.ukcc.session",
"/Mouse",
"org.ukui.ukcc.session.Mouse",
"changed",
this,
SLOT(dataChanged(QString)));
}
}
return mouseWidget;
}
const QString Mouse::name() const
{
return QStringLiteral("Mouse");
}
bool Mouse::isShowOnHomePage() const
{
return true;
}
QIcon Mouse::icon() const
{
return QIcon::fromTheme("input-mouse-symbolic");
}
bool Mouse::isEnable() const
{
return true;
}
void Mouse::initMouseStatus()
{
initDominantHand();
initScrollDirection();
initWheelSpeed();
initDoubleClickInterval();
initPointerSpeed();
initMouseAcceleration();
initPointerPosition();
initPointerSize();
initBlinkingCursor();
initCursorSpeed();
}
void Mouse::initDominantHand()
{
//初始化惯用手, 左手:右键为主键,右手:左键为主键
mouseWidget->dominantHandWidget()->buttonGroup()->blockSignals(true);
bool currentDominantHand = mouseDbus->property("dominantHand").toBool();
if (currentDominantHand == true) {
mouseWidget->dominantHandRightRadio()->setChecked(true);
} else {
mouseWidget->dominantHandLeftRadio()->setChecked(true);
}
mouseWidget->dominantHandWidget()->buttonGroup()->blockSignals(false);
}
void Mouse::initScrollDirection()
{
// 初始化滚动方向 true:界面与鼠标滚轮滚动方向相反(反向),false:界面与滚轮滚动方向相同(正向)
mouseWidget->scrollDirectionWdiget()->buttonGroup()->blockSignals(true);
bool currentScrollDirection = mouseDbus->property("scrollDirection").toBool();
if (currentScrollDirection) {
mouseWidget->scrollDirectionReverseRadio()->setChecked(true);
} else {
mouseWidget->scrollDirectionForwardRadio()->setChecked(true);
}
mouseWidget->scrollDirectionWdiget()->buttonGroup()->blockSignals(false);
}
void Mouse::initWheelSpeed()
{
//初始化滚轮速度
mouseWidget->wheelSpeedWidget()->slider()->blockSignals(true);
int value = mouseDbus->property("wheelSpeed").toInt();
if (value < 1 || value >10) {
mouseDbus->call("resetKey", "wheelSpeed");
}
mouseWidget->wheelSpeedWidget()->setValue(mouseDbus->property("wheelSpeed").toInt());
mouseWidget->wheelSpeedWidget()->slider()->blockSignals(false);
}
void Mouse::initDoubleClickInterval()
{
//初始化双击间隔时长
mouseWidget->doubleClickIntervalWidget()->slider()->blockSignals(true);
mouseWidget->doubleClickIntervalWidget()->setValue(mouseDbus->property("doubleClick").toInt());
mouseWidget->doubleClickIntervalWidget()->slider()->blockSignals(false);
}
void Mouse::initPointerSpeed()
{
//初始化指针速度
mouseWidget->pointerSpeedWidget()->slider()->blockSignals(true);
mouseWidget->pointerSpeedWidget()->setValue(static_cast<int>(mouseDbus->property("pointerSpeed").toDouble()*100));
mouseWidget->pointerSpeedWidget()->slider()->blockSignals(false);
}
void Mouse::initMouseAcceleration()
{
//初始化鼠标加速
mouseWidget->mouseAccelerationWidget()->blockSignals(true);
mouseWidget->mouseAccelerationWidget()->setChecked(mouseDbus->property("mouseAcceleration").toBool());
mouseWidget->mouseAccelerationWidget()->blockSignals(false);
}
void Mouse::initPointerPosition()
{
//初始化按 ctrl 键时显示指针位置
mouseWidget->pointerPositionWidget()->blockSignals(true);
mouseWidget->pointerPositionWidget()->setChecked(mouseDbus->property("pointerPosition").toBool());
mouseWidget->pointerPositionWidget()->blockSignals(false);
}
void Mouse::initPointerSize()
{
//初始化指针大小
mouseWidget->pointerSizeWidet()->buttonGroup()->blockSignals(true);
int currentPointerSize = mouseDbus->property("pointerSize").toInt();
if (currentPointerSize != 24 && currentPointerSize != 36 && currentPointerSize != 48) {
mouseDbus->call("resetKey", "pointerSize");
currentPointerSize = mouseDbus->property("pointerSize").toInt();
}
if (currentPointerSize == 24) {
mouseWidget->pointerSizeSmallRadio()->setChecked(true);
} else if (currentPointerSize == 36) {
mouseWidget->pointerSizeMediumRadio()->setChecked(true);
} else if (currentPointerSize == 48) {
mouseWidget->pointerSizeLargeRadio()->setChecked(true);
}
mouseWidget->pointerSizeWidet()->buttonGroup()->blockSignals(false);
}
void Mouse::initBlinkingCursor()
{
//初始化文本区域光标闪烁
mouseWidget->blinkingCursorOnTextWidget()->blockSignals(true);
mouseWidget->blinkingCursorOnTextWidget()->setChecked(mouseDbus->property("cursorBlink").toBool());
mouseWidget->blinkingCursorOnTextWidget()->blockSignals(false);
mouseWidget->cursorSpeedWidget()->setVisible(mouseDbus->property("cursorBlink").toBool());
}
void Mouse::initCursorSpeed()
{
//初始化光标速度
mouseWidget->cursorSpeedWidget()->slider()->blockSignals(true);
mouseWidget->cursorSpeedWidget()->setValue(mouseWidget->cursorSpeedWidget()->slider()->maximum() - mouseDbus->property("cursorSpeed").toInt()
+ mouseWidget->cursorSpeedWidget()->slider()->minimum());
mouseWidget->cursorSpeedWidget()->slider()->blockSignals(false);
}
void Mouse::initConnection()
{
connect(mouseWidget->dominantHandWidget(), QOverload<int>::of(&RadioButtonWidget::buttonClicked),
this, &Mouse::dominantHandSlot);
connect(mouseWidget->scrollDirectionWdiget(), QOverload<int>::of(&RadioButtonWidget::buttonClicked),
this, &Mouse::scrollDirectionSlot);
connect(mouseWidget->wheelSpeedWidget(), &SliderWidget::valueChanged, this, &Mouse::wheelSpeedSlot);
connect(mouseWidget->doubleClickIntervalWidget(), &SliderWidget::valueChanged , this, &Mouse::doubleClickIntervalSlot);
connect(mouseWidget->pointerSpeedWidget(), &SliderWidget::valueChanged, this, &Mouse::pointerSpeedSlot);
connect(mouseWidget->mouseAccelerationWidget(), &SwitchWidget::stateChanged, this, &Mouse::mouseAccelerationSlot);
connect(mouseWidget->pointerPositionWidget(), &SwitchWidget::stateChanged, this, &Mouse::pointerPositionSlot);
connect(mouseWidget->pointerSizeWidet(), QOverload<int>::of(&RadioButtonWidget::buttonClicked),
this, &Mouse::pointerSizeSlot);
connect(mouseWidget->blinkingCursorOnTextWidget(), &SwitchWidget::stateChanged, this, &Mouse::blinkCursorOnTextSlot);
connect(mouseWidget->cursorSpeedWidget(), &SliderWidget::valueChanged, this, &Mouse::cursorSpeedSlot);
}
void Mouse::dataChanged(QString key)
{
if (key == QString("dominantHand")) {
initDominantHand();
} else if (key == QString("scrollDirection")) {
initScrollDirection();
} else if (key == QString("wheelSpeed")) {
initWheelSpeed();
} else if (key == QString("doubleClick")) {
initDoubleClickInterval();
} else if (key == QString("pointerSpeed")) {
initPointerSpeed();
} else if (key == QString("mouseAcceleration")) {
initMouseAcceleration();
} else if (key == QString("pointerPosition")) {
initPointerPosition();
} else if (key == QString("pointerSize")) {
initPointerSize();
}else if (key == QString("cursorBlink")) {
initBlinkingCursor();
} else if (key == QString("cursorSpeed")) {
initCursorSpeed();
}
}
/* Slot */
void Mouse::dominantHandSlot(int id)
{
bool tmpLeftHand;
// 左键主键右手、left-handed=false右键主键左手、left-handed=true
if (id == 0) {
tmpLeftHand = false;
} else {
tmpLeftHand = true;
}
mouseDbus->call("setDominantHand", tmpLeftHand);
Common::buriedSettings(name(), mouseWidget->dominantHandWidget()->objectName(), QString("setting"));
}
void Mouse::scrollDirectionSlot(int id)
{
bool tmpScrollDirection;
// true:界面与鼠标滚轮滚动方向相反(反向),false:界面与滚轮滚动方向相同(正向)
if (id == 0) {
tmpScrollDirection = false;
} else {
tmpScrollDirection = true;
}
mouseDbus->call("setScrollDirection", tmpScrollDirection);
Common::buriedSettings(name(), mouseWidget->scrollDirectionWdiget()->objectName(), QString("setting"));
}
void Mouse::wheelSpeedSlot()
{
mouseDbus->call("setWheelSpeed", mouseWidget->wheelSpeedWidget()->value());
}
void Mouse::doubleClickIntervalSlot()
{
mouseDbus->call("setDoubleClick", mouseWidget->doubleClickIntervalWidget()->value());
qApp->setDoubleClickInterval(mouseWidget->doubleClickIntervalWidget()->value());
}
void Mouse::pointerSpeedSlot(int value)
{
mouseDbus->call("setPointerSpeed", static_cast<double>(value)/mouseWidget->pointerSpeedWidget()->slider()->maximum() * 10);
}
void Mouse::mouseAccelerationSlot(bool checked)
{
mouseDbus->call("setMouseAcceleration", checked);
Common::buriedSettings(name(), mouseWidget->mouseAccelerationWidget()->objectName(), QString("setting"), checked ? "true":"false");
}
void Mouse::pointerPositionSlot(bool checked)
{
mouseDbus->call("setPointerPosition", checked);
Common::buriedSettings(name(), mouseWidget->pointerPositionWidget()->objectName(), QString("setting"), checked ? "true":"false");
}
void Mouse::pointerSizeSlot(int id)
{
int tmpPointerSize = id;
mouseDbus->call("setPointerSize", tmpPointerSize);
Common::buriedSettings(name(), mouseWidget->pointerSizeWidet()->objectName(), QString("setting"));
}
void Mouse::blinkCursorOnTextSlot(bool checked)
{
mouseWidget->cursorSpeedWidget()->setVisible(checked);
mouseDbus->call("setCursorBlink", checked);
if (!checked) {
mouseDbus->call("setCursorSpeed", 0);
} else {
int mValue = mouseWidget->cursorSpeedWidget()->slider()->maximum() - mouseWidget->cursorSpeedWidget()->slider()->value() + mouseWidget->cursorSpeedWidget()->slider()->minimum();
mouseDbus->call("setCursorSpeed", mValue);
}
Common::buriedSettings(name(), mouseWidget->cursorSpeedWidget()->objectName(), QString("setting"), checked ? "true":"false");
}
void Mouse::cursorSpeedSlot()
{
mouseDbus->call("setCursorSpeed", mouseWidget->cursorSpeedWidget()->slider()->maximum() - mouseWidget->cursorSpeedWidget()->value()
+ mouseWidget->cursorSpeedWidget()->slider()->minimum());
}
bool Mouse::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::FocusOut) {
if (watched == mouseWidget->wheelSpeedWidget()->slider()) {
int value = mouseWidget->wheelSpeedWidget()->value();
Common::buriedSettings(name(), mouseWidget->wheelSpeedWidget()->objectName(), QString("setting"), QString::number(value));
} else if (watched == mouseWidget->doubleClickIntervalWidget()->slider()) {
int value = mouseWidget->doubleClickIntervalWidget()->value();
Common::buriedSettings(name(), mouseWidget->doubleClickIntervalWidget()->objectName(), QString("setting"), QString::number(value));
} else if (watched == mouseWidget->pointerSpeedWidget()->slider()) {
int value = mouseWidget->pointerSpeedWidget()->value();
Common::buriedSettings(name(), mouseWidget->pointerSpeedWidget()->objectName(), QString("setting"), QString::number(value));
} else if (watched == mouseWidget->cursorSpeedWidget()->slider()) {
int value = mouseWidget->cursorSpeedWidget()->value();
Common::buriedSettings(name(), mouseWidget->cursorSpeedWidget()->objectName(), QString("setting"), QString::number(value));
}
}
return QObject::eventFilter(watched, event);
}

View File

@ -0,0 +1,71 @@
#ifndef MOUSE_H
#define MOUSE_H
#include <QObject>
#include <QWidget>
#include "shell/interface.h"
#include "mouseui.h"
class Mouse : public QObject, CommonInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
Q_INTERFACES(CommonInterface)
public:
Mouse();
~Mouse();
QString plugini18nName() Q_DECL_OVERRIDE;
int pluginTypes() Q_DECL_OVERRIDE;
QWidget *pluginUi() Q_DECL_OVERRIDE;
const QString name() const Q_DECL_OVERRIDE;
bool isShowOnHomePage() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE;
private:
bool mFirstLoad = true;
QString pluginName = "";
int pluginType = 0;
MouseUI *mouseWidget = nullptr;
QDBusInterface *mouseDbus = nullptr;
void initMouseStatus();
void initDominantHand();
void initScrollDirection();
void initWheelSpeed();
void initDoubleClickInterval();
void initPointerSpeed();
void initMouseAcceleration();
void initPointerPosition();
void initPointerSize();
void initBlinkingCursor();
void initCursorSpeed();
void initConnection();
protected:
bool eventFilter(QObject *watched, QEvent *event);
public Q_SLOTS:
void dominantHandSlot(int id);
void scrollDirectionSlot(int id);
void wheelSpeedSlot();
void doubleClickIntervalSlot();
void pointerSpeedSlot(int value);
void mouseAccelerationSlot(bool checked);
void pointerPositionSlot(bool checked);
void pointerSizeSlot(int id);
void blinkCursorOnTextSlot(bool checked);
void cursorSpeedSlot();
void dataChanged(QString key);
signals:
};
#endif // MOUSE_H

View File

@ -32,14 +32,17 @@ PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
x11 \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
mouse.cpp \
mouseui.cpp
HEADERS += \
mouse.h \
mouseui.h
FORMS +=

View File

@ -20,73 +20,20 @@
#include "mouseui.h"
MouseUI::MouseUI() : mFirstLoad(true)
MouseUI::MouseUI(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
pluginName = tr("Mouse");
pluginType = DEVICES;
setAttribute(Qt::WA_DeleteOnClose);
mVlayout = new QVBoxLayout(this);
mVlayout->setMargin(0);
mVlayout->setSpacing(40);
initUI();
}
MouseUI::~MouseUI()
{
}
QString MouseUI::plugini18nName()
{
return pluginName;
}
int MouseUI::pluginTypes()
{
return pluginType;
}
QWidget *MouseUI::pluginUi()
{
if (mFirstLoad) {
mFirstLoad = false;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
initUI(pluginWidget);
initConnection();
if (Common::isTablet()) {
settingForIntel();
}
}
return pluginWidget;
}
const QString MouseUI::name() const
{
return QStringLiteral("Mouse");
}
bool MouseUI::isShowOnHomePage() const
{
return true;
}
QIcon MouseUI::icon() const
{
return QIcon::fromTheme("input-mouse-symbolic");
}
bool MouseUI::isEnable() const
{
return true;
}
void MouseUI::settingForIntel()
{
if (pluginWidget) {
mWheelSpeedWidget->hide();
mDoubleClickIntervalWidget->hide();
mScrollDirectionWdiget->setFrameShape(QFrame::HLine);
mMouseAccelerationWidget->hide();
}
}
MyLabel::MyLabel()
DoubleClickTestLabel::DoubleClickTestLabel()
{
setAttribute(Qt::WA_DeleteOnClose);
@ -100,41 +47,44 @@ MyLabel::MyLabel()
setPixmap(QPixmap(":/img/plugins/mouse/double-click-off.png"));
const QByteArray id(kMouseSchemas);
if (QGSettings::isSchemaInstalled(id)){
mSettings = new QGSettings(id, QByteArray(), this);
mDoubleClickTestDbus = new QDBusInterface("org.ukui.ukcc.session",
"/Mouse",
"org.ukui.ukcc.session.Mouse",
QDBusConnection::sessionBus(), this);
if (!mDoubleClickTestDbus->isValid()) {
qCritical() << "org.ukui.ukcc.session.KeyBoard DBus error:" << mDoubleClickTestDbus->lastError();
}
this->setToolTip(tr("double-click to test"));
}
MyLabel::~MyLabel()
DoubleClickTestLabel::~DoubleClickTestLabel()
{
}
void MyLabel::mouseDoubleClickEvent(QMouseEvent *event)
void DoubleClickTestLabel::mouseDoubleClickEvent(QMouseEvent *event)
{
Q_UNUSED(event);
int delay = mSettings->get(kDoubleClickIntervalKey).toInt();
int delay = mDoubleClickTestDbus->property("doubleClick").toInt();
setPixmap(QPixmap(":/img/plugins/mouse/double-click-on.png"));
QTimer::singleShot(delay, this, [=]{
setPixmap(QPixmap(":/img/plugins/mouse/double-click-off.png"));
});
}
void MouseUI::initUI(QWidget *widget)
void MouseUI::settingForIntel()
{
mVlayout = new QVBoxLayout(widget);
mVlayout->setContentsMargins(0, 0, 0, 0);
mWheelSpeedWidget->hide();
mDoubleClickIntervalWidget->hide();
mScrollDirectionWdiget->setFrameShape(QFrame::HLine);
mMouseAccelerationWidget->hide();
}
void MouseUI::initUI()
{
//鼠标
SettingGroup *mouseFrame = new SettingGroup(this);
//指针
SettingGroup *pointerFrame = new SettingGroup(this);
//光标
SettingGroup *cursorFrame = new SettingGroup(this);
mMouseTitleLabel = new TitleLabel(this);
mMouseTitleLabel->setText(tr("Mouse"));
mMouseTitleLabel->setContentsMargins(16,0,0,0);
@ -143,6 +93,19 @@ void MouseUI::initUI(QWidget *widget)
setWheelSpeedFrame();
setDoubleClickFrame();
mouseFrame->insertWidget(0, mDominantHandWidget);
mouseFrame->insertWidget(1, mScrollDirectionWdiget);
mouseFrame->insertWidget(2, mWheelSpeedWidget);
mouseFrame->insertWidget(3, mDoubleClickIntervalWidget);
QVBoxLayout *mouseVLayout = new QVBoxLayout(this);
mouseVLayout->setSpacing(8);
mouseVLayout->setMargin(0);
mouseVLayout->addWidget(mMouseTitleLabel);
mouseVLayout->addWidget(mouseFrame);
//指针
SettingGroup *pointerFrame = new SettingGroup(this);
mPointerTitleLabel = new TitleLabel(this);
mPointerTitleLabel->setText(tr("Pointer"));
mPointerTitleLabel->setContentsMargins(16,0,0,0);
@ -151,38 +114,38 @@ void MouseUI::initUI(QWidget *widget)
setPointerPositionFrame();
setPointerSizeFrame();
pointerFrame->insertWidget(0, mPointerSpeedWidget);
pointerFrame->insertWidget(1, mMouseAccelerationWidget);
pointerFrame->insertWidget(2, mPointerPositionWidget);
pointerFrame->insertWidget(3, mPointerSizeWidet);
QVBoxLayout *pointerVLayout = new QVBoxLayout(this);
pointerVLayout->setSpacing(8);
pointerVLayout->setMargin(0);
pointerVLayout->addWidget(mPointerTitleLabel);
pointerVLayout->addWidget(pointerFrame);
//光标
SettingGroup *cursorFrame = new SettingGroup(this);
mCursorTitleLabel = new TitleLabel(this);
mCursorTitleLabel->setText(tr("Cursor"));
mCursorTitleLabel->setContentsMargins(16,0,0,0);
setBlinkCursorFrame();
setCursorSpeedFrame();
/* add all frame to widget */
mouseFrame->insertWidget(0, mDominantHandWidget);
mouseFrame->insertWidget(1, mScrollDirectionWdiget);
mouseFrame->insertWidget(2, mWheelSpeedWidget);
mouseFrame->insertWidget(3, mDoubleClickIntervalWidget);
pointerFrame->insertWidget(0, mPointerSpeedWidget);
pointerFrame->insertWidget(1, mMouseAccelerationWidget);
pointerFrame->insertWidget(2, mPointerPositionWidget);
pointerFrame->insertWidget(3, mPointerSizeWidet);
cursorFrame->insertWidget(0, mBlinkingCursorOnTextWidget);
cursorFrame->insertWidget(1, mCursorSpeedWidget);
mVlayout->addWidget(mMouseTitleLabel);
mVlayout->addWidget(mouseFrame);
mVlayout->addSpacing(32);
mVlayout->setSpacing(8);
QVBoxLayout *cursorVLayout = new QVBoxLayout(this);
cursorVLayout->setSpacing(8);
cursorVLayout->setMargin(0);
cursorVLayout->addWidget(mCursorTitleLabel);
cursorVLayout->addWidget(cursorFrame);
mVlayout->addWidget(mPointerTitleLabel);
mVlayout->addWidget(pointerFrame);
mVlayout->addSpacing(32);
mVlayout->setSpacing(8);
mVlayout->addWidget(mCursorTitleLabel);
mVlayout->addWidget(cursorFrame);
mVlayout->addLayout(mouseVLayout);
mVlayout->addLayout(pointerVLayout);
mVlayout->addLayout(cursorVLayout);
mVlayout->addStretch();
}
@ -244,7 +207,7 @@ void MouseUI::setDoubleClickFrame()
mDoubleClickIntervalWidget->slider()->setSingleStep(100);
mDoubleClickIntervalWidget->slider()->setPageStep(100);
mDoubleClickIntervalWidget->slider()->installEventFilter(this);
mDoubleClickIntervalWidget->insertWidget(5, new MyLabel());
mDoubleClickIntervalWidget->insertWidget(5, new DoubleClickTestLabel());
}
void MouseUI::setPointerSpeedFrame()
@ -319,334 +282,3 @@ void MouseUI::setCursorSpeedFrame()
mCursorSpeedWidget->slider()->setPageStep(200);
mCursorSpeedWidget->installEventFilter(this);
}
void MouseUI::initConnection()
{
QByteArray mouseId(kMouseSchemas);
QByteArray desktopId(kDesktopSchemas);
QByteArray themeId(kThemeSchemas);
if (QGSettings::isSchemaInstalled(mouseId) && QGSettings::isSchemaInstalled(desktopId)) {
mMouseGsetting = new QGSettings(mouseId, QByteArray(), this);
mDesktopGsetting = new QGSettings(desktopId, QByteArray(), this);
mThemeSettings = new QGSettings(themeId, QByteArray(), this);
initEnableStatus();
connect(mDominantHandWidget, QOverload<int>::of(&RadioButtonWidget::buttonClicked),
this, &MouseUI::dominantHandSlot);
connect(mScrollDirectionWdiget, QOverload<int>::of(&RadioButtonWidget::buttonClicked),
this, &MouseUI::scrollDirectionSlot);
connect(mWheelSpeedWidget, &SliderWidget::valueChanged, this, &MouseUI::wheelSpeedSlot);
connect(mDoubleClickIntervalWidget, &SliderWidget::valueChanged , this, &MouseUI::doubleClickIntervalSlot);
connect(mPointerSpeedWidget, &SliderWidget::valueChanged, this, &MouseUI::pointerSpeedSlot);
connect(mMouseAccelerationWidget, &SwitchWidget::stateChanged, this, &MouseUI::mouseAccelerationSlot);
connect(mPointerPositionWidget, &SwitchWidget::stateChanged, this, &MouseUI::pointerPositionSlot);
connect(mPointerSizeWidet, QOverload<int>::of(&RadioButtonWidget::buttonClicked),
this, &MouseUI::pointerSizeSlot);
connect(mBlinkingCursorOnTextWidget, &SwitchWidget::stateChanged, this, &MouseUI::blinkCursorOnTextSlot);
connect(mCursorSpeedWidget, &SliderWidget::valueChanged, this, &MouseUI::cursorSpeedSlot);
gsettingConnection();
}
}
void MouseUI::gsettingConnection()
{
// 命令行修改 gsetting 的 key 值图形界面做出相应改变
connect(mMouseGsetting,&QGSettings::changed,[=] (const QString &key){
if(key == "leftHanded") {
bool handHabit = mMouseGsetting->get(kDominantHandKey).toBool();
if (handHabit == true) {
mDominantHandRightRadio->setChecked(true);
} else {
mDominantHandLeftRadio->setChecked(true);
}
} else if(key == "naturalScroll") {
bool scrollDirection = mMouseGsetting->get(kScrollDirection).toBool();
mScrollDirectionWdiget->buttonGroup()->blockSignals(true);
if (scrollDirection) {
mScrollDirectionReverseRadio->setChecked(true);
} else {
mScrollDirectionForwardRadio->setChecked(true);
}
mScrollDirectionWdiget->buttonGroup()->blockSignals(false);
} else if(key == "wheelSpeed") {
mWheelSpeedWidget->slider()->blockSignals(true);
int value = mMouseGsetting->get(kWheelSpeedKey).toInt();
if (value < 1 || value >10) {
mMouseGsetting->reset(kWheelSpeedKey);
}
mWheelSpeedWidget->setValue(mMouseGsetting->get(kWheelSpeedKey).toInt());
mWheelSpeedWidget->slider()->blockSignals(false);
} else if(key == "doubleClick") {
int dc = mMouseGsetting->get(kDoubleClickIntervalKey).toInt();
mDoubleClickIntervalWidget->slider()->blockSignals(true);
mDoubleClickIntervalWidget->setValue(dc);
mDoubleClickIntervalWidget->slider()->blockSignals(false);
} else if(key == "motionAcceleration") {
mPointerSpeedWidget->slider()->blockSignals(true);
mPointerSpeedWidget->setValue(static_cast<int>(mMouseGsetting->get(kPointerSpeedKey).toDouble()*100));
mPointerSpeedWidget->slider()->blockSignals(false);
} else if(key == "mouseAccel") {
mMouseAccelerationWidget->blockSignals(true);
mMouseAccelerationWidget->setChecked(mMouseGsetting->get(kMouseAccelerationKey).toBool());
mMouseAccelerationWidget->blockSignals(false);
} else if(key == "locatePointer") {
mPointerPositionWidget->blockSignals(true);
mPointerPositionWidget->setChecked(mMouseGsetting->get(kPointerPositionKey).toBool());
mPointerPositionWidget->blockSignals(false);
} else if(key == "cursorSize") {
int PointerSize = mMouseGsetting->get(kPointerSizeKey).toInt();
if (PointerSize == 24) {
mPointerSizeSmallRadio->setChecked(true);
} else if (PointerSize == 36) {
mPointerSizeMediumRadio->setChecked(true);
} else if (PointerSize == 48) {
mPointerSizeLargeRadio->setChecked(true);
} else {
mMouseGsetting->reset(kPointerSizeKey);
}
}
});
connect(mDesktopGsetting,&QGSettings::changed,[=](const QString &key) {
if (key == "cursorBlink") {
mBlinkingCursorOnTextWidget->blockSignals(true);
mBlinkingCursorOnTextWidget->setChecked(mDesktopGsetting->get(kBlinkCursorOnTextKey).toBool());
mBlinkingCursorOnTextWidget->blockSignals(false);
if (mDesktopGsetting->get(kBlinkCursorOnTextKey).toBool()) {
mBlinkingCursorOnTextWidget->setRadiusType(UkccFrame::Top);
} else {
mBlinkingCursorOnTextWidget->setRadiusType(UkccFrame::Around);
}
mCursorSpeedWidget->setVisible(mDesktopGsetting->get(kBlinkCursorOnTextKey).toBool());
}else if (key == "cursorBlinkTime") {
int mValue = mCursorSpeedWidget->slider()->maximum() - mDesktopGsetting->get(kCursorSpeedKey).toInt() + mCursorSpeedWidget->slider()->minimum();
mCursorSpeedWidget->slider()->blockSignals(true);
mCursorSpeedWidget->setValue(mValue);
mCursorSpeedWidget->slider()->blockSignals(false);
}
});
}
void MouseUI::initEnableStatus()
{
//初始化惯用手, 左手:右键为主键,右手:左键为主键
mDominantHandWidget->buttonGroup()->blockSignals(true);
bool currentDominantHand = mMouseGsetting->get(kDominantHandKey).toBool();
if (currentDominantHand == true) {
mDominantHandRightRadio->setChecked(true);
} else {
mDominantHandLeftRadio->setChecked(true);
}
mDominantHandWidget->buttonGroup()->blockSignals(false);
// 初始化滚动方向 true:界面与鼠标滚轮滚动方向相反(反向),false:界面与滚轮滚动方向相同(正向)
mScrollDirectionWdiget->buttonGroup()->blockSignals(true);
if (mMouseGsetting->keys().contains("naturalScroll")) {
bool currentScrollDirection = mMouseGsetting->get(kScrollDirection).toBool();
if (currentScrollDirection) {
mScrollDirectionReverseRadio->setChecked(true);
} else {
mScrollDirectionForwardRadio->setChecked(true);
}
}
mScrollDirectionWdiget->buttonGroup()->blockSignals(false);
//初始化滚轮速度
mWheelSpeedWidget->slider()->blockSignals(true);
int value = mMouseGsetting->get(kWheelSpeedKey).toInt();
if (value < 1 || value >10) {
mMouseGsetting->reset(kWheelSpeedKey);
}
mWheelSpeedWidget->setValue(mMouseGsetting->get(kWheelSpeedKey).toInt());
mWheelSpeedWidget->slider()->blockSignals(false);
//初始化双击间隔时长
mDoubleClickIntervalWidget->slider()->blockSignals(true);
mDoubleClickIntervalWidget->setValue(mMouseGsetting->get(kDoubleClickIntervalKey).toInt());
mDoubleClickIntervalWidget->slider()->blockSignals(false);
//初始化指针速度
mPointerSpeedWidget->slider()->blockSignals(true);
mPointerSpeedWidget->setValue(static_cast<int>(mMouseGsetting->get(kPointerSpeedKey).toDouble()*100));
mPointerSpeedWidget->slider()->blockSignals(false);
//初始化鼠标加速
mMouseAccelerationWidget->blockSignals(true);
mMouseAccelerationWidget->setChecked(mMouseGsetting->get(kMouseAccelerationKey).toBool());
mMouseAccelerationWidget->blockSignals(false);
//初始化按 ctrl 键时显示指针位置
mPointerPositionWidget->blockSignals(true);
mPointerPositionWidget->setChecked(mMouseGsetting->get(kPointerPositionKey).toBool());
mPointerPositionWidget->blockSignals(false);
//初始化指针大小
mPointerSizeWidet->buttonGroup()->blockSignals(true);
int currentPointerSize = mMouseGsetting->get(kPointerSizeKey).toInt();
if (currentPointerSize != 24 && currentPointerSize != 36 && currentPointerSize != 48) {
mMouseGsetting->reset(kPointerSizeKey);
currentPointerSize = mMouseGsetting->get(kPointerSizeKey).toInt();
}
if (currentPointerSize == 24) {
mPointerSizeSmallRadio->setChecked(true);
} else if (currentPointerSize == 36) {
mPointerSizeMediumRadio->setChecked(true);
} else if (currentPointerSize == 48) {
mPointerSizeLargeRadio->setChecked(true);
}
mPointerSizeWidet->buttonGroup()->blockSignals(false);
//初始化文本区域光标闪烁
mBlinkingCursorOnTextWidget->blockSignals(true);
mBlinkingCursorOnTextWidget->setChecked(mDesktopGsetting->get(kBlinkCursorOnTextKey).toBool());
mBlinkingCursorOnTextWidget->blockSignals(false);
//初始化光标速度
mCursorSpeedWidget->slider()->blockSignals(true);
mCursorSpeedWidget->setValue(mCursorSpeedWidget->slider()->maximum() - mDesktopGsetting->get(kCursorSpeedKey).toInt()
+ mCursorSpeedWidget->slider()->minimum());
mCursorSpeedWidget->slider()->blockSignals(false);
if (mDesktopGsetting->get(kBlinkCursorOnTextKey).toBool()) {
mBlinkingCursorOnTextWidget->setRadiusType(UkccFrame::Top);
} else {
mBlinkingCursorOnTextWidget->setRadiusType(UkccFrame::Around);
}
mCursorSpeedWidget->setVisible(mDesktopGsetting->get(kBlinkCursorOnTextKey).toBool());
}
/* Slot */
void MouseUI::dominantHandSlot(int id)
{
bool tmpLeftHand;
// 左键主键右手、left-handed=false右键主键左手、left-handed=true
if (id == 0) {
tmpLeftHand = false;
} else {
tmpLeftHand = true;
}
mMouseGsetting->set(kDominantHandKey, tmpLeftHand);
Common::buriedSettings(name(), mDominantHandWidget->objectName(), QString("setting"));
}
void MouseUI::scrollDirectionSlot(int id)
{
bool tmpScrollDirection;
// true:界面与鼠标滚轮滚动方向相反(反向),false:界面与滚轮滚动方向相同(正向)
if (id == 0) {
tmpScrollDirection = false;
} else {
tmpScrollDirection = true;
}
if (mMouseGsetting->keys().contains("naturalScroll")) {
mMouseGsetting->set(kScrollDirection, tmpScrollDirection);
} else {
qDebug() << "naturalScroll is not exist in org.ukui.peripherals-mouse";
}
Common::buriedSettings(name(), mScrollDirectionWdiget->objectName(), QString("setting"));
}
void MouseUI::wheelSpeedSlot()
{
mMouseGsetting->set(kWheelSpeedKey, mWheelSpeedWidget->value());
}
void MouseUI::doubleClickIntervalSlot()
{
mMouseGsetting->set(kDoubleClickIntervalKey, mDoubleClickIntervalWidget->value());
qApp->setDoubleClickInterval(mDoubleClickIntervalWidget->value());
}
void MouseUI::pointerSpeedSlot(int value)
{
mMouseGsetting->set(kPointerSpeedKey, static_cast<double>(value)/mPointerSpeedWidget->slider()->maximum() * 10);
}
void MouseUI::mouseAccelerationSlot(bool checked)
{
mMouseGsetting->set(kMouseAccelerationKey, checked);
Common::buriedSettings(name(), mMouseAccelerationWidget->objectName(), QString("setting"), checked ? "true":"false");
}
void MouseUI::pointerPositionSlot(bool checked)
{
mMouseGsetting->set(kPointerPositionKey, checked);
Common::buriedSettings(name(), mPointerPositionWidget->objectName(), QString("setting"), checked ? "true":"false");
}
void MouseUI::pointerSizeSlot(int id)
{
int tmpPointerSize = id;
mMouseGsetting->set(kPointerSizeKey, tmpPointerSize);
Common::buriedSettings(name(), mPointerSizeWidet->objectName(), QString("setting"));
}
void MouseUI::blinkCursorOnTextSlot(bool checked)
{
mCursorSpeedWidget->setVisible(checked);
mDesktopGsetting->set(kBlinkCursorOnTextKey, checked);
mThemeSettings->set(kBlinkCursorOnTextKey, checked);
if (!checked) {
mBlinkingCursorOnTextWidget->setRadiusType(UkccFrame::Around);
mThemeSettings->set(kCursorSpeedKey, 0);
} else {
mBlinkingCursorOnTextWidget->setRadiusType(UkccFrame::Top);
int mValue = mCursorSpeedWidget->slider()->maximum() - mCursorSpeedWidget->slider()->value() + mCursorSpeedWidget->slider()->minimum();
mThemeSettings->set(kCursorSpeedKey, mValue);
}
Common::buriedSettings(name(), mBlinkingCursorOnTextWidget->objectName(), QString("setting"), checked ? "true":"false");
}
void MouseUI::cursorSpeedSlot()
{
mDesktopGsetting->set(kCursorSpeedKey, mCursorSpeedWidget->slider()->maximum() - mCursorSpeedWidget->value()
+ mCursorSpeedWidget->slider()->minimum());
mThemeSettings->set(kCursorSpeedKey, mCursorSpeedWidget->slider()->maximum() - mCursorSpeedWidget->value()
+ mCursorSpeedWidget->slider()->minimum());
}
bool MouseUI::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::FocusOut) {
if (watched == mWheelSpeedWidget->slider()) {
int value = mWheelSpeedWidget->value();
Common::buriedSettings(name(), mWheelSpeedWidget->objectName(), QString("setting"), QString::number(value));
} else if (watched == mDoubleClickIntervalWidget->slider()) {
int value = mDoubleClickIntervalWidget->value();
Common::buriedSettings(name(), mDoubleClickIntervalWidget->objectName(), QString("setting"), QString::number(value));
} else if (watched == mPointerSpeedWidget->slider()) {
int value = mPointerSpeedWidget->value();
Common::buriedSettings(name(), mPointerSpeedWidget->objectName(), QString("setting"), QString::number(value));
} else if (watched == mCursorSpeedWidget->slider()) {
int value = mCursorSpeedWidget->value();
Common::buriedSettings(name(), mCursorSpeedWidget->objectName(), QString("setting"), QString::number(value));
}
}
return QObject::eventFilter(watched, event);
}

View File

@ -10,13 +10,12 @@
#include <QRadioButton>
#include <QSlider>
#include <QByteArray>
#include <QGSettings/QGSettings>
#include <QVariant>
#include <QApplication>
#include <QButtonGroup>
#include <QDebug>
#include <QToolButton>
#include "shell/interface.h"
#include "common.h"
@ -30,74 +29,127 @@
#include "kswitchbutton.h"
using namespace kdk;
const QByteArray kMouseSchemas = "org.ukui.peripherals-mouse";
const QString kDominantHandKey = "left-handed";
const QString kScrollDirection = "natural-scroll";
const QString kWheelSpeedKey = "wheel-speed";
const QString kDoubleClickIntervalKey = "double-click";
const QString kPointerSpeedKey = "motion-acceleration";
const QString kMouseAccelerationKey = "mouse-accel";
const QString kPointerPositionKey = "locate-pointer";
const QString kPointerSizeKey = "cursor-size";
const QByteArray kDesktopSchemas = "org.mate.interface";
const QString kBlinkCursorOnTextKey = "cursor-blink";
const QString kCursorSpeedKey = "cursor-blink-time";
const QByteArray kThemeSchemas = "org.ukui.style";
class MyLabel : public QLabel
class DoubleClickTestLabel : public QLabel
{
Q_OBJECT
public:
MyLabel();
~MyLabel();
DoubleClickTestLabel();
~DoubleClickTestLabel();
public:
QGSettings * mSettings;
QDBusInterface * mDoubleClickTestDbus;
protected:
void mouseDoubleClickEvent(QMouseEvent *event);
};
class MouseUI : public QWidget, CommonInterface
class MouseUI : public QWidget
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
Q_INTERFACES(CommonInterface)
public:
MouseUI();
~MouseUI() Q_DECL_OVERRIDE;
QString plugini18nName() Q_DECL_OVERRIDE;
int pluginTypes() Q_DECL_OVERRIDE;
QWidget *pluginUi() Q_DECL_OVERRIDE;
const QString name() const Q_DECL_OVERRIDE;
bool isShowOnHomePage() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
bool isEnable() const Q_DECL_OVERRIDE;
explicit MouseUI(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
virtual ~MouseUI();
void settingForIntel();
private:
QWidget *pluginWidget;
int pluginType;
QString pluginName;
public:
inline RadioButtonWidget *dominantHandWidget()
{
return mDominantHandWidget;
}
bool mFirstLoad;
inline QRadioButton *dominantHandLeftRadio()
{
return mDominantHandLeftRadio;
}
inline QRadioButton *dominantHandRightRadio()
{
return mDominantHandRightRadio;
}
inline RadioButtonWidget *scrollDirectionWdiget()
{
return mScrollDirectionWdiget;
}
inline QRadioButton *scrollDirectionForwardRadio()
{
return mScrollDirectionForwardRadio;
}
inline QRadioButton *scrollDirectionReverseRadio()
{
return mScrollDirectionReverseRadio;
}
inline SliderWidget *wheelSpeedWidget()
{
return mWheelSpeedWidget;
}
inline SliderWidget *doubleClickIntervalWidget()
{
return mDoubleClickIntervalWidget;
}
inline SliderWidget *pointerSpeedWidget()
{
return mPointerSpeedWidget;
}
inline SwitchWidget *mouseAccelerationWidget()
{
return mMouseAccelerationWidget;
}
inline SwitchWidget *pointerPositionWidget()
{
return mPointerPositionWidget;
}
inline RadioButtonWidget *pointerSizeWidet()
{
return mPointerSizeWidet;
}
inline QRadioButton *pointerSizeSmallRadio()
{
return mPointerSizeSmallRadio;
}
inline QRadioButton *pointerSizeMediumRadio()
{
return mPointerSizeMediumRadio;
}
inline QRadioButton *pointerSizeLargeRadio()
{
return mPointerSizeLargeRadio;
}
inline SwitchWidget *blinkingCursorOnTextWidget()
{
return mBlinkingCursorOnTextWidget;
}
inline SliderWidget *cursorSpeedWidget()
{
return mCursorSpeedWidget;
}
private:
RadioButtonWidget *mDominantHandWidget; // 惯用手
RadioButtonWidget *mScrollDirectionWdiget; // 滚动方向
RadioButtonWidget *mDominantHandWidget; // 惯用手
RadioButtonWidget *mScrollDirectionWdiget; // 滚动方向
SliderWidget *mWheelSpeedWidget; // 滚轮速度
SliderWidget *mDoubleClickIntervalWidget; // 双击间隔时长
SliderWidget *mPointerSpeedWidget; // 指针速度
SwitchWidget *mMouseAccelerationWidget; // 鼠标加速
SwitchWidget *mPointerPositionWidget; // 按 ctrl 键时显示指针位置
RadioButtonWidget *mPointerSizeWidet; // 指针大小
RadioButtonWidget *mPointerSizeWidet; // 指针大小
SwitchWidget *mBlinkingCursorOnTextWidget; // 文本区域闪烁光标
SliderWidget *mCursorSpeedWidget; // 光标速度
@ -115,12 +167,8 @@ private:
QVBoxLayout *mVlayout;
QGSettings *mMouseGsetting;
QGSettings *mDesktopGsetting;
QGSettings *mThemeSettings;
private:
void initUI(QWidget *widget);
void initUI();
void setDominantHandFrame();
void setScrollDirectionFrame();
void setWheelSpeedFrame();
@ -131,24 +179,6 @@ private:
void setPointerSizeFrame();
void setBlinkCursorFrame();
void setCursorSpeedFrame();
void initConnection();
void gsettingConnection();
void initEnableStatus();
bool eventFilter(QObject *watched, QEvent *event);
public slots:
void dominantHandSlot(int id);
void scrollDirectionSlot(int id);
void wheelSpeedSlot();
void doubleClickIntervalSlot();
void pointerSpeedSlot(int value);
void mouseAccelerationSlot(bool checked);
void pointerPositionSlot(bool checked);
void pointerSizeSlot(int id);
void blinkCursorOnTextSlot(bool checked);
void cursorSpeedSlot();
};
#endif // MOUSEUI_H

View File

@ -198,7 +198,7 @@ void Printer::refreshPrinterDevSlot()
void Printer::runExternalApp()
{
Common::buriedSettings(name(), "open system-config-printer", QString("clicked"));
if (Common::isTablet()) {
if (Common::isTablet() || Common::isWayland()) {
QDBusInterface ifc("com.kylin.AppManager",
"/com/kylin/AppManager",
"com.kylin.AppManager",

View File

@ -23,7 +23,7 @@ CONFIG += plugin \
link_pkgconfig
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kysdk-diagnostics \
TARGET = $$qtLibraryTarget(printer)
DESTDIR = ../..

View File

@ -29,7 +29,7 @@ CONFIG += link_pkgconfig c++11
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets \
kysdk-diagnostics \
DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -389,5 +389,5 @@ void Fonts::initModel()
}
}
mUkccSettings->set(UKCC_FONTS_EKY, actFontsList);
// mUkccSettings->set(UKCC_FONTS_EKY, actFontsList); To fix #151084
}

View File

@ -25,6 +25,7 @@ PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets \
kysdk-diagnostics \
INCLUDEPATH += \
$$PROJECT_ROOTDIR \

View File

@ -33,6 +33,7 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gsettings-qt \
gio-2.0 \
kysdk-qtwidgets \
kysdk-diagnostics \
# gio-unix-2.0
#DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -35,7 +35,8 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -87,7 +87,7 @@ const QStringList kIconsList {"computer.png", "user-trash.png", "system-fil
const QStringList kIntelIconList {"computer.png", "kylin-software-center.png", "ukui-control-center.png", "kylin-weather.png", "calendar-app.png", "kylin-camera.png"};
const QStringList defaultIconList {"kylin-startmenu.png", "kylin-software-center.png", "indicator-china-weather.png", "burner.png", "kylin-music.png", "kylin-photo-viewer.png"};
const QStringList heyinIconList {"kylin-alarm-clock.png", "kylin-clipboard.png", "ukui-control-center.png", "kylin-calendar.png", "kylin-ipmsg.png", "kylin-photo-viewer.png"};
const QStringList heyinIconList {"kylin-alarm-clock.png", "kylin-clipboard.png", "ukui-control-center.png", "kylin-calendar.png", "kylin-ipmsg.png", "kylin-photo-viewer.png"};
const QStringList classicIconList {"kylin-startmenu.png", "kylin-software-center.png", "kylin-alarm-clock.png", "indicator-china-weather.png", "yhkylin-backup-tools.png", "kylin-clipboard.png"};
namespace {
@ -183,24 +183,31 @@ void Theme::initThemeUi()
mLightBtn->setObjectName("lighttheme");
mDarkBtn = new ThemeButton(tr("Dark"),QPixmap(QString("://img/plugins/theme/%1.png").arg("dark")), mThemeModeFrame);
mDarkBtn->setObjectName("darktheme");
mDefaultBtn = new ThemeButton(tr("Auto"), QPixmap(QString("://img/plugins/theme/%1.png").arg("default")),mThemeModeFrame);
mDefaultBtn = new ThemeButton(tr("Default"), QPixmap(QString("://img/plugins/theme/%1.png").arg("default")),mThemeModeFrame);
mDefaultBtn->setObjectName("defaulttheme");
mAutoBtn = new ThemeButton(tr("Auto"), QPixmap(QString("://img/plugins/theme/%1.png").arg("auto")),mThemeModeFrame);
mAutoBtn->setObjectName("autotheme");
mThemeModeBtnGroup = new QButtonGroup(this);
mThemeModeBtnGroup->addButton(mLightBtn);
mThemeModeBtnGroup->addButton(mDarkBtn);
mThemeModeBtnGroup->addButton(mDefaultBtn);
mThemeModeBtnGroup->addButton(mAutoBtn);
buildThemeModeBtn(mLightBtn);
buildThemeModeBtn(mDarkBtn);
buildThemeModeBtn(mDefaultBtn);
buildThemeModeBtn(mAutoBtn);
hLyt->setSpacing(40);
hLyt->setContentsMargins(16, 16, 0, 0);
hLyt->addWidget(mLightBtn);
hLyt->addWidget(mDarkBtn);
hLyt->addWidget(mDefaultBtn);
hLyt->addWidget(mAutoBtn);
mDefaultBtn->setVisible(false);
hLyt->addStretch();
@ -282,6 +289,7 @@ void Theme::setupComponent() {
mDefaultBtn->setProperty("value", "ukui-default");
mLightBtn->setProperty("value", "ukui-light");
mDarkBtn->setProperty("value", "ukui-dark");
mAutoBtn->setProperty("value", "ukui-auto");
ui->tranSlider->setRange(35, 100);
@ -322,12 +330,15 @@ void Theme::buildThemeModeBtn(ThemeButton *button)
void Theme::initThemeMode() {
// 获取当前主题
QString currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
bool isAutoTheme = mAutoSettings->get(COLOR_KEY_AUTO_THEME).toBool();
bool isAutoTheme = getAutoTheme();
if ("ukui-white" == currentThemeMode || "ukui-default" == currentThemeMode || isAutoTheme) {
mThemeModeBtnGroup->buttonClicked(mDefaultBtn);
if (isAutoTheme) {
mThemeModeBtnGroup->buttonClicked(mAutoBtn);
emit mAutoBtn->clicked();
} else if ("ukui-white" == currentThemeMode || "ukui-default" == currentThemeMode) {
mThemeBtnGroup->buttonClicked(mDefaultBtn);
emit mDefaultBtn->clicked();
} else if ("ukui-dark" == currentThemeMode || "ukui-black" == currentThemeMode){
} else if ("ukui-dark" == currentThemeMode || "ukui-black" == currentThemeMode) {
mThemeModeBtnGroup->buttonClicked(mDarkBtn);
emit mDarkBtn->clicked();
} else {
@ -647,8 +658,7 @@ void Theme::initConnection()
if (key == "styleName") {
// 获取当前主题
if (mAutoSettings) {
bool isAutoTheme = mAutoSettings->get(COLOR_KEY_AUTO_THEME).toBool();
if (!isAutoTheme) setThemeBtnStatus();
setThemeBtnStatus();
}
}
@ -707,12 +717,12 @@ void Theme::initConnection()
if (mAutoSettings) {
connect(mAutoSettings, &QGSettings::changed, this, [=](const QString &key) {
if (key == "themeScheduleAutomatic") {
bool isAutoTheme = mAutoSettings->get(COLOR_KEY_AUTO_THEME).toBool();
bool isAutoTheme = getAutoTheme();
if (isAutoTheme) {
if (!mDefaultBtn->isChecked())
emit mDefaultBtn->click();
if (!mAutoBtn->isChecked()) {
emit mAutoBtn->click();
}
} else {
setThemeBtnStatus();
}
@ -825,14 +835,19 @@ QStringList Theme::getSystemCursorThemes() {
void Theme::setThemeBtnStatus()
{
QString currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
for (QAbstractButton * button : mThemeModeBtnGroup->buttons()){
QVariant valueVariant = button->property("value");
bool isAutoTheme = getAutoTheme();
for (QAbstractButton * button : mThemeModeBtnGroup->buttons()) {
QString propertyName = button->property("value").toString();
if ("ukui-black" == currentThemeMode) {
currentThemeMode = "ukui-dark";
} else if("ukui-white" == currentThemeMode) {
} else if ("ukui-white" == currentThemeMode) {
currentThemeMode = "ukui-light";
} else if ("ukui-auto" == propertyName && isAutoTheme && button->isChecked()) {
return ;
}
if (valueVariant.isValid() && valueVariant.toString() == currentThemeMode) {
if (propertyName == currentThemeMode && !isAutoTheme) {
disconnect(mThemeModeBtnGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(themeBtnClickSlot(QAbstractButton*)));
button->click();
connect(mThemeModeBtnGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(themeBtnClickSlot(QAbstractButton*)));
@ -944,6 +959,11 @@ QString Theme::getGlobalName()
return mGlobalName;
}
bool Theme::getAutoTheme()
{
return mAutoSettings->get(COLOR_KEY_AUTO_THEME).toBool();
}
void Theme::hideIntelComponent()
{
ui->resetBtn->setVisible(false);
@ -1122,13 +1142,6 @@ void Theme::writeKwinSettings(bool change, QString theme, bool effect) {
}
void Theme::themeBtnClickSlot(QAbstractButton *button) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"),
QStringLiteral("/org/kde/KWin/BlendChanges"),
QStringLiteral("org.kde.KWin.BlendChanges"),
QStringLiteral("start"));
msg << 300;
QDBusConnection::sessionBus().send(msg);
// 设置主题
QString themeMode = button->property("value").toString();
QString currentThemeMode = qtSettings->get(MODE_QT_KEY).toString();
@ -1142,22 +1155,22 @@ void Theme::themeBtnClickSlot(QAbstractButton *button) {
revokeGlobalThemeSlot("getQtDarkThemeName", themeMode);
revokeGlobalThemeSlot("getGtkDarkThemeName", tmpMode);
mAutoSettings->set(COLOR_KEY_AUTO_THEME, false);
} else if ("ukui-light" == themeMode){
} else if ("ukui-light" == themeMode) {
tmpMode = "ukui-white";
revokeGlobalThemeSlot("getDefaultLightDarkMode", "light");
revokeGlobalThemeSlot("getQtLightThemeName", themeMode);
revokeGlobalThemeSlot("getGtkLightThemeName", tmpMode);
mAutoSettings->set(COLOR_KEY_AUTO_THEME, false);
} else if ("ukui-default" == themeMode) {
if (mAutoSettings) {
revokeGlobalThemeSlot("getDefaultLightDarkMode", "light");
revokeGlobalThemeSlot("getQtLightThemeName", themeMode);
revokeGlobalThemeSlot("getGtkLightThemeName", tmpMode);
mAutoSettings->set(COLOR_KEY_AUTO_THEME, true);
return;
}
revokeGlobalThemeSlot("getDefaultLightDarkMode", "light");
revokeGlobalThemeSlot("getQtLightThemeName", themeMode);
revokeGlobalThemeSlot("getGtkLightThemeName", tmpMode);
mAutoSettings->set(COLOR_KEY_AUTO_THEME, false);
} else if (themeMode == "ukui-auto" && button->isChecked()) {
clickedCustomTheme();
mAutoSettings->set(COLOR_KEY_AUTO_THEME, true);
return;
}
gtkSettings->set(MODE_GTK_KEY, tmpMode);
qtSettings->set(MODE_QT_KEY, themeMode);
}
@ -1211,24 +1224,22 @@ void Theme::changeGlobalThemeSlot(QAbstractButton *button)
qtSettings->set(ICON_QT_KEY, iconName);
qtSettings->set(WIDGET_QT_KEY, widgetName);
qtSettings->set(MODE_QT_KEY, colorTheme);
qtSettings->set(COLOR_QT_KEY, accentColor);
gtkSettings->set(ICON_GTK_KEY, iconName);
gtkSettings->set(MODE_GTK_KEY, gtkColorTheme);
if (colorTheme != "ukui-default") {
gtkSettings->set(MODE_GTK_KEY, gtkColorTheme);
qtSettings->set(MODE_QT_KEY, colorTheme);
curSettings->set(CURSOR_THEME_KEY, cursorName);
if (mAutoSettings && value != "custom") {
mAutoSettings->set(COLOR_KEY_AUTO_THEME, false);
}
#ifndef OPENKYLIN
curSettings->set(CURSOR_THEME_KEY, cursorName);
#endif
if (mAutoSettings && value != "custom") {
mAutoSettings->set(COLOR_KEY_AUTO_THEME, false);
}
if (supportBlur) {
changeEffectBtnSlot(blurEnable);
}

View File

@ -116,6 +116,7 @@ private:
ThemeButton *mDefaultBtn;
ThemeButton *mDarkBtn;
ThemeButton *mLightBtn;
ThemeButton *mAutoBtn;
QButtonGroup *mThemeBtnGroup;
QButtonGroup *mThemeModeBtnGroup;
@ -180,6 +181,8 @@ private:
QString getCursorName();
QString getGlobalName();
bool getAutoTheme();
void hideIntelComponent();
void clickedCustomTheme();

View File

@ -27,7 +27,8 @@ LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt -lX11 -lXfixes -lXcursor
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kysdk-sysinfo
kysdk-sysinfo \
# kysdk-diagnostics \
SOURCES += \
cursor/cursortheme.cpp \

View File

@ -35,7 +35,7 @@ CONFIG += link_pkgconfig \
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -38,5 +38,5 @@ SUBDIRS += system/display \
}
if(contains(DEFINES, UKCC_ENABLE_GRUB)){
SUBDIRS += currency/boot \
SUBDIRS += commoninfo/boot \
}

View File

@ -28,7 +28,7 @@ PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-sysinfo \
kysdk-qtwidgets \
kysdk-diagnostics \

View File

@ -51,6 +51,8 @@
#include <QStorageInfo>
#include <QtMath>
#include <QSvgRenderer>
#include <QSqlQuery>
#include <QSqlRecord>
const QString kAboutFile = "/usr/share/applications/kylin-user-guide.desktop";
const QString kHPFile = "/usr/share/applications/hp-document.desktop";
@ -105,9 +107,10 @@ QWidget *About::pluginUi()
setupKernelCompenent();
setupSerialComponent();
setPrivacyCompent();
if (!mDiskFrame->isHidden())
setupDiskCompenet();
setupDiskCompenet();
securityControl();
setupSysInstallComponent();
setupUpgradeComponent();
mNtphostName.append(QString("0.cn.pool.ntp.org"));
mNtphostName.append(QString("1.cn.pool.ntp.org"));
@ -209,6 +212,17 @@ void About::initUI(QWidget *widget)
mPatchVersionLabel_2 = new LightLabel;
mPatchVersionFrame = createFrame(mPatchVersionLabel_1, mPatchVersionLabel_2);
/* 安装日期 */
mInstallDateLabel_1 = new FixLabel(tr("Installed Date"));
mInstallDateLabel_2 = new LightLabel;
mInstallDateFrame = createFrame(mInstallDateLabel_1, mInstallDateLabel_2);
/* 系统更新时间 */
mUpgradeDateLabel_1 = new FixLabel(tr("Upgrade Date"));
mUpgradeDateLabel_2 = new LightLabel;
mUpgradeDateFrame = createFrame(mUpgradeDateLabel_1, mUpgradeDateLabel_2);
/* 主机名 */
mHostNameLabel_1 = new FixLabel(tr("HostName"));
mHostNameLabel_2 = new LightLabel;
@ -274,6 +288,8 @@ void About::initUI(QWidget *widget)
mInformationLayout->addWidget(mVersionFrame);
mInformationLayout->addWidget(mVersionNumberFrame);
mInformationLayout->addWidget(mPatchVersionFrame);
mInformationLayout->addWidget(mInstallDateFrame);
mInformationLayout->addWidget(mUpgradeDateFrame);
mInformationLayout->addWidget(mHostNameFrame);
mInformationLayout->addWidget(mKernelFrame);
mInformationLayout->addWidget(mCpuFrame);
@ -296,8 +312,6 @@ void About::initUI(QWidget *widget)
mverticalLayout->addWidget(Aboutwidget);
mverticalLayout->addStretch();
fromOsRelease();
}
QFrame *About::initPrivacyUi()
@ -758,12 +772,12 @@ void About::setupKernelCompenent()
QString kernal = QSysInfo::kernelType() + " " + QSysInfo::kernelVersion();
getTotalMemory();
QDBusInterface *memoryDbus = new QDBusInterface("com.control.center.qt.systemdbus",
"/",
"com.control.center.interface",
QDBusConnection::systemBus(), this);
if (memoryDbus->isValid()) {
QDBusReply<QString> result = memoryDbus->call("getMemory");
mUkccDbus = new QDBusInterface("com.control.center.qt.systemdbus",
"/",
"com.control.center.interface",
QDBusConnection::systemBus(), this);
if (mUkccDbus->isValid()) {
QDBusReply<QString> result = mUkccDbus->call("getMemory");
qDebug()<<"memory :"<<result;
if (result != "0") {
memorySize.clear();
@ -795,11 +809,16 @@ void About::setupDiskCompenet()
diskResult.replace(QRegExp("[\\s]+"), " ");
diskInfo = diskResult.split(" ");
if (diskInfo.count() >= 6 && diskInfo.at(5) == "disk" && (!diskInfo.at(0).contains("fd")) &&
if (diskInfo.count() >= 6 && (!diskInfo.at(0).contains("fd")) &&
(diskInfo.at(2) !="1")) { //过滤掉可移动硬盘
QStringList totalSize;
totalSize.append(diskInfo.at(3));
disk2.insert(diskInfo.at(0),totalSize); //硬盘信息分类存储,用以兼容多硬盘电脑
if (diskInfo.at(5).contains("part"))
mDiskParts.append(diskInfo.at(0));
if (diskInfo.at(5) == "disk") {
QStringList totalSize;
totalSize.append(diskInfo.at(3));
disk2.insert(diskInfo.at(0),totalSize); //硬盘信息分类存储,用以兼容多硬盘电脑
}
}
}
QProcess process_2;
@ -826,7 +845,8 @@ void About::setupDiskCompenet()
iter.value().append(diskAvailable);
availSize = 0;
}
if (mDiskFrame->isHidden())
return;
int count = 0;
for(iter=disk2.begin();iter!=disk2.end();iter++){
if (disk2.size() == 1) {
@ -1189,7 +1209,7 @@ bool About::eventFilter(QObject *obj, QEvent *event)
return QObject::eventFilter(obj, event);
}
void About::fromOsRelease()
void About::fromOsRelseae()
{
QString filePath = "/etc/os-release";
QFile file(filePath);
@ -1206,13 +1226,10 @@ void About::fromOsRelease()
}
}
}
if (pos == -1) {
if (pos == -1)
mVersionNumberFrame->hide();
mPatchVersionFrame->hide();
}
} else {
mVersionNumberFrame->hide();
mPatchVersionFrame->hide();
}
}
@ -1326,6 +1343,85 @@ void About::getTotalMemory()
mMemAvaliable = QString("%1%2%3%4%5").arg("(").arg(QString::number(memAvaliable, 'f', 1)).arg("GB").arg(tr("avaliable")).arg(")");
}
void About::setupSysInstallComponent()
{
if (mInstallDateFrame->isHidden())
return;
for (QString part : mDiskParts) {
part = part.mid(2);
if (mUkccDbus->isValid()) {
QDBusReply<QString> result = mUkccDbus->call("getSysInstallTime", part);
if (result != "") {
QStringList list = QString(result).split(" ");
if (list.count() >= 5) {
QString date = list.at(2);
date = date.toInt() < 10 ? QString("0%1").arg(date) : date;
mInstallDateLabel_2->setText(QString("%1-%2-%3").arg(list.at(4)).arg(QString::number(getMonth(list.at(1)))).arg(date));
return;
}
}
}
}
mInstallDateFrame->hide();
}
void About::setupUpgradeComponent()
{
if (mUpgradeDateFrame->isHidden())
return;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/var/cache/kylin-system-updater/kylin-system-updater.db");
if (!db.open()) {
perror("kylin-system-updater.db open error");
mUpgradeDateFrame->hide();
return;
}
//载入数据库数据
QString date;
QSqlQuery query(db);
query.exec("SELECT * FROM updateinfos where appname=\"kylin-update-desktop-system\"");
while(query.next()){
QSqlRecord rec = query.record();
int snamecol = rec.indexOf("appname");
QString value = query.value(snamecol).toString();
if (value == "kylin-update-manager") {
snamecol = rec.indexOf("date");
date = query.value(snamecol).toString().split(" ").at(0);
mUpgradeDateLabel_2->setText(date);
db.close();
return;
}
}
db.close();
mUpgradeDateFrame->hide();
return ;
}
void About::securityControl()
{
mInstallDateFrame->hide();
mUpgradeDateFrame->hide();
// 安全管控 安装时间及系统更新时间的显示与隐藏
QVariantMap ModuleMap = Common::getModuleHideStatus();
QString moduleSettings = ModuleMap.value(name().toLower() + "Settings").toString();
QStringList setItems = moduleSettings.split(",");
foreach (QString setItem, setItems) {
QStringList item = setItem.split(":");
qDebug() << "set item Name: " << item.at(0);
if (item.at(0) == "installedDateFrame") {
mInstallDateFrame->setVisible(item.at(1) == "true");
}
if (item.at(0) == "upgradeDateFrame") {
mUpgradeDateFrame->setVisible(item.at(1) == "true");
}
}
}
void About::compareTime(QString date)
{
QString s1(getntpdate());

View File

@ -102,6 +102,9 @@ private:
void setupSystemVersion();
void setHostNameCompenet();
void setPrivacyCompent();
void setupSysInstallComponent();
void setupUpgradeComponent();
void securityControl();
void showExtend(QString dateres);
int ntpGethostbyname(char *servname); //获取 IP 地址列表
static void *threadGetAddrInfo(void *arg);
@ -111,7 +114,7 @@ private:
void reboot();
void setLabelText(QLabel *label,QString text);
bool eventFilter(QObject *obj, QEvent *event);
void fromOsRelease();
void fromOsRelseae();
QStringList getUserDefaultLanguage();
QStringList readFile(QString filepath);
@ -139,6 +142,8 @@ private:
QFrame *mVersionNumFrame;
QFrame *mVersionNumberFrame;
QFrame *mPatchVersionFrame;
QFrame *mInstallDateFrame;
QFrame *mUpgradeDateFrame;
QFrame *mInterVersionFrame;
QFrame *mHostNameFrame;
QFrame *mKernelFrame;
@ -157,6 +162,8 @@ private:
FixLabel *mVersionNumLabel_1;
FixLabel *mVersionNumberLabel_1;
FixLabel *mPatchVersionLabel_1;
FixLabel *mInstallDateLabel_1;
FixLabel *mUpgradeDateLabel_1;
FixLabel *mInterVersionLabel_1;
FixLabel *mHostNameLabel_1;
FixLabel *mKernelLabel_1;
@ -169,6 +176,8 @@ private:
LightLabel *mVersionNumLabel_2;
LightLabel *mVersionNumberLabel_2;
LightLabel *mPatchVersionLabel_2;
LightLabel *mInstallDateLabel_2;
LightLabel *mUpgradeDateLabel_2;
LightLabel *mInterVersionLabel_2;
LightLabel *mHostNameLabel_2;
LightLabel *mHostNameLabel_3;
@ -219,10 +228,12 @@ private:
QString dateRes = "";
QStringList mNtphostName;
QStringList mDiskParts;
QPixmap mThemePixmap;
bool activestatus = true;
QDBusInterface *mUkccDbus = nullptr;
Q_SIGNALS:
void resize();
void changeTheme();

View File

@ -3,14 +3,15 @@ include($$PROJECT_ROOTDIR/libukcc/widgets/Label/label.pri)
include($$PROJECT_ROOTDIR/libukcc/interface.pri)
QT += widgets dbus KI18n KCoreAddons \
widgets dbus concurrent svg
widgets dbus concurrent svg sql
TEMPLATE = lib
CONFIG += plugin \
link_pkgconfig
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kysdk-sysinfo
kysdk-sysinfo \
kysdk-diagnostics \
TARGET = $$qtLibraryTarget(about)

View File

@ -27,7 +27,8 @@ LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets \
kysdk-sysinfo \
kscreen2
kscreen2 \
kysdk-diagnostics \
SOURCES += \
brightnessFrame.cpp \

View File

@ -8,11 +8,12 @@
#include <QComboBox>
#include <QFile>
#include <QStyledItemDelegate>
#include <QDBusInterface>
#include <KF5/KScreen/kscreen/output.h>
#include <kysdk/kysdk-system/libkysysinfo.h>
static bool sizeLessThan(const QSize &sizeA, const QSize &sizeB)
{
return sizeA.width() * sizeA.height() < sizeB.width() * sizeB.height();
@ -30,6 +31,7 @@ ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *pa
connect(output.data(), &KScreen::Output::modesChanged,
this, &ResolutionSlider::init);
init();
removeSolution();
}
ResolutionSlider::~ResolutionSlider()
@ -88,6 +90,20 @@ void ResolutionSlider::init()
}
}
void ResolutionSlider::removeSolution()
{
QString plat = QString(QLatin1String(kdk_system_get_hostVirtType()));
if (plat == "qemu" || plat == "kvm") {
for (int i = 0; i < mComboBox->count(); i++) {
int index = mComboBox->currentIndex();
if (index != i) {
mComboBox->removeItem(i);
i = 0;
}
}
}
}
QSize ResolutionSlider::currentResolution() const
{
if (mModes.isEmpty()) {

View File

@ -32,6 +32,7 @@ public Q_SLOTS:
private:
void init();
void removeSolution();
private:
KScreen::OutputPtr mOutput;

View File

@ -130,20 +130,11 @@ Widget::Widget(QWidget *parent) :
initUiComponent();
initNightStatus();
#if QT_VERSION <= QT_VERSION_CHECK(5, 12, 0)
mNightModeLabel->hide();
mNightModeFrame->setVisible(false);
#else
mNightModeFrame->setVisible(this->mRedshiftIsValid);
mNightModeLabel->setVisible(this->mRedshiftIsValid);
#endif
initConnection();
loadQml();
if (Common::isOpenkylin()) {
scaleFrame->hide();
}
hideComponent();
mScreenScale = scaleGSettings->get(SCALE_KEY).toDouble();
}
@ -187,7 +178,9 @@ void Widget::setConfig(const KScreen::ConfigPtr &config)
}
mConfig = config;
mPrevConfig = config->clone();
if (mMultiScreenFrame) {
mMultiScreenFrame->setVisible(mConfig->connectedOutputs().size() > 1);
}
updateMultiScreen();
KScreen::ConfigMonitor::instance()->addConfig(mConfig);
@ -609,7 +602,8 @@ void Widget::initComponent()
multiScreenlay->addWidget(mMultiScreenLabel);
multiScreenlay->addWidget(mMultiScreenCombox);
mMultiScreenFrame->setLayout(multiScreenlay);
mMultiScreenFrame->setLayout(multiScreenlay);
mMultiScreenFrame->setVisible(false);
if (m_StatusDbus->isValid()) {
QDBusReply<bool> is_tabletmode = m_StatusDbus->call("get_current_tabletmode");
@ -647,10 +641,9 @@ void Widget::initDbusComponent()
void Widget::setHideModuleInfo()
{
mCPU = getCpuInfo();
// if (!mCPU.startsWith(kCpu, Qt::CaseInsensitive)) { //fix bug#78013
ui->quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
ui->quickWidget->setClearColor(Qt::transparent);
// }
//fix bug#78013
ui->quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
ui->quickWidget->setClearColor(Qt::transparent);
}
void Widget::writeScale(double scale)
@ -1124,10 +1117,19 @@ void Widget::addBrightnessFrame(QString name, bool openFlag, QString edidHash)
frame = new BrightnessFrame(name, true);
} else if(!mIsBattery) {
frame = new BrightnessFrame(name, false, edidHash);
for (QMap<QString, QString>::const_iterator it = I2CbusMap.constBegin(); it != I2CbusMap.constEnd(); ++it) {
if (name.contains(it.key(), Qt::CaseInsensitive)) {
frame->setI2cbus(it.value());
break;
if (edidI2CbusMap.isEmpty()) {
for (QMap<QString, QString>::const_iterator it = I2CbusMap.constBegin(); it != I2CbusMap.constEnd(); ++it) {
if (name.contains(it.key(), Qt::CaseInsensitive)) {
frame->setI2cbus(it.value());
break;
}
}
} else {
for (QMap<QString, QString>::const_iterator it = edidI2CbusMap.constBegin(); it != edidI2CbusMap.constEnd(); ++it) {
if (edidHash == it.key()) {
frame->setI2cbus(it.value());
break;
}
}
}
}
@ -1176,8 +1178,8 @@ void Widget::outputAdded(const KScreen::OutputPtr &output, bool connectChanged)
hash.reset();
hash.addData(reinterpret_cast<const char *>(edidData), 128);
QString edidHash = QString::fromLatin1(hash.result().toHex());
QString name = Utils::outputName(output);
qInfo() << "output:" << name << "edidHash:" << edidHash;
addBrightnessFrame(name, output->isEnabled(), edidHash);
connectedOutputNum++;
checkSpliceFeasibility();
@ -2117,13 +2119,22 @@ void Widget::initUiComponent()
QDBusConnection::sessionBus()));
}
void Widget::hideComponent()
{
if (Common::isOpenkylin()) {
scaleFrame->hide();
}
mNightModeFrame->setVisible(this->mRedshiftIsValid);
mNightModeLabel->setVisible(this->mRedshiftIsValid);
}
void Widget::initNightStatus()
{
QDBusInterface colorIft("org.ukui.KWin",
"/ColorCorrect",
"org.freedesktop.DBus.Properties",
QDBusConnection::sessionBus());
if (colorIft.isValid() && !mIsWayland) {
if (colorIft.isValid() && !Common::isWayland()) {
this->mRedshiftIsValid = true;
QDBusReply<QVariant> reply = colorIft.call("Get", "org.ukui.kwin.ColorCorrect", "available");
if (!reply.value().toBool()) {
@ -2500,56 +2511,125 @@ void Widget::getAllI2Cbus()
{
I2CbusMap.clear();
//暂时仅D2000机器直接使用i2c
if (!(Common::getCpuInfo().contains("D2000", Qt::CaseInsensitive))) {
return;
if (!(Common::getCpuInfo().contains("D2000", Qt::CaseInsensitive))) {
return;
}
getEdidI2Cbus();
if (edidI2CbusMap.isEmpty()) {
QMap<QString, QString> msg;
QString cmd = "find /sys/class/drm/card0-*/*/ -name '*i2c-[0-9]*'";
QProcess process;
process.start("bash", QStringList() <<"-c"<<cmd);
process.waitForFinished();
QString strResult = process.readAllStandardOutput();
QStringList resultList = strResult.split("\n"); //所有结果
qInfo()<<"read i2c process result = "<<resultList;
for (int i = 0; i < resultList.size(); i++) {
QStringList i2cList = resultList.at(i).split("/"); //切割每一行结果
if (i2cList.size() >= 5) {
if (!msg.keys().contains(i2cList.at(4))) {
//当不存在时就添加
msg.insert(i2cList.at(4), resultList.at(i));
} else {
//已经存在,但是内容更少时也重新替换,drm中文件是嵌套的可能存在包含关系故做此处理
if (msg[i2cList.at(4)].size() > resultList.at(i).size()) {
msg[i2cList.at(4)] = resultList.at(i);
}
}
}
}
QMap<QString, QString>::const_iterator it;
for (it = msg.constBegin(); it != msg.constEnd(); ++it) {
qDebug()<<" ----------MAP-MSG--------- "<<it.key()<<" "<<it.value();
//显示器名只取中间的(HDMI\VGA...)因为后面的内容kscreen和内核提供的不一定一致
//因此当有多个HDMI接口时此方式并不适用
QString name = it.key().split("-").at(1);
QStringList i2cList = it.value().split("/");
QString i2cStr = i2cList.at(i2cList.size() - 1);
if (!i2cStr.contains("i2c-",Qt::CaseInsensitive)) {
i2cStr = i2cList.at(i2cList.size() - 2);
}
QString busNum = i2cStr.split("-").at(1);
if (QString::number(busNum.toInt()) == busNum) {
if (I2CbusMap.keys().contains(name)) {
qDebug()<<"Unable to get the correct bus number from the kernel ... "<<name;
I2CbusMap.clear(); //如果出现了一样的表明有重复的接口舍弃使用内核提供的bus号
return;
}
qInfo()<<" i2c-name = "<<name<<" *** "<<"i2c-bus="<<busNum;
I2CbusMap.insert(name, busNum);
}
}
}
QMap<QString, QString> msg;
QString cmd = "find /sys/class/drm/card0-*/*/ -name '*i2c-[0-9]*'";
return;
}
// 获取所有显卡的节点信息
void Widget::getEdidI2Cbus()
{
edidI2CbusMap.clear();
QString cmd = "find /sys/class/drm/card*/*/ -name status";
QProcess process;
process.start("bash", QStringList() <<"-c"<<cmd);
process.waitForFinished();
QString strResult = process.readAllStandardOutput();
QStringList resultList = strResult.split("\n"); //所有结果
resultList.removeOne("");
qDebug()<<"read i2c process result = "<<resultList;
for (int i = 0; i < resultList.size(); i++) {
QStringList i2cList = resultList.at(i).split("/"); //切割每一行结果
if (i2cList.size() >= 5) {
if (!msg.keys().contains(i2cList.at(4))) {
//当不存在时就添加
msg.insert(i2cList.at(4), resultList.at(i));
} else {
//已经存在,但是内容更少时也重新替换,drm中文件是嵌套的可能存在包含关系故做此处理
if (msg[i2cList.at(4)].size() > resultList.at(i).size()) {
msg[i2cList.at(4)] = resultList.at(i);
QMap<QString, QString> screenMap;
for (QString s : resultList) {
s.replace("/status", "");
QStringList sl = s.split("/");
if (sl.size() >= 1) {
QString screenCardName = sl.at(sl.size() - 1);
if (!screenMap.keys().contains(screenCardName)) {
screenMap.insert(screenCardName, s);
}
}
}
qInfo()<<"screenMap:"<<screenMap;
for (QMap<QString, QString>::const_iterator it = screenMap.constBegin(); it != screenMap.constEnd(); ++it) {
QString fileName = it.value() + QString("/status");
QFile statusFile(fileName);
if (statusFile.exists() && statusFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString str(statusFile.readAll());
str.replace("\n", "");
statusFile.close();
// 是已经连接的显示器
if (str == "connected") {
qInfo() << "connected screen:" << it.value();
fileName = it.value() + QString("/edid");
QFile edidFile(fileName);
if (edidFile.exists() && edidFile.open(QIODevice::ReadOnly)) {
QByteArray edidByteArray = edidFile.readAll();
edidFile.close();
QCryptographicHash hash(QCryptographicHash::Md5);
hash.reset();
const quint8 *edidData = reinterpret_cast<const quint8 *>(edidByteArray.constData());
hash.addData(reinterpret_cast<const char *>(edidData), 128);
QString edidHash = QString::fromLatin1(hash.result().toHex());
QString cmdStr = QString("find ") + it.value() + QString("/*/ ") + QString("-name '*i2c-[0-9]*'");
process.start("bash", QStringList() <<"-c"<<cmdStr);
process.waitForFinished();
strResult = process.readAllStandardOutput();
// 获取第一行,理论上只有一行
QString i2cStr = strResult.split("\n").at(0);
QStringList i2cStrList = i2cStr.split("/");
QStringList busStrList = i2cStrList.at(i2cStrList.size() - 1).split("-");
if (busStrList.size() > 1) {
QString busNum = busStrList.at(busStrList.size() - 1);
if (QString::number(busNum.toInt()) == busNum && !edidI2CbusMap.keys().contains(edidHash)) {
edidI2CbusMap.insert(edidHash, busNum);
}
}
}
}
}
}
QMap<QString, QString>::const_iterator it;
for (it = msg.constBegin(); it != msg.constEnd(); ++it) {
qDebug()<<" ----------MAP-MSG--------- "<<it.key()<<" "<<it.value();
//显示器名只取中间的(HDMI\VGA...)因为后面的内容kscreen和内核提供的不一定一致
//因此当有多个HDMI接口时此方式并不适用
QString name = it.key().split("-").at(1);
QStringList i2cList = it.value().split("/");
QString i2cStr = i2cList.at(i2cList.size() - 1);
if (!i2cStr.contains("i2c-",Qt::CaseInsensitive)) {
i2cStr = i2cList.at(i2cList.size() - 2);
}
QString busNum = i2cStr.split("-").at(1);
if (QString::number(busNum.toInt()) == busNum) {
if (I2CbusMap.keys().contains(name)) {
qDebug()<<"Unable to get the correct bus number from the kernel ... "<<name;
I2CbusMap.clear(); //如果出现了一样的表明有重复的接口舍弃使用内核提供的bus号
return;
}
qDebug()<<" i2c-name = "<<name<<" *** "<<"i2c-bus="<<busNum;
I2CbusMap.insert(name, busNum);
}
}
return;
qInfo() << "edidI2CbusMap:"<<edidI2CbusMap;
}
bool Widget::checkSpliceFeasibility()

View File

@ -108,6 +108,7 @@ public:
int scaleToSlider(const float value);
void initUiComponent();
void hideComponent();
void addBrightnessFrame(QString name, bool openFlag, QString edidHash);
void showBrightnessFrame(const int flag = 0);
@ -116,6 +117,7 @@ public:
void changescale(QSize size = QSize());
void getAllI2Cbus();
void getEdidI2Cbus();
void initUi();
protected:
@ -323,6 +325,7 @@ private:
int mKdsStatus = INT_MIN;
QMap<QString, QString> I2CbusMap;
QMap<QString, QString> edidI2CbusMap;
SpliceDialog *spliceDialog;
int connectedOutputNum;
QLabel *spliceMethodLabel = nullptr;

View File

@ -421,7 +421,6 @@ void Notice::initListUI(QDir dir, QString path)
ukToolButton *setBtn = new ukToolButton(baseWidget);
setBtn->setProperty("useButtonPalette", true);
setBtn->setPopupMode(QToolButton::InstantPopup);
setBtn->setFixedWidth(36);
setBtn->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic"));
NoticeMenu *menu = new NoticeMenu(setBtn);
setBtn->setMenu(menu);

View File

@ -19,7 +19,8 @@ CONFIG += link_pkgconfig \
C++11
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
# Qt5X
INCLUDEPATH += \

View File

@ -2,6 +2,8 @@
#include "realizenotice.h"
#include <QDebug>
#include <QVBoxLayout>
#include <QDesktopWidget>
#include <QApplication>
#include "fixlabel.h"
NoticeMenu::NoticeMenu(QWidget *parent) :
@ -137,11 +139,17 @@ void NoticeMenu::setConnect()
void NoticeMenu::showEvent(QShowEvent *event)
{
int menuXPos = this->pos().x();
int menuWidth = this->size().width()-4;
int buttonWidth = 36;
QPoint pos = QPoint(menuXPos - menuWidth + buttonWidth,
this->pos().y());
this->move(pos);
int menuXpos = this->pos().x();
int menuYpos = this->pos().y();
QRect deskRect = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(QCursor::pos()));
int deskRectWidth = deskRect.width();
int deskRectHeight = deskRect.height();
if (menuXpos + this->width() > deskRectWidth)
menuXpos = deskRectWidth - this->width();
if (menuYpos + this->height() > deskRectHeight)
menuYpos = menuYpos - this->height() - this->parentWidget()->height();
this->move(menuXpos, menuYpos);
QMenu::showEvent(event);
}

View File

@ -10,7 +10,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets dbus
TEMPLATE = lib
CONFIG += plugin link_pkgconfig
PKGCONFIG += gsettings-qt \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
TARGET = $$qtLibraryTarget(vino)
DESTDIR = ../..

View File

@ -102,7 +102,9 @@ QWidget *Area::pluginUi()
} else {
// 有可能修改了日期,因此重新加载日期格式
initDateFormat();
if (areaInterface->isValid()) {
initDateFormat();
}
}
return areaWidget;
}
@ -293,7 +295,7 @@ void Area::initAddLanguage()
if (!areaWidget->addbutton() || !areaWidget->languageDialog()) {
return;
}
QStringList languageList = areaInterface->property("languageList" ).toStringList();
const QStringList languageList = areaInterface->property("languageList" ).toStringList();
for (QString s : languageList) {
areaWidget->languageDialog()->addRow(showLanguageName(s));
}
@ -301,7 +303,7 @@ void Area::initAddLanguage()
connect(areaWidget->addbutton(), &AddButton::clicked, this, [=]() {
areaWidget->languageDialog()->show();
});
connect(areaWidget->languageDialog(), &AddLanguageDialog::addShowLanguage, this, [=, languageList](QStringList selectedLanguageList) {
connect(areaWidget->languageDialog(), &AddLanguageDialog::addShowLanguage, this, [=](QStringList selectedLanguageList) {
for (QString selectedLanguage : selectedLanguageList) {
for (int i = 0; i < languageList.size(); ++i) {
if (selectedLanguage == showLanguageName(languageList.at(i))) {

View File

@ -31,7 +31,8 @@ CONFIG += link_pkgconfig \
C++11
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -92,7 +92,6 @@ QToolButton* LanguageFrame::createToolBtn()
btn->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic"));
btn->setProperty("useButtonPalette", true);
btn->setFixedWidth(36);
return btn;
}

View File

@ -38,7 +38,8 @@ LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt -lpolkit-qt5-core-1
PKGCONFIG += gio-2.0 \
gio-unix-2.0 \
gsettings-qt \
kysdk-qtwidgets
kysdk-qtwidgets \
kysdk-diagnostics \
#DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -280,12 +280,23 @@ int SysdbusRegister::_changeOtherUserPasswd(QString username, QString pwd){
std::string str1 = username.toStdString();
const char * user_name = str1.c_str();
std::string str2 = pwd.toStdString();
QString output;
QString newPwd = pwd;
int i = 0;
for (i = 0; i < newPwd.count(); i++){
if (!(int(newPwd.at(i).toLatin1() >= 48 && int(newPwd.at(i).toLatin1()) <= 57) ||
int(newPwd.at(i).toLatin1() >= 65 && int(newPwd.at(i).toLatin1()) <= 90) ||
int(newPwd.at(i).toLatin1() >= 97 && int(newPwd.at(i).toLatin1()) <= 122))){
newPwd = newPwd.insert(i, QString("\\"));
i++;
}
}
std::string str2 = newPwd.toStdString();
const char * passwd = str2.c_str();
QString output;
char * cmd = g_strdup_printf("/usr/bin/changeotheruserpwd '%s' '%s'", user_name, passwd);
char * cmd = g_strdup_printf("/usr/bin/changeotheruserpwd '%s' %s", user_name, passwd);
FILE *stream;
char buf[256];
@ -312,9 +323,9 @@ int SysdbusRegister::changeOtherUserPasswd(QString username, QString pwd){
return 0;
}
_changeOtherUserPasswd(username, pwd);
int _changeRet = _changeOtherUserPasswd(username, pwd);
return 1;
return _changeRet;
}
@ -1056,14 +1067,15 @@ bool SysdbusRegister::setGrupPasswd(QString username, QString passwd, bool statu
QString cmd;
if(true == status){
cmd = QString("grub-password -u %1 %2 | update-grub").arg(username).arg(passwd);
cmd = QString("grub-password -u %1 %2 && update-grub").arg(username).arg(passwd);
} else{
cmd = QString("grub-password -d | update-grub");
cmd = QString("grub-password -d && update-grub");
}
qDebug() << "cmd= " << cmd;
int ret = system(cmd.toLatin1().data());
if (ret != 0) {
qDebug() << "grub execute failed!";
qDebug() << "grub-password execute failed!" << ret;
return false;
}
@ -1093,3 +1105,20 @@ bool SysdbusRegister::getGrupPasswdStatus()
return true;
}
QString SysdbusRegister::getSysInstallTime(const QString &part)
{
QProcess process;
QString cmd = QString("tune2fs -l /dev/%1 |grep create").arg(part);
process.start("bash" , QStringList() << "-c" << cmd);
process.waitForFinished();
QString info = process.readAllStandardOutput();
if (!info.isEmpty()) {
if (info.contains("Filesystem created")) {
info.replace(QRegExp("[\\s]+"), " ");
return info.mid(20);
}
}
return QString();
}

View File

@ -170,6 +170,9 @@ public slots:
// 获取 grub 密码是否开启
Q_SCRIPTABLE bool getGrupPasswdStatus();
// 获取系统安装时间
Q_SCRIPTABLE QString getSysInstallTime(const QString &part);
};
#endif // SYSDBUSREGISTER_H

View File

@ -6,7 +6,17 @@
#include "ukccsessionserver.h"
#include "session_adaptor.h"
#include "screenStruct.h"
#include "./area/areainterface.h"
#include "plugins/keyboard/keyboardinterface.h"
#include "plugins/mouse/mouseinterface.h"
#include "plugins/area/areainterface.h"
void registerPlugins(const QString &path, QObject *object, QDBusConnection &connection) {
if (!connection.registerObject(path, object, QDBusConnection::ExportAllSlots |
QDBusConnection::ExportAllProperties |
QDBusConnection::ExportAllSignals))
qCritical() << QString("QDbus register object %1 failed reason:").arg(path) << connection.lastError();
}
int main(int argc, char *argv[])
{
@ -15,15 +25,10 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("ukcc-session-service");
qRegisterMetaType<ScreenConfig>("ScreenConfig");
qDBusRegisterMetaType<ScreenConfig>();
QTranslator translator;
translator.load("/usr/share/ukui-control-center/shell/res/i18n/" + QLocale::system().name());
app.installTranslator(&translator);
ukccSessionServer service;
new InterfaceAdaptor(&service);
AreaInterface *areaInterface = new AreaInterface();
QDBusConnection sessionBus = QDBusConnection::sessionBus();
if (!sessionBus.registerService("org.ukui.ukcc.session")) {
qCritical() << "QDbus register service failed reason:" << sessionBus.lastError();
@ -35,12 +40,13 @@ int main(int argc, char *argv[])
exit(2);
}
if (!sessionBus.registerObject("/Area", areaInterface, QDBusConnection::ExportAllSlots |
QDBusConnection::ExportAllProperties |
QDBusConnection::ExportAllSignals)) {
qCritical() << "QDbus register object /Area failed reason:" << sessionBus.lastError();
exit(3);
}
std::map <QString, QObject*> plugins;
plugins["/Area"] = new AreaInterface;
plugins["/KeyBoard"] = new KeyBoardInterface;
plugins["/Mouse"] = new MouseInterface;
for (std::map<QString, QObject*>::value_type plugin : plugins)
registerPlugins(plugin.first, plugin.second, sessionBus);
return app.exec();
}

View File

@ -0,0 +1,247 @@
#include "areainterface.h"
#include <unistd.h>
#include <QDBusConnection>
AreaInterface::AreaInterface()
{
ukccPanelGsettings = UniversalInterface::self()->ukccPanelGsettings();
accountInterface = UniversalInterface::self()->accountUserDbus();
fcitxInterface = UniversalInterface::self()->fcitxInputMethodDbus();
styleGsettings = UniversalInterface::self()->ukuiStyleGsettings();
initConnect();
}
AreaInterface::~AreaInterface()
{
}
void AreaInterface::initConnect()
{
connect(ukccPanelGsettings, &QGSettings::changed, this, [=](QString key) {
if (key == CALENDAR_KEY) {
Q_EMIT changed("calendar");
} else if (key == FIRST_DAY_KEY) {
Q_EMIT changed("firstDay");
} else if (key == DATE_FORMATE_KEY) {
Q_EMIT changed("dateFormat");
} else if (key == TIME_FORMAT_KEY) {
Q_EMIT changed("timeFormat");
} else if (key == SHOW_LANGUAGE_KEY) {
Q_EMIT changed("showLanguageList");
}
});
connect(styleGsettings, &QGSettings::changed, this, [=](QString key) {
if (key == "iconThemeName") {
Q_EMIT changed("iconThemeName");
}
});
}
const QString AreaInterface::gsettingGet(const QString &key) const
{
if (ukccPanelGsettings->keys().contains(key)) {
return ukccPanelGsettings->get(key).toString();
} else {
qCritical() << "ukccPanelGsettings not contains the key: " << key;
return "";
}
}
void AreaInterface::gsettingSet(const QString &key, const QString &value)
{
if (ukccPanelGsettings->keys().contains(key)) {
ukccPanelGsettings->set(key, value);
} else {
qCritical() << "ukccPanelGsettings not contains the key: " << key;
}
}
const QStringList AreaInterface::getFormatCountryList()
{
return QStringList() << QString("en_US.UTF-8") << QString("zh_CN.UTF-8") << QString("bo_CN.UTF-8");
}
const QStringList AreaInterface::getCalendarList()
{
QStringList list = {};
list.append(QString("solarlunar"));
QString locale = QLocale::system().name();
if ("zh_CN" == locale) {
list.append(QString("lunar"));
}
return list;
}
const QStringList AreaInterface::getFirstDayList()
{
return QStringList() << QString("monday") << QString("sunday");
}
const QStringList AreaInterface::getDateFormatList()
{
return QStringList() << QString("cn") << QString("en");
}
const QStringList AreaInterface::getTimeFormatList()
{
return QStringList() << QString("12") << QString("24");
}
const QStringList AreaInterface::getShowLanguageList()
{
if (ukccPanelGsettings->keys().contains(SHOW_LANGUAGE_KEY)) {
return ukccPanelGsettings->get(SHOW_LANGUAGE_KEY).toStringList();;
} else {
qCritical() << "ukccPanelGsettings not contains the key: " << SHOW_LANGUAGE_KEY;
}
return QStringList();
}
const QStringList AreaInterface::getLanguageList()
{
return QStringList() << QString("zh_CN") << QString("en") << QString("bo_CN");
}
const QString AreaInterface::getFormatCountry()
{
return accountInterface->property("FormatsLocale").toString();;
}
const QString AreaInterface::getCalendar()
{
return gsettingGet(CALENDAR_KEY);;
}
const QString AreaInterface::getFirstDay()
{
return gsettingGet(FIRST_DAY_KEY);;
}
const QString AreaInterface::getDateFormat()
{
return gsettingGet(DATE_FORMATE_KEY);;
}
const QString AreaInterface::getTimeFormat()
{
return gsettingGet(TIME_FORMAT_KEY);;
}
const QString AreaInterface::getLanguage()
{
return accountInterface->property("Language").toString();;
}
void AreaInterface::setFormatCountry(const QString &formatCountry)
{
if (getFormatCountryList().contains(formatCountry)) {
accountInterface->call("SetFormatsLocale", formatCountry);
Q_EMIT changed("formatCountry");
}
}
// Gsetting设置会触发changed(key)信号因此无需Q_EMIT changed避免重复触发信号。
void AreaInterface::setCalendar(const QString &calendar)
{
if (getCalendarList().contains(calendar)) {
gsettingSet(CALENDAR_KEY, calendar);
}
}
void AreaInterface::setFirstDay(const QString &firstDay)
{
if (getFirstDayList().contains(firstDay)) {
gsettingSet(FIRST_DAY_KEY, firstDay);
};
}
void AreaInterface::setDateFormat(const QString &dateFormat)
{
if (getDateFormatList().contains(dateFormat)) {
gsettingSet(DATE_FORMATE_KEY, dateFormat);
}
}
void AreaInterface::setTimeFormat(const QString &timeFormat)
{
if (getTimeFormatList().contains(timeFormat)) {
gsettingSet(TIME_FORMAT_KEY, timeFormat);
}
}
void AreaInterface::setShowLanguageList(const QStringList &languageList)
{
bool flag = true;
for (QString s: languageList) {
if (!getLanguageList().contains(s)) {
flag = false;
break;
}
}
if (flag) {
if (ukccPanelGsettings->keys().contains(SHOW_LANGUAGE_KEY)) {
ukccPanelGsettings->set(SHOW_LANGUAGE_KEY, languageList);
} else {
qCritical() << "ukccPanelGsettings not contains the key: " << SHOW_LANGUAGE_KEY;
}
}
}
void AreaInterface::setLanguage(const QString &languageCode)
{
if (getLanguageList().contains(languageCode)) {
accountInterface->call("SetLanguage", languageCode);
Q_EMIT changed("language");
}
}
void AreaInterface::reloadInputMethodConfig()
{
fcitxInterface->call("ReloadConfig");
}
void AreaInterface::changeInputMethod(const QString &inputMethod, const bool &add)
{
QString fileTextString;
QFile configFile(FCITX_CONFIG_FILE);
if (configFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
//把文件所有信息读出来
QTextStream stream(&configFile);
fileTextString = stream.readAll();
if (!fileTextString.contains(inputMethod)) {
return ;
}
QString addString = inputMethod + ":True";
QString removeString = inputMethod + ":False";
if (add) {
fileTextString.replace(removeString, addString);
} else {
fileTextString.replace(addString, removeString);
}
stream << fileTextString;
configFile.close();
reloadInputMethodConfig();
}
}
bool AreaInterface::isAddedInputMethod(const QString &inputMethod)
{
QString fileTextString;
QFile mFile(FCITX_CONFIG_FILE);
if (mFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&mFile);
fileTextString = stream.readAll();
QString string = inputMethod + ":True";
if (fileTextString.contains(string)) {
return true;
} else {
return false;
}
}
qCritical()<<"open "<<FCITX_CONFIG_FILE<<" error.";
return false;
}

View File

@ -0,0 +1,98 @@
#ifndef AREAINTERFACE_H
#define AREAINTERFACE_H
#include <QObject>
#include <QtDBus>
#include "universalinterface.h"
class AreaInterface : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.ukui.ukcc.session.Area")
Q_PROPERTY(QStringList formatCountryList READ getFormatCountryList)
Q_PROPERTY(QStringList calendarList READ getCalendarList)
Q_PROPERTY(QStringList firstDayList READ getFirstDayList)
Q_PROPERTY(QStringList dateFormatList READ getDateFormatList)
Q_PROPERTY(QStringList timeFormatList READ getTimeFormatList)
Q_PROPERTY(QStringList languageList READ getLanguageList)
Q_PROPERTY(QStringList showLanguageList READ getShowLanguageList)
Q_PROPERTY(QString formatCountry READ getFormatCountry)
Q_PROPERTY(QString calendar READ getCalendar)
Q_PROPERTY(QString firstDay READ getFirstDay)
Q_PROPERTY(QString dateFormat READ getDateFormat)
Q_PROPERTY(QString timeFormat READ getTimeFormat)
Q_PROPERTY(QString language READ getLanguage)
public:
AreaInterface();
~AreaInterface();
void initConnect();
protected:
// 对属性的访问函数
const QStringList getFormatCountryList();
const QStringList getCalendarList();
const QStringList getFirstDayList();
const QStringList getDateFormatList();
const QStringList getTimeFormatList();
const QStringList getLanguageList();
const QStringList getShowLanguageList();
const QString getFormatCountry();
const QString getCalendar();
const QString getFirstDay();
const QString getDateFormat();
const QString getTimeFormat();
const QString getLanguage();
public Q_SLOTS:
/**
* @brief
*
* @param inputMethodName
* @param add /
*/
void changeInputMethod(const QString &inputMethod, const bool &add);
/**
* @brief
*
* @param inputMethodName
* @return bool
*/
bool isAddedInputMethod(const QString &inputMethod);
// 对属性的设置函数
void setFormatCountry(const QString &formatCountry);
void setCalendar(const QString &calendar);
void setFirstDay(const QString &firstDay);
void setDateFormat(const QString &dateFormat);
void setTimeFormat(const QString &timeFormat);
void setShowLanguageList(const QStringList &languageList);
void setLanguage(const QString &languageCode);
Q_SIGNALS:
void changed(QString keyName);
private:
void reloadInputMethodConfig();
// 设置和获取gsetting的string类型的键值
const QString gsettingGet(const QString &key) const;
void gsettingSet(const QString &key, const QString &value);
private:
const QString SHOW_LANGUAGE_KEY = QString("showlanguage");
const QString FCITX_CONFIG_FILE = QDir::homePath() + "/.config/fcitx/profile";
const QString CALENDAR_KEY = QString("calendar");
const QString FIRST_DAY_KEY = QString("firstday");
const QString DATE_FORMATE_KEY = QString("date");
const QString TIME_FORMAT_KEY = QString("hoursystem");
private:
QGSettings *ukccPanelGsettings = nullptr;
QDBusInterface *accountInterface = nullptr;
QDBusInterface *fcitxInterface = nullptr;
QGSettings *styleGsettings = nullptr;
};
#endif // AREAINTERFACE_H

View File

@ -0,0 +1,111 @@
#include "keyboardinterface.h"
#include <QDebug>
KeyBoardInterface::KeyBoardInterface()
{
keyboardGsettings = UniversalInterface::self()->ukuiKeyBoardGsettings();
ukccOsdGsettings = UniversalInterface::self()->ukccOsdGsettings();
initConnect();
}
KeyBoardInterface::~KeyBoardInterface()
{
}
void KeyBoardInterface::initConnect()
{
connect(keyboardGsettings, &QGSettings::changed, this, [=](QString key) {
if (key == KEYREPEAT_KEY) {
Q_EMIT changed("repeat");
} else if (key == DELAY_KEY) {
Q_EMIT changed("delay");
} else if (key == SPEED_KEY) {
Q_EMIT changed("rate");
}
});
connect(ukccOsdGsettings, &QGSettings::changed, this, [=](QString key) {
if (key == KEYTIPS_KEY) {
Q_EMIT changed("show-lock-tip");
}
});
}
const bool KeyBoardInterface::getKeyRepeat()
{
if (keyboardGsettings->keys().contains(KEYREPEAT_KEY)) {
return keyboardGsettings->get(KEYREPEAT_KEY).toBool();
} else {
qCritical() << "keyboardGsettings not contains the key: " << KEYREPEAT_KEY;
}
return bool();
}
const int KeyBoardInterface::getDelay()
{
if (keyboardGsettings->keys().contains(DELAY_KEY)) {
return keyboardGsettings->get(DELAY_KEY).toInt();
} else {
qCritical() << "keyboardGsettings not contains the key: " << DELAY_KEY;
}
return int();
}
const int KeyBoardInterface::getRate()
{
if (keyboardGsettings->keys().contains(SPEED_KEY)) {
return keyboardGsettings->get(SPEED_KEY).toInt();
} else {
qCritical() << "keyboardGsettings not contains the key: " << SPEED_KEY;
}
return int();
}
const bool KeyBoardInterface::getShowLockTip()
{
if (ukccOsdGsettings->keys().contains(KEYTIPS_KEY)) {
return ukccOsdGsettings->get("show-lock-tip").toBool();
} else {
qCritical() << "ukccOsdGsettings not contains the key: " << KEYTIPS_KEY;
}
return bool();
}
void KeyBoardInterface::setKeyRepeat(const bool checked)
{
if (keyboardGsettings->keys().contains(KEYREPEAT_KEY)) {
keyboardGsettings->set(KEYREPEAT_KEY, checked);
} else {
qCritical() << "keyboardGsettings not contains the key: " << KEYREPEAT_KEY;
}
}
void KeyBoardInterface::setDelay(const int value)
{
if (keyboardGsettings->keys().contains(DELAY_KEY)) {
keyboardGsettings->set(DELAY_KEY, value);
} else {
qCritical() << "keyboardGsettings not contains the key: " << DELAY_KEY;
}
}
void KeyBoardInterface::setSpeed(const int value)
{
if (keyboardGsettings->keys().contains(SPEED_KEY)) {
keyboardGsettings->set(SPEED_KEY, value);
} else {
qCritical() << "keyboardGsettings not contains the key: " << SPEED_KEY;
}
}
void KeyBoardInterface::setKeyTips(const bool checked)
{
if (ukccOsdGsettings->keys().contains(KEYTIPS_KEY)) {
ukccOsdGsettings->set("show-lock-tip", checked);
} else {
qCritical() << "ukccOsdGsettings not contains the key: " << KEYTIPS_KEY;
}
}

View File

@ -0,0 +1,51 @@
#ifndef KEYBOARDINTERFACE_H
#define KEYBOARDINTERFACE_H
#include <QObject>
#include "universalinterface.h"
class KeyBoardInterface : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.ukui.ukcc.session.KeyBoard")
Q_PROPERTY(bool repeat READ getKeyRepeat)
Q_PROPERTY(int delay READ getDelay)
Q_PROPERTY(int rate READ getRate)
Q_PROPERTY(bool showLockTip READ getShowLockTip)
public:
KeyBoardInterface();
~KeyBoardInterface();
void initConnect();
private:
const QString KEYREPEAT_KEY = QString("repeat");
const QString DELAY_KEY = QString("delay");
const QString SPEED_KEY = QString("rate");
const QString KEYTIPS_KEY = QString("showLockTip");
QGSettings *keyboardGsettings = nullptr;
QGSettings *ukccOsdGsettings = nullptr;
protected:
// 对属性的访问函数
const bool getKeyRepeat();
const int getDelay();
const int getRate();
const bool getShowLockTip();
public Q_SLOTS:
// 对属性的设置函数
void setKeyRepeat(const bool checked);
void setDelay(const int value);
void setSpeed(const int value);
void setKeyTips(const bool checked);
Q_SIGNALS:
void changed(QString keyName);
};
#endif // KEYBOARDINTERFACE_H

View File

@ -0,0 +1,261 @@
#include "mouseinterface.h"
#include <QDebug>
MouseInterface::MouseInterface()
{
ukuiMouseGsettings = UniversalInterface::self()->ukuiMouseGsettings();
mateInterfaceGsettings = UniversalInterface::self()->mateInterfaceGsettings();
ukuiStyleGsettings = UniversalInterface::self()->ukuiStyleGsettings();
initConnect();
}
MouseInterface::~MouseInterface()
{
}
void MouseInterface::initConnect()
{
connect(ukuiMouseGsettings, &QGSettings::changed, this, [=](QString key) {
if (key == DOMINANT_HAND_KEY) {
Q_EMIT changed("dominantHand");
} else if (key == SCROLL_DIRECTION_KEY) {
Q_EMIT changed("scrollDirection");
} else if (key == WHEEL_SPEED_KEY) {
Q_EMIT changed("wheelSpeed");
} else if (key == DOUBLECLICK_KEY) {
Q_EMIT changed("doubleClick");
} else if (key == POINTER_SPEED_KEY) {
Q_EMIT changed("pointerSpeed");
} else if (key == MOUSE_ACCELERATION_KEY) {
Q_EMIT changed("mouseAcceleration");
} else if (key == POINTER_POSITION_KEY) {
Q_EMIT changed("pointerPosition");
} else if (key == POINTER_SIZE_KEY) {
Q_EMIT changed("pointerSize");
}
});
connect(mateInterfaceGsettings, &QGSettings::changed, this, [=](QString key) {
if (key == CURSOR_BLINK_KEY) {
Q_EMIT changed("cursorBlink");
} else if (key == CURSOR_SPEED_KEY) {
Q_EMIT changed("cursorSpeed");
}
});
}
// 对属性的访问函数
const bool MouseInterface::getDominantHand()
{
if (ukuiMouseGsettings->keys().contains(DOMINANT_HAND_KEY)) {
return ukuiMouseGsettings->get("left-handed").toBool();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << DOMINANT_HAND_KEY;
}
return bool();
}
const bool MouseInterface::getScrollDirection()
{
if (ukuiMouseGsettings->keys().contains(SCROLL_DIRECTION_KEY)) {
return ukuiMouseGsettings->get("natural-scroll").toBool();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << SCROLL_DIRECTION_KEY;
}
return bool();
}
const int MouseInterface::getWheelSpeed()
{
if (ukuiMouseGsettings->keys().contains(WHEEL_SPEED_KEY)) {
return ukuiMouseGsettings->get("wheel-speed").toInt();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << WHEEL_SPEED_KEY;
}
return int();
}
const int MouseInterface::getDoubleClick()
{
if (ukuiMouseGsettings->keys().contains(DOUBLECLICK_KEY)) {
return ukuiMouseGsettings->get("double-click").toInt();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << DOUBLECLICK_KEY;
}
return int();
}
const double MouseInterface::getPointerSpeed()
{
if (ukuiMouseGsettings->keys().contains(POINTER_SPEED_KEY)) {
return ukuiMouseGsettings->get("motion-acceleration").toDouble();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << POINTER_SPEED_KEY;
}
return double();
}
const bool MouseInterface::getMouseAcceleration()
{
if (ukuiMouseGsettings->keys().contains(MOUSE_ACCELERATION_KEY)) {
return ukuiMouseGsettings->get("mouse-accel").toBool();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << MOUSE_ACCELERATION_KEY;
}
return bool();
}
const bool MouseInterface::getPointerPosition()
{
if (ukuiMouseGsettings->keys().contains(POINTER_POSITION_KEY)) {
return ukuiMouseGsettings->get("locate-pointer").toBool();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << POINTER_POSITION_KEY;
}
return bool();
}
const int MouseInterface::getPointerSize()
{
if (ukuiMouseGsettings->keys().contains(POINTER_SIZE_KEY)) {
return ukuiMouseGsettings->get("cursor-size").toInt();
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << POINTER_SIZE_KEY;
}
return int();
}
const bool MouseInterface::getCursorBlink()
{
if (mateInterfaceGsettings->keys().contains(CURSOR_BLINK_KEY)) {
return mateInterfaceGsettings->get("cursor-blink").toBool();
} else {
qCritical() << "mateInterfaceGsettings not contains the key: " << CURSOR_BLINK_KEY;
}
return bool();
}
const int MouseInterface::getCursorSpeed()
{
if (mateInterfaceGsettings->keys().contains(CURSOR_SPEED_KEY)) {
return mateInterfaceGsettings->get("cursor-blink-time").toInt();
} else {
qCritical() << "mateInterfaceGsettings not contains the key: " << CURSOR_SPEED_KEY;
}
return int();
}
void MouseInterface::setDominantHand(const bool rightHand)
{
if (ukuiMouseGsettings->keys().contains(DOMINANT_HAND_KEY)) {
ukuiMouseGsettings->set("left-handed", rightHand);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << DOMINANT_HAND_KEY;
}
}
void MouseInterface::setScrollDirection(const bool reverse)
{
if (ukuiMouseGsettings->keys().contains(SCROLL_DIRECTION_KEY)) {
ukuiMouseGsettings->set("natural-scroll", reverse);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << SCROLL_DIRECTION_KEY;
}
}
void MouseInterface::setWheelSpeed(const int value)
{
if (ukuiMouseGsettings->keys().contains(WHEEL_SPEED_KEY)) {
ukuiMouseGsettings->set("wheel-speed", value);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << WHEEL_SPEED_KEY;
}
}
void MouseInterface::setDoubleClick(const int value)
{
if (ukuiMouseGsettings->keys().contains(DOUBLECLICK_KEY)) {
ukuiMouseGsettings->set("double-click", value);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << DOUBLECLICK_KEY;
}
}
void MouseInterface::setPointerSpeed(const double value)
{
if (ukuiMouseGsettings->keys().contains(POINTER_SPEED_KEY)) {
ukuiMouseGsettings->set("motion-acceleration", value);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << POINTER_SPEED_KEY;
}
}
void MouseInterface::setMouseAcceleration(const bool checked)
{
if (ukuiMouseGsettings->keys().contains(MOUSE_ACCELERATION_KEY)) {
ukuiMouseGsettings->set("mouse-accel", checked);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << MOUSE_ACCELERATION_KEY;
}
}
void MouseInterface::setPointerPosition(const bool checked)
{
if (ukuiMouseGsettings->keys().contains(POINTER_POSITION_KEY)) {
ukuiMouseGsettings->set("locate-pointer", checked);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << POINTER_POSITION_KEY;
}
}
void MouseInterface::setPointerSize(const int value)
{
if (ukuiMouseGsettings->keys().contains(POINTER_SIZE_KEY)) {
ukuiMouseGsettings->set("cursor-size", value);
} else {
qCritical() << "ukuiMouseGsettings not contains the key: " << POINTER_SIZE_KEY;
}
}
void MouseInterface::setCursorBlink(const bool checked)
{
if (mateInterfaceGsettings->keys().contains(CURSOR_BLINK_KEY)) {
mateInterfaceGsettings->set("cursor-blink", checked);
} else {
qCritical() << "mateInterfaceGsettings not contains the key: " << CURSOR_BLINK_KEY;
}
if (ukuiStyleGsettings->keys().contains(CURSOR_BLINK_KEY)) {
ukuiStyleGsettings->set("cursor-blink", checked);
} else {
qCritical() << "ukuiStyleGsettings not contains the key: " << CURSOR_BLINK_KEY;
}
}
void MouseInterface::setCursorSpeed(const int value)
{
if (mateInterfaceGsettings->keys().contains(CURSOR_SPEED_KEY)) {
mateInterfaceGsettings->set("cursor-blink-time", value);
} else {
qCritical() << "mateInterfaceGsettings not contains the key: " << CURSOR_SPEED_KEY;
}
if (ukuiStyleGsettings->keys().contains(CURSOR_BLINK_KEY)) {
ukuiStyleGsettings->set("cursor-blink-time", value);
} else {
qCritical() << "ukuiStyleGsettings not contains the key: " << CURSOR_BLINK_KEY;
}
}
void MouseInterface::resetKey(QString key)
{
if (key == "wheelSpeed") {
ukuiMouseGsettings->reset(WHEEL_SPEED_KEY);
} else if (key == "pointerSize") {
ukuiMouseGsettings->reset(POINTER_SIZE_KEY);
}
}

View File

@ -0,0 +1,78 @@
#ifndef MOUSEINTERFACE_H
#define MOUSEINTERFACE_H
#include <QObject>
#include "universalinterface.h"
class MouseInterface : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.ukui.ukcc.session.Mouse")
Q_PROPERTY(bool dominantHand READ getDominantHand)
Q_PROPERTY(bool scrollDirection READ getScrollDirection)
Q_PROPERTY(int wheelSpeed READ getWheelSpeed)
Q_PROPERTY(int doubleClick READ getDoubleClick)
Q_PROPERTY(double pointerSpeed READ getPointerSpeed)
Q_PROPERTY(bool mouseAcceleration READ getMouseAcceleration)
Q_PROPERTY(bool pointerPosition READ getPointerPosition)
Q_PROPERTY(int pointerSize READ getPointerSize)
Q_PROPERTY(bool cursorBlink READ getCursorBlink)
Q_PROPERTY(int cursorSpeed READ getCursorSpeed)
public:
MouseInterface();
~MouseInterface();
void initConnect();
private:
const QString DOMINANT_HAND_KEY = QString("leftHanded");
const QString SCROLL_DIRECTION_KEY = QString("naturalScroll");
const QString WHEEL_SPEED_KEY = QString("wheelSpeed");
const QString DOUBLECLICK_KEY = QString("doubleClick");
const QString POINTER_SPEED_KEY = QString("motionAcceleration");
const QString MOUSE_ACCELERATION_KEY = QString("mouseAccel");
const QString POINTER_POSITION_KEY = QString("locatePointer");
const QString POINTER_SIZE_KEY = QString("cursorSize");
const QString CURSOR_BLINK_KEY = QString("cursorBlink");
const QString CURSOR_SPEED_KEY = QString("cursorBlinkTime");
QGSettings *ukuiMouseGsettings = nullptr;
QGSettings *mateInterfaceGsettings= nullptr;
QGSettings *ukuiStyleGsettings = nullptr;
protected:
// 对属性的访问函数
const bool getDominantHand();
const bool getScrollDirection();
const int getWheelSpeed();
const int getDoubleClick();
const double getPointerSpeed();
const bool getMouseAcceleration();
const bool getPointerPosition();
const int getPointerSize();
const bool getCursorBlink();
const int getCursorSpeed();
public Q_SLOTS:
// 对属性的设置函数
void setDominantHand(const bool rightHand);
void setScrollDirection(const bool reverse);
void setWheelSpeed(const int value);
void setDoubleClick(const int value);
void setPointerSpeed(const double value);
void setMouseAcceleration(const bool checked);
void setPointerPosition(const bool checked);
void setPointerSize(const int value);
void setCursorBlink(const bool checked);
void setCursorSpeed(const int value);
void resetKey(QString key);
Q_SIGNALS:
void changed(QString keyName);
};
#endif // MOUSEINTERFACE_H

View File

@ -9,8 +9,6 @@ CONFIG += c++11 console link_pkgconfig
CONFIG -= app_bundle
PKGCONFIG += gio-2.0 \
kysdk-sysinfo \
kysdk-diagnostics \
kysdk-qtwidgets \
gsettings-qt
QMAKE_CXXFLAGS *= -D_FORTIFY_SOURCE=2 -O2
@ -39,9 +37,13 @@ INSTALLS += inst1
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
area/areainterface.cpp \
json.cpp \
main.cpp \
plugins/area/areainterface.cpp \
plugins/keyboard/keyboardinterface.cpp \
plugins/mouse/mouseinterface.cpp \
# plugins/autostart/autostartinterface.cpp \
# plugins/default/defaultinterface.cpp \
ukccsessionserver.cpp \
universalinterface.cpp
@ -49,9 +51,15 @@ SOURCES += \
target.path = /usr/bin/
!isEmpty(target.path): INSTALLS += target
HEADERS += \
area/areainterface.h \
json.h \
screenStruct.h \
ukccsessionserver.h \
universalinterface.h
json.h \
plugins/area/areainterface.h \
plugins/keyboard/keyboardinterface.h \
plugins/keyboard/keyboardinterface.h \
plugins/mouse/mouseinterface.h \
# plugins/autostart/autostartinterface.h \
# plugins/default/defaultinterface.h \
screenStruct.h \
ukccsessionserver.h \
universalinterface.h

View File

@ -85,3 +85,48 @@ QDBusInterface* UniversalInterface::fcitxInputMethodDbus()
}
return mFcitxInputMethodDbus;
}
QGSettings* UniversalInterface::ukuiKeyBoardGsettings()
{
if (!mKeyboardGsettings) {
const QByteArray id(UKUI_KEYBOARD_ID);
if (QGSettings::isSchemaInstalled(id)) {
mKeyboardGsettings = new QGSettings(id, QByteArray());
}
}
return mKeyboardGsettings;
}
QGSettings* UniversalInterface::ukccOsdGsettings()
{
if (!mUkccOsdGsettings) {
const QByteArray id(UKCC_OSD_ID);
if (QGSettings::isSchemaInstalled(id)) {
mUkccOsdGsettings = new QGSettings(id, QByteArray());
}
}
return mUkccOsdGsettings;
}
QGSettings* UniversalInterface::ukuiMouseGsettings()
{
if (!mUkuiMouseGsettings) {
const QByteArray id(UKUI_MOUSE_ID);
if (QGSettings::isSchemaInstalled(id)) {
mUkuiMouseGsettings = new QGSettings(id, QByteArray());
}
}
return mUkuiMouseGsettings;
}
QGSettings* UniversalInterface::mateInterfaceGsettings()
{
if (!mMateInterfaceGsettings) {
const QByteArray id(MATE_INTERFACE_ID);
if (QGSettings::isSchemaInstalled(id)) {
mMateInterfaceGsettings = new QGSettings(id, QByteArray());
}
}
return mMateInterfaceGsettings;
}

View File

@ -45,15 +45,51 @@ public:
*/
QDBusInterface *fcitxInputMethodDbus();
/**
* @brief org.ukui.peripherals-keyboard的gsetting
*
* @return QGSettings
*/
QGSettings* ukuiKeyBoardGsettings();
/**
* @brief org.ukui.control-center.osd的gsetting
*
* @return QGSettings
*/
QGSettings* ukccOsdGsettings();
/**
* @brief org.ukui.peripherals-mouse的gsetting
*
* @return QGSettings
*/
QGSettings* ukuiMouseGsettings();
/**
* @brief org.mate.interface的gsetting
*
* @return QGSettings
*/
QGSettings* mateInterfaceGsettings();
private:
const QByteArray UKCC_ID = QByteArray("org.ukui.control-center.panel.plugins");
const QByteArray UKUI_STYLE_ID = QByteArray("org.ukui.style");
const QByteArray UKUI_KEYBOARD_ID = QByteArray("org.ukui.peripherals-keyboard");
const QByteArray UKCC_OSD_ID = QByteArray("org.ukui.control-center.osd");
const QByteArray UKUI_MOUSE_ID = QByteArray("org.ukui.peripherals-mouse");
const QByteArray MATE_INTERFACE_ID = QByteArray("org.mate.interface");
private:
QGSettings *mUkccPanelGsettings = nullptr;
QGSettings *mUkuiStyleGsettings = nullptr;
QDBusInterface *mAccountUserDbus = nullptr;
QDBusInterface *mFcitxInputMethodDbus = nullptr;
QGSettings *mKeyboardGsettings = nullptr;
QGSettings *mUkccOsdGsettings = nullptr;
QGSettings *mUkuiMouseGsettings = nullptr;
QGSettings *mMateInterfaceGsettings= nullptr;
};
#endif // UNIVERSALINTERFACE_H

View File

@ -40,7 +40,7 @@ enum FunType {
SECURITY,
APPLICATION,
SEARCH_F,
CURRENCY,
COMMONINFO,
//NOTICEANDTASKS,
TOTALMODULES,
};

View File

@ -127,12 +127,14 @@ void MainWindow::bootOptionsFilter(QString opt, bool firstIn) {
int moduleNum;
bool isExitsModule = false;
QString funcStr;
QString funcName;
QList<FuncInfo> pFuncStructList;
for (int i = 0; i < FunctionSelect::funcinfoList.size(); i++) {
for (int j = 0; j < FunctionSelect::funcinfoList[i].size(); j++) {
if (!FunctionSelect::funcinfoList[i][j].nameString.compare(opt, Qt::CaseInsensitive)) {
moduleNum = FunctionSelect::funcinfoList[i][j].type;
funcStr = FunctionSelect::funcinfoList[i][j].namei18nString;
funcName = FunctionSelect::funcinfoList[i][j].nameString;
pFuncStructList = FunctionSelect::funcinfoList[i];
isExitsModule = true;
break;
@ -154,8 +156,13 @@ void MainWindow::bootOptionsFilter(QString opt, bool firstIn) {
QMap<QString, QObject *> pluginsObjMap = modulesList.at(moduleNum);
if (pluginsObjMap.keys().contains(funcStr)){
//开始跳转
functionBtnClicked(pluginsObjMap.value(funcStr));
if (m_ModuleMap.isEmpty() || m_ModuleMap[funcName.toLower()].toBool()) {
//开始跳转
functionBtnClicked(pluginsObjMap.value(funcStr));
return ;
} else {
QMessageBox::information(this, tr("Warnning"), tr("This function has been controlled"));
}
}
}
@ -446,6 +453,7 @@ void MainWindow::initTileBar() {
m_queryWid = new QWidget;
searchLayout->addWidget(m_queryWid);
searchLayout->setAlignment(m_queryWid, Qt::AlignHCenter);
searchLayout->setContentsMargins(8, 0, 0, 0);
m_queryWid->setFocusPolicy(Qt::NoFocus);
QHBoxLayout* queryWidLayout = new QHBoxLayout;
@ -541,9 +549,13 @@ void MainWindow::initTileBar() {
}
void MainWindow::animationFinishedSlot()
{
if (m_isSearching && !m_searchKeyWords.isEmpty()) {
m_searchWidget->setText(m_searchKeyWords);
m_searchKeyWords.clear();
if (m_isSearching) {
m_searchWidget->layout()->setAlignment(m_queryWid, Qt::AlignLeft);
} else if (!m_searchKeyWords.isEmpty()){
m_searchWidget->setText(m_searchKeyWords);
m_searchKeyWords.clear();
} else {
m_searchWidget->layout()->setAlignment(m_queryWid, Qt::AlignHCenter);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

File diff suppressed because it is too large Load Diff

View File

@ -978,7 +978,7 @@
<message>
<location filename="../../../plugins/time-language/area/area.cpp" line="185"/>
<source>sunday</source>
<translation></translation>
<translation></translation>
</message>
<message>
<source>change data format</source>
@ -3337,7 +3337,7 @@ change system settings</source>
</message>
<message>
<source>sunday</source>
<translation type="vanished"></translation>
<translation type="vanished"></translation>
</message>
</context>
<context>

View File

@ -978,7 +978,7 @@
<message>
<location filename="../../../plugins/time-language/area/area.cpp" line="185"/>
<source>sunday</source>
<translation></translation>
<translation></translation>
</message>
<message>
<source>change data format</source>
@ -3337,7 +3337,7 @@ change system settings</source>
</message>
<message>
<source>sunday</source>
<translation type="vanished"></translation>
<translation type="vanished"></translation>
</message>
</context>
<context>

View File

@ -978,7 +978,7 @@
<message>
<location filename="../../../plugins/time-language/area/area.cpp" line="185"/>
<source>sunday</source>
<translation></translation>
<translation></translation>
</message>
<message>
<source>change data format</source>
@ -3337,7 +3337,7 @@ change system settings</source>
</message>
<message>
<source>sunday</source>
<translation type="vanished"></translation>
<translation type="vanished"></translation>
</message>
</context>
<context>

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More