summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Fryatt <steve@stevefryatt.org.uk>2011-10-09 13:32:43 +0000
committerSteve Fryatt <steve@stevefryatt.org.uk>2011-10-09 13:32:43 +0000
commit17cf5fab71df242d839222abbd59d4b728dc8f90 (patch)
treebfb56ac05b0a0b3cd7d41c600d501dca0011125a
parentd21bdf16fca2821bf8dbcc903cbd23014c12c55f (diff)
downloadnetsurf-17cf5fab71df242d839222abbd59d4b728dc8f90.tar.gz
netsurf-17cf5fab71df242d839222abbd59d4b728dc8f90.tar.bz2
Add support for external hotlist utilities.
svn path=/trunk/netsurf/; revision=13022
-rw-r--r--riscos/gui.c5
-rw-r--r--riscos/hotlist.c127
-rw-r--r--riscos/hotlist.h12
-rw-r--r--riscos/options.h7
-rw-r--r--riscos/window.c2
5 files changed, 145 insertions, 8 deletions
diff --git a/riscos/gui.c b/riscos/gui.c
index 4a7b9a06a..cc8a9d7ff 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -239,6 +239,7 @@ static ns_wimp_message_list task_messages = {
message_PRINT_SAVE,
message_PRINT_ERROR,
message_PRINT_TYPE_ODD,
+ message_HOTLIST_CHANGED,
0
}
};
@@ -1436,7 +1437,9 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message)
case message_PRINT_TYPE_ODD:
ro_print_type_odd(message);
break;
-
+ case message_HOTLIST_CHANGED:
+ ro_gui_hotlist_add_cleanup();
+ break;
case message_QUIT:
netsurf_quit = true;
break;
diff --git a/riscos/hotlist.c b/riscos/hotlist.c
index 7c52d6d37..34aec9081 100644
--- a/riscos/hotlist.c
+++ b/riscos/hotlist.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <time.h>
#include "oslib/osfile.h"
+#include "oslib/osmodule.h"
#include "oslib/wimp.h"
#include "content/content.h"
#include "content/hlcache.h"
@@ -37,6 +38,7 @@
#include "riscos/dialog.h"
#include "riscos/hotlist.h"
#include "riscos/menus.h"
+#include "riscos/message.h"
#include "riscos/options.h"
#include "riscos/save.h"
#include "riscos/toolbar.h"
@@ -57,6 +59,7 @@ static void ro_gui_hotlist_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
static bool ro_gui_hotlist_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
wimp_selection *selection, menu_action action);
static void ro_gui_hotlist_toolbar_click(button_bar_action action);
+static void ro_gui_hotlist_addurl_bounce(wimp_message *message);
struct ro_treeview_callbacks ro_hotlist_treeview_callbacks = {
ro_gui_hotlist_toolbar_click,
@@ -64,13 +67,29 @@ struct ro_treeview_callbacks ro_hotlist_treeview_callbacks = {
ro_gui_hotlist_toolbar_save_buttons
};
+/* Hotlist Protocol Message Blocks, which are currently not in OSLib. */
+
+struct ro_hotlist_message_hotlist_addurl {
+ wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
+ char *url; /**< Pointer to the URL in RMA. */
+ char *title; /**< Pointer to the title in RMA. */
+ char appname[32]; /**< The application name. */
+};
+
+struct ro_hotlist_message_hotlist_changed {
+ wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
+};
+
+static char *hotlist_url = NULL; /**< URL area claimed from RMA. */
+static char *hotlist_title = NULL; /**< Title area claimed from RMA. */
+
/* The RISC OS hotlist window, toolbar and treeview data. */
static struct ro_hotlist {
- wimp_w window; /*< The hotlist RO window handle. */
- struct toolbar *toolbar; /*< The hotlist toolbar handle. */
- ro_treeview *tv; /*< The hotlist treeview handle. */
- wimp_menu *menu; /*< The hotlist window menu. */
+ wimp_w window; /**< The hotlist RO window handle. */
+ struct toolbar *toolbar; /**< The hotlist toolbar handle. */
+ ro_treeview *tv; /**< The hotlist treeview handle. */
+ wimp_menu *menu; /**< The hotlist window menu. */
} hotlist_window;
/**
@@ -420,6 +439,106 @@ bool ro_gui_hotlist_check_menu(wimp_menu *menu)
return false;
}
+
+/**
+ * Add a URL to the hotlist. This will be passed on to the core hotlist, then
+ * Message_HotlistAddURL will broadcast to any bookmark applications via the
+ * Hotlist Protocol.
+ *
+ * \param *url The URL to be added.
+ */
+
+void ro_gui_hotlist_add_page(const char *url)
+{
+ const struct url_data *data;
+ wimp_message message;
+ struct ro_hotlist_message_hotlist_addurl *add_url =
+ (struct ro_hotlist_message_hotlist_addurl *) &message;
+
+ if (url == NULL)
+ return;
+
+ /* First pass the page to NetSurf's own hotlist. */
+
+ hotlist_add_page(url);
+
+ /* Then pass it on to any helper applications that might be
+ * interested.
+ *
+ * The RMA storage is freed on receipt of a Message_HotlistChanged or
+ * a bounce from Message_HotlistAddURL. Some clients don't seem to
+ * bother sending back a Message_HotlistChanged, so in this case the
+ * strings are left in situ in RMA and cleared the next time we need
+ * to send a message.
+ */
+
+ if (hotlist_url != NULL || hotlist_title != NULL)
+ ro_gui_hotlist_add_cleanup();
+
+ if (!option_external_hotlists)
+ return;
+
+ data = urldb_get_url_data(url);
+ if (data == NULL)
+ return;
+
+ hotlist_url = osmodule_alloc(strlen(url) + 1);
+ hotlist_title = osmodule_alloc(strlen(data->title) + 1);
+
+ if (hotlist_url == NULL || hotlist_title == NULL) {
+ ro_gui_hotlist_add_cleanup();
+ return;
+ }
+
+ strcpy(hotlist_url, url);
+ strcpy(hotlist_title, data->title);
+
+ add_url->size = 60;
+ add_url->your_ref = 0;
+ add_url->action = message_HOTLIST_ADD_URL;
+ add_url->url = hotlist_url;
+ add_url->title = hotlist_title;
+ strcpy(add_url->appname, "NetSurf");
+
+ if (!ro_message_send_message(wimp_USER_MESSAGE_RECORDED, &message, 0,
+ ro_gui_hotlist_addurl_bounce))
+ ro_gui_hotlist_add_cleanup();
+}
+
+
+/**
+ * Handle bounced Message_HotlistAddURL, so that RMA storage can be freed.
+ *
+ * \param *message The bounced message content.
+ */
+
+static void ro_gui_hotlist_addurl_bounce(wimp_message *message)
+{
+ LOG(("Hotlist AddURL Bounced"));
+ ro_gui_hotlist_add_cleanup();
+}
+
+
+/**
+ * Clean up RMA storage used by the Message_HotlistAddURL protocol.
+ */
+
+void ro_gui_hotlist_add_cleanup(void)
+{
+ LOG(("Clean up RMA"));
+
+ if (hotlist_url != NULL) {
+ osmodule_free(hotlist_url);
+ hotlist_url = NULL;
+ }
+
+ if (hotlist_title != NULL) {
+ osmodule_free(hotlist_title);
+ hotlist_title = NULL;
+ }
+}
+
+
#if 0
/**
* Handle URL dropped on hotlist
diff --git a/riscos/hotlist.h b/riscos/hotlist.h
index e47c140a1..55f8d648c 100644
--- a/riscos/hotlist.h
+++ b/riscos/hotlist.h
@@ -24,6 +24,16 @@
#ifndef _NETSURF_RISCOS_HOTLIST_H_
#define _NETSURF_RISCOS_HOTLIST_H_
+/* Hotlist Protocol Messages, which are currently not in OSLib. */
+
+#ifndef message_HOTLIST_ADD_URL
+#define message_HOTLIST_ADD_URL 0x4af81
+#endif
+
+#ifndef message_HOTLIST_CHANGED
+#define message_HOTLIST_CHANGED 0x4af82
+#endif
+
#include "riscos/menus.h"
void ro_gui_hotlist_preinitialise(void);
@@ -32,6 +42,8 @@ void ro_gui_hotlist_open(void);
void ro_gui_hotlist_save(void);
bool ro_gui_hotlist_check_window(wimp_w window);
bool ro_gui_hotlist_check_menu(wimp_menu *menu);
+void ro_gui_hotlist_add_page(const char *url);
+void ro_gui_hotlist_add_cleanup(void);
#endif
diff --git a/riscos/options.h b/riscos/options.h
index 96a0d5a8b..84c76af43 100644
--- a/riscos/options.h
+++ b/riscos/options.h
@@ -64,6 +64,7 @@ extern char *option_theme_path;
extern char *option_theme_save;
extern bool option_thumbnail_iconise;
extern bool option_interactive_help;
+extern bool option_external_hotlists;
#define EXTRA_OPTION_DEFINE \
bool option_use_mouse_gestures = false;\
@@ -101,7 +102,8 @@ char *option_recent_save = 0; \
char *option_theme_path = 0; \
char *option_theme_save = 0; \
bool option_thumbnail_iconise = true; \
-bool option_interactive_help = true;
+bool option_interactive_help = true; \
+bool option_external_hotlists = true;
#define EXTRA_OPTION_TABLE \
{ "use_mouse_gestures", OPTION_BOOL, &option_use_mouse_gestures },\
@@ -139,6 +141,7 @@ bool option_interactive_help = true;
{ "theme_path", OPTION_STRING, &option_theme_path }, \
{ "theme_save", OPTION_STRING, &option_theme_save }, \
{ "thumbnail_iconise", OPTION_BOOL, &option_thumbnail_iconise }, \
-{ "interactive_help", OPTION_BOOL, &option_interactive_help }
+{ "interactive_help", OPTION_BOOL, &option_interactive_help }, \
+{ "external_hotlists", OPTION_BOOL, &option_external_hotlists }
#endif
diff --git a/riscos/window.c b/riscos/window.c
index df7dc3192..de3617db4 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -3964,7 +3964,7 @@ void ro_gui_window_action_add_bookmark(struct gui_window *g)
content_get_url(g->bw->current_content) == NULL)
return;
- hotlist_add_page(nsurl_access(content_get_url(g->bw->current_content)));
+ ro_gui_hotlist_add_page(nsurl_access(content_get_url(g->bw->current_content)));
}