void ro_gui_debugwin_open(void) { #ifdef ENABLE_DEBUGWIN ro_gui_wimp_event_register_close_window(dialog_debug, ro_gui_debugwin_close); ro_gui_wimp_event_register_redraw_window(dialog_debug, ro_gui_debugwin_redraw); ro_gui_debugwin_resize(); ro_gui_dialog_open(dialog_debug); schedule_remove(ro_gui_debugwin_update, 0); schedule(DEBUGWIN_UPDATE, ro_gui_debugwin_update, 0); #endif }
void ro_gui_query_window_bring_to_front(query_id id) { struct gui_query_window *qw = ro_gui_query_window_lookup_id(id); if (qw) { os_error *error; ro_gui_dialog_open(qw->window); error = xwimp_set_caret_position(qw->window, (wimp_i)-1, 0, 0, 1 << 25, -1); if (error) { LOG(("xwimp_get_caret_position: 0x%x : %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); } } }
query_id query_user_xy(const char *query, const char *detail, const query_callback *cb, void *pw, const char *yes, const char *no, int x, int y) { struct gui_query_window *qw; char query_buffer[300]; os_error *error; wimp_icon *icn; int width; int len; int tx; char *local_text = NULL; nserror err; qw = malloc(sizeof(struct gui_query_window)); if (!qw) { warn_user("NoMemory", NULL); return QUERY_INVALID; } qw->cb = cb; qw->pw = pw; qw->id = next_id++; qw->default_confirm = false; if (next_id == QUERY_INVALID) next_id++; if (!yes) yes = messages_get("Yes"); if (!no) no = messages_get("No"); /* set the text of the 'Yes' button and size accordingly */ err = utf8_to_local_encoding(yes, 0, &local_text); if (err != NSERROR_OK) { assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_local_encoding_failed")); local_text = NULL; } icn = &query_template->icons[ICON_QUERY_YES]; len = strlen(local_text ? local_text : yes); len = max(len, icn->data.indirected_text.size - 1); memcpy(icn->data.indirected_text.text, local_text ? local_text: yes, len); icn->data.indirected_text.text[len] = '\0'; free(local_text); local_text = NULL; error = xwimptextop_string_width(icn->data.indirected_text.text, len, &width); if (error) { LOG(("xwimptextop_string_width: 0x%x:%s", error->errnum, error->errmess)); width = len * 16; } if (!query_yes_width) query_yes_width = icn->extent.x1 - icn->extent.x0; width += 44; if (width < query_yes_width) width = query_yes_width; icn->extent.x0 = tx = icn->extent.x1 - width; /* set the text of the 'No' button and size accordingly */ err = utf8_to_local_encoding(no, 0, &local_text); if (err != NSERROR_OK) { assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_local_encoding_failed")); local_text = NULL; } icn = &query_template->icons[ICON_QUERY_NO]; len = strlen(local_text ? local_text : no); len = max(len, icn->data.indirected_text.size - 1); memcpy(icn->data.indirected_text.text, local_text ? local_text : no, len); icn->data.indirected_text.text[len] = '\0'; free(local_text); local_text = NULL; if (!query_no_width) query_no_width = icn->extent.x1 - icn->extent.x0; icn->extent.x1 = tx - 16; error = xwimptextop_string_width(icn->data.indirected_text.text, len, &width); if (error) { LOG(("xwimptextop_string_width: 0x%x:%s", error->errnum, error->errmess)); width = len * 16; } width += 28; if (width < query_no_width) width = query_no_width; icn->extent.x0 = icn->extent.x1 - width; error = xwimp_create_window(query_template, &qw->window); if (error) { warn_user("WimpError", error->errmess); free(qw); return QUERY_INVALID; } snprintf(query_buffer, sizeof query_buffer, "%s %s", messages_get(query), detail ? detail : ""); query_buffer[sizeof query_buffer - 1] = 0; ro_gui_set_icon_string(qw->window, ICON_QUERY_MESSAGE, query_buffer, true); xwimp_set_icon_state(qw->window, ICON_QUERY_HELP, wimp_ICON_DELETED, wimp_ICON_DELETED); if (x >= 0 && y >= 0) { x -= tx - 8; y += (query_template->visible.y1 - query_template->visible.y0) / 2; ro_gui_dialog_open_xy(qw->window, x, y); } else ro_gui_dialog_open(qw->window); ro_gui_wimp_event_set_user_data(qw->window, qw); ro_gui_wimp_event_register_mouse_click(qw->window, ro_gui_query_click); ro_gui_wimp_event_register_cancel(qw->window, ICON_QUERY_NO); ro_gui_wimp_event_register_ok(qw->window, ICON_QUERY_YES, ro_gui_query_apply); ro_gui_wimp_event_register_close_window(qw->window, ro_gui_query_close); error = xwimp_set_caret_position(qw->window, (wimp_i)-1, 0, 0, 1 << 25, -1); if (error) { LOG(("xwimp_get_caret_position: 0x%x : %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); } /* put this query window at the head of our list */ if (gui_query_window_list) gui_query_window_list->prev = qw; qw->prev = NULL; qw->next = gui_query_window_list; gui_query_window_list = qw; return qw->id; }
struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *gui) { const char *url = download_context_get_url(ctx); const char *mime_type = download_context_get_mime_type(ctx); const char *temp_name; char *scheme = NULL; char *filename = NULL; struct gui_download_window *dw; bool space_warning = false; os_error *error; url_func_result res; char *local_path; utf8_convert_ret err; size_t i, last_dot; dw = malloc(sizeof *dw); if (!dw) { warn_user("NoMemory", 0); return 0; } dw->ctx = ctx; dw->saved = false; dw->close_confirmed = false; dw->error = false; dw->query = QUERY_INVALID; dw->received = 0; dw->total_size = download_context_get_total_length(ctx); strncpy(dw->url, url, sizeof dw->url); dw->url[sizeof dw->url - 1] = 0; dw->status[0] = 0; gettimeofday(&dw->start_time, 0); dw->last_time = dw->start_time; dw->last_received = 0; dw->file_type = 0; dw->average_rate = 0; dw->average_points = 0; /* Get scheme from URL */ res = url_scheme(url, &scheme); if (res == URL_FUNC_NOMEM) { warn_user("NoMemory", 0); free(dw); return 0; } else if (res == URL_FUNC_OK) { /* If we have a scheme and it's "file", then * attempt to use the local filetype directly */ if (strcasecmp(scheme, "file") == 0) { char *path = NULL; res = url_path(url, &path); if (res == URL_FUNC_NOMEM) { warn_user("NoMemory", 0); free(scheme); free(dw); return 0; } else if (res == URL_FUNC_OK) { char *raw_path = curl_unescape(path, strlen(path)); if (raw_path == NULL) { warn_user("NoMemory", 0); free(path); free(scheme); free(dw); return 0; } dw->file_type = ro_filetype_from_unix_path(raw_path); curl_free(raw_path); free(path); } } free(scheme); } /* If we still don't have a filetype (i.e. failed reading local * one or fetching a remote object), then use the MIME type */ if (dw->file_type == 0) { /* convert MIME type to RISC OS file type */ error = xmimemaptranslate_mime_type_to_filetype(mime_type, &(dw->file_type)); if (error) { LOG(("xmimemaptranslate_mime_type_to_filetype: 0x%x: %s", error->errnum, error->errmess)); warn_user("MiscError", error->errmess); dw->file_type = 0xffd; } } /* open temporary output file */ temp_name = ro_gui_download_temp_name(dw); if (!ro_gui_download_check_space(dw, temp_name, NULL)) { /* issue a warning but continue with the download because the user can save it to another medium whilst it's downloading */ space_warning = true; } error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR, temp_name, 0, &dw->file); if (error) { LOG(("xosfind_openoutw: 0x%x: %s", error->errnum, error->errmess)); warn_user("SaveError", error->errmess); free(dw); return 0; } /* fill in download window icons */ download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.text = dw->url; download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.size = sizeof dw->url; download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text. text = dw->status; download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text. size = sizeof dw->status; sprintf(dw->sprite_name, "file_%.3x", dw->file_type); if (!ro_gui_wimp_sprite_exists(dw->sprite_name)) strcpy(dw->sprite_name, "file_xxx"); download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_sprite.id = (osspriteop_id) dw->sprite_name; /* Get a suitable path- and leafname for the download. */ temp_name = download_context_get_filename(dw->ctx); if (temp_name == NULL) temp_name = messages_get("SaveObject"); if (temp_name != NULL) filename = strdup(temp_name); if (filename == NULL) { LOG(("Failed to establish download filename.")); warn_user("SaveError", error->errmess); free(dw); return 0; } for (i = 0, last_dot = (size_t) -1; filename[i] != '\0'; i++) { const char c = filename[i]; if (c == '.') { last_dot = i; filename[i] = '/'; } else if (c <= ' ' || strchr(":*#$&@^%\\", c) != NULL) filename[i] = '_'; } if (option_strip_extensions && last_dot != (size_t) -1) filename[last_dot] = '\0'; if (download_dir != NULL && strlen(download_dir) > 0) snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s.%s", download_dir, filename); else snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s", filename); err = utf8_to_local_encoding(dw->path, 0, &local_path); if (err != UTF8_CONVERT_OK) { /* badenc should never happen */ assert(err != UTF8_CONVERT_BADENC); LOG(("utf8_to_local_encoding failed")); warn_user("NoMemory", 0); free(dw); return 0; } else { strncpy(dw->path, local_path, sizeof dw->path); free(local_path); } download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.text = dw->path; download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.size = sizeof dw->path; download_template->icons[ICON_DOWNLOAD_DESTINATION].data. indirected_text.text = dw->path; download_template->icons[ICON_DOWNLOAD_DESTINATION].data. indirected_text.size = sizeof dw->path; download_template->icons[ICON_DOWNLOAD_DESTINATION].flags |= wimp_ICON_DELETED; /* create and open the download window */ error = xwimp_create_window(download_template, &dw->window); if (error) { LOG(("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); free(dw); return 0; } dw->prev = 0; dw->next = download_window_list; if (download_window_list) download_window_list->prev = dw; download_window_list = dw; ro_gui_download_update_status(dw); ro_gui_dialog_open(dw->window); ro_gui_wimp_event_set_user_data(dw->window, dw); ro_gui_wimp_event_register_mouse_click(dw->window, ro_gui_download_click); ro_gui_wimp_event_register_keypress(dw->window, ro_gui_download_keypress); ro_gui_wimp_event_register_close_window(dw->window, ro_gui_download_close); /* issue the warning now, so that it appears in front of the download * window! */ if (space_warning) warn_user("DownloadWarn", messages_get("NoDiscSpace")); return dw; }
static struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *gui) { nsurl *url = download_context_get_url(ctx); const char *temp_name; char *filename = NULL; struct gui_download_window *dw; bool space_warning = false; os_error *error; char *local_path; nserror err; size_t i, last_dot; dw = malloc(sizeof *dw); if (!dw) { ro_warn_user("NoMemory", 0); return 0; } dw->ctx = ctx; dw->saved = false; dw->close_confirmed = false; dw->error = false; dw->query = QUERY_INVALID; dw->received = 0; dw->total_size = download_context_get_total_length(ctx); /** @todo change this to take a reference to the nsurl and use * that value directly rather than using a fixed buffer. */ strncpy(dw->url, nsurl_access(url), sizeof dw->url); dw->url[sizeof dw->url - 1] = 0; dw->status[0] = 0; gettimeofday(&dw->start_time, 0); dw->last_time = dw->start_time; dw->last_received = 0; dw->file_type = 0; dw->average_rate = 0; dw->average_points = 0; /* get filetype */ err = download_ro_filetype(ctx, &dw->file_type); if (err != NSERROR_OK) { ro_warn_user(messages_get_errorcode(err), 0); free(dw); return 0; } /* open temporary output file */ temp_name = ro_gui_download_temp_name(dw); if (!ro_gui_download_check_space(dw, temp_name, NULL)) { /* issue a warning but continue with the download because the user can save it to another medium whilst it's downloading */ space_warning = true; } error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR, temp_name, 0, &dw->file); if (error) { LOG("xosfind_openoutw: 0x%x: %s", error->errnum, error->errmess); ro_warn_user("SaveError", error->errmess); free(dw); return 0; } /* fill in download window icons */ download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.text = dw->url; download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.size = sizeof dw->url; download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text. text = dw->status; download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text. size = sizeof dw->status; sprintf(dw->sprite_name, "file_%.3x", dw->file_type); if (!ro_gui_wimp_sprite_exists(dw->sprite_name)) strcpy(dw->sprite_name, "file_xxx"); download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_sprite.id = (osspriteop_id) dw->sprite_name; /* Get a suitable path- and leafname for the download. */ temp_name = download_context_get_filename(dw->ctx); if (temp_name == NULL) temp_name = messages_get("SaveObject"); if (temp_name != NULL) filename = strdup(temp_name); if (filename == NULL) { LOG("Failed to establish download filename."); ro_warn_user("SaveError", error->errmess); free(dw); return 0; } for (i = 0, last_dot = (size_t) -1; filename[i] != '\0'; i++) { const char c = filename[i]; if (c == '.') { last_dot = i; filename[i] = '/'; } else if (c <= ' ' || strchr(":*#$&@^%\\", c) != NULL) filename[i] = '_'; } if (nsoption_bool(strip_extensions) && last_dot != (size_t) -1) filename[last_dot] = '\0'; if (download_dir != NULL && strlen(download_dir) > 0) snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s.%s", download_dir, filename); else snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s", filename); free(filename); err = utf8_to_local_encoding(dw->path, 0, &local_path); if (err != NSERROR_OK) { /* badenc should never happen */ assert(err !=NSERROR_BAD_ENCODING); LOG("utf8_to_local_encoding failed"); ro_warn_user("NoMemory", 0); free(dw); return 0; } else { strncpy(dw->path, local_path, sizeof dw->path); free(local_path); } download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.text = dw->path; download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.size = sizeof dw->path; download_template->icons[ICON_DOWNLOAD_DESTINATION].data. indirected_text.text = dw->path; download_template->icons[ICON_DOWNLOAD_DESTINATION].data. indirected_text.size = sizeof dw->path; download_template->icons[ICON_DOWNLOAD_DESTINATION].flags |= wimp_ICON_DELETED; /* create and open the download window */ error = xwimp_create_window(download_template, &dw->window); if (error) { LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess); ro_warn_user("WimpError", error->errmess); free(dw); return 0; } dw->prev = 0; dw->next = download_window_list; if (download_window_list) download_window_list->prev = dw; download_window_list = dw; ro_gui_download_update_status(dw); ro_gui_dialog_open(dw->window); ro_gui_wimp_event_set_user_data(dw->window, dw); ro_gui_wimp_event_register_mouse_click(dw->window, ro_gui_download_click); ro_gui_wimp_event_register_keypress(dw->window, ro_gui_download_keypress); ro_gui_wimp_event_register_close_window(dw->window, ro_gui_download_close); /* issue the warning now, so that it appears in front of the download * window! */ if (space_warning) ro_warn_user("DownloadWarn", messages_get("NoDiscSpace")); return dw; }