mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-13 12:22:05 +08:00
添加设置UI
This commit is contained in:
32
inc/page/spkpagesettings.h
Normal file
32
inc/page/spkpagesettings.h
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
#include "page/spkpagebase.h"
|
||||
#include "ui_settings.h"
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
class SpkPageSettings : public SpkPageBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpkPageSettings(QWidget *parent = nullptr);
|
||||
~SpkPageSettings();
|
||||
|
||||
void SetupUi();
|
||||
void ReadConfiguration();
|
||||
void SaveConfiguration();
|
||||
|
||||
virtual void Activated() override;
|
||||
|
||||
private:
|
||||
QScrollArea *mMainArea;
|
||||
QVBoxLayout *mMainLay;
|
||||
QWidget *mSettingsWidget;
|
||||
Ui::SpkUiSettings *mSettingsUi;
|
||||
|
||||
};
|
||||
}
|
||||
49
inc/spkconfig.h
Normal file
49
inc/spkconfig.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef SPKCONFIG_H
|
||||
#define SPKCONFIG_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QHash>
|
||||
#include <QPair>
|
||||
#include <functional>
|
||||
|
||||
class SpkConfig : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpkConfig(QObject *parent, QString configPath);
|
||||
~SpkConfig();
|
||||
|
||||
/**
|
||||
* @brief BindField If a variable is bound to the specified key, then future chanegs via SetField
|
||||
* will modify the provided variable. A callback can also be specified to make
|
||||
* sure the chanegs are acceptable.
|
||||
* @param key
|
||||
* @param value A pointer to the variable to be bound
|
||||
* @param defaultValue
|
||||
* @param callback When SetField is called to modify this specific key associated with a callback,
|
||||
* the callback is called. If the callback returned false then the original value
|
||||
* is restored to the value target, and changes won't be saved in mSettings, and
|
||||
* SetField will return false too. It is used to ensure if the target can accept
|
||||
* the changes.
|
||||
* @return false when the key is already bound.
|
||||
*/
|
||||
bool BindField(QString key, QString* value, QString defaultValue, std::function<bool(void)> callback = nullptr);
|
||||
bool BindField(QString key, int* value, int defaultValue, std::function<bool(void)> callback = nullptr);
|
||||
|
||||
bool SetField(QString key, QString value);
|
||||
bool SetField(QString key, int value);
|
||||
|
||||
// Wrapper of QSettings::value, used for "read once on startup" configurations
|
||||
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);
|
||||
|
||||
private:
|
||||
QSettings mSettings;
|
||||
|
||||
QHash<QString, QPair<QString*, std::function<bool(void)>>> mStringBindMap;
|
||||
QHash<QString, QPair<int*,std::function<bool(void)>>> mIntBindMap;
|
||||
|
||||
};
|
||||
|
||||
#endif // SPKCONFIG_H
|
||||
@@ -72,9 +72,11 @@ class SpkDownloadMgr : public QObject
|
||||
QTimer mProgressEmitterTimer;
|
||||
qint64 mDownloadedBytes;
|
||||
|
||||
int mCurrentDownloadId;
|
||||
int mCurrentDownloadId; ///< Indicates download status. -1 means no download going on.
|
||||
int mActiveWorkerCount;
|
||||
|
||||
QString mBulkServerPaths; ///< Config string, modification are taken care of by callback.
|
||||
|
||||
public slots:
|
||||
void SetDestinationFolder(QString path);
|
||||
|
||||
@@ -100,6 +102,8 @@ class SpkDownloadMgr : public QObject
|
||||
void TryScheduleFailureRetries();
|
||||
void TryScheduleFailureRetries(int i); ///< Try schedule on a specific task slot.
|
||||
|
||||
bool ServerAddressesChangedCallback(); ///< Called by SpkConfig upon address changing
|
||||
|
||||
signals:
|
||||
void DownloadProgressed(qint64 bytes, qint64 total, int id);
|
||||
void DownloadStopped(TaskResult status, int id);
|
||||
|
||||
4
inc/spkfillwidget.h
Normal file
4
inc/spkfillwidget.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef SPKFILLWIDGET_H
|
||||
#define SPKFILLWIDGET_H
|
||||
|
||||
#endif // SPKFILLWIDGET_H
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "page/spkpageapplist.h"
|
||||
#include "page/spkpageappdetails.h"
|
||||
#include "page/spkpagedownloads.h"
|
||||
#include "page/spkpagesettings.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
@@ -31,6 +32,7 @@ namespace SpkUi
|
||||
PgAppList,
|
||||
PgAppDetails,
|
||||
PgDownloads,
|
||||
PgSettings,
|
||||
PgQssTest // Must be at last
|
||||
};
|
||||
|
||||
@@ -177,6 +179,7 @@ namespace SpkUi
|
||||
SpkPageAppList *PageAppList;
|
||||
SpkPageAppDetails *PageAppDetails;
|
||||
SpkPageDownloads *PageDownloads;
|
||||
SpkPageSettings *PageSettings;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "spklogging.h"
|
||||
#include "spkresource.h"
|
||||
#include "spkconfig.h"
|
||||
|
||||
class SpkMainWindow;
|
||||
|
||||
@@ -23,7 +24,7 @@ class SpkStore : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SpkStore *Instance;
|
||||
QSettings *mCfg;
|
||||
SpkConfig *mCfg;
|
||||
SpkStore(bool aCli, QString &aLogPath);
|
||||
~SpkStore();
|
||||
|
||||
|
||||
@@ -28,4 +28,6 @@ namespace SpkUtils
|
||||
QString CutPath(QString);
|
||||
QString BytesToSize(size_t s, int prec = 2);
|
||||
bool EnsureDirExists(QString path);
|
||||
|
||||
void FillWidget(QWidget* widget, QVariant val);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user