Debian Codegraph @

musicPlayer/src/applet-amarok1.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 #include "applet-struct.h"
27 #include "applet-musicplayer.h"
28 #include "applet-draw.h"
29 #include "applet-amarok1.h"
30 #include "applet-dcop.h"
31 #include "applet-cover.h"
32
33
34 //Les Fonctions
35 void cd_amarok1_free_data (void) { //Permet de libéré la mémoire prise par notre controleur
36 cd_debug ("");
37 }
38
39 void cd_amarok1_control (MyPlayerControl pControl, const gchar *cFile) { //Permet d'effectuer les actions de bases sur le lecteur
40 GError *erreur = NULL;
41
42 if (pControl != PLAYER_JUMPBOX && pControl != PLAYER_SHUFFLE && pControl != PLAYER_REPEAT && pControl != PLAYER_ENQUEUE) {
43 g_free (myData.cRawTitle);
44 myData.cRawTitle = NULL; //Reset the title to detect it for sure ;)
45 }
46 gchar *cCommand = NULL;
47
48 switch (pControl) {
49 case PLAYER_PREVIOUS :
50 cCommand = "dcop amarok player prev";
51 break;
52 case PLAYER_PLAY_PAUSE :
53 cCommand = "dcop amarok player playPause";
54 break;
55 case PLAYER_STOP :
56 cCommand = "dcop amarok player stop";
57 break;
58 case PLAYER_NEXT :
59 cCommand = "dcop amarok player next";
60 break;
61 case PLAYER_SHUFFLE :
62 cCommand = "dcop amarok playlist shufflePlaylist";
63 break;
64 case PLAYER_REPEAT :
65 cCommand = g_strdup_printf("dcop amarok player enableRepeatPlaylist %s",
66 cd_dcop_get_boolean("dcop amarok player repeatPlaylistStatu") ?
67 "true" : "false");
68 /*recuperer le boolean "dcop amarok player repeatPlaylistStatus"
69 puis lancer : "dcop amarok player enableRepeatPlaylist false/true"*/
70 break;
71 case PLAYER_ENQUEUE :
72 if (cFile != NULL)
73 cCommand = g_strdup_printf ("dcop amarok playlist addMediaList [ \"%s\" ]", cFile);
74 break;
75 default :
76 return;
77 break;
78 }
79
80 cd_debug ("Handler Amarok 1.4: will use '%s'", cCommand);
81 g_spawn_command_line_async (cCommand, &erreur);
82 if (pControl == PLAYER_ENQUEUE)
83 g_free (cCommand);
84
85 if (erreur != NULL) {
86 cd_warning ("Attention : when trying to execute command : %s", erreur->message);
87 g_error_free (erreur);
88 CD_APPLET_MAKE_TEMPORARY_EMBLEM_CLASSIC (CAIRO_DOCK_EMBLEM_ERROR, CAIRO_DOCK_EMBLEM_UPPER_LEFT, 5000);
89 }
90 }
91
92
93 void cd_amarok1_getStatus (void)
94 {
95 int status = cd_dcop_get_int("dcop amarok player status");
96
97 cd_debug("MP : Status : %i",status);
98 switch (status)
99 {
100 case 0:
101 myData.iPlayingStatus = PLAYER_STOPPED;
102 break;
103 case 1:
104 myData.iPlayingStatus = PLAYER_PAUSED;
105 break;
106 case 2:
107 myData.iPlayingStatus = PLAYER_PLAYING;
108 break;
109 default:
110 break;
111 }
112 }
113
114 //Fonction de lecture du tuyau.
115 void cd_amarok1_read_data (void) {
116 myData.iPreviousCurrentTime = myData.iCurrentTime;
117 myData.pPreviousPlayingStatus=myData.iPlayingStatus;
118 myData.iPreviousTrackNumber=myData.iTrackNumber;
119 myData.iPreviousCurrentTime=myData.iCurrentTime;
120
121 myData.cAlbum = cd_dcop_get_string("dcop amarok player album");
122 myData.cArtist = cd_dcop_get_string("dcop amarok player artist");
123 myData.cTitle = cd_dcop_get_string("dcop amarok player title");
124 myData.iTrackNumber = cd_dcop_get_int("dcop amarok player trackPlayCounter");
125 myData.iSongLength = cd_dcop_get_int("dcop amarok player trackTotalTime");
126 myData.iCurrentTime = cd_dcop_get_int("dcop amarok player trackCurrentTime");
127 myData.cCoverPath = cd_dcop_get_string("dcop amarok player coverImage"); // On recupere l'URI et on verifie que l'image existe et n'est pas l'image par defaut d'amarok
128
129 myData.cRawTitle = g_strdup_printf ("%s - %s", myData.cArtist, myData.cTitle);
130 }
131 void cd_amarok1_acquisition (void) {
132 int r = system ("echo amarok 1.4 >> /dev/null");
133 cd_amarok1_getStatus();
134 if (myData.iPlayingStatus == PLAYER_PLAYING) {
135 cd_amarok1_read_data();
136 }
137 }
138
139
140 void cd_musicplayer_register_amarok1_handler (void) { //On enregistre notre lecteurs
141 MusicPlayerHandler *pAmarok1 = g_new0 (MusicPlayerHandler, 1);
142 pAmarok1->read_data = cd_amarok1_read_data;
143 pAmarok1->free_data = cd_amarok1_free_data;
144 pAmarok1->configure = NULL; //Cette fonction permettera de préparé le controleur
145 //Pour les lecteurs utilisants dbus, c'est elle qui connectera le dock aux services des lecteurs etc..
146 pAmarok1->control = cd_amarok1_control;
147 pAmarok1->iPlayerControls = PLAYER_PREVIOUS | PLAYER_PLAY_PAUSE | PLAYER_NEXT | PLAYER_STOP | PLAYER_SHUFFLE | PLAYER_ENQUEUE | PLAYER_REPEAT;
148 pAmarok1->appclass = "amarok";
149 pAmarok1->name = "Amarok 1.4";
150 pAmarok1->launch = "amarok";
151 pAmarok1->bSeparateAcquisition = FALSE;
152 cd_musicplayer_register_my_handler (pAmarok1);
153 }