The GUI no longer needs command line arguments: on first run it opens a settings dialog that lists the registry, downloads models in-app (mirror base, HTTP proxy, resume), and picks the active model. The caption window gains a tray icon (show/hide, settings, quit); its close button hides to the tray so the window can always be brought back, and the language pill opens the settings. Appearance (font, opacity, line counts, position) is persisted. CLI flags remain for automated testing and override settings. GUI 不再依赖命令行参数:首次启动打开设置对话框,可在应用内下载模型 (下载源/代理/断点续传)、选择当前模型与识别语言;字幕窗增加托盘(显示 隐藏/设置/退出),关闭按钮改为隐藏到托盘以免关掉后无法再打开,语言标签 点击进设置;字号/透明度/行数/位置都会持久化。命令行参数保留作自动化测试。
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <QNetworkProxy>
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
#include "modelstore.h"
|
|
|
|
class QNetworkAccessManager;
|
|
class QNetworkReply;
|
|
class QFile;
|
|
|
|
namespace lc::models {
|
|
|
|
// 按注册表下载模型文件。支持:
|
|
// - 镜像基址替换(把注册表里的地址换成用户选的源)
|
|
// - HTTP 代理
|
|
// - 断点续传(已下过的部分用 Range 续)
|
|
class ModelDownloader : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ModelDownloader(QObject * parent = nullptr);
|
|
~ModelDownloader() override;
|
|
|
|
// mirrorBase 形如 https://hf-mirror.com;留空则用注册表里的原始地址
|
|
void setMirrorBase(const QString & mirrorBase) { mirrorBase_ = mirrorBase; }
|
|
void setProxy(const QNetworkProxy & proxy) { proxy_ = proxy; }
|
|
|
|
void start(const ModelInfo & model);
|
|
void cancel();
|
|
bool isRunning() const { return running_; }
|
|
|
|
Q_SIGNALS:
|
|
void progress(const QString & file, qint64 received, qint64 total);
|
|
void status(const QString & message);
|
|
void finished(bool ok, const QString & error);
|
|
|
|
private:
|
|
void startNextFile();
|
|
void onReadyRead();
|
|
void onFinished();
|
|
void cleanup();
|
|
|
|
QString rewriteUrl(const QString & url) const;
|
|
|
|
QNetworkAccessManager * net_ = nullptr;
|
|
QNetworkReply * reply_ = nullptr;
|
|
QFile * out_ = nullptr;
|
|
std::vector<ModelFile> queue_;
|
|
size_t index_ = 0;
|
|
QString dir_;
|
|
QString mirrorBase_;
|
|
QNetworkProxy proxy_;
|
|
bool running_ = false;
|
|
bool cancel_ = false;
|
|
qint64 baseOffset_ = 0; // 断点续传的起始偏移
|
|
};
|
|
|
|
} // namespace lc::models
|