PauseMusicPackageInterface now supports MPRIS
Other small improvements
This commit is contained in:
parent
54de8fa2fa
commit
ba129a1542
6 changed files with 57 additions and 19 deletions
|
@ -53,7 +53,6 @@ void AvahiTcpLinkProvider::newConnection()
|
|||
NetworkPackage::createIdentityPackage(&np);
|
||||
int written = socket->write(np.serialize());
|
||||
|
||||
qDebug() << np.serialize();
|
||||
qDebug() << "AvahiTcpLinkProvider sent package." << written << " bytes written, waiting for reply";
|
||||
}
|
||||
|
||||
|
|
|
@ -54,10 +54,12 @@ QByteArray NetworkPackage::serialize() const
|
|||
bool ok;
|
||||
QJson::Serializer serializer;
|
||||
QByteArray json = serializer.serialize(variant,&ok);
|
||||
if (!ok) qDebug() << "Serialization error:" << serializer.errorMessage();
|
||||
json.append('\n');
|
||||
|
||||
qDebug() << "utlims chars:" << (int)(json[json.size()-1]) << (int)(json[json.size()-2]) << (int)(json[json.size()-3]);
|
||||
if (!ok) {
|
||||
qDebug() << "Serialization error:" << serializer.errorMessage();
|
||||
} else {
|
||||
qDebug() << "Serialized package:" << json;
|
||||
json.append('\n');
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@
|
|||
ClipboardPackageInterface::ClipboardPackageInterface() {
|
||||
clipboard = QApplication::clipboard();
|
||||
ignore_next_clipboard_change = false;
|
||||
connect(clipboard,SIGNAL(changed(QClipboard::Mode)),this,SLOT(clipboardChanged()));
|
||||
connect(clipboard,SIGNAL(changed(QClipboard::Mode)),this,SLOT(clipboardChanged(QClipboard::Mode)));
|
||||
}
|
||||
|
||||
void ClipboardPackageInterface::clipboardChanged()
|
||||
void ClipboardPackageInterface::clipboardChanged(QClipboard::Mode mode)
|
||||
{
|
||||
if (mode != QClipboard::QClipboard::Clipboard) return;
|
||||
|
||||
if (ignore_next_clipboard_change) {
|
||||
ignore_next_clipboard_change = false;
|
||||
return;
|
||||
|
|
|
@ -41,7 +41,7 @@ public Q_SLOTS:
|
|||
virtual bool receivePackage(const Device& device, const NetworkPackage& np);
|
||||
|
||||
private Q_SLOTS:
|
||||
void clipboardChanged();
|
||||
void clipboardChanged(QClipboard::Mode mode);
|
||||
|
||||
private:
|
||||
bool ignore_next_clipboard_change;
|
||||
|
|
|
@ -21,12 +21,16 @@
|
|||
#include "pausemusicpackageinterface.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <qdbusconnectioninterface.h>
|
||||
#include <QDBusReply>
|
||||
#include <QDBusMessage>
|
||||
|
||||
PauseMusicPackageInterface::PauseMusicPackageInterface()
|
||||
{
|
||||
//TODO: Be able to change this from settings
|
||||
pauseWhen = PauseWhenRinging;
|
||||
paused = false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,7 +40,7 @@ bool PauseMusicPackageInterface::receivePackage (const Device& device, const Net
|
|||
|
||||
bool pauseConditionFulfilled = false;
|
||||
|
||||
//TODO: I have manually tested it and it works for both cases, but I should somehow write a test for this logic
|
||||
//TODO: I have manually tested it and it works for both "pauseWhen" cases, but I should somehow write a test for this logic
|
||||
if (pauseWhen == PauseWhenRinging) {
|
||||
if (np.type() == PACKAGE_TYPE_NOTIFICATION) {
|
||||
if (np.get<QString>("notificationType") != "ringing") return false;
|
||||
|
@ -53,15 +57,43 @@ bool PauseMusicPackageInterface::receivePackage (const Device& device, const Net
|
|||
|
||||
qDebug() << "PauseMusicPackageReceiver - PauseCondition:" << pauseConditionFulfilled;
|
||||
|
||||
if (pauseConditionFulfilled && !paused) {
|
||||
//TODO: Use KDE DBUS API
|
||||
system("qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause");
|
||||
} if (!pauseConditionFulfilled && paused) {
|
||||
//FIXME: Play does not work, using PlayPause
|
||||
system("qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause");
|
||||
}
|
||||
if (pauseConditionFulfilled) {
|
||||
//TODO: Make this async
|
||||
//Search for interfaces currently playing
|
||||
QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
|
||||
Q_FOREACH (const QString& iface, interfaces) {
|
||||
if (iface.startsWith("org.mpris.MediaPlayer2")) {
|
||||
QDBusInterface *dbusInterface = new QDBusInterface(iface, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
|
||||
QDBusInterface *mprisInterface = new QDBusInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", QDBusConnection::sessionBus(), this);
|
||||
|
||||
paused = pauseConditionFulfilled;
|
||||
QString status = (qvariant_cast<QDBusVariant>(dbusInterface->call(QDBus::Block,"Get","org.mpris.MediaPlayer2.Player","PlaybackStatus").arguments().first()).variant()).toString();
|
||||
if (status == "Playing") {
|
||||
if (!pausedSources.contains(iface)) {
|
||||
pausedSources.insert(iface);
|
||||
mprisInterface->call(QDBus::Block,"Pause");
|
||||
}
|
||||
}
|
||||
|
||||
delete dbusInterface;
|
||||
delete mprisInterface;
|
||||
}
|
||||
}
|
||||
} if (!pauseConditionFulfilled) {
|
||||
//TODO: Make this async
|
||||
Q_FOREACH (const QString& iface, pausedSources) {
|
||||
QDBusInterface *mprisInterface = new QDBusInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", QDBusConnection::sessionBus(), this);
|
||||
//FIXME: Calling play does not work in spotify
|
||||
//mprisInterface->call(QDBus::Block,"Play");
|
||||
//Workaround: Using playpause instead (checking first if it is already playing)
|
||||
QDBusInterface *dbusInterface = new QDBusInterface(iface, "/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
|
||||
QString status = (qvariant_cast<QDBusVariant>(dbusInterface->call(QDBus::Block,"Get","org.mpris.MediaPlayer2.Player","PlaybackStatus").arguments().first()).variant()).toString();
|
||||
if (status == "Paused") mprisInterface->call(QDBus::Block,"PlayPause");
|
||||
delete dbusInterface;
|
||||
//End of workaround
|
||||
delete mprisInterface;
|
||||
}
|
||||
pausedSources.clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
#include "packageinterface.h"
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
class PauseMusicPackageInterface
|
||||
: public PackageInterface
|
||||
{
|
||||
|
@ -33,7 +36,7 @@ public:
|
|||
private:
|
||||
enum PauseCondtions { PauseWhenTalking, PauseWhenRinging, NeverPause };
|
||||
PauseCondtions pauseWhen;
|
||||
bool paused;
|
||||
QSet<QString> pausedSources;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue