Better name
[gmpc-mmkeys.git] / mmkeys.vala
blob3ac28d633ddab1bd3e40ac059d726c25e2d4461a
1 using GLib;
2 using Gmpc;
3 using Gmpc.Plugin;
5 [DBus (name = "org.gnome.SettingsDaemon.MediaKeys")]
6 interface MediaKeys : GLib.Object {
7 public abstract void GrabMediaPlayerKeys (string application, uint32 time);
8 public abstract void ReleaseMediaPlayerKeys (string application);
9 public signal void MediaPlayerKeyPressed (string application, string keys);
12 public class MMKeys : Gmpc.Plugin.Base {
13 public const int[] pversion = {0,0,0};
14 private DBus.Connection conn;
15 private MediaKeys keys;
16 /* Name */
17 public override weak string get_name() {
18 return "Gnome multimedia keys plugin";
20 /* Version */
21 public override weak int[] get_version() {
22 return pversion;
24 private void callback (MediaKeys mkeys, string application, string keys) {
25 if(this.get_enabled() == false) return;
26 if(application != "gmpc") return;
27 if(keys == "Play") MPD.Player.play(server);
28 else if(keys == "Pause") MPD.Player.pause(server);
29 else if(keys == "Next") MPD.Player.next(server);
30 else if(keys == "Previous") MPD.Player.prev(server);
31 else if(keys == "Stop") MPD.Player.stop(server);
33 construct {
34 /* Set the plugin as an internal one and of type pl_browser */
35 this.plugin_type = 4;
36 conn = DBus.Bus.get (DBus.BusType.SESSION);
37 keys = (MediaKeys) conn.get_object ( "org.gnome.SettingsDaemon",
38 "/org/gnome/SettingsDaemon/MediaKeys");
40 keys.GrabMediaPlayerKeys("gmpc", (uint)0);
41 keys.MediaPlayerKeyPressed += callback;
43 ~MMKeys() {
44 keys.ReleaseMediaPlayerKeys("gmpc");
47 [ModuleInit]
48 public Type plugin_get_type () {
49 return typeof (MMKeys);