aboutsummaryrefslogtreecommitdiff
path: root/src/music-player-bridge.c
diff options
context:
space:
mode:
authorKen VanDine <ken.vandine@canonical.com>2010-06-17 16:50:30 -0400
committerKen VanDine <ken.vandine@canonical.com>2010-06-17 16:50:30 -0400
commit619a7c5da5817b5da3bfd8af5c3af9de450b6d48 (patch)
tree8047ef8b2414a7f097042712dffe1e9bdfdcf90e /src/music-player-bridge.c
parent012ac7d97cc878ac1a66c9330e82b96e363f2e61 (diff)
downloadayatana-indicator-sound-619a7c5da5817b5da3bfd8af5c3af9de450b6d48.tar.gz
ayatana-indicator-sound-619a7c5da5817b5da3bfd8af5c3af9de450b6d48.tar.bz2
ayatana-indicator-sound-619a7c5da5817b5da3bfd8af5c3af9de450b6d48.zip
Import upstream version 0.3.1
Diffstat (limited to 'src/music-player-bridge.c')
-rw-r--r--src/music-player-bridge.c362
1 files changed, 362 insertions, 0 deletions
diff --git a/src/music-player-bridge.c b/src/music-player-bridge.c
new file mode 100644
index 0000000..c08a1e7
--- /dev/null
+++ b/src/music-player-bridge.c
@@ -0,0 +1,362 @@
+/* music-player-bridge.c generated by valac, the Vala compiler
+ * generated from music-player-bridge.vala, do not modify */
+
+/*
+This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libindicate/./indicator-messages.h>
+#include <libindicate/./indicator.h>
+#include <libindicate/./interests.h>
+#include <libindicate/./listener.h>
+#include <libindicate/./server.h>
+#include <libdbusmenu-glib/client.h>
+#include <libdbusmenu-glib/menuitem-proxy.h>
+#include <libdbusmenu-glib/menuitem.h>
+#include <libdbusmenu-glib/server.h>
+#include <gee.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#define TYPE_MUSIC_PLAYER_BRIDGE (music_player_bridge_get_type ())
+#define MUSIC_PLAYER_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MUSIC_PLAYER_BRIDGE, MusicPlayerBridge))
+#define MUSIC_PLAYER_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MUSIC_PLAYER_BRIDGE, MusicPlayerBridgeClass))
+#define IS_MUSIC_PLAYER_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MUSIC_PLAYER_BRIDGE))
+#define IS_MUSIC_PLAYER_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MUSIC_PLAYER_BRIDGE))
+#define MUSIC_PLAYER_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MUSIC_PLAYER_BRIDGE, MusicPlayerBridgeClass))
+
+typedef struct _MusicPlayerBridge MusicPlayerBridge;
+typedef struct _MusicPlayerBridgeClass MusicPlayerBridgeClass;
+typedef struct _MusicPlayerBridgePrivate MusicPlayerBridgePrivate;
+
+#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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
+#define _g_free0(var) (var = (g_free (var), NULL))
+
+struct _MusicPlayerBridge {
+ GObject parent_instance;
+ MusicPlayerBridgePrivate * priv;
+};
+
+struct _MusicPlayerBridgeClass {
+ GObjectClass parent_class;
+};
+
+struct _MusicPlayerBridgePrivate {
+ IndicateListener* listener;
+ DbusmenuMenuitem* root_menu;
+ GeeHashMap* registered_clients;
+};
+
+
+static gpointer music_player_bridge_parent_class = NULL;
+
+GType music_player_bridge_get_type (void);
+GType player_controller_get_type (void);
+#define MUSIC_PLAYER_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MUSIC_PLAYER_BRIDGE, MusicPlayerBridgePrivate))
+enum {
+ MUSIC_PLAYER_BRIDGE_DUMMY_PROPERTY
+};
+void music_player_bridge_on_indicator_added (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0);
+static void _music_player_bridge_on_indicator_added_indicate_listener_indicator_added (IndicateListener* _sender, IndicateListenerServer* object, IndicateListenerIndicator* p0, gpointer self);
+void music_player_bridge_on_indicator_removed (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0);
+static void _music_player_bridge_on_indicator_removed_indicate_listener_indicator_removed (IndicateListener* _sender, IndicateListenerServer* object, IndicateListenerIndicator* p0, gpointer self);
+void music_player_bridge_on_indicator_modified (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0, const char* s);
+static void _music_player_bridge_on_indicator_modified_indicate_listener_indicator_modified (IndicateListener* _sender, IndicateListenerServer* object, IndicateListenerIndicator* p0, const char* p1, gpointer self);
+void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListenerServer* object, const char* type);
+static void _music_player_bridge_on_server_added_indicate_listener_server_added (IndicateListener* _sender, IndicateListenerServer* object, const char* p0, gpointer self);
+void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateListenerServer* object, const char* type);
+static void _music_player_bridge_on_server_removed_indicate_listener_server_removed (IndicateListener* _sender, IndicateListenerServer* object, const char* p0, gpointer self);
+void music_player_bridge_on_server_count_changed (MusicPlayerBridge* self, IndicateListenerServer* object, guint i);
+static void _music_player_bridge_on_server_count_changed_indicate_listener_server_count_changed (IndicateListener* _sender, IndicateListenerServer* object, guint p0, gpointer self);
+MusicPlayerBridge* music_player_bridge_new (void);
+MusicPlayerBridge* music_player_bridge_construct (GType object_type);
+void music_player_bridge_set_root_menu_item (MusicPlayerBridge* self, DbusmenuMenuitem* menu);
+static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge* self, const char* type);
+PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, gboolean active);
+PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, gboolean active);
+void player_controller_vanish (PlayerController* self);
+static void music_player_bridge_finalize (GObject* obj);
+static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
+static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
+static gint _vala_array_length (gpointer array);
+
+
+
+static void _music_player_bridge_on_indicator_added_indicate_listener_indicator_added (IndicateListener* _sender, IndicateListenerServer* object, IndicateListenerIndicator* p0, gpointer self) {
+ music_player_bridge_on_indicator_added (self, object, p0);
+}
+
+
+static void _music_player_bridge_on_indicator_removed_indicate_listener_indicator_removed (IndicateListener* _sender, IndicateListenerServer* object, IndicateListenerIndicator* p0, gpointer self) {
+ music_player_bridge_on_indicator_removed (self, object, p0);
+}
+
+
+static void _music_player_bridge_on_indicator_modified_indicate_listener_indicator_modified (IndicateListener* _sender, IndicateListenerServer* object, IndicateListenerIndicator* p0, const char* p1, gpointer self) {
+ music_player_bridge_on_indicator_modified (self, object, p0, p1);
+}
+
+
+static void _music_player_bridge_on_server_added_indicate_listener_server_added (IndicateListener* _sender, IndicateListenerServer* object, const char* p0, gpointer self) {
+ music_player_bridge_on_server_added (self, object, p0);
+}
+
+
+static void _music_player_bridge_on_server_removed_indicate_listener_server_removed (IndicateListener* _sender, IndicateListenerServer* object, const char* p0, gpointer self) {
+ music_player_bridge_on_server_removed (self, object, p0);
+}
+
+
+static void _music_player_bridge_on_server_count_changed_indicate_listener_server_count_changed (IndicateListener* _sender, IndicateListenerServer* object, guint p0, gpointer self) {
+ music_player_bridge_on_server_count_changed (self, object, p0);
+}
+
+
+MusicPlayerBridge* music_player_bridge_construct (GType object_type) {
+ MusicPlayerBridge * self;
+ GeeHashMap* _tmp0_;
+ IndicateListener* _tmp1_;
+ self = (MusicPlayerBridge*) g_object_new (object_type, NULL);
+ self->priv->registered_clients = (_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, TYPE_PLAYER_CONTROLLER, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL), _g_object_unref0 (self->priv->registered_clients), _tmp0_);
+ self->priv->listener = (_tmp1_ = indicate_listener_ref_default (), _g_object_unref0 (self->priv->listener), _tmp1_);
+ g_signal_connect_object (self->priv->listener, "indicator-added", (GCallback) _music_player_bridge_on_indicator_added_indicate_listener_indicator_added, self, 0);
+ g_signal_connect_object (self->priv->listener, "indicator-removed", (GCallback) _music_player_bridge_on_indicator_removed_indicate_listener_indicator_removed, self, 0);
+ g_signal_connect_object (self->priv->listener, "indicator-modified", (GCallback) _music_player_bridge_on_indicator_modified_indicate_listener_indicator_modified, self, 0);
+ g_signal_connect_object (self->priv->listener, "server-added", (GCallback) _music_player_bridge_on_server_added_indicate_listener_server_added, self, 0);
+ g_signal_connect_object (self->priv->listener, "server-removed", (GCallback) _music_player_bridge_on_server_removed_indicate_listener_server_removed, self, 0);
+ g_signal_connect_object (self->priv->listener, "server-count-changed", (GCallback) _music_player_bridge_on_server_count_changed_indicate_listener_server_count_changed, self, 0);
+ return self;
+}
+
+
+MusicPlayerBridge* music_player_bridge_new (void) {
+ return music_player_bridge_construct (TYPE_MUSIC_PLAYER_BRIDGE);
+}
+
+
+static gpointer _g_object_ref0 (gpointer self) {
+ return self ? g_object_ref (self) : NULL;
+}
+
+
+void music_player_bridge_set_root_menu_item (MusicPlayerBridge* self, DbusmenuMenuitem* menu) {
+ DbusmenuMenuitem* _tmp0_;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (menu != NULL);
+ self->priv->root_menu = (_tmp0_ = _g_object_ref0 (menu), _g_object_unref0 (self->priv->root_menu), _tmp0_);
+}
+
+
+void music_player_bridge_on_indicator_added (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0) {
+ g_return_if_fail (self != NULL);
+ g_debug ("music-player-bridge.vala:51: MusicPlayerBridge-> on_indicator_added");
+}
+
+
+void music_player_bridge_on_indicator_removed (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0) {
+ g_return_if_fail (self != NULL);
+ g_debug ("music-player-bridge.vala:56: MusicPlayerBridge -> on_indicator_removed");
+}
+
+
+void music_player_bridge_on_indicator_modified (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0, const char* s) {
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (s != NULL);
+ g_debug ("music-player-bridge.vala:61: MusicPlayerBridge -> indicator_modified w" \
+"ith vale %s", s);
+}
+
+
+void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListenerServer* object, const char* type) {
+ gint _tmp1__length1;
+ char** _tmp1_;
+ char** _tmp0_;
+ char* _tmp2_;
+ char* client_name;
+ gboolean _tmp3_ = FALSE;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (type != NULL);
+ g_debug ("music-player-bridge.vala:66: MusicPlayerBridge -> on_server_added with" \
+" value %s", type);
+ if (music_player_bridge_server_is_not_of_interest (self, type)) {
+ return;
+ }
+ client_name = (_tmp2_ = g_strdup ((_tmp1_ = _tmp0_ = g_strsplit (type, ".", 0), _tmp1__length1 = _vala_array_length (_tmp0_), _tmp1_)[1]), _tmp1_ = (_vala_array_free (_tmp1_, _tmp1__length1, (GDestroyNotify) g_free), NULL), _tmp2_);
+ if (self->priv->root_menu != NULL) {
+ _tmp3_ = client_name != NULL;
+ } else {
+ _tmp3_ = FALSE;
+ }
+ if (_tmp3_) {
+ PlayerController* ctrl;
+ ctrl = player_controller_new (self->priv->root_menu, client_name, TRUE);
+ gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, client_name, ctrl);
+ g_debug ("music-player-bridge.vala:72: client of name %s has successfully regist" \
+"ered with us", client_name);
+ _g_object_unref0 (ctrl);
+ }
+ _g_free0 (client_name);
+}
+
+
+void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateListenerServer* object, const char* type) {
+ gint _tmp1__length1;
+ char** _tmp1_;
+ char** _tmp0_;
+ char* _tmp2_;
+ char* client_name;
+ gboolean _tmp3_ = FALSE;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (type != NULL);
+ g_debug ("music-player-bridge.vala:78: MusicPlayerBridge -> on_server_removed wi" \
+"th value %s", type);
+ if (music_player_bridge_server_is_not_of_interest (self, type)) {
+ return;
+ }
+ client_name = (_tmp2_ = g_strdup ((_tmp1_ = _tmp0_ = g_strsplit (type, ".", 0), _tmp1__length1 = _vala_array_length (_tmp0_), _tmp1_)[1]), _tmp1_ = (_vala_array_free (_tmp1_, _tmp1__length1, (GDestroyNotify) g_free), NULL), _tmp2_);
+ if (self->priv->root_menu != NULL) {
+ _tmp3_ = client_name != NULL;
+ } else {
+ _tmp3_ = FALSE;
+ }
+ if (_tmp3_) {
+ PlayerController* _tmp4_;
+ player_controller_vanish (_tmp4_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name));
+ _g_object_unref0 (_tmp4_);
+ gee_map_remove ((GeeMap*) self->priv->registered_clients, client_name, NULL);
+ g_debug ("music-player-bridge.vala:84: Successively removed menu_item for client" \
+" %s from registered_clients", client_name);
+ }
+ _g_free0 (client_name);
+}
+
+
+static gboolean string_contains (const char* self, const char* needle) {
+ gboolean result = FALSE;
+ g_return_val_if_fail (self != NULL, FALSE);
+ g_return_val_if_fail (needle != NULL, FALSE);
+ result = strstr (self, needle) != NULL;
+ return result;
+}
+
+
+static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge* self, const char* type) {
+ gboolean result = FALSE;
+ g_return_val_if_fail (self != NULL, FALSE);
+ g_return_val_if_fail (type != NULL, FALSE);
+ if (type == NULL) {
+ result = TRUE;
+ return result;
+ }
+ if (string_contains (type, "music") == FALSE) {
+ g_debug ("music-player-bridge.vala:91: server is of no interest, it is not an m" \
+"usic server");
+ result = TRUE;
+ return result;
+ }
+ result = FALSE;
+ return result;
+}
+
+
+void music_player_bridge_on_server_count_changed (MusicPlayerBridge* self, IndicateListenerServer* object, guint i) {
+ g_return_if_fail (self != NULL);
+ g_debug ("music-player-bridge.vala:99: MusicPlayerBridge-> on_server_count_chang" \
+"ed with value %u", i);
+}
+
+
+static void music_player_bridge_class_init (MusicPlayerBridgeClass * klass) {
+ music_player_bridge_parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (klass, sizeof (MusicPlayerBridgePrivate));
+ G_OBJECT_CLASS (klass)->finalize = music_player_bridge_finalize;
+}
+
+
+static void music_player_bridge_instance_init (MusicPlayerBridge * self) {
+ self->priv = MUSIC_PLAYER_BRIDGE_GET_PRIVATE (self);
+}
+
+
+static void music_player_bridge_finalize (GObject* obj) {
+ MusicPlayerBridge * self;
+ self = MUSIC_PLAYER_BRIDGE (obj);
+ _g_object_unref0 (self->priv->listener);
+ _g_object_unref0 (self->priv->root_menu);
+ _g_object_unref0 (self->priv->registered_clients);
+ G_OBJECT_CLASS (music_player_bridge_parent_class)->finalize (obj);
+}
+
+
+GType music_player_bridge_get_type (void) {
+ static volatile gsize music_player_bridge_type_id__volatile = 0;
+ if (g_once_init_enter (&music_player_bridge_type_id__volatile)) {
+ static const GTypeInfo g_define_type_info = { sizeof (MusicPlayerBridgeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) music_player_bridge_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MusicPlayerBridge), 0, (GInstanceInitFunc) music_player_bridge_instance_init, NULL };
+ GType music_player_bridge_type_id;
+ music_player_bridge_type_id = g_type_register_static (G_TYPE_OBJECT, "MusicPlayerBridge", &g_define_type_info, 0);
+ g_once_init_leave (&music_player_bridge_type_id__volatile, music_player_bridge_type_id);
+ }
+ return music_player_bridge_type_id__volatile;
+}
+
+
+static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
+ if ((array != NULL) && (destroy_func != NULL)) {
+ int i;
+ for (i = 0; i < array_length; i = i + 1) {
+ if (((gpointer*) array)[i] != NULL) {
+ destroy_func (((gpointer*) array)[i]);
+ }
+ }
+ }
+}
+
+
+static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
+ _vala_array_destroy (array, array_length, destroy_func);
+ g_free (array);
+}
+
+
+static gint _vala_array_length (gpointer array) {
+ int length;
+ length = 0;
+ if (array) {
+ while (((gpointer*) array)[length]) {
+ length++;
+ }
+ }
+ return length;
+}
+
+
+
+