Files
amnezia-client/client/ui/models/protocols/xrayConfigSnapshotsModel.h
T
yp fb5666057b feat: add extended vless configuration (#2566)
* update UI XRay, add new page PageProtocolXrayTransportSettings.qml PageProtocolXrayXmuxSettings.qml PageProtocolXrayXPaddingSettings.qml

* add UI PageProtocolXrayConfigsSettings, PageProtocolXrayFlowSettings, PageProtocolXraySecuritySettings

* add Xray-specific keys

* add vars xray model

* add new qml padding, update model

* update model and export

* rename file & update name class & update list xray

* fixed ui

* add save file in temp

* remove debug macros

* fixed build windows

* fix path Windows

* remove save config

* fixed changes

* fixed conf

* fixed UI

* fixed size & button save

* fixed build iOS

* fix: fixed headers base control

---------

Co-authored-by: vkamn <vk@amnezia.org>
2026-05-18 22:35:01 +08:00

77 lines
2.2 KiB
C++

#ifndef XRAYCONFIGSMODEL_H
#define XRAYCONFIGSMODEL_H
#include <QAbstractListModel>
#include <QDateTime>
#include <QJsonArray>
#include <QJsonObject>
#include <QString>
#include <QVector>
#include "core/models/protocols/xrayProtocolConfig.h"
#include "ui/models/protocols/xrayConfigModel.h"
class SecureAppSettingsRepository;
struct XrayConfigSnapshot
{
QString id;
QString displayName; // auto-generated: "XHTTP TLS Reality", "RAW Reality", etc.
QDateTime createdAt;
amnezia::XrayServerConfig serverConfig;
QJsonObject toJson() const;
static XrayConfigSnapshot fromJson(const QJsonObject &json);
};
class XrayConfigSnapshotsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles {
IdRole = Qt::UserRole + 1,
DisplayNameRole,
CreatedAtRole, // "dd.MM.yyyy HH:mm"
};
explicit XrayConfigSnapshotsModel(SecureAppSettingsRepository *appSettings, XrayConfigModel *xrayConfigModel,
QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
public slots:
void reload();
Q_INVOKABLE void createFromCurrent(const amnezia::XrayServerConfig &serverConfig);
Q_INVOKABLE amnezia::XrayServerConfig applyConfig(int index) const;
Q_INVOKABLE void removeConfig(int index);
Q_INVOKABLE QString exportToJson(int index) const;
Q_INVOKABLE bool importFromJson(const QString &jsonString);
// Convenience: create snapshot from live model, apply snapshot back to model
Q_INVOKABLE void createFromCurrentModel();
Q_INVOKABLE void applyConfigToCurrentModel(int index);
signals:
void configApplied(int index);
void configRemoved(int index);
void importFailed(const QString &errorMessage);
protected:
QHash<int, QByteArray> roleNames() const override;
private:
SecureAppSettingsRepository *m_appSettings;
XrayConfigModel *m_xrayConfigModel;
QVector<XrayConfigSnapshot> m_configs;
void persistAll();
void loadAll();
static QString buildDisplayName(const amnezia::XrayServerConfig &cfg);
};
#endif // XRAYCONFIGSMODEL_H