Debian Codegraph @

Folders/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-load-icons.h"
25 #include "applet-struct.h"
26 #include "applet-init.h"
27
28
29 CD_APPLET_DEFINE_BEGIN (N_("Folders"),
30 2, 2, 0,
31 CAIRO_DOCK_CATEGORY_APPLET_FILES,
32 N_("This applet imports folders inside the Dock\n"
33 "You can have as many instances of this applet as you want, each one with a different folder.\n"
34 "To add a folder in your dock:\n"
35 " - activate the applet, open its configuration panel, and select a folder\n"
36 " - or just drop a folder into the dock\n"
37 "Middle-click on the main icon opens the folder.\n"),
38 "Fabounet")
39 CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE
40 CD_APPLET_ALLOW_EMPTY_TITLE
41 gldi_object_register_notification (&myDockObjectMgr,
42 NOTIFICATION_DROP_DATA,
43 (GldiNotificationFunc) cd_folders_on_drop_data,
44 GLDI_RUN_FIRST, NULL);
45 CD_APPLET_DEFINE_END
46
47
48 static inline void _set_comparaison_func (GldiModuleInstance *myApplet)
49 {
50 switch (myConfig.iSortType)
51 {
52 case 0: // name
53 default:
54 myData.comp = (GCompareFunc) cairo_dock_compare_icons_name;
55 break;
56 case 1: // date
57 case 2: // size
58 myData.comp = NULL;
59 break;
60 case 3: // type
61 myData.comp = (GCompareFunc) cairo_dock_compare_icons_extension;
62 break;
63 }
64 }
65
66 static inline void _set_icon_label (GldiModuleInstance *myApplet)
67 {
68 if (myDock && myConfig.cDefaultTitle == NULL && myConfig.cDirPath != NULL)
69 {
70 gchar *cPath = g_filename_from_uri (myConfig.cDirPath, NULL, NULL);
71 if (cPath)
72 {
73 gchar *str = strrchr (cPath, '/');
74 if (str)
75 CD_APPLET_SET_NAME_FOR_MY_ICON (str+1);
76 g_free (cPath);
77 }
78 }
79 }
80
81 //\___________ 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).
82 CD_APPLET_INIT_BEGIN
83
84 if (myConfig.cDirPath == NULL)
85 {
86 CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cImageFile);
87 gldi_dialog_show_temporary_with_icon (D_("Open the configuration of the applet to choose a folder to import."),
88 myIcon, myContainer,
89 8000.,
90 myConfig.iSubdockViewType == 0 ? "same icon" : MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
91 }
92 else
93 {
94 //\_______________ On lance la tache recuperation des fichiers.
95 _set_comparaison_func (myApplet);
96 if (myConfig.bShowFiles)
97 {
98 cd_folders_start (myApplet);
99 }
100
101 //\_______________ set the icon rendering
102 if (myDock) // dock mode: set the image or the sub-dock renderer
103 {
104 cairo_dock_set_subdock_content_renderer (myIcon, myConfig.iSubdockViewType);
105 if (myConfig.iSubdockViewType == 0)
106 CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cImageFile);
107 }
108 else // desklet mode: set the image if we don't show the files.
109 {
110 if (! myConfig.bShowFiles)
111 {
112 CD_APPLET_SET_DESKLET_RENDERER ("Simple");
113 CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cImageFile);
114 }
115 }
116
117 //\_______________ set the label
118 _set_icon_label (myApplet);
119 }
120
121 //\_______________ On enregistre nos notifications.
122 CD_APPLET_REGISTER_FOR_CLICK_EVENT;
123 CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
124 CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
125 CD_APPLET_INIT_END
126
127
128 //\___________ 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.
129 CD_APPLET_STOP_BEGIN
130 CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
131 CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
132 gldi_object_remove_notification (&myContainerObjectMgr,
133 NOTIFICATION_CLICK_ICON,
134 (GldiNotificationFunc) CD_APPLET_ON_CLICK_FUNC,
135 myApplet);
136
137 CD_APPLET_STOP_END
138
139
140 //\___________ 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.
141 CD_APPLET_RELOAD_BEGIN
142 if (CD_APPLET_MY_CONFIG_CHANGED)
143 {
144 //\_______________ On detruit les icones des fichiers.
145 cd_folders_free_all_data (myApplet);
146
147 if (myConfig.cDirPath == NULL)
148 {
149 // in case of deletion of a path: force resizing
150 if (myIcon->pSubDock)
151 {
152 gldi_object_unref (GLDI_OBJECT(myIcon->pSubDock));
153 myIcon->pSubDock = NULL;
154 }
155 CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cImageFile);
156 gldi_dialog_show_temporary_with_icon (D_("Open the configuration of the applet to choose a folder to import."),
157 myIcon, myContainer,
158 8000.,
159 myConfig.iSubdockViewType == 0 ? "same icon" : MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE);
160 }
161 else
162 {
163 //\_______________ On charge les icones dans un sous-dock.
164 _set_comparaison_func (myApplet);
165 if (myConfig.bShowFiles)
166 {
167 cd_folders_start (myApplet);
168 }
169 else if (myDock && myIcon->pSubDock) // dans ce cas on veut un comportement de type lanceur, donc on ne veut pas d'un sous-dock vide.
170 {
171 gldi_object_unref (GLDI_OBJECT(myIcon->pSubDock));
172 myIcon->pSubDock = NULL;
173 }
174
175 //\_______________ set the icon rendering
176 if (myDock) // dock mode: set the image or the sub-dock renderer
177 {
178 cairo_dock_set_subdock_content_renderer (myIcon, myConfig.iSubdockViewType);
179 if (myConfig.iSubdockViewType == 0)
180 CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cImageFile);
181 }
182 else // desklet mode: set the image if we don't show the files.
183 {
184 if (! myConfig.bShowFiles)
185 {
186 CD_APPLET_SET_DESKLET_RENDERER ("Simple");
187 CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cImageFile);
188 }
189 }
190
191 //\_______________ set the label
192 _set_icon_label (myApplet);
193 }
194 }
195 CD_APPLET_RELOAD_END