|
|
@ -11,6 +11,9 @@ |
|
|
|
#include <QTimer> |
|
|
|
#include <QScrollArea> |
|
|
|
#include <QLabel> |
|
|
|
#include <QStandardPaths> |
|
|
|
#include <QDir> |
|
|
|
#include <QFileInfo> |
|
|
|
#include "mainwindow.h" |
|
|
|
#include "libcppotp/bytes.h" |
|
|
|
#include "libcppotp/otp.h" |
|
|
@ -25,15 +28,23 @@ extern "C" { |
|
|
|
MainWindow::MainWindow(QWidget *parent) : |
|
|
|
QMainWindow(parent) |
|
|
|
,m_centralWidget(nullptr) |
|
|
|
#ifdef __APPLE__ |
|
|
|
,m_settings(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + qApp->applicationName() + ".ini", QSettings::IniFormat) |
|
|
|
#else |
|
|
|
,m_settings(qApp->applicationName() + ".ini", QSettings::IniFormat) |
|
|
|
#endif |
|
|
|
,m_statusLabel(nullptr) |
|
|
|
,m_timer(new QTimer()) |
|
|
|
{ |
|
|
|
m_settings.setIniCodec("UTF-8"); |
|
|
|
|
|
|
|
#ifdef __APPLE__ |
|
|
|
QFileInfo(m_settings.fileName()).absoluteDir().mkpath("."); |
|
|
|
#endif |
|
|
|
|
|
|
|
if(!m_settings.isWritable()) { |
|
|
|
QMessageBox::critical(0, tr("Error"), tr("Permission denied while trying to write to settings file.")); |
|
|
|
qApp->quit(); |
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -104,7 +115,7 @@ void MainWindow::rebuildLayout() { |
|
|
|
QString name = names.at(i); |
|
|
|
QString key = m_settings.value(name).toString(); |
|
|
|
QString code = generateCode(key); |
|
|
|
|
|
|
|
|
|
|
|
QLabel *label = new QLabel(name + ": " + code, 0); |
|
|
|
codeVBoxLayout->addWidget(label); |
|
|
|
} |
|
|
|