Remove ACT command, remove regexes as they're no longer used.
[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 #define NOSPLIT ((void*)1)
15
16 enum {
17   /* statusbar symbols */
18   SYM_TITLE, SYM_URI, SYM_NAME,
19   SYM_LOADPRGS, SYM_LOADPRGSBAR,
20   SYM_KEYCMD, SYM_MODE, SYM_MSG,
21   SYM_SELECTED_URI,
22   /* useragent symbols */
23   SYM_WK_MAJ, SYM_WK_MIN, SYM_WK_MIC,
24   SYM_SYSNAME, SYM_NODENAME,
25   SYM_KERNREL, SYM_KERNVER,
26   SYM_ARCHSYS, SYM_ARCHUZBL,
27   SYM_DOMAINNAME, SYM_COMMIT
28 };
29
30 const struct {
31     gchar *symbol_name;
32     guint symbol_token;
33 } symbols[] = {
34     {"NAME",                 SYM_NAME},
35     {"URI",                  SYM_URI},
36     {"TITLE",                SYM_TITLE},
37     {"SELECTED_URI",         SYM_SELECTED_URI},
38     {"KEYCMD",               SYM_KEYCMD},
39     {"MODE",                 SYM_MODE},
40     {"MSG",                  SYM_MSG},
41     {"LOAD_PROGRESS",        SYM_LOADPRGS},
42     {"LOAD_PROGRESSBAR",     SYM_LOADPRGSBAR},
43
44     {"WEBKIT_MAJOR",         SYM_WK_MAJ},
45     {"WEBKIT_MINOR",         SYM_WK_MIN},
46     {"WEBKIT_MICRO",         SYM_WK_MIC},
47     {"SYSNAME",              SYM_SYSNAME},
48     {"NODENAME",             SYM_NODENAME},
49     {"KERNREL",              SYM_KERNREL},
50     {"KERNVER",              SYM_KERNVER},
51     {"ARCH_SYSTEM",          SYM_ARCHSYS},
52     {"ARCH_UZBL",            SYM_ARCHUZBL},
53     {"DOMAINNAME",           SYM_DOMAINNAME},
54     {"COMMIT",               SYM_COMMIT},
55     {NULL,                   0}
56 }, *symp = symbols;
57
58 /* status bar elements */
59 typedef struct {
60     gint           load_progress;
61     gchar          *msg;
62     gchar          *progress_s, *progress_u;
63     int            progress_w;
64 } StatusBar;
65
66
67 /* gui elements */
68 typedef struct {
69     GtkWidget*     main_window;
70     GtkWidget*     scrolled_win;
71     GtkWidget*     vbox;
72     GtkWidget*     mainbar;
73     GtkWidget*     mainbar_label;
74     GtkScrollbar*  scbar_v;   // Horizontal and Vertical Scrollbar
75     GtkScrollbar*  scbar_h;   // (These are still hidden)
76     GtkAdjustment* bar_v; // Information about document length
77     GtkAdjustment* bar_h; // and scrolling position
78     WebKitWebView* web_view;
79     gchar*         main_title;
80
81     /* WebInspector */
82     GtkWidget *inspector_window;
83     WebKitWebInspector *inspector;
84
85     StatusBar sbar;
86 } GUI;
87
88
89 /* external communication*/
90 enum { FIFO, SOCKET};
91 typedef struct {
92     gchar          *fifo_path;
93     gchar          *socket_path;
94     /* stores (key)"variable name" -> (value)"pointer to this var*/
95     GHashTable     *proto_var;
96     gchar          *sync_stdout;
97 } Communication;
98
99
100 /* internal state */
101 typedef struct {
102     gchar    *uri;
103     gchar    *config_file;
104     char    *instance_name;
105     gchar    *selected_url;
106     gchar    *executable_path;
107     GString* keycmd;
108     gchar*   searchtx;
109     struct utsname unameinfo; /* system info */
110     gboolean verbose;
111 } State;
112
113
114 /* networking */
115 typedef struct {
116     SoupSession *soup_session;
117     SoupLogger *soup_logger;
118     char *proxy_url;
119     char *useragent;
120     gint max_conns;
121     gint max_conns_host;
122 } Network;
123
124
125 /* behaviour */
126 typedef struct {
127     gchar*   load_finish_handler;
128     gchar*   load_start_handler;
129     gchar*   load_commit_handler;
130     gchar*   status_format;
131     gchar*   title_format_short;
132     gchar*   title_format_long;
133     gchar*   status_background;
134     gchar*   history_handler;
135     gchar*   fifo_dir;
136     gchar*   socket_dir;
137     gchar*   download_handler;
138     gchar*   cookie_handler;
139     gboolean always_insert_mode;
140     gboolean show_status;
141     gboolean insert_mode;
142     gboolean status_top;
143     gboolean reset_command_mode;
144     gchar*   modkey;
145     guint    modmask;
146     guint    http_debug;
147     gchar*   shell_cmd;
148     /* WebKitWebSettings exports */
149     guint    font_size;
150     guint    monospace_size;
151     guint    minimum_font_size;
152     guint    disable_plugins;
153     guint    disable_scripts;
154     guint    autoload_img;    
155     guint    autoshrink_img;  
156     guint    enable_spellcheck;
157     guint    enable_private;  
158     guint    print_bg;        
159     gchar*   style_uri;       
160     guint    resizable_txt;  
161     gchar*   default_encoding;       
162     guint    enforce_96dpi;  
163     gchar    *inject_html;
164     guint    caret_browsing;  
165     guint    mode;  
166     gchar*   base_url;
167     gchar*   html_endmarker;
168     gchar*   insert_indicator;
169     gchar*   cmd_indicator;
170     GString* html_buffer;
171     guint    html_timeout;  
172
173     /* command list: name -> Command  */
174     GHashTable* commands;
175 } Behaviour;
176
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
186     Window        xwin;
187     GScanner      *scan;
188
189     /* group bindings: key -> action */
190     GHashTable* bindings;
191 } Uzbl;
192
193
194 typedef struct {
195     char* name;
196     char* param;
197 } Action;
198
199 typedef void sigfunc(int);
200
201 /* XDG Stuff */
202
203 typedef struct {
204     gchar* environmental;
205     gchar* default_value;
206 } XDG_Var;
207
208 XDG_Var XDG[] = 
209 {
210     { "XDG_CONFIG_HOME", "~/.config" },
211     { "XDG_DATA_HOME",   "~/.local/share" },
212     { "XDG_CACHE_HOME",  "~/.cache" },
213     { "XDG_CONFIG_DIRS", "/etc/xdg" },
214     { "XDG_DATA_DIRS",   "/usr/local/share/:/usr/share/" },
215 };
216
217 /* Functions */
218 static void
219 setup_scanner();
220
221 char *
222 itos(int val);
223
224 static char *
225 str_replace (const char* search, const char* replace, const char* string);
226
227 static GArray*
228 read_file_by_line (gchar *path);
229
230 static
231 gchar* parseenv (char* string);
232
233 static void
234 clean_up(void);
235
236 static void
237 catch_sigterm(int s);
238
239 static sigfunc *
240 setup_signal(int signe, sigfunc *shandler);
241
242 static gboolean
243 set_var_value(gchar *name, gchar *val);
244
245 static gboolean
246 get_var_value(const gchar *name);
247
248 static gboolean
249 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, 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_status_cb (WebKitWebView* page, GArray *argv);
259
260 static void
261 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
262
263 static void
264 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data);
265
266 static void
267 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
268
269 static void
270 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
271
272 static void
273 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
274
275 static void
276 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
277
278 static void
279 destroy_cb (GtkWidget* widget, gpointer data);
280
281 static void
282 log_history_cb ();
283
284 static void
285 commands_hash(void);
286
287 void
288 free_action(gpointer act);
289
290 Action*
291 new_action(const gchar *name, const gchar *param);
292
293 static bool
294 file_exists (const char * filename);
295
296 static void
297 toggle_insert_mode(WebKitWebView *page, GArray *argv);
298
299 static void
300 load_uri (WebKitWebView * web_view, GArray *argv);
301
302 static void
303 new_window_load_uri (const gchar * uri);
304
305 static void
306 chain (WebKitWebView *page, GArray *argv);
307
308 static void
309 keycmd (WebKitWebView *page, GArray *argv);
310
311 static void
312 keycmd_nl (WebKitWebView *page, GArray *argv);
313
314 static void
315 keycmd_bs (WebKitWebView *page, GArray *argv);
316
317 static void
318 close_uzbl (WebKitWebView *page, GArray *argv);
319
320 static gboolean
321 run_command(const gchar *command, const guint npre,
322             const gchar **args, const gboolean sync, char **stdout);
323
324 static void
325 spawn(WebKitWebView *web_view, GArray *argv);
326
327 static void
328 spawn_sh(WebKitWebView *web_view, GArray *argv);
329
330 static void
331 spawn_sync(WebKitWebView *web_view, GArray *argv);
332
333 static void
334 spawn_sh_sync(WebKitWebView *web_view, GArray *argv);
335
336 static void
337 parse_command(const char *cmd, const char *param);
338
339 static void
340 parse_cmd_line(const char *ctl_line);
341
342 static gchar*
343 build_stream_name(int type, const gchar *dir);
344
345 static gboolean
346 control_fifo(GIOChannel *gio, GIOCondition condition);
347
348 static gchar*
349 init_fifo(gchar *dir);
350
351 static gboolean
352 control_stdin(GIOChannel *gio, GIOCondition condition);
353
354 static void
355 create_stdin();
356
357 static gchar*
358 init_socket(gchar *dir);
359
360 static gboolean
361 control_socket(GIOChannel *chan);
362
363 static void
364 update_title (void);
365
366 static gboolean
367 key_press_cb (GtkWidget* window, GdkEventKey* event);
368
369 static void
370 run_keycmd(const gboolean key_ret);
371
372 static void
373 exec_paramcmd(const Action* act, const guint i);
374
375 static GtkWidget*
376 create_browser ();
377
378 static GtkWidget*
379 create_mainbar ();
380
381 static
382 GtkWidget* create_window ();
383
384 static void
385 run_handler (const gchar *act, const gchar *args);
386
387 static void
388 add_binding (const gchar *key, const gchar *act);
389
390 static gchar*
391 get_xdg_var (XDG_Var xdg);
392
393 static gchar*
394 find_xdg_file (int xdg_type, char* filename);
395
396 static void
397 settings_init ();
398
399 static void
400 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
401
402 static void
403 search_forward_text (WebKitWebView *page, GArray *argv);
404
405 static void
406 search_reverse_text (WebKitWebView *page, GArray *argv);
407
408 static void
409 dehilight (WebKitWebView *page, GArray *argv);
410
411 static void
412 run_js (WebKitWebView * web_view, GArray *argv);
413
414 static void
415 run_external_js (WebKitWebView * web_view, GArray *argv);
416
417 static void handle_cookies (SoupSession *session,
418                             SoupMessage *msg,
419                             gpointer     user_data);
420 static void
421 save_cookies (SoupMessage *msg,
422                 gpointer     user_data);
423
424 static void
425 set_var(WebKitWebView *page, GArray *argv);
426
427 static void
428 get_var(WebKitWebView *page, GArray *argv);
429
430 static void
431 act_bind(WebKitWebView *page, GArray *argv);
432
433 static void
434 act_dump_config();
435
436 static void
437 render_html();
438
439 static void
440 set_timeout(int seconds);
441
442 static void
443 dump_var_hash(gpointer k, gpointer v, gpointer ud);
444
445 static void
446 dump_key_hash(gpointer k, gpointer v, gpointer ud);
447
448 static void
449 dump_config();
450
451
452 /* Command callbacks */
453 static void
454 cmd_load_uri();
455
456 static void
457 cmd_set_status();
458
459 static void
460 set_proxy_url();
461
462 static void
463 cmd_cookie_handler();
464
465 static void
466 move_statusbar();
467
468 static void
469 cmd_always_insert_mode();
470
471 static void
472 cmd_http_debug();
473
474 static void
475 cmd_max_conns();
476
477 static void
478 cmd_max_conns_host();
479
480 static void
481 cmd_font_size();
482
483 static void
484 cmd_disable_plugins();
485
486 static void
487 cmd_disable_scripts();
488
489 static void
490 cmd_minimum_font_size();
491
492 static void
493 cmd_fifo_dir();
494
495 static void
496 cmd_socket_dir();
497
498 static void
499 cmd_modkey();
500
501 static void
502 cmd_useragent() ;
503
504 static void
505 cmd_autoload_img();
506
507 static void
508 cmd_autoshrink_img();
509
510 static void
511 cmd_enable_spellcheck();
512
513 static void
514 cmd_enable_private();
515
516 static void
517 cmd_print_bg();
518
519 static void 
520 cmd_style_uri();
521
522 static void 
523 cmd_resizable_txt();
524
525 static void 
526 cmd_default_encoding();
527
528 static void 
529 cmd_enforce_96dpi();
530
531 static void
532 cmd_inject_html();
533
534 static void 
535 cmd_caret_browsing();
536
537 /* vi: set et ts=4: */