~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to xmms/src/applet-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
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Rémy Robertson (for any bug report, please mail me to changfu@cairo-dock.org)
 
26
Fabrice Rey (fabounet@users.berlios.de)
 
27
 
 
28
******************************************************************************/
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
 
 
32
#include "applet-struct.h"
 
33
#include "applet-draw.h"
 
34
 
 
35
 
 
36
static gchar *s_cIconName[PLAYER_NB_STATUS] = {"xmms.svg", "play.svg", "pause.svg", "stop.svg", "broken.svg"};
 
37
 
 
38
static GList * _list_icons (void) {
 
39
        GList *pIconList = NULL;
 
40
        
 
41
        Icon *pIcon;
 
42
        int i;
 
43
        for (i = 0; i < 4; i ++) {
 
44
                pIcon = g_new0 (Icon, 1);
 
45
                pIcon->acName = NULL;
 
46
                pIcon->acFileName = g_strdup_printf ("%s/%d.svg", MY_APPLET_SHARE_DATA_DIR, i);
 
47
                pIcon->fOrder = i;
 
48
                pIcon->iType = i;
 
49
                pIcon->fScale = 1.;
 
50
                pIcon->fAlpha = 1.;
 
51
                pIcon->fWidthFactor = 1.;
 
52
                pIcon->fHeightFactor = 1.;
 
53
                pIcon->acCommand = g_strdup ("none");
 
54
                pIcon->cParentDockName = NULL;
 
55
                pIconList = g_list_append (pIconList, pIcon);
 
56
        }
 
57
        
 
58
        return pIconList;
 
59
}
 
60
void cd_xmms_add_buttons_to_desklet(CairoDockModuleInstance *myApplet) {
 
61
        if (myDesklet && myConfig.extendedDesklet){
 
62
                GList *pIconList = _list_icons ();
 
63
                myDesklet->icons = pIconList;
 
64
        }
 
65
}
 
66
 
 
67
gboolean cd_xmms_draw_icon (CairoDockModuleInstance *myApplet) {
 
68
        gboolean bNeedRedraw = FALSE;
 
69
        if (myData.playingStatus == PLAYER_NONE) {
 
70
                myData.cQuickInfo = NULL;
 
71
                if (myData.cQuickInfo != myData.cPreviousQuickInfo) {
 
72
                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
 
73
                        myData.cPreviousQuickInfo = myData.cQuickInfo;
 
74
                }
 
75
        }
 
76
        else {
 
77
                switch (myConfig.quickInfoType) {
 
78
                        case MY_APPLET_NOTHING :
 
79
                                myData.cQuickInfo = NULL;
 
80
                                if (myData.cQuickInfo != myData.cPreviousQuickInfo) {
 
81
                                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
 
82
                                        myData.cPreviousQuickInfo = myData.cQuickInfo;
 
83
                                }
 
84
                        break ;
 
85
                        
 
86
                        case MY_APPLET_TIME_ELAPSED :
 
87
                                myData.cQuickInfo = "elapsed";
 
88
                                myData.cPreviousQuickInfo = myData.cQuickInfo;
 
89
                                if (myData.iCurrentTime != myData.iPreviousCurrentTime) {
 
90
                                        myData.iPreviousCurrentTime = myData.iCurrentTime;
 
91
                                        CD_APPLET_SET_MINUTES_SECONDES_AS_QUICK_INFO (myData.iCurrentTime);
 
92
                                        bNeedRedraw = TRUE;
 
93
                                }
 
94
                        break ;
 
95
                        
 
96
                        case MY_APPLET_TIME_LEFT :
 
97
                                myData.cQuickInfo = "left";
 
98
                                myData.cPreviousQuickInfo = myData.cQuickInfo;
 
99
                                if (myData.iCurrentTime != myData.iPreviousCurrentTime) {
 
100
                                        myData.iPreviousCurrentTime = myData.iCurrentTime;
 
101
                                        CD_APPLET_SET_MINUTES_SECONDES_AS_QUICK_INFO (myData.iCurrentTime - myData.iSongLength);
 
102
                                        bNeedRedraw = TRUE;
 
103
                                }
 
104
                        break ;
 
105
                        
 
106
                        case MY_APPLET_TRACK :
 
107
                                myData.cQuickInfo = "track";
 
108
                                myData.cPreviousQuickInfo = myData.cQuickInfo;
 
109
                                if (myData.iTrackNumber != myData.iPreviousTrackNumber) {
 
110
                                        myData.iPreviousTrackNumber = myData.iTrackNumber;
 
111
                                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF("%d", myData.iTrackNumber);
 
112
                                        bNeedRedraw = TRUE;
 
113
                                }
 
114
                        break ;
 
115
                        
 
116
                        default :
 
117
                        break;
 
118
                }
 
119
        }
 
120
        
 
121
        //cd_message("Previous: %s\nNow: %s", myData.previousPlayingTitle, myData.playingTitle);
 
122
        if (myData.previousPlayingTitle != myData.playingTitle) {
 
123
          myData.previousPlayingTitle = myData.playingTitle;
 
124
                if (myData.playingTitle == NULL || strcmp (myData.playingTitle, "(null)") == 0) {
 
125
                        CD_APPLET_SET_NAME_FOR_MY_ICON(myConfig.defaultTitle);
 
126
                }
 
127
                else {
 
128
                  cd_message("Changing title to: %s", myData.playingTitle);
 
129
                        CD_APPLET_SET_NAME_FOR_MY_ICON (myData.playingTitle);
 
130
                        if (myConfig.enableAnim) {
 
131
                    cd_message("Animating for: %s", myData.playingTitle);
 
132
                          cd_xmms_animate_icon(myApplet, 1);
 
133
                  }
 
134
                  if (myConfig.enableDialogs) {
 
135
                          cd_xmms_new_song_playing(myApplet);
 
136
                  }
 
137
                }
 
138
        }
 
139
        
 
140
        if (myData.playingStatus != myData.previousPlayingStatus) {  // changement de statut.
 
141
                cd_message ("PlayingStatus : %d -> %d\n", myData.previousPlayingStatus, myData.playingStatus);
 
142
                myData.previousPlayingStatus = myData.playingStatus;
 
143
                cd_xmms_set_surface (myApplet, myData.playingStatus);
 
144
                if (myData.playingStatus == 0) {
 
145
                  myData.playingTitle = NULL; //Rien ne joue
 
146
                  CD_APPLET_SET_NAME_FOR_MY_ICON(myConfig.defaultTitle);
 
147
                }
 
148
        }
 
149
        else if (bNeedRedraw) {
 
150
                CD_APPLET_REDRAW_MY_ICON;
 
151
        }
 
152
        
 
153
        return TRUE;
 
154
}
 
155
 
 
156
//Fonction qui affiche la bulle au changement de musique
 
157
//Old function without icon
 
158
static void cd_xmms_new_song_playing_old(CairoDockModuleInstance *myApplet) {
 
159
        cairo_dock_show_temporary_dialog(myData.playingTitle, myIcon, myContainer, myConfig.timeDialogs);
 
160
}
 
161
 
 
162
//With Icon.
 
163
void cd_xmms_new_song_playing(CairoDockModuleInstance *myApplet) {
 
164
        cairo_dock_remove_dialog_if_any (myIcon); //On evite la superposition ?
 
165
        if (!myConfig.bIconBubble) {
 
166
                cd_xmms_new_song_playing_old(myApplet);
 
167
                return;
 
168
        }
 
169
        
 
170
        gchar *cImagePath = NULL;
 
171
        if (myConfig.cUserImage[PLAYER_NONE] != NULL)
 
172
                cImagePath = cairo_dock_generate_file_path (myConfig.cUserImage[PLAYER_NONE]);
 
173
        else
 
174
                cImagePath = g_strdup_printf ("%s/%s", MY_APPLET_SHARE_DATA_DIR, s_cIconName[PLAYER_NONE]);
 
175
        
 
176
        cairo_dock_show_temporary_dialog_with_icon (myData.playingTitle, myIcon, myContainer, myConfig.timeDialogs, cImagePath);
 
177
        g_free(cImagePath);
 
178
}
 
179
 
 
180
//Fonction qui anime l'icone au changement de musique
 
181
void cd_xmms_animate_icon(CairoDockModuleInstance *myApplet, int animationLength) {
 
182
        if (myDock) {
 
183
                CD_APPLET_ANIMATE_MY_ICON (myConfig.changeAnimation, animationLength);
 
184
        }
 
185
}
 
186
 
 
187
void cd_xmms_set_surface (CairoDockModuleInstance *myApplet, MyPlayerStatus iStatus) {
 
188
        g_return_if_fail (iStatus < PLAYER_NB_STATUS);
 
189
        //g_print ("%s (%d)\n", __func__, iStatus);
 
190
        cairo_surface_t *pSurface = myData.pSurfaces[iStatus];
 
191
        if (pSurface == NULL) {
 
192
                if (myConfig.cUserImage[iStatus] != NULL) {
 
193
                        gchar *cUserImagePath = cairo_dock_generate_file_path (myConfig.cUserImage[iStatus]);
 
194
                        myData.pSurfaces[iStatus] = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cUserImagePath);
 
195
                        g_free (cUserImagePath);
 
196
                }
 
197
                else {
 
198
                        gchar *cImagePath = g_strdup_printf ("%s/%s", MY_APPLET_SHARE_DATA_DIR, s_cIconName[iStatus]);
 
199
                        myData.pSurfaces[iStatus] = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cImagePath);
 
200
                        g_free (cImagePath);
 
201
                }
 
202
                CD_APPLET_SET_SURFACE_ON_MY_ICON(myData.pSurfaces[iStatus]);
 
203
        }
 
204
        else {
 
205
                CD_APPLET_SET_SURFACE_ON_MY_ICON (pSurface);
 
206
        }
 
207
}
 
208
 
 
209
void cd_xmms_change_desklet_data (CairoDockModuleInstance *myApplet) {
 
210
        cd_debug ("");
 
211
        
 
212
        if (myData.playingTitle == NULL)
 
213
                return;
 
214
        if (myDesklet == NULL || !myConfig.extendedDesklet || (myConfig.iExtendedMode != MY_DESKLET_INFO && myConfig.iExtendedMode != MY_DESKLET_INFO_AND_CONTROLER))
 
215
                return;
 
216
        
 
217
        //On détermine l'artist (par default le 1er avant le tiret)
 
218
        gchar **rawTitle=NULL, *artist=NULL, *title=NULL;
 
219
        rawTitle = g_strsplit (myData.playingTitle, "-", -1);
 
220
        if (rawTitle[0] != NULL)
 
221
                artist = rawTitle[0];
 
222
        if (rawTitle[1] != NULL) {
 
223
                title = strchr (myData.playingTitle, '-');
 
224
                title ++;
 
225
                while (*title == ' ')
 
226
                        title ++;
 
227
        }
 
228
        
 
229
        gpointer data[2] = {artist, title};
 
230
        cairo_dock_render_desklet_with_new_data (myDesklet, (CairoDeskletRendererDataPtr) data);
 
231
        
 
232
        /*gpointer data[3] = {artist, title, (myConfig.iExtendedMode == MY_DESKLET_INFO ? FALSE : TRUE)};
 
233
        CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Mediaplayer", data);
 
234
        cd_xmms_set_surface (myData.playingStatus);
 
235
        gtk_widget_queue_draw (myDesklet->pWidget);*/
 
236
        
 
237
        g_strfreev (rawTitle);
 
238
}
 
239
 
 
240
void cd_xmms_player_none (CairoDockModuleInstance *myApplet) {
 
241
        cd_debug ("");
 
242
        if (myDesklet && myConfig.extendedDesklet && (myConfig.iExtendedMode == MY_DESKLET_INFO || myConfig.iExtendedMode == MY_DESKLET_INFO_AND_CONTROLER)) {
 
243
                gpointer data[2] = {NULL, NULL};
 
244
                cairo_dock_render_desklet_with_new_data (myDesklet, (CairoDeskletRendererDataPtr) data);
 
245
                
 
246
                /*gpointer data[3] = {NULL, NULL, (myConfig.iExtendedMode == MY_DESKLET_INFO ? FALSE : TRUE)};
 
247
                CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Mediaplayer", data);
 
248
                cd_xmms_set_surface (myData.playingStatus);
 
249
                gtk_widget_queue_draw (myDesklet->pWidget);*/
 
250
                }
 
251
}