summaryrefslogtreecommitdiff
path: root/amiga
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2011-05-11 18:33:31 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2011-05-11 18:33:31 +0000
commit45be35677c20da435cbc81f1b3a96d13ce3f6a37 (patch)
tree5416ef8061c75df9b491d43f24818ed6356f7e9d /amiga
parentdf081a08884bcf91ef94f679d6b3d69ab0042908 (diff)
downloadnetsurf-45be35677c20da435cbc81f1b3a96d13ce3f6a37.tar.gz
netsurf-45be35677c20da435cbc81f1b3a96d13ce3f6a37.tar.bz2
Allow users to register external applications for plugin contents, and run from
context menu svn path=/trunk/netsurf/; revision=12381
Diffstat (limited to 'amiga')
-rwxr-xr-xamiga/context_menu.c21
-rw-r--r--amiga/plugin_hack.c76
-rw-r--r--amiga/plugin_hack.h10
3 files changed, 79 insertions, 28 deletions
diff --git a/amiga/context_menu.c b/amiga/context_menu.c
index 71109ef28..d3bb8ae6f 100755
--- a/amiga/context_menu.c
+++ b/amiga/context_menu.c
@@ -33,6 +33,7 @@
#include "amiga/history_local.h"
#include "amiga/iff_dr2d.h"
#include "amiga/options.h"
+#include "amiga/plugin_hack.h"
#include "amiga/theme.h"
#include "amiga/utf8.h"
#include "desktop/textinput.h"
@@ -70,6 +71,7 @@ enum {
CMID_SELCOPY,
CMID_SELPASTE,
CMID_SELSEARCH,
+ CMID_PLUGINCMD,
CMSUB_OBJECT,
CMSUB_URL,
CMSUB_SEL,
@@ -107,6 +109,8 @@ void ami_context_menu_init(void)
ctxmenulab[CMID_SELCLEAR] = ami_utf8_easy((char *)messages_get("ClearNS"));
ctxmenulab[CMID_SELSEARCH] = ami_utf8_easy((char *)messages_get("SearchWeb"));
+ ctxmenulab[CMID_PLUGINCMD] = ami_utf8_easy((char *)messages_get("ExternalApp"));
+
ctxmenulab[CMSUB_OBJECT] = ami_utf8_easy((char *)messages_get("Object"));
ctxmenulab[CMSUB_URL] = ami_utf8_easy((char *)messages_get("Link"));
ctxmenulab[CMSUB_SEL] = ami_utf8_easy((char *)messages_get("Selection"));
@@ -360,6 +364,19 @@ void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y)
menuhascontent = true;
}
+ if(curbox->object &&
+ (content_get_type(curbox->object) == CONTENT_PLUGIN))
+ {
+ IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
+ NewObject(POPUPMENU_GetItemClass(), NULL,
+ PMIA_Title, (ULONG)ctxmenulab[CMID_PLUGINCMD],
+ PMIA_ID, CMID_PLUGINCMD,
+ PMIA_UserData, curbox->object,
+ TAG_DONE),
+ ~0);
+
+ menuhascontent = true;
+ }
if (curbox->gadget)
{
switch (curbox->gadget->type)
@@ -540,6 +557,10 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved
}
break;
+ case CMID_PLUGINCMD:
+ amiga_plugin_hack_execute((struct hlcache_handle *)userdata);
+ break;
+
case CMID_HISTORY:
if(userdata == NULL)
{
diff --git a/amiga/plugin_hack.c b/amiga/plugin_hack.c
index 51a7c9373..e1a92f1cd 100644
--- a/amiga/plugin_hack.c
+++ b/amiga/plugin_hack.c
@@ -20,22 +20,19 @@
* DataTypes picture handler (implementation)
*/
-#ifdef WITH_AMIGA_PLUGIN_HACK
#include "amiga/filetype.h"
#include "amiga/plugin_hack.h"
#include "content/content_protected.h"
#include "desktop/plotters.h"
-#include "image/bitmap.h"
#include "render/box.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/talloc.h"
-#include <proto/datatypes.h>
#include <proto/dos.h>
+#include <proto/exec.h>
#include <proto/intuition.h>
-#include <datatypes/pictureclass.h>
-#include <intuition/classusr.h>
+#include <proto/utility.h>
typedef struct amiga_plugin_hack_content {
struct content base;
@@ -58,15 +55,12 @@ static void amiga_plugin_hack_open(struct content *c, struct browser_window *bw,
static void amiga_plugin_hack_close(struct content *c);
static nserror amiga_plugin_hack_clone(const struct content *old, struct content **newc);
static content_type amiga_plugin_hack_content_type(lwc_string *mime_type);
-static void amiga_plugin_hack_mouse_action(struct content *c,
- struct browser_window *bw, browser_mouse_state mouse, int x, int y);
static const content_handler amiga_plugin_hack_content_handler = {
.create = amiga_plugin_hack_create,
.data_complete = amiga_plugin_hack_convert,
.reformat = amiga_plugin_hack_reformat,
.destroy = amiga_plugin_hack_destroy,
- .mouse_action = amiga_plugin_hack_mouse_action,
.redraw = amiga_plugin_hack_redraw,
.open = amiga_plugin_hack_open,
.close = amiga_plugin_hack_close,
@@ -133,6 +127,11 @@ bool amiga_plugin_hack_convert(struct content *c)
{
LOG(("amiga_plugin_hack_convert"));
+ content_set_ready(c);
+ content_set_done(c);
+
+ content_set_status(c, "");
+
return true;
}
@@ -145,22 +144,19 @@ void amiga_plugin_hack_destroy(struct content *c)
return;
}
-static void amiga_plugin_hack_mouse_action(struct content *c,
- struct browser_window *bw, browser_mouse_state mouse, int x, int y)
-{
- printf("action %ld for object %s\n", mouse, content__get_url(c));
- return;
-}
-
bool amiga_plugin_hack_redraw(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour,
bool repeat_x, bool repeat_y)
{
+ static plot_style_t pstyle;
+
LOG(("amiga_plugin_hack_redraw"));
- return plot.bitmap(x, y, width, height,
- c->bitmap, background_colour, BITMAPF_NONE);
+ plot.rectangle(x, y, x + width, y + height, plot_style_fill_red);
+ return plot.text(x, y+20, lwc_string_data(content__get_mime_type(c)),
+ lwc_string_length(content__get_mime_type(c)), plot_style_font);
+
}
/**
@@ -177,9 +173,10 @@ void amiga_plugin_hack_open(struct content *c, struct browser_window *bw,
struct content *page, struct box *box,
struct object_params *params)
{
- LOG(("amiga_plugin_hack_open"));
+ LOG(("amiga_plugin_hack_open %s", content__get_url(c)));
-printf("open %s\n",content__get_url(c));
+ c->width = box->width;
+ c->height = box->height;
return;
}
@@ -193,6 +190,10 @@ void amiga_plugin_hack_close(struct content *c)
void amiga_plugin_hack_reformat(struct content *c, int width, int height)
{
LOG(("amiga_plugin_hack_reformat"));
+
+ c->width = width;
+ c->height = height;
+
return;
}
@@ -232,4 +233,39 @@ content_type amiga_plugin_hack_content_type(lwc_string *mime_type)
return CONTENT_PLUGIN;
}
-#endif
+void amiga_plugin_hack_execute(struct hlcache_handle *c)
+{
+ lwc_string *mimetype;
+ lwc_string *plugincmd;
+ struct Node *node;
+ char *full_cmd;
+ BPTR in, out;
+
+ if(c == NULL) return;
+
+ mimetype = content_get_mime_type(c);
+ node = ami_mime_to_plugincmd(mimetype, &plugincmd, NULL);
+
+ if(node && plugincmd)
+ {
+ full_cmd = ASPrintf("%s %s", lwc_string_data(plugincmd), content_get_url(c));
+
+ if(full_cmd)
+ {
+ LOG(("Attempting to execute %s", full_cmd));
+
+ in = Open("NIL:", MODE_OLDFILE);
+ out = Open("NIL:", MODE_NEWFILE);
+
+ SystemTags(full_cmd,
+ SYS_Input, in,
+ SYS_Output, out,
+ SYS_Error, out,
+ SYS_Asynch, TRUE,
+ NP_Name, "NetSurf External Process",
+ TAG_DONE);
+
+ FreeVec(full_cmd);
+ }
+ }
+}
diff --git a/amiga/plugin_hack.h b/amiga/plugin_hack.h
index 27e35113f..0e9629996 100644
--- a/amiga/plugin_hack.h
+++ b/amiga/plugin_hack.h
@@ -22,16 +22,10 @@
#include "utils/config.h"
#include "utils/errors.h"
-#ifdef WITH_AMIGA_PLUGIN_HACK
+struct hlcache_handle;
nserror amiga_plugin_hack_init(void);
void amiga_plugin_hack_fini(void);
-#else
-
-#define amiga_plugin_hack_init() NSERROR_OK
-#define amiga_plugin_hack_fini() ((void) 0)
-
-#endif /* WITH_AMIGA_DATATYPES */
-
+void amiga_plugin_hack_execute(struct hlcache_handle *c);
#endif