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/>.
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"
32
static void _cd_musicplayer_prev (GtkMenuItem *menu_item, gpointer *data) {
33
myData.pCurrentHandeler->control (PLAYER_PREVIOUS, NULL);
35
static void _cd_musicplayer_pp (GtkMenuItem *menu_item, gpointer *data) {
36
myData.pCurrentHandeler->control (PLAYER_PLAY_PAUSE, NULL);
38
static void _cd_musicplayer_stop (GtkMenuItem *menu_item, gpointer *data) {
39
myData.pCurrentHandeler->control (PLAYER_STOP, NULL);
41
static void _cd_musicplayer_next (GtkMenuItem *menu_item, gpointer *data) {
42
myData.pCurrentHandeler->control (PLAYER_NEXT, NULL);
44
static void _cd_musicplayer_jumpbox (GtkMenuItem *menu_item, gpointer *data) {
45
myData.pCurrentHandeler->control (PLAYER_JUMPBOX, NULL);
47
static void _cd_musicplayer_shuffle (GtkMenuItem *menu_item, gpointer *data) {
48
myData.pCurrentHandeler->control (PLAYER_SHUFFLE, NULL);
50
static void _cd_musicplayer_repeat (GtkMenuItem *menu_item, gpointer *data) {
51
myData.pCurrentHandeler->control (PLAYER_REPEAT, NULL);
53
static void _cd_musicplayer_rate (GtkMenuItem *menu_item, gpointer *data) {
54
/// trouver un moyen esthetique.
56
static void _cd_musicplayer_info (GtkMenuItem *menu_item, gpointer *data)
58
cd_musicplayer_popup_info ();
61
static void _cd_musicplayer_find_player (GtkMenuItem *menu_item, gpointer *data)
63
MusicPlayerHandeler *pHandler = cd_musicplayer_dbus_find_opened_player ();
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."),
70
MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
72
else if (pHandler != myData.pCurrentHandeler)
74
if (myData.pCurrentHandeler)
76
cd_musicplayer_stop_handler (); // libĆØre tout ce qu'occupe notre ancien handler.
77
CD_APPLET_MANAGE_APPLICATION (myData.pCurrentHandeler->appclass, FALSE);
79
myData.pCurrentHandeler = pHandler;
80
cd_musicplayer_launch_handler ();
81
CD_APPLET_MANAGE_APPLICATION (myData.pCurrentHandeler->appclass, myConfig.bStealTaskBarIcon);
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)
89
// Actions au clic sur un bouton :
90
if (myData.mouseOnButton1)
94
_cd_musicplayer_pp (NULL, NULL);
96
else if (myData.pCurrentHandeler->launch != NULL)
98
cairo_dock_launch_command (myData.pCurrentHandeler->launch);
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)
107
if(myData.bIsRunning)
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);
114
else if (myData.pCurrentHandeler->launch != NULL)
115
cairo_dock_launch_command (myData.pCurrentHandeler->launch);
119
if(myData.bIsRunning)
120
cd_musicplayer_popup_info ();
121
else if (myData.pCurrentHandeler->launch != NULL)
122
cairo_dock_launch_command (myData.pCurrentHandeler->launch);
127
if(myData.bIsRunning)
129
if (myConfig.bPauseOnClick)
131
_cd_musicplayer_pp (NULL, NULL);
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);
138
cairo_dock_show_xwindow (myIcon->Xid);
141
else if (myData.pCurrentHandeler->launch != NULL)
142
cairo_dock_launch_command (myData.pCurrentHandeler->launch);
144
CD_APPLET_ON_CLICK_END
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)
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);
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);
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
180
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
181
if (myConfig.bPauseOnClick)
183
_cd_musicplayer_next (NULL, NULL);
187
_cd_musicplayer_pp (NULL, NULL);
189
CD_APPLET_ON_MIDDLE_CLICK_END
192
CD_APPLET_ON_DROP_DATA_BEGIN
193
cd_message (" %s --> nouvelle pochette ou chanson !", CD_APPLET_RECEIVED_DATA);
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");
202
if (myData.cArtist != NULL && myData.cAlbum != NULL/* && myData.pCurrentHandeler->cCoverDir != NULL*/)
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.
210
cd_debug("Le fichier est distant (sur %s)", cHost);
211
cCommand = g_strdup_printf ("wget -O \"%s/%s - %s.jpg\" '%s'",
215
CD_APPLET_RECEIVED_DATA);
217
else // fichier local, on le copie juste dans le cache du lecteur.
219
cd_debug("Le fichier est local");
220
cCommand = g_strdup_printf ("cp \"%s\" \"%s/%s - %s.jpg\"",
227
cd_debug ("on recupere la pochette par : '%s'", cCommand);
228
cairo_dock_launch_command (cCommand);
234
cd_musicplayer_get_cover_path (NULL, TRUE);
235
cd_musicplayer_update_icon (FALSE);
240
cd_debug ("on rajoute la chanson a la queue.");
241
myData.pCurrentHandeler->control (PLAYER_ENQUEUE, CD_APPLET_RECEIVED_DATA);
243
CD_APPLET_ON_DROP_DATA_END
246
CD_APPLET_ON_SCROLL_BEGIN
247
if (CD_APPLET_SCROLL_DOWN) {
248
_cd_musicplayer_next (NULL, NULL);
250
else if (CD_APPLET_SCROLL_UP) {
251
_cd_musicplayer_prev (NULL, NULL);
254
return CAIRO_DOCK_LET_PASS_NOTIFICATION;
255
CD_APPLET_ON_SCROLL_END
258
#define _update_button_count(on, count) \
260
if (count < NB_TRANSITION_STEP) {\
262
bNeedsUpdate = TRUE; } }\
263
else if (count != 0) {\
265
bNeedsUpdate = TRUE; }
267
CD_APPLET_ON_UPDATE_ICON_BEGIN
269
gboolean bNeedsUpdate = FALSE;
271
if (myData.iCoverTransition > 0)
273
myData.iCoverTransition --;
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);
283
CD_APPLET_STOP_UPDATE_ICON; // quit.
285
cd_opengl_render_to_texture (myApplet);
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))
293
CD_APPLET_PAUSE_UPDATE_ICON; // redraw and stop.
296
CD_APPLET_ON_UPDATE_ICON_END
299
gboolean cd_opengl_test_mouse_over_buttons (CairoDockModuleInstance *myApplet, CairoContainer *pContainer, gboolean *bStartAnimation)
301
int iPrevButtonState = myData.iButtonState;
302
myData.iButtonState = cd_opengl_check_buttons_state (myApplet);
304
if (iPrevButtonState != myData.iButtonState)
306
*bStartAnimation = TRUE; // ca c'est pour faire une animation de transition...
308
return CAIRO_DOCK_LET_PASS_NOTIFICATION;