Debian Codegraph @

Scooby-Do/src/applet-init.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 #include "stdlib.h"
21
22 #include "applet-config.h"
23 #include "applet-notifications.h"
24 #include "applet-struct.h"
25 #include "applet-session.h"
26 #include "applet-search.h"
27 #include "applet-listing.h"
28 #include "applet-backend-files.h"
29 #include "applet-backend-web.h"
30 #include "applet-backend-command.h"
31 #include "applet-backend-firefox.h"
32 #include "applet-backend-recent.h"
33 #include "applet-init.h"
34
35
36 CD_APPLET_DEFINE_BEGIN ("Scooby-Do",
37 2, 1, 4,
38 CAIRO_DOCK_CATEGORY_APPLET_SYSTEM,
39 ("This plug-in allows you to make different actions directly from the keyboard.\n"
40 "It is triggered by a keyboard shortcut (by default: CTRL + Enter):\n"
41 "It lets you find and launch applications, files, recent files, firefox bookmarks, commands, and even calculations.\n"
42 "Type what you want to search, the results will be displayed in real time.\n"
43 "The first results of each category are displayed in the main listing.\n"
44 "Use the up/down arrows to navigate inside the list,\n"
45 " and use the left/right arrows to enter into a category, or to display more actions (when a little arrow is drawn next to text).\n"
46 "Once inside a category, you can filter the results by typing some letters.\n"
47 "Press Enter to validate, maintain SHIFT or ALT to keep the list of results opened.\n"
48 "Escape or the same shortkey will cancel."),
49 "Fabounet (Fabrice Rey)")
50 CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE
51 CD_APPLET_SET_CONTAINER_TYPE (CAIRO_DOCK_MODULE_IS_PLUGIN);
52 CD_APPLET_DEFINE_END
53
54 #define _register_backends(...) do {\
55 if (myConfig.bUseFiles)\
56 cd_do_register_files_backend ();\
57 if (myConfig.bUseWeb)\
58 cd_do_register_web_backend ();\
59 if (myConfig.bUseCommand)\
60 cd_do_register_command_backend ();\
61 if (myConfig.bUseFirefox)\
62 cd_do_register_firefox_backend ();\
63 if (myConfig.bUseRecent)\
64 cd_do_register_recent_backend (); } while (0)
65 //\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading).
66 CD_APPLET_INIT_BEGIN
67 gldi_object_register_notification (&myContainerObjectMgr,
68 NOTIFICATION_KEY_PRESSED,
69 (GldiNotificationFunc) cd_do_key_pressed,
70 GLDI_RUN_AFTER, NULL);
71
72 myData.cKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkeySearch,
73 D_("Enable/disable the Finder"),
74 "Configuration", "shortkey search",
75 (CDBindkeyHandler) cd_do_on_shortkey_search);
76
77 _register_backends ();
78 CD_APPLET_INIT_END
79
80
81 //\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated.
82 CD_APPLET_STOP_BEGIN
83 gldi_object_remove_notification (&myContainerObjectMgr,
84 NOTIFICATION_KEY_PRESSED,
85 (GldiNotificationFunc) cd_do_key_pressed, NULL);
86
87 gldi_object_unref (GLDI_OBJECT(myData.cKeyBinding));
88
89 cd_do_exit_session ();
90 cd_do_stop_all_backends ();
91 CD_APPLET_STOP_END
92
93
94 //\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode.
95 CD_APPLET_RELOAD_BEGIN
96 if (CD_APPLET_MY_CONFIG_CHANGED)
97 {
98 cd_do_stop_all_backends ();
99
100 cd_do_free_all_backends ();
101
102 cd_do_destroy_listing (myData.pListing);
103 myData.pListing = NULL;
104
105 gldi_shortkey_rebind (myData.cKeyBinding, myConfig.cShortkeySearch, NULL);
106
107 if (myData.sCurrentText != NULL) // peu probable.
108 {
109 /// recharger surfaces / textures
110
111 cairo_dock_redraw_container (CAIRO_CONTAINER (g_pMainDock));
112 }
113
114 _register_backends ();
115 }
116 CD_APPLET_RELOAD_END