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