summaryrefslogtreecommitdiff
path: root/amiga/hotlist.c
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2013-09-12 12:08:50 +0100
committerChris Young <chris@unsatisfactorysoftware.co.uk>2013-09-12 12:08:50 +0100
commitfda365fb2d64333b4d60649cb7e778b51c179fc5 (patch)
treed6381c30313d327c8014308dd5055eb135279e65 /amiga/hotlist.c
parent177b46e873d29c4c5324467239bc80f11997c5e0 (diff)
downloadnetsurf-fda365fb2d64333b4d60649cb7e778b51c179fc5.tar.gz
netsurf-fda365fb2d64333b4d60649cb7e778b51c179fc5.tar.bz2
Move the hotlist menu creator into hotlist.c and make it more generic
Diffstat (limited to 'amiga/hotlist.c')
-rwxr-xr-xamiga/hotlist.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/amiga/hotlist.c b/amiga/hotlist.c
index 6fa1568fb..e9841d3f2 100755
--- a/amiga/hotlist.c
+++ b/amiga/hotlist.c
@@ -19,6 +19,17 @@
#include <proto/exec.h>
#include "amiga/hotlist.h"
#include "amiga/tree.h"
+#include "desktop/hotlist.h"
+
+struct ami_hotlist_ctx {
+ struct gui_window_2 *gw;
+ int level;
+ int item;
+ const char *folder; /* folder we're interested in */
+ bool in_menu; /* set if we are in that folder */
+ bool (*cb)(struct gui_window_2 *gw, int level, int item, const char *title, nsurl *url, bool folder);
+};
+
void ami_hotlist_initialise(const char *hotlist_file)
{
@@ -33,3 +44,61 @@ void ami_hotlist_free(const char *hotlist_file)
ami_tree_destroy(hotlist_window);
hotlist_window = NULL;
}
+
+
+static nserror ami_hotlist_folder_enter_cb(void *ctx, const char *title)
+{
+ struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
+
+ if(menu_ctx->in_menu == true) {
+ if(menu_ctx->cb(menu_ctx->gw, menu_ctx->level, menu_ctx->item, title, NULL, true) == true)
+ menu_ctx->item++;
+ } else {
+ if((menu_ctx->level == 0) && (strcmp(title, menu_ctx->folder) == 0))
+ menu_ctx->in_menu = true;
+ }
+ menu_ctx->level++;
+ return NSERROR_OK;
+}
+
+static nserror ami_hotlist_address_cb(void *ctx, nsurl *url, const char *title)
+{
+ struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
+
+ if(menu_ctx->in_menu == true) {
+ if(menu_ctx->cb(menu_ctx->gw, menu_ctx->level, menu_ctx->item, title, url, false) == true)
+ menu_ctx->item++;
+ }
+
+ return NSERROR_OK;
+}
+
+static nserror ami_hotlist_folder_leave_cb(void *ctx)
+{
+ struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
+
+ menu_ctx->level--;
+
+ if((menu_ctx->in_menu == true) && (menu_ctx->level == 0))
+ menu_ctx->in_menu = false;
+
+ return NSERROR_OK;
+}
+
+nserror ami_hotlist_scan(struct gui_window_2 *gwin, int first_item, const char *folder,
+ bool (*cb_add_item)(struct gui_window_2 *gw, int level, int item, const char *title, nsurl *url, bool folder))
+{
+ struct ami_hotlist_ctx ctx;
+
+ ctx.level = 0;
+ ctx.item = first_item;
+ ctx.folder = folder;
+ ctx.in_menu = false;
+ ctx.gw = gwin;
+ ctx.cb = cb_add_item;
+
+ return hotlist_iterate(&ctx,
+ ami_hotlist_folder_enter_cb,
+ ami_hotlist_address_cb,
+ ami_hotlist_folder_leave_cb);
+}