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/>.
21
#include <glib/gi18n.h>
24
#include "rhythmbox-struct.h"
25
#include "3dcover-draw.h"
26
#include "rhythmbox-dbus.h"
27
#include "rhythmbox-draw.h"
29
static gchar *s_cDefaultIconName[PLAYER_NB_STATUS] = {"default.svg", "play.svg", "pause.svg", "stop.svg", "broken.svg"};
30
static gchar *s_cDefaultIconName3D[PLAYER_NB_STATUS] = {"default.jpg", "play.jpg", "pause.jpg", "stop.jpg", "broken.jpg"};
32
/*static GList * _list_icons (void)
34
GList *pIconList = NULL;
37
for (i = 0; i < 4; i ++)
39
pIcon = g_new0 (Icon, 1);
41
pIcon->acFileName = g_strdup_printf ("%s/%d.png", MY_APPLET_SHARE_DATA_DIR, i);
46
pIcon->fWidthFactor = 1.;
47
pIcon->fHeightFactor = 1.;
48
pIcon->acCommand = g_strdup ("none");
49
pIcon->cParentDockName = NULL;
50
pIconList = g_list_append (pIconList, pIcon);
54
void rhythmbox_add_buttons_to_desklet (void)
56
if (myDesklet && myConfig.extendedDesklet)
58
GList *pIconList = _list_icons ();
59
myDesklet->icons = pIconList;
63
void rhythmbox_iconWitness(int animationLength)
65
CD_APPLET_ANIMATE_MY_ICON (myConfig.changeAnimation, animationLength);
69
static gboolean _rhythmbox_check_cover_is_present (gpointer data)
71
gboolean bCheckSize = GPOINTER_TO_INT (data);
72
g_print ("%s (%s)\n", __func__, myData.playing_cover);
73
if (g_file_test (myData.playing_cover, G_FILE_TEST_EXISTS))
75
cd_message ("RB-YDU : la couverture '%s' est presente sur le disque", myData.playing_cover);
77
if (!bCheckSize || cd_check_if_size_is_constant (myData.playing_cover))
79
cd_message ("RB-YDU : la couverture '%s' est desormais disponible et la taille est constante", myData.playing_cover);
80
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes)
82
if (myData.iPrevTextureCover != 0)
83
_cairo_dock_delete_texture (myData.iPrevTextureCover);
84
myData.iPrevTextureCover = myData.TextureCover;
85
myData.TextureCover = cairo_dock_create_texture_from_image (myData.playing_cover);
86
if (myData.iPrevTextureCover != 0)
88
myData.iCoverTransition = NB_TRANSITION_STEP;
89
cairo_dock_launch_animation (myContainer);
93
cd_opengl_render_to_texture (myApplet);
94
CD_APPLET_REDRAW_MY_ICON;
99
CD_APPLET_SET_IMAGE_ON_MY_ICON (myData.playing_cover);
100
CD_APPLET_REDRAW_MY_ICON;
102
myData.cover_exist = TRUE;
103
myData.iSidCheckCover = 0;
106
/*if (myData.CoverWasDistant)
108
cd_check_if_size_is_constant (myData.playing_cover);
109
if (myData.bSizeIsConstant)
111
cd_message ("RB-YDU : la couverture '%s' est desormais disponible et la taille est constante", myData.playing_cover);
112
myData.CoverWasDistant = FALSE ;
113
myData.cover_exist = FALSE;
118
cd_message ("RB-YDU : la couverture '%s' n'est pas encore complete", myData.playing_cover);
119
// On laisse myData.CoverWasDistant Ć TRUE pour rentrer Ć nouveau dans la boucle au prochain tour ;-)
124
cd_debug ("RB-YDU : BOUCLE 2 : La pochette est locale -> On affiche");
125
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes)
127
if (myData.iPrevTextureCover != 0)
128
_cairo_dock_delete_texture (myData.iPrevTextureCover);
129
myData.iPrevTextureCover = myData.TextureCover;
130
myData.TextureCover = cairo_dock_create_texture_from_image (myData.playing_cover);
131
if (myData.iPrevTextureCover != 0)
133
myData.iCoverTransition = NB_TRANSITION_STEP;
134
cairo_dock_launch_animation (myContainer);
138
cd_opengl_render_to_texture (myApplet);
139
CD_APPLET_REDRAW_MY_ICON;
144
CD_APPLET_SET_IMAGE_ON_MY_ICON (myData.playing_cover);
145
CD_APPLET_REDRAW_MY_ICON;
147
myData.cover_exist = TRUE;
148
myData.iSidCheckCover = 0;
155
static gboolean _rhythmbox_check_distant_song_info_twice (gpointer data)
157
getSongInfos (FALSE); // FALSE <=> on ne recupere que la couverture.
159
myData.iSidGetDistantCover = 0;
163
void update_icon (gboolean bFirstTime)
165
cd_message ("Update icon");
166
if(myData.playing_uri != NULL)
168
//Affichage de la chanson courante.
169
gchar *songName = g_strdup_printf("%s - %s", myData.playing_artist, myData.playing_title);
170
cd_message (" songName : %s", songName);
171
CD_APPLET_SET_NAME_FOR_MY_ICON (songName);
174
//Affichage de l'info-rapide.
175
if(myConfig.quickInfoType == MY_APPLET_TRACK && myData.playing_track > 0)
177
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%s%d", (myDesklet && myDesklet->iWidth >= 64 ? D_("Track") : ""), myData.playing_track); // inutile de redessiner notre icone, ce sera fait plus loin.
180
//Affichage de la couverture de l'album.
181
if (myData.iSidCheckCover != 0) // on stoppe la precedente boucle.
183
g_source_remove (myData.iSidCheckCover);
184
myData.iSidCheckCover = 0;
186
if (myData.iSidGetDistantCover != 0) // on stoppe la precedente boucle.
188
g_source_remove (myData.iSidGetDistantCover);
189
myData.iSidGetDistantCover = 0;
191
if (myData.playing_cover == NULL && bFirstTime) // info manquante, cela arrive avec les chansons distantes (bug de RB ?) on teste 2 fois de suite a 2 secondes d'intervalle.
193
myData.iSidGetDistantCover = g_timeout_add_seconds (2, (GSourceFunc) _rhythmbox_check_distant_song_info_twice, GINT_TO_POINTER (TRUE));
195
else if (!myData.cover_exist && myConfig.enableCover && myData.playing_cover != NULL) // couverture connue mais pas encore chargee.
197
if (myData.bCoverNeedsTest) // il faut lancer le test en boucle.
199
myData.iCurrentFileSize = 0;
200
myData.iSidCheckCover = g_timeout_add_seconds (1, (GSourceFunc) _rhythmbox_check_cover_is_present, GINT_TO_POINTER (TRUE)); // TRUE <=> tester la taille contante.
202
else // la couverture est deja disponible, on peut tester tout de suite.
204
_rhythmbox_check_cover_is_present (GINT_TO_POINTER (FALSE)); // FALSE <=> tester seulement l'existence du fichier.
208
if (! myData.cover_exist && bFirstTime) // en attendant d'avoir une couverture, ou s'il n'y en a tout simplement pas, on met les images par defaut. La 2eme fois ce n'est pas la peine de le refaire, puisque si on passe une 2eme fois dans cette fonction, c'est bien parce que la couverture n'existait pas la 1ere fois.
212
rhythmbox_set_surface (PLAYER_PLAYING);
216
rhythmbox_set_surface (PLAYER_PAUSED);
220
//Animation de l'icone et dialogue.
223
rhythmbox_iconWitness(1);
224
if(myConfig.enableDialogs)
232
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
233
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
234
if (myData.bIsRunning)
235
rhythmbox_set_surface (PLAYER_STOPPED); // je ne sais pas si en mode Stopped la chanson est NULL ou pas...
237
rhythmbox_set_surface (PLAYER_NONE);
241
void music_dialog(void)
243
cairo_dock_remove_dialog_if_any (myIcon);
244
cairo_dock_show_temporary_dialog ("%s : %s\n%s : %s\n%s : %s",
247
myConfig.timeDialogs,
249
myData.playing_artist != NULL ? myData.playing_artist : D_("Unknown"),
251
myData.playing_album != NULL ? myData.playing_album : D_("Unknown"),
253
myData.playing_title != NULL ? myData.playing_title : D_("Unknown"));
257
void rhythmbox_set_surface (MyAppletPlayerStatus iStatus)
259
g_return_if_fail (iStatus < PLAYER_NB_STATUS);
260
gboolean bUse3DTheme = (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes);
261
gchar **cIconName = (bUse3DTheme ? s_cDefaultIconName3D : s_cDefaultIconName);
262
cairo_surface_t *pSurface = myData.pSurfaces[iStatus];
264
if (pSurface == NULL) // surface pas encore chargee.
266
if (myConfig.cUserImage[iStatus] != NULL) {
267
gchar *cUserImagePath = cairo_dock_generate_file_path (myConfig.cUserImage[iStatus]);
268
myData.pSurfaces[iStatus] = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cUserImagePath);
269
g_free (cUserImagePath);
272
gchar *cImagePath = g_strdup_printf ("%s/%s", MY_APPLET_SHARE_DATA_DIR, cIconName[iStatus]);
273
myData.pSurfaces[iStatus] = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cImagePath);
278
if (myData.iPrevTextureCover != 0)
279
_cairo_dock_delete_texture (myData.iPrevTextureCover);
280
myData.iPrevTextureCover = myData.TextureCover;
281
myData.TextureCover = cairo_dock_create_texture_from_surface (myData.pSurfaces[iStatus]);
282
if (myData.iPrevTextureCover != 0)
284
myData.iCoverTransition = NB_TRANSITION_STEP;
285
cairo_dock_launch_animation (myContainer);
289
cd_opengl_render_to_texture (myApplet);
290
CD_APPLET_REDRAW_MY_ICON;
295
CD_APPLET_SET_SURFACE_ON_MY_ICON(myData.pSurfaces[iStatus]);
298
else // surface en memoire.
302
if (myData.iPrevTextureCover != 0)
303
_cairo_dock_delete_texture (myData.iPrevTextureCover);
304
myData.iPrevTextureCover = myData.TextureCover;
305
myData.TextureCover = cairo_dock_create_texture_from_surface (pSurface);
306
if (myData.iPrevTextureCover != 0)
308
myData.iCoverTransition = NB_TRANSITION_STEP;
309
cairo_dock_launch_animation (myContainer);
313
cd_opengl_render_to_texture (myApplet);
314
CD_APPLET_REDRAW_MY_ICON;
319
CD_APPLET_SET_SURFACE_ON_MY_ICON (pSurface);
324
gboolean cd_check_if_size_is_constant (gchar *cFilePath)
326
int iSize = cairo_dock_get_file_size (cFilePath);
327
gboolean bConstantSize = (iSize != 0 && iSize == myData.iCurrentFileSize);
328
myData.iCurrentFileSize = iSize;
329
return bConstantSize;
330
/*static struct stat buf;
331
g_return_val_if_fail (cFilePath != NULL, TRUE);
332
if (stat (cFileName, &buf) != -1)
334
g_print ("RB : taille de la pochette : %d -> %d\n", myData.iCurrentFileSize, buf.st_size);
335
gboolean bConstantSize = (buf.st_size != 0 && buf.st_size == myData.iCurrentFileSize);
336
myData.iCurrentFileSize = buf.st_size;
337
return bConstantSize;