Debian Codegraph @

musicPlayer/src/applet-listen.c

raw
1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <glib/gi18n.h>
24 #include <cairo-dock.h>
25
26
27 #include "applet-struct.h"
28 #include "applet-musicplayer.h"
29 #include "applet-dbus.h"
30 #include "applet-draw.h"
31 #include "applet-listen.h"
32
33
34 //Les Fonctions
35 static void cd_listen_getSongInfos(void)
36 {
37 if( myData.cPreviousRawTitle )
38 {
39 g_free( myData.cPreviousRawTitle ); myData.cPreviousRawTitle = NULL;
40 }
41 if( myData.cRawTitle )
42 {
43 myData.cPreviousRawTitle = g_strdup(myData.cRawTitle);
44 }
45 myData.cRawTitle=cairo_dock_dbus_get_string (myData.dbus_proxy_player, "current_playing");
46 }
47
48 /* Controle du lecteur */
49 static void cd_listen_control (MyPlayerControl pControl, const char *file) { //Permet d'effectuer les actions de bases sur le lecteur
50 cd_debug ("");
51
52 const gchar *cCommand = NULL;
53 /* Conseil de ChangFu pour redetecter le titre à coup sûr */
54 g_free (myData.cRawTitle);
55 myData.cRawTitle = NULL;
56
57 switch (pControl) {
58 case PLAYER_PREVIOUS :
59 cCommand = "previous";
60 break;
61
62 case PLAYER_PLAY_PAUSE :
63 cCommand = "play_pause";
64 break;
65
66 case PLAYER_NEXT :
67 cCommand = "next";
68 break;
69
70 default :
71 return;
72 break;
73 }
74
75 if (cCommand != NULL) {
76 cd_debug ("MP : Handler Listen : will use '%s'", cCommand);
77 cairo_dock_dbus_call(myData.dbus_proxy_player, cCommand);
78 }
79 }
80
81 /* Fonction de lecture des infos */
82 static void cd_listen_get_data (void)
83 {
84 cd_listen_getSongInfos(); // On recupere toutes les infos de la piste en cours
85 }
86
87
88 void cd_musicplayer_register_listen_handler (void) { //On enregistre notre lecteur
89 MusicPlayerHandler *pHandler = g_new0 (MusicPlayerHandler, 1);
90 pHandler->name = "Listen";
91 pHandler->get_data = cd_listen_get_data;
92 pHandler->stop = NULL;
93 pHandler->start = NULL; // nothing to do, since there is no signal to connect to, and we'll get the stats on the first iteration of the loop.
94 pHandler->control = cd_listen_control;
95 pHandler->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT;
96 pHandler->appclass = "listen.py";
97 pHandler->launch = "listen"; /// a verifier ..
98
99 pHandler->cMprisService = "org.gnome.Listen";
100 pHandler->cMpris2Service = "org.mpris.MediaPlayer2.listen";
101 pHandler->path = "/org/gnome/listen";
102 pHandler->interface = "org.gnome.Listen";
103 pHandler->path2 = NULL;
104 pHandler->interface2 = NULL;
105
106 pHandler->bSeparateAcquisition = FALSE;
107 pHandler->iLevel = PLAYER_BAD;
108 cd_musicplayer_register_my_handler (pHandler);
109 }