diff options
Diffstat (limited to 'src/mpris-bridge.c')
-rw-r--r-- | src/mpris-bridge.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/src/mpris-bridge.c b/src/mpris-bridge.c new file mode 100644 index 0000000..15ad9d5 --- /dev/null +++ b/src/mpris-bridge.c @@ -0,0 +1,246 @@ +/* mpris-bridge.c generated by valac 0.9.5, the Vala compiler + * generated from mpris-bridge.vala, do not modify */ + + +#include <glib.h> +#include <glib-object.h> +#include <stdlib.h> +#include <string.h> +#include <float.h> +#include <math.h> + + +#define TYPE_MPRIS_BRIDGE (mpris_bridge_get_type ()) +#define MPRIS_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MPRIS_BRIDGE, MprisBridge)) +#define MPRIS_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MPRIS_BRIDGE, MprisBridgeClass)) +#define IS_MPRIS_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MPRIS_BRIDGE)) +#define IS_MPRIS_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MPRIS_BRIDGE)) +#define MPRIS_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MPRIS_BRIDGE, MprisBridgeClass)) + +typedef struct _MprisBridge MprisBridge; +typedef struct _MprisBridgeClass MprisBridgeClass; +typedef struct _MprisBridgePrivate MprisBridgePrivate; + +#define TYPE_MPRIS_CONTROLLER (mpris_controller_get_type ()) +#define MPRIS_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MPRIS_CONTROLLER, MprisController)) +#define MPRIS_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MPRIS_CONTROLLER, MprisControllerClass)) +#define IS_MPRIS_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MPRIS_CONTROLLER)) +#define IS_MPRIS_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MPRIS_CONTROLLER)) +#define MPRIS_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MPRIS_CONTROLLER, MprisControllerClass)) + +typedef struct _MprisController MprisController; +typedef struct _MprisControllerClass MprisControllerClass; + +#define TYPE_MPRIS2_CONTROLLER (mpris2_controller_get_type ()) +#define MPRIS2_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MPRIS2_CONTROLLER, Mpris2Controller)) +#define MPRIS2_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MPRIS2_CONTROLLER, Mpris2ControllerClass)) +#define IS_MPRIS2_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MPRIS2_CONTROLLER)) +#define IS_MPRIS2_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MPRIS2_CONTROLLER)) +#define MPRIS2_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MPRIS2_CONTROLLER, Mpris2ControllerClass)) + +typedef struct _Mpris2Controller Mpris2Controller; +typedef struct _Mpris2ControllerClass Mpris2ControllerClass; + +#define MPRIS_BRIDGE_TYPE_MODE (mpris_bridge_mode_get_type ()) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) + +#define TYPE_PLAYER_CONTROLLER (player_controller_get_type ()) +#define PLAYER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLAYER_CONTROLLER, PlayerController)) +#define PLAYER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLAYER_CONTROLLER, PlayerControllerClass)) +#define IS_PLAYER_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLAYER_CONTROLLER)) +#define IS_PLAYER_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLAYER_CONTROLLER)) +#define PLAYER_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLAYER_CONTROLLER, PlayerControllerClass)) + +typedef struct _PlayerController PlayerController; +typedef struct _PlayerControllerClass PlayerControllerClass; + +#define TRANSPORT_MENUITEM_TYPE_ACTION (transport_menuitem_action_get_type ()) + +struct _MprisBridge { + GObject parent_instance; + MprisBridgePrivate * priv; +}; + +struct _MprisBridgeClass { + GObjectClass parent_class; +}; + +typedef enum { + MPRIS_BRIDGE_MODE_MPRIS_1, + MPRIS_BRIDGE_MODE_MPRIS_2 +} MprisBridgemode; + +struct _MprisBridgePrivate { + MprisController* mpris1_controller; + Mpris2Controller* mpris2_controller; + MprisBridgemode mode_in_use; +}; + +typedef enum { + TRANSPORT_MENUITEM_ACTION_PREVIOUS, + TRANSPORT_MENUITEM_ACTION_PLAY_PAUSE, + TRANSPORT_MENUITEM_ACTION_NEXT +} TransportMenuitemaction; + + +static gpointer mpris_bridge_parent_class = NULL; + +GType mpris_bridge_get_type (void) G_GNUC_CONST; +GType mpris_controller_get_type (void) G_GNUC_CONST; +GType mpris2_controller_get_type (void) G_GNUC_CONST; +static GType mpris_bridge_mode_get_type (void) G_GNUC_UNUSED; +#define MPRIS_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MPRIS_BRIDGE, MprisBridgePrivate)) +enum { + MPRIS_BRIDGE_DUMMY_PROPERTY +}; +GType player_controller_get_type (void) G_GNUC_CONST; +Mpris2Controller* mpris2_controller_new (PlayerController* ctrl); +Mpris2Controller* mpris2_controller_construct (GType object_type, PlayerController* ctrl); +gboolean mpris2_controller_was_successfull (Mpris2Controller* self); +void mpris2_controller_initial_update (Mpris2Controller* self); +MprisController* mpris_controller_new (PlayerController* ctrl, const char* inter); +MprisController* mpris_controller_construct (GType object_type, PlayerController* ctrl, const char* inter); +MprisBridge* mpris_bridge_new (PlayerController* ctrl); +MprisBridge* mpris_bridge_construct (GType object_type, PlayerController* ctrl); +gboolean mpris_controller_connected (MprisController* self); +gboolean mpris2_controller_connected (Mpris2Controller* self); +gboolean mpris_bridge_connected (MprisBridge* self); +GType transport_menuitem_action_get_type (void) G_GNUC_CONST; +void mpris_controller_transport_event (MprisController* self, TransportMenuitemaction command); +void mpris2_controller_transport_event (Mpris2Controller* self, TransportMenuitemaction command); +void mpris_bridge_transport_update (MprisBridge* self, TransportMenuitemaction update); +void mpris2_controller_expose (Mpris2Controller* self); +void mpris_bridge_expose (MprisBridge* self); +void mpris_controller_set_position (MprisController* self, double position); +void mpris2_controller_set_position (Mpris2Controller* self, double position); +void mpris_bridge_set_track_position (MprisBridge* self, double pos); +static void mpris_bridge_finalize (GObject* obj); + + + +static GType mpris_bridge_mode_get_type (void) { + static volatile gsize mpris_bridge_mode_type_id__volatile = 0; + if (g_once_init_enter (&mpris_bridge_mode_type_id__volatile)) { + static const GEnumValue values[] = {{MPRIS_BRIDGE_MODE_MPRIS_1, "MPRIS_BRIDGE_MODE_MPRIS_1", "mpris-1"}, {MPRIS_BRIDGE_MODE_MPRIS_2, "MPRIS_BRIDGE_MODE_MPRIS_2", "mpris-2"}, {0, NULL, NULL}}; + GType mpris_bridge_mode_type_id; + mpris_bridge_mode_type_id = g_enum_register_static ("MprisBridgemode", values); + g_once_init_leave (&mpris_bridge_mode_type_id__volatile, mpris_bridge_mode_type_id); + } + return mpris_bridge_mode_type_id__volatile; +} + + +MprisBridge* mpris_bridge_construct (GType object_type, PlayerController* ctrl) { + MprisBridge * self; + Mpris2Controller* _tmp0_; + g_return_val_if_fail (ctrl != NULL, NULL); + self = (MprisBridge*) g_object_new (object_type, NULL); + self->priv->mpris2_controller = (_tmp0_ = mpris2_controller_new (ctrl), _g_object_unref0 (self->priv->mpris2_controller), _tmp0_); + if (mpris2_controller_was_successfull (self->priv->mpris2_controller) == TRUE) { + MprisController* _tmp1_; + self->priv->mode_in_use = MPRIS_BRIDGE_MODE_MPRIS_2; + self->priv->mpris1_controller = (_tmp1_ = NULL, _g_object_unref0 (self->priv->mpris1_controller), _tmp1_); + mpris2_controller_initial_update (self->priv->mpris2_controller); + } else { + Mpris2Controller* _tmp2_; + MprisController* _tmp3_; + self->priv->mpris2_controller = (_tmp2_ = NULL, _g_object_unref0 (self->priv->mpris2_controller), _tmp2_); + self->priv->mode_in_use = MPRIS_BRIDGE_MODE_MPRIS_1; + self->priv->mpris1_controller = (_tmp3_ = mpris_controller_new (ctrl, "org.freedesktop.MediaPlayer"), _g_object_unref0 (self->priv->mpris1_controller), _tmp3_); + } + return self; +} + + +MprisBridge* mpris_bridge_new (PlayerController* ctrl) { + return mpris_bridge_construct (TYPE_MPRIS_BRIDGE, ctrl); +} + + +gboolean mpris_bridge_connected (MprisBridge* self) { + gboolean result = FALSE; + g_return_val_if_fail (self != NULL, FALSE); + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_1) { + result = mpris_controller_connected (self->priv->mpris1_controller); + return result; + } else { + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_2) { + result = mpris2_controller_connected (self->priv->mpris2_controller); + return result; + } + } + result = FALSE; + return result; +} + + +void mpris_bridge_transport_update (MprisBridge* self, TransportMenuitemaction update) { + g_return_if_fail (self != NULL); + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_1) { + mpris_controller_transport_event (self->priv->mpris1_controller, update); + } else { + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_2) { + mpris2_controller_transport_event (self->priv->mpris2_controller, update); + } + } +} + + +void mpris_bridge_expose (MprisBridge* self) { + g_return_if_fail (self != NULL); + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_2) { + mpris2_controller_expose (self->priv->mpris2_controller); + } else { + g_warning ("mpris-bridge.vala:56: MPRIS1 clients don't have the ability to raise/e" \ +"xpose the client"); + } +} + + +void mpris_bridge_set_track_position (MprisBridge* self, double pos) { + g_return_if_fail (self != NULL); + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_1) { + mpris_controller_set_position (self->priv->mpris1_controller, pos); + } else { + if (self->priv->mode_in_use == MPRIS_BRIDGE_MODE_MPRIS_2) { + mpris2_controller_set_position (self->priv->mpris2_controller, pos); + } + } +} + + +static void mpris_bridge_class_init (MprisBridgeClass * klass) { + mpris_bridge_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (MprisBridgePrivate)); + G_OBJECT_CLASS (klass)->finalize = mpris_bridge_finalize; +} + + +static void mpris_bridge_instance_init (MprisBridge * self) { + self->priv = MPRIS_BRIDGE_GET_PRIVATE (self); +} + + +static void mpris_bridge_finalize (GObject* obj) { + MprisBridge * self; + self = MPRIS_BRIDGE (obj); + _g_object_unref0 (self->priv->mpris1_controller); + _g_object_unref0 (self->priv->mpris2_controller); + G_OBJECT_CLASS (mpris_bridge_parent_class)->finalize (obj); +} + + +GType mpris_bridge_get_type (void) { + static volatile gsize mpris_bridge_type_id__volatile = 0; + if (g_once_init_enter (&mpris_bridge_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (MprisBridgeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) mpris_bridge_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MprisBridge), 0, (GInstanceInitFunc) mpris_bridge_instance_init, NULL }; + GType mpris_bridge_type_id; + mpris_bridge_type_id = g_type_register_static (G_TYPE_OBJECT, "MprisBridge", &g_define_type_info, 0); + g_once_init_leave (&mpris_bridge_type_id__volatile, mpris_bridge_type_id); + } + return mpris_bridge_type_id__volatile; +} + + + + |