Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Qt6 port #53

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.6.0)
cmake_minimum_required(VERSION 3.27.0)

project(qml-asteroid
VERSION 2.0.0
Expand All @@ -9,6 +9,7 @@ find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

option(WITH_ASTEROIDAPP "Build the AsteroidApp class" ON)
option(WITH_MAPPLAUNCHERD "Build the AsteroidApp class with Mapplauncherd booster support" ON)
option(WITH_CMAKE_MODULES "Install AsteroidOS CMake modules" ON)

include(FeatureSummary)
Expand All @@ -19,10 +20,12 @@ include(AsteroidCMakeSettings)

set(ASTEROID_MODULES_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/asteroidapp/cmake)

find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS DBus Qml Quick Svg REQUIRED)
find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS DBus Qml Quick Svg ShaderTools REQUIRED)
if (WITH_ASTEROIDAPP)
find_package(Mlite5 MODULE REQUIRED)
find_package(Mapplauncherd_qt5 MODULE REQUIRED)
find_package(Mlite6 MODULE REQUIRED)
if (WITH_MAPPLAUNCHERD)
find_package(Mapplauncherd_qt6 MODULE REQUIRED)
endif()
endif()

ecm_find_qmlmodule(QtQuick.VirtualKeyboard 2.1)
Expand Down
3 changes: 2 additions & 1 deletion cmake/AsteroidCMakeSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ if (NOT ASTEROID_SKIP_BUILD_SETTINGS)
set(INSTALL_QML_IMPORT_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/qml"
CACHE PATH "Custom QML import installation directory")

set(QT_MIN_VERSION "5.12.0")
# Ensure availability of QTP0001 (https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html)
set(QT_MIN_VERSION "6.5.0")
endif()
4 changes: 2 additions & 2 deletions cmake/AsteroidTranslations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ function(BUILD_TRANSLATIONS directory)
return()
endif()

find_package(Qt5LinguistTools REQUIRED)
find_package(Qt6LinguistTools REQUIRED)

file(GLOB LANGUAGE_FILES_TS ${directory}/*.ts)
#set_source_files_properties(${LANGUAGE_FILES_TS} PROPERTIES OUTPUT_LOCATION "i18n")
qt5_add_translation(LANGUAGE_FILES_QM ${LANGUAGE_FILES_TS} OPTIONS "-idbased")
qt_add_translation(LANGUAGE_FILES_QM ${LANGUAGE_FILES_TS} OPTIONS "-idbased")
add_custom_target(build-translations ALL
COMMENT "Building translations in ${director}..."
DEPENDS ${LANGUAGE_FILES_QM})
Expand Down
40 changes: 0 additions & 40 deletions cmake/FindMapplauncherd_qt5.cmake

This file was deleted.

40 changes: 40 additions & 0 deletions cmake/FindMapplauncherd_qt6.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Try to find qdeclarative6-boostable
# Once done this will define
# MAPPLAUNCHERD_QT6_FOUND - System has qdeclarative
# MAPPLAUNCHERD_QT6_INCLUDE_DIRS - The qdeclarative include directories
# MAPPLAUNCHERD_QT6_LIBRARIES - The libraries needed to use qdeclarative
# MAPPLAUNCHERD_QT6_DEFINITIONS - Compiler switches required for using qdeclarative

find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_Mapplauncherd_qt6 QUIET qdeclarative6-boostable)
set(Mapplauncherd_qt6_DEFINITIONS ${PC_Mapplauncherd_qt6_CFLAGS_OTHER})

find_path(Mapplauncherd_qt6_INCLUDE_DIRS
NAMES mdeclarativecache.h
PATH_SUFFIXES mdeclarativecache6
PATHS ${PC_Mapplauncherd_qt6_INCLUDEDIR} ${PC_Mapplauncherd_qt6_INCLUDE_DIRS})

find_library(Mapplauncherd_qt6_LIBRARIES
NAMES mdeclarativecache6
PATHS ${PC_Mapplauncherd_qt6_LIBDIR} ${PC_Mapplauncherd_qt6_LIBRARY_DIRS})

set(Mapplauncherd_qt6_VERSION ${PC_Mapplauncherd_qt6_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Mapplauncherd_qt6
FOUND_VAR
Mapplauncherd_qt6_FOUND
REQUIRED_VARS
Mapplauncherd_qt6_LIBRARIES
Mapplauncherd_qt6_INCLUDE_DIRS
VERSION_VAR
Mapplauncherd_qt6_VERSION)

mark_as_advanced(Mapplauncherd_qt6_INCLUDE_DIR Mapplauncherd_qt6_LIBRARY Mapplauncherd_qt6_VERSION)

if(Mapplauncherd_qt6_FOUND AND NOT TARGET Mapplauncherd_qt6::Mapplauncherd_qt6)
add_library(Mapplauncherd_qt6::Mapplauncherd_qt6 UNKNOWN IMPORTED)
set_target_properties(Mapplauncherd_qt6::Mapplauncherd_qt6 PROPERTIES
IMPORTED_LOCATION "${Mapplauncherd_qt6_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Mapplauncherd_qt6_INCLUDE_DIRS}")
endif()
40 changes: 0 additions & 40 deletions cmake/FindMlite5.cmake

This file was deleted.

40 changes: 40 additions & 0 deletions cmake/FindMlite6.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Try to find mlite6
# Once done this will define
# MLITE6_FOUND - System has mlite6
# MLITE6_INCLUDE_DIRS - The mlite6 include directories
# MLITE6_LIBRARIES - The libraries needed to use mlite6
# MLITE6_DEFINITIONS - Compiler switches required for using mlite6

find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_Mlite6 QUIET mlite6)
set(Mlite6_DEFINITIONS ${PC_Mlite6_CFLAGS_OTHER})

find_path(Mlite6_INCLUDE_DIRS
NAMES mlite-global.h
PATH_SUFFIXES mlite6
PATHS ${PC_Mlite6_INCLUDEDIR} ${PC_Mlite6_INCLUDE_DIRS})

find_library(Mlite6_LIBRARIES
NAMES mlite6
PATHS ${PC_Mlite6_LIBDIR} ${PC_Mlite6_LIBRARY_DIRS})

set(Mlite6_VERSION ${PC_Mlite6_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Mlite6
FOUND_VAR
Mlite6_FOUND
REQUIRED_VARS
Mlite6_LIBRARIES
Mlite6_INCLUDE_DIRS
VERSION_VAR
Mlite6_VERSION)

mark_as_advanced(Mlite6_INCLUDE_DIR Mlite6_LIBRARY Mlite6_VERSION)

if(Mlite6_FOUND AND NOT TARGET Mlite6::Mlite6)
add_library(Mlite6::Mlite6 UNKNOWN IMPORTED)
set_target_properties(Mlite6::Mlite6 PROPERTIES
IMPORTED_LOCATION "${Mlite6_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Mlite6_INCLUDE_DIRS}")
endif()
6 changes: 3 additions & 3 deletions generate-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if [ ! -f "${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h" ]; then
exit 2
fi

DEFAULT_NAME=$(grep -oP '//% "\K[^"]+(?=")' "${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h")
DEFAULT_NAME=$(sed -n 's/\/\/% //p' "${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h" | cut -d'"' -f2)
if [ -z "$DEFAULT_NAME" ]; then
echo "Default name can not be found in ${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h"
exit 3
Expand All @@ -59,7 +59,7 @@ echo "Name=$DEFAULT_NAME" >> "$OUTPUT_FILE"
for FILE in "${SRC_DIR}"/i18n/*.ts; do
echo "Processing $FILE..."

PROCESSED_LANG=$(grep -oP 'language="\K[^"]+(?=")' "$FILE")
PROCESSED_LANG=$(xmllint --xpath 'string(//TS/@language)' "$FILE")
if [ -z "$PROCESSED_LANG" ]; then
echo "> Couldn't find a corresponding language id, aborting"
continue
Expand All @@ -78,7 +78,7 @@ for FILE in "${SRC_DIR}"/i18n/*.ts; do
continue
fi

TRANSLATED_NAME=$(echo "$TRANSLATION_LINE" | grep -oP '>\K[^<]*(?=</translation>)')
TRANSLATED_NAME=$(echo "$TRANSLATION_LINE" | xmllint --xpath 'string(//translation)' -) # TODO: 2>/dev/null ?
if [ -z "$TRANSLATED_NAME" ]; then
echo "> Translation is empty, aborting"
continue
Expand Down
5 changes: 3 additions & 2 deletions src/app/AsteroidAppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(Qt5Qml @QT_MIN_VERSION@)
find_dependency(Qt5Quick @QT_MIN_VERSION@)
find_package(Qt6 @QT_MIN_VERSION@ COMPONENTS Qml Quick REQUIRED)

set(ASTEROID_MODULE_PATH "@PACKAGE_ASTEROID_MODULES_INSTALL_DIR@")

include("${CMAKE_CURRENT_LIST_DIR}/AsteroidAppTargets.cmake")
@PACKAGE_INCLUDE_QCHTARGETS@

qt_policy(SET QTP0001 NEW)
16 changes: 10 additions & 6 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ add_library(asteroidapp ${SRC} ${HEADERS})

target_link_libraries(asteroidapp
PUBLIC
Qt5::Qml
Qt5::Quick
Qt6::Qml
Qt6::Quick
PRIVATE
Mlite5::Mlite5
Mapplauncherd_qt5::Mapplauncherd_qt5)
Mlite6::Mlite6
$<$<BOOL:${WITH_MAPPLAUNCHERD}>:Mapplauncherd_qt6::Mapplauncherd_qt6>)

set_target_properties(asteroidapp PROPERTIES
EXPORT_NAME AsteroidApp
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION})
VERSION ${PROJECT_VERSION}
COMPILE_DEFINITIONS $<$<BOOL:${WITH_MAPPLAUNCHERD}>:WITH_MAPPLAUNCHERD=1>)

target_include_directories(asteroidapp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand All @@ -34,9 +35,12 @@ install(FILES asteroidapp.prf
DESTINATION ${CMAKE_INSTALL_LIBDIR}/mkspecs/features
COMPONENT Devel)

if (WITH_MAPPLAUNCHERD)
set(ASTEROIDAPP_PKGCONF_DEPS "qdeclarative6-boostable")
endif()
ecm_generate_pkgconfig_file(
BASE_NAME asteroidapp
DEPS qdeclarative5-boostable
DEPS ${ASTEROIDAPP_PKGCONF_DEPS}
FILENAME_VAR asteroidapp
DESCRIPTION ${PROJECT_DESCRIPTION}
INSTALL)
Expand Down
22 changes: 19 additions & 3 deletions src/app/asteroidapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include <QFileInfo>
#include <MDesktopEntry>
#include <QTranslator>
#include <mdeclarativecache5/MDeclarativeCache>
#if WITH_MAPPLAUNCHERD
#include <mdeclarativecache/MDeclarativeCache>

static QString applicationPath()
{
Expand All @@ -47,11 +48,16 @@ static QString applicationPath()
return QCoreApplication::applicationFilePath();
}
}
#endif

namespace AsteroidApp {
QString appName()
{
#if WITH_MAPPLAUNCHERD
QFileInfo exe = QFileInfo(applicationPath());
#else
QFileInfo exe = QFileInfo(QCoreApplication::applicationFilePath());
#endif
return exe.baseName();
}

Expand All @@ -60,14 +66,20 @@ namespace AsteroidApp {
static QGuiApplication *app = NULL;

if (app == NULL) {
#if WITH_MAPPLAUNCHERD
app = MDeclarativeCache::qApplication(argc, argv);
#else
app = new QGuiApplication(argc, argv);
#endif

app->setOrganizationName(appName());
app->setOrganizationDomain(appName());
app->setApplicationName(appName());

QTranslator *translator = new QTranslator();
translator->load(QLocale(), appName(), ".", "/usr/share/translations", ".qm");
if (!translator->load(QLocale(), appName(), ".", "/usr/share/translations", ".qm")) {
qDebug() << "Failed to load" << QLocale().name() << "translations for" << appName();
}
app->installTranslator(translator);
} else {
qWarning("AsteroidApp::application() called multiple times");
Expand All @@ -78,7 +90,11 @@ namespace AsteroidApp {

QQuickView *createView()
{
#if WITH_MAPPLAUNCHERD
QQuickView *view = MDeclarativeCache::qQuickView();
#else
QQuickView *view = new QQuickView;
#endif
MDesktopEntry entry("/usr/share/applications/" + appName() + ".desktop");
if (entry.isValid()) {
view->setTitle(entry.name());
Expand All @@ -94,7 +110,7 @@ namespace AsteroidApp {
{
QScopedPointer<QGuiApplication> app(AsteroidApp::application(argc, argv));
QScopedPointer<QQuickView> view(AsteroidApp::createView());
view->setSource(QUrl("qrc:/main.qml"));
view->setSource(QUrl("qrc:/qt/qml/asteroidapp/main.qml"));
view->resize(app->primaryScreen()->size());
view->show();
return app->exec();
Expand Down
2 changes: 1 addition & 1 deletion src/app/asteroidapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace AsteroidApp {
ASTEROIDAPP_EXPORT QGuiApplication *application(int &argc, char **argv);
ASTEROIDAPP_EXPORT QQuickView *createView();

// Very simple interface: Uses "qrc:/main.qml" as QML entry point
// Very simple interface: Uses "qrc:/qt/qml/asteroidapp/main.qml" as QML entry point
ASTEROIDAPP_EXPORT int main(int &argc, char **argv);
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/asteroidapp.prf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ QT += quick qml

target.path = /usr/bin

desktop.commands = bash $$_PRO_FILE_PWD_/i18n/generate-desktop.sh $$_PRO_FILE_PWD_ $${TARGET}.desktop
desktop.commands = sh $$_PRO_FILE_PWD_/i18n/generate-desktop.sh $$_PRO_FILE_PWD_ $${TARGET}.desktop
desktop.files = $$OUT_PWD/$${TARGET}.desktop
desktop.path = /usr/share/applications
desktop.CONFIG = no_check_exist
Expand Down
Loading