2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
23
#include <glib/gi18n.h>
24
#include <cairo-dock.h>
26
#include "applet-struct.h"
27
#include "applet-musicplayer.h"
28
#include "applet-draw.h"
30
#include "applet-xmms.h"
33
//Structure et données necessaires
36
INFO_TRACK_IN_PLAYLIST,
37
INFO_TIME_ELAPSED_IN_SEC,
39
INFO_TOTAL_TIME_IN_SEC,
45
static char *s_cTmpFile = NULL;
46
static int s_pLineNumber[NB_INFO] = {2,4,5,6,7,8,12};
49
void cd_xmms_free_data (void) { //Permet de libéré la mémoire prise par notre controleur
55
void cd_xmms_control (MyPlayerControl pControl, gchar *cFile) { //Permet d'effectuer les actions de bases sur le lecteur
56
GError *erreur = NULL;
58
if (pControl != PLAYER_JUMPBOX && pControl != PLAYER_SHUFFLE && pControl != PLAYER_REPEAT && pControl != PLAYER_ENQUEUE) {
59
g_free (myData.cRawTitle);
60
myData.cRawTitle = NULL; //Reset the title to detect it for sure ;)
62
gchar *cCommand = NULL;
65
case PLAYER_PREVIOUS :
68
case PLAYER_PLAY_PAUSE :
88
cCommand = g_strdup_printf ("xmms -e %s", cFile);
92
cd_debug ("Handeler XMMS: will use '%s'", cCommand);
93
g_spawn_command_line_async (cCommand, &erreur);
94
if (pControl == PLAYER_ENQUEUE)
98
cd_warning ("Attention : when trying to execute command : %s", erreur->message);
99
g_error_free (erreur);
100
CD_APPLET_MAKE_TEMPORARY_EMBLEM_CLASSIC (CAIRO_DOCK_EMBLEM_ERROR, CAIRO_DOCK_EMBLEM_UPPER_LEFT, 5000);
104
//Fonction de lecture du tuyau.
105
void cd_xmms_read_data (void) {
106
s_cTmpFile = g_strdup_printf("/tmp/xmms-info_%s.0",g_getenv ("USER"));
108
gchar *cContent = NULL;
109
gchar *cQuickInfo = NULL;
111
GError *erreur = NULL;
112
g_file_get_contents (s_cTmpFile, &cContent, &length, &erreur);
113
if (erreur != NULL) {
114
cd_warning ("MP : %s", erreur->message);
115
g_error_free (erreur);
116
myData.iPlayingStatus = PLAYER_NONE;
117
//cd_musicplayer_player_none ();
120
gchar **cInfopipesList = g_strsplit(cContent, "\n", -1);
123
myData.iTrackNumber = -1;
124
myData.iCurrentTime = -1;
125
myData.iSongLength = -1;
127
for (i = 0; cInfopipesList[i] != NULL; i ++) {
128
cOneInfopipe = cInfopipesList[i];
129
if (i == s_pLineNumber[INFO_STATUS]) {
130
gchar *str = strchr (cOneInfopipe, ' ');
135
if ((strcmp (str, "Playing") == 0) || (strcmp (str, "playing") == 0))
136
myData.iPlayingStatus = PLAYER_PLAYING;
137
else if ((strcmp (str, "Paused") == 0) || (strcmp (str, "paused") == 0))
138
myData.iPlayingStatus = PLAYER_PAUSED;
139
else if ((strcmp (str, "Stopped") == 0) || (strcmp (str, "stopped") == 0))
140
myData.iPlayingStatus = PLAYER_STOPPED;
142
myData.iPlayingStatus = PLAYER_BROKEN;
145
myData.iPlayingStatus = PLAYER_BROKEN;
147
else if (i == s_pLineNumber[INFO_TRACK_IN_PLAYLIST]) {
148
if (myConfig.iQuickInfoType == MY_APPLET_TRACK) {
149
gchar *str = strchr (cOneInfopipe, ':');
154
myData.iTrackNumber = atoi (str);
158
else if (i == s_pLineNumber[INFO_TIME_ELAPSED_IN_SEC]) {
159
if (myConfig.iQuickInfoType == MY_APPLET_TIME_ELAPSED || myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT) {
160
gchar *str = strchr (cOneInfopipe, ' ');
166
myData.iCurrentTime = atoi(str) * 1e-3;
170
else if (i == s_pLineNumber[INFO_TIME_ELAPSED]) {
171
if ((myConfig.iQuickInfoType == MY_APPLET_TIME_ELAPSED || myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT) && myData.iCurrentTime == -1) {
172
gchar *str = strchr (cOneInfopipe, ' ');
177
gchar *str2 = strchr (str, ':');
178
if (str2 == NULL) { // pas de minutes.
179
myData.iCurrentTime = atoi(str);
183
myData.iCurrentTime = atoi(str2+1) + 60*atoi (str); // prions pour qu'ils n'ecrivent jamais les heures ... xD
188
else if (i == s_pLineNumber[INFO_TOTAL_TIME_IN_SEC]) {
189
if (myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT) {
190
gchar *str = strchr (cOneInfopipe, ' ');
196
myData.iSongLength = atoi(str) * 1e-3;
200
else if (i == s_pLineNumber[INFO_TOTAL_TIME]) {
201
if (myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT && myData.iSongLength == -1) {
202
gchar *str = strchr (cOneInfopipe, ' ');
207
gchar *str2 = strchr (str, ':');
208
if (str2 == NULL) { // pas de minutes.
209
myData.iSongLength = atoi(str);
213
myData.iSongLength = atoi(str2+1) + 60*atoi (str); // prions pour qu'ils n'ecrivent jamais les heures ...
218
else if (i == s_pLineNumber[INFO_NOW_TITLE]) {
219
gchar *str = strchr (cOneInfopipe, ':');
224
if ((strcmp(str, "(null)") != 0) && (myData.cRawTitle == NULL || strcmp(str, myData.cRawTitle) != 0)) {
225
g_free (myData.cRawTitle);
226
myData.cRawTitle = g_strdup (str);
227
cd_message ("On a changé de son! (%s)", myData.cRawTitle);
228
//cd_musicplayer_change_desklet_data();
232
} // fin de parcours des lignes.
233
g_strfreev (cInfopipesList);
240
void cd_musicplayer_register_xmms_handler (void) { //On enregistre notre lecteurs
241
MusicPlayerHandeler *pXMMS = g_new0 (MusicPlayerHandeler, 1);
242
pXMMS->read_data = cd_xmms_read_data;
243
pXMMS->free_data = cd_xmms_free_data;
244
pXMMS->configure = NULL; //Cette fonction permettera de préparer le controleur
245
//Pour les lecteurs utilisants dbus, c'est elle qui connectera le dock aux services des lecteurs etc..
246
pXMMS->control = cd_xmms_control;
247
pXMMS->appclass = "xmms";
248
pXMMS->name = "XMMS";
249
pXMMS->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT | PLAYER_STOP | PLAYER_JUMPBOX | PLAYER_SHUFFLE | PLAYER_ENQUEUE | PLAYER_REPEAT;
250
pXMMS->launch = "xmms";
251
pXMMS->iPlayer = MP_XMMS;
252
pXMMS->bSeparateAcquisition = TRUE;
253
cd_musicplayer_register_my_handler (pXMMS, "XMMS");