From a8c9421501b42932bb44025e7dc2729ac05c4abd Mon Sep 17 00:00:00 2001 From: winnerym Date: Tue, 1 Nov 2022 18:14:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E7=BA=BF?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=88=86=E6=94=AF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BiometricAuth/CMakeLists.txt | 2 + BiometricAuth/biometricdeviceinfo.cpp | 19 + BiometricAuth/biometricdeviceinfo.h | 2 + BiometricAuth/uniauthservice.cpp | 251 +++ BiometricAuth/uniauthservice.h | 78 + CMakeLists.txt | 4 +- Common/commonfunc.cpp | 34 + Common/commonfunc.h | 3 + KylinNM/src/backthread.cpp | 17 +- data/org.ukui.screensaver.gschema.xml | 17 +- data/screensaver-startup.sh | 2 + .../LoadCustomPlugin/LoadCustomPlugin.pro | 23 + examples/LoadCustomPlugin/main.cpp | 11 + examples/LoadCustomPlugin/widget.cpp | 46 + examples/LoadCustomPlugin/widget.h | 25 + examples/LoadCustomPlugin/widget.ui | 43 + i18n_ts/bo.ts | 198 +- i18n_ts/bo_CN.ts | 1989 ++++++++++++----- i18n_ts/es.ts | 73 +- i18n_ts/fr.ts | 73 +- i18n_ts/pt.ts | 73 +- i18n_ts/ru.ts | 73 +- i18n_ts/tr.ts | 202 +- i18n_ts/zh_CN.ts | 318 ++- screensaver/CMakeLists.txt | 71 +- screensaver/assets/default.qss | 4 +- screensaver/customplugin.cpp | 22 + screensaver/customplugin.h | 21 + screensaver/language/screensaver-bo_CN.ini | 84 + screensaver/language/screensaver-zh_CN.ini | 231 +- screensaver/main.cpp | 18 +- screensaver/screensaver.cpp | 107 +- screensaver/screensaver.h | 11 +- screensaver/screensaverplugin.h | 27 + screensaver/sleeptime.cpp | 115 +- screensaver/sleeptime.h | 7 +- screensaver/weathermanager.h | 122 - src/CMakeLists.txt | 31 +- src/assets/authdialog.qss | 17 +- src/auth-pam.cpp | 52 +- src/auth-pam.h | 3 +- src/authdialog.cpp | 353 ++- src/authdialog.h | 28 +- src/authpamthread.cpp | 201 ++ src/authpamthread.h | 35 + src/batterywidget.cpp | 180 ++ src/batterywidget.h | 54 + src/configuration.cpp | 27 +- src/configuration.h | 13 +- src/device.cpp | 28 + src/device.h | 255 +++ src/enginedevice.cpp | 381 ++++ src/enginedevice.h | 100 + src/fullbackgroundwidget.cpp | 466 ++-- src/fullbackgroundwidget.h | 35 +- src/grab-x11.cpp | 10 +- src/iconedit.cpp | 51 +- src/iconedit.h | 1 + src/interface.cpp | 200 +- src/interface.h | 24 +- src/lockchecker.cpp | 237 ++ src/lockchecker.h | 75 + src/lockwidget.cpp | 1131 ++++++++-- src/lockwidget.h | 73 +- src/lockwidget.ui | 78 +- src/loginedusers.cpp | 36 + src/loginedusers.h | 41 + src/loginoptionswidget.cpp | 294 ++- src/loginoptionswidget.h | 36 +- src/mytabwidget.cpp | 40 + src/mytabwidget.h | 18 + src/org.ukui.ScreenSaver.xml | 6 + src/pam-tally.c | 20 +- src/powermanager.cpp | 265 +-- src/powermanager.h | 38 +- src/{screensaver.cpp => screensavermode.cpp} | 2 +- src/{screensaver.h => screensavermode.h} | 8 +- src/screensaverwidget.cpp | 32 +- src/screensaverwidget.h | 5 +- src/screensaverwndadaptor.cpp | 52 + src/screensaverwndadaptor.h | 58 + src/servicemanager.cpp | 122 + src/servicemanager.h | 53 + src/sessionwatcher.cpp | 230 +- src/sessionwatcher.h | 35 +- src/surewindow.cpp | 76 +- src/surewindow.h | 4 +- src/surewindow.ui | 67 +- src/tabletlockwidget.cpp | 25 +- src/tabletlockwidget.h | 6 + src/types.h | 4 + src/ukui-screensaver-backend.cpp | 67 - src/ukui-screensaver-dialog.cpp | 35 +- src/ukui-screensaver.pro | 7 +- src/weathermanager.cpp | 84 +- src/weathermanager.h | 12 +- src/xeventmonitor.cpp | 2 +- 97 files changed, 8318 insertions(+), 2017 deletions(-) create mode 100644 BiometricAuth/uniauthservice.cpp create mode 100644 BiometricAuth/uniauthservice.h create mode 100644 examples/LoadCustomPlugin/LoadCustomPlugin.pro create mode 100644 examples/LoadCustomPlugin/main.cpp create mode 100644 examples/LoadCustomPlugin/widget.cpp create mode 100644 examples/LoadCustomPlugin/widget.h create mode 100644 examples/LoadCustomPlugin/widget.ui create mode 100644 screensaver/customplugin.cpp create mode 100644 screensaver/customplugin.h create mode 100644 screensaver/language/screensaver-bo_CN.ini create mode 100644 screensaver/screensaverplugin.h delete mode 100644 screensaver/weathermanager.h create mode 100644 src/authpamthread.cpp create mode 100644 src/authpamthread.h create mode 100644 src/batterywidget.cpp create mode 100644 src/batterywidget.h create mode 100644 src/device.cpp create mode 100644 src/device.h create mode 100644 src/enginedevice.cpp create mode 100644 src/enginedevice.h create mode 100644 src/lockchecker.cpp create mode 100644 src/lockchecker.h create mode 100644 src/loginedusers.cpp create mode 100644 src/loginedusers.h create mode 100644 src/mytabwidget.cpp create mode 100644 src/mytabwidget.h rename src/{screensaver.cpp => screensavermode.cpp} (99%) rename src/{screensaver.h => screensavermode.h} (94%) create mode 100644 src/screensaverwndadaptor.cpp create mode 100644 src/screensaverwndadaptor.h create mode 100644 src/servicemanager.cpp create mode 100644 src/servicemanager.h diff --git a/BiometricAuth/CMakeLists.txt b/BiometricAuth/CMakeLists.txt index 9ba7d2c..18c3215 100644 --- a/BiometricAuth/CMakeLists.txt +++ b/BiometricAuth/CMakeLists.txt @@ -4,6 +4,7 @@ qt5_wrap_cpp(BiometricAuth_SRC biometricauthwidget.h biometricdeviceswidget.h giodbus.h + uniauthservice.h ) set(BiometricAuth_SRC @@ -13,6 +14,7 @@ set(BiometricAuth_SRC biometricauthwidget.cpp biometricdeviceswidget.cpp giodbus.cpp + uniauthservice.cpp ) include_directories( diff --git a/BiometricAuth/biometricdeviceinfo.cpp b/BiometricAuth/biometricdeviceinfo.cpp index 368b1d0..f49881e 100644 --- a/BiometricAuth/biometricdeviceinfo.cpp +++ b/BiometricAuth/biometricdeviceinfo.cpp @@ -34,6 +34,25 @@ QString DeviceType::getDeviceType(int deviceType) return QString(typeString); } +int DeviceType::getBioType(int bioType) +{ + switch(bioType) + { + case Face: + return 0; + case FingerPrint: + return 1; + case FingerVein: + return 2; + case Iris: + return 3; + case VoicePrint: + return 4; + default: + return -1; + } +} + QString DeviceType::getDeviceType_tr(int deviceType) { switch(deviceType) diff --git a/BiometricAuth/biometricdeviceinfo.h b/BiometricAuth/biometricdeviceinfo.h index c9604be..7ffb27a 100644 --- a/BiometricAuth/biometricdeviceinfo.h +++ b/BiometricAuth/biometricdeviceinfo.h @@ -69,6 +69,8 @@ public: * @return */ static QString getDeviceType_tr(int deviceType); + //根据设备优先级获取设备类型 + static int getBioType(int bioType); }; /** diff --git a/BiometricAuth/uniauthservice.cpp b/BiometricAuth/uniauthservice.cpp new file mode 100644 index 0000000..4f327af --- /dev/null +++ b/BiometricAuth/uniauthservice.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#include "uniauthservice.h" +#include +#include + +#define UNIAUTH_DBUS_SERVICE "org.ukui.UniauthBackend" +#define UNIAUTH_DBUS_PATH "/org/ukui/UniauthBackend" +#define UNIAUTH_DBUS_INTERFACE "org.ukui.UniauthBackend" + +#define FD_DBUS_SERVICE "org.freedesktop.DBus" +#define FD_DBUS_PATH "/org/freedesktop/DBus" +#define FD_DBUS_INTERFACE "org.freedesktop.DBus" + +UniAuthService::UniAuthService(QObject *parent) + : QDBusAbstractInterface(UNIAUTH_DBUS_SERVICE, + UNIAUTH_DBUS_PATH, + UNIAUTH_DBUS_INTERFACE, + QDBusConnection::systemBus(), + parent) + , m_isActivatable(false) +{ + setTimeout(2147483647); + QDBusInterface *dbusService = new QDBusInterface(FD_DBUS_SERVICE, + FD_DBUS_PATH, + FD_DBUS_INTERFACE, + QDBusConnection::systemBus()); + if (dbusService) { + QDBusReply result = dbusService->call(QStringLiteral("ListActivatableNames")); + if(!result.isValid()) { + qWarning() << "ListActivatableNames error:" << result.error().message(); + } else { + QStringList listNames = result.value(); + if (listNames.contains(UNIAUTH_DBUS_INTERFACE)) { + m_isActivatable = true; + } + } + } +} + +// 设置默认设备 +void UniAuthService::setDefaultDevice(int bioDevType, QString deviceName) +{ + qDebug() << " bioType : " << bioDevType << "deviceName : " << deviceName; + QDBusMessage result = call(QStringLiteral("setDefaultDevice"), bioDevType, deviceName); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "setDefaultDevice error:" << result.errorMessage(); + return ; + } + return ; +} + +// 获取默认设备 +QString UniAuthService::getDefaultDevice(QString userName, int bioDevType) +{ + QDBusMessage result = call(QStringLiteral("getDefaultDevice"), userName, bioDevType); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getDefaultDevice error:" << result.errorMessage(); + return ""; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + QString strDefDevice = varResult.takeFirst().toString(); + return strDefDevice; + } else { + return ""; + } +} + +// 获取所有默认设备 +QStringList UniAuthService::getAllDefaultDevice(QString userName) +{ + QStringList listDefDevices; + QDBusReply result = call(QStringLiteral("getAllDefaultDevice"), userName); + if(!result.isValid()) { + qWarning() << "getAllDefaultDevice error:" << result.error().message(); + } else { + listDefDevices = result.value(); + } + return listDefDevices; +} + +//生物特征开关接口 +bool UniAuthService::getBioAuthStatus(QString userName, int bioAuthType) +{ + QDBusMessage bioResult = call(QStringLiteral("getBioAuthStatus"), userName, bioAuthType); + if(bioResult.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getBioStatus error:" << bioResult.errorMessage(); + return false; + } + QList varResult = bioResult.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +void UniAuthService::setBioAuthStatus(int bioAuthType, bool status) +{ + qDebug() << "setBioAuthStatus bioAuthType : " << bioAuthType << "status : " << status; + QDBusMessage result = call(QStringLiteral("setBioAuthStatus"), bioAuthType, status); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "setBioAuthStatus error:" << result.errorMessage(); + return ; + } + return ; +} + +// 获取最大失败次数 +int UniAuthService::getMaxFailedTimes() +{ + QDBusMessage result = call(QStringLiteral("getMaxFailedTimes")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getMaxFailedTimes error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toInt(); + } else { + return 3; + } +} + +// 获取是否使能微信扫码登录 +bool UniAuthService::getQRCodeEnable() +{ + QDBusMessage result = call(QStringLiteral("getQRCodeEnable")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getQRCodeEnable error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否双认证 +bool UniAuthService::getDoubleAuth() +{ + QDBusMessage result = call(QStringLiteral("getDoubleAuth")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getDoubleAuth error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取用户绑定 +bool UniAuthService::getUserBind() +{ + QDBusMessage result = call(QStringLiteral("getUserBind")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getUserBind error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否在控制面板显示 +bool UniAuthService::getIsShownInControlCenter() +{ + QDBusMessage result = call(QStringLiteral("getIsShownInControlCenter")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getIsShownInControlCenter error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否使用第一个设备 +bool UniAuthService::getUseFirstDevice() +{ + QDBusMessage result = call(QStringLiteral("getUseFirstDevice")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getUseFirstDevice error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +// 获取是否隐藏切换按钮 +bool UniAuthService::getHiddenSwitchButton() +{ + QDBusMessage result = call(QStringLiteral("getHiddenSwitchButton")); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "getHiddenSwitchButton error:" << result.errorMessage(); + return false; + } + QList varResult = result.arguments(); + if (varResult.size() > 0) { + return varResult.takeFirst().toBool(); + } else { + return false; + } +} + +bool UniAuthService::isActivatable() +{ + return m_isActivatable; +} diff --git a/BiometricAuth/uniauthservice.h b/BiometricAuth/uniauthservice.h new file mode 100644 index 0000000..9bbe5b4 --- /dev/null +++ b/BiometricAuth/uniauthservice.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ +#ifndef UNIAUTH_SERVICE_H +#define UNIAUTH_SERVICE_H + +#include +#include + +enum authEnableType { + ENABLETYPE_BIO, // 全局总使能 + ENABLETYPE_SAVER, // 锁屏 + ENABLETYPE_GREETER, // 登录 + ENABLETYPE_POLKIT, // 授权 + ENABLETYPE_SU, // 暂保留 + ENABLETYPE_SUDO, // 暂保留 + ENABLETYPE_LOGIN, // 暂保留 +}; + +class UniAuthService : public QDBusAbstractInterface +{ + Q_OBJECT +public: + explicit UniAuthService(QObject *parent = nullptr); + +public Q_SLOTS: + // 设置默认设备 + void setDefaultDevice(int bioDevType, QString deviceName); + // 获取默认设备 + QString getDefaultDevice(QString userName, int bioDevType); + // 获取所有默认设备 + QStringList getAllDefaultDevice(QString userName); + //生物特征开关接口 + bool getBioAuthStatus(QString userName, int bioAuthType); + void setBioAuthStatus(int bioAuthType, bool status); + // 获取最大失败次数 + int getMaxFailedTimes(); + // 获取是否使能微信扫码登录 + bool getQRCodeEnable(); + // 获取是否双认证 + bool getDoubleAuth(); + // 获取用户绑定 + bool getUserBind(); + // 获取是否在控制面板显示 + bool getIsShownInControlCenter(); + // 获取是否使用第一个设备 + bool getUseFirstDevice(); + // 获取是否隐藏切换按钮 + bool getHiddenSwitchButton(); + +public: + bool isActivatable(); + +Q_SIGNALS: + //默认设备改变 + void defaultDeviceChanged(QString userName, int bioDevType, QString deviceName); + //开关状态改变 + void bioAuthStatusChanged(QString userName, int type, bool status); + +private: + bool m_isActivatable; +}; + +#endif // UNIAUTH_SERVICE_H diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e63621..14d81a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ find_package(OpenCV REQUIRED) find_package(PkgConfig) pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0) pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0) +pkg_check_modules(kylin-nm-base REQUIRED kylin-nm-base) + # 是否是intel项目 option (USE_INTEL "intel项目" OFF) @@ -63,5 +65,5 @@ add_subdirectory(screensaver-focus-helper) add_subdirectory(Common) add_subdirectory(KylinNM) -add_dependencies(ukui-screensaver-dialog BiometricAuth VirtualKeyboard Common) +add_dependencies(ukui-screensaver-dialog BiometricAuth VirtualKeyboard Common Screensaver) add_dependencies(ukui-screensaver-default Common) diff --git a/Common/commonfunc.cpp b/Common/commonfunc.cpp index 150bd5c..79df19e 100644 --- a/Common/commonfunc.cpp +++ b/Common/commonfunc.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include "commonfunc.h" @@ -75,3 +76,36 @@ QString ElideText(QFont font,int width,QString strInfo) return strInfo; } +/*修改图片缩放机制,图片长宽不一致时,先取图片中央的部分*/ +QPixmap scaledPixmap(QPixmap src) +{ + QPixmap rectPixmap; + if (src.width() > src.height()) { + QPixmap iconPixmap = src.copy((src.width() - src.height())/2, 0, src.height(), src.height()); + // 根据label高度等比例缩放图片 + rectPixmap = iconPixmap.scaledToHeight(src.height()); + } else { + QPixmap iconPixmap = src.copy(0, (src.height() - src.width())/2, src.width(), src.width()); + // 根据label宽度等比例缩放图片 + rectPixmap = iconPixmap.scaledToWidth(src.width()); + } + return rectPixmap; +} + +QPixmap PixmapToRound(const QPixmap &src, int radius) +{ + if (src.isNull()) { + return QPixmap(); + } + + QPixmap pixmapa(src); + QPixmap pixmap(radius*2,radius*2); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + QPainterPath path; + path.addEllipse(0, 0, radius*2, radius*2); + painter.setClipPath(path); + painter.drawPixmap(0, 0, radius*2, radius*2, pixmapa); + return pixmap; +} diff --git a/Common/commonfunc.h b/Common/commonfunc.h index 3e23bb3..43ab4a9 100644 --- a/Common/commonfunc.h +++ b/Common/commonfunc.h @@ -23,12 +23,15 @@ #include #include +#include bool ispicture(QString filepath); QString getSystemVersion(); QString getSystemDistrib(); bool getUseFirstDevice(); QString ElideText(QFont font,int width,QString strInfo); +QPixmap scaledPixmap(QPixmap src); +QPixmap PixmapToRound(const QPixmap &src, int radius); class commonFunc { diff --git a/KylinNM/src/backthread.cpp b/KylinNM/src/backthread.cpp index 5747fc8..d115d26 100644 --- a/KylinNM/src/backthread.cpp +++ b/KylinNM/src/backthread.cpp @@ -33,16 +33,13 @@ BackThread::BackThread(QObject *parent) : QObject(parent) { - cmdConnWifi = new QProcess(this); - connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput())); - connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror())); - cmdConnWifi->start("bash"); - cmdConnWifi->waitForStarted(); } BackThread::~BackThread() { - cmdConnWifi->close(); + if (cmdConnWifi) { + cmdConnWifi->close(); + } } //get the connection state of wired and wireles network @@ -278,7 +275,13 @@ void BackThread::execConnWifiPWD(QString connName, QString password) void BackThread::execConnWifi(QString connName) { //disConnLanOrWifi("wifi"); - + if (!cmdConnWifi) { + cmdConnWifi = new QProcess(this); + connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(on_readoutput())); + connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(on_readerror())); + cmdConnWifi->start("bash"); + cmdConnWifi->waitForStarted(); + } QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up \"" + connName.replace("\"","\\\"") + "\"\n"; cmdConnWifi->write(cmdStr.toUtf8().data()); } diff --git a/data/org.ukui.screensaver.gschema.xml b/data/org.ukui.screensaver.gschema.xml index b9d8aeb..302bc72 100644 --- a/data/org.ukui.screensaver.gschema.xml +++ b/data/org.ukui.screensaver.gschema.xml @@ -17,6 +17,11 @@ Automatic switching background Set this to TRUE to activate the automatic switching background. + + true + show rest time on screensaver + Set this to TRUE to show rest time on screensaver. + true show rest time on custom screensaver @@ -71,15 +76,25 @@ Wait idle delay to lock - 5 + -1 idle lock to lock Display the lock screen + + 10 + screensaver with lock timeout + Display the screensaver with lock's timeout + true Lock when sleep Set this to TRUE to lock the screen when the system goes sleep. + + true + Lock when close screen + Set this to TRUE to lock the screen when the screen goes close. + 'default-ukui' Screensaver theme selection mode diff --git a/data/screensaver-startup.sh b/data/screensaver-startup.sh index fa8710d..c110d2e 100755 --- a/data/screensaver-startup.sh +++ b/data/screensaver-startup.sh @@ -3,3 +3,5 @@ ukui-screensaver-dialog --lock-startup & >/dev/null 2>&1 /usr/lib/ukui-screensaver/screensaver-focus-helper & >/dev/null 2>&1 +#如果锁屏和桌面进程并行启动,会对锁屏启动时间有较大影响,因此先启动锁屏,1s后再往下执行 +sleep 1 diff --git a/examples/LoadCustomPlugin/LoadCustomPlugin.pro b/examples/LoadCustomPlugin/LoadCustomPlugin.pro new file mode 100644 index 0000000..ff6574b --- /dev/null +++ b/examples/LoadCustomPlugin/LoadCustomPlugin.pro @@ -0,0 +1,23 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2022-07-01T18:13:09 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = LoadCustomPlugin +TEMPLATE = app + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +FORMS += \ + widget.ui + diff --git a/examples/LoadCustomPlugin/main.cpp b/examples/LoadCustomPlugin/main.cpp new file mode 100644 index 0000000..4d6c97b --- /dev/null +++ b/examples/LoadCustomPlugin/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + + return a.exec(); +} diff --git a/examples/LoadCustomPlugin/widget.cpp b/examples/LoadCustomPlugin/widget.cpp new file mode 100644 index 0000000..45a1213 --- /dev/null +++ b/examples/LoadCustomPlugin/widget.cpp @@ -0,0 +1,46 @@ +#pragma execution_character_set("utf-8") + +#include "widget.h" +#include "ui_widget.h" +#include +#include +#include +#include +#include + +Widget::Widget(QWidget *parent) : + QWidget(parent), + ui(new Ui::Widget) +{ + ui->setupUi(this); + connect(ui->load_plugin_btn,SIGNAL(clicked(bool)),this, SLOT(slot_load_plugin())); +} + +Widget::~Widget() +{ + delete ui; +} + +void Widget::slot_load_plugin() +{ + /* + QString file_path = QFileDialog::getOpenFileName(NULL,"加载插件",".","dll (*.dll *.so)"); + if(file_path.isEmpty()) + { + return; + } + */ + QPluginLoader pluginLoader("/usr/lib/ukui-screensaver/libscreensaver-default.so"); + pluginLoader.load(); + QObject* plugin = pluginLoader.instance(); + if (plugin) { + std::unique_ptr interface_ptr = std::unique_ptr(qobject_cast(plugin)); + QWidget* widget = interface_ptr->createWidget(false,this); + widget->setFixedHeight(180); + widget->setFixedWidth(300); + QHBoxLayout* mainLayout = new QHBoxLayout(this); + + mainLayout->addWidget(widget); + ui->widget->setLayout(mainLayout); + } +} diff --git a/examples/LoadCustomPlugin/widget.h b/examples/LoadCustomPlugin/widget.h new file mode 100644 index 0000000..43d6a87 --- /dev/null +++ b/examples/LoadCustomPlugin/widget.h @@ -0,0 +1,25 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include + +namespace Ui { +class Widget; +} + +class Widget : public QWidget +{ + Q_OBJECT + +public: + explicit Widget(QWidget *parent = 0); + ~Widget(); + +public slots: + void slot_load_plugin(); + +private: + Ui::Widget *ui; +}; + +#endif // WIDGET_H diff --git a/examples/LoadCustomPlugin/widget.ui b/examples/LoadCustomPlugin/widget.ui new file mode 100644 index 0000000..22adeca --- /dev/null +++ b/examples/LoadCustomPlugin/widget.ui @@ -0,0 +1,43 @@ + + + Widget + + + + 0 + 0 + 400 + 300 + + + + Widget + + + + + 140 + 30 + 111 + 31 + + + + LoadPlugin + + + + + + 30 + 90 + 331 + 141 + + + + + + + + diff --git a/i18n_ts/bo.ts b/i18n_ts/bo.ts index 1f66585..df90984 100644 --- a/i18n_ts/bo.ts +++ b/i18n_ts/bo.ts @@ -4,108 +4,108 @@ AuthDialog - + Authentication failure, Please try again - - - + + + Please try again in %1 minutes. - - - + + + Please try again in %1 seconds. + - - + Account locked permanently. - + Verify face recognition or enter password to unlock - + Press fingerprint or enter password to unlock - + Verify voiceprint or enter password to unlock - + Verify finger vein or enter password to unlock - + Verify iris or enter password to unlock - + Use the bound wechat scanning code or enter the password to unlock - - + + Password cannot be empty - + Password - + Input Password - + Login - + Retry - + Failed to verify %1, please enter password to unlock - + Unable to verify %1, please enter password to unlock - + Failed to verify %1, you still have %2 verification opportunities - - NET Exception + + Abnormal network @@ -253,32 +253,32 @@ DeviceType - + FingerPrint - + FingerVein - + Iris - + Face - + VoicePrint - + QRCode @@ -327,7 +327,6 @@ DlgConnHidWifi - Connect to Hidden Wi-Fi Network @@ -381,7 +380,6 @@ DlgConnHidWifiLeap - Connect to Hidden Wi-Fi Network @@ -465,7 +463,6 @@ DlgConnHidWifiSecFast - Connect to Hidden Wi-Fi Network @@ -600,7 +597,6 @@ DlgConnHidWifiSecLeap - Connect to Hidden Wi-Fi Network @@ -699,7 +695,6 @@ DlgConnHidWifiSecPeap - Connect to Hidden Wi-Fi Network @@ -849,7 +844,6 @@ DlgConnHidWifiSecPwd - Connect to Hidden Wi-Fi Network @@ -948,7 +942,6 @@ DlgConnHidWifiSecTls - Connect to Hidden Wi-Fi Network @@ -1092,7 +1085,6 @@ DlgConnHidWifiSecTunnelTLS - Connect to Hidden Wi-Fi Network @@ -1227,7 +1219,6 @@ DlgConnHidWifiWep - Connect to Hidden Wi-Fi Network @@ -1331,7 +1322,6 @@ DlgConnHidWifiWpa - Connect to Hidden Wi-Fi Network @@ -1390,7 +1380,6 @@ DlgHotspotCreate - Dialog @@ -1473,7 +1462,6 @@ KeyboardWidget - KeyboardWidget @@ -1482,7 +1470,6 @@ KylinNM - kylin-nm @@ -1617,32 +1604,44 @@ LockWidget - Form - - + Date - - + Time + + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + + + + + LAN + + + + + WLAN + + LoginOptionsWidget - + Login Options - + Identify device removed! @@ -1661,7 +1660,6 @@ OneConnForm - Form @@ -1723,7 +1721,6 @@ OneLancForm - Form @@ -1824,35 +1821,39 @@ PowerManager - + Log Out - + lock - - - Restart + + + Reboot - - + Power Off - - Suspend + + Shut Down - - Sleep + + Hibernate + + + + + Suspend @@ -1872,17 +1873,17 @@ Screensaver - + Picture does not exist - + View - + You have new notification @@ -1890,8 +1891,51 @@ SleepTime - - You have rested: + + You have rested + + + + + SureWindow + + + Form + + + + + TextLabel + + + + + Cancel + + + + + Confirm + + + + + The following program is running to prevent the system from reboot! + + + + + The following program is running to prevent the system from shutting down! + + + + + The following program is running to prevent the system from suspend! + + + + + The following program is running to prevent the system from hibernate! @@ -2043,8 +2087,8 @@ - - + + lock the screen immediately @@ -2064,23 +2108,23 @@ - + Dialog for the ukui ScreenSaver. - + activated by session idle signal - - + + lock the screen and show screensaver immediately - + show screensaver immediately diff --git a/i18n_ts/bo_CN.ts b/i18n_ts/bo_CN.ts index 4135111..3b0bc42 100644 --- a/i18n_ts/bo_CN.ts +++ b/i18n_ts/bo_CN.ts @@ -4,1676 +4,2549 @@ AuthDialog + More Devices + 选择其他设备 + + + Biometric + 使用生物识别认证 + + + Password + 使用密码认证 + + + Retry - ཡང་བསྐྱར་ཚོད་ལེན། + བསྐྱར་དུ་ཞིབ་བཤེར་བྱ་དགོས། - Please enter your password or enroll your fingerprint - གསང་ཨང་མནོན་པའམ་མཛུབ་རིམ་མནོན་རོགས། + UnLock + 解锁 - Too many unsuccessful attempts,please enter password. - མཛུབ་རིས་ར་སྤྲོད་ཕམ་ཉེས་ཚད་ཆེས་ཆེ་ལས་བརྒལ་བ། ཁྱོས་གསང་ཨང་བཀོལ་ནས་ཟྭ་འབྱེད་རོགས། + Slide to unlock + 向上滑动解锁 - Fingerprint authentication failed, you still have %1 verification opportunities - མཛུབ་རིས་ར་སྤྲོད་ཕམ་ཉེས་བྱུང་། ཁྱོད་ལ་ད་དུང་གོ་སྐབས་གཅིག་ཡོད། + You have %1 unread message + 您有%1条未读消息 + + + LoggedIn + 已登录 Password: - གསང་ཨང་། + 密码: - Biometric Authentication - སྐྱེ་དངོས་ངོས་འཛིན་ཀྱི་དཔང་ལེན། - - - Other Devices - སྒྲིག་ཆས་གཞན་དག - - - Password Authentication - གསང་ཨང་ར་སྤྲོད་གྲོས་ཆིངས། - - - Authentication failure, Please try again - དཔང་ལེན་བྱ་མ་ཐུབ། ཡང་བསྐྱར་ཚོད་ལྟ་བྱོས། + Account locked %1 minutes due to %2 fail attempts + 账户锁定%1分钟由于%2次错误尝试 + + + + Please try again in %1 minutes. - + ཁྱོད་ཀྱིས་ཡང་བསྐྱར་ཐེངས་གཅིག་ལ་ཚོད་ལྟ་ཞིག་བྱེད་རོགས། + + + + Please try again in %1 seconds. - + ཁྱོད་ཀྱིས་དུས་ཚོད་སྐར་ཆ་གཅིག་གི་ནང་དུ་ཡང་བསྐྱར་ཚོད་ལྟ་ཞིག་བྱེད་རོགས། + + + + Account locked permanently. - + དུས་གཏན་དུ་ཟྭ་བརྒྱབ་པའི་རྩིས་ཐོ། + Verify face recognition or enter password to unlock - + ངོ་གདོང་ངོས་འཛིན་ལ་ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་ + Press fingerprint or enter password to unlock - + མཛུབ་རིས་མནན་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ + Verify voiceprint or enter password to unlock - + སྒྲ་པར་ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག + Verify finger vein or enter password to unlock - + མཛུབ་མོའི་ནང་དུ་ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ + Verify iris or enter password to unlock - + iris ཞིབ་བཤེར་བྱེད་པའམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་ + + Input Password + ནང་འཇུག་གི་གསང་གྲངས། + + + + Failed to verify %1, please enter password to unlock + %1ལ་ཞིབ་བཤེར་བྱེད་མ་ཐུབ་ན། གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག་རོགས། + + + + Unable to verify %1, please enter password to unlock + %1ལ་ཞིབ་བཤེར་བྱེད་ཐབས་བྲལ་བ་དང་། གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག་རོགས། + + + + Abnormal network + རྒྱུན་ལྡན་མིན་པའི་དྲ་ + + + Use the bound wechat scanning code or enter the password to log in + 使用绑定的微信扫码或输入密码登录 + + + + Password cannot be empty - + གསང་གྲངས་སྟོང་པ་ཡིན་མི་སྲིད། - Password - + Failed to verify %1, please enter password. + 验证%1失败,请输入密码. - Login - + Unable to verify %1, please enter password. + 无法验证%1,请输入密码. + + + + Failed to verify %1, you still have %2 verification opportunities + %1ལ་ཞིབ་བཤེར་བྱེད་མ་ཐུབ་ན། ཁྱེད་ཚོར་ད་དུང་%2ལ་ཞིབ་བཤེར་བྱེད་པའི་གོ་སྐབས་ཡོད། + + + Biometric/code scan authentication failed too many times, please enter the password. + 生物/扫码验证失败达最大次数,请使用密码解锁 + + + Bioauth/code scan authentication failed, you still have %1 verification opportunities + 生物/扫码验证失败,您还有%1次尝试机会 NET Exception - + 网络异常 - Failed to verify %1, you still have %2 verification opportunities - + Password Incorrect, Please try again + 密码错误,请重试 + Authentication failure,there are still %1 remaining opportunities + 认证失败,还剩%1次尝试机会 + + + Please enter your password or enroll your fingerprint + 请输入密码或者录入指纹 + + + + Authentication failure, Please try again + བདེན་དཔང་ར་སྤྲོད་བྱེད་མ་ཐུབ་ན། ཡང་བསྐྱར་ཚོད་ལྟ་ཞིག + + + Use the bound wechat scanning code or enter the password to unlock - + འབྲེལ་མཐུད་ཀྱི་འཕྲིན་ཕྲན་ཞིབ་བཤེར་ཨང་གྲངས་སམ་ཡང་ན་གསང་གྲངས་ནང་འཇུག་བྱས་ནས་ཟྭ་རྒྱག་པ། - Failed to verify %1, please enter password to unlock - + + Password + གསང་གྲངས། - Unable to verify %1, please enter password to unlock - + + Login + ཐོ་འགོད་བྱེད་པ། - Input Password - + Biometric Authentication + 生物识别认证 + + + Password Authentication + 密码认证 + + + Other Devices + 其他设备 + + + Too many unsuccessful attempts,please enter password. + 指纹验证失败达最大次数,请使用密码登录 + + + Fingerprint authentication failed, you still have %1 verification opportunities + 指纹验证失败,您还有%1次尝试机会 + + + + BioDevices + + FingerPrint + 指纹 + + + FingerVein + 指静脉 + + + Iris + 虹膜 + + + Face + 人脸 + + + VoicePrint + 声纹 + + + + BioDevicesWidget + + Please select other biometric devices + 请选择其他生物识别设备 + + + Device Type: + 设备类型: + + + Device Name: + 设备名称: BiometricAuthWidget - Identify failed, Please retry. - ངོས་འཛིན་མ་ཐུབ། ཡང་བསྐྱར་ཚོད་ལྟ་བྱོས། + + Current device: + མིག་སྔའི་སྒྲིག་ཆས་ནི། - Current device: - མིག་སྔའི་སྒྲིག་ཆས་རེའུ་མིག: + + Identify failed, Please retry. + ཕམ་ཉེས་བྱུང་བར་ངོས་འཛིན་གནང་རོགས། ཁྱེད་ཀྱིས་ཡང་བསྐྱར་ཐེངས་གཅིག་ལ BiometricDevicesWidget - OK - གཏན་འཁེལ་བྱེད་པ། - - + Please select the biometric device - ཉིད་ཀྱིས་སྐྱེ་དངོས་སྒྲིག་ཆས་འདེམ་རོགས། + སྐྱེ་དངོས་དབྱེ་འབྱེད་སྒྲིག་ཆས་འདེམས་རོགས། + Device type: - སྒྲིག་ཆས་ཀྱི་རིགས། + སྒྲིག་ཆས་ཀྱི་རིགས་དབྱིབས་ནི། + Device name: - སྒྲིག་ཆས་ཀྱི་མིང་། + སྒྲིག་ཆས་ཀྱི་མིང་གཤམ་གསལ། + + + + OK + འགྲིགས། ConfForm + edit network - + རྩོམ་སྒྲིག་དྲ་བ། + LAN name: - + LANཡི་མིང་ནི། + Method: - + བྱེད་ཐབས་ནི། + Address: - + སྡོད་གནས་ནི། + Netmask: - + དྲ་རྒྱའི་མ་སི་ཁི་ཡིས་བཤད་རྒྱུར། + Gateway: - + འགག་སྒོ་ནི། + DNS 1: - + DNS 1: + DNS 2: - + DNS 2: + Edit Conn - + རྩོམ་སྒྲིག་པ། + + Auto(DHCP) - + རང་འགུལ་(DHCP) + + Manual - + ལག་དེབ། + Cancel - + ཕྱིར་འཐེན། + Save - + གྲོན་ཆུང་བྱེད་དགོས། + Ok - + འགྲིགས། + Can not create new wired network for without wired card - + སྐུད་ཡོད་བྱང་བུ་མེད་ན་སྐུད་ཡོད་དྲ་རྒྱ་གསར་པ་གཏོད་མི་ཐུབ། + New network already created - + དྲ་རྒྱ་གསར་པ་གསར་སྐྲུན་བྱས་ཟིན་པ། + New network settings already finished - - - - New settings already effective - + དྲ་རྒྱའི་སྒྲིག་བཀོད་གསར་པ་ལེགས་འགྲུབ་བྱུང་ཡོད། + Edit Network - + རྩོམ་སྒྲིག་དྲ་བ། + Add Wired Network - + སྐུད་ཡོད་བརྙན་འཕྲིན་དྲ་བ་ཁ་སྣོན་ + + + create wired network successfully + 已创建新的有线网络 + + + change configuration of wired network successfully + 新的设置已经生效 + + + + New settings already effective + སྒྲིག་གཞི་གསར་པར་ཕན་ནུས་ཐོན་ཡོད། + + + There is a same named LAN exsits. + 已有同名连接存在 DeviceType - Face - མིའི་གདོང་། - - - Iris - འཇའ་སྐྱི། - - - VoicePrint - སྒྲ་རིས། - - + FingerPrint - མཛུབ་རིས། + མཛུབ་མོའི་པར་གཞི། + FingerVein - མཛུབ་མོའི་སྡོད་རྩ། + མཛུབ་མོ་ཝེ་ལིན། + + Iris + དབྱི་ལི་སི། + + + + Face + ངོ་གདོང་། + + + + VoicePrint + སྒྲ་གདངས་ཀྱི་པར་གཞི། + + + QRCode - + QRCode DigitalAuthDialog + + LoginByUEdu - + LoginByUEdu + now is authing, wait a moment + 认证中,请稍后 + + + Password Incorrect, Please try again + 密码错误,请重试 + + + ResetPWD? - + ཡང་བསྐྱར་བཀོད་སྒྲིག་བྱེད་དགོས་སམ། + + SetNewUEduPWD - - - - clear - + SetNewUeduPWD + ConfirmNewUEduPWD - + གསར་དུ་གཏན་འཁེལ་བྱས་པའི་ནུའུ་ཝུའུ་ཏུའུ་ཕུའུ་ཝེ་ཏི། + The two password entries are inconsistent, please reset - + གསང་བའི་འཇུག་སྒོ་གཉིས་གཅིག་མཐུན་མིན་པས་བསྐྱར་དུ་བཀོད་སྒྲིག་གནང་རོགས། + Password entered incorrectly, please try again - + གསང་གྲངས་ནང་འཇུག་བྱས་པ་ནོར་འདུག་པས་ཡང་བསྐྱར་ཚོད་ལྟ་ཞིག་གནང་རོགས། + + + + clear + གསལ་པོར་བཤད་ན། DlgConnHidWifi - Connect to Hidden Wi-Fi Network - - - + Add Hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Wi-Fi name - + Wi-Fiཡི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + + + WEP 40/128-bit Key (Hex or ASCII) + WEP 40/128 位密钥(十六进制或ASCII) + + + WEP 128-bit Passphrase + WEP 128 位密码句 + + + Dynamic WEP (802.1X) + 动态 WEP (802.1x) + + + WPA & WPA2 Enterprise + WPA 及 WPA2 企业 + + + + Connect to Hidden Wi-Fi Network + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། DlgConnHidWifiLeap + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Username - + སྤྱོད་མཁན་གྱི་མིང་། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། DlgConnHidWifiSecFast + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Anonymous identity - + མིང་མ་བཀོད་པའི་ཐོབ་ཐང + Allow automatic PAC pro_visioning - + རང་འགུལ་གྱིས་PACའགོ་pro_visioning་བྱས་ཆོག། + PAC file - + PACཡིག་ཆ། + Inner authentication - + ནང་ཁུལ་གྱི་བདེན་དཔང་ར་སྤྲོད། + Username - + སྤྱོད་མཁན་གྱི་མིང་། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + Tunneled TLS - + ཕུག་ལམ་གྱི་TLS + Protected EAP (PEAP) - + སྲུང་སྐྱོབ་ཐོབ་པའི་EAP(PEAP) + Anonymous - + མིང་མ་བཀོད་པའི་ + Authenticated - + བདེན་དཔང་ར་སྤྲོད་བྱས། + Both - + དེ་གཉིས་ཀ DlgConnHidWifiSecLeap + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Username - + སྤྱོད་མཁན་གྱི་མིང་། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + Tunneled TLS - + ཕུག་ལམ་གྱི་TLS + Protected EAP (PEAP) - + སྲུང་སྐྱོབ་ཐོབ་པའི་EAP(PEAP) DlgConnHidWifiSecPeap + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Anonymous identity - + མིང་མ་བཀོད་པའི་ཐོབ་ཐང + Domain - + ཁྱབ་ཁོངས། + CA certificate - + CA དཔང་ཡིག + CA certificate password - + CA དཔང་ཡིག་གི་གསང་གྲངས། + No CA certificate is required - + CAལག་ཁྱེར་མི་དགོས། + PEAP version - + PEAPཔར་གཞི། + Inner authentication - + ནང་ཁུལ་གྱི་བདེན་དཔང་ར་སྤྲོད། + Username - + སྤྱོད་མཁན་གྱི་མིང་། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + Tunneled TLS - + ཕུག་ལམ་གྱི་TLS + Protected EAP (PEAP) - + སྲུང་སྐྱོབ་ཐོབ་པའི་EAP(PEAP) + Choose from file - + ཡིག་ཆའི་ནང་ནས་གདམ་གསེས་ + Automatic - + རང་འགུལ་གྱིས་རང་ + Version 0 - + པར་གཞི་0 + Version 1 - + པར་གཞི་དང་པོ། DlgConnHidWifiSecPwd + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Username - + སྤྱོད་མཁན་གྱི་མིང་། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + Tunneled TLS - + ཕུག་ལམ་གྱི་TLS + Protected EAP (PEAP) - + སྲུང་སྐྱོབ་ཐོབ་པའི་EAP(PEAP) DlgConnHidWifiSecTls + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Identity - + ཐོབ་ཐང་། + Domain - + ཁྱབ་ཁོངས། + CA certificate - + CA དཔང་ཡིག + CA certificate password - + CA དཔང་ཡིག་གི་གསང་གྲངས། + No CA certificate is required - + CAལག་ཁྱེར་མི་དགོས། + User certificate - + སྤྱོད་མཁན་གྱི་ལག་ཁྱེར། + User certificate password - + སྤྱོད་མཁན་གྱི་ལག་ཁྱེར་གྱི་གསང་ + User private key - + སྤྱོད་མཁན་གྱི་སྒེར་གྱི་ལྡེ་མིག + User key password - + སྤྱོད་མཁན་གྱི་ལྡེ་མིག་གི་གསང་ + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + + + + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + Tunneled TLS - + ཕུག་ལམ་གྱི་TLS + Protected EAP (PEAP) - + སྲུང་སྐྱོབ་ཐོབ་པའི་EAP(PEAP) + + + Choose from file - + ཡིག་ཆའི་ནང་ནས་གདམ་གསེས་ DlgConnHidWifiSecTunnelTLS + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Anonymous identity - + མིང་མ་བཀོད་པའི་ཐོབ་ཐང + Domain - + ཁྱབ་ཁོངས། + CA certificate - + CA དཔང་ཡིག + CA certificate password - + CA དཔང་ཡིག་གི་གསང་གྲངས། + No CA certificate is required - + CAལག་ཁྱེར་མི་དགོས། + Inner authentication - + ནང་ཁུལ་གྱི་བདེན་དཔང་ར་སྤྲོད། + Username - + སྤྱོད་མཁན་གྱི་མིང་། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + Tunneled TLS - + ཕུག་ལམ་གྱི་TLS + Protected EAP (PEAP) - + སྲུང་སྐྱོབ་ཐོབ་པའི་EAP(PEAP) + Choose from file - + ཡིག་ཆའི་ནང་ནས་གདམ་གསེས་ DlgConnHidWifiWep + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Key - + ལྡེ་མིག + WEP index - + WEPསྟོན་གྲངས། + Authentication - + བདེན་དཔང་ར་སྤྲོད་ + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + WEP 40/128-bit Key (Hex or ASCII) - + WEP 40/128-bit Key (Hex or ASCII) + WEP 128-bit Passphrase - + WEP 128-bit Passprase + Dynamic WEP (802.1X) - + འགུལ་རྣམ་གྱི་WEP (802.1X) + WPA & WPA2 Enterprise - + WPA & WPA2 ཁེ་ལས། + 1(default) - + 1(default) + Open System - + སྒོ་འབྱེད་མ་ལག + Shared Key - + མཉམ་སྤྱོད་ཀྱི་ལྡེ་མིག DlgConnHidWifiWpa + Connect to Hidden Wi-Fi Network - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Add Hidden Wi-Fi - + སྦས་སྐུང་བྱས་པའི་Wi-Fiབསྣན་པ། + Connection - + འབྲེལ་མཐུད་ + Wi-Fi name - + Wi-Fiཡི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + C_reate… - + C_reate… + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ + + + WEP 40/128-bit Key (Hex or ASCII) + WEP 40/128 位密钥(十六进制或ASCII) + + + WEP 128-bit Passphrase + WEP 128 位密码句 + + + Dynamic WEP (802.1X) + 动态 WEP (802.1x) + + + WPA & WPA2 Enterprise + WPA 及 WPA2 企业 DlgHotspotCreate + Dialog - + གླེང་མོལ། + Create Hotspot - + ཚ་བ་ཆེ་བའི་ས་ཆ་གསར་སྐྲུན་ + Network name - + དྲ་རྒྱའི་མིང་། + Wi-Fi security - + Wi-Fiབདེ་འཇགས། + Password - + གསང་གྲངས། + Cancel - + ཕྱིར་འཐེན། + Ok - + འགྲིགས། + None - + གཅིག་ཀྱང་མེད། + WPA & WPA2 Personal - + WPA & WPA2 མི་སྒེར་ InputInfos - Get code - - - - Recapture(60s) - - - - Recapture(%1s) - - - + Service exception... - + ཞབས་ཞུའི་དམིགས་བསལ་ ... + Invaild parameters... - + གོ་མི་ཐུབ་པའི་གྲངས་ཀ་ ... + Unknown fault:%1 - + ཤེས་མེད་པའི་ནོར་འཛོལ། %1 + + + + Recapture(60s) + ཕྱིར་ལེན་པ།(60s) + + + + Recapture(%1s) + ཕྱིར་ལེན་པ།(%1s) + + + + + Get code + ཚབ་རྟགས་ཐོབ་པ། KeyboardWidget + KeyboardWidget - + མཐེབ་གཞོང་Widget + + + + KylinDBus + + kylin network applet desktop message + 麒麟网络工具信息提示 KylinNM + kylin-nm - - - - No usable network in the list - - - - HotSpot - - - - FlyMode - - - - Advanced - - - - Show KylinNM - - - - No wireless card detected - - - - Not connected - - - - Disconnected - - - - NetOn, - - - - No Other Wired Network Scheme - - - - No Other Wireless Network Scheme - - - - Wired net is disconnected - - - - Conn Ethernet Success - - - - Conn Ethernet Fail - - - - Conn Wifi Success - - - - Confirm your Wi-Fi password or usable of wireless card - - - - Inactivated LAN - + kylin-nm + + LAN - + ལན་ལན། - WLAN - + Enabel LAN List + 其他有线网络 - Activated LAN - + WiFi + 无线网络 - Activated WLAN - + Enabel WiFi List + 其他无线网络 + New WiFi + 加入其他网络 + + + Network + 网络 + + + + + Advanced + སྔོན་ཐོན་རང་བཞིན། + + + Ethernet + 有线网络 + + + Connect Hide Network + 加入网络 + + + Wifi + 无线网络 + + + Enabled + 已开启 + + + Disabled + 已关闭 + + + + HotSpot + ཚ་བ་ཆེ་བ། + + + + FlyMode + འཕུར་སྐྱོད་འཕྲུལ་འཁོར། + + + Show MainWindow + 显示网络连接界面 + + + + Inactivated LAN + འགུལ་སྐྱོད་མ་བྱས་པའི་LAN + + + Inactivated WLAN + 未激活 + + + Other WLAN - + WLAN གཞན་དག + + + + + WLAN + སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། + + + + Show KylinNM + ཅིན་ལིན་ནའེ་མུའུ་ལ་བསྟན་དོན། + + + + No wireless card detected + སྐུད་མེད་བྱང་བུ་མ་རྙེད་པ། + + + + Activated LAN + འགུལ་སྐྱོད་བྱས་པའི་LAN + + + + Activated WLAN + འགུལ་སྐྱོད་བྱས་པའི་WLAN + + + + + + + + Not connected + འབྲེལ་མཐུད་མི་བྱེད་པ། + + + + + + + + + + + + Disconnected + འབྲེལ་ཐག་ཆད་པ། + + + + No Other Wired Network Scheme + སྐུད་ཡོད་བརྙན་འཕྲིན་དྲ་བའི་འཆར་གཞི་གཞན་དག་མེད + + + Edit + 编辑 + + + Done + 完成 + + + No wifi connected. + 未连接任何网络 + + + + No Other Wireless Network Scheme + སྐུད་མེད་དྲ་རྒྱའི་འཆར་གཞི་གཞན་དག་མེད། + + + + Wired net is disconnected + སྐུད་ཡོད་དྲ་རྒྱ་ཆད་པ། + + + Wi-Fi is disconnected + 断开无线网络 + + + + Confirm your Wi-Fi password or usable of wireless card + ཁྱོད་ཀྱི་Wi-Fiཡི་གསང་གྲངས་སམ་ཡང་ན་སྐུད་མེད་བྱང་བུ་བཀོལ་སྤྱོད་བྱེད་ཆོག་པ་ར་སྤྲོད + + + Ethernet Networks + 其他有线网络 + + + New LAN + 新建有线网络 + + + Hide WiFi + 加入网络 + + + + No usable network in the list + མིང་ཐོའི་ནང་དུ་སྤྱོད་གོ་ཆོད་པའི་དྲ་རྒྱ་མེད། + + + + + NetOn, + དྲ་རྒྱ་དང་། + + + Wifi Networks + 其他无线网络 + + + None + + + + keep wired network switch is on before turning on wireless switch + 打开无线网开关前保持有线网开关打开 + + + please insert the wireless network adapter + 请先插入无线网卡 + + + Abnormal connection exist, program will delete it + 正在断开异常连接的网络 + + + update Wi-Fi list now, click again + 正在更新 Wi-Fi列表 请再次点击 + + + update Wi-Fi list now + 正在更新 Wi-Fi列表 + + + + Conn Ethernet Success + Conn Ethernetལེགས་འགྲུབ་བྱུང་བ། + + + + Conn Ethernet Fail + ཁུང་ནེ་ཨེ་ཐེ་ནའེ་ལ་ཕམ་ཉེས་བྱུང་བ། + + + + Conn Wifi Success + ཁུང་ནེ་ཝེ་ཧྥེ་ལེགས་འགྲུབ་བྱུང་བ། LockWidget + + Form + + + + Date དུས་ཚོད། - Form - ནས་འོང་བ། - - + Time དུས་ཚོད། Guest - མགྲོན་པོ། + 游客 SwitchUser - བཀོལ་མི་བརྗེ་བ། + 切换用户 + + + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + སྤྱོད་མཁན་མང་པོ་ཞིག་དུས་གཅིག་ཏུ་ཐོ་འགོད་བྱས་པ་རེད། ཁྱོད་ཀྱིས་མ་ལག་འདི་བསྐྱར་དུ་སྒྲིག་རྒྱུ་ཡིན་ནམ། + + + + LAN + སྐུད་ཡོད་དྲ་བ། + + + + WLAN + སྐུད་མེད་ཅུས་ཁོངས་ཀྱི་དྲ་བ། LoginOptionsWidget + Login Options - + ཐོ་འགོད་ཀྱི་བསལ་འདེམས་ཀྱི་དབང་ཆ། + Password + 密码 + + + Wechat + 微信 + + + Identify device removed! - + དབྱེ་འབྱེད་སྒྲིག་ཆས་མེད་པར་བཟོ་དགོས། MyLineEdit + + + Verification code - + ཞིབ་བཤེར་གྱི་ཚབ་རྟགས། OneConnForm + Form - ནས་འོང་བ། - - - Connect - - - - Disconnect - - - - Input Password... - + རྣམ་པ། + Automatically join the network - + རང་འགུལ་གྱིས་དྲ་རྒྱའི་ནང་དུ་ཞུགས་པ། + Input password + 输入密码 + + + Config + 设置 + + + + + + + Connect + སྦྲེལ་མཐུད་བྱེད་པ + + + + Disconnect + འབྲེལ་ཐག་ཆད་པ། + + + + Input Password... + ནང་འཇུག་གི་གསང་གྲངས་ + + + Connect to Hidden Wi-Fi Network - - - - None - - - - WiFi Security: - + སྦས་སྐུང་བྱས་པའི་Wi-Fiདྲ་རྒྱ་སྦྲེལ་མཐུད་བྱེད་པ། + Signal: - + བརྡ་རྟགས་ནི། + Public + 开放 + + + Safe + 安全 + + + Rate + 速率 + + + + None + གཅིག་ཀྱང་མེད། + + + + WiFi Security: + WiFiབཀོལ་སྤྱོད་བདེ་འཇགས་ནི། + + + MAC: - + MAC: + Conn Wifi Failed - + ཁུང་ནེ་ཝེ་ཧྥེ་ཕམ་སོང་། OneLancForm + Form - ནས་འོང་བ། + རྣམ་པ། + Config + 设置 + + + + Connect - + སྦྲེལ་མཐུད་བྱེད་པ + Disconnect - + འབྲེལ་ཐག་ཆད་པ། + + No Configuration - + བཀོད་སྒྲིག་བྱས་མེད་པ། + IPv4: - + IPv4: + IPv6: - + IPv6: + BandWidth: - + 带宽: + MAC: - + MAC: + + + Auto + 自动 PhoneAuthWidget + + Verification by phoneNum - + ཁ་པར་གྱི་ནུའུ་མུའུ་ཡིས་ཞིབ་བཤེར་བྱས། + 「 Use bound Phone number to verification 」 - - - - commit - + 「ས་མཚམས་ཀྱི་ཁ་པར་ཨང་གྲངས་ལ་བརྟེན་ནས་ཞིབ་བཤེར་བྱ་དགོས།」 + 「 Use SMS to verification 」 - + 「SMSབཀོལ་ནས་ཞིབ་བཤེར་བྱ་དགོས།」 + + + commit + བསྒྲུབ་རྒྱུ་ཁས་ལེན་ + + + + Network not connected~ - - - - Verification Code invalid! - - - - Verification Code incorrect.Please retry! - - - - Failed time over limit!Retry after 1 hour! - - - - verifaction failed! - + དྲ་རྒྱ་དང་འབྲེལ་མཐུད་མི་བྱེད་པ + Network unavailable~ - + དྲ་རྒྱ་སྤྱོད་མི་ཐུབ་པ~ + + + + Verification Code invalid! + ཞིབ་བཤེར་ཚད་གཞི་གོ་མི་ཆོད་པ་རེད། + + + + Verification Code incorrect.Please retry! + ཞིབ་བཤེར་ཚད་གཞི་ཡང་དག་མིན་པ། ཁྱེད་ཀྱིས་ཡང་བསྐྱར་ཐེངས་གཅིག་ལ་བསྐྱར་དུ་ཞིབ + + + + Failed time over limit!Retry after 1 hour! + ཚད་ལས་བརྒལ་ནས་ཕམ་ཁ་བྱུང་བའི་དུས་ཚོད་ ཆུ་ཚོད་1འགོར་རྗེས་ཡང་བསྐྱར་ཞིབ་བཤེར་བྱ་དགོས། + + + + verifaction failed! + ངོ་རྒོལ་བྱེད་པའི་བྱ་སྤྱོད་ལ་ཕམ་ཉེས་བྱུང་བ་རེད། PowerManager - Sleep - མལ་གསོ། + + lock + ཟྭ་རྒྱག་པ། - Log Out - རྩིས་ཐེམ་ནས་བསུབ་པ། + SwitchUser + 切换用户 + + + logout + 注销 + + + reboot + 重启 + + + shutdown + 关机 Lock Screen - བརྙན་ཡོལ་ཟྭ་རྒྱག།(_L) - - - Restart - བསྐྱར་སློང་། + 锁屏 Switch User - སྤྱོད་མཁན་བརྗེ་རེས། + 切换用户 - Suspend - འགེལ་འཇོག + + Log Out + ཕྱིར་འཐེན་བྱ་དགོས། - Power Off - འཁོར་ཁ་རྒྱག་པ། + Restart + ཡང་བསྐྱར་འགོ་འཛུགས་ - lock + + + Reboot + + + Power Off + གློག་ཆད་པ། + + + + Shut Down + ལས་མཚམས་འཇོག + + + + Hibernate + ཧིན་རྡུ་ཉི་ཞི་ཡ། + + + + Suspend + གནས་སྐབས་མཚམས་འཇོག་ + + + Sleep + 休眠 + QObject - The screensaver is inactive. - འཆར་ངོས་སྲུང་སྐྱོབ་བྱ་རིམ་སད་མི་འདུག + + The screensaver is active. + བརྙན་ཤེལ་འདི་འགུལ་སྐྱོད་བྱེད་བཞིན་ཡོད། - The screensaver is active. - འཆར་ངོས་སྲུང་སྐྱོབ་བྱ་རིམ་སད་འདུག + + The screensaver is inactive. + བརྙན་ཤེལ་འདི་ལ་ནུས་པ་མེད། Screensaver - Automatic switching - རང་འགུལ་བརྗེ་སྤོར། + exit(Esc) + 退出(Esc) + exit + 退出 + + + Picture does not exist - པར་རིས་མི་འདུག + རི་མོ་མི་གནས་པ། Set as desktop wallpaper - ཅོག་ངོས་ཀྱི་གདོང་ཤོག་ཏུ་འཇོག་པ། + 设置为桌面壁纸 - View - + Automatic switching + 自动切换 + You have %1 unread message + 您有%1条未读消息 + + + You have new notification - + ཁྱེད་ཚོར་བརྡ་ཐོ་གསར་པ་ཡོད། + + + + View + ལྟ་ཚུལ། SleepTime + + + You have rested + ཁྱེད་ཚོས་ངལ་གསོ་བྱས་ཟིན་པ་གཤམ་གསལ། + You have rested: - ཁྱེད་ཀྱིས་ ལ་ངལ་གསོས་ཟིན། + ཁྱེད་ཚོས་ངལ་གསོ་བྱས་ཟིན་པ་གཤམ་གསལ། + + + + SureWindow + + + Form + རྣམ་པ། + + + + TextLabel + ཡི་གེ་ལ་པེར་གྱིས་བཤད་རྒྱུར + + + + Cancel + ཕྱིར་འཐེན། + + + + Confirm + གཏན་འཁེལ་བྱ་དགོས། + + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + 同时有多个用户登录系统,您确定要退出系统吗? + + + + The following program is running to prevent the system from suspend! + གཤམ་གྱི་གོ་རིམ་ནི་མ་ལག་གནས་སྐབས་མཚམས་འཇོག་པར་བཀག་འགོག་བྱེད་པའི་ཆེད་དུ་ཡིན། + + + + The following program is running to prevent the system from hibernate! + གཤམ་གྱི་གོ་རིམ་ནི་མ་ལག་ལ་བཀག་འགོག་བྱེད་པའི་ཆེད་དུ་ཡིན། + + + + The following program is running to prevent the system from shutting down! + གཤམ་གྱི་གོ་རིམ་ནི་མ་ལག་གི་སྒོ་རྒྱག་པར་བཀག་འགོག་བྱེད་པའི་ཆེད་དུ་ཡིན། + + + + The following program is running to prevent the system from reboot! + གཤམ་གྱི་གོ་རིམ་ནི་མ་ལག་བསྐྱར་དུ་འབྱུང་བར་སྔོན་འགོག་བྱེད་ཆེད་ཡིན། + + + + SwitchButton + + login by password + 密码登录 + + + login by qr code + 微信登录 SwitchButtonGroup + uEduPWD - + uEduPWD + Wechat - + འཕྲིན་ཕྲན། TabletLockWidget - Cancel - + You have %1 unread message + 您有%1条未读消息 - Back - - - - Skip - + Slide to unlock + 向上滑动解锁 + New password is the same as old - + གསང་གྲངས་གསར་པ་དང་རྙིང་པ་གཅིག་མཚུངས་ཡིན། + Reset password error:%1 - + གསང་གྲངས་ཀྱི་ནོར་འཁྲུལ་བསྐྱར་དུ་བཀོད་སྒྲིག་བྱེད་པ།%1 + Please scan by correct WeChat - + ཡང་དག་པའི་འཕྲིན་ཕྲན་ཐོག་ནས་ཞིབ་བཤེར་གནང་རོགས། + + + + + + + + + Cancel + ཕྱིར་འཐེན། + + + + + Back + ཕྱིར་ལོག་པ། + + + + Skip + བྲོས་བྱོལ་དུ་སོང་བ། Utils + kylin network applet desktop message - + kylinདྲ་རྒྱའི་ཀུ་ཤུའི་ཅོག་ཙེའི་ཆ་འཕྲིན། VerificationWidget + Please scan by bound WeChat - + འཕྲིན་ཕྲན་གྱིས་ཞིབ་བཤེར་བྱེད་རོགས། VerticalVerificationWidget + Please scan by bound WeChat - + འཕྲིན་ཕྲན་གྱིས་ཞིབ་བཤེར་བྱེད་རོགས། WeChatAuthDialog + + Login by wechat - - - - 「 Use registered WeChat account to login 」 - + ཝེ་ཆི་ཐེས་ཐོ་འགོད་བྱས་པ། + + Verification by wechat - + ཝེ་ཆི་ཐེས་ཞིབ་བཤེར་བྱས་པ། + + + 「 Use registered WeChat account to login 」 + 「ཐོ་འགོད་བྱས་ཟིན་པའི་སྐད་འཕྲིན་གྱི་ཐོ་ཁོངས་ལ་བརྟེན་ནས་ཐོ་འགོད་བྱེད་པ།」 + + + + 「 Use bound WeChat account to verification 」 - + 「ཚོད་འཛིན་རང་བཞིན་གྱི་སྐད་འཕྲིན་ཨང་གྲངས་ལ་བརྟེན་ནས་ཞིབ་བཤེར་བྱ་དགོས།」 + + Network not connected~ - + དྲ་རྒྱ་དང་འབྲེལ་མཐུད་མི་བྱེད་པ + Scan code successfully - + ཞིབ་བཤེར་ཨང་གྲངས་ལེགས་འགྲུབ་བྱུང་བ། + Timeout!Try again! - + དུས་ཚོད་ཕྱིར་འགོར་སོང་། ཡང་བསྐྱར་ཚོད་ལྟ།! + + + Login failed + 登录失败 main + Start command for the ukui ScreenSaver. - ཡོལ་སྒོའི་ཁ་འབྱེད་བཀའ་བརྡ། + ukui ScreenSaver ལ་བཀོད་འདོམས་བྱེད་འགོ་ཚུགས། + + + lock the screen immediately - མྱུར་དུ་འཆར་ངོས་ཀྱི་ཟྭ་རྒྱག་པ། + འཕྲལ་དུ་བརྙན་ཤེལ་ལ་ཟྭ་རྒྱག་པ། + query the status of the screen saver - འཆར་ངོས་ལ་ཟྭ་བརྒྱབ་པའི་གནས་ཚུལ་ལེན་པ། + བརྙན་ཤེལ་གསོག་འཇོག་བྱེད་མཁན་གྱི་གནས་ཚུལ་ལ་འདྲི་རྩད་བྱས། + unlock the screen saver - འཆར་ངོས་ཀྱི་ཟྭ་ཕྱེ་བ། - - - Screensaver for ukui-screensaver - - - - show on root window - - - - show on window. - - - - window id - + བརྙན་ཤེལ་གསོག་འཇོག་བྱེད་མཁན་ལ་སྒོ་འབྱེད་ + show the screensaver - + བརྙན་ཤེལ་གྱི་བརྙན་ཤེལ་ལ་བལྟ་རུ་འཇུག་དགོས། + Dialog for the ukui ScreenSaver. - + དབྱིན་ཇིའི་བརྙན་ཤེལ་གྱི་བརྙན་ཤེལ་ལ་ཁ་པར་རྒྱག་པའི་གླེང་མོལ། + activated by session idle signal - + སྐབས་འདིའི་ཁོམ་པའི་བརྡ་རྟགས་ཀྱིས་སྐུལ་སློང་བྱས་པ། + + lock the screen and show screensaver immediately - + བརྙན་ཤེལ་ལ་ཟྭ་བརྒྱབ་ནས་འཕྲལ་མར་བརྙན་ཤེལ་གྱི་བརྙན་ཤེལ་སྟོན་པ། + show screensaver immediately - + འཕྲལ་མར་བརྙན་ཤེལ་གྱི་བརྙན་ཤེལ་སྟོན་པ། + + + + Screensaver for ukui-screensaver + དབྱིན་ཇིའི་བརྙན་ཤེལ་གྱི་བརྙན་ཤེལ་ལ་ལྟ་ཞིབ་བྱེད་མཁན། + + + + show on root window + རྩ་བའི་སྒེའུ་ཁུང་ནས་མངོན་པ། + + + + show on window. + སྒེའུ་ཁུང་ནས་མངོན་པ། + + + + window id + སྒེའུ་ཁུང་གི་ཐོབ་ཐང་ diff --git a/i18n_ts/es.ts b/i18n_ts/es.ts index 21c1487..57d0867 100644 --- a/i18n_ts/es.ts +++ b/i18n_ts/es.ts @@ -83,10 +83,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -107,6 +103,10 @@ Input Password + + Abnormal network + + BioAuthWidget @@ -1376,6 +1376,18 @@ SwitchUser Cambiar de usuario + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + + + + LAN + + + + WLAN + + LoginOptionsWidget @@ -1534,10 +1546,6 @@ Log Out - - Restart - - Power Off @@ -1547,11 +1555,19 @@ - Sleep + lock - lock + Shut Down + + + + Hibernate + + + + Reboot @@ -1584,7 +1600,42 @@ SleepTime - You have rested: + You have rested + + + + + SureWindow + + Form + Formar + + + TextLabel + TextLabel + + + Cancel + + + + Confirm + + + + The following program is running to prevent the system from reboot! + + + + The following program is running to prevent the system from shutting down! + + + + The following program is running to prevent the system from suspend! + + + + The following program is running to prevent the system from hibernate! diff --git a/i18n_ts/fr.ts b/i18n_ts/fr.ts index c4588df..437fd21 100644 --- a/i18n_ts/fr.ts +++ b/i18n_ts/fr.ts @@ -83,10 +83,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -107,6 +103,10 @@ Input Password + + Abnormal network + + BioAuthWidget @@ -1376,6 +1376,18 @@ SwitchUser Changer d'utilisateur + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + + + + LAN + + + + WLAN + + LoginOptionsWidget @@ -1534,10 +1546,6 @@ Log Out - - Restart - - Power Off @@ -1547,11 +1555,19 @@ - Sleep + lock - lock + Shut Down + + + + Hibernate + + + + Reboot @@ -1584,7 +1600,42 @@ SleepTime - You have rested: + You have rested + + + + + SureWindow + + Form + Forme + + + TextLabel + TextLabel + + + Cancel + + + + Confirm + + + + The following program is running to prevent the system from reboot! + + + + The following program is running to prevent the system from shutting down! + + + + The following program is running to prevent the system from suspend! + + + + The following program is running to prevent the system from hibernate! diff --git a/i18n_ts/pt.ts b/i18n_ts/pt.ts index 2de6ea7..1e49e91 100644 --- a/i18n_ts/pt.ts +++ b/i18n_ts/pt.ts @@ -83,10 +83,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -107,6 +103,10 @@ Input Password + + Abnormal network + + BioAuthWidget @@ -1376,6 +1376,18 @@ SwitchUser Mudar de utilizador + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + + + + LAN + + + + WLAN + + LoginOptionsWidget @@ -1534,10 +1546,6 @@ Log Out - - Restart - - Power Off @@ -1547,11 +1555,19 @@ - Sleep + lock - lock + Shut Down + + + + Hibernate + + + + Reboot @@ -1584,7 +1600,42 @@ SleepTime - You have rested: + You have rested + + + + + SureWindow + + Form + Formato + + + TextLabel + TextLabel + + + Cancel + + + + Confirm + + + + The following program is running to prevent the system from reboot! + + + + The following program is running to prevent the system from shutting down! + + + + The following program is running to prevent the system from suspend! + + + + The following program is running to prevent the system from hibernate! diff --git a/i18n_ts/ru.ts b/i18n_ts/ru.ts index f3ab806..84dd7fc 100644 --- a/i18n_ts/ru.ts +++ b/i18n_ts/ru.ts @@ -83,10 +83,6 @@ Verify iris or enter password to unlock - - NET Exception - - Failed to verify %1, you still have %2 verification opportunities @@ -107,6 +103,10 @@ Input Password + + Abnormal network + + BioAuthWidget @@ -1376,6 +1376,18 @@ SwitchUser Сменить пользователя + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + + + + LAN + + + + WLAN + + LoginOptionsWidget @@ -1534,10 +1546,6 @@ Log Out - - Restart - - Power Off @@ -1547,11 +1555,19 @@ - Sleep + lock - lock + Shut Down + + + + Hibernate + + + + Reboot @@ -1584,7 +1600,42 @@ SleepTime - You have rested: + You have rested + + + + + SureWindow + + Form + форма + + + TextLabel + TextLabel + + + Cancel + + + + Confirm + + + + The following program is running to prevent the system from reboot! + + + + The following program is running to prevent the system from shutting down! + + + + The following program is running to prevent the system from suspend! + + + + The following program is running to prevent the system from hibernate! diff --git a/i18n_ts/tr.ts b/i18n_ts/tr.ts index 1d46147..cc6562f 100644 --- a/i18n_ts/tr.ts +++ b/i18n_ts/tr.ts @@ -16,7 +16,7 @@ Parola - + Retry Yeniden Dene @@ -41,103 +41,103 @@ Kimlik doğrulama hatası, hala %1 kalan denemen var - + Authentication failure, Please try again - - - + + + Please try again in %1 minutes. - - - + + + Please try again in %1 seconds. + - - + Account locked permanently. - + Verify face recognition or enter password to unlock - + Press fingerprint or enter password to unlock - + Verify voiceprint or enter password to unlock - + Verify finger vein or enter password to unlock - + Verify iris or enter password to unlock - + Use the bound wechat scanning code or enter the password to unlock - - + + Password cannot be empty - + Password - + Input Password - + Login - + Failed to verify %1, please enter password to unlock - + Unable to verify %1, please enter password to unlock - + Failed to verify %1, you still have %2 verification opportunities - - NET Exception + + Abnormal network @@ -335,32 +335,32 @@ DeviceType - + FingerPrint Parmak İzi - + FingerVein Parmak Damarı - + Iris Göz - + Face Yüz - + VoicePrint Ses İzi - + QRCode @@ -409,7 +409,6 @@ DlgConnHidWifi - Connect to Hidden Wi-Fi Network @@ -463,7 +462,6 @@ DlgConnHidWifiLeap - Connect to Hidden Wi-Fi Network @@ -547,7 +545,6 @@ DlgConnHidWifiSecFast - Connect to Hidden Wi-Fi Network @@ -682,7 +679,6 @@ DlgConnHidWifiSecLeap - Connect to Hidden Wi-Fi Network @@ -781,7 +777,6 @@ DlgConnHidWifiSecPeap - Connect to Hidden Wi-Fi Network @@ -931,7 +926,6 @@ DlgConnHidWifiSecPwd - Connect to Hidden Wi-Fi Network @@ -1030,7 +1024,6 @@ DlgConnHidWifiSecTls - Connect to Hidden Wi-Fi Network @@ -1174,7 +1167,6 @@ DlgConnHidWifiSecTunnelTLS - Connect to Hidden Wi-Fi Network @@ -1309,7 +1301,6 @@ DlgConnHidWifiWep - Connect to Hidden Wi-Fi Network @@ -1413,7 +1404,6 @@ DlgConnHidWifiWpa - Connect to Hidden Wi-Fi Network @@ -1472,7 +1462,6 @@ DlgHotspotCreate - Dialog @@ -1555,7 +1544,6 @@ KeyboardWidget - KeyboardWidget @@ -1564,7 +1552,6 @@ KylinNM - kylin-nm @@ -1699,19 +1686,16 @@ LockWidget - Form - - + Date Tarih - - + Time Zaman @@ -1723,11 +1707,26 @@ SwitchUser Kullanıcı Değiştir + + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + + + + + LAN + + + + + WLAN + + LoginOptionsWidget - + Login Options @@ -1736,7 +1735,7 @@ Parola - + Identify device removed! @@ -1755,7 +1754,6 @@ OneConnForm - Form @@ -1817,7 +1815,6 @@ OneLancForm - Form @@ -1918,7 +1915,7 @@ PowerManager - + lock kilit @@ -1947,30 +1944,38 @@ Kullanıcı Değiştir - + Log Out Çıkış - - Restart - Yeniden Başlat + Yeniden Başlat - - + + + Reboot + + + + Power Off Bilgisayarı Kapat - - Suspend + + Shut Down - - Sleep + + Hibernate + + + + + Suspend @@ -1998,17 +2003,17 @@ çıkış - + Picture does not exist - + View - + You have new notification @@ -2024,8 +2029,51 @@ SleepTime - - You have rested: + + You have rested + + + + + SureWindow + + + Form + + + + + TextLabel + + + + + Cancel + + + + + Confirm + + + + + The following program is running to prevent the system from reboot! + + + + + The following program is running to prevent the system from shutting down! + + + + + The following program is running to prevent the system from suspend! + + + + + The following program is running to prevent the system from hibernate! @@ -2157,8 +2205,8 @@ - - + + lock the screen immediately Ekranı hemen kilitle @@ -2178,23 +2226,23 @@ - + Dialog for the ukui ScreenSaver. - + activated by session idle signal - - + + lock the screen and show screensaver immediately - + show screensaver immediately diff --git a/i18n_ts/zh_CN.ts b/i18n_ts/zh_CN.ts index c76dc77..4c27468 100644 --- a/i18n_ts/zh_CN.ts +++ b/i18n_ts/zh_CN.ts @@ -16,7 +16,7 @@ 使用密码认证 - + Retry 重试 @@ -45,76 +45,81 @@ 账户锁定%1分钟由于%2次错误尝试 - - - + + + Please try again in %1 minutes. 请%1分钟后再试 - - - + + + Please try again in %1 seconds. 请%1秒后再试 + - - + Account locked permanently. 账号已被永久锁定 - + Verify face recognition or enter password to unlock 验证人脸识别或输入密码解锁 - + Press fingerprint or enter password to unlock 按压指纹或输入密码解锁 - + Verify voiceprint or enter password to unlock 验证声纹或输入密码解锁 - + Verify finger vein or enter password to unlock 验证指静脉或输入密码解锁 - + Verify iris or enter password to unlock 验证虹膜或输入密码解锁 - + Input Password 输入密码 - + Failed to verify %1, please enter password to unlock 验证%1失败,请输入密码解锁 - + Unable to verify %1, please enter password to unlock 无法验证%1,请输入密码解锁 + + + Abnormal network + 网络异常 + Use the bound wechat scanning code or enter the password to log in 使用绑定的微信扫码或输入密码登录 - - + + Password cannot be empty 密码不能为空 @@ -127,7 +132,7 @@ 无法验证%1,请输入密码. - + Failed to verify %1, you still have %2 verification opportunities 验证%1失败,您还有%2次尝试机会 @@ -140,9 +145,8 @@ 生物/扫码验证失败,您还有%1次尝试机会 - NET Exception - 网络异常 + 网络异常 Password Incorrect, Please try again @@ -157,22 +161,22 @@ 请输入密码或者录入指纹 - + Authentication failure, Please try again 认证失败,请重试 - + Use the bound wechat scanning code or enter the password to unlock 使用绑定的微信扫码或输入密码解锁 - + Password 密码 - + Login 登录 @@ -197,6 +201,31 @@ 指纹验证失败,您还有%1次尝试机会 + + BatteryWidget + + + + BatteryMode + 电池模式 + + + + + PowerMode + 电源模式 + + + + Charging... + 正在充电... + + + + fully charged + 已充满电 + + BioDevices @@ -391,32 +420,32 @@ DeviceType - + FingerPrint 指纹 - + FingerVein 指静脉 - + Iris 虹膜 - + Face 人脸识别 - + VoicePrint 声纹 - + QRCode 二维码 @@ -1602,6 +1631,124 @@ WPA 及 WPA2 个人 + + EngineDevice + + + yes + + + + + no + + + + + Yes + + + + + No + + + + + %1% available, charged + + + + + Left %1h %2m (%3%) + + + + + %1% available + + + + + Left %1h %2m to full + + + + + charging (%1%) + + + + + %1 waiting to discharge (%2%) + + + + + %1 waiting to charge (%2%) + + + + + AC adapter + + + + + Laptop battery + + + + + UPS + + + + + Monitor + + + + + Mouse + + + + + Keyboard + + + + + PDA + + + + + Cell phone + + + + + Media player + + + + + Tablet + + + + + Computer + + + + + unrecognised + + + InputInfos @@ -1897,12 +2044,12 @@ - + Date 日期 - + Time 时间 @@ -1914,11 +2061,26 @@ SwitchUser 切换用户 + + + Multiple users are logged in at the same time.Are you sure you want to reboot this system? + 同时有多个用户登录系统,您确定要退出系统吗? + + + + LAN + 有线网络 + + + + WLAN + 无线局域网 + LoginOptionsWidget - + Login Options 登录选项 @@ -1931,7 +2093,7 @@ 微信 - + Identify device removed! 校验设备已移除! @@ -2139,7 +2301,7 @@ PowerManager - + lock 锁定 @@ -2168,33 +2330,37 @@ 切换用户 - + Log Out 注销 - - + Restart 重启 - + + Reboot + 重启 + + + Power Off 关机 - + Shut Down 关机 - + Hibernate 休眠 - + Suspend 睡眠 @@ -2216,6 +2382,15 @@ 屏幕保护程序未激活 + + S: + + + + this is only shown for laptops with multiple batteries + + + Screensaver @@ -2227,7 +2402,7 @@ 退出 - + Picture does not exist 图片不存在 @@ -2244,12 +2419,12 @@ 您有%1条未读消息 - + You have new notification 您有新的消息 - + View 预览 @@ -2257,9 +2432,13 @@ SleepTime - You have rested: - 您已休息: + 您已休息: + + + + You have rested + 您已休息 @@ -2275,19 +2454,38 @@ - + Cancel 取消 - + Confirm 确认 - Multiple users are logged in at the same time.Are you sure you want to reboot this system? - 同时有多个用户登录系统,您确定要退出系统吗? + 同时有多个用户登录系统,您确定要退出系统吗? + + + + The following program is running to prevent the system from suspend! + 以下程序正在运行,阻止系统进入睡眠! + + + + The following program is running to prevent the system from hibernate! + 以下程序正在运行,阻止系统进入休眠! + + + + The following program is running to prevent the system from shutting down! + 以下程序正在运行,阻止系统关机! + + + + The following program is running to prevent the system from reboot! + 以下程序正在运行,阻止系统重启! @@ -2441,8 +2639,8 @@ - - + + lock the screen immediately 马上锁定屏幕 @@ -2462,23 +2660,23 @@ - + Dialog for the ukui ScreenSaver. - + activated by session idle signal - - + + lock the screen and show screensaver immediately - + show screensaver immediately diff --git a/screensaver/CMakeLists.txt b/screensaver/CMakeLists.txt index 7bce0d7..834e258 100644 --- a/screensaver/CMakeLists.txt +++ b/screensaver/CMakeLists.txt @@ -29,7 +29,7 @@ qt5_wrap_cpp(screensaver_SRC cyclelabel.h scconfiguration.h sleeptime.h - weathermanager.h + ../src/weathermanager.h ../src/networkwatcher.h ) set(screensaver_SRC @@ -41,18 +41,85 @@ set(screensaver_SRC cyclelabel.cpp scconfiguration.cpp sleeptime.cpp - weathermanager.cpp + ../src/weathermanager.cpp ../src/networkwatcher.cpp ) add_executable(ukui-screensaver-default ${screensaver_SRC}) target_link_libraries(ukui-screensaver-default Qt5::Core Qt5::Widgets Qt5::X11Extras Qt5::Xml Qt5::Network ${EXTRA_LIBS}) +qt5_add_resources(screensaver_Plugin_SRC + default.qrc + ) + +qt5_wrap_cpp(screensaver_Plugin_SRC + chinesedate.h + screensaver.h + mbackground.h + cyclelabel.h + scconfiguration.h + sleeptime.h + ../src/weathermanager.h + ../src/networkwatcher.h + customplugin.h + screensaverplugin.h + ) +set(screensaver_Plugin_SRC + ${screensaver_Plugin_SRC} + chinesedate.cpp + mbackground.cpp + screensaver.cpp + cyclelabel.cpp + scconfiguration.cpp + sleeptime.cpp + ../src/weathermanager.cpp + ../src/networkwatcher.cpp + customplugin.cpp + ) + +add_library(screensaver-default SHARED ${screensaver_Plugin_SRC}) +target_link_libraries(screensaver-default Qt5::Core Qt5::Widgets Qt5::X11Extras Qt5::Xml Qt5::Network ${EXTRA_LIBS}) + +qt5_add_resources(Screensaver_SRC + default.qrc + ) + +qt5_wrap_cpp(Screensaver_SRC + chinesedate.h + screensaver.h + mbackground.h + cyclelabel.h + scconfiguration.h + sleeptime.h + ../src/weathermanager.h + ../src/networkwatcher.h + ) +set(Screensaver_SRC + ${screensaver_Plugin_SRC} + chinesedate.cpp + mbackground.cpp + screensaver.cpp + cyclelabel.cpp + scconfiguration.cpp + sleeptime.cpp + ../src/weathermanager.cpp + ../src/networkwatcher.cpp + ) + +add_library(Screensaver STATIC ${Screensaver_SRC}) +target_link_libraries(Screensaver Qt5::Core Qt5::Widgets Qt5::X11Extras Qt5::Xml Qt5::Network ${EXTRA_LIBS}) + install(TARGETS ukui-screensaver-default + screensaver-default DESTINATION lib/ukui-screensaver) install(FILES language/screensaver-zh_CN.ini language/screensaver-en_US.ini + language/screensaver-bo_CN.ini language/screensaver-jd.ini DESTINATION share/ukui-screensaver/language) + +install(FILES + screensaverplugin.h + DESTINATION include/ukui-screensaver/) diff --git a/screensaver/assets/default.qss b/screensaver/assets/default.qss index 2abe225..868e216 100644 --- a/screensaver/assets/default.qss +++ b/screensaver/assets/default.qss @@ -38,10 +38,10 @@ QLabel#authorLabel { color: #ffffff; } QLabel#myText{ - font-size:18px; + font-size:24px; border-radius: 6px; background: rgba(255, 255, 255, 82%); - padding: 24px 48px 24px 48px; + padding: 24px 24px 24px 24px; color: #000000; } QPushButton{ diff --git a/screensaver/customplugin.cpp b/screensaver/customplugin.cpp new file mode 100644 index 0000000..afacc06 --- /dev/null +++ b/screensaver/customplugin.cpp @@ -0,0 +1,22 @@ +#include "customplugin.h" +#include "screensaver.h" + +CustomPlugin::CustomPlugin(QObject *parent):QObject(parent) +{ + +} + +QString CustomPlugin::name() const +{ + return "screensaver-default"; +} + +QWidget* CustomPlugin::createWidget(bool isScreensaver,QWidget* parent) +{ + return new Screensaver(isScreensaver,parent); +} + +QString CustomPlugin::displayName() const +{ + return "screensaver-default"; +} diff --git a/screensaver/customplugin.h b/screensaver/customplugin.h new file mode 100644 index 0000000..2d041f7 --- /dev/null +++ b/screensaver/customplugin.h @@ -0,0 +1,21 @@ +#ifndef CUSTOMPLUGIN_H +#define CUSTOMPLUGIN_H + +#include "screensaverplugin.h" +#include + +class CustomPlugin : public QObject, ScreensaverPlugin +{ + Q_OBJECT + //声明QT识别的唯一标识符 + Q_PLUGIN_METADATA(IID "org.ukui.screensaver.screensaver-default1.0.0") + //声明实现的插件接口 + Q_INTERFACES(ScreensaverPlugin) +public: + CustomPlugin(QObject* parent = 0); + QString name() const override; + QWidget* createWidget(bool isScreensaver,QWidget* parent) override; + QString displayName() const override; +}; + +#endif // CUSTOMPLUGIN_H diff --git a/screensaver/language/screensaver-bo_CN.ini b/screensaver/language/screensaver-bo_CN.ini new file mode 100644 index 0000000..2405521 --- /dev/null +++ b/screensaver/language/screensaver-bo_CN.ini @@ -0,0 +1,84 @@ +[1] +FL=སྐྱེ་བོ་ཡོན་ཏན་ཡོད་མེད་པའི།། བླང་དོར་བློ་གྲོས་ལྡན་པ་མཁས།། +SL=རྡུལ་དང་འདྲེས་པའི་ལྕགས་ཕྱེ་རྣམས།། ཁབ་ལེན་རྡོ་ཡིས་ལེན་པར་ཤེས།། +[2] +FL=ལེགས་བཤད་མཁས་པའི་བློ་གྲོས་ཀྱིས།། གོ་ཡི་བླུན་པོས་དེ་ལྟ་མིན།། +SL=ཉི་མའི་འོད་ཟེར་ཤར་བ་ན།། འབྱུང་པོའི་བྱ་རྣམས་ལོང་བར་འགྱུར།། +[3] +FL=བློ་ཆུང་གྲོས་གཉིས་འཁྲུགས་པའི་ཚེ།། བློ་ལྡན་ཐབས་ཀྱིས་བདེ་བར་གསོ།། +SL=ཆུ་ཀླུང་རྙོག་པས་ཆུད་གཟན་པ།། ཆུ་དྭངས་ནོར་བུས་དྭངས་པར་བྱེད།། +[4] +FL=ཤེས་རབ་ལྡན་པ་མགོ་བསྐོར་ཡང་།། བྱ་བའི་ཆ་ལ་རྨོངས་མི་འགྱུར།། +SL=སྲོག་ཆགས་གྲོག་མ་མིག་མེད་ཀྱང་།། མིག་ལྡན་གཞན་ལས་ལྷག་པར་མགྱོགས།། +[5] +FL=བླུན་པོས་ཡོན་ཏན་ཁར་འབྱིན་ཏེ།། མཁས་པས་ཡོན་ཏན་ཁོང་དུ་སྦེད།། +SL=སོག་མ་ཆུ་ཡི་སྟེང་དུ་འཕྱོ།། ནོར་བུ་སྟེང་དུ་བཞག་ཀྱང་འབྱིང་།། +[6] +FL=མཁས་པ་ཡོན་ཏན་དཔག་མེད་ཀྱང་།། གཞན་གྱི་ཡོན་ཏན་ཆུང་ངུའང་ལེན།། +SL=དེ་ལྟར་རྒྱུན་དུ་སྤྱད་པ་ཡིས།། མྱུར་དུ་ཐམས་ཅད་མཁྱེན་པར་འགྲོ།། +[7] +FL=མཁས་པ་སློབ་པའི་དུས་ན་སྡུག། བདེ་བར་སྡོད་ལ་མཁས་མི་སྲིད།། +SL=བདེ་བ་ཆུང་ལ་ཆགས་པ་དེས།། ཆེན་པོའི་བདེ་བ་ཐོབ་མི་སྲིད།། +[8] +FL=དམ་པའི་ཡོན་ཏན་སྦས་གྱུར་ཀྱང་།། འཇིག་རྟེན་ཀུན་ལ་ཁྱབ་པར་གསལ།། +SL=སྣ་མའི་མེ་ཏོག་ལེགས་བཀབ་ཀྱང་།། དྲི་ཞིམ་ཀུན་ཏུ་ཁྱབ་པར་འགྱུར།། +[9] +FL=བློ་དང་ལྡན་ན་ཉམ་ཆུང་ཡང་།། སྟོབས་ལྡན་དགྲ་བོས་ཅི་བྱར་ཡོད།། +SL=རི་དྭགས་རྒྱལ་པོ་སྟོབས་ལྡན་ཡང་།། རི་བོང་བློ་དང་ལྡན་པས་བསད།། +[10] +FL=བླུན་པོ་བྱ་བ་ལ་སྦྱར་ན།། དོན་ཉམས་དེ་ཡང་ཉམས་པར་འགྱུར།། +SL=ཝ་སྐྱེས་རྒྱལ་པོར་བསྐོས་པ་ཡིས།། འཁོར་སྡིག་རང་ཡང་བསད་ཅེས་གྲགས།། +[11] +FL=ཕན་དང་མི་ཕན་མི་དཔྱོད་ཅིང་།། བློ་དང་ཐོས་པ་མི་སྒྲུབ་པར།། +SL=ལྟོ་འགྲངས་འབའ་ཞིག་དོན་གཉེར་བ།། སྤུ་མེད་པ་ཡི་ཕག་པ་ཡིན།། +[12] +FL=ཡོན་ཏན་ཆུང་རྣམས་ང་རྒྱལ་ཆེ།། མཁས་པར་གྱུར་ན་དུལ་བར་གནས།། +SL=ཆུ་ཕྲན་རྟག་ཏུ་ཀུ་ཅོ་ཆེ།། རྒྱ་མཚོས་ཅ་ཅོ་ག་ལ་སྒྲོག། +[13] +FL=དམ་པ་དུལ་བས་རང་གཞན་སྐྱོང་།།ངན་པ་རེངས་པས་རང་གཞན་སྡུག། +SL=འབྲས་ལྡན་ཤིང་གིས་རང་གཞན་སྲུང་།། ཤིང་སྐམ་རེངས་པས་རང་གཞན་སྲེག། +[14] +FL=ཧ་ཅང་གཡོ་སྒྱུ་མང་དྲགས་ན།། རེ་ཞིག་གྲུབ་ཀྱང་མཐའ་མར་བརླགས།། +SL=གཟིག་ལྤགས་བཀབ་པའི་བོང་བུ་ཡིས།། ལོ་ཏོག་ཟོས་མཐར་གཞན་གྱི་བསད།། +[15] +FL=གཡོ་ཅན་བཟང་བོའི་ཚུལ་བཟུང་ནས།། ཕྱི་ནས་དོན་ལ་བསླུ་བ་ཡོད།།རི་དྭགས་རྔ་མ་བསྟན་ནས་ནི།། ཁྲེལ་འདས་བོང་བུའི་ཤ་དག་འཚོང་།། +SL=མང་བོ་གཅིག་ཏུ་བློ་མཐུན་ན།། ཉམ་ཆུང་གིས་ཀྱང་དོན་ཆེན་འགྲུབ།།སྲོག་ཆགས་གྲོག་མའི་ཚོགས་འདུས་པས།།སེང་གེའི་ཕྲུ་གུ་བསད་ཅེས་གྲགས།། +[16] +FL=བདག་ཉིད་དཔོན་དུ་བསྐོས་གྱུར་ན།། དེ་ཡི་བྱ་བ་ཤེས་པ་དཀོན།། +SL=གཞན་ལ་ལྟ་བའི་མིག་ཡོད་ཀྱང་།། རང་ཉིད་བལྟ་ན་མེ་ལོང་དགོས།། +[17] +FL=རང་གིས་ངན་སྤྱོད་མ་བྱས་ན།། བརྒྱ་བྱིན་གྱིས་ཀྱང་སྨན་མི་ནུས།། +SL=ཆུ་མིག་རང་ཉིད་མ་བསྐམས་ན།། ས་ཡིས་མནན་པས་ག་ལ་ཐུབ།། +[18] +FL=བློ་ལྡན་བྱ་བ་ཅུང་ཟད་ཀྱང་།། རྒྱུན་དུ་གྲོས་ཀྱིས་བསྒྲུབ་པར་བྱ།། +SL=གྲུབ་པར་གྱུར་ན་ལྟ་ཅི་སྨྲོས།། མ་གྲུབ་ན་ཡང་མཛེས་པའི་རྒྱུ།། +[19] +FL=རང་ལ་དགོས་པའི་བསྟན་བཅོས་རྣམས།། ཉི་མ་རེ་ལ་ཚིག་རེ་ཟུངས།། +SL=གྲོག་མཁར་དང་ནི་སྦྲང་རྩི་ལྟར།། རིང་བོར་མི་ཐོགས་མཁས་པར་འགྱུར།། +[20] +FL=མཁས་པ་ཡོན་ཏན་མཛོད་འཛིན་པ།། དེ་དག་ལེགས་བཤད་རིན་ཆེན་སྡུད།། +SL=རྒྱ་མཚོ་ཆེན་པོ་ཆུ་བོའི་གཏེར།། ཡིན་ཕྱིར་ཆུ་ཕྲན་ཐམས་ཅད་འབབ།། +[21] +FL=ཡོན་ཏན་ལྡན་ན་སྐྱེ་བོ་ཀུན།། མ་བསྡུས་པར་ཡང་རང་ཉིད་འདུ།། +SL=དྲི་ལྡན་མེ་ཏོག་རྒྱང་རིང་ཡང་།། བུང་བ་སྤྲིན་གྱི་ཚོགས་བཞིན་འཁོར།། +[22] +FL=བློ་གྲོས་ལྡན་པ་གཉིས་བགྲོས་ན།། བློ་གྲོས་ལེགས་པ་གཞན་འབྱུང་སྲིད།། +SL=ཡུང་བ་དང་ནི་ཚ་ལེ་ལས།། ཁ་དོག་གཞན་ཞིག་སྐྱེ་བར་འགྱུར།། +[23] +FL=ཐབས་ལ་མཁས་ན་ཆེན་པོ་ཡང་།། བྲན་དུ་བཀོལ་བར་ག་ལ་དཀའ།། +SL=མཁའ་ལྡིང་མཐུ་རྩལ་ཆེ་ན་ཡང་།། གོས་སེར་ཅན་གྱི་བཞོན་པར་གྱུར།། +[24] +FL=བློ་དང་ལྡན་ན་མ་སྨྲས་ཀྱང་།། རྣམ་འགྱུར་ཉིད་ལས་བསམ་པ་གོ། +SL=བལ་བོའི་སེའུ་མ་ཟོས་ཀྱང་།། ཁ་དོག་ཉིད་ལས་བྲོ་བ་ཤེས།། +[25] +FL=དམ་པ་རྒྱང་ན་གནས་ན་ཡང་།། འཁོར་འདབས་ཕན་པས་རིང་ནས་སྐྱོང་།། +SL=མཁའ་ལ་སྤྲིན་ཆེན་འཁྲིགས་པ་ཡིས།། ས་ཡི་ལོ་ཏོག་ཁྱད་པར་འཕེལ།། +[26] +FL=དམ་པ་སྡིག་པ་ཆུང་ཡང་སྤོང་།། དམན་རྣམས་ཆེན་པོའང་དེ་ལྟ་མིན།། +SL=ཞོ་ལ་རྡུལ་ཕྲན་འབྱར་བ་སེལ།།ཆང་ལ་ཕབ་ཀྱང་ལྷག་པར་འདེབས།། +[27] +FL=རྒྱལ་པོ་རང་ཡུལ་ཆེ་བ་ཙམ།། དམ་པ་གང་དུ་ཕྱིན་པར་བཀུར།། +SL=མེ་ཏོག་ཕལ་ཆེར་ཉིན་རེའི་རྒྱན།། གཙུག་གི་ནོར་བུ་གང་དུའང་མཆོད།། +[28] +FL=རིག་པ་ནངས་པར་འཆི་ཡང་བསླབ།། ཚེ་འདིར་མཁས་པར་མ་གྱུར་ཀྱང་།། +SL=སྐྱེ་བ་ཕྱི་མར་བཅོལ་བ་ཡི།། ནོར་ལ་རང་ཉིད་ལེན་དང་མཚུངས།། diff --git a/screensaver/language/screensaver-zh_CN.ini b/screensaver/language/screensaver-zh_CN.ini index f8befd1..c921ed2 100644 --- a/screensaver/language/screensaver-zh_CN.ini +++ b/screensaver/language/screensaver-zh_CN.ini @@ -1,161 +1,168 @@ [1] -FL=因为有悔,所以披星戴月 -SL=因为有梦,所以奋不顾身 -author= +OL=天生我材必有用,千金散尽还复来。 +author=李白《将进酒》 [2] -OL=大直若屈,大巧若拙,大辩若讷。 -author=《老子》 +OL=新时代的伟大成就是党和人民一道拼出来、干出来、奋斗出来的。 +author=习近平 [3] -OL=博学之,审问之,慎思之,明辨之,笃行之。 -author=《礼记》 +OL=莫愁前路无知己,天下谁人不识君。 +author=高适《别董大二首》 [4] -OL=兼听则明,偏听则暗。 -author=《资治通鉴》 +OL=莫听穿林打叶声,何妨吟啸且徐行。 +author=苏轼《定风波》 [5] -FL=一花一世界,一叶一追寻。 -SL=一曲一场叹,一生为一人。 -author=威廉·布莱克《天真的预言》 +OL=党用伟大奋斗创造了百年伟业,也一定能用新的伟大奋斗创造新的伟业。 +author=习近平 [6] -FL=月光下,你带着笑地向我步来, -SL=月色与雪色之间,你是第三种绝色。 -author=余光中 +OL=巧言令色,鲜矣仁! +author=《论语》 [7] -OL=不要问我心里有没有你,我余光中都是你。 -author=余光中 +FL=与君初相识,犹如故人归。 +SL=天涯明月新,朝暮最相思。 +author=杜牧《会友》 [8] -FL=你要是愿意,我就永远爱你, -SL=你要是不愿意,我就永远相思。 -author=王小波 +FL=一个饱经沧桑而初心不变的党,才能基业常青; +SL=一个铸就辉煌仍勇于自我革命的党,才能无坚不摧。 +author=习近平 [9] -FL=草在结它的种子,风在摇它的叶子。 -SL=我们站着,不说话,就十分美好。 -author=顾城 +OL=见贤思齐焉,见不贤而内自省也。 +author=《论语》 [10] -OL=见到你,我觉得多少适应了这个世界。 -author=村上春树 +OL=为政以德,譬如北辰,居其所而众星共之。 +author=《论语》 [11] -OL=不须耳鬓常厮伴,一笑低头意已倾。 -author=朱生豪 +FL=道阻且长,行则将至。前进道路上,无论是风高浪急还是惊涛骇浪, +SL=人民永远是我们最坚实的依托、最强大的底气。 +author=习近平 [12] -FL=君臣一梦,今古空名。 -SL=但远山长,云山乱,晓山青。 -author=苏轼 +OL=知彼知己,百战不殆。 +author=《孙子兵法》 [13] -FL=心如规矩,志如尺衡, -SL=平静如水,正直如绳。 -author=严遵 +OL=人患不知其过,既知之,不能改,是无勇也。 +author=韩愈《五箴》 [14] -OL=近水知鱼性,近山识鸟音。 -author=周希陶 +FL=新征程是充满光荣和梦想的远征。蓝图已经绘就,号角已经吹响。 +SL=我们要踔厉奋发、勇毅前行,努力创造更加灿烂的明天。 +author=习近平 [15] -OL=此处果有可乐,我即别无所思。 -author=林语堂 +OL=万物并育而不相害,道并行而不相悖 +author=《礼记·中庸》 [16] -FL=心之所向,素履以往, -SL=生如逆旅,一苇以航。 -author=七堇年《尘曲》 +OL=自信人生二百年,会当水击三千里 +author=毛泽东《七古·残句》 [17] -FL=你说,我们就山居于此吧, -SL=胭脂用尽时,桃花就开了。 -author=与谢野晶子 +OL=我们完全有信心有能力在新时代新征程创造令世人刮目相看的新的更大奇迹。 +author=习近平 [18] -OL=世间所有的相遇,都是久别重逢。 -author=白落梅 +OL=青春虚度无所成,白首衔悲亦何及。 +author=权德舆《放歌行》 [19] -OL=浮云一别后,流水十年间。 -author=韦应物《淮上喜会梁川故人》 +OL=劳动模范是民族的精英、人民的楷模,是共和国的功臣。 +author=习近平 [20] -OL=最是人间留不住,朱颜辞镜花辞树。 -author=王国维《蝶恋花》 +FL=当前最重要的任务是撸起袖子加油干, +SL=一步一个脚印把党的二十大作出的重大决策部署付诸行动、见之于成效。 +author=习近平 [21] -OL=行到水穷处,坐看云起时。 -author=王维 +FL=广大人民群众坚持爱国奉献,无怨无悔,让我感到千千万万普通人最伟大, +SL=同时让我感到幸福都是奋斗出来的。 +author=2018新年贺词 习近平 [22] -OL=我有一瓢酒,可以慰风尘。 -author=韦应物 +OL=中华文化既是历史的、也是当代的,既是民族的、也是世界的。 +author=习近平 [23] -OL=墙头马上遥相顾,一见知君即断肠。 -author=白居易 +OL=没有坚实的物质技术基础,就不可能全面建成社会主义现代化强国。 +author=习近平 [24] -OL=人生到处知何似,应似飞鸿踏雪泥。 -author=《和子由渑池怀旧》 +OL=我们党没有自己的特殊利益,党在任何时候都是把群众利益放在第一位。 +author=习近平 [25] -OL=粗缯大布裹生涯,腹有诗书气自华。 -author=《和董传留别》 +OL=知者行之始。行者知之成。 +author=王阳明《传习录·卷上·门人陆澄录》 [26] -OL=清风徐来,水波不兴。 -author=《前赤壁赋》 +FL=江山就是人民,人民就是江山。 +SL=中国共产党领导人民打江山、守江山,守的是人民的心,治国有常,利民为本。 +author=习近平 [27] -OL=我有斗酒,藏之久矣,以待子不时之须。 -author=《后赤壁赋》 +OL=此心不动,随机而动。 +author=王阳明 [28] -FL=若是有缘,千山暮雪,万里层云,终会重逢。 -SL=若是无缘,自此一去,天涯海角,再难相会。 -author=白落梅《你若安好便是晴天》 +OL=你未看此花时,此花与汝心同归于寂。 +author=《传习录·卷下·门人黄省曾录》 [29] -FL=愿你一生努力,一生被爱。 -SL=想要的都拥有,得不到的都释怀。 -author=八月长安 +FL=时代呼唤我们,人民期待着我们, +SL=唯有矢志不渝、笃行不怠,方能不负时代、不负人民。 +author=习近平 [30] -OL=凌晨四点醒来,发现海棠花未眠。 -author=川端康成 +OL=省察是有事时存养,存养是无事时省察。 +author=王阳明《传习录》 [31] -OL=无路可走的时候,就不断回到原点。 -author=东野圭吾 +OL=路漫漫其修远兮,吾将上下而求索。 +author=《离骚》 [32] -OL=你要批评指点四周的风景,你首先要爬上屋顶。 -author=歌德 +OL=当代中国青年生逢其时,施展才干的舞台无比广阔,实现梦想的前景无比光明。 +author=习近平 [33] -OL=只有流过血的手指,才能弹出世间的绝唱。 -author=泰戈尔 +FL=解决台湾问题是中国人自己的事,要由中国人来决定。 +SL=国家统一、民族复兴的历史车轮滚滚向前,祖国完全统一一定要实现,也一定能够实现。 +author=习近平 [34] -FL=幸亏时光不会倒流, -SL=否则万物一定会朝旧岁月里疾步奔跑。 -author=《迷楼》 +OL=悲莫悲兮生别离,乐莫乐兮新相知。 +author=《九歌·少司命》 [35] -FL=我看到那些岁月如何奔驰, -SL=挨过了冬季,便迎来了春天。 -author=《瓦尔登湖》 +OL=风飒飒兮木萧萧,思公子兮徒离忧。 +author=《九歌·山鬼》 [36] -FL=整个世界展现在我们面前, -SL=期待着我们去创造,而不是去重复。 -author=毕加索 +OL=善守者,藏于九地之下,善攻者,动于九天之上。 +author=《孙子兵法》 [37] -FL=不必太纠结于当下,也不必太忧虑未来, -SL=当你经历过一些事情的时候,眼前的风景已经和从前不一样了。 -author=村上春树 +FL=我们正意气风发迈向全面建设社会主义现代化国家新征程, +SL=向第二个百年奋斗目标进军,以中国式现代化全面推进中华民族伟大复兴。 +author=习近平 [38] -OL=三更梦醒,你是檐上落下的星。 -author=佚名 +OL=善战者,致人而不致于人。 +author=《孙子兵法·虚实第六》 [39] -OL=我将永远忠于自己,披星戴月的奔向理想与自由。 -author=佚名 +OL=乱生于治,怯生于勇,弱生于强。 +author=《孙子兵法·兵势第五》 [40] -OL=有一天,我看了43次日落! -author=《小王子》 +FL=中国式现代化是中国共产党和中国人民长期实践探索的成果, +SL=是一项伟大而艰巨的事业。惟其艰巨,所以伟大;惟其艰巨,更显光荣。 +author=习近平 [41] -OL=当太阳升到最高点的时候,影子就不见了。 -author=佚名 +OL=不战而屈人之兵,善之善者也。 +author=《孙子兵法·谋攻第三》 [42] -OL=拯救地球好累,虽然有些疲惫但我还是会。 -author=《超人不会飞》 +OL=天行健,君子以自强不息。 +author=《周易.乾卦》 [43] -OL=陌上花开,可缓缓归矣 -author=佚名 +FL=中国开放的大门只会越来越大。我们将坚定不移全面深化改革开放, +SL=坚定不移推动高质量发展,以自身发展为世界创造更多机遇。 +author=习近平 [44] -OL=别慌,月亮也正在大海某处迷茫 -author=佚名 +OL=积善之家,必有余庆;积不善之家,必有余殃。 +author=《周易.坤卦》 [45] -OL=夏天到了,春天的不甘该统统放下了 -author=佚名 +OL=穷则变,变则通,通则久。 +author=《周易.系辞下》 [46] -OL=保持热爱,奔赴山海 -author=佚名 +FL=我们历来主张,人类的前途命运应该由世界各国人民来把握和决定。 +SL=只要共行天下大道,各国就能够和睦相处、合作共赢,携手创造世界的美好未来。 +author=习近平 [47] -FL=你好,是故事的开始, -SL=你要好好的,是故事的结局。 -author=佚名 +OL=天若有情天亦老,人间正道是沧桑 +author=毛泽东《七律·人民解放军占领南京》 [48] -OL=工欲善其事,必先利其器。 -author=《孔子》 +OL=仰天大笑出门去,我辈岂是蓬蒿人。 +author=李白《南陵别儿童入京》 +[49] +OL=落叶秋风生渭水,落叶满长安。 +author=贾岛《忆江上吴处士》 +[50] +OL=人生来是精神所附丽的物质,免不掉物质所常有的惰性。 +author=朱光潜《朝抵抗力最大的路径走》 +[51] +FL=能朝抵抗力最大的路径走,是人的特点。 +SL=人在能尽量发挥这特点时,就足见出他有富裕的生活力。 +author=朱光潜《朝抵抗力最大的路径走》 diff --git a/screensaver/main.cpp b/screensaver/main.cpp index eb40b19..c7d725f 100644 --- a/screensaver/main.cpp +++ b/screensaver/main.cpp @@ -34,7 +34,6 @@ #include "config.h" -#define WORKING_DIRECTORY "/usr/share/ukui-screensaver" bool bControlFlg = false;//是否控制面板窗口 int main(int argc, char *argv[]) @@ -44,19 +43,11 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif QApplication a(argc, argv); - prctl(PR_SET_PDEATHSIG, SIGHUP); - //加载翻译文件 - QString locale = QLocale::system().name(); - QTranslator translator; - QString qmFile = QString(WORKING_DIRECTORY"/i18n_qm/%1.qm").arg(locale); - translator.load(qmFile); - a.installTranslator(&translator); - qDebug() << "load translation file " << qmFile; - + prctl(PR_SET_PDEATHSIG, SIGHUP); QCommandLineParser parser; QString windowId; - Screensaver s; + Screensaver s(false); XWindowAttributes xwa; parser.setApplicationDescription("Test helper"); @@ -88,7 +79,7 @@ int main(int argc, char *argv[]) s.winId(); s.windowHandle()->setParent(window); XGetWindowAttributes (QX11Info::display(), wid, &xwa); - +/* #ifndef USE_INTEL XClassHint ch; ch.res_name = NULL; @@ -96,10 +87,9 @@ int main(int argc, char *argv[]) XGetClassHint (QX11Info::display(), wid, &ch); if(ch.res_name && strcmp(ch.res_name,"ukui-control-center")==0){ bControlFlg = true; - s.addClickedEvent(); } #endif - +*/ //获取屏保所在屏幕对应的缩放比例。 for(auto screen : QGuiApplication::screens()) { diff --git a/screensaver/screensaver.cpp b/screensaver/screensaver.cpp index e481abe..b67a12e 100644 --- a/screensaver/screensaver.cpp +++ b/screensaver/screensaver.cpp @@ -48,14 +48,16 @@ #include #include #include +#include #include +#include "../src/weathermanager.h" +#include "commonfunc.h" #include "screensaver.h" #include #include #include #include -#include "commonfunc.h" #include "config.h" #define TIME_TYPE_SCHEMA "org.ukui.control-center.panel.plugins" @@ -66,11 +68,13 @@ #define KEY_MESSAGE_SHOW_ENABLED "show-message-enabled" #define KEY_HOURSYSTEM "hoursystem" #define KEY_DATE_FORMAT "date" +#define WORKING_DIRECTORY "/usr/share/ukui-screensaver" QTime Screensaver::m_currentTime = QTime::currentTime(); extern bool bControlFlg; -Screensaver::Screensaver(QWidget *parent): +Screensaver::Screensaver(bool isscreensaver,QWidget *parent): + isScreensaver(isscreensaver), QWidget(parent), switchTimer(nullptr), backgroundPath(""), @@ -93,9 +97,16 @@ Screensaver::Screensaver(QWidget *parent): hasChanged(false), process(nullptr), screenLabel(nullptr), - respondClick(false), - m_weatherManager(new WeatherManager(this)) + respondClick(false) { + //加载翻译文件 + QString locale = QLocale::system().name(); + QTranslator translator; + QString qmFile = QString(WORKING_DIRECTORY"/i18n_qm/%1.qm").arg(locale); + translator.load(qmFile); + qApp->installTranslator(&translator); + qDebug() << "load translation file " << qmFile; + installEventFilter(this); // setWindowFlags(Qt::X11BypassWindowManagerHint); setUpdateCenterWidget(); @@ -117,7 +128,7 @@ Screensaver::Screensaver(QWidget *parent): m_background = new MBackground(); QString backgroundFile = configuration->getDefaultBackground(); - background = QPixmap(backgroundFile); + background = loadFromFile(backgroundFile); QList labelList = this->findChildren(); for(int i = 0;isetStyleSheet(QString("font-size:5px;border-radius: 2px;background: %1;color: %2;padding: 4px 8px 4px 8px;border-width: 1px;border-style: solid;border-color:%3;") \ .arg(stringColor).arg(textString).arg(borderString)); else - myTextLabel->setStyleSheet(QString("font-size:18px;border-radius: 6px;background: %1;color: %2;padding: 24px 48px 24px 48px;border-width: 1px;border-style: solid;border-color:%3;") \ + myTextLabel->setStyleSheet(QString("font-size:24px;border-radius: 6px;background: %1;color: %2;padding: 24px 24px 24px 24px;border-width: 1px;border-style: solid;border-color:%3;") \ .arg(stringColor).arg(textString).arg(borderString)); } } @@ -367,7 +378,7 @@ bool Screensaver::eventFilter(QObject *obj, QEvent *event) #ifndef USE_INTEL if(obj == this){ if(event->type()==QEvent::MouseButtonPress){ - if(respondClick){ + if(!isScreensaver){ if(!process){ process = new QProcess(this); } @@ -495,7 +506,7 @@ void Screensaver::resizeEvent(QResizeEvent */*event*/) { float scale = 1.0; scale = (float)width()/1920; - if(width() < 600 || height()<400){//当显示在控制面板上时,字体缩小三倍。 + if((width() < 600 || height()<400) && !isScreensaver){//当显示在控制面板上时,字体缩小三倍。 if(flag == 0) { QList labelList = this->findChildren(); @@ -651,7 +662,10 @@ void Screensaver::setUpdateCenterWidget() lang=lang.split('.')[0]; qDebug()<<"langStr = "<beginGroup(QString::number(index)); if(qsettings->contains("OL")){ - centerlabel1->setText(qsettings->value("OL").toString()); + if(qsettings->value("OL").typeName() == "QString") + centerlabel1->setText(qsettings->value("OL").toString()); + else + centerlabel1->setText(qsettings->value("OL").toStringList().join(' ')); centerlabel2->hide(); #ifndef USE_INTEL authorlabel->setText(qsettings->value("author").toString()); @@ -798,8 +815,14 @@ void Screensaver::updateCenterWidget(int index) } else if(qsettings->contains("FL")) { - centerlabel1->setText(qsettings->value("FL").toString()); - centerlabel2->setText(qsettings->value("SL").toString()); + if(qsettings->value("FL").typeName() == "QString") + centerlabel2->setText(qsettings->value("FL").toString()); + else + centerlabel2->setText(qsettings->value("FL").toStringList().join(' ')); + if(qsettings->value("SL").typeName() == "QString") + centerlabel2->setText(qsettings->value("SL").toString()); + else + centerlabel2->setText(qsettings->value("SL").toStringList().join(' ')); centerlabel2->show(); #ifndef USE_INTEL authorlabel->setText(qsettings->value("author").toString()); @@ -1038,7 +1061,7 @@ void Screensaver::updateDate() timer->setTimerType(Qt::PreciseTimer); connect(timer, SIGNAL(timeout()), this, SLOT(updateTime())); } - timer->start(800); + timer->start(500); updateTime(); } @@ -1078,15 +1101,19 @@ void Screensaver::updateTime() m_currentTime = QTime::currentTime(); #else - if(timeType == 12) - this->dateOfLocaltime->setText(QDateTime::currentDateTime().toString("A hh:mm")); - else - this->dateOfLocaltime->setText(QDateTime::currentDateTime().toString("hh:mm")); + QDateTime curDateTime = QDateTime::currentDateTime(); + if (m_lastDateTime.isNull() || qAbs(curDateTime.secsTo(m_lastDateTime)) >=1) { + if(timeType == 12) + this->dateOfLocaltime->setText(curDateTime.toString("A hh:mm")); + else + this->dateOfLocaltime->setText(curDateTime.toString("hh:mm")); - if(dateType == "cn") - this->dateOfDay->setText(QDate::currentDate().toString("yyyy/MM/dd ddd")); - else - this->dateOfDay->setText(QDate::currentDate().toString("yyyy-MM-dd ddd")); + if(dateType == "cn") + this->dateOfDay->setText(curDateTime.date().toString("yyyy/MM/dd ddd")); + else + this->dateOfDay->setText(curDateTime.date().toString("yyyy-MM-dd ddd")); + m_lastDateTime = curDateTime; + } if(sleepTime){ if(!sleepTime->setTime(QDateTime::currentDateTime())){ @@ -1107,7 +1134,7 @@ void Screensaver::updateBackground() { QString path = m_background->getRand(); if(!path.isEmpty() && ispicture(path)){ - background = QPixmap(path); + background = loadFromFile(path); hasChanged=true; isMovie(); } @@ -1122,7 +1149,7 @@ void Screensaver::setRandomText() cycleLabel = new QLabel(this); cycleLabel->setFixedSize(16,16); layout->addWidget(cycleLabel); - layout->setSpacing(16); + layout->setSpacing(8); myTextLabel = new QLabel(myTextWidget); myTextLabel->setObjectName("myText"); // myTextLabel->setBackgroundRole(QPalette::Base); @@ -1147,7 +1174,7 @@ void Screensaver::setRandomText() // .arg(stringColor).arg(textString).arg(borderString)); blur_Num = configuration->getBlurNumber(); curStyle = configuration->getcurStyle(); - qDebug()<<"cu人Style= "<setStyleSheet(QString("QLabel{background: rgba(0, 0, 0, %1); color:#FFFFFF; border-radius:16px}").arg(blur_Num * 0.01)); cycleLabel->setStyleSheet(QString("QLabel{background: rgba(0, 0, 0, %1); color:#FFFFFF; border-radius:8px}").arg(blur_Num * 0.01)); @@ -1214,7 +1241,10 @@ void Screensaver::setCenterWidget() authorlabel = new QLabel(""); } else if(qsettings->contains("OL")){ - centerlabel1 = new QLabel(qsettings->value("OL").toString()); + if(qsettings->value("OL").typeName() == "QString") + centerlabel1 = new QLabel(qsettings->value("OL").toString()); + else + centerlabel1 = new QLabel(qsettings->value("OL").toStringList().join(' ')); centerlabel2 = new QLabel(""); centerlabel2->hide(); #ifndef USE_INTEL @@ -1223,8 +1253,14 @@ void Screensaver::setCenterWidget() } else if(qsettings->contains("FL")) { - centerlabel1 = new QLabel(qsettings->value("FL").toString()); - centerlabel2 = new QLabel(qsettings->value("SL").toString()); + if(qsettings->value("FL").typeName() == "QString") + centerlabel1 = new QLabel(qsettings->value("FL").toString()); + else + centerlabel1 = new QLabel(qsettings->value("FL").toStringList().join(' ')); + if(qsettings->value("SL").typeName() == "QString") + centerlabel2 = new QLabel(qsettings->value("SL").toString()); + else + centerlabel2 = new QLabel(qsettings->value("SL").toStringList().join(' ')); centerlabel2->show(); #ifndef USE_INTEL authorlabel = new QLabel(qsettings->value("author").toString()); @@ -1356,6 +1392,15 @@ void Screensaver::hideNotice() { m_widgetNotice->hide(); } + +QPixmap Screensaver::loadFromFile(QString strPath) +{ + QImageReader reader; + reader.setFileName(strPath); + reader.setAutoTransform(true); + reader.setDecideFormatFromContent(true); + return QPixmap::fromImageReader(&reader); +} /* void Screensaver::setDesktopBackground() { diff --git a/screensaver/screensaver.h b/screensaver/screensaver.h index cca782b..39bb7a1 100644 --- a/screensaver/screensaver.h +++ b/screensaver/screensaver.h @@ -37,14 +37,15 @@ #include "checkbutton.h" #include "scconfiguration.h" #include "cyclelabel.h" -#include "weathermanager.h" + +class WeatherManager; class Screensaver : public QWidget { Q_OBJECT public: - explicit Screensaver(QWidget *parent = 0); + explicit Screensaver(bool isScreensaver,QWidget *parent = 0); ~Screensaver(); void addClickedEvent(); @@ -69,6 +70,7 @@ private: void enterEvent(QEvent*); void leaveEvent(QEvent*); void isMovie(); + QPixmap loadFromFile(QString strPath); QTimer *switchTimer; QTimer *fadeTimer; @@ -135,7 +137,7 @@ private: int blur_Num; QString curStyle; - WeatherManager *m_weatherManager; + WeatherManager *m_weatherManager=nullptr; QWidget *m_weatherLaout; QLabel *m_weatherIcon; QLabel *m_weatherArea; @@ -153,7 +155,8 @@ private: int delayTime; QTimer *movieTimer = nullptr; int currentCount = 0; - + QDateTime m_lastDateTime; + bool isScreensaver = false; protected: void paintEvent(QPaintEvent *event); void resizeEvent(QResizeEvent *event); diff --git a/screensaver/screensaverplugin.h b/screensaver/screensaverplugin.h new file mode 100644 index 0000000..041bf38 --- /dev/null +++ b/screensaver/screensaverplugin.h @@ -0,0 +1,27 @@ +#ifndef SCREENSAVER_PLUGIN_H +#define SCREENSAVER_PLUGIN_H + +#include + +class ScreensaverPlugin +{ +public: + virtual ~ScreensaverPlugin() {} + //插件实例的名称 + virtual QString name() const = 0; + + //创建UI的实例 + virtual QWidget* createWidget(bool isScreensaver,QWidget* parent) = 0; + + //获得插件的展示名称 + virtual QString displayName() const = 0; +}; + +//定义了在QT系统中该接口的全局唯一的ID +//实现该SDK的插件也要定义相同的ID +//接口的ID中包含了版本信息,通过该ID我们可以区别不同版本的SDK和插件 +//Q_DECLARE_INTERFACE宏将类型和ID关联起来,这样QT就可以验证加载的插件是否可以转换成MyPluginInterface类型 +#define interface_iid "org.ukui.screensaver.screensaver-default1.0.0" +Q_DECLARE_INTERFACE(ScreensaverPlugin, interface_iid) + +#endif // FILTER_H diff --git a/screensaver/sleeptime.cpp b/screensaver/sleeptime.cpp index 9fd6650..7367a35 100644 --- a/screensaver/sleeptime.cpp +++ b/screensaver/sleeptime.cpp @@ -22,7 +22,9 @@ #include SleepTime::SleepTime(QWidget *parent) : QWidget(parent), - sleepTime(0) + sleepTime(0), + m_nLastSleepLeave(0), + m_nLastSleepTimeSecs(0) { init(); } @@ -36,29 +38,21 @@ void SleepTime::init() { layout = new QHBoxLayout(this); layout->setDirection(QBoxLayout::RightToLeft); - layout->setSpacing(4); + layout->setSpacing(8); - for(int i=0;i<2;i++) - { - QLabel *label = new QLabel(this); - label->setText("0"); - label->setFixedSize(40,40); - label->setObjectName("clockTime"); - list.append(label); - } - - QLabel *colon = new QLabel(this); - colon->setText(":"); - colon->setObjectName("colon"); - list.append(colon); - - for(int i=0;i<2;i++) + for(int i=0;i<3;i++) { QLabel *label = new QLabel(this); label->setText("0"); label->setFixedSize(40,40); label->setObjectName("clockTime"); list.append(label); + if (i < 2) { + QLabel *colon = new QLabel(this); + colon->setText(":"); + colon->setObjectName("colon"); + list.append(colon); + } } for(int i=0;isetText(tr("You have rested:")); + restTime->setText(tr("You have rested")); restTime->setObjectName("restTime"); restTime->setAlignment(Qt::AlignBottom); restTime->adjustSize(); + layout->addSpacing(8); layout->addWidget(restTime); initTime = QDateTime::currentDateTime(); + m_lastTime = initTime; } int SleepTime::setTime(QDateTime time) { - sleepTime = initTime.secsTo(time); - if(sleepTime>5999 || sleepTime<0){ - hide(); - return false; + // 与上一次取时间的时间差 + long nNewSleepTime = qAbs(m_lastTime.msecsTo(time)); + sleepTime = qAbs(initTime.msecsTo(time)); + // 时间差大于1s,则认为时间异常变化,保存已过去的时间 + if (nNewSleepTime > 1000) { + m_nLastSleepLeave += qAbs(m_lastTime.msecsTo(initTime)); + sleepTime = 0; + initTime = time; } + m_lastTime = time; + //当前时间差+异常情况过去的时间 + sleepTime += m_nLastSleepLeave; + sleepTime = sleepTime/1000; - int sec = sleepTime % 60; - int min = sleepTime/60; - setSeconds(sec); - setMinute(min); + if (m_nLastSleepTimeSecs == 0 || qAbs(sleepTime - m_nLastSleepTimeSecs) >= 1) { + int hour = sleepTime / 3600; + int sec = sleepTime % 3600 % 60; + int min = sleepTime % 3600 / 60; + setHour(hour); + setSeconds(sec); + setMinute(min); + m_nLastSleepTimeSecs = sleepTime; + } return true; } +void SleepTime::setHour(int hour) +{ + QString time; + if (hour >= 100) { + QLabelSetText(list.at(4), QString::number(hour)); + } else if (hour < 10) { + time = "0" + QString::number(hour); + list.at(4)->setText(time); + } else { + time = QString::number(hour); + list.at(4)->setText(time); + } + +} + void SleepTime::setSeconds(int seconds) { - int sec1 = seconds%10; - int sec2 = seconds/10; - - list.at(0)->setText(QString::number(sec1)); - list.at(1)->setText(QString::number(sec2)); + QString time; + if (seconds < 10) { + time = "0" + QString::number(seconds); + } else { + time = QString::number(seconds); + } + list.at(0)->setText(time); } void SleepTime::setMinute(int minutes) { - - int min1 = minutes%10; - int min2 = minutes/10; - list.at(3)->setText(QString::number(min1)); - list.at(4)->setText(QString::number(min2)); + QString time; + if (minutes < 10) { + time = "0" + QString::number(minutes); + } else { + time = QString::number(minutes); + } + list.at(2)->setText(time); } void SleepTime::setSmallMode() @@ -117,3 +145,18 @@ void SleepTime::setSmallMode() list.at(i)->setFixedSize(8,8); adjustSize(); } + +bool SleepTime::QLabelSetText(QLabel *label, QString string) +{ + bool is_over_length = false; + QFontMetrics fontMetrics(label->font()); + int fontSize = fontMetrics.width(string); + QString str = string; + if (fontSize > (label->width()-5)) { + str = fontMetrics.elidedText(string, Qt::ElideRight, label->width()); + is_over_length = true; + } + label->setText(str); + return is_over_length; +} + diff --git a/screensaver/sleeptime.h b/screensaver/sleeptime.h index bef0e32..e5e4186 100644 --- a/screensaver/sleeptime.h +++ b/screensaver/sleeptime.h @@ -39,12 +39,17 @@ private: QLabel *restTime; QList list; QHBoxLayout *layout; - int sleepTime; + long long sleepTime; + long long m_nLastSleepLeave; + long long m_nLastSleepTimeSecs; QDateTime initTime; + QDateTime m_lastTime; void init(); + void setHour(int hour); void setSeconds(int seconds); void setMinute(int minutes); + bool QLabelSetText(QLabel *label, QString string); }; #endif // SLEEPTIME_H diff --git a/screensaver/weathermanager.h b/screensaver/weathermanager.h deleted file mode 100644 index 3f29c40..0000000 --- a/screensaver/weathermanager.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * Authors: ZHAI Kang-ning -**/ -#ifndef WEATHERMANAGER_H -#define WEATHERMANAGER_H - -#include -#include -#include -#include - -#include "../src/networkwatcher.h" - -class QNetworkAccessManager; -class QNetworkReply; -class LocalWeatherInfo; - -class WeatherManager : public QObject -{ - Q_OBJECT -public: - explicit WeatherManager(QObject *parent = nullptr); - -Q_SIGNALS: - void onWeatherUpdate(QString city, QString cond, QString temperature); - -private Q_SLOTS: - void replyFinished(QNetworkReply *); - void onNetworkStateChanged(uint state); - -public: - void getWeather(); - QPixmap getWeatherIcon(); - QPixmap getWeatherIcon(QString cond); - - QString getCityName(); - QString getCond(); - QString getTemperature(); - -private: - bool updateLocation();//更新位置,从用户设置获取城市信息,如有多个,只取第一个,未对接 - void weatherRequest(); - - bool getLogcalWeather(); - QString getLogcalCityId(); - -private: - QString m_city_id; // "101030100" 默认天津 - QString m_city_name; - QString m_cond_txt; //天气条件 晴、阴等 - QString m_temperature;//温度 10、20等 - - QNetworkAccessManager *m_net_manager; - QTimer *m_timer; - QGSettings *m_settings; - - LocalWeatherInfo *m_local_weather_info; - NetWorkWatcher *m_networkWatcher; - - int m_networkTryNum = 0; -}; - -class LocalWeatherInfo : QObject -{ - //"1920-08-27 10:17:42,101310204,澄迈,小雨,95%,25℃,北风,1级," 时间,城市编码,城市名称,天气,湿度,温度,风向,风力 - Q_OBJECT -public: - explicit LocalWeatherInfo(QObject *parent = nullptr); - -private: - QString m_update_time; - QString m_city_id; - QString m_city_name; - QString m_cond_text; - QString m_air_humidity; - QString m_temperature; - QString m_wind_direction; - QString m_wind_force; -public: - bool isTimeValid(); - - void setTime(QString time); - QString getTime(); - - void setCityId(QString cityId); - QString getCityId(); - - void setCityName(QString cityName); - QString getCityName(); - - void setCondText(QString condText); - QString getCondText(); - - void setAirHumidity(QString airHumidity); - QString getAirHumidity(); - - void setTemperature(QString temperature); - QString getTemperature(); - - void setWindDirection(QString windDirection); - QString getWindDirection(); - - void setWindForce(QString windForce); - QString getWindForce(); -}; - -#endif // WEATHERMANAGER_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4b7f93..60c0226 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ pkg_check_modules(QGS REQUIRED gsettings-qt) pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(MMIX REQUIRED libmatemixer) +pkg_check_modules(kylin-nm-base REQUIRED kylin-nm-base) find_library(PAM_LIBRARIES pam) @@ -13,6 +14,7 @@ include_directories(${PROJECT_BINARY_DIR}) include_directories(${PROJECT_SOURCE_DIR}/VirtualKeyboard/src) include_directories(${PROJECT_SOURCE_DIR}/BiometricAuth) include_directories(${PROJECT_SOURCE_DIR}/Common) +include_directories(${PROJECT_SOURCE_DIR}/screensaver) include_directories(${PROJECT_SOURCE_DIR}/KylinNM) include_directories(${PROJECT_SOURCE_DIR}/KylinNM/src) include_directories(${PROJECT_SOURCE_DIR}/KylinNM/hot-spot) @@ -25,6 +27,7 @@ include_directories( ${QGS_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${MMIX_INCLUDE_DIRS} + ${kylin-nm-base_INCLUDE_DIRS} ) set(EXTRA_LIBS @@ -38,6 +41,7 @@ set(EXTRA_LIBS ${MMIX_LIBRARIES} -lrt -lpthread + -llibnm-icon-kylin ) qt5_wrap_ui(dialog_SRC @@ -48,6 +52,7 @@ qt5_wrap_ui(dialog_SRC qt5_add_resources(dialog_SRC assets.qrc ../KylinNM/nmqrc.qrc #暂时将麒麟网络的资源文件放到这里,否则显示不出来,暂时不知道原因 + ../screensaver/default.qrc ) # 头文件中包含了Xlib.h,需要单独拿出来处理,不知道原因 @@ -60,7 +65,9 @@ qt5_wrap_cpp(dialog_SRC screensaverwidget.h auth.h auth-pam.h - screensaver.h + authpamthread.h + screensavermode.h + screensaverwndadaptor.h xeventmonitor.h monitorwatcher.h configuration.h @@ -86,10 +93,17 @@ qt5_wrap_cpp(dialog_SRC networkwatcher.h digitalkeyboard.h surewindow.h + loginedusers.h + lockchecker.h + servicemanager.h + mytabwidget.h PhysicalDeviceSet/brightnessdeviceset.h PhysicalDeviceSet/flightmodeset.h PhysicalDeviceSet/sounddeviceset.h PhysicalDeviceSet/touchscreenset.h + device.h + enginedevice.h + batterywidget.h ) set(dialog_SRC @@ -102,11 +116,13 @@ set(dialog_SRC loginoptionswidget.cpp screensaverwidget.cpp auth-pam.cpp + authpamthread.cpp xeventmonitor.cpp monitorwatcher.cpp grab-x11.cpp configuration.cpp - screensaver.cpp + screensavermode.cpp + screensaverwndadaptor.cpp powermanager.cpp utils.cpp users.cpp @@ -128,12 +144,20 @@ set(dialog_SRC networkwatcher.cpp digitalkeyboard.cpp surewindow.cpp + loginedusers.cpp + lockchecker.cpp + servicemanager.cpp + mytabwidget.cpp PhysicalDeviceSet/brightnessdeviceset.cpp PhysicalDeviceSet/flightmodeset.cpp PhysicalDeviceSet/sounddeviceset.cpp PhysicalDeviceSet/touchscreenset.cpp + device.cpp + enginedevice.cpp + batterywidget.cpp ) add_executable(ukui-screensaver-dialog ${dialog_SRC}) +add_definitions(-DAPP_API_MAJOR=0 -DAPP_API_MINOR=11 -DAPP_API_FUNC=0) target_link_libraries(ukui-screensaver-dialog Qt5::Core @@ -143,11 +167,12 @@ target_link_libraries(ukui-screensaver-dialog Qt5::X11Extras Qt5::Network ${EXTRA_LIBS} - BiometricAuth + BiometricAuth VirtualKeyboard Common Kylin-nm ukui-log4qt + Screensaver ) link_libraries(libmatemixer.so glib-2.0.so) diff --git a/src/assets/authdialog.qss b/src/assets/authdialog.qss index cdf0026..dd3a1a0 100644 --- a/src/assets/authdialog.qss +++ b/src/assets/authdialog.qss @@ -11,6 +11,9 @@ QPushButton::hover{ QPushButton::pressed { background-color: rgba(255,255,255,40%); } +QPushButton::checked { + background-color: rgba(255, 255, 255, 40%); +} QToolButton{ text-align:center; @@ -60,7 +63,7 @@ QToolTip{ /* 密码输入框 */ QLineEdit { background: #FFFFFF; - border: 1px solid #FFFFFF; + border: 2px solid #FFFFFF; border-radius: 6px; color:black; font-size: 14px; @@ -68,10 +71,10 @@ QLineEdit { } QLineEdit::hover { - border: 1px solid #FFFFFF; + border: 2px solid #FFFFFF; } QLineEdit::focus{ - + border: 2px solid #2C73C8; } /* 大写提示 */ @@ -95,6 +98,7 @@ QLineEdit::focus{ } #echoModeButton::checked { } + /* 登录按钮 */ #loginButton{ min-width: 24px; @@ -106,6 +110,11 @@ QLineEdit::focus{ border-radius:12px; } +#loginButton::hover, +#loginButton::pressed{ + background:#9B3D6BE5; +} + /* PAM message提示*/ #messageLabel { font-size: 16px; @@ -124,7 +133,7 @@ QMenu{ background-color: rgb(255,255,255,15%); color: white; border-radius: 4px; - width:260px; + width:250px; font-size: 16px; padding: 5px 5px 5px 5px; } diff --git a/src/auth-pam.cpp b/src/auth-pam.cpp index aa01e1c..c83a2a0 100644 --- a/src/auth-pam.cpp +++ b/src/auth-pam.cpp @@ -36,7 +36,6 @@ static int pam_conversation(int msgLength, const struct pam_message **msg, void sigchld_handler(int signo); AuthPAM::AuthPAM(QObject *parent) : Auth(parent), - pid(0), nPrompts(0), _isAuthenticated(false), _isAuthenticating(false) @@ -50,54 +49,33 @@ void AuthPAM::authenticate(const QString &userName) if(pipe(toParent) || pipe(toChild)) qDebug()<< "create pipe failed: " << strerror(errno); - if((pid = fork()) < 0) - { - qDebug() << "fork error: " << strerror(errno); - } - else if(pid == 0) - { - prctl(PR_SET_PDEATHSIG, SIGHUP); - close(toParent[0]); - close(toChild[1]); - int arg1_int = toParent[1]; - int arg2_int = toChild[0]; - char arg1[128]; - char arg2[128]; - sprintf(arg1,"%d",arg1_int); - sprintf(arg2,"%d",arg2_int); - execlp ("ukui-screensaver-checkpass", - "ukui-screensaver-checkpass", - arg1, arg2,userName.toLocal8Bit().data(), NULL); - _exit (EXIT_FAILURE); - } - else - { - close(toParent[1]); - close(toChild[0]); - _isAuthenticating = true; - notifier = new QSocketNotifier(toParent[0], QSocketNotifier::Read); - connect(notifier, &QSocketNotifier::activated, this, &AuthPAM::onSockRead); - } + m_authPamThread = new AuthPamThread(); + m_authPamThread->startAuthPam(toChild[0], toParent[1], userName); + _isAuthenticating = true; + notifier = new QSocketNotifier(toParent[0], QSocketNotifier::Read); + connect(notifier, &QSocketNotifier::activated, this, &AuthPAM::onSockRead); } void AuthPAM::stopAuth() { - if(pid != 0) - { + if (m_authPamThread) { messageList.clear(); responseList.clear(); _isAuthenticating = false; _isAuthenticated = false; nPrompts = 0; - ::kill(pid, SIGKILL); - - close(toParent[0]); - close(toChild[1]); if(notifier){ - notifier->deleteLater(); + disconnect(notifier, &QSocketNotifier::activated, this, &AuthPAM::onSockRead); + delete notifier; notifier = nullptr; } - pid = 0; + close(toParent[1]); + close(toChild[1]); + m_authPamThread->stopAuthPam(); + delete m_authPamThread; + m_authPamThread = nullptr; + close(toParent[0]); + close(toChild[0]); } } diff --git a/src/auth-pam.h b/src/auth-pam.h index 3fba36c..2499442 100644 --- a/src/auth-pam.h +++ b/src/auth-pam.h @@ -22,6 +22,7 @@ #include #include +#include "authpamthread.h" typedef struct pam_message PAM_MESSAGE; typedef struct pam_response PAM_RESPONSE; @@ -47,7 +48,7 @@ private Q_SLOTS: private: QString userName; - pid_t pid; + AuthPamThread *m_authPamThread = nullptr; QSocketNotifier *notifier; int nPrompts; QStringList responseList; diff --git a/src/authdialog.cpp b/src/authdialog.cpp index 4852dcc..309e0cd 100644 --- a/src/authdialog.cpp +++ b/src/authdialog.cpp @@ -36,13 +36,14 @@ #include "pam-tally.h" #include "commonfunc.h" #include "loginoptionswidget.h" +#include "servicemanager.h" +#include "imageutil.h" AuthDialog::AuthDialog(const UserItem &user, QWidget *parent) : QWidget(parent), user(user), auth(new AuthPAM(this)), authMode(UNKNOWN), - m_deviceCount(-1), m_biometricProxy(nullptr), m_widgetLoginOpts(nullptr), m_buttonsWidget(nullptr), @@ -52,17 +53,30 @@ AuthDialog::AuthDialog(const UserItem &user, QWidget *parent) : m_timer(nullptr), isLockingFlg(false), m_nCurLockMin(0), - useFirstDevice(false) + w_timer(nullptr), + m_uniauthService(new UniAuthService(this)) { + setObjectName("AuthDialog"); + + QFile qssFile(":/qss/assets/authdialog.qss"); + if(qssFile.open(QIODevice::ReadOnly)) { + this->setStyleSheet(qssFile.readAll()); + } initUI(); pam_tally_init(); //这里写函数声明 connect(auth, &Auth::showMessage, this, &AuthDialog::onShowMessage); connect(auth, &Auth::showPrompt, this, &AuthDialog::onShowPrompt); connect(auth, &Auth::authenticateComplete, this, &AuthDialog::onAuthComplete); + ServiceManager *sm = ServiceManager::instance(); + connect(sm, &ServiceManager::serviceStatusChanged, + this, &AuthDialog::onBiometricDbusChanged); - useFirstDevice = getUseFirstDevice(); m_failedTimes.clear(); + + connect(m_messageButton, &QPushButton::clicked, + this, &AuthDialog::onMessageButtonClicked); + } void AuthDialog::startAuth() @@ -88,29 +102,11 @@ void AuthDialog::stopAuth() clearMessage(); // auth->stopAuth(); - m_passwordEdit->readOnly(true); + // m_passwordEdit->readOnly(true); // if(m_passwdWidget) // m_passwdWidget->hide(); } -QPixmap AuthDialog::PixmapToRound(const QPixmap &src, int radius) -{ - if (src.isNull()) { - return QPixmap(); - } - - QPixmap pixmapa(src); - QPixmap pixmap(radius*2,radius*2); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QPainterPath path; - path.addEllipse(0, 0, radius*2, radius*2); - painter.setClipPath(path); - painter.drawPixmap(0, 0, radius*2, radius*2, pixmapa); - return pixmap; -} - void AuthDialog::initUI() { if (scale < 0.5) { @@ -132,6 +128,7 @@ void AuthDialog::initUI() m_labelHeadImg->hide(); QPixmap facePixmap(user.icon); + facePixmap = scaledPixmap(facePixmap); facePixmap = facePixmap.scaled(154*scale,154*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); facePixmap = PixmapToRound(facePixmap, 77*scale); m_labelHeadImg->setAlignment(Qt::AlignCenter); @@ -161,7 +158,6 @@ void AuthDialog::initUI() m_labelQRCode->setLayout(layoutQRCode); m_labelQRCodeTip = new QLabel(); m_labelQRCodeTip->setFixedSize(22,22); - m_labelQRCodeTip->setPixmap(QIcon::fromTheme("ukui-dialog-warning").pixmap(QSize(22,22))); layoutQRCode->addWidget(m_labelQRCodeTip, 0, Qt::AlignHCenter); m_labelQRCodeMsg = new QLabel(); m_labelQRCodeMsg->setFixedHeight(24); @@ -200,12 +196,16 @@ void AuthDialog::initUI() m_passwdWidget->setInputMethodHints(Qt::ImhNone); m_passwordEdit->setObjectName(QStringLiteral("passwordEdit")); - m_passwordEdit->setIcon(QIcon(":/image/assets/login-button.svg")); + QPixmap iconLogin = QIcon::fromTheme("system-lock-screen-symbolic").pixmap(16,16); + iconLogin = ImageUtil::drawSymbolicColoredPixmap(iconLogin, "white"); + m_passwordEdit->setIcon(iconLogin); m_passwordEdit->setFocusPolicy(Qt::StrongFocus); m_passwordEdit->installEventFilter(this); m_passwordEdit->readOnly(true); + /*免密登录时,会出现闪一下密码框的问题,因此初始化时隐藏,收到pam发来的prompt类型的消息后再显示*/ + m_passwordEdit->hide(); m_passwordEdit->setType(QLineEdit::Password); - setFocusProxy(m_passwordEdit); + //setFocusProxy(m_passwordEdit); connect(m_passwordEdit, SIGNAL(clicked(const QString&)), this, SLOT(onRespond(const QString&))); @@ -375,6 +375,7 @@ void AuthDialog::setChildrenGeometry() m_labelHeadImg->setStyleSheet(QString("border-radius: %1px; border:0px solid white;").arg(77*scale)); m_labelHeadImg->setGeometry((width() - 154*scale) / 2 , m_labelLoginTypeTip->geometry().bottom()+24*scale, 154*scale, 154*scale); QPixmap facePixmap(user.icon); + facePixmap = scaledPixmap(facePixmap); facePixmap = facePixmap.scaled(154*scale,154*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); facePixmap = PixmapToRound(facePixmap, 77*scale); m_labelHeadImg->setPixmap(facePixmap); @@ -395,9 +396,13 @@ void AuthDialog::setChildrenGeometry() m_passwordEdit->setGeometry((m_passwdWidget->width() - 240)/2, 0, 240, 40); m_messageLabel->setGeometry((m_passwdWidget->width() - 240)/2, m_passwordEdit->geometry().bottom() + 4, - width()-(m_passwdWidget->width() - 240)/2, 20); - + width()-(m_passwdWidget->width() - 240)/2, 36); + m_messageLabel->setMinimumHeight(36); m_messageButton->setGeometry((m_passwdWidget->width() - 200)/2, 0, 200, 40); + m_messageButton->setStyleSheet("QPushButton:!checked:!pressed:!hover{background-color: rgba(255,255,255,40)}" + "QPushButton:!checked:!pressed:hover{background-color: rgba(255,255,255,100)}" + "QPushButton:pressed{background-color: rgba(255,255,255,40)}"); + setBiometricWidgetGeometry(); } @@ -580,6 +585,52 @@ void AuthDialog::setX11Focus() } } +void AuthDialog::setFocusin(int target) +{ + if(m_passwordEdit && m_widgetLoginOpts) { + switch (target) { + case REMOVE: //焦点清除 + m_widgetLoginOpts->tabOptionSelected(2); + m_passwordEdit->setFocusin(2); + m_nameLabel->setFocus(); + break; + case IN_LIGIN: //焦点在登录按钮 + m_widgetLoginOpts->tabOptionSelected(2); + m_passwordEdit->setFocusin(1); + break; + case BIO_RIGHT: //登录选项焦点右移 + m_widgetLoginOpts->tabOptionSelected(0); + m_passwordEdit->setFocusin(2); + m_nameLabel->setFocus(); + break; + case BIO_LEFT: //登录选项焦点左移 + m_widgetLoginOpts->tabOptionSelected(1); + m_passwordEdit->setFocusin(target); + m_nameLabel->setFocus(); + break; + case IN_LINEEDIT: //焦点在密码输入框 + m_widgetLoginOpts->tabOptionSelected(2); + m_passwordEdit->setFocusin(0); + break; + default: + m_passwordEdit->setFocusin(target); + m_widgetLoginOpts->tabOptionSelected(2); + break; + } + } +} + +void AuthDialog::setClick() +{ + m_widgetLoginOpts->tabOptionSelected(3); +} + +void AuthDialog::checkPassword() +{ + m_passwordEdit->clicked_cb(); + setFocusin(REMOVE); +} + void AuthDialog::onShowPrompt(const QString &prompt, Auth::PromptType type) { qDebug() << "-------prompt: " << prompt; @@ -620,6 +671,7 @@ void AuthDialog::onShowPrompt(const QString &prompt, Auth::PromptType type) m_passwordEdit->clear(); m_passwordEdit->setPrompt(text); m_passwordEdit->show(); + m_passwordEdit->setFocus(); if(!m_timer){ m_timer = new QTimer(this); m_timer->setInterval(200); @@ -667,17 +719,24 @@ void AuthDialog::show_authenticated(bool successful) { m_passwdWidget->show(); m_passwordEdit->hide(); + m_passwordEdit->setFocusPolicy(Qt::NoFocus); + m_messageButton->setFocusPolicy(Qt::StrongFocus); + setFocusProxy(m_messageButton); m_messageButton->show(); m_messageButton->setFocus(); m_messageButton->setDefault(true); - connect(m_messageButton, &QPushButton::clicked, - this, &AuthDialog::onMessageButtonClicked); if(successful) { isretry = false; m_messageButton->setText(tr("Login")); switchLoginOptType(LOGINOPT_TYPE_PASSWORD); +// QTimer::singleShot(100, this, [=](){ +// qDebug()<<"Delay to focus msgBtn!!"; +// m_messageButton->show(); +// m_messageButton->setFocus(); +// m_messageButton->setDefault(true); +// }); } else { @@ -706,6 +765,10 @@ void AuthDialog::onMessageButtonClicked() void AuthDialog::onRespond(const QString &text) { + if (!prompted && text != BIOMETRIC_SUCCESS) { + qInfo()<<"Wait for input passwd!"; + return; + } unacknowledged_messages=false; clearMessage(); startWaiting(); @@ -752,8 +815,13 @@ void AuthDialog::performBiometricAuth() if(!m_biometricProxy) { m_biometricProxy = new BiometricProxy(this); - isHiddenSwitchButton = GetHiddenSwitchButton(); - maxFailedTimes = GetFailedTimes(); + if (m_uniauthService && m_uniauthService->isActivatable()) { + isHiddenSwitchButton = m_uniauthService->getHiddenSwitchButton(); + maxFailedTimes = m_uniauthService->getMaxFailedTimes(); + } else { + isHiddenSwitchButton = GetHiddenSwitchButton(); + maxFailedTimes = GetFailedTimes(); + } } //服务没启动,或者打开DBus连接出错 @@ -773,14 +841,8 @@ void AuthDialog::performBiometricAuth() //初始化生物识别认证UI initBiometricWidget(); - //初始化enableBiometriAuth - if(m_deviceCount <= 0) - { - m_deviceCount = m_widgetLoginOpts->getLoginOptCount(); - } - //没有可用设备,不启用生物识别认证 - if(m_deviceCount < 1) + if(m_widgetLoginOpts->getLoginOptCount() < 1) { qWarning() << "No available devices"; skipBiometricAuth(); @@ -788,9 +850,8 @@ void AuthDialog::performBiometricAuth() } //获取默认设备 - if(m_deviceName.isEmpty()) - { - m_deviceName = GetDefaultDevice(user.name); + if (m_widgetLoginOpts) { + m_deviceName = m_widgetLoginOpts->getDefaultDevice(user.name); } qDebug() << m_deviceName; if (m_deviceInfo) { @@ -800,15 +861,11 @@ void AuthDialog::performBiometricAuth() } } - //如果默认设备为空的话,第一次不启动生物识别认证 + //如果默认设备为空的话,不进行生物认证 if(m_deviceName.isEmpty() && !m_deviceInfo) { - if(useFirstDevice == true) { - m_deviceInfo = m_widgetLoginOpts->getFirstDevInfo(); - } else { - skipBiometricAuth(); - return; - } + skipBiometricAuth(); + return; } //clearMessage(); @@ -816,13 +873,11 @@ void AuthDialog::performBiometricAuth() if(!m_deviceInfo) { m_deviceInfo = m_widgetLoginOpts->findDeviceByName(m_deviceName); - if (!m_deviceInfo) - m_deviceInfo = m_widgetLoginOpts->getFirstDevInfo(); - } - if(!m_deviceInfo) - { - skipBiometricAuth(); - return; + if(!m_deviceInfo) + { + skipBiometricAuth(); + return; + } } switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); startBioAuth(); @@ -839,13 +894,15 @@ void AuthDialog::initBiometricWidget() if(m_widgetLoginOpts) { m_widgetLoginOpts->setUser(user.uid); } else { - m_widgetLoginOpts = new LoginOptionsWidget(m_biometricProxy, user.uid, this); + m_widgetLoginOpts = new LoginOptionsWidget(m_biometricProxy, user.uid, m_uniauthService, this); connect(m_widgetLoginOpts, &LoginOptionsWidget::authComplete, this, &AuthDialog::onBiometricAuthComplete); connect(m_widgetLoginOpts, &LoginOptionsWidget::optionSelected, this, &AuthDialog::onDeviceChanged); connect(m_widgetLoginOpts, &LoginOptionsWidget::updateImage, this, &AuthDialog::onLoginOptImage); + connect(m_widgetLoginOpts, &LoginOptionsWidget::setLoadingImage, + this, &AuthDialog::onLoadingImage); connect(m_widgetLoginOpts, &LoginOptionsWidget::notifyOptionsChange, this, &AuthDialog::onLoginOptsCount); connect(m_widgetLoginOpts, &LoginOptionsWidget::updateAuthMsg, @@ -874,10 +931,17 @@ void AuthDialog::setBiometricWidgetGeometry() } } -void AuthDialog::onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr &deviceInfo) +int AuthDialog::getBioNum() +{ + return m_widgetLoginOpts->getLoginOptCount(); +} + +void AuthDialog::onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr &deviceInfo, bool keyNavigation) { if (!deviceInfo) return; + if(!keyNavigation) + Q_EMIT loginOptionClicked(); qDebug() << "device changed: " << *deviceInfo; if(m_failedTimes.contains(deviceInfo->id) && m_failedTimes[deviceInfo->id] >= maxFailedTimes){ @@ -896,7 +960,13 @@ void AuthDialog::onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr void AuthDialog::onBiometricAuthComplete(bool result, int nStatus) { if(!result) { - if (nStatus >= 2) { + if (nStatus == 5 && m_deviceInfo) { + if(w_timer && w_timer->isActive()) + w_timer->stop(); + QImage imgFailed; + setFaceImg(imgFailed, 2); + return; + } else if (nStatus >= 2 && nStatus != 5) { if (m_deviceInfo) { if (m_failedTimes.contains(m_deviceInfo->id)) { m_failedTimes[m_deviceInfo->id] = m_failedTimes[m_deviceInfo->id] + 1; @@ -931,12 +1001,12 @@ void AuthDialog::onBiometricAuthComplete(bool result, int nStatus) qDebug()<<"Biometric dbus error:"<= 2 && m_deviceInfo) { + if (nStatus >= 2 && nStatus != 5 && m_deviceInfo) { if (m_deviceInfo->deviceType == DeviceType::Face) { QImage imgFailed; setFaceImg(imgFailed, 1); @@ -985,6 +1055,7 @@ void AuthDialog::setQRCode(QImage& imgQRCode) m_imgQRCode.load(":/image/assets/ukui-qrcode-null.svg"); } else { m_imgQRCode = imgQRCode; + m_labelQRCodeTip->hide(); } m_imgQRCode = m_imgQRCode.scaled(QSize(150*scale, 150*scale)); m_labelQRCode->setAlignment(Qt::AlignCenter); @@ -995,10 +1066,16 @@ void AuthDialog::setQRCodeMsg(QString strMsg) { if (strMsg.isEmpty()) { m_labelQRCodeMsg->hide(); - m_labelQRCodeTip->hide(); + //m_labelQRCodeTip->hide(); } else { + //一开始认证时就没有网,直接停止加载状态 + if(w_timer && w_timer->isActive()) + { + w_timer->stop(); + } m_labelQRCodeMsg->setText(strMsg); m_labelQRCodeMsg->show(); + m_labelQRCodeTip->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(QSize(22,22))); m_labelQRCodeTip->show(); } } @@ -1015,6 +1092,10 @@ void AuthDialog::setFaceImg(QImage& imgFace, int nStatus) case 1: faceImage = QPixmap(":/image/assets/ukui-loginopt-lose.svg"); break; + case 2: + faceImage = m_widgetLoginOpts->loadSvg(":/image/assets/ukui-loginopt-smile.svg", "gray", 48); + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,20%);").arg(77*scale)); + break; default: faceImage = QPixmap(":/image/assets/ukui-loginopt-smile.svg"); break; @@ -1025,6 +1106,19 @@ void AuthDialog::setFaceImg(QImage& imgFace, int nStatus) m_labelFace->setPixmap(faceImage); } +void AuthDialog::updatePixmap() +{ + QMatrix matrix; + matrix.rotate(90.0); + m_waitingPixmap = m_waitingPixmap.transformed(matrix, Qt::FastTransformation); + if(m_uCurLoginOptType == LOGINOPT_TYPE_QRCODE) + m_labelQRCodeTip->setPixmap(m_waitingPixmap); + else if(m_uCurLoginOptType == LOGINOPT_TYPE_FACE) { + m_labelFace->setPixmap(m_waitingPixmap); + } +} + + void AuthDialog::setLoginTypeTip(QString strLoginTypeTip) { m_strLoginTypeTip = strLoginTypeTip; @@ -1044,7 +1138,7 @@ void AuthDialog::setLoginMsg(QString strLoginMsg) setLoginTypeTip(strLoginMsg); } -void AuthDialog::onLoginOptsCount(unsigned uCount) +void AuthDialog::onLoginOptsCount(unsigned uCount, bool is_bioBtn) { qDebug()<<"----------------------onLoginOptsCount Count:"<isDeviceDisable(m_deviceInfo->id)) { m_widgetLoginOpts->stopAuth(); authMode = BIOMETRIC; - startAuth(); + //初始化生物识别认证UI + initBiometricWidget(); + + //没有可用设备,不启用生物识别认证 + if(m_widgetLoginOpts->getLoginOptCount() < 1) + { + qWarning() << "No available devices"; + return; + } + + //获取默认设备 + if (m_widgetLoginOpts) { + m_deviceName = m_widgetLoginOpts->getDefaultDevice(user.name); + } + qDebug() << m_deviceName; + if (m_deviceInfo) { + if (!m_widgetLoginOpts || !m_widgetLoginOpts->findDeviceById(m_deviceInfo->id) + || m_widgetLoginOpts->isDeviceDisable(m_deviceInfo->id)) { + m_deviceInfo = DeviceInfoPtr(); + } + } + + //如果默认设备为空的话,不进行生物认证 + if(m_deviceName.isEmpty() && !m_deviceInfo) + { + return; + } + + if(!m_deviceInfo) + { + m_deviceInfo = m_widgetLoginOpts->findDeviceByName(m_deviceName); + if(!m_deviceInfo) + { + return; + } + } + switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); + startBioAuth(); } + if(is_bioBtn && uCount <= 1) + Q_EMIT loginOptionClicked(); } void AuthDialog::onLoginOptImage(QImage img) @@ -1075,4 +1208,98 @@ void AuthDialog::onLoginOptImage(QImage img) } else if (m_uCurLoginOptType == LOGINOPT_TYPE_QRCODE) { setQRCode(img); } + if(w_timer && w_timer->isActive()) + { + w_timer->stop(); + } +} + +void AuthDialog::onLoadingImage() +{ + if(!w_timer) + { + w_timer = new QTimer(this); + w_timer->setInterval(150); + connect(w_timer, &QTimer::timeout, this, &AuthDialog::updatePixmap); + } + m_waitingPixmap = QIcon::fromTheme("ukui-loading-0-symbolic").pixmap(24, 24); + m_labelFace->setAlignment(Qt::AlignCenter); + if (m_uCurLoginOptType == LOGINOPT_TYPE_FACE) { + m_labelFace->setPixmap(m_waitingPixmap); + m_labelFace->show(); + } else if (m_uCurLoginOptType == LOGINOPT_TYPE_QRCODE) { + m_labelQRCodeTip->setPixmap(m_waitingPixmap); + m_labelQRCodeTip->show(); + } + w_timer->start(); +} + +void AuthDialog::onBiometricDbusChanged(bool bActive) +{ + qDebug()<<"BiometricDbus:"<isActivatable()) { + isHiddenSwitchButton = m_uniauthService->getHiddenSwitchButton(); + maxFailedTimes = m_uniauthService->getMaxFailedTimes(); + } else { + isHiddenSwitchButton = GetHiddenSwitchButton(); + maxFailedTimes = GetFailedTimes(); + } + } + + //服务没启动,或者打开DBus连接出错 + if(!m_biometricProxy->isValid()) + { + qWarning() << "An error occurs when connect to the biometric DBus"; + if (m_deviceInfo) { + if (!m_widgetLoginOpts || !m_widgetLoginOpts->findDeviceById(m_deviceInfo->id) + || m_widgetLoginOpts->isDeviceDisable(m_deviceInfo->id)) { + m_deviceInfo = DeviceInfoPtr(); + } + } + return; + } + + //初始化生物识别认证UI + initBiometricWidget(); + + //没有可用设备,不启用生物识别认证 + if(m_widgetLoginOpts->getLoginOptCount() < 1) + { + qWarning() << "No available devices"; + return; + } + + //获取默认设备 + if (m_widgetLoginOpts) { + m_deviceName = m_widgetLoginOpts->getDefaultDevice(user.name); + } + qDebug() << m_deviceName; + if (m_deviceInfo) { + if (!m_widgetLoginOpts || !m_widgetLoginOpts->findDeviceById(m_deviceInfo->id) + || m_widgetLoginOpts->isDeviceDisable(m_deviceInfo->id)) { + m_deviceInfo = DeviceInfoPtr(); + } + } + + //如果默认设备为空的话,不再使用生物认证 + if(m_deviceName.isEmpty() && !m_deviceInfo) { + return; + } + + if (!m_deviceInfo) { + m_deviceInfo = m_widgetLoginOpts->findDeviceByName(m_deviceName); + if(!m_deviceInfo) { + return; + } + } + switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); + startBioAuth(); + }); + } } diff --git a/src/authdialog.h b/src/authdialog.h index 73ecd16..4ce6348 100644 --- a/src/authdialog.h +++ b/src/authdialog.h @@ -30,6 +30,7 @@ #include "users.h" #include "biometricdeviceinfo.h" #include "pam-tally.h" +#include "uniauthservice.h" namespace Ui { class AuthDialog; @@ -45,6 +46,14 @@ class BiometricDevicesWidget; class PamTally; class LoginOptionsWidget; +enum FOCUS { + REMOVE = 0, + IN_LIGIN, + BIO_RIGHT, + BIO_LEFT, + IN_LINEEDIT, +}; + extern float scale; class AuthDialog : public QWidget { @@ -56,6 +65,10 @@ public: void closeEvent(QCloseEvent *event); void setUserOfAuth(); void setX11Focus(); + void setFocusin(int target); + void setClick(); + void checkPassword(); + int getBioNum(); private: void initUI(); void startWaiting(); @@ -66,10 +79,10 @@ private: void initBiometricWidget(); void setChildrenGeometry(); void setBiometricWidgetGeometry(); - QPixmap PixmapToRound(const QPixmap &src, int radius); void startBioAuth(unsigned uTimeout = 1000); void show_authenticated (bool successful = true); void setLoginTypeTip(QString strLoginTypeTip); + void updatePixmap(); private Q_SLOTS: void onShowMessage(const QString &message, Auth::MessageType type); @@ -80,7 +93,7 @@ private Q_SLOTS: // void onBioAuthStop(); // void setBioMovieImage(); // void updateIcon(); - void onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr &deviceInfo); + void onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr &deviceInfo, bool keyNavigation); void onBiometricAuthComplete(bool result, int nStatus); void onBiometricButtonClicked(); void onPasswordButtonClicked(); @@ -89,13 +102,15 @@ private Q_SLOTS: void pamBioSuccess(); void onMessageButtonClicked(); void switchLoginOptType(unsigned uLoginOptType); - void onLoginOptsCount(unsigned uCount); + void onLoginOptsCount(unsigned uCount, bool is_bioBtn); void onLoginOptImage(QImage img); void setLoginMsg(QString strLoginMsg); void setQRCode(QImage& imgQRCode); void setFaceImg(QImage& imgFace, int nStatus = 0); void onM_passwordEditClicked(); void setQRCodeMsg(QString strMsg); + void onBiometricDbusChanged(bool bActive); + void onLoadingImage(); public Q_SLOTS: // void switchToBiometric(); @@ -108,6 +123,7 @@ public Q_SLOTS: Q_SIGNALS: void authenticateCompete(bool result); void clickPassword(bool clicked); + void loginOptionClicked(); private: UserItem user; Auth *auth; @@ -117,7 +133,6 @@ private: AuthMode authMode; // biometric auth - int m_deviceCount; QString m_deviceName; DeviceInfoPtr m_deviceInfo = nullptr; BiometricProxy *m_biometricProxy; @@ -153,7 +168,6 @@ private: bool isHiddenSwitchButton; QMap m_failedTimes; QTimer *m_bioTimer; - bool useFirstDevice; bool isLockingFlg; //判断当前是否正在锁定倒计时 int m_nCurLockMin; //当前锁定的分钟数 bool prompted = false; @@ -171,6 +185,10 @@ private: unsigned m_uCurLoginOptType = LOGINOPT_TYPE_PASSWORD; // 当前登录验证方式 QString m_strLoginTypeTip = ""; int m_nLastDeviceId = -1; + + QPixmap m_waitingPixmap; + QTimer *w_timer; + UniAuthService *m_uniauthService = nullptr; }; #endif // AUTHDIALOG_H diff --git a/src/authpamthread.cpp b/src/authpamthread.cpp new file mode 100644 index 0000000..4dabca7 --- /dev/null +++ b/src/authpamthread.cpp @@ -0,0 +1,201 @@ +#include "authpamthread.h" + +#include +#include +#include +#include +#include +#include +#include + +#define PAM_SERVICE_NAME "ukui-screensaver-qt" + +static void writeData(int fd, const void *buf, ssize_t count); +static void writeString(int fd, const char *data); +static int readData(int fd, void *buf, size_t count); +static char * readString(int fd); +static int pam_conversation(int msgLength, const struct pam_message **msg, + struct pam_response **resp, void *appData); + +AuthPamThread::AuthPamThread(QObject* parent) + : QThread(parent) +{ +} + +AuthPamThread::~AuthPamThread() +{ + +} + +void AuthPamThread::writeData(int fd, const void *buf, ssize_t count) +{ + if (!m_isAuthenticating) { + return; + } + if(write(fd, buf, count) != count) + qDebug() << "write to parent failed: " << strerror(errno); +} + +void AuthPamThread::writeString(int fd, const char *data) +{ + int length = data ? strlen(data) : -1; + writeData(fd, &length, sizeof(length)); + if(data) + writeData(fd, data, sizeof(char) * length); +} + +int AuthPamThread::readData(int fd, void *buf, size_t count) +{ + ssize_t nRead = 0; + while(true) { + nRead = read(fd, buf, count); + if (!m_isAuthenticating) { + break; + } + if (nRead < 0) { + if (errno == EAGAIN) { + usleep(100*1000); + continue; + } else { + qDebug() << "read data failed: " << strerror(errno) << errno; + } + } + break; + } + return nRead; +} + +char* AuthPamThread::readString(int fd) +{ + int length; + + if(readData(fd, &length, sizeof(length)) <= 0) + return NULL; + if(length <= 0) + length = 0; + + char *value = (char *)malloc(sizeof(char) * (length + 1)); + readData(fd, value, length); + + value[length] = '\0'; + + return value; +} + +static int +pam_conversation(int msgLength, const struct pam_message **msg, + struct pam_response **resp, void *appData) +{ + struct pam_response *response = (struct pam_response*)calloc(msgLength,sizeof(struct pam_response)); + AuthPamThread* pData = (AuthPamThread*)appData; + if (!pData || pData->m_fdRead < 0 || pData->m_fdWrite < 0) { + return PAM_CONV_ERR; + } + + int authComplete = 0; + pData->writeData(pData->m_fdWrite, (const void*)&authComplete, sizeof(authComplete)); + pData->writeData(pData->m_fdWrite, (const void*)&msgLength, sizeof(msgLength)); + //发送pam消息 + for(int i = 0; i < msgLength; i++) + { + const struct pam_message *m = msg[i]; + pData->writeData(pData->m_fdWrite, (const void *)&m->msg_style, sizeof(m->msg_style)); + pData->writeString(pData->m_fdWrite, m->msg); + } + //读取响应 + for(int i = 0; i < msgLength; i++) + { + struct pam_response *r = &response[i]; + if (pData->readData(pData->m_fdRead, &r->resp_retcode, sizeof(r->resp_retcode)) < 0) { + break; + } + r->resp = pData->readString(pData->m_fdRead); + } + *resp = response; + return PAM_SUCCESS; +} + +void AuthPamThread::_authenticate(const char *userName) +{ + qDebug() << "authenticate " << userName; + + pam_handle_t *pamh = NULL; + char *newUser = NULL; + int ret; + int authRet; + struct pam_conv conv; + + conv.conv = pam_conversation; + conv.appdata_ptr = this; + + ret = pam_start(PAM_SERVICE_NAME, userName, &conv, &pamh); + if(ret != PAM_SUCCESS) { + qDebug() << "failed to start PAM: " << pam_strerror(NULL, ret); + } + + authRet = pam_authenticate(pamh, 0); + + ret = pam_get_item(pamh, PAM_USER, (const void **)&newUser); + if(ret != PAM_SUCCESS) { + pam_end(pamh, 0); + qDebug() << "failed to get username"; + } + + if(authRet == PAM_SUCCESS) { + /*检测账户有效性,即使密码认证通过,如果账户锁定或无效,也无法解锁*/ + authRet = pam_acct_mgmt(pamh, 0); + } + + if(authRet != PAM_SUCCESS) { + qDebug() << "failed to acct mgmt " << pam_strerror(NULL, authRet); + } + + if (newUser) { + free(newUser); + newUser = NULL; + } + fprintf(stderr, "authentication result: %d\n", authRet); + + // 发送认证结果 + int authComplete = 1; + writeData(m_fdWrite, (const void*)&authComplete, sizeof(authComplete)); + writeData(m_fdWrite, (const void *)&authRet, sizeof(authRet)); + qDebug() << "--- 认证完成"; +} + +void AuthPamThread::startAuthPam(int fdRead, int fdWrite, QString strUserName) +{ + if (!isRunning()) { + qDebug()<<"startAuthPam ----"; + m_isAuthenticating = true; + int nFlags = fcntl(fdRead, F_GETFL); + nFlags = nFlags | O_NONBLOCK; + fcntl(fdRead, F_SETFL, nFlags); + m_fdRead = fdRead; + m_fdWrite = fdWrite; + m_strUserName = strUserName; + start(); + } else { + qDebug()<<"AuthPamThread is running!!"; + } +} + +void AuthPamThread::run() +{ + if (m_fdRead >=0 && m_fdWrite >= 0 && !m_strUserName.isEmpty()) { + _authenticate(m_strUserName.toLocal8Bit().data()); + } else { + qDebug()<<"AuthPamThread param error:"< + +class AuthPamThread : public QThread +{ + Q_OBJECT +public: + AuthPamThread(QObject* parent = nullptr); + virtual ~AuthPamThread(); + void startAuthPam(int fdRead, int fdWrite, QString strUserName); + void stopAuthPam(); + + void writeData(int fd, const void *buf, ssize_t count); + void writeString(int fd, const char *data); + int readData(int fd, void *buf, size_t count); + char *readString(int fd); + +protected: + void run(); + +private: + void _authenticate(const char *userName); + +public: + int m_fdRead = -1; + int m_fdWrite = -1; + QString m_strUserName = ""; + +private: + bool m_isAuthenticating = false; +}; + +#endif // AUTHPAMTHREAD_H diff --git a/src/batterywidget.cpp b/src/batterywidget.cpp new file mode 100644 index 0000000..76387c7 --- /dev/null +++ b/src/batterywidget.cpp @@ -0,0 +1,180 @@ +#include "batterywidget.h" +#include +#include +#include +#include +#include + +BatteryWidget::BatteryWidget(QPoint point, QWidget *parent) : + QWidget(parent), + mPoint(point) +{ +// setWindowOpacity(0); + setAttribute(Qt::WA_TranslucentBackground); + initUi(); + setupComponent(); +} + +void BatteryWidget::initUi() +{ + QVBoxLayout *Lyt = new QVBoxLayout(this); + Lyt->setContentsMargins(16, 16, 16, 16); + Lyt->setSpacing(8); + mModeLabel = new QLabel(this); + mModeLabel->setFixedHeight(24); + mModeLabel->setStyleSheet("QLabel{font-size: 16px;font-family: NotoSansCJKsc-Bold, NotoSansCJKsc;" + "font-weight: bold;}"); + + QHBoxLayout *Lyt_1 = new QHBoxLayout(); + Lyt_1->setSpacing(4); + + mIconBtn = new QPushButton(this); + mIconBtn->setFixedSize(48, 32); + mIconBtn->setStyleSheet("QPushButton{\ + color: rgb(255, 255, 255, 255);\ + border: none;\ + border-radius: 4px;\ + outline: none;\ + }"); + + mValueLabel = new QLabel(this); + mValueLabel->setFixedSize(48, 48); + + mStatusLabel = new QLabel(this); + mStatusLabel->setFixedHeight(36); + mStatusLabel->setAlignment(Qt::AlignRight); + + Lyt_1->addWidget(mIconBtn); + Lyt_1->addWidget(mValueLabel); + Lyt_1->addStretch(); + Lyt_1->addWidget(mStatusLabel); + + Lyt->addWidget(mModeLabel); + Lyt->addLayout(Lyt_1); + Lyt->addStretch(); +} + +void BatteryWidget::setupComponent() +{ + QString batteryPath = ""; + dface = new QDBusInterface(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTERFACE, QDBusConnection::systemBus(), this); + QDBusReply> reply = dface->call("EnumerateDevices"); + if (dface->isValid()) { + for (QDBusObjectPath op : reply.value()) { + if (op.path().contains("battery_")) { + batteryPath = op.path(); + qDebug() << "battery path is :" << batteryPath; + break; + } + } + } else { + qDebug() << "Enumerate devices failed"; + } + batInterface = new QDBusInterface(UPOWER_SERVICE, batteryPath, FREEDESKTOP_UPOWER, QDBusConnection::systemBus(), this); + + QDBusConnection::systemBus().connect( + UPOWER_SERVICE, batteryPath, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealMessage(QDBusMessage))); + iface = new QDBusInterface(UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); + if (dface->isValid()) { + mIconBtn->setIconSize(QSize(48, 32)); + mIconBtn->setFocusPolicy(Qt::NoFocus); + mIconBtn->setIcon(QIcon::fromTheme(getBatteryIconName())); + } + ed = EngineDevice::getInstance(); + onBatteryChanged(ed->engine_get_state()); + + int size; + size = ed->devices.size(); + for (int i = 0; i < size; i++) { + DEVICE *dv; + dv = ed->devices.at(i); + + if (dv->m_dev.kind == UP_DEVICE_KIND_LINE_POWER) { + continue; + } + + connect(ed, &EngineDevice::engine_signal_Battery_State, this, &BatteryWidget::onBatteryChanged); + continue; + } +} + +void BatteryWidget::setPoint(QPoint point) +{ + mPoint = point; +} + +QString BatteryWidget::getBatteryIconName() +{ + if (dface->isValid() && iface->isValid()) { + bool batteryState = false; + QDBusReply reply = iface->call("Get", UPOWER_SERVICE, "OnBattery"); + if (reply.isValid()) { + batteryState = reply.value().toBool(); + } + double percentage = -1.0; + QDBusReply percentage_reply = batInterface->call("Get", UPOWER_DIVICES_SERVICE, "Percentage"); + if (percentage_reply.isValid()) { + percentage = percentage_reply.value().toDouble(); + } + + if (batteryState) { + return QString("battery-level-%1-symbolic").arg((int)percentage / 10 * 10); + } else { + return QString("battery-level-%1-charging-symbolic").arg((int)percentage / 10 * 10); + } + } + return QString(); +} + +void BatteryWidget::showEvent(QShowEvent *event) +{ + QPoint pos = QPoint(mPoint.x(), + mPoint.y() - 112); + this->move(pos); + QWidget::showEvent(event); +} + +void BatteryWidget::paintEvent(QPaintEvent *event) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing, true); + p.save(); + p.setBrush(opt.palette.color(QPalette::Base)); + p.setPen(Qt::transparent); + p.setOpacity(0.75); + p.drawRoundedRect(this->rect(), 16, 16); + p.restore(); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} + +void BatteryWidget::setBatteryIcon(QString icon) +{ + mIconBtn->setIcon(QIcon::fromTheme(icon)); +} + +void BatteryWidget::onBatteryChanged(QStringList args) +{ + int battery = args.at(0).toInt(); + int batteryState = args.at(1).toInt(); + if (batteryState == 1 || batteryState == 5) { + mStatusLabel->setText(tr("Charging...")); + } else if (batteryState == 4) { + mStatusLabel->setText(tr("fully charged")); + } + if (batteryState == 4 || batteryState == 1 || batteryState == 5) { + mStatusLabel->setVisible(true); + mModeLabel->setText(tr("PowerMode")); + } else { + mStatusLabel->setVisible(false); + mModeLabel->setText(tr("BatteryMode")); + } + + mValueLabel->setText(QString("%1%").arg(battery)); +} + +void BatteryWidget::dealMessage(QDBusMessage) +{ + mIconBtn->setIcon(QIcon::fromTheme(getBatteryIconName())); +} diff --git a/src/batterywidget.h b/src/batterywidget.h new file mode 100644 index 0000000..b9d460c --- /dev/null +++ b/src/batterywidget.h @@ -0,0 +1,54 @@ +#ifndef BATTERYWIDGET_H +#define BATTERYWIDGET_H + +#include +#include +#include +#include +#include +#include +#include "enginedevice.h" + +#define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" +#define UPOWER_INTERFACE "org.freedesktop.UPower" +#define UPOWER_PATH "/org/freedesktop/UPower" +#define UPOWER_SERVICE "org.freedesktop.UPower" +#define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" +#define UPOWER_DIVICES_SERVICE "org.freedesktop.UPower.Device" + +class BatteryWidget : public QWidget +{ + Q_OBJECT +public: + BatteryWidget(QPoint point, QWidget *parent = nullptr); + + void initUi(); + void setupComponent(); + void setPoint(QPoint point); + QString getBatteryIconName(); + +protected: + void showEvent(QShowEvent *event); + void paintEvent(QPaintEvent *event); + +private: + QLabel *mModeLabel; + QPushButton *mIconBtn; + QLabel *mValueLabel; + QLabel *mStatusLabel; + QPoint mPoint; + + QDBusInterface *batInterface; + QDBusInterface *iface; + QDBusInterface *dface; + + EngineDevice* ed; + +private Q_SLOTS: + void setBatteryIcon(QString icon); + void onBatteryChanged(QStringList args); + void dealMessage(QDBusMessage); + +}; + +#endif // BATTERYWIDGET_H diff --git a/src/configuration.cpp b/src/configuration.cpp index ac964a0..fa5a9e8 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -38,6 +38,7 @@ #define XSCREENSAVER_DIRNAME "/usr/lib/xscreensaver" #define KEY_IDLE_DELAY "idleDelay" #define KEY_IDLE_LOCK "idleLock" +#define KEY_LOCK_TIMEOUT "lockTimeout" Configuration* Configuration::instance_ = nullptr; @@ -51,13 +52,13 @@ Configuration::Configuration(QObject *parent) : QObject(parent) /* Initiailization */ mode = gsettings->get(KEY_MODE).toString(); themes = gsettings->get(KEY_THEMES).toStringList(); - idleDelay = gsettings->get( - KEY_IDLE_DELAY).toInt(); + idleDelay = gsettings->get(KEY_IDLE_DELAY).toInt(); lockEnabled = gsettings->get(KEY_LOCK_ENABLED).toBool(); idleLock = gsettings->get(KEY_IDLE_LOCK).toInt(); imageSwitchInterval = gsettings->get(KEY_IMAGE_SWITCH_INTERVAL).toInt(); imageTSEffect = gsettings->get(KEY_IMAGE_TRANSITION_EFFECT).toInt(); background = gsettings->get(KEY_BACKGROUND).toString(); + m_nLockTimeout = gsettings->get(KEY_LOCK_TIMEOUT).toInt(); qDebug() << mode << themes; qDebug() << imageSwitchInterval << imageTSEffect; @@ -118,6 +119,8 @@ void Configuration::onConfigurationChanged(QString key) imageTSEffect = gsettings->get(KEY_IMAGE_TRANSITION_EFFECT).toInt(); else if(key == KEY_IMAGE_SWITCH_INTERVAL) imageSwitchInterval = gsettings->get(KEY_IMAGE_SWITCH_INTERVAL).toInt(); + else if (key == KEY_LOCK_TIMEOUT) + m_nLockTimeout = gsettings->get(KEY_LOCK_TIMEOUT).toInt(); } /* @@ -205,12 +208,22 @@ QString Configuration::getBackground() return "/usr/share/backgrounds/1-warty-final-ubuntukylin.jpg"; } -int Configuration::xscreensaverActivatedWhenIdle() -{ - return idleDelay; -} - bool Configuration::lockWhenXScreensaverActivated() { return lockEnabled; } + +int Configuration::idlelock() +{ + return idleLock; +} + +int Configuration::idledelay() +{ + return idleDelay; +} + +int Configuration::locktimeout() +{ + return m_nLockTimeout; +} diff --git a/src/configuration.h b/src/configuration.h index a138775..a74fada 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -25,7 +25,7 @@ //#include "gsettings.h" #include -#include "screensaver.h" +#include "screensavermode.h" class QGSettings; @@ -38,9 +38,11 @@ public: public: ScreenSaver *getScreensaver(); static Configuration *instance(QObject *parent = nullptr); - QString getBackground(); - int xscreensaverActivatedWhenIdle(); + QString getBackground(); bool lockWhenXScreensaverActivated(); + int idlelock(); + int idledelay(); + int locktimeout(); public Q_SLOTS: void onConfigurationChanged(QString key); @@ -56,11 +58,12 @@ private: QString background; bool idleActivationEnabled; bool lockEnabled; - int idleDelay; - int idleLock; + int idleDelay = -1; + int idleLock = -1; int imageTSEffect; int imageSwitchInterval; static Configuration *instance_; + int m_nLockTimeout = -1; }; #endif // CONFIGURATION_H diff --git a/src/device.cpp b/src/device.cpp new file mode 100644 index 0000000..f7a62c2 --- /dev/null +++ b/src/device.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2021 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "device.h" +#include + +DEVICE::DEVICE(QObject *parent) : QObject(parent) {} + +void DEVICE::handleChanged(QDBusMessage msg) +{ + Q_EMIT device_property_changed(msg, m_dev.path); +} + +DEVICE::~DEVICE() {} diff --git a/src/device.h b/src/device.h new file mode 100644 index 0000000..fd72185 --- /dev/null +++ b/src/device.h @@ -0,0 +1,255 @@ +/* + * Copyright 2021 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DEVICE_H +#define DEVICE_H + +#include + +#define GPM_DBUS_SERVICE "org.ukui.PowerManager" +#define GPM_DBUS_INTERFACE "org.ukui.PowerManager" +#define GPM_DBUS_INTERFACE_BACKLIGHT "org.ukui.PowerManager.Backlight" +#define GPM_DBUS_INTERFACE_KBD_BACKLIGHT "org.ukui.PowerManager.KbdBacklight" +#define GPM_DBUS_PATH "/org/ukui/PowerManager" +#define GPM_DBUS_PATH_BACKLIGHT "/org/ukui/PowerManager/Backlight" +#define GPM_DBUS_PATH_KBD_BACKLIGHT "/org/ukui/PowerManager/KbdBacklight" + +/* common descriptions of this program */ +#define GPM_NAME _("Power Manager") +#define GPM_DESCRIPTION _("Power Manager for the MATE desktop") + +/* schema location */ +#define GPM_SETTINGS_SCHEMA "org.ukui.power-manager" +#define GPM_SETTINGS_KEY_POLICY "icon-policy" + +/* actions */ +#define GPM_SETTINGS_ACTION_CRITICAL_UPS "action-critical-ups" +#define GPM_SETTINGS_ACTION_CRITICAL_BATT "action-critical-battery" +#define GPM_SETTINGS_ACTION_LOW_UPS "action-low-ups" +#define GPM_SETTINGS_ACTION_SLEEP_TYPE_AC "action-sleep-type-ac" +#define GPM_SETTINGS_ACTION_SLEEP_TYPE_BATT "action-sleep-type-battery" +#define GPM_SETTINGS_SLEEP_WHEN_CLOSED "event-when-closed-battery" + +/* backlight stuff */ +#define GPM_SETTINGS_BACKLIGHT_ENABLE "backlight-enable" +#define GPM_SETTINGS_BACKLIGHT_BATTERY_REDUCE "backlight-battery-reduce" +#define GPM_SETTINGS_DPMS_METHOD_AC "dpms-method-ac" +#define GPM_SETTINGS_DPMS_METHOD_BATT "dpms-method-battery" +#define GPM_SETTINGS_IDLE_BRIGHTNESS "idle-brightness" +#define GPM_SETTINGS_IDLE_DIM_AC "idle-dim-ac" +#define GPM_SETTINGS_IDLE_DIM_BATT "idle-dim-battery" +#define GPM_SETTINGS_IDLE_DIM_TIME "idle-dim-time" +#define GPM_SETTINGS_BRIGHTNESS_AC "brightness-ac" +#define GPM_SETTINGS_BRIGHTNESS_BAT "brightness-bat" +#define GPM_SETTINGS_BRIGHTNESS_DIM_BATT "brightness-dim-battery" + +/* keyboard backlight */ +#define GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE "kbd-backlight-battery-reduce" +#define GPM_SETTINGS_KBD_BRIGHTNESS_ON_AC "kbd-brightness-on-ac" +#define GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_BATT "kbd-brightness-dim-by-on-battery" +#define GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_IDLE "kbd-brightness-dim-by-on-idle" + +/* buttons */ +#define GPM_SETTINGS_BUTTON_LID_AC "button-lid-ac" +#define GPM_SETTINGS_BUTTON_LID_BATT "button-lid-battery" +#define GPM_SETTINGS_BUTTON_SUSPEND "button-suspend" +#define GPM_SETTINGS_BUTTON_HIBERNATE "button-hibernate" +#define GPM_SETTINGS_BUTTON_POWER "button-power" + +/* general */ +#define GPM_SETTINGS_USE_TIME_POLICY "use-time-for-policy" +#define GPM_SETTINGS_NETWORKMANAGER_SLEEP "network-sleep" +#define GPM_SETTINGS_IDLE_CHECK_CPU "check-type-cpu" + + +/* notify */ +#define GPM_SETTINGS_NOTIFY_LOW_CAPACITY "notify-low-capacity" +#define GPM_SETTINGS_NOTIFY_DISCHARGING "notify-discharging" +#define GPM_SETTINGS_NOTIFY_FULLY_CHARGED "notify-fully-charged" +#define GPM_SETTINGS_NOTIFY_SLEEP_FAILED "notify-sleep-failed" +#define GPM_SETTINGS_NOTIFY_SLEEP_FAILED_URI "notify-sleep-failed-uri" +#define GPM_SETTINGS_NOTIFY_LOW_POWER "notify-low-power" +#define GPM_SETTINGS_BAT_POLICY "power-policy-battery" +#define GPM_SETTINGS_ON_BAT_AUTO_SAVE "on-battery-auto-save" +#define GPM_SETTINGS_LOW_BAT_AUTO_SAVE "low-battery-auto-save" +#define GPM_SETTINGS_DISPLAY_LEFT_TIME "dispaly-left-time-of-charge-and-discharge" + + +/* thresholds */ +#define GPM_SETTINGS_PERCENTAGE_LOW "percentage-low" +#define GPM_SETTINGS_PERCENTAGE_CRITICAL "percentage-critical" +#define GPM_SETTINGS_PERCENTAGE_ACTION "percentage-action" +#define GPM_SETTINGS_TIME_LOW "time-low" +#define GPM_SETTINGS_TIME_CRITICAL "time-critical" +#define GPM_SETTINGS_TIME_ACTION "time-action" + +/* timeout */ +#define GPM_SETTINGS_SLEEP_COMPUTER_AC "sleep-computer-ac" +#define GPM_SETTINGS_SLEEP_COMPUTER_BATT "sleep-computer-battery" +#define GPM_SETTINGS_SLEEP_COMPUTER_UPS "sleep-computer-ups" +#define GPM_SETTINGS_SLEEP_DISPLAY_AC "sleep-display-ac" +#define GPM_SETTINGS_SLEEP_DISPLAY_BATT "sleep-display-battery" +#define GPM_SETTINGS_SLEEP_DISPLAY_UPS "sleep-display-ups" + +/* ui */ +#define GPM_SETTINGS_ICON_POLICY "icon-policy" +#define GPM_SETTINGS_ENABLE_SOUND "enable-sound" +#define GPM_SETTINGS_SHOW_ACTIONS "show-actions" + +/* statistics */ +#define GPM_SETTINGS_INFO_HISTORY_TIME "info-history-time" +#define GPM_SETTINGS_INFO_HISTORY_TYPE "info-history-type" +#define GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH "info-history-graph-smooth" +#define GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS "info-history-graph-points" +#define GPM_SETTINGS_INFO_STATS_TYPE "info-stats-type" +#define GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH "info-stats-graph-smooth" +#define GPM_SETTINGS_INFO_STATS_GRAPH_POINTS "info-stats-graph-points" +#define GPM_SETTINGS_INFO_PAGE_NUMBER "info-page-number" +#define GPM_SETTINGS_INFO_LAST_DEVICE "info-last-device" + +#if __aarch64__ +#define ARCH64 TRUE +#else +#define ARCH64 FALSE +#endif + +typedef enum { + GPM_ICON_POLICY_ALWAYS, + GPM_ICON_POLICY_PRESENT, + GPM_ICON_POLICY_CHARGE, + GPM_ICON_POLICY_LOW, + GPM_ICON_POLICY_CRITICAL, + GPM_ICON_POLICY_NEVER +} GpmIconPolicy; + +typedef enum { + GPM_ACTION_POLICY_BLANK, + GPM_ACTION_POLICY_SUSPEND, + GPM_ACTION_POLICY_SHUTDOWN, + GPM_ACTION_POLICY_HIBERNATE, + GPM_ACTION_POLICY_INTERACTIVE, + GPM_ACTION_POLICY_NOTHING +} GpmActionPolicy; + + + +typedef enum { + UP_DEVICE_KIND_UNKNOWN, + UP_DEVICE_KIND_LINE_POWER, + UP_DEVICE_KIND_BATTERY, + UP_DEVICE_KIND_UPS, + UP_DEVICE_KIND_MONITOR, + UP_DEVICE_KIND_MOUSE, + UP_DEVICE_KIND_KEYBOARD, + UP_DEVICE_KIND_PDA, + UP_DEVICE_KIND_PHONE, + UP_DEVICE_KIND_MEDIA_PLAYER, + UP_DEVICE_KIND_TABLET, + UP_DEVICE_KIND_COMPUTER, + UP_DEVICE_KIND_LAST +} UpDeviceKind; + +/** + * UpDeviceState: + * + * The device state. + **/ +typedef enum { + UP_DEVICE_STATE_UNKNOWN, + UP_DEVICE_STATE_CHARGING, + UP_DEVICE_STATE_DISCHARGING, + UP_DEVICE_STATE_EMPTY, + UP_DEVICE_STATE_FULLY_CHARGED, + UP_DEVICE_STATE_PENDING_CHARGE, + UP_DEVICE_STATE_PENDING_DISCHARGE, + UP_DEVICE_STATE_LAST +} UpDeviceState; + +/** + * UpDeviceTechnology: + * + * The device technology. + **/ +typedef enum { + UP_DEVICE_TECHNOLOGY_UNKNOWN, + UP_DEVICE_TECHNOLOGY_LITHIUM_ION, + UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER, + UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE, + UP_DEVICE_TECHNOLOGY_LEAD_ACID, + UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM, + UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE, + UP_DEVICE_TECHNOLOGY_LAST +} UpDeviceTechnology; + +/** + * UpDeviceLevel: + * + * The warning level of a battery. + **/ +typedef enum { + UP_DEVICE_LEVEL_UNKNOWN, + UP_DEVICE_LEVEL_NONE, + UP_DEVICE_LEVEL_DISCHARGING, + UP_DEVICE_LEVEL_LOW, + UP_DEVICE_LEVEL_CRITICAL, + UP_DEVICE_LEVEL_ACTION, + UP_DEVICE_LEVEL_LAST +} UpDeviceLevel; + +struct DEV +{ + UpDeviceKind kind; + UpDeviceLevel warnlevel; + QString Device; + QString Type; + QString PowerSupply; + QString Online; + QString Model; + QString Energy; + QString EnergyEmpty; + QString EnergyFull; + QString EnergyRate; + bool IsPresent; + QString IsRechargeable; + double Percentage; + UpDeviceState State; + qlonglong TimeToEmpty; + qlonglong TimeToFull; + QString Voltage; + double Capacity; + QString Technology; + QString path; + +}; + +class DEVICE : public QObject +{ + Q_OBJECT +public: + explicit DEVICE(QObject *parent = nullptr); + ~DEVICE(); +Q_SIGNALS: + void device_property_changed(QDBusMessage msg,QString path); + + +public Q_SLOTS: + void handleChanged(QDBusMessage msg); +public: + DEV m_dev; +}; + +#endif // DEVICE_H diff --git a/src/enginedevice.cpp b/src/enginedevice.cpp new file mode 100644 index 0000000..f67ff9c --- /dev/null +++ b/src/enginedevice.cpp @@ -0,0 +1,381 @@ +/* + * Copyright 2021 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "enginedevice.h" +#include "device.h" +#include +#include +#include +#include +#include + +EngineDevice *EngineDevice::instance = NULL; + +void EngineDevice::power_device_get_devices() +{ + QList deviceNames; + + /* call enum dbus*/ + QDBusMessage msg = QDBusMessage::createMethodCall(DBUS_SERVICE, DBUS_OBJECT, DBUS_INTERFACE, "EnumerateDevices"); + QDBusMessage res = QDBusConnection::systemBus().call(msg); + + if (res.type() == QDBusMessage::ReplyMessage) { + const QDBusArgument &dbusArg = res.arguments().at(0).value(); + dbusArg >> deviceNames; + } else { + } + int len = deviceNames.size(); + // qDebug()<m_dev.path = deviceNames.at(i).path(); + getProperty(device->m_dev.path, device->m_dev); + /* connect the nofity signal to changecallback */ + QDBusConnection::systemBus().connect( + DBUS_SERVICE, + device->m_dev.path, + DBUS_INTERFACE_PRO, + QString("PropertiesChanged"), + device, + SLOT(handleChanged(QDBusMessage))); + connect( + device, + SIGNAL(device_property_changed(QDBusMessage, QString)), + this, + SLOT(power_device_change_callback(QDBusMessage, QString))); + + /* add to device list*/ + devices.append(device); + } +} + +EngineDevice::EngineDevice(QObject *parent) : QObject(parent) +{ + settings = new QGSettings(GPM_SETTINGS_SCHEMA); + power_device_get_devices(); +} + +void EngineDevice::getProperty(QString path, DEV &dev) +{ + QDBusMessage msg = QDBusMessage::createMethodCall(DBUS_SERVICE, path, DBUS_INTERFACE_PRO, "GetAll"); + msg << DBUS_INTERFACE_DEV; + QDBusMessage res = QDBusConnection::systemBus().call(msg); + + if (res.type() == QDBusMessage::ReplyMessage) { + const QDBusArgument &dbusArg = res.arguments().at(0).value(); + QMap map; + dbusArg >> map; + + dev.kind = (UpDeviceKind)map.value(QString("Type")).toInt(); + dev.Type = engine_kind_to_localised_text((UpDeviceKind)map.value(QString("Type")).toInt(), 1); + dev.Model = map.value(QString("Model")).toString(); + dev.Device = map.value(QString("NativePath")).toString(); + dev.IsPresent = (map.value(QString("IsPresent")).toBool()); + dev.PowerSupply = boolToString(map.value(QString("PowerSupply")).toBool()); + dev.Percentage = map.value(QString("Percentage")).toDouble(); + dev.Percentage = ((float)((int)((dev.Percentage + 0.05) * 10))) / 10; + + dev.Online = boolToString(map.value(QString("Online")).toBool()); + dev.State = (UpDeviceState)map.value(QString("State")).toInt(); + dev.TimeToEmpty = map.value(QString("TimeToEmpty")).toLongLong(); + dev.TimeToFull = map.value(QString("TimeToFull")).toLongLong(); + } +} + +QString EngineDevice::boolToString(bool ret) +{ + return ret ? tr("yes") : tr("no"); +} + +void EngineDevice::putAttributes(QMap &map, DEV &btrDetailData) +{ + if (map.contains("TimeToFull")) { + btrDetailData.TimeToFull = map.value(QString("TimeToFull")).toLongLong(); + } + if (map.contains("TimeToEmpty")) { + btrDetailData.TimeToEmpty = map.value(QString("TimeToEmpty")).toLongLong(); + } + if (map.contains("State")) { + btrDetailData.State = (UpDeviceState)map.value(QString("State")).toInt(); + } + if (map.contains("Percentage")) { + btrDetailData.Percentage = map.value(QString("Percentage")).toDouble(); + btrDetailData.Percentage = ((float)((int)((btrDetailData.Percentage + 0.05) * 10))) / 10; + } + if (map.contains("PowerSupply")) { + btrDetailData.PowerSupply = (map.value(QString("PowerSupply")).toBool()) ? tr("Yes") : tr("No"); + } + if (map.contains("IsPresent")) { + btrDetailData.IsPresent = (map.value(QString("IsPresent")).toBool()); + } +} + +void EngineDevice::power_device_change_callback(QDBusMessage msg, QString path) +{ + /* if battery change to display devices */ + /* judge state */ + DEVICE *item = nullptr; + Q_FOREACH (auto item_tmp, devices) { + if (item_tmp->m_dev.path == path) { + item = item_tmp; + break; + } + } + + if (item == nullptr) + return; + const QDBusArgument &arg = msg.arguments().at(1).value(); + QMap map; + arg >> map; + putAttributes(map, item->m_dev); + + /*recaculate state*/ + power_device_recalculate_state(); +} + +void EngineDevice::power_device_recalculate_state() +{ + engine_recalculate_summary(); +} + +/** + * engine_recalculate_summary: + */ +bool EngineDevice::engine_recalculate_summary() +{ + QString summary; + QStringList Battery_State; + + Battery_State = engine_get_state(); + summary = engine_get_summary(); + if (Battery_State.isEmpty()) { + return false; + } + if (previous_summary.isNull()) { + previous_summary = summary; + Q_EMIT engine_signal_summary_change(summary); + Q_EMIT engine_signal_Battery_State(Battery_State); + return true; + } + + if (previous_summary != summary) { + previous_summary = summary; + Q_EMIT engine_signal_summary_change(summary); + Q_EMIT engine_signal_Battery_State(Battery_State); + return true; + } + return false; +} + +QStringList EngineDevice::engine_get_state() +{ + DEVICE *device; + UpDeviceState state; + QStringList tooltip; + QStringList part; + bool is_present; + UpDeviceKind kind; + + Q_FOREACH (device, devices) { + is_present = device->m_dev.IsPresent; + state = device->m_dev.State; + kind = device->m_dev.kind; + if ((!is_present) || (kind != UP_DEVICE_KIND_BATTERY)) + continue; + if (state == UP_DEVICE_STATE_EMPTY) + continue; + part = engine_get_Battery_State(device); + if (!part.isEmpty()) + tooltip.append(part); + } + return tooltip; +} + +QStringList EngineDevice::engine_get_Battery_State(DEVICE *dv) +{ + UpDeviceState state; + double percentage; + QStringList result; + state = dv->m_dev.State; + int EMPTY = dv->m_dev.TimeToEmpty; + percentage = dv->m_dev.Percentage; + bool is_present; + is_present = dv->m_dev.IsPresent; + if (!is_present) + return result; + result.append(QString("%1").arg(percentage)); + result.append(QString("%1").arg(state)); + result.append(QString("%1").arg(EMPTY)); + return result; +} + +/** + * engine_get_summary: + * + * Returns the complete tooltip ready for display + **/ +QString EngineDevice::engine_get_summary() +{ + DEVICE *device; + UpDeviceState state; + QString tooltip; + QString part; + bool is_present; + UpDeviceKind kind; + + Q_FOREACH (device, devices) { + is_present = device->m_dev.IsPresent; + state = device->m_dev.State; + kind = device->m_dev.kind; + if ((!is_present) || (kind != UP_DEVICE_KIND_BATTERY)) + continue; + if (state == UP_DEVICE_STATE_EMPTY) + continue; + part = engine_get_device_summary(device); + if (!part.isNull()) + tooltip = QString("%1").arg(part); + } + return tooltip; +} + +/** + * engine_get_device_summary: + **/ + +QString EngineDevice::engine_get_device_summary(DEVICE *dv) +{ + QString kind_desc; + UpDeviceKind kind; + UpDeviceState state; + double percentage; + bool is_present; + uint time_to_full; + uint time_to_empty; + + QString result; + + kind = dv->m_dev.kind; + is_present = dv->m_dev.IsPresent; + state = dv->m_dev.State; + percentage = dv->m_dev.Percentage; + time_to_empty = dv->m_dev.TimeToEmpty; + time_to_full = dv->m_dev.TimeToFull; + if (!is_present) + return NULL; + + kind_desc = engine_kind_to_localised_text(kind, 1); + + if (state == UP_DEVICE_STATE_FULLY_CHARGED) { + + result = tr("%1% available, charged").arg(percentage); + + } else if (state == UP_DEVICE_STATE_DISCHARGING) { + + int is_show = settings->get(GPM_SETTINGS_DISPLAY_LEFT_TIME).toInt(); + if (is_show) { + result = tr("Left %1h %2m (%3%)") + .arg((time_to_empty) / 3600) + .arg(((time_to_empty) % 3600) / 60) + .arg(percentage); + } else { + result = tr("%1% available").arg(percentage); + } + + } else if (state == UP_DEVICE_STATE_CHARGING) { + int is_show = settings->get(GPM_SETTINGS_DISPLAY_LEFT_TIME).toInt(); + if (is_show) { + result = tr("Left %1h %2m to full").arg((time_to_full) / 3600).arg(((time_to_full) % 3600) / 60); + } else { + result = tr("charging (%1%)").arg(percentage); + } + + } else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { + + /* TRANSLATORS: this is only shown for laptops with multiple batteries */ + result = tr("%1 waiting to discharge (%2%)").arg(kind_desc).arg(percentage); + + } else if (state == UP_DEVICE_STATE_PENDING_CHARGE) { + + /* TRANSLATORS: this is only shown for laptops with multiple batteries */ + result = tr("%1 waiting to charge (%2%)").arg(kind_desc).arg(percentage); + + } else { + printf("in an undefined state we are not charging or " + "discharging and the batteries are also not charged"); + result = QString("%1 (%2%)").arg(kind_desc).arg(percentage); + } + return result; +} + +/** + * engine_kind_to_localised_text: + **/ +QString EngineDevice::engine_kind_to_localised_text(UpDeviceKind kind, uint number) +{ + Q_UNUSED(number); + QString text; + switch (kind) { + case UP_DEVICE_KIND_LINE_POWER: + + text = tr("AC adapter"); + break; + case UP_DEVICE_KIND_BATTERY: + /* TRANSLATORS: laptop primary battery */ + text = tr("Laptop battery"); + break; + case UP_DEVICE_KIND_UPS: + /* TRANSLATORS: battery-backed AC power source */ + text = tr("UPS"); + break; + case UP_DEVICE_KIND_MONITOR: + /* TRANSLATORS: a monitor is a device to measure voltage and current */ + text = tr("Monitor"); + break; + case UP_DEVICE_KIND_MOUSE: + /* TRANSLATORS: wireless mice with internal batteries */ + text = tr("Mouse"); + break; + case UP_DEVICE_KIND_KEYBOARD: + /* TRANSLATORS: wireless keyboard with internal battery */ + text = tr("Keyboard"); + break; + case UP_DEVICE_KIND_PDA: + /* TRANSLATORS: portable device */ + text = tr("PDA"); + break; + case UP_DEVICE_KIND_PHONE: + /* TRANSLATORS: cell phone (mobile...) */ + text = tr("Cell phone"); + break; + case UP_DEVICE_KIND_MEDIA_PLAYER: + /* TRANSLATORS: media player, mp3 etc */ + text = tr("Media player"); + break; + case UP_DEVICE_KIND_TABLET: + /* TRANSLATORS: tablet device */ + text = tr("Tablet"); + break; + case UP_DEVICE_KIND_COMPUTER: + /* TRANSLATORS: tablet device */ + text = tr("Computer"); + break; + default: + printf("enum unrecognised: %i", kind); + text = tr("unrecognised"); + } + return text; +} diff --git a/src/enginedevice.h b/src/enginedevice.h new file mode 100644 index 0000000..c87bacc --- /dev/null +++ b/src/enginedevice.h @@ -0,0 +1,100 @@ +/* + * Copyright 2021 KylinSoft Co., Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ENGINEDEVICE_H +#define ENGINEDEVICE_H + +#include +#include "device.h" +#include +#include +#include +#include + + +#define DBUS_SERVICE "org.freedesktop.UPower" +#define DBUS_OBJECT "/org/freedesktop/UPower" +#define DBUS_INTERFACE "org.freedesktop.UPower" + +#define DBUS_INTERFACE_PRO "org.freedesktop.DBus.Properties" +#define DBUS_INTERFACE_DEV "org.freedesktop.UPower.Device" + +class EngineDevice : public QObject +{ + Q_OBJECT +private: + static EngineDevice* instance; + explicit EngineDevice(QObject *parent = nullptr); + class Deconstructor + { + public: + ~Deconstructor() { + if(instance) + { + delete instance; + instance = nullptr; + } + } + }; + static Deconstructor deconstructor; + +public: + static EngineDevice* getInstance() + { + if(instance==nullptr) + { + instance = new EngineDevice; + + } + return instance; + } + +Q_SIGNALS: + void engine_signal_discharge(DEV dv); + void engine_signal_charge(DEV dv); + void engine_signal_fullycharge(DEV dv); + void engine_signal_charge_low(DEV dv); + void engine_signal_charge_critical(DEV dv); + void engine_signal_charge_action(DEV dv); + void engine_signal_summary_change(QString summary); + void engine_signal_Battery_State(QStringList Battery_State); +public Q_SLOTS: + void power_device_change_callback(QDBusMessage msg, QString path); + +public: + QGSettings *settings; + QList devices; + QString previous_icon; + QString previous_summary; + + DEVICE *composite_device; + void power_device_recalculate_state(); + bool engine_recalculate_summary(); + void getProperty(QString path, DEV &dev); + QString engine_get_summary(); + QStringList engine_get_state (); + QString engine_kind_to_localised_text(UpDeviceKind kind, uint number); + void power_device_get_devices(); + + QStringList engine_get_Battery_State(DEVICE* dv); + + QString boolToString(bool ret); + QString engine_get_device_summary(DEVICE *dv); + void putAttributes(QMap &map, DEV &btrDetailData); +}; + +#endif // ENGINEDEVICE_H diff --git a/src/fullbackgroundwidget.cpp b/src/fullbackgroundwidget.cpp index c199287..52efbe6 100644 --- a/src/fullbackgroundwidget.cpp +++ b/src/fullbackgroundwidget.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include "lockwidget.h" #include #include #include @@ -48,11 +50,10 @@ #include #include -#include "lockwidget.h" #include "xeventmonitor.h" #include "monitorwatcher.h" #include "configuration.h" -#include "screensaver.h" +#include "screensavermode.h" #include "screensaverwidget.h" #include "grab-x11.h" #include "tabletlockwidget.h" @@ -75,10 +76,8 @@ extern void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool qual QT_END_NAMESPACE #define BLUR_RADIUS 300 -#define GSETTINGS_SCHEMA_SCREENSAVER "org.ukui.screensaver" -#define KEY_IDLE_DELAY "idleDelay" -#define KEY_IDLE_LOCK "idleLock" -#define KEY_IDLE_LOCK_ENABLED "idleLockEnabled" + +#define SUBWND_COUNT_MAX 1024 QPixmap scaledPixmap(int width, int height, QString url) { @@ -198,7 +197,7 @@ QPixmap blurPixmap(QPixmap pixmap) FullBackgroundWidget::FullBackgroundWidget(QWidget *parent) : QWidget(parent), lockWidget(nullptr), - xEventMonitor(new XEventMonitor(this)), + //xEventMonitor(new XEventMonitor(this)), //monitorWatcher(new MonitorWatcher(this)), configuration(Configuration::instance()), isLocked(false), @@ -209,19 +208,23 @@ FullBackgroundWidget::FullBackgroundWidget(QWidget *parent) m_delay(false) { qDebug() << "init - screenStatus: " << screenStatus; + m_listWndIds.clear(); setMouseTracking(true); // connect(monitorWatcher, &MonitorWatcher::monitorCountChanged, // this, &FullBackgroundWidget::onScreenCountChanged); - QDesktopWidget *desktop = QApplication::desktop(); +// QDesktopWidget *desktop = QApplication::desktop(); - connect(desktop, &QDesktopWidget::resized, - this, &FullBackgroundWidget::onDesktopResized); - connect(desktop, &QDesktopWidget::workAreaResized, - this, &FullBackgroundWidget::onDesktopResized); - connect(desktop, &QDesktopWidget::primaryScreenChanged, - this, &FullBackgroundWidget::onDesktopResized); - connect(desktop, &QDesktopWidget::screenCountChanged, - this, &FullBackgroundWidget::onDesktopResized); +// connect(desktop, &QDesktopWidget::resized, +// this, &FullBackgroundWidget::onDesktopResized); +// connect(desktop, &QDesktopWidget::workAreaResized, +// this, &FullBackgroundWidget::onDesktopResized); +// connect(desktop, &QDesktopWidget::primaryScreenChanged, +// this, &FullBackgroundWidget::onDesktopResized); +// connect(desktop, &QDesktopWidget::screenCountChanged, +// this, &FullBackgroundWidget::onDesktopResized); + + connect(QApplication::primaryScreen(),&QScreen::geometryChanged, this, &FullBackgroundWidget::onDesktopResized); + connect(QApplication::screens().at(0), &QScreen::virtualGeometryChanged, this,&FullBackgroundWidget::onDesktopResized); QDBusInterface *iface = new QDBusInterface("org.freedesktop.login1", "/org/freedesktop/login1", @@ -236,33 +239,17 @@ FullBackgroundWidget::FullBackgroundWidget(QWidget *parent) SS_DBUS_INTERFACE, QDBusConnection::sessionBus()); - connect(interfaceScreensaver, SIGNAL(SessionIdle()), - this, SLOT(showScreensaver())); + connect(interfaceScreensaver, SIGNAL(SecondRunParam(QString)), + this, SLOT(onSecondRunParam(QString))); +// 闲置不会主动锁住 +// QDBusInterface *interfaceLock = new QDBusInterface( +// SS_DBUS_SERVICE, +// SS_DBUS_PATH, +// SS_DBUS_INTERFACE, +// QDBusConnection::sessionBus()); - settings_delay = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); - connect(settings_delay, &QGSettings::changed, - this, &FullBackgroundWidget::onConfigurationDelayChanged); - idleDelay = settings_delay->get("idle-delay").toInt(); - qDebug()<<"idleDelay="<get("idle-lock").toInt(); - -// lockEnabled_Key = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); -// connect(lockEnabled_Key, &QGSettings::changed, -// this, &FullBackgroundWidget::lockEnabledChanged); -// lockEnabled = lockEnabled_Key->get("idle-lock-enabled").toBool(); -// qDebug()<, QStringList))); @@ -316,32 +303,26 @@ void FullBackgroundWidget::laterActivate() { activateWindow(); raise(); + raiseOtherWnd(); setFocus(); - if(lockWidget && lockWidget->isVisible()) - lockWidget->setFocus(); + if(lockWidget && lockWidget->isVisible()) { + //lockWidget->setFocus(); + lockWidget->onActiveWindpw();//将焦点设置到密码框 + } + update(); } -void FullBackgroundWidget::onConfigurationDelayChanged(QString key) +void FullBackgroundWidget::laterOtherActivate() { - if(key == KEY_IDLE_DELAY){ - idleDelay = settings_delay->get("idle-delay").toInt(); + activateWindow(); + raiseOtherWnd(); + //setFocus(); + if(lockWidget && lockWidget->isVisible()) { + //lockWidget->setFocus(); + lockWidget->onActiveWindpw();//将焦点设置到密码框 } } -void FullBackgroundWidget::onConfigurationLockChanged(QString key) -{ - if(key == KEY_IDLE_LOCK){ - idleLock = settings_lock->get("idle-lock").toInt(); - } -} - -//void FullBackgroundWidget::lockEnabledChanged(QString key) -//{ -// if(key == KEY_IDLE_LOCK_ENABLED){ -// lockEnabled = lockEnabled_Key->get("idle-lock-enabled").toBool(); -// } -//} - void FullBackgroundWidget::setLockState() { if(lockState == true) @@ -380,6 +361,15 @@ void FullBackgroundWidget::killWindow() void FullBackgroundWidget::setIsStartup(bool val) { isStartup = val; + if (lockWidget) { + lockWidget->setStartupMode(isStartup); + } + Q_EMIT StartupModeChanged(isStartup); +} + +bool FullBackgroundWidget::IsStartupMode() +{ + return isStartup; } void FullBackgroundWidget::paintEvent(QPaintEvent *event) @@ -423,7 +413,12 @@ void FullBackgroundWidget::paintEvent(QPaintEvent *event) void FullBackgroundWidget::closeEvent(QCloseEvent *event) { qDebug() << "FullBackgroundWidget::closeEvent"; - + if (isStartup) + setIsStartup(false); + if(future.isRunning()){ + future.cancel(); + future.waitForFinished(); + } #ifdef USE_INTEL //蓝牙连接后 唤醒信号会有延迟 以防退出时未收到信号导致kwin compositor未resume QDBusInterface *interface = new QDBusInterface("org.ukui.KWin", @@ -447,7 +442,7 @@ void FullBackgroundWidget::closeEvent(QCloseEvent *event) widget->close(); } closeGrab(); - + return QWidget::closeEvent(event); } @@ -465,46 +460,133 @@ void FullBackgroundWidget::showEvent(QShowEvent *event) bool FullBackgroundWidget::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { - if (qstrcmp(eventType, "xcb_generic_event_t") != 0) { + if (qstrcmp(eventType, "xcb_generic_event_t") != 0) { + return false; + } + xcb_generic_event_t *event = reinterpret_cast(message); + const uint8_t responseType = event->response_type & ~0x80; + if (responseType == XCB_CONFIGURE_NOTIFY) { + xcb_configure_notify_event_t *xc = reinterpret_cast(event); + if(xc->window == winId()) { + laterOtherActivate(); return false; } - xcb_generic_event_t *event = reinterpret_cast(message); - const uint8_t responseType = event->response_type & ~0x80; - if (responseType == XCB_CONFIGURE_NOTIFY) { - xcb_configure_notify_event_t *xc = reinterpret_cast(event); - if(xc->window == winId()) - return false; - XWindowAttributes window_attributes; - XGetWindowAttributes (QX11Info::display(), xc->window,&window_attributes); - XClassHint ch; - ch.res_name = NULL; - ch.res_class = NULL; - XGetClassHint (QX11Info::display(), xc->window, &ch); - if(QString(ch.res_name) == "ukui-screensaver-dialog") - return false; - - laterActivate(); - }else if(responseType == XCB_MAP_NOTIFY){ - xcb_map_notify_event_t *xm = reinterpret_cast(event); - if(xm->window == winId()) - return false; - XWindowAttributes window_attributes; - XGetWindowAttributes (QX11Info::display(), xm->window,&window_attributes); - XClassHint ch; - ch.res_name = NULL; - ch.res_class = NULL; - XGetClassHint (QX11Info::display(), xm->window, &ch); - if(QString(ch.res_name) == "ukui-screensaver-dialog") - return false; - laterActivate(); - } - return false; + XClassHint ch; + ch.res_name = NULL; + ch.res_class = NULL; + Display* display = XOpenDisplay(0); + if (!display) { + return false; + } + XGetClassHint (display, xc->window, &ch); + XCloseDisplay(display); + if(QString(ch.res_name) == "ukui-screensaver-dialog") { + if (ch.res_name) + XFree(ch.res_name); + if (ch.res_class) + XFree(ch.res_class); + laterOtherActivate(); + return false; + } else if (isOtherWnd(xc->window)) { + if (ch.res_name) + XFree(ch.res_name); + if (ch.res_class) + XFree(ch.res_class); + return false; + } + if (ch.res_name) + XFree(ch.res_name); + if (ch.res_class) + XFree(ch.res_class); + laterActivate(); + } else if(responseType == XCB_MAP_NOTIFY){ + xcb_map_notify_event_t *xm = reinterpret_cast(event); + if(xm->window == winId()) { + laterOtherActivate(); + return false; + } + XClassHint ch; + ch.res_name = NULL; + ch.res_class = NULL; + Display* display = XOpenDisplay(0); + if (!display) { + return false; + } + XGetClassHint (display, xm->window, &ch); + XCloseDisplay(display); + if(QString(ch.res_name) == "ukui-screensaver-dialog") { + if (ch.res_name) + XFree(ch.res_name); + if (ch.res_class) + XFree(ch.res_class); + laterOtherActivate(); + return false; + } else if (isOtherWnd(xm->window)) { + if (ch.res_name) + XFree(ch.res_name); + if (ch.res_class) + XFree(ch.res_class); + return false; + } + if (ch.res_name) + XFree(ch.res_name); + if (ch.res_class) + XFree(ch.res_class); + laterActivate(); + } else if (responseType == XCB_DESTROY_NOTIFY) { + xcb_destroy_notify_event_t *xd = reinterpret_cast(event); + if(isOtherWnd(xd->window)) { + UnRegisteSubWnd(xd->window); + return false; + } + } else if (responseType == XCB_UNMAP_NOTIFY) { + xcb_unmap_notify_event_t *xum = reinterpret_cast(event); + if(isOtherWnd(xum->window)) { + UnRegisteSubWnd(xum->window); + return false; + } + } else if (responseType == XCB_KEY_PRESS) { + //xcb_key_press_event_t *xc = reinterpret_cast(event); + //qDebug()<<"---------------------XCB_KEY_PRESS:"<detail; + //onGlobalKeyPress(xc->detail); + } else if (responseType == XCB_KEY_RELEASE) { + //xcb_key_release_event_t *xc = reinterpret_cast(event); + //qDebug()<<"---------------------XCB_KEY_RELEASE:"<detail; + //onGlobalKeyRelease(xc->detail); + } else if(responseType == XCB_GE_GENERIC){ + xcb_ge_generic_event_t *xc = reinterpret_cast(event); + if(xc->event_type == XCB_BUTTON_PRESS){ //此处获取的是窗口内的点击事件,光标坐标不需要使用,就直接使用QCursor接口获取了 + onGlobalButtonPressed(QCursor::pos().x(), QCursor::pos().y()); + }else if(xc->event_type == XCB_MOTION_NOTIFY){ //此处获取的是窗口内的点击事件,光标坐标不需要使用,就直接使用QCursor接口获取了 + onGlobalButtonDrag(QCursor::pos().x(),QCursor::pos().y()); + } + }else if (responseType == XCB_BUTTON_PRESS) { //此处获取的是窗口外的鼠标点击 + xcb_button_press_event_t *xc = reinterpret_cast(event); + int x = xc->root_x; + int y = xc->root_y; + onGlobalButtonPressed(x, y); + qDebug()<<"---------------------XCB_BUTTON_PRESS:"<(event); + int x = xc->root_x; + int y = xc->root_y; + onGlobalButtonDrag(x, y); + qDebug()<<"---------------------XCB_MOTION_NOTIFY:"<getBackground()); reader.setAutoTransform(true); + reader.setDecideFormatFromContent(true); reader.setScaledSize(QApplication::primaryScreen()->size()); background = QPixmap::fromImageReader(&reader); @@ -552,6 +641,8 @@ void FullBackgroundWidget::init() setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); + + /*x100下会出现黑色小方块问题,设置此属性时正常*/ setAttribute(Qt::WA_TranslucentBackground); XWindowAttributes rootAttr; @@ -566,16 +657,10 @@ void FullBackgroundWidget::init() // QDBusConnection::sessionBus()); // connect(smInterface, SIGNAL(StatusChanged(uint)), // this, SLOT(onSessionStatusChanged(uint))); - - connect(xEventMonitor, SIGNAL(keyPress(const QString &)), - this, SLOT(onGlobalKeyPress(const QString &))); - connect(xEventMonitor, SIGNAL(keyRelease(const QString &)), - this, SLOT(onGlobalKeyRelease(const QString &))); - connect(xEventMonitor, SIGNAL(buttonDrag(int, int)), - this, SLOT(onGlobalButtonDrag(int, int))); - connect(xEventMonitor, SIGNAL(buttonPress(int, int)), - this, SLOT(onGlobalButtonPressed(int, int))); - +// connect(xEventMonitor, SIGNAL(buttonDrag(int, int)), +// this, SLOT(onGlobalButtonDrag(int, int))); +// connect(xEventMonitor, SIGNAL(buttonPress(int, int)), +// this, SLOT(onGlobalButtonPressed(int, int))); // int totalWidth = 0; // int totalHeight = 0; @@ -587,8 +672,8 @@ void FullBackgroundWidget::init() // setGeometry(0, 0, totalWidth, totalHeight); QDesktopWidget *desktop = QApplication::desktop(); setGeometry(desktop->geometry()); - - xEventMonitor->start(); + +// xEventMonitor->start(); #ifdef USE_INTEL SoundDeviceSet::instance(); @@ -667,8 +752,11 @@ void FullBackgroundWidget::showLockWidget() }); #else lockWidget = new LockWidget(this); + lockWidget->setStartupMode(isStartup); connect(lockWidget, &LockWidget::closed, this, &FullBackgroundWidget::close); + connect(lockWidget, &LockWidget::keyGlobalRelease, + this, &FullBackgroundWidget::onGlobalKeyRelease); #endif } onCursorMoved(QCursor::pos()); @@ -678,9 +766,25 @@ void FullBackgroundWidget::showLockWidget() repaint(); } -void FullBackgroundWidget::showScreensaver() +void FullBackgroundWidget::onSecondRunParam(QString strParam) +{ + qDebug()<<"onSecondRunParam:"<getScreensaver(); + /*锁屏设置的Qt::WA_TranslucentBackground属性会导致第三方屏保变得透明,因此在使用第三方屏保时 + * 取消该属性,清除屏保时再设置回来*/ + if(saver->path != "/usr/lib/ukui-screensaver/ukui-screensaver-default") + { + setAttribute(Qt::WA_TranslucentBackground,false); + } + ScreenSaverWidget *saverWidget = new ScreenSaverWidget(saver, this); qDebug() << " new ScreenSaverWidget"; widgetXScreensaverList.push_back(saverWidget); @@ -711,12 +823,17 @@ void FullBackgroundWidget::showScreensaver() if(lockWidget) { lockWidget->stopAuth(); - lockWidget->hide(); + lockWidget->hide(); + } + if (!isPreview && !(screenStatus & SCREEN_LOCK)) { + // 延迟启动锁屏 + delayLockScreen(); } } void FullBackgroundWidget::clearScreensavers() { + stopDelayLockScreen(); #ifdef USE_INTEL screenStatus = /*(ScreenStatus)(screenStatus & ~SCREEN_SAVER)*/SCREEN_LOCK; #else @@ -727,7 +844,7 @@ void FullBackgroundWidget::clearScreensavers() widget->close(); } widgetXScreensaverList.clear(); - + setAttribute(Qt::WA_TranslucentBackground,true); qDebug() << "clearScreensavers - screenStatus: " << screenStatus; unsetCursor(); @@ -751,7 +868,7 @@ int FullBackgroundWidget::onSessionStatusChanged(uint status) } qDebug() << "onSessionStatusChanged - screenStatus: " << screenStatus; - if(!configuration->xscreensaverActivatedWhenIdle()) + if(configuration->idledelay() == -1) { return -1; } @@ -778,28 +895,42 @@ int FullBackgroundWidget::onSessionStatusChanged(uint status) showLockWidget(); showScreensaver(); #else - if(configuration->xscreensaverActivatedWhenIdle() != -1 && configuration->lockWhenXScreensaverActivated()) - { - //显示锁屏和屏保 - showLockWidget(); - showScreensaver(); - } - else if(configuration->xscreensaverActivatedWhenIdle() != -1) - { - if( idleDelay == idleLock && idleLock != -1){ - //显示锁屏和屏保 - showLockWidget(); - showScreensaver(); - }else{ - //只显示屏保 - showScreensaver(); - } - } + //显示屏保 + showScreensaver(); #endif } return 0; } +void FullBackgroundWidget::delayLockScreen() +{ + if (!m_timerLock) { + m_timerLock = new QTimer(this); + connect(m_timerLock, &QTimer::timeout, this, &FullBackgroundWidget::onLockScreenTimeout); + } + qDebug()<<"LockTimeout:"<locktimeout(); + if (configuration->locktimeout() != -1) { + stopDelayLockScreen(); + m_timerLock->start(configuration->locktimeout()*1000); + } +} + +void FullBackgroundWidget::stopDelayLockScreen() +{ + if (m_timerLock && m_timerLock->isActive()) { + m_timerLock->stop(); + } +} + +void FullBackgroundWidget::onLockScreenTimeout() +{ + qDebug()<<"onLockScreenTimeout:"<lockWhenXScreensaverActivated(); + if (configuration->lockWhenXScreensaverActivated()) { + showLock(); + } + m_timerLock->stop(); +} + void FullBackgroundWidget::onBlankScreensaver() { showLockWidget(); @@ -816,6 +947,23 @@ void FullBackgroundWidget::onBlankScreensaver() } setCursor(Qt::BlankCursor); isBlank = true; + + /*在进行压力测试时,可能会出现锁屏界面启动极慢,导致在睡眠之前调用了锁屏,但 + * 锁屏没来得及绑定睡眠唤醒信号,导致唤醒后,锁屏界面没有收到信号从而一直显示黑屏的问题。 + * 因此这里在进入黑色屏保时,通过后台接口,获取一次当前是否应该显示黑色屏保状态*/ + QDBusInterface *interface = new QDBusInterface(SS_DBUS_SERVICE, + SS_DBUS_PATH, + SS_DBUS_INTERFACE); + + QDBusReply stateReply = interface->call("GetBlankState"); + if(!stateReply.isValid()){ + return ; + } + + if(!stateReply){ + isBlank = false; + clearScreensavers(); + } } void FullBackgroundWidget::onScreensaver() @@ -824,7 +972,7 @@ void FullBackgroundWidget::onScreensaver() showScreensaver(); } -void FullBackgroundWidget::onGlobalKeyPress(const QString &key) +void FullBackgroundWidget::onGlobalKeyPress(const quint8 &key) { #ifdef USE_INTEL qDebug() << "onGlobalKeyPress " << key << "screenStatus " << screenStatus; @@ -851,10 +999,12 @@ void FullBackgroundWidget::onGlobalKeyPress(const QString &key) // lockWidget->RecieveKey(keyValue); // } // } +#else + #endif } -void FullBackgroundWidget::onGlobalKeyRelease(const QString &key) +void FullBackgroundWidget::onGlobalKeyRelease(int key) { // if(key == "Caps_Lock") // { @@ -899,11 +1049,15 @@ void FullBackgroundWidget::onGlobalKeyRelease(const QString &key) // 键盘上的num_lock生效、不需要登录界面进行管理 } #else - if(key == "Escape" && screenStatus == SCREEN_LOCK) + if(key == Qt::Key_Escape && screenStatus == SCREEN_LOCK) // "escape" { bool canShow = true; if (lockWidget && !lockWidget->exitSubWidget()) canShow = false; + if (configuration && configuration->idledelay() == -1) + canShow = false; + if (!m_isAlreadyShowSaver) + canShow = false; if (canShow) showScreensaver(); } @@ -1008,7 +1162,7 @@ void FullBackgroundWidget::onDesktopResized() QDesktopWidget *desktop = QApplication::desktop(); setGeometry(desktop->geometry()); if(lockWidget) - onCursorMoved(QCursor::pos()); + onCursorMoved(QCursor::pos()); if(screenStatus & SCREEN_SAVER) { clearScreensavers(); @@ -1038,6 +1192,7 @@ void FullBackgroundWidget::onPrepareForSleep(bool sleep) { ///系统休眠时,会关闭总线,导致设备不可用,发生错误 ///在系统休眠之前停止认证,在系统唤醒后重新开始认证 + qDebug()<<"onPrepareForSleep:"< FullBackgroundWidget::GetSubWndIds() +{ + return m_listWndIds; +} + +void FullBackgroundWidget::raiseOtherWnd() +{ + //qDebug()<<"raiseOtherWnd----:"< GetSubWndIds(); + bool IsStartupMode(); + public Q_SLOTS: void onCursorMoved(const QPoint &pos); void lock(); void showLockWidget(); void showLock(); - void showScreensaver(); + void showScreensaver(bool isPreview = false); + void onSecondRunParam(QString strParam); int onSessionStatusChanged(uint status); void inhibit(); void uninhibit(); @@ -69,6 +75,10 @@ public Q_SLOTS: void propertiesChangedSlot(QString, QMap, QStringList); void onShowBlackBackGround(); #endif + +Q_SIGNALS: + void StartupModeChanged(bool isStartup); + private: void init(); void clearScreensavers(); @@ -77,24 +87,27 @@ private: QPixmap getPaddingPixmap(QPixmap pixmap, int width, int height); // void checkNumLock(); // int numberMatch(const QString &key); + void raiseOtherWnd(); + bool isOtherWnd(int wndId); + void delayLockScreen(); + void stopDelayLockScreen(); private Q_SLOTS: void onScreenCountChanged(int); void onDesktopResized(); - void onGlobalKeyPress(const QString &key); - void onGlobalKeyRelease(const QString &key); + void onGlobalKeyPress(const quint8 &key); + void onGlobalKeyRelease(int key); void onGlobalButtonDrag(int xPos, int yPos); void onGlobalButtonPressed(int xPos, int yPos); void onPrepareForSleep(bool sleep); void switchToLinux(); void laterActivate(); + void laterOtherActivate(); void setLockState(); void killWindow(); void laterInhibit(bool val); void laterStartAuth(); - void onConfigurationDelayChanged(QString key); - void onConfigurationLockChanged(QString key); -// void lockEnabledChanged(QString key); + void onLockScreenTimeout(); private: QDBusInterface *smInterface; @@ -117,15 +130,15 @@ private: bool isPassed; bool m_delay; int isBlank; - QGSettings *settings_delay; - QGSettings *settings_lock; - QGSettings *lockEnabled_Key; QProcess *process = nullptr; - int idleDelay; - int idleLock; bool lockEnabled; bool isStartup = false; QFuture future; + + // 上层窗口管理 + QList m_listWndIds; + QTimer *m_timerLock = nullptr; + bool m_isAlreadyShowSaver = false; }; #endif // FULLBACKGROUNDWIDGET_H diff --git a/src/grab-x11.cpp b/src/grab-x11.cpp index a03d14d..03806d2 100644 --- a/src/grab-x11.cpp +++ b/src/grab-x11.cpp @@ -41,7 +41,7 @@ static bool grabKeyboard() static bool grabMouse() { #define GRABEVENTS ButtonPressMask | ButtonReleaseMask | PointerMotionMask | \ - EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask + EnterWindowMask | LeaveWindowMask int rv = XGrabPointer(QX11Info::display(), QX11Info::appRootWindow(), True, GRABEVENTS, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); @@ -60,24 +60,26 @@ bool establishGrab() if(!grabKeyboard()) return false; +/*抓取鼠标会导致触摸无效,因此这里先注释掉*/ +/* if(!grabMouse()) { XUngrabKeyboard(QX11Info::display(), CurrentTime); XFlush(QX11Info::display()); return false; } - +*/ return true; } bool closeGrab() { - XSync(QX11Info::display(), False); + //XSync(QX11Info::display(), False); XServerGraber xserverGraber; Q_UNUSED(xserverGraber); XUngrabKeyboard(QX11Info::display(), CurrentTime); - XUngrabPointer(QX11Info::display(), CurrentTime); + // XUngrabPointer(QX11Info::display(), CurrentTime); XFlush(QX11Info::display()); return true; } diff --git a/src/iconedit.cpp b/src/iconedit.cpp index a620826..c708076 100644 --- a/src/iconedit.cpp +++ b/src/iconedit.cpp @@ -69,15 +69,15 @@ IconEdit::IconEdit(QWidget *parent) m_iconButton = new QPushButton(this); m_iconButton->setObjectName(QStringLiteral("loginButton")); - m_iconButton->setFocusPolicy(Qt::NoFocus); m_iconButton->setCursor(QCursor(Qt::PointingHandCursor)); m_iconButton->installEventFilter(this); + m_iconButton->setFocusPolicy(Qt::FocusPolicy::NoFocus); m_modeButton = new QPushButton(this); m_modeButton->setObjectName(QStringLiteral("echoModeButton")); m_modeButton->setCheckable(true); m_modeButton->setIcon(QIcon::fromTheme("ukui-eye-display-symbolic")); - m_modeButton->setFocusPolicy(Qt::NoFocus); + m_modeButton->setFocusPolicy(Qt::FocusPolicy::NoFocus); m_modeButton->setCursor(Qt::PointingHandCursor); m_modeButton->installEventFilter(this); connect(m_modeButton, &QPushButton::clicked, this, [&](bool checked){ @@ -114,14 +114,15 @@ bool IconEdit::eventFilter(QObject *obj, QEvent *event) } if(event->type() == 2) { + setFocusin(0); Q_EMIT clickedPassword(true); } if(event->type() == 23) { - XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); + //XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); update(); }else if(event->type() == QEvent::MouseButtonPress){ - XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); + //XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); update(); } } @@ -132,18 +133,14 @@ bool IconEdit::eventFilter(QObject *obj, QEvent *event) } if(event->type() == 2) { + setFocusin(0); Q_EMIT clickedPassword(true); } - if(event->type() == QEvent::HoverEnter){ - setIcon(QIcon(":/image/assets/login-button-hover.svg")); - } - else if(event->type() == QEvent::HoverLeave){ - setIcon(QIcon(":/image/assets/login-button.svg")); - } } if(obj == m_modeButton){ if(event->type() == 2) { + setFocusin(0); Q_EMIT clickedPassword(true); } } @@ -174,8 +171,29 @@ void IconEdit::resizeEvent(QResizeEvent *) void IconEdit::setX11Focus() { - XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); - update(); + //XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); + update(); +} + +void IconEdit::setFocusin(int target) +{ + switch (target) { + case 0: + m_edit->setFocus(); + m_iconButton->setStyleSheet("min-width: 24px; max-width: 24px; min-height: 24px; max-height: 24px;" + "icon-size: 22px; background:#3D6BE5; border-radius:12px;"); + break; + case 1: + m_edit->clearFocus(); + m_iconButton->setStyleSheet("min-width: 24px; max-width: 24px; min-height: 24px; max-height: 24px;" + "icon-size: 22px; background:#000000; border-radius:12px;"); + break; + default: + m_iconButton->setStyleSheet("min-width: 24px; max-width: 24px; min-height: 24px; max-height: 24px;" + "icon-size: 22px; background:#3D6BE5; border-radius:12px;"); + m_edit->clearFocus(); + break; + } } void IconEdit::clicked_cb() @@ -209,6 +227,7 @@ void IconEdit::setIcon(const QString &text) void IconEdit::setIcon(const QIcon &icon) { m_iconButton->setIcon(icon); + m_iconButton->setIconSize(QSize(12,12)); m_iconButton->setText(""); m_icon = icon; m_iconText = ""; @@ -268,9 +287,10 @@ void IconEdit::startWaiting() // m_waitingPixmap = ImageUtil::loadSvg(":/image/assets/ukui-loginopt-face.svg", "white", 24); // m_iconButton->setIcon(QIcon(m_waitingPixmap)); - QPixmap icon = QIcon::fromTheme("ukui-loading-symbolic-0").pixmap(16,16); + QPixmap icon = QIcon::fromTheme("ukui-loading-0-symbolic").pixmap(16,16); m_waitingPixmap = ImageUtil::drawSymbolicColoredPixmap(icon, "white"); m_iconButton->setIcon(m_waitingPixmap); + m_iconButton->setIconSize(QSize(16,16)); m_timer->start(); } @@ -284,8 +304,10 @@ void IconEdit::stopWaiting() m_iconButton->setAttribute(Qt::WA_TransparentForMouseEvents, false); m_edit->setReadOnly(false); //m_iconButton->setEnabled(true); - if(!m_icon.isNull()) + if(!m_icon.isNull()) { m_iconButton->setIcon(m_icon); + m_iconButton->setIconSize(QSize(12,12)); + } else m_iconButton->setText(m_iconText); } @@ -298,6 +320,7 @@ void IconEdit::updatePixmap() matrix.rotate(90.0); m_waitingPixmap = m_waitingPixmap.transformed(matrix, Qt::FastTransformation); m_iconButton->setIcon(QIcon(m_waitingPixmap)); + m_iconButton->setIconSize(QSize(16, 16)); } /* void IconEdit::setCapsState(bool capsState) diff --git a/src/iconedit.h b/src/iconedit.h index 7a66db7..729197d 100644 --- a/src/iconedit.h +++ b/src/iconedit.h @@ -44,6 +44,7 @@ public: void startWaiting(); void stopWaiting(); void setX11Focus(); + void setFocusin(int target); void readOnly(bool enabled); void setLocked(bool lock); //void setEnabled(bool enabled); diff --git a/src/interface.cpp b/src/interface.cpp index 12d5b60..c16a672 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -24,12 +24,15 @@ #include #include #include +#include #include +#include +#include +#include Interface::Interface(QObject *parent) : QObject(parent), m_timerCount(0), - settings(nullptr), m_timer(nullptr) { lockState = false; @@ -53,8 +56,6 @@ Interface::Interface(QObject *parent) [=](int exitCode, QProcess::ExitStatus exitStatus){ emitLockState(false); }); - - settings = new QGSettings("org.ukui.screensaver","",this); QDBusInterface *iface = new QDBusInterface("org.freedesktop.login1", "/org/freedesktop/login1", @@ -62,8 +63,43 @@ Interface::Interface(QObject *parent) QDBusConnection::systemBus(), this); connect(iface, SIGNAL(PrepareForSleep(bool)), this, SLOT(onPrepareForSleep(bool))); - inhibit(); + // 监听一些会话状态 + m_sessionWatcher = new SessionWatcher(this); + connect(m_sessionWatcher, &SessionWatcher::sessionIdle, + this, &Interface::onSessionIdleReceived); +// connect(m_sessionWatcher, &SessionWatcher::sessionLockIdle, +// this, &Interface::Lock); + connect(m_sessionWatcher, &SessionWatcher::sessionIdle, + this, [=](){ + QDBusMessage message; + message = QDBusMessage::createSignal(SS_DBUS_PATH, + SS_DBUS_INTERFACE, + "SecondRunParam"); + message<<"SessionIdle"; + QDBusConnection::sessionBus().send(message); + }); +// connect(m_sessionWatcher, &SessionWatcher::sessionLockIdle, +// this, [=](){ +// QDBusMessage message; +// message = QDBusMessage::createSignal(SS_DBUS_PATH, +// SS_DBUS_INTERFACE, +// "SessionLockIdle"); +// QDBusConnection::sessionBus().send(message); +// }); + connect(m_sessionWatcher, &SessionWatcher::sessionIdleExit, + this, &Interface::onSessionIdleExit); + connect(m_sessionWatcher, &SessionWatcher::lidStateChanged, + this, &Interface::onLidStateChaned); + + // 监听关屏信号 + QDBusConnection::sessionBus().connect(QString(), + "/", + "ukui.power.manager", + "TurnOffDisplay", + this, + SLOT(onScreenClosed(bool))); + inhibit(); } bool Interface::GetSlpState() @@ -76,6 +112,11 @@ bool Interface::GetLockState() return ((process.state() != QProcess::NotRunning) && lockState); } +bool Interface::GetBlankState() +{ + return blankState; +} + void Interface::SetLockState() { lockState = true; @@ -104,8 +145,9 @@ void Interface::UnLock() void Interface::Lock() { - if(process.state() != QProcess::NotRunning) + if(process.state() != QProcess::NotRunning) { return ; + } qDebug() << "Lock requested"; lockState = false; QString cmd = QString("/usr/bin/ukui-screensaver-dialog --lock"); @@ -117,6 +159,11 @@ void Interface::Lock() void Interface::onSessionIdleReceived() { + qDebug()<<"onSessionIdleReceived--------"; + if (!checkStatus(SESSION_STATUS_SCREENSAVER)) { + qDebug()<<"m_nStatus:"<get("sleep-activation-enabled").toBool()){ + if (!checkStatus(SESSION_STATUS_SLEEPED)) { + uninhibit(); + return; + } + + if (checkScreenDialogRunning()) { uninhibit(); return; } @@ -204,9 +297,10 @@ void Interface::onPrepareForSleep(bool sleep) return; } + blankState = true; this->onShowBlankScreensaver(); - if(!m_timer){ + if(!m_timer){ m_timer = new QTimer(this); connect(m_timer, &QTimer::timeout, this, [&]{ m_timerCount+=1; @@ -222,10 +316,49 @@ void Interface::onPrepareForSleep(bool sleep) } else { + m_nStatus &= ~SESSION_STATUS_SLEEPED; + blankState = false; inhibit(); } } +void Interface::onSessionIdleExit() +{ + qDebug()<<"onSessionIdleExit--------"; + m_nStatus &= ~SESSION_STATUS_SCREENSAVER; + m_nStatus &= ~SESSION_STATUS_SCREENCLOSE; +} + +void Interface::onScreenClosed(bool state) +{ + qDebug()<<"onScreenClosed:"<isLidCloseWithBlank()) { + m_nStatus &= ~SESSION_STATUS_SCREENCLOSE; + } + } +} + void Interface::ShowScreensaver() { if(process.state() != QProcess::NotRunning) @@ -269,3 +402,54 @@ void Interface::uninhibit() m_inhibitFileDescriptor = QDBusUnixFileDescriptor(); } + +bool Interface::checkStatus(int nStatus) +{ + if (!m_sessionWatcher) { + return false; + } + switch (nStatus) { + case SESSION_STATUS_SLEEPED: + { + m_nStatus |= nStatus; + if (!m_sessionWatcher->isSleepActivationEnable()) { + return false; + } + } + break; + case SESSION_STATUS_SCREENCLOSE: + { + m_nStatus |= nStatus; + if ((m_nStatus&SESSION_STATUS_SLEEPED) || !m_sessionWatcher->isCloseActivationEnable()) { + return false; + } + if (((m_sessionWatcher->closeActivationDelay() == m_sessionWatcher->sleepActivationDelay()) + && m_sessionWatcher->sleepActivationDelay() != -1) && !m_sessionWatcher->isSleepActivationEnable()) { + qDebug()<<"Sleep same with Close and Sleep disable!"; + return false; + } + } + break; + case SESSION_STATUS_SCREENSAVER: + { + m_nStatus |= nStatus; + if ((m_nStatus&SESSION_STATUS_SLEEPED) || (m_nStatus&SESSION_STATUS_SCREENCLOSE)) { + return false; + } + if (((m_sessionWatcher->idledelay()*60 == m_sessionWatcher->sleepActivationDelay()) + && m_sessionWatcher->sleepActivationDelay() != -1) && !m_sessionWatcher->isSleepActivationEnable()) { + qDebug()<<"Sleep same with idle and Sleep disable!"; + return false; + } + if (((m_sessionWatcher->idledelay()*60 == m_sessionWatcher->closeActivationDelay()) + && m_sessionWatcher->closeActivationDelay() != -1) && !m_sessionWatcher->isCloseActivationEnable()) { + qDebug()<<"Close same with idle and Close disable!"; + return false; + } + } + break; + default: + return false; + } + return true; +} diff --git a/src/interface.h b/src/interface.h index 411ce5c..97e9b44 100644 --- a/src/interface.h +++ b/src/interface.h @@ -25,6 +25,7 @@ #include #include "types.h" #include "logind.h" +#include "sessionwatcher.h" class QGSettings; class Interface : public QObject, protected QDBusContext @@ -34,10 +35,13 @@ class Interface : public QObject, protected QDBusContext Q_CLASSINFO("D-Bus Interface", SS_DBUS_SERVICE) public: + enum { + SESSION_STATUS_SCREENSAVER = 1, // 屏保 + SESSION_STATUS_SCREENCLOSE = 2, // 关屏 + SESSION_STATUS_SLEEPED = 4, // 休眠/睡眠 + }; explicit Interface(QObject *parent = nullptr); LogindIntegration *m_logind; -Q_SIGNALS: - void SessionIdle(); public Q_SLOTS: /** @@ -54,19 +58,27 @@ public Q_SLOTS: void onShowBlankScreensaver(); void onNameLost(const QString&); void onPrepareForSleep(bool sleep); - + bool checkScreenDialogRunning(); + void onSessionIdleExit(); + void onScreenClosed(bool state); + void onLidStateChaned(bool isClosed); + bool GetBlankState(); private: bool checkExistChild(); void inhibit(); void uninhibit(); + void emitLockState(bool); + bool checkStatus(int nStatus); + +private: bool lockState; bool slpState; - void emitLockState(bool); int m_timerCount; - QGSettings *settings; + SessionWatcher *m_sessionWatcher = nullptr; QTimer *m_timer; QDBusUnixFileDescriptor m_inhibitFileDescriptor; - + int m_nStatus = 0; // 当前状态 + bool blankState = false; private: QProcess process; }; diff --git a/src/lockchecker.cpp b/src/lockchecker.cpp new file mode 100644 index 0000000..7cc44e3 --- /dev/null +++ b/src/lockchecker.cpp @@ -0,0 +1,237 @@ +/* + * Copyright (C) Copyright 2021 KylinSoft Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#include "lockchecker.h" +#include "loginedusers.h" +#include +#include +#include +#include +#include +#include +#include + +#define SYSTEMD_SERVICE "org.freedesktop.login1" +#define SYSTEMD_PATH "/org/freedesktop/login1" +#define SYSTEMD_INTERFACE "org.freedesktop.login1.Manager" + +QDBusArgument &InhibitInfo::operator<<(QDBusArgument &argument, const InhibitInfo::InhibitorInfo &mystruct) +{ + argument.beginStructure(); + argument << mystruct.name << mystruct.icon; + argument.endStructure(); + return argument; +} + +const QDBusArgument &InhibitInfo::operator>>(const QDBusArgument &argument, InhibitInfo::InhibitorInfo &mystruct) +{ + argument.beginStructure(); + argument >> mystruct.name >> mystruct.icon ; + argument.endStructure(); + return argument; +} + +LockChecker::LockChecker() +{ +} + +LockChecker::~LockChecker() +{ +} + +int LockChecker::checkLock() +{ + bool lockfile = false; + bool lockuser = false; + + QFile file_backup("/tmp/lock/kylin-backup.lock"); + QFile file_update("/tmp/lock/kylin-update.lock"); + if (file_backup.exists()) { + int fd_backup = open(QString("/tmp/lock/kylin-backup.lock").toUtf8().data(), O_RDONLY); + int b = flock(fd_backup, LOCK_EX|LOCK_NB); + qDebug() << "b" << b; + if (b < 0) { + lockfile = true; + QString file_user = getName(&file_backup); + if (file_user == qgetenv("USER")) { + lockuser = true; + } + } + file_backup.close(); + if (flock(fd_backup, LOCK_UN) == 0) { + qDebug() << "unlock sucess."; + } else { + qDebug() << "unlock fail."; + } + } + if (file_update.exists()) { + int fd_update = open(QString("/tmp/lock/kylin-update.lock").toUtf8().data(), O_RDONLY); + int c = flock(fd_update, LOCK_EX|LOCK_NB); + qDebug() << "c" << c; + if (c < 0) { + lockfile = true; + QString file_user = getName(&file_update); + if (file_user == qgetenv("USER")) { + lockuser = true; + } + } + file_backup.close(); + if (flock(fd_update, LOCK_UN) == 0) { + qDebug() << "unlock sucess."; + } else { + qDebug() << "unlock fail."; + } + } + if (lockfile) { + if(lockuser) + return 2; + return 1; + } + return 0; +} + +QStringList LockChecker::getLoginedUsers() +{ + QStringList loginedUser; + qRegisterMetaType("LoginedUsers"); + qDBusRegisterMetaType(); + QDBusInterface loginInterface(SYSTEMD_SERVICE, + SYSTEMD_PATH, + SYSTEMD_INTERFACE, + QDBusConnection::systemBus()); + + if (loginInterface.isValid()) { + qDebug() << "create interface success"; + } + + QDBusMessage result = loginInterface.call("ListUsers"); + QList outArgs = result.arguments(); + QVariant first = outArgs.at(0); + const QDBusArgument &dbusArgs = first.value(); + + QVector loginedUsers; + + dbusArgs.beginArray(); + while (!dbusArgs.atEnd()) { + LoginedUsers user; + dbusArgs >> user; + loginedUsers.push_back(user); + } + dbusArgs.endArray(); + + for (LoginedUsers user : loginedUsers) { + + QDBusInterface userPertyInterface("org.freedesktop.login1", + user.objpath.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus()); + + QDBusReply reply = userPertyInterface.call("Get", "org.freedesktop.login1.User", "State"); + if (reply.isValid()) { + QString status = reply.value().toString(); + if ("closing" != status) { + loginedUser.append(user.userName); + } + } + } + return loginedUser; +} + +QVector LockChecker::listInhibitor(QString type) +{ + qDBusRegisterMetaType(); + + QVector resVec; + + QDBusInterface loginInterface("org.gnome.SessionManager", "/org/gnome/SessionManager", + "org.gnome.SessionManager", QDBusConnection::sessionBus()); + + if (loginInterface.isValid()) { + qDebug() << "create interface success"; + } + + QDBusMessage result = loginInterface.call("ListInhibitor", QVariant(type)); + QList outArgs = result.arguments(); + QVariant first = outArgs.at(0); + const QDBusArgument &dbusArgs = first.value(); + + dbusArgs.beginArray(); + while (!dbusArgs.atEnd()) { + InhibitInfo::InhibitorInfo inhibtor; + dbusArgs >> inhibtor; + resVec.push_back(inhibtor); + } + + dbusArgs.endArray(); + + return resVec; +} + +QString LockChecker::getName(QFile *a) +{ + QString user = getenv("USER"); + if (a->exists()) { + a->open(QIODevice::ReadOnly|QIODevice::Text); + QTextStream fileStream(a); + int k = 0; + while (!fileStream.atEnd()) { + QString line = fileStream.readLine(); + if (k == 0) { + QString a = line; + qDebug() << "uid="< outArgs = ret.arguments(); + QVariant first = outArgs.at(0); + const QDBusArgument &dbusArgs = first.value(); + QDBusObjectPath path; + dbusArgs.beginArray(); + int userNum = 0; + while (!dbusArgs.atEnd()) { + dbusArgs >> path; + userNum++; + } + dbusArgs.endArray(); + qDebug() << userNum; + + return userNum; +} diff --git a/src/lockchecker.h b/src/lockchecker.h new file mode 100644 index 0000000..6653850 --- /dev/null +++ b/src/lockchecker.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) Copyright 2021 KylinSoft Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#ifndef LOCKCHECKER_H +#define LOCKCHECKER_H + +#include +#include + +namespace InhibitInfo { + struct InhibitorInfo { + QString name; + QString icon; + }; + + QDBusArgument &operator<<(QDBusArgument &argument, const InhibitInfo::InhibitorInfo &mystruct); + + const QDBusArgument &operator>>(const QDBusArgument &argument, InhibitInfo::InhibitorInfo &mystruct); +} + +//struct userInfo { +// int userId; +// QString userName; +// QDBusObjectPath userPath; +//}; + +//QDBusArgument &operator <<(QDBusArgument &arg, const userInfo &usersInfo); +//const QDBusArgument &operator >>(const QDBusArgument &arg, userInfo &usersInfo); + +Q_DECLARE_METATYPE(InhibitInfo::InhibitorInfo) + +class LockChecker +{ +public: + LockChecker(); + ~LockChecker(); + +public: + static int checkLock(); + + static QStringList getLoginedUsers(); + +// static QVector getInhibitors(); + static QVector listInhibitor(QString type); + +// static bool isSleepBlocked(); + +// static bool isShutdownBlocked(); + +// static void getSleepInhibitors(QStringList &sleepInhibitors, QStringList &sleepInhibitorsReason); + +// static void getShutdownInhibitors(QStringList &shutdownInhibitors, QStringList &shutdownInhibitorsReason); + + static int getCachedUsers(); + +private: + static QString getName(QFile *a); +}; + +#endif // LOCKCHECKER_H diff --git a/src/lockwidget.cpp b/src/lockwidget.cpp index 19678ae..264468f 100644 --- a/src/lockwidget.cpp +++ b/src/lockwidget.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #include #include #include "authdialog.h" @@ -43,6 +45,7 @@ #include "commonfunc.h" #include "hoverwidget.h" #include "kylinnm.h" +#include "mytabwidget.h" #include #include @@ -50,6 +53,11 @@ #define TIME_TYPE_SCHEMA "org.ukui.control-center.panel.plugins" #define CONFIG_FILE "/etc/lightdm/ukui-greeter.conf" +#define ON_TAB_SHEET "QPushButton{background-color: rgba(255,255,255,15%); border-radius: 4px; border: 2px solid #2C73C8;}" +#define ON_NORMAL_SHEET "QPushButton{text-align:center;color: rgb(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;} \ + QPushButton::hover{background-color: rgb(255,255,255,15%);} \ + QPushButton::pressed {background-color: rgba(255,255,255,40%);}\ + QPushButton::checked {background-color: rgba(255, 255, 255, 40%);}" float scale; LockWidget::LockWidget(QWidget *parent) : QWidget(parent), @@ -65,13 +73,18 @@ LockWidget::LockWidget(QWidget *parent) ui->setupUi(this); // m_kylinNM->installEventFilter(this); + if(users->getUsers().count() < 2){ + ui->btnSwitchUser->hide(); + } UserItem user = users->getUserByName(getenv("USER")); authDialog = new AuthDialog(user, this); authDialog->installEventFilter(this); connect(authDialog, &AuthDialog::authenticateCompete, this, &LockWidget::closed); connect(authDialog,&AuthDialog::clickPassword, - this,&LockWidget::hideNetManager); + this,&LockWidget::onClickPassword); + connect(authDialog,&AuthDialog::loginOptionClicked, + this,&LockWidget::resetNavigation); // connect(this, &LockWidget::capsLockChanged, // authDialog, &AuthDialog::onCapsLockChanged); @@ -79,19 +92,19 @@ LockWidget::LockWidget(QWidget *parent) // updateNetIcon(m_kylinNM->getConnectStatus()); // }); - xEventMonitor = new XEventMonitor(this); - connect(xEventMonitor, SIGNAL(keyPress(const QString &)), this, - SLOT(onGlobalKeyPress(const QString &))); - connect(xEventMonitor, SIGNAL(keyRelease(const QString &)), this, - SLOT(onGlobalkeyRelease(const QString &))); - xEventMonitor->start(); - this->installEventFilter(this); initUI(); if(users->getUsers().count() < 2){ + is_switchBtn = false; ui->btnSwitchUser->hide(); } + if(is_batteryBtn) + horAT = BATTERYBTN; + else if(!is_batteryBtn && is_switchBtn) + horAT = SWITCHBTN; + else + horAT = NETWORKBTN; } LockWidget::~LockWidget() @@ -103,28 +116,56 @@ void LockWidget::closeEvent(QCloseEvent *event) { qDebug() << "LockWidget::closeEvent"; authDialog->close(); + return QWidget::closeEvent(event); } bool LockWidget::eventFilter(QObject *obj, QEvent *event) { - if (obj == m_kylinNM) - return true; - if(event->type() == 2){ - if(obj == ui->btnPowerManager || obj == ui->btnSwitchUser || obj == ui->btnNetworkManager) + if(obj == mkylinNM) + return true; + + if(obj == ui->btnPowerManager || obj == ui->btnSwitchUser || obj == btnNetworkManager || obj == ui->btnBatteryStatus) return false; - if(scrollArea && scrollArea->isVisible()){ - scrollArea->hide(); - } - if(powermanager && powermanager->isVisible()){ - authDialog->setFocus(); - authDialog->show(); - powermanager->hide(); + if(mBatteryWidget && mBatteryWidget->isVisible()) { + setCheckedSheet(BATTERYBTN, false); + at_plugins = false; } - if(m_kylinNM && m_kylinNM->isVisible()){ - m_kylinNM->hide(); + + if(scrollArea && scrollArea->isVisible()) { + setCheckedSheet(SWITCHBTN,false); + at_plugins = false; + } + + if(vKeyboard && vKeyboard->isVisible()) { + vKeyboard->hide(); + at_plugins = false; + } + + if(m_kylinNM && m_kylinNM->isVisible()) { + setCheckedSheet(NETWORKBTN, false); + at_plugins = false; + } + + if(powermanager && powermanager->isVisible()){ + authDialog->show(); + powermanager->hide(); + tabAt = LINEEDIT; + setBottomBtnSheet(); + authDialog->setFocusin(IN_LINEEDIT); + powermanager->clearStatus(); + at_power = false; + } + + if(tabAt != LINEEDIT) { + authDialog->setFocusin(REMOVE); + if(tabAt == BOTTMBTN) { + tabAt = LINEEDIT; + setBottomBtnSheet(); + tabAt = BOTTMBTN; + } } } @@ -134,52 +175,380 @@ bool LockWidget::eventFilter(QObject *obj, QEvent *event) //qDebug()<<"````````````````````````````````````````````"<type(); } } - +/* if(event->type() == QEvent::WindowActivate){ if(!isNetFinished){ - isNetFinished = true; - QTimer::singleShot(2000, this, [=](){ - m_kylinNM = new KylinNM(this); - m_kylinNM->installEventFilter(this); - connect(m_kylinNM, &KylinNM::onConnectChanged, this,[=](){ - updateNetIcon(m_kylinNM->getConnectStatus()); - }); - m_kylinNM->hide(); - QtConcurrent::run([=](){ - updateNetIcon(getNetStatus()); - }); - }); + isNetFinished = true; + QTimer::singleShot(1000, this, [=](){ + loadNetPlugin(); +// m_kylinNM = new KylinNM(this); +// m_kylinNM->installEventFilter(this); +// connect(m_kylinNM, &KylinNM::onConnectChanged, this,[=](){ +// updateNetIcon(m_kylinNM->getConnectStatus()); +// }); +// m_kylinNM->hide(); +// QtConcurrent::run([=](){ +// updateNetIcon(getNetStatus()); +// }); + }); } } - +*/ return false; } -void LockWidget::onGlobalKeyPress(const QString &key) +void LockWidget::setStartupMode(bool mode) { -} - -void LockWidget::onGlobalkeyRelease(const QString &key) -{ - if (key == "Escape") { - - } else if (key == "Up" || key == "Down" || key == "Return" || key == "KP_Enter") { - qDebug()<<" key = "<isVisible()) - keyBdRelease(key); + m_isStartupMode = mode; + if (powermanager) { + powermanager->setStartupMode(m_isStartupMode); } } -void LockWidget::keyBdRelease(QString key) +void LockWidget::key_enter_release(int key) +{ + if (tabAt == BOTTMBTN) { + switch (horAT) { + case BATTERYBTN: + showBattery(); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + break; + case SWITCHBTN: + if(scrollArea && scrollArea->isVisible()) { + if(authDialog) + { + if(list.at(nowAt)->objectName() != getenv("USER")) + authDialog->stopAuth(); + } + if(list.at(nowAt)->objectName() == "Guest") + { + displayManager->switchToGuest(); + } + else if(list.at(nowAt)->objectName() == "SwitchUser") + { + displayManager->switchToGreeter(); + } + else + { + if(list.at(nowAt)->objectName() != getenv("USER")) + displayManager->switchToUser(list.at(nowAt)->objectName()); + } + } else { + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + showUserMenu(); + } + break; + case NETWORKBTN: + if(!m_kylinNM || !(m_kylinNM && m_kylinNM->isVisible())) + showNetManager(true); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + authDialog->setFocusin(REMOVE); + break; + case KEYBOARDBTN: + if(!vKeyboard || !(vKeyboard && vKeyboard->isVisible())) + showVirtualKeyboard(); + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + break; + case POWERBTN: + showPowerManager(true); + break; + default: + break; + } + } else if (tabAt == BIOBTN) { + authDialog->setClick(); + } else if (tabAt == ENTERBTN) { + authDialog->checkPassword(); + tabAt = LINEEDIT; + } else if (tabAt == POWERMANAGER) { + powermanager->keyBdRelease(key); + } +} + +void LockWidget::key_tab_release(int key) +{ + if(key == Qt::Key_Tab) { + if (at_plugins) { + authDialog->setFocusin(REMOVE); + return; + } + switch (tabAt) { + case LINEEDIT: + authDialog->setFocusin(IN_LIGIN); + tabAt = ENTERBTN; + break; + case ENTERBTN: + if(authDialog->getBioNum() >1) { + authDialog->setFocusin(BIO_RIGHT); + tabAt = BIOBTN; + } else { + tabAt = BOTTMBTN; + authDialog->setFocusin(REMOVE); + qDebug() << " is_batteryBtn = " << is_batteryBtn; + if(is_batteryBtn){ + horAT = BATTERYBTN; + } else if(users->getUsers().count() > 1){ + horAT = SWITCHBTN; + } else { + horAT =NETWORKBTN; + } + setBottomBtnSheet(); + qDebug() << " horat = " << horAT; + } + break; + case BIOBTN: + tabAt = BOTTMBTN; + authDialog->setFocusin(REMOVE); + qDebug() << " is_batteryBtn = " << is_batteryBtn; + if(is_batteryBtn) { + horAT = BATTERYBTN; + setBottomBtnSheet(); + } else if(users->getUsers().count() > 1){ + horAT = SWITCHBTN; + setBottomBtnSheet(); + } else { + horAT =NETWORKBTN; + setBottomBtnSheet(); + } + qDebug() << " horat = " << horAT; + break; + case BOTTMBTN: + if(!at_power) { + authDialog->setFocusin(IN_LINEEDIT); + tabAt = LINEEDIT; + setBottomBtnSheet(); + } else if (at_power) { + powermanager->keyBdRelease(Qt::Key_Right); + tabAt = POWERMANAGER; + setBottomBtnSheet(); + } + break; + case POWERMANAGER: + powermanager->clearStatus(); + tabAt = BOTTMBTN; + if(is_batteryBtn) { + horAT = BATTERYBTN; + setBottomBtnSheet(); + } else if(users->getUsers().count() > 1){ + horAT = SWITCHBTN; + setBottomBtnSheet(); + } else { + horAT =NETWORKBTN; + setBottomBtnSheet(); + } + break; + case EMPTY: + authDialog->setFocusin(IN_LINEEDIT); + tabAt = LINEEDIT; + setBottomBtnSheet(); + } + } +} + +void LockWidget::key_shiftTab_release() +{ + if (at_plugins) { + authDialog->setFocusin(REMOVE); + return; + } + switch (tabAt) { + case LINEEDIT: + tabAt = BOTTMBTN; + authDialog->setFocusin(REMOVE); + if(is_batteryBtn) + horAT = BATTERYBTN; + else if(users->getUsers().count() > 1){ + horAT = SWITCHBTN; + } else { + horAT =NETWORKBTN; + } + setBottomBtnSheet(); + break; + case ENTERBTN: + authDialog->setFocusin(IN_LINEEDIT); + tabAt = LINEEDIT; + setBottomBtnSheet(); + break; + case BIOBTN: + authDialog->setFocusin(IN_LIGIN); + tabAt = ENTERBTN; + break; + case BOTTMBTN: + if(!at_power) { + if(authDialog->getBioNum() >1) { + authDialog->setFocusin(BIO_RIGHT); + tabAt = BIOBTN; + } else { + authDialog->setFocusin(IN_LIGIN); + tabAt = ENTERBTN; + } + } else { + powermanager->keyBdRelease(Qt::Key_Right); + tabAt = POWERMANAGER; + } + setBottomBtnSheet(); + break; + case POWERMANAGER: + powermanager->clearStatus(); + tabAt = BOTTMBTN; + if(is_batteryBtn) { + horAT = BATTERYBTN; + setBottomBtnSheet(); + } else if(users->getUsers().count() > 1){ + horAT = SWITCHBTN; + setBottomBtnSheet(); + } else { + horAT =NETWORKBTN; + setBottomBtnSheet(); + } + break; + case EMPTY: + authDialog->setFocusin(IN_LINEEDIT); + tabAt = LINEEDIT; + setBottomBtnSheet(); + } +} + +void LockWidget::key_LR_release(int key) +{ + if(key == Qt::Key_Right) { + if(tabAt == BOTTMBTN) { + if (at_plugins) + return; + switch (horAT) { + case BATTERYBTN: + if(is_switchBtn) + horAT = SWITCHBTN; + else + horAT = NETWORKBTN; + break; + case SWITCHBTN: + horAT = NETWORKBTN; + break; + case NETWORKBTN: + horAT = KEYBOARDBTN; + break; + case KEYBOARDBTN: + horAT = POWERBTN; + break; + case POWERBTN: + if(is_batteryBtn) + horAT = BATTERYBTN; + else if(is_switchBtn) + horAT = SWITCHBTN; + else + horAT = NETWORKBTN; + break; + default: + break; + } + setBottomBtnSheet(); + } else if (tabAt == BIOBTN) { + authDialog->setFocusin(BIO_RIGHT); + } else if (tabAt == POWERMANAGER) { + powermanager->keyBdRelease(Qt::Key_Right); + } + } else if (key == Qt::Key_Left) { + if(tabAt == BOTTMBTN) { + if (at_plugins) + return; + switch (horAT) { + case BATTERYBTN: + horAT = POWERBTN; + break; + case SWITCHBTN: + if(is_batteryBtn) + horAT = BATTERYBTN; + else + horAT = POWERBTN; + break; + case NETWORKBTN: + if(is_switchBtn) + horAT = SWITCHBTN; + else if(is_batteryBtn) + horAT = BATTERYBTN; + else + horAT = POWERBTN;; + break; + case KEYBOARDBTN: + horAT = NETWORKBTN; + break; + case POWERBTN: + horAT = KEYBOARDBTN; + break; + default: + break; + } + setBottomBtnSheet(); + } else if (tabAt == BIOBTN) { + authDialog->setFocusin(BIO_LEFT); + } else if (tabAt == POWERMANAGER) { + powermanager->keyBdRelease(Qt::Key_Left); + } + } +} + +void LockWidget::setBottomBtnSheet() +{ + if (tabAt == BOTTMBTN) { + switch (horAT) { + case BATTERYBTN: + ui->btnBatteryStatus->setStyleSheet(ON_TAB_SHEET); + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnKeyboard->setStyleSheet(ON_NORMAL_SHEET); + ui->btnPowerManager->setStyleSheet(ON_NORMAL_SHEET); + break; + case SWITCHBTN: + ui->btnSwitchUser->setStyleSheet(ON_TAB_SHEET); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnKeyboard->setStyleSheet(ON_NORMAL_SHEET); + ui->btnPowerManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + break; + case NETWORKBTN: + btnNetworkManager->setStyleSheet(ON_TAB_SHEET); + ui->btnKeyboard->setStyleSheet(ON_NORMAL_SHEET); + ui->btnPowerManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + break; + case KEYBOARDBTN: + ui->btnKeyboard->setStyleSheet(ON_TAB_SHEET); + ui->btnPowerManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + break; + case POWERBTN: + ui->btnPowerManager->setStyleSheet(ON_TAB_SHEET); + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnKeyboard->setStyleSheet(ON_NORMAL_SHEET); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + break; + default: + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnKeyboard->setStyleSheet(ON_NORMAL_SHEET); + ui->btnPowerManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + break; + } + } else { + ui->btnSwitchUser->setStyleSheet(ON_NORMAL_SHEET); + btnNetworkManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnKeyboard->setStyleSheet(ON_NORMAL_SHEET); + ui->btnPowerManager->setStyleSheet(ON_NORMAL_SHEET); + ui->btnBatteryStatus->setStyleSheet(ON_NORMAL_SHEET); + } +} + +void LockWidget::key_OB_release(int key) { - //usersMenu->setFocus(); QString focus = "focus"; QString normal = "normal"; - if(key == "Up"){ -// if(nowAt == -1){ -// nowAt = 0; -// setButtonStyle(focus); -// } + if(key == Qt::Key_Up){ // "Up" for(int i = 0; i < list.count(); i++){ if(nowAt == i){ if(i == 0) @@ -191,14 +560,13 @@ void LockWidget::keyBdRelease(QString key) nowAt = i-1; /*else if(i == 0){ - qDebug()<<"enheng???111"<setStyleSheet("HoverWidget{background-color:rgb(255,255,255,40%);border-radius: 6px;}" "HoverWidget:hover:!pressed{background-color:rgb(255,255,255,15%);border-radius: 6px;}"); nowAt = list.count() -1; }*/ } } - } else if(key == "Down") { + } else if(key == Qt::Key_Down) { // "Down" for(int i = list.count(); i >= 0; i--){ if(nowAt == i){ if(i == list.count() - 1) @@ -209,33 +577,22 @@ void LockWidget::keyBdRelease(QString key) "HoverWidget:hover:!pressed{background-color:rgb(255,255,255,15%);border-radius: 6px;}"); nowAt = i+1; /*else if(i == list.count() - 1){ - qDebug()<<"enheng???111"<setStyleSheet("HoverWidget{background-color:rgb(255,255,255,40%);border-radius: 6px;}" "HoverWidget:hover:!pressed{background-color:rgb(255,255,255,15%);border-radius: 6px;}"); nowAt = 0; }*/ } } - } else if(key == "Return" || key == "KP_Enter"){ - if(authDialog) - { - authDialog->stopAuth(); - } - if(list.at(nowAt)->objectName() == "Guest") - { - displayManager->switchToGuest(); - } - else if(list.at(nowAt)->objectName() == "SwitchUser") - { - displayManager->switchToGreeter(); - } - else - { - displayManager->switchToUser(list.at(nowAt)->objectName()); - } } } +void LockWidget::resetNavigation() +{ + tabAt = LINEEDIT; + setBottomBtnSheet(); + authDialog->setFocusin(IN_LINEEDIT); +} + void LockWidget::startAuth() { if(authDialog) @@ -255,7 +612,7 @@ void LockWidget::stopAuth() void LockWidget::setX11Focus() { if(authDialog){ - authDialog->setX11Focus(); + //authDialog->setX11Focus(); } } @@ -311,6 +668,54 @@ void LockWidget::initUI() ui->lblDate->adjustSize(); ui->widgetTime->adjustSize(); + //电池电量显示icon + batInterface = new QDBusInterface( + "org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", QDBusConnection::systemBus(), this); + + QString batteryPath = ""; + dface = new QDBusInterface(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTERFACE, QDBusConnection::systemBus(), this); + QDBusReply> reply = dface->call("EnumerateDevices"); + if (dface->isValid()) { + for (QDBusObjectPath op : reply.value()) { + if (op.path().contains("battery_")) { + batteryPath = op.path(); + qDebug() << "battery path is :" << batteryPath; + break; + } + } + } else { + qDebug() << "Enumerate devices failed"; + } + + iface = new QDBusInterface(UPOWER_SERVICE, batteryPath, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); + if (dface->isValid()) { + QDBusReply reply = batInterface->call("Get", "org.freedesktop.UPower", "LidIsPresent"); + if (reply.isValid()) { + if (true == reply.value().toBool()) { + setBatteryIcon(getBatteryIconName()); + QDBusConnection::systemBus().connect( + UPOWER_SERVICE, batteryPath, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealMessage(QDBusMessage))); + ui->btnBatteryStatus->setFixedSize(48,48); + ui->btnBatteryStatus->setIconSize(QSize(24,24)); + ui->btnBatteryStatus->setFocusPolicy(Qt::NoFocus); + ui->btnBatteryStatus->installEventFilter(this); + mBatteryWidget = new BatteryWidget(QPoint(ui->btnBatteryStatus->x(), ui->btnBatteryStatus->y()), this); + mBatteryWidget->hide(); + connect(ui->btnBatteryStatus,&QPushButton::clicked + ,this,&LockWidget::showBattery); + } else { + ui->btnBatteryStatus->hide(); + is_batteryBtn = false; + } + } else { + ui->btnBatteryStatus->hide(); + is_batteryBtn = false; + } + } else { + ui->btnBatteryStatus->hide(); + is_batteryBtn = false; + } + //电源管理 ui->btnPowerManager->setIcon(QIcon(":/image/assets/powerManager.png")); ui->btnPowerManager->setFixedSize(48,48); @@ -322,19 +727,29 @@ void LockWidget::initUI() ,this,&LockWidget::showPowerManager); - QtConcurrent::run([=](){ - updateNetIcon(getNetStatus()); - }); +// QtConcurrent::run([=](){ +// updateNetIcon(getNetStatus()); +// }); - ui->btnNetworkManager->setFixedSize(48,48); - ui->btnNetworkManager->setIconSize(QSize(24,24)); - ui->btnNetworkManager->setFocusPolicy(Qt::NoFocus); + btnNetworkManager = new KyNetworkIcon(this); + btnNetworkManager->setStyleSheet("QPushButton{text-align:center;color: rgb(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;} \ + QPushButton::hover{background-color: rgb(255,255,255,15%);} \ + QPushButton::pressed {background-color: rgba(255,255,255,40%);}\ + QPushButton::checked {background-color: rgba(255, 255, 255, 40%);}"); + btnNetworkManager->setCheckable(true); + btnNetworkManager->setFixedSize(48,48); + btnNetworkManager->setIconSize(QSize(24,24)); + btnNetworkManager->setFocusPolicy(Qt::NoFocus); // ui->btnNetworkManager->setStyleSheet("QPushButton:Hover{border-radius:24px;background-color:rgba(255, 255, 255, 0.15);}" // "QPushButton:Pressed{border-radius:24px;background-color:rgba(255, 255, 255, 0.05);}"); - ui->btnNetworkManager->installEventFilter(this); + btnNetworkManager->installEventFilter(this); + btnNetworkManager->setCursor(Qt::PointingHandCursor); - connect(ui->btnNetworkManager,&QPushButton::clicked - ,this,&LockWidget::showNetManager); + connect(btnNetworkManager,&QPushButton::clicked + ,this, [&,this](){ + this->showNetManager(); + this->setCursor(Qt::ArrowCursor); + }); //虚拟键盘 ui->btnKeyboard->setIcon(QIcon(":/image/assets/keyboard.svg")); @@ -359,57 +774,82 @@ void LockWidget::initUI() ui->btnSwitchUser->setIconSize(QSize(24, 24)); ui->btnSwitchUser->setFixedSize(48, 48); ui->btnSwitchUser->setFocusPolicy(Qt::NoFocus); + ui->btnSwitchUser->setCheckable(true); ui->btnSwitchUser->raise(); connect(ui->btnSwitchUser, &QPushButton::clicked, - this, [&]{ - if(!usersMenu){ - initUserMenu(); - } - - if(scrollArea && scrollArea->isVisible()){ - scrollArea->hide(); - } - else{ - scrollArea->show(); - if(m_kylinNM && m_kylinNM->isVisible()) - m_kylinNM->hide(); - scrollArea->setFocus(); - } - }); + this, &LockWidget::showUserMenu); } } void LockWidget::showVirtualKeyboard() { + tabAt = LINEEDIT; + setBottomBtnSheet(); + tabAt = BOTTMBTN; + horAT = KEYBOARDBTN; if(!vKeyboard){ vKeyboard = new VirtualKeyboard(this); vKeyboard->hide(); connect(vKeyboard, &VirtualKeyboard::aboutToClose, - vKeyboard, &VirtualKeyboard::hide); + this, &LockWidget::hideBottomPlugins); } vKeyboard->setVisible(vKeyboard->isHidden()); + if(!vKeyboard->isHidden()){ vKeyboard->raise(); + authDialog->setFocusin(IN_LINEEDIT); + at_plugins = true; } setVirkeyboardPos(); } -void LockWidget::showPowerManager() +void LockWidget::showUserMenu() +{ + if(!usersMenu){ + initUserMenu(); + } + tabAt = LINEEDIT; + setBottomBtnSheet(); + tabAt = BOTTMBTN; + horAT = SWITCHBTN; + + if(scrollArea && scrollArea->isVisible()){ + setCheckedSheet(SWITCHBTN,false); + at_plugins = false; + authDialog->setFocusin(REMOVE); + } + else{ + setCheckedSheet(SWITCHBTN, true); + at_plugins = true; + if(m_kylinNM && m_kylinNM->isVisible()) + setCheckedSheet(NETWORKBTN, false); + if(mBatteryWidget && mBatteryWidget->isVisible()) + setCheckedSheet(BATTERYBTN, false); + scrollArea->setFocus(); + } +} + +void LockWidget::showPowerManager(bool keynavigation) { if(!powermanager){ - powermanager = new PowerManager(this); + powermanager = new PowerManager(getLoginedNum(), this); + powermanager->setStartupMode(m_isStartupMode); sureWidget = new SureWindow(this); powermanager->hide(); connect(powermanager,SIGNAL(lock()) ,this,SLOT(showPowerManager())); connect(powermanager,SIGNAL(switchToUser()) ,this,SLOT(switchToGreeter())); + connect(powermanager, SIGNAL(showInhibitWarning(QVector&,int)), + this,SLOT(showWarning(QVector&,int))); connect(powermanager, SIGNAL(mulUsersLogined(int)), this,SLOT(switchToSureDialog(int))); + connect(powermanager, SIGNAL(clickedSuspend()) + , this, SLOT(resetNavigation())); sureWidget->adjustSize(); sureWidget->move((width()-sureWidget->geometry().width())/2, (height()-sureWidget->geometry().height())/2); sureWidget->hide(); @@ -420,20 +860,39 @@ void LockWidget::showPowerManager() } if(m_kylinNM && m_kylinNM->isVisible()) - m_kylinNM->hide(); + setCheckedSheet(NETWORKBTN, false); if(scrollArea && scrollArea->isVisible()) - scrollArea->hide(); + setCheckedSheet(SWITCHBTN,false); + if(mBatteryWidget && mBatteryWidget->isVisible()) + setCheckedSheet(BATTERYBTN, false); if(sureWidget && sureWidget->isVisible()) sureWidget->hide(); + if(vKeyboard && vKeyboard->isVisible()) + vKeyboard->hide(); if(powermanager->isVisible()){ - authDialog->setFocus(); authDialog->show(); powermanager->hide(); + tabAt = LINEEDIT; + setBottomBtnSheet(); + authDialog->setFocusin(IN_LINEEDIT); + powermanager->clearStatus(); + at_power = false; } else{ authDialog->hide(); powermanager->show(); powermanager->setFocus(); + if(keynavigation){ + powermanager->keyBdRelease(Qt::Key_Right); + tabAt = POWERMANAGER; + setBottomBtnSheet(); + } else { + tabAt = LINEEDIT; + setBottomBtnSheet(); + tabAt = BOTTMBTN; + horAT = POWERBTN; + } + at_power = true; #ifndef USE_INTEL powermanager->showNormalSize(); #endif @@ -443,13 +902,48 @@ void LockWidget::showPowerManager() } } -void LockWidget::switchToSureDialog(int type) +void LockWidget::setCheckedSheet(int type, bool show) +{ + switch (type) { + case BATTERYBTN: + if(show) { + mBatteryWidget->show(); + ui->btnBatteryStatus->setChecked(true); + } else { + mBatteryWidget->hide(); + ui->btnBatteryStatus->setChecked(false); + } + break; + case SWITCHBTN: + if(show) { + scrollArea->show(); + ui->btnSwitchUser->setChecked(true); + } else { + scrollArea->hide(); + ui->btnSwitchUser->setChecked(false); + } + break; + case NETWORKBTN: + if(show) { + m_kylinNM->show(); + btnNetworkManager->setChecked(true); + } else { + m_kylinNM->hide(); + btnNetworkManager->setChecked(false); + } + break; + default: + break; + } +} + +void LockWidget::showWarning(QVector &wlist, int type) { powermanagerType = type; if(m_kylinNM && m_kylinNM->isVisible()) - m_kylinNM->hide(); + setCheckedSheet(NETWORKBTN, false); if(scrollArea && scrollArea->isVisible()) - scrollArea->hide(); + setCheckedSheet(SWITCHBTN, false); authDialog->hide(); powermanager->hide(); @@ -457,9 +951,34 @@ void LockWidget::switchToSureDialog(int type) sureWidget->setFocus(); ui->widgetTime->hide(); ui->btnPowerManager->hide(); - ui->btnNetworkManager->hide(); + btnNetworkManager->hide(); ui->btnSwitchUser->hide(); ui->btnKeyboard->hide(); + ui->btnBatteryStatus->hide(); + + sureWidget->setWarning(wlist, type); +} + +void LockWidget::switchToSureDialog(int type) +{ + powermanagerType = type; + if(m_kylinNM && m_kylinNM->isVisible()) + setCheckedSheet(NETWORKBTN, false); + if(scrollArea && scrollArea->isVisible()) + setCheckedSheet(SWITCHBTN, false); + + authDialog->hide(); + powermanager->hide(); + sureWidget->show(); + sureWidget->setFocus(); + ui->widgetTime->hide(); + ui->btnPowerManager->hide(); + btnNetworkManager->hide(); + ui->btnSwitchUser->hide(); + ui->btnKeyboard->hide(); + ui->btnBatteryStatus->hide(); + + sureWidget->setTips(tr("Multiple users are logged in at the same time.Are you sure you want to reboot this system?")); } void LockWidget::hideSureDialog() @@ -468,59 +987,161 @@ void LockWidget::hideSureDialog() powermanager->show(); ui->widgetTime->show(); ui->btnPowerManager->show(); - ui->btnNetworkManager->show(); + btnNetworkManager->show(); ui->btnSwitchUser->show(); ui->btnKeyboard->show(); + ui->btnBatteryStatus->show(); } void LockWidget::confirmClicked() { if(m_kylinNM && m_kylinNM->isVisible()) - m_kylinNM->hide(); + setCheckedSheet(NETWORKBTN, false); if(scrollArea && scrollArea->isVisible()) - scrollArea->hide(); + setCheckedSheet(SWITCHBTN, false); + if(mBatteryWidget && mBatteryWidget->isVisible()) + setCheckedSheet(BATTERYBTN, false); sureWidget->hide(); powermanager->hide(); authDialog->show(); ui->widgetTime->show(); ui->btnPowerManager->show(); - ui->btnNetworkManager->show(); + btnNetworkManager->show(); ui->btnSwitchUser->show(); ui->btnKeyboard->show(); + ui->btnBatteryStatus->show(); powermanager->doEvent(powermanagerType); } -void LockWidget::showNetManager() +void LockWidget::showNetManager(bool keynavigation) { + if(!keynavigation) { + tabAt = LINEEDIT; + setBottomBtnSheet(); + tabAt = BOTTMBTN; + horAT = NETWORKBTN; + } if(!m_kylinNM){ - return; + /*这里放在点击按钮后加载,一个原因是启动优化,另一个原因是如果放在构造函数中加载,则必须 + * 先让网络窗口显示出来一次,否则会在锁屏程序退出时,锁屏窗口在closeEvent中崩溃,原因未知 + * 同时,可以尽量降低在未操作网络时,网络程序对锁屏窗口的影响*/ + loadNetPlugin(); + m_kylinNM->hide(); } if(m_kylinNM->isVisible()) { - m_kylinNM->hide(); + setCheckedSheet(NETWORKBTN, false); } else { - m_kylinNM->show(); + setCheckedSheet(NETWORKBTN, true); if(scrollArea && scrollArea->isVisible()) - scrollArea->hide(); + setCheckedSheet(SWITCHBTN, false); + if(mBatteryWidget && mBatteryWidget->isVisible()) + setCheckedSheet(BATTERYBTN, false); m_kylinNM->setGeometry(this->width() - m_kylinNM->width() - 20, this->height() - m_kylinNM->height() - 100, m_kylinNM->width(), m_kylinNM->height()); - m_kylinNM->updateWifiList(); + m_kylinNM->raise(); + m_kylinNM->setFocus(); + /*在150%缩放下,点击网络弹窗左上角有线连接部分,authDialog会收到点击事件导致网络弹窗隐藏, + * 这里只调用m_kylinNM->raise()仍会有问题,需要再调用一次authDialog->lower()才行,原因未知*/ + if(authDialog && authDialog->isVisible()){ + authDialog->lower(); + } + authDialog->clearFocus(); + if(mBatteryWidget && mBatteryWidget->isVisible()) + mBatteryWidget->lower(); + mBatteryWidget->clearFocus(); + at_plugins = true; + + //m_kylinNM->updateWifiList(); } } -void LockWidget::hideNetManager() +void LockWidget::onClickPassword() { - if(!m_kylinNM){ - return; + tabAt = LINEEDIT; + if(is_switchBtn) + horAT = SWITCHBTN; + else + horAT = NETWORKBTN; + setBottomBtnSheet(); + authDialog->setFocusin(IN_LINEEDIT); + + if(m_kylinNM && m_kylinNM->isVisible()) { + setCheckedSheet(NETWORKBTN, false); + at_plugins = false; } + if(scrollArea && scrollArea->isVisible()) { + setCheckedSheet(SWITCHBTN, false); + at_plugins = false; + } + + if(vKeyboard && vKeyboard->isVisible()) { + vKeyboard->hide(); + at_plugins = false; + } +} + +void LockWidget::showBattery() +{ + if(mBatteryWidget->isVisible()) { + setCheckedSheet(BATTERYBTN, false); + at_plugins = false; + } else { + setCheckedSheet(BATTERYBTN, true); + at_plugins = true; + } + + tabAt = LINEEDIT; + setBottomBtnSheet(); + tabAt = BOTTMBTN; + horAT = BATTERYBTN; + if(scrollArea && scrollArea->isVisible()){ + setCheckedSheet(SWITCHBTN, false); + } else if (m_kylinNM && m_kylinNM->isVisible()){ + setCheckedSheet(NETWORKBTN, false); + } +} + +void LockWidget::hideBottomPlugins() +{ if(m_kylinNM && m_kylinNM->isVisible()) - m_kylinNM->hide(); + setCheckedSheet(NETWORKBTN, false); + if(scrollArea && scrollArea->isVisible()) - scrollArea->hide(); + setCheckedSheet(SWITCHBTN, false); + + if(vKeyboard && vKeyboard->isVisible()) { + vKeyboard->hide(); + at_plugins = false; + } + //tabAt = EMPTY; + tabAt = LINEEDIT; + setBottomBtnSheet(); +} + +void LockWidget::setBatteryIcon(QString str) +{ + QPixmap pixmap = QIcon::fromTheme(str).pixmap(QSize(24, 24)); + QImage img = pixmap.toImage(); + for (int x = 0; x < img.width(); x++) { + for (int y = 0; y < img.height(); y++) { + QColor color = img.pixelColor(x, y); + color.setRed(255); + color.setGreen(255); + color.setBlue(255); + img.setPixelColor(x, y, color); + } + } + ui->btnBatteryStatus->setIcon(QPixmap::fromImage(img)); +} + +void LockWidget::dealMessage(QDBusMessage) +{ + setBatteryIcon(getBatteryIconName()); } int LockWidget::getNetStatus() @@ -559,22 +1180,109 @@ void LockWidget::updateNetIcon(int status) switch(status) { case 0: //有线 - ui->btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-wired.png")); + btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-wired.png")); break; case 1: //无线 - ui->btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-wifi.png")); + btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-wifi.png")); break; case 2: //有线+无线 - ui->btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-wired.png")); + btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-wired.png")); break; default: //无连接 - ui->btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-no-signal.png")); + btnNetworkManager->setIcon(QIcon(":/image/assets/intel/icon-no-signal.png")); } } +void LockWidget::loadNetPlugin() +{ + m_kylinNM = new QWidget(this); + m_kylinNM->setFixedSize(420,480); + m_kylinNM->setObjectName("m_kylinNM"); + m_kylinNM->setStyleSheet("#m_kylinNM{background-color: white; border-radius:12px;}"); + + mkylinNM = new MyTabWidget(m_kylinNM); + mkylinNM->setFixedSize(420,480); + mkylinNM->tabBar()->setFixedHeight(40); + mkylinNM->installEventFilter(this); + + QPluginLoader netloader("/usr/lib/kylin-nm/libnetconnect.so");//有线 + QPluginLoader wlanloader("/usr/lib/kylin-nm/libwlanconnect.so");//无线 + + if (netloader.load()) { + QObject * plugin = netloader.instance(); + + if (plugin) { + Interface * pluginInstance = qobject_cast(plugin); + // 插件是否启用 + if (!pluginInstance) { + return; + } + + pluginInstance->setPluginType(SIMPLE); + QWidget *widget = pluginInstance->pluginUi(); + mkylinNM->addTab(widget,""); + + } else { + qDebug() << "Load Failed: " << netloader.errorString() << "\n"; + return; + } + } else { + qDebug() << "Load Failed: " << netloader.errorString() << "\n"; + return; + } + + if (wlanloader.load()) { + QObject * plugin = wlanloader.instance(); + + if (plugin) { + Interface * pluginInstance = qobject_cast(plugin); + // 插件是否启用 + if (!pluginInstance) { + return; + } + + pluginInstance->setPluginType(SIMPLE); + /*这里需要先调用setParentWidget,否则会出现网络连接弹窗无法弹出来的问题*/ + pluginInstance->setParentWidget(this); + QWidget *widget = pluginInstance->pluginUi(); + mkylinNM->addTab(widget,""); + + } else { + qDebug() << "Load Failed: " << wlanloader.errorString() << "\n"; + return; + } + } else { + qDebug() << "Load Failed: " << wlanloader.errorString() << "\n"; + return; + } + + + QHBoxLayout *m_tabBarLayout = new QHBoxLayout(mkylinNM); + m_tabBarLayout->setContentsMargins(0,0,0,0); + QLabel *m_lanLabel = new QLabel(tr("LAN")); + m_lanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + QLabel *m_wlanLabel = new QLabel(tr("WLAN")); + m_wlanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + m_tabBarLayout->addWidget(m_lanLabel); + m_tabBarLayout->addWidget(m_wlanLabel); + mkylinNM->tabBar()->setLayout(m_tabBarLayout); + mkylinNM->tabBar()->setFixedWidth(420); + QPalette pal = qApp->palette(); + pal.setBrush(QPalette::Background, Qt::white); +// m_kylinNM->setPalette(pal); + mkylinNM->widget(0)->setPalette(pal); + mkylinNM->widget(1)->setPalette(pal); + + m_kylinNM->setGeometry(this->width() - mkylinNM->width() - 20, + this->height() - mkylinNM->height() - 100, + mkylinNM->width(), + mkylinNM->height()); + +} + void LockWidget::switchToGreeter() { if(authDialog) @@ -617,6 +1325,13 @@ void LockWidget::initUserMenu() usersMenu = new QMenu(scrollContents); usersMenu->setObjectName("usersMenu"); usersMenu->setToolTipsVisible(true); + usersMenu->setStyleSheet("QMenu{background-color: rgb(255,255,255,15%);color: white;border-radius: 4px;width:250px;font-size: 16px;padding: 5px 5px 5px 5px;} \ + QMenu::icon{padding: 2px 5px 2px 5px;}\ + QMenu::item{width:225px;border-radius: 4px;height:36px;font-size:16px;padding: 2px 10px 2px 10px;} \ + QMenu::item:selected {border-radius: 4px;background-color:rgb(255,255,255,40%);} \ + QMenu::item:pressed {border-radius: 4px;background-color: rgb(255,255,255,40%);} \ + QLabel {color: white;font-size: 16px;}"); + // usersMenu->setStyleSheet("QMenu{background-color:transparent;color:white;padding:5px 5px 5px 8px}"); //QToolTip{border-radius:4px;background-color:rgb(255,255,255,40%);color:white;} //如果没有设置x11属性,则由于弹出菜单受窗口管理器管理,而主窗口不受,在点击菜单又点回主窗口会闪屏。 @@ -637,6 +1352,7 @@ void LockWidget::initUserMenu() widget->setFixedSize(240, 40); QLabel *iconlabel =new QLabel(widget); QPixmap p(users->getDefaultIcon()); + p = scaledPixmap(p); p = p.scaled(32*scale,32*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); p = PixmapToRound(p, 16*scale); iconlabel->setPixmap(p); @@ -671,6 +1387,7 @@ void LockWidget::initUserMenu() widget->setFixedSize(240, 40); QLabel *iconlabel =new QLabel(widget); QPixmap p(users->getDefaultIcon()); + p = scaledPixmap(p); p = p.scaled(32*scale,32*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); p = PixmapToRound(p, 16*scale); iconlabel->setPixmap(p); @@ -695,13 +1412,13 @@ void LockWidget::initUserMenu() "HoverWidget:hover:!pressed{background-color:rgb(255,255,255,15%);border-radius: 6px;}"); } } - scrollContents->setFixedSize(usersMenu->width() - 14, usersMenu->height()); + scrollContents->setFixedSize(usersMenu->width(), usersMenu->height()); //设置弹出菜单,设置弹出菜单的坐标为切换用户按钮的上方,中间保持一定间隔。 if(scrollArea){ if(scrollContents->height() < height()/2){ - scrollArea->setFixedSize(usersMenu->width(),scrollContents->height()+1); + scrollArea->setFixedSize(usersMenu->width(), scrollContents->height()+1); }else{ - scrollArea->setFixedSize(usersMenu->width() + 4, height()/2); + scrollArea->setFixedSize(usersMenu->width() + 16, height()/2); } scrollArea->move(ui->btnSwitchUser->geometry().x()- scrollArea->width()/2 + 24, \ height() - 72 - scrollArea->height() - 5); @@ -711,9 +1428,25 @@ void LockWidget::initUserMenu() void LockWidget::keyReleaseEvent(QKeyEvent *e) { - if(e->key() == Qt::Key_K){ + Q_EMIT keyGlobalRelease(e->key()); + +/* if (e->key() == 9) { // "Escape" + + } else */if(e->key() == Qt::Key_K){ if(e->modifiers() & Qt::ControlModifier) showVirtualKeyboard(); + } else if (e->key() == Qt::Key_Tab) { + key_tab_release(e->key()); + } else if(e->key() == Qt::Key_Backtab){ + if(e->modifiers() & Qt::ShiftModifier) + key_shiftTab_release(); + } else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down) { // "Up" "Down" + if(scrollArea && scrollArea->isVisible()) + key_OB_release(e->key()); + } else if (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right ) { // "Left" "Right" + key_LR_release(e->key()); + } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter || e->key() == Qt::Key_Space) { // "Return" "KP_Enter" "Space" + key_enter_release(e->key()); } } @@ -726,8 +1459,11 @@ void LockWidget::resizeEvent(QResizeEvent *event) //系统时间 ui->widgetTime->move((width()-ui->widgetTime->geometry().width())/2, 59*scale); - if(sureWidget) + + if(sureWidget){ + sureWidget->adjustSize(); sureWidget->move((width()-sureWidget->geometry().width())/2, (height()-sureWidget->geometry().height())/2); + } //认证窗口 //设置认证窗口左右居中 @@ -749,21 +1485,32 @@ void LockWidget::resizeEvent(QResizeEvent *event) x = x+ui->btnKeyboard->width()+16; ui->btnKeyboard->move(width() - x, height() - y); - x = x + ui->btnNetworkManager->width()+16; - ui->btnNetworkManager->move(width() - x, height() - y); + x = x + btnNetworkManager->width()+16; + btnNetworkManager->move(width() - x, height() - y); - x = x + ui->btnSwitchUser->width()+16; - ui->btnSwitchUser->move(width() - x, height() - y); + if(!ui->btnSwitchUser->isHidden()) { + x = x + ui->btnSwitchUser->width()+16; + ui->btnSwitchUser->move(width() - x, height() - y); + } + + x = x + ui->btnBatteryStatus->width()+16; + ui->btnBatteryStatus->move(width() - x, height() - y); setVirkeyboardPos(); + if (mBatteryWidget) { + mBatteryWidget->setFixedSize(314, 112); + mBatteryWidget->setPoint(QPoint(width() - 334, ui->btnBatteryStatus->y() - 16)); + } + + if(scrollContents && usersMenu) - scrollContents->setFixedSize(usersMenu->width() - 14, usersMenu->height()); + scrollContents->setFixedSize(usersMenu->width(), usersMenu->height()); //设置弹出菜单,设置弹出菜单的坐标为切换用户按钮的上方,中间保持一定间隔。 if(scrollArea){ if(scrollContents->height() < height()/2){ scrollArea->setFixedSize(usersMenu->width(),scrollContents->height()+1); }else{ - scrollArea->setFixedSize(usersMenu->width() + 4, height()/2); + scrollArea->setFixedSize(usersMenu->width() + 16, height()/2); } scrollArea->move(ui->btnSwitchUser->geometry().x()- scrollArea->width()/2 + 24, \ height() - y - scrollArea->height() - 5); @@ -788,7 +1535,7 @@ void LockWidget::resizeEvent(QResizeEvent *event) powermanager->width(),powermanager->height()); } - XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); +// XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); } @@ -805,6 +1552,7 @@ void LockWidget::onUserAdded(const UserItem &user) widget->setFixedSize(240, 40); QLabel *iconlabel =new QLabel(widget); QPixmap p(user.icon); + p = scaledPixmap(p); p = p.scaled(32*scale,32*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); p = PixmapToRound(p, 16*scale); iconlabel->setPixmap(p); @@ -816,6 +1564,7 @@ void LockWidget::onUserAdded(const UserItem &user) if(getLoadStatus(user.name)){ QLabel *statusIcon = new QLabel(widget); QPixmap status(":/image/assets/selected.svg"); + status = scaledPixmap(status); status = status.scaled(14*scale,14*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); p = PixmapToRound(status, 7*scale); statusIcon->setPixmap(status); @@ -837,24 +1586,6 @@ void LockWidget::onUserAdded(const UserItem &user) usersMenu->adjustSize(); } -QPixmap LockWidget::PixmapToRound(const QPixmap &src, int radius) -{ - if (src.isNull()) { - return QPixmap(); - } - - QPixmap pixmapa(src); - QPixmap pixmap(radius*2,radius*2); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QPainterPath path; - path.addEllipse(0, 0, radius*2, radius*2); - painter.setClipPath(path); - painter.drawPixmap(0, 0, radius*2, radius*2, pixmapa); - return pixmap; -} - void LockWidget::onUserDeleted(const UserItem &user) { for(auto action : usersMenu->actions()) @@ -947,23 +1678,91 @@ void LockWidget::onUserMenuTrigged(QAction *action) bool LockWidget::exitSubWidget() { bool allExited = true; - if(scrollArea && scrollArea->isVisible()){ - scrollArea->hide(); + if(mBatteryWidget && mBatteryWidget->isVisible()) { + setCheckedSheet(BATTERYBTN, false); + at_plugins = false; + if(tabAt == BOTTMBTN && horAT == BATTERYBTN) + ui->btnBatteryStatus->setStyleSheet(ON_TAB_SHEET); + } else if(scrollArea && scrollArea->isVisible()){ + setCheckedSheet(SWITCHBTN, false); + at_plugins = false; + if(tabAt == BOTTMBTN && horAT == SWITCHBTN) + ui->btnSwitchUser->setStyleSheet(ON_TAB_SHEET); allExited = false; - } - if(powermanager && powermanager->isVisible()){ - authDialog->setFocus(); + } else if(m_kylinNM && m_kylinNM->isVisible()){ + setCheckedSheet(NETWORKBTN, false); + at_plugins = false; + if(tabAt == BOTTMBTN && horAT == NETWORKBTN) + btnNetworkManager->setStyleSheet(ON_TAB_SHEET); + allExited = false; + } else if(vKeyboard && vKeyboard->isVisible()) { + vKeyboard->hide(); + at_plugins = false; + if(tabAt == BOTTMBTN && horAT == KEYBOARDBTN) + ui->btnKeyboard->setStyleSheet(ON_TAB_SHEET); + allExited = false; + } else if(powermanager && powermanager->isVisible()){ authDialog->show(); powermanager->hide(); + tabAt = LINEEDIT; + setBottomBtnSheet(); + authDialog->setFocusin(IN_LINEEDIT); + powermanager->clearStatus(); + at_power = false; allExited = false; } - if(m_kylinNM && m_kylinNM->isVisible()){ - m_kylinNM->hide(); - allExited = false; - } + if(tabAt != LINEEDIT) + authDialog->setFocusin(REMOVE); +// if (!is_keynavigation) { +// resetNavigation(); +// } return allExited; } +void LockWidget::onActiveWindpw() +{ + if(tabAt == LINEEDIT) { + if(authDialog && authDialog->isVisible()) + authDialog->setFocusin(IN_LINEEDIT); + } +} + +QString LockWidget::getBatteryIconName() +{ + if (iface->isValid() && dface->isValid()) { + bool batteryState = false; + QDBusReply reply = batInterface->call("Get", UPOWER_SERVICE, "OnBattery"); + if (reply.isValid()) { + batteryState = reply.value().toBool(); + } + double percentage = -1.0; + QDBusReply percentage_reply = iface->call("Get", UPOWER_DIVICES_SERVICE, "Percentage"); + if (percentage_reply.isValid()) { + percentage = percentage_reply.value().toDouble(); + } + + if (true == batteryState) { + return QString("battery-level-%1-symbolic").arg((int)percentage / 10 * 10); + } else { + return QString("battery-level-%1-charging-symbolic").arg((int)percentage / 10 * 10); + } + } + return QString(); +} + +int LockWidget::getLoginedNum() +{ + if(loginedNum != 0) + return loginedNum; + for(auto user : users->getUsers()) + { + if(getLoadStatus(user.name)){ + loginedNum++; + } + } + return loginedNum; +} + QDBusArgument &operator <<(QDBusArgument &arg, const userInfo &usersInfo) { arg.beginStructure(); diff --git a/src/lockwidget.h b/src/lockwidget.h index c8352c3..08030b4 100644 --- a/src/lockwidget.h +++ b/src/lockwidget.h @@ -25,8 +25,13 @@ #include #include #include +#include +#include +#include "kylin-nm/kylin-nm-interface.h" #include "surewindow.h" +#include "lockchecker.h" #include "xeventmonitor.h" +#include "batterywidget.h" namespace Ui { class LockWidget; @@ -52,6 +57,23 @@ class QMenu; class QScrollArea; class KylinNM; +enum TABAT { + EMPTY = -1, + LINEEDIT = 0, + ENTERBTN, + BIOBTN, + BOTTMBTN, + POWERMANAGER, +}; + +enum HORIZONBTN { + BATTERYBTN = 0, + SWITCHBTN, + NETWORKBTN, + KEYBOARDBTN, + POWERBTN, +}; + class LockWidget : public QWidget { Q_OBJECT @@ -64,8 +86,13 @@ public: void stopAuth(); void setX11Focus(); bool exitSubWidget(); + void setStartupMode(bool mode); + void onActiveWindpw(); + QString getBatteryIconName(); + Q_SIGNALS: void closed(); + void keyGlobalRelease(int key); // void capsLockChanged(); private: @@ -75,22 +102,35 @@ private: void updateNetIcon(int status); bool getLoadStatus(const QString &name); int getNetStatus(); - QPixmap PixmapToRound(const QPixmap &src, int radius); - void keyBdRelease(QString key); + void key_OB_release(int key); + void key_tab_release(int key); + void key_shiftTab_release(); + void key_LR_release(int key); + void key_enter_release(int key); + int getLoginedNum(); + void loadNetPlugin(); + void setBottomBtnSheet(); + void setCheckedSheet(int type, bool show); private Q_SLOTS: void onUserAdded(const UserItem &user); void onUserDeleted(const UserItem &user); void onUserMenuTrigged(QAction *action); void showVirtualKeyboard(); - void showPowerManager(); - void showNetManager(); + void showPowerManager(bool keynavigation = false); + void showUserMenu(); + void showNetManager(bool keynavigation = false); + void showBattery(); void switchToGreeter(); void switchToSureDialog(int type); + void showWarning(QVector &list, int type); void hideSureDialog(); void confirmClicked(); - void hideNetManager(); - void onGlobalKeyPress(const QString &key); - void onGlobalkeyRelease(const QString &key); + void onClickPassword(); + void hideBottomPlugins(); + void resetNavigation(); + void setBatteryIcon(QString str); + void dealMessage(QDBusMessage); + protected: bool eventFilter(QObject *obj, QEvent *event); void resizeEvent(QResizeEvent *event); @@ -112,13 +152,28 @@ private: QScrollArea *scrollArea; QWidget *scrollContents; - KylinNM *m_kylinNM = nullptr; + QWidget *m_kylinNM = nullptr; + BatteryWidget *mBatteryWidget = nullptr; + QTabWidget *mkylinNM = nullptr; QWidget *m_NetManagerWidget; QStringList m_loginedUser; bool isNetFinished = false; int powermanagerType; - XEventMonitor *xEventMonitor; int nowAt = -1; + int loginedNum = 0; + QPushButton *btnNetworkManager = nullptr; + bool m_isStartupMode = false; + bool is_switchBtn = true; + bool is_batteryBtn = true; + bool is_keynavigation =false; + int tabAt = LINEEDIT; + int horAT = BATTERYBTN; + int at_power = false; + bool at_plugins = false; + + QDBusInterface *batInterface = nullptr; + QDBusInterface *iface = nullptr; + QDBusInterface *dface = nullptr; }; #endif // LOCKWIDGET_H diff --git a/src/lockwidget.ui b/src/lockwidget.ui index 22caea6..b6c8c42 100644 --- a/src/lockwidget.ui +++ b/src/lockwidget.ui @@ -28,6 +28,23 @@ Qt::NoFocus + + QPushButton{ + text-align:center; + color: rgb(255, 255, 255, 255); + border: none; + border-radius: 4px; + outline: none; +} +QPushButton::hover{ + background-color: rgb(255,255,255,15%); +} +QPushButton::pressed { + background-color: rgba(255,255,255,40%); +} + + + @@ -73,6 +90,23 @@ Qt::NoFocus + + QPushButton{ + text-align:center; + color: rgb(255, 255, 255, 255); + border: none; + border-radius: 4px; + outline: none; +} +QPushButton::hover{ + background-color: rgb(255,255,255,15%); +} +QPushButton::pressed { + background-color: rgba(255,255,255,40%); +} + + + @@ -89,24 +123,56 @@ PointingHandCursor + + QPushButton{ + text-align:center; + color: rgb(255, 255, 255, 255); + border: none; + border-radius: 4px; + outline: none; +} +QPushButton::hover{ + background-color: rgb(255,255,255,15%); +} +QPushButton::pressed { + background-color: rgba(255,255,255,40%); +} + + + - + - 370 + 330 10 - 80 - 26 + 97 + 32 PointingHandCursor - - Qt::NoFocus + + QPushButton::menu-indicator{ + image:none; +} +QPushButton{ + text-align:center; + color: rgb(255, 255, 255, 255); + border: none; + border-radius: 4px; + outline: none; +} +QPushButton::hover{ + background-color: rgb(255,255,255,15%); +} +QPushButton::pressed { + background-color: rgba(255,255,255,40%); +} diff --git a/src/loginedusers.cpp b/src/loginedusers.cpp new file mode 100644 index 0000000..5d7f440 --- /dev/null +++ b/src/loginedusers.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "loginedusers.h" + +QDBusArgument &operator<<(QDBusArgument &argument, const LoginedUsers &mystruct) +{ + argument.beginStructure(); + argument << mystruct.uid << mystruct.userName << mystruct.objpath;//< mystruct.usergroup; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, LoginedUsers &mystruct) +{ + argument.beginStructure(); + argument >> mystruct.uid >> mystruct.userName >> mystruct.objpath;// >> mystruct.usergroup; + argument.endStructure(); + return argument; +} diff --git a/src/loginedusers.h b/src/loginedusers.h new file mode 100644 index 0000000..c69ebe5 --- /dev/null +++ b/src/loginedusers.h @@ -0,0 +1,41 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef LOGINEDUSER_H +#define LOGINEDUSER_H + +#include + +struct LoginedUsers +{ + int uid; + QString userName; + QDBusObjectPath objpath; +}; + +QDBusArgument &operator<<(QDBusArgument &argument, const LoginedUsers &mystruct); + +const QDBusArgument &operator>>(const QDBusArgument &argument, LoginedUsers &mystruct); + + + +Q_DECLARE_METATYPE(LoginedUsers) + +#endif // LOGINEDUSER_H diff --git a/src/loginoptionswidget.cpp b/src/loginoptionswidget.cpp index c35e09d..943cbff 100644 --- a/src/loginoptionswidget.cpp +++ b/src/loginoptionswidget.cpp @@ -12,17 +12,32 @@ #include #include #include +#include #include #include #include #include #include -LoginOptionsWidget::LoginOptionsWidget(BiometricProxy* proxy, int uid, QWidget *parent) +#define ON_TAB_SHEET "QPushButton{background-color: rgba(255,255,255,15%); border-radius: 4px; border: 2px solid #2C73C8;}" +#define ON_NORMAL_SHEET "QPushButton{background-color: rgba(255,255,255,0); border-radius: 4px; border: none;}\ + QPushButton::hover{ background-color: rgb(255,255,255,15%);}\ + QPushButton::pressed {background-color: rgba(255,255,255,40%);}\ + QPushButton::checked {background-color: rgba(255, 255, 255, 40%);}" + +LoginOptionsWidget::LoginOptionsWidget(BiometricProxy* proxy, int uid, UniAuthService* uniauthService, QWidget *parent) : QWidget(parent) , m_biomericProxy(proxy) , m_uid(uid) + , m_uniauthService(uniauthService) { + m_listPriority.clear(); + m_listPriority.push_back(BioT_Face); + m_listPriority.push_back(BioT_FingerPrint); + m_listPriority.push_back(BioT_Iris); + m_listPriority.push_back(BioT_VoicePrint); + m_listPriority.push_back(BioT_FingerVein); + m_listPriority.push_back(REMOTE_QRCODE_TYPE); initUI(); initConnections(); m_mapDisableDev.clear(); @@ -129,17 +144,37 @@ DeviceInfoPtr LoginOptionsWidget::getFirstDevInfo() return devInfo; } +DeviceInfoPtr LoginOptionsWidget::getWechatDevice() +{ + DeviceInfoPtr devInfo = nullptr; + DeviceMap::iterator itDevInfo = m_mapDevices.begin(); + for (; itDevInfo != m_mapDevices.end(); itDevInfo++) { + for (auto devinfo : itDevInfo.value()) { + if (devinfo && devinfo->deviceType == REMOTE_QRCODE_TYPE) { + if (!isDeviceDisable(devinfo->id)) { + devInfo = devinfo; + break; + } + } + } + if (devInfo) { + break; + } + } + return devInfo; +} + void LoginOptionsWidget::addOptionButton(unsigned uLoginOptType, int nDrvId, QString strDrvName) { if (m_mapOptBtns.contains(nDrvId)) { return ; } - QToolButton *newButton = new QToolButton(); + QPushButton *newButton = new QPushButton(); QVBoxLayout *layoutBtn = new QVBoxLayout(); newButton->setLayout(layoutBtn); - QLabel *newLabel = new QLabel(); + //QLabel *newLabel = new QLabel(); layoutBtn->setAlignment(Qt::AlignCenter); - layoutBtn->addWidget(newLabel); + //layoutBtn->addWidget(newLabel); newButton->setCheckable(true); newButton->setChecked(false); newButton->setFocusPolicy(Qt::NoFocus); @@ -177,7 +212,8 @@ void LoginOptionsWidget::addOptionButton(unsigned uLoginOptType, int nDrvId, QSt iconPixmap = loadSvg(":/image/assets/ukui-loginopt-qrcode.svg", "white", 16); break; } - newLabel->setPixmap(iconPixmap); + newButton->setIcon(iconPixmap); + //newLabel->setPixmap(iconPixmap); newButton->setToolTip(strDrvName); newButton->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); newButton->setFixedSize(48, 48); @@ -193,7 +229,7 @@ void LoginOptionsWidget::addOptionButton(unsigned uLoginOptType, int nDrvId, QSt void LoginOptionsWidget::clearOptionButtons() { - QMap::iterator itMapBtn = m_mapOptBtns.begin(); + QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { if (itMapBtn.value()) { m_btnGroup->removeButton(itMapBtn.value()); @@ -220,7 +256,7 @@ void LoginOptionsWidget::updateOptionButtons() qDebug()<<"m_mapOptBtns.size():"<hide(); - QMap::iterator itMapBtn = m_mapOptBtns.begin(); + QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { if (itMapBtn.value()) { itMapBtn.value()->hide(); @@ -228,7 +264,7 @@ void LoginOptionsWidget::updateOptionButtons() } } else { m_labelOptTitle->show(); - QMap::iterator itMapBtn = m_mapOptBtns.begin(); + QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { if (itMapBtn.value()) { itMapBtn.value()->show(); @@ -246,9 +282,10 @@ void LoginOptionsWidget::setUser(int uid) void LoginOptionsWidget::readDevicesInfo() { m_mapDevices.clear(); - bool isAuthEnable = GetAuthEnable(); - bool isQRCodeEnable = GetQRCodeEnable(); + bool isAuthEnable = getBioAuthEnable(ENABLETYPE_SAVER); + bool isQRCodeEnable = getQRCodeEnable(); DeviceList deviceList = m_biomericProxy->GetDevList(); + QStringList listDefDevices = getAllDefDevices(); for(auto pDeviceInfo : deviceList) { qDebug()<<"BeginGetFeature------!"; @@ -261,7 +298,10 @@ void LoginOptionsWidget::readDevicesInfo() continue; int nDevType = LOGINOPT_TYPE_OTHERS; nDevType = convertDeviceType(pDeviceInfo->deviceType); - m_mapDevices[nDevType].push_back(pDeviceInfo); + if (listDefDevices.contains(pDeviceInfo->shortName) && + !m_mapDevices.contains(nDevType)) { + m_mapDevices[nDevType].push_back(pDeviceInfo); + } } } updateOptionButtons(); @@ -304,6 +344,8 @@ void LoginOptionsWidget::startAuth_() m_isInAuth = true; m_dupFD = -1; + Q_EMIT setLoadingImage(); + QDBusPendingCall call = m_biomericProxy->Identify(m_curDevInfo->id, m_uid); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, @@ -362,6 +404,10 @@ void LoginOptionsWidget::onIdentifyComplete(QDBusPendingCallWatcher *watcher) Q_EMIT authComplete(false, 1); } else if (ret.opsStatus == OPS_IDENTIFY_STOP_BY_USER || ret.opsStatus == OPS_VERIFY_STOP_BY_USER) { Q_EMIT authComplete(false, -2); // 主动停止,直接重试 + } else if (ret.opsStatus == OPS_OPEN_FAIL || ret.opsStatus == OPS_OPEN_ERROR) { // 无法打开设备(设备是坏的/被占用),直接禁用 + Q_EMIT authComplete(false, 5); + } else if (ret.opsStatus >= OPS_GET_FLIST_SUCCESS && ret.opsStatus <= OPS_GET_FLIST_MAX) { + Q_EMIT authComplete(false, -3); // 主动停止,直接重试 } else { Q_EMIT authComplete(false, 2); } @@ -520,7 +566,10 @@ void LoginOptionsWidget::onUSBDeviceHotPlug(int drvid, int action, int /*devNum* //设备数量发生了变化 if(count != savedCount) { updateOptionButtons(); - Q_EMIT notifyOptionsChange(count); + Q_EMIT notifyOptionsChange(count, at_bioBtn); + if(at_bioBtn && count >= 1) + tabOptionSelected(FirstDevice); + updateUIStatus(); } } @@ -534,14 +583,14 @@ bool LoginOptionsWidget::getAuthDouble() void LoginOptionsWidget::updateUIStatus() { if (m_mapOptBtns.contains(-1)) { - QToolButton* btn = m_mapOptBtns[-1]; + QPushButton* btn = m_mapOptBtns[-1]; if (btn) { btn->setChecked(true); } } if (m_curDevInfo) { if (m_mapOptBtns.contains(m_curDevInfo->id)) { - QToolButton* btn = m_mapOptBtns[m_curDevInfo->id]; + QPushButton* btn = m_mapOptBtns[m_curDevInfo->id]; if (btn) { btn->setChecked(true); } @@ -549,18 +598,148 @@ void LoginOptionsWidget::updateUIStatus() } } -void LoginOptionsWidget::onOptionSelected(int nIndex) +void LoginOptionsWidget::onOptionSelected(int nIndex, bool keyNavigation) { if (nIndex < 0) return; + if(!keyNavigation) + tabOptionSelected(CLEAR); if (nIndex < m_listDriveId.size()) { DeviceInfoPtr info = findDeviceById(m_listDriveId[nIndex]); if (info && !isDeviceDisable(info->id)) { - Q_EMIT optionSelected(convertDeviceType(info->deviceType), info); + Q_EMIT optionSelected(convertDeviceType(info->deviceType), info ,keyNavigation); } } } +void LoginOptionsWidget::tabOptionSelected(int option) +{ + switch(option) { + case RIGHT: + at_bioBtn = true; + if(nowAt+1 < m_listDriveId.count()) { + DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[nowAt+1]); + if (infoNow) { + QPushButton* btn = m_mapOptBtns[infoNow->id]; + if (btn) { + btn->setStyleSheet(ON_TAB_SHEET); + } + } + if(nowAt >= 0) { + DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[nowAt]); + if (infoOld) { + QPushButton* btn = m_mapOptBtns[infoOld->id]; + if (btn) { + btn->setStyleSheet(ON_NORMAL_SHEET); + } + } + } + nowAt += 1; + } else if (nowAt+1 == m_listDriveId.count()) { + DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[0]); + if (infoNow) { + QPushButton* btn = m_mapOptBtns[infoNow->id]; + if (btn) { + btn->setStyleSheet(ON_TAB_SHEET); + } + } + DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[nowAt]); + if (infoOld) { + QPushButton* btn = m_mapOptBtns[infoOld->id]; + if (btn) { + btn->setStyleSheet(ON_NORMAL_SHEET); + } + } + nowAt = 0; + } + break; + case LEFT: + at_bioBtn = true; + if(nowAt-1 >= 0) { + DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[nowAt-1]); + if (infoNow) { + QPushButton* btn = m_mapOptBtns[infoNow->id]; + if (btn) { + btn->setStyleSheet(ON_TAB_SHEET); + } + } + DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[nowAt]); + if (infoOld) { + QPushButton* btn = m_mapOptBtns[infoOld->id]; + if (btn) { + btn->setStyleSheet(ON_NORMAL_SHEET); + } + } + nowAt -= 1; + } else if (nowAt-1 < 0) { + DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[m_listDriveId.count() - 1]); + if (infoNow) { + QPushButton* btn = m_mapOptBtns[infoNow->id]; + if (btn) { + btn->setStyleSheet(ON_TAB_SHEET); + } + } + DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[0]); + if (infoOld) { + QPushButton* btn = m_mapOptBtns[infoOld->id]; + if (btn) { + btn->setStyleSheet(ON_NORMAL_SHEET); + } + } + nowAt = m_listDriveId.count() - 1; + } + break; + case CLEAR: + at_bioBtn = false; + if(nowAt >= 0) { + for(int i = 0; i < getLoginOptCount(); i++) { + DeviceInfoPtr infoClear = findDeviceById(m_listDriveId[i]); + if (infoClear) { + QPushButton* btn = m_mapOptBtns[infoClear->id]; + if (btn) { + btn->setStyleSheet(ON_NORMAL_SHEET); + } + } + } + nowAt = -1; + } + break; + case FirstDevice: + at_bioBtn = true; + if(nowAt >= 0) { + for(int i = 0; i < getLoginOptCount(); i++) { + DeviceInfoPtr infoClear = findDeviceById(m_listDriveId[i]); + if (infoClear) { + QPushButton* btn = m_mapOptBtns[infoClear->id]; + if (btn) { + btn->setStyleSheet(ON_NORMAL_SHEET); + } + } + } + DeviceInfoPtr infoFirst = findDeviceById(m_listDriveId[0]); + if (infoFirst) { + QPushButton* btn = m_mapOptBtns[infoFirst->id]; + if (btn) { + btn->setStyleSheet(ON_TAB_SHEET); + } + } + nowAt = 0; + } + break; + case CLICK: + at_bioBtn = false; + DeviceInfoPtr infoClick = findDeviceById(m_listDriveId[nowAt]); + if (infoClick) { + QPushButton* btn = m_mapOptBtns[infoClick->id]; + if (btn) { + onOptionSelected(nowAt, true); + } + } + break; + + } +} + int LoginOptionsWidget::convertDeviceType(int nDevType) { int nLoginOptType = LOGINOPT_TYPE_OTHERS; @@ -594,7 +773,7 @@ void LoginOptionsWidget::setDeviceDisable(int nDevId, bool bDisable) { if (bDisable) { m_mapDisableDev[m_uid][nDevId] = true; - QMap::iterator itMapBtn = m_mapOptBtns.begin(); + QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { if (itMapBtn.key() == nDevId && itMapBtn.value()) { itMapBtn.value()->setDisabled(true); @@ -603,7 +782,7 @@ void LoginOptionsWidget::setDeviceDisable(int nDevId, bool bDisable) } } else { m_mapDisableDev[m_uid][nDevId] = false; - QMap::iterator itMapBtn = m_mapOptBtns.begin(); + QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { if (itMapBtn.key() == nDevId && itMapBtn.value()) { itMapBtn.value()->setDisabled(false); @@ -678,3 +857,82 @@ QPixmap LoginOptionsWidget::drawSymbolicColoredPixmap(QPixmap &source, QString c } return QPixmap::fromImage(img); } + +bool LoginOptionsWidget::getBioAuthEnable(int nType) +{ + bool isEnable = false; + if (m_uniauthService && m_uniauthService->isActivatable()) { + struct passwd *pwInfo = getpwuid(m_uid); + if (pwInfo) { + isEnable = m_uniauthService->getBioAuthStatus(pwInfo->pw_name, ENABLETYPE_BIO); + if (isEnable) { + isEnable = m_uniauthService->getBioAuthStatus(pwInfo->pw_name, nType); + } + return isEnable; + } else { + return false; + } + } else { + return GetAuthEnable(); + } +} + +bool LoginOptionsWidget::getQRCodeEnable() +{ + if (m_uniauthService && m_uniauthService->isActivatable()) { + return m_uniauthService->getQRCodeEnable(); + } else { + return GetQRCodeEnable(); + } +} + +QString LoginOptionsWidget::getDefaultDevice(QString strUserName) +{ + if (m_uniauthService && m_uniauthService->isActivatable()) { + QString defaultDeviceName = ""; + for (auto bioType : m_listPriority) { + QString strDeviceName = m_uniauthService->getDefaultDevice(strUserName, bioType); + if(!strDeviceName.isEmpty()) { + DeviceInfoPtr pDeviceInfo = findDeviceByName(strDeviceName); + if (pDeviceInfo) { + defaultDeviceName = strDeviceName; + break; + } + } + } + return defaultDeviceName; + } else { + return GetDefaultDevice(strUserName); + } +} + +QStringList LoginOptionsWidget::getAllDefDevices() +{ + QStringList listDefDevices; + if (m_uniauthService && m_uniauthService->isActivatable()) { + struct passwd *pwdInfo = getpwuid(m_uid); + if (pwdInfo) { + listDefDevices = m_uniauthService->getAllDefaultDevice(pwdInfo->pw_name); + } + } else { + QString defaultDeviceName; + + struct passwd *pwd = getpwuid(m_uid); + QString userConfigFile = QString(pwd->pw_dir) + "/.biometric_auth/ukui_biometric.conf"; + QSettings userConfig(userConfigFile, QSettings::IniFormat); + qDebug() << userConfig.fileName(); + defaultDeviceName = userConfig.value("DefaultDevice").toString(); + qDebug() << defaultDeviceName; + + if(defaultDeviceName.isEmpty()) { + QSettings sysConfig("/etc/biometric-auth/ukui-biometric.conf", QSettings::IniFormat); + defaultDeviceName = sysConfig.value("DefaultDevice").toString(); + } + qDebug() << "default device: " << defaultDeviceName; + if(!defaultDeviceName.isEmpty()){ + listDefDevices.push_back(defaultDeviceName); + } + } + return listDefDevices; +} + diff --git a/src/loginoptionswidget.h b/src/loginoptionswidget.h index c53a0bc..c8630da 100644 --- a/src/loginoptionswidget.h +++ b/src/loginoptionswidget.h @@ -4,12 +4,13 @@ #include #include "biometricproxy.h" #include "biometricdeviceinfo.h" +#include "uniauthservice.h" class QLabel; class QButtonGroup; class QHBoxLayout; class QVBoxLayout; -class QToolButton; +class QPushButton; class QTimer; class QPixmap; @@ -26,16 +27,25 @@ typedef enum { UniT_Remote, /** 远程账户 **/ }BioType; +enum OPTION{ + RIGHT = 0, + LEFT, + CLEAR, + CLICK, + FirstDevice, +}; + class LoginOptionsWidget : public QWidget { Q_OBJECT public: - explicit LoginOptionsWidget(BiometricProxy* proxy, int uid, QWidget *parent = nullptr); + explicit LoginOptionsWidget(BiometricProxy* proxy, int uid, UniAuthService* uniauthService, QWidget *parent = nullptr); virtual ~LoginOptionsWidget(); bool getCurLoginOpt(int& nLoginOptType, int& nDrvId); unsigned getLoginOptCount(); DeviceInfoPtr getFirstDevInfo(); + DeviceInfoPtr getWechatDevice(); int convertDeviceType(int nDevType); void setUser(int uid); @@ -46,6 +56,10 @@ public: DeviceInfoPtr findDeviceByName(const QString &name); void setDeviceDisable(int nDevId, bool bDisable = true); bool isDeviceDisable(int nDevId); + bool getBioAuthEnable(int nType); + bool getQRCodeEnable(); + QString getDefaultDevice(QString strUserName); + QStringList getAllDefDevices(); /** * @brief 进行生物识别认证 @@ -67,21 +81,24 @@ public: return m_isInAuth; } + QPixmap loadSvg(QString path, QString color, int size); public Q_SLOTS: void readDevicesInfo(); void onIdentifyComplete(QDBusPendingCallWatcher *watcher); void onStatusChanged(int drvid, int status); void onFrameWritten(int drvid); void onUSBDeviceHotPlug(int drvid, int action, int devNum); - void onOptionSelected(int nIndex); + void onOptionSelected(int nIndex, bool keyNavigation = false); + void tabOptionSelected(int option); Q_SIGNALS: - void notifyOptionsChange(unsigned uOptionsCount); - void optionSelected(unsigned uLoginOptType, const DeviceInfoPtr &deviceInfo); + void notifyOptionsChange(unsigned uOptionsCount, bool is_bioBtn); + void optionSelected(unsigned uLoginOptType, const DeviceInfoPtr &deviceInfo, bool keyNavigation); void updateImage(QImage img); void authComplete(bool bResult, int nStatus); void updateAuthMsg(QString strMsg); - + void setLoadingImage(); + void deviceCountChanged(int num); private: void initUI(); void initConnections(); @@ -91,7 +108,6 @@ private: void startAuth_(); bool getAuthDouble(); void updateUIStatus(); - QPixmap loadSvg(QString path, QString color, int size); QPixmap drawSymbolicColoredPixmap(QPixmap &source, QString cgColor); private: @@ -113,8 +129,12 @@ private: QLabel *m_labelOptTitle = nullptr; QButtonGroup *m_btnGroup = nullptr; QList m_listDriveId; - QMap m_mapOptBtns; + QMap m_mapOptBtns; QMap> m_mapDisableDev; + int nowAt = -1; + bool at_bioBtn = false; + UniAuthService *m_uniauthService = nullptr; + QList m_listPriority; }; #endif // LOGINOPTIONSWIDGET_H diff --git a/src/mytabwidget.cpp b/src/mytabwidget.cpp new file mode 100644 index 0000000..7256584 --- /dev/null +++ b/src/mytabwidget.cpp @@ -0,0 +1,40 @@ +#include "mytabwidget.h" +#include +#include +#include + +MyTabWidget::MyTabWidget(QWidget *parent) : QTabWidget(parent) +{ + //隐藏标题栏 + // setWindowFlags(Qt::FramelessWindowHint);//无边框 置顶 + + //设置窗口背景透明 +// setAttribute(Qt::WA_TranslucentBackground,false); + + //设置样式 + +// QWidget *w = new QWidget(this); +// QWidget *k = new QWidget(this); +// this->addTab(w,"111"); +// this->addTab(k,"222"); + + +} + +void MyTabWidget::paintEvent(QPaintEvent *p1) +{ + //绘制样式 + QStyleOption opt; + opt.initFrom(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);//绘制样式 + + QBitmap bmp(this->size()); + bmp.fill(); + QPainter painter(&bmp); + painter.setPen(Qt::NoPen); + painter.setBrush(Qt::black); + painter.setRenderHint(QPainter::Antialiasing); + painter.drawRoundedRect(bmp.rect(), 12, 12); + setMask(bmp); +} diff --git a/src/mytabwidget.h b/src/mytabwidget.h new file mode 100644 index 0000000..65ff60a --- /dev/null +++ b/src/mytabwidget.h @@ -0,0 +1,18 @@ +#ifndef MYTABWIDGET_H +#define MYTABWIDGET_H + +#include +#include + +class MyTabWidget : public QTabWidget +{ + Q_OBJECT +public: + explicit MyTabWidget(QWidget *parent = nullptr); + void paintEvent(QPaintEvent *event); + +signals: + +}; + +#endif // WIDGET_H diff --git a/src/org.ukui.ScreenSaver.xml b/src/org.ukui.ScreenSaver.xml index 482c477..3e47687 100644 --- a/src/org.ukui.ScreenSaver.xml +++ b/src/org.ukui.ScreenSaver.xml @@ -9,6 +9,9 @@ + + + @@ -20,5 +23,8 @@ + + + diff --git a/src/pam-tally.c b/src/pam-tally.c index d32f578..ff0642c 100644 --- a/src/pam-tally.c +++ b/src/pam-tally.c @@ -357,14 +357,20 @@ pam_modutil_read(int fd, char *buffer, int count) void get_tally(uid_t uid, int *tfile, struct tallylog *tally) { - char filename[50]={0}; - sprintf(filename,"%s","/tmp/.tallylog"); + char filename[50]={0}; + sprintf(filename,"/tmp/.tallylog.d/.%d",uid); + fprintf(stderr,"new_filename = :%s \n",filename); + void *void_tally = tally; - void *void_tally = tally; - if ((*tfile = open(filename, O_RDONLY)) == -1){ - fprintf(stderr, "open tallylog failed \n"); - return ; - } + if ((*tfile = open(filename, O_RDONLY)) == -1){ + fprintf(stderr, "lseek tallylog failed,Re-open the new file, uid = %d \n",uid); + sprintf(filename,"/tmp/.tallylog"); + fprintf(stderr,"old_filename = :%s \n",filename); + if ((*tfile = open(filename, O_RDONLY)) == -1){ + fprintf(stderr, "open tallylog failed \n"); + return ; + } + } if (lseek(*tfile, (off_t)uid*(off_t)sizeof(*tally), SEEK_SET) == (off_t)-1) { fprintf(stderr, "lseek tallylog failed \n"); diff --git a/src/powermanager.cpp b/src/powermanager.cpp index 7bc190d..698cc00 100644 --- a/src/powermanager.cpp +++ b/src/powermanager.cpp @@ -27,11 +27,15 @@ #include #include #include "powermanager.h" +#include "lockchecker.h" const static QString login1Service = QStringLiteral("org.freedesktop.login1"); const static QString login1Path = QStringLiteral("/org/freedesktop/login1"); const static QString login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager"); +#define NORMAL "normal" +#define FOCUS "focus" + #ifdef USE_INTEL PowerManager::PowerManager(QWidget *parent) : QWidget(parent), @@ -42,11 +46,16 @@ PowerManager::PowerManager(QWidget *parent) setQSS(); } #else -PowerManager::PowerManager(QWidget *parent) +PowerManager::PowerManager(int num, QWidget *parent) : QListWidget(parent), lasttime(QTime::currentTime()) { // resize(ITEM_WIDTH*7, ITEM_HEIGHT); + QFile qssFile(":/qss/assets/authdialog.qss"); + if(qssFile.open(QIODevice::ReadOnly)) { + this->setStyleSheet(qssFile.readAll()); + } + setObjectName("PowerManager"); setFlow(QListWidget::LeftToRight); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -54,8 +63,6 @@ PowerManager::PowerManager(QWidget *parent) //QObject::connect(this,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(powerClicked(QListWidgetItem*))); -// QObject::connect(this, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this,\ -// SLOT(keyboardPressed(QListWidgetItem*,QListWidgetItem*))); sessionInterface = new QDBusInterface("org.gnome.SessionManager", "/org/gnome/SessionManager", @@ -69,13 +76,6 @@ PowerManager::PowerManager(QWidget *parent) QDBusConnection::systemBus(), this); - xEventMonitor = new XEventMonitor(this); - connect(xEventMonitor, SIGNAL(keyPress(const QString &)), this, - SLOT(onGlobalKeyPress(const QString &))); - connect(xEventMonitor, SIGNAL(keyRelease(const QString &)), this, - SLOT(onGlobalkeyRelease(const QString &))); - xEventMonitor->start(); - QDBusReply stateReply = loginInterface->call("CanSuspend"); if(stateReply.isValid() && stateReply.value() == "yes"){ canSuspend = true; @@ -93,45 +93,15 @@ PowerManager::PowerManager(QWidget *parent) initUI(); resize((ITEM_WIDTH+ITEM_SPACING*2)*this->count()-ITEM_SPACING*2, ITEM_HEIGHT+ITEM_SPACING*2); //setCurrentRow(0); + loginedNum = num; } - -void PowerManager::keyboardPressed(QListWidgetItem *item_c, QListWidgetItem *item_p) -{ -// if(item_p){ -// QString name = itemWidget(item_c)->objectName(); -// if(name == rebootWidget->objectName()){ -// rebootFace->setStyleSheet("background-color: rgba(255, 255, 255, 40%),\ -// QLabel:hover{background-color:rgb(255,255,255,40%)"); -// } else if(name == shutdownWidget->objectName()){ -// shutdownFace->setStyleSheet("background-color: rgba(255, 255, 255, 40%)"); -// } else if(suspendWidget && name == suspendWidget->objectName()){ -// suspendFace->setStyleSheet("background-color: rgba(255, 255, 255, 40%)"); -// } else if(hibernateWidget && name == hibernateWidget->objectName()){ -// hibernateFace->setStyleSheet("background-color: rgba(255, 255, 255, 40%)"); -// } -// QString name_p = itemWidget(item_p)->objectName(); -// if(name_p == rebootWidget->objectName()){ -// rebootFace->setStyleSheet("background-color: rgba(255, 255, 255, 20% QLabel:hover{background-color:rgb(255,255,255,40%))"); - -// } else if(name_p == shutdownWidget->objectName()){ -// shutdownFace->setStyleSheet("background-color: rgba(255, 255, 255, 20%\ -// QLabel:hover{background-color:rgb(255,255,255,40%))"); -// } else if(suspendWidget && name_p == suspendWidget->objectName()){ -// suspendFace->setStyleSheet("background-color: rgba(255, 255, 255, 20%\ -// QLabel:hover{background-color:rgb(255,255,255,40%))"); -// } else if(hibernateWidget && name_p == hibernateWidget->objectName()){ -// hibernateFace->setStyleSheet("background-color: rgba(255, 255, 255, 20%); QLabel:hover{background-color:rgb(255,255,255,40%))"); -// } -// } -} - - - bool PowerManager::eventFilter(QObject *obj, QEvent *event) { - if(event->type() != QEvent::MouseButtonPress){ - return false; + /*这里之前使用点击事件,再某些机器上会出现点击睡眠后,先睡眠,再自动唤醒的问题, + * 原因不明,改为鼠标释放事件时无此问题*/ + if(event->type() != QEvent::MouseButtonRelease){ + return QWidget::eventFilter(obj, event); } QString name = obj->objectName(); @@ -149,69 +119,67 @@ bool PowerManager::eventFilter(QObject *obj, QEvent *event) else if(name == "hibernateFace") hibernateWidgetClicked(); - return false; + return QWidget::eventFilter(obj, event); } -void PowerManager::onGlobalKeyPress(const QString &key) +void PowerManager::onGlobalKeyPress(const quint8 &key) { } -void PowerManager::onGlobalkeyRelease(const QString &key) +void PowerManager::onGlobalkeyRelease(const quint8 &key) { - if (key == "Escape") { +// if (key == 9) { // "Escape" - } else if (key == "Left" || key == "Right" || key == "Return" || key == "KP_Enter") { - keyBdRelease(key); - } +// } else if (key == 113 || key == 114 || key == 36 || key == 104) { // "Left" "Right" "Return" "KP_Enter" +// keyBdRelease(key); +// } } -void PowerManager::keyBdRelease(QString key) +void PowerManager::keyBdRelease(int key) { - QString focus = "focus"; - QString normal = "normal"; - if(key == "Right"){ + if(key == Qt::Key_Right){ // "Right" if(nowAt == -1){ nowAt = 0; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 0){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 1; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 1){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 2; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 2){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 3; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 3){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 0; - setButtonStyle(focus); + setButtonStyle(FOCUS); } - } else if(key == "Left") { + } else if(key == Qt::Key_Left) { // "Left" if(nowAt == -1){ nowAt = 3; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 3){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 2; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 2){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 1; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 1){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 0; - setButtonStyle(focus); + setButtonStyle(FOCUS); } else if(nowAt == 0){ - setButtonStyle(normal); + setButtonStyle(NORMAL); nowAt = 3; - setButtonStyle(focus); + setButtonStyle(FOCUS); } - } else if(key == "Return" || key == "KP_Enter"){ + } else if(key == Qt::Key_Return || key == Qt::Key_Enter || key == Qt::Key_Space){ // "Return" "KP_Enter" "Space" if(nowAt == 0 && this->isVisible()) hibernateWidgetClicked(); else if(nowAt == 1 && this->isVisible()) @@ -223,72 +191,22 @@ void PowerManager::keyBdRelease(QString key) } } +void PowerManager::clearStatus() +{ + for(nowAt = 0; nowAt < listLabel.count(); nowAt++) { + setButtonStyle(NORMAL); + } + nowAt = -1; +} void::PowerManager::setButtonStyle(QString Style) { if(Style == "normal") - listLabel.at(nowAt)->setStyleSheet("background-color: rgba(255, 255, 255, 15%);QLabel:hover{background-color:rgb(255,255,255,40%);QLabel:pressed{background-color:rgb(255,255,255,30%))"); + listLabel.at(nowAt)->setStyleSheet("background-color: rgba(255, 255, 255, 15%);QLabel:hover{background-color:rgba(255,255,255,40%)};QLabel:pressed:!hover{background-color:rgba(255,255,255,30%)}"); else if(Style == "focus") listLabel.at(nowAt)->setStyleSheet("background-color: rgba(255, 255, 255, 20%);border: 1px solid #296CD9; border-radius: 64px;"); } -QStringList PowerManager::getLoginedUsers() -{ - QStringList m_loginedUser; - QDBusMessage result = loginInterface->call("ListUsers"); - QList outArgs = result.arguments(); - QVariant first = outArgs.at(0); - QDBusArgument dbvFirst = first.value(); - QVariant vFirst = dbvFirst.asVariant(); - const QDBusArgument &dbusArgs = vFirst.value(); - - - QVector loginedUsers; - - dbusArgs.beginArray(); - while (!dbusArgs.atEnd()) { - usersInfo user; - dbusArgs >> user; - loginedUsers.push_back(user); - } - - for (usersInfo user: loginedUsers) { - - QDBusInterface userPertyInterface("org.freedesktop.login1", user.usersPath.path(), - "org.freedesktop.DBus.Properties", - QDBusConnection::systemBus()); - - QDBusReply reply = - userPertyInterface.call("Get", "org.freedesktop.login1.User", "State"); - if (reply.isValid()) { - QString status = reply.value().toString(); - if ("closing" != status) { - m_loginedUser.append(user.usersName); - } - } - } - return m_loginedUser; -} - -QDBusArgument &operator <<(QDBusArgument &arg, const usersInfo &userInfo) -{ - arg.beginStructure(); - arg << userInfo.usersId - << userInfo.usersName - << userInfo.usersPath; - arg.endStructure(); - return arg; -} -const QDBusArgument &operator >>(const QDBusArgument &arg, usersInfo &userInfo) -{ - arg.beginStructure(); - arg >> userInfo.usersId - >> userInfo.usersName - >> userInfo.usersPath; - arg.endStructure(); - return arg; -} - void PowerManager::powerClicked(QListWidgetItem *item) { int interval = lasttime.msecsTo(QTime::currentTime()); @@ -412,7 +330,7 @@ void PowerManager::initUI() QLabel *rebootLabel = new QLabel(this); rebootPB->setProperty("class", "PowerManagerPB"); rebootPB->setIcon(QIcon(QPixmap(":/image/assets/intel/reboot.png").scaled(40,40))); - rebootLabel->setText(tr("Restart")); + rebootLabel->setText(tr("Reboot")); rebootLabel->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); QVBoxLayout *rebootlayout = new QVBoxLayout(rebootWidget); @@ -562,44 +480,97 @@ void PowerManager::setQSS() void PowerManager::doEvent(int type) { switch (type) { - case REBOOT: - sessionInterface->call("reboot"); + case SLEEP: + loginInterface->call("Suspend",true); + emit lock(); + break; + case HIBERNATE: + loginInterface->call("Hibernate",true); + emit lock(); + break; + case REBOOT: + if (is_hibernate && loginedNum > 1) { + Q_EMIT mulUsersLogined(REBOOT); + is_hibernate = false; + } else + loginInterface->call("Reboot", true); + break; + case SHUTDOWN: + if (is_hibernate && loginedNum > 1) { + Q_EMIT mulUsersLogined(SHUTDOWN); + is_hibernate = false; + } else + loginInterface->call("PowerOff", true); break; - case SHOTDOWN: - sessionInterface->call("powerOff"); default: break; } } +void PowerManager::setStartupMode(bool mode) +{ + m_isStartupMode = mode; +} + void PowerManager::suspendWidgetClicked() { - loginInterface->call("Suspend",true); + QVector res = LockChecker::listInhibitor("sleep"); + if (!res.isEmpty()) { + Q_EMIT showInhibitWarning(res, SLEEP); + return; + } emit lock(); + Q_EMIT clickedSuspend(); + loginInterface->call("Suspend",true); } void PowerManager::hibernateWidgetClicked() { - loginInterface->call("Hibernate",true); + QVector res = LockChecker::listInhibitor("sleep"); + if (!res.isEmpty()) { + Q_EMIT showInhibitWarning(res, HIBERNATE); + return; + } emit lock(); + loginInterface->call("Hibernate",true); } void PowerManager::shutdownWidgetClicked() { - if(getLoginedUsers().count() > 1){ - Q_EMIT mulUsersLogined(SHOTDOWN); + QVector res = LockChecker::listInhibitor("shutdown"); + if (!res.isEmpty()) { + Q_EMIT showInhibitWarning(res, SHUTDOWN); + is_hibernate = true; + return; + } else if(loginedNum > 1){ + Q_EMIT mulUsersLogined(SHUTDOWN); + is_hibernate = false; return; } - sessionInterface->call("powerOff"); + if (m_isStartupMode) { + loginInterface->call("PowerOff", true); + } else { + sessionInterface->call("powerOff"); + } } void PowerManager::rebootWidgetClicked() { - if(getLoginedUsers().count() > 1){ + QVector res = LockChecker::listInhibitor("shutdown"); + if (!res.isEmpty()) { + Q_EMIT showInhibitWarning(res, REBOOT); + is_hibernate = true; + return; + } else if(loginedNum > 1){ Q_EMIT mulUsersLogined(REBOOT); + is_hibernate = false; return; } - sessionInterface->call("reboot"); + if (m_isStartupMode) { + loginInterface->call("Reboot", true); + } else { + sessionInterface->call("reboot"); + } } void PowerManager::logoutWidgetCliced() @@ -696,7 +667,7 @@ void PowerManager::initUI() rebootFace->installEventFilter(this); rebootLabel->setAlignment(Qt::AlignCenter); rebootFace->setPixmap(QPixmap(":/image/assets/reboot.png").scaled(58,58)); - rebootLabel->setText(tr("Restart")); + rebootLabel->setText(tr("Reboot")); rebootWidget->setFixedSize(ITEM_WIDTH,ITEM_HEIGHT); QVBoxLayout *rebootlayout = new QVBoxLayout(rebootWidget); rebootlayout->addWidget(rbLabelWidget); diff --git a/src/powermanager.h b/src/powermanager.h index 3a4a1ee..854c881 100644 --- a/src/powermanager.h +++ b/src/powermanager.h @@ -23,7 +23,7 @@ #include #include #include "config.h" -#include "xeventmonitor.h" +#include "lockchecker.h" #ifdef USE_INTEL #define ITEM_WIDTH 128 #define ITEM_HEIGHT (ITEM_WIDTH + 40) @@ -38,19 +38,12 @@ class PowerManager:public QWidget enum stateType { REBOOT, - SHOTDOWN, - NOTHING + SHUTDOWN, + SLEEP, + HIBERNATE, + NOTHING, }; -struct usersInfo { - int usersId; - QString usersName; - QDBusObjectPath usersPath; -}; - -QDBusArgument &operator <<(QDBusArgument &arg, const usersInfo &userInfo); -const QDBusArgument &operator >>(const QDBusArgument &arg, usersInfo &userInfo); - class QLabel; class QListWidget; class QListWidgetItem; @@ -61,13 +54,20 @@ class PowerManager:public QListWidget Q_OBJECT public: - PowerManager(QWidget *parent = 0); + PowerManager(int num = 0, QWidget *parent = 0); #ifdef USE_INTEL bool hibernate(); #else void showNormalSize(); void showSmallSize(); + void keyBdRelease(int key); + void clearStatus(); void doEvent(int type); + void setStartupMode(bool mode); + +public Q_SLOTS: + void onGlobalKeyPress(const quint8 &key); + void onGlobalkeyRelease(const quint8 &key); #endif private: void initUI(); @@ -85,6 +85,7 @@ private: QDBusInterface *loginInterface; QDBusInterface *actService; int login_Num; + bool is_hibernate = false; bool canSuspend; bool canHibernate; @@ -96,11 +97,12 @@ private: QWidget *rebootWidget; QWidget *shutdownWidget; QTime lasttime; - XEventMonitor *xEventMonitor; QLabel *rebootFace; QLabel *shutdownFace; QLabel *hibernateFace; QLabel *suspendFace; + int loginedNum = 0; + bool m_isStartupMode = false; private: void lockWidgetClicked(); @@ -109,7 +111,7 @@ private: void rebootWidgetClicked(); QStringList getLoginedUsers(); void shutdownWidgetClicked(); - void keyBdRelease(QString key); + //void keyBdRelease(quint8 key); void setButtonStyle(QString Style); #ifdef USE_INTEL bool reboot(); @@ -122,14 +124,14 @@ private Q_SLOTS: #ifndef USE_INTEL void powerClicked(QListWidgetItem *item); bool eventFilter(QObject *obj, QEvent *event); - void onGlobalKeyPress(const QString &key); - void onGlobalkeyRelease(const QString &key); - void keyboardPressed(QListWidgetItem *item,QListWidgetItem*); + #endif Q_SIGNALS: void switchToUser(); void lock(); void mulUsersLogined(int type); + void showInhibitWarning(QVector &list, int type); + void clickedSuspend(); }; #endif // POWERMANAGER_H diff --git a/src/screensaver.cpp b/src/screensavermode.cpp similarity index 99% rename from src/screensaver.cpp rename to src/screensavermode.cpp index 744d33b..37eab3c 100644 --- a/src/screensaver.cpp +++ b/src/screensavermode.cpp @@ -15,7 +15,7 @@ * along with this program; if not, see . * **/ -#include "screensaver.h" +#include "screensavermode.h" #include #include #include diff --git a/src/screensaver.h b/src/screensavermode.h similarity index 94% rename from src/screensaver.h rename to src/screensavermode.h index d3f2ad3..51c738e 100644 --- a/src/screensaver.h +++ b/src/screensavermode.h @@ -15,8 +15,8 @@ * along with this program; if not, see . * **/ -#ifndef SCREENSAVER_H -#define SCREENSAVER_H +#ifndef SCREENSAVER_MODE_H +#define SCREENSAVER_MODE_H #include #include @@ -44,7 +44,7 @@ class ScreenSaver : public QObject public: SaverMode mode; //path is a directory or a file path if mode is SAVER_IMAGE - QString path; + QString path = ""; QString lastPath; //for images saver @@ -74,4 +74,4 @@ Q_DECLARE_METATYPE(ScreenSaver) QDebug &operator<<(QDebug stream, const ScreenSaver &screensaver); -#endif // SCREENSAVER_H +#endif // SCREENSAVER_MODE_H diff --git a/src/screensaverwidget.cpp b/src/screensaverwidget.cpp index e194c54..48d2a43 100644 --- a/src/screensaverwidget.cpp +++ b/src/screensaverwidget.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "screensaver.h" #include #include ScreenSaverWidget::ScreenSaverWidget(ScreenSaver *screensaver, QWidget *parent) @@ -33,6 +34,7 @@ ScreenSaverWidget::ScreenSaverWidget(ScreenSaver *screensaver, QWidget *parent) closing(false) { qDebug() << "ScreenSaverWidget::ScreenSaverWidget"; + setAttribute(Qt::WA_DeleteOnClose); setMouseTracking(true); setFocus(); this->installEventFilter(this); @@ -83,8 +85,10 @@ ScreenSaverWidget::~ScreenSaverWidget() void ScreenSaverWidget::closeEvent(QCloseEvent *event) { qDebug() << "ScreenSaverWidget::closeEvent---beginStop"; - if(process.state() != QProcess::NotRunning) + if(process.state() != QProcess::NotRunning) { process.kill(); + process.waitForFinished(200); + } if(!closing){ closing = true; @@ -147,12 +151,30 @@ bool ScreenSaverWidget::eventFilter(QObject *obj, QEvent *event) /* Embed xscreensavers */ void ScreenSaverWidget::embedXScreensaver(const QString &path) { - QString cmd = path + " -window-id " + QString::number(winId()); - if(process.state() == QProcess::NotRunning) - process.start(cmd); + qDebug()<<"embedXScreensaver path = "<mode == SAVER_SINGLE){ + QString cmd = path + " -window-id " + QString::number(winId()); + if(process.state() == QProcess::NotRunning) + process.start(cmd); + }else if(screensaver->mode == SAVER_DEFAULT || screensaver->mode == SAVER_DEFAULT_CUSTOM){ + if(!m_screensaver){ + m_screensaver = new Screensaver(true,this); + //m_screensaver->resize(1366,768); + //m_screensaver->setGeometry(this->geometry()); + // m_screensaver->setGeometry(0,0,1920,1080); + + } + } } - +void ScreenSaverWidget::resizeEvent(QResizeEvent *event) +{ + if(m_screensaver){ + m_screensaver->setGeometry(this->geometry()); + } +} void ScreenSaverWidget::onBackgroundChanged(const QString &/*path*/) { diff --git a/src/screensaverwidget.h b/src/screensaverwidget.h index a76d428..7099cba 100644 --- a/src/screensaverwidget.h +++ b/src/screensaverwidget.h @@ -20,8 +20,9 @@ #include #include -#include "screensaver.h" +#include "screensavermode.h" +class Screensaver; class ScreenSaverWidget : public QWidget { Q_OBJECT @@ -34,6 +35,7 @@ protected: void closeEvent(QCloseEvent *); void paintEvent(QPaintEvent *event); bool eventFilter(QObject *obj, QEvent *event); + void resizeEvent(QResizeEvent *event); private: void embedXScreensaver(const QString &path); @@ -46,6 +48,7 @@ private: bool closing; float opacity; QProcess process; + Screensaver *m_screensaver = nullptr; }; #endif // SCREENSAVERWIDGET_H diff --git a/src/screensaverwndadaptor.cpp b/src/screensaverwndadaptor.cpp new file mode 100644 index 0000000..34761ed --- /dev/null +++ b/src/screensaverwndadaptor.cpp @@ -0,0 +1,52 @@ +#include "screensaverwndadaptor.h" + +#include +#include +#include +#include +#include +#include +#include + +ScreenSaverWndAdaptor::ScreenSaverWndAdaptor(FullBackgroundWidget *parent) + : QDBusAbstractAdaptor(parent) + , m_parentWidget(parent) +{ + // constructor + setAutoRelaySignals(true); + + connect(m_parentWidget, SIGNAL(StartupModeChanged(bool)), this, SIGNAL(StartupModeChanged(bool))); +} + +ScreenSaverWndAdaptor::~ScreenSaverWndAdaptor() +{ + +} + +int ScreenSaverWndAdaptor::RegisteSubWnd(quint64 uWndId) +{ + int nWndCount = m_parentWidget->RegisteSubWnd(uWndId); + if (nWndCount >= 0) { + Q_EMIT SubWndChanged(nWndCount); + } + return nWndCount; +} + +int ScreenSaverWndAdaptor::UnRegisteSubWnd(quint64 uWndId) +{ + int nWndCount = m_parentWidget->UnRegisteSubWnd(uWndId); + if (nWndCount >= 0) { + Q_EMIT SubWndChanged(nWndCount); + } + return nWndCount; +} + +QList ScreenSaverWndAdaptor::GetSubWndIds() +{ + return m_parentWidget->GetSubWndIds(); +} + +bool ScreenSaverWndAdaptor::IsStartupMode() +{ + return m_parentWidget->IsStartupMode(); +} diff --git a/src/screensaverwndadaptor.h b/src/screensaverwndadaptor.h new file mode 100644 index 0000000..0641c0c --- /dev/null +++ b/src/screensaverwndadaptor.h @@ -0,0 +1,58 @@ +#ifndef SCREENSAVERWNDADAPTOR_H +#define SCREENSAVERWNDADAPTOR_H + +#include +#include +#include "fullbackgroundwidget.h" +QT_BEGIN_NAMESPACE +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +class ScreenSaverWndAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.ukui.ScreenSaverWnd") + Q_CLASSINFO("D-Bus Introspection", "" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "") +public: + ScreenSaverWndAdaptor(FullBackgroundWidget *parent = nullptr); + virtual ~ScreenSaverWndAdaptor(); + +public Q_SLOTS: + int RegisteSubWnd(quint64 uWndId); + int UnRegisteSubWnd(quint64 uWndId); + QList GetSubWndIds(); + bool IsStartupMode(); + +Q_SIGNALS: + void SubWndChanged(int nCount); + void StartupModeChanged(bool isStartup); + +private: + FullBackgroundWidget *m_parentWidget = nullptr; +}; + +#endif // SCREENSAVERWNDADAPTOR_H diff --git a/src/servicemanager.cpp b/src/servicemanager.cpp new file mode 100644 index 0000000..427678e --- /dev/null +++ b/src/servicemanager.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#include "servicemanager.h" +#include +#include + +#define SERVICE "biometric-authentication.service" +#define DBUS_SERVICE "org.ukui.Biometric" +#define DBUS_PATH "/org/ukui/Biometric" +#define DBUS_INTERFACE "org.ukui.Biometric" + +#define FD_DBUS_SERVICE "org.freedesktop.DBus" +#define FD_DBUS_PATH "/org/freedesktop/DBus" +#define FD_DBUS_INTERFACE "org.freedesktop.DBus" + +ServiceManager *ServiceManager::instance_ = nullptr; + +ServiceManager::ServiceManager(QObject *parent) + : QObject(parent), + dbusService(nullptr), + bioService(nullptr) +{ + init(); +} + +void ServiceManager::init() +{ + if(!dbusService) + { + dbusService = new QDBusInterface(FD_DBUS_SERVICE, + FD_DBUS_PATH, + FD_DBUS_INTERFACE, + QDBusConnection::systemBus()); + connect(dbusService, SIGNAL(NameOwnerChanged(QString, QString, QString)), + this, SLOT(onDBusNameOwnerChanged(QString,QString,QString))); + } +} + +ServiceManager *ServiceManager::instance() +{ + if(!instance_) + { + instance_ = new ServiceManager; + } + return instance_; +} + +bool ServiceManager::connectToService() +{ + if(!bioService) + { + bioService = new QDBusInterface(DBUS_SERVICE, + DBUS_PATH, + DBUS_INTERFACE, + QDBusConnection::systemBus()); + } + return bioService->isValid(); +} + +void ServiceManager::onDBusNameOwnerChanged(const QString &name, + const QString &oldOwner, + const QString &newOwner) +{ + if(name == DBUS_SERVICE) + { + qDebug() << "service status changed:" + << (newOwner.isEmpty() ? "inactivate" : "activate"); + Q_EMIT serviceStatusChanged(!newOwner.isEmpty()); + } +} + +/*! + * \brief checkServiceExist + * 检查生物识别后台服务是否已启动 + */ +bool ServiceManager::serviceExists() +{ + QDBusReply reply = dbusService->call("NameHasOwner", DBUS_SERVICE); + if(!reply.isValid()) + { + qDebug() << "check service exists error:" << reply.error(); + return false; + } + return reply.value(); +} + +/*! + * \brief ServiceManager::apiCompatible + * 检查API版本和服务的版本是否兼容 + */ +bool ServiceManager::apiCompatible() +{ + if(!connectToService()) + return false; + + QDBusReply reply = bioService->call("CheckAppApiVersion", + APP_API_MAJOR, + APP_API_MINOR, + APP_API_FUNC); + if(!reply.isValid()) + { + qDebug() << "check api compatibility error: " << reply.error(); + return false; + } + return (reply.value() == 0); +} diff --git a/src/servicemanager.h b/src/servicemanager.h new file mode 100644 index 0000000..548cf1d --- /dev/null +++ b/src/servicemanager.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +**/ + +#ifndef SERVICEMANAGER_H +#define SERVICEMANAGER_H + +#include +#include + +class ServiceManager : public QObject +{ + Q_OBJECT +public: + static ServiceManager *instance(); + bool serviceExists(); + bool apiCompatible(); + +private: + explicit ServiceManager(QObject *parent = nullptr); + void init(); + bool connectToService(); + +Q_SIGNALS: + void serviceStatusChanged(bool activate); + +public Q_SLOTS: + void onDBusNameOwnerChanged(const QString &name, + const QString &oldOwner, + const QString &newOwner); + +private: + static ServiceManager *instance_; + QDBusInterface *dbusService; + QDBusInterface *bioService; + bool serviceStatus; +}; + +#endif // SERVICEMANAGER_H diff --git a/src/sessionwatcher.cpp b/src/sessionwatcher.cpp index c97d7b8..1f4d7a5 100644 --- a/src/sessionwatcher.cpp +++ b/src/sessionwatcher.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "types.h" #define GSETTINGS_SCHEMA_SCREENSAVER "org.ukui.screensaver" @@ -28,6 +29,17 @@ #define KEY_IDLE_LOCK_ENABLED "idleLockEnabled" #define TIME_TYPE_SCHEMA "org.ukui.control-center.panel.plugins" +#define GSETTINGS_SCHEMA_SCREENSAVER_DEFAULT "org.ukui.screensaver-default" +#define KEY_SHOW_REST_TIME "showRestTime" // old +#define KEY_SHOW_CUSTOM_REST_TIME "showCustomRestTime" +#define KEY_SHOW_UKUI_REST_TIME "showUkuiRestTime" + +#define POWER_TYPE_SCHENA "org.ukui.power-manager" +#define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" +#define UPOWER_PATH "/org/freedesktop/UPower" +#define UPOWER_SERVICE "org.freedesktop.UPower" +#define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" + SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) { sessionPath = qgetenv("XDG_SESSION_PATH"); @@ -36,7 +48,7 @@ SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) SM_DBUS_SERVICE, SM_DBUS_PATH, SM_DBUS_INTERFACE, - QDBusConnection::sessionBus()); + QDBusConnection::sessionBus(), this); connect(interface, SIGNAL(StatusChanged(unsigned int)), this, SLOT(onStatusChanged(unsigned int))); @@ -45,19 +57,81 @@ SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) DM_DBUS_SERVICE, DM_DBUS_PATH, DM_DBUS_INTERFACE, - QDBusConnection::systemBus()); + QDBusConnection::systemBus(), this); connect(displayManagerInterface, SIGNAL(SessionRemoved(QDBusObjectPath)), this, SLOT(onSessionRemoved(QDBusObjectPath))); - settings_delay = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); - connect(settings_delay, &QGSettings::changed, - this, &SessionWatcher::onConfigurationDelayChanged); - idleDelay = settings_delay->get("idle-delay").toInt(); + QStringList keysScreenSaver; + if(QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_SCREENSAVER)){ + m_ssSettings = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); + connect(m_ssSettings, &QGSettings::changed, + this, &SessionWatcher::onSSConfigChanged); + keysScreenSaver = m_ssSettings->keys(); + // 重置屏保从不字段 + if (keysScreenSaver.contains(KEY_IDLE_ACTIVATION_ENABLED)) { + bool isEnable = m_ssSettings->get("idle-activation-enabled").toBool(); + if (!isEnable) { + m_ssSettings->set("idle-activation-enabled", true); + if (keysScreenSaver.contains(KEY_IDLE_DELAY)) { + m_ssSettings->set("idle-delay", -1); + } + } + } + // 重置锁屏时间(不处理超时锁屏220620) + if (keysScreenSaver.contains(KEY_IDLE_LOCK)) { + m_ssSettings->set("idle-lock", -1); + } + idleDelay = m_ssSettings->get("idle-delay").toInt(); + idleLock = m_ssSettings->get("idle-lock").toInt(); + } - settings_lock = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); - connect(settings_lock, &QGSettings::changed, - this, &SessionWatcher::onConfigurationLockChanged); - idleLock = settings_lock->get("idle-lock").toInt(); + if(QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_SCREENSAVER_DEFAULT)){ + m_sdSettings = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER_DEFAULT, "", this); + // 重置屏保休息时间字段 + QStringList keysScreenSaverDefault = m_sdSettings->keys(); + if (keysScreenSaverDefault.contains(KEY_SHOW_REST_TIME)) { + bool isShow = m_sdSettings->get("show-rest-time").toBool(); + if (!isShow) { + m_sdSettings->set("show-rest-time", true); + if (keysScreenSaverDefault.contains(KEY_SHOW_CUSTOM_REST_TIME)) { + m_sdSettings->set("show-custom-rest-time", isShow); + } + if (keysScreenSaverDefault.contains(KEY_SHOW_UKUI_REST_TIME)) { + m_sdSettings->set("show-ukui-rest-time", isShow); + } + } + } + } + + // for PowerManager + // 同步旧的电源管理唤醒是否需密码配置 + FILE *fp = NULL; + fp = popen("xset s 0 0", "r"); + fclose(fp); + + if(QGSettings::isSchemaInstalled(POWER_TYPE_SCHENA)){ + m_pmSettings = new QGSettings(POWER_TYPE_SCHENA,"", this); + QStringList keys = m_pmSettings->keys(); + if (keys.contains("lockSuspend")) { + bool ret = m_pmSettings->get("lockSuspend").toBool(); + if(ret){ + m_pmSettings->set("lock-suspend",false); + } + } + if (keys.contains("lockHibernate")) { + bool ret = m_pmSettings->get("lockHibernate").toBool(); + if(ret){ + m_pmSettings->set("lock-hibernate",false); + } + } + if (keys.contains("lockBlankScreen") && keysScreenSaver.contains("closeActivationEnabled")) { + bool oldValue = m_pmSettings->get("lockBlankScreen").toBool(); + if(!oldValue && m_ssSettings){ + m_ssSettings->set("close-activation-enabled", oldValue); + m_pmSettings->set("lock-blank-screen", true); + } + } + } QString userName = getenv("USER"); QString configPath; @@ -77,29 +151,17 @@ SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) connect(timegsettings, &QGSettings::changed, this, &SessionWatcher::onConfigurationTimeTpChanged); -// activationEnabled_Key = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); -// connect(activationEnabled_Key, &QGSettings::changed, -// this, &SessionWatcher::activationEnabledChanged); -// idleActivationEnabled = activationEnabled_Key->get("idle-activation-enabled").toBool(); - -// lockEnabled_Key = new QGSettings(GSETTINGS_SCHEMA_SCREENSAVER, "", this); -// connect(lockEnabled_Key, &QGSettings::changed, -// this, &SessionWatcher::lockEnabledChanged); -// lockEnabled = lockEnabled_Key->get("idle-lock-enabled").toBool(); -// qDebug()<get("idle-delay").toInt(); - } + // 监听合盖信号 + QDBusConnection::systemBus().connect( + UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(onLidWatcherMessage(void))); } -void SessionWatcher::onConfigurationLockChanged(QString key) +void SessionWatcher::onSSConfigChanged(QString strKey) { - if(key == KEY_IDLE_LOCK){ - idleLock = settings_lock->get("idle-lock").toInt(); + if(strKey == KEY_IDLE_DELAY){ + idleDelay = m_ssSettings->get("idle-delay").toInt(); + } else if (strKey == KEY_IDLE_LOCK){ + idleLock = m_ssSettings->get("idle-lock").toInt(); } } @@ -119,25 +181,13 @@ void SessionWatcher::onConfigurationTimeTpChanged(QString key) void SessionWatcher::setValue(const QString &key, const QVariant &value) { + if (!configSettings) + return; configSettings->beginGroup("Greeter"); configSettings->setValue(key, value); configSettings->endGroup(); } -//void SessionWatcher::activationEnabledChanged(QString key) -//{ -// if(key == KEY_IDLE_ACTIVATION_ENABLED){ -// idleActivationEnabled = activationEnabled_Key->get("idle-activation-enabled").toBool(); -// } -//} - -//void SessionWatcher::lockEnabledChanged(QString key) -//{ -// if(key == KEY_IDLE_LOCK_ENABLED){ -// lockEnabled = lockEnabled_Key->get("idle-lock-enabled").toBool(); -// } -//} - void SessionWatcher::onStatusChanged(unsigned int status) { if(status == SESSION_IDLE) { @@ -179,6 +229,7 @@ void SessionWatcher::onStatusChanged(unsigned int status) if(m_timer2 && m_timer2->isActive()){ m_timer2->stop(); } + Q_EMIT sessionIdleExit(); } } @@ -188,3 +239,94 @@ void SessionWatcher::onSessionRemoved(const QDBusObjectPath &objectPath) if(objectPath.path() == sessionPath) exit(0); } + +bool SessionWatcher::isSleepActivationEnable() +{ + if (!m_ssSettings) + return false; + QStringList settingsKeys = m_ssSettings->keys(); + if (settingsKeys.contains("sleepActivationEnabled")) { + return m_ssSettings->get("sleep-activation-enabled").toBool(); + } else { + return false; + } +} + +bool SessionWatcher::isCloseActivationEnable() +{ + if (!m_ssSettings) + return false; + QStringList settingsKeys = m_ssSettings->keys(); + if (settingsKeys.contains("closeActivationEnabled")) { + return m_ssSettings->get("close-activation-enabled").toBool(); + } else { + return false; + } +} + +bool SessionWatcher::isLockEnable() +{ + if (!m_ssSettings) + return false; + QStringList settingsKeys = m_ssSettings->keys(); + if (settingsKeys.contains("lockEnabled")) { + return m_ssSettings->get("lock-enabled").toBool(); + } else { + return false; + } +} + +int SessionWatcher::sleepActivationDelay() +{ + if (!m_pmSettings) + return -1; + QStringList settingsKeys = m_pmSettings->keys(); + if (settingsKeys.contains("sleepComputerAc")) { + return m_pmSettings->get("sleep-computer-ac").toInt(); + } else { + return -1; + } +} + +int SessionWatcher::closeActivationDelay() +{ + if (!m_pmSettings) + return -1; + QStringList settingsKeys = m_pmSettings->keys(); + if (settingsKeys.contains("sleepDisplayAc")) { + return m_pmSettings->get("sleep-display-ac").toInt(); + } else { + return -1; + } +} + +int SessionWatcher::idledelay() +{ + return idleDelay; +} + +bool SessionWatcher::isLidCloseWithBlank() +{ + if (!m_pmSettings) + return false; + QStringList settingsKeys = m_pmSettings->keys(); + if (settingsKeys.contains("buttonLidAc")) { + QString strAction = m_pmSettings->get("button-lid-ac").toString(); + return (strAction == "blank"); + } else { + return false; + } +} + +void SessionWatcher::onLidWatcherMessage(void) +{ + QDBusInterface iface(UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); + QDBusReply reply = iface.call("Get", "org.freedesktop.UPower", "LidIsClosed"); + if (reply.isValid()) { + m_lidState = reply.value().toBool(); + Q_EMIT lidStateChanged(m_lidState); + qDebug() << "lid state:" << m_lidState; + } else { + qDebug() << "Failed to get lid closed event!"; + } +} diff --git a/src/sessionwatcher.h b/src/sessionwatcher.h index 9b202d1..0d5419d 100644 --- a/src/sessionwatcher.h +++ b/src/sessionwatcher.h @@ -31,32 +31,39 @@ class SessionWatcher : public QObject public: explicit SessionWatcher(QObject *parent = nullptr); void setValue(const QString &key, const QVariant &value); + bool isSleepActivationEnable(); + bool isCloseActivationEnable(); + bool isLockEnable(); + int sleepActivationDelay(); + int closeActivationDelay(); + int idledelay(); + bool isLidCloseWithBlank(); // 合盖关屏 + Q_SIGNALS: void sessionIdle(); void sessionLockIdle(); + void sessionIdleExit(); + void lidStateChanged(bool isClosed); private Q_SLOTS: void onStatusChanged(unsigned int status); void onSessionRemoved(const QDBusObjectPath &objectPath); - void onConfigurationDelayChanged(QString key); - void onConfigurationLockChanged(QString key); void onConfigurationTimeTpChanged(QString key); -// void activationEnabledChanged(QString key); -// void lockEnabledChanged(QString key); + void onSSConfigChanged(QString strKey); + void onLidWatcherMessage(void); + private: QString sessionPath; - QGSettings *settings_delay; - QGSettings *settings_lock; - QGSettings *activationEnabled_Key; - QGSettings *lockEnabled_Key; - QGSettings *timegsettings; - QSettings *configSettings; - bool idleActivationEnabled; - bool lockEnabled; - int idleDelay; - int idleLock; + QGSettings *timegsettings = nullptr; + QSettings *configSettings = nullptr; + QGSettings *m_ssSettings = nullptr; + QGSettings *m_pmSettings = nullptr; + QGSettings *m_sdSettings = nullptr; + int idleDelay = -1; + int idleLock = -1; QTimer *m_timer = nullptr; QTimer *m_timer2 = nullptr; + bool m_lidState = false; }; #endif // SESSIONWATCHER_H diff --git a/src/surewindow.cpp b/src/surewindow.cpp index 7633f15..8ee86e4 100644 --- a/src/surewindow.cpp +++ b/src/surewindow.cpp @@ -1,20 +1,14 @@ #include "surewindow.h" #include "ui_surewindow.h" #include +#include SureWindow::SureWindow(QWidget *parent) : QWidget(parent), ui(new Ui::SureWindow) { ui->setupUi(this); - ui->tipLabel->setText(tr("Multiple users are logged in at the same time.Are you sure " - "you want to reboot this system?")); ui->tipLabel->setStyleSheet("color:white;font:14pt;"); - ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;}" - "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" - "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); - ui->confirmBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;}" - "QPushButton:hover{background: rgba(255, 255, 255, 0.25);border-radius: 8px;}" - "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); + //ui->tipLabel->setWordWrap(true); connect(ui->cancelBtn, &QPushButton::clicked, this, [&]() { emit cantelButtonclicked(); }); connect(ui->confirmBtn, &QPushButton::clicked, this, [&]() { emit confirmButtonclicked(); }); } @@ -22,11 +16,71 @@ SureWindow::SureWindow(QWidget *parent) : SureWindow::~SureWindow() { delete ui; - - } -void SureWindow::setText(const QString tips) +void SureWindow::setTips(const QString tips) { + ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;}" + "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" + "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); + + ui->confirmBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;}" + "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" + "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); + ui->confirmBtn->show(); + ui->tipLabel->show(); + ui->listView->hide(); ui->tipLabel->setText(tips); } + +void SureWindow::setWarning(QVector &list, int type) +{ + switch (type) { + case 0: + ui->tipLabel->setText(tr("The following program is running to prevent the system from reboot!")); + break; + case 1: + ui->tipLabel->setText(tr("The following program is running to prevent the system from shutting down!")); + break; + case 2: + ui->tipLabel->setText(tr("The following program is running to prevent the system from suspend!")); + break; + case 3: + ui->tipLabel->setText(tr("The following program is running to prevent the system from hibernate!")); + break; + default: + break; + } + ui->tipLabel->adjustSize(); + adjustSize(); + ui->listView->show(); + + QStandardItemModel *model = new QStandardItemModel(this); + for (auto iter = list.begin(); iter != list.end(); ++iter) { + QIcon icon; + QString appName = iter->name; + QString iconName = iter->icon; + + if (!iconName.isEmpty() && QIcon::hasThemeIcon(iconName)) { + icon = QIcon::fromTheme(iconName); + } else if (QIcon::hasThemeIcon("application-x-desktop")) { + icon = QIcon::fromTheme("application-x-desktop"); + } + model->appendRow(new QStandardItem(icon, appName)); + } + + ui->listView->verticalScrollMode(); + ui->listView->setStyleSheet("font:10pt;color:white; background-color: rgba(255,255,255,30%); border-radius: 12px;"); + ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->listView->setIconSize(QSize(32,32)); + ui->listView->setModel(model); + ui->listView->setFixedSize(520, 320); + adjustSize(); + ui->cancelBtn->setFixedSize(120, 48); + + ui->confirmBtn->hide(); + ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 24px;}" + "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 24px;}" + "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 24px;}"); + +} diff --git a/src/surewindow.h b/src/surewindow.h index 89871ff..8f15d27 100644 --- a/src/surewindow.h +++ b/src/surewindow.h @@ -1,6 +1,7 @@ #ifndef SUREWINDOW_H #define SUREWINDOW_H +#include "lockchecker.h" #include namespace Ui { @@ -14,7 +15,8 @@ class SureWindow : public QWidget public: explicit SureWindow(QWidget *parent = nullptr); ~SureWindow(); - void setText(const QString tips); + void setTips(const QString tips); + void setWarning(QVector &list, int type); private: Ui::SureWindow *ui; diff --git a/src/surewindow.ui b/src/surewindow.ui index 0f921d5..278cab5 100644 --- a/src/surewindow.ui +++ b/src/surewindow.ui @@ -6,8 +6,8 @@ 0 0 - 821 - 631 + 632 + 674 @@ -15,7 +15,7 @@ - 46 + 24 @@ -72,11 +72,60 @@ + + + + 0 + + + 19 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 520 + 320 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + 24 + + 5 + @@ -100,8 +149,8 @@ - 96 - 36 + 120 + 48 @@ -113,14 +162,14 @@ - 96 - 36 + 120 + 48 - 96 - 36 + 120 + 48 diff --git a/src/tabletlockwidget.cpp b/src/tabletlockwidget.cpp index 82e4932..ff972bc 100644 --- a/src/tabletlockwidget.cpp +++ b/src/tabletlockwidget.cpp @@ -78,7 +78,8 @@ TabletLockWidget::TabletLockWidget(QWidget *parent) : m_vKeyboard->installEventFilter(this); this->installEventFilter(this); - powermanager = new PowerManager(this); + powermanager = new PowerManager(0, this); + powermanager->setStartupMode(m_isStartupMode); powermanager->hide(); initUI(); @@ -118,6 +119,14 @@ bool TabletLockWidget::eventFilter(QObject *obj, QEvent *event) return QWidget::eventFilter(obj, event); } +void TabletLockWidget::setStartupMode(bool mode) +{ + m_isStartupMode = mode; + if (powermanager) { + powermanager->setStartupMode(m_isStartupMode); + } +} + void TabletLockWidget::startAuth() { m_digitalAuthDialog->startAuth(); @@ -632,3 +641,17 @@ EduPlatformInterface* TabletLockWidget::getEduPlatformInterface() return m_eduPlatformInterface; } + +void TabletLockWidget::onGlobalKeyPress(const quint8 &key) +{ + if (powermanager && powermanager->isVisible()) { + powermanager->onGlobalKeyPress(key); + } +} + +void TabletLockWidget::onGlobalkeyRelease(const quint8 &key) +{ + if (powermanager && powermanager->isVisible()) { + powermanager->onGlobalkeyRelease(key); + } +} diff --git a/src/tabletlockwidget.h b/src/tabletlockwidget.h index 12be613..dba18d7 100644 --- a/src/tabletlockwidget.h +++ b/src/tabletlockwidget.h @@ -65,6 +65,11 @@ public: return true; }; // void RecieveKey(int key); + void setStartupMode(bool mode); + +public Q_SLOTS: + void onGlobalKeyPress(const quint8 &key); + void onGlobalkeyRelease(const quint8 &key); Q_SIGNALS: void closed(); @@ -122,6 +127,7 @@ private: int m_authType; int m_pageType = 0; + bool m_isStartupMode = false; }; #endif // TABLETLOCKWIDGET_H diff --git a/src/types.h b/src/types.h index 42d5522..76b1fd1 100644 --- a/src/types.h +++ b/src/types.h @@ -56,6 +56,10 @@ enum ScreenStatus #define SS_DBUS_PATH "/" #define SS_DBUS_INTERFACE "org.ukui.ScreenSaver" +#define SSWND_DBUS_SERVICE "org.ukui.ScreenSaverWnd" +#define SSWND_DBUS_PATH "/" +#define SSWND_DBUS_INTERFACE "org.ukui.ScreenSaverWnd" + #define BIO_ERROR -1 #define BIO_FAILED 0 #define BIO_SUCCESS 1 diff --git a/src/ukui-screensaver-backend.cpp b/src/ukui-screensaver-backend.cpp index 63f6351..31783b0 100644 --- a/src/ukui-screensaver-backend.cpp +++ b/src/ukui-screensaver-backend.cpp @@ -21,7 +21,6 @@ #include #include "interface.h" -#include "sessionwatcher.h" #include "screensaveradaptor.h" #include "types.h" @@ -31,8 +30,6 @@ #include #include -#define POWER_TYPE_SCHENA "org.ukui.power-manager" - void sig_chld(int /*signo*/) { pid_t pid; @@ -43,10 +40,6 @@ void sig_chld(int /*signo*/) int main(int argc, char *argv[]) { -// if(signal(SIGCHLD, sig_chld) == SIG_ERR) { -// perror("signal error"); -// exit(EXIT_FAILURE); -// } initUkuiLog4qt("ukui-screensaver-backend"); // 重启或关机时不被session关掉 qunsetenv("SESSION_MANAGER"); @@ -65,31 +58,6 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - FILE *fp; - - // for PowerManager - fp = popen("xset s 0 0", "r"); - fclose(fp); -// Q_UNUSED(fp) - - QGSettings *powerSettings; - if(QGSettings::isSchemaInstalled(POWER_TYPE_SCHENA)){ - powerSettings = new QGSettings(POWER_TYPE_SCHENA,"",NULL); - QStringList keys = powerSettings->keys(); - if (keys.contains("lockSuspend")) { - bool ret = powerSettings->get("lockSuspend").toBool(); - if(ret){ - powerSettings->set("lock-suspend",false); - } - } - if (keys.contains("lockHibernate")) { - bool ret = powerSettings->get("lockHibernate").toBool(); - if(ret){ - powerSettings->set("lock-hibernate",false); - } - } - } - // 注册DBus Interface *interface = new Interface(); ScreenSaverAdaptor adaptor(interface); @@ -107,41 +75,6 @@ int main(int argc, char *argv[]) } qDebug() << service.baseService(); - // 发送DBus信号 - SessionWatcher *watcher = new SessionWatcher; - QObject::connect(watcher, &SessionWatcher::sessionIdle, - interface, &Interface::onSessionIdleReceived); - - QObject::connect(watcher, &SessionWatcher::sessionLockIdle, - interface, &Interface::Lock); - - QObject::connect(watcher, &SessionWatcher::sessionIdle, - &a, [&]{ - QDBusMessage message = QDBusMessage::createSignal(SS_DBUS_PATH, - SS_DBUS_INTERFACE, - "SessionIdle"); - service.send(message); - //qDebug()<<"message="<start(3000); - QObject::connect(checkInterface, SIGNAL(NameLost(QString)), interface, SLOT(onNameLost(QString))); diff --git a/src/ukui-screensaver-dialog.cpp b/src/ukui-screensaver-dialog.cpp index bd7bb1e..d13bf28 100644 --- a/src/ukui-screensaver-dialog.cpp +++ b/src/ukui-screensaver-dialog.cpp @@ -33,6 +33,7 @@ #include #include #include +#include "screensaverwndadaptor.h" #include #include #include "fullbackgroundwidget.h" @@ -196,11 +197,27 @@ int main(int argc, char *argv[]) window = new FullBackgroundWidget(); - QFile qssFile(":/qss/assets/authdialog.qss"); - if(qssFile.open(QIODevice::ReadOnly)) { - a.setStyleSheet(qssFile.readAll()); +// QFile qssFile(":/qss/assets/authdialog.qss"); +// if(qssFile.open(QIODevice::ReadOnly)) { +// a.setStyleSheet(qssFile.readAll()); +// } +// qssFile.close(); + // 注册DBus + ScreenSaverWndAdaptor adaptorWnd(window); + + QDBusConnection service = QDBusConnection::sessionBus(); + if(!service.registerService(SSWND_DBUS_SERVICE)) { + qDebug() << service.lastError().message(); + return 1; } - qssFile.close(); + if(!service.registerObject(SSWND_DBUS_PATH, SSWND_DBUS_SERVICE, &adaptorWnd, + QDBusConnection::ExportAllSlots | + QDBusConnection::ExportAllSignals)) { + qDebug() << service.lastError().message(); + return 1; + } + qDebug() << service.baseService(); + if(parser.isSet(blankOption)) { @@ -218,14 +235,16 @@ int main(int argc, char *argv[]) if(parser.isSet(lstOption)) { + window->setIsStartup(true); window->lock(); - window->setIsStartup(true); } if(parser.isSet(sessionIdleOption)) { - if(window->onSessionStatusChanged(SESSION_IDLE) == -1) - return 0; + if(window->onSessionStatusChanged(SESSION_IDLE) == -1) { + window->close(); + return 0; + } } if(parser.isSet(lscreensaverOption)) @@ -240,7 +259,7 @@ int main(int argc, char *argv[]) */ if(parser.isSet(screensaverOption)) { - window->showScreensaver(); + window->showScreensaver(true); } #ifdef USE_INTEL diff --git a/src/ukui-screensaver.pro b/src/ukui-screensaver.pro index f8b4b43..aab53d3 100644 --- a/src/ukui-screensaver.pro +++ b/src/ukui-screensaver.pro @@ -44,7 +44,7 @@ SOURCES += \ auxiliary.cpp \ configuration.cpp \ screensaverwidget.cpp \ - screensaver.cpp \ + screensavermode.cpp \ event_monitor.cpp \ monitorwatcher.cpp @@ -58,7 +58,7 @@ HEADERS += \ auxiliary.h \ configuration.h \ screensaverwidget.h \ - screensaver.h \ + screensavermode.h \ event_monitor.h \ monitorwatcher.h @@ -73,7 +73,8 @@ TRANSLATIONS = ../i18n_ts/zh_CN.ts \ ../i18n_ts/ru.ts \ ../i18n_ts/fr.ts \ ../i18n_ts/pt.ts \ - ../i18n_ts/es.ts + ../i18n_ts/es.ts \ + ../i18n_ts/bo_CN.ts target.path = /usr/bin/ diff --git a/src/weathermanager.cpp b/src/weathermanager.cpp index e1738f2..506b34c 100644 --- a/src/weathermanager.cpp +++ b/src/weathermanager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,17 +40,18 @@ const int weatherReqInterval = 1000 * 60 * 20; //定时更新天气,和麒麟天 const QByteArray schemaWeather = "org.china-weather-data.settings"; static const QMap weatherMap { - {"NA", "55"}, - {"晴", "0"}, - {"多云", "1"}, - {"阴", "2"}, - {"阵雨", "3"}, - {"雷阵雨", "4"}, - {"小雨", "7"}, - {"中雨", "8"}, - {"大雨", "9"}, - {"中到大雨", "9"}, - {"雪", "13"}, + {"晴", "100"},{"多云", "101"},{"少云", "102"},{"晴间多云", "103"},{"阴", "104"}, + {"有风", "200"},{"平静", "201"},{"微风", "202"},{"和风", "203"},{"清风", "204"},{"强风劲风", "205"},{"疾风", "206"},{"大风", "207"},{"烈风", "208"},{"风暴", "209"}, + {"狂暴风", "210"},{"飓风", "211"},{"龙卷风", "212"},{"热带风暴", "213"}, + {"阵雨", "300"},{"强阵雨", "301"},{"雷阵雨", "302"},{"强雷阵雨", "303"},{"雷阵雨伴有冰雹", "304"},{"小雨", "305"},{"中雨", "306"},{"大雨", "307"},{"极端降雨", "308"},{"毛毛雨细雨", "309"}, + {"暴雨", "310"},{"大暴雨", "311"},{"特大暴雨", "312"},{"冻雨", "313"},{"小到中雨", "314"},{"中到大雨", "315"},{"大到暴雨", "316"},{"暴雨到大暴雨", "317"},{"大暴雨到特大暴雨", "318"}, + {"雨", "399"}, + {"小雪", "400"},{"中雪", "401"},{"大雪", "402"},{"暴雪", "403"},{"雨夹雪", "404"},{"雨雪天气", "405"},{"阵雨夹雪", "406"},{"阵雪", "407"},{"小到中雪", "408"},{"中到大雪", "409"}, + {"大到暴雪", "410"},{"雪", "499"}, + {"薄雾", "500"},{"雾", "501"},{"霾", "502"},{"扬沙", "503"},{"浮尘", "504"},{"沙尘暴", "507"},{"强沙尘暴", "508"},{"大雾", "509"}, + {"强浓雾", "510"},{"中度霾", "511"},{"重度霾", "512"},{"严重霾", "513"},{"大雾", "514"},{"特强浓雾", "515"}, + {"热", "900"},{"冷", "901"}, + {"未知", "999"} }; WeatherManager::WeatherManager(QObject *parent) : QObject(parent) @@ -66,6 +67,20 @@ WeatherManager::WeatherManager(QObject *parent) : QObject(parent) m_local_weather_info = new LocalWeatherInfo(this); connect(m_timer, &QTimer::timeout, this, &WeatherManager::weatherRequest); + + m_networkWatcher = new NetWorkWatcher(this); + connect(m_networkWatcher, &NetWorkWatcher::NetworkStateChanged, this, &WeatherManager::onNetworkStateChanged); + + m_networkWatcher->checkOnline(); +} + +void WeatherManager::onNetworkStateChanged(uint state) +{ + qDebug() << state; + if (NM_STATE_CONNECTED_GLOBAL != state) + emit onWeatherUpdate("天气不可用", NULL, NULL); + else + getWeather(); } void WeatherManager::getWeather() @@ -96,6 +111,9 @@ bool WeatherManager::updateLocation() emit onWeatherUpdate(m_local_weather_info->getCityName(), m_local_weather_info->getCondText(), m_local_weather_info->getTemperature()); + + + m_networkWatcher->checkOnline(); return true; } m_city_id = getLogcalCityId(); @@ -153,6 +171,23 @@ QString WeatherManager::getLogcalCityId() void WeatherManager::replyFinished(QNetworkReply *reply) { + if(reply != nullptr && reply->error() != QNetworkReply::NoError) + { + qWarning() << "[WeatherManager][replyFinished] get weather error:(" + << reply->error() << ")" << reply->errorString(); + if (m_networkTryNum < 15) + { + m_networkTryNum++; + QTimer::singleShot(1000, this, [=]{ + weatherRequest(); + }); + } else { + m_networkTryNum = 0; + } + emit onWeatherUpdate("天气不可用", "", ""); + return; + } + //注:天气信息只解析了锁屏需要展示的部分 QByteArray BA; QJsonDocument JD; @@ -180,13 +215,14 @@ void WeatherManager::replyFinished(QNetworkReply *reply) } if (now.contains("tmp")){ - m_temperature = now.mid(4); + m_temperature = now.mid(4) + "°C"; } } emit onWeatherUpdate(m_city_name, m_cond_txt, m_temperature); } } else { qWarning() << "get weather info error : " << JPE.errorString(); + emit onWeatherUpdate("天气不可用", "", ""); } reply->deleteLater(); @@ -202,17 +238,33 @@ QPixmap WeatherManager::getWeatherIcon(QString cond) if (cond.isEmpty()) { qWarning() << "cond info is unknown"; - return QPixmap(":/image/assets/weather/55.png").scaled(32,32); + return QPixmap(":/weather/assets/weather-icon/999.svg").scaled(32,32); } //根据m_cond_txt QString numStr = weatherMap.value(cond); if (!numStr.isEmpty()) { qDebug() << "----------------numStr=" + numStr; - return QPixmap(":/image/assets/weather/" + numStr +".png").scaled(32,32); + return QPixmap(":/weather/assets/weather-icon/" + numStr +".svg").scaled(32,32); } - return QPixmap(":/image/assets/weather/55.png").scaled(32,32); + qWarning() << "天气为|" << cond << "|"; + return QPixmap(":/weather/assets/weather-icon/999.svg").scaled(32,32); +} + +QString WeatherManager::getCityName() +{ + return ""; +} + +QString WeatherManager::getCond() +{ + return ""; +} + +QString WeatherManager::getTemperature() +{ + return ""; } LocalWeatherInfo::LocalWeatherInfo(QObject *parent) diff --git a/src/weathermanager.h b/src/weathermanager.h index b1d2783..3f29c40 100644 --- a/src/weathermanager.h +++ b/src/weathermanager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,8 @@ #include #include +#include "../src/networkwatcher.h" + class QNetworkAccessManager; class QNetworkReply; class LocalWeatherInfo; @@ -39,12 +41,17 @@ Q_SIGNALS: private Q_SLOTS: void replyFinished(QNetworkReply *); + void onNetworkStateChanged(uint state); public: void getWeather(); QPixmap getWeatherIcon(); QPixmap getWeatherIcon(QString cond); + QString getCityName(); + QString getCond(); + QString getTemperature(); + private: bool updateLocation();//更新位置,从用户设置获取城市信息,如有多个,只取第一个,未对接 void weatherRequest(); @@ -63,6 +70,9 @@ private: QGSettings *m_settings; LocalWeatherInfo *m_local_weather_info; + NetWorkWatcher *m_networkWatcher; + + int m_networkTryNum = 0; }; class LocalWeatherInfo : QObject diff --git a/src/xeventmonitor.cpp b/src/xeventmonitor.cpp index 3d2feb4..9eca744 100644 --- a/src/xeventmonitor.cpp +++ b/src/xeventmonitor.cpp @@ -115,7 +115,7 @@ void XEventMonitorPrivate::run() // Receive KeyPress, KeyRelease, ButtonPress, ButtonRelease and MotionNotify events. memset(range, 0, sizeof(XRecordRange)); - range->device_events.first = KeyPress; + range->device_events.first = ButtonPress; range->device_events.last = MotionNotify; // And create the XRECORD context. From 6b46dc924f352d8e747e96d31f335978aea1e7c4 Mon Sep 17 00:00:00 2001 From: winnerym Date: Tue, 1 Nov 2022 19:51:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index ac00a29..af7487d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -ukui-screensaver (3.22.1.2-ok1~1024) yangtze; urgency=medium +ukui-screensaver (3.22.1.3-ok2~1101) yangtze; urgency=medium * BUG号:无 * 需求号:Task#114869 【登录锁屏】增加登录、锁屏状态显示 From 794445293f2dc19b75d8cf4fde1a114671247b6e Mon Sep 17 00:00:00 2001 From: winnerym Date: Tue, 1 Nov 2022 20:01:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E4=BB=A5=E9=87=8D=E7=BC=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index af7487d..ecbec6d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -ukui-screensaver (3.22.1.3-ok2~1101) yangtze; urgency=medium +ukui-screensaver (3.22.1.3-ok3~1101) yangtze; urgency=medium * BUG号:无 * 需求号:Task#114869 【登录锁屏】增加登录、锁屏状态显示