1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/**
* 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 2, 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 "biometricdeviceinfo.h"
#include <QDebug>
#include <QtDBus>
//#include <QDBusAbstractInterface>
QString DeviceType::getDeviceType(int deviceType)
{
if(deviceType >= __MAX_NR_TYPES)
{
return "";
}
QMetaEnum meta = QMetaEnum::fromType<Type>();
const char *typeString = meta.valueToKey(deviceType);
return QString(typeString);
}
QString DeviceType::getDeviceType_tr(int deviceType)
{
switch(deviceType)
{
case FingerPrint:
return tr("FingerPrint");
case FingerVein:
return tr("FingerVein");
case Iris:
return tr("Iris");
case Face:
return tr("Face");
case VoicePrint:
return tr("VoicePrint");
default:
return "";
}
}
QDebug operator <<(QDebug stream, const DeviceInfo &deviceInfo)
{
stream << "["
<< deviceInfo.id
<< deviceInfo.shortName
<< deviceInfo.fullName
<< deviceInfo.deviceType
<< deviceInfo.driverEnable
<< deviceInfo.deviceNum
<< "]";
return stream;
}
QDBusArgument &operator <<(QDBusArgument &arg, const DeviceInfo &deviceInfo)
{
arg.beginStructure();
arg << deviceInfo.id
<< deviceInfo.shortName
<< deviceInfo.fullName
<< deviceInfo.driverEnable
<< deviceInfo.deviceNum
<< deviceInfo.deviceType
<< deviceInfo.storageType
<< deviceInfo.eigType
<< deviceInfo.verifyType
<< deviceInfo.identifyType
<< deviceInfo.busType
<< deviceInfo.deviceStatus
<< deviceInfo.OpsStatus;
arg.endStructure();
return arg;
}
const QDBusArgument &operator >>(const QDBusArgument &arg, DeviceInfo &deviceInfo)
{
arg.beginStructure();
arg >> deviceInfo.id
>> deviceInfo.shortName
>> deviceInfo.fullName
>> deviceInfo.driverEnable
>> deviceInfo.deviceNum
>> deviceInfo.deviceType
>> deviceInfo.storageType
>> deviceInfo.eigType
>> deviceInfo.verifyType
>> deviceInfo.identifyType
>> deviceInfo.busType
>> deviceInfo.deviceStatus
>> deviceInfo.OpsStatus;
arg.endStructure();
return arg;
}
void registerMetaType()
{
qRegisterMetaType<DeviceInfo>("DeviceInfo");
qDBusRegisterMetaType<DeviceInfo>();
}
QString GetDefaultDevice(const QString &userName)
{
//QString configPath = QString("/home/%1/" UKUI_BIOMETRIC_CONFIG_PATH).arg(userName);
QString configPath = QDir::homePath() + "/" + UKUI_BIOMETRIC_CONFIG_PATH;
QSettings settings(configPath, QSettings::IniFormat);
qDebug() << "configure path: " << settings.fileName();
QString defaultDevice = settings.value("DefaultDevice").toString();
if(defaultDevice.isEmpty())
{
QSettings sysSettings(UKUI_BIOMETRIC_SYS_CONFIG_PATH, QSettings::IniFormat);
defaultDevice = sysSettings.value("DefaultDevice").toString();
}
return defaultDevice;
}
static int getValueFromSettings(const QString &userName, const QString &key, int defaultValue = 3)
{
//从家目录下的配置文件中获取
//QString configPath = QString("/home/%1/" UKUI_BIOMETRIC_CONFIG_PATH).arg(userName);
QString configPath = QDir::homePath() + "/" + UKUI_BIOMETRIC_CONFIG_PATH;
QSettings settings(configPath, QSettings::IniFormat);
QString valueStr = settings.value(key).toString();
//如果没有获取到,则从系统配置文件中获取
if(valueStr.isEmpty())
{
QSettings sysSettings(UKUI_BIOMETRIC_SYS_CONFIG_PATH, QSettings::IniFormat);
valueStr = sysSettings.value(key).toString();
}
bool ok;
int value = valueStr.toInt(&ok);
if( (value == 0 && !ok) || valueStr.isEmpty() )
{
value = defaultValue;
}
return value;
}
bool GetHiddenSwitchButton()
{
QSettings sysSettings(UKUI_BIOMETRIC_SYS_CONFIG_PATH, QSettings::IniFormat);
if(sysSettings.contains("HiddenSwitchButton"))
return sysSettings.value("HiddenSwitchButton").toBool();
else
return false;
}
int GetFailedTimes()
{
QSettings sysSettings(UKUI_BIOMETRIC_SYS_CONFIG_PATH, QSettings::IniFormat);
if(sysSettings.contains("MaxFailedTimes"))
return sysSettings.value("MaxFailedTimes").toInt();
else
return 3;
}
int GetMaxFailedAutoRetry(const QString &userName)
{
return getValueFromSettings(userName, "MaxFailedAutoRetry");
}
int GetMaxTimeoutAutoRetry(const QString &userName)
{
return getValueFromSettings(userName, "MaxTimeoutAutoRetry");
}
|