File indexing completed on 2024-12-22 05:16:04
0001 /* 0002 Copyright 2020 Devin Lin <espidev@gmail.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), which shall 0010 act as a proxy defined in Section 6 of version 3 of the license. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Lesser General Public License for more details. 0016 0017 You should have received a copy of the GNU Lesser General Public 0018 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include "fprintdevice.h" 0022 0023 FprintDevice::FprintDevice(QDBusObjectPath path, QObject *parent) 0024 : QObject(parent) 0025 , m_devicePath(path.path()) 0026 , m_fprintInterface(new NetReactivatedFprintDeviceInterface(QStringLiteral("net.reactivated.Fprint"), path.path(), QDBusConnection::systemBus(), this)) 0027 , m_freedesktopInterface( 0028 new QDBusInterface(QStringLiteral("net.reactivated.Fprint"), path.path(), "org.freedesktop.DBus.Properties", QDBusConnection::systemBus(), this)) 0029 { 0030 connect(m_fprintInterface, &NetReactivatedFprintDeviceInterface::EnrollStatus, this, &FprintDevice::enrollStatus); 0031 } 0032 0033 QDBusPendingReply<QStringList> FprintDevice::listEnrolledFingers(const QString &username) 0034 { 0035 return m_fprintInterface->ListEnrolledFingers(username); 0036 } 0037 0038 QDBusError FprintDevice::claim(const QString &username) 0039 { 0040 auto reply = m_fprintInterface->Claim(username); 0041 reply.waitForFinished(); 0042 return reply.error(); 0043 } 0044 0045 QDBusError FprintDevice::release() 0046 { 0047 auto reply = m_fprintInterface->Release(); 0048 reply.waitForFinished(); 0049 return reply.error(); 0050 } 0051 0052 QDBusError FprintDevice::deleteEnrolledFingers() 0053 { 0054 auto reply = m_fprintInterface->DeleteEnrolledFingers2(); 0055 reply.waitForFinished(); 0056 return reply.error(); 0057 } 0058 0059 QDBusError FprintDevice::deleteEnrolledFinger(QString &finger) 0060 { 0061 auto reply = m_fprintInterface->DeleteEnrolledFinger(finger); 0062 reply.waitForFinished(); 0063 return reply.error(); 0064 } 0065 0066 QDBusError FprintDevice::startEnrolling(const QString &finger) 0067 { 0068 auto reply = m_fprintInterface->EnrollStart(finger); 0069 reply.waitForFinished(); 0070 return reply.error(); 0071 } 0072 0073 QDBusError FprintDevice::stopEnrolling() 0074 { 0075 auto reply = m_fprintInterface->EnrollStop(); 0076 reply.waitForFinished(); 0077 return reply.error(); 0078 } 0079 0080 void FprintDevice::enrollStatus(QString result, bool done) 0081 { 0082 Q_UNUSED(done) 0083 0084 if (result == "enroll-completed") { 0085 Q_EMIT enrollCompleted(); 0086 } else if (result == "enroll-failed" || result == "enroll-data-full" || result == "enroll-disconnected" || result == "enroll-unknown-error") { 0087 Q_EMIT enrollFailed(result); 0088 } else if (result == "enroll-stage-passed") { 0089 Q_EMIT enrollStagePassed(); 0090 } else if (result == "enroll-retry-scan" || result == "enroll-swipe-too-short" || result == "enroll-finger-not-centered" 0091 || result == "enroll-remove-and-retry") { 0092 Q_EMIT enrollRetryStage(result); 0093 } 0094 } 0095 0096 int FprintDevice::numOfEnrollStages() 0097 { 0098 QDBusReply<QDBusVariant> reply = m_freedesktopInterface->call("Get", "net.reactivated.Fprint.Device", "num-enroll-stages"); 0099 if (!reply.isValid()) { 0100 qDebug() << "error fetching num-enroll-stages:" << reply.error(); 0101 return 0; 0102 } 0103 return reply.value().variant().toInt(); 0104 } 0105 0106 FprintDevice::ScanType FprintDevice::scanType() 0107 { 0108 QDBusReply<QDBusVariant> reply = m_freedesktopInterface->call("Get", "net.reactivated.Fprint.Device", "scan-type"); 0109 if (!reply.isValid()) { 0110 qDebug() << "error fetching scan-type:" << reply.error(); 0111 return FprintDevice::Press; 0112 } 0113 0114 const QString type = reply.value().variant().toString(); 0115 0116 if (type == QLatin1String("press")) { 0117 return FprintDevice::Press; 0118 } 0119 0120 if (type == QLatin1String("swipe")) { 0121 return FprintDevice::Swipe; 0122 } 0123 0124 qWarning() << "Unknown fprint scan-type:" << type; 0125 0126 return FprintDevice::Press; 0127 } 0128 0129 bool FprintDevice::fingerPresent() 0130 { 0131 QDBusReply<QDBusVariant> reply = m_freedesktopInterface->call("Get", "net.reactivated.Fprint.Device", "finger-present"); 0132 if (!reply.isValid()) { 0133 qDebug() << "error fetching finger-present:" << reply.error(); 0134 return ""; 0135 } 0136 return reply.value().variant().toBool(); 0137 } 0138 0139 bool FprintDevice::fingerNeeded() 0140 { 0141 QDBusReply<QDBusVariant> reply = m_freedesktopInterface->call("Get", "net.reactivated.Fprint.Device", "finger-needed"); 0142 if (!reply.isValid()) { 0143 qDebug() << "error fetching finger-needed:" << reply.error(); 0144 return ""; 0145 } 0146 return reply.value().variant().toBool(); 0147 }