Disable DBus as dependency for Android

This commit is contained in:
Bart De Vries 2021-05-03 10:43:24 +02:00
parent fb1516281e
commit 0846dd9d9b
5 changed files with 34 additions and 9 deletions

View File

@ -30,7 +30,7 @@ find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons Syndication Config I18n)
if (ANDROID)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Svg DBus)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Svg)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Kirigami2)
find_package(OpenSSL REQUIRED)
else()

View File

@ -1,5 +1,5 @@
set(SRCS_alligator
set(SRCS_base
main.cpp
feedsmodel.cpp
entriesmodel.cpp
@ -19,21 +19,27 @@ set(SRCS_alligator
errorlogmodel.cpp
error.h
mpris2/mpris2.cpp
mpris2/mediaplayer2.cpp
mpris2/mediaplayer2player.cpp
resources.qrc
)
if(ANDROID)
set (SRCS ${SRCS_base})
else()
set (SRCS ${SRCS_base}
mpris2/mediaplayer2.cpp
mpris2/mediaplayer2player.cpp
)
qt5_add_dbus_interface(SRCS_alligator dbus-interfaces/org.freedesktop.PowerManagement.Inhibit.xml inhibitinterface)
qt5_add_dbus_interface(SRCS_alligator dbus-interfaces/org.gnome.SessionManager.xml gnomesessioninterface)
qt5_add_dbus_interface(SRCS dbus-interfaces/org.freedesktop.PowerManagement.Inhibit.xml inhibitinterface)
qt5_add_dbus_interface(SRCS dbus-interfaces/org.gnome.SessionManager.xml gnomesessioninterface)
endif()
add_executable(alligator ${SRCS_alligator})
add_executable(alligator ${SRCS})
kconfig_add_kcfg_files(alligator settingsmanager.kcfgc GENERATE_MOC)
target_include_directories(alligator PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(alligator PRIVATE Qt5::Core Qt5::Qml Qt5::Quick Qt5::QuickControls2 Qt5::Sql Qt5::Multimedia Qt5::DBus KF5::Syndication KF5::CoreAddons KF5::ConfigGui KF5::I18n)
target_link_libraries(alligator PRIVATE Qt5::Core Qt5::Qml Qt5::Quick Qt5::QuickControls2 Qt5::Sql Qt5::Multimedia KF5::Syndication KF5::CoreAddons KF5::ConfigGui KF5::I18n)
if(ANDROID)
target_link_libraries(alligator PRIVATE
@ -72,7 +78,7 @@ if(ANDROID)
overflow-menu
)
else()
target_link_libraries(alligator PRIVATE Qt5::Widgets)
target_link_libraries(alligator PRIVATE Qt5::Widgets Qt5::DBus)
endif()
install(TARGETS alligator ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})

View File

@ -8,10 +8,14 @@
#include "mpris2.h"
#include "audiomanager.h"
#if !defined Q_OS_ANDROID
#include "mediaplayer2.h"
#include "mediaplayer2player.h"
#endif
#if !defined Q_OS_ANDROID
#include <QDBusConnection>
#endif
#if defined Q_OS_WIN
#include <Windows.h>
@ -26,6 +30,7 @@ Mpris2::Mpris2(QObject *parent)
void Mpris2::initDBusService()
{
#if !defined Q_OS_ANDROID
QString mspris2Name(QStringLiteral("org.mpris.MediaPlayer2.") + m_playerName);
bool success = QDBusConnection::sessionBus().registerService(mspris2Name);
@ -49,6 +54,7 @@ void Mpris2::initDBusService()
connect(m_mp2.get(), &MediaPlayer2::raisePlayer, this, &Mpris2::raisePlayer);
}
#endif
}
Mpris2::~Mpris2() = default;
@ -76,11 +82,13 @@ void Mpris2::setPlayerName(const QString &playerName)
m_playerName = playerName;
#if !defined Q_OS_ANDROID
if (m_audioPlayer && !m_playerName.isEmpty()) {
if (!m_mp2) {
initDBusService();
}
}
#endif
emit playerNameChanged();
}
@ -92,18 +100,22 @@ void Mpris2::setAudioPlayer(AudioManager *audioPlayer)
m_audioPlayer = audioPlayer;
#if !defined Q_OS_ANDROID
if (m_audioPlayer && !m_playerName.isEmpty()) {
if (!m_mp2) {
initDBusService();
}
}
#endif
emit audioPlayerChanged();
}
void Mpris2::setShowProgressOnTaskBar(bool value)
{
#if !defined Q_OS_ANDROID
m_mp2p->setShowProgressOnTaskBar(value);
#endif
mShowProgressOnTaskBar = value;
Q_EMIT showProgressOnTaskBarChanged();
}

View File

@ -12,8 +12,10 @@
#include <QSharedPointer>
#include <memory>
#if !defined Q_OS_ANDROID
class MediaPlayer2Player;
class MediaPlayer2;
#endif
class AudioManager;
class Mpris2 : public QObject
@ -54,8 +56,11 @@ Q_SIGNALS:
private:
void initDBusService();
#if !defined Q_OS_ANDROID
std::unique_ptr<MediaPlayer2> m_mp2;
std::unique_ptr<MediaPlayer2Player> m_mp2p;
#endif
QString m_playerName;
AudioManager *m_audioPlayer = nullptr;
bool mShowProgressOnTaskBar = true;

View File

@ -24,8 +24,10 @@
#include <QDebug>
#include <QString>
#if !defined Q_OS_ANDROID && !defined Q_OS_WIN
#include "gnomesessioninterface.h"
#include "inhibitinterface.h"
#endif
class PowerManagementInterfacePrivate
{