aboutsummaryrefslogtreecommitdiff
path: root/src/music-player-bridge.c
blob: dddaa1a88ae6d85fd43499bd4d723a85a0dd44ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/* music-player-bridge.c generated by valac 0.10.0, the Vala compiler
 * generated from music-player-bridge.vala, do not modify */

/*
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>
#include <gio/gdesktopappinfo.h>
#include <gio/gio.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 TYPE_FAMILIAR_PLAYERS_DB (familiar_players_db_get_type ())
#define FAMILIAR_PLAYERS_DB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDB))
#define FAMILIAR_PLAYERS_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDBClass))
#define IS_FAMILIAR_PLAYERS_DB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FAMILIAR_PLAYERS_DB))
#define IS_FAMILIAR_PLAYERS_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FAMILIAR_PLAYERS_DB))
#define FAMILIAR_PLAYERS_DB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDBClass))

typedef struct _FamiliarPlayersDB FamiliarPlayersDB;
typedef struct _FamiliarPlayersDBClass FamiliarPlayersDBClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define PLAYER_CONTROLLER_TYPE_STATE (player_controller_state_get_type ())

struct _MusicPlayerBridge {
	GObject parent_instance;
	MusicPlayerBridgePrivate * priv;
};

struct _MusicPlayerBridgeClass {
	GObjectClass parent_class;
};

struct _MusicPlayerBridgePrivate {
	IndicateListener* listener;
	DbusmenuMenuitem* root_menu;
	GeeHashMap* registered_clients;
	FamiliarPlayersDB* playersDB;
};

typedef enum  {
	PLAYER_CONTROLLER_STATE_OFFLINE,
	PLAYER_CONTROLLER_STATE_INSTANTIATING,
	PLAYER_CONTROLLER_STATE_READY,
	PLAYER_CONTROLLER_STATE_CONNECTED,
	PLAYER_CONTROLLER_STATE_DISCONNECTED
} PlayerControllerstate;


static gpointer music_player_bridge_parent_class = NULL;

GType music_player_bridge_get_type (void) G_GNUC_CONST;
GType player_controller_get_type (void) G_GNUC_CONST;
GType familiar_players_db_get_type (void) G_GNUC_CONST;
#define MUSIC_PLAYER_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MUSIC_PLAYER_BRIDGE, MusicPlayerBridgePrivate))
enum  {
	MUSIC_PLAYER_BRIDGE_DUMMY_PROPERTY
};
MusicPlayerBridge* music_player_bridge_new (void);
MusicPlayerBridge* music_player_bridge_construct (GType object_type);
FamiliarPlayersDB* familiar_players_db_new (void);
FamiliarPlayersDB* familiar_players_db_construct (GType object_type);
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);
static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlayerBridge* self);
GeeSet* familiar_players_db_records (FamiliarPlayersDB* self);
static char* music_player_bridge_truncate_player_name (char* app_info_name);
static char* music_player_bridge_determine_key (char* path);
static gint music_player_bridge_calculate_menu_position (MusicPlayerBridge* self);
GType player_controller_state_get_type (void) G_GNUC_CONST;
PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, const char* mpris_name, gint offset, PlayerControllerstate initial_state);
PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, const char* mpris_name, gint offset, PlayerControllerstate initial_state);
void player_controller_set_app_info (PlayerController* self, GAppInfo* value);
GAppInfo* player_controller_get_app_info (PlayerController* self);
#define PLAYER_CONTROLLER_WIDGET_QUANTITY 4
static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge* self, const char* type);
static void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, IndicateListenerServer* server, char* path, void* data);
GAppInfo* music_player_bridge_create_app_info (const char* path);
gboolean familiar_players_db_already_familiar (FamiliarPlayersDB* self, const char* desktop);
void familiar_players_db_insert (FamiliarPlayersDB* self, const char* desktop);
void player_controller_update_state (PlayerController* self, PlayerControllerstate new_state);
void player_controller_activate (PlayerController* self);
void player_controller_hibernate (PlayerController* self);
void music_player_bridge_set_root_menu_item (MusicPlayerBridge* self, DbusmenuMenuitem* menu);
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_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);
}


MusicPlayerBridge* music_player_bridge_construct (GType object_type) {
	MusicPlayerBridge * self;
	FamiliarPlayersDB* _tmp0_;
	GeeHashMap* _tmp1_;
	IndicateListener* _tmp2_;
	self = (MusicPlayerBridge*) g_object_new (object_type, NULL);
	self->priv->playersDB = (_tmp0_ = familiar_players_db_new (), _g_object_unref0 (self->priv->playersDB), _tmp0_);
	self->priv->registered_clients = (_tmp1_ = 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), _tmp1_);
	self->priv->listener = (_tmp2_ = indicate_listener_ref_default (), _g_object_unref0 (self->priv->listener), _tmp2_);
	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);
	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;
}


static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlayerBridge* self) {
	g_return_if_fail (self != NULL);
	{
		GeeSet* _tmp0_;
		GeeIterator* _tmp1_;
		GeeIterator* _app_it;
		_app_it = (_tmp1_ = gee_iterable_iterator ((GeeIterable*) (_tmp0_ = familiar_players_db_records (self->priv->playersDB))), _g_object_unref0 (_tmp0_), _tmp1_);
		while (TRUE) {
			char* app;
			GDesktopAppInfo* info;
			GDesktopAppInfo* _tmp2_;
			GAppInfo* app_info;
			char* _tmp3_;
			char* _tmp4_;
			PlayerController* _tmp5_;
			PlayerController* ctrl;
			char* _tmp6_;
			if (!gee_iterator_next (_app_it)) {
				break;
			}
			app = (char*) gee_iterator_get (_app_it);
			if (app == NULL) {
				g_warning ("music-player-bridge.vala:45: App string in keyfile is null therefore m" \
"oving on to next player");
				_g_free0 (app);
				continue;
			}
			g_debug ("music-player-bridge.vala:49: attempting to make an app info from %s", app);
			info = g_desktop_app_info_new_from_filename (app);
			if (info == NULL) {
				g_warning ("music-player-bridge.vala:54: Could not create a desktopappinfo instanc" \
"e from app: %s", app);
				_g_object_unref0 (info);
				_g_free0 (app);
				continue;
			}
			app_info = _g_object_ref0 ((_tmp2_ = info, G_IS_APP_INFO (_tmp2_) ? ((GAppInfo*) _tmp2_) : NULL));
			ctrl = (_tmp5_ = player_controller_new (self->priv->root_menu, _tmp3_ = music_player_bridge_truncate_player_name (g_strdup (g_app_info_get_name (app_info))), _tmp4_ = music_player_bridge_determine_key (g_strdup (app)), music_player_bridge_calculate_menu_position (self), PLAYER_CONTROLLER_STATE_OFFLINE), _g_free0 (_tmp4_), _g_free0 (_tmp3_), _tmp5_);
			player_controller_set_app_info (ctrl, app_info);
			if (player_controller_get_app_info (ctrl) == NULL) {
				g_warning ("music-player-bridge.vala:66: for some reason the app info is null");
			}
			gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, _tmp6_ = music_player_bridge_determine_key (g_strdup (app)), ctrl);
			_g_free0 (_tmp6_);
			_g_object_unref0 (ctrl);
			_g_object_unref0 (app_info);
			_g_object_unref0 (info);
			_g_free0 (app);
		}
		_g_object_unref0 (_app_it);
	}
}


static gint music_player_bridge_calculate_menu_position (MusicPlayerBridge* self) {
	gint result = 0;
	g_return_val_if_fail (self != NULL, 0);
	if (gee_map_get_size ((GeeMap*) self->priv->registered_clients) == 0) {
		result = 2;
		return result;
	} else {
		result = 2 + (gee_map_get_size ((GeeMap*) self->priv->registered_clients) * PLAYER_CONTROLLER_WIDGET_QUANTITY);
		return result;
	}
}


void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListenerServer* object, const char* type) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (type != NULL);
	g_debug ("music-player-bridge.vala:83: MusicPlayerBridge -> on_server_added with" \
" value %s", type);
	if (music_player_bridge_server_is_not_of_interest (self, type)) {
		return;
	}
	if (self->priv->root_menu != NULL) {
		indicate_listener_get_server_property_cb cb;
		cb = (indicate_listener_get_server_property_cb) music_player_bridge_desktop_info_callback;
		indicate_listener_server_get_desktop (self->priv->listener, object, cb, self);
	}
}


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 void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, IndicateListenerServer* server, char* path, void* data) {
	void* _tmp0_;
	MusicPlayerBridge* bridge;
	GAppInfo* app_info;
	char* name;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	bridge = _g_object_ref0 ((_tmp0_ = data, IS_MUSIC_PLAYER_BRIDGE (_tmp0_) ? ((MusicPlayerBridge*) _tmp0_) : NULL));
	app_info = music_player_bridge_create_app_info (path);
	name = music_player_bridge_truncate_player_name (g_strdup (g_app_info_get_name (app_info)));
	if (string_contains (path, "/")) {
		_tmp1_ = familiar_players_db_already_familiar (bridge->priv->playersDB, path) == FALSE;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		char* _tmp2_;
		PlayerController* _tmp3_;
		PlayerController* ctrl;
		char* _tmp4_;
		g_debug ("music-player-bridge.vala:99: About to store desktop file path: %s", path);
		familiar_players_db_insert (bridge->priv->playersDB, path);
		ctrl = (_tmp3_ = player_controller_new (bridge->priv->root_menu, name, _tmp2_ = music_player_bridge_determine_key (g_strdup (path)), music_player_bridge_calculate_menu_position (bridge), PLAYER_CONTROLLER_STATE_READY), _g_free0 (_tmp2_), _tmp3_);
		g_object_set ((GObject*) ctrl, "app_info", app_info, NULL);
		gee_abstract_map_set ((GeeAbstractMap*) bridge->priv->registered_clients, _tmp4_ = music_player_bridge_determine_key (g_strdup (path)), ctrl);
		_g_free0 (_tmp4_);
		g_debug ("music-player-bridge.vala:108: successfully created appinfo and instanc" \
"e from path and set it on the respective instance");
		_g_object_unref0 (ctrl);
	} else {
		char* key;
		PlayerController* _tmp5_;
		PlayerController* _tmp6_;
		key = music_player_bridge_determine_key (g_strdup (path));
		player_controller_update_state (_tmp5_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) bridge->priv->registered_clients, key), PLAYER_CONTROLLER_STATE_READY);
		_g_object_unref0 (_tmp5_);
		player_controller_activate (_tmp6_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) bridge->priv->registered_clients, key));
		_g_object_unref0 (_tmp6_);
		g_debug ("music-player-bridge.vala:114: Ignoring desktop file path callback beca" \
"use the db cache file has it already: %s", path);
		_g_free0 (key);
	}
	_g_free0 (name);
	_g_object_unref0 (app_info);
	_g_object_unref0 (bridge);
	_g_free0 (path);
}


void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateListenerServer* object, const char* type) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (type != NULL);
	g_debug ("music-player-bridge.vala:120: MusicPlayerBridge -> on_server_removed w" \
"ith value %s", type);
	if (music_player_bridge_server_is_not_of_interest (self, type)) {
		return;
	}
	if (self->priv->root_menu != NULL) {
		gint tmp_length1;
		gint _tmp_size_;
		char** _tmp1_;
		char** _tmp0_;
		char** tmp;
		tmp = (_tmp1_ = _tmp0_ = g_strsplit (type, ".", 0), tmp_length1 = _vala_array_length (_tmp0_), _tmp_size_ = tmp_length1, _tmp1_);
		g_debug ("music-player-bridge.vala:124: attempt to remove %s", tmp[tmp_length1 - 1]);
		if (tmp_length1 > 0) {
			PlayerController* _tmp2_;
			player_controller_hibernate (_tmp2_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, tmp[tmp_length1 - 1]));
			_g_object_unref0 (_tmp2_);
			g_debug ("music-player-bridge.vala:127: Successively offlined client %s", tmp[tmp_length1 - 1]);
		}
		tmp = (_vala_array_free (tmp, tmp_length1, (GDestroyNotify) g_free), NULL);
	}
}


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:135: server is of no interest,  it is not an " \
"music server");
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}


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_);
	music_player_bridge_try_to_add_inactive_familiar_clients (self);
}


GAppInfo* music_player_bridge_create_app_info (const char* path) {
	GAppInfo* result = NULL;
	GDesktopAppInfo* info;
	GDesktopAppInfo* _tmp0_;
	GAppInfo* app_info;
	g_return_val_if_fail (path != NULL, NULL);
	info = g_desktop_app_info_new_from_filename (path);
	if (path == NULL) {
		g_warning ("music-player-bridge.vala:151: Could not create a desktopappinfo instan" \
"ce from app: %s", path);
		result = NULL;
		_g_object_unref0 (info);
		return result;
	}
	app_info = _g_object_ref0 ((_tmp0_ = info, G_IS_APP_INFO (_tmp0_) ? ((GAppInfo*) _tmp0_) : NULL));
	result = app_info;
	_g_object_unref0 (info);
	return result;
}


static char* string_strip (const char* self) {
	char* result = NULL;
	char* _result_;
	g_return_val_if_fail (self != NULL, NULL);
	_result_ = g_strdup (self);
	g_strstrip (_result_);
	result = _result_;
	return result;
}


static char* music_player_bridge_truncate_player_name (char* app_info_name) {
	char* result = NULL;
	char* _tmp0_;
	char* _tmp1_;
	char* _result_;
	gint tokens_length1;
	gint _tokens_size_;
	char** _tmp3_;
	char** _tmp2_;
	char** tokens;
	g_return_val_if_fail (app_info_name != NULL, NULL);
	_result_ = (_tmp1_ = string_strip (_tmp0_ = g_utf8_strdown (app_info_name, -1)), _g_free0 (_tmp0_), _tmp1_);
	tokens = (_tmp3_ = _tmp2_ = g_strsplit (_result_, " ", 0), tokens_length1 = _vala_array_length (_tmp2_), _tokens_size_ = tokens_length1, _tmp3_);
	if (tokens_length1 > 1) {
		char* _tmp4_;
		_result_ = (_tmp4_ = g_strdup (tokens[0]), _g_free0 (_result_), _tmp4_);
	}
	g_debug ("music-player-bridge.vala:167: truncate player name %s", _result_);
	result = _result_;
	tokens = (_vala_array_free (tokens, tokens_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (app_info_name);
	return result;
}


static char* music_player_bridge_determine_key (char* path) {
	char* result = NULL;
	gint tokens_length1;
	gint _tokens_size_;
	char** _tmp1_;
	char** _tmp0_;
	char** tokens;
	char* filename;
	char** _tmp2_;
	char** _tmp3_;
	gint _tmp3__length1;
	char* _tmp4_;
	char* _result_;
	gint temp_length1;
	gint _temp_size_;
	char** _tmp6_;
	char** _tmp5_;
	char** temp;
	g_return_val_if_fail (path != NULL, NULL);
	tokens = (_tmp1_ = _tmp0_ = g_strsplit (path, "/", 0), tokens_length1 = _vala_array_length (_tmp0_), _tokens_size_ = tokens_length1, _tmp1_);
	if (tokens_length1 < 2) {
		result = NULL;
		tokens = (_vala_array_free (tokens, tokens_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (path);
		return result;
	}
	filename = g_strdup (tokens[tokens_length1 - 1]);
	_result_ = (_tmp4_ = g_strdup ((_tmp3_ = _tmp2_ = g_strsplit (filename, ".", 0), _tmp3__length1 = _vala_array_length (_tmp2_), _tmp3_)[0]), _tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL), _tmp4_);
	temp = (_tmp6_ = _tmp5_ = g_strsplit (_result_, "-", 0), temp_length1 = _vala_array_length (_tmp5_), _temp_size_ = temp_length1, _tmp6_);
	if (temp_length1 > 1) {
		char* _tmp7_;
		_result_ = (_tmp7_ = g_strdup (temp[0]), _g_free0 (_result_), _tmp7_);
	}
	g_debug ("music-player-bridge.vala:181: determine key result = %s", _result_);
	result = _result_;
	temp = (_vala_array_free (temp, temp_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (filename);
	tokens = (_vala_array_free (tokens, tokens_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (path);
	return result;
}


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_unref0 (self->priv->playersDB);
	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;
}