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

« back to all changes in this revision

Viewing changes to xmms/src/applet-init.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
 
 
31
#include "applet-struct.h"
 
32
#include "applet-config.h"
 
33
#include "applet-notifications.h"
 
34
#include "applet-draw.h"
 
35
#include "applet-infopipe.h"
 
36
#include "applet-init.h"
 
37
 
 
38
 
 
39
CD_APPLET_DEFINITION ("xmms",
 
40
        1, 6, 2,
 
41
        CAIRO_DOCK_CATEGORY_CONTROLER,
 
42
        N_("An applet dedicated to control XMMS, Audacious, Banshee & Exaile.\n"
 
43
        "XMMS & Audacious are fully supported, but Banshee and Exaile's monitoring is still experimental.\n"
 
44
        "For XMMS, you have to install the 'xmms-infopipe' plug-in.\n"
 
45
        "Launch/Play/Pause on left click, Next song on middle click.\n"
 
46
        "You can drag and drop songs on the icon to put them in the queue.\n"
 
47
        "Scroll up/down to play the previous/next song."),
 
48
        "ChAnGFu (Rémy Robertson)")
 
49
 
 
50
static gchar *s_cPlayerClass[MY_NB_PLAYERS] = {"xmms", "audacious", "banshee", "exaile"};
 
51
 
 
52
CD_APPLET_INIT_BEGIN
 
53
        if (myDesklet) {
 
54
                if (myConfig.extendedDesklet) {
 
55
                        cd_xmms_add_buttons_to_desklet (myApplet);
 
56
                        if (myConfig.iExtendedMode == MY_DESKLET_INFO || myConfig.iExtendedMode == MY_DESKLET_INFO_AND_CONTROLER) {
 
57
                                gpointer data[3] = {"None", "None", GINT_TO_POINTER (myConfig.iExtendedMode == MY_DESKLET_INFO ? FALSE : TRUE)};
 
58
                                CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Mediaplayer", data);
 
59
                        }
 
60
                        else {
 
61
                                gpointer data[2] = {GINT_TO_POINTER (TRUE), GINT_TO_POINTER (FALSE)};
 
62
                                CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Caroussel", data);
 
63
                        }
 
64
                }
 
65
                else {
 
66
                        CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
67
                }
 
68
        }
 
69
        
 
70
        myData.playingStatus = PLAYER_NONE;
 
71
        myData.previousPlayingStatus = -1;
 
72
        myData.previousPlayingTitle = NULL;
 
73
        myData.iPreviousTrackNumber = -1;
 
74
        myData.iPreviousCurrentTime = -1;
 
75
        myData.pTask = cairo_dock_new_task (1,
 
76
                (CairoDockGetDataAsyncFunc) cd_xmms_read_pipe,
 
77
                (CairoDockUpdateSyncFunc) cd_xmms_draw_icon,
 
78
                myApplet);
 
79
        cairo_dock_launch_task (myData.pTask);
 
80
        
 
81
        if (myConfig.bStealTaskBarIcon) {
 
82
                cairo_dock_inhibate_class (s_cPlayerClass[myConfig.iPlayer], myIcon);
 
83
        }
 
84
        
 
85
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
86
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
 
87
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
88
        CD_APPLET_REGISTER_FOR_DROP_DATA_EVENT;
 
89
        CD_APPLET_REGISTER_FOR_SCROLL_EVENT;
 
90
CD_APPLET_INIT_END
 
91
 
 
92
 
 
93
CD_APPLET_STOP_BEGIN
 
94
        //\_______________ On se desabonne de nos notifications.
 
95
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
 
96
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
 
97
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
 
98
        CD_APPLET_UNREGISTER_FOR_DROP_DATA_EVENT;
 
99
        CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT;
 
100
        
 
101
        if (myIcon->cClass != NULL)
 
102
                cairo_dock_deinhibate_class (s_cPlayerClass[myConfig.iPlayer], myIcon);
 
103
CD_APPLET_STOP_END
 
104
 
 
105
 
 
106
CD_APPLET_RELOAD_BEGIN
 
107
        //\_______________ On recharge les donnees qui ont pu changer.
 
108
        if (CD_APPLET_MY_CONFIG_CHANGED && myDesklet) {
 
109
                if ( ! myConfig.extendedDesklet && myDesklet->icons != NULL) {
 
110
                        g_list_foreach (myDesklet->icons, (GFunc) cairo_dock_free_icon, NULL);
 
111
                        g_list_free (myDesklet->icons);
 
112
                        myDesklet->icons = NULL;
 
113
                }
 
114
                else if (myConfig.extendedDesklet && myDesklet->icons == NULL) {
 
115
                        cd_xmms_add_buttons_to_desklet (myApplet);
 
116
                }
 
117
        }
 
118
        
 
119
        int i;
 
120
        for (i = 0; i < PLAYER_NB_STATUS; i ++) { // reset surfaces.
 
121
                if (myData.pSurfaces[i] != NULL) {
 
122
                        cairo_surface_destroy (myData.pSurfaces[i]);
 
123
                        myData.pSurfaces[i] = NULL;
 
124
                }
 
125
        }
 
126
        
 
127
        if (myDesklet) {
 
128
                if (myConfig.extendedDesklet) {
 
129
                        if (myConfig.iExtendedMode == MY_DESKLET_INFO || myConfig.iExtendedMode == MY_DESKLET_INFO_AND_CONTROLER) {
 
130
                                gpointer data[3] = {"None", "None", GINT_TO_POINTER (myConfig.iExtendedMode == MY_DESKLET_INFO ? FALSE : TRUE)};
 
131
                                CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Mediaplayer", data);
 
132
                        }
 
133
                        else {
 
134
                                gpointer data[2] = {GINT_TO_POINTER (TRUE), GINT_TO_POINTER (FALSE)};
 
135
                                CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Caroussel", data);
 
136
                        }
 
137
                }
 
138
                else {
 
139
                        CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
140
                }
 
141
        }
 
142
        
 
143
        //\_______________ On relance avec la nouvelle config ou on redessine.
 
144
        myData.playingStatus = PLAYER_NONE;
 
145
        myData.previousPlayingStatus = -1;
 
146
        myData.previousPlayingTitle = NULL;
 
147
        myData.iPreviousTrackNumber = -1;
 
148
        myData.iPreviousCurrentTime = -1;
 
149
        if (CD_APPLET_MY_CONFIG_CHANGED) {
 
150
                if (myIcon->cClass != NULL) { // on est en train d'inhiber l'appli.
 
151
                        if (! myConfig.bStealTaskBarIcon || strcmp (myIcon->cClass, s_cPlayerClass[myConfig.iPlayer]) != 0) { // on ne veut plus l'inhiber ou on veut inhiber une autre.
 
152
                                cairo_dock_deinhibate_class (myIcon->cClass, myIcon);
 
153
                        }
 
154
                }
 
155
                if (myConfig.bStealTaskBarIcon && myIcon->cClass == NULL) { // on comence a inhiber l'appli si on ne le faisait pas, ou qu'on s'est arrete.
 
156
                        cairo_dock_inhibate_class (s_cPlayerClass[myConfig.iPlayer], myIcon);
 
157
                }
 
158
                // inutile de relancer le timer, sa frequence ne change pas. Inutile aussi de faire 1 iteration ici, les modifs seront prises en compte a la prochaine iteration, dans au plus 1s.
 
159
        }
 
160
        else {  // on redessine juste l'icone.
 
161
                cd_xmms_draw_icon (myApplet);
 
162
        }
 
163
CD_APPLET_RELOAD_END