| 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 |
exemples : |
| 22 |
---------- |
| 23 |
|
| 24 |
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock/my_applet org.cairodock.CairoDock.applet.SetLabel string:new_label |
| 25 |
|
| 26 |
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock/demo org.cairodock.CairoDock.applet.AddDataRenderer string:gauge int32:2 string:Turbo-night-fuel |
| 27 |
|
| 28 |
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock/demo org.cairodock.CairoDock.applet.RenderValues array:double:.7,.2 |
| 29 |
|
| 30 |
******************************************************************************/ |
| 31 |
|
| 32 |
#include <math.h> |
| 33 |
#include <glib.h> |
| 34 |
#include <dbus/dbus-glib.h> |
| 35 |
#include <dbus/dbus-glib-bindings.h> |
| 36 |
|
| 37 |
#include "interface-applet-signals.h" |
| 38 |
#include "interface-applet-methods.h" |
| 39 |
|
| 40 |
static inline GldiModuleInstance *_get_module_instance_from_dbus_applet (dbusApplet *pDbusApplet) |
| 41 |
{ |
| 42 |
return pDbusApplet->pModuleInstance; |
| 43 |
} |
| 44 |
|
| 45 |
static inline gboolean _get_icon_and_container_from_id (dbusApplet *pDbusApplet, const gchar *cIconID, Icon **pIcon, GldiContainer **pContainer) |
| 46 |
{ |
| 47 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 48 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 49 |
|
| 50 |
if (cIconID == NULL) |
| 51 |
{ |
| 52 |
*pIcon = pInstance->pIcon; |
| 53 |
*pContainer = pInstance->pContainer; |
| 54 |
} |
| 55 |
else |
| 56 |
{ |
| 57 |
GList *piconsList = (pInstance->pDock ? (pInstance->pIcon->pSubDock ? pInstance->pIcon->pSubDock->icons : NULL) : pInstance->pDesklet->icons); |
| 58 |
*pIcon = cairo_dock_get_icon_with_command (piconsList, cIconID); |
| 59 |
*pContainer = (pInstance->pDesklet ? CAIRO_CONTAINER (pInstance->pDesklet) : CAIRO_CONTAINER (pInstance->pIcon->pSubDock)); |
| 60 |
} |
| 61 |
g_return_val_if_fail (pIcon != NULL && pContainer != NULL, FALSE); |
| 62 |
return TRUE; |
| 63 |
} |
| 64 |
|
| 65 |
static inline int _get_container_type (GldiContainer *pContainer) |
| 66 |
{ |
| 67 |
int iType = -1; |
| 68 |
|
| 69 |
if (CAIRO_DOCK_IS_DOCK (GLDI_OBJECT(pContainer))) |
| 70 |
return 0; |
| 71 |
if (CAIRO_DOCK_IS_DESKLET (pContainer)) |
| 72 |
return 1; |
| 73 |
if (CAIRO_DOCK_IS_DIALOG (pContainer)) |
| 74 |
return 2; |
| 75 |
if (CAIRO_DOCK_IS_FLYING_CONTAINER (pContainer)) |
| 76 |
return 3; |
| 77 |
|
| 78 |
return iType; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
static gboolean _applet_set_quick_info (dbusApplet *pDbusApplet, const gchar *cQuickInfo, const gchar *cIconID, GError **error) |
| 83 |
{ |
| 84 |
Icon *pIcon; |
| 85 |
GldiContainer *pContainer; |
| 86 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 87 |
return FALSE; |
| 88 |
|
| 89 |
gldi_icon_set_quick_info (pIcon, cQuickInfo && *cQuickInfo != '\0' ? cQuickInfo : NULL); |
| 90 |
cairo_dock_redraw_icon (pIcon); |
| 91 |
return TRUE; |
| 92 |
} |
| 93 |
|
| 94 |
static gboolean _applet_set_label (dbusApplet *pDbusApplet, const gchar *cLabel, const gchar *cIconID, GError **error) |
| 95 |
{ |
| 96 |
Icon *pIcon; |
| 97 |
GldiContainer *pContainer; |
| 98 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 99 |
return FALSE; |
| 100 |
|
| 101 |
gldi_icon_set_name (pIcon, cLabel); |
| 102 |
cairo_dock_redraw_icon (pIcon); /// needs a function to redraw the label... |
| 103 |
return TRUE; |
| 104 |
} |
| 105 |
|
| 106 |
static gboolean _applet_set_icon (dbusApplet *pDbusApplet, const gchar *cImage, const gchar *cIconID, GError **error) |
| 107 |
{ |
| 108 |
Icon *pIcon; |
| 109 |
GldiContainer *pContainer; |
| 110 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 111 |
return FALSE; |
| 112 |
|
| 113 |
g_return_val_if_fail (pIcon->image.pSurface != NULL, FALSE); |
| 114 |
cairo_t *pIconContext = cairo_create (pIcon->image.pSurface); |
| 115 |
cairo_dock_set_image_on_icon (pIconContext, cImage, pIcon, pContainer); |
| 116 |
cairo_destroy (pIconContext); |
| 117 |
cairo_dock_redraw_icon (pIcon); |
| 118 |
return TRUE; |
| 119 |
} |
| 120 |
|
| 121 |
/* Not used |
| 122 |
static gboolean _applet_set_icon_with_default (dbusApplet *pDbusApplet, const gchar **cImages, const gchar *cIconID, GError **error) |
| 123 |
{ |
| 124 |
Icon *pIcon; |
| 125 |
GldiContainer *pContainer; |
| 126 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 127 |
return FALSE; |
| 128 |
|
| 129 |
g_return_val_if_fail (pIcon->image.pSurface != NULL, FALSE); |
| 130 |
cairo_t *pIconContext = cairo_create (pIcon->image.pSurface); |
| 131 |
int i; |
| 132 |
for (i = 0; cImages[i] != NULL; i ++) |
| 133 |
{ |
| 134 |
|
| 135 |
///cairo_dock_set_image_on_icon (pIconContext, cImage, pIcon, pContainer); |
| 136 |
} |
| 137 |
cairo_destroy (pIconContext); |
| 138 |
cairo_dock_redraw_icon (pIcon); |
| 139 |
return TRUE; |
| 140 |
} |
| 141 |
*/ |
| 142 |
static gboolean _applet_set_emblem (dbusApplet *pDbusApplet, const gchar *cImage, gint iPosition, const gchar *cIconID, GError **error) |
| 143 |
{ |
| 144 |
Icon *pIcon; |
| 145 |
GldiContainer *pContainer; |
| 146 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 147 |
return FALSE; |
| 148 |
|
| 149 |
if (cImage == NULL || *cImage == '\0' || strcmp (cImage, "none") == 0) |
| 150 |
{ |
| 151 |
cairo_dock_remove_overlay_at_position (pIcon, iPosition < CAIRO_OVERLAY_NB_POSITIONS ? iPosition : iPosition - CAIRO_OVERLAY_NB_POSITIONS, myApplet); // for ease of use, handle both case similarily. |
| 152 |
} |
| 153 |
else |
| 154 |
{ |
| 155 |
if (iPosition >= CAIRO_OVERLAY_NB_POSITIONS) // [N; 2N-1] => print the overlay |
| 156 |
cairo_dock_print_overlay_on_icon_from_image (pIcon, cImage, iPosition - CAIRO_OVERLAY_NB_POSITIONS); |
| 157 |
else // [0, N-1] => add it |
| 158 |
cairo_dock_add_overlay_from_image (pIcon, cImage, iPosition, myApplet); // use 'myApplet' to identify the overlays set by the Dbus plug-in (since the plug-in can't be deactivated, 'myApplet' is constant). |
| 159 |
} |
| 160 |
|
| 161 |
cairo_dock_redraw_icon (pIcon); |
| 162 |
return TRUE; |
| 163 |
} |
| 164 |
|
| 165 |
static gboolean _applet_animate (dbusApplet *pDbusApplet, const gchar *cAnimation, gint iNbRounds, const gchar *cIconID, GError **error) |
| 166 |
{ |
| 167 |
Icon *pIcon; |
| 168 |
GldiContainer *pContainer; |
| 169 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 170 |
return FALSE; |
| 171 |
|
| 172 |
if (CAIRO_DOCK_IS_DOCK (pContainer) && cAnimation != NULL) |
| 173 |
{ |
| 174 |
gldi_icon_request_animation (pIcon, cAnimation, iNbRounds); |
| 175 |
return TRUE; |
| 176 |
} |
| 177 |
return FALSE; |
| 178 |
} |
| 179 |
|
| 180 |
static gboolean _applet_show_dialog (dbusApplet *pDbusApplet, const gchar *message, gint iDuration, const gchar *cIconID, GError **error) |
| 181 |
{ |
| 182 |
Icon *pIcon; |
| 183 |
GldiContainer *pContainer; |
| 184 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 185 |
return FALSE; |
| 186 |
|
| 187 |
// On empeche l'accumulation de dialogues informatifs. |
| 188 |
gldi_dialogs_remove_on_icon (pIcon); |
| 189 |
|
| 190 |
gldi_dialog_show_temporary_with_icon (message, pIcon, pContainer, 1000 * iDuration, "same icon"); |
| 191 |
return TRUE; |
| 192 |
} |
| 193 |
|
| 194 |
// deprecated |
| 195 |
static gboolean _applet_ask_question (dbusApplet *pDbusApplet, const gchar *cMessage, const gchar *cIconID, GError **error) |
| 196 |
{ |
| 197 |
Icon *pIcon; |
| 198 |
GldiContainer *pContainer; |
| 199 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 200 |
return FALSE; |
| 201 |
|
| 202 |
if (pDbusApplet->pDialog) // on n'autorise qu'un seul dialogue interactif a la fois. |
| 203 |
gldi_object_unref (GLDI_OBJECT(pDbusApplet->pDialog)); |
| 204 |
pDbusApplet->pDialog = gldi_dialog_show_with_question (cMessage, pIcon, pContainer, "same icon", (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_question, pDbusApplet, NULL); |
| 205 |
return TRUE; |
| 206 |
} |
| 207 |
|
| 208 |
static gboolean _applet_ask_value (dbusApplet *pDbusApplet, const gchar *cMessage, gdouble fInitialValue, gdouble fMaxValue, const gchar *cIconID, GError **error) |
| 209 |
{ |
| 210 |
Icon *pIcon; |
| 211 |
GldiContainer *pContainer; |
| 212 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 213 |
return FALSE; |
| 214 |
|
| 215 |
if (pDbusApplet->pDialog) // on n'autorise qu'un seul dialogue interactif a la fois. |
| 216 |
gldi_object_unref (GLDI_OBJECT(pDbusApplet->pDialog)); |
| 217 |
pDbusApplet->pDialog = gldi_dialog_show_with_value (cMessage, pIcon, pContainer, "same icon", fInitialValue, fMaxValue, (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_value, pDbusApplet, NULL); |
| 218 |
return TRUE; |
| 219 |
} |
| 220 |
|
| 221 |
static gboolean _applet_ask_text (dbusApplet *pDbusApplet, const gchar *cMessage, const gchar *cInitialText, const gchar *cIconID, GError **error) |
| 222 |
{ |
| 223 |
Icon *pIcon; |
| 224 |
GldiContainer *pContainer; |
| 225 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 226 |
return FALSE; |
| 227 |
|
| 228 |
if (pDbusApplet->pDialog) // on n'autorise qu'un seul dialogue interactif a la fois. |
| 229 |
gldi_object_unref (GLDI_OBJECT(pDbusApplet->pDialog)); |
| 230 |
pDbusApplet->pDialog = gldi_dialog_show_with_entry (cMessage, pIcon, pContainer, "same icon", cInitialText, (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_text, pDbusApplet, NULL); |
| 231 |
return TRUE; |
| 232 |
} |
| 233 |
// end of deprecated |
| 234 |
|
| 235 |
static void _on_text_changed (GtkWidget *pEntry, GtkWidget *pLabel) |
| 236 |
{ |
| 237 |
int iNbChars; |
| 238 |
if (GTK_IS_ENTRY (pEntry)) |
| 239 |
{ |
| 240 |
const gchar *cText = gtk_entry_get_text (GTK_ENTRY (pEntry)); |
| 241 |
iNbChars = (cText ? strlen (cText) : 0); |
| 242 |
} |
| 243 |
else |
| 244 |
{ |
| 245 |
GtkTextBuffer *pBuffer = GTK_TEXT_BUFFER (pEntry); |
| 246 |
iNbChars = gtk_text_buffer_get_char_count (pBuffer); |
| 247 |
} |
| 248 |
|
| 249 |
int iNbCharsMax = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (pEntry), "nb-chars-max")); |
| 250 |
|
| 251 |
gchar *cLabel; |
| 252 |
if (iNbChars < iNbCharsMax) |
| 253 |
cLabel = g_strdup_printf ("<b>%d</b>", iNbChars); |
| 254 |
else |
| 255 |
cLabel = g_strdup_printf ("<span color=\"red\"><b>%d</b></span>", iNbChars); |
| 256 |
gtk_label_set_markup (GTK_LABEL (pLabel), cLabel); |
| 257 |
gldi_dialog_set_widget_text_color (pLabel); |
| 258 |
g_free (cLabel); |
| 259 |
} |
| 260 |
static void _on_dialog_destroyed (dbusApplet *pDbusApplet) |
| 261 |
{ |
| 262 |
CD_APPLET_ENTER; |
| 263 |
pDbusApplet->pDialog = NULL; |
| 264 |
CD_APPLET_LEAVE(); |
| 265 |
} |
| 266 |
static gboolean _applet_popup_dialog (dbusApplet *pDbusApplet, GHashTable *hDialogAttributes, GHashTable *hWidgetAttributes, const gchar *cIconID, GError **error) |
| 267 |
{ |
| 268 |
g_return_val_if_fail (hDialogAttributes != NULL, FALSE); |
| 269 |
Icon *pIcon; |
| 270 |
GldiContainer *pContainer; |
| 271 |
if (! _get_icon_and_container_from_id (pDbusApplet, cIconID, &pIcon, &pContainer)) |
| 272 |
return FALSE; |
| 273 |
|
| 274 |
if (pDbusApplet->pDialog) // on n'autorise qu'un seul dialogue interactif a la fois. |
| 275 |
gldi_object_unref (GLDI_OBJECT(pDbusApplet->pDialog)); |
| 276 |
|
| 277 |
CairoDialogAttr attr; |
| 278 |
memset (&attr, 0, sizeof (CairoDialogAttr)); |
| 279 |
GValue *v; |
| 280 |
|
| 281 |
// attributs du dialogue. |
| 282 |
gchar *cImageFilePath = NULL; |
| 283 |
v = g_hash_table_lookup (hDialogAttributes, "icon"); |
| 284 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 285 |
{ |
| 286 |
int w, h; |
| 287 |
cairo_dock_get_icon_extent (pIcon, &w, &h); |
| 288 |
cImageFilePath = cairo_dock_search_icon_s_path (g_value_get_string (v), MAX (w, h)); |
| 289 |
attr.cImageFilePath = cImageFilePath; |
| 290 |
} |
| 291 |
else |
| 292 |
attr.cImageFilePath = "same icon"; |
| 293 |
|
| 294 |
v = g_hash_table_lookup (hDialogAttributes, "message"); |
| 295 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 296 |
attr.cText = g_value_get_string (v); |
| 297 |
|
| 298 |
v = g_hash_table_lookup (hDialogAttributes, "time-length"); |
| 299 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 300 |
attr.iTimeLength = 1000 * g_value_get_int (v); |
| 301 |
|
| 302 |
gchar **cButtonsImage = NULL; |
| 303 |
v = g_hash_table_lookup (hDialogAttributes, "buttons"); |
| 304 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 305 |
{ |
| 306 |
cButtonsImage = g_strsplit (g_value_get_string (v), ";", -1); // NULL-terminated |
| 307 |
attr.cButtonsImage = (const gchar **)cButtonsImage; |
| 308 |
} |
| 309 |
|
| 310 |
v = g_hash_table_lookup (hDialogAttributes, "force-above"); |
| 311 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 312 |
attr.bForceAbove = g_value_get_boolean (v); |
| 313 |
|
| 314 |
v = g_hash_table_lookup (hDialogAttributes, "use-markup"); |
| 315 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 316 |
attr.bUseMarkup = g_value_get_boolean (v); |
| 317 |
|
| 318 |
attr.pUserData = pDbusApplet; |
| 319 |
attr.pFreeDataFunc = (GFreeFunc)_on_dialog_destroyed; |
| 320 |
|
| 321 |
// attributs du widget interactif. |
| 322 |
GtkWidget *pInteractiveWidget = NULL, *pOneWidget = NULL; |
| 323 |
if (hWidgetAttributes != NULL) // un widget d'interaction est defini. |
| 324 |
{ |
| 325 |
v = g_hash_table_lookup (hWidgetAttributes, "widget-type"); |
| 326 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 327 |
{ |
| 328 |
const gchar *cType = g_value_get_string (v); |
| 329 |
if (cType) |
| 330 |
{ |
| 331 |
if (strcmp (cType, "text-entry") == 0) |
| 332 |
{ |
| 333 |
gboolean bMultiLines = FALSE; |
| 334 |
gboolean bEditable = TRUE; |
| 335 |
gboolean bVisible = TRUE; |
| 336 |
int iNbCharsMax = 0; |
| 337 |
const gchar *cInitialText = NULL; |
| 338 |
|
| 339 |
v = g_hash_table_lookup (hWidgetAttributes, "multi-lines"); |
| 340 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 341 |
bMultiLines = g_value_get_boolean (v); |
| 342 |
|
| 343 |
v = g_hash_table_lookup (hWidgetAttributes, "editable"); |
| 344 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 345 |
bEditable = g_value_get_boolean (v); |
| 346 |
|
| 347 |
v = g_hash_table_lookup (hWidgetAttributes, "visible"); |
| 348 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 349 |
bVisible = g_value_get_boolean (v); |
| 350 |
|
| 351 |
v = g_hash_table_lookup (hWidgetAttributes, "nb-chars"); |
| 352 |
if (v && G_VALUE_HOLDS_INT(v)) |
| 353 |
iNbCharsMax = g_value_get_int(v); |
| 354 |
|
| 355 |
v = g_hash_table_lookup (hWidgetAttributes, "initial-value"); |
| 356 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 357 |
cInitialText = g_value_get_string (v); |
| 358 |
|
| 359 |
if (bMultiLines) |
| 360 |
{ |
| 361 |
pOneWidget = gtk_text_view_new (); |
| 362 |
GtkWidget *pScrolledWindow = gtk_scrolled_window_new (NULL, NULL); |
| 363 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (pScrolledWindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
| 364 |
#if GTK_CHECK_VERSION (3, 8, 0) |
| 365 |
gtk_container_add (GTK_CONTAINER (pScrolledWindow), pOneWidget); |
| 366 |
#else |
| 367 |
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (pScrolledWindow), pOneWidget); |
| 368 |
#endif |
| 369 |
g_object_set (pScrolledWindow, "width-request", 230, "height-request", 130, NULL); |
| 370 |
pInteractiveWidget = pScrolledWindow; |
| 371 |
|
| 372 |
if (! bEditable) |
| 373 |
gtk_text_view_set_editable (GTK_TEXT_VIEW (pOneWidget), FALSE); |
| 374 |
|
| 375 |
if (cInitialText != NULL) |
| 376 |
{ |
| 377 |
GtkTextBuffer *pBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (pOneWidget)); |
| 378 |
gtk_text_buffer_set_text (pBuffer, cInitialText, -1); |
| 379 |
} |
| 380 |
|
| 381 |
if (attr.cButtonsImage != NULL) |
| 382 |
attr.pActionFunc = (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_text_view; |
| 383 |
} |
| 384 |
else |
| 385 |
{ |
| 386 |
pOneWidget = gtk_entry_new (); |
| 387 |
pInteractiveWidget = pOneWidget; |
| 388 |
gtk_entry_set_has_frame (GTK_ENTRY (pOneWidget), FALSE); |
| 389 |
g_object_set (pOneWidget, "width-request", CAIRO_DIALOG_MIN_ENTRY_WIDTH, NULL); |
| 390 |
if (cInitialText != NULL) |
| 391 |
gtk_entry_set_text (GTK_ENTRY (pOneWidget), cInitialText); |
| 392 |
if (! bEditable) |
| 393 |
gtk_editable_set_editable (GTK_EDITABLE (pOneWidget), FALSE); |
| 394 |
if (! bVisible) |
| 395 |
gtk_entry_set_visibility (GTK_ENTRY (pOneWidget), FALSE); |
| 396 |
|
| 397 |
if (attr.cButtonsImage != NULL) |
| 398 |
attr.pActionFunc = (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_text_entry; |
| 399 |
} |
| 400 |
if (iNbCharsMax != 0) |
| 401 |
{ |
| 402 |
gchar *cLabel = g_strdup_printf ("<b>%zd</b>", cInitialText ? strlen (cInitialText) : 0); |
| 403 |
GtkWidget *pLabel = gtk_label_new (cLabel); |
| 404 |
g_free (cLabel); |
| 405 |
gtk_label_set_use_markup (GTK_LABEL (pLabel), TRUE); |
| 406 |
GtkWidget *pBox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); |
| 407 |
gtk_box_pack_start (GTK_BOX (pBox), pInteractiveWidget, TRUE, TRUE, 0); |
| 408 |
gtk_box_pack_start (GTK_BOX (pBox), pLabel, FALSE, FALSE, 0); |
| 409 |
pInteractiveWidget = pBox; |
| 410 |
|
| 411 |
if (bMultiLines) |
| 412 |
{ |
| 413 |
GtkTextBuffer *pBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (pOneWidget)); |
| 414 |
g_signal_connect (pBuffer, "changed", G_CALLBACK (_on_text_changed), pLabel); |
| 415 |
g_object_set_data (G_OBJECT (pBuffer), "nb-chars-max", GINT_TO_POINTER (iNbCharsMax)); |
| 416 |
} |
| 417 |
else |
| 418 |
{ |
| 419 |
g_signal_connect (pOneWidget, "changed", G_CALLBACK (_on_text_changed), pLabel); |
| 420 |
g_object_set_data (G_OBJECT (pOneWidget), "nb-chars-max", GINT_TO_POINTER (iNbCharsMax)); |
| 421 |
gtk_entry_set_width_chars (GTK_ENTRY (pOneWidget), MIN (iNbCharsMax/2, 100)); // a rough estimate is: 140 chars ~ 1024 pixels |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
else if (strcmp (cType, "scale") == 0) |
| 426 |
{ |
| 427 |
GtkWidget *pScale = NULL; |
| 428 |
double fMinValue = 0.; |
| 429 |
double fMaxValue = 100.; |
| 430 |
int iNbDigit = 2; |
| 431 |
double fInitialValue = 0.; |
| 432 |
const gchar *cMinLabel = NULL; |
| 433 |
const gchar *cMaxLabel = NULL; |
| 434 |
|
| 435 |
v = g_hash_table_lookup (hWidgetAttributes, "min-value"); |
| 436 |
if (v && G_VALUE_HOLDS_DOUBLE (v)) |
| 437 |
fMinValue = g_value_get_double (v); |
| 438 |
|
| 439 |
v = g_hash_table_lookup (hWidgetAttributes, "max-value"); |
| 440 |
if (v && G_VALUE_HOLDS_DOUBLE (v)) |
| 441 |
fMaxValue = g_value_get_double (v); |
| 442 |
fMaxValue = MAX (fMaxValue, fMinValue+1); |
| 443 |
|
| 444 |
v = g_hash_table_lookup (hWidgetAttributes, "nb-digit"); |
| 445 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 446 |
iNbDigit = g_value_get_int (v); |
| 447 |
|
| 448 |
v = g_hash_table_lookup (hWidgetAttributes, "initial-value"); |
| 449 |
if (v && G_VALUE_HOLDS_DOUBLE (v)) |
| 450 |
fInitialValue = g_value_get_double (v); |
| 451 |
fInitialValue = MAX (MIN (fInitialValue, fMaxValue), fMinValue); |
| 452 |
|
| 453 |
v = g_hash_table_lookup (hWidgetAttributes, "min-label"); |
| 454 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 455 |
cMinLabel = g_value_get_string (v); |
| 456 |
|
| 457 |
v = g_hash_table_lookup (hWidgetAttributes, "max-label"); |
| 458 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 459 |
cMaxLabel = g_value_get_string (v); |
| 460 |
|
| 461 |
pScale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, fMinValue, fMaxValue, (fMaxValue - fMinValue) / 100.); |
| 462 |
pOneWidget = pScale; |
| 463 |
gtk_scale_set_digits (GTK_SCALE (pScale), iNbDigit); |
| 464 |
gtk_range_set_value (GTK_RANGE (pScale), fInitialValue); |
| 465 |
|
| 466 |
g_object_set (pScale, "width-request", 150, NULL); |
| 467 |
gldi_dialog_set_widget_text_color (pScale); |
| 468 |
|
| 469 |
if (cMinLabel || cMaxLabel) |
| 470 |
{ |
| 471 |
GtkWidget *pExtendedWidget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); |
| 472 |
GtkWidget *label = gtk_label_new (cMinLabel); |
| 473 |
GtkWidget *pAlign = gtk_alignment_new (1., 1., 0., 0.); |
| 474 |
gtk_container_add (GTK_CONTAINER (pAlign), label); |
| 475 |
gtk_box_pack_start (GTK_BOX (pExtendedWidget), pAlign, FALSE, FALSE, 0); |
| 476 |
gtk_box_pack_start (GTK_BOX (pExtendedWidget), pScale, FALSE, FALSE, 0); |
| 477 |
label = gtk_label_new (cMaxLabel); |
| 478 |
pAlign = gtk_alignment_new (1., 1., 0., 0.); |
| 479 |
gtk_container_add (GTK_CONTAINER (pAlign), label); |
| 480 |
gtk_box_pack_start (GTK_BOX (pExtendedWidget), pAlign, FALSE, FALSE, 0); |
| 481 |
pInteractiveWidget = pExtendedWidget; |
| 482 |
} |
| 483 |
else |
| 484 |
pInteractiveWidget = pScale; |
| 485 |
|
| 486 |
if (attr.cButtonsImage != NULL) |
| 487 |
attr.pActionFunc = (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_scale; |
| 488 |
} |
| 489 |
else if (strcmp (cType, "list") == 0) |
| 490 |
{ |
| 491 |
gboolean bEditable = FALSE; |
| 492 |
const gchar *cValues = NULL; |
| 493 |
gchar **cValuesList = NULL; |
| 494 |
const gchar *cInitialText = NULL; |
| 495 |
int iInitialValue = 0; |
| 496 |
|
| 497 |
v = g_hash_table_lookup (hWidgetAttributes, "editable"); |
| 498 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 499 |
bEditable = g_value_get_boolean (v); |
| 500 |
|
| 501 |
v = g_hash_table_lookup (hWidgetAttributes, "values"); |
| 502 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 503 |
cValues = g_value_get_string (v); |
| 504 |
|
| 505 |
if (cValues != NULL) |
| 506 |
cValuesList = g_strsplit (cValues, ";", -1); |
| 507 |
|
| 508 |
if (bEditable) |
| 509 |
pOneWidget = gtk_combo_box_text_new_with_entry (); |
| 510 |
else |
| 511 |
pOneWidget = gtk_combo_box_text_new (); |
| 512 |
pInteractiveWidget = pOneWidget; |
| 513 |
|
| 514 |
if (cValuesList != NULL) |
| 515 |
{ |
| 516 |
int i; |
| 517 |
for (i = 0; cValuesList[i] != NULL; i ++) |
| 518 |
{ |
| 519 |
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pInteractiveWidget), cValuesList[i]); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
v = g_hash_table_lookup (hWidgetAttributes, "initial-value"); |
| 524 |
if (bEditable) |
| 525 |
{ |
| 526 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 527 |
cInitialText = g_value_get_string (v); |
| 528 |
if (cInitialText != NULL) |
| 529 |
{ |
| 530 |
GtkWidget *pEntry = gtk_bin_get_child (GTK_BIN (pInteractiveWidget)); |
| 531 |
gtk_entry_set_text (GTK_ENTRY (pEntry), cInitialText); |
| 532 |
} |
| 533 |
} |
| 534 |
else |
| 535 |
{ |
| 536 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 537 |
iInitialValue = g_value_get_int (v); |
| 538 |
gtk_combo_box_set_active (GTK_COMBO_BOX (pInteractiveWidget), iInitialValue); |
| 539 |
} |
| 540 |
|
| 541 |
if (attr.cButtonsImage != NULL) |
| 542 |
{ |
| 543 |
if (bEditable) |
| 544 |
attr.pActionFunc = (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_combo_entry; |
| 545 |
else |
| 546 |
attr.pActionFunc = (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_combo; |
| 547 |
} |
| 548 |
} |
| 549 |
else |
| 550 |
cd_warning ("unknown widget type '%s'", cType); |
| 551 |
} // fin du type de widget. |
| 552 |
} |
| 553 |
} |
| 554 |
attr.pInteractiveWidget = pInteractiveWidget; |
| 555 |
|
| 556 |
if (pInteractiveWidget == NULL) // pas de widget, on renverra le numero du bouton appuye. |
| 557 |
{ |
| 558 |
if (attr.cButtonsImage != NULL) |
| 559 |
attr.pActionFunc = (CairoDockActionOnAnswerFunc) cd_dbus_applet_emit_on_answer_buttons; |
| 560 |
} |
| 561 |
else |
| 562 |
g_object_set_data (G_OBJECT (pInteractiveWidget), "cd-widget", pOneWidget); |
| 563 |
|
| 564 |
attr.pIcon = pIcon; |
| 565 |
attr.pContainer = pContainer; |
| 566 |
|
| 567 |
pDbusApplet->pDialog = gldi_dialog_new (&attr); |
| 568 |
if (pOneWidget) |
| 569 |
gtk_widget_grab_focus (pOneWidget); |
| 570 |
|
| 571 |
g_free (cImageFilePath); |
| 572 |
if (cButtonsImage) |
| 573 |
g_strfreev (cButtonsImage); |
| 574 |
return TRUE; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
/////////////////////////////////////////////////// |
| 579 |
////////// sub-applet interface methods /////////// |
| 580 |
/////////////////////////////////////////////////// |
| 581 |
|
| 582 |
gboolean cd_dbus_sub_applet_set_quick_info (dbusSubApplet *pDbusSubApplet, const gchar *cQuickInfo, const gchar *cIconID, GError **error) |
| 583 |
{ |
| 584 |
return _applet_set_quick_info (pDbusSubApplet->pApplet, cQuickInfo, cIconID, error); |
| 585 |
} |
| 586 |
|
| 587 |
gboolean cd_dbus_sub_applet_set_label (dbusSubApplet *pDbusSubApplet, const gchar *cLabel, const gchar *cIconID, GError **error) |
| 588 |
{ |
| 589 |
return _applet_set_label (pDbusSubApplet->pApplet, cLabel, cIconID, error); |
| 590 |
} |
| 591 |
|
| 592 |
gboolean cd_dbus_sub_applet_set_icon (dbusSubApplet *pDbusSubApplet, const gchar *cImage, const gchar *cIconID, GError **error) |
| 593 |
{ |
| 594 |
return _applet_set_icon (pDbusSubApplet->pApplet, cImage, cIconID, error); |
| 595 |
} |
| 596 |
|
| 597 |
gboolean cd_dbus_sub_applet_set_emblem (dbusSubApplet *pDbusSubApplet, const gchar *cImage, gint iPosition, const gchar *cIconID, GError **error) |
| 598 |
{ |
| 599 |
return _applet_set_emblem (pDbusSubApplet->pApplet, cImage, iPosition, cIconID, error); |
| 600 |
} |
| 601 |
|
| 602 |
gboolean cd_dbus_sub_applet_animate (dbusSubApplet *pDbusSubApplet, const gchar *cAnimation, gint iNbRounds, const gchar *cIconID, GError **error) |
| 603 |
{ |
| 604 |
return _applet_animate (pDbusSubApplet->pApplet, cAnimation, iNbRounds, cIconID, error); |
| 605 |
} |
| 606 |
|
| 607 |
gboolean cd_dbus_sub_applet_show_dialog (dbusSubApplet *pDbusSubApplet, const gchar *cMessage, gint iDuration, const gchar *cIconID, GError **error) |
| 608 |
{ |
| 609 |
return _applet_show_dialog (pDbusSubApplet->pApplet, cMessage, iDuration, cIconID, error); |
| 610 |
} |
| 611 |
|
| 612 |
// deprecated |
| 613 |
gboolean cd_dbus_sub_applet_ask_question (dbusSubApplet *pDbusSubApplet, const gchar *cMessage, const gchar *cIconID, GError **error) |
| 614 |
{ |
| 615 |
return _applet_ask_question (pDbusSubApplet->pApplet, cMessage, cIconID, error); |
| 616 |
} |
| 617 |
|
| 618 |
gboolean cd_dbus_sub_applet_ask_value (dbusSubApplet *pDbusSubApplet, const gchar *cMessage, gdouble fInitialValue, gdouble fMaxValue, const gchar *cIconID, GError **error) |
| 619 |
{ |
| 620 |
return _applet_ask_value (pDbusSubApplet->pApplet, cMessage, fInitialValue, fMaxValue, cIconID, error); |
| 621 |
} |
| 622 |
|
| 623 |
gboolean cd_dbus_sub_applet_ask_text (dbusSubApplet *pDbusSubApplet, const gchar *cMessage, const gchar *cInitialText, const gchar *cIconID, GError **error) |
| 624 |
{ |
| 625 |
return _applet_ask_text (pDbusSubApplet->pApplet, cMessage, cInitialText, cIconID, error); |
| 626 |
} |
| 627 |
// end of deprecated |
| 628 |
|
| 629 |
gboolean cd_dbus_sub_applet_popup_dialog (dbusSubApplet *pDbusSubApplet, GHashTable *hDialogAttributes, GHashTable *hWidgetAttributes, const gchar *cIconID, GError **error) |
| 630 |
{ |
| 631 |
return _applet_popup_dialog (pDbusSubApplet->pApplet, hDialogAttributes, hWidgetAttributes, cIconID, error); |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
gboolean cd_dbus_sub_applet_add_sub_icons (dbusSubApplet *pDbusSubApplet, const gchar **pIconFields, GError **error) |
| 636 |
{ |
| 637 |
//g_print ("%s ()\n", __func__); |
| 638 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusSubApplet->pApplet); |
| 639 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 640 |
|
| 641 |
Icon *pIcon = pInstance->pIcon; |
| 642 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 643 |
|
| 644 |
GldiContainer *pContainer = pInstance->pContainer; |
| 645 |
g_return_val_if_fail (pContainer != NULL, FALSE); |
| 646 |
|
| 647 |
GList *pCurrentIconsList = (pInstance->pDock ? (pIcon->pSubDock ? pIcon->pSubDock->icons : NULL) : pInstance->pDesklet->icons); |
| 648 |
Icon *pLastIcon = cairo_dock_get_last_icon (pCurrentIconsList); |
| 649 |
int n = (pLastIcon ? pLastIcon->fOrder + 1 : 0); |
| 650 |
|
| 651 |
GList *pIconsList = NULL; |
| 652 |
Icon *pOneIcon; |
| 653 |
int i; |
| 654 |
for (i = 0; pIconFields[3*i] && pIconFields[3*i+1] && pIconFields[3*i+2]; i ++) |
| 655 |
{ |
| 656 |
pOneIcon = cairo_dock_create_dummy_launcher (g_strdup (pIconFields[3*i]), |
| 657 |
g_strdup (pIconFields[3*i+1]), |
| 658 |
g_strdup (pIconFields[3*i+2]), |
| 659 |
NULL, |
| 660 |
i + n); |
| 661 |
pIconsList = g_list_append (pIconsList, pOneIcon); |
| 662 |
} |
| 663 |
if (pIconFields[3*i] != NULL) |
| 664 |
{ |
| 665 |
cd_warning ("the number of argument is incorrect\nThis may result in an incorrect number of loaded icons."); |
| 666 |
} |
| 667 |
|
| 668 |
gpointer data[3] = {GINT_TO_POINTER (0), GINT_TO_POINTER (TRUE), NULL}; |
| 669 |
cairo_dock_insert_icons_in_applet (pInstance, pIconsList, NULL, "Panel", (CairoDeskletRendererConfigPtr) data); // NULL <=> default sub-docks renderer |
| 670 |
|
| 671 |
return TRUE; |
| 672 |
} |
| 673 |
|
| 674 |
gboolean cd_dbus_sub_applet_remove_sub_icon (dbusSubApplet *pDbusSubApplet, const gchar *cIconID, GError **error) |
| 675 |
{ |
| 676 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusSubApplet->pApplet); |
| 677 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 678 |
|
| 679 |
Icon *pIcon = pInstance->pIcon; |
| 680 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 681 |
|
| 682 |
GldiContainer *pContainer = pInstance->pContainer; |
| 683 |
g_return_val_if_fail (pContainer != NULL, FALSE); |
| 684 |
|
| 685 |
if (cIconID == NULL || strcmp (cIconID, "any") == 0) // remove all |
| 686 |
{ |
| 687 |
cairo_dock_remove_all_icons_from_applet (pInstance); |
| 688 |
} |
| 689 |
else |
| 690 |
{ |
| 691 |
GList *pIconsList = (pInstance->pDock ? (pIcon->pSubDock ? pIcon->pSubDock->icons : NULL) : pInstance->pDesklet->icons); |
| 692 |
Icon *pOneIcon = cairo_dock_get_icon_with_command (pIconsList, cIconID); |
| 693 |
///cairo_dock_remove_icon_from_applet (pInstance, pOneIcon); |
| 694 |
gldi_object_unref (GLDI_OBJECT(pOneIcon)); |
| 695 |
} |
| 696 |
|
| 697 |
return TRUE; |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
/////////////////////////////////////////////// |
| 702 |
////////// applet interface methods /////////// |
| 703 |
/////////////////////////////////////////////// |
| 704 |
|
| 705 |
gboolean cd_dbus_applet_set_quick_info (dbusApplet *pDbusApplet, const gchar *cQuickInfo, GError **error) |
| 706 |
{ |
| 707 |
return _applet_set_quick_info (pDbusApplet, cQuickInfo, NULL, error); |
| 708 |
} |
| 709 |
|
| 710 |
gboolean cd_dbus_applet_set_label (dbusApplet *pDbusApplet, const gchar *cLabel, GError **error) |
| 711 |
{ |
| 712 |
return _applet_set_label (pDbusApplet, cLabel, NULL, error); |
| 713 |
} |
| 714 |
|
| 715 |
gboolean cd_dbus_applet_set_icon (dbusApplet *pDbusApplet, const gchar *cImage, GError **error) |
| 716 |
{ |
| 717 |
return _applet_set_icon (pDbusApplet, cImage, NULL, error); |
| 718 |
} |
| 719 |
|
| 720 |
gboolean cd_dbus_applet_set_emblem (dbusApplet *pDbusApplet, const gchar *cImage, gint iPosition, GError **error) |
| 721 |
{ |
| 722 |
return _applet_set_emblem (pDbusApplet, cImage, iPosition, NULL, error); |
| 723 |
} |
| 724 |
|
| 725 |
gboolean cd_dbus_applet_animate (dbusApplet *pDbusApplet, const gchar *cAnimation, gint iNbRounds, GError **error) |
| 726 |
{ |
| 727 |
return _applet_animate (pDbusApplet, cAnimation, iNbRounds, NULL, error); |
| 728 |
} |
| 729 |
|
| 730 |
gboolean cd_dbus_applet_demands_attention (dbusApplet *pDbusApplet, gboolean bStart, const gchar *cAnimation, GError **error) |
| 731 |
{ |
| 732 |
Icon *pIcon; |
| 733 |
GldiContainer *pContainer; |
| 734 |
if (! _get_icon_and_container_from_id (pDbusApplet, NULL, &pIcon, &pContainer)) |
| 735 |
return FALSE; |
| 736 |
|
| 737 |
if (bStart) |
| 738 |
{ |
| 739 |
if (CAIRO_DOCK_IS_DOCK (pContainer)) |
| 740 |
{ |
| 741 |
gldi_icon_request_attention (pIcon, cAnimation, 0); // 0 <=> sans arret. |
| 742 |
} |
| 743 |
} |
| 744 |
else if (pIcon->bIsDemandingAttention) |
| 745 |
{ |
| 746 |
gldi_icon_stop_attention (pIcon); |
| 747 |
} |
| 748 |
return TRUE; |
| 749 |
} |
| 750 |
|
| 751 |
gboolean cd_dbus_applet_show_dialog (dbusApplet *pDbusApplet, const gchar *message, gint iDuration, GError **error) |
| 752 |
{ |
| 753 |
cd_debug ("%s (%s)", __func__, message); |
| 754 |
return _applet_show_dialog (pDbusApplet, message, iDuration, NULL, error); |
| 755 |
} |
| 756 |
|
| 757 |
// deprecated |
| 758 |
gboolean cd_dbus_applet_ask_question (dbusApplet *pDbusApplet, const gchar *message, GError **error) |
| 759 |
{ |
| 760 |
cd_debug ("%s (%s)", __func__, message); |
| 761 |
return _applet_ask_question (pDbusApplet, message, NULL, error); |
| 762 |
} |
| 763 |
|
| 764 |
gboolean cd_dbus_applet_ask_value (dbusApplet *pDbusApplet, const gchar *message, gdouble fInitialValue, gdouble fMaxValue, GError **error) |
| 765 |
{ |
| 766 |
cd_debug ("%s (%s)", __func__, message); |
| 767 |
return _applet_ask_value (pDbusApplet, message, fInitialValue, fMaxValue, NULL, error); |
| 768 |
} |
| 769 |
|
| 770 |
gboolean cd_dbus_applet_ask_text (dbusApplet *pDbusApplet, const gchar *message, const gchar *cInitialText, GError **error) |
| 771 |
{ |
| 772 |
cd_debug ("%s (%s)", __func__, message); |
| 773 |
return _applet_ask_text (pDbusApplet, message, cInitialText, NULL, error); |
| 774 |
} |
| 775 |
// end of deprecated |
| 776 |
|
| 777 |
gboolean cd_dbus_applet_popup_dialog (dbusApplet *pDbusApplet, GHashTable *hDialogAttributes, GHashTable *hWidgetAttributes, GError **error) |
| 778 |
{ |
| 779 |
return _applet_popup_dialog (pDbusApplet, hDialogAttributes, hWidgetAttributes, NULL, error); |
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
gboolean cd_dbus_applet_add_data_renderer (dbusApplet *pDbusApplet, const gchar *cType, gint iNbValues, const gchar *cTheme, GError **error) |
| 784 |
{ |
| 785 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 786 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 787 |
|
| 788 |
Icon *pIcon = pInstance->pIcon; |
| 789 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 790 |
|
| 791 |
GldiContainer *pContainer = pInstance->pContainer; |
| 792 |
g_return_val_if_fail (pContainer != NULL, FALSE); |
| 793 |
|
| 794 |
CairoDataRendererAttribute *pRenderAttr = NULL; // attributes for the global data-renderer. |
| 795 |
CairoGaugeAttribute aGaugeAttr; // gauge attributes. |
| 796 |
CairoGraphAttribute aGraphAttr; // graph attributes. |
| 797 |
CairoGraphAttribute aProgressBarAttr; // progressbar attributes. |
| 798 |
double *fHighColor = NULL, *fLowColor = NULL; |
| 799 |
if (strcmp (cType, "gauge") == 0) |
| 800 |
{ |
| 801 |
memset (&aGaugeAttr, 0, sizeof (CairoGaugeAttribute)); |
| 802 |
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aGaugeAttr); |
| 803 |
aGaugeAttr.cThemePath = cairo_dock_get_data_renderer_theme_path (cType, cTheme, CAIRO_DOCK_ANY_PACKAGE); |
| 804 |
} |
| 805 |
else if (strcmp (cType, "graph") == 0) |
| 806 |
{ |
| 807 |
memset (&aGraphAttr, 0, sizeof (CairoGraphAttribute)); |
| 808 |
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aGraphAttr); |
| 809 |
int w, h; |
| 810 |
cairo_dock_get_icon_extent (pIcon, &w, &h); |
| 811 |
pRenderAttr->iMemorySize = (w > 1 ? w : 32); |
| 812 |
// Line;Plain;Bar;Circle;Plain Circle |
| 813 |
if (cTheme == NULL || strcmp (cTheme, "Line") == 0) |
| 814 |
aGraphAttr.iType = CAIRO_DOCK_GRAPH_LINE; |
| 815 |
else if (strcmp (cTheme, "Plain") == 0) |
| 816 |
aGraphAttr.iType = CAIRO_DOCK_GRAPH_PLAIN; |
| 817 |
else if (strcmp (cTheme, "Bar") == 0) |
| 818 |
aGraphAttr.iType = CAIRO_DOCK_GRAPH_BAR; |
| 819 |
else if (strcmp (cTheme, "Circle") == 0) |
| 820 |
aGraphAttr.iType = CAIRO_DOCK_GRAPH_CIRCLE; |
| 821 |
else if (strcmp (cTheme, "Plain Circle") == 0) |
| 822 |
aGraphAttr.iType = CAIRO_DOCK_GRAPH_CIRCLE_PLAIN; |
| 823 |
aGraphAttr.bMixGraphs = FALSE; |
| 824 |
fHighColor = g_new (double, iNbValues*3); |
| 825 |
fLowColor = g_new (double, iNbValues*3); |
| 826 |
int i; |
| 827 |
for (i = 0; i < iNbValues; i ++) |
| 828 |
{ |
| 829 |
fHighColor[3*i] = 1; |
| 830 |
fHighColor[3*i+1] = 0; |
| 831 |
fHighColor[3*i+2] = 0; |
| 832 |
fLowColor[3*i] = 0; |
| 833 |
fLowColor[3*i+1] = 1; |
| 834 |
fLowColor[3*i+2] = 1; |
| 835 |
} |
| 836 |
aGraphAttr.fHighColor = fHighColor; |
| 837 |
aGraphAttr.fLowColor = fLowColor; |
| 838 |
aGraphAttr.fBackGroundColor[0] = 0; |
| 839 |
aGraphAttr.fBackGroundColor[0] = 0; |
| 840 |
aGraphAttr.fBackGroundColor[0] = 1; |
| 841 |
aGraphAttr.fBackGroundColor[0] = .4; |
| 842 |
} |
| 843 |
else if (strcmp (cType, "progressbar") == 0) |
| 844 |
{ |
| 845 |
memset (&aProgressBarAttr, 0, sizeof (CairoProgressBarAttribute)); |
| 846 |
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aProgressBarAttr); |
| 847 |
} |
| 848 |
|
| 849 |
if (pRenderAttr == NULL || iNbValues <= 0) |
| 850 |
{ |
| 851 |
cairo_dock_remove_data_renderer_on_icon (pIcon); |
| 852 |
return TRUE; |
| 853 |
} |
| 854 |
|
| 855 |
pRenderAttr->cModelName = cType; |
| 856 |
pRenderAttr->iLatencyTime = 500; // 1/2s |
| 857 |
pRenderAttr->iNbValues = iNbValues; |
| 858 |
//pRenderAttr->bUpdateMinMax = TRUE; |
| 859 |
//pRenderAttr->bWriteValues = TRUE; |
| 860 |
g_return_val_if_fail (pIcon->image.pSurface != NULL, FALSE); |
| 861 |
cairo_dock_add_new_data_renderer_on_icon (pIcon, pContainer, pRenderAttr); |
| 862 |
|
| 863 |
g_free (fHighColor); |
| 864 |
g_free (fLowColor); |
| 865 |
|
| 866 |
return TRUE; |
| 867 |
} |
| 868 |
|
| 869 |
gboolean cd_dbus_applet_render_values (dbusApplet *pDbusApplet, GArray *pValues, GError **error) |
| 870 |
{ |
| 871 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 872 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 873 |
|
| 874 |
Icon *pIcon = pInstance->pIcon; |
| 875 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 876 |
|
| 877 |
GldiContainer *pContainer = pInstance->pContainer; |
| 878 |
g_return_val_if_fail (pContainer != NULL, FALSE); |
| 879 |
|
| 880 |
g_return_val_if_fail (pIcon->image.pSurface != NULL, FALSE); |
| 881 |
cairo_t *pDrawContext = cairo_create (pIcon->image.pSurface); |
| 882 |
cairo_dock_render_new_data_on_icon (pIcon, pContainer, pDrawContext, (double *)pValues->data); |
| 883 |
cairo_destroy (pDrawContext); |
| 884 |
|
| 885 |
cairo_dock_redraw_icon (pIcon); |
| 886 |
return TRUE; |
| 887 |
} |
| 888 |
|
| 889 |
gboolean cd_dbus_applet_control_appli (dbusApplet *pDbusApplet, const gchar *cApplicationClass, GError **error) |
| 890 |
{ |
| 891 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 892 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 893 |
|
| 894 |
Icon *pIcon = pInstance->pIcon; |
| 895 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 896 |
|
| 897 |
gchar *cClass = (cApplicationClass ? g_ascii_strdown (cApplicationClass, -1) : NULL); |
| 898 |
if (cairo_dock_strings_differ (pIcon->cClass, cClass)) |
| 899 |
{ |
| 900 |
if (pIcon->cClass != NULL) |
| 901 |
cairo_dock_deinhibite_class (pIcon->cClass, pIcon); |
| 902 |
if (cClass != NULL) |
| 903 |
{ |
| 904 |
cairo_dock_inhibite_class (cClass, pIcon); /// useful to use cairo_dock_register_class ?... |
| 905 |
} |
| 906 |
if (! cairo_dock_is_loading ()) |
| 907 |
{ |
| 908 |
GldiContainer *pContainer = pInstance->pContainer; |
| 909 |
if (pContainer != NULL) |
| 910 |
cairo_dock_redraw_icon (pIcon); |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
g_free (cClass); |
| 915 |
return TRUE; |
| 916 |
} |
| 917 |
|
| 918 |
gboolean cd_dbus_applet_show_appli (dbusApplet *pDbusApplet, gboolean bShow, GError **error) // deprecated |
| 919 |
{ |
| 920 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 921 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 922 |
|
| 923 |
Icon *pIcon = pInstance->pIcon; |
| 924 |
g_return_val_if_fail (pIcon != NULL && pIcon->pAppli != NULL, FALSE); |
| 925 |
|
| 926 |
if (bShow) |
| 927 |
gldi_window_show (pIcon->pAppli); |
| 928 |
else |
| 929 |
gldi_window_minimize (pIcon->pAppli); |
| 930 |
|
| 931 |
return TRUE; |
| 932 |
} |
| 933 |
|
| 934 |
gboolean cd_dbus_applet_act_on_appli (dbusApplet *pDbusApplet, const gchar *cAction, GError **error) |
| 935 |
{ |
| 936 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 937 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 938 |
|
| 939 |
Icon *pIcon = pInstance->pIcon; |
| 940 |
g_return_val_if_fail (pIcon != NULL && pIcon->pAppli != NULL, FALSE); |
| 941 |
|
| 942 |
g_return_val_if_fail (cAction != NULL, FALSE); |
| 943 |
|
| 944 |
if (strcmp (cAction, "minimize") == 0) |
| 945 |
gldi_window_minimize (pIcon->pAppli); |
| 946 |
else if (strcmp (cAction, "show") == 0) |
| 947 |
gldi_window_show (pIcon->pAppli); |
| 948 |
else if (strcmp (cAction, "toggle-visibility") == 0) |
| 949 |
{ |
| 950 |
if (pIcon->pAppli->bIsHidden) |
| 951 |
gldi_window_show (pIcon->pAppli); |
| 952 |
else |
| 953 |
gldi_window_minimize (pIcon->pAppli); |
| 954 |
} |
| 955 |
else if (strcmp (cAction, "maximize") == 0) |
| 956 |
gldi_window_maximize(pIcon->pAppli, TRUE); |
| 957 |
else if (strcmp (cAction, "restore") == 0) |
| 958 |
gldi_window_maximize (pIcon->pAppli, FALSE); |
| 959 |
else if (strcmp (cAction, "toggle-size") == 0) |
| 960 |
{ |
| 961 |
gldi_window_maximize (pIcon->pAppli, ! pIcon->pAppli->bIsMaximized); |
| 962 |
} |
| 963 |
else if (strcmp (cAction, "close") == 0) |
| 964 |
gldi_window_close (pIcon->pAppli); |
| 965 |
else if (strcmp (cAction, "kill") == 0) |
| 966 |
gldi_window_kill (pIcon->pAppli); |
| 967 |
else |
| 968 |
{ |
| 969 |
cd_warning ("invalid action '%s' on window %s", cAction, pIcon->cName); |
| 970 |
} |
| 971 |
|
| 972 |
return TRUE; |
| 973 |
} |
| 974 |
|
| 975 |
gboolean cd_dbus_applet_populate_menu (dbusApplet *pDbusApplet, const gchar **pLabels, GError **error) // deprecated |
| 976 |
{ |
| 977 |
if (myData.pModuleMainMenu == NULL || pDbusApplet != myData.pCurrentMenuDbusApplet) |
| 978 |
{ |
| 979 |
cd_warning ("the 'PopulateMenu' method can only be used to populate the menu that was summoned from a right-click on your applet !\nthat is to say, after you received a 'build-menu' event."); |
| 980 |
return FALSE; |
| 981 |
} |
| 982 |
|
| 983 |
int i; |
| 984 |
for (i = 0; pLabels[i] != NULL; i ++) |
| 985 |
{ |
| 986 |
if (*pLabels[i] == '\0') |
| 987 |
{ |
| 988 |
gtk_menu_shell_append (GTK_MENU_SHELL (myData.pModuleMainMenu), gtk_separator_menu_item_new ()); |
| 989 |
} |
| 990 |
else |
| 991 |
{ |
| 992 |
cairo_dock_add_in_menu_with_stock_and_data (pLabels[i], |
| 993 |
NULL, |
| 994 |
G_CALLBACK (cd_dbus_emit_on_menu_select), |
| 995 |
myData.pModuleMainMenu, |
| 996 |
GINT_TO_POINTER (i)); |
| 997 |
} |
| 998 |
} |
| 999 |
gtk_widget_show_all (myData.pModuleMainMenu); |
| 1000 |
|
| 1001 |
return TRUE; |
| 1002 |
} |
| 1003 |
|
| 1004 |
gboolean cd_dbus_applet_add_menu_items (dbusApplet *pDbusApplet, GPtrArray *pItems, GError **error) |
| 1005 |
{ |
| 1006 |
if (myData.pModuleMainMenu == NULL/** || myData.pModuleSubMenu == NULL*/ || pDbusApplet != myData.pCurrentMenuDbusApplet) |
| 1007 |
{ |
| 1008 |
cd_warning ("the 'AddMenuItems' method can only be used to populate the menu that was summoned from a right-click on your applet !\nthat is to say, after you received a 'build-menu' event."); |
| 1009 |
return FALSE; |
| 1010 |
} |
| 1011 |
|
| 1012 |
GtkRequisition natural_size; |
| 1013 |
gtk_widget_get_preferred_size (myData.pModuleMainMenu, NULL, &natural_size); |
| 1014 |
int iItemHeight = 0, iMenuHeight = natural_size.height; |
| 1015 |
int iIconSize; |
| 1016 |
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &iIconSize, NULL); |
| 1017 |
|
| 1018 |
// get the position of our items in the menu. |
| 1019 |
int iPosition = myData.iMenuPosition; |
| 1020 |
|
| 1021 |
// insert a separator |
| 1022 |
GtkWidget *pMenuItem = gtk_separator_menu_item_new (); |
| 1023 |
gtk_menu_shell_insert (GTK_MENU_SHELL (myData.pModuleMainMenu), pMenuItem, iPosition++); |
| 1024 |
gtk_widget_get_preferred_size (pMenuItem, NULL, &natural_size); |
| 1025 |
iItemHeight += natural_size.height; |
| 1026 |
|
| 1027 |
// table des menus et groupes de radio-boutons. |
| 1028 |
GHashTable *pSubMenus = g_hash_table_new_full (g_int_hash, |
| 1029 |
g_int_equal, |
| 1030 |
g_free, |
| 1031 |
NULL); |
| 1032 |
GHashTable *pGroups = g_hash_table_new_full (g_int_hash, |
| 1033 |
g_int_equal, |
| 1034 |
g_free, |
| 1035 |
NULL); |
| 1036 |
|
| 1037 |
// on parcours la liste des items. |
| 1038 |
GHashTable *pItem; |
| 1039 |
GtkWidget *pMenu; |
| 1040 |
GSList *group = NULL; |
| 1041 |
GValue *v; |
| 1042 |
guint i; |
| 1043 |
for (i = 0; i < pItems->len; i ++) |
| 1044 |
{ |
| 1045 |
pItem = g_ptr_array_index (pItems, i); |
| 1046 |
|
| 1047 |
// get its properties. |
| 1048 |
const gchar *cLabel = NULL, *cIcon = NULL, *cToolTip = NULL; |
| 1049 |
int iType = 0, iMenuID = -1, id = i, iGroupID = 0; |
| 1050 |
gboolean bState = FALSE; |
| 1051 |
gpointer data; |
| 1052 |
|
| 1053 |
v = g_hash_table_lookup (pItem, "type"); |
| 1054 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 1055 |
iType = g_value_get_int (v); |
| 1056 |
|
| 1057 |
v = g_hash_table_lookup (pItem, "label"); |
| 1058 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 1059 |
cLabel = g_value_get_string (v); |
| 1060 |
|
| 1061 |
v = g_hash_table_lookup (pItem, "id"); |
| 1062 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 1063 |
id = g_value_get_int (v); |
| 1064 |
data = GINT_TO_POINTER (id); |
| 1065 |
|
| 1066 |
if (iType == 0 || iType == 1) |
| 1067 |
{ |
| 1068 |
v = g_hash_table_lookup (pItem, "icon"); |
| 1069 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 1070 |
cIcon = g_value_get_string (v); |
| 1071 |
} |
| 1072 |
|
| 1073 |
v = g_hash_table_lookup (pItem, "state"); |
| 1074 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 1075 |
bState = g_value_get_boolean (v); |
| 1076 |
|
| 1077 |
v = g_hash_table_lookup (pItem, "group"); |
| 1078 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 1079 |
{ |
| 1080 |
iGroupID = g_value_get_int (v); |
| 1081 |
group = g_hash_table_lookup (pGroups, &iGroupID); // si NULL, ca fera un nouveau groupe. |
| 1082 |
} |
| 1083 |
else // si on ne definit pas le groupe, c'est donc le groupe en cours qui est utilise, ou un nouveau groupe si encore aucun n'est en cours. |
| 1084 |
iGroupID = id; // utilise seulement si le groupe est nouvellement cree, pour l'enregistrer. |
| 1085 |
|
| 1086 |
// create the item according to its type. |
| 1087 |
switch (iType) |
| 1088 |
{ |
| 1089 |
case 0 : // normal entry |
| 1090 |
pMenuItem = gldi_menu_item_new_with_action (cLabel, cIcon, G_CALLBACK (cd_dbus_emit_on_menu_select), data); |
| 1091 |
break; |
| 1092 |
case 1: // sub-menu |
| 1093 |
{ |
| 1094 |
GtkWidget *pSubMenu; |
| 1095 |
pMenuItem = gldi_menu_item_new_with_submenu (cLabel, cIcon, &pSubMenu); |
| 1096 |
int *pID = g_new (int, 1); |
| 1097 |
*pID = id; |
| 1098 |
g_hash_table_insert (pSubMenus, pID, pSubMenu); |
| 1099 |
} |
| 1100 |
break; |
| 1101 |
case 2: // separator |
| 1102 |
pMenuItem = gtk_separator_menu_item_new (); |
| 1103 |
break; |
| 1104 |
case 3: // check-box |
| 1105 |
pMenuItem = gtk_check_menu_item_new_with_label (cLabel); |
| 1106 |
if (bState) |
| 1107 |
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(pMenuItem), bState); |
| 1108 |
g_signal_connect(G_OBJECT(pMenuItem), "toggled", G_CALLBACK(cd_dbus_emit_on_menu_select), data); |
| 1109 |
break; |
| 1110 |
case 4: // group-box |
| 1111 |
pMenuItem = gtk_radio_menu_item_new_with_label (group, cLabel); |
| 1112 |
if (group == NULL) // le groupe ne change plus par la suite (g_list_append). |
| 1113 |
{ |
| 1114 |
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM(pMenuItem)); |
| 1115 |
int *pID = g_new (int, 1); |
| 1116 |
*pID = iGroupID; |
| 1117 |
g_hash_table_insert (pGroups, pID, group); |
| 1118 |
} |
| 1119 |
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(pMenuItem), bState); |
| 1120 |
g_signal_connect(G_OBJECT(pMenuItem), "toggled", G_CALLBACK(cd_dbus_emit_on_menu_select), data); |
| 1121 |
break; |
| 1122 |
default: |
| 1123 |
continue; |
| 1124 |
} |
| 1125 |
|
| 1126 |
// set sensitivity |
| 1127 |
v = g_hash_table_lookup (pItem, "sensitive"); |
| 1128 |
if (v && G_VALUE_HOLDS_BOOLEAN (v)) |
| 1129 |
gtk_widget_set_sensitive (pMenuItem, g_value_get_boolean (v)); |
| 1130 |
|
| 1131 |
// set the tooltip |
| 1132 |
v = g_hash_table_lookup (pItem, "tooltip"); |
| 1133 |
if (v && G_VALUE_HOLDS_STRING (v)) |
| 1134 |
{ |
| 1135 |
cToolTip = g_value_get_string (v); |
| 1136 |
gtk_widget_set_tooltip_text (pMenuItem, cToolTip); |
| 1137 |
} |
| 1138 |
|
| 1139 |
// insert in its menu. |
| 1140 |
v = g_hash_table_lookup (pItem, "menu"); |
| 1141 |
if (v && G_VALUE_HOLDS_INT (v)) |
| 1142 |
iMenuID = g_value_get_int (v); |
| 1143 |
if (iMenuID <= 0) |
| 1144 |
pMenu = myData.pModuleMainMenu; |
| 1145 |
else |
| 1146 |
{ |
| 1147 |
pMenu = g_hash_table_lookup (pSubMenus, &iMenuID); |
| 1148 |
if (pMenu == NULL) |
| 1149 |
pMenu = myData.pModuleMainMenu; |
| 1150 |
} |
| 1151 |
|
| 1152 |
gtk_menu_shell_insert (GTK_MENU_SHELL (pMenu), pMenuItem, iPosition++); |
| 1153 |
if (pMenu == myData.pModuleMainMenu) |
| 1154 |
{ |
| 1155 |
gtk_widget_show_all (pMenuItem); // make it visible now so that its height is correctly calculated by GTK (else its child is ignored) |
| 1156 |
gtk_widget_get_preferred_size (pMenuItem, NULL, &natural_size); |
| 1157 |
iItemHeight += natural_size.height; |
| 1158 |
} |
| 1159 |
} |
| 1160 |
|
| 1161 |
g_hash_table_destroy (pSubMenus); |
| 1162 |
g_hash_table_destroy (pGroups); |
| 1163 |
gtk_widget_show_all (myData.pModuleMainMenu); |
| 1164 |
|
| 1165 |
g_object_set (myData.pModuleMainMenu, "height-request", iMenuHeight + iItemHeight, NULL); // GTK doesn't resize menus correctly, so we have to force it... |
| 1166 |
gtk_menu_reposition (GTK_MENU (myData.pModuleMainMenu)); |
| 1167 |
|
| 1168 |
return TRUE; |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
gboolean cd_dbus_applet_bind_shortkey (dbusApplet *pDbusApplet, const gchar **cShortkeys, GError **error) |
| 1173 |
{ |
| 1174 |
cd_debug ("%s ()", __func__); |
| 1175 |
g_return_val_if_fail (cShortkeys != NULL, FALSE); |
| 1176 |
|
| 1177 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 1178 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 1179 |
|
| 1180 |
const gchar *cShortkey, *cDescription = "-", *cGroupName = "Configuration", *cKeyName = "shortkey"; |
| 1181 |
GldiShortkey *pKeyBinding; |
| 1182 |
int i; |
| 1183 |
GList *kb; |
| 1184 |
|
| 1185 |
if (pDbusApplet->pShortkeyList == NULL) |
| 1186 |
{ |
| 1187 |
for (i = 0; cShortkeys[i] != NULL; i ++) |
| 1188 |
{ |
| 1189 |
cShortkey = cShortkeys[i]; |
| 1190 |
pKeyBinding = gldi_shortkey_new (cShortkey, |
| 1191 |
pInstance->pModule->pVisitCard->cTitle, |
| 1192 |
cDescription, |
| 1193 |
pInstance->pModule->pVisitCard->cIconFilePath, |
| 1194 |
pInstance->cConfFilePath, |
| 1195 |
cGroupName, cKeyName, |
| 1196 |
(CDBindkeyHandler) cd_dbus_applet_emit_on_shortkey, pDbusApplet), |
| 1197 |
pDbusApplet->pShortkeyList = g_list_append (pDbusApplet->pShortkeyList, pKeyBinding); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
else // just rebind, we consider that the applet wants to rebind the same shortkeys. |
| 1201 |
{ |
| 1202 |
for (i = 0, kb = pDbusApplet->pShortkeyList; cShortkeys[i] != NULL && kb != NULL; i ++, kb = kb->next) |
| 1203 |
{ |
| 1204 |
cShortkey = cShortkeys[i]; |
| 1205 |
pKeyBinding = kb->data; |
| 1206 |
gldi_shortkey_rebind (pKeyBinding, cShortkey, NULL); |
| 1207 |
} |
| 1208 |
} |
| 1209 |
return TRUE; |
| 1210 |
} |
| 1211 |
|
| 1212 |
|
| 1213 |
gboolean cd_dbus_applet_get (dbusApplet *pDbusApplet, const gchar *cProperty, GValue *v, GError **error) |
| 1214 |
{ |
| 1215 |
cd_debug ("%s (%s)", __func__, cProperty); |
| 1216 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 1217 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 1218 |
|
| 1219 |
Icon *pIcon = pInstance->pIcon; |
| 1220 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 1221 |
|
| 1222 |
GldiContainer *pContainer = pInstance->pContainer; |
| 1223 |
g_return_val_if_fail (pContainer != NULL, FALSE); |
| 1224 |
|
| 1225 |
// x, y, orientation, type, width, height |
| 1226 |
if (strcmp (cProperty, "x") == 0) |
| 1227 |
{ |
| 1228 |
int x; |
| 1229 |
if (pContainer->bIsHorizontal) |
| 1230 |
{ |
| 1231 |
x = pContainer->iWindowPositionX + pIcon->fDrawX + pIcon->fWidth * pIcon->fScale/2; |
| 1232 |
} |
| 1233 |
else |
| 1234 |
{ |
| 1235 |
x = pContainer->iWindowPositionY + pIcon->fDrawY + pIcon->fHeight * pIcon->fScale/2; |
| 1236 |
} |
| 1237 |
g_value_init (v, G_TYPE_INT); |
| 1238 |
g_value_set_int (v, x); |
| 1239 |
} |
| 1240 |
else if (strcmp (cProperty, "y") == 0) |
| 1241 |
{ |
| 1242 |
int y; |
| 1243 |
if (pContainer->bIsHorizontal) |
| 1244 |
{ |
| 1245 |
y = pContainer->iWindowPositionY + pIcon->fDrawY + pIcon->fHeight * pIcon->fScale/2; |
| 1246 |
} |
| 1247 |
else |
| 1248 |
{ |
| 1249 |
y = pContainer->iWindowPositionX + pIcon->fDrawX + pIcon->fWidth * pIcon->fScale/2; |
| 1250 |
} |
| 1251 |
g_value_init (v, G_TYPE_INT); |
| 1252 |
g_value_set_int (v, y); |
| 1253 |
} |
| 1254 |
else if (strcmp (cProperty, "orientation") == 0) |
| 1255 |
{ |
| 1256 |
CairoDockPositionType iScreenBorder = ((! pContainer->bIsHorizontal) << 1) | (! pContainer->bDirectionUp); |
| 1257 |
g_value_init (v, G_TYPE_UINT); |
| 1258 |
g_value_set_uint (v, iScreenBorder); |
| 1259 |
} |
| 1260 |
else if (strcmp (cProperty, "container") == 0) |
| 1261 |
{ |
| 1262 |
g_value_init (v, G_TYPE_UINT); |
| 1263 |
int iType = _get_container_type (pContainer); |
| 1264 |
g_value_set_uint (v, iType); |
| 1265 |
} |
| 1266 |
else if (strcmp (cProperty, "width") == 0) // this is the dimension of the icon when it's hovered. |
| 1267 |
{ |
| 1268 |
int iWidth, iHeight; |
| 1269 |
cairo_dock_get_icon_extent (pIcon, &iWidth, &iHeight); |
| 1270 |
g_value_init (v, G_TYPE_INT); |
| 1271 |
g_value_set_int (v, iWidth); |
| 1272 |
} |
| 1273 |
else if (strcmp (cProperty, "height") == 0) |
| 1274 |
{ |
| 1275 |
int iWidth, iHeight; |
| 1276 |
cairo_dock_get_icon_extent (pIcon, &iWidth, &iHeight); |
| 1277 |
g_value_init (v, G_TYPE_INT); |
| 1278 |
g_value_set_int (v, iHeight); |
| 1279 |
} |
| 1280 |
else if (strncmp (cProperty, "Xid", 3) == 0) |
| 1281 |
{ |
| 1282 |
g_value_init (v, G_TYPE_UINT64); |
| 1283 |
g_value_set_uint64 (v, GPOINTER_TO_INT(pIcon->pAppli)); |
| 1284 |
} |
| 1285 |
else if (strcmp (cProperty, "has_focus") == 0) |
| 1286 |
{ |
| 1287 |
gboolean bHasFocus = (pIcon->pAppli != NULL && pIcon->pAppli == gldi_windows_get_active ()); |
| 1288 |
g_value_init (v, G_TYPE_BOOLEAN); |
| 1289 |
g_value_set_boolean (v, bHasFocus); |
| 1290 |
} |
| 1291 |
else |
| 1292 |
{ |
| 1293 |
g_set_error (error, 1, 1, "the property %s doesn't exist", cProperty); |
| 1294 |
return FALSE; |
| 1295 |
} |
| 1296 |
return TRUE; |
| 1297 |
} |
| 1298 |
|
| 1299 |
gboolean cd_dbus_applet_get_all (dbusApplet *pDbusApplet, GHashTable **hProperties, GError **error) |
| 1300 |
{ |
| 1301 |
cd_debug ("%s ()", __func__); |
| 1302 |
GldiModuleInstance *pInstance = _get_module_instance_from_dbus_applet (pDbusApplet); |
| 1303 |
g_return_val_if_fail (pInstance != NULL, FALSE); |
| 1304 |
|
| 1305 |
Icon *pIcon = pInstance->pIcon; |
| 1306 |
g_return_val_if_fail (pIcon != NULL, FALSE); |
| 1307 |
|
| 1308 |
GldiContainer *pContainer = pInstance->pContainer; |
| 1309 |
g_return_val_if_fail (pContainer != NULL, FALSE); |
| 1310 |
|
| 1311 |
int x, y; |
| 1312 |
if (pContainer->bIsHorizontal) |
| 1313 |
{ |
| 1314 |
x = pContainer->iWindowPositionX + pIcon->fDrawX + pIcon->fWidth * pIcon->fScale/2; |
| 1315 |
y = pContainer->iWindowPositionY + pIcon->fDrawY + pIcon->fHeight * pIcon->fScale/2; |
| 1316 |
} |
| 1317 |
else |
| 1318 |
{ |
| 1319 |
y = pContainer->iWindowPositionX + pIcon->fDrawX + pIcon->fWidth * pIcon->fScale/2; |
| 1320 |
x = pContainer->iWindowPositionY + pIcon->fDrawY + pIcon->fHeight * pIcon->fScale/2; |
| 1321 |
} |
| 1322 |
CairoDockPositionType iScreenBorder = ((! pContainer->bIsHorizontal) << 1) | (! pContainer->bDirectionUp); |
| 1323 |
int iWidth, iHeight; |
| 1324 |
cairo_dock_get_icon_extent (pIcon, &iWidth, &iHeight); |
| 1325 |
|
| 1326 |
gboolean bHasFocus = (pIcon->pAppli != NULL && pIcon->pAppli == gldi_windows_get_active ()); |
| 1327 |
|
| 1328 |
GHashTable *h = g_hash_table_new_full (g_str_hash, |
| 1329 |
g_str_equal, |
| 1330 |
g_free, |
| 1331 |
g_free); |
| 1332 |
*hProperties = h; |
| 1333 |
GValue *v; |
| 1334 |
|
| 1335 |
v = g_new0 (GValue, 1); |
| 1336 |
g_value_init (v, G_TYPE_INT); |
| 1337 |
g_value_set_int (v, x); |
| 1338 |
g_hash_table_insert (h, g_strdup ("x"), v); |
| 1339 |
|
| 1340 |
v = g_new0 (GValue, 1); |
| 1341 |
g_value_init (v, G_TYPE_INT); |
| 1342 |
g_value_set_int (v, y); |
| 1343 |
g_hash_table_insert (h, g_strdup ("y"), v); |
| 1344 |
|
| 1345 |
v = g_new0 (GValue, 1); |
| 1346 |
g_value_init (v, G_TYPE_UINT); |
| 1347 |
g_value_set_uint (v, iScreenBorder); |
| 1348 |
g_hash_table_insert (h, g_strdup ("orientation"), v); |
| 1349 |
|
| 1350 |
v = g_new0 (GValue, 1); |
| 1351 |
g_value_init (v, G_TYPE_UINT); |
| 1352 |
int iType = _get_container_type (pContainer); |
| 1353 |
g_value_set_uint (v, iType); |
| 1354 |
g_hash_table_insert (h, g_strdup ("container"), v); |
| 1355 |
|
| 1356 |
v = g_new0 (GValue, 1); |
| 1357 |
g_value_init (v, G_TYPE_INT); |
| 1358 |
g_value_set_int (v, iWidth); |
| 1359 |
g_hash_table_insert (h, g_strdup ("width"), v); |
| 1360 |
|
| 1361 |
v = g_new0 (GValue, 1); |
| 1362 |
g_value_init (v, G_TYPE_INT); |
| 1363 |
g_value_set_int (v, iHeight); |
| 1364 |
g_hash_table_insert (h, g_strdup ("height"), v); |
| 1365 |
|
| 1366 |
v = g_new0 (GValue, 1); |
| 1367 |
g_value_init (v, G_TYPE_UINT64); |
| 1368 |
g_value_set_uint64(v, GPOINTER_TO_INT(pIcon->pAppli)); |
| 1369 |
g_hash_table_insert (h, g_strdup ("Xid"), v); |
| 1370 |
|
| 1371 |
v = g_new0 (GValue, 1); |
| 1372 |
g_value_init (v, G_TYPE_BOOLEAN); |
| 1373 |
g_value_set_boolean (v, bHasFocus); |
| 1374 |
g_hash_table_insert (h, g_strdup ("has_focus"), v); |
| 1375 |
|
| 1376 |
return TRUE; |
| 1377 |
} |