Merge commit 'remotes/holizz/home-and-end' into experimental
[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*   history_handler;
97     gchar*   fifo_dir;
98     gchar*   socket_dir;
99     gchar*   download_handler;
100     gchar*   cookie_handler;
101     gchar*   new_window;
102     gchar*   default_font_family;
103     gchar*   monospace_font_family;
104     gchar*   sans_serif_font_family;
105     gchar*   serif_font_family;
106     gchar*   fantasy_font_family;
107     gchar*   cursive_font_family;
108     gchar*   scheme_handler;
109     gboolean always_insert_mode;
110     gboolean show_status;
111     gboolean insert_mode;
112     gboolean status_top;
113     gboolean reset_command_mode;
114     gchar*   modkey;
115     guint    modmask;
116     guint    http_debug;
117     gchar*   shell_cmd;
118     /* WebKitWebSettings exports */
119     guint    font_size;
120     guint    monospace_size;
121     guint    minimum_font_size;
122     gfloat   zoom_level;
123     guint    disable_plugins;
124     guint    disable_scripts;
125     guint    autoload_img;
126     guint    autoshrink_img;
127     guint    enable_spellcheck;
128     guint    enable_private;
129     guint    print_bg;
130     gchar*   style_uri;
131     guint    resizable_txt;
132     gchar*   default_encoding;
133     guint    enforce_96dpi;
134     gchar    *inject_html;
135     guint    caret_browsing;
136     guint    mode;
137     gchar*   base_url;
138     gchar*   insert_indicator;
139     gchar*   cmd_indicator;
140     gboolean print_version;
141
142     /* command list: name -> Command  */
143     GHashTable* commands;
144 } Behaviour;
145
146 /* javascript */
147 typedef struct {
148     gboolean            initialized;
149     JSClassDefinition   classdef;
150     JSClassRef          classref;
151 } Javascript;
152
153 /* static information */
154 typedef struct {
155     int   webkit_major;
156     int   webkit_minor;
157     int   webkit_micro;
158     gchar *arch;
159     gchar *commit;
160 } Info;
161
162 /* main uzbl data structure */
163 typedef struct {
164     GUI           gui;
165     State         state;
166     Network       net;
167     Behaviour     behave;
168     Communication comm;
169     Javascript    js;
170     Info          info;
171
172     Window        xwin;
173
174     /* group bindings: key -> action */
175     GHashTable* bindings;
176 } Uzbl;
177
178
179 typedef struct {
180     char* name;
181     char* param;
182 } Action;
183
184 typedef void sigfunc(int);
185
186 /* XDG Stuff */
187
188 typedef struct {
189     gchar* environmental;
190     gchar* default_value;
191 } XDG_Var;
192
193 XDG_Var XDG[] =
194 {
195     { "XDG_CONFIG_HOME", "~/.config" },
196     { "XDG_DATA_HOME",   "~/.local/share" },
197     { "XDG_CACHE_HOME",  "~/.cache" },
198     { "XDG_CONFIG_DIRS", "/etc/xdg" },
199     { "XDG_DATA_DIRS",   "/usr/local/share/:/usr/share/" },
200 };
201
202 /* Functions */
203 char *
204 itos(int val);
205
206 char *
207 str_replace (const char* search, const char* replace, const char* string);
208
209 GArray*
210 read_file_by_line (const gchar *path);
211
212 gchar*
213 parseenv (char* string);
214
215 void
216 clean_up(void);
217
218 void
219 catch_sigterm(int s);
220
221 sigfunc *
222 setup_signal(int signe, sigfunc *shandler);
223
224 gboolean
225 set_var_value(const gchar *name, gchar *val);
226
227 void
228 print(WebKitWebView *page, GArray *argv, GString *result);
229
230 gboolean
231 navigation_decision_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
232
233 gboolean
234 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
235
236 gboolean
237 mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
238
239 /*@null@*/ WebKitWebView*
240 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
241
242 gboolean
243 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
244
245 void
246 toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result);
247
248 void
249 toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result);
250
251 void
252 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
253
254 void
255 title_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
256
257 void
258 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
259
260 void
261 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
262
263 void
264 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
265
266 void
267 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
268
269 void
270 destroy_cb (GtkWidget* widget, gpointer data);
271
272 void
273 log_history_cb ();
274
275 void
276 commands_hash(void);
277
278 void
279 free_action(gpointer act);
280
281 Action*
282 new_action(const gchar *name, const gchar *param);
283
284 bool
285 file_exists (const char * filename);
286
287 void
288 set_keycmd();
289
290 void
291 set_mode_indicator();
292
293 void
294 update_indicator();
295
296 void
297 set_insert_mode(gboolean mode);
298
299 void
300 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
301
302 void
303 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
304
305 void
306 new_window_load_uri (const gchar * uri);
307
308 void
309 chain (WebKitWebView *page, GArray *argv, GString *result);
310
311 void
312 keycmd (WebKitWebView *page, GArray *argv, GString *result);
313
314 void
315 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
316
317 void
318 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
319
320 void
321 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
322
323 gboolean
324 run_command(const gchar *command, const guint npre,
325             const gchar **args, const gboolean sync, char **output_stdout);
326
327 char*
328 build_progressbar_ascii(int percent);
329
330 void
331 talk_to_socket(WebKitWebView *web_view, GArray *argv, GString *result);
332
333 void
334 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
335
336 void
337 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
338
339 void
340 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
341
342 void
343 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
344
345 void
346 parse_command(const char *cmd, const char *param, GString *result);
347
348 void
349 parse_cmd_line(const char *ctl_line, GString *result);
350
351 /*@null@*/ gchar*
352 build_stream_name(int type, const gchar *dir);
353
354 gboolean
355 control_fifo(GIOChannel *gio, GIOCondition condition);
356
357 /*@null@*/ gchar*
358 init_fifo(gchar *dir);
359
360 gboolean
361 control_stdin(GIOChannel *gio, GIOCondition condition);
362
363 void
364 create_stdin();
365
366 /*@null@*/ gchar*
367 init_socket(gchar *dir);
368
369 gboolean
370 control_socket(GIOChannel *chan);
371
372 gboolean
373 control_client_socket(GIOChannel *chan);
374
375 void
376 update_title (void);
377
378 gboolean
379 key_press_cb (GtkWidget* window, GdkEventKey* event);
380
381 void
382 run_keycmd(const gboolean key_ret);
383
384 void
385 exec_paramcmd(const Action* act, const guint i);
386
387 void
388 initialize (int argc, char *argv[]);
389
390 void
391 create_browser ();
392
393 GtkWidget*
394 create_mainbar ();
395
396 GtkWidget*
397 create_window ();
398
399 GtkPlug*
400 create_plug ();
401
402 void
403 run_handler (const gchar *act, const gchar *args);
404
405 void
406 add_binding (const gchar *key, const gchar *act);
407
408 /*@null@*/ gchar*
409 get_xdg_var (XDG_Var xdg);
410
411 /*@null@*/ gchar*
412 find_xdg_file (int xdg_type, const char* filename);
413
414 void
415 settings_init ();
416
417 void
418 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
419
420 void
421 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
422
423 void
424 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
425
426 void
427 dehilight (WebKitWebView *page, GArray *argv, GString *result);
428
429 void
430 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
431
432 void
433 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
434
435 void
436 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
437
438 void handle_cookies (SoupSession *session,
439                             SoupMessage *msg,
440                             gpointer     user_data);
441 void
442 save_cookies (SoupMessage *msg,
443                 gpointer     user_data);
444
445 void
446 set_var(WebKitWebView *page, GArray *argv, GString *result);
447
448 void
449 act_bind(WebKitWebView *page, GArray *argv, GString *result);
450
451 void
452 act_dump_config();
453
454 void
455 dump_var_hash(gpointer k, gpointer v, gpointer ud);
456
457 void
458 dump_key_hash(gpointer k, gpointer v, gpointer ud);
459
460 void
461 dump_config();
462
463 void
464 retrieve_geometry();
465
466 void
467 update_gui(WebKitWebView *page, GArray *argv, GString *result);
468
469 gboolean
470 configure_event_cb(GtkWidget* window, GdkEventConfigure* event);
471
472 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
473 typedef struct {
474     Command function;
475     gboolean no_split;
476 } CommandInfo;
477
478 /* Command callbacks */
479 void
480 cmd_load_uri();
481
482 void
483 cmd_set_status();
484
485 void
486 set_proxy_url();
487
488 void
489 set_icon();
490
491 void
492 cmd_cookie_handler();
493
494 void
495 cmd_scheme_handler();
496
497 void
498 move_statusbar();
499
500 void
501 cmd_always_insert_mode();
502
503 void
504 cmd_http_debug();
505
506 void
507 cmd_max_conns();
508
509 void
510 cmd_max_conns_host();
511
512 /* exported WebKitWebSettings properties */
513
514 void
515 cmd_font_size();
516
517 void
518 cmd_default_font_family();
519
520 void
521 cmd_monospace_font_family();
522
523 void
524 cmd_sans_serif_font_family();
525
526 void
527 cmd_serif_font_family();
528
529 void
530 cmd_cursive_font_family();
531
532 void
533 cmd_fantasy_font_family();
534
535 void
536 cmd_zoom_level();
537
538 void
539 cmd_disable_plugins();
540
541 void
542 cmd_disable_scripts();
543
544 void
545 cmd_minimum_font_size();
546
547 void
548 cmd_fifo_dir();
549
550 void
551 cmd_socket_dir();
552
553 void
554 cmd_modkey();
555
556 void
557 cmd_useragent() ;
558
559 void
560 cmd_autoload_img();
561
562 void
563 cmd_autoshrink_img();
564
565 void
566 cmd_enable_spellcheck();
567
568 void
569 cmd_enable_private();
570
571 void
572 cmd_print_bg();
573
574 void
575 cmd_style_uri();
576
577 void
578 cmd_resizable_txt();
579
580 void
581 cmd_default_encoding();
582
583 void
584 cmd_enforce_96dpi();
585
586 void
587 cmd_inject_html();
588
589 void
590 cmd_caret_browsing();
591
592 void
593 cmd_set_geometry();
594
595 /* vi: set et ts=4: */