Levi
Levi

Reputation: 317

How to create a simple webkit browser in vala?

I have this simple code:

using GLib;
using Gtk;
using WebKit;

public class Browser : Window {
private const string URL = "http://mixtape.quadhome.com/6/";

public Browser() {
    this.add(this.create_web_window());

    this.destroy.connect(Gtk.main_quit);
}

private ScrolledWindow create_web_window() {
    var view = new WebView();
    view.load_uri(Browser.URL);

    var scrolled_window = new ScrolledWindow(null, null);
    scrolled_window.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
    scrolled_window.add(view);

    return scrolled_window;
}

public static int main(string[] args) {
    Gtk.init(ref args);

    var browser = new Browser();
    browser.show_all();

    Gtk.main();

    return 0;
}
}

My problem here is when I compile with:

valac --pkg gtk+-3.0 --pkg webkit2gtk-4.0 searcher.vala

It gives this error:

fatal error: webkit2/webkit2.h: No such file or directory
#include <webkit2/webkit2.h>

I use valac-0.26 so it has webkit2gtk-4.0. I found with some googleing that there is no "webkit2gtk-4.0.pc" so I donwloaded from an arch package and then it wanted "javascriptcore.pc" and after I copied that too it gave the same error message. These were all in "/usr/lib/pkgconfig". Now I'm pretty much stuck. Please help me if anyone can.

Upvotes: 1

Views: 1234

Answers (1)

rawiro
rawiro

Reputation: 226

first you have to install the dev dependencies..

sudo apt-get install libwebkit2gtk-3.0-dev

another thing.. in webkit2 theres no need to place the webview in a scrolled window

attach it to the window directly

window.add(webview)

or

mygtkwidget.add(webview)

Upvotes: 2

Related Questions