mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-19 09:32:20 +08:00
新增了配置的保存,以及第一次打开程序时安装默认配置
This commit is contained in:
parent
aa22cd7ff2
commit
af40213c5a
@ -34,6 +34,9 @@ namespace SpkUi
|
|||||||
ui->lblSettingsTitle->setObjectName("styConfTitle");
|
ui->lblSettingsTitle->setObjectName("styConfTitle");
|
||||||
ui->lblCleanup->setObjectName("styConfTitle");
|
ui->lblCleanup->setObjectName("styConfTitle");
|
||||||
ui->lblAdvanced->setObjectName("styConfTitle");
|
ui->lblAdvanced->setObjectName("styConfTitle");
|
||||||
|
|
||||||
|
connect(ui->btnSave, &QPushButton::clicked,
|
||||||
|
this, &SpkPageSettings::SaveConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpkPageSettings::ReadConfiguration()
|
void SpkPageSettings::ReadConfiguration()
|
||||||
@ -51,12 +54,20 @@ namespace SpkUi
|
|||||||
|
|
||||||
void SpkPageSettings::SaveConfiguration()
|
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()
|
void SpkPageSettings::Activated()
|
||||||
{
|
{
|
||||||
ReadConfiguration();
|
ReadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,35 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="lblSettingsTitle">
|
<layout class="QHBoxLayout" name="layTitle">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Spark Store Settings</string>
|
<widget class="QLabel" name="lblSettingsTitle">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<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>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Line" name="lineTitle">
|
<widget class="Line" name="lineTitle">
|
||||||
|
@ -22,7 +22,7 @@ namespace SpkUi
|
|||||||
SpkDownloadMgr *mDownloadMgr;
|
SpkDownloadMgr *mDownloadMgr;
|
||||||
QMap<uint, SpkDownloadEntry*> mEntries;
|
QMap<uint, SpkDownloadEntry*> mEntries;
|
||||||
uint mNextDownloadId;
|
uint mNextDownloadId;
|
||||||
QQueue<QPair<int, QString>> mWaitingDownloads;
|
QQueue<QPair<uint, QString>> mWaitingDownloads;
|
||||||
enum { Idle, Waiting, Downloading } mCurrentStatus;
|
enum { Idle, Waiting, Downloading } mCurrentStatus;
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
|
@ -37,6 +37,8 @@ class SpkConfig : public QObject
|
|||||||
QVariant ReadField(QString key, QVariant defaultValue);
|
QVariant ReadField(QString key, QVariant defaultValue);
|
||||||
// Wrapper of QSettings::setValue, used for "set and restart to take effect" configurations
|
// Wrapper of QSettings::setValue, used for "set and restart to take effect" configurations
|
||||||
void SetSettings(QString key, QVariant value);
|
void SetSettings(QString key, QVariant value);
|
||||||
|
// Wrapper of QSettings::sync
|
||||||
|
void Sync();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings mSettings;
|
QSettings mSettings;
|
||||||
|
@ -97,3 +97,13 @@ QVariant SpkConfig::ReadField(QString key, QVariant defaultValue)
|
|||||||
{
|
{
|
||||||
return mSettings.value(key, 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()));
|
.arg(reply->error()));
|
||||||
// Tell ResourceContext
|
// Tell ResourceContext
|
||||||
if(!reply->property("outdated").toBool())
|
if(!reply->property("outdated").toBool())
|
||||||
AcquisitionFinish(id, ret);
|
emit AcquisitionFinish(id, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.data = reply->readAll();
|
ret.data = reply->readAll();
|
||||||
@ -102,7 +102,7 @@ void SpkResource::ResourceDownloaded()
|
|||||||
|
|
||||||
// Tell ResourceContext
|
// Tell ResourceContext
|
||||||
if(!reply->property("outdated").toBool())
|
if(!reply->property("outdated").toBool())
|
||||||
AcquisitionFinish(id, ret);
|
emit AcquisitionFinish(id, ret);
|
||||||
|
|
||||||
ContinueNext:
|
ContinueNext:
|
||||||
// Start next possible mission
|
// Start next possible mission
|
||||||
@ -215,7 +215,7 @@ void SpkResource::PurgeCachedResource(const QString &aPkgName, SpkResource::Reso
|
|||||||
{
|
{
|
||||||
auto dir = QDir(mCacheDirectory + aPkgName + '/', ResourceName[aType] + '*');
|
auto dir = QDir(mCacheDirectory + aPkgName + '/', ResourceName[aType] + '*');
|
||||||
auto list = dir.entryList();
|
auto list = dir.entryList();
|
||||||
sLog("Resource \"" + dir.absolutePath() + '/' + dir.nameFilters()[0] +
|
sLog("Resource \"" + dir.absolutePath() + '/' + dir.nameFilters().constFirst() +
|
||||||
"\" was requested to be removed.");
|
"\" was requested to be removed.");
|
||||||
|
|
||||||
if(list.isEmpty())
|
if(list.isEmpty())
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include "spkutils.h"
|
#include "spkutils.h"
|
||||||
|
|
||||||
SpkStore *SpkStore::Instance = nullptr;
|
SpkStore *SpkStore::Instance = nullptr;
|
||||||
static void InstallDefaultConfigs();
|
static bool InstallDefaultConfigs(QString configPath);
|
||||||
|
|
||||||
SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
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");
|
mCfg = new SpkConfig(this, QDir::homePath() + "/.config/spark-store/config");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mCfg = new SpkConfig(this, ":/info/default_config");
|
#if 1
|
||||||
#if 0
|
if(InstallDefaultConfigs(mConfigPath))
|
||||||
bool cfgDirOk;
|
mCfg = new SpkConfig(this, QDir::homePath() + "/.config/spark-store/config");
|
||||||
if(!qgetenv("SPARK_NO_INSTALL_CONFIG").toInt())
|
else
|
||||||
{
|
|
||||||
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!"));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
mCfg = new SpkConfig(this, ":/info/default_config");
|
||||||
}
|
}
|
||||||
|
|
||||||
mNetMgr = new QNetworkAccessManager(this);
|
mNetMgr = new QNetworkAccessManager(this);
|
||||||
@ -123,7 +108,32 @@ QNetworkReply *SpkStore::SendCustomHeadRequest(QNetworkRequest req)
|
|||||||
return mNetMgr->head(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