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>
23
#include "rhythmbox-dbus.h"
24
#include "rhythmbox-draw.h"
25
#include "rhythmbox-struct.h"
26
#include "rhythmbox-menu-functions.h"
27
#include "3dcover-draw.h"
30
//*********************************************************************************
31
// rhythmbox_previous : Joue la piste précédante
32
//*********************************************************************************
33
static void rhythmbox_previous (GtkMenuItem *menu_item, gpointer *data)
36
cairo_dock_launch_command ("rhythmbox-client --previous");
39
//*********************************************************************************
40
// rhythmbox_next : Joue la piste suivante
41
//*********************************************************************************
42
static void rhythmbox_next (GtkMenuItem *menu_item, gpointer *data)
45
cairo_dock_launch_command ("rhythmbox-client --next");
48
static void rhythmbox_play_pause (GtkMenuItem *menu_item, gpointer *data)
51
cairo_dock_launch_command ("rhythmbox-client --play-pause");
54
static void rhythmbox_music (GtkMenuItem *menu_item, gpointer *data)
59
//*********************************************************************************
60
// Informations sur l'applet et l'auteur.
61
//*********************************************************************************
64
//*********************************************************************************
65
// Fonction appelée a la construction du menu.
66
// Cette fonction remplit le menu principal avec les actions previous, next, et information.
67
//*********************************************************************************
68
CD_APPLET_ON_BUILD_MENU_BEGIN
69
if (myData.dbus_enable)
71
CD_APPLET_ADD_IN_MENU (D_("Previous"), rhythmbox_previous, CD_APPLET_MY_MENU);
73
CD_APPLET_ADD_IN_MENU (D_("Next (middle-click)"), rhythmbox_next, CD_APPLET_MY_MENU);
75
CD_APPLET_ADD_IN_MENU (D_("Play/Pause (left-click)"), rhythmbox_play_pause, CD_APPLET_MY_MENU);
77
CD_APPLET_ADD_IN_MENU (D_("Information"), rhythmbox_music, CD_APPLET_MY_MENU);
79
CD_APPLET_ADD_ABOUT_IN_MENU (CD_APPLET_MY_MENU);
80
CD_APPLET_ON_BUILD_MENU_END
83
//*********************************************************************************
84
// Fonction appelée au clique sur l'icone.
85
// Cette fonction met le lecteur en pause ou en lecture selon son état.
86
//*********************************************************************************
87
CD_APPLET_ON_CLICK_BEGIN
88
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myData.numberButtons != 0 && myConfig.bOpenglThemes && myDesklet)
90
// Actions au clic sur un bouton :
91
if (myData.mouseOnButton1)
97
g_spawn_command_line_async ("rhythmbox-client --pause", NULL);
101
g_spawn_command_line_async ("rhythmbox-client --play", NULL);
106
g_spawn_command_line_async ("rhythmbox", NULL);
109
else if (myData.mouseOnButton2)
110
g_spawn_command_line_async ("rhythmbox-client --previous", NULL);
111
else if (myData.mouseOnButton3)
112
g_spawn_command_line_async ("rhythmbox-client --next", NULL);
113
else if (myData.mouseOnButton4)
114
g_spawn_command_line_async ("rhythmbox", NULL);
117
if(myData.bIsRunning)
120
g_spawn_command_line_async ("rhythmbox", NULL);
127
if(myData.bIsRunning)
131
g_spawn_command_line_async ("rhythmbox-client --pause", NULL);
135
g_spawn_command_line_async ("rhythmbox-client --play", NULL);
140
g_spawn_command_line_async ("rhythmbox", NULL);
143
CD_APPLET_ON_CLICK_END
146
//*********************************************************************************
147
// Fonction appelée au clique du milieu sur l'icone.
148
// Cette fonction passe a la chanson suivante.
149
//*********************************************************************************
150
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
152
rhythmbox_getPlaying();
155
g_spawn_command_line_async ("rhythmbox-client --next", NULL);
157
CD_APPLET_ON_MIDDLE_CLICK_END
160
CD_APPLET_ON_DROP_DATA_BEGIN
161
cd_message (" %s --> nouvelle pochette ou chanson !", CD_APPLET_RECEIVED_DATA);
163
gboolean isJpeg = g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"jpg")
164
|| g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"JPG")
165
|| g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"jpeg")
166
|| g_str_has_suffix(CD_APPLET_RECEIVED_DATA,"JPEG");
170
if(myData.playing_artist != NULL && myData.playing_album != NULL)
172
cd_debug("Le fichier est un JPEG");
173
GString *command = g_string_new ("");
174
if(strncmp(CD_APPLET_RECEIVED_DATA, "http://", 7) == 0)
176
cd_debug("Le fichier est distant");
177
g_string_printf (command, "wget -O %s/.cache/rhythmbox/covers/\"%s - %s.jpg\" %s",
179
myData.playing_artist,
180
myData.playing_album,
181
CD_APPLET_RECEIVED_DATA);
185
cd_debug("Le fichier est local");
186
gchar *cFilePath = (*CD_APPLET_RECEIVED_DATA == '/' ? g_strdup (CD_APPLET_RECEIVED_DATA) : g_filename_from_uri (CD_APPLET_RECEIVED_DATA, NULL, NULL));
187
g_string_printf (command, "cp %s %s/.cache/rhythmbox/covers/\"%s - %s.jpg\"",
190
myData.playing_artist,
191
myData.playing_album);
194
g_spawn_command_line_async (command->str, NULL);
195
cd_debug("La commande est passée");
196
g_string_free (command, TRUE);
201
gchar *cCommand = g_strdup_printf ("rhythmbox-client --enqueue %s", CD_APPLET_RECEIVED_DATA);
202
g_spawn_command_line_async (cCommand, NULL);
205
CD_APPLET_ON_DROP_DATA_END
208
CD_APPLET_ON_SCROLL_BEGIN
209
if (CD_APPLET_SCROLL_DOWN) {
210
rhythmbox_next (NULL, NULL);
212
else if (CD_APPLET_SCROLL_UP) {
213
rhythmbox_previous (NULL, NULL);
216
return CAIRO_DOCK_LET_PASS_NOTIFICATION;
217
CD_APPLET_ON_SCROLL_END
220
#define _update_button_count(on, count) \
222
if (count < NB_TRANSITION_STEP) {\
224
bNeedsUpdate = TRUE; } }\
225
else if (count != 0) {\
227
bNeedsUpdate = TRUE; }
228
CD_APPLET_ON_UPDATE_ICON_BEGIN
230
gboolean bNeedsUpdate = FALSE;
232
if (myData.iCoverTransition > 0)
234
myData.iCoverTransition --;
238
_update_button_count (myData.mouseOnButton1, myData.iButton1Count);
239
_update_button_count (myData.mouseOnButton2, myData.iButton2Count);
240
_update_button_count (myData.mouseOnButton3, myData.iButton3Count);
241
_update_button_count (myData.mouseOnButton4, myData.iButton4Count);
244
CD_APPLET_STOP_UPDATE_ICON; // quit.
246
cd_opengl_render_to_texture (myApplet);
248
if ((myData.iCoverTransition == 0) &&
249
(myData.iButton1Count == 0 || myData.iButton1Count == NB_TRANSITION_STEP) &&
250
(myData.iButton2Count == 0 || myData.iButton2Count == NB_TRANSITION_STEP) &&
251
(myData.iButton3Count == 0 || myData.iButton3Count == NB_TRANSITION_STEP) &&
252
(myData.iButton4Count == 0 || myData.iButton4Count == NB_TRANSITION_STEP))
254
CD_APPLET_PAUSE_UPDATE_ICON; // redraw and stop.
257
CD_APPLET_ON_UPDATE_ICON_END
260
gboolean cd_opengl_test_mouse_over_buttons (CairoDockModuleInstance *myApplet, CairoContainer *pContainer, gboolean *bStartAnimation)
262
if (pContainer != myContainer)
263
return CAIRO_DOCK_LET_PASS_NOTIFICATION;
265
int iPrevState = myData.iState;
266
myData.iState = cd_opengl_check_buttons_state (myApplet);
268
if (iPrevState != myData.iState)
270
*bStartAnimation = TRUE; // ca c'est pour faire une animation de transition...
271
//cd_opengl_render_to_texture (myApplet); // ...sinon on redessine juste.
273
return CAIRO_DOCK_LET_PASS_NOTIFICATION;