annotate src/uicmd.cc @ 0:6ee11bf9e3ea

Initial revision
author jcid
date Sun, 07 Oct 2007 00:36:34 +0200
parents
children ab2998c07f18
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: uicmd.cc
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 * Copyright (C) 2005 Jorge Arellano Cid <jcid@dillo.org>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 // Functions/Methods for commands triggered from the UI
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 #include <stdio.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 #include <stdarg.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 #include <fltk/Widget.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #include "dir.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 #include "ui.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include "uicmd.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include "timeout.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #include "menu.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include "dialog.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include "bookmark.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include "history.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include "msg.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include "prefs.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 #include "dw/fltkviewport.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 #include "nav.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 // Platform idependent part
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 using namespace dw::core;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 // FLTK related
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 using namespace dw::fltk;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 UI *ui;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 BrowserWindow *bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 } Uibw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 * Local data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 // A matching table for all open ui/bw pairs
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 // BUG: must be dynamic.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 static Uibw uibws[32];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 static int uibws_num = 0, uibws_max = 32;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 static char *save_dir = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 using namespace fltk;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 * Create a new UI and its associated BrowserWindow data structure.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 if (ww <= 0 || wh <= 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 // TODO: set default geometry from dillorc.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 ww = 780;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 wh = 580;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 // Create and set the UI
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 UI *new_ui = new UI(ww, wh, "Dillo: UI");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 new_ui->set_status("http://www.dillo.org/");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 //new_ui->set_location("http://dillo.org/");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 //new_ui->customize(12);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 // Now create the Dw render layout and viewport
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 FltkPlatform *platform = new FltkPlatform ();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 Layout *layout = new Layout (platform);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 // BUG: This is a workaround for FLTK's non-working replace().
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 new_ui->set_render_layout_begin();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 int p_h = new_ui->panel_h();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 int s_h = new_ui->status_h();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 FltkViewport *viewport = new FltkViewport (0, p_h, ww, wh-p_h-s_h);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 layout->attachView (viewport);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 //viewport->addGadget(new_ui->fullscreen_button());
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 new_ui->set_render_layout_end();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 // This was the original code.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 // Set the render_layout widget into the UI
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 // new_ui->set_render_layout(*viewport);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 // Now, create a new browser window structure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 BrowserWindow *new_bw = a_Bw_new(ww, wh, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 // Set new_bw as callback data for UI
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 new_ui->user_data(new_bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 // Reference the UI from the bw
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 new_bw->ui = (void *)new_ui;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 // Copy the layout pointer into the bw data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 new_bw->render_layout = (void*)layout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 // insert the new ui/bw pair in the table
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 if (uibws_num < uibws_max) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 uibws[uibws_num].ui = new_ui;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 uibws[uibws_num].bw = new_bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 uibws_num++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 new_ui->show();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 return new_bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 * Close one browser window
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 void a_UIcmd_close_bw(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 BrowserWindow *bw = (BrowserWindow *)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118 UI *ui = (UI*)bw->ui;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 Layout *layout = (Layout*)bw->render_layout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 MSG("a_UIcmd_close_bw\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 ui->destroy();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 delete(layout);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 a_Bw_free(bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 * Close all the browser windows
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 void a_UIcmd_close_all_bw()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 BrowserWindow *bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 while ((bw = a_Bw_get()))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 a_UIcmd_close_bw((void*)bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
137
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 * Open a new URL in the given browser window.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141 * our custom "file:" URIs are normalized here too.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 char *new_urlstr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
146 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147 int ch;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 if (urlstr && *urlstr) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 /* Filter URL string */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 new_urlstr = a_Url_string_strip_delimiters(urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 if (!dStrncasecmp(new_urlstr, "file:", 5)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 /* file URI */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 ch = new_urlstr[5];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 if (!ch || ch == '.') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 url = a_Url_new(a_Dir_get_owd(), "file:", 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159 } else if (ch == '~') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 url = a_Url_new(dGethomedir(), "file:", 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 url = a_Url_new(new_urlstr, "file:", 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
163 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 /* common case */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167 url = a_Url_new(new_urlstr, NULL, 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
169 dFree(new_urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 if (url) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172 a_Nav_push(bw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
176
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
177 /* let the rendered area have focus */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
178 //gtk_widget_grab_focus(GTK_BIN(bw->render_main_scroll)->child);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
179 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
180
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
181 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
182 * Open a new URL in the given browser window
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184 void a_UIcmd_open_url_nw(BrowserWindow *bw, DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
185 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186 a_Nav_push_nw(bw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
189 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
190 * Send the browser back to previous page
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
191 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192 void a_UIcmd_back(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194 a_Nav_back((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
195 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
196
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
197 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
198 * Popup the navigation menu of the Back button
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
199 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
200 void a_UIcmd_back_popup(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
201 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202 a_Menu_history_popup((BrowserWindow*)vbw, -1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206 * Send the browser to next page in the history list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208 void a_UIcmd_forw(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 a_Nav_forw((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
213 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 * Popup the navigation menu of the Forward button
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216 void a_UIcmd_forw_popup(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
218 a_Menu_history_popup((BrowserWindow*)vbw, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
220
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
221 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
222 * Send the browser to home URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
223 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
224 void a_UIcmd_home(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
225 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
226 a_Nav_home((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
227 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
228
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
229 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230 * Reload current URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
231 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
232 void a_UIcmd_reload(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
233 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
234 a_Nav_reload((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
235 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
236
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
237 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
238 * Return a suitable filename for a given URL.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
239 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
240 char *UIcmd_make_save_filename(const char *urlstr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
241 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
242 size_t MaxLen = 64;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
243 char *FileName, *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
244 const char *dir = a_UIcmd_get_save_dir();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
246 if ((name = strrchr(urlstr, '/'))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247 if (strlen(++name) > MaxLen) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
248 name = name + strlen(name) - MaxLen;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250 FileName = dStrconcat(dir ? dir : "", name, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
252 FileName = dStrconcat(dir ? dir : "", urlstr, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
253 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
254 return FileName;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
255 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
256
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
257 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
258 * Get the default directory for saving files.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
259 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260 const char *a_UIcmd_get_save_dir()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 return save_dir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
263 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
264
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 * Set the default directory for saving files.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
267 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268 void a_UIcmd_set_save_dir(const char *dir)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
270 char *p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
272 if (dir && (p = strrchr(dir, '/'))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 dFree(save_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 // assert a trailing '/'
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275 save_dir = dStrconcat(dir, (p[1] != 0) ? "/" : "", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
276 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
280 * Save current URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
281 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
282 void a_UIcmd_save(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
283 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
284 const char *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
285 char *SuggestedName, *urlstr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
286 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
287
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 // BUG: this should be set by preferences.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
289 a_UIcmd_set_save_dir("/tmp/k/");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
290
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
291 urlstr = a_UIcmd_get_location_text((BrowserWindow*)vbw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
292 url = a_Url_new(urlstr, NULL, 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
293 SuggestedName = UIcmd_make_save_filename(urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 name = a_Dialog_save_file("Save Page as File", NULL, SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
295 MSG("a_UIcmd_save: %s\n", name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 dFree(SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297 dFree(urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
298
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
299 if (name) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
300 a_Nav_save_url((BrowserWindow*)vbw, url, name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
301 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
302
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
303 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
304 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
305
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
306 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
307 * Stop network activity on this bw.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
308 * The stop button was pressed: stop page (and images) downloads.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
309 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
310 void a_UIcmd_stop(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
311 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
312 BrowserWindow *bw = (BrowserWindow *)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
313
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
314 MSG("a_UIcmd_stop()\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
315 a_Bw_stop_clients(bw, BW_Root + BW_Img + Bw_Force);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
316 a_UIcmd_set_buttons_sens(bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
318
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
319 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
320 * Open URL with dialog chooser
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
321 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
322 void a_UIcmd_open_file(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
323 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
324 char *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
325 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
326
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
327 name = a_Dialog_open_file("Open File", NULL, "");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
329 if (name) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 url = a_Url_new(name, "file:", 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
331 a_Nav_push((BrowserWindow*)vbw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
332 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
333 dFree(name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
334 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
335 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
336
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
337 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
338 * Get an URL from a dialog and open it
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
339 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
340 void a_UIcmd_open_url_dialog(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
341 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
342 const char *urlstr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
343
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
344 if ((urlstr = a_Dialog_input("Please enter a URL:"))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
345 a_UIcmd_open_urlstr(vbw, urlstr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
346 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
347 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
348
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
349 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
350 * Returns a newly allocated string holding a search url generated from
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
351 * a string of keywords (separarated by blanks) and prefs.search_url.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
352 * The search string is urlencoded.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
353 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354 char *UIcmd_make_search_str(const char *str)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
355 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356 char *keys = a_Url_encode_hex_str(str), *c = prefs.search_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
357 Dstr *ds = dStr_sized_new(128);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
358 char *search_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
359
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
360 for (; *c; c++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
361 if (*c == '%')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
362 switch(*++c) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
363 case 's':
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
364 dStr_append(ds, keys); break;;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
365 case '%':
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
366 dStr_append_c(ds, '%'); break;;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
367 case 0:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
368 MSG_WARN("search_url ends with '%%'\n"); c--; break;;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
369 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
370 MSG_WARN("illegal specifier '%%%c' in search_url\n", *c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
371 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
372 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
373 dStr_append_c(ds, *c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
374 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
375 dFree(keys);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
376
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
377 search_url = ds->str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
378 dStr_free(ds, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
379 return search_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
380 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
381
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
382 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
383 * Get a query from a dialog and open it
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
384 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
385 void a_UIcmd_search_dialog(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
386 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
387 const char *query, *url_str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
388
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
389 if ((query = a_Dialog_input("Search the Web:"))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
390 url_str = UIcmd_make_search_str(query);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
391 a_UIcmd_open_urlstr(vbw, url_str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
392 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
393 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
394
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
395 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
396 * Save link URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
397 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
398 void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
399 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
400 const char *name;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
401 char *SuggestedName;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
402
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
403 // BUG: this should be set by preferences.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
404 a_UIcmd_set_save_dir("/tmp/k/");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
405
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
406 SuggestedName = UIcmd_make_save_filename(URL_STR(url));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
407 name = a_Dialog_save_file("Save Link as File", NULL, SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
408 MSG("a_UIcmd_save_link: %s\n", name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
409 dFree(SuggestedName);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
410
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
411 if (name) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
412 a_Nav_save_url(bw, url, name);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
413 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
414 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
415
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
416 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
417 * Request the bookmarks page
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
418 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
419 void a_UIcmd_book(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
420 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
421 DilloUrl *url = a_Url_new("dpi:/bm/", NULL, 0, 0, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
422 a_Nav_push((BrowserWindow*)vbw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
423 a_Url_free(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
424 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
425
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
426 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
427 * Add a bookmark for a certain URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
428 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
429 void a_UIcmd_add_bookmark(BrowserWindow *bw, DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
430 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
431 a_Bookmarks_add(bw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
432 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
433
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
434
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
435 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
436 * Popup the page menu
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
437 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
438 void a_UIcmd_page_popup(void *vbw, DilloUrl *url, const char *bugs_txt)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
439 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
440 a_Menu_page_popup((BrowserWindow*)vbw, url, bugs_txt);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
441 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
442
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
443 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
444 * Popup the link menu
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
445 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
446 void a_UIcmd_link_popup(void *vbw, DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
447 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
448 a_Menu_link_popup((BrowserWindow*)vbw, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
449 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
450
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
451 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
452 * Show a text window with the URL's source
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
453 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
454 void a_UIcmd_view_page_source(DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
455 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
456 char *buf;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
457 int buf_size;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
458
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
459 if (a_Nav_get_buf(url, &buf, &buf_size)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
460 a_Dialog_text_window(buf, "View Page source");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
461 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
462 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
463
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
464 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
465 * Show a text window with the URL's source
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
466 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
467 void a_UIcmd_view_page_bugs(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
468 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
469 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
470
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
471 if (bw->num_page_bugs > 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
472 a_Dialog_text_window(bw->page_bugs->str, "Detected HTML errors");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
473 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
474 a_Dialog_msg("Zero detected HTML errors!");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
475 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
476 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
477
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
478 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
479 * Popup the bug meter menu
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
480 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
481 void a_UIcmd_bugmeter_popup(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
482 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
483 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
484
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
485 a_Menu_bugmeter_popup(bw, a_History_get_url(NAV_TOP(bw)));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
486 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
487
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
488 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
489 * Make a list of URL indexes for the history popup
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
490 * based on direction (-1 = back, 1 = forward)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
491 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
492 int *a_UIcmd_get_history(BrowserWindow *bw, int direction)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
493 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
494 int i, j, n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
495 int *hlist;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
496
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
497 // Count the number of URLs
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
498 i = a_Nav_stack_ptr(bw) + direction;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
499 for (n = 0 ; i >= 0 && i < a_Nav_stack_size(bw); i+=direction)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
500 ++n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
501 hlist = dNew(int, n + 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
502
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
503 // Fill the list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
504 i = a_Nav_stack_ptr(bw) + direction;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
505 for (j = 0 ; i >= 0 && i < a_Nav_stack_size(bw); i+=direction, j += 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
506 hlist[j] = NAV_IDX(bw,i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
507 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
508 hlist[j] = -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
509
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
510 return hlist;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
511 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
512
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
513 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
514 * Jump to a certain URL in the navigation stack.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
515 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
516 void a_UIcmd_nav_jump(BrowserWindow *bw, int offset, int new_bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
517 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
518 a_Nav_jump(bw, offset, new_bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
519 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
520
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
521 // UI binding functions -------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
522
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
523 #define BW2UI(bw) ((UI*)(bw->ui))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
524
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
525 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
526 * Return browser window width and height
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
527 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
528 void a_UIcmd_get_wh(BrowserWindow *bw, int *w, int *h)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
529 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
530 *w = BW2UI(bw)->w();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
531 *h = BW2UI(bw)->h();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
532 _MSG("a_UIcmd_wh: w=%d, h=%d\n", *w, *h);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
533 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
534
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
535 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
536 * Get location's text
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
537 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
538 char *a_UIcmd_get_location_text(BrowserWindow *bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
539 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
540 return dStrdup(BW2UI(bw)->get_location());
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
541 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
542
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
543 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
544 * Set location's text
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
545 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
546 void a_UIcmd_set_location_text(void *vbw, const char *text)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
547 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
548 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
549 BW2UI(bw)->set_location(text);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
550 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
551
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
552 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
553 * Set the page progress bar
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
554 * cmd: 0 Deactivate, 1 Update, 2 Clear
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
555 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
556 void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
557 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
558 BW2UI(bw)->set_page_prog(nbytes, cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
559 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
560
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
561 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
562 * Set the images progress bar
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
563 * cmd: 0 Deactivate, 1 Update, 2 Clear
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
564 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
565 void a_UIcmd_set_img_prog(BrowserWindow *bw, int n_img, int t_img, int cmd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
566 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
567 BW2UI(bw)->set_img_prog(n_img, t_img, cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
568 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
569
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
570 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
571 * Set the bug meter progress label
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
572 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
573 void a_UIcmd_set_bug_prog(BrowserWindow *bw, int n_bug)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
574 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
575 BW2UI(bw)->set_bug_prog(n_bug);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
576 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
577
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
578 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
579 * Set the page title.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
580 * now it goes to the window titlebar (maybe to TAB label in the future).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
581 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
582 void a_UIcmd_set_page_title(BrowserWindow *bw, const char *label)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
583 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
584 BW2UI(bw)->set_page_title(label);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
585 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
586
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
587 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
588 * Set a printf-like status string on the bottom of the dillo window.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
589 * Beware: The safe way to set an arbitrary string is
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
590 * a_UIcmd_set_msg(bw, "%s", str)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
591 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
592 void a_UIcmd_set_msg(BrowserWindow *bw, const char *format, ...)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
593 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
594 va_list argp;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
595 Dstr *ds = dStr_sized_new(128);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
596 va_start(argp, format);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
597 dStr_vsprintf(ds, format, argp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
598 va_end(argp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
599 BW2UI(bw)->set_status(ds->str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
600 dStr_free(ds, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
601 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
602
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
603 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
604 * Set the sensitivity of back/forw/stop buttons.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
605 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
606 static void a_UIcmd_set_buttons_sens_cb(void *vbw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
607 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
608 int sens;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
609 BrowserWindow *bw = (BrowserWindow*)vbw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
610
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
611 // Stop
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
612 sens = (dList_length(bw->ImageClients) || dList_length(bw->RootClients));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
613 BW2UI(bw)->button_set_sens(UI_STOP, sens);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
614 // Back
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
615 sens = (a_Nav_stack_ptr(bw) > 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
616 BW2UI(bw)->button_set_sens(UI_BACK, sens);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
617 // Forward
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
618 sens = (a_Nav_stack_ptr(bw) < a_Nav_stack_size(bw) - 1 &&
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
619 !bw->nav_expecting);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
620 BW2UI(bw)->button_set_sens(UI_FORW, sens);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
621
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
622 bw->sens_idle_up = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
623 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
624
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
625
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
626 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
627 * Set the timeout function for button sensitivity
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
628 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
629 void a_UIcmd_set_buttons_sens(BrowserWindow *bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
630 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
631 if (bw->sens_idle_up == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
632 a_Timeout_add(0.0, a_UIcmd_set_buttons_sens_cb, bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
633 bw->sens_idle_up = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
634 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
635 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
636
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
637 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
638 * Toggle control panel (aka. fullscreen)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
639 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
640 void a_UIcmd_fullscreen_toggle(BrowserWindow *bw)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
641 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
642 BW2UI(bw)->fullscreen_toggle();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
643 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
644