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

« back to all changes in this revision

Viewing changes to musicPlayer/src/applet-notifications.c

Tags: upstream-2.0.9
ImportĀ upstreamĀ versionĀ 2.0.9

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 <stdlib.h>
 
21
#include <string.h>
 
22
 
 
23
#include "applet-struct.h"
 
24
#include "applet-musicplayer.h"
 
25
#include "applet-draw.h"
 
26
#include "applet-dbus.h"
 
27
#include "3dcover-draw.h"
 
28
#include "applet-cover.h"
 
29
#include "applet-notifications.h"
 
30
 
 
31
 
 
32
static void _cd_musicplayer_prev (GtkMenuItem *menu_item, gpointer *data) {
 
33
        myData.pCurrentHandeler->control (PLAYER_PREVIOUS, NULL);
 
34
}
 
35
static void _cd_musicplayer_pp (GtkMenuItem *menu_item, gpointer *data) {
 
36
        myData.pCurrentHandeler->control (PLAYER_PLAY_PAUSE, NULL);
 
37
}
 
38
static void _cd_musicplayer_stop (GtkMenuItem *menu_item, gpointer *data) {
 
39
        myData.pCurrentHandeler->control (PLAYER_STOP, NULL);
 
40
}
 
41
static void _cd_musicplayer_next (GtkMenuItem *menu_item, gpointer *data) {
 
42
        myData.pCurrentHandeler->control (PLAYER_NEXT, NULL);
 
43
}
 
44
static void _cd_musicplayer_jumpbox (GtkMenuItem *menu_item, gpointer *data) {
 
45
        myData.pCurrentHandeler->control (PLAYER_JUMPBOX, NULL);
 
46
}
 
47
static void _cd_musicplayer_shuffle (GtkMenuItem *menu_item, gpointer *data) {
 
48
        myData.pCurrentHandeler->control (PLAYER_SHUFFLE, NULL);
 
49
}
 
50
static void _cd_musicplayer_repeat (GtkMenuItem *menu_item, gpointer *data) {
 
51
        myData.pCurrentHandeler->control (PLAYER_REPEAT, NULL);
 
52
}
 
53
static void _cd_musicplayer_rate (GtkMenuItem *menu_item, gpointer *data) {
 
54
        /// trouver un moyen esthetique.
 
55
}
 
56
static void _cd_musicplayer_info (GtkMenuItem *menu_item, gpointer *data)
 
57
{
 
58
        cd_musicplayer_popup_info ();
 
59
}
 
60
 
 
61
static void _cd_musicplayer_find_player (GtkMenuItem *menu_item, gpointer *data)
 
62
{
 
63
        MusicPlayerHandeler *pHandler = cd_musicplayer_dbus_find_opened_player ();
 
64
        if (pHandler == NULL)
 
65
        {
 
66
                cairo_dock_show_temporary_dialog_with_icon (D_("Sorry, I couldn't detect any player.\nIf it is running, it is maybe because its version is too old and does not offer such service."),
 
67
                        myIcon,
 
68
                        myContainer,
 
69
                        7000,
 
70
                        MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
 
71
        }
 
72
        else if (pHandler != myData.pCurrentHandeler)
 
73
        {
 
74
                if (myData.pCurrentHandeler)
 
75
                {
 
76
                        cd_musicplayer_stop_handler ();  // libĆØre tout ce qu'occupe notre ancien handler.
 
77
                        CD_APPLET_MANAGE_APPLICATION (myData.pCurrentHandeler->appclass, FALSE);
 
78
                }
 
79
                myData.pCurrentHandeler = pHandler;
 
80
                cd_musicplayer_launch_handler ();
 
81
                CD_APPLET_MANAGE_APPLICATION (myData.pCurrentHandeler->appclass, myConfig.bStealTaskBarIcon);
 
82
        }
 
83
}
 
84
 
 
85
//\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons.
 
86
CD_APPLET_ON_CLICK_BEGIN
 
87
        if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myData.numberButtons != 0  && myConfig.bOpenglThemes && myDesklet)
 
88
        {
 
89
                // Actions au clic sur un bouton :
 
90
                if (myData.mouseOnButton1)
 
91
                {
 
92
                        if(myData.bIsRunning)
 
93
                        {
 
94
                                _cd_musicplayer_pp (NULL, NULL);
 
95
                        }
 
96
                        else if (myData.pCurrentHandeler->launch != NULL)
 
97
                        {
 
98
                                cairo_dock_launch_command (myData.pCurrentHandeler->launch);
 
99
                        }
 
100
                }
 
101
                else if (myData.mouseOnButton2)
 
102
                        _cd_musicplayer_prev (NULL, NULL);
 
103
                else if (myData.mouseOnButton3)
 
104
                        _cd_musicplayer_next (NULL, NULL);
 
105
                else if (myData.mouseOnButton4)
 
106
                {
 
107
                        if(myData.bIsRunning)
 
108
                        {
 
109
                                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_JUMPBOX)
 
110
                                        _cd_musicplayer_jumpbox (NULL, NULL);
 
111
                                else if (myIcon->Xid != 0)
 
112
                                        cairo_dock_show_xwindow (myIcon->Xid);
 
113
                        }
 
114
                        else if (myData.pCurrentHandeler->launch != NULL)
 
115
                                cairo_dock_launch_command (myData.pCurrentHandeler->launch);
 
116
                }
 
117
                else
 
118
                {
 
119
                        if(myData.bIsRunning)
 
120
                                cd_musicplayer_popup_info ();
 
121
                        else if (myData.pCurrentHandeler->launch != NULL)
 
122
                                cairo_dock_launch_command (myData.pCurrentHandeler->launch);
 
123
                }
 
124
        }
 
125
        else
 
126
        {
 
127
                if(myData.bIsRunning)
 
128
                {
 
129
                        if (myConfig.bPauseOnClick)
 
130
                        {
 
131
                                _cd_musicplayer_pp (NULL, NULL);
 
132
                        }
 
133
                        else
 
134
                        {
 
135
                                if (myIcon->Xid == cairo_dock_get_current_active_window ())  // la fenetre du lecteur a le focus. en mode desklet ca ne marche pas car il aura pris le focus au moment du clic.
 
136
                                        cairo_dock_minimize_xwindow (myIcon->Xid);
 
137
                                else
 
138
                                        cairo_dock_show_xwindow (myIcon->Xid);
 
139
                        }
 
140
                }
 
141
                else if (myData.pCurrentHandeler->launch != NULL)
 
142
                        cairo_dock_launch_command (myData.pCurrentHandeler->launch);
 
143
        }
 
144
CD_APPLET_ON_CLICK_END
 
145
 
 
146
 
 
147
//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
 
148
CD_APPLET_ON_BUILD_MENU_BEGIN
 
149
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
150
        if (! myData.bIsRunning)
 
151
        {
 
152
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Find opened player"), GTK_STOCK_FIND, _cd_musicplayer_find_player, CD_APPLET_MY_MENU);
 
153
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_PLAY_PAUSE)
 
154
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (myData.pCurrentHandeler->name, (myData.iPlayingStatus != PLAYER_PLAYING ? GTK_STOCK_MEDIA_PLAY : GTK_STOCK_MEDIA_PAUSE), _cd_musicplayer_pp, CD_APPLET_MY_MENU);
 
155
        }
 
156
        else
 
157
        {
 
158
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_PREVIOUS)
 
159
                        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Previous"), GTK_STOCK_MEDIA_PREVIOUS, _cd_musicplayer_prev, CD_APPLET_MY_MENU);
 
160
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_PLAY_PAUSE)
 
161
                        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Play/Pause (left-click)"), (myData.iPlayingStatus != PLAYER_PLAYING ? GTK_STOCK_MEDIA_PLAY : GTK_STOCK_MEDIA_PAUSE), _cd_musicplayer_pp, CD_APPLET_MY_MENU);
 
162
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_NEXT)
 
163
                        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Next (middle-click)"), GTK_STOCK_MEDIA_NEXT, _cd_musicplayer_next, CD_APPLET_MY_MENU);
 
164
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_STOP)
 
165
                        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Stop"), GTK_STOCK_MEDIA_STOP, _cd_musicplayer_stop, CD_APPLET_MY_MENU);
 
166
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_JUMPBOX)
 
167
                        CD_APPLET_ADD_IN_MENU (D_("Show JumpBox"), _cd_musicplayer_jumpbox, CD_APPLET_MY_MENU);
 
168
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_SHUFFLE)
 
169
                        CD_APPLET_ADD_IN_MENU (D_("Toggle Shuffle"), _cd_musicplayer_shuffle, CD_APPLET_MY_MENU);
 
170
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_REPEAT)
 
171
                        CD_APPLET_ADD_IN_MENU (D_("Toggle Repeat"), _cd_musicplayer_repeat, CD_APPLET_MY_MENU);
 
172
                if (myData.pCurrentHandeler->iPlayerControls & PLAYER_RATE)
 
173
                        CD_APPLET_ADD_IN_MENU (D_("Rate this song"), _cd_musicplayer_rate, CD_APPLET_MY_MENU);
 
174
        }
 
175
        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Information"), GTK_STOCK_INFO, _cd_musicplayer_info, CD_APPLET_MY_MENU);
 
176
        CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
177
CD_APPLET_ON_BUILD_MENU_END
 
178
 
 
179
 
 
180
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
181
        if (myConfig.bPauseOnClick)
 
182
        {
 
183
                _cd_musicplayer_next (NULL, NULL);
 
184
        }
 
185
        else
 
186
        {
 
187
                _cd_musicplayer_pp (NULL, NULL);
 
188
        }
 
189
CD_APPLET_ON_MIDDLE_CLICK_END
 
190
 
 
191
 
 
192
CD_APPLET_ON_DROP_DATA_BEGIN
 
193
        cd_message (" %s --> nouvelle pochette ou chanson !", CD_APPLET_RECEIVED_DATA);
 
194
        
 
195
        gboolean isJpeg = g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"jpg") 
 
196
                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"JPG")
 
197
                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"jpeg")
 
198
                || g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"JPEG");
 
199
        
 
200
        if (isJpeg)
 
201
        {
 
202
                if (myData.cArtist != NULL && myData.cAlbum != NULL/* && myData.pCurrentHandeler->cCoverDir != NULL*/)
 
203
                {
 
204
                        cd_debug("Le fichier est un JPEG");
 
205
                        gchar *cDirPath = myData.pCurrentHandeler->cCoverDir ? g_strdup (myData.pCurrentHandeler->cCoverDir) : g_strdup_printf("%s/musicplayer", g_cCairoDockDataDir);
 
206
                        gchar *cCommand, *cHost = NULL;
 
207
                        gchar *cFilePath = (*CD_APPLET_RECEIVED_DATA == '/' ? g_strdup (CD_APPLET_RECEIVED_DATA) : g_filename_from_uri (CD_APPLET_RECEIVED_DATA, &cHost, NULL));
 
208
                        if (cHost != NULL)  // fichier distant, on le telecharge dans le cache du lecteur.
 
209
                        {
 
210
                                cd_debug("Le fichier est distant (sur %s)", cHost);
 
211
                                cCommand = g_strdup_printf ("wget -O \"%s/%s - %s.jpg\" '%s'",
 
212
                                        cDirPath,
 
213
                                        myData.cArtist,
 
214
                                        myData.cAlbum,
 
215
                                        CD_APPLET_RECEIVED_DATA);
 
216
                        }
 
217
                        else  // fichier local, on le copie juste dans le cache du lecteur.
 
218
                        {
 
219
                                cd_debug("Le fichier est local");
 
220
                                cCommand = g_strdup_printf ("cp \"%s\" \"%s/%s - %s.jpg\"",
 
221
                                        cFilePath,
 
222
                                        cDirPath,
 
223
                                        myData.cArtist,
 
224
                                        myData.cAlbum);
 
225
                                
 
226
                        }
 
227
                        cd_debug ("on recupere la pochette par : '%s'", cCommand);
 
228
                        cairo_dock_launch_command (cCommand);
 
229
                        g_free (cCommand);
 
230
                        g_free (cFilePath);
 
231
                        g_free (cHost);
 
232
                        g_free (cDirPath);
 
233
                        
 
234
                        cd_musicplayer_get_cover_path (NULL, TRUE);
 
235
                        cd_musicplayer_update_icon (FALSE);
 
236
                }
 
237
        }
 
238
        else
 
239
        {
 
240
                cd_debug ("on rajoute la chanson a la queue.");
 
241
                myData.pCurrentHandeler->control (PLAYER_ENQUEUE, CD_APPLET_RECEIVED_DATA);
 
242
        }
 
243
CD_APPLET_ON_DROP_DATA_END
 
244
 
 
245
 
 
246
CD_APPLET_ON_SCROLL_BEGIN
 
247
        if (CD_APPLET_SCROLL_DOWN) {
 
248
                _cd_musicplayer_next (NULL, NULL);
 
249
        }
 
250
        else if (CD_APPLET_SCROLL_UP) {
 
251
                _cd_musicplayer_prev (NULL, NULL);
 
252
        }
 
253
        else
 
254
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
255
CD_APPLET_ON_SCROLL_END
 
256
 
 
257
 
 
258
#define _update_button_count(on, count) \
 
259
        if (on) {\
 
260
                if (count < NB_TRANSITION_STEP) {\
 
261
                        count ++;\
 
262
                        bNeedsUpdate = TRUE; } }\
 
263
        else if (count != 0) {\
 
264
                count --;\
 
265
                bNeedsUpdate = TRUE; }
 
266
 
 
267
CD_APPLET_ON_UPDATE_ICON_BEGIN
 
268
 
 
269
        gboolean bNeedsUpdate = FALSE;
 
270
        
 
271
        if (myData.iCoverTransition > 0)
 
272
        {
 
273
                myData.iCoverTransition --;
 
274
                bNeedsUpdate = TRUE;
 
275
        }
 
276
        
 
277
        _update_button_count (myData.mouseOnButton1, myData.iButton1Count);
 
278
        _update_button_count (myData.mouseOnButton2, myData.iButton2Count);
 
279
        _update_button_count (myData.mouseOnButton3, myData.iButton3Count);
 
280
        _update_button_count (myData.mouseOnButton4, myData.iButton4Count);
 
281
        
 
282
        if (! bNeedsUpdate)
 
283
                CD_APPLET_STOP_UPDATE_ICON;  // quit.
 
284
        
 
285
        cd_opengl_render_to_texture (myApplet);
 
286
        
 
287
        if ((myData.iCoverTransition == 0) &&
 
288
                (myData.iButton1Count == 0 || myData.iButton1Count == NB_TRANSITION_STEP) &&
 
289
                (myData.iButton2Count == 0 || myData.iButton2Count == NB_TRANSITION_STEP) &&
 
290
                (myData.iButton3Count == 0 || myData.iButton3Count == NB_TRANSITION_STEP) &&
 
291
                (myData.iButton4Count == 0 || myData.iButton4Count == NB_TRANSITION_STEP))
 
292
        {
 
293
                CD_APPLET_PAUSE_UPDATE_ICON;  // redraw and stop.
 
294
        }
 
295
        
 
296
CD_APPLET_ON_UPDATE_ICON_END
 
297
 
 
298
 
 
299
gboolean cd_opengl_test_mouse_over_buttons (CairoDockModuleInstance *myApplet, CairoContainer *pContainer, gboolean *bStartAnimation)
 
300
{
 
301
        int iPrevButtonState = myData.iButtonState;
 
302
        myData.iButtonState = cd_opengl_check_buttons_state (myApplet);
 
303
        
 
304
        if (iPrevButtonState != myData.iButtonState)
 
305
        {
 
306
                *bStartAnimation = TRUE;  // ca c'est pour faire une animation de transition...
 
307
        }
 
308
        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
309
}