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 #ifndef __CAIRO_DOCK_GUI_FACTORY__
22 #define  __CAIRO_DOCK_GUI_FACTORY__
23 
24 #include <gtk/gtk.h>
25 G_BEGIN_DECLS
26 
27 
28 /**
29 *@file cairo-dock-gui-factory.h This class handles the construction of the common widgets used in the conf files.
30 *
31 * A conf file is a common group/key file, with the following syntax :
32 * \code
33 * [Group]
34 * #comment about key1
35 * key1 = 1
36 * #comment about key2
37 * key2 = pouic
38 * \endcode
39 *
40 * Each key in the conf file has a comment.
41 *
42 * The first character of the comment defines the type of widget. Known types are listed in the CairoDockGUIWidgetType enum.
43 *
44 * A key can be a behaviour key or an appearance key. Appearance keys are keys that defines the look of the appli, they belong to the theme. Behaviour keys are keys that define some configuration parameters, that depends on the user. To mark a key as an apppearance one, suffix the widget character with a '+'. Thus, keys not marked with a '+' won't be loaded when the user loads a theme, except if he forces it.
45 *
46 * After the widget character and its suffix, some widget accept a list of values. For instance, a spinbutton can have a min and a max limits, a list can have pre-defined elements, etc. Such values are set between '[' and ']' brackets, and separated by ';' inside.
47 *
48 * After that, let a blank to start the widget description. It will appear on the left of the widget; description must be short enough to fit the config panel width.
49 *
50 * You can complete this description with a tooltip. To do that, on a new comment line, add some text between '{' and '}' brackets. Tooltips appear above the widget when you let the mouse over it for ~1 second. They can be as long as you want. Use '\n' to insert new lines inside the tooltip.
51 *
52 */
53 
54 #define CAIRO_DOCK_GUI_MARGIN 4
55 
56 /// Types of widgets that Cairo-Dock can automatically build.
57 typedef enum {
58 	/// boolean in a button to tick.
59 	CAIRO_DOCK_WIDGET_CHECK_BUTTON='b',
60 	/// boolean in a button to tick, that will control the sensitivity of the next widget.
61 	CAIRO_DOCK_WIDGET_CHECK_CONTROL_BUTTON='B',
62 	/// integer in a spin button.
63 	CAIRO_DOCK_WIDGET_SPIN_INTEGER='i',
64 	/// integer in an horizontal scale.
65 	CAIRO_DOCK_WIDGET_HSCALE_INTEGER='I',
66 	/// pair of integers for dimansion WidthxHeight
67 	CAIRO_DOCK_WIDGET_SIZE_INTEGER='j',
68 	/// double in a spin button.
69 	CAIRO_DOCK_WIDGET_SPIN_DOUBLE='f',
70 	/// 3 doubles with a color selector (RGB).
71 	CAIRO_DOCK_WIDGET_COLOR_SELECTOR_RGB='c',
72 	/// 4 doubles with a color selector (RGBA).
73 	CAIRO_DOCK_WIDGET_COLOR_SELECTOR_RGBA='C',
74 	/// double in an horizontal scale.
75 	CAIRO_DOCK_WIDGET_HSCALE_DOUBLE='e',
76 
77 	/// list of views.
78 	CAIRO_DOCK_WIDGET_VIEW_LIST='n',
79 	/// list of themes in a combo, with preview and readme.
80 	CAIRO_DOCK_WIDGET_THEME_LIST='h',
81 	/// list of available animations.
82 	CAIRO_DOCK_WIDGET_ANIMATION_LIST='a',
83 	/// list of available dialog decorators.
84 	CAIRO_DOCK_WIDGET_DIALOG_DECORATOR_LIST='t',
85 	/// list of available desklet decorations.
86 	CAIRO_DOCK_WIDGET_DESKLET_DECORATION_LIST='O',
87 	/// same but with the 'default' choice too.
88 	CAIRO_DOCK_WIDGET_DESKLET_DECORATION_LIST_WITH_DEFAULT='o',
89 	/// list of existing docks.
90 	CAIRO_DOCK_WIDGET_DOCK_LIST='d',
91 	/// list of icons of a dock.
92 	CAIRO_DOCK_WIDGET_ICONS_LIST='N',
93 	/// list of installed icon themes.
94 	CAIRO_DOCK_WIDGET_ICON_THEME_LIST='w',
95 	/// list of screens
96 	CAIRO_DOCK_WIDGET_SCREENS_LIST='r',
97 	/// a button to jump to another module inside the config panel.
98 	CAIRO_DOCK_WIDGET_JUMP_TO_MODULE='m',
99 	/// same but only if the module exists.
100 	CAIRO_DOCK_WIDGET_JUMP_TO_MODULE_IF_EXISTS='M',
101 
102 	/// a button to launch a specific command.
103 	CAIRO_DOCK_WIDGET_LAUNCH_COMMAND='Z',
104 	/// a button to launch a specific command with a condition.
105 	CAIRO_DOCK_WIDGET_LAUNCH_COMMAND_IF_CONDITION='G',
106 
107 	/// a text entry.
108 	CAIRO_DOCK_WIDGET_STRING_ENTRY='s',
109 	/// a text entry with a file selector.
110 	CAIRO_DOCK_WIDGET_FILE_SELECTOR='S',
111 	/// a text entry with a file selector, files are filtered to only display images.
112 	CAIRO_DOCK_WIDGET_IMAGE_SELECTOR='g',
113 	/// a text entry with a folder selector.
114 	CAIRO_DOCK_WIDGET_FOLDER_SELECTOR='D',
115 	/// a text entry with a file selector and a 'play' button, for sound files.
116 	CAIRO_DOCK_WIDGET_SOUND_SELECTOR='u',
117 	/// a text entry with a shortkey selector.
118 	CAIRO_DOCK_WIDGET_SHORTKEY_SELECTOR='k',
119 	/// a text entry with a class selector.
120 	CAIRO_DOCK_WIDGET_CLASS_SELECTOR='K',
121 	/// a text entry, where text is hidden and the result is encrypted in the .conf file.
122 	CAIRO_DOCK_WIDGET_PASSWORD_ENTRY='p',
123 	/// a font selector button.
124 	CAIRO_DOCK_WIDGET_FONT_SELECTOR='P',
125 
126 	/// a text list.
127 	CAIRO_DOCK_WIDGET_LIST='L',
128 	/// a combo-entry, that is to say a list where one can add a custom choice.
129 	CAIRO_DOCK_WIDGET_LIST_WITH_ENTRY='E',
130 	/// a combo where the number of the line is used for the choice.
131 	CAIRO_DOCK_WIDGET_NUMBERED_LIST='l',
132 	/// a combo where the number of the line is used for the choice, and for controlling the sensitivity of the widgets below.
133 	CAIRO_DOCK_WIDGET_NUMBERED_CONTROL_LIST='y',
134 	/// a combo where the number of the line is used for the choice, and for controlling the sensitivity of the widgets below; controlled widgets are indicated in the list : {entry;index first widget;nb widgets}.
135 	CAIRO_DOCK_WIDGET_NUMBERED_CONTROL_LIST_SELECTIVE='Y',
136 	/// a tree view, where lines are numbered and can be moved up and down.
137 	CAIRO_DOCK_WIDGET_TREE_VIEW_SORT='T',
138 	/// a tree view, where lines can be added, removed, and moved up and down.
139 	CAIRO_DOCK_WIDGET_TREE_VIEW_SORT_AND_MODIFY='U',
140 	/// a tree view, where lines are numbered and can be selected or not.
141 	CAIRO_DOCK_WIDGET_TREE_VIEW_MULTI_CHOICE='V',
142 
143 	/// an empty GtkContainer, in case you need to build custom widgets.
144 	CAIRO_DOCK_WIDGET_EMPTY_WIDGET='_',
145 	/// an empty GtkContainer, the same but using full available space.
146 	CAIRO_DOCK_WIDGET_EMPTY_FULL='<',
147 	/// a simple text label.
148 	CAIRO_DOCK_WIDGET_TEXT_LABEL='>',
149 	/// a simple text label.
150 	CAIRO_DOCK_WIDGET_LINK='W',
151 	/// a label containing the handbook of the applet.
152 	CAIRO_DOCK_WIDGET_HANDBOOK='A',
153 	/// an horizontal separator.
154 	CAIRO_DOCK_WIDGET_SEPARATOR='v',
155 	/// a frame. The previous frame will be closed.
156 	CAIRO_DOCK_WIDGET_FRAME='F',
157 	/// a frame inside an expander. The previous frame will be closed.
158 	CAIRO_DOCK_WIDGET_EXPANDER='X',
159 	CAIRO_DOCK_NB_GUI_WIDGETS
160 	} CairoDockGUIWidgetType;
161 
162 #define CAIRO_DOCK_WIDGET_CAIRO_ONLY '*'
163 #define CAIRO_DOCK_WIDGET_OPENGL_ONLY '&'
164 
165 /// Model used for combo-box and tree-view. CAIRO_DOCK_MODEL_NAME is the name as displayed in the widget, and CAIRO_DOCK_MODEL_RESULT is the resulting string effectively written in the config file.
166 typedef enum {
167 	CAIRO_DOCK_MODEL_NAME = 0,  // displayed name
168 	CAIRO_DOCK_MODEL_RESULT,  // string that will be used for this line
169 	CAIRO_DOCK_MODEL_DESCRIPTION_FILE,  // readme file
170 	CAIRO_DOCK_MODEL_IMAGE,  // preview file
171 	CAIRO_DOCK_MODEL_ACTIVE,  // whether the line is enabled/disabled (checkbox)
172 	CAIRO_DOCK_MODEL_ORDER,  // used to sort lines
173 	CAIRO_DOCK_MODEL_ORDER2,  // used to sort lines
174 	CAIRO_DOCK_MODEL_ICON,  // icon to be displayed
175 	CAIRO_DOCK_MODEL_STATE,  // used to give a state to the line
176 	CAIRO_DOCK_MODEL_SIZE,  // size
177 	CAIRO_DOCK_MODEL_AUTHOR,  // author
178 	CAIRO_DOCK_MODEL_NB_COLUMNS
179 	} CairoDockGUIModelColumns;
180 
181 /// Definition of a widget corresponding to a given (group;key) pair.
182 struct _CairoDockGroupKeyWidget {
183 	gchar *cGroupName;
184 	gchar *cKeyName;
185 	GSList *pSubWidgetList;
186 	gchar *cOriginalConfFilePath;
187 	GtkWidget *pLabel;
188 	GtkWidget *pKeyBox;
189 	};
190 
191 
192 #if ! GTK_CHECK_VERSION(3, 10, 0)
193 GtkWidget* gtk_button_new_from_icon_name (const gchar *icon_name, GtkIconSize  size);
194 #endif
195 
196 GtkWidget *cairo_dock_gui_make_preview_box (GtkWidget *pMainWindow, GtkWidget *pOneWidget, gboolean bHorizontalPackaging, int iAddInfoBar, const gchar *cInitialDescription, const gchar *cInitialImage, GPtrArray *pDataGarbage);
197 
198 void _cairo_dock_set_value_in_pair (GtkSpinButton *pSpinButton, gpointer *data);  // exportee pour pouvoir desactiver la callback.
199 
200 const gchar *cairo_dock_parse_key_comment (gchar *cKeyComment, char *iElementType, guint *iNbElements, gchar ***pAuthorizedValuesList, gboolean *bAligned, const gchar **cTipString);
201 
202 GtkWidget *cairo_dock_build_group_widget (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cGettextDomain, GtkWidget *pMainWindow, GSList **pWidgetList, GPtrArray *pDataGarbage, const gchar *cOriginalConfFilePath);
203 
204 GtkWidget *cairo_dock_build_key_file_widget_full (GKeyFile* pKeyFile, const gchar *cGettextDomain, GtkWidget *pMainWindow, GSList **pWidgetList, GPtrArray *pDataGarbage, const gchar *cOriginalConfFilePath, GtkWidget *pCurrentNoteBook);
205 
206 #define cairo_dock_build_key_file_widget(pKeyFile, cGettextDomain, pMainWindow, pWidgetList, pDataGarbage, cOriginalConfFilePath) cairo_dock_build_key_file_widget_full (pKeyFile, cGettextDomain, pMainWindow, pWidgetList, pDataGarbage, cOriginalConfFilePath, NULL)
207 
208 GtkWidget *cairo_dock_build_conf_file_widget (const gchar *cConfFilePath, const gchar *cGettextDomain, GtkWidget *pMainWindow, GSList **pWidgetList, GPtrArray *pDataGarbage, const gchar *cOriginalConfFilePath);
209 
210 
211 void cairo_dock_update_keyfile_from_widget_list (GKeyFile *pKeyFile, GSList *pWidgetList);
212 
213 
214 void cairo_dock_free_generated_widget_list (GSList *pWidgetList);
215 
216 
217   ///////////////
218  // utilities //
219 ///////////////
220 
221 void cairo_dock_fill_model_with_themes (GtkListStore *pModel, GHashTable *pThemeTable, const gchar *cHint);
222 
223 void cairo_dock_fill_combo_with_list (GtkWidget *pCombo, GList *pElementList, const gchar *cActiveElement);  // utile pour les applets.
224 
225 GtkWidget *cairo_dock_gui_make_tree_view (gboolean bGetActiveOnly);
226 
227 GtkWidget *cairo_dock_gui_make_combo (gboolean bWithEntry);
228 
229 void cairo_dock_gui_select_in_combo_full (GtkWidget *pOneWidget, const gchar *cValue, gboolean bIsTheme);
230 #define cairo_dock_gui_select_in_combo(pOneWidget, cValue) cairo_dock_gui_select_in_combo_full (pOneWidget, cValue, FALSE)
231 
232 gchar **cairo_dock_gui_get_active_rows_in_tree_view (GtkWidget *pOneWidget, gboolean bSelectedRows, gsize *iNbElements);
233 
234 /** Get a widget from a list of widgets representing a configuration window.
235 The widgets represent a pair (group,key) as defined in the config file.
236 @param pWidgetList list of widgets built from the config file
237 @param cGroupName name of the group the widget belongs to
238 @param cKeyName name of the key the widget represents
239 @return the widget asociated with the (group,key) , or NULL if none is found
240 */
241 CairoDockGroupKeyWidget *cairo_dock_gui_find_group_key_widget_in_list (GSList *pWidgetList, const gchar *cGroupName, const gchar *cKeyName);
242 
243 #define cairo_dock_gui_get_widgets(pGroupKeyWidget) (pGroupKeyWidget)->pSubWidgetList
244 #define cairo_dock_gui_get_first_widget(pGroupKeyWidget) ((pGroupKeyWidget)->pSubWidgetList ? (pGroupKeyWidget)->pSubWidgetList->data : NULL)
245 #define cairo_dock_gui_add_widget(pGroupKeyWidget, pOneWidget) (pGroupKeyWidget)->pSubWidgetList = g_slist_append ((pGroupKeyWidget)->pSubWidgetList, pOneWidget)
246 
247 GtkWidget *_gtk_image_new_from_file (const gchar *cIcon, int iSize);
248 
249 G_END_DECLS
250 #endif
251