Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 19 Aug 2017, 18:39
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
Surfer html viewer, want to improve it
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [25 Posts]   Goto page: 1, 2 Next
Author Message
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8194
Location: Perth, Western Australia

PostPosted: Mon 31 Jul 2017, 10:33    Post subject:  Surfer html viewer, want to improve it
Subject description: Want to embed link to external browser
 

Some pups, including Quirky, not sure about latest Xenialpup and Slacko, use 'surfer' for the internal html help viewer.

This is a very small web page browser, written in C and uses GTK and libgtkhtml.

It has a couple of dependencies from the same guy who created surfer, 'gnet' and 'libsystem', for pups that use surfer, these should already be in the devx.

All sources are here:
http://distro.ibiblio.org/quirky/quirky6/sources/t2/april/Surfer-0.0.7-patched_libgtkhtml.tar.bz2
http://distro.ibiblio.org/quirky/quirky6/sources/t2/april/gnet-2.0.8.tar.bz2
http://distro.ibiblio.org/quirky/quirky6/sources/t2/april/libSystem-0.1.6-patched1.tar.bz2

Compiling is simple Makefile, from memory, need to edit PREFIX, change from /usr/local to /usr

libgtkhtml is there also:
http://distro.ibiblio.org/quirky/quirky6/sources/t2/april/libgtkhtml-2.11.1.tar.bz2

Surfer is a great little viewer for local html files, however, there is one big problem. libgtkhtml supports html4 and some css, no javascript.
If surfer is used to view a local help file, which has links to the internet, then surfer will attempt to open those links, and in many cases will crash.

What would be really great is to hack the C source of surfer somehow, so that two kinds of hyperlinks can be specified in a web page, local, suitable to be opened by surfer, and remote (the internet) and opened by 'defaultbrowser' (which will be SeaMonkey, Firefox, etc).

I have been staring at the source code, but can't see how to do it. So, thought that I would throw the problem out there, see if someone with gtk coding skills can think of how to do it. Or maybe not even gtk, just C skills.

There might not be any takers, but you never know...

Edit
Note, there is one little foible of surfer, it does not like "file://" prefix on local links. So open a file like this:
# surfer /usr/share/doc/home.htm

_________________
http://barryk.org/news/
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1633

PostPosted: Mon 31 Jul 2017, 19:25    Post subject:  

Hey Barry, maybe something like this?

Code:
diff -Naur Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c
--- Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c   2009-08-14 18:54:05.000000000 +0200
+++ Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c   2017-08-01 00:59:41.118965319 +0200
@@ -1067,7 +1067,15 @@
    fprintf(stderr, "DEBUG: %s(\"%s\") base=\"%s\" => \"%s\"\n", __func__,
          url, _ghtml_get_base(ghtml), link);
 #endif
-   _ghtml_document_load(ghtml, link, NULL);
+   if (g_str_has_prefix(link, "http://")   ||
+      g_str_has_prefix(link, "https://")   ||
+      g_str_has_prefix(link, "ftp://"))   /* maybe more prefixes are needed */
+   {
+      system(g_strdup_printf("%s %s %s", "defaultbrowser", link, "&")); /* & to send it to background */
+   }
+   else
+      _ghtml_document_load(ghtml, link, NULL);
+
    g_free(link);
 }

(Also attached, because copying from browser may append spaces to each line.)

I'm just a beginner in C and that's the best I could come up with, but works just fine down here.

Greetings!
surfer-remote_links.patch.tar.gz
Description 
gz

 Download 
Filename  surfer-remote_links.patch.tar.gz 
Filesize  543 Bytes 
Downloaded  26 Time(s) 

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6754
Location: Auckland, New Zealand

PostPosted: Mon 31 Jul 2017, 21:00    Post subject:  

Using xdg-open is more portable - is it included in all puppies these days?
_________________
If you have or know of a good gtkdialog application, please post a link here

Classic Puppy quotes

ROOT FOREVER
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8194
Location: Perth, Western Australia

PostPosted: Tue 01 Aug 2017, 04:40    Post subject:  

SFR,
I tested your patch, it works great. I appreciate the help, it makes Surfer so much more useful.

I have applied SFR's patch and assigned it as HelpSurfer version 0.1, source here:
http://barryk.org/news/?viewDetailed=00632

_________________
http://barryk.org/news/
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1633

PostPosted: Tue 01 Aug 2017, 05:30    Post subject:  

Alright, glad it works!

However, here's a small revision, because I just realized that URLs that contain an amphersand won't be working properly without quotes.
Also, replaced all calls to g_str_has_prefix with one g_regex_match_simple and since g_strdup_printf allocates memory, I had to use a transient variable to free it afterwards.
Code:
diff -Naur Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c
--- Surfer-0.0.7-patched_libgtkhtml_old/src/ghtml-gtkhtml.c   2009-08-14 18:54:05.000000000 +0200
+++ Surfer-0.0.7-patched_libgtkhtml_new/src/ghtml-gtkhtml.c   2017-08-01 11:17:41.846580886 +0200
@@ -1059,6 +1059,7 @@
 {
    GHtml * ghtml;
    gchar * link;
+   gchar * syscmd;
 
    ghtml = g_object_get_data(G_OBJECT(document), "ghtml");
    if((link = _ghtml_make_url(_ghtml_get_base(ghtml), url)) == NULL)
@@ -1067,7 +1068,14 @@
    fprintf(stderr, "DEBUG: %s(\"%s\") base=\"%s\" => \"%s\"\n", __func__,
          url, _ghtml_get_base(ghtml), link);
 #endif
-   _ghtml_document_load(ghtml, link, NULL);
+   if (g_regex_match_simple("^http://|^https://|^ftp://", link, 0, 0))
+   {
+      syscmd = g_strdup_printf("%s '%s' %s", "defaultbrowser", link, "&");
+      system(syscmd);
+      g_free(syscmd);
+   }
+   else
+      _ghtml_document_load(ghtml, link, NULL);
    g_free(link);
 }

___________

@Disciple: yeah, xdg-open works, too (at least here in Fatdog).

Greetings!
surfer-remote_links_v2.patch.tar.gz
Description 
gz

 Download 
Filename  surfer-remote_links_v2.patch.tar.gz 
Filesize  622 Bytes 
Downloaded  22 Time(s) 

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
gyro

Joined: 28 Oct 2008
Posts: 1400
Location: Brisbane, Australia

PostPosted: Tue 01 Aug 2017, 08:43    Post subject:  

It might be a bit rude of me to comment since you already have a working patch;
But would it not be better to turn the test around:
Code:
+   if (g_str_has_prefix(link, "file:///")
+      _ghtml_document_load(ghtml, link, NULL);
+   else
+   {
+      syscmd = g_strdup_printf("%s '%s' %s", "defaultbrowser", link, "&");
+      system(syscmd);
+      g_free(syscmd);
+   }

gyro
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1633

PostPosted: Tue 01 Aug 2017, 09:29    Post subject:  

Not at all, better_code > one's_feelings. Wink

However, I ditched this approach at the very beginning, because of:
BarryK in the first post wrote:
Note, there is one little foible of surfer, it does not like "file://" prefix on local links.

Local links in Fatdog docs (that I used for testing) don't contain this prefix and are relative:
Code:
<a href="tray.html">Tray icons</a>

so it wouldn't work anyway...

Btw, I think ^mailto: could also be added. Surfer does not even recognize this protocol.

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8194
Location: Perth, Western Australia

PostPosted: Wed 02 Aug 2017, 05:15    Post subject:  

SFR,
That's great, I will apply your latest patch.

While I am putting in requests Smile

If you look at helpsurfer-0.1, src/Makefile has "-D NOURLBAR, because as a simple help viewer I didn't think it needed the url entry box.

Also there is "-D EMBEDDED", which removes the drop-down menu bar.

The icon bar still displays, but it would be nice with an "exit" icon. Currently, the only way to close the app is by the close-box top-right of window.

_________________
http://barryk.org/news/
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1633

PostPosted: Wed 02 Aug 2017, 07:42    Post subject:  

Here you go:

Code:
diff -Naur helpsurfer-0.1_old/src/callbacks.c helpsurfer-0.1_new/src/callbacks.c
--- helpsurfer-0.1_old/src/callbacks.c   2009-08-14 18:55:18.000000000 +0200
+++ helpsurfer-0.1_new/src/callbacks.c   2017-08-02 12:17:50.366562155 +0200
@@ -47,6 +47,12 @@
    return FALSE;
 }
 
+/* quit button */
+void on_button_close(GtkWidget * widget, gpointer data)
+{
+   on_closex(widget, NULL, data);
+}
+
 
 #ifndef EMBEDDED
 /* file menu */
diff -Naur helpsurfer-0.1_old/src/callbacks.h helpsurfer-0.1_new/src/callbacks.h
--- helpsurfer-0.1_old/src/callbacks.h   2009-08-14 18:55:18.000000000 +0200
+++ helpsurfer-0.1_new/src/callbacks.h   2017-08-02 12:17:27.103229126 +0200
@@ -24,6 +24,8 @@
 /* window */
 gboolean on_closex(GtkWidget * widget, GdkEvent * event, gpointer data);
 
+void on_button_close(GtkWidget * widget, gpointer data);
+
 #ifndef EMBEDDED
 /* file menu */
 void on_file_close(GtkWidget * widget, gpointer data);
diff -Naur helpsurfer-0.1_old/src/surfer.c helpsurfer-0.1_new/src/surfer.c
--- helpsurfer-0.1_old/src/surfer.c   2017-08-01 09:10:39.000000000 +0200
+++ helpsurfer-0.1_new/src/surfer.c   2017-08-02 12:18:58.289894600 +0200
@@ -205,6 +205,9 @@
    g_signal_connect(G_OBJECT(toolitem), "toggled", G_CALLBACK(
             on_fullscreen), surfer);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
+   toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
+   g_signal_connect(G_OBJECT(toolitem), "clicked", G_CALLBACK(on_button_close), surfer);
+   gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
    gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
    /* toolbar */
 //#ifndef NOURLBAR

Just note that this patch is against helpsurfer-0.1.

Greetings!
helpsurfer-quit_button.patch.tar.gz
Description 
gz

 Download 
Filename  helpsurfer-quit_button.patch.tar.gz 
Filesize  729 Bytes 
Downloaded  16 Time(s) 

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8194
Location: Perth, Western Australia

PostPosted: Wed 02 Aug 2017, 20:44    Post subject:  

That's great!

I have bumped HelpSurfer to version 0.2, see blog post:

http://barryk.org/news/?viewDetailed=00635

_________________
http://barryk.org/news/
Back to top
View user's profile Send private message Visit poster's website 
mavrothal


Joined: 24 Aug 2009
Posts: 2868

PostPosted: Fri 04 Aug 2017, 05:12    Post subject:  

ignor... Embarassed
_________________
Kids all over the world go around with an XO laptop. They deserve one puppy (or many) too Very Happy
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8194
Location: Perth, Western Australia

PostPosted: Sun 06 Aug 2017, 21:09    Post subject:  

Have now bumped HelpSurfer to version 0.3.

Source:
http://distro.ibiblio.org/quirky/quirky6/sources/alphabetical/h/helpsurfer-0.3.tar.gz

PET:
http://distro.ibiblio.org/quirky/quirky6/amd64/packages/pet_packages-xerus/helpsurfer-0.3-xerus64.pet

There was something else that I wanted HelpSurfer to be able to do: execute local executables.
This is not a web browser, it is a local help viewer, and although it is not legitimate html, HelpSurfer now supports hyperlinks to

"exec:<executable> <parameters>"

For example:

Code:
<a href="exec:leafpad /usr/share/doc/home.htm">EXECUTE LEAFPAD</a>


I have a requirement for this feature.

Patch for 0.2 is attached, with a false ".gz" appended.

Thanks to SFR, 'coz I was able to easily see how to extend what he has already done.
helpsurfer-link-executable.patch.gz
Description 
gz

 Download 
Filename  helpsurfer-link-executable.patch.gz 
Filesize  845 Bytes 
Downloaded  10 Time(s) 

_________________
http://barryk.org/news/
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4731

PostPosted: Mon 07 Aug 2017, 15:05    Post subject:  

I love to see people working on projects like this, but netsurf-framebuffer or even the gtk version is better and smaller... and still actively developed.
The big advantage to the framebuffer version though is that puppy's man pages work in the console. I put together a patch a while back that automatically detected linux framebuffer vs X11(actually xcb) backends... it even works in wayland and any platform with SDL support. Not mention that netsurf now uses duktape for JavaScript support.

If you want something really lite, check out goingnuts Chimera patches.

Regarding the exec "feature", this can be done more securely using cgi scripts on localhost like slitaz does for a lot of their apps (things we typically use gtkdialog for)

#EDIT: added links

_________________
Web Programming - Pet Packaging 100 & 101

Last edited by technosaurus on Tue 08 Aug 2017, 15:51; edited 1 time in total
Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 4652
Location: Ontario

PostPosted: Tue 08 Aug 2017, 12:28    Post subject:  

I don't know how to program but I did make the following observation...

If error messages are removed then more downloaded web pages will open up correctly. For example downloaded murga forum web pages
open nicely (except for images) and plain text files and XML.

What I did was simplify following
Code:
/* surfer_error */
int surfer_error(Surfer * surfer, char const * message, int ret)
{
   GtkWidget * dialog;

   dialog = gtk_message_dialog_new((surfer != NULL)
         ? GTK_WINDOW(surfer->window) : NULL,
         GTK_DIALOG_DESTROY_WITH_PARENT,
         GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", message);
   gtk_window_set_title(GTK_WINDOW(dialog), "Error");
   g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
            gtk_widget_destroy), NULL);
   gtk_widget_show(dialog);
   return ret;
}


to

Code:

/* surfer_error */
int surfer_error(Surfer * surfer, char const * message, int ret)
{
   
   return ret;
}



This gets rid of error message, however I must run 'killall surfer'
in terminal to stop memory filling up when a incompatible page is loaded.

__________________________________________________
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 8194
Location: Perth, Western Australia

PostPosted: Tue 08 Aug 2017, 21:28    Post subject:  

A quick post: yesterday I bumped the version to 0.5.

Source:
http://distro.ibiblio.org/quirky/quirky6/sources/alphabetical/h/helpsurfer-0.5.tar.gz

Blog post:
http://barryk.org/news/?viewDetailed=00641


don570,
I will take a look at your suggestion.

_________________
http://barryk.org/news/
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [25 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0972s ][ Queries: 14 (0.0069s) ][ GZIP on ]