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

« back to all changes in this revision

Viewing changes to rhythmbox/src/rhythmbox-menu-functions.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 <stdlib.h>
 
21
#include <glib/gi18n.h>
 
22
 
 
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"
 
28
 
 
29
 
 
30
//*********************************************************************************
 
31
// rhythmbox_previous : Joue la piste précédante
 
32
//*********************************************************************************
 
33
static void rhythmbox_previous (GtkMenuItem *menu_item, gpointer *data)
 
34
{
 
35
        cd_message ("");
 
36
        cairo_dock_launch_command ("rhythmbox-client --previous");
 
37
}
 
38
 
 
39
//*********************************************************************************
 
40
// rhythmbox_next : Joue la piste suivante
 
41
//*********************************************************************************
 
42
static void rhythmbox_next (GtkMenuItem *menu_item, gpointer *data)
 
43
{
 
44
        cd_message ("");
 
45
        cairo_dock_launch_command ("rhythmbox-client --next");
 
46
}
 
47
 
 
48
static void rhythmbox_play_pause (GtkMenuItem *menu_item, gpointer *data)
 
49
{
 
50
        cd_message ("");
 
51
        cairo_dock_launch_command ("rhythmbox-client --play-pause");
 
52
}
 
53
 
 
54
static void rhythmbox_music (GtkMenuItem *menu_item, gpointer *data)
 
55
{
 
56
        music_dialog();
 
57
}
 
58
 
 
59
//*********************************************************************************
 
60
// Informations sur l'applet et l'auteur.
 
61
//*********************************************************************************
 
62
 
 
63
 
 
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)
 
70
        {
 
71
                CD_APPLET_ADD_IN_MENU (D_("Previous"), rhythmbox_previous, CD_APPLET_MY_MENU);
 
72
                
 
73
                CD_APPLET_ADD_IN_MENU (D_("Next (middle-click)"), rhythmbox_next, CD_APPLET_MY_MENU);
 
74
                
 
75
                CD_APPLET_ADD_IN_MENU (D_("Play/Pause (left-click)"), rhythmbox_play_pause, CD_APPLET_MY_MENU);
 
76
                
 
77
                CD_APPLET_ADD_IN_MENU (D_("Information"), rhythmbox_music, CD_APPLET_MY_MENU);
 
78
        }
 
79
        CD_APPLET_ADD_ABOUT_IN_MENU (CD_APPLET_MY_MENU);
 
80
CD_APPLET_ON_BUILD_MENU_END
 
81
 
 
82
 
 
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)
 
89
        {                       
 
90
                // Actions au clic sur un bouton :
 
91
                if (myData.mouseOnButton1)
 
92
                {
 
93
                        if(myData.bIsRunning)
 
94
                        {
 
95
                                if(myData.playing)
 
96
                                {
 
97
                                        g_spawn_command_line_async ("rhythmbox-client --pause", NULL);
 
98
                                }
 
99
                                else
 
100
                                {
 
101
                                        g_spawn_command_line_async ("rhythmbox-client --play", NULL);
 
102
                                }
 
103
                        }
 
104
                        else
 
105
                        {
 
106
                                g_spawn_command_line_async ("rhythmbox", NULL);
 
107
                        }
 
108
                }
 
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);
 
115
                else
 
116
                {
 
117
                        if(myData.bIsRunning)
 
118
                                music_dialog();
 
119
                        else
 
120
                                g_spawn_command_line_async ("rhythmbox", NULL);
 
121
                }
 
122
        }
 
123
        else
 
124
        {
 
125
                cd_message ("");
 
126
                
 
127
                if(myData.bIsRunning)
 
128
                {
 
129
                        if(myData.playing)
 
130
                        {
 
131
                                g_spawn_command_line_async ("rhythmbox-client --pause", NULL);
 
132
                        }
 
133
                        else
 
134
                        {
 
135
                                g_spawn_command_line_async ("rhythmbox-client --play", NULL);
 
136
                        }
 
137
                }
 
138
                else
 
139
                {
 
140
                        g_spawn_command_line_async ("rhythmbox", NULL);
 
141
                }
 
142
        }
 
143
CD_APPLET_ON_CLICK_END
 
144
 
 
145
 
 
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 
 
151
        cd_message ("");
 
152
        rhythmbox_getPlaying();
 
153
        if (myData.playing)
 
154
        {
 
155
                g_spawn_command_line_async ("rhythmbox-client --next", NULL);
 
156
        }
 
157
CD_APPLET_ON_MIDDLE_CLICK_END
 
158
 
 
159
 
 
160
CD_APPLET_ON_DROP_DATA_BEGIN
 
161
        cd_message (" %s --> nouvelle pochette ou chanson !", CD_APPLET_RECEIVED_DATA);
 
162
 
 
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");
 
167
        
 
168
        if(isJpeg)
 
169
        {
 
170
                if(myData.playing_artist != NULL && myData.playing_album != NULL)
 
171
                {
 
172
                        cd_debug("Le fichier est un JPEG");
 
173
                        GString *command = g_string_new ("");
 
174
                        if(strncmp(CD_APPLET_RECEIVED_DATA, "http://", 7) == 0)
 
175
                        {
 
176
                                cd_debug("Le fichier est distant");
 
177
                                g_string_printf (command, "wget -O %s/.cache/rhythmbox/covers/\"%s - %s.jpg\" %s",
 
178
                                        g_getenv ("HOME"),
 
179
                                        myData.playing_artist,
 
180
                                        myData.playing_album,
 
181
                                        CD_APPLET_RECEIVED_DATA);
 
182
                        }
 
183
                        else
 
184
                        {
 
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\"",
 
188
                                        cFilePath,
 
189
                                        g_getenv ("HOME"),
 
190
                                        myData.playing_artist,
 
191
                                        myData.playing_album);
 
192
                                g_free (cFilePath);
 
193
                        }
 
194
                        g_spawn_command_line_async (command->str, NULL);
 
195
                        cd_debug("La commande est passée");
 
196
                        g_string_free (command, TRUE);
 
197
                }
 
198
        }
 
199
        else
 
200
        {
 
201
                gchar *cCommand = g_strdup_printf ("rhythmbox-client --enqueue %s", CD_APPLET_RECEIVED_DATA);
 
202
                g_spawn_command_line_async (cCommand, NULL);
 
203
                g_free (cCommand);
 
204
        }
 
205
CD_APPLET_ON_DROP_DATA_END
 
206
 
 
207
 
 
208
CD_APPLET_ON_SCROLL_BEGIN
 
209
                if (CD_APPLET_SCROLL_DOWN) {
 
210
                        rhythmbox_next (NULL, NULL);
 
211
                }
 
212
                else if (CD_APPLET_SCROLL_UP) {
 
213
                        rhythmbox_previous (NULL, NULL);
 
214
                }
 
215
                else
 
216
                        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
217
CD_APPLET_ON_SCROLL_END
 
218
 
 
219
 
 
220
#define _update_button_count(on, count) \
 
221
        if (on) {\
 
222
                if (count < NB_TRANSITION_STEP) {\
 
223
                        count ++;\
 
224
                        bNeedsUpdate = TRUE; } }\
 
225
        else if (count != 0) {\
 
226
                count --;\
 
227
                bNeedsUpdate = TRUE; }
 
228
CD_APPLET_ON_UPDATE_ICON_BEGIN
 
229
 
 
230
        gboolean bNeedsUpdate = FALSE;
 
231
        
 
232
        if (myData.iCoverTransition > 0)
 
233
        {
 
234
                myData.iCoverTransition --;
 
235
                bNeedsUpdate = TRUE;
 
236
        }
 
237
        
 
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);
 
242
        
 
243
        if (! bNeedsUpdate)
 
244
                CD_APPLET_STOP_UPDATE_ICON;  // quit.
 
245
        
 
246
        cd_opengl_render_to_texture (myApplet);
 
247
        
 
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))
 
253
        {
 
254
                CD_APPLET_PAUSE_UPDATE_ICON;  // redraw and stop.
 
255
        }
 
256
        
 
257
CD_APPLET_ON_UPDATE_ICON_END
 
258
 
 
259
 
 
260
gboolean cd_opengl_test_mouse_over_buttons (CairoDockModuleInstance *myApplet, CairoContainer *pContainer, gboolean *bStartAnimation)
 
261
{
 
262
        if (pContainer != myContainer)
 
263
                return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
264
        
 
265
        int iPrevState = myData.iState;
 
266
        myData.iState = cd_opengl_check_buttons_state (myApplet);
 
267
        
 
268
        if (iPrevState != myData.iState)
 
269
        {
 
270
                *bStartAnimation = TRUE;  // ca c'est pour faire une animation de transition...
 
271
                //cd_opengl_render_to_texture (myApplet);  // ...sinon on redessine juste.
 
272
        }
 
273
        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
274
}