call set_mode_indicator after updating the whatever_indicator setting
[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 char *
218 itos(int val);
219
220 char *
221 str_replace (const char* search, const char* replace, const char* string);
222
223 GArray*
224 read_file_by_line (gchar *path);
225
226 gchar*
227 parseenv (char* string);
228
229 void
230 clean_up(void);
231
232 void
233 catch_sigterm(int s);
234
235 sigfunc *
236 setup_signal(int signe, sigfunc *shandler);
237
238 gboolean
239 set_var_value(gchar *name, gchar *val);
240
241 void
242 print(WebKitWebView *page, GArray *argv, GString *result);
243
244 gboolean
245 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
246
247 gboolean
248 mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
249
250 WebKitWebView*
251 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
252
253 gboolean
254 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
255
256 void
257 toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result);
258
259 void
260 toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result);
261
262 void
263 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
264
265 void
266 title_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
267
268 void
269 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
270
271 void
272 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
273
274 void
275 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
276
277 void
278 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
279
280 void
281 destroy_cb (GtkWidget* widget, gpointer data);
282
283 void
284 log_history_cb ();
285
286 void
287 commands_hash(void);
288
289 void
290 free_action(gpointer act);
291
292 Action*
293 new_action(const gchar *name, const gchar *param);
294
295 bool
296 file_exists (const char * filename);
297
298 void
299 set_keycmd();
300
301 void
302 set_mode_indicator();
303
304 void
305 update_indicator();
306
307 void
308 set_insert_mode(gboolean mode);
309
310 void
311 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
312
313 void
314 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
315
316 void
317 new_window_load_uri (const gchar * uri);
318
319 void
320 chain (WebKitWebView *page, GArray *argv, GString *result);
321
322 void
323 keycmd (WebKitWebView *page, GArray *argv, GString *result);
324
325 void
326 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
327
328 void
329 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
330
331 void
332 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
333
334 gboolean
335 run_command(const gchar *command, const guint npre,
336             const gchar **args, const gboolean sync, char **output_stdout);
337
338 char*
339 build_progressbar_ascii(int percent);
340
341 void
342 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
343
344 void
345 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
346
347 void
348 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
349
350 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 void
357 parse_cmd_line(const char *ctl_line, GString *result);
358
359 gchar*
360 build_stream_name(int type, const gchar *dir);
361
362 gboolean
363 control_fifo(GIOChannel *gio, GIOCondition condition);
364
365 gchar*
366 init_fifo(gchar *dir);
367
368 gboolean
369 control_stdin(GIOChannel *gio, GIOCondition condition);
370
371 void
372 create_stdin();
373
374 gchar*
375 init_socket(gchar *dir);
376
377 gboolean
378 control_socket(GIOChannel *chan);
379
380 gboolean
381 control_client_socket(GIOChannel *chan);
382
383 void
384 update_title (void);
385
386 gboolean
387 key_press_cb (GtkWidget* window, GdkEventKey* event);
388
389 void
390 run_keycmd(const gboolean key_ret);
391
392 void
393 exec_paramcmd(const Action* act, const guint i);
394
395 void
396 initialize ();
397
398 GtkWidget*
399 create_browser ();
400
401 GtkWidget*
402 create_mainbar ();
403
404 GtkWidget*
405 create_window ();
406
407 GtkPlug*
408 create_plug ();
409
410 void
411 run_handler (const gchar *act, const gchar *args);
412
413 void
414 add_binding (const gchar *key, const gchar *act);
415
416 gchar*
417 get_xdg_var (XDG_Var xdg);
418
419 gchar*
420 find_xdg_file (int xdg_type, char* filename);
421
422 void
423 settings_init ();
424
425 void
426 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
427
428 void
429 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
430
431 void
432 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
433
434 void
435 dehilight (WebKitWebView *page, GArray *argv, GString *result);
436
437 void
438 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
439
440 void
441 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
442
443 void
444 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
445
446 void handle_cookies (SoupSession *session,
447                             SoupMessage *msg,
448                             gpointer     user_data);
449 void
450 save_cookies (SoupMessage *msg,
451                 gpointer     user_data);
452
453 void
454 set_var(WebKitWebView *page, GArray *argv, GString *result);
455
456 void
457 act_bind(WebKitWebView *page, GArray *argv, GString *result);
458
459 void
460 act_dump_config();
461
462 void
463 render_html();
464
465 void
466 set_timeout(int seconds);
467
468 void
469 dump_var_hash(gpointer k, gpointer v, gpointer ud);
470
471 void
472 dump_key_hash(gpointer k, gpointer v, gpointer ud);
473
474 void
475 dump_config();
476
477 void
478 retreive_geometry();
479
480 gboolean
481 configure_event_cb(GtkWidget* window, GdkEventConfigure* event);
482
483 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
484 typedef struct {
485     Command function;
486     gboolean no_split;
487 } CommandInfo;
488
489 /* Command callbacks */
490 void
491 cmd_load_uri();
492
493 void
494 cmd_set_status();
495
496 void
497 set_proxy_url();
498
499 void
500 set_icon();
501
502 void
503 cmd_cookie_handler();
504
505 void
506 cmd_new_window();
507
508 void
509 move_statusbar();
510
511 void
512 cmd_always_insert_mode();
513
514 void
515 cmd_http_debug();
516
517 void
518 cmd_max_conns();
519
520 void
521 cmd_max_conns_host();
522
523 /* exported WebKitWebSettings properties */
524
525 void
526 cmd_font_size();
527
528 void
529 cmd_zoom_level();
530
531 void
532 cmd_disable_plugins();
533
534 void
535 cmd_disable_scripts();
536
537 void
538 cmd_minimum_font_size();
539
540 void
541 cmd_fifo_dir();
542
543 void
544 cmd_socket_dir();
545
546 void
547 cmd_modkey();
548
549 void
550 cmd_useragent() ;
551
552 void
553 cmd_autoload_img();
554
555 void
556 cmd_autoshrink_img();
557
558 void
559 cmd_enable_spellcheck();
560
561 void
562 cmd_enable_private();
563
564 void
565 cmd_print_bg();
566
567 void
568 cmd_style_uri();
569
570 void
571 cmd_resizable_txt();
572
573 void
574 cmd_default_encoding();
575
576 void
577 cmd_enforce_96dpi();
578
579 void
580 cmd_inject_html();
581
582 void
583 cmd_caret_browsing();
584
585 void
586 cmd_set_geometry();
587
588 /* vi: set et ts=4: */