2026-04-24 20:20:24 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QVariantList>
|
2026-04-27 15:06:59 +08:00
|
|
|
#include <QVariantMap>
|
2026-04-24 20:20:24 +08:00
|
|
|
#include "LocalSendCore/DiscoveryManager.h"
|
|
|
|
|
#include "LocalSendCore/HttpServer.h"
|
|
|
|
|
#include "LocalSendCore/HttpClient.h"
|
|
|
|
|
#include "LocalSendCore/SessionManager.h"
|
|
|
|
|
#include "LocalSendCore/SecurityContext.h"
|
|
|
|
|
#include "LocalSendCore/Settings.h"
|
|
|
|
|
|
|
|
|
|
class AppController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(QString alias READ alias WRITE setAlias NOTIFY aliasChanged)
|
|
|
|
|
Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged)
|
|
|
|
|
Q_PROPERTY(QVariantList devices READ devices NOTIFY devicesChanged)
|
|
|
|
|
Q_PROPERTY(bool serverRunning READ serverRunning NOTIFY serverRunningChanged)
|
2026-04-27 15:06:59 +08:00
|
|
|
Q_PROPERTY(QString downloadPath READ downloadPath WRITE setDownloadPath NOTIFY downloadPathChanged)
|
|
|
|
|
Q_PROPERTY(bool quickSave READ quickSave WRITE setQuickSave NOTIFY quickSaveChanged)
|
2026-04-24 20:20:24 +08:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit AppController(QObject* parent = nullptr);
|
|
|
|
|
~AppController() override;
|
|
|
|
|
|
|
|
|
|
void initialize();
|
|
|
|
|
|
|
|
|
|
QString alias() const;
|
|
|
|
|
void setAlias(const QString& alias);
|
|
|
|
|
|
|
|
|
|
quint16 port() const;
|
|
|
|
|
void setPort(quint16 port);
|
|
|
|
|
|
2026-04-27 15:06:59 +08:00
|
|
|
QString downloadPath() const;
|
|
|
|
|
void setDownloadPath(const QString& path);
|
|
|
|
|
|
|
|
|
|
bool quickSave() const;
|
|
|
|
|
void setQuickSave(bool enabled);
|
|
|
|
|
|
2026-04-24 20:20:24 +08:00
|
|
|
QVariantList devices() const;
|
|
|
|
|
bool serverRunning() const;
|
|
|
|
|
|
|
|
|
|
Q_INVOKABLE void startDiscovery();
|
|
|
|
|
Q_INVOKABLE void stopDiscovery();
|
|
|
|
|
Q_INVOKABLE void refreshDevices();
|
2026-04-27 15:06:59 +08:00
|
|
|
|
|
|
|
|
Q_INVOKABLE void acceptReceive(const QString& sessionId);
|
|
|
|
|
Q_INVOKABLE void declineReceive(const QString& sessionId);
|
2026-04-24 20:20:24 +08:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void aliasChanged();
|
|
|
|
|
void portChanged();
|
2026-04-27 15:06:59 +08:00
|
|
|
void downloadPathChanged();
|
|
|
|
|
void quickSaveChanged();
|
2026-04-24 20:20:24 +08:00
|
|
|
void devicesChanged();
|
|
|
|
|
void serverRunningChanged();
|
2026-04-27 15:06:59 +08:00
|
|
|
void receiveRequest(const QString& sessionId, const QString& senderAlias,
|
|
|
|
|
const QString& senderIp, const QVariantList& files);
|
|
|
|
|
void receiveProgress(const QString& sessionId, const QString& fileId, double progress);
|
|
|
|
|
void receiveCompleted(const QString& sessionId);
|
|
|
|
|
void receiveError(const QString& sessionId, const QString& error);
|
2026-04-24 20:20:24 +08:00
|
|
|
void sendProgress(const QString& sessionId, double progress);
|
|
|
|
|
void sendCompleted(const QString& sessionId);
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void onDeviceDiscovered(const LocalSend::Device& device);
|
|
|
|
|
void onDeviceLost(const QString& fingerprint);
|
2026-04-27 15:06:59 +08:00
|
|
|
void onRegisterRequest(const LocalSend::RegisterDto& dto, const QHostAddress& sender);
|
|
|
|
|
void onPrepareUploadRequest(const QString& httpSessionId,
|
|
|
|
|
const LocalSend::PrepareUploadRequestDto& dto,
|
|
|
|
|
const QHostAddress& sender);
|
|
|
|
|
void onUploadRequest(const QString& sessionId, const QString& fileId,
|
|
|
|
|
const QString& token, const QByteArray& data);
|
|
|
|
|
void onSessionAccepted(const QString& sessionId, const QMap<QString, QString>& tokens);
|
|
|
|
|
void onSessionDeclined(const QString& sessionId);
|
|
|
|
|
void onReceiveProgress(const QString& sessionId, const QString& fileId, double progress);
|
|
|
|
|
void onReceiveCompleted(const QString& sessionId);
|
2026-04-24 20:20:24 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
LocalSend::Settings* m_settings = nullptr;
|
|
|
|
|
LocalSend::SecurityContext* m_security = nullptr;
|
|
|
|
|
LocalSend::DiscoveryManager* m_discovery = nullptr;
|
|
|
|
|
LocalSend::HttpServer* m_server = nullptr;
|
|
|
|
|
LocalSend::SessionManager* m_sessions = nullptr;
|
|
|
|
|
|
|
|
|
|
QMap<QString, LocalSend::Device> m_devices;
|
|
|
|
|
|
|
|
|
|
LocalSend::InfoDto buildInfoDto() const;
|
2026-04-27 15:06:59 +08:00
|
|
|
QString generateUniqueFilePath(const QString& baseDir, const QString& fileName) const;
|
2026-04-24 20:20:24 +08:00
|
|
|
};
|