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