6 #include "FingerNames.h"
8 void FMEnroll::getIface() {
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)));
22 * FMEnroll constructor
24 FMEnroll::FMEnroll(DeviceModel device
, QString login
, int finger
, QWidget
*parent
) :
25 KDialog(parent
), finger_(finger
), device_(device
), actualStage(0),
27 // Modal dialog, only Cancel button, precedent by separator
29 showButtonSeparator(true);
30 setButtons(KDialog::Cancel
);
33 dbc
= FMDbusConn::getConn();
36 // Init and traslate UI components
37 initComponents(enrollStages
);
39 setMainWidget(mainPanel
);
40 QObject::connect(timer
, SIGNAL(timeout()), this, SLOT(timeout()));
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()) {
64 if (!dbc
->isDeviceClaimed()) {
65 actualStatus
->setText(i18n("Error while claiming device."));
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();
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() {
93 setWindowTitle(i18n("Enrolling finger..."));
96 setWhatsThis(i18n("Enroll finger window"));
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..."));
112 void FMEnroll::setStatusMessage(QString result
) {
114 bool checked
= false;
115 if (result
== "enroll-stage-passed") {
117 actualStatus
->setText(i18n("Stage passed"));
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
);
132 timer
->start(timeout
);
139 void FMEnroll::enrollStatus(QString result
, bool done
) {
140 qDebug() << "enrollStatus:" << result
<< ", done: " << done
;
143 if (result
== "enroll-completed") {
144 actualStatus
->setText(i18n("Enroll completed"));
145 stages
[actualStage
]->setChecked(true);
146 setButtons(KDialog::Ok
);
148 } else if (result
== "enroll-disconnected") {
149 actualStatus
->setText(i18n("Device disconected. Fingerprint is not enrolled."));
151 dbc
->releaseDevice();
152 } else if (result
== "enroll-failed") {
153 actualStatus
->setText(i18n("Enroll failed."));
155 } else if (result
== "enroll-unknown-error") {
156 actualStatus
->setText(i18n("Unknown error."));
160 } else setStatusMessage(result
);
163 void FMEnroll::timeout() {
164 // Create actual status message
166 if (scanType
== "swipe") {
167 msg
= QString(i18n("Swipe your \"%1\" on \"%2\""));
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();
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
;
186 for (int i
= 0; i
< enrollStages
; i
++) {
187 if (stages
[i
]) delete stages
[i
];
191 if (animLabel
) delete animLabel
;
192 if (stagesLayout
) delete stagesLayout
;
193 if (mainLayout
) delete mainLayout
;
194 if (mainPanel
) delete mainPanel
;
197 dbc
->releaseDevice();