Debian Codegraph @

Dbus/src/applet-dbus.c

raw
1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /******************************************************************************
21 exemples :
22 ----------
23
24 dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.CreateLauncherFromScratch string:inkscape string:yep string:rien 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
33
34 ******************************************************************************/
35
36 #include <fcntl.h> // O_RDONLY
37 #include <unistd.h> // open, read, close
38 #include <signal.h> // kill
39 #include <glib.h>
40 #include <glib/gstdio.h>
41 #include <dbus/dbus-glib.h>
42 #include <dbus/dbus-glib-bindings.h>
43
44 #ifdef __FreeBSD__
45 #include <kvm.h>
46 #include <sys/param.h>
47 #include <sys/sysctl.h>
48 #include <sys/user.h>
49 #include <limits.h>
50 #endif
51
52 #include "interface-main-methods.h"
53 #include "dbus-main-spec.h"
54 #include "interface-applet-object.h"
55 #include "interface-applet-signals.h"
56 #include "applet-dbus.h"
57
58 #define DISTANT_DIR "3.4.0"
59 #define GETTEXT_NAME_EXTRAS "cairo-dock-plugins-extra"
60 #define LOCALE_DIR_NAME "locale"
61
62 ///////////////////
63 /// MAIN OBJECT ///
64 ///////////////////
65
66 G_DEFINE_TYPE(dbusMainObject, cd_dbus_main, G_TYPE_OBJECT);
67
68 static void cd_dbus_main_class_init(dbusMainObjectClass *klass)
69 {
70 cd_message("");
71 }
72 static void cd_dbus_main_init (dbusMainObject *pMainObject)
73 {
74 cd_message("");
75
76 // Initialise the DBus connection
77 pMainObject->connection = cairo_dock_get_session_connection ();
78
79 dbus_g_object_type_install_info(cd_dbus_main_get_type(), &dbus_glib_cd_dbus_main_object_info);
80
81 // Register DBUS path
82 dbus_g_connection_register_g_object(pMainObject->connection, myData.cBasePath, G_OBJECT(pMainObject));
83 }
84
85
86 //////////////////////////
87 /// MODULE REGISTERING ///
88 //////////////////////////
89
90 static void _on_init_module (GldiModuleInstance *pModuleInstance, GKeyFile *pKeyFile)
91 {
92 cd_debug ("%s ()", __func__);
93
94 //\_____________ On initialise l'icone.
95 cd_dbus_action_on_init_module (pModuleInstance);
96 //\_____________ On cree l'objet sur le bus.
97 dbusApplet *pDbusApplet = cd_dbus_create_remote_applet_object (pModuleInstance);
98 g_return_if_fail (pDbusApplet != NULL);
99
100 //\____________ On met a jour le fichier de conf si necessaire, c'est plus simple pour les applets.
101 if (pKeyFile != NULL)
102 {
103 if (cairo_dock_conf_file_needs_update (pKeyFile, pModuleInstance->pModule->pVisitCard->cModuleVersion))
104 {
105 ///cairo_dock_flush_conf_file (pKeyFile, pModuleInstance->cConfFilePath, pModuleInstance->pModule->pVisitCard->cShareDataDir, pModuleInstance->pModule->pVisitCard->cConfFileName);
106 gchar *cTemplate = g_strdup_printf ("%s/%s", pModuleInstance->pModule->pVisitCard->cShareDataDir, pModuleInstance->pModule->pVisitCard->cConfFileName);
107 cairo_dock_upgrade_conf_file (pModuleInstance->cConfFilePath, pKeyFile, cTemplate);
108 g_free (cTemplate);
109 }
110 }
111
112 //\_____________ On (re)lance l'executable de l'applet.
113 cd_dbus_launch_applet_process (pModuleInstance, pDbusApplet);
114 }
115 static gboolean _cd_dbus_register_new_module (const gchar *cModuleName, const gchar *cDescription, const gchar *cAuthor, const gchar *cVersion, gint iCategory, const gchar *cIconName, const gchar *cTitle, const gchar *cShareDataDir, gboolean bMultiInstance, gboolean bActAsLauncher)
116 {
117 cd_message ("%s (%s)", __func__, cModuleName);
118
119 //\____________ on cree et on enregistre un nouveau module s'il n'existe pas deja.
120 GldiModule *pModule = gldi_module_get (cModuleName);
121 if (pModule != NULL) // le module existe deja, rien a faire.
122 {
123 cd_warning ("this module (%s) is already registered", cModuleName);
124 return FALSE;
125 }
126 else // on enregistre ce nouveau module.
127 {
128 GldiVisitCard *pVisitCard = g_new0 (GldiVisitCard, 1);
129 pVisitCard->cModuleName = g_strdup (cModuleName);
130 pVisitCard->iMajorVersionNeeded = 2;
131 pVisitCard->iMinorVersionNeeded = 1;
132 pVisitCard->iMicroVersionNeeded = 1;
133 pVisitCard->cPreviewFilePath = cShareDataDir ? g_strdup_printf ("%s/preview", cShareDataDir) : NULL;
134 pVisitCard->cGettextDomain = g_strdup (GETTEXT_NAME_EXTRAS);
135 pVisitCard->cUserDataDir = g_strdup (cModuleName);
136 pVisitCard->cShareDataDir = g_strdup (cShareDataDir);
137 pVisitCard->cConfFileName = g_strdup_printf ("%s.conf", cModuleName);
138 pVisitCard->cModuleVersion = g_strdup (cVersion);
139 pVisitCard->cAuthor = g_strdup (cAuthor);
140 pVisitCard->iCategory = iCategory;
141 if (cIconName != NULL)
142 pVisitCard->cIconFilePath = g_strdup (cIconName); // take the filename as it is, the path will be searched when needed only.
143 else
144 pVisitCard->cIconFilePath = (cShareDataDir ? g_strdup_printf ("%s/icon", cShareDataDir) : NULL);
145 pVisitCard->iSizeOfConfig = 4; // au cas ou ...
146 pVisitCard->iSizeOfData = 4; // au cas ou ...
147 pVisitCard->cDescription = g_strdup (cDescription);
148 pVisitCard->cTitle = cTitle ?
149 g_strdup (dgettext (pVisitCard->cGettextDomain, cTitle)) :
150 g_strdup (cModuleName);
151 pVisitCard->iContainerType = CAIRO_DOCK_MODULE_CAN_DOCK | CAIRO_DOCK_MODULE_CAN_DESKLET;
152 pVisitCard->bMultiInstance = bMultiInstance;
153 pVisitCard->bActAsLauncher = bActAsLauncher; // ex.: XChat controls xchat/xchat-gnome, but it does that only after initializing; we need to know if it's a launcher before the taskbar is loaded, hence this parameter.
154 GldiModuleInterface *pInterface = g_new0 (GldiModuleInterface, 1);
155 pInterface->initModule = _on_init_module;
156 pInterface->stopModule = cd_dbus_emit_on_stop_module;
157 pInterface->reloadModule = cd_dbus_emit_on_reload_module;
158 pModule = gldi_module_new (pVisitCard, pInterface);
159 if (! pModule)
160 {
161 cd_warning ("registration of '%s' has failed.", cModuleName);
162 return FALSE;
163 }
164 }
165 return TRUE;
166 }
167
168 gboolean cd_dbus_register_module_in_dir (const gchar *cModuleName, const gchar *cThirdPartyPath)
169 {
170 cd_debug ("%s (%s, %s)", __func__, cModuleName, cThirdPartyPath);
171 gchar *cFilePath = g_strdup_printf ("%s/%s/auto-load.conf", cThirdPartyPath, cModuleName);
172 GKeyFile *pKeyFile = cairo_dock_open_key_file (cFilePath);
173 if (pKeyFile == NULL)
174 {
175 cd_warning ("file %s should not be here", cFilePath);
176 g_free (cFilePath);
177 return FALSE;
178 }
179
180 GError *error = NULL;
181
182 gchar *cDescription = g_key_file_get_string (pKeyFile, "Register", "description", &error);
183 if (error != NULL)
184 {
185 cd_warning (error->message);
186 g_error_free (error);
187 error = NULL;
188 }
189 gchar *cAuthor = g_key_file_get_string (pKeyFile, "Register", "author", &error);
190 if (error != NULL)
191 {
192 cd_warning (error->message);
193 g_error_free (error);
194 error = NULL;
195 }
196 gchar *cVersion = g_key_file_get_string (pKeyFile, "Register", "version", &error);
197 if (error != NULL)
198 {
199 cd_warning (error->message);
200 g_error_free (error);
201 error = NULL;
202 }
203 int iCategory = g_key_file_get_integer (pKeyFile, "Register", "category", &error);
204 if (error != NULL)
205 {
206 cd_warning (error->message);
207 g_error_free (error);
208 error = NULL;
209 iCategory = CAIRO_DOCK_CATEGORY_APPLET_ACCESSORY;
210 }
211 gchar *cIconName = g_key_file_get_string (pKeyFile, "Register", "icon", NULL); // NULL if not specified, in which case we use the "icon" file.
212 if (cIconName && *cIconName == '\0')
213 {
214 g_free (cIconName);
215 cIconName = NULL;
216 }
217 gchar *cTitle = g_key_file_get_string (pKeyFile, "Register", "title", NULL); // NULL if not specified
218 if (cTitle && *cTitle == '\0')
219 {
220 g_free (cTitle);
221 cTitle = NULL;
222 }
223
224 gboolean bMultiInstance = g_key_file_get_boolean (pKeyFile, "Register", "multi-instance", NULL); // false if not specified
225
226 gboolean bActAsLauncher = g_key_file_get_boolean (pKeyFile, "Register", "act as launcher", NULL); // false if not specified
227
228 gchar *cShareDataDir = g_strdup_printf ("%s/%s", cThirdPartyPath, cModuleName);
229
230 g_key_file_free (pKeyFile);
231
232 gboolean bActivationOk = _cd_dbus_register_new_module (cModuleName, cDescription, cAuthor, cVersion, iCategory, cIconName, cTitle, cShareDataDir, bMultiInstance, bActAsLauncher);
233 g_free (cDescription);
234 g_free (cAuthor);
235 g_free (cVersion);
236 g_free (cIconName);
237 g_free (cTitle);
238 g_free (cShareDataDir);
239 g_free (cFilePath);
240 return bActivationOk;
241 }
242
243 static gboolean _cd_dbus_register_all_applets_in_dir (const gchar *cDirPath)
244 {
245 gboolean bAppletRegistered = FALSE;
246 const gchar *cFileName;
247 gchar *cThirdPartyPath = g_strdup_printf ("%s/%s", cDirPath, CD_DBUS_APPLETS_FOLDER);
248
249 GDir *dir = g_dir_open (cThirdPartyPath, 0, NULL); // si le repertoire n'existe pas, on ne veut pas de warning.
250 if (dir == NULL)
251 {
252 g_free (cThirdPartyPath);
253 return bAppletRegistered;
254 }
255
256 do
257 {
258 cFileName = g_dir_read_name (dir);
259 if (cFileName == NULL)
260 break ;
261
262 if (strcmp (cFileName, LOCALE_DIR_NAME) != 0)
263 bAppletRegistered |= cd_dbus_register_module_in_dir (cFileName, cThirdPartyPath);
264 }
265 while (1);
266 g_dir_close (dir);
267 g_free (cThirdPartyPath);
268 return bAppletRegistered;
269 }
270
271
272 /////////////////////
273 /// MODULE UPDATE ///
274 /////////////////////
275
276 static void _get_package_path (gchar *cModuleName)
277 {
278 const gchar *cSharePackagesDir = MY_APPLET_SHARE_DATA_DIR"/"CD_DBUS_APPLETS_FOLDER;
279 gchar *cUserPackagesDir = g_strdup_printf ("%s/%s", g_cCairoDockDataDir, CD_DBUS_APPLETS_FOLDER);
280 ///gchar *cDistantPackagesDir = g_strdup_printf ("%s/%d.%d.%d", CD_DBUS_APPLETS_FOLDER, g_iMajorVersion, g_iMinorVersion, g_iMicroVersion);
281 const gchar *cDistantPackagesDir = CD_DBUS_APPLETS_FOLDER"/"DISTANT_DIR;
282 gchar *cPath = cairo_dock_get_package_path (cModuleName,
283 cSharePackagesDir,
284 cUserPackagesDir,
285 cDistantPackagesDir,
286 CAIRO_DOCK_UPDATED_PACKAGE);
287 cd_debug ("*** update of the applet '%s' -> got '%s'", cModuleName, cPath);
288 g_free (cPath);
289 g_free (cUserPackagesDir);
290 //g_free (cDistantPackagesDir);
291 }
292 static gboolean _apply_package_update (gchar *cModuleName)
293 {
294 GldiModule *pModule = gldi_module_get (cModuleName);
295
296 if (pModule && pModule->pInstancesList != NULL) // applet active => reload it (pModule can be NULL in case of "locale").
297 {
298 cd_debug ("*** applet '%s' is active, reload it", cModuleName);
299 GldiModuleInstance *pModuleInstance = pModule->pInstancesList->data;
300 Icon *pIcon = pModuleInstance->pIcon;
301 GldiContainer *pContainer = pModuleInstance->pContainer;
302
303 // unregister the module, since anything can have changed, including its definition.
304 gldi_object_unref (GLDI_OBJECT(pModule)); // stoppe le module (toutes les instances), ce qui appelle stop_module, qui emet le signal 'stop' vers l'applet distante (qui du coup quitte). L'objet distant est detruit durant le stop.
305
306 // clean the dock from the remaining icon.
307 if (pIcon != NULL && pContainer != NULL) // par contre les icones restent, mais ne sont plus des applets (elles ont perdu leur module). On fait donc le menage.
308 {
309 if (CAIRO_DOCK_IS_DOCK (pContainer))
310 {
311 gldi_icon_detach (pIcon);
312 gldi_object_unref (GLDI_OBJECT(pIcon));
313 ///cairo_dock_update_dock_size (CAIRO_DOCK (pContainer));
314 ///cairo_dock_redraw_container (pContainer);
315 }
316 }
317
318 // now register again the updated module.
319 gchar *cThirdPartyPath = g_strdup_printf ("%s/%s", g_cCairoDockDataDir, CD_DBUS_APPLETS_FOLDER);
320 cd_dbus_register_module_in_dir (cModuleName, cThirdPartyPath);
321 g_free (cThirdPartyPath);
322
323 // and activate it again.
324 pModule = gldi_module_get (cModuleName); // the module has been destroyed previously, so grab it again.
325 g_return_val_if_fail (pModule != NULL, TRUE);
326 gldi_module_activate (pModule);
327 }
328
329 // get corresponding task and free it.
330 GldiTask *pUpdateTask = NULL;
331 GList *t;
332 for (t = myData.pUpdateTasksList; t != NULL; t = t->next)
333 {
334 pUpdateTask = t->data;
335 if (pUpdateTask->pSharedMemory && strcmp (pUpdateTask->pSharedMemory, cModuleName) == 0)
336 {
337 myData.pUpdateTasksList = g_list_delete_link (myData.pUpdateTasksList, t);
338 gldi_task_discard (pUpdateTask);
339 break;
340 }
341 }
342 return TRUE;
343 }
344 static void _check_update_package (const gchar *cModuleName, CairoDockPackage *pPackage, gpointer data)
345 {
346 cd_message ("*** %s (%s, %d)", __func__, cModuleName, pPackage->iType);
347 if (pPackage->iType == CAIRO_DOCK_UPDATED_PACKAGE)
348 {
349 gchar *cUserDirPath = g_strdup_printf ("%s/%s/%s", g_cCairoDockDataDir, CD_DBUS_APPLETS_FOLDER, cModuleName);
350 if (g_file_test (cUserDirPath, G_FILE_TEST_EXISTS))
351 {
352 cd_message ("*** the applet '%s' needs to be updated", cModuleName);
353 GldiTask *pUpdateTask = gldi_task_new_full (0,
354 (GldiGetDataAsyncFunc) _get_package_path,
355 (GldiUpdateSyncFunc) _apply_package_update,
356 (GFreeFunc) g_free,
357 g_strdup (cModuleName));
358 myData.pUpdateTasksList = g_list_prepend (myData.pUpdateTasksList, pUpdateTask);
359 gldi_task_launch (pUpdateTask);
360 }
361 }
362 }
363 static void _on_got_list (GHashTable *pPackagesTable, gpointer data)
364 {
365 if (pPackagesTable != NULL)
366 {
367 g_hash_table_foreach (pPackagesTable, (GHFunc) _check_update_package, NULL);
368 }
369 gldi_task_discard (myData.pGetListTask);
370 myData.pGetListTask = NULL;
371 }
372
373
374 ///////////////
375 /// SERVICE ///
376 ///////////////
377 void cd_dbus_clean_up_processes (gboolean bAll)
378 {
379 #ifdef __FreeBSD__ // thanks to Max Power for the BSD port
380 kvm_t *kd; //pointer for KVM library
381 char errbuf[_POSIX2_LINE_MAX]; //error message
382 int nentries; //number of processes
383 int p; //current process
384 struct kinfo_proc *kp;
385 kd = kvm_openfiles (NULL,"/dev/null",NULL,O_RDONLY,errbuf);
386 if(kd == 0)
387 {
388 cd_warning ("Dbus : %s",errbuf);
389 return;
390 }
391 kp = kvm_getprocs(kd,KERN_PROC_PROC,0,&nentries);
392 for(p=0; p<nentries;p++)
393 {
394 //SEARCHING...
395 char** pidargv = kvm_getargv(kd,&kp[p],0);
396 if(pidargv==NULL)
397 continue; // not able to get args
398 int pidargc;
399 for(pidargc=0;pidargv[pidargc];pidargc++); // get the number or args
400 if(pidargc<3) //not enough parameters
401 continue;
402 if(strcmp (pidargv[pidargc-2], myData.cProgName) != 0) // not our program name.
403 continue;
404 if(atoi (pidargv[pidargc-1]) == 0) // last arg is not a number
405 continue;
406
407 //..SEEK...
408 if (bAll || kp[p].ki_ppid==1) // old process, if parent exprired ppid is set to 1
409 {
410 //...AND DESTROY
411 cd_message ("this applet (%s %d) is linked to an old gldi process (%d), kill it.", kp[p].ki_comm, kp[p].ki_pid, kp[p].ki_ppid);
412 kill (kp[p].ki_pid, SIGKILL); // SIGTERM sometimes lets the process alive.
413 }
414 }
415 kvm_close(kd);
416 #else
417 static gchar cFilePathBuffer[23+1]; // /proc/12345/cmdline + 4octets de marge.
418 static gchar cContent[512+1];
419
420 GError *erreur = NULL;
421 GDir *dir = g_dir_open ("/proc", 0, &erreur);
422 if (erreur != NULL)
423 {
424 cd_warning ("Dbus : %s", erreur->message);
425 g_error_free (erreur);
426 return;
427 }
428
429 int iPid, iPPid;
430 const gchar *cPid;
431 while ((cPid = g_dir_read_name (dir)) != NULL)
432 {
433 // get the command line that spawned the process.
434 if (! g_ascii_isdigit (*cPid))
435 continue;
436
437 snprintf (cFilePathBuffer, 23, "/proc/%s/cmdline", cPid);
438 int pipe = open (cFilePathBuffer, O_RDONLY);
439 if (pipe <= 0)
440 continue ;
441
442 int iNbBytesRead;
443 if ((iNbBytesRead = read (pipe, cContent, sizeof (cContent))) <= 1) // ends with a nul char.
444 {
445 close (pipe);
446 continue;
447 }
448 close (pipe);
449
450 // search for the pattern "... progname 123", where spaces are nul char.
451 const gchar *str = cContent + iNbBytesRead - 2; // last non-nul char.
452 while (*str != '\0' && str != cContent) // search the previous nul char.
453 str --;
454 if (str == cContent) // not found
455 continue;
456 iPPid = atoi (str+1);
457 if (iPPid == 0) // not a pid.
458 continue;
459
460 str --; // skip the nul char.
461 while (*str != '\0' && str != cContent) // search the previous nul char.
462 str --;
463 if (str == cContent) // not found
464 continue;
465 if (strcmp (str+1, myData.cProgName) != 0) // not our program name.
466 continue;
467
468 // found, kill the applet process.
469 gchar *cProcFile = g_strdup_printf ("/proc/%d", iPPid);
470 if (bAll || ! g_file_test (cProcFile, G_FILE_TEST_EXISTS)) // old process
471 {
472 cd_message ("this applet (%s %s) is linked to an old gldi process (%d), kill it.", cContent, cPid, iPPid);
473 iPid = atoi (cPid);
474 kill (iPid, SIGKILL); // SIGTERM sometimes lets the process alive.
475 }
476 }
477 g_dir_close (dir);
478 #endif
479 }
480
481 void cd_dbus_launch_service (void)
482 {
483 g_return_if_fail (myData.pMainObject == NULL);
484 cd_message ("dbus : launching service...");
485
486 //\____________ define the base path on the bus. So each program built on gldi has its own path on the gldi bus, and will place its applets under its own path.
487 const gchar *cProgName = g_get_prgname ();
488 g_return_if_fail (cProgName != NULL);
489 int n = strlen (cProgName);
490 gchar *cName1 = g_new0 (gchar, n+1); // prog name without '-' and '_'
491 gchar *cName2 = g_new0 (gchar, n+1); // same but with upper char after the '-' and '_'
492 int i, k=0;
493 for (i = 0; i < n; i ++)
494 {
495 if (cProgName[i] == '-' || cProgName[i] == '_')
496 continue;
497 cName1[k] = g_ascii_tolower (cProgName[i]);
498 if (i == 0 || cProgName[i-1] == '-' || cProgName[i-1] == '_')
499 cName2[k] = g_ascii_toupper (cProgName[i]);
500 else
501 cName2[k] = cName1[k];
502 k ++;
503 }
504 myData.cProgName = cProgName;
505 myData.cBasePath = g_strdup_printf ("/org/%s/%s", cName1, cName2);
506 g_free (cName1);
507 g_free (cName2);
508
509 //\____________ kill all the orphean applets (for instance if the dock has crashed, or if it was interrupted by a CTRL+C, or if it stopped and the applet was busy and didn't receive the stop event (dbus-timeout)).
510 cd_dbus_clean_up_processes (FALSE); // FALSE <=> from old gldi instances
511
512 //\____________ Register the service name (the service name is registerd once by the first gldi instance).
513 cairo_dock_register_service_name ("org.cairodock.CairoDock"); /// what happens if the gldi instance that had registered the name quits while a 2nd instance remains ? do we need to queue ?...
514
515 //\____________ create the main object on the bus.
516 myData.pMainObject = g_object_new (cd_dbus_main_get_type(), NULL); // call cd_dbus_main_class_init() and cd_dbus_main_init().
517
518 //\____________ internationalize the applets (we need to do that before registering applets).
519 gchar *cLocaleDir = g_strdup_printf ("%s/"CD_DBUS_APPLETS_FOLDER"/"LOCALE_DIR_NAME, g_cCairoDockDataDir); // user version of /usr/share/locale
520 if (! g_file_test (cLocaleDir, G_FILE_TEST_EXISTS)) // translations not downloaded yet.
521 {
522 gchar *cUserAppletsFolder = g_strdup_printf ("%s/"CD_DBUS_APPLETS_FOLDER, g_cCairoDockDataDir);
523 if (! g_file_test (cUserAppletsFolder, G_FILE_TEST_EXISTS))
524 {
525 if (g_mkdir (cUserAppletsFolder, 7*8*8+7*8+5) != 0) // create an empty folder; since there is no date file, the "locale" package will be seen as "to be updated" by the package manager, which will therefore download it.
526 cd_warning ("couldn't create '%s'; third-party applets can't be added", cUserAppletsFolder);
527 }
528 g_free (cUserAppletsFolder);
529
530 /*
531 * create an empty folder; since there is no date file, the "locale"
532 * package will be seen as "to be updated" by the package manager, and
533 * will therefore download it.
534 * But if last-modif file is not available, it will be seen as "to be
535 * updated" only if the external package is younger than one month:
536 * => cairo-dock-packages.c:_cairo_dock_parse_package_list
537 * Solution: added a file with "0" to force the download
538 */
539 if (g_mkdir (cLocaleDir, 7*8*8+7*8+5) != 0)
540 cd_warning ("couldn't create '%s'; applets won't be translated", cLocaleDir);
541 else
542 {
543 gchar *cVersionFile = g_strdup_printf ("%s/last-modif", cLocaleDir);
544 g_file_set_contents (cVersionFile,
545 "0",
546 -1,
547 NULL);
548 g_free (cVersionFile);
549 }
550 }
551 bindtextdomain (GETTEXT_NAME_EXTRAS, cLocaleDir); // bind the applets' domain to the user locale folder.
552 bind_textdomain_codeset (GETTEXT_NAME_EXTRAS, "UTF-8");
553 g_free (cLocaleDir);
554
555 //\____________ register the applets installed in the default folders.
556 gboolean bAppletRegistered = FALSE;
557 bAppletRegistered |= _cd_dbus_register_all_applets_in_dir (MY_APPLET_SHARE_DATA_DIR);
558
559 bAppletRegistered |= _cd_dbus_register_all_applets_in_dir (g_cCairoDockDataDir);
560
561 //\____________ download in background the list of existing applets.
562 if (bAppletRegistered) // only if some third-party applets are present on the disk.
563 {
564 const gchar *cSharePackagesDir = NULL; // no share data dir, since we can't write in /usr
565 gchar *cUserPackagesDir = g_strdup_printf ("%s/%s", g_cCairoDockDataDir, CD_DBUS_APPLETS_FOLDER);
566 const gchar *cDistantPackagesDir = CD_DBUS_APPLETS_FOLDER"/"DISTANT_DIR;
567 myData.pGetListTask = cairo_dock_list_packages_async (cSharePackagesDir,
568 cUserPackagesDir,
569 cDistantPackagesDir,
570 (CairoDockGetPackagesFunc) _on_got_list,
571 NULL, // data
572 NULL); // table
573 g_free (cUserPackagesDir);
574 }
575
576 //\____________ Start the bridge to Unity Launcher API.
577 /* launch it asap, because if another Unity claims the bus before us,
578 * the messages will be emitted on the bus, and we might miss them.
579 */
580 #ifdef DBUSMENU_GTK_FOUND // need SetMenu => DBusMenu
581 if (myConfig.bLaunchLauncherAPIDaemon)
582 cairo_dock_launch_command (CD_PLUGINS_DIR"/cairo-dock-launcher-API-daemon");
583 #endif
584 }
585
586
587 ///////////////////
588 /// MARSHALLERS ///
589 ///////////////////
590 // must be in this file, otherwise we get include hell because of the generated code in *-spec.h
591
592 void cd_dbus_marshal_VOID__INT_STRING (GClosure *closure,
593 GValue *return_value G_GNUC_UNUSED,
594 guint n_param_values,
595 const GValue *param_values,
596 gpointer invocation_hint G_GNUC_UNUSED,
597 gpointer marshal_data)
598 {
599 //g_print ("%s ()\n", __func__);
600 typedef void (*GMarshalFunc_VOID__INT_STRING) (gpointer data1,
601 gint arg_1,
602 gchar *arg_2,
603 gpointer data2);
604 register GMarshalFunc_VOID__INT_STRING callback;
605 register GCClosure *cc = (GCClosure*) closure;
606 register gpointer data1, data2;
607 g_return_if_fail (n_param_values == 3); // return_value est NULL ici, car la callback ne renvoit rien.
608
609 if (G_CCLOSURE_SWAP_DATA (closure))
610 {
611 data1 = closure->data;
612 data2 = g_value_peek_pointer (param_values + 0);
613 }
614 else
615 {
616 data1 = g_value_peek_pointer (param_values + 0);
617 data2 = closure->data;
618 }
619 callback = (GMarshalFunc_VOID__INT_STRING) (marshal_data ? marshal_data : cc->callback);
620
621 callback (data1,
622 g_marshal_value_peek_int (param_values + 1),
623 g_marshal_value_peek_string (param_values + 2),
624 data2);
625 }
626 void cd_dbus_marshal_VOID__BOOLEAN_STRING (GClosure *closure,
627 GValue *return_value G_GNUC_UNUSED,
628 guint n_param_values,
629 const GValue *param_values,
630 gpointer invocation_hint G_GNUC_UNUSED,
631 gpointer marshal_data)
632 {
633 //g_print ("%s ()\n", __func__);
634 typedef void (*GMarshalFunc_VOID__BOOLEAN_STRING) (gpointer data1,
635 gboolean arg_1,
636 gchar *arg_2,
637 gpointer data2);
638 register GMarshalFunc_VOID__BOOLEAN_STRING callback;
639 register GCClosure *cc = (GCClosure*) closure;
640 register gpointer data1, data2;
641 g_return_if_fail (n_param_values == 3); // return_value est NULL ici, car la callback ne renvoit rien.
642
643 if (G_CCLOSURE_SWAP_DATA (closure))
644 {
645 data1 = closure->data;
646 data2 = g_value_peek_pointer (param_values + 0);
647 }
648 else
649 {
650 data1 = g_value_peek_pointer (param_values + 0);
651 data2 = closure->data;
652 }
653 callback = (GMarshalFunc_VOID__BOOLEAN_STRING) (marshal_data ? marshal_data : cc->callback);
654
655 callback (data1,
656 g_marshal_value_peek_boolean (param_values + 1),
657 g_marshal_value_peek_string (param_values + 2),
658 data2);
659 }
660 void cd_dbus_marshal_VOID__STRING_STRING (GClosure *closure,
661 GValue *return_value G_GNUC_UNUSED,
662 guint n_param_values,
663 const GValue *param_values,
664 gpointer invocation_hint G_GNUC_UNUSED,
665 gpointer marshal_data)
666 {
667 //g_print ("%s ()\n", __func__);
668 typedef void (*GMarshalFunc_VOID__STRING_STRING) (gpointer data1,
669 gchar *arg_1,
670 gchar *arg_2,
671 gpointer data2);
672 register GMarshalFunc_VOID__STRING_STRING callback;
673 register GCClosure *cc = (GCClosure*) closure;
674 register gpointer data1, data2;
675 g_return_if_fail (n_param_values == 3); // return_value est NULL ici, car la callback ne renvoit rien.
676
677 if (G_CCLOSURE_SWAP_DATA (closure))
678 {
679 data1 = closure->data;
680 data2 = g_value_peek_pointer (param_values + 0);
681 }
682 else
683 {
684 data1 = g_value_peek_pointer (param_values + 0);
685 data2 = closure->data;
686 }
687 callback = (GMarshalFunc_VOID__STRING_STRING) (marshal_data ? marshal_data : cc->callback);
688
689 callback (data1,
690 g_marshal_value_peek_string (param_values + 1),
691 g_marshal_value_peek_string (param_values + 2),
692 data2);
693 }
694 void cd_dbus_marshal_VOID__VALUE (GClosure *closure,
695 GValue *return_value G_GNUC_UNUSED,
696 guint n_param_values,
697 const GValue *param_values,
698 gpointer invocation_hint G_GNUC_UNUSED,
699 gpointer marshal_data)
700 {
701 //g_print ("%s ()\n", __func__);
702 typedef void (*GMarshalFunc_VOID__VALUE) (gpointer data1,
703 GValue *arg_1,
704 gpointer data2);
705 register GMarshalFunc_VOID__VALUE callback;
706 register GCClosure *cc = (GCClosure*) closure;
707 register gpointer data1, data2;
708 g_return_if_fail (n_param_values == 2); // return_value est NULL ici, car la callback ne renvoit rien.
709
710 if (G_CCLOSURE_SWAP_DATA (closure))
711 {
712 data1 = closure->data;
713 data2 = g_value_peek_pointer (param_values + 0);
714 }
715 else
716 {
717 data1 = g_value_peek_pointer (param_values + 0);
718 data2 = closure->data;
719 }
720 callback = (GMarshalFunc_VOID__VALUE) (marshal_data ? marshal_data : cc->callback);
721
722 callback (data1,
723 g_marshal_value_peek_pointer (param_values + 1),
724 data2);
725 }
726 void cd_dbus_marshal_VOID__INT_VALUE (GClosure *closure,
727 GValue *return_value G_GNUC_UNUSED,
728 guint n_param_values,
729 const GValue *param_values,
730 gpointer invocation_hint G_GNUC_UNUSED,
731 gpointer marshal_data)
732 {
733 //g_print ("%s ()\n", __func__);
734 typedef void (*GMarshalFunc_VOID__INT_VALUE) (gpointer data1,
735 gint arg_1,
736 GValue *arg_2,
737 gpointer data2);
738 register GMarshalFunc_VOID__INT_VALUE callback;
739 register GCClosure *cc = (GCClosure*) closure;
740 register gpointer data1, data2;
741 g_return_if_fail (n_param_values == 3); // return_value est NULL ici, car la callback ne renvoit rien.
742
743 if (G_CCLOSURE_SWAP_DATA (closure))
744 {
745 data1 = closure->data;
746 data2 = g_value_peek_pointer (param_values + 0);
747 }
748 else
749 {
750 data1 = g_value_peek_pointer (param_values + 0);
751 data2 = closure->data;
752 }
753 callback = (GMarshalFunc_VOID__INT_VALUE) (marshal_data ? marshal_data : cc->callback);
754
755 callback (data1,
756 g_marshal_value_peek_int (param_values + 1),
757 g_marshal_value_peek_pointer (param_values + 2),
758 data2);
759 }
760 void cd_dbus_marshal_VOID__VALUE_STRING (GClosure *closure,
761 GValue *return_value G_GNUC_UNUSED,
762 guint n_param_values,
763 const GValue *param_values,
764 gpointer invocation_hint G_GNUC_UNUSED,
765 gpointer marshal_data)
766 {
767 //g_print ("%s ()\n", __func__);
768 typedef void (*GMarshalFunc_VOID__VALUE_STRING) (gpointer data1,
769 GValue *arg_1,
770 gchar *arg_2,
771 gpointer data2);
772 register GMarshalFunc_VOID__VALUE_STRING callback;
773 register GCClosure *cc = (GCClosure*) closure;
774 register gpointer data1, data2;
775 g_return_if_fail (n_param_values == 3); // return_value est NULL ici, car la callback ne renvoit rien.
776
777 if (G_CCLOSURE_SWAP_DATA (closure))
778 {
779 data1 = closure->data;
780 data2 = g_value_peek_pointer (param_values + 0);
781 }
782 else
783 {
784 data1 = g_value_peek_pointer (param_values + 0);
785 data2 = closure->data;
786 }
787 callback = (GMarshalFunc_VOID__VALUE_STRING) (marshal_data ? marshal_data : cc->callback);
788
789 callback (data1,
790 g_marshal_value_peek_pointer (param_values + 1),
791 g_marshal_value_peek_string (param_values + 2),
792 data2);
793 }