Codebase list dillo / upstream/0.8.6 src / commands.c
upstream/0.8.6

Tree @upstream/0.8.6 (Download .tar.gz)

commands.c @upstream/0.8.6raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
 * File: commands.c
 *
 * Copyright (C) 1997 Raph Levien <raph@acm.org>
 * Copyright (C) 1999 Sammy Mannaert <nstalkie@tvd.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <gtk/gtk.h>
#include <stdio.h>              /* for sprintf */
#include <sys/time.h>           /* for gettimeofday (testing gorp only) */
#include <unistd.h>
#include <string.h>             /* for strcat() */

#include "msg.h"
#include "bookmark.h"
#include "interface.h"
#include "history.h"
#include "nav.h"
#include "misc.h"
#include "commands.h"
#include "prefs.h"
#include "menu.h"
#include "capi.h"
#include "selection.h"

/* FILE MENU */

/*
 * Create a new browser window
 */
void a_Commands_new_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *nbw, *bw = (BrowserWindow *)client_data;

   nbw = a_Interface_browser_window_new(bw->main_window->allocation.width,
                                  bw->main_window->allocation.height, 0);
   /* focus the location bar */
   gtk_widget_grab_focus(nbw->location);
}

/*
 * Create and show the "Open file" dialog
 */
void a_Commands_openfile_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Interface_openfile_dialog(bw);
}

/*
 * Create and show the "Open Url" dialog window
 */
void a_Commands_openurl_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;
   a_Interface_open_dialog(widget, bw);
}

/*
 * ?
 */
void a_Commands_prefs_callback(GtkWidget *widget, gpointer client_data)
{
}

/*
 * Close browser window, and exit dillo if it's the last one.
 */
void a_Commands_close_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;
   gtk_widget_destroy(bw->main_window);
}

/*
 * Free memory and quit dillo
 */
void a_Commands_exit_callback(GtkWidget *widget, gpointer client_data)
{
   a_Interface_quit_all();
}


/* PAGE MENU */

/*
 * Show current page's source code.
 */
void a_Commands_viewsource_callback (GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;
   gchar *buf;
   gint buf_size;

   /* Get page source data */
   a_Capi_get_buf(a_History_get_url(NAV_TOP(bw)), &buf, &buf_size);
   /* Show it */
   a_Interface_text_window (&bw->viewsource_window,
                            "View Source", "view_source",
                            buf, buf_size,
                            530, 500);
}

/*
 * Show the detected HTML errors in current page.
 */
void a_Commands_view_page_bugs_callback (GtkWidget *widget,
                                         gpointer client_data)
{
   DilloHtmlLB *html_lb = client_data;

   a_Interface_text_window (&html_lb->bw->pagebugs_window,
                            "Detected HTML errors", "page_bugs",
                            html_lb->page_bugs->str,
                            html_lb->page_bugs->len,
                            530, 500);
}

/*
 * ?
 */
void a_Commands_selectall_callback(GtkWidget *widget, gpointer client_data)
{
}

/*
 * Create and show the "Find Text" dialog window
 */
void a_Commands_findtext_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Interface_findtext_dialog( bw );
}

/*
 * Print the page!
 * ('cat page.html | html2ps | lpr -Pcool'   Why bother?  I think providing
 * such an option in a configurable way should cut it  --Jcid)
 */
void a_Commands_print_callback(GtkWidget *widget, gpointer client_data)
{
}


/* TOOLBAR MENU */

/*
 * Abort all active connections for this page
 * (Downloads MUST keep flowing)
 */
void a_Commands_stop_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = client_data;
   a_Nav_cancel_expect(bw);
   a_Interface_stop(bw);
   a_Interface_set_button_sens(bw);
   a_Interface_msg(bw, "Stopped");
}

/*
 *  Back to previous page
 */
void a_Commands_back_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Nav_back(bw);
}

/*
 * Creates the menu for the forward navigation button.
 */
GtkMenu *a_Commands_forw_button_menu_creator_callback(GtkExtButton *button,
                                                      gpointer client_data)
{
   BrowserWindow *bw = client_data;

   if (bw->menu_popup.over_forw)
      gtk_widget_destroy(bw->menu_popup.over_forw);
   bw->menu_popup.over_forw = a_Menu_popup_history_new(bw, +1);
   return GTK_MENU(bw->menu_popup.over_forw);
}

/*
 * Creates the menu for the backward navigation button.
 */
GtkMenu *a_Commands_back_button_menu_creator_callback(GtkExtButton *button,
                                                      gpointer client_data)
{
   BrowserWindow *bw = client_data;

   if (bw->menu_popup.over_back)
      gtk_widget_destroy(bw->menu_popup.over_back);
   bw->menu_popup.over_back = a_Menu_popup_history_new(bw, -1);
   return GTK_MENU(bw->menu_popup.over_back);
}

/*
 * Handler for menu entries in the history menus. This one is called, when
 * the link should be opened in the same window.
 */
void a_Commands_history_callback_same_bw(GtkWidget *widget,
                                         gpointer client_data)
{
   BrowserWindow *bw = client_data;

   a_Nav_jump_callback(widget, bw, 0);
}

/*
 * Handler for menu entries in the history menus. This one is called, when
 * the link should be opened in a new window.
 */
void a_Commands_history_callback_new_bw(GtkWidget *widget,
                                        gpointer client_data)
{
   BrowserWindow *bw = client_data;

   a_Nav_jump_callback(widget, bw, 1);
}

/*
 * Go to the next page in the history buffer
 */
void a_Commands_forw_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Nav_forw(bw);
}

/*
 * Start the reload process
 */
void a_Commands_reload_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Nav_reload(bw);
}

/*
 * Go home!
 */
void a_Commands_home_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Nav_home(bw);
}

/*
 * Bring up the save page dialog
 */
void a_Commands_save_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Interface_save_dialog(widget, bw);
}

/*
 * Bring up the save link dialog
 */
void a_Commands_save_link_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Interface_save_link_dialog(widget, bw);
}


/* BOOKMARKS MENU */

/*
 * Add a bookmark to the current bookmark widget.
 */
void a_Commands_addbm_callback(GtkWidget *widget, gpointer client_data)
{
   a_Bookmarks_add(widget, client_data);
}

/*
 * Show the bookmarks-file as rendered html
 */
void a_Commands_viewbm_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;

   a_Bookmarks_show(bw);
}


/* HELP MENU */

/*
 * This one was intended as a link to help-info on the web site, but
 * currently points to the home page  --Jcid
 */
void a_Commands_helphome_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *) client_data;
   DilloUrl *url = a_Url_new(DILLO_HOME, NULL, 0, 0, 0);

   a_Nav_push(bw, url);
   a_Url_free(url);
}


/* RIGHT BUTTON POP-UP MENU */

/*
 * Open link in browser-window
 */
void a_Commands_open_link_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;

   a_Nav_push(bw, a_Menu_popup_get_url(bw));
}

/*
 * Open link in another browser-window
 */
void a_Commands_open_link_nw_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;
   gint width, height;
   BrowserWindow *newbw;

   gdk_window_get_size (bw->main_window->window, &width, &height);
   newbw = a_Interface_browser_window_new(width, height, 0);
   a_Nav_push(newbw, a_Menu_popup_get_url(bw));
}

/*
 * Called when the user wants the popup's URL for pasting.
 */
void a_Commands_select_popup_url_callback(GtkWidget *widget, gpointer data)
{
   BrowserWindow *bw = (BrowserWindow *)data;
   a_Selection_set_selection(widget, URL_STR(a_Menu_popup_get_url(bw)));
}


/* BUG METER POP-UP MENU */

/*
 * Helper function for validation.
 */
static void Commands_ob_validate_page(BrowserWindow *bw, const gchar *fmt)
{
   GString *gstr = g_string_sized_new(128);
   gchar *o_url, *e_url, *n_url;
   DilloUrl *url;

   /* prepare the validation request URI */
   o_url = URL_STR(a_History_get_url(NAV_TOP(bw)));
   e_url = a_Misc_escape_chars(o_url, ":/?");
   n_url = e_url ? e_url : o_url;
   g_string_sprintf(gstr, fmt, n_url);
   if (n_url != o_url)
      g_free(n_url);
   url = a_Url_new(gstr->str, NULL, 0, 0, 0);
   g_string_free(gstr, TRUE);

   a_Nav_push(bw, url);
   a_Url_free(url);
}

/*
 * Validate current page with the W3C's validator.
 */
void a_Commands_ob_w3c_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;
   const gchar *w3c_fmt="http://validator.w3.org/check?uri=%s";

   Commands_ob_validate_page(bw, w3c_fmt);
}

/*
 * Validate current page with the WDG's validator.
 */
void a_Commands_ob_wdg_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;
   const gchar *wdg_fmt=
      "http://www.htmlhelp.org/cgi-bin/validate.cgi?url=%s&warnings=yes";

   Commands_ob_validate_page(bw, wdg_fmt);
}

/*
 * Request the info page for bug meter.
 */
void a_Commands_ob_info_callback(GtkWidget *widget, gpointer client_data)
{
   BrowserWindow *bw = (BrowserWindow *)client_data;
   const gchar *info_str = "http://www.dillo.org/help/bug_meter.html";
   DilloUrl *url = a_Url_new(info_str, NULL, 0, 0, 0);

   a_Nav_push(bw, url);
   a_Url_free(url);
}