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