32
32
// MPRIS2 compliant players.
33
33
#include "dbus-mpris2.h"
35
// Handcrafted DBus-interfaces for Skype.
35
// Handcrafted DBus-interface for Skype.
36
36
#include "dbus-skype.h"
38
// Send commands to rec-manager.c
39
#include "rec-manager-struct.h"
39
42
static GHashTable *g_player_list = NULL;
41
// Hopefully the core system sets this function
42
static DBusDataCallbackFunc g_data_callback_func;
44
44
static void dbus_player_disconnect_signals();
45
45
static void dbus_player_clear_list();
71
71
skype_module_exit();
74
void dbus_player_set_callback_func(DBusDataCallbackFunc data_callback_func) {
75
// Set data callback function so we can send messages to rec-manager.c
76
g_data_callback_func = data_callback_func;
74
static RecorderCommand *convert_data(MediaPlayerRec *pl) {
75
// Convert MediaPlayerRec to RecorderCommand
78
TrackInfo *tr = &pl->track;
80
RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
81
cmd->track = g_strndup(tr->track, MPRIS_STRLEN);
82
cmd->artist = g_strndup(tr->artist, MPRIS_STRLEN);
83
cmd->album = g_strndup(tr->album, MPRIS_STRLEN);
84
cmd->track_pos = tr->current_secs;
85
cmd->track_len = tr->total_secs;
86
cmd->flags = tr->flags;
88
// MediaPlayer changed status.
90
if (tr->status == PLAYER_STATUS_PAUSED) {
91
cmd->type = RECORDING_PAUSE;
93
} else if (tr->status == PLAYER_STATUS_PLAYING) {
94
cmd->type = RECORDING_START;
96
} else if (tr->status == PLAYER_STATUS_NOTIFY_MSG) {
97
cmd->type = RECORDING_NOTIFY_MSG;
100
// tr.status == PLAYER_STATUS_CLOSED ||
101
// tr.status == PLAYER_STATUS_STOPPED
102
cmd->type = RECORDING_STOP;
79
108
void dbus_player_process_data(gpointer player) {
80
// Send message to the rec-manager.c?
82
// Has callback function?
83
if (g_data_callback_func) {
85
g_data_callback_func(player);
109
// Send message to the rec-manager.c
112
// Convert MediaPlayerRec to RecorderCommand
113
RecorderCommand *cmd = convert_data(player);
115
// Send the command. Rec-manager will free the cmd structure after processing.
116
rec_manager_send_command(cmd);
89
119
void dbus_player_player_changed(gchar *service_name) {
353
383
player->type = COMM_PROGRAM;
355
385
// Set application name
356
skype_get_app_name(player);
386
player->app_name = skype_get_app_name();
358
388
// Function to register/unregister notification methods
359
389
player->func_set_signals = skype_setup;
380
void dbus_player_send_notification(MediaPlayerRec *player, gchar *msg) {
381
// Send notification msg to the recorder/GUI.
382
MediaPlayerRec *p = NULL;
386
// Create a dummy MediaPlayerRec
387
p = mpris2_player_new(NULL);
390
// Send msg in the track field
391
TrackInfo *tr = &p->track;
393
str_copy(tr->track, msg, MPRIS_STRLEN-1);
395
tr->status = PLAYER_STATUS_NOTIFY_MSG;
397
// Sends the message via dbus-player.c
398
dbus_player_process_data(p);
402
dbus_player_delete_item(p);
410
void dbus_player_send_notification(gchar *msg) {
411
RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
412
cmd->type = RECORDING_NOTIFY_MSG;
413
cmd->track = g_strndup(msg, MPRIS_STRLEN);
415
// Send command to rec-manager.c.
416
// It will free the cmd structure after processing.
417
rec_manager_send_command(cmd);