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