1
/******************************************************************************
3
This file is a part of the cairo-dock program,
4
released under the terms of the GNU General Public License.
6
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
8
******************************************************************************/
14
#include "cairo-dock-load.h"
15
#include "cairo-dock-draw.h"
16
#include "cairo-dock-config.h"
17
#include "cairo-dock-launcher-factory.h"
18
#include "cairo-dock-surface-factory.h"
19
#include "cairo-dock-animations.h"
20
#include "cairo-dock-themes-manager.h"
21
#include "cairo-dock-keyfile-utilities.h"
22
#include "cairo-dock-applet-factory.h"
23
#include "cairo-dock-log.h"
24
#include "cairo-dock-dock-factory.h"
25
#include "cairo-dock-callbacks.h"
26
#include "cairo-dock-dock-manager.h"
27
#include "cairo-dock-draw-opengl.h"
28
#include "cairo-dock-applet-facility.h"
30
extern gchar *g_cCurrentThemePath;
31
extern gchar *g_cCairoDockDataDir;
33
extern double g_fAmplitude;
34
extern double g_fAlbedo;
36
extern CairoDockLabelDescription g_iconTextDescription;
37
extern CairoDockLabelDescription g_quickInfoTextDescription;
38
extern gboolean g_bTextAlwaysHorizontal;
41
void cairo_dock_set_icon_surface_full (cairo_t *pIconContext, cairo_surface_t *pSurface, double fScale, double fAlpha, Icon *pIcon, CairoContainer *pContainer)
43
g_return_if_fail (cairo_status (pIconContext) == CAIRO_STATUS_SUCCESS);
45
//\________________ On efface l'ancienne image.
46
cairo_set_source_rgba (pIconContext, 0.0, 0.0, 0.0, 0.0);
47
cairo_set_operator (pIconContext, CAIRO_OPERATOR_SOURCE);
48
cairo_paint (pIconContext);
49
cairo_set_operator (pIconContext, CAIRO_OPERATOR_OVER);
51
//\________________ On applique la nouvelle image.
52
if (pSurface != NULL && fScale > 0)
54
cairo_save (pIconContext);
55
if (fScale != 1 && pIcon != NULL)
57
double fMaxScale = cairo_dock_get_max_scale (pContainer);
58
cairo_translate (pIconContext, pIcon->fWidth * fMaxScale / 2 * (1 - fScale) , pIcon->fHeight * fMaxScale / 2 * (1 - fScale));
59
cairo_scale (pIconContext, fScale, fScale);
62
cairo_set_source_surface (
69
cairo_paint_with_alpha (pIconContext, fAlpha);
71
cairo_paint (pIconContext);
72
cairo_restore (pIconContext);
74
cairo_dock_update_icon_texture (pIcon);
77
void cairo_dock_add_reflection_to_icon (cairo_t *pIconContext, Icon *pIcon, CairoContainer *pContainer)
79
g_return_if_fail (pIcon != NULL && pContainer!= NULL);
80
if (pIcon->pReflectionBuffer != NULL)
82
cairo_surface_destroy (pIcon->pReflectionBuffer);
83
pIcon->pReflectionBuffer = NULL;
86
double fMaxScale = (CAIRO_DOCK_IS_DOCK (pContainer) ? (1 + g_fAmplitude) / CAIRO_DOCK (pContainer)->fRatio : 1);
87
gboolean bIsHorizontal = pContainer->bIsHorizontal;
88
pIcon->pReflectionBuffer = cairo_dock_create_reflection_surface (pIcon->pIconBuffer,
90
(bIsHorizontal ? pIcon->fWidth : pIcon->fHeight) * fMaxScale,
91
(bIsHorizontal ? pIcon->fHeight : pIcon->fWidth) * fMaxScale,
94
pContainer->bDirectionUp);
96
if (pIcon->pFullIconBuffer != NULL)
98
cairo_surface_destroy (pIcon->pFullIconBuffer);
99
pIcon->pFullIconBuffer = NULL;
101
pIcon->pFullIconBuffer = cairo_dock_create_icon_surface_with_reflection (pIcon->pIconBuffer,
102
pIcon->pReflectionBuffer,
104
(bIsHorizontal ? pIcon->fWidth : pIcon->fHeight) * fMaxScale,
105
(bIsHorizontal ? pIcon->fHeight : pIcon->fWidth) * fMaxScale,
108
pContainer->bDirectionUp);
111
void cairo_dock_set_icon_surface_with_reflect (cairo_t *pIconContext, cairo_surface_t *pSurface, Icon *pIcon, CairoContainer *pContainer)
113
cairo_dock_set_icon_surface (pIconContext, pSurface);
115
cairo_dock_add_reflection_to_icon (pIconContext, pIcon, pContainer);
118
void cairo_dock_set_image_on_icon (cairo_t *pIconContext, gchar *cImagePath, Icon *pIcon, CairoContainer *pContainer)
120
double fMaxScale = (CAIRO_DOCK_IS_DOCK (pContainer) ? (1 + g_fAmplitude) / CAIRO_DOCK (pContainer)->fRatio : 1);
121
cairo_surface_t *pImageSurface = cairo_dock_create_surface_for_icon (cImagePath,
123
pIcon->fWidth * fMaxScale,
124
pIcon->fHeight * fMaxScale);
126
cairo_dock_set_icon_surface_with_reflect (pIconContext, pImageSurface, pIcon, pContainer);
128
cairo_surface_destroy (pImageSurface);
131
void cairo_dock_draw_bar_on_icon (cairo_t *pIconContext, double fValue, Icon *pIcon, CairoContainer *pContainer)
133
double fMaxScale = (CAIRO_DOCK_IS_DOCK (pContainer) ? (1 + g_fAmplitude) / CAIRO_DOCK (pContainer)->fRatio : 1);
134
cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (0.,
136
pIcon->fWidth * fMaxScale,
137
0.); // de gauche a droite.
138
g_return_if_fail (cairo_pattern_status (pGradationPattern) == CAIRO_STATUS_SUCCESS);
140
cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE);
141
cairo_pattern_add_color_stop_rgba (pGradationPattern,
147
cairo_pattern_add_color_stop_rgba (pGradationPattern,
154
cairo_save (pIconContext);
155
cairo_set_operator (pIconContext, CAIRO_OPERATOR_OVER);
157
cairo_set_line_width (pIconContext, 6);
158
cairo_set_line_cap (pIconContext, CAIRO_LINE_CAP_ROUND);
160
cairo_move_to (pIconContext, 3, pIcon->fHeight * fMaxScale - 3);
161
cairo_rel_line_to (pIconContext, (pIcon->fWidth * fMaxScale - 6) * fValue, 0);
163
cairo_set_source (pIconContext, pGradationPattern);
164
cairo_stroke (pIconContext);
166
cairo_pattern_destroy (pGradationPattern);
167
cairo_restore (pIconContext);
170
void cairo_dock_set_icon_name (cairo_t *pSourceContext, const gchar *cIconName, Icon *pIcon, CairoContainer *pContainer) // fonction proposee par Necropotame.
172
g_return_if_fail (pIcon != NULL && pContainer != NULL); // le contexte sera verifie plus loin.
173
gchar *cUniqueName = NULL;
175
if (pIcon->pSubDock != NULL)
177
cUniqueName = cairo_dock_get_unique_dock_name (cIconName);
178
cIconName = cUniqueName;
179
cairo_dock_rename_dock (pIcon->acName, pIcon->pSubDock, cUniqueName);
182
if (pIcon->acName != cIconName)
184
g_free (pIcon->acName);
185
pIcon->acName = g_strdup (cIconName);
188
g_free (cUniqueName);
190
cairo_dock_fill_one_text_buffer(
193
&g_iconTextDescription,
194
(g_bTextAlwaysHorizontal ? CAIRO_DOCK_HORIZONTAL : pContainer->bIsHorizontal),
195
pContainer->bDirectionUp);
196
cairo_dock_update_label_texture (pIcon);
198
void cairo_dock_set_icon_name_full (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, const gchar *cIconNameFormat, ...)
201
va_start (args, cIconNameFormat);
202
gchar *cFullText = g_strdup_vprintf (cIconNameFormat, args);
203
cairo_dock_set_icon_name (pSourceContext, cFullText, pIcon, pContainer);
208
void cairo_dock_set_quick_info (cairo_t *pSourceContext, const gchar *cQuickInfo, Icon *pIcon, double fMaxScale)
210
g_return_if_fail (pIcon != NULL); // le contexte sera verifie plus loin.
212
if (pIcon->cQuickInfo != cQuickInfo)
214
g_free (pIcon->cQuickInfo);
215
pIcon->cQuickInfo = g_strdup (cQuickInfo);
218
cairo_dock_fill_one_quick_info_buffer (pIcon,
220
&g_quickInfoTextDescription,
222
cairo_dock_update_quick_info_texture (pIcon);
225
void cairo_dock_set_quick_info_full (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, const gchar *cQuickInfoFormat, ...)
228
va_start (args, cQuickInfoFormat);
229
gchar *cFullText = g_strdup_vprintf (cQuickInfoFormat, args);
230
cairo_dock_set_quick_info (pSourceContext, cFullText, pIcon, (CAIRO_DOCK_IS_DOCK (pContainer) ? (1 + g_fAmplitude) / 1 : 1));
235
void cairo_dock_set_hours_minutes_as_quick_info (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, int iTimeInSeconds)
237
int hours = iTimeInSeconds / 3600;
238
int minutes = (iTimeInSeconds % 3600) / 60;
240
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dh%02d", hours, abs (minutes));
242
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dmn", minutes);
245
void cairo_dock_set_minutes_secondes_as_quick_info (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, int iTimeInSeconds)
247
int minutes = iTimeInSeconds / 60;
248
int secondes = iTimeInSeconds % 60;
250
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%d:%02d", minutes, abs (secondes));
252
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%s0:%02d", (secondes < 0 ? "-" : ""), abs (secondes));
255
void cairo_dock_set_size_as_quick_info (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, long long int iSizeInBytes)
257
if (iSizeInBytes < 1024)
259
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dB", iSizeInBytes);
261
else if (iSizeInBytes < (1 << 20))
263
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dK", (int) (iSizeInBytes>>10));
265
else if (iSizeInBytes < (1 << 30))
267
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dM", (int) (iSizeInBytes>>20));
271
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dG", (int) (iSizeInBytes>>30));
275
void cairo_dock_animate_icon (Icon *pIcon, CairoDock *pDock, CairoDockAnimationType iAnimationType, int iNbRounds)
277
cairo_dock_arm_animation (pIcon, iAnimationType, iNbRounds);
278
cairo_dock_start_animation (pIcon, pDock);
282
gchar* cairo_dock_manage_themes_for_applet (gchar *cAppletShareDataDir, gchar *cThemeDirName, gchar *cAppletConfFilePath, GKeyFile *pKeyFile, gchar *cGroupName, gchar *cKeyName, gboolean *bFlushConfFileNeeded, gchar *cDefaultThemeName, const gchar *cExtraDirName)
284
GError *erreur = NULL;
285
gchar *cThemesDirPath = g_strdup_printf ("%s/%s", cAppletShareDataDir, cThemeDirName);
286
GHashTable *pThemeTable = cairo_dock_list_themes (cThemesDirPath, NULL, &erreur);
289
cd_warning (erreur->message);
290
g_error_free (erreur);
293
g_free (cThemesDirPath);
295
if (cExtraDirName != NULL)
297
cThemesDirPath = g_strdup_printf ("%s/%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_EXTRAS_DIR, cExtraDirName);
298
pThemeTable = cairo_dock_list_themes (cThemesDirPath, pThemeTable, NULL); // le repertoire peut ne pas exister, donc on ignore l'erreur.
299
g_free (cThemesDirPath);
302
gchar *cThemePath = NULL;
303
if (pThemeTable != NULL)
305
cairo_dock_update_conf_file_with_themes (pKeyFile, cAppletConfFilePath, pThemeTable, cGroupName, cKeyName);
307
gchar *cChosenThemeName = cairo_dock_get_string_key_value (pKeyFile, cGroupName, cKeyName, bFlushConfFileNeeded, cDefaultThemeName, NULL, NULL);
308
if (cChosenThemeName != NULL)
309
cThemePath = g_strdup (g_hash_table_lookup (pThemeTable, cChosenThemeName));
310
g_free (cChosenThemeName);
312
if (cThemePath == NULL && cDefaultThemeName != NULL)
313
cThemePath = g_strdup (g_hash_table_lookup (pThemeTable, cDefaultThemeName));
315
g_hash_table_destroy (pThemeTable);
320
GtkWidget *cairo_dock_create_sub_menu (gchar *cLabel, GtkWidget *pMenu)
322
GtkWidget *pSubMenu = gtk_menu_new ();
323
GtkWidget *pMenuItem = gtk_menu_item_new_with_label (cLabel);
324
gtk_menu_shell_append (GTK_MENU_SHELL (pMenu), pMenuItem);
325
gtk_menu_item_set_submenu (GTK_MENU_ITEM (pMenuItem), pSubMenu);
331
static gboolean _cairo_dock_timer (CairoDockMeasure *pMeasureTimer)
333
cairo_dock_launch_measure (pMeasureTimer);
336
static gpointer _cairo_dock_threaded_calculation (CairoDockMeasure *pMeasureTimer)
338
//cd_debug ("*** debut du thread (%d)", g_atomic_int_get (&pMeasureTimer->iThreadIsRunning));
339
if (pMeasureTimer->acquisition != NULL)
340
pMeasureTimer->acquisition (pMeasureTimer->pUserData);
342
g_mutex_lock (pMeasureTimer->pMutexData);
343
pMeasureTimer->read (pMeasureTimer->pUserData);
344
g_mutex_unlock (pMeasureTimer->pMutexData);
346
g_atomic_int_set (&pMeasureTimer->iThreadIsRunning, 0);
349
static gboolean _cairo_dock_check_for_redraw (CairoDockMeasure *pMeasureTimer)
351
int iThreadIsRunning = g_atomic_int_get (&pMeasureTimer->iThreadIsRunning);
352
//cd_debug ("%s (%d)", __func__, iThreadIsRunning);
353
if (! iThreadIsRunning)
355
//\_______________________ On recharge ce qu'il faut avec ces nouvelles donnees.
356
g_mutex_lock (pMeasureTimer->pMutexData);
357
gboolean bContinue = pMeasureTimer->update (pMeasureTimer->pUserData);
358
g_mutex_unlock (pMeasureTimer->pMutexData);
360
//\_______________________ On lance/arrete le timer si necessaire.
363
if (pMeasureTimer->iSidTimer != 0)
365
g_source_remove (pMeasureTimer->iSidTimer);
366
pMeasureTimer->iSidTimer = 0;
369
else if (pMeasureTimer->iSidTimer == 0 && pMeasureTimer->iCheckInterval != 0)
371
pMeasureTimer->iFrequencyState = CAIRO_DOCK_FREQUENCY_NORMAL;
372
pMeasureTimer->iSidTimer = g_timeout_add_seconds (pMeasureTimer->iCheckInterval, (GSourceFunc) _cairo_dock_timer, pMeasureTimer);
375
pMeasureTimer->iSidTimerRedraw = 0;
380
void cairo_dock_launch_measure (CairoDockMeasure *pMeasureTimer)
382
g_return_if_fail (pMeasureTimer != NULL);
383
if (pMeasureTimer->pMutexData == NULL)
385
if (pMeasureTimer->acquisition != NULL)
386
pMeasureTimer->acquisition (pMeasureTimer->pUserData);
387
if (pMeasureTimer->read != NULL)
388
pMeasureTimer->read (pMeasureTimer->pUserData);
389
gboolean bContinue = pMeasureTimer->update (pMeasureTimer->pUserData);
393
if (pMeasureTimer->iSidTimer != 0)
395
g_source_remove (pMeasureTimer->iSidTimer);
396
pMeasureTimer->iSidTimer = 0;
399
else if (pMeasureTimer->iSidTimer == 0 && pMeasureTimer->iCheckInterval != 0)
401
pMeasureTimer->iFrequencyState = CAIRO_DOCK_FREQUENCY_NORMAL;
402
pMeasureTimer->iSidTimer = g_timeout_add_seconds (pMeasureTimer->iCheckInterval, (GSourceFunc) _cairo_dock_timer, pMeasureTimer);
405
else if (g_atomic_int_compare_and_exchange (&pMeasureTimer->iThreadIsRunning, 0, 1)) // il etait egal a 0, on lui met 1 et on lance le thread.
407
//cd_debug (" ==> lancement du thread de calcul");
409
if (pMeasureTimer->iSidTimerRedraw == 0)
410
pMeasureTimer->iSidTimerRedraw = g_timeout_add (MAX (150, MIN (0.15 * pMeasureTimer->iCheckInterval, 333)), (GSourceFunc) _cairo_dock_check_for_redraw, pMeasureTimer);
412
GError *erreur = NULL;
413
GThread* pThread = g_thread_create ((GThreadFunc) _cairo_dock_threaded_calculation, pMeasureTimer, FALSE, &erreur);
416
cd_warning (erreur->message);
417
g_error_free (erreur);
420
else if (pMeasureTimer->iSidTimer == 0 && pMeasureTimer->iCheckInterval != 0)
422
pMeasureTimer->iFrequencyState = CAIRO_DOCK_FREQUENCY_NORMAL;
423
pMeasureTimer->iSidTimer = g_timeout_add_seconds (pMeasureTimer->iCheckInterval, (GSourceFunc) _cairo_dock_timer, pMeasureTimer);
427
static gboolean _cairo_dock_one_shot_timer (CairoDockMeasure *pMeasureTimer)
429
pMeasureTimer->iSidTimerRedraw = 0;
430
cairo_dock_launch_measure (pMeasureTimer);
433
void cairo_dock_launch_measure_delayed (CairoDockMeasure *pMeasureTimer, double fDelay)
435
pMeasureTimer->iSidTimerRedraw = g_timeout_add (fDelay, (GSourceFunc) _cairo_dock_one_shot_timer, pMeasureTimer);
438
CairoDockMeasure *cairo_dock_new_measure_timer (int iCheckInterval, CairoDockAquisitionTimerFunc acquisition, CairoDockReadTimerFunc read, CairoDockUpdateTimerFunc update, gpointer pUserData)
440
CairoDockMeasure *pMeasureTimer = g_new0 (CairoDockMeasure, 1);
441
if (read != NULL || acquisition != NULL)
442
pMeasureTimer->pMutexData = g_mutex_new ();
443
pMeasureTimer->iCheckInterval = iCheckInterval;
444
pMeasureTimer->acquisition = acquisition;
445
pMeasureTimer->read = read;
446
pMeasureTimer->update = update;
447
pMeasureTimer->pUserData = pUserData;
448
return pMeasureTimer;
451
static void _cairo_dock_pause_measure_timer (CairoDockMeasure *pMeasureTimer)
453
if (pMeasureTimer == NULL)
455
if (pMeasureTimer->iSidTimerRedraw != 0)
457
g_source_remove (pMeasureTimer->iSidTimerRedraw);
458
pMeasureTimer->iSidTimerRedraw = 0;
460
if (pMeasureTimer->iSidTimer!= 0)
462
g_source_remove (pMeasureTimer->iSidTimer);
463
pMeasureTimer->iSidTimer= 0;
467
void cairo_dock_stop_measure_timer (CairoDockMeasure *pMeasureTimer)
469
if (pMeasureTimer == NULL)
472
_cairo_dock_pause_measure_timer (pMeasureTimer);
474
cd_message ("***on attend que le thread termine...(%d)", g_atomic_int_get (&pMeasureTimer->iThreadIsRunning));
475
while (g_atomic_int_get (&pMeasureTimer->iThreadIsRunning))
477
gtk_main_iteration ();
478
cd_message ("***temine.");
481
void cairo_dock_free_measure_timer (CairoDockMeasure *pMeasureTimer)
483
if (pMeasureTimer == NULL)
485
cairo_dock_stop_measure_timer (pMeasureTimer);
487
if (pMeasureTimer->pMutexData != NULL)
488
g_mutex_free (pMeasureTimer->pMutexData);
489
g_free (pMeasureTimer);
492
gboolean cairo_dock_measure_is_active (CairoDockMeasure *pMeasureTimer)
494
return (pMeasureTimer != NULL && pMeasureTimer->iSidTimer != 0);
497
static void _cairo_dock_restart_timer_with_frequency (CairoDockMeasure *pMeasureTimer, int iNewCheckInterval)
499
gboolean bNeedsRestart = (pMeasureTimer->iSidTimer != 0);
500
_cairo_dock_pause_measure_timer (pMeasureTimer);
502
if (bNeedsRestart && iNewCheckInterval != 0)
503
pMeasureTimer->iSidTimer = g_timeout_add_seconds (iNewCheckInterval, (GSourceFunc) _cairo_dock_timer, pMeasureTimer);
506
void cairo_dock_change_measure_frequency (CairoDockMeasure *pMeasureTimer, int iNewCheckInterval)
508
g_return_if_fail (pMeasureTimer != NULL);
509
pMeasureTimer->iCheckInterval = iNewCheckInterval;
511
_cairo_dock_restart_timer_with_frequency (pMeasureTimer, iNewCheckInterval);
514
void cairo_dock_relaunch_measure_immediately (CairoDockMeasure *pMeasureTimer, int iNewCheckInterval)
516
cairo_dock_stop_measure_timer (pMeasureTimer); // on stoppe avant car on ne veut pas attendre la prochaine iteration.
517
cairo_dock_change_measure_frequency (pMeasureTimer, iNewCheckInterval); // nouvelle frequence eventuelement.
518
cairo_dock_launch_measure (pMeasureTimer); // mesure immediate.
521
void cairo_dock_downgrade_frequency_state (CairoDockMeasure *pMeasureTimer)
523
if (pMeasureTimer->iFrequencyState < CAIRO_DOCK_FREQUENCY_SLEEP)
525
pMeasureTimer->iFrequencyState ++;
526
int iNewCheckInterval;
527
switch (pMeasureTimer->iFrequencyState)
529
case CAIRO_DOCK_FREQUENCY_LOW :
530
iNewCheckInterval = 2 * pMeasureTimer->iCheckInterval;
532
case CAIRO_DOCK_FREQUENCY_VERY_LOW :
533
iNewCheckInterval = 4 * pMeasureTimer->iCheckInterval;
535
case CAIRO_DOCK_FREQUENCY_SLEEP :
536
iNewCheckInterval = 10 * pMeasureTimer->iCheckInterval;
538
default : // ne doit pas arriver.
539
iNewCheckInterval = pMeasureTimer->iCheckInterval;
543
cd_message ("degradation de la mesure (etat <- %d/%d)", pMeasureTimer->iFrequencyState, CAIRO_DOCK_NB_FREQUENCIES-1);
544
_cairo_dock_restart_timer_with_frequency (pMeasureTimer, iNewCheckInterval);
548
void cairo_dock_set_normal_frequency_state (CairoDockMeasure *pMeasureTimer)
550
if (pMeasureTimer->iFrequencyState != CAIRO_DOCK_FREQUENCY_NORMAL)
552
pMeasureTimer->iFrequencyState = CAIRO_DOCK_FREQUENCY_NORMAL;
553
_cairo_dock_restart_timer_with_frequency (pMeasureTimer, pMeasureTimer->iCheckInterval);
557
//Utile pour jouer des fichiers son depuis le dock.
558
//A utiliser avec l'Objet UI 'u' dans les .conf
559
void cairo_dock_play_sound (const gchar *cSoundPath)
561
cd_debug ("%s (%s)", __func__, cSoundPath);
562
if (cSoundPath == NULL)
564
cd_warning ("No sound to play, halt.");
568
GError *erreur = NULL;
569
gchar *cSoundCommand = NULL;
570
if (g_file_test ("/usr/bin/play", G_FILE_TEST_EXISTS))
571
cSoundCommand = g_strdup_printf("play \"%s\"", cSoundPath);
573
else if (g_file_test ("/usr/bin/aplay", G_FILE_TEST_EXISTS))
574
cSoundCommand = g_strdup_printf("aplay \"%s\"", cSoundPath);
576
else if (g_file_test ("/usr/bin/paplay", G_FILE_TEST_EXISTS))
577
cSoundCommand = g_strdup_printf("paplay \"%s\"", cSoundPath);
579
cairo_dock_launch_command (cSoundCommand);
581
g_free (cSoundCommand);
584
void cairo_dock_get_gnome_version (int *iMajor, int *iMinor, int *iMicro) {
585
gchar *cContent = NULL;
587
GError *erreur = NULL;
588
g_file_get_contents ("/usr/share/gnome-about/gnome-version.xml", &cContent, &length, &erreur);
590
if (erreur != NULL) {
591
cd_warning ("Attention : %s", erreur->message);
592
g_error_free (erreur);
600
gchar **cLineList = g_strsplit (cContent, "\n", -1);
601
gchar *cOneLine = NULL, *cMajor = NULL, *cMinor = NULL, *cMicro = NULL;
602
int i, iMaj = 0, iMin = 0, iMic = 0;
603
for (i = 0; cLineList[i] != NULL; i ++) {
604
cOneLine = cLineList[i];
605
if (*cOneLine == '\0')
609
cMajor = g_strstr_len (cOneLine, -1, "<platform>"); //<platform>2</platform>
610
if (cMajor != NULL) {
611
cMajor += 10; //On saute <platform>
612
gchar *str = strchr (cMajor, '<');
614
*str = '\0'; //On bloque a </platform>
615
iMaj = atoi (cMajor);
617
else { //Gutsy xml's doesn't have <platform> but <major>
618
cMajor = g_strstr_len (cOneLine, -1, "<major>"); //<major>2</major>
619
if (cMajor != NULL) {
620
cMajor += 7; //On saute <major>
621
gchar *str = strchr (cMajor, '<');
623
*str = '\0'; //On bloque a </major>
624
iMaj = atoi (cMajor);
629
cMinor = g_strstr_len (cOneLine, -1, "<minor>"); //<minor>22</minor>
630
if (cMinor != NULL) {
631
cMinor += 7; //On saute <minor>
632
gchar *str = strchr (cMinor, '<');
634
*str = '\0'; //On bloque a </minor>
635
iMin = atoi (cMinor);
639
cMicro = g_strstr_len (cOneLine, -1, "<micro>"); //<micro>3</micro>
640
if (cMicro != NULL) {
641
cMicro += 7; //On saute <micro>
642
gchar *str = strchr (cMicro, '<');
644
*str = '\0'; //On bloque a </micro>
645
iMic = atoi (cMicro);
648
if (iMaj != 0 && iMin != 0 && iMic != 0)
649
break; //On s'enfou du reste
652
cd_debug ("Gnome Version %d.%d.%d", iMaj, iMin, iMic);
659
g_strfreev (cLineList);