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