Skip to content

Commit

Permalink
Merge branch 'remove_qml_dependency' into 'master'
Browse files Browse the repository at this point in the history
Remove qml dependency and clean up code a bit. Fixes JB#53226

See merge request mer-core/qtmpris!8
  • Loading branch information
pvuorela committed Feb 19, 2021
2 parents 90b7759 + 93ac929 commit ade1b9a
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 54 deletions.
3 changes: 0 additions & 3 deletions README.md
Expand Up @@ -7,9 +7,6 @@ Qt and QML MPRIS interface and adaptor
Installation:
-------------

MPRIS for Qt depends on [Extended DBus for Qt](https://github.com/nemomobile/qtdbusextended) so make sure to install it before building this project.


```
$ qmake && make && make install
```
Expand Down
18 changes: 12 additions & 6 deletions declarative/mprisplugin.cpp
Expand Up @@ -31,17 +31,23 @@

#include <qqml.h>

MprisPlugin::MprisPlugin(QObject *parent) :
QQmlExtensionPlugin(parent) {

static QObject * api_factory(QQmlEngine *, QJSEngine *)
{
return new Mpris;
}

MprisPlugin::~MprisPlugin() {
MprisPlugin::MprisPlugin(QObject *parent) :
QQmlExtensionPlugin(parent)
{
}

MprisPlugin::~MprisPlugin()
{
}

void MprisPlugin::registerTypes(const char *uri) {
qmlRegisterSingletonType<Mpris>(uri, 1, 0, "Mpris", Mpris::api_factory);
void MprisPlugin::registerTypes(const char *uri)
{
qmlRegisterSingletonType<Mpris>(uri, 1, 0, "Mpris", api_factory);
qmlRegisterType<MprisPlayer>(uri, 1, 0, "MprisPlayer");
qmlRegisterType<MprisManager>(uri, 1, 0, "MprisManager");
}
6 changes: 5 additions & 1 deletion example/controller/controller.cpp
Expand Up @@ -29,13 +29,17 @@

#include <QGuiApplication>

static QObject * api_factory(QQmlEngine *, QJSEngine *)
{
return new Mpris;
}

int main(int argc, char *argv[])
{
QGuiApplication *app = new QGuiApplication(argc, argv);
QQuickView *view = new QQuickView;

qmlRegisterSingletonType<Mpris>("org.nemomobile.qtmpris", 1, 0, "Mpris", Mpris::api_factory);
qmlRegisterSingletonType<Mpris>("org.nemomobile.qtmpris", 1, 0, "Mpris", api_factory);
qmlRegisterType<MprisManager>("org.nemomobile.qtmpris", 1, 0, "MprisManager");

view->setSource(app->applicationDirPath().append("/../qml/controller.qml"));
Expand Down
6 changes: 5 additions & 1 deletion example/player/player.cpp
Expand Up @@ -30,13 +30,17 @@

#include <QGuiApplication>

static QObject * api_factory(QQmlEngine *, QJSEngine *)
{
return new Mpris;
}

int main(int argc, char *argv[])
{
QGuiApplication *app = new QGuiApplication(argc, argv);
QQuickView *view = new QQuickView;

qmlRegisterSingletonType<Mpris>("org.nemomobile.qtmpris", 1, 0, "Mpris", Mpris::api_factory);
qmlRegisterSingletonType<Mpris>("org.nemomobile.qtmpris", 1, 0, "Mpris", api_factory);
qmlRegisterType<MprisPlayer>("org.nemomobile.qtmpris", 1, 0, "MprisPlayer");

view->setSource(app->applicationDirPath().append("/../qml/player.qml"));
Expand Down
3 changes: 1 addition & 2 deletions rpm/mpris-qt.spec
@@ -1,7 +1,7 @@
Name: mpris-qt5

Summary: Qt and QML MPRIS interface and adaptor
Version: 0.0.5
Version: 1.0.6
Release: 1
License: LGPLv2
URL: https://git.sailfishos.org/mer-core/qtmpris
Expand Down Expand Up @@ -55,7 +55,6 @@ rm -rf %{buildroot}
%files devel
%defattr(-,root,root,-)
%{_datarootdir}/qt5/mkspecs/features/%{name}.prf
%{_includedir}/qt5/MprisQt/MprisQt
%{_includedir}/qt5/MprisQt/Mpris
%{_includedir}/qt5/MprisQt/MprisPlayer
%{_includedir}/qt5/MprisQt/MprisController
Expand Down
1 change: 0 additions & 1 deletion src/MprisQt

This file was deleted.

15 changes: 6 additions & 9 deletions src/mpris.cpp
Expand Up @@ -25,12 +25,14 @@

#include "mpris.h"

#include <QQmlEngine>
#include <QJSEngine>

static const char *playbackStatusStrings[] = { "Playing", "Paused", "Stopped" };
static const char *loopStatusStrings[] = { "None", "Track", "Playlist" };
static const char *metadataStrings[] = { "mpris:trackid", "mpris:length", "mpris:artUrl", "xesam:album", "xesam:albumArtist", "xesam:artist", "xesam:asText", "xesam:audioBPM", "xesam:autoRating", "xesam:comment", "xesam:composer", "xesam:contentCreated", "xesam:discNumber", "xesam:firstUsed", "xesam:genre", "xesam:lastUsed", "xesam:lyricist", "xesam:title", "xesam:trackNumber", "xesam:url", "xesam:useCount", "xesam:userRating" };
static const char *metadataStrings[] = { "mpris:trackid", "mpris:length", "mpris:artUrl", "xesam:album",
"xesam:albumArtist", "xesam:artist", "xesam:asText", "xesam:audioBPM",
"xesam:autoRating", "xesam:comment", "xesam:composer", "xesam:contentCreated",
"xesam:discNumber", "xesam:firstUsed", "xesam:genre", "xesam:lastUsed",
"xesam:lyricist", "xesam:title", "xesam:trackNumber", "xesam:url",
"xesam:useCount", "xesam:userRating" };


Mpris::Mpris(QObject *parent)
Expand All @@ -42,11 +44,6 @@ Mpris::~Mpris()
{
}

QObject *Mpris::api_factory(QQmlEngine *, QJSEngine *)
{
return new Mpris;
}

QString Mpris::metadataToString(Mpris::Metadata metadata)
{
return enumerationToString(metadata);
Expand Down
7 changes: 1 addition & 6 deletions src/mpris.h
Expand Up @@ -26,14 +26,11 @@
#ifndef MPRIS_H
#define MPRIS_H

#include <MprisQt>
#include <mprisqt.h>

#include <QtCore/QObject>
#include <QtCore/QString>

class QQmlEngine;
class QJSEngine;

class MPRIS_QT_EXPORT Mpris : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -85,8 +82,6 @@ class MPRIS_QT_EXPORT Mpris : public QObject
Mpris(QObject *parent = 0);
~Mpris();

static QObject *api_factory(QQmlEngine *, QJSEngine *);

Q_INVOKABLE static QString metadataToString(Metadata metadata);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/mpriscontroller.h
Expand Up @@ -26,7 +26,7 @@
#ifndef MPRISCONTROLLER_H
#define MPRISCONTROLLER_H

#include <MprisQt>
#include <mprisqt.h>
#include <Mpris>

#include <QDBusConnection>
Expand Down
7 changes: 3 additions & 4 deletions src/mprismanager.cpp
Expand Up @@ -27,12 +27,11 @@

#include "mpriscontroller.h"

#include <qqmlinfo.h>

#include <QDBusConnection>
#include <QDBusConnectionInterface>

#include <QtCore/QSignalMapper>
#include <QDebug>

static const QString mprisNameSpace = QStringLiteral("org.mpris.MediaPlayer2.*");
static const QString dBusService = QStringLiteral("org.freedesktop.DBus");
Expand All @@ -58,7 +57,7 @@ MprisManager::MprisManager(QObject *parent)
QDBusConnection connection = getDBusConnection();

if (!connection.isConnected()) {
qmlInfo(this) << "Failed attempting to connect to DBus";
qWarning() << "Mpris: Failed attempting to connect to DBus";
return;
}

Expand Down Expand Up @@ -177,7 +176,7 @@ void MprisManager::setCurrentService(const QString &service)
QRegExp rx(mprisNameSpace);
rx.setPatternSyntax(QRegExp::Wildcard);
if (!rx.exactMatch(service)) {
qmlInfo(this) << service << "is not a proper Mpris2 service";
qWarning() << "Mpris:" << service << "is not a proper Mpris2 service";
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mprismanager.h
Expand Up @@ -26,7 +26,7 @@
#ifndef MPRISMANAGER_H
#define MPRISMANAGER_H

#include <MprisQt>
#include <mprisqt.h>
#include <Mpris>
#include <MprisController>

Expand Down
17 changes: 8 additions & 9 deletions src/mprisplayer.cpp
Expand Up @@ -27,13 +27,12 @@

#include "mprisplayer_p.h"

#include <qqmlinfo.h>

#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDBusPendingCallWatcher>
#include <QDBusReply>
#include <QDebug>

static const QString serviceNamePrefix = QStringLiteral("org.mpris.MediaPlayer2.");
static const QString mprisObjectPath = QStringLiteral("/org/mpris/MediaPlayer2");
Expand Down Expand Up @@ -78,9 +77,9 @@ MprisPlayer::MprisPlayer(QObject *parent)
QDBusConnection connection = getDBusConnection();

if (!connection.isConnected()) {
qmlInfo(this) << "Failed attempting to connect to DBus";
qWarning() << "Mpris: Failed attempting to connect to DBus";
} else if (!connection.registerObject(mprisObjectPath, this)) {
qmlInfo(this) << "Failed attempting to register object path. Already registered?";
qWarning() << "Mpris: Failed attempting to register object path. Already registered?";
}
}

Expand Down Expand Up @@ -537,19 +536,19 @@ QVariantMap MprisPlayer::typeMetadata(const QVariantMap &aMetadata)
void MprisPlayer::registerService()
{
if (m_serviceName.isEmpty()) {
qmlInfo(this) << "Failed to register service: empty service name";
qWarning() << "Mpris: Failed to register service: empty service name";
return;
}

QDBusConnection connection = getDBusConnection();

if (!connection.isConnected()) {
qmlInfo(this) << "Failed attempting to connect to DBus";
qWarning() << "Mpris: Failed attempting to connect to DBus";
return;
}

if (!connection.registerService(QString(serviceNamePrefix).append(m_serviceName))) {
qmlInfo(this) << "Failed attempting to register service: " << m_serviceName << " Already taken?";
qWarning() << "Mpris: Failed attempting to register service: " << m_serviceName << " Already taken?";
}

return;
Expand All @@ -572,7 +571,7 @@ void MprisPlayer::notifyPropertiesChanged(const QString& interfaceName, const QV
QDBusConnection connection = getDBusConnection();

if (!connection.isConnected()) {
qmlInfo(this) << "Failed attempting to connect to DBus";
qWarning() << "Mpris: Failed attempting to connect to DBus";
return;
}

Expand All @@ -585,6 +584,6 @@ void MprisPlayer::notifyPropertiesChanged(const QString& interfaceName, const QV
message.setArguments(arguments);

if (!connection.send(message)) {
qmlInfo(this) << "Failed to send DBus property notification signal";
qWarning() << "Mpris: Failed to send DBus property notification signal";
}
}
2 changes: 1 addition & 1 deletion src/mprisplayer.h
Expand Up @@ -26,7 +26,7 @@
#ifndef MPRISPLAYER_H
#define MPRISPLAYER_H

#include <MprisQt>
#include <mprisqt.h>
#include <Mpris>

#include <QDBusContext>
Expand Down
8 changes: 3 additions & 5 deletions src/mprisplayeradaptor.cpp
Expand Up @@ -27,8 +27,6 @@

#include "mprisplayer.h"

#include <qqmlinfo.h>

#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
Expand Down Expand Up @@ -563,7 +561,7 @@ void MprisPlayerAdaptor::onMaximumRateChanged() const
MprisPlayer * const player = static_cast<MprisPlayer *>(parent());

if (player->maximumRate() < 1) {
qmlInfo(this) << "Maximum rate should be equal or above 1";
qWarning() << "Mpris: Maximum rate should be equal or above 1";
return;
}

Expand All @@ -588,7 +586,7 @@ void MprisPlayerAdaptor::onMinimumRateChanged() const
MprisPlayer * const player = static_cast<MprisPlayer *>(parent());

if (player->minimumRate() > 1) {
qmlInfo(this) << "Minimum rate should be equal or less than 1";
qWarning() << "Mpris: Minimum rate should be equal or less than 1";
return;
}

Expand All @@ -613,7 +611,7 @@ void MprisPlayerAdaptor::onRateChanged() const
MprisPlayer * const player = static_cast<MprisPlayer *>(parent());

if (player->rate() <= 0 || player->rate() < player->minimumRate() || player->rate() > player->maximumRate()) {
qmlInfo(this) << "Rate should never be negative or out of the minimum and maximum limits";
qWarning() << "Mpris: Rate should never be negative or out of the minimum and maximum limits";
return;
}

Expand Down
2 changes: 0 additions & 2 deletions src/mprisrootadaptor.cpp
Expand Up @@ -27,8 +27,6 @@

#include "mprisplayer.h"

#include <qqmlinfo.h>

#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
Expand Down
3 changes: 1 addition & 2 deletions src/src.pro
Expand Up @@ -3,7 +3,7 @@ include(../common.pri)
TEMPLATE = lib
CONFIG += qt link_pkgconfig no_keywords

QT = core dbus qml
QT = core dbus

TARGET = $${MPRISQTLIB}

Expand Down Expand Up @@ -44,7 +44,6 @@ HEADERS += \
mprismanager.h

INSTALL_HEADERS = \
MprisQt \
Mpris \
MprisPlayer \
MprisController \
Expand Down

0 comments on commit ade1b9a

Please sign in to comment.