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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Rémy Robertson (for any bug report, please mail me to changfu@cairo-dock.org)
26
Fabrice Rey (fabounet@users.berlios.de)
28
******************************************************************************/
34
#include <glib/gstdio.h>
36
#include "applet-struct.h"
37
#include "applet-infopipe.h"
38
#include "applet-draw.h"
41
static char *s_cTmpFile = NULL;
45
INFO_TRACK_IN_PLAYLIST,
46
INFO_TIME_ELAPSED_IN_SEC,
48
INFO_TOTAL_TIME_IN_SEC,
54
static int s_pLineNumber[MY_NB_PLAYERS][NB_INFO] = {
62
//Fonction de lecture du tuyau.
63
void cd_xmms_read_pipe (CairoDockModuleInstance *myApplet)
65
//\________________________ On determine le pipe.
66
gchar *cPipeCommand = NULL;
67
switch (myConfig.iPlayer) { // On emule un pipe pour les lecteurs qui n'en ont pas.
70
case MY_AUDACIOUS : //Il faut émuler le pipe d'audacious par AUDTOOL
71
cPipeCommand = g_strdup_printf ("bash %s/infoaudacious.sh", MY_APPLET_SHARE_DATA_DIR);
73
case MY_BANSHEE : //Le pipe est trop lent et cause des freezes... // Il faut émuler le pipe de banshee par le script
74
cPipeCommand = g_strdup_printf ("bash %s/infobanshee.sh", MY_APPLET_SHARE_DATA_DIR);
76
case MY_EXAILE : //Le pipe est trop lent, récupération des infos une fois sur deux avec un pique du cpu lors de l'éxécution du script // Il faut émuler le pipe d'audacious par Exaile -q
77
cPipeCommand = g_strdup_printf ("bash %s/infoexaile.sh", MY_APPLET_SHARE_DATA_DIR);
83
//\________________________ On lit le pipe.
84
gchar *cResult = NULL;
85
if (cPipeCommand != NULL) // c'est un lecteur avec un pipe emule.
87
cResult = cairo_dock_launch_command_sync (cPipeCommand);
88
g_free (cPipeCommand);
90
else if (myConfig.iPlayer == MY_XMMS) // c'est XMMS, il a deja son propre pipe.
92
gchar *cPipe = g_strdup_printf ("/tmp/xmms-info_%s.0",g_getenv ("USER"));
94
GError *erreur = NULL;
95
g_file_get_contents (cPipe, &cResult, &length, &erreur);
98
cd_warning("xmms : %s", erreur->message);
105
if (cResult == NULL) // erreur lors de la leture du pipe, on sort.
107
myData.playingStatus = PLAYER_NONE;
108
cd_xmms_player_none (myApplet);
112
//\________________________ On recupere les donnees.
113
gchar **cInfopipesList = g_strsplit(cResult, "\n", -1);
116
gchar *cQuickInfo = NULL;
118
myData.iTrackNumber = -1;
119
myData.iCurrentTime = -1;
120
myData.iSongLength = -1;
121
int *pLineNumber = s_pLineNumber[myConfig.iPlayer];
123
for (i = 0; cInfopipesList[i] != NULL; i ++) {
124
cOneInfopipe = cInfopipesList[i];
125
if (i == pLineNumber[INFO_STATUS]) {
126
gchar *str = strchr (cOneInfopipe, ' ');
131
if ((strcmp (str, "Playing") == 0) || (strcmp (str, "playing") == 0))
132
myData.playingStatus = PLAYER_PLAYING;
133
else if ((strcmp (str, "Paused") == 0) || (strcmp (str, "paused") == 0))
134
myData.playingStatus = PLAYER_PAUSED;
135
else if ((strcmp (str, "Stopped") == 0) || (strcmp (str, "stopped") == 0))
136
myData.playingStatus = PLAYER_STOPPED;
138
myData.playingStatus = PLAYER_BROKEN;
141
myData.playingStatus = PLAYER_BROKEN;
143
else if (i == pLineNumber[INFO_TRACK_IN_PLAYLIST]) {
144
if (myConfig.quickInfoType == MY_APPLET_TRACK) {
145
gchar *str = strchr (cOneInfopipe, ':');
150
myData.iTrackNumber = atoi (str);
154
else if (i == pLineNumber[INFO_TIME_ELAPSED_IN_SEC]) {
155
if (myConfig.quickInfoType == MY_APPLET_TIME_ELAPSED || myConfig.quickInfoType == MY_APPLET_TIME_LEFT) {
156
gchar *str = strchr (cOneInfopipe, ' ');
162
myData.iCurrentTime = atoi(str) * 1e-3;
166
else if (i == pLineNumber[INFO_TIME_ELAPSED]) {
167
if ((myConfig.quickInfoType == MY_APPLET_TIME_ELAPSED || myConfig.quickInfoType == MY_APPLET_TIME_LEFT) && myData.iCurrentTime == -1) {
168
gchar *str = strchr (cOneInfopipe, ' ');
173
gchar *str2 = strchr (str, ':');
174
if (str2 == NULL) { // pas de minutes.
175
myData.iCurrentTime = atoi(str);
179
myData.iCurrentTime = atoi(str2+1) + 60*atoi (str); // prions pour qu'ils n'ecrivent jamais les heures ... xD
184
else if (i == pLineNumber[INFO_TOTAL_TIME_IN_SEC]) {
185
if (myConfig.quickInfoType == MY_APPLET_TIME_LEFT) {
186
gchar *str = strchr (cOneInfopipe, ' ');
192
myData.iSongLength = atoi(str) * 1e-3;
196
else if (i == pLineNumber[INFO_TOTAL_TIME]) {
197
if (myConfig.quickInfoType == MY_APPLET_TIME_LEFT && myData.iSongLength == -1) {
198
gchar *str = strchr (cOneInfopipe, ' ');
203
gchar *str2 = strchr (str, ':');
204
if (str2 == NULL) { // pas de minutes.
205
myData.iSongLength = atoi(str);
209
myData.iSongLength = atoi(str2+1) + 60*atoi (str); // prions pour qu'ils n'ecrivent jamais les heures ...
214
else if (i == pLineNumber[INFO_NOW_TITLE]) {
215
gchar *str = strchr (cOneInfopipe, ':');
220
if ((strcmp(str," (null)") != 0) && (myData.playingTitle == NULL || strcmp(str, myData.playingTitle) != 0)) {
221
g_free (myData.playingTitle);
222
myData.playingTitle = g_strdup (str);
223
cd_message("On a changé de son! (%s)", myData.playingTitle);
224
cd_xmms_change_desklet_data(myApplet);
228
} // fin de parcours des lignes.
229
g_strfreev (cInfopipesList);
231
if (myConfig.iPlayer != MY_XMMS) {
232
g_remove (s_cTmpFile);