2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
25
#include "cairo-dock-load.h"
26
#include "cairo-dock-draw.h"
27
#include "cairo-dock-config.h"
28
#include "cairo-dock-launcher-factory.h"
29
#include "cairo-dock-surface-factory.h"
30
#include "cairo-dock-animations.h"
31
#include "cairo-dock-themes-manager.h"
32
#include "cairo-dock-keyfile-utilities.h"
33
#include "cairo-dock-applet-factory.h"
34
#include "cairo-dock-log.h"
35
#include "cairo-dock-dock-factory.h"
36
#include "cairo-dock-callbacks.h"
37
#include "cairo-dock-dock-manager.h"
38
#include "cairo-dock-draw-opengl.h"
39
#include "cairo-dock-icons.h"
40
#include "cairo-dock-container.h"
41
#include "cairo-dock-gui-manager.h"
42
#include "cairo-dock-applet-facility.h"
44
extern gchar *g_cCurrentThemePath;
45
extern gchar *g_cCairoDockDataDir;
46
extern gchar *g_cConfFile;
47
extern CairoDockImageBuffer g_pIconBackgroundBuffer;
48
///extern cairo_surface_t *g_pIconBackgroundImageSurface;
49
///extern double g_iIconBackgroundImageWidth, g_iIconBackgroundImageHeight;
51
extern gboolean g_bUseOpenGL;
54
void cairo_dock_set_icon_surface_full (cairo_t *pIconContext, cairo_surface_t *pSurface, double fScale, double fAlpha, Icon *pIcon, CairoContainer *pContainer)
56
g_return_if_fail (cairo_status (pIconContext) == CAIRO_STATUS_SUCCESS);
58
//\________________ On efface l'ancienne image.
59
cairo_dock_erase_cairo_context (pIconContext);
61
//\________________ On met le background de l'icone si necessaire
63
pIcon->pIconBuffer != NULL &&
64
g_pIconBackgroundBuffer.pSurface != NULL &&
65
(! CAIRO_DOCK_IS_SEPARATOR (pIcon)/* && (myIcons.bBgForApplets || ! CAIRO_DOCK_IS_APPLET(pIcon))*/))
67
cd_message (">>> %s prendra un fond d'icone", pIcon->cName);
69
cairo_save (pIconContext);
71
cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
72
cairo_scale(pIconContext,
73
iWidth / g_pIconBackgroundBuffer.iWidth,
74
iHeight / g_pIconBackgroundBuffer.iHeight);
75
cairo_set_source_surface (pIconContext,
76
g_pIconBackgroundBuffer.pSurface,
79
cairo_set_operator (pIconContext, CAIRO_OPERATOR_DEST_OVER);
80
cairo_paint (pIconContext);
81
cairo_restore (pIconContext);
84
//\________________ On applique la nouvelle image.
85
if (pSurface != NULL && fScale > 0)
87
cairo_save (pIconContext);
88
if (fScale != 1 && pIcon != NULL)
91
cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
92
cairo_translate (pIconContext, .5 * iWidth * (1 - fScale) , .5 * iHeight * (1 - fScale));
93
cairo_scale (pIconContext, fScale, fScale);
96
cairo_set_source_surface (
103
cairo_paint_with_alpha (pIconContext, fAlpha);
105
cairo_paint (pIconContext);
106
cairo_restore (pIconContext);
109
cairo_dock_update_icon_texture (pIcon);
113
void cairo_dock_set_icon_surface_with_reflect (cairo_t *pIconContext, cairo_surface_t *pSurface, Icon *pIcon, CairoContainer *pContainer)
115
cairo_dock_set_icon_surface_full (pIconContext, pSurface, 1., 1., pIcon, pContainer);
117
cairo_dock_add_reflection_to_icon (pIconContext, pIcon, pContainer);
120
void cairo_dock_set_image_on_icon (cairo_t *pIconContext, const gchar *cImagePath, Icon *pIcon, CairoContainer *pContainer)
122
if (cImagePath != pIcon->cFileName)
124
g_free (pIcon->cFileName);
125
pIcon->cFileName = g_strdup (cImagePath);
128
cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
129
cairo_surface_t *pImageSurface = cairo_dock_create_surface_for_icon (cImagePath,
134
cairo_dock_set_icon_surface_with_reflect (pIconContext, pImageSurface, pIcon, pContainer);
136
cairo_surface_destroy (pImageSurface);
139
void cairo_dock_set_icon_surface_with_bar (cairo_t *pIconContext, cairo_surface_t *pSurface, double fValue, Icon *pIcon, CairoContainer *pContainer)
141
g_return_if_fail (cairo_status (pIconContext) == CAIRO_STATUS_SUCCESS);
143
//\________________ On efface l'ancienne image.
144
cairo_dock_erase_cairo_context (pIconContext);
146
//\________________ On applique la nouvelle image.
147
if (pSurface != NULL)
149
cairo_set_source_surface (
154
cairo_paint (pIconContext);
157
//\________________ On dessine la barre.
158
cairo_dock_draw_bar_on_icon (pIconContext, fValue, pIcon, pContainer);
161
cairo_dock_update_icon_texture (pIcon);
164
void cairo_dock_draw_bar_on_icon (cairo_t *pIconContext, double fValue, Icon *pIcon, CairoContainer *pContainer)
167
cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
169
cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (0.,
172
0.); // de gauche a droite.
173
g_return_if_fail (cairo_pattern_status (pGradationPattern) == CAIRO_STATUS_SUCCESS);
175
cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE);
176
cairo_pattern_add_color_stop_rgba (pGradationPattern,
177
(fValue >= 0 ? 0. : 1.),
182
cairo_pattern_add_color_stop_rgba (pGradationPattern,
183
(fValue >= 0 ? 1. : 0.),
189
cairo_save (pIconContext);
190
cairo_set_operator (pIconContext, CAIRO_OPERATOR_OVER);
192
cairo_set_line_width (pIconContext, 6);
193
cairo_set_line_cap (pIconContext, CAIRO_LINE_CAP_ROUND);
195
cairo_move_to (pIconContext, 3, iHeight - 3);
196
cairo_rel_line_to (pIconContext, (iWidth - 6) * fabs (fValue), 0);
198
cairo_set_source (pIconContext, pGradationPattern);
199
cairo_stroke (pIconContext);
201
cairo_pattern_destroy (pGradationPattern);
202
cairo_restore (pIconContext);
205
void cairo_dock_set_hours_minutes_as_quick_info (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, int iTimeInSeconds)
207
int hours = iTimeInSeconds / 3600;
208
int minutes = (iTimeInSeconds % 3600) / 60;
210
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dh%02d", hours, abs (minutes));
212
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%dmn", minutes);
215
void cairo_dock_set_minutes_secondes_as_quick_info (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, int iTimeInSeconds)
217
int minutes = iTimeInSeconds / 60;
218
int secondes = iTimeInSeconds % 60;
219
cd_debug ("%s (%d:%d)\n", __func__, minutes, secondes);
221
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%d:%02d", minutes, abs (secondes));
223
cairo_dock_set_quick_info_full (pSourceContext, pIcon, pContainer, "%s0:%02d", (secondes < 0 ? "-" : ""), abs (secondes));
226
gchar *cairo_dock_get_human_readable_size (long long int iSizeInBytes)
229
if (iSizeInBytes >> 10 == 0)
231
return g_strdup_printf ("%dB", (int) iSizeInBytes);
233
else if (iSizeInBytes >> 20 == 0)
235
fValue = (double) (iSizeInBytes) / 1024.;
236
return g_strdup_printf (fValue < 10 ? "%.1fK" : "%.0fK", fValue);
238
else if (iSizeInBytes >> 30 == 0)
240
fValue = (double) (iSizeInBytes >> 10) / 1024.;
241
return g_strdup_printf (fValue < 10 ? "%.1fM" : "%.0fM", fValue);
243
else if (iSizeInBytes >> 40 == 0)
245
fValue = (double) (iSizeInBytes >> 20) / 1024.;
246
return g_strdup_printf (fValue < 10 ? "%.1fG" : "%.0fG", fValue);
250
fValue = (double) (iSizeInBytes >> 30) / 1024.;
251
return g_strdup_printf (fValue < 10 ? "%.1fT" : "%.0fT", fValue);
255
void cairo_dock_set_size_as_quick_info (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer, long long int iSizeInBytes)
257
gchar *cSize = cairo_dock_get_human_readable_size (iSizeInBytes);
258
cairo_dock_set_quick_info (pSourceContext, pIcon, pContainer, cSize);
264
gchar *cairo_dock_get_theme_path_for_module (const gchar *cAppletConfFilePath, GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, const gchar *cDefaultThemeName, const gchar *cShareThemesDir, const gchar *cExtraDirName)
266
gchar *cThemeName = cairo_dock_get_string_key_value (pKeyFile, cGroupName, cKeyName, bFlushConfFileNeeded, cDefaultThemeName, NULL, NULL);
268
gchar *cUserThemesDir = (cExtraDirName != NULL ? g_strdup_printf ("%s/%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_EXTRAS_DIR, cExtraDirName) : NULL);
269
CairoDockThemeType iType = cairo_dock_extract_theme_type_from_name (cThemeName);
270
gchar *cThemePath = cairo_dock_get_theme_path (cThemeName, cShareThemesDir, cUserThemesDir, cExtraDirName, iType);
272
if (iType != CAIRO_DOCK_ANY_THEME)
274
g_key_file_set_string (pKeyFile, cGroupName, cKeyName, cThemeName);
275
cairo_dock_write_keys_to_file (pKeyFile, cAppletConfFilePath);
278
g_free (cUserThemesDir);
283
GtkWidget *cairo_dock_create_sub_menu (const gchar *cLabel, GtkWidget *pMenu, const gchar *cImage)
285
GtkWidget *pMenuItem, *image, *pSubMenu = gtk_menu_new ();
288
pMenuItem = gtk_menu_item_new_with_label (cLabel);
292
pMenuItem = gtk_image_menu_item_new_with_label (cLabel);
295
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size (cImage, 24, 24, NULL);
296
image = gtk_image_new_from_pixbuf (pixbuf);
297
g_object_unref (pixbuf);
301
image = gtk_image_new_from_stock (cImage, GTK_ICON_SIZE_MENU);
303
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (pMenuItem), image);
305
gtk_menu_shell_append (GTK_MENU_SHELL (pMenu), pMenuItem);
306
gtk_menu_item_set_submenu (GTK_MENU_ITEM (pMenuItem), pSubMenu);
312
//Utile pour jouer des fichiers son depuis le dock.
313
//A utiliser avec l'Objet UI 'u' dans les .conf
314
void cairo_dock_play_sound (const gchar *cSoundPath)
316
cd_debug ("%s (%s)", __func__, cSoundPath);
317
if (cSoundPath == NULL)
319
cd_warning ("No sound to play, halt.");
323
GError *erreur = NULL;
324
gchar *cSoundCommand = NULL;
325
if (g_file_test ("/usr/bin/play", G_FILE_TEST_EXISTS))
326
cSoundCommand = g_strdup_printf("play \"%s\"", cSoundPath);
328
else if (g_file_test ("/usr/bin/aplay", G_FILE_TEST_EXISTS))
329
cSoundCommand = g_strdup_printf("aplay \"%s\"", cSoundPath);
331
else if (g_file_test ("/usr/bin/paplay", G_FILE_TEST_EXISTS))
332
cSoundCommand = g_strdup_printf("paplay \"%s\"", cSoundPath);
334
cairo_dock_launch_command (cSoundCommand);
336
g_free (cSoundCommand);
339
void cairo_dock_get_gnome_version (int *iMajor, int *iMinor, int *iMicro) {
340
gchar *cContent = NULL;
342
GError *erreur = NULL;
343
g_file_get_contents ("/usr/share/gnome-about/gnome-version.xml", &cContent, &length, &erreur);
345
if (erreur != NULL) {
346
cd_warning (erreur->message);
347
g_error_free (erreur);
355
gchar **cLineList = g_strsplit (cContent, "\n", -1);
356
gchar *cOneLine = NULL, *cMajor = NULL, *cMinor = NULL, *cMicro = NULL;
357
int i, iMaj = 0, iMin = 0, iMic = 0;
358
for (i = 0; cLineList[i] != NULL; i ++) {
359
cOneLine = cLineList[i];
360
if (*cOneLine == '\0')
364
cMajor = g_strstr_len (cOneLine, -1, "<platform>"); //<platform>2</platform>
365
if (cMajor != NULL) {
366
cMajor += 10; //On saute <platform>
367
gchar *str = strchr (cMajor, '<');
369
*str = '\0'; //On bloque a </platform>
370
iMaj = atoi (cMajor);
372
else { //Gutsy xml's doesn't have <platform> but <major>
373
cMajor = g_strstr_len (cOneLine, -1, "<major>"); //<major>2</major>
374
if (cMajor != NULL) {
375
cMajor += 7; //On saute <major>
376
gchar *str = strchr (cMajor, '<');
378
*str = '\0'; //On bloque a </major>
379
iMaj = atoi (cMajor);
384
cMinor = g_strstr_len (cOneLine, -1, "<minor>"); //<minor>22</minor>
385
if (cMinor != NULL) {
386
cMinor += 7; //On saute <minor>
387
gchar *str = strchr (cMinor, '<');
389
*str = '\0'; //On bloque a </minor>
390
iMin = atoi (cMinor);
394
cMicro = g_strstr_len (cOneLine, -1, "<micro>"); //<micro>3</micro>
395
if (cMicro != NULL) {
396
cMicro += 7; //On saute <micro>
397
gchar *str = strchr (cMicro, '<');
399
*str = '\0'; //On bloque a </micro>
400
iMic = atoi (cMicro);
403
if (iMaj != 0 && iMin != 0 && iMic != 0)
404
break; //On s'enfou du reste
407
cd_debug ("Gnome Version %d.%d.%d", iMaj, iMin, iMic);
414
g_strfreev (cLineList);
417
void cairo_dock_pop_up_about_applet (GtkMenuItem *menu_item, CairoDockModuleInstance *pModuleInstance)
419
cairo_dock_popup_module_instance_description (pModuleInstance);
423
void cairo_dock_open_module_config_on_demand (int iClickedButton, GtkWidget *pInteractiveWidget, CairoDockModuleInstance *pModuleInstance, CairoDialog *pDialog)
425
if (iClickedButton == 0 || iClickedButton == -1) // bouton OK ou touche Entree.
427
/**cairo_dock_build_main_ihm (g_cConfFile, FALSE);
428
cairo_dock_present_module_instance_gui (pModuleInstance);*/
429
cairo_dock_show_module_instance_gui (pModuleInstance, -1);