Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Weixuan Xiao
kdeconnect-kde
Commits
ba129a15
Commit
ba129a15
authored
Jul 24, 2013
by
Albert Vaca Cintora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PauseMusicPackageInterface now supports MPRIS
Other small improvements
parent
54de8fa2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
19 deletions
+57
-19
daemon/linkproviders/avahitcplinkprovider.cpp
daemon/linkproviders/avahitcplinkprovider.cpp
+0
-1
daemon/networkpackage.cpp
daemon/networkpackage.cpp
+6
-4
daemon/packageinterfaces/clipboardpackageinterface.cpp
daemon/packageinterfaces/clipboardpackageinterface.cpp
+4
-2
daemon/packageinterfaces/clipboardpackageinterface.h
daemon/packageinterfaces/clipboardpackageinterface.h
+1
-1
daemon/packageinterfaces/pausemusicpackageinterface.cpp
daemon/packageinterfaces/pausemusicpackageinterface.cpp
+42
-10
daemon/packageinterfaces/pausemusicpackageinterface.h
daemon/packageinterfaces/pausemusicpackageinterface.h
+4
-1
No files found.
daemon/linkproviders/avahitcplinkprovider.cpp
View file @
ba129a15
...
...
@@ -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"
;
}
...
...
daemon/networkpackage.cpp
View file @
ba129a15
...
...
@@ -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
;
}
...
...
daemon/packageinterfaces/clipboardpackageinterface.cpp
View file @
ba129a15
...
...
@@ -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
;
...
...
daemon/packageinterfaces/clipboardpackageinterface.h
View file @
ba129a15
...
...
@@ -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
;
...
...
daemon/packageinterfaces/pausemusicpackageinterface.cpp
View file @
ba129a15
...
...
@@ -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
);
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"
);
}
}
paused
=
pauseConditionFulfilled
;
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
;
...
...
daemon/packageinterfaces/pausemusicpackageinterface.h
View file @
ba129a15
...
...
@@ -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
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment