Debian Codegraph @

musicPlayer/src/applet-musicplayer.c

raw
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 <string.h>
22 #include <cairo-dock.h>
23
24 #include "applet-struct.h"
25 #include "applet-draw.h"
26 #include "applet-dbus.h"
27 #include "applet-musicplayer.h"
28
29 static void _on_name_owner_changed (const gchar *cName, gboolean bOwned, gpointer data);
30
31 /*
32 detect running:
33 get dbus services
34 foreach:
35 is mpris2 -> get it
36 is in handlers list -> get it
37
38 if no current handler:
39 click/menu -> detect running player -> build list with the found one selected -> set as default in conf, get and launch handler
40
41 if preferred player is defined:
42 get handler from name
43 if none: make a generic handler from the service
44 set as current
45 watch it; watch mpris2 too
46 detect both async -> present => owned
47
48 owned =>
49 if mpris2: set mpris2 handler as current
50 launch it
51 not owned => stop handler
52 */
53
54 static inline void _fill_handler_properties (const gchar *cDesktopFileName, gchar *cAppClass)
55 {
56 g_free ((gchar*)myData.pCurrentHandler->appclass);
57 myData.pCurrentHandler->appclass = cAppClass;
58 g_free ((gchar*)myData.pCurrentHandler->launch);
59 myData.pCurrentHandler->launch = g_strdup (cairo_dock_get_class_command (myData.pCurrentHandler->appclass));
60 if (myData.pCurrentHandler->launch == NULL) // we really need a command to launch it on click, so insist a little
61 myData.pCurrentHandler->launch = g_strdup (cDesktopFileName);
62 g_free ((gchar*)myData.pCurrentHandler->cDisplayedName);
63 myData.pCurrentHandler->cDisplayedName = g_strdup (cairo_dock_get_class_name (myData.pCurrentHandler->appclass));
64 }
65
66 static inline void _get_right_class_and_desktop_file (const gchar *cName, gchar **cDesktopFileName, gchar **cAppClass)
67 {
68 if (myConfig.cLastKnownDesktopFile)
69 {
70 *cDesktopFileName = myConfig.cLastKnownDesktopFile;
71 *cAppClass = cairo_dock_register_class (*cDesktopFileName); // no need to be freed here
72 }
73 if (*cAppClass == NULL && cName) // myConfig.cLastKnownDesktopFile is NULL when transitionning from an old version of the applet where we didn't use the "Desktop Entry" property yet -> use some heuristic as a fallback.
74 {
75 *cAppClass = cairo_dock_register_class (cName); // no need to be freed here
76 if (*cAppClass == NULL &&
77 (*cDesktopFileName = strrchr (cName, '.')) != NULL) // if cName = org.mpris.MediaPlayer2.amarok => amarok
78 *cAppClass = cairo_dock_register_class (*cDesktopFileName+1); // no need to be freed here
79 else
80 *cDesktopFileName = (gchar *)cName;
81 }
82 cd_debug ("%s (%s - %s) => (%s - %s)", __func__, myConfig.cLastKnownDesktopFile, cName, *cDesktopFileName, *cAppClass);
83 }
84
85 MusicPlayerHandler *cd_musicplayer_get_handler_by_name (const gchar *cName)
86 {
87 g_return_val_if_fail (cName != NULL, NULL);
88 GList *h;
89 MusicPlayerHandler *handler;
90 for (h = myData.pHandlers; h != NULL; h = h->next)
91 {
92 handler = h->data;
93 if (strcmp (handler->name, cName) == 0)
94 return handler;
95 }
96 return NULL;
97 }
98
99
100 static void _cd_musicplayer_get_data_async (gpointer data) {
101 if (myData.pCurrentHandler->get_data)
102 myData.pCurrentHandler->get_data();
103 }
104
105 static gboolean _cd_musicplayer_update_from_data (gpointer data)
106 {
107 g_return_val_if_fail (myData.pCurrentHandler->iLevel != PLAYER_EXCELLENT, FALSE);
108 //cd_debug ("MP - %s (%d : %d -> %d)", __func__, myData.iPlayingStatus, myData.iPreviousCurrentTime, myData.iCurrentTime);
109 CD_APPLET_ENTER;
110 gboolean bNeedRedraw = FALSE;
111
112 // All players: update the time.
113 if (myData.iCurrentTime != myData.iPreviousCurrentTime)
114 {
115 myData.iPreviousCurrentTime = myData.iCurrentTime;
116 if (myData.iPlayingStatus == PLAYER_PLAYING || myData.iPlayingStatus == PLAYER_PAUSED)
117 {
118 if (myData.iCurrentTime >= 0) // peut etre -1 si le lecteur a demarre mais ne fournit pas encore de temps.
119 {
120 if (myConfig.iQuickInfoType == MY_APPLET_TIME_ELAPSED)
121 {
122 CD_APPLET_SET_MINUTES_SECONDES_AS_QUICK_INFO (myData.iCurrentTime);
123 }
124 else if (myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT)
125 {
126 CD_APPLET_SET_MINUTES_SECONDES_AS_QUICK_INFO (myData.iCurrentTime - myData.iSongLength);
127 }
128 }
129 else
130 CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
131 }
132 else
133 {
134 CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
135 }
136 bNeedRedraw = TRUE;
137 }
138
139 // Bad players: update the icon if the state or song has changed (no signals for this).
140 if (myData.pCurrentHandler->iLevel == PLAYER_BAD)
141 {
142 if (myData.iPlayingStatus != myData.pPreviousPlayingStatus) // state has changed.
143 {
144 cd_debug ("MP : PlayingStatus : %d -> %d", myData.pPreviousPlayingStatus, myData.iPlayingStatus);
145 myData.pPreviousPlayingStatus = myData.iPlayingStatus;
146
147 cd_musicplayer_update_icon ();
148 bNeedRedraw = FALSE;
149 }
150 else if (cairo_dock_strings_differ (myData.cPreviousRawTitle, myData.cRawTitle)) // song has changed.
151 {
152 g_free (myData.cPreviousRawTitle);
153 myData.cPreviousRawTitle = g_strdup (myData.cRawTitle);
154 cd_musicplayer_update_icon ();
155 bNeedRedraw = FALSE;
156 }
157 }
158
159 if (bNeedRedraw)
160 CD_APPLET_REDRAW_MY_ICON;
161
162 CD_APPLET_LEAVE (myData.pCurrentHandler->iLevel == PLAYER_BAD || (myData.pCurrentHandler->iLevel == PLAYER_GOOD && myData.iPlayingStatus == PLAYER_PLAYING));
163 }
164
165 static gboolean _cd_musicplayer_get_data_and_update (gpointer data) {
166 CD_APPLET_ENTER;
167 if (myData.pCurrentHandler->get_data)
168 myData.pCurrentHandler->get_data();
169 return _cd_musicplayer_update_from_data (data); // cette fonction sort.
170 }
171
172 /* Initialise le backend et lance la tache periodique si necessaire.
173 */
174 void cd_musicplayer_launch_handler (void)
175 {
176 cd_debug ("%s (%s, %s)", __func__, myData.pCurrentHandler->name, myData.pCurrentHandler->appclass);
177 // connect to the player.
178 if (myData.dbus_proxy_player != NULL) // don't start twice.
179 return;
180 if (! cd_musicplayer_dbus_connect_handler (myData.pCurrentHandler))
181 return;
182
183 // start the handler (connect to signals, or whatever the handler has to do internally).
184 if (myData.pCurrentHandler->start != NULL)
185 {
186 myData.pCurrentHandler->start();
187 }
188
189 // start the timer.
190 if (myData.pCurrentHandler->get_data && (myData.pCurrentHandler->iLevel == PLAYER_BAD || (myData.pCurrentHandler->iLevel == PLAYER_GOOD && (myConfig.iQuickInfoType == MY_APPLET_TIME_ELAPSED || myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT)))) // il y'a de l'acquisition de donnees periodique a faire.
191 {
192 if (myData.pCurrentHandler->bSeparateAcquisition == TRUE) // Utilisation du thread pour les actions longues
193 {
194 myData.pTask = gldi_task_new (1,
195 (GldiGetDataAsyncFunc) _cd_musicplayer_get_data_async,
196 (GldiUpdateSyncFunc) _cd_musicplayer_update_from_data,
197 NULL);
198 }
199 else
200 {
201 myData.pTask = gldi_task_new (1,
202 NULL,
203 (GldiUpdateSyncFunc) _cd_musicplayer_get_data_and_update,
204 NULL);
205 }
206 gldi_task_launch (myData.pTask);
207 } // else all is done by signals.
208
209 myData.bIsRunning = TRUE;
210 }
211
212 /* Relance le backend s'il avait ete arrete (lecteur en pause ou arrete).
213 */
214 void cd_musicplayer_relaunch_handler (void)
215 {
216 if (myData.pCurrentHandler->get_data && (myData.pCurrentHandler->iLevel == PLAYER_BAD || (myData.pCurrentHandler->iLevel == PLAYER_GOOD && (myConfig.iQuickInfoType == MY_APPLET_TIME_ELAPSED || myConfig.iQuickInfoType == MY_APPLET_TIME_LEFT)))) // il y'a de l'acquisition de donnees periodique a faire.
217 {
218 if (!gldi_task_is_active (myData.pTask))
219 gldi_task_launch (myData.pTask);
220 }
221 }
222
223 /* Arrete le backend en nettoyant la memoire
224 */
225 void cd_musicplayer_stop_current_handler (gboolean bStopWatching)
226 {
227 if (myData.pCurrentHandler == NULL)
228 return ;
229 cd_debug ("MP : stopping %s", myData.pCurrentHandler->name);
230
231 // cancel any detection or watching of the current handler.
232 if (myData.pDetectPlayerCall != NULL)
233 {
234 dbus_g_proxy_cancel_call (cairo_dock_get_main_proxy (), myData.pDetectPlayerCall);
235 myData.pDetectPlayerCall = NULL;
236 }
237 if (myData.pGetPropsCall)
238 {
239 dbus_g_proxy_cancel_call (cairo_dock_get_main_proxy (), myData.pGetPropsCall);
240 myData.pGetPropsCall = NULL;
241 }
242
243 if (bStopWatching)
244 {
245 cairo_dock_stop_watching_dbus_name_owner (myData.pCurrentHandler->cMprisService, (CairoDockDbusNameOwnerChangedFunc)_on_name_owner_changed);
246 if (myData.cMpris2Service != NULL) // can be null if we already got the MPRIS2 handler.
247 {
248 cairo_dock_stop_watching_dbus_name_owner (myData.cMpris2Service, (CairoDockDbusNameOwnerChangedFunc)_on_name_owner_changed);
249 g_free (myData.cMpris2Service);
250 myData.cMpris2Service = NULL;
251 }
252 }
253
254 // stop whatever the handler was doing internally.
255 if (myData.pCurrentHandler->stop != NULL)
256 myData.pCurrentHandler->stop();
257
258 // disconnect from the bus, stop all signals/task
259 cd_musicplayer_dbus_disconnect_from_bus ();
260
261 gldi_task_free (myData.pTask);
262 myData.pTask = NULL;
263
264 // return to initial state.
265 myData.bIsRunning = FALSE;
266 myData.iPlayingStatus = PLAYER_NONE;
267 myData.iCurrentTime = 0;
268 myData.iGetTimeFailed = 0;
269 CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
270 }
271
272
273 void cd_musicplayer_register_my_handler (MusicPlayerHandler *pHandler)
274 {
275 if (cd_musicplayer_get_handler_by_name (pHandler->name) != NULL) // un peu paranoiaque...
276 {
277 cd_warning ("MP : Handler %s already listed", pHandler->name);
278 return ;
279 }
280
281 myData.pHandlers = g_list_prepend (myData.pHandlers, pHandler);
282 }
283
284
285 /* Detruit un backend
286 */
287 void cd_musicplayer_free_handler (MusicPlayerHandler *pHandler)
288 {
289 if (pHandler == NULL)
290 return ;
291
292 g_free (pHandler->cCoverDir);
293 g_free (pHandler);
294 }
295
296 static void _on_got_desktop_entry (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer data)
297 {
298 CD_APPLET_ENTER;
299 myData.pGetPropsCall = NULL;
300
301 GValue v = G_VALUE_INIT;
302 GError *error = NULL;
303 gboolean bSuccess = dbus_g_proxy_end_call (proxy,
304 call_id,
305 &error,
306 G_TYPE_VALUE,
307 &v,
308 G_TYPE_INVALID);
309 if (error)
310 {
311 cd_warning ("%s", error->message);
312 g_error_free (error);
313 }
314 if (bSuccess && G_VALUE_HOLDS_STRING (&v))
315 {
316 const gchar *cDesktopFileName = g_value_get_string (&v);
317 cd_debug (" got desktop-entry '%s' (was '%s') from the service '%s'", cDesktopFileName, myConfig.cLastKnownDesktopFile, myData.pCurrentHandler->cMprisService);
318
319 if (cDesktopFileName != NULL)
320 {
321 if (myConfig.cLastKnownDesktopFile == NULL || strcmp (cDesktopFileName, myConfig.cLastKnownDesktopFile) != 0) // the property has changed from the previous time.
322 {
323 gchar *cAppClass = cairo_dock_register_class (cDesktopFileName); // no need to be freed here
324 cd_debug (" desktop-entry has changed, update => Class: %s", cAppClass);
325 if (cAppClass != NULL) // maybe the application has given a wrong cAppClass... Amarok? :)
326 {
327 // store the desktop filename, since we can't have it until the service is up, the next time the applet is started, which means we wouldn't be able to launch the player.
328 cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE,
329 G_TYPE_STRING, "Configuration", "desktop-entry", cDesktopFileName,
330 G_TYPE_INVALID);
331 g_free (myConfig.cLastKnownDesktopFile);
332 myConfig.cLastKnownDesktopFile = g_strdup (cDesktopFileName);
333
334 // register the desktop file, and get the common properties of this class.
335 _fill_handler_properties (cDesktopFileName, cAppClass);
336
337 if (myData.pCurrentHandler->appclass != NULL)
338 {
339 cairo_dock_set_data_from_class (myData.pCurrentHandler->appclass, myIcon);
340 }
341
342 if (myConfig.bStealTaskBarIcon)
343 CD_APPLET_MANAGE_APPLICATION (myData.pCurrentHandler->appclass);
344 }
345 else
346 cd_warning ("Wrong .desktop file name: %s", cDesktopFileName);
347 }
348 }
349 g_value_unset (&v);
350 }
351 CD_APPLET_LEAVE ();
352 }
353 static void _on_name_owner_changed (const gchar *cName, gboolean bOwned, gpointer data)
354 {
355 CD_APPLET_ENTER;
356 cd_debug ("%s (%s, %d)", __func__, cName, bOwned);
357
358 // launch or stop the handler.
359 if (bOwned)
360 {
361 if (strncmp (cName, CD_MPRIS2_SERVICE_BASE, strlen (CD_MPRIS2_SERVICE_BASE)) == 0) // the MPRIS2 service is now on the bus, it has priority.
362 {
363 cd_debug ("the MPRIS2 service is now on the bus, it has priority");
364 // set the MPRIS2 handler as the current one if not already the case.
365 if (strcmp (myData.pCurrentHandler->name, "Mpris2") != 0) // the current handler is not the MPRIS2 one, stop it and use the latter instead.
366 {
367 cd_debug ("our current handler is not the MPRIS2 one, stop it and use the latter instead");
368 // stop the old handler
369 if (myData.cMpris2Service != cName)
370 g_free (myData.cMpris2Service);
371 myData.cMpris2Service = NULL; // we're already watching it, don't re-watch (we can't unwatch ourselves in the callback, plus it's a waste of CPU).
372
373 cd_musicplayer_stop_current_handler (TRUE); // so once we detect the MPRIS2 service on the bus, the other one is dropped forever.
374
375 // set the MPRIS2 handler as the current one
376 myData.pCurrentHandler = cd_musicplayer_get_handler_by_name ("Mpris2"); // no need to watch it, it was already done (that's why we are here !)
377
378 // fill its properties
379 gchar *cAppClass = NULL, *cDesktopFileName = NULL;
380 _get_right_class_and_desktop_file (cName, &cDesktopFileName, &cAppClass);
381 if (cAppClass) // better to not use any class than a wrong class
382 _fill_handler_properties (cDesktopFileName, cAppClass);
383
384 g_free ((gchar*)myData.pCurrentHandler->cMprisService);
385 myData.pCurrentHandler->cMprisService = g_strdup (cName);
386 }
387 // get the desktop properties of the player.
388 // we do it now that the service is on the bus, because we can't guess them for sure from the MPRIS service name only (ex.: Rhythmbox has "org.mpris.MediaPlayer2.rhythmbox3" but its class is "rhythmbox").
389 DBusGProxy *pProxyProp = cairo_dock_create_new_session_proxy (
390 myData.pCurrentHandler->cMprisService,
391 CD_MPRIS2_OBJ,
392 DBUS_INTERFACE_PROPERTIES);
393 if (myData.pGetPropsCall)
394 dbus_g_proxy_cancel_call (cairo_dock_get_main_proxy (), myData.pGetPropsCall);
395 myData.pGetPropsCall = dbus_g_proxy_begin_call (pProxyProp, "Get",
396 (DBusGProxyCallNotify)_on_got_desktop_entry,
397 myApplet,
398 (GDestroyNotify) NULL,
399 G_TYPE_STRING, CD_MPRIS2_MAIN_IFACE,
400 G_TYPE_STRING, "DesktopEntry",
401 G_TYPE_INVALID);
402 }
403 else // it's not the MPRIS2 service, ignore it if we already have the MPRIS2 service (shouldn't happen though).
404 {
405 if (strcmp (myData.pCurrentHandler->name, "Mpris2") == 0)
406 {
407 cd_debug ("it's not the MPRIS2 service, ignore it since we already have the MPRIS2 service");
408 CD_APPLET_LEAVE ();
409 }
410 }
411
412 cd_musicplayer_launch_handler ();
413 }
414 else // else stop the handler.
415 {
416 cd_debug ("stop the handler {%s, %s}", myData.pCurrentHandler->name, myData.pCurrentHandler->launch);
417 cd_musicplayer_stop_current_handler (FALSE); // FALSE = keep watching it.
418 cd_musicplayer_apply_status_surface (PLAYER_NONE);
419 if (myConfig.cDefaultTitle != NULL)
420 {
421 CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.cDefaultTitle);
422 }
423 else
424 {
425 if (strcmp (myData.pCurrentHandler->name, "Mpris2") == 0)
426 {
427 gchar *cDefaultName = cd_musicplayer_get_string_with_first_char_to_upper (myData.pCurrentHandler->launch);
428 CD_APPLET_SET_NAME_FOR_MY_ICON (cDefaultName);
429 g_free (cDefaultName);
430 }
431 else
432 {
433 CD_APPLET_SET_NAME_FOR_MY_ICON (myData.pCurrentHandler->name);
434 }
435 cd_debug ("stopped {%s, %s}", myData.pCurrentHandler->name, myData.pCurrentHandler->launch);
436 }
437 }
438 CD_APPLET_LEAVE ();
439 }
440
441 static void _on_detect_handler (gboolean bPresent, gpointer data)
442 {
443 CD_APPLET_ENTER;
444 myData.pDetectPlayerCall = NULL;
445 cd_debug ("%s presence on the bus: %d", myData.pCurrentHandler->cMprisService, bPresent);
446 if (bPresent)
447 {
448 _on_name_owner_changed (myData.pCurrentHandler->cMprisService, bPresent, data);
449 }
450 CD_APPLET_LEAVE ();
451 }
452
453 static void _on_detect_mpris2 (gboolean bPresent, gpointer data)
454 {
455 CD_APPLET_ENTER;
456 myData.pDetectPlayerCall = NULL;
457 cd_debug ("MPRIS2 presence on the bus: %d", bPresent);
458 if (bPresent)
459 _on_name_owner_changed (myData.cMpris2Service, bPresent, data);
460 else if (myData.pCurrentHandler->cMprisService != NULL) // couldn't detect it, but it has another service, so try this one.
461 myData.pDetectPlayerCall = cairo_dock_dbus_detect_application_async (myData.pCurrentHandler->cMprisService, (CairoDockOnAppliPresentOnDbus) _on_detect_handler, NULL);
462 CD_APPLET_LEAVE ();
463 }
464
465 /**
466 Set the current handler from its name.
467 It can be either the name of an old handler, or the name of an MPRIS2 service.
468 - if an old handler matches the name, use it, and detect it on the bus; also detect an MPRIS2 with the same name
469 - if no handler matches, then it's an MPRIS2 service; set the MPRIS2 handler as the current one, and detect it on the bus.
470 */
471 void cd_musicplayer_set_current_handler (const gchar *cName)
472 {
473 cd_debug ("%s (%s)", __func__, cName);
474 // stop completely any previous handler
475 cd_musicplayer_stop_current_handler (TRUE);
476
477 // if no handler is defined, go to a neutral state.
478 if (cName == NULL)
479 {
480 myData.pCurrentHandler = NULL;
481 cd_musicplayer_apply_status_surface (PLAYER_NONE);
482 if (myConfig.cDefaultTitle == NULL)
483 CD_APPLET_SET_NAME_FOR_MY_ICON (myApplet->pModule->pVisitCard->cTitle);
484 return;
485 }
486
487 // find a handler from the given name
488 myData.pCurrentHandler = cd_musicplayer_get_handler_by_name (cName);
489
490 if (myData.pCurrentHandler != NULL) // an old handler exist with this name, use it but also look for the associated MPRIS2 service.
491 {
492 myData.cMpris2Service = myData.pCurrentHandler->cMpris2Service ? g_strdup (myData.pCurrentHandler->cMpris2Service) : g_strdup_printf (CD_MPRIS2_SERVICE_BASE".%s", cName);
493 cd_debug ("We check this MPRIS2 service: %s", myData.cMpris2Service);
494
495 cairo_dock_watch_dbus_name_owner (myData.cMpris2Service, (CairoDockDbusNameOwnerChangedFunc) _on_name_owner_changed, NULL);
496
497 myData.pDetectPlayerCall = cairo_dock_dbus_detect_application_async (myData.cMpris2Service, (CairoDockOnAppliPresentOnDbus) _on_detect_mpris2, NULL); // mpris2 first, and then the other one.
498 }
499 else // no such handler, make an MPRIS2 service with this name.
500 {
501 // get the MPRIS2 handler
502 myData.pCurrentHandler = cd_musicplayer_get_handler_by_name ("Mpris2");
503
504 gchar *cAppClass = NULL, *cDesktopFileName = NULL;
505 _get_right_class_and_desktop_file (cName, &cDesktopFileName, &cAppClass);
506 if (cAppClass) // better to not use any class than a wrong class
507 _fill_handler_properties (cDesktopFileName, cAppClass);
508
509 myData.pCurrentHandler->cMprisService = g_strdup_printf (CD_MPRIS2_SERVICE_BASE".%s", cName);
510 myData.cMpris2Service = NULL;
511 }
512
513 // watch it on the bus.
514 if (myData.pCurrentHandler->cMprisService != NULL) // paranoia
515 {
516 cairo_dock_watch_dbus_name_owner (myData.pCurrentHandler->cMprisService, (CairoDockDbusNameOwnerChangedFunc) _on_name_owner_changed, NULL);
517
518 // detect its presence on the bus.
519 if (myData.pDetectPlayerCall == NULL) // if we're already detecting MPRIS2, we'll detect this handler after we got the answer.
520 myData.pDetectPlayerCall = cairo_dock_dbus_detect_application_async (myData.pCurrentHandler->cMprisService, (CairoDockOnAppliPresentOnDbus) _on_detect_handler, NULL);
521 }
522
523 // set the current icon and label.
524 if (myData.pCurrentHandler->appclass != NULL)
525 {
526 cairo_dock_set_data_from_class (myData.pCurrentHandler->appclass, myIcon);
527 }
528
529 cd_musicplayer_apply_status_surface (PLAYER_NONE); // until we detect any service, consider it's not running.
530 if (myConfig.cDefaultTitle == NULL)
531 {
532 /**if (myIcon->cName != NULL)
533 {
534 CD_APPLET_SET_NAME_FOR_MY_ICON (myIcon->cName);
535 }
536 else */if (strcmp (myData.pCurrentHandler->name, "Mpris2") != 0)
537 {
538 CD_APPLET_SET_NAME_FOR_MY_ICON (myData.pCurrentHandler->name);
539 }
540 else
541 {
542 gchar *cDefaultName = cd_musicplayer_get_string_with_first_char_to_upper (myData.pCurrentHandler->launch);
543 CD_APPLET_SET_NAME_FOR_MY_ICON (cDefaultName);
544 g_free (cDefaultName);
545 }
546 }
547
548 // manage its taskbar icon.
549 if (myData.pCurrentHandler->appclass != NULL)
550 {
551 cairo_dock_set_data_from_class (myData.pCurrentHandler->appclass, myIcon);
552 }
553
554 if (myConfig.bStealTaskBarIcon)
555 CD_APPLET_MANAGE_APPLICATION (myData.pCurrentHandler->appclass);
556 }
557
558 gchar *cd_musicplayer_get_string_with_first_char_to_upper (const gchar *cName)
559 {
560 return (cName == NULL) ? NULL : g_strdup_printf ("%c%s", g_ascii_toupper (*cName), cName + 1);
561 }