156 lines
6.1 KiB
C++
156 lines
6.1 KiB
C++
#include "DeviceSettingsWindow.h"
|
|
|
|
#include <QVBoxLayout>
|
|
#include <QHeaderView>
|
|
#include <QScrollArea>
|
|
#include <QCoreApplication>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
|
|
#include <QSettings>
|
|
#include "bank/AccountSettingsWindow.h"
|
|
#include "dao/BankProfileDAO.h"
|
|
#include "db/BankProfileInfo.h"
|
|
|
|
static QString formatStatus(const BankProfileInfo &app) {
|
|
if (!app.install) return "не установлен";
|
|
if (app.status == "active") {
|
|
if (!app.pinCodeChecked)
|
|
return app.pinCode.isEmpty() ? "нет пин-код" : "пин-код не проверен";
|
|
return "работает";
|
|
}
|
|
if (app.status == "off") return "выключено";
|
|
return app.status;
|
|
}
|
|
|
|
DeviceSettingsWindow::DeviceSettingsWindow(QWidget *parent, const QString &deviceId, const QString &deviceName)
|
|
: QWidget(parent,
|
|
Qt::Window
|
|
| Qt::WindowTitleHint
|
|
| Qt::WindowSystemMenuHint
|
|
| Qt::WindowCloseButtonHint
|
|
| Qt::WindowMinMaxButtonsHint),
|
|
m_deviceId(deviceId),
|
|
m_deviceName(deviceName) {
|
|
setWindowTitle("Настройки устройства [" + m_deviceName + "]");
|
|
setMinimumSize(600, 300);
|
|
resize(700, 400);
|
|
|
|
auto *mainLayout = new QVBoxLayout(this);
|
|
|
|
auto *scrollArea = new QScrollArea(this);
|
|
scrollArea->setWidgetResizable(true);
|
|
|
|
auto *contentWidget = new QWidget;
|
|
auto *layout = new QVBoxLayout(contentWidget);
|
|
layout->setContentsMargins(4, 4, 4, 4);
|
|
layout->setAlignment(Qt::AlignTop);
|
|
|
|
auto *tableWidget = new QTableWidget(this);
|
|
tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
|
|
tableWidget->setFocusPolicy(Qt::NoFocus);
|
|
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
reloadContent(tableWidget);
|
|
tableWidget->resizeColumnsToContents();
|
|
tableWidget->resizeRowsToContents();
|
|
|
|
layout->addWidget(tableWidget);
|
|
|
|
contentWidget->setLayout(layout);
|
|
scrollArea->setWidget(contentWidget);
|
|
mainLayout->addWidget(scrollArea);
|
|
setLayout(mainLayout);
|
|
}
|
|
|
|
void DeviceSettingsWindow::reloadContent(QTableWidget *tableWidget) {
|
|
QList<BankProfileInfo> apps = BankProfileDAO::getAllApplicationsByDeviceId(m_deviceId);
|
|
|
|
// Дополняем список банками из config.ini, которых нет в БД
|
|
const QSettings configSettings("config.ini", QSettings::IniFormat);
|
|
const QStringList banks = configSettings.value("apps/list").toStringList();
|
|
QSet<QString> existingCodes;
|
|
for (const BankProfileInfo &a : apps) {
|
|
existingCodes.insert(a.code);
|
|
}
|
|
for (const QString &rawBank : banks) {
|
|
const QString bank = rawBank.trimmed();
|
|
if (bank.isEmpty() || existingCodes.contains(bank)) continue;
|
|
BankProfileInfo stub;
|
|
stub.id = -1;
|
|
stub.deviceId = m_deviceId;
|
|
stub.code = bank;
|
|
stub.name = configSettings.value(bank + "/name", bank).toString();
|
|
stub.package = configSettings.value(bank + "/android_package_name").toString();
|
|
stub.currency = configSettings.value(bank + "/currency").toString();
|
|
stub.status = "off";
|
|
stub.install = false;
|
|
apps.append(stub);
|
|
}
|
|
|
|
tableWidget->clearContents();
|
|
tableWidget->setRowCount(apps.size());
|
|
tableWidget->setColumnCount(7);
|
|
tableWidget->setHorizontalHeaderLabels({"", "Приложение", "Пакет", "Валюта", "Статус", "Комментарий", ""});
|
|
|
|
tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
for (int i = 0; i < 7; ++i)
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(5, QHeaderView::Stretch);
|
|
|
|
for (int k = 0; k < apps.size(); ++k) {
|
|
const BankProfileInfo &app = apps[k];
|
|
|
|
// Иконка
|
|
auto *icon = new QLabel(tableWidget);
|
|
QPixmap pixmap(QCoreApplication::applicationDirPath() + "/images/" + app.code + "_icon.png");
|
|
icon->setPixmap(pixmap.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
icon->setStyleSheet("background-color: transparent; padding: 0 4px 0 0;");
|
|
icon->setMinimumSize(24, 20);
|
|
tableWidget->setCellWidget(k, 0, icon);
|
|
|
|
// Название
|
|
auto *nameItem = new QTableWidgetItem(app.name);
|
|
nameItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
tableWidget->setItem(k, 1, nameItem);
|
|
|
|
// Пакет
|
|
auto *packageItem = new QTableWidgetItem(app.package);
|
|
packageItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
tableWidget->setItem(k, 2, packageItem);
|
|
|
|
// Валюта
|
|
auto *currencyItem = new QTableWidgetItem(app.currency);
|
|
currencyItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
tableWidget->setItem(k, 3, currencyItem);
|
|
|
|
// Статус
|
|
auto *statusItem = new QTableWidgetItem(formatStatus(app));
|
|
statusItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
if (app.status != "active" || !app.pinCodeChecked)
|
|
statusItem->setForeground(QBrush(Qt::red));
|
|
else
|
|
statusItem->setForeground(QBrush(Qt::darkGreen));
|
|
tableWidget->setItem(k, 4, statusItem);
|
|
|
|
// Комментарий
|
|
auto *commentItem = new QTableWidgetItem(app.comment);
|
|
commentItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
|
tableWidget->setItem(k, 5, commentItem);
|
|
|
|
// Кнопка "Настроить"
|
|
auto *settingsBtn = new QPushButton("Настроить", tableWidget);
|
|
settingsBtn->setStyleSheet("background-color: green; color: white; border-radius: 4px; height: 26px;");
|
|
tableWidget->setCellWidget(k, 6, settingsBtn);
|
|
|
|
connect(settingsBtn, &QPushButton::clicked, this, [this, app]() {
|
|
auto *window = new AccountSettingsWindow(nullptr, m_deviceId, m_deviceName, app);
|
|
window->setWindowFlags(window->windowFlags() | Qt::Window);
|
|
window->setAttribute(Qt::WA_DeleteOnClose);
|
|
window->show();
|
|
window->raise();
|
|
window->activateWindow();
|
|
});
|
|
}
|
|
}
|