Skip to content

Commit

Permalink
Modernized QML and resource integration using cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Aug 14, 2023
1 parent 31a1929 commit d2360fe
Show file tree
Hide file tree
Showing 196 changed files with 787 additions and 724 deletions.
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[submodule "lib/fontawesome.pri"]
path = thirdparty/fontawesome.pri
url = https://github.com/PhilInTheGaps/fontawesome.pri

[submodule "lib/o2"]
path = thirdparty/o2
url = https://github.com/pipacs/o2
Expand All @@ -15,3 +11,6 @@
[submodule "thirdparty/sentry-native"]
path = thirdparty/sentry-native
url = https://github.com/getsentry/sentry-native
[submodule "thirdparty/qml-icon-fonts"]
path = thirdparty/qml-icon-fonts
url = https://github.com/PhilInTheGaps/qml-icon-fonts
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ if (EXISTS ${CGET_TOOLCHAIN_FILE})
message(STATUS "Found CGet toolchain file: ${CGET_TOOLCHAIN_FILE}")
endif()

find_package(Qt6 COMPONENTS Core REQUIRED)
qt_standard_project_setup(REQUIRES 6.5)
set(CMAKE_AUTORCC ON) # turn on automatic invocation of the RCC
add_compile_definitions(QT_DEPRECATED_WARNINGS)

# set c++ version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -32,6 +27,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# set external lib dir
set(EXTERNAL_LIB_DIR ${CMAKE_SOURCE_DIR}/thirdparty)

find_package(Qt6 COMPONENTS Core Gui Quick QuickControls2 Qml Multimedia Network DBus Concurrent Core5Compat LinguistTools Test REQUIRED)
find_package(QuaZip-Qt6 REQUIRED)
find_package(QtKeychain REQUIRED)

qt_standard_project_setup(REQUIRES 6.5)
set(CMAKE_AUTORCC ON) # turn on automatic invocation of the RCC
add_compile_definitions(QT_DEPRECATED_WARNINGS)

# set version number
include(SetVersionNumber)

Expand All @@ -49,12 +52,19 @@ message(STATUS "Build directory: ${CMAKE_CURRENT_BINARY_DIR}")

enable_testing(true)

include(AddPoppler)
include(AddTagLib)
include(AddGSL)
include(AddPropertyHelper)
include(AddHttpStatusCodes)
include(AddMarkdownLib)
include(AddO2)

set(SENTRY_ENABLE_INSTALL ON)
add_subdirectory(thirdparty/sentry-native)

add_subdirectory(thirdparty/qml-icon-fonts)

# Code Coverage
if (ENABLE_CODE_COVERAGE)
include(CodeCoverage)
Expand Down
35 changes: 7 additions & 28 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
cmake_minimum_required(VERSION 3.19)

include(AddFontAwesome)

# set QML import path
list(APPEND QML_IMPORT_PATH ${FONT_AWESOME_DIR})
list(APPEND QML_IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ui")
list(REMOVE_DUPLICATES QML_IMPORT_PATH)
set(QML_IMPORT_PATH ${QML_IMPORT_PATH} CACHE STRING "Qt Creator extra qml import paths" FORCE)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick QuickControls2 Qml LinguistTools)
find_library(GM-COMPANION-LIB_DIR gm-companion-lib)

# sources
add_subdirectory(ui)

set(SOURCES
main.cpp
logger.cpp
Expand All @@ -29,31 +21,17 @@ set(HEADERS
messages/message.h
)

# resources
set(RESOURCES
resources/resources.qrc
ui/qml.qrc
ui/CustomComponents/components.qrc
)

# rc files
set(RCFILES
gm-companion.rc
)

# translations
set(TRANSLATIONS
resources/translations/gm-companion_de_DE.ts
resources/translations/gm-companion_en_US.ts
)

qt_add_executable(gm-companion ${SOURCES} ${HEADERS} ${RESOURCES} ${RCFILES})
qt_add_executable(gm-companion ${SOURCES} ${HEADERS} ${RCFILES})

if (BUILD_TRANSLATIONS)
qt_add_translations(gm-companion
TS_FILES
resources/translations/gm-companion_de_DE.ts
resources/translations/gm-companion_en_US.ts
i18n/gm-companion_de_DE.ts
i18n/gm-companion_en_US.ts
INCLUDE_DIRECTORIES
.
../src
Expand All @@ -67,12 +45,13 @@ target_include_directories(gm-companion PRIVATE

target_link_libraries(gm-companion PRIVATE
gm-companion-lib
gm-companion-ui
gm-companion-uiplugin
Qt6::Core
Qt6::Gui
Qt6::Quick
Qt6::QuickControls2
Qt6::Qml
fontawesome
sentry
)

Expand Down
2 changes: 1 addition & 1 deletion app/gm-companion.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IDI_ICON1 ICON DISCARDABLE "resources/icons/gm-companion.ico"
IDI_ICON1 ICON DISCARDABLE "ui/resources/icons/gm-companion.ico"

#include <windows.h>
#include "version.h"
Expand Down
File renamed without changes.
File renamed without changes.
60 changes: 23 additions & 37 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include <QScopeGuard>
#include <QTranslator>
#include <QtQuickControls2/QQuickStyle>

#include <sentry.h>

#include "addons/addonmanager.h"
#include "filesystem/file.h"
#include "filesystem/fileaccessswitcher.h"
Expand All @@ -26,6 +24,8 @@
#include "tools.h"
#include "updates/updatemanager.h"

using namespace Qt::Literals::StringLiterals;

Q_LOGGING_CATEGORY(gmMain, "gm.main")

Q_DECLARE_METATYPE(QFuture<void>)
Expand All @@ -50,8 +50,7 @@ void initTranslations()
qCDebug(gmMain()) << "Initializing translations ...";
auto *translator = new QTranslator;

if (translator->load(SettingsManager::getLanguage(), QStringLiteral("gm-companion"), QStringLiteral("_"),
QStringLiteral(":/i18n")))
if (translator->load(SettingsManager::getLanguage(), u"gm-companion"_s, u"_"_s, u":/i18n"_s))
{
QGuiApplication::installTranslator(translator);

Expand All @@ -63,23 +62,19 @@ void initTranslations()
}
}

/// Install fonts for FontAwesome.pri
void initResources()
{
Q_INIT_RESOURCE(fontawesome);
Q_INIT_RESOURCE(libresources);
QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fa-solid.ttf"));
QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fa-regular.ttf"));
QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fa-brands.ttf"));
Q_INIT_RESOURCE(services_resources);
}

auto main(int argc, char *argv[]) -> int
{
QGuiApplication app(argc, argv);
QGuiApplication::setApplicationName(QStringLiteral("GM-Companion"));
QGuiApplication::setOrganizationName(QStringLiteral("GM-Companion"));
QGuiApplication::setOrganizationDomain(QStringLiteral("gm-companion.github.io"));
QGuiApplication::setWindowIcon(QIcon(":/icons/icon.png"));
QGuiApplication::setApplicationName(u"GM-Companion"_s);
QGuiApplication::setOrganizationName(u"GM-Companion"_s);
QGuiApplication::setOrganizationDomain(u"gm-companion.github.io"_s);
QGuiApplication::setWindowIcon(QIcon(u":/resources/icons/icon.png"_s));

#if defined(Q_OS_WIN)
app.setFont(QFont("Segoe UI"));
Expand All @@ -95,17 +90,14 @@ auto main(int argc, char *argv[]) -> int

// Sentry.io crash reporting
// Crash reports and session tracking are opt-in settings
if (SettingsManager::instance()->get(QStringLiteral("crashReports"), false, QStringLiteral("Telemetry")))
if (SettingsManager::instance()->get(u"crashReports"_s, false, u"Telemetry"_s))
{
qCDebug(gmMain()) << "Crash reports are enabled!";
auto *sentryOptions = sentry_options_new();
sentry_options_set_dsn(sentryOptions,
"https://[email protected]/6375554");
sentry_options_set_release(sentryOptions,
QStringLiteral("gm-companion@%1").arg(CURRENT_VERSION).toUtf8().data());
sentry_options_set_dsn(sentryOptions, "https://[email protected]/6375554");
sentry_options_set_release(sentryOptions, u"gm-companion@%1"_s.arg(CURRENT_VERSION).toUtf8().data());

auto isSessionTrackingEnabled =
SettingsManager::instance()->get(QStringLiteral("sessionTracking"), false, QStringLiteral("Telemetry"));
auto isSessionTrackingEnabled = SettingsManager::instance()->get(u"sessionTracking"_s, false, u"Telemetry"_s);
sentry_options_set_auto_session_tracking(sentryOptions, isSessionTrackingEnabled ? 1 : 0);
if (isSessionTrackingEnabled) qCDebug(gmMain()) << "Session tracking is enabled!";

Expand All @@ -116,13 +108,8 @@ auto main(int argc, char *argv[]) -> int

auto sentryClose = qScopeGuard([] { sentry_close(); });

// Make classes available for QML
QUrl const source(QStringLiteral("qrc:/main.qml"));

QQuickStyle::setStyle(QStringLiteral("style"));

QQuickStyle::setStyle(u"Style"_s);
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral("qrc:/"));

// Misc
QNetworkAccessManager networkManager(nullptr);
Expand All @@ -132,18 +119,17 @@ auto main(int argc, char *argv[]) -> int
GoogleDrive gd(networkManager, nullptr);
Files::File::init(&nc, &gd);

engine.rootContext()->setContextProperty(QStringLiteral("settings_manager"), new QuickSettingsManager);
engine.rootContext()->setContextProperty(QStringLiteral("update_manager"), new UpdateManager);
engine.rootContext()->setContextProperty(QStringLiteral("addon_manager"), AddonManager::instance());
engine.rootContext()->setContextProperty(QStringLiteral("addon_repository_manager"),
&(AddonManager::instance()->repositoryManager()));
engine.rootContext()->setContextProperty(QStringLiteral("message_manager"), MessageManager::instance());
engine.addImageProvider(QStringLiteral("audioElementIcons"), new AudioThumbnailProvider);
engine.rootContext()->setContextProperty(u"settings_manager"_s, new QuickSettingsManager);
engine.rootContext()->setContextProperty(u"update_manager"_s, new UpdateManager);
engine.rootContext()->setContextProperty(u"addon_manager"_s, AddonManager::instance());
engine.rootContext()->setContextProperty(u"addon_repository_manager"_s, &(AddonManager::instance()->repositoryManager()));
engine.rootContext()->setContextProperty(u"message_manager"_s, MessageManager::instance());
engine.addImageProvider(u"audioElementIcons"_s, new AudioThumbnailProvider);

// Services
engine.rootContext()->setContextProperty(QStringLiteral("spotify_service"), Spotify::instance());
engine.rootContext()->setContextProperty(QStringLiteral("googledrive_service"), &gd);
engine.rootContext()->setContextProperty(QStringLiteral("nextcloud_service"), &nc);
engine.rootContext()->setContextProperty(u"spotify_service"_s, Spotify::instance());
engine.rootContext()->setContextProperty(u"googledrive_service"_s, &gd);
engine.rootContext()->setContextProperty(u"nextcloud_service"_s, &nc);

// Load tools
const AudioTool audioTool(&engine);
Expand All @@ -156,7 +142,7 @@ auto main(int argc, char *argv[]) -> int
const NotesTool notesTool(&engine);
const ConverterTool converterTool(&engine);

engine.load(source);
engine.loadFromModule("ui"_L1, "Main"_L1);

if (engine.rootObjects().isEmpty()) return -1;

Expand Down
26 changes: 0 additions & 26 deletions app/resources/resources.qrc

This file was deleted.

Loading

0 comments on commit d2360fe

Please sign in to comment.