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