mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
chore: update files of projects
This commit is contained in:
parent
f8de670f01
commit
e882611061
@ -30,13 +30,20 @@ include(.cmake/sak_common_deploy.cmake)
|
||||
sak_get_last_commit(${CMAKE_CURRENT_SOURCE_DIR} "SAK")
|
||||
sak_get_last_commit_time(${CMAKE_CURRENT_SOURCE_DIR} "SAK")
|
||||
|
||||
# Assistant module
|
||||
# Assistant module.
|
||||
include_directories(src/assistants)
|
||||
include_directories(src/assistantsui)
|
||||
include(${CMAKE_SOURCE_DIR}/.cmake/sak_i18n.cmake)
|
||||
sak_add_lupdate()
|
||||
sak_add_lrelease()
|
||||
|
||||
# Glog module.
|
||||
option(SAK_USING_GLOG "Using glog module." ON)
|
||||
if(SAK_USING_GLOG)
|
||||
add_compile_definitions(SAK_USING_GLOG)
|
||||
sak_add_subdiretory("glog-master")
|
||||
endif()
|
||||
|
||||
macro(sak_import_assistant assistant_dir_name)
|
||||
string(TOUPPER ${assistant_dir_name} upper_name)
|
||||
set(SAK_IMPORT_MODULE_NAME SAK_IMPORT_MODULE_${upper_name}ASSISTANT)
|
||||
@ -129,7 +136,7 @@ sak_auto_execute_deployqt(SwissArmyKnife)
|
||||
sak_set_target_properties(SwissArmyKnife)
|
||||
target_link_libraries(
|
||||
SwissArmyKnife
|
||||
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets
|
||||
PRIVATE glog::glog Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets
|
||||
Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::SerialPort
|
||||
Qt${QT_VERSION_MAJOR}::SerialBus Qt${QT_VERSION_MAJOR}::Bluetooth)
|
||||
install(
|
||||
|
||||
@ -1,156 +1,181 @@
|
||||
/*******************************************************************************
|
||||
/***************************************************************************************************
|
||||
* Copyright 2023 Qsaker(qsaker@foxmail.com). All rights reserved.
|
||||
*
|
||||
* The file is encoded using "utf8 with bom", it is a part
|
||||
* of QtSwissArmyKnife project.
|
||||
* The file is encoded using "utf8 with bom", it is a part of QtSwissArmyKnife project.
|
||||
*
|
||||
* QtSwissArmyKnife is licensed according to the terms in
|
||||
* the file LICENCE in the root of the source code directory.
|
||||
******************************************************************************/
|
||||
* QtSwissArmyKnife is licensed according to the terms in the file LICENCE in the root of the source
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#include <QCoreApplication>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "sakdatastructure.h"
|
||||
#include "saksettings.h"
|
||||
|
||||
static const QString fileName() {
|
||||
QStandardPaths::StandardLocation type = QStandardPaths::AppConfigLocation;
|
||||
QString path = QStandardPaths::writableLocation(type);
|
||||
auto ret =
|
||||
QString("%1/%2.ini").arg(path, QCoreApplication::applicationName());
|
||||
return ret;
|
||||
static const QString fileName()
|
||||
{
|
||||
QStandardPaths::StandardLocation type = QStandardPaths::AppConfigLocation;
|
||||
QString path = QStandardPaths::writableLocation(type);
|
||||
auto ret = QString("%1/%2.ini").arg(path, QCoreApplication::applicationName());
|
||||
return ret;
|
||||
}
|
||||
|
||||
SAKSettings::SAKSettings(QObject* parent)
|
||||
: QSettings{::fileName(), QSettings::IniFormat, parent} {
|
||||
qCInfo(mLoggingCategory) << "settings file:" << fileName();
|
||||
: QSettings{::fileName(), QSettings::IniFormat, parent}
|
||||
{
|
||||
qCInfo(mLoggingCategory) << "settings file:" << fileName();
|
||||
}
|
||||
|
||||
SAKSettings* SAKSettings::instance() {
|
||||
static SAKSettings* settings = Q_NULLPTR;
|
||||
if (!settings) {
|
||||
settings = new SAKSettings(qApp);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
int SAKSettings::hdpiPolicy() {
|
||||
int ret = value(mSettingsKey.hdpiPolicy).toInt();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if ((ret < 1) || (ret > 5)) {
|
||||
if (ret != SAKDataStructure::HdpiPolicySystem) {
|
||||
ret = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
SAKSettings* SAKSettings::instance()
|
||||
{
|
||||
static SAKSettings* settings = Q_NULLPTR;
|
||||
if (!settings) {
|
||||
settings = new SAKSettings(qApp);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
QString SAKSettings::settingsPath()
|
||||
{
|
||||
QString settingsFile(fileName());
|
||||
QString path = settingsFile.left(settingsFile.lastIndexOf("/"));
|
||||
return path;
|
||||
}
|
||||
|
||||
int SAKSettings::hdpiPolicy()
|
||||
{
|
||||
int ret = value(mSettingsKey.hdpiPolicy).toInt();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if ((ret < 1) || (ret > 5)) {
|
||||
if (ret != SAKDataStructure::HdpiPolicySystem) {
|
||||
ret = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SAKSettings::setHdpiPolicy(int policy) {
|
||||
void SAKSettings::setHdpiPolicy(int policy)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if ((policy < 1) || (policy > 5)) {
|
||||
if (policy != SAKDataStructure::HdpiPolicySystem) {
|
||||
policy = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
if ((policy < 1) || (policy > 5)) {
|
||||
if (policy != SAKDataStructure::HdpiPolicySystem) {
|
||||
policy = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
setValue(mSettingsKey.hdpiPolicy, policy);
|
||||
emit hdpiPolicyChanged();
|
||||
setValue(mSettingsKey.hdpiPolicy, policy);
|
||||
emit hdpiPolicyChanged();
|
||||
}
|
||||
|
||||
int SAKSettings::uiType() {
|
||||
int ret = value(mSettingsKey.uiType).toInt();
|
||||
if ((ret < 0) || (ret > 1)) {
|
||||
ret = UiTypeWidget;
|
||||
}
|
||||
int SAKSettings::uiType()
|
||||
{
|
||||
int ret = value(mSettingsKey.uiType).toInt();
|
||||
if ((ret < 0) || (ret > 1)) {
|
||||
ret = UiTypeWidget;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SAKSettings::setUiType(int type) {
|
||||
if ((type < 0) || (type > 1)) {
|
||||
type = UiTypeWidget;
|
||||
}
|
||||
void SAKSettings::setUiType(int type)
|
||||
{
|
||||
if ((type < 0) || (type > 1)) {
|
||||
type = UiTypeWidget;
|
||||
}
|
||||
|
||||
setValue(mSettingsKey.uiType, type);
|
||||
emit uiTypeChanged();
|
||||
setValue(mSettingsKey.uiType, type);
|
||||
emit uiTypeChanged();
|
||||
}
|
||||
|
||||
QString SAKSettings::appStyle() {
|
||||
return value(mSettingsKey.appStyle, SAK_STYLE_DEFAULT).toString();
|
||||
QString SAKSettings::appStyle()
|
||||
{
|
||||
return value(mSettingsKey.appStyle, SAK_STYLE_DEFAULT).toString();
|
||||
}
|
||||
|
||||
void SAKSettings::setAppStyle(const QString& style) {
|
||||
setValue(mSettingsKey.appStyle, style);
|
||||
void SAKSettings::setAppStyle(const QString& style)
|
||||
{
|
||||
setValue(mSettingsKey.appStyle, style);
|
||||
}
|
||||
|
||||
QString SAKSettings::language() {
|
||||
return value(mSettingsKey.language).toString();
|
||||
QString SAKSettings::language()
|
||||
{
|
||||
return value(mSettingsKey.language).toString();
|
||||
}
|
||||
|
||||
void SAKSettings::setLanguage(const QString& lan) {
|
||||
setValue(mSettingsKey.language, lan);
|
||||
void SAKSettings::setLanguage(const QString& lan)
|
||||
{
|
||||
setValue(mSettingsKey.language, lan);
|
||||
}
|
||||
|
||||
bool SAKSettings::clearSettings() {
|
||||
return value(mSettingsKey.clearSettings).toBool();
|
||||
bool SAKSettings::clearSettings()
|
||||
{
|
||||
return value(mSettingsKey.clearSettings).toBool();
|
||||
}
|
||||
|
||||
void SAKSettings::setClearSettings(bool clear) {
|
||||
setValue(mSettingsKey.clearSettings, clear);
|
||||
emit clearSettingsChanged();
|
||||
void SAKSettings::setClearSettings(bool clear)
|
||||
{
|
||||
setValue(mSettingsKey.clearSettings, clear);
|
||||
emit clearSettingsChanged();
|
||||
}
|
||||
|
||||
int SAKSettings::pageIndex() {
|
||||
return value(mSettingsKey.pageIndex).toInt();
|
||||
int SAKSettings::pageIndex()
|
||||
{
|
||||
return value(mSettingsKey.pageIndex).toInt();
|
||||
}
|
||||
|
||||
void SAKSettings::setPageIndex(int index) {
|
||||
setValue(mSettingsKey.pageIndex, index);
|
||||
emit pageIndexChanged();
|
||||
void SAKSettings::setPageIndex(int index)
|
||||
{
|
||||
setValue(mSettingsKey.pageIndex, index);
|
||||
emit pageIndexChanged();
|
||||
}
|
||||
|
||||
bool SAKSettings::isTextBesideIcon() {
|
||||
return value(mSettingsKey.isTextBesideIcon).toBool();
|
||||
bool SAKSettings::isTextBesideIcon()
|
||||
{
|
||||
return value(mSettingsKey.isTextBesideIcon).toBool();
|
||||
}
|
||||
|
||||
void SAKSettings::setIsTextBesideIcon(bool is) {
|
||||
setValue(mSettingsKey.isTextBesideIcon, is);
|
||||
emit isTextBesideIconChanged();
|
||||
void SAKSettings::setIsTextBesideIcon(bool is)
|
||||
{
|
||||
setValue(mSettingsKey.isTextBesideIcon, is);
|
||||
emit isTextBesideIconChanged();
|
||||
}
|
||||
|
||||
int SAKSettings::palette() {
|
||||
int ret = value(mSettingsKey.palette).toInt();
|
||||
if ((ret != SAKDataStructure::PaletteSystem) &&
|
||||
(ret != SAKDataStructure::PaletteLight) &&
|
||||
(ret != SAKDataStructure::PaletteDark) &&
|
||||
(ret != SAKDataStructure::PaletteCustom)) {
|
||||
ret = SAKDataStructure::PaletteSystem;
|
||||
}
|
||||
int SAKSettings::palette()
|
||||
{
|
||||
int ret = value(mSettingsKey.palette).toInt();
|
||||
if ((ret != SAKDataStructure::PaletteSystem) && (ret != SAKDataStructure::PaletteLight)
|
||||
&& (ret != SAKDataStructure::PaletteDark) && (ret != SAKDataStructure::PaletteCustom)) {
|
||||
ret = SAKDataStructure::PaletteSystem;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SAKSettings::setPalette(int p) {
|
||||
setValue(mSettingsKey.palette, p);
|
||||
emit paletteChanged();
|
||||
void SAKSettings::setPalette(int p)
|
||||
{
|
||||
setValue(mSettingsKey.palette, p);
|
||||
emit paletteChanged();
|
||||
}
|
||||
|
||||
QString SAKSettings::customPalette() {
|
||||
return value(mSettingsKey.customPalette).toString();
|
||||
QString SAKSettings::customPalette()
|
||||
{
|
||||
return value(mSettingsKey.customPalette).toString();
|
||||
}
|
||||
|
||||
void SAKSettings::setCustomPalette(const QString& p) {
|
||||
setValue(mSettingsKey.customPalette, p);
|
||||
emit customPaletteChanged();
|
||||
void SAKSettings::setCustomPalette(const QString& p)
|
||||
{
|
||||
setValue(mSettingsKey.customPalette, p);
|
||||
emit customPaletteChanged();
|
||||
}
|
||||
|
||||
QVariant SAKSettings::value(const QString& key,
|
||||
const QVariant& defaultValue) const {
|
||||
return QSettings::value(key, defaultValue);
|
||||
QVariant SAKSettings::value(const QString& key, const QVariant& defaultValue) const
|
||||
{
|
||||
return QSettings::value(key, defaultValue);
|
||||
}
|
||||
|
||||
void SAKSettings::setValue(const QString& key, const QVariant& value) {
|
||||
QSettings::setValue(key, value);
|
||||
void SAKSettings::setValue(const QString& key, const QVariant& value)
|
||||
{
|
||||
QSettings::setValue(key, value);
|
||||
}
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
/*******************************************************************************
|
||||
/***************************************************************************************************
|
||||
* Copyright 2023 Qsaker(qsaker@foxmail.com). All rights reserved.
|
||||
*
|
||||
* The file is encoded using "utf8 with bom", it is a part
|
||||
* of QtSwissArmyKnife project.
|
||||
* The file is encoded using "utf8 with bom", it is a part of QtSwissArmyKnife project.
|
||||
*
|
||||
* QtSwissArmyKnife is licensed according to the terms in
|
||||
* the file LICENCE in the root of the source code directory.
|
||||
******************************************************************************/
|
||||
* QtSwissArmyKnife is licensed according to the terms in the file LICENCE in the root of the source
|
||||
* code directory.
|
||||
**************************************************************************************************/
|
||||
#ifndef SAKSETTINGS_H
|
||||
#define SAKSETTINGS_H
|
||||
|
||||
#include <Qt>
|
||||
#include <QSettings>
|
||||
#include <QLoggingCategory>
|
||||
#include <QSettings>
|
||||
#include <Qt>
|
||||
|
||||
class SAKSettings : public QSettings
|
||||
{
|
||||
Q_OBJECT
|
||||
// clang-format off
|
||||
Q_PROPERTY(int hdpiPolicy READ hdpiPolicy WRITE setHdpiPolicy NOTIFY hdpiPolicyChanged)
|
||||
Q_PROPERTY(int uiType READ uiType WRITE setUiType NOTIFY uiTypeChanged)
|
||||
Q_PROPERTY(bool clearSettings READ clearSettings WRITE setClearSettings NOTIFY clearSettingsChanged)
|
||||
@ -24,6 +24,7 @@ class SAKSettings : public QSettings
|
||||
Q_PROPERTY(bool isTextBesideIcon READ isTextBesideIcon WRITE setIsTextBesideIcon NOTIFY isTextBesideIconChanged)
|
||||
Q_PROPERTY(int palette READ palette WRITE setPalette NOTIFY paletteChanged)
|
||||
Q_PROPERTY(QString customPalette READ customPalette WRITE setCustomPalette NOTIFY customPaletteChanged)
|
||||
// clang-format on
|
||||
public:
|
||||
enum UiType {
|
||||
UiTypeWidget,
|
||||
@ -37,6 +38,8 @@ private:
|
||||
public:
|
||||
static SAKSettings *instance();
|
||||
|
||||
QString settingsPath();
|
||||
|
||||
int hdpiPolicy();
|
||||
void setHdpiPolicy(int policy);
|
||||
|
||||
@ -74,13 +77,12 @@ signals:
|
||||
void customPaletteChanged();
|
||||
|
||||
public:
|
||||
Q_INVOKABLE QVariant value(const QString &key,
|
||||
const QVariant &defaultValue
|
||||
= QVariant()) const;
|
||||
Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||
Q_INVOKABLE void setValue(const QString &key, const QVariant &value);
|
||||
|
||||
private:
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
const QString hdpiPolicy{"hdpiPolicy"};
|
||||
const QString uiType{"uiType"};
|
||||
const QString appStyle{"appStyle"};
|
||||
|
||||
48
src/main.cc
48
src/main.cc
@ -6,13 +6,57 @@
|
||||
* QtSwissArmyKnife is licensed according to the terms in the file LICENCE in the root of the
|
||||
* source code directory.
|
||||
**************************************************************************************************/
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStyleFactory>
|
||||
|
||||
#ifdef SAK_USING_GLOG
|
||||
#include "glog/logging.h"
|
||||
#endif
|
||||
|
||||
#include "sakapplication.h"
|
||||
#include "sakinterface.h"
|
||||
#include "saklog.h"
|
||||
#include "saksettings.h"
|
||||
|
||||
#ifdef SAK_USING_GLOG
|
||||
|
||||
void sakInitGoogleLogging(char *argv0)
|
||||
{
|
||||
QString logPath = SAKSettings::instance()->settingsPath();
|
||||
logPath += "/log";
|
||||
QDir dir(SAKSettings::instance()->settingsPath());
|
||||
if (!dir.exists(logPath) && !dir.mkpath(logPath)) {
|
||||
qWarning() << "Make log directory failed";
|
||||
}
|
||||
|
||||
google::SetLogFilenameExtension(".log"); // The suffix of log file.
|
||||
google::EnableLogCleaner(30); // Keep the log file for 30 days.
|
||||
google::SetApplicationFingerprint("SAK"); // (It seem to be no use.)
|
||||
|
||||
fLB::FLAGS_logtostdout = false;
|
||||
fLB::FLAGS_logtostderr = false;
|
||||
fLS::FLAGS_log_dir = logPath.toUtf8().data(); // The path of log.
|
||||
fLI::FLAGS_logbufsecs = 0; //
|
||||
fLU::FLAGS_max_log_size = 10; // The max size(MB) of log file.
|
||||
fLB::FLAGS_stop_logging_if_full_disk = true; //
|
||||
fLB::FLAGS_alsologtostderr = false; //
|
||||
|
||||
#ifndef QT_DEBUG
|
||||
google::InitGoogleLogging(argv0);
|
||||
#endif
|
||||
qInfo() << "The logging path is:" << qPrintable(logPath);
|
||||
}
|
||||
|
||||
void sakShutdownGoogleLogging()
|
||||
{
|
||||
#ifndef QT_DEBUG
|
||||
google::ShutdownGoogleLogging();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void qtLogToGlog(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
QByteArray localMsg = msg.toUtf8();
|
||||
@ -39,6 +83,8 @@ void qtLogToGlog(QtMsgType type, const QMessageLogContext &context, const QStrin
|
||||
Q_UNUSED(file)
|
||||
Q_UNUSED(line)
|
||||
#endif
|
||||
|
||||
SAKLog::messageOutput(type, context, msg);
|
||||
}
|
||||
|
||||
static void sakInitApp()
|
||||
@ -106,11 +152,13 @@ static void sakInitAppStyle()
|
||||
int main(const int argc, char* argv[])
|
||||
{
|
||||
sakInitApp();
|
||||
sakInitGoogleLogging(argv[0]);
|
||||
sakInstallMessageHandler();
|
||||
sakTryToClearSettings();
|
||||
sakInitHdpi();
|
||||
sakInitAppStyle();
|
||||
|
||||
SAKApplication app(argc, argv);
|
||||
sakShutdownGoogleLogging();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user