-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
51 lines (41 loc) · 1.12 KB
/
mainwindow.cpp
File metadata and controls
51 lines (41 loc) · 1.12 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <adddialog.h>
#include <otpwidget.h>
#include <oath.h>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
oath_init();
// Create timer that triggers the OTP Widgets to update every second
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateOTPWidgets()));
m_timer->start(1000);
}
MainWindow::~MainWindow()
{
oath_done();
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
AddDialog *addDialog = new AddDialog;
// If the user clicked okay
if (addDialog->exec() == QDialog::Accepted) {
OTPWidget *otpWidget = new OTPWidget(this);
otpWidget->setService(addDialog->getService());
otpWidget->setSecret(addDialog->getSecret());
otpWidget->totpGenerate();
ui->otpWidgetsLayout->addWidget(otpWidget);
}
return;
}
void MainWindow::updateOTPWidgets()
{
foreach (OTPWidget *otpWidget, ui->centralWidget->findChildren<OTPWidget*>()) {
otpWidget->updateWidget();
}
}