6 #include "FingerNames.h"
9 * getIface - create new D-Bus interface object, reads scan type and number of
12 void FMEnroll::getIface() {
14 dbc
->claimDevice(device_
.device
, login_
);
15 if (dbc
->isDeviceClaimed()) {
16 enrollStages
= dbc
->getEnrollStages();
17 scanType
= dbc
->getScanType();
18 QObject::connect(dbc
, SIGNAL(EnrollStatus(QString
,bool)),
19 this, SLOT(enrollStatus(QString
,bool)));
26 * FMEnroll constructor
27 * @param device device selected
28 * @param login users login
29 * @param finger selected finger
30 * @param parent parent widget
32 FMEnroll::FMEnroll(DeviceModel device
, QString login
, int finger
, QWidget
*parent
) :
33 KDialog(parent
), finger_(finger
), device_(device
), actualStage(0),
35 // Modal dialog, only Cancel button, precedent by separator
37 showButtonSeparator(true);
38 setButtons(KDialog::Cancel
);
41 dbc
= FMDbusConn::getConn();
44 // Init and traslate UI components
45 initComponents(enrollStages
);
47 setMainWidget(mainPanel
);
48 QObject::connect(timer
, SIGNAL(timeout()), this, SLOT(timeout()));
51 statusLayout
->addWidget(statusLabel
);
52 statusLayout
->addWidget(actualStatus
);
53 statusLayout
->addStretch();
54 mainLayout
->addLayout(statusLayout
);
56 stagesLayout
->addStretch();
57 for (int i
= 0; i
< enrollStages
; i
++) {
58 stagesLayout
->addWidget(stages
[i
]);
60 stagesLayout
->addStretch();
61 stagesLayout
->addWidget(animLabel
);
63 mainLayout
->addLayout(stagesLayout
);
64 mainPanel
->setLayout(mainLayout
);
66 setMaximumSize(minimumSizeHint());
67 setMinimumSize(minimumSizeHint());
69 if (!dbc
->isDeviceClaimed()) {
70 actualStatus
->setText(i18n("Error while claiming device."));
72 dbc
->enrollStart(fingerNames
[finger_
].iface
);
77 * initCimponents - init all widgets
78 * @param enrollStages number of enroll stages
80 void FMEnroll::initComponents(int enrollStages
) {
81 mainPanel
= new QWidget();
82 statusLabel
= new QLabel();
83 QFont font
= statusLabel
->font();
84 font
.setWeight(QFont::Bold
);
85 statusLabel
->setFont(font
);
86 actualStatus
= new QLabel();
87 statusLayout
= new QHBoxLayout();
88 stagesLayout
= new QHBoxLayout();
89 mainLayout
= new QVBoxLayout();
91 timer
->setSingleShot(true);
92 animLabel
= new SensorAnimLabel(scanType
);
94 stages
= (EnrollStatus
**)malloc(sizeof(EnrollStatus
*)*enrollStages
);
95 for (int i
= 0; i
< enrollStages
; i
++) {
96 stages
[i
] = new EnrollStatus(this);
101 * retranslate - update all UI strings
103 void FMEnroll::retranslate() {
105 setWindowTitle(i18n("Enrolling finger..."));
108 setWhatsThis(i18n("Enroll finger window"));
111 statusLabel
->setText(i18n("Status")+":");
113 // Set stages tooltips
114 for (int i
= 0; i
< enrollStages
; i
++) {
115 QString msg
= i18n("Stage %1").arg(i
+ 1);
116 stages
[i
]->setToolTip(msg
);
117 stages
[i
]->setWhatsThis(i18n("Current enrollment progess..."));
125 * setStatusMessage - set suitable status message for actual enroll status
126 * @param result actual enroll status
128 void FMEnroll::setStatusMessage(QString result
) {
130 bool checked
= false;
131 if (result
== "enroll-stage-passed") {
133 actualStatus
->setText(i18n("Stage passed"));
135 } else if (result
== "enroll-swipe-too-short") {
136 actualStatus
->setText(i18n("Swipe too short"));
137 } else if (result
== "enroll-finger-not-centered") {
138 actualStatus
->setText(i18n("Finger not centered"));
139 } else if (result
== "enroll-remove-and-retry") {
140 actualStatus
->setText(i18n("Remove and retry"));
141 } else if (result
== "enroll-retry-scan") {
142 actualStatus
->setText(i18n("Retry scan"));
145 stages
[actualStage
]->setChecked(checked
);
148 timer
->start(timeout
);
156 * enrollStatus - Slot for asynchronous enroll signals
157 * @param result actual enroll status
158 * @param done true if enroll process is completed, otherwise false
160 void FMEnroll::enrollStatus(QString result
, bool done
) {
161 qDebug() << "enrollStatus:" << result
<< ", done: " << done
;
164 if (result
== "enroll-completed") {
165 actualStatus
->setText(i18n("Enroll completed"));
166 stages
[actualStage
]->setChecked(true);
167 setButtons(KDialog::Ok
);
169 } else if (result
== "enroll-disconnected") {
170 actualStatus
->setText(i18n("Device disconected. Fingerprint is not enrolled."));
172 dbc
->releaseDevice();
173 } else if (result
== "enroll-failed") {
174 actualStatus
->setText(i18n("Enroll failed."));
176 } else if (result
== "enroll-unknown-error") {
177 actualStatus
->setText(i18n("Unknown error."));
181 } else setStatusMessage(result
);
185 * timeout - handle timeout and set proper message
187 void FMEnroll::timeout() {
188 // Create actual status message
190 if (scanType
== "swipe") {
191 msg
= QString(i18n("Swipe your \"%1\" on \"%2\""));
193 msg
= QString(i18n("Place your \"%1\" on \"%2\""));
195 msg
= msg
.arg(i18n(fingerNames
[finger_
].name
), device_
.name
);
196 actualStatus
->setText(msg
);
197 stages
[actualStage
]->clearStatus();
202 * FMEnroll destructor
204 FMEnroll::~FMEnroll() {
205 qDebug() << "FMEnroll destructor";
206 if (statusLabel
) delete statusLabel
;
207 if (actualStatus
) delete actualStatus
;
208 if (statusLayout
) delete statusLayout
;
210 for (int i
= 0; i
< enrollStages
; i
++) {
211 if (stages
[i
]) delete stages
[i
];
215 if (animLabel
) delete animLabel
;
216 if (stagesLayout
) delete stagesLayout
;
217 if (mainLayout
) delete mainLayout
;
218 if (mainPanel
) delete mainPanel
;
221 dbc
->releaseDevice();