~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-201110111206

« back to all changes in this revision

Viewing changes to Dbus/src/interface-main-methods.c

  • Committer: Kees Cook
  • Date: 2011-08-11 23:17:39 UTC
  • mfrom: (20.1.1 cairo-dock-plug-ins)
  • Revision ID: kees@outflux.net-20110811231739-cteedan51tmdg77v
Tags: 2.4.0~0beta2-0ubuntu1
releasing version 2.4.0~0beta2-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
exemples : 
22
22
----------
23
23
 
24
 
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.CreateLauncherFromScratch string:gimp.png string:"fake gimp" string:gimp string:none
25
 
 
26
 
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.SetLabel string:new_label string:icon_name string:any string:none
27
 
 
28
 
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.SetQuickInfo string:123 string:none string:none string:dustbin
29
 
 
30
 
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Animate string:default int32:2 string:any string:firefox string:none
31
 
 
32
 
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.SetIcon string:firefox-3.0 string:any string:nautilus string:none
 
24
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.SetQuickInfo string:123 string:"class=firefox"
 
25
 
 
26
dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Animate string:default int32:2 string:"class=firefox"
33
27
 
34
28
******************************************************************************/
35
29
 
36
30
#include <unistd.h>
37
31
#include <glib.h>
38
32
 
 
33
#include "cairo-dock.h"
39
34
#include "interface-main-methods.h"
40
35
 
41
36
#define nullify_argument(string) do {\
61
56
        return TRUE;
62
57
}
63
58
 
 
59
static void _show_hide_one_dock (const gchar *cDockName, CairoDock *pDock, gpointer data)
 
60
{
 
61
        if (pDock->iRefCount != 0)
 
62
                return ;
 
63
        gboolean bShow = GPOINTER_TO_INT (data);
 
64
        if (bShow)
 
65
        {
 
66
                ///cairo_dock_pop_up (pDock);
 
67
                ///if (pDock->bAutoHide)
 
68
                        cairo_dock_emit_enter_signal (CAIRO_CONTAINER (pDock));
 
69
        }
 
70
        else
 
71
        {
 
72
                ///cairo_dock_pop_down (pDock);  // ne fait rien s'il n'etait pas "popped".
 
73
                ///if (pDock->bAutoHide)
 
74
                        cairo_dock_emit_leave_signal (CAIRO_CONTAINER (pDock));
 
75
        }
 
76
}
 
77
gboolean cd_dbus_main_show_dock (dbusMainObject *pDbusCallback, gint iVisibiliy, GError **error)
 
78
{
 
79
        if (! myConfig.bEnableShowDock)
 
80
                return FALSE;
 
81
        
 
82
        if (g_pMainDock == NULL)
 
83
                return FALSE;
 
84
        
 
85
        gboolean bShow;
 
86
        switch (iVisibiliy)
 
87
        {
 
88
                case 0:  // hide
 
89
                        bShow = FALSE;
 
90
                break;
 
91
                case 1:  // show
 
92
                        bShow = TRUE;
 
93
                break;
 
94
                case 2:  // toggle
 
95
                default:
 
96
                        bShow = (g_pMainDock->bIsBelow || (g_pMainDock->bAutoHide && g_pMainDock->fHideOffset == 1));
 
97
                break;          
 
98
        }
 
99
        
 
100
        if (bShow)
 
101
                cairo_dock_stop_quick_hide ();
 
102
        
 
103
        cairo_dock_foreach_docks ((GHFunc) _show_hide_one_dock, GINT_TO_POINTER (bShow));
 
104
        
 
105
        if (! bShow)
 
106
                cairo_dock_quick_hide_all_docks ();
 
107
        
 
108
        return TRUE;
 
109
}
 
110
 
 
111
gboolean cd_dbus_main_show_desklet (dbusMainObject *pDbusCallback, gboolean *widgetLayer, GError **error)
 
112
{
 
113
        if (! myConfig.bEnableDesklets)
 
114
                return FALSE;
 
115
        if (dbus_deskletVisible)
 
116
        {
 
117
                cairo_dock_set_desklets_visibility_to_default ();
 
118
                cairo_dock_show_xwindow (dbus_xLastActiveWindow);
 
119
        }
 
120
        else
 
121
        {
 
122
                dbus_xLastActiveWindow = cairo_dock_get_current_active_window ();
 
123
                cairo_dock_set_all_desklets_visible (widgetLayer != NULL ? *widgetLayer : FALSE);
 
124
        }
 
125
        dbus_deskletVisible = !dbus_deskletVisible;
 
126
        return TRUE;
 
127
}
 
128
 
 
129
 
64
130
gboolean cd_dbus_main_reload_module (dbusMainObject *pDbusCallback, const gchar *cModuleName, GError **error)
65
131
{
66
132
        if (! myConfig.bEnableReloadModule)
72
138
        }
73
139
        else
74
140
        {
75
 
                //CairoDockInternalModule *pInternalModule = cairo_dock_find_internal_module_from_name (cModuleName);
76
141
                GldiManager *pManager = gldi_get_manager (cModuleName);
77
142
                if (pManager != NULL)
78
143
                {
79
 
                        //cairo_dock_reload_internal_module (pInternalModule, g_cConfFile);
80
144
                        gldi_reload_manager (pManager, g_cConfFile);
81
145
                }
82
146
                else
96
160
        CairoDockModule *pModule = cairo_dock_find_module_from_name (cModuleName);
97
161
        if (pModule == NULL)
98
162
        {
99
 
                /*if (cairo_dock_find_internal_module_from_name (cModuleName) != NULL)
 
163
                if (gldi_get_manager (cModuleName) != NULL)
100
164
                        cd_warning ("Internal modules can't be (de)activated.");
101
 
                else*/
 
165
                else
102
166
                        cd_warning ("no such module (%s)", cModuleName);
103
167
                return FALSE;
104
168
        }
110
174
        return TRUE;
111
175
}
112
176
 
113
 
gboolean cd_dbus_main_show_desklet(dbusMainObject *pDbusCallback, gboolean *widgetLayer, GError **error)
114
 
{
115
 
        if (! myConfig.bEnableDesklets)
116
 
                return FALSE;
117
 
        if (dbus_deskletVisible)
118
 
        {
119
 
                cairo_dock_set_desklets_visibility_to_default ();
120
 
                cairo_dock_show_xwindow (dbus_xLastActiveWindow);
121
 
        }
122
 
        else
123
 
        {
124
 
                dbus_xLastActiveWindow = cairo_dock_get_current_active_window ();
125
 
                cairo_dock_set_all_desklets_visible (widgetLayer != NULL ? *widgetLayer : FALSE);
126
 
        }
127
 
        dbus_deskletVisible = !dbus_deskletVisible;
128
 
        return TRUE;
129
 
}
130
 
 
131
 
static void _show_hide_one_dock (const gchar *cDockName, CairoDock *pDock, gpointer data)
132
 
{
133
 
        if (pDock->iRefCount != 0)
134
 
                return ;
135
 
        gboolean bShow = GPOINTER_TO_INT (data);
136
 
        if (bShow)
137
 
        {
138
 
                ///cairo_dock_pop_up (pDock);
139
 
                if (pDock->bAutoHide)
140
 
                        cairo_dock_emit_enter_signal (CAIRO_CONTAINER (pDock));
141
 
        }
142
 
        else
143
 
        {
144
 
                ///cairo_dock_pop_down (pDock);  // ne fait rien s'il n'etait pas "popped".
145
 
                if (pDock->bAutoHide)
146
 
                        cairo_dock_emit_leave_signal (CAIRO_CONTAINER (pDock));
147
 
        }
148
 
}
149
 
gboolean cd_dbus_main_show_dock (dbusMainObject *pDbusCallback, gboolean bShow, GError **error)
150
 
{
151
 
        if (! myConfig.bEnableShowDock)
152
 
                return FALSE;
153
 
        
154
 
        if (bShow)
155
 
                cairo_dock_stop_quick_hide ();
156
 
        
157
 
        cairo_dock_foreach_docks ((GHFunc) _show_hide_one_dock, GINT_TO_POINTER (bShow));
158
 
        
159
 
        if (! bShow)
160
 
                cairo_dock_quick_hide_all_docks ();
161
 
        
162
 
        return TRUE;
163
 
}
164
 
 
165
 
gboolean cd_dbus_main_create_launcher_from_scratch (dbusMainObject *pDbusCallback, const gchar *cIconFile, const gchar *cLabel, const gchar *cCommand, const gchar *cParentDockName, GError **error)
166
 
{
167
 
        if (! myConfig.bEnableCreateLauncher)
168
 
                return FALSE;
169
 
        
170
 
        nullify_argument (cParentDockName);
171
 
        if (cParentDockName == NULL)
172
 
                cParentDockName = CAIRO_DOCK_MAIN_DOCK_NAME;
 
177
 
 
178
  //////////////////
 
179
 /// ICON QUERY ///
 
180
//////////////////
 
181
 
 
182
typedef struct {
 
183
        const gchar *cType;
 
184
        const gchar *cName;
 
185
        const gchar *cCommand;
 
186
        const gchar *cClass;
 
187
        const gchar *cContainerName;
 
188
        Window Xid;
 
189
        const gchar *cDesktopFile;
 
190
        const gchar *cModuleName;
 
191
        gint iPosition;
 
192
        gboolean bMatchAll;
 
193
        GList *pMatchingIcons;
 
194
} CDIconQueryBuffer;
 
195
static inline gboolean _strings_match (const gchar *q, const gchar *p)  // query, parameter
 
196
{
 
197
        if (!p)
 
198
                return (strcmp (q, "none") == 0);
 
199
        int n = strlen(q);
 
200
        if (n != 0 && q[n-1] == '*')  // ok with UTF-8 too.
 
201
                return (strncmp (q, p, n-1) == 0);
 
202
        return (strcmp (q, p) == 0);
 
203
}
 
204
static inline gboolean _strings_match_case (const gchar *q, const gchar *p)  // query, parameter
 
205
{
 
206
        if (!p)
 
207
                return (strcmp (q, "none") == 0);
 
208
        int n = strlen(q);
 
209
        if (n != 0 && q[n-1] == '*')
 
210
                return (g_ascii_strncasecmp (q, p, n-1) == 0);
 
211
        return (g_ascii_strcasecmp (q, p) == 0);
 
212
}
 
213
static gboolean _icon_is_matching (Icon *pIcon, CairoContainer *pContainer, CDIconQueryBuffer *pQuery)
 
214
{
 
215
        gboolean bOr = FALSE;
 
216
        gboolean bAnd = TRUE;  // at least 1 of the fields is not nul.
 
217
        gboolean r;
 
218
        if (pQuery->cType)
 
219
        {
 
220
                const gchar *cType;
 
221
                if (CAIRO_DOCK_ICON_TYPE_IS_LAUNCHER (pIcon))
 
222
                        cType = "Launcher";
 
223
                else if (CAIRO_DOCK_ICON_TYPE_IS_APPLI (pIcon))
 
224
                        cType = "Application";
 
225
                else if (CAIRO_DOCK_ICON_TYPE_IS_APPLET (pIcon))
 
226
                        cType = "Applet";
 
227
                else if (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
 
228
                        cType = "Separator";
 
229
                else if (CAIRO_DOCK_ICON_TYPE_IS_CONTAINER (pIcon))
 
230
                        cType = "Container";
 
231
                else if (CAIRO_DOCK_ICON_TYPE_IS_CLASS_CONTAINER (pIcon))
 
232
                        cType = "Class-Container";
 
233
                else
 
234
                        cType = "Other";
 
235
                r = (strcmp (pQuery->cType, cType) == 0);
 
236
                bOr |= r;
 
237
                bAnd &= r;
 
238
        }
 
239
        if (pQuery->cName)
 
240
        {
 
241
                r = _strings_match (pQuery->cName, pIcon->cName);
 
242
                bOr |= r;
 
243
                bAnd &= r;
 
244
        }
 
245
        if (pQuery->cCommand)
 
246
        {
 
247
                r = _strings_match (pQuery->cCommand, pIcon->cCommand);
 
248
                bOr |= r;
 
249
                bAnd &= r;
 
250
        }
 
251
        if (pQuery->cClass)
 
252
        {
 
253
                r = _strings_match_case (pQuery->cClass, pIcon->cClass);
 
254
                bOr |= r;
 
255
                bAnd &= r;
 
256
        }
 
257
        if (pQuery->cContainerName)
 
258
        {
 
259
                const gchar *cContainerName = NULL;
 
260
                if (CAIRO_DOCK_IS_DOCK (pContainer))
 
261
                        cContainerName = pIcon->cParentDockName;
 
262
                else if (CAIRO_DOCK_IS_DESKLET (pContainer))
 
263
                {
 
264
                        Icon *pMainIcon = CAIRO_DESKLET (pContainer)->pIcon;
 
265
                        if (CAIRO_DOCK_IS_APPLET (pMainIcon))
 
266
                                cContainerName = pMainIcon->pModuleInstance->pModule->pVisitCard->cModuleName;
 
267
                }
 
268
                r = _strings_match (pQuery->cContainerName, cContainerName);
 
269
                bOr |= r;
 
270
                bAnd &= r;
 
271
        }
 
272
        if (pQuery->Xid != 0)
 
273
        {
 
274
                r = (pIcon->Xid == pQuery->Xid);
 
275
                bOr |= r;
 
276
                bAnd &= r;
 
277
        }
 
278
        if (pQuery->cDesktopFile)
 
279
        {
 
280
                r = _strings_match (pQuery->cDesktopFile, pIcon->cDesktopFileName);
 
281
                if (!r && CAIRO_DOCK_IS_APPLET (pIcon) && pIcon->pModuleInstance->cConfFilePath)
 
282
                {
 
283
                        if (*pQuery->cDesktopFile == '/')  // query the complete path.
 
284
                        {
 
285
                                r = _strings_match (pQuery->cDesktopFile, pIcon->pModuleInstance->cConfFilePath);
 
286
                        }
 
287
                        else  // query the file name only.
 
288
                        {
 
289
                                gchar *str = strrchr (pIcon->pModuleInstance->cConfFilePath, '/');
 
290
                                if (str)
 
291
                                        r = _strings_match (pQuery->cDesktopFile, str+1);
 
292
                        }
 
293
                }
 
294
                bOr |= r;
 
295
                bAnd &= r;
 
296
        }
 
297
        if (pQuery->cModuleName)
 
298
        {
 
299
                r = (CAIRO_DOCK_IS_APPLET (pIcon) && _strings_match (pQuery->cModuleName, pIcon->pModuleInstance->pModule->pVisitCard->cModuleName));
 
300
                bOr |= r;
 
301
                bAnd &= r;
 
302
        }
 
303
        
 
304
        return ((pQuery->bMatchAll && bAnd) || (!pQuery->bMatchAll && bOr));
 
305
}
 
306
static void _check_icon_matching (Icon *pIcon, CairoContainer *pContainer, CDIconQueryBuffer *pQuery)
 
307
{
 
308
        if (_icon_is_matching (pIcon, pContainer, pQuery))
 
309
                pQuery->pMatchingIcons = g_list_prepend (pQuery->pMatchingIcons, pIcon);
 
310
}
 
311
static void _get_icon_at_position_in_dock (const gchar *cDockName, CairoDock *pDock, CDIconQueryBuffer *pQuery)
 
312
{
 
313
        Icon *pIcon = g_list_nth_data (pDock->icons, pQuery->iPosition);
 
314
        if (pIcon != NULL)
 
315
                pQuery->pMatchingIcons = g_list_prepend (pQuery->pMatchingIcons, pIcon);
 
316
}
 
317
static gboolean _get_icon_at_position_in_desklet (CairoDesklet *pDesklet, CDIconQueryBuffer *pQuery)
 
318
{
 
319
        Icon *pIcon = g_list_nth_data (pDesklet->icons, pQuery->iPosition);
 
320
        if (pIcon != NULL)
 
321
                pQuery->pMatchingIcons = g_list_prepend (pQuery->pMatchingIcons, pIcon);
 
322
        return FALSE;  // don't stop.
 
323
}
 
324
static gboolean _prepare_query (CDIconQueryBuffer *pQuery, const gchar *cKey, const gchar *cValue)
 
325
{
 
326
        g_return_val_if_fail (cKey != NULL, FALSE);
 
327
        if (cValue == NULL)  // use "none" keyword to look for "icons that don't have key".
 
328
                return FALSE;
 
329
        
 
330
        if (strcmp (cKey, "name") == 0 || strcmp (cKey, "label") == 0)
 
331
                pQuery->cName = cValue;
 
332
        else if (strcmp (cKey, "command") == 0)
 
333
                pQuery->cCommand = cValue;
 
334
        else if (strcmp (cKey, "class") == 0)
 
335
                pQuery->cClass = cValue;
 
336
        else if (strcmp (cKey, "container") == 0)
 
337
                pQuery->cContainerName = cValue;
 
338
        else if (strcmp (cKey, "Xid") == 0)
 
339
                pQuery->Xid = strtol(cValue, NULL, 0);  // can read hexa, decimal or octal.
 
340
        else if (strcmp (cKey, "config-file") == 0)
 
341
                pQuery->cDesktopFile = cValue;
 
342
        else if (strcmp (cKey, "module") == 0)
 
343
                pQuery->cModuleName = cValue;
 
344
        else if (strcmp (cKey, "position") == 0)
 
345
                pQuery->iPosition = atoi (cValue);
 
346
        else if (strcmp (cKey, "type") == 0)
 
347
                pQuery->cType = cValue;
 
348
        else
 
349
        {
 
350
                cd_warning ("wrong key (%s)", cKey);
 
351
                return FALSE;
 
352
        }
 
353
        return TRUE;
 
354
}
 
355
static GList *_find_matching_icons_for_key (const gchar *cKey, const gchar *cValue)
 
356
{
 
357
        //g_print ("  %s (%s, %s)\n", __func__, cKey, cValue);
 
358
        CDIconQueryBuffer query;
 
359
        memset (&query, 0, sizeof (CDIconQueryBuffer));
 
360
        query.iPosition = -1;
 
361
        query.bMatchAll = TRUE;
 
362
        
 
363
        gboolean bValidQuery = _prepare_query (&query, cKey, cValue);
 
364
        g_return_val_if_fail (bValidQuery, NULL);
 
365
        
 
366
        if (query.iPosition >= 0)
 
367
        {
 
368
                cairo_dock_foreach_docks ((GHFunc) _get_icon_at_position_in_dock, &query);
 
369
                cairo_dock_foreach_desklet ((CairoDockForeachDeskletFunc) _get_icon_at_position_in_desklet, &query);
 
370
        }
 
371
        else
 
372
        {
 
373
                cairo_dock_foreach_icons ((CairoDockForeachIconFunc) _check_icon_matching, &query);
 
374
        }
 
375
        return query.pMatchingIcons;
 
376
}
 
377
static GList *_find_matching_icons_for_test (gchar *cTest)
 
378
{
 
379
        g_return_val_if_fail (cTest != NULL, NULL);
 
380
        //g_print (" %s (%s)\n", __func__, cTest);
 
381
        
 
382
        gchar *str = strchr (cTest, '=');
 
383
        g_return_val_if_fail (str != NULL, NULL);
 
384
        
 
385
        *str = '\0';
 
386
        gchar *cKey = g_strstrip ((gchar*)cTest);  // g_strstrip modifies the string in place (by moving the rest of the characters forward and cutting the trailing spaces)
 
387
        gchar *cValue = g_strstrip (str+1);
 
388
        
 
389
        return _find_matching_icons_for_key (cKey, cValue);
 
390
}
 
391
static GList *_merge (GList *pList1, GList *pList2)
 
392
{
 
393
        //g_print ("%s ()\n", __func__);
 
394
        GList *pList = NULL;
 
395
        GList *ic;
 
396
        Icon *pIcon;
 
397
        for (ic = pList1; ic != NULL; ic = ic->next)
 
398
        {
 
399
                pIcon = ic->data;
 
400
                if (g_list_find (pList2, pIcon) != NULL)
 
401
                        pList = g_list_prepend (pList, pIcon);
 
402
        }
 
403
        g_list_free (pList1);
 
404
        g_list_free (pList2);
 
405
        return pList;
 
406
}
 
407
static GList *_concat (GList *pList1, GList *pList2)
 
408
{
 
409
        //g_print ("%s ()\n", __func__);
 
410
        GList *pList = g_list_copy (pList2);
 
411
        GList *ic;
 
412
        Icon *pIcon;
 
413
        for (ic = pList1; ic != NULL; ic = ic->next)
 
414
        {
 
415
                pIcon = ic->data;
 
416
                if (!g_list_find (pList2, pIcon))
 
417
                        pList = g_list_prepend (pList, pIcon);
 
418
        }
 
419
        g_list_free (pList1);
 
420
        g_list_free (pList2);
 
421
        return pList;
 
422
}
 
423
GList *cd_dbus_find_matching_icons (gchar *cQuery)
 
424
{
 
425
        g_return_val_if_fail (cQuery != NULL, NULL);
 
426
        //g_print ("%s (%s)\n", __func__, cQuery);
 
427
        
 
428
        gchar *str;
 
429
        str = strchr (cQuery, '|');  // a && b || c && d <=> (a && b) || (c && d)
 
430
        if (str)
 
431
        {
 
432
                *str = '\0';
 
433
                GList *pList1 = cd_dbus_find_matching_icons (cQuery);
 
434
                GList *pList2 = cd_dbus_find_matching_icons (str+1);
 
435
                return _concat (pList1, pList2);
 
436
        }
 
437
        str = strchr (cQuery, '&');
 
438
        if (str)
 
439
        {
 
440
                *str = '\0';
 
441
                GList *pList1 = cd_dbus_find_matching_icons (cQuery);
 
442
                GList *pList2 = cd_dbus_find_matching_icons (str+1);
 
443
                return _merge (pList1, pList2);
 
444
        }
 
445
        return _find_matching_icons_for_test (cQuery);
 
446
}
 
447
 
 
448
 
 
449
gboolean cd_dbus_main_get_icon_properties (dbusMainObject *pDbusCallback, gchar *cIconQuery, GPtrArray **pIconAttributes, GError **error)
 
450
{
 
451
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);  // if NULL, will just return an empty array.
 
452
        
 
453
        GPtrArray *pTab = g_ptr_array_new ();
 
454
        *pIconAttributes = pTab;
 
455
        
 
456
        GHashTable *h;
 
457
        GValue *v;
 
458
        Icon *pIcon;
 
459
        CairoContainer *pContainer;
 
460
        int iPosition;
 
461
        const gchar *cType;
 
462
        const gchar *cContainerName;
 
463
        const gchar *cDesktopFile;
 
464
        GList *ic;
 
465
        for (ic = pList; ic != NULL; ic = ic->next)
 
466
        {
 
467
                pIcon = ic->data;
 
468
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
469
                
 
470
                h = g_hash_table_new_full (g_str_hash,
 
471
                        g_str_equal,
 
472
                        g_free,  /// can we use const char here instead of duplicating each string ?...
 
473
                        g_free);
 
474
                g_ptr_array_add (pTab, h);
 
475
                
 
476
                if (CAIRO_DOCK_ICON_TYPE_IS_LAUNCHER (pIcon))
 
477
                        cType = "Launcher";
 
478
                else if (CAIRO_DOCK_ICON_TYPE_IS_APPLI (pIcon))
 
479
                        cType = "Application";
 
480
                else if (CAIRO_DOCK_ICON_TYPE_IS_APPLET (pIcon))
 
481
                        cType = "Applet";
 
482
                else if (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
 
483
                        cType = "Separator";
 
484
                else if (CAIRO_DOCK_ICON_TYPE_IS_CONTAINER (pIcon))
 
485
                        cType = "Container";
 
486
                else if (CAIRO_DOCK_ICON_TYPE_IS_CLASS_CONTAINER (pIcon))
 
487
                        cType = "Class-Container";
 
488
                else
 
489
                        cType = "Other";
 
490
                v = g_new0 (GValue, 1);
 
491
                g_value_init (v, G_TYPE_STRING);
 
492
                g_value_set_string (v, cType);
 
493
                g_hash_table_insert (h, g_strdup ("type"), v);
 
494
                
 
495
                cDesktopFile = NULL;
 
496
                if (pIcon->cDesktopFileName != NULL)
 
497
                        cDesktopFile = pIcon->cDesktopFileName;
 
498
                else if (CAIRO_DOCK_IS_APPLET (pIcon))
 
499
                        cDesktopFile = pIcon->pModuleInstance->cConfFilePath;
 
500
                v = g_new0 (GValue, 1);
 
501
                g_value_init (v, G_TYPE_STRING);
 
502
                g_value_set_string (v, cDesktopFile);
 
503
                g_hash_table_insert (h, g_strdup ("config-file"), v);
 
504
                
 
505
                if (CAIRO_DOCK_IS_APPLET (pIcon))
 
506
                {
 
507
                        v = g_new0 (GValue, 1);
 
508
                        g_value_init (v, G_TYPE_STRING);
 
509
                        g_value_set_string (v, pIcon->pModuleInstance->pModule->pVisitCard->cModuleName);
 
510
                        g_hash_table_insert (h, g_strdup ("module"), v);
 
511
                }
 
512
                
 
513
                v = g_new0 (GValue, 1);
 
514
                g_value_init (v, G_TYPE_STRING);
 
515
                g_value_set_string (v, pIcon->cName);  /// g_value_set_static_string ?...
 
516
                g_hash_table_insert (h, g_strdup ("name"), v);
 
517
                
 
518
                v = g_new0 (GValue, 1);
 
519
                g_value_init (v, G_TYPE_STRING);
 
520
                g_value_set_string (v, pIcon->cCommand);
 
521
                g_hash_table_insert (h, g_strdup ("command"), v);
 
522
                
 
523
                v = g_new0 (GValue, 1);
 
524
                g_value_init (v, G_TYPE_STRING);
 
525
                g_value_set_string (v, pIcon->cClass);
 
526
                g_hash_table_insert (h, g_strdup ("class"), v);
 
527
                
 
528
                v = g_new0 (GValue, 1);
 
529
                g_value_init (v, G_TYPE_STRING);
 
530
                g_value_set_string (v, pIcon->cFileName);
 
531
                g_hash_table_insert (h, g_strdup ("icon"), v);
 
532
                
 
533
                v = g_new0 (GValue, 1);
 
534
                g_value_init (v, G_TYPE_STRING);
 
535
                g_value_set_string (v, pIcon->cQuickInfo);
 
536
                g_hash_table_insert (h, g_strdup ("quick-info"), v);
 
537
                
 
538
                v = g_new0 (GValue, 1);
 
539
                g_value_init (v, G_TYPE_UINT);
 
540
                g_value_set_uint (v, pIcon->Xid);
 
541
                g_hash_table_insert (h, g_strdup ("Xid"), v);
 
542
                
 
543
                iPosition = -1;
 
544
                cContainerName = NULL;
 
545
                if (CAIRO_DOCK_IS_DOCK (pContainer))
 
546
                {
 
547
                        CairoDock *pDock = CAIRO_DOCK (pContainer);
 
548
                        iPosition = g_list_index (pDock->icons, pIcon);
 
549
                        cContainerName = pIcon->cParentDockName;
 
550
                }
 
551
                else if (CAIRO_DOCK_IS_DESKLET (pContainer))
 
552
                {
 
553
                        CairoDesklet *pDesklet = CAIRO_DESKLET (pContainer);
 
554
                        if (pDesklet->pIcon == pIcon)
 
555
                                iPosition = 0;
 
556
                        else
 
557
                                iPosition = g_list_index (pDesklet->icons, pIcon);
 
558
                        if (CAIRO_DOCK_IS_APPLET (pDesklet->pIcon))
 
559
                                cContainerName = pDesklet->pIcon->pModuleInstance->pModule->pVisitCard->cModuleName;
 
560
                }
 
561
                v = g_new0 (GValue, 1);
 
562
                g_value_init (v, G_TYPE_INT);
 
563
                g_value_set_int (v, iPosition);
 
564
                g_hash_table_insert (h, g_strdup ("position"), v);
 
565
                
 
566
                v = g_new0 (GValue, 1);
 
567
                g_value_init (v, G_TYPE_STRING);
 
568
                g_value_set_string (v, cContainerName);
 
569
                g_hash_table_insert (h, g_strdup ("container"), v);
 
570
                
 
571
                v = g_new0 (GValue, 1);
 
572
                g_value_init (v, G_TYPE_DOUBLE);
 
573
                g_value_set_double (v, pIcon->fOrder);
 
574
                g_hash_table_insert (h, g_strdup ("order"), v);
 
575
        }
 
576
        
 
577
        g_list_free (pList);
 
578
        return TRUE;
 
579
}
 
580
 
 
581
static void _set_container_props (CairoContainer *pContainer, GHashTable *h)
 
582
{
 
583
        GValue *v;
 
584
        int x, y, w, ht;
 
585
        if (pContainer->bIsHorizontal)
 
586
        {
 
587
                x = pContainer->iWindowPositionX;
 
588
                y = pContainer->iWindowPositionY;
 
589
                w = pContainer->iWidth;
 
590
                ht = pContainer->iHeight;
 
591
        }
 
592
        else
 
593
        {
 
594
                y = pContainer->iWindowPositionX;
 
595
                x = pContainer->iWindowPositionY;
 
596
                ht = pContainer->iWidth;
 
597
                w = pContainer->iHeight;
 
598
        }
 
599
        v = g_new0 (GValue, 1);
 
600
        g_value_init (v, G_TYPE_INT);
 
601
        g_value_set_int (v, pContainer->iWindowPositionX);
 
602
        g_hash_table_insert (h, g_strdup ("x"), v);
 
603
        
 
604
        v = g_new0 (GValue, 1);
 
605
        g_value_init (v, G_TYPE_INT);
 
606
        g_value_set_int (v, y);
 
607
        g_hash_table_insert (h, g_strdup ("y"), v);
 
608
        
 
609
        v = g_new0 (GValue, 1);
 
610
        g_value_init (v, G_TYPE_INT);
 
611
        g_value_set_int (v, w);
 
612
        g_hash_table_insert (h, g_strdup ("width"), v);
 
613
        
 
614
        v = g_new0 (GValue, 1);
 
615
        g_value_init (v, G_TYPE_INT);
 
616
        g_value_set_int (v, ht);
 
617
        g_hash_table_insert (h, g_strdup ("height"), v);
 
618
        
 
619
        CairoDockPositionType iScreenBorder = ((! pContainer->bIsHorizontal) << 1) | (! pContainer->bDirectionUp);
 
620
        v = g_new0 (GValue, 1);
 
621
        g_value_init (v, G_TYPE_UINT);
 
622
        g_value_set_uint (v, iScreenBorder);
 
623
        g_hash_table_insert (h, g_strdup ("orientation"), v);
 
624
}
 
625
static void _insert_dock_props (const gchar *cDockName, CairoDock *pDock, GPtrArray *pTab)
 
626
{
 
627
        GHashTable *h = g_hash_table_new_full (g_str_hash,
 
628
                g_str_equal,
 
629
                g_free,  /// can we use const char here instead of duplicating each string ?...
 
630
                g_free);
 
631
        g_ptr_array_add (pTab, h);
 
632
        
 
633
        GValue *v;
 
634
        
 
635
        v = g_new0 (GValue, 1);
 
636
        g_value_init (v, G_TYPE_STRING);
 
637
        g_value_set_string (v, "Dock");
 
638
        g_hash_table_insert (h, g_strdup ("type"), v);
 
639
        
 
640
        v = g_new0 (GValue, 1);
 
641
        g_value_init (v, G_TYPE_STRING);
 
642
        g_value_set_string (v, cDockName);
 
643
        g_hash_table_insert (h, g_strdup ("name"), v);
 
644
        
 
645
        v = g_new0 (GValue, 1);
 
646
        g_value_init (v, G_TYPE_BOOLEAN);
 
647
        g_value_set_boolean (v, (pDock->iRefCount > 0));
 
648
        g_hash_table_insert (h, g_strdup ("is-sub-dock"), v);
 
649
        
 
650
        v = g_new0 (GValue, 1);
 
651
        g_value_init (v, G_TYPE_INT);
 
652
        g_value_set_int (v, g_list_length (pDock->icons));
 
653
        g_hash_table_insert (h, g_strdup ("nb-icons"), v);
 
654
        
 
655
        _set_container_props (CAIRO_CONTAINER (pDock), h);
 
656
}
 
657
static gboolean _insert_desklet_props (CairoDesklet *pDesklet, GPtrArray *pTab)
 
658
{
 
659
        GHashTable *h = g_hash_table_new_full (g_str_hash,
 
660
                g_str_equal,
 
661
                g_free,  /// can we use const char here instead of duplicating each string ?...
 
662
                g_free);
 
663
        g_ptr_array_add (pTab, h);
 
664
        
 
665
        GValue *v;
 
666
        
 
667
        v = g_new0 (GValue, 1);
 
668
        g_value_init (v, G_TYPE_STRING);
 
669
        g_value_set_string (v, "Desklet");
 
670
        g_hash_table_insert (h, g_strdup ("type"), v);
 
671
        
 
672
        v = g_new0 (GValue, 1);
 
673
        g_value_init (v, G_TYPE_STRING);
 
674
        g_value_set_string (v, CAIRO_DOCK_IS_APPLET (pDesklet->pIcon) ? pDesklet->pIcon->pModuleInstance->pModule->pVisitCard->cModuleName : "");
 
675
        g_hash_table_insert (h, g_strdup ("name"), v);
 
676
        
 
677
        v = g_new0 (GValue, 1);
 
678
        g_value_init (v, G_TYPE_INT);
 
679
        g_value_set_int (v, 1 + g_list_length (pDesklet->icons));
 
680
        g_hash_table_insert (h, g_strdup ("nb-icons"), v);
 
681
        
 
682
        _set_container_props (CAIRO_CONTAINER (pDesklet), h);
 
683
        return FALSE;
 
684
}
 
685
static gboolean _check_desklet_name (CairoDesklet *pDesklet, const gchar *cName)
 
686
{
 
687
        if (CAIRO_DOCK_IS_APPLET (pDesklet->pIcon))
 
688
        {
 
689
                return (strcmp (cName, pDesklet->pIcon->pModuleInstance->pModule->pVisitCard->cModuleName) == 0);
 
690
        }
 
691
        return FALSE;
 
692
}
 
693
gboolean cd_dbus_main_get_container_properties (dbusMainObject *pDbusCallback, const gchar *cName, GPtrArray **pAttributes, GError **error)
 
694
{
 
695
        nullify_argument (cName);
 
696
        
 
697
        GPtrArray *pTab = g_ptr_array_new ();
 
698
        *pAttributes = pTab;
 
699
        
 
700
        if (cName == NULL)
 
701
        {
 
702
                cairo_dock_foreach_docks ((GHFunc)_insert_dock_props, pTab);
 
703
                cairo_dock_foreach_desklet ((CairoDockForeachDeskletFunc) _insert_desklet_props, pTab);
 
704
        }
 
705
        else
 
706
        {
 
707
                CairoDock *pDock = cairo_dock_search_dock_from_name (cName);
 
708
                if (pDock != NULL)
 
709
                {
 
710
                        _insert_dock_props (cName, pDock, pTab);
 
711
                }
 
712
                else
 
713
                {
 
714
                        CairoDesklet *pDesklet = cairo_dock_foreach_desklet ((CairoDockForeachDeskletFunc) _check_desklet_name, (gpointer)cName);
 
715
                        if (pDesklet != NULL)
 
716
                        {
 
717
                                _insert_desklet_props (pDesklet, pTab);
 
718
                        }
 
719
                }
 
720
        }
 
721
        
 
722
        return TRUE;
 
723
}
 
724
 
 
725
static gboolean _insert_module_props (CairoDockModule *pModule, GPtrArray *pTab)
 
726
{
 
727
        GHashTable *h = g_hash_table_new_full (g_str_hash,
 
728
                g_str_equal,
 
729
                g_free,  /// can we use const char here instead of duplicating each string ?...
 
730
                g_free);
 
731
        g_ptr_array_add (pTab, h);
 
732
        
 
733
        GValue *v;
 
734
        
 
735
        v = g_new0 (GValue, 1);
 
736
        g_value_init (v, G_TYPE_STRING);
 
737
        g_value_set_string (v, pModule->pVisitCard->cModuleName);
 
738
        g_hash_table_insert (h, g_strdup ("name"), v);
 
739
        
 
740
        v = g_new0 (GValue, 1);
 
741
        g_value_init (v, G_TYPE_UINT);
 
742
        g_value_set_uint (v, pModule->pVisitCard->iContainerType);
 
743
        g_hash_table_insert (h, g_strdup ("type"), v);
 
744
        
 
745
        v = g_new0 (GValue, 1);
 
746
        g_value_init (v, G_TYPE_UINT);
 
747
        g_value_set_uint (v, pModule->pVisitCard->iCategory);
 
748
        g_hash_table_insert (h, g_strdup ("category"), v);
 
749
        
 
750
        v = g_new0 (GValue, 1);
 
751
        g_value_init (v, G_TYPE_STRING);
 
752
        g_value_set_string (v, pModule->pVisitCard->cTitle);
 
753
        g_hash_table_insert (h, g_strdup ("title"), v);
 
754
        
 
755
        v = g_new0 (GValue, 1);
 
756
        g_value_init (v, G_TYPE_STRING);
 
757
        g_value_set_string (v, pModule->pVisitCard->cIconFilePath);
 
758
        g_hash_table_insert (h, g_strdup ("icon"), v);
 
759
        
 
760
        v = g_new0 (GValue, 1);
 
761
        g_value_init (v, G_TYPE_STRING);
 
762
        g_value_set_string (v, pModule->pVisitCard->cPreviewFilePath);
 
763
        g_hash_table_insert (h, g_strdup ("preview"), v);
 
764
        
 
765
        v = g_new0 (GValue, 1);
 
766
        g_value_init (v, G_TYPE_STRING);
 
767
        g_value_set_string (v, dgettext (pModule->pVisitCard->cGettextDomain, pModule->pVisitCard->cDescription));
 
768
        g_hash_table_insert (h, g_strdup ("description"), v);
 
769
        
 
770
        v = g_new0 (GValue, 1);
 
771
        g_value_init (v, G_TYPE_STRING);
 
772
        g_value_set_string (v, pModule->pVisitCard->cAuthor);
 
773
        g_hash_table_insert (h, g_strdup ("author"), v);
 
774
        
 
775
        v = g_new0 (GValue, 1);
 
776
        g_value_init (v, G_TYPE_BOOLEAN);
 
777
        g_value_set_boolean (v, pModule->pVisitCard->bMultiInstance);
 
778
        g_hash_table_insert (h, g_strdup ("is-multi-instance"), v);
 
779
        
 
780
        g_print ("list instances ...\n");
 
781
        gchar **pInstances = g_new0 (gchar*, g_list_length (pModule->pInstancesList)+1);
 
782
        CairoDockModuleInstance *pInstance;
 
783
        int i = 0;
 
784
        GList *mi;
 
785
        for (mi = pModule->pInstancesList; mi != NULL; mi = mi->next)
 
786
        {
 
787
                pInstance = mi->data;
 
788
                pInstances[i++] = g_strdup (pInstance->cConfFilePath);
 
789
        }
 
790
        g_print ("write instances ...\n");
 
791
        v = g_new0 (GValue, 1);
 
792
        g_value_init (v, G_TYPE_STRV);
 
793
        g_value_set_boxed (v, pInstances);
 
794
        g_hash_table_insert (h, g_strdup ("instances"), v);
 
795
        g_print ("done.\n");
 
796
        return TRUE;  // continue
 
797
}
 
798
gboolean cd_dbus_main_get_module_properties (dbusMainObject *pDbusCallback, const gchar *cName, GPtrArray **pAttributes, GError **error)
 
799
{
 
800
        nullify_argument (cName);
 
801
        
 
802
        GPtrArray *pTab = g_ptr_array_new ();
 
803
        *pAttributes = pTab;
 
804
        
 
805
        if (cName == NULL)
 
806
        {
 
807
                cairo_dock_foreach_module_in_alphabetical_order ((GCompareFunc) _insert_module_props, pTab);
 
808
        }
 
809
        else
 
810
        {
 
811
                CairoDockModule *pModule = cairo_dock_find_module_from_name (cName);
 
812
                if (pModule != NULL)
 
813
                {
 
814
                        _insert_module_props (pModule, pTab);
 
815
                }
 
816
        }
 
817
        return TRUE;
 
818
}
 
819
 
 
820
gboolean cd_dbus_main_add_launcher (dbusMainObject *pDbusCallback, const gchar *cDesktopFilePath, gdouble fOrder, const gchar *cDockName, gchar **cLauncherFile, GError **error)
 
821
{
 
822
        *cLauncherFile = NULL;
 
823
        if (! myConfig.bEnableCreateLauncher)
 
824
                return FALSE;
 
825
        g_return_val_if_fail (cDesktopFilePath != NULL, FALSE);
 
826
        
 
827
        //\_______________ get the dock where to insert the icon.
 
828
        nullify_argument (cDockName);
 
829
        if (cDockName == NULL)
 
830
                cDockName = CAIRO_DOCK_MAIN_DOCK_NAME;
 
831
        
 
832
        CairoDock * pParentDock = cairo_dock_search_dock_from_name (cDockName);
 
833
        if (pParentDock == NULL)
 
834
        {
 
835
                cd_warning ("dock %s does not exist", cDockName);
 
836
                pParentDock = g_pMainDock;
 
837
        }
 
838
        
 
839
        //\_______________ add a new icon in the current theme.
 
840
        int iLauncherType = -1;
 
841
        if (strcmp (cDesktopFilePath, "separator.desktop") == 0)
 
842
                iLauncherType = CAIRO_DOCK_DESKTOP_FILE_FOR_SEPARATOR;
 
843
        else if (strcmp (cDesktopFilePath, "container.desktop") == 0)
 
844
                iLauncherType = CAIRO_DOCK_DESKTOP_FILE_FOR_CONTAINER;
 
845
        else if (strcmp (cDesktopFilePath, "launcher.desktop") == 0)
 
846
                iLauncherType = CAIRO_DOCK_DESKTOP_FILE_FOR_LAUNCHER;
 
847
        
 
848
        if (fOrder < 0)
 
849
                fOrder = CAIRO_DOCK_LAST_ORDER;
 
850
        Icon *pNewIcon;
 
851
        if (iLauncherType != -1)
 
852
                pNewIcon = cairo_dock_add_new_launcher_by_type (iLauncherType, pParentDock, fOrder, CAIRO_DOCK_LAUNCHER);
 
853
        else
 
854
                pNewIcon = cairo_dock_add_new_launcher_by_uri (cDesktopFilePath, pParentDock, fOrder);
 
855
        if (pNewIcon != NULL)
 
856
        {
 
857
                *cLauncherFile = g_strdup (pNewIcon->cDesktopFileName);
 
858
                return TRUE;
 
859
        }
 
860
        else
 
861
                return FALSE;
 
862
}
 
863
 
 
864
gboolean cd_dbus_main_add_temporary_icon (dbusMainObject *pDbusCallback, GHashTable *hIconAttributes, GError **error)
 
865
{
 
866
        if (! myConfig.bEnableCreateLauncher)
 
867
                return FALSE;
 
868
        
 
869
        g_return_val_if_fail (hIconAttributes != NULL, FALSE);
 
870
        
 
871
        //\_______________ get the attributes.
 
872
        GValue *v;
 
873
        const gchar *cType = "Launcher";
 
874
        v = g_hash_table_lookup (hIconAttributes, "type");
 
875
        if (v && G_VALUE_HOLDS_STRING (v))
 
876
        {
 
877
                cType = g_value_get_string (v);
 
878
        }
 
879
        
 
880
        const gchar *cIcon = NULL;
 
881
        v = g_hash_table_lookup (hIconAttributes, "icon");
 
882
        if (v && G_VALUE_HOLDS_STRING (v))
 
883
        {
 
884
                cIcon = g_value_get_string (v);
 
885
        }
 
886
        
 
887
        const gchar *cName = NULL;
 
888
        v = g_hash_table_lookup (hIconAttributes, "name");
 
889
        if (!v)
 
890
                v = g_hash_table_lookup (hIconAttributes, "label");
 
891
        if (v && G_VALUE_HOLDS_STRING (v))
 
892
        {
 
893
                cName = g_value_get_string (v);
 
894
        }
 
895
        
 
896
        const gchar *cParentDockName = CAIRO_DOCK_MAIN_DOCK_NAME;
 
897
        v = g_hash_table_lookup (hIconAttributes, "container");
 
898
        if (v && G_VALUE_HOLDS_STRING (v))
 
899
        {
 
900
                cParentDockName = g_value_get_string (v);
 
901
        }
 
902
        
 
903
        const gchar *cQuickInfo = NULL;
 
904
        v = g_hash_table_lookup (hIconAttributes, "quick-info");
 
905
        if (v && G_VALUE_HOLDS_STRING (v))
 
906
        {
 
907
                cQuickInfo = g_value_get_string (v);
 
908
        }
 
909
        
 
910
        double fOrder = CAIRO_DOCK_LAST_ORDER;
 
911
        v = g_hash_table_lookup (hIconAttributes, "order");
 
912
        if (v && G_VALUE_HOLDS_DOUBLE (v))
 
913
        {
 
914
                fOrder = g_value_get_double (v);
 
915
        }
 
916
        
 
917
        int iPosition = -1;
 
918
        v = g_hash_table_lookup (hIconAttributes, "position");
 
919
        if (v && G_VALUE_HOLDS_INT (v))
 
920
        {
 
921
                iPosition = g_value_get_int (v);
 
922
        }
 
923
        
 
924
        const gchar *cCommand = NULL;
 
925
        v = g_hash_table_lookup (hIconAttributes, "command");
 
926
        if (v && G_VALUE_HOLDS_STRING (v))
 
927
        {
 
928
                cCommand = g_value_get_string (v);
 
929
        }
 
930
        
 
931
        const gchar *cClass = NULL;
 
932
        v = g_hash_table_lookup (hIconAttributes, "class");
 
933
        if (v && G_VALUE_HOLDS_STRING (v))
 
934
        {
 
935
                cClass = g_value_get_string (v);  // "none" to skip taskbar
 
936
        }
173
937
        
174
938
        CairoDock *pParentDock = cairo_dock_search_dock_from_name (cParentDockName);
175
939
        if (pParentDock == NULL)
176
940
        {
177
 
                cd_message ("le dock parent (%s) n'existe pas, on le cree", cParentDockName);
178
 
                pParentDock = cairo_dock_create_dock (cParentDockName, NULL);
179
 
        }
180
 
        
181
 
        Icon *pIcon = cairo_dock_create_dummy_launcher (g_strdup (cLabel),
182
 
                g_strdup (cIconFile),
183
 
                g_strdup (cCommand),
184
 
                NULL,
185
 
                CAIRO_DOCK_LAST_ORDER);
 
941
                cd_warning ("dock %s does not exist", cParentDockName);
 
942
                pParentDock = g_pMainDock;
 
943
        }
 
944
        
 
945
        if (iPosition > -1)  // the position will overwrite the order if ever both are defined.
 
946
        {
 
947
                fOrder = 0;
 
948
                Icon *nth_icon;
 
949
                double nth_order = -1;
 
950
                int i;
 
951
                GList *ic;
 
952
                for (i = 0, ic = pParentDock->icons; i < iPosition && ic != NULL; i ++, ic = ic->next)
 
953
                {
 
954
                        nth_icon = ic->data;
 
955
                        nth_order = nth_icon->fOrder;
 
956
                }
 
957
                if (ic == NULL)  // not enough icons, place the new one just after the last one.
 
958
                {
 
959
                        fOrder = nth_order + 1;
 
960
                }
 
961
                else
 
962
                {
 
963
                        nth_icon = ic->data;
 
964
                        fOrder = (nth_order + nth_icon->fOrder) / 2;
 
965
                }
 
966
        }
 
967
        
 
968
        //\_______________ create a corresponding icon.
 
969
        Icon *pIcon;
 
970
        if (cType == NULL || strcmp (cType, "Launcher") == 0)
 
971
        {
 
972
                pIcon = cairo_dock_create_dummy_launcher (g_strdup (cName),
 
973
                        g_strdup (cIcon),
 
974
                        g_strdup (cCommand),
 
975
                        g_strdup (cQuickInfo),
 
976
                        fOrder);
 
977
                pIcon->iTrueType = CAIRO_DOCK_ICON_TYPE_LAUNCHER;  // make it a launcher, since we have no control on it, so that the dock handles it as any launcher.
 
978
                if (cClass == NULL)
 
979
                {
 
980
                        gchar *cGuessedClass = cairo_dock_guess_class (cCommand, NULL);
 
981
                        pIcon->cClass = cairo_dock_register_class (cGuessedClass);
 
982
                        g_free (cGuessedClass);
 
983
                }
 
984
                else if (strcmp (cClass, "none") != 0)
 
985
                {
 
986
                        pIcon->cClass = cairo_dock_register_class (cClass);
 
987
                        if (pIcon->cClass == NULL)  // if we couldn't find the class desktop file, set the class anyway, since it was explicitely specified; the method caller probably knows more than us what he's doing.
 
988
                                pIcon->cClass = g_strdup (cClass);
 
989
                }
 
990
        }
 
991
        else if (strcmp (cType, "Container") == 0)
 
992
        {
 
993
                int iSubdockViewType = 0;
 
994
                if (!cIcon || strcmp (cIcon, "Box") == 0)
 
995
                {
 
996
                        iSubdockViewType = 3;
 
997
                        cIcon = NULL;
 
998
                }
 
999
                else if (strcmp (cIcon, "Stack") == 0)
 
1000
                {
 
1001
                        iSubdockViewType = 2;
 
1002
                        cIcon = NULL;
 
1003
                }
 
1004
                else if (strcmp (cIcon, "Emblems") == 0)
 
1005
                {
 
1006
                        iSubdockViewType = 1;
 
1007
                        cIcon = NULL;
 
1008
                }
 
1009
                gchar *cUniqueName = cairo_dock_get_unique_dock_name (cName);
 
1010
                pIcon = cairo_dock_create_dummy_launcher (cUniqueName,
 
1011
                        g_strdup (cIcon),
 
1012
                        NULL,
 
1013
                        NULL,
 
1014
                        fOrder);
 
1015
                pIcon->iTrueType = CAIRO_DOCK_ICON_TYPE_CONTAINER;
 
1016
                pIcon->iSubdockViewType = iSubdockViewType;
 
1017
                pIcon->pSubDock = cairo_dock_create_subdock_from_scratch (NULL, pIcon->cName, pParentDock);  // NULL <=> default sub-docks view.
 
1018
        }
 
1019
        else if (strcmp (cType, "Separator") == 0)
 
1020
        {
 
1021
                pIcon = cairo_dock_create_separator_icon (CAIRO_DOCK_LAUNCHER, NULL);  // NULL because we'll load the icon ourselves later.
 
1022
        }
 
1023
        else
 
1024
        {
 
1025
                cd_warning ("type '%s' invalid", cType);
 
1026
                return FALSE;
 
1027
        }
186
1028
        pIcon->cParentDockName = g_strdup (cParentDockName);
187
 
        cairo_dock_set_launcher_class (pIcon, NULL);
188
1029
        
 
1030
        //\_______________ load it inside the dock.
189
1031
        cairo_dock_load_icon_buffers (pIcon, CAIRO_CONTAINER (pParentDock));
190
1032
        
191
1033
        cairo_dock_insert_icon_in_dock (pIcon, pParentDock, CAIRO_DOCK_UPDATE_DOCK_SIZE, CAIRO_DOCK_ANIMATE_ICON);
192
 
        cairo_dock_launch_animation (CAIRO_CONTAINER (pParentDock));
 
1034
        cairo_dock_start_icon_animation (pIcon, pParentDock);
193
1035
        
194
1036
        if (pIcon->cClass != NULL)
195
1037
        {
199
1041
        return TRUE;
200
1042
}
201
1043
 
202
 
gboolean cd_dbus_main_load_launcher_from_file (dbusMainObject *pDbusCallback, const gchar *cDesktopFile, GError **error)  // pris de cairo_dock_add_new_launcher_by_uri().
203
 
{
204
 
        if (! myConfig.bEnableTweakingLauncher)
205
 
                return FALSE;
206
 
        g_return_val_if_fail (cDesktopFile != NULL, FALSE);
207
 
        
208
 
        Icon *pIcon = cairo_dock_create_icon_from_desktop_file (cDesktopFile);
209
 
        
210
 
        if (pIcon == NULL)
211
 
        {
212
 
                cd_warning ("the icon couldn't be created, check that the file '%s' exists and is a valid and readable .desktop file\n", cDesktopFile);
213
 
                return FALSE;
214
 
        }
215
 
        
216
 
        CairoDock * pParentDock = cairo_dock_search_dock_from_name (pIcon->cParentDockName);
217
 
        if (pParentDock != NULL)  // a priori toujours vrai puisqu'il est cree au besoin. En fait c'est probablement le main dock pour un .desktop de base.
218
 
        {
219
 
                cairo_dock_insert_icon_in_dock (pIcon, pParentDock, CAIRO_DOCK_UPDATE_DOCK_SIZE, CAIRO_DOCK_ANIMATE_ICON);
220
 
                cairo_dock_start_icon_animation (pIcon, pParentDock);
221
 
        }
222
 
        cd_debug (" => cDesktopFileName : %s\n", pIcon->cDesktopFileName);
223
 
        
224
 
        return TRUE;
225
 
}
226
 
 
227
1044
static void _find_launcher_in_dock (Icon *pIcon, CairoDock *pDock, gpointer *data)
228
1045
{
229
1046
        gchar *cDesktopFile = data[0];
230
1047
        Icon **pFoundIcon = data[1];
231
 
        if (pIcon->cDesktopFileName && g_ascii_strncasecmp (cDesktopFile, pIcon->cDesktopFileName, strlen (cDesktopFile)) == 0)
 
1048
        if ((pIcon->cDesktopFileName && g_ascii_strncasecmp (cDesktopFile, pIcon->cDesktopFileName, strlen (cDesktopFile)) == 0)
 
1049
        || (pIcon->cCommand && g_ascii_strncasecmp (cDesktopFile, pIcon->cCommand, strlen (cDesktopFile)) == 0))
232
1050
        {
233
1051
                *pFoundIcon = pIcon;
234
1052
        }
235
1053
}
236
 
Icon *cd_dbus_find_launcher (const gchar *cDesktopFile)
 
1054
static Icon *cd_dbus_find_launcher (const gchar *cDesktopFile)
237
1055
{
238
1056
        Icon *pIcon = NULL;
239
1057
        gpointer data[2];
243
1061
        return pIcon;
244
1062
}
245
1063
 
246
 
gboolean cd_dbus_main_reload_launcher (dbusMainObject *pDbusCallback, const gchar *cDesktopFile, GError **error)
247
 
{
248
 
        if (! myConfig.bEnableTweakingLauncher)
249
 
                return FALSE;
250
 
        
251
 
        nullify_argument (cDesktopFile);
252
 
        g_return_val_if_fail (cDesktopFile != NULL, FALSE);
253
 
        
254
 
        Icon *pIcon = cd_dbus_find_launcher (cDesktopFile);
255
 
        if (pIcon == NULL)
256
 
                return FALSE;
257
 
        
258
 
        cairo_dock_reload_launcher (pIcon);
259
 
        
260
 
        return TRUE;
261
 
}
262
 
 
263
 
gboolean cd_dbus_main_remove_launcher (dbusMainObject *pDbusCallback, const gchar *cDesktopFile, GError **error)
264
 
{
265
 
        if (! myConfig.bEnableTweakingLauncher)
266
 
                return FALSE;
267
 
        
268
 
        nullify_argument (cDesktopFile);
269
 
        g_return_val_if_fail (cDesktopFile != NULL, FALSE);
270
 
        
271
 
        Icon *pIcon = cd_dbus_find_launcher (cDesktopFile);
272
 
        if (pIcon == NULL)
273
 
                return FALSE;
274
 
        
275
 
        if (pIcon->pSubDock != NULL)  // on detruit le sous-dock et ce qu'il contient.
276
 
        {
277
 
                cairo_dock_destroy_dock (pIcon->pSubDock, (pIcon->cClass != NULL ? pIcon->cClass : pIcon->cName));
278
 
                pIcon->pSubDock = NULL;
279
 
        }
280
 
        
281
 
        cairo_dock_trigger_icon_removal_from_dock (pIcon);
282
 
        
283
 
        return TRUE;
284
 
}
285
 
 
286
 
 
287
 
 
288
 
 
289
 
static void _find_icon_in_dock (Icon *pIcon, CairoDock *pDock, gpointer *data)
290
 
{
291
 
        gchar *cIconName = data[0];
292
 
        gchar *cIconCommand = data[1];
293
 
        Icon **pFoundIcon = data[2];
294
 
        gchar *cName = (pIcon->cInitialName != NULL ? pIcon->cInitialName : pIcon->cName);
295
 
        //g_print ("%s (%s/%s, %s/%s)\n", __func__, cName, cIconName, pIcon->cCommand, cIconCommand);
296
 
        if ((cIconName == NULL || (cName && g_ascii_strncasecmp (cIconName, cName, strlen (cIconName)) == 0)) &&
297
 
                (cIconCommand == NULL || (pIcon->cCommand && g_ascii_strncasecmp (cIconCommand, pIcon->cCommand, strlen (cIconCommand)) == 0) || (pIcon->cClass && g_ascii_strncasecmp (cIconCommand, pIcon->cClass, strlen (cIconCommand)) == 0)))  // si un des parametre est non nul, alors on exige qu'il corresponde. 'cIconCommand' peut correspondre soit avec la commande, soit avec la classe.
298
 
        {
299
 
                Icon *icon = *pFoundIcon;
300
 
                if (icon != NULL)  // on avait deja trouve une icone avant.
301
 
                {
302
 
                        cName = (pIcon->cInitialName != NULL ? pIcon->cInitialName : pIcon->cName);
303
 
                        if ((cIconName && cName && g_ascii_strcasecmp (cIconName, cName) == 0) ||
304
 
                                (cIconCommand && pIcon->cCommand && g_ascii_strcasecmp (cIconCommand, pIcon->cCommand)))  // elle satisfait entierement aux criteres, donc on la garde.
305
 
                                return ;
306
 
                }
307
 
                *pFoundIcon = pIcon;
308
 
        }
309
 
}
310
 
Icon *cd_dbus_find_icon (const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName)
311
 
{
312
 
        Icon *pIcon = NULL;
313
 
        if (cModuleName != NULL)  // c'est une icone d'un des modules.
314
 
        {
315
 
                CairoDockModule *pModule = cairo_dock_find_module_from_name (cModuleName);
316
 
                g_return_val_if_fail (pModule != NULL, FALSE);
317
 
                
318
 
                if (pModule->pInstancesList != NULL)
319
 
                {
320
 
                        CairoDockModuleInstance *pModuleInstance = pModule->pInstancesList->data;
321
 
                        if (pModuleInstance != NULL)
322
 
                                pIcon = pModuleInstance->pIcon;
323
 
                }
324
 
        }
325
 
        else if (cIconName || cIconCommand) // on cherche une icone de lanceur.
326
 
        {
327
 
                gpointer data[3];
328
 
                data[0] = (gpointer) cIconName;
329
 
                data[1] = (gpointer) cIconCommand;
330
 
                data[2] = &pIcon;
331
 
                cairo_dock_foreach_icons_in_docks ((CairoDockForeachIconFunc) _find_icon_in_dock, data);
332
 
        }
333
 
        return pIcon;
334
 
}
335
 
gboolean cd_dbus_main_set_quick_info (dbusMainObject *pDbusCallback, const gchar *cQuickInfo, const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName, GError **error)
 
1064
gboolean cd_dbus_main_reload_icon (dbusMainObject *pDbusCallback, gchar *cIconQuery, GError **error)
 
1065
{
 
1066
        if (! myConfig.bEnableTweakingLauncher)
 
1067
                return FALSE;
 
1068
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1069
        if (pList == NULL)
 
1070
                return FALSE;
 
1071
        
 
1072
        Icon *pIcon;
 
1073
        CairoContainer *pContainer;
 
1074
        GList *ic;
 
1075
        for (ic = pList; ic != NULL; ic = ic->next)
 
1076
        {
 
1077
                pIcon = ic->data;
 
1078
                
 
1079
                if ((CAIRO_DOCK_ICON_TYPE_IS_LAUNCHER (pIcon)
 
1080
                        || CAIRO_DOCK_ICON_TYPE_IS_CONTAINER (pIcon)
 
1081
                        || CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon))
 
1082
                && pIcon->cDesktopFileName != NULL)  // user icon.
 
1083
                {
 
1084
                        cairo_dock_reload_launcher (pIcon);
 
1085
                }
 
1086
                else if (CAIRO_DOCK_IS_APPLET (pIcon))
 
1087
                {
 
1088
                        cairo_dock_reload_module_instance (pIcon->pModuleInstance, TRUE);  // TRUE <=> reload config.
 
1089
                }
 
1090
                else  // for appli icons, reload their image (custom image for instance).
 
1091
                {
 
1092
                        pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1093
                        if (pContainer == NULL)
 
1094
                                continue;
 
1095
                        
 
1096
                        cairo_dock_reload_icon_image (pIcon, pContainer);
 
1097
                        cairo_dock_redraw_icon (pIcon, pContainer);
 
1098
                }
 
1099
        }
 
1100
        
 
1101
        return TRUE;
 
1102
}
 
1103
 
 
1104
static gboolean _on_icon_deleted (GList *ic, Icon *pIcon)
 
1105
{
 
1106
        ic->data = NULL;
 
1107
}
 
1108
gboolean cd_dbus_main_remove_icon (dbusMainObject *pDbusCallback, gchar *cIconQuery, GError **error)
 
1109
{
 
1110
        if (! myConfig.bEnableTweakingLauncher)
 
1111
                return FALSE;
 
1112
        
 
1113
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1114
        if (pList == NULL)
 
1115
                return FALSE;
 
1116
        
 
1117
        // first connect to the "delete" signal, to not destroy 2 times an icon (case of an icon in a sub-dock that is destroyed just before).
 
1118
        Icon *pIcon;
 
1119
        CairoContainer *pContainer;
 
1120
        GList *ic;
 
1121
        for (ic = pList; ic != NULL; ic = ic->next)
 
1122
        {
 
1123
                pIcon = ic->data;
 
1124
                cairo_dock_register_notification_on_object (pIcon,
 
1125
                        NOTIFICATION_STOP_ICON,
 
1126
                        (CairoDockNotificationFunc) _on_icon_deleted,
 
1127
                        CAIRO_DOCK_RUN_FIRST, ic);
 
1128
        }
 
1129
        
 
1130
        // delete all the matching icons, including their sub-icons.
 
1131
        for (ic = pList; ic != NULL; ic = ic->next)
 
1132
        {
 
1133
                pIcon = ic->data;
 
1134
                if (pIcon == NULL)  // icon has been destroyed just before.
 
1135
                        continue;
 
1136
                
 
1137
                cairo_dock_remove_notification_func_on_object (pIcon,
 
1138
                        NOTIFICATION_STOP_ICON,
 
1139
                        (CairoDockNotificationFunc) _on_icon_deleted,
 
1140
                        ic);  // remove it now, since maybe this icon won't be deleted.
 
1141
                
 
1142
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1143
                if (pContainer == NULL)
 
1144
                        continue;
 
1145
                
 
1146
                if (CAIRO_DOCK_ICON_TYPE_IS_LAUNCHER (pIcon)
 
1147
                || CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)
 
1148
                || CAIRO_DOCK_ICON_TYPE_IS_CONTAINER (pIcon))  // case of a launcher/separator/sub-dock inside a dock.
 
1149
                {
 
1150
                        if (pIcon->pSubDock != NULL)  // on detruit le sous-dock et ce qu'il contient.
 
1151
                        {
 
1152
                                cairo_dock_destroy_dock (pIcon->pSubDock, (pIcon->cClass != NULL ? pIcon->cClass : pIcon->cName));
 
1153
                                pIcon->pSubDock = NULL;
 
1154
                        }
 
1155
 
 
1156
                        cairo_dock_trigger_icon_removal_from_dock (pIcon);
 
1157
                }
 
1158
                else if (CAIRO_DOCK_IS_APPLET (pIcon))  // case of an applet inside a dock or a desklet.
 
1159
                {
 
1160
                        cairo_dock_remove_module_instance (pIcon->pModuleInstance);
 
1161
                }  // don't remove appli icons, as they would anyway be re-created automatically by the applications-manager.
 
1162
        }
 
1163
        
 
1164
        g_list_free (pList);
 
1165
        return TRUE;
 
1166
}
 
1167
 
 
1168
 
 
1169
  ///////////////////
 
1170
 /// SET ON ICON ///
 
1171
///////////////////
 
1172
 
 
1173
gboolean cd_dbus_main_set_quick_info (dbusMainObject *pDbusCallback, const gchar *cQuickInfo, gchar *cIconQuery, GError **error)
336
1174
{
337
1175
        if (! myConfig.bEnableSetQuickInfo)
338
1176
                return FALSE;
339
1177
        
340
 
        nullify_argument (cIconName);
341
 
        nullify_argument (cIconCommand);
342
 
        nullify_argument (cModuleName);
 
1178
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1179
        if (pList == NULL)
 
1180
                return FALSE;
 
1181
        
343
1182
        nullify_argument (cQuickInfo);
344
1183
        
345
 
        Icon *pIcon = cd_dbus_find_icon (cIconName, cIconCommand, cModuleName);
346
 
        if (pIcon == NULL)
347
 
                return FALSE;
348
 
        
349
 
        CairoContainer *pContainer = cairo_dock_search_container_from_icon (pIcon);
350
 
        g_return_val_if_fail (pContainer != NULL, FALSE);
351
 
        
352
 
        cairo_dock_set_quick_info (pIcon, pContainer, cQuickInfo);
353
 
        cairo_dock_redraw_icon (pIcon, pContainer);
 
1184
        Icon *pIcon;
 
1185
        CairoContainer *pContainer;
 
1186
        GList *ic;
 
1187
        for (ic = pList; ic != NULL; ic = ic->next)
 
1188
        {
 
1189
                pIcon = ic->data;
 
1190
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1191
                if (pContainer == NULL)
 
1192
                        continue;
 
1193
                
 
1194
                cairo_dock_set_quick_info (pIcon, pContainer, cQuickInfo);
 
1195
                cairo_dock_redraw_icon (pIcon, pContainer);
 
1196
        }
 
1197
        
 
1198
        g_list_free (pList);
354
1199
        return TRUE;
355
1200
}
356
1201
 
357
 
gboolean cd_dbus_main_set_label (dbusMainObject *pDbusCallback, const gchar *cLabel, const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName, GError **error)
 
1202
gboolean cd_dbus_main_set_label (dbusMainObject *pDbusCallback, const gchar *cLabel, gchar *cIconQuery, GError **error)
358
1203
{
359
1204
        if (! myConfig.bEnableSetLabel)
360
1205
                return FALSE;
361
1206
        
362
 
        nullify_argument (cIconName);
363
 
        nullify_argument (cIconCommand);
364
 
        nullify_argument (cModuleName);
 
1207
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1208
        if (pList == NULL)
 
1209
                return FALSE;
 
1210
        
365
1211
        nullify_argument (cLabel);
366
1212
        
367
 
        Icon *pIcon = cd_dbus_find_icon (cIconName, cIconCommand, cModuleName);
368
 
        if (pIcon == NULL)
369
 
                return FALSE;
370
 
        
371
 
        CairoContainer *pContainer = cairo_dock_search_container_from_icon (pIcon);
372
 
        g_return_val_if_fail (pContainer != NULL, FALSE);
373
 
        cairo_dock_set_icon_name (cLabel, pIcon, pContainer);
374
 
        return TRUE;
375
 
}
376
 
 
377
 
gboolean cd_dbus_main_set_icon (dbusMainObject *pDbusCallback, const gchar *cImage, const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName, GError **error)
378
 
{
379
 
        if (! myConfig.bEnableSetIcon)
380
 
                return FALSE;
381
 
        
382
 
        nullify_argument (cIconName);
383
 
        nullify_argument (cIconCommand);
384
 
        nullify_argument (cModuleName);
385
 
        
386
 
        Icon *pIcon = cd_dbus_find_icon (cIconName, cIconCommand, cModuleName);
387
 
        if (pIcon == NULL)
388
 
                return FALSE;
389
 
        
390
 
        CairoContainer *pContainer = cairo_dock_search_container_from_icon (pIcon);
391
 
        g_return_val_if_fail (pContainer != NULL, FALSE);
392
 
        g_return_val_if_fail (pIcon->pIconBuffer != NULL, FALSE);
393
 
        cairo_t *pIconContext = cairo_create (pIcon->pIconBuffer);
394
 
        cairo_dock_set_image_on_icon (pIconContext, cImage, pIcon, pContainer);
395
 
        cairo_destroy (pIconContext);
396
 
        cairo_dock_redraw_icon (pIcon, pContainer);
397
 
        return TRUE;
398
 
}
399
 
 
400
 
gboolean cd_dbus_main_set_emblem (dbusMainObject *pDbusCallback, const gchar *cImage, gint iPosition, const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName, GError **error)
401
 
{
402
 
        if (! myConfig.bEnableSetIcon)
403
 
                return FALSE;
404
 
        
405
 
        nullify_argument (cIconName);
406
 
        nullify_argument (cIconCommand);
407
 
        nullify_argument (cModuleName);
408
 
        
409
 
        Icon *pIcon = cd_dbus_find_icon (cIconName, cIconCommand, cModuleName);
410
 
        if (pIcon == NULL)
411
 
                return FALSE;
412
 
        
413
 
        CairoContainer *pContainer = cairo_dock_search_container_from_icon (pIcon);
414
 
        g_return_val_if_fail (pContainer != NULL, FALSE);
415
 
        g_return_val_if_fail (pIcon->pIconBuffer != NULL, FALSE);
416
 
        cairo_t *pIconContext = cairo_create (pIcon->pIconBuffer);
417
 
        
418
 
        CairoEmblem *pEmblem = cairo_dock_make_emblem (cImage, pIcon, pContainer);
419
 
        pEmblem->iPosition = iPosition;
420
 
        cairo_dock_draw_emblem_on_icon (pEmblem, pIcon, pContainer);
421
 
        cairo_dock_free_emblem (pEmblem);
422
 
        
423
 
        cairo_destroy (pIconContext);
424
 
        cairo_dock_redraw_icon (pIcon, pContainer);
425
 
        return TRUE;
426
 
}
427
 
 
428
 
gboolean cd_dbus_main_animate (dbusMainObject *pDbusCallback, const gchar *cAnimation, gint iNbRounds, const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName, GError **error)
 
1213
        Icon *pIcon;
 
1214
        CairoContainer *pContainer;
 
1215
        GList *ic;
 
1216
        for (ic = pList; ic != NULL; ic = ic->next)
 
1217
        {
 
1218
                pIcon = ic->data;
 
1219
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1220
                if (pContainer == NULL)
 
1221
                        continue;
 
1222
                
 
1223
                cairo_dock_set_icon_name (cLabel, pIcon, pContainer);
 
1224
        }
 
1225
        
 
1226
        g_list_free (pList);
 
1227
        return TRUE;
 
1228
}
 
1229
 
 
1230
gboolean cd_dbus_main_set_icon (dbusMainObject *pDbusCallback, const gchar *cImage, gchar *cIconQuery, GError **error)
 
1231
{
 
1232
        if (! myConfig.bEnableSetIcon)
 
1233
                return FALSE;
 
1234
        
 
1235
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1236
        if (pList == NULL)
 
1237
                return FALSE;
 
1238
        
 
1239
        Icon *pIcon;
 
1240
        CairoContainer *pContainer;
 
1241
        GList *ic;
 
1242
        for (ic = pList; ic != NULL; ic = ic->next)
 
1243
        {
 
1244
                pIcon = ic->data;
 
1245
                if (pIcon->pIconBuffer == NULL)
 
1246
                        continue;
 
1247
                
 
1248
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1249
                if (pContainer == NULL)
 
1250
                        continue;
 
1251
                
 
1252
                cairo_t *pIconContext = cairo_create (pIcon->pIconBuffer);
 
1253
                cairo_dock_set_image_on_icon (pIconContext, cImage, pIcon, pContainer);
 
1254
                cairo_destroy (pIconContext);
 
1255
                cairo_dock_redraw_icon (pIcon, pContainer);
 
1256
        }
 
1257
        
 
1258
        g_list_free (pList);
 
1259
        return TRUE;
 
1260
}
 
1261
 
 
1262
gboolean cd_dbus_main_set_emblem (dbusMainObject *pDbusCallback, const gchar *cImage, gint iPosition, gchar *cIconQuery, GError **error)
 
1263
{
 
1264
        if (! myConfig.bEnableSetIcon)
 
1265
                return FALSE;
 
1266
        
 
1267
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1268
        if (pList == NULL)
 
1269
                return FALSE;
 
1270
        
 
1271
        Icon *pIcon;
 
1272
        CairoContainer *pContainer;
 
1273
        GList *ic;
 
1274
        for (ic = pList; ic != NULL; ic = ic->next)
 
1275
        {
 
1276
                pIcon = ic->data;
 
1277
                if (pIcon->pIconBuffer == NULL)
 
1278
                        continue;
 
1279
                
 
1280
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1281
                if (pContainer == NULL)
 
1282
                        continue;
 
1283
                
 
1284
                cairo_t *pIconContext = cairo_create (pIcon->pIconBuffer);
 
1285
        
 
1286
                CairoEmblem *pEmblem = cairo_dock_make_emblem (cImage, pIcon, pContainer);
 
1287
                pEmblem->iPosition = iPosition;
 
1288
                cairo_dock_draw_emblem_on_icon (pEmblem, pIcon, pContainer);
 
1289
                cairo_dock_free_emblem (pEmblem);
 
1290
 
 
1291
                cairo_destroy (pIconContext);
 
1292
                cairo_dock_redraw_icon (pIcon, pContainer);
 
1293
        }
 
1294
        
 
1295
        g_list_free (pList);
 
1296
        return TRUE;
 
1297
}
 
1298
 
 
1299
gboolean cd_dbus_main_animate (dbusMainObject *pDbusCallback, const gchar *cAnimation, gint iNbRounds, gchar *cIconQuery, GError **error)
429
1300
{
430
1301
        if (! myConfig.bEnableAnimateIcon || cAnimation == NULL)
431
1302
                return FALSE;
432
1303
        
433
 
        nullify_argument (cIconName);
434
 
        nullify_argument (cIconCommand);
435
 
        nullify_argument (cModuleName);
436
 
        
437
 
        Icon *pIcon = cd_dbus_find_icon (cIconName, cIconCommand, cModuleName);
438
 
        if (pIcon == NULL)
439
 
                return FALSE;
440
 
        
441
 
        CairoContainer *pContainer = cairo_dock_search_container_from_icon (pIcon);
442
 
        g_return_val_if_fail (pContainer != NULL, FALSE);
443
 
        
444
 
        if (! CAIRO_DOCK_IS_DOCK (pContainer))
445
 
                return FALSE;
446
 
        
447
 
        cairo_dock_request_icon_animation (pIcon, CAIRO_DOCK (pContainer), cAnimation, iNbRounds);
448
 
        return TRUE;
449
 
}
450
 
 
451
 
gboolean cd_dbus_main_show_dialog (dbusMainObject *pDbusCallback, const gchar *message, gint iDuration, const gchar *cIconName, const gchar *cIconCommand, const gchar *cModuleName, GError **error)
 
1304
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1305
        if (pList == NULL)
 
1306
                return FALSE;
 
1307
        
 
1308
        Icon *pIcon;
 
1309
        CairoContainer *pContainer;
 
1310
        GList *ic;
 
1311
        for (ic = pList; ic != NULL; ic = ic->next)
 
1312
        {
 
1313
                pIcon = ic->data;
 
1314
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1315
                if (! CAIRO_DOCK_IS_DOCK (pContainer))
 
1316
                        continue;
 
1317
                cairo_dock_request_icon_animation (pIcon, CAIRO_DOCK (pContainer), cAnimation, iNbRounds);
 
1318
        }
 
1319
        
 
1320
        g_list_free (pList);
 
1321
        return TRUE;
 
1322
}
 
1323
 
 
1324
gboolean cd_dbus_main_demands_attention (dbusMainObject *pDbusCallback, gboolean bStart, const gchar *cAnimation, gchar *cIconQuery, GError **error)
 
1325
{
 
1326
        if (! myConfig.bEnableAnimateIcon)
 
1327
                return FALSE;
 
1328
        
 
1329
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
 
1330
        if (pList == NULL)
 
1331
                return FALSE;
 
1332
        
 
1333
        Icon *pIcon;
 
1334
        CairoContainer *pContainer;
 
1335
        GList *ic;
 
1336
        for (ic = pList; ic != NULL; ic = ic->next)
 
1337
        {
 
1338
                pIcon = ic->data;
 
1339
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1340
                if (! CAIRO_DOCK_IS_DOCK (pContainer))
 
1341
                        continue;
 
1342
                
 
1343
                if (bStart)
 
1344
                {
 
1345
                        cairo_dock_request_icon_attention (pIcon, CAIRO_DOCK (pContainer), cAnimation, 0);  // 0 <=> non-stop.
 
1346
                }
 
1347
                else if (pIcon->bIsDemandingAttention)
 
1348
                {
 
1349
                        cairo_dock_stop_icon_attention (pIcon, CAIRO_DOCK (pContainer));
 
1350
                }
 
1351
        }
 
1352
        
 
1353
        g_list_free (pList);
 
1354
        return TRUE;
 
1355
}
 
1356
 
 
1357
gboolean cd_dbus_main_show_dialog (dbusMainObject *pDbusCallback, const gchar *message, gint iDuration, gchar *cIconQuery, GError **error)
452
1358
{
453
1359
        if (! myConfig.bEnablePopUp)
454
1360
                return FALSE;
455
1361
        g_return_val_if_fail (message != NULL, FALSE);
456
1362
        
457
 
        nullify_argument (cIconName);
458
 
        nullify_argument (cIconCommand);
459
 
        nullify_argument (cModuleName);
 
1363
        GList *pList = cd_dbus_find_matching_icons (cIconQuery);
460
1364
        
461
 
        Icon *pIcon = cd_dbus_find_icon (cIconName, cIconCommand, cModuleName);
462
 
        if (pIcon != NULL)
 
1365
        Icon *pIcon;
 
1366
        CairoContainer *pContainer;
 
1367
        GList *ic;
 
1368
        for (ic = pList; ic != NULL; ic = ic->next)
463
1369
        {
464
 
                CairoContainer *pContainer = cairo_dock_search_container_from_icon (pIcon);
465
 
                if (pContainer != NULL)
466
 
                {
467
 
                        cairo_dock_show_temporary_dialog_with_icon (message, pIcon, pContainer, 1000 * iDuration, "same icon");
468
 
                        return TRUE;
469
 
                }
 
1370
                pIcon = ic->data;
 
1371
                pContainer = cairo_dock_search_container_from_icon (pIcon);
 
1372
                if (! CAIRO_DOCK_IS_DOCK (pContainer))
 
1373
                        continue;
 
1374
                cairo_dock_show_temporary_dialog_with_icon (message, pIcon, pContainer, 1000 * iDuration, "same icon");
 
1375
                break;  // only show 1 dialog.
470
1376
        }
471
1377
        
472
 
        cairo_dock_show_general_message (message, 1000 * iDuration);
473
 
        return TRUE;
474
 
}
475
 
 
476
 
/*gboolean cd_dbus_get_appet_context (dbusMainObject *pDbusCallback, const gchar *cAppletName, GPtrArray **pContext, GError **error)
477
 
{
478
 
        g_return_val_if_fail (cAppletName != NULL, FALSE);
479
 
        
480
 
        // get the applet's object on the bus.
481
 
        
482
 
        
483
 
        // fill the context.
484
 
        GPtrArray *ctx = g_ptr_array_sized_new (4);
485
 
        GValue *v;
486
 
 
487
 
        v = g_new0 (GValue, 1);
488
 
        g_value_init (v, G_TYPE_STRING);
489
 
        g_value_set_string (v, g_get_prgname());
490
 
        g_ptr_array_add (ctx, v);
491
 
 
492
 
        v = g_new0 (GValue, 1);
493
 
        g_value_init (v, G_TYPE_STRING);
494
 
        g_value_set_string (v, g_get_application_name());
495
 
        g_ptr_array_add (ctx, v);
496
 
 
497
 
        v = g_new0 (GValue, 1);
498
 
        g_value_init (v, G_TYPE_STRING);
499
 
        g_value_set_string (v, g_strdup_printf ("%s/%s/%s", ));
500
 
        g_ptr_array_add (ctx, v);
501
 
 
502
 
 
503
 
        
504
 
        return TRUE;
505
 
}
506
 
*/
 
 
b'\\ No newline at end of file'
 
1378
        if (ic == NULL)  // empty list, or didn't find a valid icon.
 
1379
                cairo_dock_show_general_message (message, 1000 * iDuration);
 
1380
        
 
1381
        g_list_free (pList);
 
1382
        return TRUE;
 
1383
}