0

I'm writing a simple browser in Vala and WebKitGTK+. One of the things I need to do is set the window's title to that of the webpage title, so I monitor title changes with web_view.notify["title"].connect. However, sometimes the value of title is null, when it obviously shouldn't be.

Some examples I remember:

In any case, using the Web Inspector shows that the pages do have a title set.

Is this a bug I should report? Or maybe I'm doing something wrong? Here's the code I'm using:

//valac --thread --pkg webkitgtk-3.0 --pkg gtk+-3.0 --vapidir=./ test.vala
//The vapidir folder should have webkitgtk-3.0.vapi and webkitgtk-3.0.deps

using WebKit;
using Gtk;

public class Test : Gtk.Window {
    public WebView webview;
    public Test () {
        this.title = "Test";
        this.window_position = Gtk.WindowPosition.CENTER;
        this.set_default_size (800, 600);
        this.hide_titlebar_when_maximized = false;

        this.destroy.connect (() => {
            Gtk.main_quit ();
        });

        var scroll = new ScrolledWindow (null, null);
        this.webview = new WebView ();
        this.add (scroll);
        scroll.add (webview);

        webview.settings.enable_developer_extras = true;
        webview.notify["title"].connect ((sender, property) => {
            if (webview.title != null) {
                this.title = webview.title;
                stdout.printf (webview.title + "\n");
            } else {
                stdout.printf ("(null)\n");
            }
        });

        webview.web_inspector.inspect_web_view.connect ((p0) => {
            var w = new Window ();
            w.window_position = WindowPosition.CENTER;
            w.title = "Inspector";
            w.set_default_size (800,600);
            WebView view = new WebView ();
            unowned WebView view2 = view;
            w.add (view2);
            w.show_all ();
            return view2;
        });
    }

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

        Test app = new Test ();
        app.webview.load_uri ("http://google.com");
        app.show_all ();
        Gtk.main ();
        return 0;
    }
}
Arturo Torres Sánchez
  • 2,751
  • 4
  • 20
  • 33
  • You might want to try asking in a webkitgtk-specific location (I don't know that any of the webkitgtk people keep an eye on stack overflow). If I were you I would try #webkitgtk+ on freenode. – nemequ Feb 20 '13 at 13:06

1 Answers1

0

There is a signal called title_changed for that purpose and you should always use the signals provided by webkitgtk instead of the GLib notify feature.
(GLib notify is emitted each time a value changes, even if the change is just for the purpose of clearing the old value, such as in your case.)

Ivaldi
  • 660
  • 6
  • 22