From 5db1eae529dca654aa4591371918a07954824edb Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Sun, 4 Jul 2004 18:44:51 +0000 Subject: [project @ 2004-07-04 18:44:51 by rjw] Loading/saving of hotlists. Initial work for hotlist menu. svn path=/import/netsurf/; revision=1046 --- riscos/gui.c | 9 +- riscos/gui.h | 4 +- riscos/hotlist.c | 425 ++++++++++++++++++++++++++++++++++++++++++------------- riscos/menus.c | 56 +++++++- riscos/toolbar.c | 4 +- 5 files changed, 396 insertions(+), 102 deletions(-) (limited to 'riscos') diff --git a/riscos/gui.c b/riscos/gui.c index 8ae1fd26c..49c71f77e 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -71,13 +71,14 @@ static clock_t gui_last_poll; /**< Time of last wimp_poll. */ osspriteop_area *gui_sprites; /**< Sprite area containing pointer and hotlist sprites */ /** Accepted wimp user messages. */ -static wimp_MESSAGE_LIST(28) task_messages = { { +static wimp_MESSAGE_LIST(29) task_messages = { { message_HELP_REQUEST, message_DATA_SAVE, message_DATA_SAVE_ACK, message_DATA_LOAD, message_DATA_OPEN, message_MENU_WARNING, + message_MENUS_DELETED, #ifdef WITH_URI message_URI_PROCESS, message_URI_RETURN_RESULT, @@ -386,6 +387,7 @@ void ro_gui_check_resolvers(void) void gui_quit(void) { + ro_gui_hotlist_save(); ro_gui_history_quit(); free(gui_sprites); wimp_close_down(task_handle); @@ -834,6 +836,11 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message) ro_gui_menu_warning((wimp_message_menu_warning *) &message->data); break; + case message_MENUS_DELETED: + if (current_menu == hotlist_menu) { + ro_gui_hotlist_menu_closed(); + } + break; #ifdef WITH_URI case message_URI_PROCESS: diff --git a/riscos/gui.h b/riscos/gui.h index 2ab06f165..3980ba2eb 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -27,7 +27,7 @@ extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_debug; extern wimp_w history_window; extern wimp_w hotlist_window; -extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu; +extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu; extern int iconbar_menu_height; extern struct form_control *current_gadget; extern gui_window *window_list; @@ -177,6 +177,7 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer); /* in hotlist.c */ void ro_gui_hotlist_init(void); +void ro_gui_hotlist_save(void); void ro_gui_hotlist_show(void); void ro_gui_hotlist_add(char *title, struct content *content); void ro_gui_hotlist_redraw(wimp_draw *redraw); @@ -184,6 +185,7 @@ void ro_gui_hotlist_click(wimp_pointer *pointer); void ro_gui_hotlist_selection_drag_end(wimp_dragged *drag); void ro_gui_hotlist_move_drag_end(wimp_dragged *drag); bool ro_gui_hotlist_keypress(int key); +void ro_gui_hotlist_menu_closed(void); /* in save.c */ void ro_gui_save_click(wimp_pointer *pointer); diff --git a/riscos/hotlist.c b/riscos/hotlist.c index f791d24aa..96297a62e 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -33,6 +33,13 @@ #define HOTLIST_TEXT_BUFFER 256 +#define HOTLIST_LEAF_INSET 32 +#define HOTLIST_ICON_WIDTH 36 +#define HOTLIST_LINE_HEIGHT 44 +#define HOTLIST_TEXT_PADDING 16 + +#define HOTLIST_LOAD_BUFFER 1024 + struct hotlist_entry { /** The next hotlist entry at this level, or NULL for no more @@ -120,7 +127,7 @@ static wimp_window hotlist_window_definition = { 1, 1, {"Hotlist"}, - 0, + 0 }; /* An icon to plot text with @@ -165,11 +172,17 @@ static osspriteop_trans_tab *pixel_table; */ wimp_mouse_state drag_buttons; +/* Whether the current selection was from a menu click +*/ +bool menu_selection = false; + +/* Hotlist loading buffer +*/ +char *load_buf; static bool ro_gui_hotlist_load(void); -static void ro_gui_hotlist_save(void); -static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry entry); -static bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry entry); +static bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry); +static bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry *entry); static void ro_gui_hotlist_link_entry(struct hotlist_entry *parent, struct hotlist_entry *entry); static void ro_gui_hotlist_visited_update(struct content *content, struct hotlist_entry *entry); static int ro_gui_hotlist_redraw_tree(struct hotlist_entry *entry, int level, int x0, int y0); @@ -184,18 +197,14 @@ static void ro_gui_hotlist_selection_drag(struct hotlist_entry *entry, bool toggle, bool redraw); static int ro_gui_hotlist_selection_count(struct hotlist_entry *entry); static void ro_gui_hotlist_update_expansion(struct hotlist_entry *entry, bool only_selected, - bool expand, bool contract); + bool folders, bool links, bool expand, bool contract); +static void ro_gui_hotlist_launch_selection(struct hotlist_entry *entry); static char *last_visit_to_string(time_t last_visit); void ro_gui_hotlist_init(void) { os_error *error; - /* Ensure we have a directory to save to later. - */ - xosfile_create_dir(".WWW", 0); - xosfile_create_dir(".WWW.NetSurf", 0); - /* Set the initial root options */ root.next_entry = NULL; @@ -206,7 +215,7 @@ void ro_gui_hotlist_init(void) { /* Load the hotlist */ if (!ro_gui_hotlist_load()) { - return; +// return; } /* Get our sprite ids for faster plotting. This could be done in a @@ -291,7 +300,7 @@ void ro_gui_hotlist_show(void) { if (!(state.flags & wimp_WINDOW_OPEN)) { /* Clear the selection/expansion states */ - ro_gui_hotlist_update_expansion(root.child_entry, false, false, true); + ro_gui_hotlist_update_expansion(root.child_entry, false, true, true, false, true); ro_gui_hotlist_selection_state(root.child_entry, false, false); /* Get the current screen size @@ -324,7 +333,8 @@ bool ro_gui_hotlist_load(void) { fileswitch_object_type obj_type = 0; struct hotlist_entry *netsurf; struct hotlist_entry *entry; - bool success; + bool success = true; + bool found = false; /* Check if we have an initial hotlist. OS_File does funny things relating to errors, so we use the object type to determine success @@ -340,9 +350,34 @@ bool ro_gui_hotlist_load(void) { return false; } + /* Get some memory to work with + */ + load_buf = malloc(HOTLIST_LOAD_BUFFER); + if (!load_buf) { + warn_user("HotlistLoadError", 0); + fclose(fp); + return false; + } + + /* Check for the opening to vaguely validate our file + */ + if ((fgets(load_buf, HOTLIST_LOAD_BUFFER, fp) == NULL) || + (strncmp("", load_buf, 6) != 0)) { + warn_user("HotlistLoadError", 0); + free(load_buf); + fclose(fp); + return false; + } + + /* Keep reading until we get to a
    + */ + while (!found && (fgets(load_buf, HOTLIST_LOAD_BUFFER, fp))) { + if (strncmp("
      ", load_buf, 4) == 0) found = true; + } + /* Start our recursive load */ - success = ro_gui_hotlist_load_entry(fp, root); + if (found) success = ro_gui_hotlist_load_entry(fp, &root); /* Tell the user if we had any problems */ @@ -352,6 +387,7 @@ bool ro_gui_hotlist_load(void) { /* Close our file and return */ + free(load_buf); fclose(fp); return success; } else { @@ -377,6 +413,15 @@ bool ro_gui_hotlist_load(void) { void ro_gui_hotlist_save(void) { FILE *fp; + /* Don't save if we didn't load + */ + if (!hotlist_window) return; + + /* Ensure we have a directory to save to later. + */ + xosfile_create_dir(".WWW", 0); + xosfile_create_dir(".WWW.NetSurf", 0); + /* Open our file */ fp = fopen(".WWW.NetSurf.Hotlist", "w"); @@ -385,23 +430,158 @@ void ro_gui_hotlist_save(void) { return; } + /* HTML header + */ + fprintf(fp, "\n\nHotlist\n\n"); + /* Start our recursive save */ - if (!ro_gui_hotlist_save_entry(fp, root)) { + if (!ro_gui_hotlist_save_entry(fp, root.child_entry)) { warn_user("HotlistSaveError", 0); } + + /* HTML footer + */ + fprintf(fp, "\n\n"); /* Close our file */ fclose(fp); + + /* Set the filetype to HTML + */ + xosfile_set_type(".WWW.NetSurf.Hotlist", 0xfaf); } -bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry entry) { - return false; +bool ro_gui_hotlist_save_entry(FILE *fp, struct hotlist_entry *entry) { + if (!entry) return true; + + /* We're starting a new child + */ + fprintf(fp, "
        \n"); + + /* Work through the entries + */ + while (entry) { + /* Save this entry + */ + if (entry->url) { + fprintf(fp, "
      • %s\n", entry->url, entry->title); + } else { + fprintf(fp, "
      • %s\n", entry->title); + } + fprintf(fp, "\n", entry->title); + if (entry->url) { + fprintf(fp, "\n", entry->url); + fprintf(fp, "\n", entry->filetype); + } + if (entry->add_date != -1) fprintf(fp, "\n", (int)entry->add_date); + if (entry->last_date != -1) fprintf(fp, "\n", (int)entry->last_date); + if (entry->visits != 0) fprintf(fp, "\n", entry->visits); + + /* Continue onwards + */ + if (entry->child_entry) { + ro_gui_hotlist_save_entry(fp, entry->child_entry); + } + entry = entry->next_entry; + } + + /* We're starting a new child + */ + fprintf(fp, "
      \n"); + return true; } -bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry entry) { - return false; +bool ro_gui_hotlist_load_entry(FILE *fp, struct hotlist_entry *entry) { + struct hotlist_entry *last_entry = NULL; + char *title = NULL; + char *url = NULL; + int add_date = -1; + int last_date = -1; + int visits = 0; + int filetype = 0; + int val_length; + + /* Check we can add to something + */ + if (entry == NULL) return false; + + /* Keep reading until we get to a
        + */ + while (fgets(load_buf, HOTLIST_LOAD_BUFFER, fp)) { + + /* Check if we should commit what we have + */ + if ((strncmp("
      • ", load_buf, 4) == 0) || + (strncmp("
      ", load_buf, 5) == 0) || + (strncmp("
        ", load_buf, 4) == 0)) { + if (title != NULL) { + /* Add the entry + */ + last_entry = ro_gui_hotlist_create(title, url, filetype, entry); + last_entry->add_date = add_date; + if (last_entry->url) { + last_entry->last_date = last_date; + last_entry->visits = visits; + last_entry->filetype = filetype; + } + + /* Reset for the next entry + */ + free(title); + title = NULL; + if (url) { + free(url); + url = NULL; + } + add_date = -1; + last_date = -1; + visits = 0; + filetype = 0; + } + } + + /* Check if we've reached the end of our run + */ + if (strncmp("
      ", load_buf, 5) == 0) return true; + + /* Check for some data + */ + if (strncmp("