| 1 |
/* |
| 2 |
* This file is part of budgie-desktop |
| 3 |
* |
| 4 |
* Copyright Budgie Desktop Developers |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Simple wrapper to ensure a lifetime reference to the encapsulated objects |
| 14 |
*/ |
| 15 |
public class MprisClient : GLib.Object { |
| 16 |
public MprisPlayerIface player { construct set; get; } |
| 17 |
public MprisDbusPropIface prop { construct set; get; } |
| 18 |
|
| 19 |
public MprisClient(MprisPlayerIface player, MprisDbusPropIface prop) { |
| 20 |
Object(player: player, prop: prop); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* We need to probe the dbus daemon directly, hence this interface |
| 26 |
*/ |
| 27 |
[DBus (name="org.freedesktop.DBus")] |
| 28 |
public interface MprisDBusImpl : Object { |
| 29 |
public abstract async string[] list_names() throws DBusError, IOError; |
| 30 |
public signal void name_owner_changed(string name, string old_owner, string new_owner); |
| 31 |
public signal void name_acquired(string name); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Vala dbus property notifications are not working. Manually probe property changes. |
| 36 |
*/ |
| 37 |
[DBus (name="org.freedesktop.DBus.Properties")] |
| 38 |
public interface MprisDbusPropIface : GLib.Object { |
| 39 |
public signal void properties_changed(string iface, HashTable<string,Variant> changed, string[] invalid); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Represents the base org.mpris.MediaPlayer2 spec |
| 44 |
*/ |
| 45 |
[DBus (name="org.mpris.MediaPlayer2")] |
| 46 |
public interface MprisIface : GLib.Object { |
| 47 |
public abstract async void raise() throws DBusError, IOError; |
| 48 |
public abstract async void quit() throws DBusError, IOError; |
| 49 |
|
| 50 |
public abstract bool can_quit { get; set; } |
| 51 |
public abstract bool fullscreen { get; } /* Optional */ |
| 52 |
public abstract bool can_set_fullscreen { get; } /* Optional */ |
| 53 |
public abstract bool can_raise { get; } |
| 54 |
public abstract bool has_track_list { get; } |
| 55 |
public abstract string identity { owned get; } |
| 56 |
public abstract string desktop_entry { owned get; } /* Optional */ |
| 57 |
public abstract string[] supported_uri_schemes { owned get; } |
| 58 |
public abstract string[] supported_mime_types { owned get; } |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Interface for the org.mpris.MediaPlayer2.Player spec |
| 63 |
* This is the one that actually does cool stuff! |
| 64 |
* |
| 65 |
* @note We cheat and inherit from MprisIface to save faffing around with two |
| 66 |
* iface initialisations over one |
| 67 |
*/ |
| 68 |
[DBus (name="org.mpris.MediaPlayer2.Player")] |
| 69 |
public interface MprisPlayerIface : MprisIface { |
| 70 |
public abstract async void next() throws DBusError, IOError; |
| 71 |
public abstract async void previous() throws DBusError, IOError; |
| 72 |
public abstract async void pause() throws DBusError, IOError; |
| 73 |
public abstract async void play_pause() throws DBusError, IOError; |
| 74 |
public abstract async void stop() throws DBusError, IOError; |
| 75 |
public abstract async void play() throws DBusError, IOError; |
| 76 |
/* Eh we don't use everything in this iface :p */ |
| 77 |
public abstract async void seek(int64 offset) throws DBusError, IOError; |
| 78 |
public abstract async void open_uri(string uri) throws DBusError, IOError; |
| 79 |
|
| 80 |
public abstract string playback_status { owned get; } |
| 81 |
public abstract string loop_status { owned get; set; } /* Optional */ |
| 82 |
public abstract double rate { get; set; } |
| 83 |
public abstract bool shuffle { set; get; } /* Optional */ |
| 84 |
|
| 85 |
public abstract HashTable<string,Variant> metadata { owned get; } |
| 86 |
|
| 87 |
public abstract double volume {get; set; } |
| 88 |
public abstract int64 position { get; } |
| 89 |
public abstract double minimum_rate { get; } |
| 90 |
public abstract double maximum_rate { get; } |
| 91 |
public abstract bool can_go_next { get; } |
| 92 |
public abstract bool can_go_previous { get; } |
| 93 |
public abstract bool can_play { get; } |
| 94 |
public abstract bool can_pause { get; } |
| 95 |
public abstract bool can_seek { get; } |
| 96 |
public abstract bool can_control { get; } |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Utility function, return a new iface instance, i.e. deal |
| 101 |
* with all the dbus cruft |
| 102 |
* |
| 103 |
* @param busname The busname to instaniate ifaces from |
| 104 |
* @return a new MprisClient, or null if errors occurred. |
| 105 |
*/ |
| 106 |
public async MprisClient? new_iface(string busname) { |
| 107 |
MprisPlayerIface? play = null; |
| 108 |
MprisClient? cl = null; |
| 109 |
MprisDbusPropIface? prop = null; |
| 110 |
|
| 111 |
try { |
| 112 |
play = yield Bus.get_proxy(BusType.SESSION, busname, "/org/mpris/MediaPlayer2"); |
| 113 |
} catch (Error e) { |
| 114 |
message(e.message); |
| 115 |
return null; |
| 116 |
} |
| 117 |
try { |
| 118 |
prop = yield Bus.get_proxy(BusType.SESSION, busname, "/org/mpris/MediaPlayer2"); |
| 119 |
} catch (Error e) { |
| 120 |
message(e.message); |
| 121 |
return null; |
| 122 |
} |
| 123 |
cl = new MprisClient(play, prop); |
| 124 |
|
| 125 |
return cl; |
| 126 |
} |