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