~cairo-dock-team/ubuntu/precise/cairo-dock-plug-ins/3.0.0.1

« back to all changes in this revision

Viewing changes to musicPlayer/src/applet-xmms.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne, Matthieu Baerts (matttbe), Julien Lavergne
  • Date: 2009-10-05 19:27:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091005192717-mvqvb395guktr401
Tags: 2.0.9-0ubuntu1
[ Matthieu Baerts (matttbe) ]
* New upstream release (LP: #435590)
* debian/control: 
 - Remove ${shlibs:Depends} for integration plug-ins to avoid
   pulling shared libraries which are detected automatically.
 - Added curl as depends for cairo-dock-plug-ins
* debian/rules:
 - Add --enable-dnd2share and --enable-musicplayer to enable new applets.
 - Remove --enable-rhythmbox and --enable-nvidia to remove those applets,
   not maintained upstream.
* Update *.install to take all generated applets.

[ Julien Lavergne ]
* Adjust changelog with Daniel Holbach suggestions.
* cairo-dock-plug-ins.changelogs:  Install specific changelog for 2.0.9
* Build-depends on cairo-dock-dev (>= 2.0.9)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "applet-struct.h"
 
27
#include "applet-musicplayer.h"
 
28
#include "applet-draw.h"
 
29
 
 
30
#include "applet-xmms.h"
 
31
 
 
32
 
 
33
//Structure et données necessaires
 
34
enum {
 
35
        INFO_STATUS = 0,
 
36
        INFO_TRACK_IN_PLAYLIST,
 
37
        INFO_TIME_ELAPSED_IN_SEC,
 
38
        INFO_TIME_ELAPSED,
 
39
        INFO_TOTAL_TIME_IN_SEC,
 
40
        INFO_TOTAL_TIME,
 
41
        INFO_NOW_TITLE,
 
42
        NB_INFO
 
43
} AppletInfoEnum;
 
44
 
 
45
static char  *s_cTmpFile = NULL;
 
46
static int s_pLineNumber[NB_INFO] = {2,4,5,6,7,8,12};
 
47
 
 
48
//Les Fonctions
 
49
void cd_xmms_free_data (void) { //Permet de libéré la mémoire prise par notre controleur
 
50
        cd_debug ("");
 
51
        g_free (s_cTmpFile);
 
52
        s_cTmpFile = NULL;
 
53
}
 
54
 
 
55
void cd_xmms_control (MyPlayerControl pControl, gchar *cFile) { //Permet d'effectuer les actions de bases sur le lecteur
 
56
        GError *erreur = NULL;
 
57
        
 
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 ;)
 
61
        }
 
62
        gchar *cCommand = NULL;
 
63
        
 
64
        switch (pControl) {
 
65
                case PLAYER_PREVIOUS :
 
66
                        cCommand = "xmms -r";
 
67
                break;
 
68
                case PLAYER_PLAY_PAUSE :
 
69
                        cCommand = "xmms -t";
 
70
                break;
 
71
                case PLAYER_STOP :
 
72
                        cCommand = "xmms -s";
 
73
                break;
 
74
                case PLAYER_NEXT :
 
75
                        cCommand = "xmms -f";
 
76
                break;
 
77
                case PLAYER_JUMPBOX :
 
78
                        cCommand = "xmms -j";
 
79
                break;
 
80
                case PLAYER_SHUFFLE :
 
81
                        cCommand = "xmms -S";
 
82
                break;
 
83
                case PLAYER_REPEAT :
 
84
                        cCommand = "xmms -R";
 
85
                break;
 
86
                case PLAYER_ENQUEUE :
 
87
                        if (cFile != NULL)
 
88
                                cCommand = g_strdup_printf ("xmms -e %s", cFile);
 
89
                break;
 
90
        }
 
91
        
 
92
        cd_debug ("Handeler XMMS: will use '%s'", cCommand);
 
93
        g_spawn_command_line_async (cCommand, &erreur);
 
94
        if (pControl == PLAYER_ENQUEUE)
 
95
                g_free (cCommand);
 
96
        
 
97
        if (erreur != NULL) {
 
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);
 
101
        }
 
102
}
 
103
 
 
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"));
 
107
                
 
108
        gchar *cContent = NULL;
 
109
        gchar *cQuickInfo = NULL;
 
110
        gsize length=0;
 
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 ();
 
118
        }
 
119
        else {
 
120
                gchar **cInfopipesList = g_strsplit(cContent, "\n", -1);
 
121
                g_free (cContent);
 
122
                gchar *cOneInfopipe;
 
123
                myData.iTrackNumber = -1;
 
124
                myData.iCurrentTime = -1;
 
125
                myData.iSongLength = -1;
 
126
                int i;
 
127
                for (i = 0; cInfopipesList[i] != NULL; i ++) {
 
128
                        cOneInfopipe = cInfopipesList[i];
 
129
                        if (i == s_pLineNumber[INFO_STATUS]) {
 
130
                                gchar *str = strchr (cOneInfopipe, ' ');
 
131
                                if (str != NULL) {
 
132
                                        str ++;
 
133
                                        while (*str == ' ')
 
134
                                                str ++;
 
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;
 
141
                                        else
 
142
                                                myData.iPlayingStatus = PLAYER_BROKEN;
 
143
                                }
 
144
                                else
 
145
                                        myData.iPlayingStatus = PLAYER_BROKEN;
 
146
                        }
 
147
                        else if (i == s_pLineNumber[INFO_TRACK_IN_PLAYLIST]) {
 
148
                                if (myConfig.iQuickInfoType == MY_APPLET_TRACK) {
 
149
                                        gchar *str = strchr (cOneInfopipe, ':');
 
150
                                        if (str != NULL) {
 
151
                                                str ++;
 
152
                                                while (*str == ' ')
 
153
                                                        str ++;
 
154
                                                myData.iTrackNumber = atoi (str);
 
155
                                        }
 
156
                                }
 
157
                        }
 
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, ' ');
 
161
                                        if (str != NULL) {
 
162
                                                str ++;
 
163
                                                while (*str == ' ')
 
164
                                                        str ++;
 
165
                                                if (*str != 'N')
 
166
                                                        myData.iCurrentTime = atoi(str) * 1e-3;
 
167
                                        }
 
168
                                }
 
169
                        }
 
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, ' ');
 
173
                                        if (str != NULL) {
 
174
                                                str ++;
 
175
                                                while (*str == ' ')
 
176
                                                        str ++;
 
177
                                                gchar *str2 = strchr (str, ':');
 
178
                                                if (str2 == NULL) { // pas de minutes.
 
179
                                                        myData.iCurrentTime = atoi(str);
 
180
                                                }
 
181
                                                else {
 
182
                                                        *str2 = '\0';
 
183
                                                        myData.iCurrentTime = atoi(str2+1) + 60*atoi (str);  // prions pour qu'ils n'ecrivent jamais les heures ... xD
 
184
                                                }
 
185
                                        }
 
186
                                }
 
187
                        }
 
188
                        else if (i == s_pLineNumber[INFO_TOTAL_TIME_IN_SEC]) {
 
189
                                if (myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT) {
 
190
                                        gchar *str = strchr (cOneInfopipe, ' ');
 
191
                                        if (str != NULL) {
 
192
                                                str ++;
 
193
                                                while (*str == ' ')
 
194
                                                        str ++;
 
195
                                                if (*str != 'N')
 
196
                                                        myData.iSongLength = atoi(str) * 1e-3;
 
197
                                        }
 
198
                                }
 
199
                        }
 
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, ' ');
 
203
                                        if (str != NULL) {
 
204
                                                str ++;
 
205
                                                while (*str == ' ')
 
206
                                                        str ++;
 
207
                                                gchar *str2 = strchr (str, ':');
 
208
                                                if (str2 == NULL) { // pas de minutes.
 
209
                                                        myData.iSongLength = atoi(str);
 
210
                                                }
 
211
                                                else {
 
212
                                                        *str2 = '\0';
 
213
                                                        myData.iSongLength = atoi(str2+1) + 60*atoi (str);  // prions pour qu'ils n'ecrivent jamais les heures ...
 
214
                                                }
 
215
                                        }
 
216
                                }
 
217
                        }
 
218
                        else if (i == s_pLineNumber[INFO_NOW_TITLE]) {
 
219
                                gchar *str = strchr (cOneInfopipe, ':');
 
220
                                if (str != NULL) {
 
221
                                        str ++;
 
222
                                        while (*str == ' ')
 
223
                                                str ++;
 
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();
 
229
                                        }
 
230
                                }
 
231
                        }
 
232
                }  // fin de parcours des lignes.
 
233
                g_strfreev (cInfopipesList);
 
234
        }
 
235
        
 
236
        g_free (s_cTmpFile);
 
237
        s_cTmpFile = NULL;
 
238
}
 
239
 
 
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");
 
254
}