cleaner and more robust status/window format & update_title stuff
[uzbl-00z.git] / uzbl.h
blob368ad46c300a84ce8d3ac55707b12048a2ba2441
1 /* -*- c-basic-offset: 4; -*-
3 * See LICENSE for license details
5 * Changelog:
6 * ---------
8 * (c) 2009 by Robert Manea
9 * - introduced struct concept
10 * - statusbar template
14 #define STATUS_DEFAULT "<span background=\"darkblue\" foreground=\"white\"> MODE </span> <span background=\"red\" foreground=\"white\">KEYCMD</span> (LOAD_PROGRESS%) <b>TITLE</b> - Uzbl browser"
15 #define TITLE_LONG_DEFAULT "KEYCMD MODE TITLE - Uzbl browser <NAME> > SELECTED_URI"
16 #define TITLE_SHORT_DEFAULT "TITLE - Uzbl browser <NAME>"
19 enum {
20 /* statusbar symbols */
21 SYM_TITLE, SYM_URI, SYM_NAME,
22 SYM_LOADPRGS, SYM_LOADPRGSBAR,
23 SYM_KEYCMD, SYM_MODE, SYM_MSG,
24 SYM_SELECTED_URI,
25 /* useragent symbols */
26 SYM_WK_MAJ, SYM_WK_MIN, SYM_WK_MIC,
27 SYM_SYSNAME, SYM_NODENAME,
28 SYM_KERNREL, SYM_KERNVER,
29 SYM_ARCHSYS, SYM_ARCHUZBL,
30 SYM_DOMAINNAME, SYM_COMMIT
33 const struct {
34 gchar *symbol_name;
35 guint symbol_token;
36 } symbols[] = {
37 {"NAME", SYM_NAME},
38 {"URI", SYM_URI},
39 {"TITLE", SYM_TITLE},
40 {"SELECTED_URI", SYM_SELECTED_URI},
41 {"KEYCMD", SYM_KEYCMD},
42 {"MODE", SYM_MODE},
43 {"MSG", SYM_MSG},
44 {"LOAD_PROGRESS", SYM_LOADPRGS},
45 {"LOAD_PROGRESSBAR", SYM_LOADPRGSBAR},
47 {"WEBKIT_MAJOR", SYM_WK_MAJ},
48 {"WEBKIT_MINOR", SYM_WK_MIN},
49 {"WEBKIT_MICRO", SYM_WK_MIC},
50 {"SYSNAME", SYM_SYSNAME},
51 {"NODENAME", SYM_NODENAME},
52 {"KERNREL", SYM_KERNREL},
53 {"KERNVER", SYM_KERNVER},
54 {"ARCH_SYSTEM", SYM_ARCHSYS},
55 {"ARCH_UZBL", SYM_ARCHUZBL},
56 {"DOMAINNAME", SYM_DOMAINNAME},
57 {"COMMIT", SYM_COMMIT},
58 {NULL, 0}
59 }, *symp = symbols;
61 /* status bar elements */
62 typedef struct {
63 gint load_progress;
64 gchar *msg;
65 } StatusBar;
68 /* gui elements */
69 typedef struct {
70 GtkWidget* main_window;
71 GtkWidget* scrolled_win;
72 GtkWidget* vbox;
73 GtkWidget* mainbar;
74 GtkWidget* mainbar_label;
75 GtkScrollbar* scbar_v; // Horizontal and Vertical Scrollbar
76 GtkScrollbar* scbar_h; // (These are still hidden)
77 GtkAdjustment* bar_v; // Information about document length
78 GtkAdjustment* bar_h; // and scrolling position
79 WebKitWebView* web_view;
80 gchar* main_title;
82 StatusBar sbar;
83 } GUI;
86 /* external communication*/
87 enum { FIFO, SOCKET};
88 typedef struct {
89 gchar *fifo_path;
90 gchar *socket_path;
91 /* stores (key)"variable name" -> (value)"pointer to this var*/
92 GHashTable *proto_var;
93 /* command parsing regexes */
94 GRegex *set_regex;
95 GRegex *act_regex;
96 GRegex *keycmd_regex;
97 GRegex *get_regex;
98 GRegex *bind_regex;
99 } Communication;
102 /* internal state */
103 typedef struct {
104 gchar *uri;
105 gchar *config_file;
106 char *instance_name;
107 gchar config_file_path[500];
108 gchar selected_url[500];
109 char executable_path[500];
110 GString* keycmd;
111 gchar searchtx[500];
112 struct utsname unameinfo; /* system info */
113 gboolean verbose;
114 } State;
117 /* networking */
118 typedef struct {
119 SoupSession *soup_session;
120 SoupLogger *soup_logger;
121 char *proxy_url;
122 char *useragent;
123 gint max_conns;
124 gint max_conns_host;
125 } Network;
128 /* behaviour */
129 typedef struct {
130 gchar* load_finish_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 guint default_font_size;
149 guint minimum_font_size;
150 gchar* shell_cmd;
152 /* command list: name -> Command */
153 GHashTable* commands;
154 } Behaviour;
157 /* main uzbl data structure */
158 typedef struct {
159 GUI gui;
160 State state;
161 Network net;
162 Behaviour behave;
163 Communication comm;
165 Window xwin;
166 GScanner *scan;
168 /* group bindings: key -> action */
169 GHashTable* bindings;
170 } Uzbl;
173 typedef struct {
174 char* name;
175 char* param;
176 } Action;
178 typedef void sigfunc(int);
180 /* XDG Stuff */
182 typedef struct {
183 gchar* environmental;
184 gchar* default_value;
185 } XDG_Var;
187 XDG_Var XDG[] =
189 { "XDG_CONFIG_HOME", "~/.config" },
190 { "XDG_DATA_HOME", "~/.local/share" },
191 { "XDG_CACHE_HOME", "~/.cache" },
192 { "XDG_CONFIG_DIRS", "/etc/xdg" },
193 { "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" },
196 /* Functions */
197 static void
198 setup_scanner();
200 char *
201 itos(int val);
203 static char *
204 str_replace (const char* search, const char* replace, const char* string);
206 static void
207 clean_up(void);
209 static void
210 catch_sigterm(int s);
212 static sigfunc *
213 setup_signal(int signe, sigfunc *shandler);
215 static gboolean
216 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
218 WebKitWebView*
219 create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data);
221 static gboolean
222 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
224 static void
225 toggle_status_cb (WebKitWebView* page, const char *param);
227 static void
228 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
230 static void
231 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data);
233 static void
234 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
236 static void
237 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
239 static void
240 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
242 static void
243 destroy_cb (GtkWidget* widget, gpointer data);
245 static void
246 log_history_cb ();
248 static void
249 commands_hash(void);
251 void
252 free_action(gpointer act);
254 Action*
255 new_action(const gchar *name, const gchar *param);
257 static bool
258 file_exists (const char * filename);
260 void
261 set_insert_mode(WebKitWebView *page, const gchar *param);
263 static void
264 load_uri (WebKitWebView * web_view, const gchar *param);
266 static void
267 new_window_load_uri (const gchar * uri);
269 static void
270 close_uzbl (WebKitWebView *page, const char *param);
272 static gboolean
273 run_command(const char *command, const char *args, const gboolean sync, char **stdout);
275 static void
276 spawn(WebKitWebView *web_view, const char *param);
278 static void
279 spawn_sh(WebKitWebView *web_view, const char *param);
281 static void
282 parse_command(const char *cmd, const char *param);
284 static void
285 runcmd(WebKitWebView *page, const char *param);
287 static void
288 parse_cmd_line(const char *ctl_line);
290 static gchar*
291 build_stream_name(int type, const gchar *dir);
293 static gboolean
294 var_is(const char *x, const char *y);
296 static gchar*
297 set_useragent(gchar *val);
299 static gboolean
300 control_fifo(GIOChannel *gio, GIOCondition condition);
302 static gchar*
303 init_fifo(gchar *dir);
305 static gboolean
306 control_stdin(GIOChannel *gio, GIOCondition condition);
308 static void
309 create_stdin();
311 static gchar*
312 init_socket(gchar *dir);
314 static gboolean
315 control_socket(GIOChannel *chan);
317 static void
318 update_title (void);
320 static gboolean
321 key_press_cb (WebKitWebView* page, GdkEventKey* event);
323 static void
324 run_keycmd(const gboolean key_ret);
326 static GtkWidget*
327 create_browser ();
329 static GtkWidget*
330 create_mainbar ();
332 static
333 GtkWidget* create_window ();
335 static void
336 add_binding (const gchar *key, const gchar *act);
338 static gchar*
339 get_xdg_var (XDG_Var xdg);
341 static gchar*
342 find_xdg_file (int xdg_type, char* filename);
344 static void
345 settings_init ();
347 static void
348 search_text (WebKitWebView *page, const char *param);
350 static void
351 run_js (WebKitWebView * web_view, const gchar *param);
353 static void handle_cookies (SoupSession *session,
354 SoupMessage *msg,
355 gpointer user_data);
356 static void
357 save_cookies (SoupMessage *msg,
358 gpointer user_data);
359 /* vi: set et ts=4: */