~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to rhythmbox/src/rhythmbox-draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

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 <string.h>
 
21
#include <glib/gi18n.h>
 
22
#include <sys/stat.h>
 
23
 
 
24
#include "rhythmbox-struct.h"
 
25
#include "3dcover-draw.h"
 
26
#include "rhythmbox-dbus.h"
 
27
#include "rhythmbox-draw.h"
 
28
 
 
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"};
 
31
 
 
32
/*static GList * _list_icons (void)
 
33
{
 
34
        GList *pIconList = NULL;
 
35
        Icon *pIcon;
 
36
        int i;
 
37
        for (i = 0; i < 4; i ++)
 
38
        {
 
39
                pIcon = g_new0 (Icon, 1);
 
40
                pIcon->acName = NULL;
 
41
                pIcon->acFileName = g_strdup_printf ("%s/%d.png", MY_APPLET_SHARE_DATA_DIR, i);
 
42
                pIcon->fOrder = i;
 
43
                pIcon->iType = i;
 
44
                pIcon->fScale = 1.;
 
45
                pIcon->fAlpha = 1.;
 
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);
 
51
        }
 
52
        return pIconList;
 
53
}
 
54
void rhythmbox_add_buttons_to_desklet (void)
 
55
{
 
56
        if (myDesklet && myConfig.extendedDesklet)
 
57
        {
 
58
                GList *pIconList = _list_icons ();
 
59
                myDesklet->icons = pIconList;
 
60
        }
 
61
}*/
 
62
 
 
63
void rhythmbox_iconWitness(int animationLength)
 
64
{
 
65
        CD_APPLET_ANIMATE_MY_ICON (myConfig.changeAnimation, animationLength);
 
66
}
 
67
 
 
68
 
 
69
static gboolean _rhythmbox_check_cover_is_present (gpointer data)
 
70
{
 
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))
 
74
        {
 
75
                cd_message ("RB-YDU : la couverture '%s' est presente sur le disque", myData.playing_cover);
 
76
                
 
77
                if (!bCheckSize || cd_check_if_size_is_constant (myData.playing_cover))
 
78
                {
 
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)
 
81
                        {       
 
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)
 
87
                                {
 
88
                                        myData.iCoverTransition = NB_TRANSITION_STEP;
 
89
                                        cairo_dock_launch_animation (myContainer);
 
90
                                }
 
91
                                else
 
92
                                {
 
93
                                        cd_opengl_render_to_texture (myApplet);
 
94
                                        CD_APPLET_REDRAW_MY_ICON;
 
95
                                }
 
96
                        }
 
97
                        else
 
98
                        {
 
99
                                CD_APPLET_SET_IMAGE_ON_MY_ICON (myData.playing_cover);
 
100
                                CD_APPLET_REDRAW_MY_ICON;
 
101
                        }
 
102
                        myData.cover_exist = TRUE;
 
103
                        myData.iSidCheckCover = 0;
 
104
                        return FALSE;
 
105
                }
 
106
                /*if (myData.CoverWasDistant)
 
107
                {
 
108
                        cd_check_if_size_is_constant (myData.playing_cover);
 
109
                        if (myData.bSizeIsConstant)
 
110
                        { 
 
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;
 
114
                                return TRUE;
 
115
                        }
 
116
                        else 
 
117
                        {
 
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 ;-)
 
120
                        }                       
 
121
                }
 
122
                else
 
123
                {
 
124
                        cd_debug ("RB-YDU : BOUCLE 2 : La pochette est locale -> On affiche");
 
125
                        if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes)
 
126
                        {       
 
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)
 
132
                                {
 
133
                                        myData.iCoverTransition = NB_TRANSITION_STEP;
 
134
                                        cairo_dock_launch_animation (myContainer);
 
135
                                }
 
136
                                else
 
137
                                {
 
138
                                        cd_opengl_render_to_texture (myApplet);
 
139
                                        CD_APPLET_REDRAW_MY_ICON;
 
140
                                }
 
141
                        }
 
142
                        else
 
143
                        {
 
144
                                CD_APPLET_SET_IMAGE_ON_MY_ICON (myData.playing_cover);
 
145
                                CD_APPLET_REDRAW_MY_ICON;
 
146
                        }
 
147
                        myData.cover_exist = TRUE;
 
148
                        myData.iSidCheckCover = 0;
 
149
                        return FALSE;
 
150
                }*/
 
151
        }
 
152
        return TRUE;
 
153
}
 
154
 
 
155
static gboolean _rhythmbox_check_distant_song_info_twice (gpointer data)
 
156
{
 
157
        getSongInfos (FALSE);  // FALSE <=> on ne recupere que la couverture.
 
158
        update_icon (FALSE);
 
159
        myData.iSidGetDistantCover = 0;
 
160
        return FALSE;
 
161
}
 
162
 
 
163
void update_icon (gboolean bFirstTime)
 
164
{
 
165
        cd_message ("Update icon");
 
166
        if(myData.playing_uri != NULL)
 
167
        {
 
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);
 
172
                g_free (songName);
 
173
                
 
174
                //Affichage de l'info-rapide.
 
175
                if(myConfig.quickInfoType == MY_APPLET_TRACK && myData.playing_track > 0)
 
176
                {
 
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.
 
178
                }
 
179
                
 
180
                //Affichage de la couverture de l'album.
 
181
                if (myData.iSidCheckCover != 0)  // on stoppe la precedente boucle.
 
182
                {
 
183
                        g_source_remove (myData.iSidCheckCover);
 
184
                        myData.iSidCheckCover = 0;
 
185
                }
 
186
                if (myData.iSidGetDistantCover != 0)  // on stoppe la precedente boucle.
 
187
                {
 
188
                        g_source_remove (myData.iSidGetDistantCover);
 
189
                        myData.iSidGetDistantCover = 0;
 
190
                }
 
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.
 
192
                {
 
193
                        myData.iSidGetDistantCover = g_timeout_add_seconds (2, (GSourceFunc) _rhythmbox_check_distant_song_info_twice, GINT_TO_POINTER (TRUE));
 
194
                }
 
195
                else if (!myData.cover_exist && myConfig.enableCover && myData.playing_cover != NULL)  // couverture connue mais pas encore chargee.
 
196
                {
 
197
                        if (myData.bCoverNeedsTest)  // il faut lancer le test en boucle.
 
198
                        {
 
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.
 
201
                        }
 
202
                        else  // la couverture est deja disponible, on peut tester tout de suite.
 
203
                        {
 
204
                                _rhythmbox_check_cover_is_present (GINT_TO_POINTER (FALSE));  // FALSE <=> tester seulement l'existence du fichier.
 
205
                        }
 
206
                }
 
207
                
 
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.
 
209
                {
 
210
                        if(myData.playing)
 
211
                        {
 
212
                                rhythmbox_set_surface (PLAYER_PLAYING);
 
213
                        }
 
214
                        else
 
215
                        {
 
216
                                rhythmbox_set_surface (PLAYER_PAUSED);
 
217
                        }
 
218
                }
 
219
                
 
220
                //Animation de l'icone et dialogue.
 
221
                if(bFirstTime)
 
222
                {
 
223
                        rhythmbox_iconWitness(1);
 
224
                        if(myConfig.enableDialogs)
 
225
                        {
 
226
                                music_dialog();
 
227
                        }
 
228
                }
 
229
        }
 
230
        else
 
231
        {
 
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...
 
236
                else
 
237
                        rhythmbox_set_surface (PLAYER_NONE);
 
238
        }
 
239
}
 
240
 
 
241
void music_dialog(void)
 
242
{
 
243
        cairo_dock_remove_dialog_if_any (myIcon);
 
244
        cairo_dock_show_temporary_dialog ("%s : %s\n%s : %s\n%s : %s",
 
245
                myIcon,
 
246
                myContainer,
 
247
                myConfig.timeDialogs,
 
248
                D_("Artist"),
 
249
                myData.playing_artist != NULL ? myData.playing_artist : D_("Unknown"),
 
250
                D_("Album"),
 
251
                myData.playing_album != NULL ? myData.playing_album : D_("Unknown"),
 
252
                D_("Title"),
 
253
                myData.playing_title != NULL ? myData.playing_title : D_("Unknown"));
 
254
}
 
255
 
 
256
 
 
257
void rhythmbox_set_surface (MyAppletPlayerStatus iStatus)
 
258
{
 
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];
 
263
        
 
264
        if (pSurface == NULL)  // surface pas encore chargee.
 
265
        {
 
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);
 
270
                }
 
271
                else {
 
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);
 
274
                        g_free (cImagePath);
 
275
                }
 
276
                if (bUse3DTheme)
 
277
                {
 
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)
 
283
                        {
 
284
                                myData.iCoverTransition = NB_TRANSITION_STEP;
 
285
                                cairo_dock_launch_animation (myContainer);
 
286
                        }
 
287
                        else
 
288
                        {
 
289
                                cd_opengl_render_to_texture (myApplet);
 
290
                                CD_APPLET_REDRAW_MY_ICON;
 
291
                        }
 
292
                }
 
293
                else
 
294
                {
 
295
                        CD_APPLET_SET_SURFACE_ON_MY_ICON(myData.pSurfaces[iStatus]);
 
296
                }
 
297
        }
 
298
        else  // surface en memoire.
 
299
        {
 
300
                if (bUse3DTheme)
 
301
                {
 
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)
 
307
                        {
 
308
                                myData.iCoverTransition = NB_TRANSITION_STEP;
 
309
                                cairo_dock_launch_animation (myContainer);
 
310
                        }
 
311
                        else
 
312
                        {
 
313
                                cd_opengl_render_to_texture (myApplet);
 
314
                                CD_APPLET_REDRAW_MY_ICON;
 
315
                        }
 
316
                }
 
317
                else
 
318
                {
 
319
                        CD_APPLET_SET_SURFACE_ON_MY_ICON (pSurface);
 
320
                }
 
321
        }
 
322
}
 
323
 
 
324
gboolean cd_check_if_size_is_constant (gchar *cFilePath)
 
325
{
 
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)
 
333
        {
 
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;
 
338
        }
 
339
        else
 
340
                return TRUE;*/
 
341
}