@MODE works.
[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     {"MODE",                 SYM_MODE},
28
29     {NULL,                   0}
30 }, *symp = symbols;
31
32 /* status bar elements */
33 typedef struct {
34     gint           load_progress;
35     gchar          *msg;
36     gchar          *progress_s, *progress_u;
37     int            progress_w;
38     gchar          *progress_bar;
39     gchar          *mode_indicator;
40 } StatusBar;
41
42
43 /* gui elements */
44 typedef struct {
45     GtkWidget*     main_window;
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     GString* 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     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
153     /* command list: name -> Command  */
154     GHashTable* commands;
155 } Behaviour;
156
157 /* javascript */
158 typedef struct {
159     gboolean            initialized;
160     JSClassDefinition   classdef;
161     JSClassRef          classref;
162 } Javascript;
163
164 /* static information */
165 typedef struct {
166     int   webkit_major;
167     int   webkit_minor;
168     int   webkit_micro;
169     gchar *arch;
170     gchar *commit;
171 } Info;
172
173 /* main uzbl data structure */
174 typedef struct {
175     GUI           gui;
176     State         state;
177     Network       net;
178     Behaviour     behave;
179     Communication comm;
180     Javascript    js;
181     Info          info;
182
183     Window        xwin;
184     GScanner      *scan;
185
186     /* group bindings: key -> action */
187     GHashTable* bindings;
188 } Uzbl;
189
190
191 typedef struct {
192     char* name;
193     char* param;
194 } Action;
195
196 typedef void sigfunc(int);
197
198 /* XDG Stuff */
199
200 typedef struct {
201     gchar* environmental;
202     gchar* default_value;
203 } XDG_Var;
204
205 XDG_Var XDG[] = 
206 {
207     { "XDG_CONFIG_HOME", "~/.config" },
208     { "XDG_DATA_HOME",   "~/.local/share" },
209     { "XDG_CACHE_HOME",  "~/.cache" },
210     { "XDG_CONFIG_DIRS", "/etc/xdg" },
211     { "XDG_DATA_DIRS",   "/usr/local/share/:/usr/share/" },
212 };
213
214 /* Functions */
215 void
216 setup_scanner();
217
218 char *
219 itos(int val);
220
221 static char *
222 str_replace (const char* search, const char* replace, const char* string);
223
224 static GArray*
225 read_file_by_line (gchar *path);
226
227 static
228 gchar* parseenv (char* string);
229
230 static void
231 clean_up(void);
232
233 static void
234 catch_sigterm(int s);
235
236 static sigfunc *
237 setup_signal(int signe, sigfunc *shandler);
238
239 gboolean
240 set_var_value(gchar *name, gchar *val);
241
242 static void
243 print(WebKitWebView *page, GArray *argv, GString *result);
244
245 static gboolean
246 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
247
248 static gboolean
249 mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
250
251 WebKitWebView*
252 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
253
254 static gboolean
255 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
256
257 static void
258 toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result);
259
260 static void
261 toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result);
262
263 static void
264 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
265
266 static void
267 title_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
268
269 void
270 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
271
272 static void
273 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
274
275 static void
276 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
277
278 static void
279 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
280
281 static void
282 destroy_cb (GtkWidget* widget, gpointer data);
283
284 static void
285 log_history_cb ();
286
287 static void
288 commands_hash(void);
289
290 void
291 free_action(gpointer act);
292
293 Action*
294 new_action(const gchar *name, const gchar *param);
295
296 static bool
297 file_exists (const char * filename);
298
299 static void
300 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
301
302 static void
303 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
304
305 static void
306 new_window_load_uri (const gchar * uri);
307
308 static void
309 chain (WebKitWebView *page, GArray *argv, GString *result);
310
311 static void
312 keycmd (WebKitWebView *page, GArray *argv, GString *result);
313
314 static void
315 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
316
317 static void
318 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
319
320 static void
321 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
322
323 static gboolean
324 run_command(const gchar *command, const guint npre,
325             const gchar **args, const gboolean sync, char **output_stdout);
326
327 static char*
328 build_progressbar_ascii(int percent);
329
330 static void
331 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
332
333 static void
334 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
335
336 static void
337 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
338
339 static void
340 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
341
342 static void
343 parse_command(const char *cmd, const char *param, GString *result);
344
345 static void
346 parse_cmd_line(const char *ctl_line, GString *result);
347
348 static gchar*
349 build_stream_name(int type, const gchar *dir);
350
351 static gboolean
352 control_fifo(GIOChannel *gio, GIOCondition condition);
353
354 static gchar*
355 init_fifo(gchar *dir);
356
357 static gboolean
358 control_stdin(GIOChannel *gio, GIOCondition condition);
359
360 static void
361 create_stdin();
362
363 static gchar*
364 init_socket(gchar *dir);
365
366 static gboolean
367 control_socket(GIOChannel *chan);
368
369 static gboolean
370 control_client_socket(GIOChannel *chan);
371
372 static void
373 update_title (void);
374
375 static gboolean
376 key_press_cb (GtkWidget* window, GdkEventKey* event);
377
378 static void
379 run_keycmd(const gboolean key_ret);
380
381 static void
382 exec_paramcmd(const Action* act, const guint i);
383
384 void
385 initialize ();
386
387 GtkWidget*
388 create_browser ();
389
390 static GtkWidget*
391 create_mainbar ();
392
393 static
394 GtkWidget* create_window ();
395
396 static
397 GtkPlug* create_plug ();
398
399 static void
400 run_handler (const gchar *act, const gchar *args);
401
402 static void
403 add_binding (const gchar *key, const gchar *act);
404
405 static gchar*
406 get_xdg_var (XDG_Var xdg);
407
408 static gchar*
409 find_xdg_file (int xdg_type, char* filename);
410
411 static void
412 settings_init ();
413
414 static void
415 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
416
417 static void
418 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
419
420 static void
421 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
422
423 static void
424 dehilight (WebKitWebView *page, GArray *argv, GString *result);
425
426 static void
427 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
428
429 static void
430 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
431
432 static void
433 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
434
435 static void handle_cookies (SoupSession *session,
436                             SoupMessage *msg,
437                             gpointer     user_data);
438 static void
439 save_cookies (SoupMessage *msg,
440                 gpointer     user_data);
441
442 static void
443 set_var(WebKitWebView *page, GArray *argv, GString *result);
444
445 static void
446 act_bind(WebKitWebView *page, GArray *argv, GString *result);
447
448 static void
449 act_dump_config();
450
451 static void
452 render_html();
453
454 static void
455 set_timeout(int seconds);
456
457 static void
458 dump_var_hash(gpointer k, gpointer v, gpointer ud);
459
460 static void
461 dump_key_hash(gpointer k, gpointer v, gpointer ud);
462
463 static void
464 dump_config();
465
466
467 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
468 typedef struct {
469     Command function;
470     gboolean no_split;
471 } CommandInfo;
472
473 /* Command callbacks */
474 static void
475 cmd_load_uri();
476
477 static void
478 cmd_set_status();
479
480 static void
481 set_proxy_url();
482
483 static void
484 set_icon();
485
486 static void
487 cmd_cookie_handler();
488
489 static void
490 move_statusbar();
491
492 static void
493 cmd_always_insert_mode();
494
495 static void
496 cmd_http_debug();
497
498 static void
499 cmd_max_conns();
500
501 static void
502 cmd_max_conns_host();
503
504 /* exported WebKitWebSettings properties */
505
506 static void
507 cmd_font_size();
508
509 static void
510 cmd_zoom_level();
511
512 static void
513 cmd_disable_plugins();
514
515 static void
516 cmd_disable_scripts();
517
518 static void
519 cmd_minimum_font_size();
520
521 static void
522 cmd_fifo_dir();
523
524 static void
525 cmd_socket_dir();
526
527 static void
528 cmd_modkey();
529
530 void
531 cmd_useragent() ;
532
533 static void
534 cmd_autoload_img();
535
536 static void
537 cmd_autoshrink_img();
538
539 static void
540 cmd_enable_spellcheck();
541
542 static void
543 cmd_enable_private();
544
545 static void
546 cmd_print_bg();
547
548 static void 
549 cmd_style_uri();
550
551 static void 
552 cmd_resizable_txt();
553
554 static void 
555 cmd_default_encoding();
556
557 static void 
558 cmd_enforce_96dpi();
559
560 static void
561 cmd_inject_html();
562
563 static void 
564 cmd_caret_browsing();
565
566 /* vi: set et ts=4: */