Skip to content

Commit

Permalink
More updates for Qt 6 and ECM
Browse files Browse the repository at this point in the history
Closes: #12
  • Loading branch information
plfiorini committed Dec 2, 2023
1 parent 96ca746 commit ccd972c
Show file tree
Hide file tree
Showing 23 changed files with 182 additions and 343 deletions.
70 changes: 42 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
cmake_minimum_required(VERSION 3.10.0)
cmake_minimum_required(VERSION 3.19)

project("QtAccountsService"
VERSION "1.4.0"
DESCRIPTION "Qt-style API for Accounts Service"
LANGUAGES CXX C
)

## Only build on the appropriate platforms.
if(NOT UNIX OR CMAKE_SYSTEM_NAME MATCHES "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)

## Treat warnings as errors:
add_compile_options(-Wall -Wextra -Werror)

## CMake settings:
include(KDECMakeSettings)

## QML module:
include(ECMQmlModule)

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

## Set minimum versions required:
set(QT_MIN_VERSION "6.4.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()

## Features:
option(QTACCOUNTSSERVICE_WITH_EXAMPLES "Build examples" ON)
add_feature_info("QtAccountsService Examples" QTACCOUNTSSERVICE_WITH_EXAMPLES "Build QtAccountsService examples")

## Find Qt 5:
find_package(Qt6 "${QT_MIN_VERSION}"
CONFIG REQUIRED
COMPONENTS
Core
DBus
Gui
Qml
Quick
QuickTest
)
include(features.cmake)

## Treat warnings as errors:
add_compile_options(-Wall -Wextra -Werror)
## Project setup:
qt6_standard_project_setup(REQUIRES 6.6)

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

## QML import path:
if(NOT QML_IMPORT_PATH)
set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/bin CACHE STRING "" FORCE)
endif()

## Add subdirectories:
add_subdirectory(src/accountsservice)
Expand All @@ -51,7 +63,9 @@ if(QTACCOUNTSSERVICE_WITH_EXAMPLES)
add_subdirectory(examples/useraccount)
add_subdirectory(examples/userslistview)
endif()
add_subdirectory(src/imports/accountsservice)
if(TARGET Liri::Qt6AccountsService)
add_subdirectory(src/imports/accountsservice)
endif()
if(BUILD_TESTING)
add_subdirectory(tests/auto/api)
endif()
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ For more information [read here](http://www.freedesktop.org/wiki/Software/Accoun

## Dependencies

Qt >= 5.8.0 with at least the following modules is required:
Qt >= 6.6.0 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)

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
* [cmake](https://gitlab.kitware.com/cmake/cmake) >= 3.19.0
* [extra-cmake-modules](https://invent.kde.org/frameworks/extra-cmake-modules) >= 5.245.0
* [cmake-shared](https://github.com/lirios/cmake-shared.git) >= 2.0.99

## Installation

Expand Down
13 changes: 6 additions & 7 deletions examples/listusers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
liri_add_executable(listusers
SOURCES
main.cpp
LIBRARIES
qt6_add_executable(listusers
main.cpp
)

target_link_libraries(listusers
PRIVATE
Qt6::Core
Liri::Qt6AccountsService
NO_TARGET_INSTALLATION
)

liri_finalize_executable(listusers)
21 changes: 11 additions & 10 deletions examples/loggedinuser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
liri_add_executable(loggedinuser
SOURCES
loggedinuser.qml
main.cpp
RESOURCES
resources.qrc
LIBRARIES
set(SOURCES
loggedinuser.qml
main.cpp
)

qt6_add_resources(SOURCES resources.qrc)

qt6_add_executable(loggedinuser ${SOURCES})

target_link_libraries(loggedinuser
PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Qml
NO_TARGET_INSTALLATION
)

liri_finalize_executable(loggedinuser)
21 changes: 11 additions & 10 deletions examples/useraccount/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
liri_add_executable(useraccount
SOURCES
main.cpp
useraccount.qml
RESOURCES
resources.qrc
LIBRARIES
set(SOURCES
main.cpp
useraccount.qml
)

qt6_add_resources(SOURCES resources.qrc)

qt6_add_executable(useraccount ${SOURCES})

target_link_libraries(useraccount
PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Qml
NO_TARGET_INSTALLATION
)

liri_finalize_executable(useraccount)
21 changes: 11 additions & 10 deletions examples/userslistview/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
liri_add_executable(userslistview
SOURCES
main.cpp
userslistview.qml
RESOURCES
resources.qrc
LIBRARIES
set(SOURCES
main.cpp
userslistview.qml
)

qt6_add_resources(SOURCES resources.qrc)

qt6_add_executable(userslistview ${SOURCES})

target_link_libraries(userslistview
PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Qml
NO_TARGET_INSTALLATION
)

liri_finalize_executable(userslistview)
27 changes: 27 additions & 0 deletions features.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: 2023 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
# SPDX-License-Identifier: BSD-3-Clause

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

## Find Qt:
find_package(Qt6
REQUIRED
COMPONENTS
Core
DBus
Qml
QmlIntegration
Quick
QuickTest
)

#### Features

option(QTACCOUNTSSERVICE_WITH_EXAMPLES "Build examples" ON)
add_feature_info("QtAccountsService Examples" QTACCOUNTSSERVICE_WITH_EXAMPLES "Build QtAccountsService examples")

## Features summary:
if(NOT LIRI_SUPERBUILD)
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
endif()
27 changes: 12 additions & 15 deletions src/accountsservice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
qt6_add_dbus_interfaces(
SOURCES
org.freedesktop.Accounts.xml
org.freedesktop.Accounts.User.xml
)

liri_add_module(Qt6AccountsService
DESCRIPTION
"Qt style API for Accounts Service"
Expand All @@ -6,29 +12,20 @@ liri_add_module(Qt6AccountsService
VERSIONED_MODULE_NAME
Qt6AccountsService
SOURCES
accountsmanager.cpp
accountsmanager.h
accountsmanager_p.h
useraccount.cpp
useraccount.h
useraccount_p.h
usersmodel.cpp
usersmodel.h
usersmodel_p.h
DBUS_INTERFACE_SOURCES
org.freedesktop.Accounts.xml
org.freedesktop.Accounts.User.xml
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_FOREACH
accountsmanager.cpp accountsmanager.h accountsmanager_p.h
useraccount.cpp useraccount.h useraccount_p.h
usersmodel.cpp usersmodel.h usersmodel_p.h
${SOURCES}
PUBLIC_LIBRARIES
Qt6::Core
Qt6::DBus
Qt6::Gui
Qt6::QmlIntegration
PKGCONFIG_DEPENDENCIES
Qt6Core
Qt6DBus
Qt6Gui
Qt6QmlIntegration
)

liri_finalize_module(Qt6AccountsService)
6 changes: 3 additions & 3 deletions src/accountsservice/accountsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void AccountsManager::cacheUser(const QString &userName)

QDBusPendingCall call = d->interface->CacheUser(userName);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *w) {
connect(watcher, &QDBusPendingCallWatcher::finished, this, [&](QDBusPendingCallWatcher *w) {
QDBusPendingReply<QDBusObjectPath> reply = *w;
w->deleteLater();
if (reply.isError()) {
Expand Down Expand Up @@ -162,7 +162,7 @@ void AccountsManager::uncacheUser(const QString &userName)

QDBusPendingCall call = d->interface->UncacheUser(userName);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *w) {
connect(watcher, &QDBusPendingCallWatcher::finished, this, [&](QDBusPendingCallWatcher *w) {
QDBusPendingReply<QDBusObjectPath> reply = *w;
w->deleteLater();
if (reply.isError()) {
Expand Down Expand Up @@ -195,7 +195,7 @@ void AccountsManager::listCachedUsers()

QDBusPendingCall call = d->interface->ListCachedUsers();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *w) {
connect(watcher, &QDBusPendingCallWatcher::finished, this, [&](QDBusPendingCallWatcher *w) {
QDBusPendingReply<QList<QDBusObjectPath>> reply = *w;
w->deleteLater();
if (reply.isError()) {
Expand Down
6 changes: 4 additions & 2 deletions src/accountsservice/accountsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#ifndef QTACCOUNTSSERVICE_ACCOUNTSMANAGER_H
#define QTACCOUNTSSERVICE_ACCOUNTSMANAGER_H

#include <QtCore/QObject>
#include <QtDBus/QDBusConnection>
#include <QObject>
#include <QDBusConnection>
#include <QtQmlIntegration>

#include <Qt6AccountsService/UserAccount>

Expand All @@ -38,6 +39,7 @@ class AccountsManagerPrivate;
class QT6ACCOUNTSSERVICE_EXPORT AccountsManager : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit AccountsManager(const QDBusConnection &bus = QDBusConnection::systemBus(),
QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/accountsservice/accountsmanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef QTACCOUNTSSERVICE_ACCOUNTSMANAGER_P_H
#define QTACCOUNTSSERVICE_ACCOUNTSMANAGER_P_H

#include "accounts_interface.h"
#include "accountsinterface.h"

//
// W A R N I N G
Expand Down
8 changes: 5 additions & 3 deletions src/accountsservice/useraccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
#ifndef QTACCOUNTSSERVICE_USERACCOUNT_H
#define QTACCOUNTSSERVICE_USERACCOUNT_H

#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtDBus/QDBusConnection>
#include <QObject>
#include <QString>
#include <QDBusConnection>
#include <QtQmlIntegration>

#include <Qt6AccountsService/qt6accountsserviceglobal.h>

Expand Down Expand Up @@ -66,6 +67,7 @@ class QT6ACCOUNTSSERVICE_EXPORT UserAccount : public QObject
Q_PROPERTY(QString location READ location WRITE setLocation NOTIFY locationChanged)
Q_PROPERTY(QString xsession READ xsession WRITE setXSession NOTIFY xsessionChanged)
Q_DECLARE_PRIVATE(UserAccount)
QML_ELEMENT
public:
enum AccountType { StandardAccountType = 0, AdministratorAccountType };
Q_ENUM(AccountType)
Expand Down
2 changes: 1 addition & 1 deletion src/accountsservice/useraccount_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define QTACCOUNTSSERVICE_USERACCOUNT_P_H

#include "useraccount.h"
#include "user_interface.h"
#include "userinterface.h"

//
// W A R N I N G
Expand Down
4 changes: 3 additions & 1 deletion src/accountsservice/usersmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#ifndef QTACCOUNTSSERVICE_USERSMODEL_H
#define QTACCOUNTSSERVICE_USERSMODEL_H

#include <QtCore/QAbstractListModel>
#include <QAbstractListModel>
#include <QtQmlIntegration>

#include <Qt6AccountsService/qt6accountsserviceglobal.h>

Expand All @@ -37,6 +38,7 @@ class QT6ACCOUNTSSERVICE_EXPORT UsersModel : public QAbstractListModel
{
Q_OBJECT
Q_DECLARE_PRIVATE(UsersModel)
QML_ELEMENT
public:
enum Roles {
UserAccountRole = Qt::UserRole + 1,
Expand Down
Loading

0 comments on commit ccd972c

Please sign in to comment.