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

« back to all changes in this revision

Viewing changes to xmms/src/applet-notifications.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
#include <glib/gi18n.h>
 
32
 
 
33
#include "applet-struct.h"
 
34
#include "applet-notifications.h"
 
35
#include "applet-infopipe.h"
 
36
 
 
37
 
 
38
void cd_xmms_prev(CairoDockModuleInstance *myApplet) {
 
39
        GError *erreur = NULL;
 
40
        g_free (myData.playingTitle);
 
41
        myData.playingTitle = NULL; //Reseting the title to detect it for sure
 
42
        switch (myConfig.iPlayer) {
 
43
                case MY_XMMS :
 
44
                        g_spawn_command_line_async ("xmms -r", &erreur);
 
45
                break;
 
46
                case MY_AUDACIOUS :
 
47
                        g_spawn_command_line_async ("audacious -r", &erreur);
 
48
                break;
 
49
                case MY_BANSHEE :
 
50
                        g_spawn_command_line_async ("banshee --previous", &erreur);
 
51
                break;
 
52
                case MY_EXAILE :
 
53
                        g_spawn_command_line_async ("exaile -p", &erreur);
 
54
                break;
 
55
                default :
 
56
                return ;
 
57
        }
 
58
        if (erreur != NULL) {
 
59
                cd_warning ("Attention : when trying to execute 'previous on %d' : %s", myConfig.iPlayer, erreur->message);
 
60
                g_error_free (erreur);
 
61
        }
 
62
}
 
63
 
 
64
void cd_xmms_pp(CairoDockModuleInstance *myApplet) {
 
65
        GError *erreur = NULL;
 
66
        switch (myConfig.iPlayer) {
 
67
                case MY_XMMS :
 
68
                        g_spawn_command_line_async ("xmms -t", &erreur);
 
69
                break;
 
70
                case MY_AUDACIOUS :
 
71
                        g_spawn_command_line_async ("audacious -t", &erreur);
 
72
                break;
 
73
                case MY_BANSHEE :
 
74
                        g_spawn_command_line_async ("banshee --toggle-playing", &erreur);
 
75
                break;
 
76
                case MY_EXAILE :
 
77
                        g_spawn_command_line_async ("exaile -t", &erreur);
 
78
                break;
 
79
                default :
 
80
                return ;
 
81
        }
 
82
        if (erreur != NULL) {
 
83
                cd_warning ("Attention : when trying to execute 'play pause on %d' : %s", myConfig.iPlayer, erreur->message);
 
84
                g_error_free (erreur);
 
85
        }
 
86
}
 
87
void cd_xmms_stop(CairoDockModuleInstance *myApplet) {
 
88
        GError *erreur = NULL;
 
89
        switch (myConfig.iPlayer) {
 
90
                case MY_XMMS :
 
91
                        g_spawn_command_line_async ("xmms -s", &erreur);
 
92
                break;
 
93
                case MY_AUDACIOUS :
 
94
                        g_spawn_command_line_async ("audacious -s", &erreur);
 
95
                break;
 
96
                case MY_EXAILE :
 
97
                        g_spawn_command_line_async ("exaile -s", &erreur);
 
98
                break;
 
99
                default :  // banshee n'a pas de --stop.
 
100
                return ;
 
101
        }
 
102
        if (erreur != NULL) {
 
103
                cd_warning ("Attention : when trying to execute 'stop on %d' : %s", myConfig.iPlayer, erreur->message);
 
104
                g_error_free (erreur);
 
105
        }
 
106
}
 
107
void cd_xmms_next(CairoDockModuleInstance *myApplet) {
 
108
        GError *erreur = NULL;
 
109
        g_free (myData.playingTitle);
 
110
        myData.playingTitle = NULL; //Resetting the title to detect it for sure
 
111
        switch (myConfig.iPlayer) {
 
112
                case MY_XMMS :
 
113
                        g_spawn_command_line_async ("xmms -f", &erreur);
 
114
                break;
 
115
                case MY_AUDACIOUS :
 
116
                        g_spawn_command_line_async ("audacious -f", &erreur);
 
117
                break;
 
118
                case MY_BANSHEE :
 
119
                        g_spawn_command_line_async ("banshee --next", &erreur);
 
120
                break;
 
121
                case MY_EXAILE :
 
122
                        g_spawn_command_line_async ("exaile -n", &erreur);
 
123
                break;
 
124
                default :
 
125
                return ;
 
126
        }
 
127
        if (erreur != NULL) {
 
128
                cd_warning ("Attention : when trying to execute 'next on %d' : %s", myConfig.iPlayer, erreur->message);
 
129
                g_error_free (erreur);
 
130
        }
 
131
}
 
132
void cd_xmms_shuffle(CairoDockModuleInstance *myApplet) {
 
133
        GError *erreur = NULL;
 
134
        switch (myConfig.iPlayer) {
 
135
                case MY_XMMS :
 
136
                        g_spawn_command_line_async ("xmms -S", &erreur);
 
137
                break;
 
138
                case MY_AUDACIOUS :
 
139
                        g_spawn_command_line_async ("audtool playlist-repeat-toggle ", &erreur);
 
140
                break;
 
141
                default :
 
142
                return ;
 
143
        }
 
144
        if (erreur != NULL) {
 
145
                cd_warning ("Attention : when trying to execute 'shuffle on %d' : %s", myConfig.iPlayer, erreur->message);
 
146
                g_error_free (erreur);
 
147
        }
 
148
}
 
149
void cd_xmms_repeat(CairoDockModuleInstance *myApplet) {
 
150
        GError *erreur = NULL;
 
151
        switch (myConfig.iPlayer) {
 
152
                case MY_XMMS :
 
153
                        g_spawn_command_line_async ("xmms -R", &erreur);
 
154
                break;
 
155
                case MY_AUDACIOUS :
 
156
                        g_spawn_command_line_async ("audtool playlist-shuffle-toggle", &erreur);
 
157
                break;
 
158
                default :
 
159
                return ;
 
160
        }
 
161
        if (erreur != NULL) {
 
162
                cd_warning ("Attention : when trying to execute 'repeat on %d' : %s", myConfig.iPlayer, erreur->message);
 
163
                g_error_free (erreur);
 
164
        }
 
165
}
 
166
void cd_xmms_jumpbox(CairoDockModuleInstance *myApplet) {
 
167
        GError *erreur = NULL;
 
168
        switch (myConfig.iPlayer) {
 
169
                case MY_XMMS :
 
170
                        g_spawn_command_line_async ("xmms -j", &erreur);
 
171
                break;
 
172
                case MY_AUDACIOUS :
 
173
                        g_spawn_command_line_async ("audacious -j", &erreur);
 
174
                break;
 
175
                default :
 
176
                return ;
 
177
        }
 
178
        if (erreur != NULL) {
 
179
                cd_warning ("Attention : when trying to execute 'jumpbox on %d' : %s", myConfig.iPlayer, erreur->message);
 
180
                g_error_free (erreur);
 
181
        }
 
182
}
 
183
void cd_xmms_enqueue(CairoDockModuleInstance *myApplet, const gchar *cFile) {
 
184
        GError *erreur = NULL;
 
185
        gchar *cCommand = NULL;
 
186
        switch (myConfig.iPlayer) {
 
187
                case MY_XMMS :
 
188
                        cCommand = g_strdup_printf ("xmms -e %s", cFile);
 
189
                break;
 
190
                case MY_AUDACIOUS :
 
191
                        cCommand = g_strdup_printf ("audacious -e %s", cFile);
 
192
                break;
 
193
                case MY_BANSHEE :
 
194
                        cCommand = g_strdup_printf ("banshee --enqueue %s", cFile);
 
195
                break;
 
196
                case MY_EXAILE :
 
197
                        //Vraiment limité ce player...
 
198
                break;
 
199
                default :
 
200
                return ;
 
201
        }
 
202
        if (cCommand != NULL && cFile != NULL) {
 
203
                cd_debug("XMMS: will use '%s'", cCommand);
 
204
                g_spawn_command_line_async (cCommand, &erreur);
 
205
                g_free(cCommand);
 
206
        }
 
207
        if (erreur != NULL) {
 
208
                cd_warning ("Attention : when trying to execute 'next on %d' : %s", myConfig.iPlayer, erreur->message);
 
209
                g_error_free (erreur);
 
210
        }
 
211
}
 
212
 
 
213
 
 
214
 
 
215
 
 
216
static void _xmms_action_by_id (CairoDockModuleInstance *myApplet, int iAction) {
 
217
        switch (iAction) {
 
218
                case 0:
 
219
                        cd_xmms_prev(myApplet);
 
220
                break;
 
221
                case 1:
 
222
                        cd_xmms_pp(myApplet);
 
223
                break;
 
224
                case 2:
 
225
                        cd_xmms_stop(myApplet);
 
226
                break;
 
227
                case 3:
 
228
                        cd_xmms_next(myApplet);
 
229
                break;
 
230
                default :
 
231
                        cd_warning ("no action defined");
 
232
                break;
 
233
        }
 
234
}
 
235
CD_APPLET_ON_CLICK_BEGIN
 
236
        if (myDesklet != NULL && pClickedContainer == myContainer && pClickedIcon != NULL && pClickedIcon != myIcon) {  // clic sur une des icones du desklet.
 
237
                _xmms_action_by_id (myApplet, pClickedIcon->iType);
 
238
        }
 
239
        else {
 
240
          cd_xmms_pp(myApplet);
 
241
        }
 
242
CD_APPLET_ON_CLICK_END
 
243
 
 
244
 
 
245
static void _on_play_pause (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
246
{
 
247
        cd_xmms_pp (myApplet);
 
248
}
 
249
static void _on_prev (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
250
{
 
251
        cd_xmms_prev (myApplet);
 
252
}
 
253
static void _on_next (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
254
{
 
255
        cd_xmms_next (myApplet);
 
256
}
 
257
static void _on_stop (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
258
{
 
259
        cd_xmms_stop (myApplet);
 
260
}
 
261
static void _on_jumpbox (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
262
{
 
263
        cd_xmms_jumpbox (myApplet);
 
264
}
 
265
static void _on_shuffle (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
266
{
 
267
        cd_xmms_shuffle (myApplet);
 
268
}
 
269
static void _on_repeat (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
270
{
 
271
        cd_xmms_repeat (myApplet);
 
272
}
 
273
 
 
274
CD_APPLET_ON_BUILD_MENU_BEGIN
 
275
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
276
        CD_APPLET_ADD_IN_MENU (D_("Previous"), _on_prev, CD_APPLET_MY_MENU);
 
277
        CD_APPLET_ADD_IN_MENU (D_("Play/Pause (left-click)"), _on_play_pause, CD_APPLET_MY_MENU);
 
278
        if (myConfig.iPlayer != MY_BANSHEE) {
 
279
                CD_APPLET_ADD_IN_MENU (D_("Stop"), _on_stop, CD_APPLET_MY_MENU);
 
280
        }
 
281
        CD_APPLET_ADD_IN_MENU (D_("Next (middle-click)"), _on_next, CD_APPLET_MY_MENU);
 
282
        if ((myConfig.iPlayer != MY_BANSHEE) && (myConfig.iPlayer != MY_EXAILE)) {
 
283
                CD_APPLET_ADD_IN_MENU (D_("Show JumpBox"), _on_jumpbox, pSubMenu);
 
284
                CD_APPLET_ADD_IN_MENU (D_("Toggle Shuffle"), _on_shuffle, pSubMenu);
 
285
                CD_APPLET_ADD_IN_MENU (D_("Toggle Repeat"), _on_repeat, pSubMenu);
 
286
        }
 
287
        CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
288
CD_APPLET_ON_BUILD_MENU_END
 
289
 
 
290
 
 
291
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
292
        cd_xmms_next(myApplet);
 
293
CD_APPLET_ON_MIDDLE_CLICK_END
 
294
 
 
295
 
 
296
CD_APPLET_ON_DROP_DATA_BEGIN
 
297
        cd_message (" XMMS: %s to enqueue", CD_APPLET_RECEIVED_DATA);
 
298
        cd_xmms_enqueue (myApplet, CD_APPLET_RECEIVED_DATA);
 
299
CD_APPLET_ON_DROP_DATA_END
 
300
 
 
301
 
 
302
 
 
303
CD_APPLET_ON_SCROLL_BEGIN
 
304
                if (CD_APPLET_SCROLL_DOWN) {
 
305
                        cd_xmms_next(myApplet);
 
306
                }
 
307
                else if (CD_APPLET_SCROLL_UP) {
 
308
                        cd_xmms_prev(myApplet);
 
309
                }
 
310
                else
 
311
                        return CAIRO_DOCK_LET_PASS_NOTIFICATION;
 
312
CD_APPLET_ON_SCROLL_END