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