Saturday, 19 December 2015

Patch for BeOS/Haiku: Adding websearch bar

From 18895a3cd7afc26b9bb5f8b58fdde93856a6ca55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adri=C3=A1n=20Arroyo=20Calle?=
<adrian.arroyocalle@gmail.com>
Date: Fri, 18 Dec 2015 22:50:25 +0000
Subject: WebSearch bar

WebSearch new position

diff --git a/beos/Makefile.target b/beos/Makefile.target
index 5edb896..4661751 100644
--- a/beos/Makefile.target
+++ b/beos/Makefile.target
@@ -102,7 +102,7 @@ RDEF_IMP_BEOS := $(addprefix $(OBJROOT)/,$(subst /,_,$(RDEF_IMP_BEOS)))
RDEP_BEOS := \
adblock.css beosdefault.css default.css internal.css quirks.css \
netsurf.png favicon.png ca-bundle.txt \
- credits.html licence.html welcome.html maps.html
+ credits.html licence.html welcome.html maps.html SearchEngines
RDEP_BEOS := $(addprefix beos/res/,$(RDEP_BEOS)) \
$(wildcard beos/res/icons/*.png) \
$(wildcard beos/res/??/*) \
@@ -130,6 +130,7 @@ install-beos:
@cp -vRL beos/res/default.css $(DESTDIR)$(NETSURF_BEOS_RESOURCES)
@cp -vRL beos/res/beosdefault.css $(DESTDIR)$(NETSURF_BEOS_RESOURCES)
@cp -vRL gtk/res/license $(DESTDIR)$(NETSURF_BEOS_RESOURCES)
+ @cp -vRL beos/res/SearchEngines $(DESTDIR)$(NETSURF_BEOS_RESOURCES)
# @cp -vRL beos/res/throbber/*.png $(DESTDIR)$(NETSURF_BEOS_RESOURCES)throbber
$(call split_install_messages, beos, $(DESTDIR)$(NETSURF_BEOS_RESOURCES))

diff --git a/beos/gui.cpp b/beos/gui.cpp
index 9486382..a877ee7 100644
--- a/beos/gui.cpp
+++ b/beos/gui.cpp
@@ -1,4 +1,5 @@
/*
+ * Copyright 2015 Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
* Copyright 2008 François Revol <mmu_man@users.sourceforge.net>
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
*
@@ -137,6 +138,7 @@ NSBrowserApplication::MessageReceived(BMessage *message)
case 'home':
case 'urlc':
case 'urle':
+ case 'sear':
case 'menu':
// NetPositive messages
case B_NETPOSITIVE_OPEN_URL:
@@ -221,7 +223,7 @@ char *realpath(const char *f, char *buf)
#endif

/* finds the NetSurf binary image ID and path
- *
+ *
*/
image_id nsbeos_find_app_path(char *path)
{
@@ -254,7 +256,7 @@ image_id nsbeos_find_app_path(char *path)
* \param def default to return if file not found
* \return path to resource.
*/
-static char *find_resource(char *buf, const char *filename, const char *def)
+char *find_resource(char *buf, const char *filename, const char *def)
{
const char *cdir = NULL;
status_t err;
@@ -342,7 +344,7 @@ static void check_homedir(void)
}

path.Append("NetSurf");
- err = create_directory(path.Path(), 0644);
+ err = create_directory(path.Path(), 0644);
if (err < B_OK) {
LOG(("Unable to create %s", path.Path()));
die("NetSurf could not create its settings directory.\n");
@@ -561,7 +563,7 @@ static void gui_init(int argc, char** argv)
FIND_THROB(8);
nsbeos_throbber_initialise_from_png(9,
filenames[0], filenames[1], filenames[2], filenames[3],
- filenames[4], filenames[5], filenames[6], filenames[7],
+ filenames[4], filenames[5], filenames[6], filenames[7],
filenames[8]);
#undef FIND_THROB
#undef STROF
@@ -618,7 +620,7 @@ static void gui_init(int argc, char** argv)
LOG(("Using '%s' as Cookie Jar file", buf));
nsoption_set_charp(cookie_jar, strdup(buf));
}
- if ((nsoption_charp(cookie_file) == NULL) ||
+ if ((nsoption_charp(cookie_file) == NULL) ||
(nsoption_charp(cookie_jar) == NULL))
die("Failed initialising cookie options");

@@ -747,7 +749,7 @@ void nsbeos_gui_poll(void)
timeout.tv_usec = (long)(next_schedule % 1000000LL);

//LOG(("gui_poll: select(%d, ..., %Ldus", max_fd, next_schedule));
- fd_count = select(max_fd, &read_fd_set, &write_fd_set, &exc_fd_set,
+ fd_count = select(max_fd, &read_fd_set, &write_fd_set, &exc_fd_set,
&timeout);
//LOG(("select: %d\n", fd_count));

@@ -810,7 +812,7 @@ void nsbeos_gui_view_source(struct hlcache_handle *content)
if (temp_name) {
path.SetTo(temp_name);
BEntry entry;
- if (entry.SetTo(path.Path()) >= B_OK
+ if (entry.SetTo(path.Path()) >= B_OK
&& entry.Exists() && entry.IsFile())
done = true;
}
@@ -841,11 +843,11 @@ void nsbeos_gui_view_source(struct hlcache_handle *content)
}
lwc_string *mime = content_get_mime_type(content);
if (mime) {
- file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL,
+ file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL,
lwc_string_data(mime), lwc_string_length(mime) + 1);
lwc_string_unref(mime);
}
-
+
}

entry_ref ref;
@@ -873,7 +875,7 @@ void nsbeos_gui_view_source(struct hlcache_handle *content)
if (msgr.SendMessage(&m) >= B_OK)
break;
}
-
+
err = be_roster->Launch(editorSigs[i], (BMessage *)&m, &team);
if (err >= B_OK)
break;
@@ -926,7 +928,7 @@ void warn_user(const char *warning, const char *detail)
if (detail)
text << ":\n" << detail;

- alert = new BAlert("NetSurf Warning", text.String(), "Debug", "Ok", NULL,
+ alert = new BAlert("NetSurf Warning", text.String(), "Debug", "Ok", NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT);
if (alert->Go() < 1)
debugger("warn_user");
@@ -939,7 +941,7 @@ void die(const char * const error)
BString text("Cannot continue:\n");
text << error;

- alert = new BAlert("NetSurf Error", text.String(), "Debug", "Ok", NULL,
+ alert = new BAlert("NetSurf Error", text.String(), "Debug", "Ok", NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
if (alert->Go() < 1)
debugger("die");
diff --git a/beos/gui.h b/beos/gui.h
index 215cda8..b9f560e 100644
--- a/beos/gui.h
+++ b/beos/gui.h
@@ -1,4 +1,5 @@
/*
+ * Copyright 2015 Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
* Copyright 2008 François Revol <mmu_man@users.sourceforge.net>
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
*
@@ -65,6 +66,7 @@ void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaf

void nsbeos_gui_view_source(struct hlcache_handle *content);
image_id nsbeos_find_app_path(char *path);
+char *find_resource(char *buf, const char *filename, const char *def);

void nsbeos_update_system_ui_colors(void);

diff --git a/beos/res/SearchEngines b/beos/res/SearchEngines
new file mode 100644
index 0000000..38e7795
--- /dev/null
+++ b/beos/res/SearchEngines
@@ -0,0 +1,20 @@
+Google|www.google.com|http://www.google.com/search?q=%s|http://www.google.com/favicon.ico|
+Yahoo|search.yahoo.com|http://search.yahoo.com/search?p=%s|http://www.yahoo.com/favicon.ico|
+Bing|www.bing.com|http://www.bing.com/search?q=%s|http://www.bing.com/favicon.ico|
+Business.com|www.business.com|http://www.business.com/search/rslt_default.asp?query=%s|http://www.business.com/favicon.ico|
+Omgili|www.omgili.com|http://www.omgili.com/AAAAA/%s.html|http://omgili.com/public/images/favicon.ico|
+BBC News|search.bbc.co.uk|http://search.bbc.co.uk/search?q=%s&tab=ns|http://www.bbc.co.uk/favicon.ico|
+Ubuntu Packages|packages.ubuntu.com|http://packages.ubuntu.com/search?keywords=%s|http://packages.ubuntu.com/favicon.ico|
+Creative Commons|creativecommons.org|http://creativecommons.org/?s=%s|http://creativecommons.org/favicon.ico|fixme:favicon does not work as it is served as x-icon and is a png
+Ask.com|www.ask.com|http://www.ask.com/web?q=%s|http://sp.uk.ask.com/sh/i/a14/favicon/favicon.ico|fixme:favicon is served as text/plain
+Dictionary.com|dictionary.reference.com|http://dictionary.reference.com/browse/%s?jss=0|http://dictionary.reference.com/favicon.ico|
+Youtube|www.youtube.com|http://www.youtube.com/results?search_query=%s|http://www.youtube.com/favicon.ico|
+AOL|search.aol.com|http://search.aol.com/aol/search?query=%s|http://www.aol.com/favicon.ico|
+Baidu|www.baidu.com|http://www.baidu.com/s?wd=%s|http://www.baidu.com/favicon.ico|
+Amazon|www.amazon.com|http://www.amazon.com/s/ref=nb_ss_gw?field-keywords=%s|http://www.amazon.com/favicon.ico|
+Ebay|shop.ebay.com|http://shop.ebay.com/items/%s|http://www.ebay.com/favicon.ico|
+IMDB|www.imdb.com|http://www.imdb.com/find?q=%s|http://www.imdb.com/favicon.ico|
+ESPN|search.espn.go.com|http://search.espn.go.com/%s/|http://www.espn.go.com/favicon.ico|
+Wikipedia|en.wikipedia.org|http://en.wikipedia.org/w/index.php?title=Special%%3ASearch&search=%s|http://en.wikipedia.org/favicon.ico|
+DuckDuckGo|www.duckduckgo.com|http://www.duckduckgo.com/html/?q=%s|http://www.duckduckgo.com/favicon.ico|fixme:Their ico upsets the current implementation
+Seeks|www.seeks-project.info|https://www.seeks-project.info/search.php/search?q=%s|http://www.seeks-project.info/search.php/public/images/seek_icon_32x32_transparent.png|fixme:they have no icon
diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp
index 04b4261..2f38497 100644
--- a/beos/scaffolding.cpp
+++ b/beos/scaffolding.cpp
@@ -1,4 +1,5 @@
/*
+ * Copyright 2015 Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
* Copyright 2008 François Revol <mmu_man@users.sourceforge.net>
* Copyright 2006 Rob Kendrick <rjek@rjek.com>
*
@@ -56,6 +57,8 @@ extern "C" {
#include "desktop/browser.h"
#include "desktop/netsurf.h"
#include "desktop/version.h"
+#include "desktop/searchweb.h"
+#include "desktop/search.h"
#include "desktop/plotters.h"
#include "utils/nsoption.h"
#include "desktop/textinput.h"
@@ -109,6 +112,7 @@ struct beos_scaffolding {
BControl *home_button;

NSIconTextControl *url_bar;
+ NSIconTextControl *search_bar;
//BMenuField *url_bar_completion;

NSThrobber *throbber;
@@ -418,7 +422,7 @@ NSThrobber::SetBitmap(const BBitmap *bitmap)


NSBaseView::NSBaseView(BRect frame)
- : BView(frame, "NetSurf", B_FOLLOW_ALL_SIDES,
+ : BView(frame, "NetSurf", B_FOLLOW_ALL_SIDES,
0 /*B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS*/ /*| B_SUBPIXEL_PRECISE*/),
fScaffolding(NULL)
{
@@ -476,6 +480,7 @@ NSBaseView::MessageReceived(BMessage *message)
case 'home':
case 'urlc':
case 'urle':
+ case 'sear':
case 'menu':
case NO_ACTION:
case HELP_OPEN_CONTENTS:
@@ -606,7 +611,7 @@ NSBaseView::Instantiate(BMessage *archive)

//TODO:FIXME: fix replicants
// do as much as possible in this thread to avoid deadlocks
-
+
gui_init_replicant(2, info->args);

replicant_done_sem = create_sem(0, "NS Replicant created");
@@ -651,6 +656,7 @@ NSBaseView::AllAttached()
g->home_button->SetTarget(this);

g->url_bar->SetTarget(this);
+ g->search_bar->SetTarget(this);

rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR);
SetViewColor(c);
@@ -667,6 +673,7 @@ NSBaseView::AllAttached()
g->home_button->SetViewColor(c);
g->home_button->SetLowColor(c);
g->url_bar->SetViewColor(c);
+ g->search_bar->SetViewColor(c);
g->throbber->SetViewColor(c);
g->scroll_view->SetViewColor(c);

@@ -802,6 +809,7 @@ static void nsbeos_scaffolding_update_colors(nsbeos_scaffolding *g)
g->reload_button->SetViewColor(c);
g->home_button->SetViewColor(c);
g->url_bar->SetViewColor(c);
+ g->search_bar->SetViewColor(c);
g->throbber->SetViewColor(c);
g->scroll_view->SetViewColor(c);

@@ -1068,6 +1076,41 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m
//nsbeos_completion_update(text.String());
break;
}
+ case 'sear':
+ {
+ nserror ret;
+ nsurl* url;
+ BString text;
+ if (!scaffold->search_bar->LockLooper())
+ break;
+ text = scaffold->search_bar->Text();
+ scaffold->search_bar->UnlockLooper();
+
+ char t[PATH_MAX];
+ find_resource(t,"SearchEngines","./beos/res/SearchEngines");
+
+ search_web_init(t);
+
+ ret = search_web_omni(text.String(),SEARCH_WEB_OMNI_SEARCHONLY
+ ,&url);
+ if (ret == NSERROR_OK) {
+ ret = browser_window_create(
+ (browser_window_create_flags)(BW_CREATE_HISTORY | BW_CREATE_TAB),
+ url,
+ NULL,
+ bw,
+ NULL);
+ nsurl_unref(url);
+ }
+
+ if (ret != NSERROR_OK) {
+ warn_user(messages_get_errorcode(ret), 0);
+ }
+
+ search_web_finalise();
+
+ break;
+ }
/*
case 'menu':
{
@@ -1386,12 +1429,12 @@ void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view)
rect.top += TOOLBAR_HEIGHT;
rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
-
+
view->ResizeTo(rect.Width() /*+ 1*/, rect.Height() /*+ 1*/);
view->MoveTo(rect.LeftTop());


- g->scroll_view = new BScrollView("NetSurfScrollView", view,
+ g->scroll_view = new BScrollView("NetSurfScrollView", view,
B_FOLLOW_ALL, 0, true, true, B_NO_BORDER);

g->top_view->AddChild(g->scroll_view);
@@ -1422,7 +1465,7 @@ void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view)
rect.right = rect.left + divider - 1;

/*
- BBox *statusBarBox = new BBox(rect, "StatusBarBox",
+ BBox *statusBarBox = new BBox(rect, "StatusBarBox",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM,
B_WILL_DRAW | B_FRAME_EVENTS,
B_RAISED_BORDER);
@@ -1450,6 +1493,7 @@ void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view)
g->home_button->SetTarget(view);

g->url_bar->SetTarget(view);
+ g->search_bar->SetTarget(view);

nsbeos_scaffolding_update_colors(g);

@@ -1511,8 +1555,8 @@ static BMenuItem *make_menu_item(const char *name, BMessage *message, bool enabl
// try to understand accelerators
int32 start = label.IFindLast(" ");
if (start > 0 && (label.Length() - start > 1)
- && (label.Length() - start < 7)
- && (label[start + 1] == 'F'
+ && (label.Length() - start < 7)
+ && (label[start + 1] == 'F'
|| !strcmp(label.String() + start + 1, "PRINT")
|| label[start + 1] == '\xe2'
|| label[start + 1] == '^')) {
@@ -1625,7 +1669,7 @@ void BBitmapButton::SetBitmap(const char* attrname)

fBitmap = new BBitmap(BRect(0, 0, 32, 32), B_RGB32);
status_t status = BIconUtils::GetVectorIcon((const uint8*)data, size, fBitmap);
-
+
if(status != B_OK) {
fprintf(stderr, "%s > oops %s\n", attrname, strerror(status));
delete fBitmap;
@@ -2011,7 +2055,7 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel)
rect = g->top_view->Bounds();
rect.bottom = rect.top + TOOLBAR_HEIGHT - 1;
rect.left = rect.right - DRAGGER_WIDTH + 1;
- g->dragger = new BDragger(rect, g->top_view,
+ g->dragger = new BDragger(rect, g->top_view,
B_FOLLOW_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW);
g->top_view->AddChild(g->dragger);
g->dragger->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -2026,7 +2070,7 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel)
rect = g->top_view->Bounds();
rect.bottom = rect.top + TOOLBAR_HEIGHT - 1;
rect.right = rect.right - DRAGGER_WIDTH;
- g->tool_bar = new BBox(rect, "Toolbar",
+ g->tool_bar = new BBox(rect, "Toolbar",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS
| B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
g->top_view->AddChild(g->tool_bar);
@@ -2074,15 +2118,14 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel)
g->tool_bar->AddChild(g->home_button);
nButtons++;

-
// url bar
rect = g->tool_bar->Bounds();
- rect.left += TOOLBAR_HEIGHT * nButtons;
- rect.right -= TOOLBAR_HEIGHT * 1;
+ rect.left += TOOLBAR_HEIGHT * nButtons; // +124
+ rect.right -= TOOLBAR_HEIGHT * 1 + 124;
rect.InsetBySelf(5, 5);
message = new BMessage('urle');
message->AddPointer("scaffolding", g);
- g->url_bar = new NSIconTextControl(rect, "url_bar", "", "", message,
+ g->url_bar = new NSIconTextControl(rect, "url_bar", "", "", message,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
g->url_bar->SetDivider(0);
rect = g->url_bar->TextView()->TextRect();
@@ -2090,6 +2133,21 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel)
g->url_bar->TextView()->SetTextRect(rect);
g->tool_bar->AddChild(g->url_bar);

+ // search bar
+
+ rect = g->tool_bar->Bounds();
+ rect.left += TOOLBAR_HEIGHT * nButtons + (g->url_bar->Bounds().right - g->url_bar->Bounds().left);
+ rect.right -= TOOLBAR_HEIGHT * 1;
+ rect.InsetBy(5,5);
+ message = new BMessage('sear');
+ message->AddPointer("scaffolding", g);
+ g->search_bar = new NSIconTextControl(rect,"search_bar","","Search...",message,
+ B_FOLLOW_RIGHT);
+ g->search_bar->SetDivider(0);
+ rect = g->search_bar->TextView()->TextRect();
+ rect.left += 0; // 16 if you put a Favicon
+ g->search_bar->TextView()->SetTextRect(rect);
+ g->tool_bar->AddChild(g->search_bar);

// throbber
rect.Set(0, 0, 24, 24);
@@ -2109,7 +2167,7 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel)
// the status bar at the bottom
BString status("NetSurf");
status << " " << netsurf_version;
- g->status_bar = new BStringView(BRect(0,0,-1,-1), "StatusBar",
+ g->status_bar = new BStringView(BRect(0,0,-1,-1), "StatusBar",
status.String(), B_FOLLOW_LEFT/*_RIGHT*/ | B_FOLLOW_BOTTOM);

// will be added to the scrollview when adding the top view.
--
2.2.2

Hi Netsurfers,

I've made a patch for the BeOS/Haiku frontend that adds the websearch
bar. Current frontend only has a URL bar. This patch is for a task of
Google Code-In 2015. Here's a screenshot of NetSurf with the patch:
http://i.imgur.com/dgM9e8y.png

Greetings, Adrián

No comments:

Post a Comment