update mode indicator when @insert_mode is set
[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_mode_indicator();
302
303 void
304 set_insert_mode(gboolean mode);
305
306 static void
307 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
308
309 static void
310 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
311
312 static void
313 new_window_load_uri (const gchar * uri);
314
315 static void
316 chain (WebKitWebView *page, GArray *argv, GString *result);
317
318 static void
319 keycmd (WebKitWebView *page, GArray *argv, GString *result);
320
321 static void
322 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
323
324 static void
325 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
326
327 static void
328 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
329
330 static gboolean
331 run_command(const gchar *command, const guint npre,
332             const gchar **args, const gboolean sync, char **output_stdout);
333
334 static char*
335 build_progressbar_ascii(int percent);
336
337 static void
338 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
339
340 static void
341 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
342
343 static void
344 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
345
346 static void
347 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
348
349 static void
350 parse_command(const char *cmd, const char *param, GString *result);
351
352 static void
353 parse_cmd_line(const char *ctl_line, GString *result);
354
355 static gchar*
356 build_stream_name(int type, const gchar *dir);
357
358 static gboolean
359 control_fifo(GIOChannel *gio, GIOCondition condition);
360
361 static gchar*
362 init_fifo(gchar *dir);
363
364 static gboolean
365 control_stdin(GIOChannel *gio, GIOCondition condition);
366
367 static void
368 create_stdin();
369
370 static gchar*
371 init_socket(gchar *dir);
372
373 static gboolean
374 control_socket(GIOChannel *chan);
375
376 static gboolean
377 control_client_socket(GIOChannel *chan);
378
379 static void
380 update_title (void);
381
382 static gboolean
383 key_press_cb (GtkWidget* window, GdkEventKey* event);
384
385 static void
386 run_keycmd(const gboolean key_ret);
387
388 static void
389 exec_paramcmd(const Action* act, const guint i);
390
391 void
392 initialize ();
393
394 GtkWidget*
395 create_browser ();
396
397 static GtkWidget*
398 create_mainbar ();
399
400 static
401 GtkWidget* create_window ();
402
403 static
404 GtkPlug* create_plug ();
405
406 static void
407 run_handler (const gchar *act, const gchar *args);
408
409 static void
410 add_binding (const gchar *key, const gchar *act);
411
412 static gchar*
413 get_xdg_var (XDG_Var xdg);
414
415 static gchar*
416 find_xdg_file (int xdg_type, char* filename);
417
418 static void
419 settings_init ();
420
421 static void
422 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
423
424 static void
425 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
426
427 static void
428 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
429
430 static void
431 dehilight (WebKitWebView *page, GArray *argv, GString *result);
432
433 static void
434 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
435
436 static void
437 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
438
439 static void
440 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
441
442 static void handle_cookies (SoupSession *session,
443                             SoupMessage *msg,
444                             gpointer     user_data);
445 static void
446 save_cookies (SoupMessage *msg,
447                 gpointer     user_data);
448
449 static void
450 set_var(WebKitWebView *page, GArray *argv, GString *result);
451
452 static void
453 act_bind(WebKitWebView *page, GArray *argv, GString *result);
454
455 static void
456 act_dump_config();
457
458 static void
459 render_html();
460
461 static void
462 set_timeout(int seconds);
463
464 static void
465 dump_var_hash(gpointer k, gpointer v, gpointer ud);
466
467 static void
468 dump_key_hash(gpointer k, gpointer v, gpointer ud);
469
470 static void
471 dump_config();
472
473
474 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
475 typedef struct {
476     Command function;
477     gboolean no_split;
478 } CommandInfo;
479
480 /* Command callbacks */
481 static void
482 cmd_load_uri();
483
484 static void
485 cmd_set_status();
486
487 static void
488 set_proxy_url();
489
490 static void
491 set_icon();
492
493 static void
494 cmd_cookie_handler();
495
496 static void
497 cmd_new_window();
498
499 static void
500 move_statusbar();
501
502 static void
503 cmd_always_insert_mode();
504
505 static void
506 cmd_http_debug();
507
508 static void
509 cmd_max_conns();
510
511 static void
512 cmd_max_conns_host();
513
514 /* exported WebKitWebSettings properties */
515
516 static void
517 cmd_font_size();
518
519 static void
520 cmd_zoom_level();
521
522 static void
523 cmd_disable_plugins();
524
525 static void
526 cmd_disable_scripts();
527
528 static void
529 cmd_minimum_font_size();
530
531 static void
532 cmd_fifo_dir();
533
534 static void
535 cmd_socket_dir();
536
537 static void
538 cmd_modkey();
539
540 void
541 cmd_useragent() ;
542
543 static void
544 cmd_autoload_img();
545
546 static void
547 cmd_autoshrink_img();
548
549 static void
550 cmd_enable_spellcheck();
551
552 static void
553 cmd_enable_private();
554
555 static void
556 cmd_print_bg();
557
558 static void
559 cmd_style_uri();
560
561 static void
562 cmd_resizable_txt();
563
564 static void
565 cmd_default_encoding();
566
567 static void
568 cmd_enforce_96dpi();
569
570 static void
571 cmd_inject_html();
572
573 static void
574 cmd_caret_browsing();
575
576 /* vi: set et ts=4: */