Added animation for swipe sensor.
[KFingerManager.git] / src / FMEnroll.cpp
blobb9e7e5f38e8910cfc746d90905ce0c740ef14185
1 #include <KLocale>
2 #include <QtCore>
3 #include <QFont>
5 #include "FMEnroll.h"
6 #include "FingerNames.h"
8 void FMEnroll::getIface() {
9 enrollStages = 0;
10 dbc->claimDevice(device_.device, login_);
11 if (dbc->isDeviceClaimed()) {
12 enrollStages = dbc->getEnrollStages();
13 scanType = dbc->getScanType();
14 QObject::connect(dbc, SIGNAL(EnrollStatus(QString,bool)),
15 this, SLOT(enrollStatus(QString,bool)));
16 } else {
17 scanType = "";
21 /**
22 * FMEnroll constructor
24 FMEnroll::FMEnroll(DeviceModel device, QString login, int finger, QWidget *parent) :
25 KDialog(parent), finger_(finger), device_(device), actualStage(0),
26 login_(login) {
27 // Modal dialog, only Cancel button, precedent by separator
28 setModal(true);
29 showButtonSeparator(true);
30 setButtons(KDialog::Cancel);
32 // D-Bus connection
33 dbc = FMDbusConn::getConn();
34 getIface();
36 // Init and traslate UI components
37 initComponents(enrollStages);
38 retranslate();
39 setMainWidget(mainPanel);
40 QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
42 // Layout
43 statusLayout->addWidget(statusLabel);
44 statusLayout->addWidget(actualStatus);
45 statusLayout->addStretch();
46 mainLayout->addLayout(statusLayout);
48 stagesLayout->addStretch();
49 for (int i = 0; i < enrollStages; i++) {
50 stagesLayout->addWidget(stages[i]);
52 stagesLayout->addStretch();
53 stagesLayout->addWidget(animLabel);
55 mainLayout->addLayout(stagesLayout);
56 mainPanel->setLayout(mainLayout);
58 setMaximumSize(minimumSizeHint());
59 setMinimumSize(minimumSizeHint());
61 if (!dbc->isDeviceClaimed()) {
62 getIface();
64 if (!dbc->isDeviceClaimed()) {
65 actualStatus->setText(i18n("Error while claiming device."));
66 } else {
67 dbc->enrollStart(fingerNames[finger_].iface);
71 void FMEnroll::initComponents(int enrollStages) {
72 mainPanel = new QWidget();
73 statusLabel = new QLabel();
74 QFont font = statusLabel->font();
75 font.setWeight(QFont::Bold);
76 statusLabel->setFont(font);
77 actualStatus = new QLabel();
78 statusLayout = new QHBoxLayout();
79 stagesLayout = new QHBoxLayout();
80 mainLayout = new QVBoxLayout();
81 timer = new QTimer();
82 timer->setSingleShot(true);
83 animLabel = new SensorAnimLabel(scanType);
85 stages = (EnrollStatus**)malloc(sizeof(EnrollStatus*)*enrollStages);
86 for (int i = 0; i < enrollStages; i++) {
87 stages[i] = new EnrollStatus(this);
91 void FMEnroll::retranslate() {
92 // Set Window Title
93 setWindowTitle(i18n("Enrolling finger..."));
95 // What's this
96 setWhatsThis(i18n("Enroll finger window"));
98 // Set status label
99 statusLabel->setText(i18n("Status")+":");
101 // Set stages tooltips
102 for (int i = 0; i < enrollStages; i++) {
103 QString msg = i18n("Stage %1").arg(i + 1);
104 stages[i]->setToolTip(msg);
105 stages[i]->setWhatsThis(i18n("Current enrollment progess..."));
108 // Status message
109 timeout();
112 void FMEnroll::setStatusMessage(QString result) {
113 int timeout = 2500;
114 bool checked = false;
115 if (result == "enroll-stage-passed") {
116 checked = true;
117 actualStatus->setText(i18n("Stage passed"));
118 timeout = 1250;
119 } else if (result == "enroll-swipe-too-short") {
120 actualStatus->setText(i18n("Swipe too short"));
121 } else if (result == "enroll-finger-not-centered") {
122 actualStatus->setText(i18n("Finger not centered"));
123 } else if (result == "enroll-remove-and-retry") {
124 actualStatus->setText(i18n("Remove and retry"));
125 } else if (result == "enroll-retry-scan") {
126 actualStatus->setText(i18n("Retry scan"));
129 stages[actualStage]->setChecked(checked);
130 animLabel->stop();
132 timer->start(timeout);
134 if (checked) {
135 actualStage++;
139 void FMEnroll::enrollStatus(QString result, bool done) {
140 qDebug() << "enrollStatus:" << result << ", done: " << done;
142 if (done == true) {
143 if (result == "enroll-completed") {
144 actualStatus->setText(i18n("Enroll completed"));
145 stages[actualStage]->setChecked(true);
146 setButtons(KDialog::Ok);
147 dbc->enrollStop();
148 } else if (result == "enroll-disconnected") {
149 actualStatus->setText(i18n("Device disconected. Fingerprint is not enrolled."));
150 dbc->enrollStop();
151 dbc->releaseDevice();
152 } else if (result == "enroll-failed") {
153 actualStatus->setText(i18n("Enroll failed."));
154 dbc->enrollStop();
155 } else if (result == "enroll-unknown-error") {
156 actualStatus->setText(i18n("Unknown error."));
157 dbc->enrollStop();
159 animLabel->stop();
160 } else setStatusMessage(result);
163 void FMEnroll::timeout() {
164 // Create actual status message
165 QString msg;
166 if (scanType == "swipe") {
167 msg = QString(i18n("Swipe your \"%1\" on \"%2\""));
168 } else {
169 msg = QString(i18n("Place your \"%1\" on \"%2\""));
171 msg = msg.arg(i18n(fingerNames[finger_].name), device_.name);
172 actualStatus->setText(msg);
173 stages[actualStage]->clearStatus();
174 animLabel->start();
178 * FMEnroll destructor
180 FMEnroll::~FMEnroll() {
181 qDebug() << "FMEnroll destructor";
182 if (statusLabel) delete statusLabel;
183 if (actualStatus) delete actualStatus;
184 if (statusLayout) delete statusLayout;
185 if (stages) {
186 for (int i = 0; i < enrollStages; i++) {
187 if (stages[i]) delete stages[i];
189 free(stages);
191 if (animLabel) delete animLabel;
192 if (stagesLayout) delete stagesLayout;
193 if (mainLayout) delete mainLayout;
194 if (mainPanel) delete mainPanel;
195 if (dbc) {
196 dbc->enrollStop();
197 dbc->releaseDevice();
198 dbc->releaseConn();