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