[project @ 2005-02-08 23:37:41 by rjw]

Give global history some functionality

svn path=/import/netsurf/; revision=1508
This commit is contained in:
Richard Wilson 2005-02-08 23:37:41 +00:00
parent acb914b90a
commit 06a6a902c6
4 changed files with 157 additions and 10 deletions

View File

@ -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
*/
@ -145,6 +154,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.
*/
@ -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);
}
}
}

View File

@ -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
*/

View File

@ -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;
}

View File

@ -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();
}