mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-10-24 11:12:21 +08:00
添加服务器url配置功能
This commit is contained in:
parent
562b582f72
commit
98cf333386
@ -1,9 +1,12 @@
|
|||||||
#include "sparkapi.h"
|
#include "sparkapi.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
QString SparkAPI::serverUrl = "";
|
||||||
|
|
||||||
SparkAPI::SparkAPI(QObject *parent) : QObject(parent)
|
SparkAPI::SparkAPI(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
SparkAPI::serverUrl = "https://cdn.d.store.deepinos.org.cn/";
|
||||||
}
|
}
|
||||||
void SparkAPI::get(QUrl url)
|
void SparkAPI::get(QUrl url)
|
||||||
{
|
{
|
||||||
@ -41,9 +44,13 @@ void SparkAPI::getAppInfo(QUrl spk)
|
|||||||
}
|
}
|
||||||
QString SparkAPI::getServerUrl()
|
QString SparkAPI::getServerUrl()
|
||||||
{
|
{
|
||||||
return "https://cdn.d.store.deepinos.org.cn/";
|
return SparkAPI::serverUrl;
|
||||||
}
|
}
|
||||||
QString SparkAPI::getImgServerUrl()
|
QString SparkAPI::getImgServerUrl()
|
||||||
{
|
{
|
||||||
return "https://cdn.d.store.deepinos.org.cn/";
|
return SparkAPI::serverUrl;
|
||||||
|
}
|
||||||
|
void SparkAPI::setServerUrl(QString url)
|
||||||
|
{
|
||||||
|
SparkAPI::serverUrl = url;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,16 @@ class SparkAPI : public QObject
|
|||||||
public:
|
public:
|
||||||
static QString getServerUrl();
|
static QString getServerUrl();
|
||||||
static QString getImgServerUrl();
|
static QString getImgServerUrl();
|
||||||
|
static void setServerUrl(QString url);
|
||||||
void getSearchList(QString keyword);
|
void getSearchList(QString keyword);
|
||||||
void get(QUrl url);
|
void get(QUrl url);
|
||||||
void getAppList(QString type);
|
void getAppList(QString type);
|
||||||
void getAppInfo(QUrl spk);
|
void getAppInfo(QUrl spk);
|
||||||
explicit SparkAPI(QObject *parent = nullptr);
|
explicit SparkAPI(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QString serverUrl;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished(QJsonArray);
|
void finished(QJsonArray);
|
||||||
void finishedObject(QJsonObject);
|
void finishedObject(QJsonObject);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
initConfig();
|
||||||
moveToCenter(this); //让窗口居中显示
|
moveToCenter(this); //让窗口居中显示
|
||||||
|
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity", this);
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity", this);
|
||||||
@ -34,7 +34,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
//ui->titlebar->setSwitchThemeMenuVisible(false); // 去除 dtk 标题栏主题切换菜单
|
//ui->titlebar->setSwitchThemeMenuVisible(false); // 去除 dtk 标题栏主题切换菜单
|
||||||
setMaskAlpha(240);
|
setMaskAlpha(240);
|
||||||
|
|
||||||
initConfig();
|
|
||||||
updateUi(0);
|
updateUi(0);
|
||||||
|
|
||||||
QAction *setting = new QAction(tr("Settings"));
|
QAction *setting = new QAction(tr("Settings"));
|
||||||
|
|||||||
@ -6,6 +6,7 @@ SettingsPage::SettingsPage(QWidget *parent) :
|
|||||||
ui(new Ui::SettingsPage)
|
ui(new Ui::SettingsPage)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
initConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPage::setTheme(bool dark)
|
void SettingsPage::setTheme(bool dark)
|
||||||
@ -19,7 +20,99 @@ void SettingsPage::setTheme(bool dark)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsPage::readServerList()
|
||||||
|
{
|
||||||
|
// 读取服务器列表并初始化
|
||||||
|
QFile file(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
|
||||||
|
|
||||||
|
//判断文件是否存在
|
||||||
|
if (!file.exists())
|
||||||
|
{
|
||||||
|
ui->comboBox_server->addItem("https://d.store.deepinos.org.cn/");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
qDebug()<<"无法读取server.list";
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建QTextStream对象
|
||||||
|
QTextStream textStream(&file);
|
||||||
|
|
||||||
|
QString lineData = textStream.readLine();//读取文件的第一行
|
||||||
|
ui->comboBox_server->addItem(lineData);
|
||||||
|
while(!lineData.isNull())
|
||||||
|
{
|
||||||
|
lineData = textStream.readLine();
|
||||||
|
ui->comboBox_server->addItem(lineData);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < ui->comboBox_server->count(); i++)
|
||||||
|
{
|
||||||
|
if(ui->comboBox_server->itemText(i) == "开发者模式 Dev only")
|
||||||
|
{
|
||||||
|
ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(i, 0), QVariant(0), Qt::UserRole - 1);
|
||||||
|
}
|
||||||
|
if(ui->comboBox_server->itemText(i) == "镜像源 Download only")
|
||||||
|
{
|
||||||
|
for(int j = i; j < ui->comboBox_server->count(); j++)
|
||||||
|
{
|
||||||
|
ui->comboBox_server->model()->setData(ui->comboBox_server->model()->index(j, 0), QVariant(0), Qt::UserRole - 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsPage::initConfig()
|
||||||
|
{
|
||||||
|
readServerList();
|
||||||
|
|
||||||
|
// 读取服务器URL并初始化菜单项的链接
|
||||||
|
QSettings readConfig(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
|
||||||
|
if(!readConfig.value("server/choose").toString().isEmpty() && readConfig.value("server/updated").toString() == "TRUE")
|
||||||
|
{
|
||||||
|
ui->comboBox_server->setCurrentText(readConfig.value("server/choose").toString());
|
||||||
|
SparkAPI::setServerUrl(readConfig.value("server/choose").toString());
|
||||||
|
}
|
||||||
|
configCanSave = true; // 防止触发保存配置信号
|
||||||
|
}
|
||||||
|
|
||||||
SettingsPage::~SettingsPage()
|
SettingsPage::~SettingsPage()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsPage::on_pushButton_updateServer_clicked()
|
||||||
|
{
|
||||||
|
QtConcurrent::run([=]()
|
||||||
|
{
|
||||||
|
ui->pushButton_updateServer->setEnabled(false);
|
||||||
|
ui->comboBox_server->clear();
|
||||||
|
|
||||||
|
QFile::remove(QDir::homePath().toUtf8() + "/.config/spark-store/server.list");
|
||||||
|
system("curl -o " + QDir::homePath().toUtf8() + "/.config/spark-store/server.list https://d.store.deepinos.org.cn/store/server-and-mirror.list");
|
||||||
|
|
||||||
|
ui->pushButton_updateServer->setEnabled(true);
|
||||||
|
ui->comboBox_server->setCurrentIndex(0);
|
||||||
|
|
||||||
|
readServerList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SettingsPage::on_comboBox_server_currentIndexChanged(const QString &arg1)
|
||||||
|
{
|
||||||
|
SparkAPI::setServerUrl(arg1); // 服务器信息更新
|
||||||
|
|
||||||
|
const QString updatedInfo = "TRUE";
|
||||||
|
if(configCanSave)
|
||||||
|
{
|
||||||
|
// ui->label_setting1->show();
|
||||||
|
QSettings *setConfig = new QSettings(QDir::homePath() + "/.config/spark-store/config.ini", QSettings::IniFormat);
|
||||||
|
setConfig->setValue("server/choose", arg1);
|
||||||
|
setConfig->setValue("server/updated", updatedInfo);
|
||||||
|
setConfig->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,12 @@
|
|||||||
#define SETTINGSPAGE_H
|
#define SETTINGSPAGE_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QtConcurrent>
|
||||||
|
#include "../backend/sparkapi.h"
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class SettingsPage;
|
class SettingsPage;
|
||||||
}
|
}
|
||||||
@ -16,7 +21,15 @@ public:
|
|||||||
void setTheme(bool dark);
|
void setTheme(bool dark);
|
||||||
~SettingsPage();
|
~SettingsPage();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_pushButton_updateServer_clicked();
|
||||||
|
|
||||||
|
void on_comboBox_server_currentIndexChanged(const QString &arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool configCanSave;
|
||||||
|
void readServerList();
|
||||||
|
void initConfig();
|
||||||
Ui::SettingsPage *ui;
|
Ui::SettingsPage *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user