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