summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2005-02-08 23:37:41 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2005-02-08 23:37:41 +0000
commit06a6a902c6e48ced47157ab57ffa3e3c1d410398 (patch)
treec8a47af87029069cbe33568cf913ffdad075a2a2
parentacb914b90af6f937c73c153a818c97baa13eb8c4 (diff)
downloadnetsurf-06a6a902c6e48ced47157ab57ffa3e3c1d410398.tar.gz
netsurf-06a6a902c6e48ced47157ab57ffa3e3c1d410398.tar.bz2
[project @ 2005-02-08 23:37:41 by rjw]
Give global history some functionality svn path=/import/netsurf/; revision=1508
-rw-r--r--riscos/global_history.c117
-rw-r--r--riscos/hotlist.c1
-rw-r--r--riscos/menus.c37
-rw-r--r--riscos/window.c12
4 files changed, 157 insertions, 10 deletions
diff --git a/riscos/global_history.c b/riscos/global_history.c
index f0940b3b5..d3efc386c 100644
--- a/riscos/global_history.c
+++ b/riscos/global_history.c
@@ -14,6 +14,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "netsurf/content/url_store.h"
@@ -28,6 +29,7 @@
#include "netsurf/utils/utils.h"
#define MAXIMUM_URL_LENGTH 1024
+#define MAXIMUM_BASE_NODES 16
#define GLOBAL_HISTORY_RECENT_READ "Choices:WWW.NetSurf.Recent"
#define GLOBAL_HISTORY_RECENT_WRITE "<Choices$Write>.WWW.NetSurf.Recent"
@@ -35,9 +37,16 @@
#define GLOBAL_HISTORY_WRITE "<Choices$Write>.WWW.NetSurf.History"
+static struct node *global_history_base_node[MAXIMUM_BASE_NODES];
+static int global_history_base_node_time[MAXIMUM_BASE_NODES];
+static int global_history_base_node_count = 0;
+
static char *global_history_recent_url[GLOBAL_HISTORY_RECENT_URLS];
static int global_history_recent_count = 0;
+static void ro_gui_global_history_initialise_nodes(void);
+static void ro_gui_global_history_initialise_node(const char *title, time_t base,
+ int days_back);
static void ro_gui_global_history_add(char *title, char *url, int visit_date);
/* A basic window for the history
@@ -113,11 +122,11 @@ void ro_gui_global_history_initialise(void) {
global_history_tree = NULL;
}
global_history_tree->root->expanded = true;
+ ro_gui_global_history_initialise_nodes();
+ /* todo: load history */
tree_initialise(global_history_tree);
-
-
- if (!global_history_tree) return;
global_history_tree->handle = (int)global_history_window;
+ global_history_tree->movable = false;
/* Create our toolbar
*/
@@ -146,6 +155,70 @@ void ro_gui_global_history_initialise(void) {
/**
+ * Initialises the base nodes
+ */
+static void ro_gui_global_history_initialise_nodes(void) {
+ struct tm *full_time;
+ time_t t;
+ int weekday;
+ int i;
+
+ /* get the current time */
+ t = time(NULL);
+ if (t == -1)
+ return;
+
+ /* get the time at the start of today */
+ full_time = localtime(&t);
+ weekday = full_time->tm_wday;
+ full_time->tm_sec = 0;
+ full_time->tm_min = 0;
+ full_time->tm_hour = 0;
+ t = mktime(full_time);
+ if (t == -1)
+ return;
+
+ ro_gui_global_history_initialise_node(messages_get("DateToday"), t, 0);
+ if (weekday > 0)
+ ro_gui_global_history_initialise_node(messages_get("DateYesterday"),
+ t, -1);
+ for (i = 2; i <= weekday; i++)
+ ro_gui_global_history_initialise_node(NULL, t, -i);
+ ro_gui_global_history_initialise_node(messages_get("Date1Week"),
+ t, -weekday - 7);
+ ro_gui_global_history_initialise_node(messages_get("Date2Week"),
+ t, -weekday - 14);
+ ro_gui_global_history_initialise_node(messages_get("Date3Week"),
+ t, -weekday - 21);
+}
+
+static void ro_gui_global_history_initialise_node(const char *title, time_t base,
+ int days_back) {
+ struct tm *full_time;
+ char buffer[64];
+ struct node *node;
+
+ base += days_back * 60 * 60 * 24;
+ if (!title) {
+ full_time = localtime(&base);
+ strftime((char *)&buffer, (size_t)64, "%A", full_time);
+ node = tree_create_folder_node(NULL, buffer);
+ } else
+ node = tree_create_folder_node(NULL, title);
+
+ if (!node)
+ return;
+
+ node->retain_in_memory = true;
+ node->deleted = true;
+ node->editable = false;
+ global_history_base_node[global_history_base_node_count] = node;
+ global_history_base_node_time[global_history_base_node_count] = base;
+ global_history_base_node_count++;
+}
+
+
+/**
* Saves the global history and recent URL data.
*/
void ro_gui_global_history_save(void) {
@@ -250,8 +323,42 @@ void global_history_add(struct gui_window *g) {
* \param visit_date the visit date
*/
void ro_gui_global_history_add(char *title, char *url, int visit_date) {
- LOG(("Added '%s' ('%s') dated %i.", title, url, visit_date));
-
+ int i, j;
+ struct node *parent = NULL;
+ struct node *link;
+ struct node *node;
+ bool before = false;
+
+ /* Find/create the node to link into
+ */
+ for (i = 0; i < global_history_base_node_count; i++) {
+ if (global_history_base_node_time[i] <= visit_date) {
+ parent = global_history_base_node[i];
+ if (parent->deleted) {
+ link = global_history_tree->root;
+ for (j = 0; j < i; j++) {
+ if (!global_history_base_node[j]->deleted) {
+ link = global_history_base_node[j];
+ before = true;
+ break;
+ }
+ }
+ tree_link_node(link, parent, before);
+ tree_recalculate_node_positions(global_history_tree->root);
+ tree_redraw_area(global_history_tree, 0, 0, 16384, 16384); }
+ break;
+ }
+ }
+
+ if (parent) {
+ node = tree_create_URL_node_brief(parent, title, url, 0xfaf, visit_date);
+ if (node) {
+ tree_redraw_area(global_history_tree, node->box.x - NODE_INSTEP,
+ 0, NODE_INSTEP, 16384);
+ tree_handle_node_changed(global_history_tree, node, false,
+ true);
+ }
+ }
}
diff --git a/riscos/hotlist.c b/riscos/hotlist.c
index fa3ed7c77..cdcf9960b 100644
--- a/riscos/hotlist.c
+++ b/riscos/hotlist.c
@@ -133,6 +133,7 @@ void ro_gui_hotlist_initialise(void) {
}
if (!hotlist_tree) return;
hotlist_tree->handle = (int)hotlist_window;
+ hotlist_tree->movable = true;
/* Create our toolbar
*/
diff --git a/riscos/menus.c b/riscos/menus.c
index bc7e31315..15c0987d3 100644
--- a/riscos/menus.c
+++ b/riscos/menus.c
@@ -988,6 +988,41 @@ void ro_gui_menu_selection(wimp_selection *selection)
ro_gui_menu_prepare_hotlist();
break;
}
+ } else if (current_menu == global_history_menu) {
+ switch (selection->items[0]) {
+ case 0: /* Hotlist-> */
+ switch (selection->items[1]) {
+ case 0: /* Export */
+ break;
+ case 1: /* Expand */
+ tree_handle_expansion(global_history_tree, global_history_tree->root, true,
+ (selection->items[2] != 2), (selection->items[2] != 1));
+ break;
+ case 2: /* Collapse */
+ tree_handle_expansion(global_history_tree, global_history_tree->root, false,
+ (selection->items[2] != 2), (selection->items[2] != 1));
+ break;
+ }
+ break;
+ case 1: /* Selection-> */
+ switch (selection->items[1]) {
+ case 0: /* Launch */
+ ro_gui_tree_launch_selected(global_history_tree);
+ break;
+ case 1: /* Delete */
+ tree_delete_selected_nodes(global_history_tree, global_history_tree->root);
+ break;
+ }
+ break;
+ case 2: /* Select all */
+ ro_gui_tree_keypress(1, global_history_tree);
+ ro_gui_menu_prepare_global_history();
+ break;
+ case 3: /* Clear */
+ ro_gui_tree_keypress(26, global_history_tree);
+ ro_gui_menu_prepare_global_history();
+ break;
+ }
} else if (current_menu == browser_menu) {
struct content *c = current_gui->bw->current_content;
switch (selection->items[0]) {
@@ -1598,7 +1633,7 @@ void ro_gui_menu_global_history_warning(wimp_message_menu_warning *warning)
switch (warning->selection.items[1]) {
case -1: /* Root */
ro_gui_menu_prepare_global_history();
- error = xwimp_create_sub_menu(hotlist_select_menu,
+ error = xwimp_create_sub_menu(history_select_menu,
warning->pos.x, warning->pos.y);
break;
}
diff --git a/riscos/window.c b/riscos/window.c
index 0e3c5bea8..4852f8fc9 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -1191,10 +1191,14 @@ void ro_gui_toolbar_click(struct gui_window *g, wimp_pointer *pointer)
g->bw->current_content->url,
ro_content_filetype(g->bw->current_content),
time(NULL), -1, 0);
- tree_redraw_area(hotlist_tree, node->box.x - NODE_INSTEP, 0,
- NODE_INSTEP, 16384);
- tree_handle_node_changed(hotlist_tree, node, false, true);
- ro_gui_tree_scroll_visible(hotlist_tree, &node->data);
+ if (node) {
+ tree_redraw_area(hotlist_tree,
+ node->box.x - NODE_INSTEP, 0,
+ NODE_INSTEP, 16384);
+ tree_handle_node_changed(hotlist_tree, node, false,
+ true);
+ ro_gui_tree_scroll_visible(hotlist_tree, &node->data);
+ }
} else if (hotlist_tree) {
ro_gui_hotlist_show();
}