mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-12 16:42:21 +08:00
新增了配置的保存,以及第一次打开程序时安装默认配置
This commit is contained in:
parent
aa22cd7ff2
commit
af40213c5a
@ -34,6 +34,9 @@ namespace SpkUi
|
||||
ui->lblSettingsTitle->setObjectName("styConfTitle");
|
||||
ui->lblCleanup->setObjectName("styConfTitle");
|
||||
ui->lblAdvanced->setObjectName("styConfTitle");
|
||||
|
||||
connect(ui->btnSave, &QPushButton::clicked,
|
||||
this, &SpkPageSettings::SaveConfiguration);
|
||||
}
|
||||
|
||||
void SpkPageSettings::ReadConfiguration()
|
||||
@ -51,12 +54,20 @@ namespace SpkUi
|
||||
|
||||
void SpkPageSettings::SaveConfiguration()
|
||||
{
|
||||
auto ui = mSettingsUi;
|
||||
auto settings = CFG;
|
||||
|
||||
CFG->SetSettings("resource/concurrent", ui->spnConcurrentResDownloads->value());
|
||||
assert(CFG->SetField("url/api", ui->edtApiUrl->text()));
|
||||
assert(CFG->SetField("url/res", ui->edtResourceUrl->text()));
|
||||
CFG->SetSettings("dirs/cache", ui->edtResourceCachePath->text());
|
||||
assert(CFG->SetField("dirs/download", ui->edtDownloadPath->text()));
|
||||
assert(CFG->SetField("download/servers", ui->edtDownloadServers->toPlainText()));
|
||||
CFG->SetSettings("internal/qss_path", ui->edtQssPath->text());
|
||||
}
|
||||
|
||||
void SpkPageSettings::Activated()
|
||||
{
|
||||
ReadConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,11 +15,35 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSettingsTitle">
|
||||
<property name="text">
|
||||
<string>Spark Store Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="layTitle">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSettingsTitle">
|
||||
<property name="text">
|
||||
<string>Spark Store Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="text">
|
||||
<string>Apply</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="lineTitle">
|
||||
|
@ -22,7 +22,7 @@ namespace SpkUi
|
||||
SpkDownloadMgr *mDownloadMgr;
|
||||
QMap<uint, SpkDownloadEntry*> mEntries;
|
||||
uint mNextDownloadId;
|
||||
QQueue<QPair<int, QString>> mWaitingDownloads;
|
||||
QQueue<QPair<uint, QString>> mWaitingDownloads;
|
||||
enum { Idle, Waiting, Downloading } mCurrentStatus;
|
||||
|
||||
// UI
|
||||
|
@ -37,6 +37,8 @@ class SpkConfig : public QObject
|
||||
QVariant ReadField(QString key, QVariant defaultValue);
|
||||
// Wrapper of QSettings::setValue, used for "set and restart to take effect" configurations
|
||||
void SetSettings(QString key, QVariant value);
|
||||
// Wrapper of QSettings::sync
|
||||
void Sync();
|
||||
|
||||
private:
|
||||
QSettings mSettings;
|
||||
|
@ -97,3 +97,13 @@ QVariant SpkConfig::ReadField(QString key, QVariant defaultValue)
|
||||
{
|
||||
return mSettings.value(key, defaultValue);
|
||||
}
|
||||
|
||||
void SpkConfig::SetSettings(QString key, QVariant value)
|
||||
{
|
||||
mSettings.setValue(key, value);
|
||||
}
|
||||
|
||||
void SpkConfig::Sync()
|
||||
{
|
||||
mSettings.sync();
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ void SpkResource::ResourceDownloaded()
|
||||
.arg(reply->error()));
|
||||
// Tell ResourceContext
|
||||
if(!reply->property("outdated").toBool())
|
||||
AcquisitionFinish(id, ret);
|
||||
emit AcquisitionFinish(id, ret);
|
||||
}
|
||||
|
||||
ret.data = reply->readAll();
|
||||
@ -102,7 +102,7 @@ void SpkResource::ResourceDownloaded()
|
||||
|
||||
// Tell ResourceContext
|
||||
if(!reply->property("outdated").toBool())
|
||||
AcquisitionFinish(id, ret);
|
||||
emit AcquisitionFinish(id, ret);
|
||||
|
||||
ContinueNext:
|
||||
// Start next possible mission
|
||||
@ -215,7 +215,7 @@ void SpkResource::PurgeCachedResource(const QString &aPkgName, SpkResource::Reso
|
||||
{
|
||||
auto dir = QDir(mCacheDirectory + aPkgName + '/', ResourceName[aType] + '*');
|
||||
auto list = dir.entryList();
|
||||
sLog("Resource \"" + dir.absolutePath() + '/' + dir.nameFilters()[0] +
|
||||
sLog("Resource \"" + dir.absolutePath() + '/' + dir.nameFilters().constFirst() +
|
||||
"\" was requested to be removed.");
|
||||
|
||||
if(list.isEmpty())
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "spkutils.h"
|
||||
|
||||
SpkStore *SpkStore::Instance = nullptr;
|
||||
static void InstallDefaultConfigs();
|
||||
static bool InstallDefaultConfigs(QString configPath);
|
||||
|
||||
SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
||||
{
|
||||
@ -30,27 +30,12 @@ SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
||||
mCfg = new SpkConfig(this, QDir::homePath() + "/.config/spark-store/config");
|
||||
else
|
||||
{
|
||||
mCfg = new SpkConfig(this, ":/info/default_config");
|
||||
#if 0
|
||||
bool cfgDirOk;
|
||||
if(!qgetenv("SPARK_NO_INSTALL_CONFIG").toInt())
|
||||
{
|
||||
QString path = mConfigPath.section('/', 1, -2, QString::SectionIncludeLeadingSep);
|
||||
if(!QDir().exists(path))
|
||||
{
|
||||
if(!QDir().mkpath(path))
|
||||
sErrPop(QObject::tr("Config directory \"%1\" cannot be created.").arg(path));
|
||||
else
|
||||
cfgDirOk = true;
|
||||
}
|
||||
else
|
||||
cfgDirOk = true;
|
||||
|
||||
if(cfgDirOk) // Only try copying if config dir is OK
|
||||
if(!QFile::copy(":/info/default_config", QDir::homePath() + "/.config/spark-store/config"))
|
||||
sErrPop(tr("Cannot install default config file!"));
|
||||
}
|
||||
#if 1
|
||||
if(InstallDefaultConfigs(mConfigPath))
|
||||
mCfg = new SpkConfig(this, QDir::homePath() + "/.config/spark-store/config");
|
||||
else
|
||||
#endif
|
||||
mCfg = new SpkConfig(this, ":/info/default_config");
|
||||
}
|
||||
|
||||
mNetMgr = new QNetworkAccessManager(this);
|
||||
@ -123,7 +108,32 @@ QNetworkReply *SpkStore::SendCustomHeadRequest(QNetworkRequest req)
|
||||
return mNetMgr->head(req);
|
||||
}
|
||||
|
||||
static void InstallDefaultConfigs()
|
||||
static bool InstallDefaultConfigs(QString configPath)
|
||||
{
|
||||
//TODO:STUB
|
||||
bool cfgDirOk = false;
|
||||
if(!qEnvironmentVariableIntValue("SPARK_NO_INSTALL_CONFIG"))
|
||||
{
|
||||
cfgDirOk = SpkUtils::EnsureDirExists(SpkUtils::CutPath(configPath));
|
||||
|
||||
if(cfgDirOk) // Only try copying if config dir is OK
|
||||
{
|
||||
if(!QFile::copy(":/info/default_config", QDir::homePath() + "/.config/spark-store/config"))
|
||||
{
|
||||
sErrPop(QObject::tr("Cannot install default config file!"));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copying from resource to disk causes the file to be read only (444)
|
||||
// Set it to 644 manually
|
||||
QFile::setPermissions(QDir::homePath() + "/.config/spark-store/config",
|
||||
QFileDevice::WriteOwner | QFileDevice::ReadOwner |
|
||||
QFileDevice::ReadGroup | QFileDevice::ReadOther);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user