| 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/gstdio.h> |
| 22 |
|
| 23 |
#include "applet-config.h" |
| 24 |
#include "applet-notifications.h" |
| 25 |
#include "applet-struct.h" |
| 26 |
#include "applet-init.h" |
| 27 |
#include "applet-draw.h" |
| 28 |
#include "applet-musicplayer.h" |
| 29 |
#include "applet-dbus.h" |
| 30 |
#include "3dcover-draw.h" |
| 31 |
|
| 32 |
#include "applet-xmms2.h" //Support XMMS2 |
| 33 |
#include "applet-exaile.h" //Support Exaile |
| 34 |
#include "applet-exaile3.h" //Support Exaile 0.3 |
| 35 |
#include "applet-songbird.h" //Support Songbird |
| 36 |
#include "applet-banshee.h" //Support Banshee |
| 37 |
#include "applet-rhythmbox.h" //Support Rhythmbox |
| 38 |
#include "applet-qmmp.h" //Support Qmmp |
| 39 |
#include "applet-gmusicbrowser.h" //Support GMusicBrowser |
| 40 |
#include "applet-guayadeque.h" //Support Guayadeque |
| 41 |
#include "applet-quodlibet.h" //Support QuodLibet |
| 42 |
#include "applet-listen.h" //Support Listen |
| 43 |
#include "applet-amarok2.h" //Support Amarok 2 |
| 44 |
#include "applet-audacious.h" //Support Audacious |
| 45 |
#include "applet-clementine.h" // Support Clementine |
| 46 |
#include "applet-mpris2.h" // Support Clementine |
| 47 |
|
| 48 |
CD_APPLET_DEFINE_BEGIN (N_("musicPlayer"), |
| 49 |
2,0,0, |
| 50 |
CAIRO_DOCK_CATEGORY_APPLET_ACCESSORY, |
| 51 |
N_("This applet lets you control any music player.\n" |
| 52 |
"First choose the player you want to control.\n" |
| 53 |
"<b>click</b> to show/hide the player or pause,\n" |
| 54 |
"<b>middle-click</b> to pause or go to next song,\n" |
| 55 |
"<b>Scroll up/down</b> to change the song or control the volume.\n" |
| 56 |
"You can drag and drop songs on the icon to put them in the queue (depends on Player),\n" |
| 57 |
" and jpeg image to use as cover.\n" |
| 58 |
"Note: you may have to install or activate the MPRIS plug-in of the player."), |
| 59 |
"ChanGFu (Rémy Robertson), Mav (Yann SLADEK), Tofe, Jackass, Nochka85, Fabounet") |
| 60 |
CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE |
| 61 |
CD_APPLET_ALLOW_EMPTY_TITLE |
| 62 |
CD_APPLET_ACT_AS_LAUNCHER |
| 63 |
CD_APPLET_DEFINE_END |
| 64 |
|
| 65 |
|
| 66 |
//\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading). |
| 67 |
CD_APPLET_INIT_BEGIN |
| 68 |
// Register the players |
| 69 |
// Note: with MPRIS2, we don't need to register a custom handler for each player. We only register handlers of old interfaces (MPRIS1 and before). |
| 70 |
// Once all players use MPRIS2, we can drop all handlers but the MPRIS2 one. |
| 71 |
cd_musicplayer_register_exaile_handler(); |
| 72 |
cd_musicplayer_register_exaile3_handler(); |
| 73 |
cd_musicplayer_register_songbird_handler(); |
| 74 |
cd_musicplayer_register_banshee_handler(); |
| 75 |
cd_musicplayer_register_rhythmbox_handler(); |
| 76 |
cd_musicplayer_register_qmmp_handler(); |
| 77 |
cd_musicplayer_register_quodlibet_handler(); |
| 78 |
cd_musicplayer_register_listen_handler(); |
| 79 |
cd_musicplayer_register_amarok2_handler(); |
| 80 |
cd_musicplayer_register_xmms2_handler(); |
| 81 |
cd_musicplayer_register_audacious_handler(); |
| 82 |
cd_musicplayer_register_guayadeque_handler(); |
| 83 |
cd_musicplayer_register_clementine_handler(); |
| 84 |
cd_musicplayer_register_gmusicbrowser_handler(); |
| 85 |
cd_musicplayer_register_mpris2_handler(); |
| 86 |
|
| 87 |
gchar *cCoverPath = g_strdup_printf ("%s/musicplayer", g_cCairoDockDataDir); |
| 88 |
if (! g_file_test (cCoverPath, G_FILE_TEST_EXISTS)) |
| 89 |
{ |
| 90 |
if (g_mkdir (cCoverPath, 7*8*8+7*8+5) != 0) |
| 91 |
cd_warning ("couldn't create directory %s to download covers", cCoverPath); |
| 92 |
} |
| 93 |
g_free (cCoverPath); |
| 94 |
|
| 95 |
|
| 96 |
//\_______________ on definit un mode de rendu pour notre desklet. |
| 97 |
if (myDesklet) { |
| 98 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 99 |
} |
| 100 |
else if (myIcon->cName == NULL || *myIcon->cName == '\0') |
| 101 |
{ |
| 102 |
gchar *cDefaultName = cd_musicplayer_get_string_with_first_char_to_upper (myConfig.cMusicPlayer); |
| 103 |
CD_APPLET_SET_NAME_FOR_MY_ICON (cDefaultName); |
| 104 |
g_free (cDefaultName); |
| 105 |
} |
| 106 |
|
| 107 |
cairo_dock_set_icon_ignore_quicklist (myIcon); // ignore additional actions in the menu, as the applet already adds the actions supported by any player. |
| 108 |
|
| 109 |
//\_______________ on charge le theme 3D si necessaire. |
| 110 |
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes) |
| 111 |
myConfig.bOpenglThemes = cd_opengl_load_3D_theme (myApplet, myConfig.cThemePath); |
| 112 |
|
| 113 |
|
| 114 |
//\_______________ on demarre le backend. |
| 115 |
// Pour forcer le dessin initial. |
| 116 |
myData.iPlayingStatus = PLAYER_NONE; |
| 117 |
myData.pPreviousPlayingStatus = -1; |
| 118 |
myData.iPreviousTrackNumber = -1; |
| 119 |
myData.iPreviousCurrentTime = -1; |
| 120 |
|
| 121 |
cd_musicplayer_set_current_handler (myConfig.cMusicPlayer); |
| 122 |
|
| 123 |
//\_______________ On s'abonne aux notifications. |
| 124 |
CD_APPLET_REGISTER_FOR_CLICK_EVENT; |
| 125 |
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 126 |
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; |
| 127 |
CD_APPLET_REGISTER_FOR_DROP_DATA_EVENT; |
| 128 |
CD_APPLET_REGISTER_FOR_SCROLL_EVENT; |
| 129 |
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes) |
| 130 |
{ |
| 131 |
CD_APPLET_REGISTER_FOR_UPDATE_ICON_SLOW_EVENT; // pour les animation de transitions. |
| 132 |
if (myDesklet) // On ne teste le survol des boutons que si l'applet est detachee |
| 133 |
{ |
| 134 |
gldi_object_register_notification (myContainer, |
| 135 |
NOTIFICATION_MOUSE_MOVED, |
| 136 |
(GldiNotificationFunc) cd_opengl_test_mouse_over_buttons, |
| 137 |
GLDI_RUN_AFTER, |
| 138 |
myApplet); |
| 139 |
} |
| 140 |
} |
| 141 |
CD_APPLET_INIT_END |
| 142 |
|
| 143 |
|
| 144 |
//\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated. |
| 145 |
CD_APPLET_STOP_BEGIN |
| 146 |
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; |
| 147 |
CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 148 |
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; |
| 149 |
CD_APPLET_UNREGISTER_FOR_DROP_DATA_EVENT; |
| 150 |
CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT; |
| 151 |
gldi_object_remove_notification (myContainer, |
| 152 |
NOTIFICATION_MOUSE_MOVED, |
| 153 |
(GldiNotificationFunc) cd_opengl_test_mouse_over_buttons, |
| 154 |
myApplet); |
| 155 |
|
| 156 |
// stop the current handler. |
| 157 |
cd_musicplayer_stop_current_handler (TRUE); |
| 158 |
|
| 159 |
MusicPlayerHandler *pHandler = cd_musicplayer_get_handler_by_name ("Mpris2"); // Mpris2 handler has dynamic fields, free them. |
| 160 |
g_free ((gchar*)pHandler->launch); |
| 161 |
pHandler->launch = NULL; |
| 162 |
g_free ((gchar*)pHandler->appclass); |
| 163 |
pHandler->appclass = NULL; |
| 164 |
g_free ((gchar*)pHandler->cDisplayedName); |
| 165 |
pHandler->cDisplayedName = NULL; |
| 166 |
g_free ((gchar*)pHandler->cMprisService); |
| 167 |
pHandler->cMprisService = NULL; |
| 168 |
|
| 169 |
|
| 170 |
// On stoppe les boucles de recup de la pochette. |
| 171 |
if (myData.iSidCheckCover != 0) |
| 172 |
g_source_remove (myData.iSidCheckCover); |
| 173 |
gldi_task_free (myData.pCoverTask); |
| 174 |
|
| 175 |
// on libere la classe. |
| 176 |
gchar *cNull = NULL; |
| 177 |
CD_APPLET_MANAGE_APPLICATION (cNull); |
| 178 |
CD_APPLET_STOP_END |
| 179 |
|
| 180 |
|
| 181 |
//\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode. |
| 182 |
CD_APPLET_RELOAD_BEGIN |
| 183 |
//\_______________ On reset surfaces et textures. |
| 184 |
int i; |
| 185 |
for (i = 0; i < PLAYER_NB_STATUS; i ++) { // reset surfaces. |
| 186 |
if (myData.pSurfaces[i] != NULL) { |
| 187 |
cairo_surface_destroy (myData.pSurfaces[i]); |
| 188 |
myData.pSurfaces[i] = NULL; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
cd_opengl_reset_opengl_datas (myApplet); |
| 193 |
|
| 194 |
//\_______________ On recharge entierement le theme 3D. |
| 195 |
if (CD_APPLET_MY_CONFIG_CHANGED) |
| 196 |
{ |
| 197 |
if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer. |
| 198 |
{ |
| 199 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 200 |
} |
| 201 |
|
| 202 |
CD_APPLET_UNREGISTER_FOR_UPDATE_ICON_SLOW_EVENT; |
| 203 |
gldi_object_remove_notification (CD_APPLET_MY_OLD_CONTAINER, |
| 204 |
NOTIFICATION_MOUSE_MOVED, |
| 205 |
(GldiNotificationFunc) cd_opengl_test_mouse_over_buttons, |
| 206 |
myApplet); |
| 207 |
|
| 208 |
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes) |
| 209 |
{ |
| 210 |
CD_APPLET_REGISTER_FOR_UPDATE_ICON_SLOW_EVENT; |
| 211 |
if (myDesklet) // On ne teste le survol des boutons que si l'applet est detachee |
| 212 |
gldi_object_register_notification (myContainer, |
| 213 |
NOTIFICATION_MOUSE_MOVED, |
| 214 |
(GldiNotificationFunc) cd_opengl_test_mouse_over_buttons, |
| 215 |
GLDI_RUN_AFTER, |
| 216 |
myApplet); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
if (CD_APPLET_MY_CONTAINER_IS_OPENGL && myConfig.bOpenglThemes) |
| 221 |
{ |
| 222 |
myConfig.bOpenglThemes = cd_opengl_load_3D_theme (myApplet, myConfig.cThemePath); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
//\_______________ On force le redessin. |
| 227 |
//myData.iPlayingStatus = PLAYER_NONE; |
| 228 |
myData.pPreviousPlayingStatus = -1; |
| 229 |
if( myData.cPreviousRawTitle ) |
| 230 |
{ |
| 231 |
g_free (myData.cPreviousRawTitle); |
| 232 |
myData.cPreviousRawTitle = NULL; |
| 233 |
} |
| 234 |
if( myData.cPreviousCoverPath ) |
| 235 |
{ |
| 236 |
g_free (myData.cPreviousCoverPath); |
| 237 |
myData.cPreviousCoverPath = NULL; |
| 238 |
} |
| 239 |
myData.iPreviousTrackNumber = -1; |
| 240 |
myData.iPreviousCurrentTime = -1; |
| 241 |
|
| 242 |
myData.cover_exist = FALSE; |
| 243 |
myData.iCurrentFileSize = 0; |
| 244 |
myData.iGetTimeFailed = 0; |
| 245 |
|
| 246 |
//\_______________ On gere le changement de player ou on redessine juste l'icone. |
| 247 |
if (CD_APPLET_MY_CONFIG_CHANGED) |
| 248 |
{ |
| 249 |
// on stoppe l'ancien backend et on relance le nouveau. |
| 250 |
cd_musicplayer_stop_current_handler (TRUE); // libere tout ce qu'occupe notre ancien handler. |
| 251 |
|
| 252 |
gchar *cNull = NULL; |
| 253 |
CD_APPLET_MANAGE_APPLICATION (cNull); |
| 254 |
|
| 255 |
cd_musicplayer_set_current_handler (myConfig.cMusicPlayer); |
| 256 |
} |
| 257 |
else // on redessine juste l'icone. |
| 258 |
{ |
| 259 |
if (myConfig.bEnableCover && myData.cover_exist && myData.cCoverPath != NULL) // cover is available |
| 260 |
{ |
| 261 |
cd_musiplayer_apply_cover (); |
| 262 |
} |
| 263 |
else // no cover -> set the status surface. |
| 264 |
{ |
| 265 |
cd_musicplayer_apply_status_surface (myData.iPlayingStatus); |
| 266 |
} |
| 267 |
} |
| 268 |
CD_APPLET_RELOAD_END |