1
0
forked from BRT/arc
arc/views/device/DeviceSettingsWindow.cpp
slava 712b73316c Remove CommonBirbankScript and its derived classes from the codebase
Deleted `CommonBirbankScript` and its associated derived classes (`GetLastDaysHistoryBirbankScript`, `LoginAndCheckAccountsBirbankScript`, `PayByCardBirbankScript`). Removed dependencies on these scripts, including XML parsing, account handling, and transaction workflows related to the Birbank app.
2026-03-21 17:41:05 +07:00

133 lines
5.1 KiB
C++

#include "DeviceSettingsWindow.h"
#include <QVBoxLayout>
#include <QHeaderView>
#include <QScrollArea>
#include <QCoreApplication>
#include <QPushButton>
#include <QLabel>
#include "bank/AccountSettingsWindow.h"
#include "dao/ApplicationDAO.h"
#include "db/ApplicationInfo.h"
static QString formatStatus(const ApplicationInfo &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<ApplicationInfo> apps = ApplicationDAO::getApplicationsByDeviceId(m_deviceId);
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 ApplicationInfo &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();
});
}
}