[Vala] Call method "on destroy"



So. I got my sample to work. Thanks for your previous input.

Instead of just destroying the window i destroy first the webkit.webview inside of it and then the window 
itself:

if (player != null){
    player.stop ();    // only web_view.destroy ();
    player.destroy ();
}

My question now is if i can put this code inside some kind of methd which automattically gets fired on 
destroy ().
Putting it into the destructor ~Destructor() does not work.

So maybe there is a signal i did not find or i can override the destroy method calling my code first followed 
by the base.destroy() -method.

Whats the way to go with this?

Complete code:


//valac --pkg=gtk+-2.0 --pkg=webkit-1.0 --thread browser.vala && ./browser

using Gtk;
using WebKit;

public class MainWindow : Window {
  WebPlayer player;

  public void run (){
    change_media ();
    Timeout.add (2000, change_media);
  }

  private bool change_media (){
    if (player != null){
      player.stop ();
      player.destroy ();
    }
    player = new WebPlayer ();
    player.start ("http://www.youtube.com/embed/XSGBVzeBUbk";);
    return true;
  }
}

public class WebPlayer : Window {
  private WebView web_view;

  public WebPlayer (){
    title = "web player";
    name = "window";
    set_size_request (800, 600);
    web_view = new WebView ();
    this.add (web_view);
  }

  public void stop (){
    web_view.destroy ();
  }

  public void start (string url){
    web_view.open (url);
    show_all ();
  }
}

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

  var window = new MainWindow ();
  window.run ();

  Gtk.main ();

  return 0;
}
Diese E-Mail und ihre Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie 
nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort 
den Absender und vernichten Sie diese Mail inklusive Anhänge. Das unerlaubte Kopieren sowie die unbefugte 
Weitergabe der Inhalte dieser Mail ist nicht gestattet.
This e-mail and any attachments may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy 
this e-mail including the attachments. Any unauthorized copying, disclosure or distribution of the material 
in this e-mail is strictly forbidden.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]