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