优化用户列表信息获取
This commit is contained in:
parent
cad3d82aea
commit
5595530cc4
|
@ -153,7 +153,7 @@ set(backend_SRC
|
|||
dbusifs/upowerhelper.cpp
|
||||
dbusifs/enginedevice.cpp
|
||||
dbusifs/device.cpp
|
||||
dbusifs/accountservicehelper.cpp
|
||||
dbusifs/accountshelper.cpp
|
||||
dbusifs/sessionhelper.cpp
|
||||
dbusifs/uniauthservice.cpp
|
||||
dbusifs/biometrichelper.cpp
|
||||
|
|
|
@ -203,6 +203,7 @@ enum SessionStatus
|
|||
#define DM_DBUS_PATH "/org/freedesktop/DisplayManager"
|
||||
#define DM_DBUS_INTERFACE "org.freedesktop.DisplayManager"
|
||||
#define DM_SEAT_INTERFACE "org.freedesktop.DisplayManager.Seat"
|
||||
#define DM_SESSION_INTERFACE "org.freedesktop.DisplayManager.Session"
|
||||
|
||||
#define SSWND_DBUS_SERVICE "org.ukui.ScreenSaverWnd"
|
||||
#define SSWND_DBUS_PATH "/"
|
||||
|
@ -310,5 +311,13 @@ typedef enum {
|
|||
#define FD_DBUS_SERVICE "org.freedesktop.DBus"
|
||||
#define FD_DBUS_PATH "/org/freedesktop/DBus"
|
||||
#define FD_DBUS_INTERFACE "org.freedesktop.DBus"
|
||||
#define FD_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
|
||||
|
||||
#define ACCOUNTS_DBUS_SERVICE "org.freedesktop.Accounts"
|
||||
#define ACCOUNTS_DBUS_PATH "/org/freedesktop/Accounts"
|
||||
#define ACCOUNTS_DBUS_INTERFACE "org.freedesktop.Accounts"
|
||||
|
||||
#define ACCOUNTS_USER_DBUS_INTERFACE "org.freedesktop.Accounts.User"
|
||||
#define ACCOUNTS_USER_LDM_SERVICE_INTERFACE "org.freedesktop.DisplayManager.AccountsService"
|
||||
|
||||
#endif // DEFINETYPES_H
|
||||
|
|
|
@ -15,34 +15,27 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
**/
|
||||
#include "accountservicehelper.h"
|
||||
#include "accountshelper.h"
|
||||
#include "definetypes.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDebug>
|
||||
#include "userinfo.h"
|
||||
|
||||
const static QString accountsService = QStringLiteral("org.freedesktop.Accounts");
|
||||
const static QString accountsPath = QStringLiteral("/org/freedesktop/Accounts");
|
||||
const static QString accountsInterface = QStringLiteral("org.freedesktop.Accounts");
|
||||
const static QString propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties");
|
||||
const static QString accountsUserInterface = QStringLiteral("org.freedesktop.Accounts.User");
|
||||
|
||||
AccountServiceHelper::AccountServiceHelper(QObject *parent)
|
||||
AccountsHelper::AccountsHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_accountsInterface = new QDBusInterface(accountsService,
|
||||
accountsPath,
|
||||
accountsInterface,
|
||||
QDBusConnection::systemBus(),
|
||||
this);
|
||||
initData();
|
||||
initConnections();
|
||||
}
|
||||
|
||||
AccountServiceHelper::~AccountServiceHelper()
|
||||
AccountsHelper::~AccountsHelper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString AccountServiceHelper::getUserLanguageByName(QString strUserName)
|
||||
QString AccountsHelper::getUserLanguageByName(QString strUserName)
|
||||
{
|
||||
QString strLanguage = "";
|
||||
if(!m_accountsInterface)
|
||||
|
@ -51,9 +44,9 @@ QString AccountServiceHelper::getUserLanguageByName(QString strUserName)
|
|||
if(!userPath.isValid())
|
||||
qWarning() << "Get UserPath error:" << userPath.error();
|
||||
else {
|
||||
QDBusInterface userIface(accountsService, userPath.value().path(),
|
||||
propertiesInterface, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> languageReply = userIface.call("Get", accountsUserInterface, "Language");
|
||||
QDBusInterface userIface(ACCOUNTS_DBUS_SERVICE, userPath.value().path(),
|
||||
FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> languageReply = userIface.call("Get", ACCOUNTS_USER_DBUS_INTERFACE, "Language");
|
||||
if(!languageReply.isValid())
|
||||
qWarning() << "Get User's language error" << languageReply.error();
|
||||
else {
|
||||
|
@ -63,7 +56,7 @@ QString AccountServiceHelper::getUserLanguageByName(QString strUserName)
|
|||
return strLanguage;
|
||||
}
|
||||
|
||||
QString AccountServiceHelper::getUserBackgroundByName(QString strUserName)
|
||||
QString AccountsHelper::getUserBackgroundByName(QString strUserName)
|
||||
{
|
||||
QString strBackground = "";
|
||||
if(!m_accountsInterface)
|
||||
|
@ -72,9 +65,9 @@ QString AccountServiceHelper::getUserBackgroundByName(QString strUserName)
|
|||
if(!userPath.isValid())
|
||||
qWarning() << "Get UserPath error:" << userPath.error();
|
||||
else {
|
||||
QDBusInterface userIface(accountsService, userPath.value().path(),
|
||||
propertiesInterface, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> backgroundReply = userIface.call("Get", accountsUserInterface, "BackgroundFile");
|
||||
QDBusInterface userIface(ACCOUNTS_DBUS_SERVICE, userPath.value().path(),
|
||||
FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> backgroundReply = userIface.call("Get", ACCOUNTS_USER_DBUS_INTERFACE, "BackgroundFile");
|
||||
if(!backgroundReply.isValid())
|
||||
qWarning() << "Get User's background error" << backgroundReply.error();
|
||||
else {
|
||||
|
@ -84,7 +77,7 @@ QString AccountServiceHelper::getUserBackgroundByName(QString strUserName)
|
|||
return strBackground;
|
||||
}
|
||||
|
||||
QString AccountServiceHelper::getUserSessionByName(QString strUserName)
|
||||
QString AccountsHelper::getUserSessionByName(QString strUserName)
|
||||
{
|
||||
QString strSession = "";
|
||||
if(!m_accountsInterface)
|
||||
|
@ -93,9 +86,9 @@ QString AccountServiceHelper::getUserSessionByName(QString strUserName)
|
|||
if(!userPath.isValid())
|
||||
qWarning() << "Get UserPath error:" << userPath.error();
|
||||
else {
|
||||
QDBusInterface userIface(accountsService, userPath.value().path(),
|
||||
propertiesInterface, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> sessionReply = userIface.call("Get", accountsUserInterface, "XSession");
|
||||
QDBusInterface userIface(ACCOUNTS_DBUS_SERVICE, userPath.value().path(),
|
||||
FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> sessionReply = userIface.call("Get", ACCOUNTS_USER_DBUS_INTERFACE, "XSession");
|
||||
if(!sessionReply.isValid())
|
||||
qWarning() << "Get User's xsession error" << sessionReply.error();
|
||||
else {
|
||||
|
@ -105,7 +98,7 @@ QString AccountServiceHelper::getUserSessionByName(QString strUserName)
|
|||
return strSession;
|
||||
}
|
||||
|
||||
QString AccountServiceHelper::getAccountBackground(uid_t uid)
|
||||
QString AccountsHelper::getAccountBackground(uid_t uid)
|
||||
{
|
||||
QString strBackground = "";
|
||||
if(!m_accountsInterface)
|
||||
|
@ -114,9 +107,9 @@ QString AccountServiceHelper::getAccountBackground(uid_t uid)
|
|||
if(!userPath.isValid())
|
||||
qWarning() << "Get UserPath error:" << userPath.error();
|
||||
else {
|
||||
QDBusInterface userIface(accountsService, userPath.value().path(),
|
||||
propertiesInterface, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> backgroundReply = userIface.call("Get", accountsUserInterface, "BackgroundFile");
|
||||
QDBusInterface userIface(ACCOUNTS_DBUS_SERVICE, userPath.value().path(),
|
||||
FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> backgroundReply = userIface.call("Get", ACCOUNTS_USER_DBUS_INTERFACE, "BackgroundFile");
|
||||
if(!backgroundReply.isValid())
|
||||
qWarning() << "Get User's BackgroundFile error" << backgroundReply.error();
|
||||
else {
|
||||
|
@ -125,3 +118,39 @@ QString AccountServiceHelper::getAccountBackground(uid_t uid)
|
|||
}
|
||||
return strBackground;
|
||||
}
|
||||
|
||||
void AccountsHelper::initData()
|
||||
{
|
||||
if (!m_accountsInterface) {
|
||||
m_accountsInterface = new QDBusInterface(ACCOUNTS_DBUS_SERVICE,
|
||||
ACCOUNTS_DBUS_PATH,
|
||||
ACCOUNTS_DBUS_INTERFACE,
|
||||
QDBusConnection::systemBus(),
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
void AccountsHelper::initConnections()
|
||||
{
|
||||
connect(m_accountsInterface, SIGNAL(UserAdded(QDBusObjectPath)), this, SIGNAL(UserAdded(QDBusObjectPath)));
|
||||
connect(m_accountsInterface, SIGNAL(UserDeleted(QDBusObjectPath)), this, SIGNAL(UserRemoved(QDBusObjectPath)));
|
||||
}
|
||||
|
||||
QStringList AccountsHelper::getUserList()
|
||||
{
|
||||
QStringList listUsers;
|
||||
if (!m_accountsInterface)
|
||||
return listUsers;
|
||||
QDBusMessage ret = m_accountsInterface->call("ListCachedUsers");
|
||||
QList<QVariant> outArgs = ret.arguments();
|
||||
QVariant first = outArgs.at(0);
|
||||
const QDBusArgument &dbusArgs = first.value<QDBusArgument>();
|
||||
QDBusObjectPath path;
|
||||
dbusArgs.beginArray();
|
||||
while (!dbusArgs.atEnd()) {
|
||||
dbusArgs >> path;
|
||||
listUsers << path.path();
|
||||
}
|
||||
dbusArgs.endArray();
|
||||
return listUsers;
|
||||
}
|
|
@ -20,14 +20,16 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include <QMap>
|
||||
#include <QDBusObjectPath>
|
||||
|
||||
class AccountServiceHelper : public QObject
|
||||
class AccountsHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AccountServiceHelper(QObject *parent = nullptr);
|
||||
explicit AccountsHelper(QObject *parent = nullptr);
|
||||
|
||||
virtual ~AccountServiceHelper();
|
||||
virtual ~AccountsHelper();
|
||||
|
||||
QString getUserLanguageByName(QString strUserName);
|
||||
|
||||
|
@ -37,6 +39,16 @@ public:
|
|||
|
||||
QString getAccountBackground(uid_t uid);
|
||||
|
||||
QStringList getUserList();
|
||||
|
||||
Q_SIGNALS:
|
||||
void UserAdded(const QDBusObjectPath &path);
|
||||
void UserRemoved(const QDBusObjectPath &path);
|
||||
|
||||
private:
|
||||
void initData();
|
||||
void initConnections();
|
||||
|
||||
private:
|
||||
QDBusInterface *m_accountsInterface = nullptr;
|
||||
};
|
|
@ -33,7 +33,7 @@
|
|||
#include "switchuserutils.h"
|
||||
#include "pamauthenticate.h"
|
||||
#include "upowerhelper.h"
|
||||
#include "accountservicehelper.h"
|
||||
#include "accountshelper.h"
|
||||
#include "sessionhelper.h"
|
||||
#include "sessionwatcher.h"
|
||||
#include "freedesktophelper.h"
|
||||
|
@ -56,7 +56,7 @@ void DbusUpperInterface::initData()
|
|||
{
|
||||
m_bLockState = false;
|
||||
m_bSlpState = false;
|
||||
m_accountsHelper = new AccountServiceHelper(this);
|
||||
m_accountsHelper = new AccountsHelper(this);
|
||||
m_lightDmHelper = new LightDMHelper(m_accountsHelper, this);
|
||||
m_login1Helper = new Login1Helper(this);
|
||||
m_config = new Configuration(this);
|
||||
|
|
|
@ -37,7 +37,7 @@ class QJsonObject;
|
|||
class PamAuthenticate;
|
||||
class UsdHelper;
|
||||
class UpowerHelper;
|
||||
class AccountServiceHelper;
|
||||
class AccountsHelper;
|
||||
class SessionHelper;
|
||||
class SessionWatcher;
|
||||
class BioAuthenticate;
|
||||
|
@ -381,7 +381,7 @@ private:
|
|||
PamAuthenticate *m_pamAuth = nullptr;
|
||||
UsdHelper *m_usdHelper = nullptr;
|
||||
UpowerHelper *m_upowerHelper = nullptr;
|
||||
AccountServiceHelper *m_accountsHelper = nullptr;
|
||||
AccountsHelper *m_accountsHelper = nullptr;
|
||||
bool lockState = false;
|
||||
SessionHelper *m_sessionHelper = nullptr;
|
||||
SessionWatcher *m_sessionWatcher = nullptr;
|
||||
|
|
|
@ -22,14 +22,21 @@
|
|||
#include "securityuser.h"
|
||||
#include <pwd.h>
|
||||
#include "proxymodel.h"
|
||||
#include "accountservicehelper.h"
|
||||
#include "accountshelper.h"
|
||||
#include "definetypes.h"
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusMessage>
|
||||
#include <QVariantMap>
|
||||
|
||||
LightDMHelper::LightDMHelper(AccountServiceHelper *accountHelper, QObject *parent)
|
||||
LightDMHelper::LightDMHelper(AccountsHelper *accountHelper, QObject *parent)
|
||||
: QLightDM::Greeter(parent)
|
||||
, m_sessionsModel(nullptr)
|
||||
, m_secUser(SecurityUser::instance())
|
||||
, m_strCurUserName("")
|
||||
, m_accountServiceHelper(accountHelper)
|
||||
, m_ldmSessions(new QMap<QString, std::shared_ptr<LightDMSessionInfo>>())
|
||||
, m_mapUsers(new QMap<QString, UserInfoPtr>())
|
||||
, m_dbusIfsLDM(nullptr)
|
||||
{
|
||||
//连接到lightdm
|
||||
if(!connectToDaemonSync()){
|
||||
|
@ -46,11 +53,10 @@ void LightDMHelper::initData()
|
|||
updateSessionsInfo();
|
||||
setSession(defaultSessionHint());
|
||||
// 获取用户信息
|
||||
initLDMSessionsInfo();
|
||||
m_isShowManualLogin = showManualLoginHint();
|
||||
if(!hideUsersHint()){
|
||||
m_modelUsers = new UsersModel(this);
|
||||
m_modelUsers->setSourceModel(new QLightDM::UsersModel(this));
|
||||
connect(m_modelUsers, &UsersModel::userInfoChanged, this, &LightDMHelper::onUsersChanged);
|
||||
initAccountsUsersInfo();
|
||||
if(hasValidUsers() == 0) {
|
||||
m_isShowManualLogin = true;
|
||||
}
|
||||
|
@ -127,7 +133,7 @@ bool LightDMHelper::setCurrentUser(QString strUserName)
|
|||
|
||||
UserInfoPtr LightDMHelper::findUserByUid(uid_t id)
|
||||
{
|
||||
for (auto userInfoPtr : m_listUsers) {
|
||||
for (auto userInfoPtr : m_mapUsers->values()) {
|
||||
if (userInfoPtr->uid() == id) {
|
||||
return userInfoPtr;
|
||||
}
|
||||
|
@ -137,7 +143,7 @@ UserInfoPtr LightDMHelper::findUserByUid(uid_t id)
|
|||
|
||||
UserInfoPtr LightDMHelper::findUserByName(QString strName)
|
||||
{
|
||||
for (auto userInfoPtr : m_listUsers) {
|
||||
for (auto userInfoPtr : m_mapUsers->values()) {
|
||||
if (userInfoPtr->name() == strName) {
|
||||
return userInfoPtr;
|
||||
}
|
||||
|
@ -147,7 +153,7 @@ UserInfoPtr LightDMHelper::findUserByName(QString strName)
|
|||
|
||||
bool LightDMHelper::hasSameUser(const UserInfoPtr userInfoPtr)
|
||||
{
|
||||
for (auto user : m_listUsers) {
|
||||
for (auto user : m_mapUsers->values()) {
|
||||
if (user->uid() == userInfoPtr->uid()
|
||||
&& user->name() == userInfoPtr->name()) {
|
||||
return true;
|
||||
|
@ -158,12 +164,9 @@ bool LightDMHelper::hasSameUser(const UserInfoPtr userInfoPtr)
|
|||
|
||||
bool LightDMHelper::hasValidUsers()
|
||||
{
|
||||
if (!m_modelUsers)
|
||||
return false;
|
||||
int count = 0;
|
||||
for(int i = 0; i < m_modelUsers->rowCount(QModelIndex()); i++){
|
||||
QString name = m_modelUsers->index(i).data(QLightDM::UsersModel::NameRole).toString();
|
||||
if(m_secUser->isSecrityUser(name))
|
||||
for (auto user : m_mapUsers->values()) {
|
||||
if(m_secUser->isSecrityUser(user->name()))
|
||||
count++;
|
||||
}
|
||||
return (bool)(count>0);
|
||||
|
@ -182,58 +185,18 @@ bool LightDMHelper::isSameUser(UserInfoPtr userA, UserInfoPtr userB)
|
|||
|
||||
void LightDMHelper::onUsersChanged()
|
||||
{
|
||||
if (!m_modelUsers)
|
||||
return ;
|
||||
updateUsersInfo();
|
||||
Q_EMIT usersInfoChanged();
|
||||
}
|
||||
|
||||
void LightDMHelper::updateUsersInfo()
|
||||
{
|
||||
m_listUsers.clear();
|
||||
if (m_modelUsers) {
|
||||
for(int i = 0; i < m_modelUsers->rowCount(QModelIndex()); i++){
|
||||
QString name = m_modelUsers->index(i).data(QLightDM::UsersModel::NameRole).toString();
|
||||
if(m_secUser->isSecrityUser(name)) {
|
||||
std::shared_ptr<UserInfo> userInfoPtr = std::make_shared<UserInfo>();
|
||||
userInfoPtr->updateName(name);
|
||||
uid_t uid = m_modelUsers->index(i).data(QLightDM::UsersModel::UidRole).toUInt();
|
||||
userInfoPtr->updateUid(uid);
|
||||
QString strRealName = m_modelUsers->index(i).data(QLightDM::UsersModel::RealNameRole).toString();
|
||||
if (strRealName.isEmpty()) {
|
||||
strRealName = name;
|
||||
}
|
||||
userInfoPtr->updateFullName(strRealName);
|
||||
QString strBackGround = m_modelUsers->index(i).data(QLightDM::UsersModel::BackgroundPathRole).toString();
|
||||
if (!strBackGround.isEmpty() && QFileInfo(strBackGround).exists()){
|
||||
userInfoPtr->updateBackground(strBackGround);
|
||||
QList<UserInfoPtr> userInfos = m_mapUsers->values();
|
||||
for (auto user : userInfos) {
|
||||
if (isUserLoggined(user->name())) {
|
||||
user->updateLoggedIn(true);
|
||||
} else {
|
||||
if (m_accountServiceHelper) {
|
||||
strBackGround = m_accountServiceHelper->getAccountBackground(uid);
|
||||
if (!strBackGround.isEmpty() && QFileInfo(strBackGround).exists()){
|
||||
userInfoPtr->updateBackground(strBackGround);
|
||||
}
|
||||
}
|
||||
}
|
||||
QString strImgHead = m_modelUsers->index(i).data(QLightDM::UsersModel::ImagePathRole).toString();
|
||||
if (!strImgHead.isEmpty() && QFileInfo(strImgHead).exists()){
|
||||
userInfoPtr->updateHeadImage(strImgHead);
|
||||
}
|
||||
|
||||
bool isLoggedIn = m_modelUsers->index(i).data(QLightDM::UsersModel::LoggedInRole).toBool();
|
||||
userInfoPtr->updateLoggedIn(isLoggedIn);
|
||||
|
||||
if (m_accountServiceHelper) {
|
||||
QString strLang = m_accountServiceHelper->getUserLanguageByName(name);
|
||||
if (!strLang.isEmpty()){
|
||||
userInfoPtr->updateLang(strLang);
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasSameUser(userInfoPtr)) {
|
||||
m_listUsers.append(userInfoPtr);
|
||||
}
|
||||
}
|
||||
user->updateLoggedIn(false);
|
||||
}
|
||||
}
|
||||
if (m_isShowManualLogin) {
|
||||
|
@ -241,7 +204,8 @@ void LightDMHelper::updateUsersInfo()
|
|||
userInfoPtr->updateFullName(tr("Login"));
|
||||
userInfoPtr->updateName("*login");
|
||||
if (!hasSameUser(userInfoPtr)) {
|
||||
m_listUsers.append(userInfoPtr);
|
||||
const QString path = userInfoPtr->path().isEmpty() ? userInfoPtr->name() : userInfoPtr->path();
|
||||
m_mapUsers->insert(path, userInfoPtr);
|
||||
}
|
||||
}
|
||||
if (hasGuestAccountHint()) {
|
||||
|
@ -249,7 +213,8 @@ void LightDMHelper::updateUsersInfo()
|
|||
userInfoPtr->updateFullName(tr("Guest"));
|
||||
userInfoPtr->updateName("*guest");
|
||||
if (!hasSameUser(userInfoPtr)) {
|
||||
m_listUsers.append(userInfoPtr);
|
||||
const QString path = userInfoPtr->path().isEmpty() ? userInfoPtr->name() : userInfoPtr->path();
|
||||
m_mapUsers->insert(path, userInfoPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,5 +233,199 @@ void LightDMHelper::updateSessionsInfo()
|
|||
|
||||
QList<UserInfoPtr> LightDMHelper::getUsersInfo()
|
||||
{
|
||||
return m_listUsers;
|
||||
return m_mapUsers->values();
|
||||
}
|
||||
|
||||
bool LightDMHelper::isUserLoggined(const QString &strUserName)
|
||||
{
|
||||
QList<std::shared_ptr<LightDMSessionInfo>> sessionList = m_ldmSessions->values();
|
||||
auto it = std::find_if(sessionList.begin(), sessionList.end(), [strUserName](std::shared_ptr<LightDMSessionInfo> &session) {
|
||||
return session->userName() == strUserName;
|
||||
});
|
||||
if (it != sessionList.end()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LightDMHelper::initLDMSessionsInfo()
|
||||
{
|
||||
if (!m_dbusIfsLDM) {
|
||||
m_dbusIfsLDM = new QDBusInterface(DM_DBUS_SERVICE, DM_DBUS_PATH, DM_DBUS_INTERFACE, QDBusConnection::systemBus(), this);
|
||||
connect(m_dbusIfsLDM, SIGNAL(SessionAdded(QDBusObjectPath)), this, SLOT(onLDMSessionAdded(QDBusObjectPath)));
|
||||
connect(m_dbusIfsLDM, SIGNAL(SessionRemoved(QDBusObjectPath)), this, SLOT(onLDMSessionRemoved(QDBusObjectPath)));
|
||||
|
||||
QStringList listSessions;
|
||||
QDBusInterface ifLDMProp(DM_DBUS_SERVICE, DM_DBUS_PATH, FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusMessage ret = ifLDMProp.call("GetAll", DM_DBUS_INTERFACE);
|
||||
QList<QVariant> outArgs = ret.arguments();
|
||||
QVariant first = outArgs.at(0);
|
||||
const QDBusArgument &dbusArgs = first.value<QDBusArgument>();
|
||||
dbusArgs.beginMap();
|
||||
while(!dbusArgs.atEnd()) {
|
||||
QString key;
|
||||
QVariant value;
|
||||
dbusArgs.beginMapEntry();
|
||||
dbusArgs >> key >> value;
|
||||
if (key == "Sessions") {
|
||||
const QDBusArgument &dbusObjPaths = value.value<QDBusArgument>();
|
||||
QDBusObjectPath path;
|
||||
dbusObjPaths.beginArray();
|
||||
while (!dbusObjPaths.atEnd()) {
|
||||
dbusObjPaths >> path;
|
||||
listSessions << path.path();
|
||||
}
|
||||
dbusObjPaths.endArray();
|
||||
}
|
||||
dbusArgs.endMapEntry();
|
||||
}
|
||||
dbusArgs.endMap();
|
||||
for (auto session : listSessions) {
|
||||
std::shared_ptr<LightDMSessionInfo> ldmSessionInfo(new LightDMSessionInfo(session, this));
|
||||
m_ldmSessions->insert(session, ldmSessionInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LightDMHelper::onLDMSessionAdded(QDBusObjectPath objPath)
|
||||
{
|
||||
qDebug()<< "Add LDM Session, path:"<<objPath.path();
|
||||
|
||||
if (m_ldmSessions->contains(objPath.path())) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<LightDMSessionInfo> ldmSessionInfo(new LightDMSessionInfo(objPath.path(), this));
|
||||
m_ldmSessions->insert(objPath.path(), ldmSessionInfo);
|
||||
onUsersChanged();
|
||||
}
|
||||
|
||||
void LightDMHelper::onLDMSessionRemoved(QDBusObjectPath objPath)
|
||||
{
|
||||
if (!m_ldmSessions->contains(objPath.path())) {
|
||||
return;
|
||||
}
|
||||
const std::shared_ptr<LightDMSessionInfo> session = m_ldmSessions->value(objPath.path());
|
||||
m_ldmSessions->remove(objPath.path());
|
||||
onUsersChanged();
|
||||
}
|
||||
|
||||
void LightDMHelper::initAccountsUsersInfo()
|
||||
{
|
||||
if (m_accountServiceHelper) {
|
||||
QStringList listUsers = m_accountServiceHelper->getUserList();
|
||||
for (auto user : listUsers) {
|
||||
LocalUserInfoPtr userInfo(new LocalUserInfo(user, this));
|
||||
connect(userInfo.get(), &UserInfo::userPropChanged, this, &LightDMHelper::onUsersChanged);
|
||||
m_mapUsers->insert(user, userInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LightDMHelper::onUserAdded(QDBusObjectPath objPath)
|
||||
{
|
||||
qDebug()<< "Add Accounts User, path:"<<objPath.path();
|
||||
|
||||
if (m_mapUsers->contains(objPath.path())) {
|
||||
return;
|
||||
}
|
||||
LocalUserInfoPtr userInfo(new LocalUserInfo(objPath.path(), this));
|
||||
connect(userInfo.get(), &UserInfo::userPropChanged, this, &LightDMHelper::onUsersChanged);
|
||||
m_mapUsers->insert(objPath.path(), userInfo);
|
||||
onUsersChanged();
|
||||
}
|
||||
|
||||
void LightDMHelper::onUserRemoved(QDBusObjectPath objPath)
|
||||
{
|
||||
if (!m_mapUsers->contains(objPath.path())) {
|
||||
return;
|
||||
}
|
||||
const UserInfoPtr userInfo = m_mapUsers->value(objPath.path());
|
||||
qDebug()<< "Remove Accounts User, name:"<<userInfo->name();
|
||||
m_mapUsers->remove(objPath.path());
|
||||
onUsersChanged();
|
||||
}
|
||||
|
||||
LightDMSessionInfo::LightDMSessionInfo(const QString &strPath, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_strPath(strPath)
|
||||
{
|
||||
initData();
|
||||
initConnections();
|
||||
}
|
||||
|
||||
LightDMSessionInfo::~LightDMSessionInfo()
|
||||
{
|
||||
if (m_propertiesChangedConnected) {
|
||||
QDBusConnection::systemBus().disconnect(DM_DBUS_SERVICE,
|
||||
m_strPath,
|
||||
FD_PROPERTIES_INTERFACE,
|
||||
"PropertiesChanged",
|
||||
this,
|
||||
SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
|
||||
m_propertiesChangedConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LightDMSessionInfo::initData()
|
||||
{
|
||||
QDBusInterface ifaceExtra(DM_DBUS_SERVICE, m_strPath, FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusMessage ret = ifaceExtra.call("GetAll", DM_SESSION_INTERFACE);
|
||||
QList<QVariant> outArgs = ret.arguments();
|
||||
QVariant first = outArgs.at(0);
|
||||
const QDBusArgument &dbusArgs = first.value<QDBusArgument>();
|
||||
dbusArgs.beginMap();
|
||||
while(!dbusArgs.atEnd()) {
|
||||
QString key;
|
||||
QVariant value;
|
||||
dbusArgs.beginMapEntry();
|
||||
dbusArgs >> key >> value;
|
||||
if (key == "Seat") {
|
||||
m_strSeatPath = value.toString();
|
||||
} else if (key == "UserName") {
|
||||
m_strUserName = value.toString();
|
||||
}
|
||||
dbusArgs.endMapEntry();
|
||||
}
|
||||
dbusArgs.endMap();
|
||||
}
|
||||
|
||||
void LightDMSessionInfo::initConnections()
|
||||
{
|
||||
if (!m_propertiesChangedConnected) {
|
||||
QDBusConnection::systemBus().connect(DM_DBUS_SERVICE,
|
||||
m_strPath,
|
||||
FD_PROPERTIES_INTERFACE,
|
||||
"PropertiesChanged",
|
||||
this,
|
||||
SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
|
||||
m_propertiesChangedConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LightDMSessionInfo::onPropertiesChanged(const QString& interfaceName,
|
||||
const QVariantMap& changedProperties,
|
||||
const QStringList& invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(invalidatedProperties);
|
||||
if (interfaceName == DM_SESSION_INTERFACE) {
|
||||
QVariantMap::const_iterator itVar = changedProperties.constBegin();
|
||||
for ( ; itVar != changedProperties.constEnd(); itVar++) {
|
||||
QVariant varValue = itVar.value();
|
||||
if(itVar.key() == "Seat") {
|
||||
m_strSeatPath = varValue.toString();
|
||||
} else if(itVar.key() == "UserName") {
|
||||
m_strUserName = varValue.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator <<(QDebug stream, const LightDMSessionInfo &sessionInfo)
|
||||
{
|
||||
stream << "["
|
||||
<< sessionInfo.path()
|
||||
<< sessionInfo.userName()
|
||||
<< sessionInfo.seatPath()
|
||||
<< "]";
|
||||
return stream;
|
||||
}
|
||||
|
|
|
@ -24,11 +24,13 @@
|
|||
#include <QLightDM/UsersModel>
|
||||
#include <QList>
|
||||
#include <QModelIndex>
|
||||
#include <QDBusInterface>
|
||||
#include "userinfo.h"
|
||||
|
||||
class SecurityUser;
|
||||
class UsersModel;
|
||||
class AccountServiceHelper;
|
||||
class AccountsHelper;
|
||||
class LightDMSessionInfo;
|
||||
/**
|
||||
* @brief lightdm工具类
|
||||
*
|
||||
|
@ -42,7 +44,7 @@ public:
|
|||
*
|
||||
* @param parent 父指针
|
||||
*/
|
||||
explicit LightDMHelper(AccountServiceHelper *accountHelper, QObject *parent = nullptr);
|
||||
explicit LightDMHelper(AccountsHelper *accountHelper, QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -103,6 +105,14 @@ public Q_SLOTS:
|
|||
*/
|
||||
void onUsersChanged();
|
||||
|
||||
void onLDMSessionAdded(QDBusObjectPath objPath);
|
||||
|
||||
void onLDMSessionRemoved(QDBusObjectPath objPath);
|
||||
|
||||
void onUserAdded(QDBusObjectPath objPath);
|
||||
|
||||
void onUserRemoved(QDBusObjectPath objPath);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* @brief 认证成功
|
||||
|
@ -153,16 +163,51 @@ private:
|
|||
|
||||
void updateSessionsInfo();
|
||||
|
||||
void initLDMSessionsInfo();
|
||||
|
||||
bool isUserLoggined(const QString &strUserName);
|
||||
|
||||
void initAccountsUsersInfo();
|
||||
|
||||
private:
|
||||
bool m_isShowManualLogin; /**< 是否显示手动登录 */
|
||||
QString m_strSession; /**< 当前会话 */
|
||||
QString m_strCurUserName; /**< 当前选择用户 */
|
||||
QList<UserInfoPtr> m_listUsers; /**< 用户信息列表 */
|
||||
SecurityUser *m_secUser = nullptr; /**< 安全用户信息指针 */
|
||||
QLightDM::SessionsModel *m_sessionsModel; /**< lightdm 会话数据指针 */
|
||||
QList<QString> m_listSessions; /**< 会话列表 */
|
||||
UsersModel *m_modelUsers = nullptr; /**< lightdm 用户数据指针 */
|
||||
AccountServiceHelper *m_accountServiceHelper = nullptr;
|
||||
QMap<QString, UserInfoPtr> *m_mapUsers; /**< accounts 用户信息列表指针 */
|
||||
AccountsHelper *m_accountServiceHelper = nullptr;
|
||||
QMap<QString, std::shared_ptr<LightDMSessionInfo>> *m_ldmSessions;
|
||||
QDBusInterface *m_dbusIfsLDM;
|
||||
};
|
||||
|
||||
class LightDMSessionInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LightDMSessionInfo(const QString &strPath, QObject* parent = nullptr);
|
||||
|
||||
virtual ~LightDMSessionInfo();
|
||||
|
||||
inline QString path() const { return m_strPath; }
|
||||
inline QString userName() const { return m_strUserName; }
|
||||
inline QString seatPath() const { return m_strSeatPath; }
|
||||
|
||||
private:
|
||||
void initData();
|
||||
void initConnections();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPropertiesChanged(const QString&, const QVariantMap&, const QStringList&);
|
||||
|
||||
private:
|
||||
QString m_strPath;
|
||||
bool m_propertiesChangedConnected = false;
|
||||
QString m_strSeatPath;
|
||||
QString m_strUserName;
|
||||
};
|
||||
|
||||
QDebug operator <<(QDebug stream, const LightDMSessionInfo &userInfo);
|
||||
|
||||
#endif // LIGHTDMHELPER_H
|
||||
|
|
203
src/userinfo.cpp
203
src/userinfo.cpp
|
@ -17,9 +17,16 @@
|
|||
**/
|
||||
#include "userinfo.h"
|
||||
#include "global_utils.h"
|
||||
#include "definetypes.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusArgument>
|
||||
#include <QFile>
|
||||
|
||||
UserInfo::UserInfo()
|
||||
: m_isLoggedIn(false)
|
||||
UserInfo::UserInfo(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_isLoggedIn(false)
|
||||
, m_uId(-1)
|
||||
, m_strBackground(DEFAULT_BACKGROUND_PATH)
|
||||
, m_strLang(qgetenv("LANG"))
|
||||
|
@ -29,7 +36,8 @@ UserInfo::UserInfo()
|
|||
}
|
||||
|
||||
UserInfo::UserInfo(const UserInfo &userInfo)
|
||||
: m_isLoggedIn(userInfo.m_isLoggedIn)
|
||||
: QObject(userInfo.parent())
|
||||
, m_isLoggedIn(userInfo.m_isLoggedIn)
|
||||
, m_uId(userInfo.m_uId)
|
||||
, m_strHeadImage(userInfo.m_strHeadImage)
|
||||
, m_strFullName(userInfo.m_strFullName)
|
||||
|
@ -50,23 +58,13 @@ bool UserInfo::operator==(const UserInfo &userInfo) const
|
|||
return userInfo.uid() == m_uId && userInfo.name() == m_strName;
|
||||
}
|
||||
|
||||
UserInfo& UserInfo::operator=(const UserInfo &userInfo)
|
||||
{
|
||||
if (this == &userInfo) return *this;
|
||||
|
||||
updateLoggedIn(userInfo.isLoggedIn());
|
||||
updateUid(userInfo.uid());
|
||||
updateHeadImage(userInfo.headImage());
|
||||
updateFullName(userInfo.fullName());
|
||||
updateBackground(userInfo.backGround());
|
||||
updateLang(userInfo.lang());
|
||||
updateName(userInfo.name());
|
||||
return *this;
|
||||
}
|
||||
|
||||
void UserInfo::updateLoggedIn(const bool &isLoggedIn)
|
||||
{
|
||||
if (isLoggedIn == m_isLoggedIn) {
|
||||
return ;
|
||||
}
|
||||
m_isLoggedIn = isLoggedIn;
|
||||
Q_EMIT userPropChanged(m_strName);
|
||||
}
|
||||
|
||||
void UserInfo::updateUid(const uid_t &id)
|
||||
|
@ -112,3 +110,174 @@ QDebug operator <<(QDebug stream, const UserInfo &userInfo)
|
|||
<< "]";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
LocalUserInfo::LocalUserInfo(const uid_t &uId, QObject* parent)
|
||||
: UserInfo(parent)
|
||||
, m_strPath("/org/freedesktop/Accounts/User" + QString::number(uId))
|
||||
{
|
||||
initData();
|
||||
initConnections();
|
||||
}
|
||||
|
||||
LocalUserInfo::LocalUserInfo(const QString &strPath, QObject* parent)
|
||||
: UserInfo(parent)
|
||||
, m_strPath(strPath)
|
||||
{
|
||||
initData();
|
||||
initConnections();
|
||||
}
|
||||
|
||||
LocalUserInfo::LocalUserInfo(const LocalUserInfo &localUser)
|
||||
: UserInfo(localUser)
|
||||
, m_strPath(localUser.path())
|
||||
{
|
||||
if (m_strPath.isEmpty()) {
|
||||
m_strPath = QString("/org/freedesktop/Accounts/User" + QString::number(localUser.uid()));
|
||||
}
|
||||
initConnections();
|
||||
}
|
||||
|
||||
LocalUserInfo::~LocalUserInfo()
|
||||
{
|
||||
if (m_propertiesChangedConnected) {
|
||||
QDBusConnection::systemBus().disconnect(ACCOUNTS_DBUS_SERVICE,
|
||||
m_strPath,
|
||||
FD_PROPERTIES_INTERFACE,
|
||||
"PropertiesChanged",
|
||||
this,
|
||||
SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
|
||||
m_propertiesChangedConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LocalUserInfo::initData()
|
||||
{
|
||||
QDBusInterface ifaceExtra(ACCOUNTS_DBUS_SERVICE, m_strPath, FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
QDBusMessage ret = ifaceExtra.call("GetAll", ACCOUNTS_USER_LDM_SERVICE_INTERFACE);
|
||||
QList<QVariant> outArgs = ret.arguments();
|
||||
QVariant first = outArgs.at(0);
|
||||
const QDBusArgument &dbusArgsExtra = first.value<QDBusArgument>();
|
||||
dbusArgsExtra.beginMap();
|
||||
while(!dbusArgsExtra.atEnd()) {
|
||||
QString key;
|
||||
QVariant value;
|
||||
dbusArgsExtra.beginMapEntry();
|
||||
dbusArgsExtra >> key >> value;
|
||||
if(key == "BackgroundFile") {
|
||||
QString strBackground = value.toString();
|
||||
if(strBackground.isEmpty() || !QFile(strBackground).exists() || !QFile(strBackground).size()) {
|
||||
m_strBackground = DEFAULT_BACKGROUND_PATH;
|
||||
} else {
|
||||
m_strBackground = strBackground;
|
||||
}
|
||||
}
|
||||
dbusArgsExtra.endMapEntry();
|
||||
}
|
||||
dbusArgsExtra.endMap();
|
||||
|
||||
QDBusInterface iface(ACCOUNTS_DBUS_SERVICE, m_strPath, FD_PROPERTIES_INTERFACE, QDBusConnection::systemBus());
|
||||
ret = iface.call("GetAll", ACCOUNTS_USER_DBUS_INTERFACE);
|
||||
outArgs = ret.arguments();
|
||||
first = outArgs.at(0);
|
||||
const QDBusArgument &dbusArgs = first.value<QDBusArgument>();
|
||||
dbusArgs.beginMap();
|
||||
while(!dbusArgs.atEnd()) {
|
||||
QString key;
|
||||
QVariant value;
|
||||
dbusArgs.beginMapEntry();
|
||||
dbusArgs >> key >> value;
|
||||
if(key == "UserName") {
|
||||
m_strName = value.toString();
|
||||
} else if(key == "RealName") {
|
||||
m_strFullName = value.toString();
|
||||
} else if(key == "IconFile") {
|
||||
QString strHeadImage = value.toString();
|
||||
if(strHeadImage.isEmpty() || !QFile(strHeadImage).exists() || !QFile(strHeadImage).size()) {
|
||||
m_strHeadImage = getDefaultFace();
|
||||
} else {
|
||||
m_strHeadImage = strHeadImage;
|
||||
}
|
||||
} else if(key == "Uid") {
|
||||
m_uId = value.toUInt();
|
||||
} else if(key == "Language") {
|
||||
m_strLang = value.toString();
|
||||
} else if (key == "BackgroundFile") {
|
||||
QString strBackground = value.toString();
|
||||
if(!strBackground.isEmpty() && QFile(strBackground).exists() && QFile(strBackground).size()) {
|
||||
m_strBackground = strBackground;
|
||||
}
|
||||
}
|
||||
dbusArgs.endMapEntry();
|
||||
}
|
||||
dbusArgs.endMap();
|
||||
if(m_strFullName.isEmpty()) {
|
||||
m_strFullName = m_strName;
|
||||
}
|
||||
}
|
||||
|
||||
void LocalUserInfo::initConnections()
|
||||
{
|
||||
if (!m_propertiesChangedConnected) {
|
||||
QDBusConnection::systemBus().connect(ACCOUNTS_DBUS_SERVICE,
|
||||
m_strPath,
|
||||
FD_PROPERTIES_INTERFACE,
|
||||
"PropertiesChanged",
|
||||
this,
|
||||
SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
|
||||
m_propertiesChangedConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LocalUserInfo::onPropertiesChanged(const QString& interfaceName,
|
||||
const QVariantMap& changedProperties,
|
||||
const QStringList& invalidatedProperties)
|
||||
{
|
||||
Q_UNUSED(invalidatedProperties);
|
||||
if (interfaceName == ACCOUNTS_USER_DBUS_INTERFACE) {
|
||||
QVariantMap::const_iterator itVar = changedProperties.constBegin();
|
||||
for ( ; itVar != changedProperties.constEnd(); itVar++) {
|
||||
QVariant varValue = itVar.value();
|
||||
if(itVar.key() == "UserName") {
|
||||
m_strName = varValue.toString();
|
||||
} else if(itVar.key() == "RealName") {
|
||||
m_strFullName = varValue.toString();
|
||||
} else if(itVar.key() == "IconFile") {
|
||||
QString strHeadImage = varValue.toString();
|
||||
if(strHeadImage.isEmpty() || !QFile(strHeadImage).exists() || !QFile(strHeadImage).size()) {
|
||||
m_strHeadImage = getDefaultFace();
|
||||
} else {
|
||||
m_strHeadImage = strHeadImage;
|
||||
}
|
||||
} else if(itVar.key() == "Uid") {
|
||||
m_uId = varValue.toUInt();
|
||||
} else if(itVar.key() == "Language") {
|
||||
m_strLang = varValue.toString();
|
||||
} else if (itVar.key() == "BackgroundFile") {
|
||||
QString strBackground = varValue.toString();
|
||||
if(!strBackground.isEmpty() && QFile(strBackground).exists() && QFile(strBackground).size()) {
|
||||
m_strBackground = strBackground;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_strFullName.isEmpty()) {
|
||||
m_strFullName = m_strName;
|
||||
}
|
||||
Q_EMIT userPropChanged(m_strName);
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator <<(QDebug stream, const LocalUserInfo &userInfo)
|
||||
{
|
||||
stream << "["
|
||||
<< userInfo.path()
|
||||
<< userInfo.uid()
|
||||
<< userInfo.name()
|
||||
<< userInfo.fullName()
|
||||
<< userInfo.headImage()
|
||||
<< userInfo.backGround()
|
||||
<< userInfo.isLoggedIn()
|
||||
<< userInfo.lang()
|
||||
<< "]";
|
||||
return stream;
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@
|
|||
#include <memory>
|
||||
#include <QDebug>
|
||||
|
||||
class UserInfo
|
||||
class UserInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UserInfo();
|
||||
UserInfo(const UserInfo &userInfo);
|
||||
explicit UserInfo(QObject *parent = nullptr);
|
||||
explicit UserInfo(const UserInfo &userInfo);
|
||||
virtual ~UserInfo();
|
||||
|
||||
bool operator==(const UserInfo &userInfo) const;
|
||||
UserInfo& operator=(const UserInfo &userInfo);
|
||||
|
||||
public:
|
||||
inline bool isLoggedIn() const { return m_isLoggedIn; }
|
||||
|
@ -41,6 +41,9 @@ public:
|
|||
inline QString lang() const { return m_strLang; }
|
||||
inline QString name() const { return m_strName; }
|
||||
|
||||
virtual inline QString path() const { return QString(); }
|
||||
|
||||
public:
|
||||
void updateLoggedIn(const bool &isLoggedIn);
|
||||
void updateUid(const uid_t &id);
|
||||
void updateHeadImage(const QString &path);
|
||||
|
@ -49,6 +52,9 @@ public:
|
|||
void updateLang(const QString &lang);
|
||||
void updateName(const QString &name);
|
||||
|
||||
Q_SIGNALS:
|
||||
void userPropChanged(const QString &userName);
|
||||
|
||||
protected:
|
||||
bool m_isLoggedIn; // 是否已登录
|
||||
uid_t m_uId; // 用户 uid
|
||||
|
@ -63,4 +69,32 @@ typedef std::shared_ptr<UserInfo> UserInfoPtr;
|
|||
|
||||
QDebug operator <<(QDebug stream, const UserInfo &userInfo);
|
||||
|
||||
class LocalUserInfo : public UserInfo
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LocalUserInfo(const uid_t &uId, QObject* parent = nullptr);
|
||||
explicit LocalUserInfo(const QString &strPath, QObject* parent = nullptr);
|
||||
explicit LocalUserInfo(const LocalUserInfo &localUser);
|
||||
|
||||
virtual ~LocalUserInfo();
|
||||
|
||||
inline QString path() const override { return m_strPath; }
|
||||
|
||||
private:
|
||||
void initData();
|
||||
void initConnections();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPropertiesChanged(const QString&, const QVariantMap&, const QStringList&);
|
||||
|
||||
private:
|
||||
QString m_strPath;
|
||||
bool m_propertiesChangedConnected = false;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<LocalUserInfo> LocalUserInfoPtr;
|
||||
|
||||
QDebug operator <<(QDebug stream, const LocalUserInfo &userInfo);
|
||||
|
||||
#endif // USERINFO_H
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "../lock-dialog/pam-tally.h"
|
||||
#include "global_utils.h"
|
||||
|
||||
AuthDialog::AuthDialog(LockDialogModel *model, UserInfo userInfo, QWidget *parent)
|
||||
AuthDialog::AuthDialog(LockDialogModel *model, UserInfoPtr userInfo, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_modelLockDialog(model)
|
||||
, m_isLockingFlg(false)
|
||||
|
@ -336,21 +336,21 @@ void AuthDialog::initLoginoptionWidget()
|
|||
|
||||
void AuthDialog::updateUI()
|
||||
{
|
||||
QPixmap p(m_curUserInfo.headImage());
|
||||
QPixmap p(m_curUserInfo->headImage());
|
||||
QPixmap userIcon = scaledPixmap(p);
|
||||
userIcon = userIcon.scaled(154*scale, 154*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
userIcon = PixmapToRound(userIcon, 77*scale);
|
||||
m_labelHeadImg->setPixmap(userIcon);
|
||||
|
||||
m_nameLabel->setText(m_curUserInfo.fullName());
|
||||
m_nameLabel->setText(m_curUserInfo->fullName());
|
||||
|
||||
m_fRetryButton->setStyleSheet(QString("QPushButton{border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,10%);}"
|
||||
"QPushButton::hover{background-color: rgb(255,255,255,30%);}"
|
||||
"QPushButton::pressed {background-color: rgba(255,255,255,40%);}").arg((int)(77*scale)));
|
||||
m_fRetryButton->setFixedSize(154*scale, 154*scale);
|
||||
m_fRetryButton->setIconSize(QSize(48*scale, 48*scale));
|
||||
qDebug()<<"AuthDialog updateUI:"<<isGreeterMode() << ","<<m_curUserInfo.isLoggedIn();
|
||||
if (!isGreeterMode() && m_curUserInfo.isLoggedIn()) {
|
||||
qDebug()<<"AuthDialog updateUI:"<<isGreeterMode() << ","<<m_curUserInfo->isLoggedIn();
|
||||
if (!isGreeterMode() && m_curUserInfo->isLoggedIn()) {
|
||||
QPixmap iconLogin = QIcon::fromTheme("system-lock-screen-symbolic").pixmap(12,12);
|
||||
iconLogin = drawSymbolicColoredPixmap(iconLogin, "white");
|
||||
if (m_passwordEdit) {
|
||||
|
@ -530,7 +530,7 @@ void AuthDialog::switchLoginOptType(unsigned uLoginOptType, bool faceBtnClicked)
|
|||
return;
|
||||
}
|
||||
|
||||
if (uLoginOptType != m_uCurLoginOptType || (m_deviceInfo && m_deviceInfo->id != m_nLastDeviceId) || m_curUserInfo.name() != m_lastUserName) {
|
||||
if (uLoginOptType != m_uCurLoginOptType || (m_deviceInfo && m_deviceInfo->id != m_nLastDeviceId) || m_curUserInfo->name() != m_lastUserName) {
|
||||
clearMessage();
|
||||
switch(uLoginOptType) {
|
||||
case LOGINOPT_TYPE_PASSWORD:
|
||||
|
@ -591,7 +591,7 @@ void AuthDialog::switchLoginOptType(unsigned uLoginOptType, bool faceBtnClicked)
|
|||
m_nLastDeviceId = -1;
|
||||
}
|
||||
|
||||
m_lastUserName = m_curUserInfo.name();
|
||||
m_lastUserName = m_curUserInfo->name();
|
||||
m_uCurLoginOptType = uLoginOptType;
|
||||
}
|
||||
|
||||
|
@ -695,7 +695,7 @@ void AuthDialog::onRespondUkey(const QString &text)
|
|||
{
|
||||
if (m_loginOpts && m_deviceInfo){
|
||||
m_loginOpts->SetExtraInfo(text,"pincode");
|
||||
m_loginOpts->startAuth(m_deviceInfo, m_curUserInfo.uid());
|
||||
m_loginOpts->startAuth(m_deviceInfo, m_curUserInfo->uid());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,11 +913,11 @@ void AuthDialog::onPamShowPrompt(QString strPrompt, int nType)
|
|||
|
||||
void AuthDialog::onPamAuthCompleted()
|
||||
{
|
||||
if (m_curUserInfo.name().isEmpty())
|
||||
if (m_curUserInfo->name().isEmpty())
|
||||
return ;
|
||||
m_passwordEdit->stopWaiting();
|
||||
bool isAuthenticated = (Q_EMIT m_modelLockDialog->pamIsAuthenticated());
|
||||
qDebug()<<"onPamAuthCompleted:"<<isAuthenticated<<m_curUserInfo.name();
|
||||
qDebug()<<"onPamAuthCompleted:"<<isAuthenticated<<m_curUserInfo->name();
|
||||
if(isAuthenticated) {
|
||||
if((m_bRecvPrompt && !m_bHasUnacknowledgedMsg ) || m_bDirectLogin) {
|
||||
m_bDirectLogin = false;
|
||||
|
@ -926,12 +926,12 @@ void AuthDialog::onPamAuthCompleted()
|
|||
m_passwordEdit->readOnly(false);
|
||||
m_passwordEdit->clear();
|
||||
clearMessage();
|
||||
m_failMap.remove(m_curUserInfo.uid());
|
||||
m_failMap.remove(m_curUserInfo->uid());
|
||||
setLoginTypeTip("");
|
||||
setUkeyTypeTip("");
|
||||
authMode = UNKNOWN;
|
||||
m_uCurLoginOptType = LOGINOPT_TYPE_PASSWORD;
|
||||
Q_EMIT authSucceed(m_curUserInfo.name());
|
||||
Q_EMIT authSucceed(m_curUserInfo->name());
|
||||
|
||||
} else {
|
||||
qDebug()<<"m_bRecvPrompt = "<<m_bRecvPrompt<<" m_bHasUnacknowledgedMsg = "<<m_bHasUnacknowledgedMsg;
|
||||
|
@ -989,17 +989,17 @@ void AuthDialog::onRespond(const QString &strRes)
|
|||
qInfo()<<"Wait for input passwd!";
|
||||
return;
|
||||
}
|
||||
if (m_curUserInfo.name().isEmpty()) {
|
||||
if (m_curUserInfo->name().isEmpty()) {
|
||||
qInfo()<<"No user be selected!!";
|
||||
return ;
|
||||
}
|
||||
m_bHasUnacknowledgedMsg = false;
|
||||
clearMessage();
|
||||
|
||||
qDebug()<<"onRespond:"<<m_curUserInfo.name();
|
||||
if(m_curUserInfo.name() == "*guest"){
|
||||
Q_EMIT m_modelLockDialog->pamAuthenticate(m_curUserInfo.name());
|
||||
} else if(m_curUserInfo.name() == "*login") { //用户输入用户名
|
||||
qDebug()<<"onRespond:"<<m_curUserInfo->name();
|
||||
if(m_curUserInfo->name() == "*guest"){
|
||||
Q_EMIT m_modelLockDialog->pamAuthenticate(m_curUserInfo->name());
|
||||
} else if(m_curUserInfo->name() == "*login") { //用户输入用户名
|
||||
m_isManual = true;
|
||||
m_isNameLogin = true;
|
||||
|
||||
|
@ -1021,19 +1021,19 @@ void AuthDialog::onRespond(const QString &strRes)
|
|||
|
||||
void AuthDialog::startAuth()
|
||||
{
|
||||
if (!m_curUserInfo.name().isEmpty()) {
|
||||
if (!m_curUserInfo->name().isEmpty()) {
|
||||
m_bRecvPrompt = false;
|
||||
m_bHasUnacknowledgedMsg = false;
|
||||
//用户认证
|
||||
if(m_curUserInfo.name() == "*guest") { //游客登录
|
||||
if(m_curUserInfo->name() == "*guest") { //游客登录
|
||||
qDebug() << "guest login";
|
||||
m_passwordEdit->show();
|
||||
m_passwordEdit->setPrompt(tr("login"));
|
||||
} else if(m_curUserInfo.name() == "*login") { //手动输入用户名
|
||||
} else if(m_curUserInfo->name() == "*login") { //手动输入用户名
|
||||
Q_EMIT m_modelLockDialog->pamAuthenticate("");
|
||||
} else {
|
||||
qDebug() << "login: " << m_curUserInfo.name();
|
||||
Q_EMIT m_modelLockDialog->pamAuthenticate(m_curUserInfo.name());
|
||||
qDebug() << "login: " << m_curUserInfo->name();
|
||||
Q_EMIT m_modelLockDialog->pamAuthenticate(m_curUserInfo->name());
|
||||
m_passwordEdit->clear();
|
||||
m_passwordEdit->readOnly(true);
|
||||
}
|
||||
|
@ -1053,15 +1053,15 @@ void AuthDialog::stopAuth()
|
|||
clearMessage();
|
||||
}
|
||||
|
||||
void AuthDialog::onCurUserInfoChanged(const UserInfo &userInfo)
|
||||
void AuthDialog::onCurUserInfoChanged(UserInfoPtr userInfo)
|
||||
{
|
||||
if (m_curUserInfo.uid() > -1 && userInfo.uid() == m_curUserInfo.uid()) {
|
||||
if (m_curUserInfo->uid() > -1 && userInfo->uid() == m_curUserInfo->uid()) {
|
||||
m_curUserInfo = userInfo;
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
void AuthDialog::onCurUserChanged(const UserInfo &userInfo)
|
||||
void AuthDialog::onCurUserChanged(UserInfoPtr userInfo)
|
||||
{
|
||||
if(m_loginOpts){
|
||||
m_loginOpts->stopAuth();
|
||||
|
@ -1121,13 +1121,13 @@ void AuthDialog::onMessageButtonClicked()
|
|||
m_passwordEdit->clear();
|
||||
clearMessage();
|
||||
|
||||
m_failMap.remove(m_curUserInfo.uid());
|
||||
m_failMap.remove(m_curUserInfo->uid());
|
||||
setLoginTypeTip("");
|
||||
setUkeyTypeTip("");
|
||||
authMode = UNKNOWN;
|
||||
m_uCurLoginOptType = LOGINOPT_TYPE_PASSWORD;
|
||||
|
||||
Q_EMIT authSucceed(m_curUserInfo.name());
|
||||
Q_EMIT authSucceed(m_curUserInfo->name());
|
||||
} else {
|
||||
m_messageButton->hide();
|
||||
m_messageLabel->setText("");
|
||||
|
@ -1145,14 +1145,14 @@ void AuthDialog::clearMessage()
|
|||
|
||||
bool AuthDialog::unlockUserTimer()
|
||||
{
|
||||
if (m_curUserInfo.name().isEmpty())
|
||||
if (m_curUserInfo->name().isEmpty())
|
||||
return false;
|
||||
int failed_count = 0;
|
||||
int time_left = 0;
|
||||
int deny = 0;
|
||||
int fail_time =0;
|
||||
int unlock_time = 0;
|
||||
QString curUserName = m_curUserInfo.name();
|
||||
QString curUserName = m_curUserInfo->name();
|
||||
|
||||
if (NULL == curUserName.toLatin1().data()) {
|
||||
qDebug() << "get user info failed." ;
|
||||
|
@ -1257,7 +1257,7 @@ void AuthDialog::pamBioSuccess()
|
|||
if(m_deviceInfo && m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){
|
||||
//ukey时不调用ukey认证
|
||||
}else{
|
||||
m_loginOpts->startAuth(m_deviceInfo, m_curUserInfo.uid());
|
||||
m_loginOpts->startAuth(m_deviceInfo, m_curUserInfo->uid());
|
||||
}
|
||||
|
||||
if (m_deviceInfo) {
|
||||
|
@ -1370,10 +1370,10 @@ void AuthDialog::performBiometricAuth()
|
|||
|
||||
//获取默认设备
|
||||
if (m_loginOpts) {
|
||||
if(m_curUserInfo.name() == "*login")
|
||||
if(m_curUserInfo->name() == "*login")
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_strManualLoginName);
|
||||
else
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo.name());
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo->name());
|
||||
|
||||
if (m_isCustomDefault) { // 认证插件配置默认插件认证
|
||||
if (m_loginOpts) {
|
||||
|
@ -1408,7 +1408,7 @@ void AuthDialog::performBiometricAuth()
|
|||
}
|
||||
|
||||
//已经错误超过3次
|
||||
if(m_failMap.contains(m_curUserInfo.uid()) && m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] >= maxFailedTimes)
|
||||
if(m_failMap.contains(m_curUserInfo->uid()) && m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] >= maxFailedTimes)
|
||||
{
|
||||
if (m_deviceInfo->deviceType == UniT_Remote) {
|
||||
setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(getDeviceType_tr(m_deviceInfo->deviceType)));
|
||||
|
@ -1445,11 +1445,11 @@ void AuthDialog::skipBiometricAuth()
|
|||
void AuthDialog::initBiometricWidget()
|
||||
{
|
||||
if(m_loginOpts) {
|
||||
m_loginOpts->setUser(m_curUserInfo.uid());
|
||||
m_loginOpts->setUser(m_curUserInfo->uid());
|
||||
} else {
|
||||
QHBoxLayout *optsLayout = new QHBoxLayout(m_widgetLoginOpts);
|
||||
optsLayout->setContentsMargins(0,0,0,0);
|
||||
m_loginOpts = new LoginOptionsWidget(m_biometricProxy, m_curUserInfo.uid(), m_uniauthService, m_widgetLoginOpts);
|
||||
m_loginOpts = new LoginOptionsWidget(m_biometricProxy, m_curUserInfo->uid(), m_uniauthService, m_widgetLoginOpts);
|
||||
optsLayout->addWidget(m_loginOpts);
|
||||
connect(m_loginOpts, &LoginOptionsWidget::authComplete,
|
||||
this, &AuthDialog::onBiometricAuthComplete);
|
||||
|
@ -1463,7 +1463,7 @@ void AuthDialog::initBiometricWidget()
|
|||
this, &AuthDialog::onLoginOptsCount);
|
||||
connect(m_loginOpts, &LoginOptionsWidget::updateAuthMsg,
|
||||
this, &AuthDialog::setLoginMsg);
|
||||
m_loginOpts->setUser(m_curUserInfo.uid());
|
||||
m_loginOpts->setUser(m_curUserInfo->uid());
|
||||
}
|
||||
|
||||
qDebug()<<"OptsCount:"<<m_loginOpts->getLoginOptCount();
|
||||
|
@ -1524,7 +1524,7 @@ void AuthDialog::onLoginOptsCount(unsigned uCount)
|
|||
}
|
||||
|
||||
//获取默认设备
|
||||
if(m_curUserInfo.name() == "*login"){
|
||||
if(m_curUserInfo->name() == "*login"){
|
||||
if(isLoadingUkey){
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_strManualLoginName,UniT_General_Ukey);
|
||||
}else{
|
||||
|
@ -1532,9 +1532,9 @@ void AuthDialog::onLoginOptsCount(unsigned uCount)
|
|||
}
|
||||
} else{
|
||||
if(isLoadingUkey){
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo.name(),UniT_General_Ukey);
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo->name(),UniT_General_Ukey);
|
||||
}else{
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo.name());
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo->name());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1560,7 +1560,7 @@ void AuthDialog::onLoginOptsCount(unsigned uCount)
|
|||
}
|
||||
|
||||
//已经错误超过3次
|
||||
if(m_failMap.contains(m_curUserInfo.uid()) && m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] >= maxFailedTimes)
|
||||
if(m_failMap.contains(m_curUserInfo->uid()) && m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] >= maxFailedTimes)
|
||||
{
|
||||
if (m_deviceInfo->deviceType == UniT_Remote) {
|
||||
setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(getDeviceType_tr(m_deviceInfo->deviceType)));
|
||||
|
@ -1641,7 +1641,7 @@ void AuthDialog::onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr
|
|||
|
||||
if(deviceInfo)
|
||||
qDebug() << "device changed: " << *deviceInfo;
|
||||
if(deviceInfo && m_failMap[m_curUserInfo.uid()][deviceInfo->id] >= maxFailedTimes){
|
||||
if(deviceInfo && m_failMap[m_curUserInfo->uid()][deviceInfo->id] >= maxFailedTimes){
|
||||
qDebug() << "Failed MAX!!";
|
||||
return ;
|
||||
}
|
||||
|
@ -1691,18 +1691,18 @@ void AuthDialog::onBiometricAuthComplete(bool result, int nStatus)
|
|||
return;
|
||||
} else if (nStatus >= 2 && nStatus != 5){
|
||||
if (m_deviceInfo) {
|
||||
if(m_failMap.contains(m_curUserInfo.uid()) && m_failMap[m_curUserInfo.uid()].contains(m_deviceInfo->id)){
|
||||
m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] = m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] + 1;
|
||||
if(m_failMap.contains(m_curUserInfo->uid()) && m_failMap[m_curUserInfo->uid()].contains(m_deviceInfo->id)){
|
||||
m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] = m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] + 1;
|
||||
}else{
|
||||
m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] = 1;
|
||||
m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] = 1;
|
||||
}
|
||||
qDebug()<<"Failed count:"<<m_failMap[m_curUserInfo.uid()][m_deviceInfo->id]<<",Max:"<<maxFailedTimes;
|
||||
qDebug()<<"Failed count:"<<m_failMap[m_curUserInfo->uid()][m_deviceInfo->id]<<",Max:"<<maxFailedTimes;
|
||||
if (m_deviceInfo->deviceType == BioT_Face) {
|
||||
QImage imgFailed;
|
||||
setFaceImg(imgFailed, 1);
|
||||
m_fTimeoutTimes = 0;
|
||||
}
|
||||
if(m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] >= maxFailedTimes){
|
||||
if(m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] >= maxFailedTimes){
|
||||
if (m_deviceInfo->deviceType == UniT_Remote) {
|
||||
setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(getDeviceType_tr(m_deviceInfo->deviceType)));
|
||||
QImage nullImage;
|
||||
|
@ -1725,11 +1725,11 @@ void AuthDialog::onBiometricAuthComplete(bool result, int nStatus)
|
|||
if(m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){
|
||||
setUkeyTypeTip(tr("Failed to verify %1, you still have %2 verification opportunities")
|
||||
.arg(getDeviceType_tr(m_deviceInfo->deviceType))
|
||||
.arg(maxFailedTimes-m_failMap[m_curUserInfo.uid()][m_deviceInfo->id]));
|
||||
.arg(maxFailedTimes-m_failMap[m_curUserInfo->uid()][m_deviceInfo->id]));
|
||||
}else {
|
||||
setLoginTypeTip(tr("Failed to verify %1, you still have %2 verification opportunities")
|
||||
.arg(getDeviceType_tr(m_deviceInfo->deviceType))
|
||||
.arg(maxFailedTimes-m_failMap[m_curUserInfo.uid()][m_deviceInfo->id]));
|
||||
.arg(maxFailedTimes-m_failMap[m_curUserInfo->uid()][m_deviceInfo->id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1852,10 +1852,10 @@ void AuthDialog::onBiometricDbusChanged(bool bActive)
|
|||
|
||||
//获取默认设备
|
||||
if (m_loginOpts) {
|
||||
if(m_curUserInfo.name() == "*login")
|
||||
if(m_curUserInfo->name() == "*login")
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_strManualLoginName);
|
||||
else
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo.name());
|
||||
m_deviceName = m_loginOpts->getDefaultDevice(m_curUserInfo->name());
|
||||
}
|
||||
qDebug() << m_deviceName;
|
||||
if (m_deviceInfo) {
|
||||
|
@ -1879,7 +1879,7 @@ void AuthDialog::onBiometricDbusChanged(bool bActive)
|
|||
}
|
||||
|
||||
//已经错误超过3次
|
||||
if(m_failMap.contains(m_curUserInfo.uid()) && m_failMap[m_curUserInfo.uid()][m_deviceInfo->id] >= maxFailedTimes) {
|
||||
if(m_failMap.contains(m_curUserInfo->uid()) && m_failMap[m_curUserInfo->uid()][m_deviceInfo->id] >= maxFailedTimes) {
|
||||
if (m_deviceInfo->deviceType == UniT_Remote) {
|
||||
setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(getDeviceType_tr(m_deviceInfo->deviceType)));
|
||||
} else {
|
||||
|
@ -1972,17 +1972,17 @@ QString AuthDialog::onCustomRequest(QString strReqJson)
|
|||
if (reqType == "GetInformations") { // 请求信息
|
||||
QString strType = rootObj.value("Type").toString();
|
||||
if (strType.contains("CurrentUser")) { // 当前用户信息
|
||||
if (m_curUserInfo.uid() >= 0 && !m_curUserInfo.name().isEmpty() && !m_curUserInfo.name().startsWith("*")) {
|
||||
if (m_curUserInfo->uid() >= 0 && !m_curUserInfo->name().isEmpty() && !m_curUserInfo->name().startsWith("*")) {
|
||||
QJsonObject user;
|
||||
user["Name"] = m_curUserInfo.name();
|
||||
user["Id"] = (double)(m_curUserInfo.uid());
|
||||
user["Name"] = m_curUserInfo->name();
|
||||
user["Id"] = (double)(m_curUserInfo->uid());
|
||||
QFile faceFile(m_face);
|
||||
if (!faceFile.exists()) {
|
||||
user["HeadImg"] = m_strDefaultFace;
|
||||
} else {
|
||||
user["HeadImg"] = m_face;
|
||||
}
|
||||
user["RealName"] = m_curUserInfo.fullName();
|
||||
user["RealName"] = m_curUserInfo->fullName();
|
||||
contentObj["CurrentUser"] = user;
|
||||
} else {
|
||||
retObj["Ret"] = -1;
|
||||
|
|
|
@ -25,7 +25,7 @@ class AuthDialog : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AuthDialog(LockDialogModel *model, UserInfo userInfo, QWidget *parent = nullptr);
|
||||
explicit AuthDialog(LockDialogModel *model, UserInfoPtr userInfo, QWidget *parent = nullptr);
|
||||
|
||||
void initUI();
|
||||
void switchLoginOptType(unsigned uLoginOptType,bool faceBtnClicked = false);
|
||||
|
@ -33,8 +33,8 @@ public:
|
|||
public:
|
||||
void startAuth();
|
||||
void stopAuth();
|
||||
void onCurUserChanged(const UserInfo &userInfo);
|
||||
void onCurUserInfoChanged(const UserInfo &userInfo);
|
||||
void onCurUserChanged(UserInfoPtr userInfo);
|
||||
void onCurUserInfoChanged(UserInfoPtr userInfo);
|
||||
|
||||
void updateUI();
|
||||
void updateAuthSize();
|
||||
|
@ -184,7 +184,7 @@ private:
|
|||
|
||||
BioButtonListWidget *bottomListWidget = nullptr;
|
||||
|
||||
UserInfo m_curUserInfo;
|
||||
UserInfoPtr m_curUserInfo;
|
||||
bool m_bRecvPrompt = false;
|
||||
bool m_bHasUnacknowledgedMsg = false;
|
||||
bool m_bDirectLogin = false;
|
||||
|
|
|
@ -46,10 +46,7 @@ LockWidget::LockWidget(LockDialogModel *model, QWidget *parent)
|
|||
, m_modelLockDialog(model)
|
||||
{
|
||||
scale = 1.0;
|
||||
UserInfoPtr ptrUser = m_modelLockDialog->findUserByName(m_modelLockDialog->defaultUserName());
|
||||
if (ptrUser) {
|
||||
m_curUserInfo = *ptrUser;
|
||||
}
|
||||
m_curUserInfo = m_modelLockDialog->findUserByName(m_modelLockDialog->defaultUserName());
|
||||
initUI();
|
||||
initConnections();
|
||||
initUsdMediaKeys();
|
||||
|
@ -194,7 +191,7 @@ void LockWidget::resizeEvent(QResizeEvent *event)
|
|||
m_powerListWidget->move((width() - m_powerListWidget->width())/2, (height() - m_powerListWidget->height())/2 - BOTTOM_MARGIN*scale);
|
||||
|
||||
updateBottomButton();
|
||||
if (m_curUserInfo.isLoggedIn() && m_sessionButton) {
|
||||
if (m_curUserInfo->isLoggedIn() && m_sessionButton) {
|
||||
buttonListWidget->setFixedSize(QSize(48*(buttonListWidget->count() - 1) + buttonListWidget->spacing()*2*(buttonListWidget->count() - 1), 64));
|
||||
} else {
|
||||
buttonListWidget->setFixedSize(QSize(48*buttonListWidget->count() + buttonListWidget->spacing()*2*buttonListWidget->count(), 64));
|
||||
|
@ -386,7 +383,7 @@ void LockWidget::initButtonWidget()
|
|||
buttonListWidget->setItemWidget(m_btnItemSession, m_sessionButton);
|
||||
buttonListWidget->addItem(m_btnItemSession);
|
||||
m_sessionButton->setObjectName("BtnSession");
|
||||
if (m_curUserInfo.isLoggedIn()) {
|
||||
if (m_curUserInfo->isLoggedIn()) {
|
||||
buttonListWidget->setItemHidden(m_btnItemSession, true);
|
||||
} else {
|
||||
buttonListWidget->setItemHidden(m_btnItemSession, false);
|
||||
|
@ -495,7 +492,7 @@ void LockWidget::initButtonWidget()
|
|||
});
|
||||
}
|
||||
|
||||
if (m_curUserInfo.isLoggedIn() && m_sessionButton) {
|
||||
if (m_curUserInfo->isLoggedIn() && m_sessionButton) {
|
||||
buttonListWidget->setFixedSize(QSize(48*(buttonListWidget->count() - 1) + buttonListWidget->spacing()*2*(buttonListWidget->count() - 1), 64));
|
||||
} else {
|
||||
buttonListWidget->setFixedSize(QSize(48*buttonListWidget->count() + buttonListWidget->spacing()*2*buttonListWidget->count(), 64));
|
||||
|
@ -643,9 +640,9 @@ void LockWidget::onUsersInfoChanged()
|
|||
height()- BOTTOM_MARGIN*scale - buttonListWidget->height() - buttonListWidget->spacing()*scale - m_userListWidget->height());
|
||||
}
|
||||
}
|
||||
UserInfoPtr ptrUser = m_modelLockDialog->findUserByName(m_curUserInfo.name());
|
||||
UserInfoPtr ptrUser = m_modelLockDialog->findUserByName(m_curUserInfo->name());
|
||||
if (ptrUser) {
|
||||
m_curUserInfo = *ptrUser;
|
||||
m_curUserInfo = ptrUser;
|
||||
if (authDialog) {
|
||||
authDialog->onCurUserInfoChanged(m_curUserInfo);
|
||||
}
|
||||
|
@ -656,15 +653,15 @@ void LockWidget::onCurUserChanged(const QString &strUserName)
|
|||
{
|
||||
UserInfoPtr ptrUser = m_modelLockDialog->findUserByName(strUserName);
|
||||
if (ptrUser) {
|
||||
m_curUserInfo = *ptrUser;
|
||||
qDebug()<<"CurUserInfo:"<<m_curUserInfo;
|
||||
m_curUserInfo = ptrUser;
|
||||
qDebug()<<"CurUserInfo:"<<*m_curUserInfo;
|
||||
if (isGreeterMode()) {
|
||||
LanguageSetting::instance()->onLanguageChanged(m_curUserInfo.lang());
|
||||
LanguageSetting::instance()->onLanguageChanged(m_curUserInfo->lang());
|
||||
}
|
||||
if (authDialog)
|
||||
authDialog->onCurUserChanged(m_curUserInfo);
|
||||
}
|
||||
if (m_btnItemSession && m_curUserInfo.isLoggedIn()) {
|
||||
if (m_btnItemSession && m_curUserInfo->isLoggedIn()) {
|
||||
buttonListWidget->setItemHidden(m_btnItemSession, true);
|
||||
} else {
|
||||
buttonListWidget->setItemHidden(m_btnItemSession, false);
|
||||
|
|
|
@ -138,7 +138,7 @@ private:
|
|||
|
||||
LockDialogModel *m_modelLockDialog = nullptr;
|
||||
|
||||
UserInfo m_curUserInfo;
|
||||
UserInfoPtr m_curUserInfo;
|
||||
|
||||
AuthDialog *authDialog = nullptr;
|
||||
QTimer *m_timerChkActive = nullptr;
|
||||
|
|
Loading…
Reference in New Issue