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