Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Source for desktop plugin
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include "desktop.h"
11 :
12 : #include <ctype.h> // for tolower
13 : #include <stdlib.h> // for getenv
14 : #include <strings.h> // for strcasecmp
15 :
16 : #include <kdberrors.h>
17 : #include <kdbhelper.h>
18 : #include <kdblogger.h>
19 : #include <kdbmacros.h>
20 :
21 :
22 20 : int elektraDesktopGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
23 : {
24 : ELEKTRA_LOG ("get desktop %s from %s\n", keyName (parentKey), keyString (parentKey));
25 :
26 20 : if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/desktop"))
27 : {
28 20 : KeySet * contract =
29 20 : ksNew (30, keyNew ("system/elektra/modules/desktop", KEY_VALUE, "desktop plugin waits for your orders", KEY_END),
30 : keyNew ("system/elektra/modules/desktop/exports", KEY_END),
31 : keyNew ("system/elektra/modules/desktop/exports/get", KEY_FUNC, elektraDesktopGet, KEY_END),
32 : keyNew ("system/elektra/modules/desktop/exports/set", KEY_FUNC, elektraDesktopSet, KEY_END),
33 : #include ELEKTRA_README
34 : keyNew ("system/elektra/modules/desktop/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
35 20 : ksAppend (returned, contract);
36 20 : ksDel (contract);
37 :
38 20 : return 1; // success
39 : }
40 :
41 : const char * desktop;
42 : // get key
43 0 : if (getenv ("GNOME_DESKTOP_SESSION_ID"))
44 : {
45 0 : ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "gnome", KEY_END));
46 : }
47 0 : else if (getenv ("KDE_FULL_SESSION"))
48 : {
49 0 : ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "kde", KEY_END));
50 : }
51 0 : else if (getenv ("TDE_FULL_SESSION"))
52 : {
53 0 : ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "tde", KEY_END));
54 : }
55 0 : else if ((desktop = getenv ("DESKTOP_SESSION")) && !strcasecmp (desktop, "unity"))
56 : {
57 0 : ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, "unity", KEY_END));
58 : }
59 0 : else if ((desktop = getenv ("XDG_CURRENT_DESKTOP")))
60 : {
61 0 : char * str = elektraStrDup (desktop);
62 0 : for (int i = 0; str[i]; i++)
63 : {
64 0 : str[i] = tolower (str[i]);
65 : }
66 0 : ksAppendKey (returned, keyNew (keyName (parentKey), KEY_VALUE, str, KEY_END));
67 0 : elektraFree (str);
68 : }
69 :
70 : return 1; // success
71 : }
72 :
73 0 : int elektraDesktopSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
74 : {
75 : ELEKTRA_LOG ("set desktop %s from %s\n", keyName (parentKey), keyString (parentKey));
76 :
77 0 : KeySet * info = ksNew (0, KS_END);
78 0 : elektraDesktopGet (handle, info, parentKey);
79 0 : ELEKTRA_SET_ERROR_READ_ONLY (info, returned, parentKey);
80 0 : return 0;
81 : }
82 :
83 20 : Plugin * ELEKTRA_PLUGIN_EXPORT
84 : {
85 : // clang-format off
86 20 : return elektraPluginExport ("desktop",
87 : ELEKTRA_PLUGIN_GET, &elektraDesktopGet,
88 : ELEKTRA_PLUGIN_SET, &elektraDesktopSet,
89 : ELEKTRA_PLUGIN_END);
90 : }
91 :
|