1 /*
2     This file is part of darktable,
3     Copyright (C) 2011-2021 darktable developers.
4 
5     darktable is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     darktable is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 
21 #include <glib-object.h>
22 
23 /** \brief enum of signals to listen for in darktable.
24     \note To add a new signal, first off add a enum and
25     document what it's used for, then add a matching signal string
26     name to _strings in signal.c
27 */
28 typedef enum dt_signal_t
29 {
30   /** \brief This signal is raised when mouse hovers over image thumbs
31       both on lighttable and in the filmstrip.
32       no param, no returned value
33    */
34   DT_SIGNAL_MOUSE_OVER_IMAGE_CHANGE,
35 
36   /** \brief This signal is raised when image shown in the main view change
37       no param, no returned value
38    */
39   DT_SIGNAL_ACTIVE_IMAGES_CHANGE,
40 
41   /** \brief This signal is raised when dt_control_queue_redraw() is called.
42     no param, no returned value
43   */
44   DT_SIGNAL_CONTROL_REDRAW_ALL,
45 
46   /** \brief This signal is raised when dt_control_queue_redraw_center() is called.
47     no param, no returned value
48    */
49   DT_SIGNAL_CONTROL_REDRAW_CENTER,
50 
51   /** \brief This signal is raised by viewmanager when a view has changed.
52     1 : dt_view_t * the old view
53     2 : dt_view_t * the new (current) view
54     no returned value
55    */
56   DT_SIGNAL_VIEWMANAGER_VIEW_CHANGED,
57 
58   /** \bief This signal is raised when a thumb is doubleclicked in
59     thumbtable (filemananger, filmstrip)
60     1 : int the imageid of the thumbnail
61     no returned value
62    */
63   DT_SIGNAL_VIEWMANAGER_THUMBTABLE_ACTIVATE,
64 
65   /** \brief This signal is raised when collection changed. To avoid leaking the list,
66     dt_collection_t is connected to this event and responsible of that.
67     1 : dt_collection_change_t the reason why the collection has changed
68     2 : dt_collection_properties_t the property that has changed
69     3 : GList of imageids that have changed (can be null if it's a global change)
70     4 : next untouched imgid in the list (-1 if no list)
71     no returned value
72     */
73   /** image list not to be freed by the caller, automatically freed */
74   DT_SIGNAL_COLLECTION_CHANGED,
75 
76   /** \brief This signal is raised when the selection is changed
77   no param, no returned value
78     */
79   DT_SIGNAL_SELECTION_CHANGED,
80 
81   /** \brief This signal is raised when a tag is added/deleted/changed  */
82   DT_SIGNAL_TAG_CHANGED,
83 
84   /** \brief This signal is raised when a geotag is added/deleted/changed  */
85   // when imgs <> NULL these images have some geotag changes
86   // when imgs == NULL locations have changed
87   // if locid <> 0 it the new selected location on map
88   DT_SIGNAL_GEOTAG_CHANGED,
89 
90   /** \brief This signal is raised when metadata status (shown/hidden) or value has changed */
91   DT_SIGNAL_METADATA_CHANGED,
92 
93   /** \brief This signal is raised when any of image info has changed  */
94   /** image list not to be freed by the caller, automatically freed */
95   // TODO check if tag and metadata could be included there
96   DT_SIGNAL_IMAGE_INFO_CHANGED,
97 
98   /** \brief This signal is raised when a style is added/deleted/changed  */
99   DT_SIGNAL_STYLE_CHANGED,
100 
101   /** \brief This signal is raised to request image order change */
102   DT_SIGNAL_IMAGES_ORDER_CHANGE,
103 
104   /** \brief This signal is raised when a filmroll is deleted/changed but not imported
105       \note when a filmroll is imported, use DT_SIGNALS_FILMOLLS_IMPORTED, as the gui
106        has to behave differently
107   */
108   DT_SIGNAL_FILMROLLS_CHANGED,
109 
110   /** \brief This signal is raised only when a filmroll is imported
111     1 :  int the film_id for the film that triggered the import. in case of recursion, other filmrolls might
112     be affected
113     no return
114    */
115   DT_SIGNAL_FILMROLLS_IMPORTED,
116 
117   /** \brief This signal is raised only when a filmroll is removed */
118   DT_SIGNAL_FILMROLLS_REMOVED,
119 
120   /* \brief This signal is raised when a preset is created/updated/deleted */
121   DT_SIGNAL_PRESETS_CHANGED,
122 
123   /** \brief This signal is raised when darktable.develop is initialized.
124       \note any modules that wants to access darktable->develop should connect
125       to this signal to be sure darktable.develop is initialized.
126   no param, no returned value
127    */
128   DT_SIGNAL_DEVELOP_INITIALIZE,
129 
130   /** \brief This signal is raised when a mipmap has been generated and flushed to cache
131     1 :  int the imgid of the mipmap
132     no returned value
133     */
134   DT_SIGNAL_DEVELOP_MIPMAP_UPDATED,
135 
136   /** \brief This signal is raised when develop preview pipe process is finished
137   no param, no returned value
138     */
139   DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED,
140 
141   /** \brief This signal is raised when develop preview2 pipe process is finished
142   no param, no returned value
143     */
144   DT_SIGNAL_DEVELOP_PREVIEW2_PIPE_FINISHED,
145 
146   /** \brief This signal is raised when pipe is finished and the gui is attached
147   no param, no returned value
148     */
149   DT_SIGNAL_DEVELOP_UI_PIPE_FINISHED,
150 
151   /** \brief This signal is raised when develop history is about to be changed
152     1 : GList *  the current history
153     2 : uint32_t the correpsing history end
154     3 : GList *  the current iop-order list
155   no returned value
156     */
157   DT_SIGNAL_DEVELOP_HISTORY_WILL_CHANGE,
158 
159   /** \brief This signal is raised when develop history is changed
160   no param, no returned value
161     */
162   DT_SIGNAL_DEVELOP_HISTORY_CHANGE,
163 
164   /** \brief This signal is raised when a module is removed from the history stack
165     1 module
166     no returned value
167     */
168   DT_SIGNAL_DEVELOP_MODULE_REMOVE,
169 
170   /** \brief This signal is raised when order of modules in pipeline is changed */
171   DT_SIGNAL_DEVELOP_MODULE_MOVED,
172 
173   /** \brief This signal is raised when image is changed in darkroom */
174   DT_SIGNAL_DEVELOP_IMAGE_CHANGED,
175 
176   /** \brief This signal is raised when the screen profile has changed
177   no param, no returned value
178     */
179   DT_SIGNAL_CONTROL_PROFILE_CHANGED,
180 
181   /** \brief This signal is raised when a profile is changed by the user
182     1 uint32_t :  the profile type that has changed
183     no return
184     */
185   DT_SIGNAL_CONTROL_PROFILE_USER_CHANGED,
186 
187   /** \brief This signal is raised when a new image is imported (not cloned)
188     1 uint32_t :  the new image id
189     no return
190     */
191   DT_SIGNAL_IMAGE_IMPORT,
192 
193   /** \brief This signal is raised after an image has been exported
194     to a file, but before it is sent to facebook/picasa etc...
195     export won't happen until this function returns
196     1 int : the imgid exported
197     2 char* : the filename we exported to
198     3 dt_imageio_module_format_t* : the format used for export
199     4 dt_imageio_module_data_t* : the format's data
200     5 dt_imageio_module_storage_t* : the storage used for export (can be NULL)
201     6 dt_imageio_module_data_t* : the storage's data (can be NULL)
202     no return
203     */
204   DT_SIGNAL_IMAGE_EXPORT_TMPFILE,
205 
206   /** \brief This signal is raised when a new storage module is loaded
207     noparameters
208     no return
209     */
210   DT_SIGNAL_IMAGEIO_STORAGE_CHANGE,
211 
212   /** \brief This signal is raised after preferences have been changed
213     no parameters
214     no return
215     */
216   DT_SIGNAL_PREFERENCES_CHANGE,
217 
218   /** \brief This signal is raised when new gphoto2 cameras might have been detected
219     no return
220    * */
221   DT_SIGNAL_CAMERA_DETECTED,
222 
223   /** \brief This signal is raised when dt_control_navigation_redraw() is called.
224     no param, no returned value
225   */
226   DT_SIGNAL_CONTROL_NAVIGATION_REDRAW,
227 
228   /** \brief This signal is raised when dt_control_log_redraw() is called.
229     no param, no returned value
230   */
231   DT_SIGNAL_CONTROL_LOG_REDRAW,
232 
233   /** \brief This signal is raised when dt_control_toast_redraw() is called.
234     no param, no returned value
235   */
236   DT_SIGNAL_CONTROL_TOAST_REDRAW,
237 
238   /** \brief This signal is raised when new color picker data are available in the pixelpipe.
239     1 module
240     2 piece
241     no returned value
242   */
243   DT_SIGNAL_CONTROL_PICKERDATA_READY,
244 
245   /* \brief This signal is raised when metadata view needs update */
246   DT_SIGNAL_METADATA_UPDATE,
247 
248   /* \brief This signal is raised when a module is in trouble and message is to be displayed */
249   DT_SIGNAL_TROUBLE_MESSAGE,
250 
251   /* \brief This signal is raised when the user choses a new location from map (module location)*/
252   DT_SIGNAL_LOCATION_CHANGED,
253 
254   /* do not touch !*/
255   DT_SIGNAL_COUNT
256 } dt_signal_t;
257 
258 typedef enum dt_debug_signal_action_t
259 {
260   // powers of two, masking
261   DT_DEBUG_SIGNAL_ACT_RAISE       = 1 << 0,
262   DT_DEBUG_SIGNAL_ACT_CONNECT     = 1 << 1,
263   DT_DEBUG_SIGNAL_ACT_DISCONNECT  = 1 << 2,
264   DT_DEBUG_SIGNAL_ACT_PRINT_TRACE = 1 << 3,
265 } dt_debug_signal_action_t;
266 
267 /* inititialize the signal framework */
268 struct dt_control_signal_t *dt_control_signal_init();
269 /* raises a signal */
270 void dt_control_signal_raise(const struct dt_control_signal_t *ctlsig, const dt_signal_t signal, ...);
271 /* connects a callback to a signal */
272 void dt_control_signal_connect(const struct dt_control_signal_t *ctlsig, const dt_signal_t signal,
273                                GCallback cb, gpointer user_data);
274 /* disconnects a callback from a sink */
275 void dt_control_signal_disconnect(const struct dt_control_signal_t *ctlsig, GCallback cb, gpointer user_data);
276 /* blocks a callback */
277 void dt_control_signal_block_by_func(const struct dt_control_signal_t *ctlsig, GCallback cb, gpointer user_data);
278 /* unblocks a callback */
279 void dt_control_signal_unblock_by_func(const struct dt_control_signal_t *ctlsig, GCallback cb, gpointer user_data);
280 
281 #define DT_DEBUG_CONTROL_SIGNAL_RAISE(ctlsig, signal, ...)                                                                       \
282   do                                                                                                                             \
283   {                                                                                                                              \
284     if((darktable.unmuted_signal_dbg_acts & DT_DEBUG_SIGNAL_ACT_RAISE) && darktable.unmuted_signal_dbg[signal])                 \
285     {                                                                                                                            \
286       dt_print(DT_DEBUG_SIGNAL, "[signal] %s:%d, function %s(): raise signal %s\n", __FILE__, __LINE__, __FUNCTION__, #signal);  \
287     }                                                                                                                            \
288     dt_control_signal_raise(ctlsig, signal, ##__VA_ARGS__);                                                                      \
289   } while (0)
290 
291 #define DT_DEBUG_CONTROL_SIGNAL_CONNECT(ctlsig, signal, cb, user_data)                                                           \
292   do                                                                                                                             \
293   {                                                                                                                              \
294     if((darktable.unmuted_signal_dbg_acts & DT_DEBUG_SIGNAL_ACT_CONNECT) && darktable.unmuted_signal_dbg[signal])                \
295     {                                                                                                                            \
296       dt_print(DT_DEBUG_SIGNAL, "[signal] %s:%d, function: %s() connect handler %s to signal %s\n", __FILE__, __LINE__,          \
297                __FUNCTION__, #cb, #signal);                                                                                      \
298     }                                                                                                                            \
299     dt_control_signal_connect(ctlsig, signal, cb, user_data);                                                                    \
300   } while (0)
301 
302 #define DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(ctlsig, cb, user_data)                                                                \
303   do                                                                                                                             \
304   {                                                                                                                              \
305     if(darktable.unmuted_signal_dbg_acts & DT_DEBUG_SIGNAL_ACT_DISCONNECT)                                                       \
306     {                                                                                                                            \
307       dt_print(DT_DEBUG_SIGNAL, "[signal] %s:%d, function: %s() disconnect handler %s\n", __FILE__, __LINE__, __FUNCTION__, #cb);\
308     }                                                                                                                            \
309     dt_control_signal_disconnect(ctlsig, cb, user_data);                                                                         \
310   } while (0)
311 
312 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
313 // vim: shiftwidth=2 expandtab tabstop=2 cindent
314 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
315