pass char* as const char * where possible
[uzbl-mobile] / uzbl.h
1 /* -*- c-basic-offset: 4; -*-
2
3  * See LICENSE for license details
4  *
5  * Changelog:
6  * ---------
7  *
8  * (c) 2009 by Robert Manea
9  *     - introduced struct concept
10  *     - statusbar template
11  *
12  */
13
14 enum {
15   /* statusbar symbols */
16   SYM_TITLE, SYM_URI, SYM_NAME,
17   SYM_LOADPRGS, SYM_LOADPRGSBAR,
18   SYM_KEYCMD, SYM_MODE, SYM_MSG,
19   SYM_SELECTED_URI,
20 };
21
22 const struct {
23     gchar *symbol_name;
24     guint symbol_token;
25 } symbols[] = {
26     {"KEYCMD",               SYM_KEYCMD},
27
28     {NULL,                   0}
29 }, *symp = symbols;
30
31 /* status bar elements */
32 typedef struct {
33     gint           load_progress;
34     gchar          *msg;
35     gchar          *progress_s, *progress_u;
36     int            progress_w;
37     gchar          *progress_bar;
38     gchar          *mode_indicator;
39 } StatusBar;
40
41
42 /* gui elements */
43 typedef struct {
44     GtkWidget*     main_window;
45     gchar*         geometry;
46     GtkPlug*       plug;
47     GtkWidget*     scrolled_win;
48     GtkWidget*     vbox;
49     GtkWidget*     mainbar;
50     GtkWidget*     mainbar_label;
51     GtkScrollbar*  scbar_v;   // Horizontal and Vertical Scrollbar
52     GtkScrollbar*  scbar_h;   // (These are still hidden)
53     GtkAdjustment* bar_v; // Information about document length
54     GtkAdjustment* bar_h; // and scrolling position
55     WebKitWebView* web_view;
56     gchar*         main_title;
57     gchar*         icon;
58
59     /* WebInspector */
60     GtkWidget *inspector_window;
61     WebKitWebInspector *inspector;
62
63     StatusBar sbar;
64 } GUI;
65
66
67 /* external communication*/
68 enum { FIFO, SOCKET};
69 typedef struct {
70     gchar          *fifo_path;
71     gchar          *socket_path;
72     /* stores (key)"variable name" -> (value)"pointer to this var*/
73     GHashTable     *proto_var;
74
75     gchar          *sync_stdout;
76 } Communication;
77
78
79 /* internal state */
80 typedef struct {
81     gchar    *uri;
82     gchar    *config_file;
83     int      socket_id;
84     char     *instance_name;
85     gchar    *selected_url;
86     gchar    *executable_path;
87     gchar*   keycmd;
88     gchar*   searchtx;
89     gboolean verbose;
90 } State;
91
92
93 /* networking */
94 typedef struct {
95     SoupSession *soup_session;
96     SoupLogger *soup_logger;
97     char *proxy_url;
98     char *useragent;
99     gint max_conns;
100     gint max_conns_host;
101 } Network;
102
103
104 /* behaviour */
105 typedef struct {
106     gchar*   load_finish_handler;
107     gchar*   load_start_handler;
108     gchar*   load_commit_handler;
109     gchar*   status_format;
110     gchar*   title_format_short;
111     gchar*   title_format_long;
112     gchar*   status_background;
113     gchar*   history_handler;
114     gchar*   fifo_dir;
115     gchar*   socket_dir;
116     gchar*   download_handler;
117     gchar*   cookie_handler;
118     gchar*   new_window;
119     gboolean always_insert_mode;
120     gboolean show_status;
121     gboolean insert_mode;
122     gboolean status_top;
123     gboolean reset_command_mode;
124     gchar*   modkey;
125     guint    modmask;
126     guint    http_debug;
127     gchar*   shell_cmd;
128     /* WebKitWebSettings exports */
129     guint    font_size;
130     guint    monospace_size;
131     guint    minimum_font_size;
132     gfloat   zoom_level;
133     guint    disable_plugins;
134     guint    disable_scripts;
135     guint    autoload_img;
136     guint    autoshrink_img;
137     guint    enable_spellcheck;
138     guint    enable_private;
139     guint    print_bg;
140     gchar*   style_uri;
141     guint    resizable_txt;
142     gchar*   default_encoding;
143     guint    enforce_96dpi;
144     gchar    *inject_html;
145     guint    caret_browsing;
146     guint    mode;
147     gchar*   base_url;
148     gchar*   html_endmarker;
149     gchar*   insert_indicator;
150     gchar*   cmd_indicator;
151     GString* html_buffer;
152     guint    html_timeout;
153     gboolean print_version;
154
155     /* command list: name -> Command  */
156     GHashTable* commands;
157 } Behaviour;
158
159 /* javascript */
160 typedef struct {
161     gboolean            initialized;
162     JSClassDefinition   classdef;
163     JSClassRef          classref;
164 } Javascript;
165
166 /* static information */
167 typedef struct {
168     int   webkit_major;
169     int   webkit_minor;
170     int   webkit_micro;
171     gchar *arch;
172     gchar *commit;
173 } Info;
174
175 /* main uzbl data structure */
176 typedef struct {
177     GUI           gui;
178     State         state;
179     Network       net;
180     Behaviour     behave;
181     Communication comm;
182     Javascript    js;
183     Info          info;
184
185     Window        xwin;
186
187     /* group bindings: key -> action */
188     GHashTable* bindings;
189 } Uzbl;
190
191
192 typedef struct {
193     char* name;
194     char* param;
195 } Action;
196
197 typedef void sigfunc(int);
198
199 /* XDG Stuff */
200
201 typedef struct {
202     gchar* environmental;
203     gchar* default_value;
204 } XDG_Var;
205
206 XDG_Var XDG[] =
207 {
208     { "XDG_CONFIG_HOME", "~/.config" },
209     { "XDG_DATA_HOME",   "~/.local/share" },
210     { "XDG_CACHE_HOME",  "~/.cache" },
211     { "XDG_CONFIG_DIRS", "/etc/xdg" },
212     { "XDG_DATA_DIRS",   "/usr/local/share/:/usr/share/" },
213 };
214
215 /* Functions */
216 char *
217 itos(int val);
218
219 char *
220 str_replace (const char* search, const char* replace, const char* string);
221
222 GArray*
223 read_file_by_line (gchar *path);
224
225 gchar*
226 parseenv (char* string);
227
228 void
229 clean_up(void);
230
231 void
232 catch_sigterm(int s);
233
234 sigfunc *
235 setup_signal(int signe, sigfunc *shandler);
236
237 gboolean
238 set_var_value(gchar *name, gchar *val);
239
240 void
241 print(WebKitWebView *page, GArray *argv, GString *result);
242
243 gboolean
244 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
245
246 gboolean
247 mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
248
249 WebKitWebView*
250 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
251
252 gboolean
253 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
254
255 void
256 toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result);
257
258 void
259 toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result);
260
261 void
262 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
263
264 void
265 title_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
266
267 void
268 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
269
270 void
271 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
272
273 void
274 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
275
276 void
277 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
278
279 void
280 destroy_cb (GtkWidget* widget, gpointer data);
281
282 void
283 log_history_cb ();
284
285 void
286 commands_hash(void);
287
288 void
289 free_action(gpointer act);
290
291 Action*
292 new_action(const gchar *name, const gchar *param);
293
294 bool
295 file_exists (const char * filename);
296
297 void
298 set_keycmd();
299
300 void
301 set_mode_indicator();
302
303 void
304 update_indicator();
305
306 void
307 set_insert_mode(gboolean mode);
308
309 void
310 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
311
312 void
313 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
314
315 void
316 new_window_load_uri (const gchar * uri);
317
318 void
319 chain (WebKitWebView *page, GArray *argv, GString *result);
320
321 void
322 keycmd (WebKitWebView *page, GArray *argv, GString *result);
323
324 void
325 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
326
327 void
328 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
329
330 void
331 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
332
333 gboolean
334 run_command(const gchar *command, const guint npre,
335             const gchar **args, const gboolean sync, char **output_stdout);
336
337 char*
338 build_progressbar_ascii(int percent);
339
340 void
341 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
342
343 void
344 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
345
346 void
347 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
348
349 void
350 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
351
352 void
353 parse_command(const char *cmd, const char *param, GString *result);
354
355 void
356 parse_cmd_line(const char *ctl_line, GString *result);
357
358 gchar*
359 build_stream_name(int type, const gchar *dir);
360
361 gboolean
362 control_fifo(GIOChannel *gio, GIOCondition condition);
363
364 gchar*
365 init_fifo(gchar *dir);
366
367 gboolean
368 control_stdin(GIOChannel *gio, GIOCondition condition);
369
370 void
371 create_stdin();
372
373 gchar*
374 init_socket(gchar *dir);
375
376 gboolean
377 control_socket(GIOChannel *chan);
378
379 gboolean
380 control_client_socket(GIOChannel *chan);
381
382 void
383 update_title (void);
384
385 gboolean
386 key_press_cb (GtkWidget* window, GdkEventKey* event);
387
388 void
389 run_keycmd(const gboolean key_ret);
390
391 void
392 exec_paramcmd(const Action* act, const guint i);
393
394 void
395 initialize (int argc, char *argv[]);
396
397 GtkWidget*
398 create_browser ();
399
400 GtkWidget*
401 create_mainbar ();
402
403 GtkWidget*
404 create_window ();
405
406 GtkPlug*
407 create_plug ();
408
409 void
410 run_handler (const gchar *act, const gchar *args);
411
412 void
413 add_binding (const gchar *key, const gchar *act);
414
415 gchar*
416 get_xdg_var (XDG_Var xdg);
417
418 gchar*
419 find_xdg_file (int xdg_type, char* filename);
420
421 void
422 settings_init ();
423
424 void
425 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
426
427 void
428 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
429
430 void
431 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
432
433 void
434 dehilight (WebKitWebView *page, GArray *argv, GString *result);
435
436 void
437 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
438
439 void
440 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
441
442 void
443 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
444
445 void handle_cookies (SoupSession *session,
446                             SoupMessage *msg,
447                             gpointer     user_data);
448 void
449 save_cookies (SoupMessage *msg,
450                 gpointer     user_data);
451
452 void
453 set_var(WebKitWebView *page, GArray *argv, GString *result);
454
455 void
456 act_bind(WebKitWebView *page, GArray *argv, GString *result);
457
458 void
459 act_dump_config();
460
461 void
462 render_html();
463
464 void
465 set_timeout(int seconds);
466
467 void
468 dump_var_hash(gpointer k, gpointer v, gpointer ud);
469
470 void
471 dump_key_hash(gpointer k, gpointer v, gpointer ud);
472
473 void
474 dump_config();
475
476 void
477 retreive_geometry();
478
479 gboolean
480 configure_event_cb(GtkWidget* window, GdkEventConfigure* event);
481
482 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
483 typedef struct {
484     Command function;
485     gboolean no_split;
486 } CommandInfo;
487
488 /* Command callbacks */
489 void
490 cmd_load_uri();
491
492 void
493 cmd_set_status();
494
495 void
496 set_proxy_url();
497
498 void
499 set_icon();
500
501 void
502 cmd_cookie_handler();
503
504 void
505 cmd_new_window();
506
507 void
508 move_statusbar();
509
510 void
511 cmd_always_insert_mode();
512
513 void
514 cmd_http_debug();
515
516 void
517 cmd_max_conns();
518
519 void
520 cmd_max_conns_host();
521
522 /* exported WebKitWebSettings properties */
523
524 void
525 cmd_font_size();
526
527 void
528 cmd_zoom_level();
529
530 void
531 cmd_disable_plugins();
532
533 void
534 cmd_disable_scripts();
535
536 void
537 cmd_minimum_font_size();
538
539 void
540 cmd_fifo_dir();
541
542 void
543 cmd_socket_dir();
544
545 void
546 cmd_modkey();
547
548 void
549 cmd_useragent() ;
550
551 void
552 cmd_autoload_img();
553
554 void
555 cmd_autoshrink_img();
556
557 void
558 cmd_enable_spellcheck();
559
560 void
561 cmd_enable_private();
562
563 void
564 cmd_print_bg();
565
566 void
567 cmd_style_uri();
568
569 void
570 cmd_resizable_txt();
571
572 void
573 cmd_default_encoding();
574
575 void
576 cmd_enforce_96dpi();
577
578 void
579 cmd_inject_html();
580
581 void
582 cmd_caret_browsing();
583
584 void
585 cmd_set_geometry();
586
587 /* vi: set et ts=4: */