mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-28 23:09:43 +03:00
[project @ 2005-12-31 04:36:24 by rjw]
Read data from url_store, use new wimp_event system. svn path=/import/netsurf/; revision=1913
This commit is contained in:
parent
28f51bfcf5
commit
442f0e2a2c
@ -24,6 +24,7 @@
|
||||
#include "netsurf/riscos/menus.h"
|
||||
#include "netsurf/riscos/theme.h"
|
||||
#include "netsurf/riscos/treeview.h"
|
||||
#include "netsurf/riscos/wimp_event.h"
|
||||
#include "netsurf/utils/messages.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/url.h"
|
||||
@ -34,8 +35,6 @@
|
||||
|
||||
#define GLOBAL_HISTORY_RECENT_READ "Choices:WWW.NetSurf.Recent"
|
||||
#define GLOBAL_HISTORY_RECENT_WRITE "<Choices$Write>.WWW.NetSurf.Recent"
|
||||
#define GLOBAL_HISTORY_READ "Choices:WWW.NetSurf.History"
|
||||
#define GLOBAL_HISTORY_WRITE "<Choices$Write>.WWW.NetSurf.History"
|
||||
|
||||
|
||||
static struct node *global_history_base_node[MAXIMUM_BASE_NODES];
|
||||
@ -47,13 +46,11 @@ static int global_history_recent_count = 0;
|
||||
|
||||
static bool global_history_init;
|
||||
|
||||
|
||||
static bool ro_gui_global_history_click(wimp_pointer *pointer);
|
||||
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,
|
||||
int filetype);
|
||||
static void ro_gui_global_history_save_node(struct node *node, FILE *fp);
|
||||
struct node *ro_gui_global_history_find(const char *url);
|
||||
|
||||
/* A basic window for the history
|
||||
*/
|
||||
@ -98,10 +95,11 @@ void ro_gui_global_history_initialise(void) {
|
||||
FILE *fp;
|
||||
const char *title;
|
||||
os_error *error;
|
||||
char *node_title;
|
||||
char *node_url;
|
||||
int node_filetype;
|
||||
int node_visited;
|
||||
struct hostname_data *hostname;
|
||||
struct url_data *url;
|
||||
int url_count = 0;
|
||||
struct url_content **url_block;
|
||||
int i = 0;
|
||||
|
||||
/* Create our window
|
||||
*/
|
||||
@ -119,6 +117,12 @@ void ro_gui_global_history_initialise(void) {
|
||||
error->errnum, error->errmess));
|
||||
die(error->errmess);
|
||||
}
|
||||
ro_gui_wimp_event_register_redraw_window(global_history_window,
|
||||
ro_gui_tree_redraw);
|
||||
ro_gui_wimp_event_register_open_window(global_history_window,
|
||||
ro_gui_tree_open);
|
||||
ro_gui_wimp_event_register_mouse_click(global_history_window,
|
||||
ro_gui_global_history_click);
|
||||
|
||||
/* Create an empty tree
|
||||
*/
|
||||
@ -138,6 +142,10 @@ void ro_gui_global_history_initialise(void) {
|
||||
tree_initialise(global_history_tree);
|
||||
global_history_tree->handle = (int)global_history_window;
|
||||
global_history_tree->movable = false;
|
||||
ro_gui_wimp_event_set_user_data(global_history_window,
|
||||
global_history_tree);
|
||||
ro_gui_wimp_event_register_keypress(global_history_window,
|
||||
ro_gui_tree_keypress);
|
||||
|
||||
/* Create our toolbar
|
||||
*/
|
||||
@ -161,60 +169,40 @@ void ro_gui_global_history_initialise(void) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/* load global history */
|
||||
fp = fopen(GLOBAL_HISTORY_READ, "r");
|
||||
if (!fp)
|
||||
LOG(("Failed to open file '%s' for reading",
|
||||
GLOBAL_HISTORY_READ));
|
||||
else {
|
||||
global_history_init = true;
|
||||
while (fgets(s, MAXIMUM_URL_LENGTH, fp)) {
|
||||
if (s[strlen(s) - 1] == '\n')
|
||||
s[strlen(s) - 1] = '\0';
|
||||
node_title = strdup(s);
|
||||
if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) {
|
||||
LOG(("Error reading global history"));
|
||||
warn_user("HistoryCorrupt", 0);
|
||||
fclose(fp);
|
||||
global_history_init = false;
|
||||
/* count the number of URLs to add */
|
||||
for (hostname = url_store_hostnames; hostname;
|
||||
hostname = hostname->next)
|
||||
for (url = hostname->url; url; url = url->next)
|
||||
url_count++;
|
||||
if (url_count == 0)
|
||||
return;
|
||||
}
|
||||
if (s[strlen(s) - 1] == '\n')
|
||||
s[strlen(s) - 1] = '\0';
|
||||
node_url = strdup(s);
|
||||
if ((!node_title) || (!node_url)) {
|
||||
LOG(("No memory to read global history node"));
|
||||
|
||||
/* place pointers to the URL data in a single block of memory so
|
||||
* they can be quickly sorted */
|
||||
url_block = (struct url_content **)malloc(
|
||||
url_count * sizeof(struct url_content *));
|
||||
if (!url_block) {
|
||||
warn_user("NoMemory", 0);
|
||||
fclose(fp);
|
||||
global_history_init = false;
|
||||
LOG(("Insufficient memory for malloc()"));
|
||||
return;
|
||||
}
|
||||
if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) {
|
||||
LOG(("Error reading global history"));
|
||||
warn_user("HistoryCorrupt", 0);
|
||||
fclose(fp);
|
||||
for (hostname = url_store_hostnames; hostname;
|
||||
hostname = hostname->next)
|
||||
for (url = hostname->url; url; url = url->next)
|
||||
url_block[i++] = &url->data;
|
||||
assert(i == url_count);
|
||||
|
||||
/* sort information by the last_visit information */
|
||||
qsort(url_block, url_count, sizeof(struct url_content *),
|
||||
url_store_compare_last_visit);
|
||||
|
||||
/* add URLs to the global history */
|
||||
global_history_init = true;
|
||||
for (i = 0; i < url_count; i++)
|
||||
global_history_add(url_block[i]);
|
||||
|
||||
global_history_init = false;
|
||||
return;
|
||||
}
|
||||
node_filetype = atoi(s);
|
||||
if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) {
|
||||
LOG(("Error reading global history"));
|
||||
warn_user("HistoryCorrupt", 0);
|
||||
fclose(fp);
|
||||
global_history_init = false;
|
||||
return;
|
||||
}
|
||||
node_visited = atoi(s);
|
||||
ro_gui_global_history_add(node_title, node_url,
|
||||
node_visited, node_filetype);
|
||||
free(node_title);
|
||||
node_title = NULL;
|
||||
free(node_url);
|
||||
node_url = NULL;
|
||||
}
|
||||
global_history_init = false;
|
||||
fclose(fp);
|
||||
}
|
||||
free(url_block);
|
||||
}
|
||||
|
||||
|
||||
@ -283,7 +271,7 @@ static void ro_gui_global_history_initialise_node(const char *title,
|
||||
|
||||
|
||||
/**
|
||||
* Saves the global history and recent URL data.
|
||||
* Saves the global history's recent URL data.
|
||||
*/
|
||||
void ro_gui_global_history_save(void) {
|
||||
FILE *fp;
|
||||
@ -302,44 +290,6 @@ void ro_gui_global_history_save(void) {
|
||||
global_history_recent_url[i]);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/* save global history tree */
|
||||
fp = fopen(GLOBAL_HISTORY_WRITE, "w");
|
||||
if (!fp)
|
||||
LOG(("Failed to open file '%s' for writing",
|
||||
GLOBAL_HISTORY_WRITE));
|
||||
else {
|
||||
ro_gui_global_history_save_node(global_history_tree->root, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the global history for a tree node.
|
||||
*/
|
||||
void ro_gui_global_history_save_node(struct node *node, FILE *fp) {
|
||||
struct node_element *element;
|
||||
|
||||
for (; node; node = node->next) {
|
||||
if (node->folder) {
|
||||
ro_gui_global_history_save_node(node->child, fp);
|
||||
} else {
|
||||
element = tree_find_element(node, TREE_ELEMENT_URL);
|
||||
if (element) {
|
||||
fprintf(fp, "%s\n%s\n%i\n", node->data.text,
|
||||
element->text,
|
||||
element->user_data);
|
||||
|
||||
element = tree_find_element(node,
|
||||
TREE_ELEMENT_VISITED);
|
||||
if (element)
|
||||
fprintf(fp, "%i\n", element->user_data);
|
||||
else
|
||||
fprintf(fp, "-1\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -348,13 +298,14 @@ void ro_gui_global_history_save_node(struct node *node, FILE *fp) {
|
||||
*
|
||||
* \param pointer the pointer state
|
||||
*/
|
||||
void ro_gui_global_history_click(wimp_pointer *pointer) {
|
||||
bool ro_gui_global_history_click(wimp_pointer *pointer) {
|
||||
ro_gui_tree_click(pointer, global_history_tree);
|
||||
if (pointer->buttons == wimp_CLICK_MENU)
|
||||
ro_gui_menu_create(global_history_menu, pointer->pos.x,
|
||||
pointer->pos.y, pointer->w);
|
||||
else
|
||||
ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -372,46 +323,20 @@ int ro_gui_global_history_help(int x, int y) {
|
||||
|
||||
/**
|
||||
* Adds to the global history
|
||||
*
|
||||
* \param g the gui_window to add to the global history
|
||||
*/
|
||||
void global_history_add(struct gui_window *g) {
|
||||
url_func_result res;
|
||||
char *norm_url = NULL;
|
||||
|
||||
assert(g);
|
||||
|
||||
if ((!g->bw->current_content) || (!global_history_tree))
|
||||
return;
|
||||
|
||||
res = url_normalize(g->bw->current_content->url, &norm_url);
|
||||
if (res != URL_FUNC_OK) {
|
||||
warn_user("NoMemory", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
ro_gui_global_history_add(g->bw->current_content->title,
|
||||
norm_url, time(NULL),
|
||||
ro_content_filetype(g->bw->current_content));
|
||||
free(norm_url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds to the global history
|
||||
*
|
||||
* \param title the page title
|
||||
* \param url the page URL
|
||||
* \param visit_date the visit date
|
||||
*/
|
||||
void ro_gui_global_history_add(char *title, char *url, int visit_date,
|
||||
int filetype) {
|
||||
void global_history_add(struct url_content *data) {
|
||||
int i, j;
|
||||
struct node *parent = NULL;
|
||||
struct node *link;
|
||||
struct node *node;
|
||||
struct node_element *element;
|
||||
bool before = false;
|
||||
int visit_date;
|
||||
int filetype;
|
||||
|
||||
assert(data);
|
||||
|
||||
visit_date = data->last_visit;
|
||||
filetype = ro_content_filetype_from_type(data->type);
|
||||
|
||||
/* Find/create the node to link into
|
||||
*/
|
||||
@ -439,10 +364,28 @@ void ro_gui_global_history_add(char *title, char *url, int visit_date,
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
/* find any previous occurance */
|
||||
if (!global_history_init) {
|
||||
node = ro_gui_global_history_find(data->url);
|
||||
if (node) {
|
||||
/* \todo: calculate old/new positions and redraw
|
||||
* only the relevant portion */
|
||||
tree_redraw_area(global_history_tree,
|
||||
0, 0, 16384, 16384);
|
||||
tree_update_URL_node(node);
|
||||
tree_delink_node(node);
|
||||
tree_link_node(parent, node, false);
|
||||
tree_handle_node_changed(global_history_tree,
|
||||
node, false, true);
|
||||
/* ro_gui_tree_scroll_visible(hotlist_tree,
|
||||
&node->data);
|
||||
*/ return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the node at the bottom
|
||||
*/
|
||||
node = tree_create_URL_node_brief(parent, title, url, filetype,
|
||||
visit_date);
|
||||
node = tree_create_URL_node_shared(parent, data);
|
||||
if (node && !global_history_init)
|
||||
tree_redraw_area(global_history_tree,
|
||||
node->box.x - NODE_INSTEP,
|
||||
@ -451,21 +394,27 @@ void ro_gui_global_history_add(char *title, char *url, int visit_date,
|
||||
tree_handle_node_changed(global_history_tree, node,
|
||||
true, false);
|
||||
|
||||
/* Remove any duplicate URL from within the parent node.
|
||||
* This must be done after the duplicate has been created as
|
||||
* deleting all children of a child automatically collapses
|
||||
* the display.
|
||||
*/
|
||||
for (node = parent->child; node && (node->next);
|
||||
node = node->next) {
|
||||
element = tree_find_element(node, TREE_ELEMENT_URL);
|
||||
if ((element) && (!strcmp(url, element->text))) {
|
||||
tree_delete_node(global_history_tree, node,
|
||||
false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct node *ro_gui_global_history_find(const char *url) {
|
||||
int i;
|
||||
struct node *node;
|
||||
struct node_element *element;
|
||||
|
||||
for (i = 0; i < global_history_base_node_count; i++) {
|
||||
if (!global_history_base_node[i]->deleted) {
|
||||
for (node = global_history_base_node[i]->child;
|
||||
node; node = node->next) {
|
||||
element = tree_find_element(node,
|
||||
TREE_ELEMENT_URL);
|
||||
if ((element) && (url == element->text))
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,19 +12,13 @@
|
||||
#ifndef _NETSURF_RISCOS_GLOBALHISTORY_H_
|
||||
#define _NETSURF_RISCOS_GLOBALHISTORY_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "oslib/wimp.h"
|
||||
#include "netsurf/content/url_store.h"
|
||||
#include "netsurf/desktop/browser.h"
|
||||
|
||||
#define GLOBAL_HISTORY_RECENT_URLS 16
|
||||
|
||||
void ro_gui_global_history_initialise(void);
|
||||
void ro_gui_global_history_save(void);
|
||||
void ro_gui_global_history_click(wimp_pointer *pointer);
|
||||
void ro_gui_global_history_dialog_click(wimp_pointer *pointer);
|
||||
void ro_gui_global_history_menu_closed(void);
|
||||
int ro_gui_global_history_help(int x, int y);
|
||||
void ro_gui_global_history_save(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
226
riscos/hotlist.c
226
riscos/hotlist.c
@ -30,6 +30,7 @@
|
||||
#include "netsurf/riscos/tinct.h"
|
||||
#include "netsurf/riscos/treeview.h"
|
||||
#include "netsurf/riscos/wimp.h"
|
||||
#include "netsurf/riscos/wimp_event.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/messages.h"
|
||||
#include "netsurf/utils/utils.h"
|
||||
@ -38,6 +39,7 @@
|
||||
|
||||
static void ro_gui_hotlist_visited(struct content *content, struct tree *tree,
|
||||
struct node *node);
|
||||
static bool ro_gui_hotlist_click(wimp_pointer *pointer);
|
||||
|
||||
/* A basic window for the hotlist
|
||||
*/
|
||||
@ -89,6 +91,7 @@ void ro_gui_hotlist_initialise(void) {
|
||||
const char *title;
|
||||
os_error *error;
|
||||
struct node *node;
|
||||
struct url_content *data;
|
||||
|
||||
/* Create our window
|
||||
*/
|
||||
@ -106,6 +109,12 @@ void ro_gui_hotlist_initialise(void) {
|
||||
error->errnum, error->errmess));
|
||||
die(error->errmess);
|
||||
}
|
||||
ro_gui_wimp_event_register_redraw_window(hotlist_window,
|
||||
ro_gui_tree_redraw);
|
||||
ro_gui_wimp_event_register_open_window(hotlist_window,
|
||||
ro_gui_tree_open);
|
||||
ro_gui_wimp_event_register_mouse_click(hotlist_window,
|
||||
ro_gui_hotlist_click);
|
||||
|
||||
/* Either load or create a hotlist
|
||||
*/
|
||||
@ -126,9 +135,11 @@ void ro_gui_hotlist_initialise(void) {
|
||||
node = tree_create_folder_node(hotlist_tree->root, "NetSurf");
|
||||
if (!node)
|
||||
node = hotlist_tree->root;
|
||||
tree_create_URL_node(node, messages_get("HotlistHomepage"),
|
||||
"http://netsurf.sourceforge.net/", 0xfaf,
|
||||
time(NULL), -1, 0);
|
||||
data = url_store_find("http://netsurf.sourceforge.net/");
|
||||
if (data) {
|
||||
tree_create_URL_node(node, data,
|
||||
messages_get("HotlistHomepage"));
|
||||
}
|
||||
tree_initialise(hotlist_tree);
|
||||
} else {
|
||||
fclose(fp);
|
||||
@ -137,6 +148,9 @@ void ro_gui_hotlist_initialise(void) {
|
||||
if (!hotlist_tree) return;
|
||||
hotlist_tree->handle = (int)hotlist_window;
|
||||
hotlist_tree->movable = true;
|
||||
ro_gui_wimp_event_set_user_data(hotlist_window, hotlist_tree);
|
||||
ro_gui_wimp_event_register_keypress(hotlist_window,
|
||||
ro_gui_tree_keypress);
|
||||
|
||||
/* Create our toolbar
|
||||
*/
|
||||
@ -172,13 +186,14 @@ void ro_gui_hotlist_save(void) {
|
||||
*
|
||||
* \param pointer the pointer state
|
||||
*/
|
||||
void ro_gui_hotlist_click(wimp_pointer *pointer) {
|
||||
bool ro_gui_hotlist_click(wimp_pointer *pointer) {
|
||||
ro_gui_tree_click(pointer, hotlist_tree);
|
||||
if (pointer->buttons == wimp_CLICK_MENU)
|
||||
ro_gui_menu_create(hotlist_menu, pointer->pos.x,
|
||||
pointer->pos.y, pointer->w);
|
||||
else
|
||||
ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -210,16 +225,6 @@ void ro_gui_hotlist_visited(struct content *content, struct tree *tree,
|
||||
element = tree_find_element(node, TREE_ELEMENT_URL);
|
||||
if ((element) && (!strcmp(element->text,
|
||||
content->url))) {
|
||||
element->user_data =
|
||||
ro_content_filetype(content);
|
||||
element = tree_find_element(node,
|
||||
TREE_ELEMENT_VISITS);
|
||||
if (element)
|
||||
element->user_data += 1;
|
||||
element = tree_find_element(node,
|
||||
TREE_ELEMENT_LAST_VISIT);
|
||||
if (element)
|
||||
element->user_data = time(NULL);
|
||||
tree_update_URL_node(node);
|
||||
tree_handle_node_changed(tree, node, true,
|
||||
false);
|
||||
@ -237,17 +242,20 @@ void ro_gui_hotlist_visited(struct content *content, struct tree *tree,
|
||||
* \param node the node to prepare the dialogue for, or NULL
|
||||
*/
|
||||
void ro_gui_hotlist_prepare_folder_dialog(struct node *node) {
|
||||
const char *name;
|
||||
const char *title;
|
||||
|
||||
dialog_folder_node = node;
|
||||
if (node) {
|
||||
ro_gui_set_window_title(dialog_folder,
|
||||
messages_get("EditFolder"));
|
||||
ro_gui_set_icon_string(dialog_folder, 1, node->data.text);
|
||||
title = messages_get("EditFolder");
|
||||
name = node->data.text;
|
||||
} else {
|
||||
ro_gui_set_window_title(dialog_folder,
|
||||
messages_get("NewFolder"));
|
||||
ro_gui_set_icon_string(dialog_folder, 1,
|
||||
messages_get("Folder"));
|
||||
title = messages_get("NewFolder");
|
||||
name = messages_get("Folder");
|
||||
}
|
||||
ro_gui_set_window_title(dialog_folder, title);
|
||||
ro_gui_set_icon_string(dialog_folder, ICON_FOLDER_NAME, name);
|
||||
ro_gui_wimp_event_memorise(dialog_folder);
|
||||
}
|
||||
|
||||
|
||||
@ -258,135 +266,111 @@ void ro_gui_hotlist_prepare_folder_dialog(struct node *node) {
|
||||
*/
|
||||
void ro_gui_hotlist_prepare_entry_dialog(struct node *node) {
|
||||
struct node_element *element;
|
||||
const char *name;
|
||||
const char *title;
|
||||
const char *url = "";
|
||||
|
||||
dialog_entry_node = node;
|
||||
if (node) {
|
||||
ro_gui_set_window_title(dialog_entry, messages_get("EditLink"));
|
||||
ro_gui_set_icon_string(dialog_entry, 1, node->data.text);
|
||||
element = tree_find_element(node, TREE_ELEMENT_URL);
|
||||
if (element)
|
||||
ro_gui_set_icon_string(dialog_entry, 3, element->text);
|
||||
else
|
||||
ro_gui_set_icon_string(dialog_entry, 3, "");
|
||||
title = messages_get("EditLink");
|
||||
name = node->data.text;
|
||||
if ((element = tree_find_element(node, TREE_ELEMENT_URL)))
|
||||
url = element->text;
|
||||
} else {
|
||||
ro_gui_set_window_title(dialog_entry, messages_get("NewLink"));
|
||||
ro_gui_set_icon_string(dialog_entry, 1, messages_get("Link"));
|
||||
ro_gui_set_icon_string(dialog_entry, 3, "");
|
||||
title = messages_get("NewLink");
|
||||
name = messages_get("Link");
|
||||
}
|
||||
ro_gui_set_window_title(dialog_entry, title);
|
||||
ro_gui_set_icon_string(dialog_entry, ICON_ENTRY_NAME, name);
|
||||
ro_gui_set_icon_string(dialog_entry, ICON_ENTRY_URL, url);
|
||||
ro_gui_wimp_event_memorise(dialog_entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Respond to a mouse click
|
||||
* Apply the settings of dialog window (folder/entry edit)
|
||||
*
|
||||
* \param pointer the pointer state
|
||||
* \param w the window to apply
|
||||
*/
|
||||
void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) {
|
||||
bool ro_gui_hotlist_dialog_apply(wimp_w w) {
|
||||
struct node_element *element;
|
||||
struct node *node;
|
||||
char *title = NULL;
|
||||
char *title;
|
||||
char *icon;
|
||||
char *url = NULL;
|
||||
char *old_value;
|
||||
int icon = pointer->i;
|
||||
int close_icon, ok_icon;
|
||||
url_func_result res;
|
||||
url_func_result res = URL_FUNC_OK;
|
||||
struct url_content *data;
|
||||
|
||||
if (pointer->w == dialog_entry) {
|
||||
title = strip(ro_gui_get_icon_string(pointer->w, 1));
|
||||
url = strip(ro_gui_get_icon_string(pointer->w, 3));
|
||||
close_icon = 4;
|
||||
ok_icon = 5;
|
||||
node = dialog_entry_node;
|
||||
} else {
|
||||
title = strip(ro_gui_get_icon_string(pointer->w, 1));
|
||||
close_icon = 2;
|
||||
ok_icon = 3;
|
||||
node = dialog_folder_node;
|
||||
}
|
||||
|
||||
if (icon == close_icon) {
|
||||
if (pointer->buttons == wimp_CLICK_SELECT) {
|
||||
ro_gui_dialog_close(pointer->w);
|
||||
xwimp_create_menu((wimp_menu *)-1, 0, 0);
|
||||
} else {
|
||||
if (pointer->w == dialog_folder)
|
||||
ro_gui_hotlist_prepare_folder_dialog(
|
||||
dialog_folder_node);
|
||||
else
|
||||
ro_gui_hotlist_prepare_entry_dialog(
|
||||
dialog_entry_node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (icon != ok_icon)
|
||||
return;
|
||||
|
||||
/* Check we have valid values
|
||||
*/
|
||||
if ((title != NULL) && (strlen(title) == 0)) {
|
||||
warn_user("NoNameError", 0);
|
||||
return;
|
||||
}
|
||||
if ((url != NULL) && (strlen(url) == 0)) {
|
||||
/* get our data */
|
||||
if (w == dialog_entry) {
|
||||
icon = strip(ro_gui_get_icon_string(w, ICON_ENTRY_URL));
|
||||
if (strlen(icon) == 0) {
|
||||
warn_user("NoURLError", 0);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Update/insert our data
|
||||
*/
|
||||
if (!node) {
|
||||
if (pointer->w == dialog_folder) {
|
||||
dialog_folder_node = tree_create_folder_node(
|
||||
hotlist_tree->root,
|
||||
title);
|
||||
node = dialog_folder_node;
|
||||
} else {
|
||||
dialog_entry_node = tree_create_URL_node(
|
||||
hotlist_tree->root,
|
||||
title, url, 0xfaf, time(NULL), -1, 0);
|
||||
res = url_normalize(icon, &url);
|
||||
title = strip(ro_gui_get_icon_string(w, ICON_ENTRY_NAME));
|
||||
node = dialog_entry_node;
|
||||
} else {
|
||||
title = strip(ro_gui_get_icon_string(w, ICON_FOLDER_NAME));
|
||||
node = dialog_folder_node;
|
||||
}
|
||||
title = strdup(title);
|
||||
|
||||
/* check for failed functions or lack of text */
|
||||
if ((title == NULL) || (strlen(title) == 0) || (res != URL_FUNC_OK)) {
|
||||
free(url);
|
||||
free(title);
|
||||
node = NULL;
|
||||
if ((title == NULL) || (res != URL_FUNC_OK))
|
||||
warn_user("NoMemory", 0);
|
||||
else if (strlen(title) == 0)
|
||||
warn_user("NoNameError", 0);
|
||||
return false;
|
||||
}
|
||||
ro_gui_set_icon_string(w,
|
||||
(url ? ICON_ENTRY_NAME : ICON_FOLDER_NAME), title);
|
||||
|
||||
/* update/insert our data */
|
||||
if (!node) {
|
||||
if (url) {
|
||||
data = url_store_find(url);
|
||||
if (!data) {
|
||||
free(url);
|
||||
free(title);
|
||||
return false;
|
||||
}
|
||||
if (!data->title)
|
||||
data->title = strdup(title);
|
||||
node = dialog_entry_node = tree_create_URL_node(
|
||||
hotlist_tree->root, data, title);
|
||||
|
||||
} else {
|
||||
node = dialog_folder_node = tree_create_folder_node(
|
||||
hotlist_tree->root, title);
|
||||
}
|
||||
free(url);
|
||||
free(title);
|
||||
if (!node) {
|
||||
warn_user("NoMemory", 0);
|
||||
return false;
|
||||
}
|
||||
tree_handle_node_changed(hotlist_tree, node, true, false);
|
||||
ro_gui_tree_scroll_visible(hotlist_tree, &node->data);
|
||||
tree_redraw_area(hotlist_tree, node->box.x - NODE_INSTEP,
|
||||
0, NODE_INSTEP, 16384);
|
||||
} else {
|
||||
if (url) {
|
||||
element = tree_find_element(node, TREE_ELEMENT_URL);
|
||||
if (element) {
|
||||
old_value = element->text;
|
||||
res = url_normalize(url, &element->text);
|
||||
if (res != URL_FUNC_OK) {
|
||||
warn_user("NoMemory", 0);
|
||||
element->text = old_value;
|
||||
return;
|
||||
}
|
||||
free(old_value);
|
||||
}
|
||||
}
|
||||
if (title) {
|
||||
old_value = node->data.text;
|
||||
node->data.text = strdup(title);
|
||||
if (!node->data.text) {
|
||||
warn_user("NoMemory", 0);
|
||||
node->data.text = old_value;
|
||||
return;
|
||||
}
|
||||
free(old_value);
|
||||
free(element->text);
|
||||
element->text = url;
|
||||
ro_gui_set_icon_string(w, ICON_ENTRY_URL, url);
|
||||
}
|
||||
free(node->data.text);
|
||||
node->data.text = title;
|
||||
tree_handle_node_changed(hotlist_tree, node, true, false);
|
||||
}
|
||||
|
||||
if (pointer->buttons == wimp_CLICK_SELECT) {
|
||||
ro_gui_dialog_close(pointer->w);
|
||||
ro_gui_menu_closed();
|
||||
return;
|
||||
}
|
||||
if (pointer->w == dialog_folder)
|
||||
ro_gui_hotlist_prepare_folder_dialog(dialog_folder_node);
|
||||
else
|
||||
ro_gui_hotlist_prepare_entry_dialog(dialog_entry_node);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user