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

Port to Qt 6 #11

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ on:
- develop

jobs:
linux-qt5:
uses: lirios/.github/.github/workflows/build-linux-qt5.yml@master
linux-qt6:
uses: lirios/.github/.github/workflows/build-linux-qt6.yml@master
with:
dependencies: "solid-devel"
build_dependencies: "cmake-shared qtgsettings libliri aurora-scanner aurora-compositor session"
dependencies: "kf6-solid-devel"
build_dependencies: "cmake-shared qtgsettings libliri session"
54 changes: 26 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
cmake_minimum_required(VERSION 3.10.0)
cmake_minimum_required(VERSION 3.19)

project("PowerManager"
VERSION "0.9.0"
DESCRIPTION "Power management support"
LANGUAGES CXX C
)

## Shared macros and functions:
if(NOT LIRI_LOCAL_ECM)
find_package(LiriCMakeShared "2.0.0" REQUIRED NO_MODULE)
list(APPEND CMAKE_MODULE_PATH "${LCS_MODULE_PATH}")
endif()

## Set minimum versions required:
set(QT_MIN_VERSION "5.10.0")
set(KF5_MIN_VERSION "5.48.0")

## Liri specific setup common for all modules:
include(LiriSetup)

## Only build on the appropriate platforms.
if(NOT UNIX OR ANDROID)
message(NOTICE "Skipping the build as the condition \"UNIX OR ANDROID\" is not met.")
return()
endif()

## ECM:
find_package(ECM 5.245.0 REQUIRED NO_MODULE)
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})

## Installation directories:
include(KDEInstallDirs)

## Compiler settings:
set(KDE_SKIP_NULLPTR_WARNINGS_SETTINGS TRUE)
include(KDECompilerSettings NO_POLICY_SCOPE)

## CMake settings:
include(KDECMakeSettings)

## QML module:
include(ECMQmlModule)

## Disable use of C++ API deprecated in Qt 5.15
add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x050F00)

## Features:
include(features.cmake)

## Features:
option(LIRI_ENABLE_SYSTEMD "Enable systemd support" ON)
add_feature_info("Liri::Systemd" LIRI_ENABLE_SYSTEMD "Enable systemd support")

## Variables:
if(LIRI_ENABLE_SYSTEMD)
set(INSTALL_SYSTEMDUSERUNITDIR "${INSTALL_LIBDIR}/systemd/user" CACHE PATH "systemd user unit directory [PREFIX/lib/systemd/user]")
set(INSTALL_SYSTEMDUSERUNITDIR "${KDE_INSTALL_LIBDIR}/systemd/user" CACHE PATH "systemd user unit directory [PREFIX/lib/systemd/user]")
endif()

## Find Qt 5:
find_package(Qt5 "${QT_MIN_VERSION}"
CONFIG REQUIRED
COMPONENTS
Core
DBus
Gui
Qml
Quick
LinguistTools
)

## Add subdirectories:
add_subdirectory(data/settings)
if(LIRI_ENABLE_SYSTEMD)
Expand All @@ -54,4 +52,4 @@ endif()
add_subdirectory(src/imports/power)
add_subdirectory(src/daemon)
add_subdirectory(src/settings/power)
add_subdirectory(src/statusarea/power)
#add_subdirectory(src/statusarea/power)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Power management support for Liri.

## Dependencies

Qt >= 5.10.0 with at least the following modules is required:
Qt >= 6.7 with at least the following modules is required:

* [qtbase](http://code.qt.io/cgit/qt/qtbase.git)
* [qtdeclarative](http://code.qt.io/cgit/qt/qtdeclarative.git)
Expand All @@ -23,8 +23,8 @@ The following modules and their dependencies are required:

* [cmake](https://gitlab.kitware.com/cmake/cmake) >= 3.10.0
* [cmake-shared](https://github.com/lirios/cmake-shared.git) >= 1.0.0
* [fluid](https://github.com/lirios/fluid) >= 1.0.0
* [qtgsettings](https://github.com/lirios/qtgsettings) >= 1.1.0
* [fluid](https://github.com/lirios/fluid) >= 2.0.0
* [qtgsettings](https://github.com/lirios/qtgsettings) >= 2.0.0
* [libliri](https://github.com/lirios/libliri.git)
* [solid](http://quickgit.kde.org/?p=solid.git)

Expand Down
2 changes: 1 addition & 1 deletion data/settings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
file(GLOB _files "*.xml")
install(FILES ${_files} DESTINATION "${INSTALL_DATADIR}/glib-2.0/schemas")
install(FILES ${_files} DESTINATION "${KDE_INSTALL_DATADIR}/glib-2.0/schemas")
6 changes: 1 addition & 5 deletions data/systemd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
if(IS_ABSOLUTE "${INSTALL_LIBEXECDIR}")
set(ABSOLUTE_LIBEXECDIR "${INSTALL_LIBEXECDIR}")
else()
set(ABSOLUTE_LIBEXECDIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_LIBEXECDIR}")
endif()
set(LIBEXECDIR "${KDE_INSTALL_LIBEXECDIR}")
configure_file(
"liri-daemon-power.service.in"
"${CMAKE_CURRENT_BINARY_DIR}/liri-daemon-power.service"
Expand Down
2 changes: 1 addition & 1 deletion data/systemd/liri-daemon-power.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ PartOf=liri-daemons.target

[Service]
Type=dbus
ExecStart=@ABSOLUTE_LIBEXECDIR@/liri-daemon --module=power
ExecStart=@LIBEXECDIR@/liri-daemon --module=power
BusName=io.liri.Daemon.Modules.Power
Restart=on-failure
34 changes: 34 additions & 0 deletions features.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2024 Pier Luigi Fiorini <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause

## Enable feature summary at the end of the configure run:
include(FeatureSummary)

## Set minimum versions required:
set(QT_MIN_VERSION "6.7.0")
set(KF6_MIN_VERSION "6.1.0")

## Find Qt:
find_package(Qt6 "${QT_MIN_VERSION}"
REQUIRED
COMPONENTS
Core
DBus
Gui
Qml
Quick
LinguistTools
)

# Find Solid:
find_package(KF6Solid "${KF6_MIN_VERSION}" REQUIRED)

#### Features

option(LIRI_ENABLE_SYSTEMD "Enable systemd support" ON)
add_feature_info("Liri::Systemd" LIRI_ENABLE_SYSTEMD "Enable systemd support")

## Features summary:
if(NOT LIRI_SUPERBUILD)
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
endif()
69 changes: 37 additions & 32 deletions src/daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
find_package(KF5Solid "${KF5_MIN_VERSION}" REQUIRED)

if(NOT TARGET Liri::Qt5GSettings)
find_package(Qt5GSettings REQUIRED)
if(NOT TARGET Liri::Qt6GSettings)
find_package(Qt6GSettings REQUIRED)
endif()
if(NOT TARGET Liri::Core)
find_package(Liri1Core REQUIRED)
Expand All @@ -16,40 +14,47 @@ if(NOT TARGET Liri::Daemon)
find_package(Liri1Daemon REQUIRED)
endif()

# Translations
file(GLOB LiriPowerManager_TRANSLATIONS "${CMAKE_CURRENT_SOURCE_DIR}/../../translations/daemon/*_*.ts")
qt5_add_translation(LiriPowerManager_QM_FILES ${LiriPowerManager_TRANSLATIONS})
install(FILES ${LiriPowerManager_QM_FILES}
DESTINATION "${INSTALL_DATADIR}/liri-power-manager/translations")
qt_add_plugin(LiriDaemonPowerPlugin
CLASS_NAME PowerPlugin
MANUAL_FINALIZATION
batterywatcher.cpp batterywatcher.h
idlewatcher.cpp idlewatcher.h
lidwatcher.cpp lidwatcher.h
plugin.cpp plugin.h
powermanager.cpp powermanager.h
translation.cpp translation.h
)

liri_add_plugin(power
TYPE
liri/daemon
SOURCES
batterywatcher.cpp
batterywatcher.h
idlewatcher.cpp
idlewatcher.h
lidwatcher.cpp
lidwatcher.h
plugin.cpp
plugin.h
powermanager.cpp
powermanager.h
translation.cpp
translation.h
${LiriPowerManager_QM_FILES}
DEFINES
set_target_properties(LiriDaemonPowerPlugin PROPERTIES
OUTPUT_NAME power
)

target_compile_definitions(LiriDaemonPowerPlugin
PRIVATE
QT_NO_CAST_FROM_ASCII
QT_NO_FOREACH
LIBRARIES
Qt5::DBus
)

target_link_libraries(LiriDaemonPowerPlugin
PRIVATE
Qt6::Core
Qt6::DBus
Liri::Daemon
Liri::Qt5GSettings
Liri::Qt6GSettings
Liri::Core
Liri::LocalDevice
Liri::Notifications
KF5::Solid
KF6::Solid
)

liri_finalize_plugin(power)
qt_finalize_target(LiriDaemonPowerPlugin)

file(GLOB ts_files "${CMAKE_CURRENT_SOURCE_DIR}/../../translations/daemon/liri-power-manager_*.ts")
qt_add_translations(LiriDaemonPowerPlugin
TS_FILES ${ts_files}
)

install(
TARGETS LiriDaemonPowerPlugin
DESTINATION ${KDE_INSTALL_PLUGINDIR}/liri/daemon
)
2 changes: 1 addition & 1 deletion src/daemon/powermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <QObject>

#include <Qt5GSettings/QGSettings>
#include <Qt6GSettings/QGSettings>

class PowerManager : public QObject
{
Expand Down
9 changes: 1 addition & 8 deletions src/daemon/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,9 @@ void loadDaemonTranslations()
#ifndef QT_NO_TRANSLATION
QString locale = QLocale::system().name();

// Find the translations directory
const QString path = QLatin1String("liri-power-manager/translations");
const QString translationsDir =
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
path,
QStandardPaths::LocateDirectory);

// Load translations
QTranslator *appTranslator = new QTranslator(QCoreApplication::instance());
if (appTranslator->load(QStringLiteral("%1/liri-power-manager_%2").arg(translationsDir, locale))) {
if (appTranslator->load(QStringLiteral(":/i18n/liri-power-manager_%1").arg(locale))) {
QCoreApplication::installTranslator(appTranslator);
} else if (locale == QLatin1String("C") ||
locale.startsWith(QLatin1String("en"))) {
Expand Down
44 changes: 23 additions & 21 deletions src/imports/power/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
find_package(KF5Solid "${KF5_MIN_VERSION}" REQUIRED)

if(NOT TARGET Liri::Core)
find_package(Liri1Core REQUIRED)
endif()

liri_add_qml_plugin(PowerQmlPlugin
MODULE_PATH
"Liri/Power"
VERSION
"1.0"
OUTPUT_NAME
"powerplugin"
SOURCES
batteriesmodel.cpp
batteriesmodel.h
battery.cpp
battery.h
plugin.cpp
QML_FILES
qmldir
DEFINES
ecm_add_qml_module(PowerQmlPlugin
URI Liri.Power
VERSION 1.0
CLASS_NAME PowerPlugin
DEPENDENCIES QtQuick
)

target_sources(PowerQmlPlugin
PRIVATE
batteriesmodel.cpp batteriesmodel.h
battery.cpp battery.h
)

target_compile_definitions(PowerQmlPlugin
PRIVATE
QT_NO_CAST_FROM_ASCII
QT_NO_FOREACH
LIBRARIES
)

target_link_libraries(PowerQmlPlugin
PRIVATE
Qt6::Core
Qt6::Qml
Liri::Core
KF5::Solid
KF6::Solid
)

liri_finalize_qml_plugin(PowerQmlPlugin)
ecm_finalize_qml_module(PowerQmlPlugin)
17 changes: 5 additions & 12 deletions src/imports/power/batteriesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ BatteriesModel::BatteriesModel(QObject *parent)

Battery *BatteriesModel::primaryBattery() const
{
for (auto battery : qAsConst(m_batteries)) {
for (auto battery : std::as_const(m_batteries)) {
if (battery->type() == Battery::PrimaryBattery)
return battery;
}
Expand Down Expand Up @@ -115,9 +115,6 @@ QHash<int, QByteArray> BatteriesModel::roleNames() const
roles.insert(EnergyRateRole, QByteArrayLiteral("energyRate"));
roles.insert(VoltageRole, QByteArrayLiteral("voltage"));
roles.insert(TemperatureRole, QByteArrayLiteral("temperature"));
roles.insert(IsRecalledRole, QByteArrayLiteral("isRecalled"));
roles.insert(RecallVendorRole, QByteArrayLiteral("recallVendor"));
roles.insert(RecallUrlRole, QByteArrayLiteral("recallUrl"));
roles.insert(VendorRole, QByteArrayLiteral("vendor"));
roles.insert(ProductRole, QByteArrayLiteral("product"));
roles.insert(SerialRole, QByteArrayLiteral("serial"));
Expand All @@ -142,7 +139,7 @@ QVariant BatteriesModel::data(const QModelIndex &index, int role) const

switch (role) {
case BatteryRole:
return qVariantFromValue(battery);
return QVariant::fromValue(battery);
case UdiRole:
return battery->udi();
case NameRole:
Expand Down Expand Up @@ -182,14 +179,8 @@ QVariant BatteriesModel::data(const QModelIndex &index, int role) const
return battery->voltage();
case TemperatureRole:
return battery->temperature();
case IsRecalledRole:
return battery->isRecalled();
case RecallVendorRole:
return battery->recallVendor();
case RecallUrlRole:
return battery->recallUrl();
case VendorRole:
return battery->recallVendor();
return battery->vendor();
case ProductRole:
return battery->product();
case SerialRole:
Expand All @@ -198,3 +189,5 @@ QVariant BatteriesModel::data(const QModelIndex &index, int role) const

return QVariant();
}

#include "moc_batteriesmodel.cpp"
Loading
Loading