added ability to set proxy_url on the fly, refactored some code
[uzbl-mobile] / uzbl.h
1 /* 
2  * See LICENSE for license details
3  *
4  * Changelog:
5  * ---------
6  *
7  * (c) 2009 by Robert Manea
8  *     - introduced struct concept
9  *     - statusbar template
10  *     
11  */
12
13 #define STATUS_DEFAULT "<span background=\"darkblue\" foreground=\"white\"> MODE </span> <span background=\"red\" foreground=\"white\">KEYCMD</span> (LOAD_PROGRESS%)  <b>TITLE</b>  - Uzbl browser"
14
15 /* statusbar symbols */
16 enum { SYM_TITLE, SYM_URI, SYM_NAME, 
17        SYM_LOADPRGS, SYM_LOADPRGSBAR,
18        SYM_KEYCMD, SYM_MODE, SYM_MSG};
19 const struct {
20     gchar *symbol_name;
21     guint symbol_token;
22 } symbols[] = {
23     {"NAME",                 SYM_NAME},
24     {"URI",                  SYM_URI},
25     {"TITLE",                SYM_TITLE},
26     {"KEYCMD",               SYM_KEYCMD},
27     {"MODE",                 SYM_MODE},
28     {"MSG",                  SYM_MSG},
29     {"LOAD_PROGRESS",        SYM_LOADPRGS},
30     {"LOAD_PROGRESSBAR",     SYM_LOADPRGSBAR},
31     {NULL,                   0}
32 }, *symp = symbols;
33
34 /* status bar elements */
35 typedef struct {
36     gint           load_progress;
37     gchar          *msg;
38 } StatusBar;
39
40
41 /* gui elements */
42 typedef struct {
43     GtkWidget*     main_window;
44     GtkWidget*     mainbar;
45     GtkWidget*     mainbar_label;
46     GtkScrollbar*  scbar_v;   // Horizontal and Vertical Scrollbar
47     GtkScrollbar*  scbar_h;   // (These are still hidden)
48     GtkAdjustment* bar_v; // Information about document length
49     GtkAdjustment* bar_h; // and scrolling position
50     WebKitWebView* web_view;
51     gchar*         main_title;
52
53     StatusBar sbar;
54 } GUI;
55
56
57 /* external communication*/
58 enum { FIFO, SOCKET};
59 typedef struct {
60     char           fifo_path[64];
61     char           socket_path[108];
62     /* stores (key)"variable name" -> (value)"pointer to this var*/
63     GHashTable     *proto_var;
64     /* command parsing regexes */
65     GRegex         *set_regex; 
66     GRegex         *get_regex; 
67     GRegex         *bind_regex; 
68 } Communication;
69
70
71 /* internal state */
72 typedef struct {
73     gchar    *uri;
74     gchar    *config_file;
75     char    *instance_name;
76     gchar    config_file_path[500];
77     gchar    selected_url[500];
78     char     executable_path[500];
79     GString* keycmd;
80     gchar    searchtx[500];
81     struct utsname unameinfo; /* system info */
82 } State;
83
84
85 /* networking */
86 typedef struct {
87     SoupSession *soup_session;
88     SoupLogger *soup_logger;
89     char *proxy_url;
90     char *useragent;
91     gint max_conns;
92     gint max_conns_host;
93 } Network;
94
95
96 /* behaviour */
97 typedef struct {
98     gchar*   status_format;
99     gchar*   status_background;
100     gchar*   history_handler;
101     gchar*   fifo_dir;
102     gchar*   socket_dir;
103     gchar*   download_handler;
104     gchar*   cookie_handler;
105     gboolean always_insert_mode;
106     gboolean show_status;
107     gboolean insert_mode;
108     gboolean status_top;
109     gchar*   modkey;
110     guint    modmask;
111     guint    http_debug;
112
113     /* command list: name -> Command  */
114     GHashTable* commands;
115 } Behaviour;
116
117
118 /* main uzbl data structure */
119 typedef struct {
120     GUI           gui;
121     State         state;
122     Network       net;
123     Behaviour     behave;
124     Communication comm;
125
126     Window        xwin;
127     GScanner      *scan;
128
129     /* group bindings: key -> action */
130     GHashTable* bindings;
131 } Uzbl;
132
133
134 typedef struct {
135     char* name;
136     char* param;
137 } Action;
138
139 typedef void sigfunc(int);
140
141 /* Functions */
142 static void
143 setup_scanner();
144
145 char *
146 itos(int val);
147
148 static void
149 clean_up(void);
150
151 static void
152 catch_sigterm(int s);
153
154 static sigfunc *
155 setup_signal(int signe, sigfunc *shandler);
156
157 static gboolean
158 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
159
160 WebKitWebView*
161 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
162
163 static gboolean
164 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
165
166 static void
167 toggle_status_cb (WebKitWebView* page, const char *param);
168
169 static void
170 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
171
172 static void
173 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data);
174
175 static void
176 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
177
178 static void
179 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
180
181 static void
182 destroy_cb (GtkWidget* widget, gpointer data);
183
184 static void
185 log_history_cb ();
186
187 static void
188 commands_hash(void);
189
190 void
191 free_action(gpointer act);
192
193 Action*
194 new_action(const gchar *name, const gchar *param);
195
196 static bool
197 file_exists (const char * filename);
198
199 void
200 set_insert_mode(WebKitWebView *page, const gchar *param);
201
202 static void
203 load_uri (WebKitWebView * web_view, const gchar *param);
204
205 static void
206 new_window_load_uri (const gchar * uri);
207
208 static void
209 close_uzbl (WebKitWebView *page, const char *param);
210
211 static gboolean
212 run_command_async(const char *command, const char *args);
213
214 static gboolean
215 run_command_sync(const char *command, const char *args, char **stdout);
216
217 static void
218 spawn(WebKitWebView *web_view, const char *param);
219
220 static void
221 parse_command(const char *cmd, const char *param);
222
223 void
224 build_stream_name(int type);
225
226 static void
227 control_fifo(GIOChannel *gio, GIOCondition condition);
228
229 static void
230 create_fifo();
231
232 static gboolean
233 control_stdin(GIOChannel *gio, GIOCondition condition);
234
235 static void
236 create_stdin();
237
238 static void
239 create_socket();
240
241 static void
242 control_socket(GIOChannel *chan);
243  
244
245 static void
246 update_title (void);
247  
248 static gboolean
249 key_press_cb (WebKitWebView* page, GdkEventKey* event);
250
251 static GtkWidget*
252 create_browser ();
253
254 static GtkWidget*
255 create_mainbar ();
256
257 static
258 GtkWidget* create_window ();
259
260 static void
261 add_binding (const gchar *key, const gchar *act);
262
263 static void
264 settings_init ();
265
266 static void
267 search_text (WebKitWebView *page, const char *param);
268
269 static void
270 run_js (WebKitWebView * web_view, const gchar *param);
271
272 static char *
273 str_replace (const char* search, const char* replace, const char* string);
274
275 static void handle_cookies (SoupSession *session,
276                                                         SoupMessage *msg,
277                                                         gpointer     user_data);
278 static void
279 save_cookies (SoupMessage *msg,
280                           gpointer     user_data);
281 /* vi: set et ts=4: */