lots of stuff, see below.
[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
80     gchar          *sync_stdout;
81 } Communication;
82
83
84 /* internal state */
85 typedef struct {
86     gchar    *uri;
87     gchar    *config_file;
88     int      socket_id;
89     char     *instance_name;
90     gchar    *selected_url;
91     gchar    *executable_path;
92     GString* keycmd;
93     gchar*   searchtx;
94     gboolean verbose;
95 } State;
96
97
98 /* networking */
99 typedef struct {
100     SoupSession *soup_session;
101     SoupLogger *soup_logger;
102     char *proxy_url;
103     char *useragent;
104     gint max_conns;
105     gint max_conns_host;
106 } Network;
107
108
109 /* behaviour */
110 typedef struct {
111     gchar*   load_finish_handler;
112     gchar*   load_start_handler;
113     gchar*   load_commit_handler;
114     gchar*   status_format;
115     gchar*   title_format_short;
116     gchar*   title_format_long;
117     gchar*   status_background;
118     gchar*   history_handler;
119     gchar*   fifo_dir;
120     gchar*   socket_dir;
121     gchar*   download_handler;
122     gchar*   cookie_handler;
123     gboolean always_insert_mode;
124     gboolean show_status;
125     gboolean insert_mode;
126     gboolean status_top;
127     gboolean reset_command_mode;
128     gchar*   modkey;
129     guint    modmask;
130     guint    http_debug;
131     gchar*   shell_cmd;
132     /* WebKitWebSettings exports */
133     guint    font_size;
134     guint    monospace_size;
135     guint    minimum_font_size;
136     gfloat   zoom_level;
137     guint    disable_plugins;
138     guint    disable_scripts;
139     guint    autoload_img;    
140     guint    autoshrink_img;  
141     guint    enable_spellcheck;
142     guint    enable_private;  
143     guint    print_bg;        
144     gchar*   style_uri;       
145     guint    resizable_txt;  
146     gchar*   default_encoding;       
147     guint    enforce_96dpi;  
148     gchar    *inject_html;
149     guint    caret_browsing;  
150     guint    mode;  
151     gchar*   base_url;
152     gchar*   html_endmarker;
153     gchar*   insert_indicator;
154     gchar*   cmd_indicator;
155     GString* html_buffer;
156     guint    html_timeout;  
157
158     /* command list: name -> Command  */
159     GHashTable* commands;
160 } Behaviour;
161
162 /* javascript */
163 typedef struct {
164     gboolean            initialized;
165     JSClassDefinition   classdef;
166     JSClassRef          classref;
167 } Javascript;
168
169 /* static information */
170 typedef struct {
171     int   webkit_major;
172     int   webkit_minor;
173     int   webkit_micro;
174     gchar *arch;
175     gchar *commit;
176 } Info;
177
178 /* main uzbl data structure */
179 typedef struct {
180     GUI           gui;
181     State         state;
182     Network       net;
183     Behaviour     behave;
184     Communication comm;
185     Javascript    js;
186     Info          info;
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 void
221 setup_scanner();
222
223 char *
224 itos(int val);
225
226 static char *
227 str_replace (const char* search, const char* replace, const char* string);
228
229 static GArray*
230 read_file_by_line (gchar *path);
231
232 static
233 gchar* parseenv (char* string);
234
235 static void
236 clean_up(void);
237
238 static void
239 catch_sigterm(int s);
240
241 static sigfunc *
242 setup_signal(int signe, sigfunc *shandler);
243
244 gboolean
245 set_var_value(gchar *name, gchar *val);
246
247 static void
248 print(WebKitWebView *page, GArray *argv, GString *result);
249
250 static gboolean
251 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
252
253 static gboolean
254 mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
255
256 WebKitWebView*
257 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
258
259 static gboolean
260 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
261
262 static void
263 toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result);
264
265 static void
266 toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result);
267
268 static void
269 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
270
271 static void
272 title_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
273
274 static void
275 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
276
277 static void
278 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
279
280 static void
281 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
282
283 static void
284 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
285
286 static void
287 destroy_cb (GtkWidget* widget, gpointer data);
288
289 static void
290 log_history_cb ();
291
292 static 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 static bool
302 file_exists (const char * filename);
303
304 static void
305 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
306
307 static void
308 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
309
310 static void
311 new_window_load_uri (const gchar * uri);
312
313 static void
314 chain (WebKitWebView *page, GArray *argv, GString *result);
315
316 static void
317 keycmd (WebKitWebView *page, GArray *argv, GString *result);
318
319 static void
320 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
321
322 static void
323 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
324
325 static void
326 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
327
328 static gboolean
329 run_command(const gchar *command, const guint npre,
330             const gchar **args, const gboolean sync, char **output_stdout);
331
332 static void
333 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
334
335 static void
336 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
337
338 static void
339 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
340
341 static void
342 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
343
344 static void
345 parse_command(const char *cmd, const char *param, GString *result);
346
347 static void
348 parse_cmd_line(const char *ctl_line, GString *result);
349
350 static gchar*
351 build_stream_name(int type, const gchar *dir);
352
353 static gboolean
354 control_fifo(GIOChannel *gio, GIOCondition condition);
355
356 static gchar*
357 init_fifo(gchar *dir);
358
359 static gboolean
360 control_stdin(GIOChannel *gio, GIOCondition condition);
361
362 static void
363 create_stdin();
364
365 static gchar*
366 init_socket(gchar *dir);
367
368 static gboolean
369 control_socket(GIOChannel *chan);
370
371 static gboolean
372 control_client_socket(GIOChannel *chan);
373
374 static void
375 update_title (void);
376
377 static gboolean
378 key_press_cb (GtkWidget* window, GdkEventKey* event);
379
380 static void
381 run_keycmd(const gboolean key_ret);
382
383 static void
384 exec_paramcmd(const Action* act, const guint i);
385
386 void
387 initialize ();
388
389 GtkWidget*
390 create_browser ();
391
392 static GtkWidget*
393 create_mainbar ();
394
395 static
396 GtkWidget* create_window ();
397
398 static
399 GtkPlug* create_plug ();
400
401 static void
402 run_handler (const gchar *act, const gchar *args);
403
404 static void
405 add_binding (const gchar *key, const gchar *act);
406
407 static gchar*
408 get_xdg_var (XDG_Var xdg);
409
410 static gchar*
411 find_xdg_file (int xdg_type, char* filename);
412
413 static void
414 settings_init ();
415
416 static void
417 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
418
419 static void
420 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
421
422 static void
423 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
424
425 static void
426 dehilight (WebKitWebView *page, GArray *argv, GString *result);
427
428 static void
429 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
430
431 static void
432 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
433
434 static void
435 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
436
437 static void handle_cookies (SoupSession *session,
438                             SoupMessage *msg,
439                             gpointer     user_data);
440 static void
441 save_cookies (SoupMessage *msg,
442                 gpointer     user_data);
443
444 static void
445 set_var(WebKitWebView *page, GArray *argv, GString *result);
446
447 static void
448 act_bind(WebKitWebView *page, GArray *argv, GString *result);
449
450 static void
451 act_dump_config();
452
453 static void
454 render_html();
455
456 static void
457 set_timeout(int seconds);
458
459 static void
460 dump_var_hash(gpointer k, gpointer v, gpointer ud);
461
462 static void
463 dump_key_hash(gpointer k, gpointer v, gpointer ud);
464
465 static void
466 dump_config();
467
468
469 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
470 typedef struct {
471     Command function;
472     gboolean no_split;
473 } CommandInfo;
474
475 /* Command callbacks */
476 static void
477 cmd_load_uri();
478
479 static void
480 cmd_set_status();
481
482 static void
483 set_proxy_url();
484
485 static void
486 set_icon();
487
488 static void
489 cmd_cookie_handler();
490
491 static void
492 move_statusbar();
493
494 static void
495 cmd_always_insert_mode();
496
497 static void
498 cmd_http_debug();
499
500 static void
501 cmd_max_conns();
502
503 static void
504 cmd_max_conns_host();
505
506 /* exported WebKitWebSettings properties */
507
508 static void
509 cmd_font_size();
510
511 static void
512 cmd_zoom_level();
513
514 static void
515 cmd_disable_plugins();
516
517 static void
518 cmd_disable_scripts();
519
520 static void
521 cmd_minimum_font_size();
522
523 static void
524 cmd_fifo_dir();
525
526 static void
527 cmd_socket_dir();
528
529 static void
530 cmd_modkey();
531
532 void
533 cmd_useragent() ;
534
535 static void
536 cmd_autoload_img();
537
538 static void
539 cmd_autoshrink_img();
540
541 static void
542 cmd_enable_spellcheck();
543
544 static void
545 cmd_enable_private();
546
547 static void
548 cmd_print_bg();
549
550 static void 
551 cmd_style_uri();
552
553 static void 
554 cmd_resizable_txt();
555
556 static void 
557 cmd_default_encoding();
558
559 static void 
560 cmd_enforce_96dpi();
561
562 static void
563 cmd_inject_html();
564
565 static void 
566 cmd_caret_browsing();
567
568 /* vi: set et ts=4: */