/* ghtml_load_url */ void ghtml_load_url(GtkWidget * widget, char const * url) { GHtml * ghtml; char * p; char * q = NULL; const char about[] = "<!DOCTYPE html>\n<html>\n" "<head><title>About " PACKAGE "</title></head>\n" "<body>\n<center>\n<h1>" PACKAGE " " VERSION "</h1>\n" "<p>Copyright © 2009-2013 Pierre Pronchery <khorben@" "defora.org></p>\n</center>\n</body>\n</html>"; ghtml = g_object_get_data(G_OBJECT(widget), "ghtml"); if((p = _ghtml_make_url(NULL, url)) != NULL) url = p; if(strcmp("about:blank", url) == 0) webkit_web_view_load_string(WEBKIT_WEB_VIEW(ghtml->view), "", NULL, NULL, url); else if(strncmp("about:", url, 6) == 0) webkit_web_view_load_string(WEBKIT_WEB_VIEW(ghtml->view), about, NULL, NULL, url); else { #if WEBKIT_CHECK_VERSION(1, 1, 1) webkit_web_view_load_uri(WEBKIT_WEB_VIEW(ghtml->view), url); #else webkit_web_view_open(WEBKIT_WEB_VIEW(ghtml->view), url); #endif } g_free(p); g_free(q); surfer_set_progress(ghtml->surfer, 0.0); surfer_set_security(ghtml->surfer, SS_NONE); _ghtml_set_status(widget, _("Connecting...")); }
/* ghtml_load_url */ void ghtml_load_url(GtkWidget * widget, char const * url) { GHtml * ghtml; gchar * link; ghtml = g_object_get_data(G_OBJECT(widget), "ghtml"); if((link = _ghtml_make_url(NULL, url)) != NULL) url = link; _ghtml_document_load(ghtml, url, NULL); g_free(link); }
/* on_view_event_after */ static gboolean _on_view_event_after(GtkWidget * widget, GdkEvent * event, gpointer data) { GHtml * ghtml = data; GdkEventButton * eb; GtkTextIter start; GtkTextIter end; gint x; gint y; GtkTextIter iter; GSList * tags; GSList * p; char * link = NULL; gchar * url; if(event->type != GDK_BUTTON_RELEASE || event->button.button != 1) return FALSE; eb = &event->button; gtk_text_buffer_get_selection_bounds(ghtml->tbuffer, &start, &end); if(gtk_text_iter_get_offset(&start) != gtk_text_iter_get_offset(&end)) return FALSE; gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_WIDGET, eb->x, eb->y, &x, &y); gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, x, y); tags = gtk_text_iter_get_tags(&iter); for(p = tags; p != NULL; p = p->next) if((link = g_object_get_data(G_OBJECT(p->data), "link")) != NULL) break; if(tags != NULL) g_slist_free(tags); if(link == NULL) return FALSE; url = (ghtml->base != NULL) ? ghtml->base : _history_get_location( ghtml->current); if((url = _ghtml_make_url(url, link)) != NULL) surfer_open(ghtml->surfer, url); else surfer_open(ghtml->surfer, link); g_free(url); return FALSE; }
Download * download_new(DownloadPrefs * prefs, char const * url) { Download * download; char * p; char buf[256]; GtkWidget * vbox; GtkWidget * hbox; GtkSizeGroup * left; GtkWidget * widget; PangoFontDescription * bold; unsigned long id; /* verify arguments */ if(prefs == NULL || url == NULL) { errno = EINVAL; _download_error(NULL, NULL, 1); return NULL; } if((download = malloc(sizeof(*download))) == NULL) { _download_error(NULL, "malloc", 1); return NULL; } /* initialize structure */ download->prefs.output = (prefs->output != NULL) ? strdup(prefs->output) : NULL; download->prefs.user_agent = (prefs->user_agent != NULL) ? strdup(prefs->user_agent) : NULL; if((p = _ghtml_make_url(NULL, url)) != NULL) url = p; download->url = strdup(url); free(p); if(download->url != NULL && prefs->output == NULL) download->prefs.output = strdup(basename(download->url)); download->conn = NULL; download->data_received = 0; download->content_length = 0; download->timeout = 0; download->pulse = 0; /* verify initialization */ if((prefs->output != NULL && download->prefs.output == NULL) || (prefs->user_agent != NULL && download->prefs.user_agent == NULL) || download->url == NULL || gettimeofday(&download->tv, NULL) != 0) { _download_error(NULL, "gettimeofday", 1); download_delete(download); return NULL; } /* window */ if(prefs->embedded == 0) { download->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); snprintf(buf, sizeof(buf), "%s %s", _("Download"), download->url); #if GTK_CHECK_VERSION(2, 6, 0) gtk_window_set_icon_name(GTK_WINDOW(download->window), "stock_download"); #endif gtk_window_set_resizable(GTK_WINDOW(download->window), FALSE); gtk_window_set_title(GTK_WINDOW(download->window), buf); g_signal_connect_swapped(download->window, "delete-event", G_CALLBACK(_download_on_closex), download); } else { download->window = gtk_plug_new(0); g_signal_connect_swapped(download->window, "embedded", G_CALLBACK(_download_on_embedded), download); } #if GTK_CHECK_VERSION(3, 0, 0) vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); #else vbox = gtk_vbox_new(FALSE, 2); #endif bold = pango_font_description_new(); pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD); left = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); /* address */ #if GTK_CHECK_VERSION(3, 0, 0) hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); #else hbox = gtk_hbox_new(FALSE, 4); #endif widget = gtk_label_new(_("Address: ")); #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_override_font(widget, bold); g_object_set(widget, "halign", GTK_ALIGN_START, NULL); #else gtk_widget_modify_font(widget, bold); gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5); #endif gtk_size_group_add_widget(left, widget); gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0); download->address = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(download->address), download->url); gtk_editable_set_editable(GTK_EDITABLE(download->address), FALSE); gtk_box_pack_start(GTK_BOX(hbox), download->address, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); /* labels */ _download_label(vbox, bold, left, _("File: "), &download->filename, download->prefs.output); _download_label(vbox, bold, left, _("Status: "), &download->status, _("Resolving...")); _download_label(vbox, bold, left, _("Received: "), &download->received, _("0.0 kB")); _download_label(vbox, bold, left, _("Remaining: "), &download->remaining, _("Unknown")); /* progress bar */ download->progress = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(vbox), download->progress, FALSE, FALSE, 0); /* checkbox */ download->check = gtk_check_button_new_with_label( _("Close window when the download is complete")); gtk_box_pack_start(GTK_BOX(vbox), download->check, FALSE, FALSE, 0); /* button */ #if GTK_CHECK_VERSION(3, 0, 0) hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); #else hbox = gtk_hbox_new(FALSE, 4); #endif download->cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); g_signal_connect_swapped(download->cancel, "clicked", G_CALLBACK( _download_on_cancel), download); gtk_box_pack_end(GTK_BOX(hbox), download->cancel, FALSE, TRUE, 0); download->browse = gtk_button_new_with_mnemonic("_Open folder"); gtk_widget_set_no_show_all(download->browse, TRUE); widget = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON); gtk_button_set_image(GTK_BUTTON(download->browse), widget); g_signal_connect_swapped(download->browse, "clicked", G_CALLBACK( _download_on_browse), download); gtk_box_pack_end(GTK_BOX(hbox), download->browse, FALSE, TRUE, 0); gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(download->window), 4); gtk_container_add(GTK_CONTAINER(download->window), vbox); download->timeout = g_idle_add(_download_on_idle, download); _download_refresh(download); gtk_widget_show_all(vbox); if(prefs->embedded == 0) gtk_widget_show(download->window); else { id = gtk_plug_get_id(GTK_PLUG(download->window)); printf("%lu\n", id); fclose(stdout); } _download_cnt++; return download; }