Added functionality for (re)setting fifo_dir.
[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     gchar          *fifo_path;
61     gchar          *socket_path;
62     /* stores (key)"variable name" -> (value)"pointer to this var*/
63     GHashTable     *proto_var;
64     /* command parsing regexes */
65     GRegex         *set_regex;
66     GRegex         *cmd_regex;
67     GRegex         *get_regex; 
68     GRegex         *bind_regex; 
69 } Communication;
70
71
72 /* internal state */
73 typedef struct {
74     gchar    *uri;
75     gchar    *config_file;
76     char    *instance_name;
77     gchar    config_file_path[500];
78     gchar    selected_url[500];
79     char     executable_path[500];
80     GString* keycmd;
81     gchar    searchtx[500];
82     struct utsname unameinfo; /* system info */
83 } State;
84
85
86 /* networking */
87 typedef struct {
88     SoupSession *soup_session;
89     SoupLogger *soup_logger;
90     char *proxy_url;
91     char *useragent;
92     gint max_conns;
93     gint max_conns_host;
94 } Network;
95
96
97 /* behaviour */
98 typedef struct {
99     gchar*   load_finish_handler;
100     gchar*   status_format;
101     gchar*   status_background;
102     gchar*   history_handler;
103     gchar*   fifo_dir;
104     gchar*   socket_dir;
105     gchar*   download_handler;
106     gchar*   cookie_handler;
107     gboolean always_insert_mode;
108     gboolean show_status;
109     gboolean insert_mode;
110     gboolean status_top;
111     gboolean never_reset_mode;
112     gchar*   modkey;
113     guint    modmask;
114     guint    http_debug;
115
116     /* command list: name -> Command  */
117     GHashTable* commands;
118 } Behaviour;
119
120
121 /* main uzbl data structure */
122 typedef struct {
123     GUI           gui;
124     State         state;
125     Network       net;
126     Behaviour     behave;
127     Communication comm;
128
129     Window        xwin;
130     GScanner      *scan;
131
132     /* group bindings: key -> action */
133     GHashTable* bindings;
134 } Uzbl;
135
136
137 typedef struct {
138     char* name;
139     char* param;
140 } Action;
141
142 typedef void sigfunc(int);
143
144 /* Functions */
145 static void
146 setup_scanner();
147
148 char *
149 itos(int val);
150
151 static void
152 clean_up(void);
153
154 static void
155 catch_sigterm(int s);
156
157 static sigfunc *
158 setup_signal(int signe, sigfunc *shandler);
159
160 static gboolean
161 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
162
163 WebKitWebView*
164 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
165
166 static gboolean
167 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
168
169 static void
170 toggle_status_cb (WebKitWebView* page, const char *param);
171
172 static void
173 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
174
175 static void
176 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data);
177
178 static void
179 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
180
181 static void
182 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
183
184 static void
185 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
186
187 static void
188 destroy_cb (GtkWidget* widget, gpointer data);
189
190 static void
191 log_history_cb ();
192
193 static void
194 commands_hash(void);
195
196 void
197 free_action(gpointer act);
198
199 Action*
200 new_action(const gchar *name, const gchar *param);
201
202 static bool
203 file_exists (const char * filename);
204
205 void
206 set_insert_mode(WebKitWebView *page, const gchar *param);
207
208 static void
209 load_uri (WebKitWebView * web_view, const gchar *param);
210
211 static void
212 new_window_load_uri (const gchar * uri);
213
214 static void
215 close_uzbl (WebKitWebView *page, const char *param);
216
217 static gboolean
218 run_command_async(const char *command, const char *args);
219
220 static gboolean
221 run_command_sync(const char *command, const char *args, char **stdout);
222
223 static void
224 spawn(WebKitWebView *web_view, const char *param);
225
226 static void
227 parse_command(const char *cmd, const char *param);
228
229 void
230 build_stream_name(int type);
231
232 static void
233 control_fifo(GIOChannel *gio, GIOCondition condition);
234
235 static void
236 set_fifo_dir();
237
238 static void
239 create_fifo();
240
241 static gboolean
242 control_stdin(GIOChannel *gio, GIOCondition condition);
243
244 static void
245 create_stdin();
246
247 static void
248 create_socket();
249
250 static void
251 control_socket(GIOChannel *chan);
252  
253
254 static void
255 update_title (void);
256  
257 static gboolean
258 key_press_cb (WebKitWebView* page, GdkEventKey* event);
259
260 static GtkWidget*
261 create_browser ();
262
263 static GtkWidget*
264 create_mainbar ();
265
266 static
267 GtkWidget* create_window ();
268
269 static void
270 add_binding (const gchar *key, const gchar *act);
271
272 static void
273 settings_init ();
274
275 static void
276 search_text (WebKitWebView *page, const char *param);
277
278 static void
279 run_js (WebKitWebView * web_view, const gchar *param);
280
281 static char *
282 str_replace (const char* search, const char* replace, const char* string);
283
284 static void handle_cookies (SoupSession *session,
285                                                         SoupMessage *msg,
286                                                         gpointer     user_data);
287 static void
288 save_cookies (SoupMessage *msg,
289                           gpointer     user_data);
290 /* vi: set et ts=4: */