mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
parent
918aa15e74
commit
5a01b4bb35
4
.github/workflows/ci-linux.yml
vendored
4
.github/workflows/ci-linux.yml
vendored
@ -150,7 +150,7 @@ jobs:
|
|||||||
uses: johnwbyrd/update-release@v1.0.0
|
uses: johnwbyrd/update-release@v1.0.0
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
files: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64
|
files: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64.AppImage
|
||||||
release: Continuous Build
|
release: Continuous Build
|
||||||
tag: continuous-build
|
tag: continuous-build
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ jobs:
|
|||||||
uses: ncipollo/release-action@v1.11.0
|
uses: ncipollo/release-action@v1.11.0
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
artifacts: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64
|
artifacts: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64.AppImage
|
||||||
commit: master
|
commit: master
|
||||||
tag: v${{env.VNOTE_VER}}
|
tag: v${{env.VNOTE_VER}}
|
||||||
allowUpdates: true
|
allowUpdates: true
|
||||||
|
4
.github/workflows/ci-win.yml
vendored
4
.github/workflows/ci-win.yml
vendored
@ -112,7 +112,7 @@ jobs:
|
|||||||
- name: Archive Artifacts
|
- name: Archive Artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: VNote-${{env.VNOTE_VER}}-win64${{matrix.config.suffix}}
|
name: VNote-${{env.VNOTE_VER}}-win64${{matrix.config.suffix}}.zip
|
||||||
path: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-win64${{matrix.config.suffix}}
|
path: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-win64${{matrix.config.suffix}}
|
||||||
|
|
||||||
- name: Archive Installer
|
- name: Archive Installer
|
||||||
@ -135,7 +135,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
# glob not supported
|
# glob not supported
|
||||||
files: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-win64${{matrix.config.suffix}}
|
files: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-win64${{matrix.config.suffix}}.zip
|
||||||
release: Continuous Build
|
release: Continuous Build
|
||||||
tag: continuous-build
|
tag: continuous-build
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ if((QT_DEFAULT_MAJOR_VERSION GREATER 5))
|
|||||||
qt_add_lupdate(vnote TS_FILES ${VX_TS_FILES})
|
qt_add_lupdate(vnote TS_FILES ${VX_TS_FILES})
|
||||||
endif()
|
endif()
|
||||||
# Generate .qm files from .ts files (lrelease)
|
# Generate .qm files from .ts files (lrelease)
|
||||||
|
set_source_files_properties(${VX_TS_FILES} PROPERTIES
|
||||||
|
OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/translations")
|
||||||
qt_add_translation(VX_QM_FILES ${VX_TS_FILES})
|
qt_add_translation(VX_QM_FILES ${VX_TS_FILES})
|
||||||
add_custom_target(lrelease DEPENDS ${VX_QM_FILES})
|
add_custom_target(lrelease DEPENDS ${VX_QM_FILES})
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@ CommandLineOptions::ParseResult CommandLineOptions::parse(const QStringList &p_a
|
|||||||
const QCommandLineOption verboseOpt("verbose", MainWindow::tr("Print more logs."));
|
const QCommandLineOption verboseOpt("verbose", MainWindow::tr("Print more logs."));
|
||||||
parser.addOption(verboseOpt);
|
parser.addOption(verboseOpt);
|
||||||
|
|
||||||
|
const QCommandLineOption logStderrOpt("log-stderr", MainWindow::tr("Log to stderr."));
|
||||||
|
parser.addOption(logStderrOpt);
|
||||||
|
|
||||||
// WebEngine options.
|
// WebEngine options.
|
||||||
// No need to handle them. Just add them to the parser to avoid parse error.
|
// No need to handle them. Just add them to the parser to avoid parse error.
|
||||||
{
|
{
|
||||||
@ -63,5 +66,9 @@ CommandLineOptions::ParseResult CommandLineOptions::parse(const QStringList &p_a
|
|||||||
m_verbose = true;
|
m_verbose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(logStderrOpt)) {
|
||||||
|
m_logToStderr = true;
|
||||||
|
}
|
||||||
|
|
||||||
return ParseResult::Ok;
|
return ParseResult::Ok;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ public:
|
|||||||
QStringList m_pathsToOpen;
|
QStringList m_pathsToOpen;
|
||||||
|
|
||||||
bool m_verbose = false;
|
bool m_verbose = false;
|
||||||
|
|
||||||
|
bool m_logToStderr = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMMANDLINEOPTIONS_H
|
#endif // COMMANDLINEOPTIONS_H
|
||||||
|
@ -191,8 +191,7 @@ bool ConfigMgr::checkAppConfig()
|
|||||||
|
|
||||||
// Load extra data.
|
// Load extra data.
|
||||||
splash->showMessage("Loading extra resource data");
|
splash->showMessage("Loading extra resource data");
|
||||||
const QString extraRcc(PathUtils::concatenateFilePath(QCoreApplication::applicationDirPath(),
|
const QString extraRcc("app:vnote_extra.rcc");
|
||||||
QStringLiteral("vnote_extra.rcc")));
|
|
||||||
bool ret = QResource::registerResource(extraRcc);
|
bool ret = QResource::registerResource(extraRcc);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
Exception::throwOne(Exception::Type::FailToReadFile,
|
Exception::throwOne(Exception::Type::FailToReadFile,
|
||||||
@ -571,6 +570,26 @@ QString ConfigMgr::getApplicationVersion()
|
|||||||
return appVersion;
|
return appVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigMgr::initAppPrefixPath()
|
||||||
|
{
|
||||||
|
// Support QFile("app:abc.txt").
|
||||||
|
QStringList potential_dirs;
|
||||||
|
auto app_dir_path = QCoreApplication::applicationDirPath();
|
||||||
|
qInfo() << "executable dir: " << app_dir_path;
|
||||||
|
potential_dirs << app_dir_path;
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
QDir localBinDir(app_dir_path);
|
||||||
|
if (localBinDir.exists("../local/bin/vnote")) {
|
||||||
|
auto app_dir_path2 = localBinDir.cleanPath(localBinDir.filePath("../local/bin"));
|
||||||
|
qInfo() << "executable dir: " << app_dir_path2;
|
||||||
|
potential_dirs << app_dir_path2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QDir::setSearchPaths("app", potential_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
QJsonValue ConfigMgr::parseAndReadConfig(const QString &p_exp) const
|
QJsonValue ConfigMgr::parseAndReadConfig(const QString &p_exp) const
|
||||||
{
|
{
|
||||||
if (p_exp.startsWith(QStringLiteral("main."))) {
|
if (p_exp.startsWith(QStringLiteral("main."))) {
|
||||||
|
@ -120,6 +120,8 @@ namespace vnotex
|
|||||||
|
|
||||||
static QString getApplicationVersion();
|
static QString getApplicationVersion();
|
||||||
|
|
||||||
|
static void initAppPrefixPath();
|
||||||
|
|
||||||
static void initForUnitTest();
|
static void initForUnitTest();
|
||||||
|
|
||||||
static const QString c_orgName;
|
static const QString c_orgName;
|
||||||
|
@ -8,19 +8,27 @@ using namespace vnotex;
|
|||||||
|
|
||||||
QFile Logger::s_file;
|
QFile Logger::s_file;
|
||||||
|
|
||||||
bool Logger::s_debugLog = false;
|
bool Logger::s_verbose = false;
|
||||||
|
|
||||||
void Logger::init(bool p_debugLog)
|
bool Logger::s_logToStderr = false;
|
||||||
|
|
||||||
|
void Logger::init(bool p_verbose, bool p_logToStderr)
|
||||||
{
|
{
|
||||||
s_debugLog = p_debugLog;
|
s_verbose = p_verbose;
|
||||||
|
s_logToStderr = p_logToStderr;
|
||||||
|
|
||||||
#if defined(QT_NO_DEBUG)
|
#if defined(QT_NO_DEBUG)
|
||||||
|
if (!s_logToStderr) {
|
||||||
s_file.setFileName(ConfigMgr::getInst().getLogFile());
|
s_file.setFileName(ConfigMgr::getInst().getLogFile());
|
||||||
if (s_file.size() >= 5 * 1024 * 1024) {
|
if (s_file.size() >= 5 * 1024 * 1024) {
|
||||||
s_file.open(QIODevice::WriteOnly | QIODevice::Text);
|
s_file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
} else {
|
} else {
|
||||||
s_file.open(QIODevice::Append | QIODevice::Text);
|
s_file.open(QIODevice::Append | QIODevice::Text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// Always log to stderr in debug.
|
||||||
|
s_logToStderr = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qInstallMessageHandler(Logger::log);
|
qInstallMessageHandler(Logger::log);
|
||||||
@ -44,7 +52,7 @@ static QString getFileName(const char *p_file)
|
|||||||
void Logger::log(QtMsgType p_type, const QMessageLogContext &p_context, const QString &p_msg)
|
void Logger::log(QtMsgType p_type, const QMessageLogContext &p_context, const QString &p_msg)
|
||||||
{
|
{
|
||||||
#if defined(QT_NO_DEBUG)
|
#if defined(QT_NO_DEBUG)
|
||||||
if (!s_debugLog && p_type == QtDebugMsg) {
|
if (!s_verbose && p_type == QtDebugMsg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -76,7 +84,7 @@ void Logger::log(QtMsgType p_type, const QMessageLogContext &p_context, const QS
|
|||||||
|
|
||||||
QString fileName = getFileName(p_context.file);
|
QString fileName = getFileName(p_context.file);
|
||||||
|
|
||||||
#if defined(QT_NO_DEBUG)
|
if (!s_logToStderr) {
|
||||||
QTextStream stream(&s_file);
|
QTextStream stream(&s_file);
|
||||||
stream << header << (QString("(%1:%2) ").arg(fileName).arg(p_context.line))
|
stream << header << (QString("(%1:%2) ").arg(fileName).arg(p_context.line))
|
||||||
<< localMsg << "\n";
|
<< localMsg << "\n";
|
||||||
@ -85,7 +93,7 @@ void Logger::log(QtMsgType p_type, const QMessageLogContext &p_context, const QS
|
|||||||
s_file.close();
|
s_file.close();
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#else
|
} else {
|
||||||
std::string fileStr = fileName.toStdString();
|
std::string fileStr = fileName.toStdString();
|
||||||
const char *file = fileStr.c_str();
|
const char *file = fileStr.c_str();
|
||||||
|
|
||||||
@ -114,5 +122,5 @@ void Logger::log(QtMsgType p_type, const QMessageLogContext &p_context, const QS
|
|||||||
}
|
}
|
||||||
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,16 @@ namespace vnotex
|
|||||||
public:
|
public:
|
||||||
Logger() = delete;
|
Logger() = delete;
|
||||||
|
|
||||||
static void init(bool p_debugLog);
|
static void init(bool p_verbose, bool p_logToStderr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void log(QtMsgType p_type, const QMessageLogContext &p_context, const QString &p_msg);
|
static void log(QtMsgType p_type, const QMessageLogContext &p_context, const QString &p_msg);
|
||||||
|
|
||||||
static QFile s_file;
|
static QFile s_file;
|
||||||
|
|
||||||
static bool s_debugLog;
|
static bool s_verbose;
|
||||||
|
|
||||||
|
static bool s_logToStderr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -11,6 +11,7 @@
|
|||||||
#include <QWebEngineSettings>
|
#include <QWebEngineSettings>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QAccessible>
|
#include <QAccessible>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
#include <core/configmgr.h>
|
#include <core/configmgr.h>
|
||||||
#include <core/mainconfig.h>
|
#include <core/mainconfig.h>
|
||||||
@ -40,10 +41,12 @@ int main(int argc, char *argv[])
|
|||||||
QTextCodec::setCodecForLocale(codec);
|
QTextCodec::setCodecForLocale(codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
|
||||||
// This only takes effect on Win, X11 and Android.
|
// This only takes effect on Win, X11 and Android.
|
||||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Set OpenGL option on Windows.
|
// Set OpenGL option on Windows.
|
||||||
// Set environment QT_OPENGL to "angle/desktop/software".
|
// Set environment QT_OPENGL to "angle/desktop/software".
|
||||||
@ -77,6 +80,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Application app(argc, argv);
|
Application app(argc, argv);
|
||||||
|
|
||||||
|
ConfigMgr::initAppPrefixPath();
|
||||||
|
|
||||||
QAccessible::installFactory(&FakeAccessible::accessibleFactory);
|
QAccessible::installFactory(&FakeAccessible::accessibleFactory);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -135,7 +140,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init logger after app info is set.
|
// Init logger after app info is set.
|
||||||
Logger::init(cmdOptions.m_verbose);
|
Logger::init(cmdOptions.m_verbose, cmdOptions.m_logToStderr);
|
||||||
|
|
||||||
qInfo() << QString("%1 (v%2) started at %3 (%4)").arg(ConfigMgr::c_appName,
|
qInfo() << QString("%1 (v%2) started at %3 (%4)").arg(ConfigMgr::c_appName,
|
||||||
app.applicationVersion(),
|
app.applicationVersion(),
|
||||||
@ -204,42 +209,47 @@ void loadTranslators(QApplication &p_app)
|
|||||||
QLocale locale;
|
QLocale locale;
|
||||||
qInfo() << "locale:" << locale.name();
|
qInfo() << "locale:" << locale.name();
|
||||||
|
|
||||||
const QString envTranslationFolder(QStringLiteral("translations"));
|
const auto translationsPath = QDir("app:translations").absolutePath();
|
||||||
|
qInfo() << "translations dir: " << translationsPath;
|
||||||
|
if (translationsPath.isEmpty()) {
|
||||||
|
qWarning() << "failed to locate translations directory";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// For QTextEdit/QTextBrowser and other basic widgets.
|
// For QTextEdit/QTextBrowser and other basic widgets.
|
||||||
QScopedPointer<QTranslator> qtbaseTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> qtbaseTranslator(new QTranslator(&p_app));
|
||||||
if (qtbaseTranslator->load(locale, "qtbase", "_", envTranslationFolder)) {
|
if (qtbaseTranslator->load(locale, "qtbase", "_", translationsPath)) {
|
||||||
p_app.installTranslator(qtbaseTranslator.take());
|
p_app.installTranslator(qtbaseTranslator.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
// qt_zh_CN.ts does not cover the real QDialogButtonBox which uses QPlatformTheme.
|
// qt_zh_CN.ts does not cover the real QDialogButtonBox which uses QPlatformTheme.
|
||||||
QScopedPointer<QTranslator> dialogButtonBoxTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> dialogButtonBoxTranslator(new QTranslator(&p_app));
|
||||||
if (dialogButtonBoxTranslator->load(locale, "qdialogbuttonbox", "_", envTranslationFolder)) {
|
if (dialogButtonBoxTranslator->load(locale, "qdialogbuttonbox", "_", translationsPath)) {
|
||||||
p_app.installTranslator(dialogButtonBoxTranslator.take());
|
p_app.installTranslator(dialogButtonBoxTranslator.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<QTranslator> webengineTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> webengineTranslator(new QTranslator(&p_app));
|
||||||
if (webengineTranslator->load(locale, "qwebengine", "_", envTranslationFolder)) {
|
if (webengineTranslator->load(locale, "qwebengine", "_", translationsPath)) {
|
||||||
p_app.installTranslator(webengineTranslator.take());
|
p_app.installTranslator(webengineTranslator.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<QTranslator> qtTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> qtTranslator(new QTranslator(&p_app));
|
||||||
if (qtTranslator->load(locale, "qtv", "_", envTranslationFolder)) {
|
if (qtTranslator->load(locale, "qtv", "_", translationsPath)) {
|
||||||
p_app.installTranslator(qtTranslator.take());
|
p_app.installTranslator(qtTranslator.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<QTranslator> qtEnvTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> qtEnvTranslator(new QTranslator(&p_app));
|
||||||
if (qtEnvTranslator->load(locale, "qt", "_", envTranslationFolder)) {
|
if (qtEnvTranslator->load(locale, "qt", "_", translationsPath)) {
|
||||||
p_app.installTranslator(qtEnvTranslator.take());
|
p_app.installTranslator(qtEnvTranslator.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<QTranslator> vnoteTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> vnoteTranslator(new QTranslator(&p_app));
|
||||||
if (vnoteTranslator->load(locale, "vnote", "_", envTranslationFolder)) {
|
if (vnoteTranslator->load(locale, "vnote", "_", translationsPath)) {
|
||||||
p_app.installTranslator(vnoteTranslator.take());
|
p_app.installTranslator(vnoteTranslator.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<QTranslator> vtexteditTranslator(new QTranslator(&p_app));
|
QScopedPointer<QTranslator> vtexteditTranslator(new QTranslator(&p_app));
|
||||||
if (vtexteditTranslator->load(locale, "vtextedit", "_", envTranslationFolder)) {
|
if (vtexteditTranslator->load(locale, "vtextedit", "_", translationsPath)) {
|
||||||
p_app.installTranslator(vtexteditTranslator.take());
|
p_app.installTranslator(vtexteditTranslator.take());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user