24#include <glib/gstdio.h>
43#define UPDATE_RATE 500
99 GtkTreeRowReference *
row;
140 GtkCellRenderer *renderer;
142 treeview = GTK_TREE_VIEW(gtk_builder_get_object(gladeFile,
146 renderer = gtk_cell_renderer_progress_new();
147 gtk_tree_view_insert_column_with_attributes(
treeview,
160 renderer = gtk_cell_renderer_text_new();
161 g_object_set(G_OBJECT(renderer),
163 PANGO_WRAP_WORD_CHAR,
167 gtk_tree_view_insert_column_with_attributes(
treeview,
174 gtk_tree_view_column_set_expand(
179 renderer = gtk_cell_renderer_text_new();
180 gtk_tree_view_insert_column_with_attributes(
treeview,
189 renderer = gtk_cell_renderer_text_new();
190 gtk_tree_view_insert_column_with_attributes(
treeview,
221 enum { PAUSE_BUTTON, CLEAR_BUTTON, CANCEL_BUTTON, RESUME_BUTTON };
245 selected = gtk_tree_selection_count_selected_rows(
selection);
247 rows = gtk_tree_selection_get_selected_rows(
selection, &model);
248 while (rows != NULL) {
249 gtk_tree_model_get_iter(model,
251 (GtkTreePath*)rows->data);
252 gtk_tree_model_get(model,
262 while (rows != NULL) {
279 gtk_tree_path_free(data);
295 GList *rows, *dls = NULL;
303 while (rows != NULL) {
306 gtk_tree_model_get_iter(GTK_TREE_MODEL(
dl_ctx.
store),
308 (GtkTreePath*)rows->data);
316 dls = g_list_prepend(dls, dl);
331 g_list_foreach(dls, (GFunc)action, NULL);
341 size_info = g_strdup_printf(
messages_get(
"gtkSizeInfo"),
348 r = g_strdup_printf(
"%s\n%s", dl->
name->str, size_info);
350 r = g_strdup_printf(
"%s\n%s", dl->
name->str, dl->
error->message);
364 return g_strdup(
"-");
367 hours = seconds / 3600;
368 seconds -= hours * 3600;
369 minutes = seconds / 60;
370 seconds -= minutes * 60;
373 return g_strdup_printf(
"%u:%02u:%02u",
378 return g_strdup_printf(
"%u:%02u", minutes, seconds);
387 char speed[strlen(human) +
SLEN(
"/s") + 1];
388 sprintf(
speed,
"%s/s", human);
393 gtk_tree_model_get_iter(GTK_TREE_MODEL(
dl_ctx.
store),
395 gtk_tree_row_reference_get_path(dl->
row));
420 gboolean update, pulse_mode = FALSE;
422 unsigned long long int total = 0;
424 gfloat percent, elapsed = g_timer_elapsed(
dl_ctx.
timer, NULL);
428 for (list =
dl_ctx.
list; list != NULL; list = list->next) {
430 update = force_update;
470 text = g_strdup_printf(
472 "gtkProgressBarPulse" :
473 "gtkProgressBarPulseSingle"),
478 percent = total != 0 ? (double)
downloaded / (
double)total : 0;
480 floor(percent * 100), dls);
502 gtk_tree_model_get_iter(GTK_TREE_MODEL(
dl_ctx.
store),
504 gtk_tree_row_reference_get_path(dl->
row));
509 g_string_free(dl->
name, TRUE);
522 GtkTreeViewColumn *
column,
528 model = gtk_tree_view_get_model(
tree);
530 if (gtk_tree_model_get_iter(model, &iter,
path)) {
552 gtk_tree_model_get_iter(GTK_TREE_MODEL(
dl_ctx.
store),
554 gtk_tree_row_reference_get_path(dl->
row));
603 enum { GTK_RESPONSE_DOWNLOAD, GTK_RESPONSE_SAVE_AS };
612 dialog = gtk_message_dialog_new_with_markup(
614 GTK_DIALOG_DESTROY_WITH_PARENT,
615 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
616 "<span size=\"x-large\" weight=\"ultrabold\">%s</span>"
617 "\n\n<small>%s</small>",
621 gtk_dialog_add_buttons(GTK_DIALOG(
dialog),
628 gtk_widget_destroy(
dialog);
633 case GTK_RESPONSE_SAVE_AS: {
634 dialog = gtk_file_chooser_dialog_new(
637 GTK_FILE_CHOOSER_ACTION_SAVE,
641 gtk_file_chooser_set_current_name
643 gtk_file_chooser_set_current_folder
644 (GTK_FILE_CHOOSER(
dialog),
646 gtk_file_chooser_set_do_overwrite_confirmation
647 (GTK_FILE_CHOOSER(
dialog),
651 if (
result == GTK_RESPONSE_ACCEPT)
653 (GTK_FILE_CHOOSER(
dialog));
654 gtk_widget_destroy(
dialog);
657 case GTK_RESPONSE_DOWNLOAD: {
668 if (g_file_test(
destination, G_FILE_TEST_EXISTS) &&
674 info = g_strdup_printf(
messages_get(
"gtkOverwriteInfo"),
677 dialog = gtk_message_dialog_new_with_markup(
679 GTK_DIALOG_DESTROY_WITH_PARENT,
680 GTK_MESSAGE_QUESTION,
684 gtk_message_dialog_format_secondary_markup(
685 GTK_MESSAGE_DIALOG(
dialog),
689 button = gtk_dialog_add_button(GTK_DIALOG(
dialog),
691 GTK_RESPONSE_DOWNLOAD);
692 gtk_button_set_image(GTK_BUTTON(button),
695 GTK_ICON_SIZE_BUTTON));
698 if (
result == GTK_RESPONSE_CANCEL)
701 gtk_widget_destroy(
dialog);
721 dialog = gtk_message_dialog_new_with_markup(
726 "<big><b>%s</b></big>\n\n"
731 gtk_dialog_run(GTK_DIALOG(
dialog));
732 gtk_widget_destroy(
dialog);
771 gboolean unknown_size;
784 download = malloc(
sizeof *download);
785 if (download == NULL) {
812 download->
row = gtk_tree_row_reference_new(
814 gtk_tree_model_get_path(
828 download->
error = NULL;
834 g_string_free(download->
name, TRUE);
835 g_string_free(download->
time_left, TRUE);
839 g_io_channel_set_encoding(download->
write, NULL, &download->
error);
871 g_io_channel_write_chars(dw->
write, data,
size, NULL, &dw->
error);
872 if (dw->
error != NULL) {
905 g_io_channel_shutdown(dw->
write, TRUE, &dw->
error);
906 g_io_channel_unref(dw->
write);
941 NSLOG(netsurf, INFO,
"Download UI builder init failed");
945 gtk_builder_connect_signals(builder, NULL);
947 dl_ctx.
pause = GTK_BUTTON(gtk_builder_get_object(builder,
949 dl_ctx.
clear = GTK_BUTTON(gtk_builder_get_object(builder,
951 dl_ctx.
cancel = GTK_BUTTON(gtk_builder_get_object(builder,
953 dl_ctx.
resume = GTK_BUTTON(gtk_builder_get_object(builder,
956 dl_ctx.
progress = GTK_PROGRESS_BAR(gtk_builder_get_object(builder,
958 dl_ctx.
window = GTK_WINDOW(gtk_builder_get_object(builder,
964 gtk_window_set_destroy_with_parent(GTK_WINDOW(
dl_ctx.
window),
984 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(
dl_ctx.
store),
987 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(
dl_ctx.
store),
1006 g_signal_connect_swapped(gtk_builder_get_object(builder,
"buttonClear"),
1011 g_signal_connect_swapped(gtk_builder_get_object(builder,
"buttonCancel"),
1042 dialog = gtk_message_dialog_new_with_markup(
1045 GTK_MESSAGE_WARNING,
1047 "<big><b>%s</b></big>\n\n"
1048 "<small>%s</small>",
1052 gtk_dialog_add_buttons(GTK_DIALOG(
dialog),
1053 "gtk-cancel", GTK_RESPONSE_CANCEL,
1054 "gtk-quit", GTK_RESPONSE_CLOSE,
1057 response = gtk_dialog_run(GTK_DIALOG(
dialog));
1058 gtk_widget_destroy(
dialog);
1060 if (response == GTK_RESPONSE_CANCEL) {
GtkWidget * nsgtk_image_new_from_stock(const gchar *id, GtkIconSize size)
Creates a GtkImage displaying a stock icon.
gboolean nsgtk_widget_get_visible(GtkWidget *widget)
Compatibility functions for older GTK versions (interface)
#define NSGTK_STOCK_SAVE_AS
#define NSGTK_STOCK_CANCEL
void download_context_destroy(download_context *ctx)
Destroy a download context.
nsurl * download_context_get_url(const download_context *ctx)
Retrieve the URL for a download.
const char * download_context_get_filename(const download_context *ctx)
Retrieve the filename for a download.
void download_context_abort(download_context *ctx)
Abort a download fetch.
unsigned long long int download_context_get_total_length(const download_context *ctx)
Retrieve total byte length of download.
Core download context (interface)
nserror
Enumeration of error codes.
@ NSERROR_SAVE_FAILED
Failed to save data.
static gboolean nsgtk_download_update(gboolean force_update)
static struct gui_download_table download_table
static void nsgtk_download_gfunc__gtk_tree_path_free(gpointer data, gpointer user_data)
Wrapper to GFunc-ify gtk_tree_path_free for g_list_foreach.
static gboolean nsgtk_download_gsourcefunc__nsgtk_download_update(gpointer user_data)
Wrapper to GSourceFunc-ify nsgtk_download_update.
@ NSGTK_DOWNLOAD_N_COLUMNS
@ NSGTK_DOWNLOAD_PROGRESS
@ NSGTK_DOWNLOAD_REMAINING
void nsgtk_download_show(GtkWindow *parent)
Show the download window.
static void nsgtk_download_do(nsgtk_download_selection_action action)
static void nsgtk_download_sensitivity_update_buttons(nsgtk_download_actions sensitivity)
static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size)
core callback on receipt of data
static struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *gui)
core callback on creating a new download
static gchar * nsgtk_download_info_to_string(struct gui_download_window *dl)
@ NSGTK_DOWNLOAD_CANCELED
@ NSGTK_DOWNLOAD_COMPLETE
void nsgtk_download_destroy(void)
Destroy download window.
static void nsgtk_download_change_status(struct gui_download_window *dl, nsgtk_download_status status)
static void nsgtk_download_gfunc__g_free(gpointer data, gpointer user_data)
Wrapper to GFunc-ify g_free for g_list_foreach.
static gboolean nsgtk_download_handle_error(GError *error)
static gboolean nsgtk_download_hide(GtkWidget *window)
static void nsgtk_download_change_sensitivity(struct gui_download_window *dl, nsgtk_download_actions sensitivity)
static void nsgtk_download_store_cancel_item(struct gui_download_window *dl, void *user_data)
static GtkTreeView * nsgtk_download_tree_view_new(GtkBuilder *gladeFile)
static const gchar * status_messages[]
static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg)
core callback on error
static void nsgtk_download_tree_view_row_activated(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *column, gpointer data)
static void nsgtk_download_store_clear_item(struct gui_download_window *dl, void *user_data)
static void nsgtk_download_store_create_item(struct gui_download_window *dl)
bool nsgtk_check_for_downloads(GtkWindow *parent)
Check with user if download is in progress they want to complete.
static void gui_download_window_done(struct gui_download_window *dw)
core callback when core download is complete
static void nsgtk_download_store_update_item(struct gui_download_window *dl)
static gchar * nsgtk_download_time_to_string(gint seconds)
nserror nsgtk_download_init(void)
Initialise download window ready for use.
void(* nsgtk_download_selection_action)(struct gui_download_window *dl, void *user_data)
static struct download_window_ctx dl_ctx
global instance of the download window
static gint nsgtk_download_sort(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
struct gui_download_table * nsgtk_download_table
download operation table for gtk
static gchar * nsgtk_download_dialog_show(const gchar *filename, const gchar *domain, const gchar *size)
Prompt user for downloaded file name.
static void nsgtk_download_sensitivity_evaluate(GtkTreeSelection *selection)
nserror nsgtk_warning(const char *warning, const char *detail)
Warn the user of an event.
struct nsgtk_scaffolding * nsgtk_get_scaffold(struct gui_window *g)
get containing nsgtk scaffolding handle from gui window handle
Interface to platform-specific download operations.
#define NSLOG(catname, level, logmsg, args...)
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
NetSurf URL handling (interface).
bool nsurl_has_component(const nsurl *url, nsurl_component part)
Enquire about the existence of componenets in a given URL.
lwc_string * nsurl_get_component(const nsurl *url, nsurl_component part)
Get part of a URL as a lwc_string, from a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out)
Create gtk builder object for the named ui resource.
Interface to gtk builtin resource handling.
GtkWindow * nsgtk_scaffolding_window(struct nsgtk_scaffolding *g)
Get the gtk window for a scaffolding.
Interface to utility string handling.
char * human_friendly_bytesize(unsigned long long int bytesize)
Create a human readable representation of a size in bytes.
A context for a download.
context for a nsgtk download window.
GtkProgressBar * progress
GtkTreeSelection * selection
function table for download windows.
struct gui_download_window *(* create)(struct download_context *ctx, struct gui_window *parent)
context for each download.
unsigned int total_size
Size of resource, or 0 if unknown.
unsigned long long int size_downloaded
nsgtk_download_status status
nsatari_download_status status
GtkTreeRowReference * row
unsigned long long int size_total
nsgtk_download_actions sensitivity
struct download_context * ctx
Associated context, or 0 if the fetch has completed or aborted.
NSDownloadWindow * window
first entry in window list
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Interface to a number of general purpose functionality.
#define fallthrough
switch fall through
#define SLEN(x)
Calculate length of constant C string.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.