[KMediaSession] Allow app and desktop entry name to be set in constructor

This commit is contained in:
Bart De Vries 2023-02-16 13:32:52 +01:00
parent e1a20b3ebc
commit 780e63c2f2
3 changed files with 12 additions and 9 deletions

View File

@ -27,7 +27,7 @@ class AudioManagerPrivate
private:
SolidExtras::NetworkStatus m_networkStatus;
KMediaSession m_player;
KMediaSession m_player = KMediaSession(QStringLiteral("kasts"), QStringLiteral("org.kde.kasts"));
Entry *m_entry = nullptr;
bool m_readyToPlay = false;
@ -57,8 +57,6 @@ AudioManager::AudioManager(QObject *parent)
: QObject(parent)
, d(std::make_unique<AudioManagerPrivate>())
{
d->m_player.setPlayerName(QStringLiteral("kasts"));
d->m_player.setDesktopEntryName(QStringLiteral("org.kde.kasts"));
d->m_player.setMpris2PauseInsteadOfStop(true);
connect(&d->m_player, &KMediaSession::currentBackendChanged, this, &AudioManager::currentBackendChanged);

View File

@ -45,16 +45,14 @@ private:
std::unique_ptr<Mpris2> m_mpris;
MetaData *m_meta = nullptr;
QString m_playerName =
KAboutData::applicationData().displayName().isEmpty() ? QStringLiteral("KMediaSession") : KAboutData::applicationData().displayName();
QString m_desktopEntryName =
KAboutData::applicationData().desktopFileName().isEmpty() ? QStringLiteral("org.kde.kmediasession") : KAboutData::applicationData().desktopFileName();
QString m_playerName;
QString m_desktopEntryName;
bool m_mpris2PauseInsteadOfStop = false;
bool m_canGoNext = false;
bool m_canGoPrevious = false;
};
KMediaSession::KMediaSession(QObject *parent)
KMediaSession::KMediaSession(const QString &playerName, const QString &desktopEntryName, QObject *parent)
: QObject(parent)
, d(std::make_unique<KMediaSessionPrivate>())
{
@ -75,6 +73,13 @@ KMediaSession::KMediaSession(QObject *parent)
#endif
// set up mpris2
d->m_playerName = playerName.isEmpty()
? (KAboutData::applicationData().displayName().isEmpty() ? QStringLiteral("KMediaSession") : KAboutData::applicationData().displayName())
: playerName;
d->m_desktopEntryName = desktopEntryName.isEmpty()
? (KAboutData::applicationData().desktopFileName().isEmpty() ? QStringLiteral("org.kde.kmediasession")
: KAboutData::applicationData().desktopFileName())
: desktopEntryName;
d->m_mpris = std::make_unique<Mpris2>(this);
qCDebug(KMediaSessionLog) << "KMediaSession::KMediaSession end";

View File

@ -86,7 +86,7 @@ public:
};
Q_ENUM(Error)
explicit KMediaSession(QObject *parent = nullptr);
explicit KMediaSession(const QString &playerName = QStringLiteral(""), const QString &desktopEntryName = QStringLiteral(""), QObject *parent = nullptr);
~KMediaSession();
[[nodiscard]] Q_INVOKABLE QString backendName(KMediaSession::MediaBackends backend) const;