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