diff --git a/src/common/definetypes.h b/src/common/definetypes.h index f54a3a1..a04bf8e 100644 --- a/src/common/definetypes.h +++ b/src/common/definetypes.h @@ -23,6 +23,7 @@ typedef enum _LOCK_CMD_ID_e LOCK_CMD_ID_GET_USERINFO_LIST = 0, LOCK_CMD_ID_USERINFO_CHANGED, LOCK_CMD_ID_SET_USER, + LOCK_CMD_ID_SWITCH_TO_USER, LOCK_CMD_ID_GET_DEFAULT_AUTH_USER, LOCK_CMD_ID_GET_CURRENT_USER, LOCK_CMD_ID_CURRENT_USER_CHANGED, diff --git a/src/lock-backend/dbusupperinterface.cpp b/src/lock-backend/dbusupperinterface.cpp index 043720e..f20adad 100644 --- a/src/lock-backend/dbusupperinterface.cpp +++ b/src/lock-backend/dbusupperinterface.cpp @@ -566,6 +566,9 @@ int DbusUpperInterface::SetInformation(QString strJson) case LOCK_CMD_ID_SET_USER: nRet = SetCurrentUser(rootObj); break; + case LOCK_CMD_ID_SWITCH_TO_USER: + nRet = switchToUser(rootObj); + break; case LOCK_CMD_ID_SET_SESSION: nRet = SetCurrentSession(rootObj); break; @@ -881,39 +884,6 @@ int DbusUpperInterface::SetCurrentUser(const QJsonObject &objInfo) m_lightDmHelper->setSession(strSession); } } - { - QString strSwitchSeatPath = ""; - QString strDesUserName = strUserName; - QString strCurUserName = SwitchUserUtils::GetCurUserName(); - if (strCurUserName.isEmpty()) { - qDebug()<<"GetCurUserName failed!"; - nRet = 1; - } else { - UserDisplayIfInfo curUdii = SwitchUserUtils::GetUserUDII(strCurUserName); - UserDisplayIfInfo desUdii = {""}; - if (!strDesUserName.isEmpty()) { - desUdii = SwitchUserUtils::GetUserUDII(strDesUserName); - if (desUdii.strUserName.isEmpty()) { - desUdii.strUserName = strDesUserName; - } - } - - if (!curUdii.strSeatPath.isEmpty()) { - strSwitchSeatPath = curUdii.strSeatPath; - } - if (!desUdii.strSeatPath.isEmpty()) { - strSwitchSeatPath = desUdii.strSeatPath; - } - - if (strSwitchSeatPath.isEmpty()) { - qWarning()<<"switch user: switch seat path invalid!"; - nRet = 1; - } else { - nRet = SwitchUserUtils::SwitchToUserSession(strSwitchSeatPath, desUdii); - qDebug()<<"Switch user result:"<= 0) { @@ -925,6 +895,46 @@ int DbusUpperInterface::SetCurrentUser(const QJsonObject &objInfo) return nRet; } +int DbusUpperInterface::switchToUser(const QJsonObject &objInfo) +{ + int nRet = -1; + QString strUserName = objInfo.value("Content").toString(); + if (!strUserName.isEmpty()) { + QString strSwitchSeatPath = ""; + QString strDesUserName = strUserName; + QString strCurUserName = SwitchUserUtils::GetCurUserName(); + if (strCurUserName.isEmpty()) { + qDebug()<<"GetCurUserName failed!"; + nRet = 1; + } else { + UserDisplayIfInfo curUdii = SwitchUserUtils::GetUserUDII(strCurUserName); + UserDisplayIfInfo desUdii = {""}; + if (!strDesUserName.isEmpty()) { + desUdii = SwitchUserUtils::GetUserUDII(strDesUserName); + if (desUdii.strUserName.isEmpty()) { + desUdii.strUserName = strDesUserName; + } + } + + if (!curUdii.strSeatPath.isEmpty()) { + strSwitchSeatPath = curUdii.strSeatPath; + } + if (!desUdii.strSeatPath.isEmpty()) { + strSwitchSeatPath = desUdii.strSeatPath; + } + + if (strSwitchSeatPath.isEmpty()) { + qWarning()<<"switch user: switch seat path invalid!"; + nRet = 1; + } else { + nRet = SwitchUserUtils::SwitchToUserSession(strSwitchSeatPath, desUdii); + qDebug()<<"Switch user result:"< reply = SetInformation(QString(QJsonDocument(jsonCmd).toJson())); + reply.waitForFinished(); + if (reply.isError()) { + qWarning() << "switchToUser error: " << reply.error().message(); + return -1; + } else { + return reply.value(); + } +} + bool BackendDbusHelper::usdExternalDoAction(int actionType) { QJsonObject jsonCmd; diff --git a/src/lock-dialog/backenddbushelper.h b/src/lock-dialog/backenddbushelper.h index 85a47e0..dc40461 100644 --- a/src/lock-dialog/backenddbushelper.h +++ b/src/lock-dialog/backenddbushelper.h @@ -134,6 +134,7 @@ public Q_SLOTS: void onUpdateInformation(const QString &strJson); bool setCurrentUser(QString strUserName); + int switchToUser(QString strUserName); bool setCurrentSession(QString strSession); bool lockStateChanged(bool isVisible); void startSession(); diff --git a/src/lock-dialog/lockdialogmodel.h b/src/lock-dialog/lockdialogmodel.h index 1ee7b33..0543b3e 100644 --- a/src/lock-dialog/lockdialogmodel.h +++ b/src/lock-dialog/lockdialogmodel.h @@ -317,6 +317,7 @@ Q_SIGNALS: /// void setCurrentUser(QString strUserName); + int switchToUser(QString strUserName); void setCurrentSession(QString strSession); void startSession(); void pamAuthenticate(QString strUserName); diff --git a/src/lock-dialog/lockdialogperformer.cpp b/src/lock-dialog/lockdialogperformer.cpp index 3f34f71..e80460d 100644 --- a/src/lock-dialog/lockdialogperformer.cpp +++ b/src/lock-dialog/lockdialogperformer.cpp @@ -72,6 +72,7 @@ void LockDialogPerformer::initConnections() connect(m_bdHelper, &BackendDbusHelper::usdMediaKeysConfChanged, m_modelLockDialog, &LockDialogModel::onUsdMediaKeysChanged); ///通过信号直接调用槽 connect(m_modelLockDialog, &LockDialogModel::setCurrentUser, m_bdHelper, &BackendDbusHelper::setCurrentUser); + connect(m_modelLockDialog, &LockDialogModel::switchToUser, m_bdHelper, &BackendDbusHelper::switchToUser); connect(m_modelLockDialog, &LockDialogModel::setCurrentSession, m_bdHelper, &BackendDbusHelper::setCurrentSession); connect(m_modelLockDialog, &LockDialogModel::startSession, m_bdHelper, &BackendDbusHelper::startSession); connect(m_modelLockDialog, &LockDialogModel::pamAuthenticate, m_bdHelper, &BackendDbusHelper::pamAuthenticate); diff --git a/src/widgets/authdialog.cpp b/src/widgets/authdialog.cpp index e76c600..f3d224e 100644 --- a/src/widgets/authdialog.cpp +++ b/src/widgets/authdialog.cpp @@ -1002,6 +1002,14 @@ void AuthDialog::startAuth() void AuthDialog::stopAuth() { + if(m_loginOpts) + { + if(m_bioTimer && m_bioTimer->isActive()) + m_bioTimer->stop(); + m_loginOpts->stopAuth(); + + m_loginOpts->hide(); + } clearMessage(); } diff --git a/src/widgets/fullbackgroundwidget.cpp b/src/widgets/fullbackgroundwidget.cpp index 3cb618a..5c4385c 100644 --- a/src/widgets/fullbackgroundwidget.cpp +++ b/src/widgets/fullbackgroundwidget.cpp @@ -259,7 +259,7 @@ void FullBackgroundWidget::onShowLock(bool isStartup) Q_EMIT m_modelLockDialog->setCurrentUser(m_modelLockDialog->defaultUserName()); Q_EMIT m_modelLockDialog->lockStateChanged(true); if(m_lockWidget) - m_lockWidget->show(); + m_lockWidget->show(); } void FullBackgroundWidget::onShowSessionIdle() @@ -271,8 +271,8 @@ void FullBackgroundWidget::onShowSessionIdle() void FullBackgroundWidget::onShowLockScreensaver() { - show(); - Q_EMIT m_modelLockDialog->lockStateChanged(true); + onShowLock(false); + onShowScreensaver(); } void FullBackgroundWidget::onShowScreensaver() diff --git a/src/widgets/lockwidget.cpp b/src/widgets/lockwidget.cpp index d6cd8cd..be236d5 100644 --- a/src/widgets/lockwidget.cpp +++ b/src/widgets/lockwidget.cpp @@ -31,6 +31,7 @@ #include "VirtualKeyboard/src/virtualkeyboardwidget.h" #include "blockwidget.h" #include "pluginsloader.h" +#include "global_utils.h" #define BLUR_RADIUS 300 #define RIGHT_MARGIN 24 @@ -302,6 +303,7 @@ void LockWidget::initConnections() connect(m_modelLockDialog, &LockDialogModel::usersInfoChanged, this, &LockWidget::onUsersInfoChanged); connect(m_modelLockDialog, &LockDialogModel::currentUserChanged, this, &LockWidget::onCurUserChanged); connect(m_modelLockDialog, &LockDialogModel::currentSessionChanged, this, &LockWidget::onSessionChanged); + connect(m_modelLockDialog, &LockDialogModel::sessionActiveChanged, this, &LockWidget::onSessionActiveChanged); if (authDialog) { connect(authDialog, SIGNAL(authSucceed(QString)), this, SIGNAL(authSucceed(QString))); connect(authDialog, &AuthDialog::userChangedByManual, @@ -324,7 +326,9 @@ void LockWidget::initUserWidget() m_userListWidget->setMaxHeight(height()/2); m_userListWidget->updateWidgetSize(); m_userListWidget->hide(); - connect(m_userListWidget, &UserListWidget::userSelected, m_modelLockDialog, &LockDialogModel::setCurrentUser); + connect(m_userListWidget, &UserListWidget::userSelected, m_modelLockDialog, [=](QString strUserName){ + SwitchToUser(strUserName); + }); m_userListWidget->clearFocus(); m_userListWidget->move(width() - m_userListWidget->width() - RIGHT_MARGIN, height()- BOTTOM_MARGIN*scale - buttonListWidget->height() - buttonListWidget->spacing()*scale - m_userListWidget->height()); @@ -662,7 +666,11 @@ void LockWidget::onCurUserChanged(const QString &strUserName) void LockWidget::onUserChangedByManual(const QString &userName) { if (m_modelLockDialog && m_modelLockDialog->findUserByName(userName)) { - Q_EMIT m_modelLockDialog->setCurrentUser(userName); + if (isCurUserSelf(userName)) { + Q_EMIT m_modelLockDialog->setCurrentUser(userName); + } else { + SwitchToUser(userName); + } } else { } @@ -934,8 +942,9 @@ void LockWidget::onCancelBtnClicked() void LockWidget::onCustomRequestAccount(QString account) { - if(m_modelLockDialog) - Q_EMIT m_modelLockDialog->setCurrentUser(account); + if(m_modelLockDialog) { + SwitchToUser(account); + } } void LockWidget::onGetCustomPluginMsg(QString strMsg) @@ -977,3 +986,52 @@ void LockWidget::startAuth() authDialog->startAuth(); } } + +void LockWidget::onSessionActiveChanged(bool isActive) +{ + if (isActive) { + if (m_timerChkActive && m_timerChkActive->isActive()) { + m_timerChkActive->stop(); + if (this->isHidden()) { + this->show(); + update(); + } + } +// if(authDialog) { +// authDialog->stopAuth(); +// } + } +} + +void LockWidget::SwitchToUser(QString strUserName) +{ + if(m_modelLockDialog) { + int nSwitchRet = Q_EMIT m_modelLockDialog->switchToUser(strUserName); + if (nSwitchRet != 0) { + Q_EMIT m_modelLockDialog->setCurrentUser(strUserName); + } else { +// if(authDialog) { +// authDialog->stopAuth(); +// } + if (!isCurUserSelf(strUserName) && !isHidden()) { + this->hide(); + update(); + if (!m_timerChkActive) { + m_timerChkActive = new QTimer(this); + m_timerChkActive->setInterval(10*1000); + connect(m_timerChkActive, &QTimer::timeout, this, [&,this](){ + if (this->isHidden()) { + this->show(); + } + m_timerChkActive->stop(); + }); + } else { + if (m_timerChkActive->isActive()) { + m_timerChkActive->stop(); + } + } + m_timerChkActive->start(); + } + } + } +} diff --git a/src/widgets/lockwidget.h b/src/widgets/lockwidget.h index 2b29d1c..0632647 100644 --- a/src/widgets/lockwidget.h +++ b/src/widgets/lockwidget.h @@ -63,6 +63,8 @@ private: void updateBottomButton(); + void SwitchToUser(QString strUserName); + private Q_SLOTS: /** * @brief item选中状态改变 @@ -115,6 +117,8 @@ private Q_SLOTS: */ void onGetCustomPluginMsg(QString strMsg); + void onSessionActiveChanged(bool isActive); + Q_SIGNALS: void authSucceed(QString strUserName); @@ -137,6 +141,7 @@ private: UserInfo m_curUserInfo; AuthDialog *authDialog = nullptr; + QTimer *m_timerChkActive = nullptr; // usd快捷键键值 QString m_areaScreenShot;