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 #ifndef __CD_APPLET_STRUCT__
21 #define  __CD_APPLET_STRUCT__
22 
23 #include <cairo-dock.h>
24 
25 //Canvas
26 typedef struct _MusicPlayerHandler MusicPlayerHandler;
27 
28 typedef enum {
29 	PLAYER_NONE = 0,
30 	PLAYER_PLAYING,
31 	PLAYER_PAUSED,
32 	PLAYER_STOPPED,
33 	PLAYER_BROKEN,
34 	PLAYER_NB_STATUS
35 } MyPlayerStatus;
36 
37 typedef enum {
38 	PLAYER_PREVIOUS		= 1<<0,
39 	PLAYER_PLAY_PAUSE	= 1<<1,
40 	PLAYER_STOP			= 1<<2,
41 	PLAYER_NEXT			= 1<<3,
42 	PLAYER_JUMPBOX		= 1<<4,
43 	PLAYER_SHUFFLE		= 1<<5,
44 	PLAYER_REPEAT		= 1<<6,
45 	PLAYER_ENQUEUE		= 1<<7,
46 	PLAYER_RATE			= 1<<8,
47 	PLAYER_VOLUME		= 1<<9
48 } MyPlayerControl;
49 
50 typedef enum {
51 	PLAYER_BAD=0,  // aucune notification, il faut tout tester en permanence.
52 	PLAYER_GOOD,  // notification de changement d'etat et de chanson, mais pas de temps => il faut une boucle seulement pour afficher le temps ecoule.
53 	PLAYER_EXCELLENT,  // notification pour chaque evenement => aucune boucle n'est necessaire.
54 	PLAYER_NB_LEVELS
55 } MyLevel;  // niveau du lecteur.
56 
57 
58 typedef void (*MusicPlayerGetDataFunc) (void);  // acquisition des donnees, threade.
59 typedef void (*MusicPlayerStopFunc) (void);  // libere les ressources specifiques au backend (deconnexion des signaux, etc)
60 typedef void (*MusicPlayerStartFunc) (void);  // initialise le backend (connexion des signaux, etc)
61 typedef void (*MusicPlayerControlerFunc) (MyPlayerControl pControl, const gchar *cFile);  // controle du lecteur (play/pause/next/etc)
62 typedef void (*MusicPlayerGetCoverFunc) (void);  // pour les lecteurs buggues, recupere la couverture. Renseigner ce champ fera que si le lecteur n'a pas renvoye de couverture au changement de chanson, on retentera 2 secondes plus tard avec cette fonction.
63 typedef gboolean (*MusicPlayerGetLoopStatusFunc) (void);
64 typedef gboolean (*MusicPlayerGetShuffleStatusFunc) (void);
65 typedef gboolean (*MusicPlayerRaiseFunc) (void);  // show window from systray
66 typedef gboolean (*MusicPlayerQuitFunc) (void);  // quit when within the systray
67 
68 
69 struct _MusicPlayerHandler {
70 	const gchar *name;  // nom du backend.
71 	MusicPlayerGetDataFunc 		get_data;
72 	MusicPlayerStopFunc 		stop;
73 	MusicPlayerStartFunc		start;
74 	MusicPlayerControlerFunc	control;
75 	MusicPlayerGetCoverFunc		get_cover;  // actually deprecated, since now most players will send a signal when the 'cover' param is changed.
76 	MusicPlayerGetLoopStatusFunc get_loop_status;
77 	MusicPlayerGetShuffleStatusFunc get_shuffle_status;
78 	MusicPlayerRaiseFunc raise;
79 	MusicPlayerQuitFunc quit;
80 	const gchar *cMprisService;  // old Dbus service name (may not even follow the MPRIS protocole)
81 	const gchar *path;  // Player object
82 	const gchar *interface;
83 	const gchar *path2;  // TrackList object.
84 	const gchar *interface2;
85 	const gchar *appclass;  // classe de l'appli.
86 	const gchar *launch;  // commande lancant le lecteur.
87 	gchar *cDisplayedName;  // displayed name, or NULL
88 	gchar *cCoverDir;  // repertoire utilisateur de l'appli, contenant les couvertures.
89 	gboolean bSeparateAcquisition;  // Sert a activer le thread ou pas (TRUE = active; False = desactive)
90 	MyPlayerControl iPlayerControls;  // un masque "OU" de MyPlayerControl.
91 	MyLevel iLevel;
92 	const gchar *cMpris2Service;  // MPRIS2 dbus name.
93 };
94 
95 //Structures essentielles de l'applet
96 typedef enum {
97 	MY_APPLET_NOTHING = 0,
98 	MY_APPLET_TIME_ELAPSED,
99 	MY_APPLET_TIME_LEFT,
100 	MY_APPLET_PERCENTAGE,
101 	MY_APPLET_TRACK,
102 	MY_APPLET_NB_QUICK_INFO_TYPE
103 } MyAppletQuickInfoType;
104 
105 #define NB_TRANSITION_STEP 8.
106 
107 #define MP_DBUS_TYPE_SONG_METADATA (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
108 
109 #define CD_MPRIS2_SERVICE_BASE "org.mpris.MediaPlayer2"
110 #define CD_MPRIS2_OBJ "/org/mpris/MediaPlayer2"
111 #define CD_MPRIS2_MAIN_IFACE "org.mpris.MediaPlayer2"
112 
113 struct _AppletConfig {
114 	gboolean bEnableDialogs;
115 	gint iDialogDuration;
116 	gboolean bEnableCover;
117 	gboolean bEnableAnim;
118 	gchar *cChangeAnimation;
119 	gchar *cMusicPlayer;
120 	gchar *cLastKnownDesktopFile;  // "desktop-entry" property of the MPRIS2 service. Since we can't have it until we connect to the service, and therefore until the player is running, we can't launch the player (the MPRIS2 name and the binary name are not necessarily the same).
121 	MyAppletQuickInfoType iQuickInfoType;
122 	gchar *cDefaultTitle;
123 	gchar *cUserImage[PLAYER_NB_STATUS];
124 	gboolean bStealTaskBarIcon;
125 
126 	gboolean bDownload;
127 	gint iTimeToWait;
128 	gchar *cThemePath;
129 	gboolean bOpenglThemes;
130 
131 	gboolean bPauseOnClick;
132 	gboolean bNextPrevOnScroll;
133 };
134 
135 typedef struct {
136 	gchar *cArtist;
137 	gchar *cAlbum;
138 	gchar *cPlayingUri;
139 	gchar *cLocalPath;
140 	gboolean bSuccess;
141 	} CDSharedMemory;
142 
143 struct _AppletData {
144 	// general
145 	GldiTask *pTask;
146 	GList *pHandlers;
147 	MusicPlayerHandler *pCurrentHandler;
148 	gchar *cMpris2Service;  // MPRIS2 service associated with the current handler.
149 
150 	//Informations essentielles
151 	DBusGProxy *dbus_proxy_player;
152 	DBusGProxy *dbus_proxy_shell;
153 	gchar *cRawTitle, *cPreviousRawTitle;
154 	gchar *cTitle;
155 	gchar *cArtist;
156 	gchar *cAlbum;
157 	gchar* cPlayingUri;
158 	gchar* cTrackID;
159 	MyPlayerStatus iPlayingStatus, pPreviousPlayingStatus;
160 	gint iTrackNumber, iPreviousTrackNumber;  // track number = position dans la play-list, et non pas numero de piste dans l'album (qui ne nous interesse pas).
161 	gint iCurrentTime, iPreviousCurrentTime, iGetTimeFailed;
162 	gint iSongLength;
163 	gint iRating;
164 	gint iTrackListLength;
165 	gint iTrackListIndex;
166 
167 	// Pour les lecteurs utilisant DBus
168 	gboolean bIsRunning;
169 	DBusGProxyCall *pDetectPlayerCall;
170 	DBusGProxyCall *pGetPropsCall;
171 
172 	//Donnees de dessin
173 	cairo_surface_t *pSurfaces[PLAYER_NB_STATUS];
174 	cairo_surface_t *pCover;
175 
176 	// Les pochettes
177 	gchar *cCoverPath, *cPreviousCoverPath;
178 	gboolean cover_exist;
179 	guint iSidCheckCover;
180 	gint iNbCheckCover;
181 	gint iCurrentFileSize;
182 	GldiTask *pCoverTask;  // async task to download the cover on the net.
183 
184 	// pochette 3D
185 	gint iCoverTransition;
186 	GLuint iPrevTextureCover;
187 	GLuint TextureFrame;
188 	GLuint TextureCover;
189 	GLuint TextureReflect;
190 
191 	gdouble itopleftX;
192 	gdouble itopleftY;
193 	gdouble ibottomleftX;
194 	gdouble ibottomleftY;
195 	gdouble ibottomrightX;
196 	gdouble ibottomrightY;
197 	gdouble itoprightX;
198 	gdouble itoprightY;
199 	GLuint draw_cover;  // calllist
200 
201 	gint numberButtons;
202 	gboolean osd;
203 	/// A passer en structure...
204 	gboolean mouseOnButton1;
205 	GLuint TextureButton1;
206 	gdouble button1coordX, button1coordY;
207 	gdouble button1sizeX, button1sizeY;
208 	gint iButton1Count;
209 	GLuint TextureOsdPlay;
210 	gdouble osdPlaycoordX, osdPlaycoordY;
211 	gdouble osdPlaysizeX, osdPlaysizeY;
212 	GLuint TextureOsdPause;
213 	gdouble osdPausecoordX, osdPausecoordY;
214 	gdouble osdPausesizeX, osdPausesizeY;
215 
216 	gboolean mouseOnButton2;
217 	GLuint TextureButton2;
218 	gdouble button2coordX, button2coordY;
219 	gdouble button2sizeX, button2sizeY;
220 	gint iButton2Count;
221 	GLuint TextureOsdPrev;
222 	gdouble osdPrevcoordX, osdPrevcoordY;
223 	gdouble osdPrevsizeX, osdPrevsizeY;
224 
225 	gboolean mouseOnButton3;
226 	GLuint TextureButton3;
227 	gdouble button3coordX, button3coordY;
228 	gdouble button3sizeX, button3sizeY;
229 	gint iButton3Count;
230 	GLuint TextureOsdNext;
231 	gdouble osdNextcoordX, osdNextcoordY;
232 	gdouble osdNextsizeX, osdNextsizeY;
233 
234 	gboolean mouseOnButton4;
235 	GLuint TextureButton4;
236 	gdouble button4coordX, button4coordY;
237 	gdouble button4sizeX, button4sizeY;
238 	gint iButton4Count;
239 	GLuint TextureOsdHome;
240 	gdouble osdHomecoordX, osdHomecoordY;
241 	gdouble osdHomesizeX, osdHomesizeY;
242 
243 	gint iMouseX;
244 	gint iMouseY;
245 	gint iButtonState;  // combinaison des etats des differents boutons.
246 };
247 
248 
249 #endif
250