using System; using Gtk; using WebKit; using bytex64.WebThing; public class LoadThrobber : Gtk.DrawingArea { public enum Mode { LoadStarted, LoadInProgress, LoadFinished }; public Mode LoadState; int r; uint idletimer; public LoadThrobber(WebThing wt) { LoadState = Mode.LoadStarted; wt.WebView.LoadStarted += WebView_LoadStarted; wt.WebView.LoadCommitted += WebView_LoadCommitted; wt.WebView.LoadProgressChanged += WebView_LoadProgressChanged; wt.WebView.LoadFinished += WebView_LoadFinished; SetSizeRequest(64, 64); } protected override bool OnExposeEvent(Gdk.EventExpose e) { Gdk.Window w = e.Window; Gdk.GC gc = new Gdk.GC(w); int width, height; w.GetSize(out width, out height); gc.Foreground = new Gdk.Color(0, 0, 0); gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Butt, Gdk.JoinStyle.Round); w.Clear(); switch(LoadState) { case Mode.LoadStarted: w.DrawArc(gc, false, 4, 4, width-8, width-8, -r*64, 90*64); w.DrawArc(gc, false, 4, 4, width-8, width-8, -r*64 + 180*64, 90*64); r += 5; break; case Mode.LoadInProgress: case Mode.LoadFinished: w.DrawArc(gc, false, 4, 4, width-8, width-8, 90*64, -r*64); break; } return true; } void WebView_LoadStarted(object o, LoadStartedArgs e) { this.Show(); Console.WriteLine("Loading Started"); LoadState = Mode.LoadStarted; idletimer = GLib.Timeout.Add(100, delegate { QueueDraw(); return true; }); } void WebView_LoadCommitted(object o, LoadCommittedArgs e) { Console.WriteLine("Loading Committed"); LoadState = Mode.LoadInProgress; GLib.Source.Remove(idletimer); r = 0; QueueDraw(); } void WebView_LoadProgressChanged(object o, LoadProgressChangedArgs e) { Console.WriteLine("Loading Progress: {0}", e.Progress); r = (int) ((e.Progress / 100.0) * 360); QueueDraw(); } void WebView_LoadFinished(object o, LoadFinishedArgs e) { Console.WriteLine("Loading Finished"); LoadState = Mode.LoadFinished; this.Hide(); } } public class Plugin { public Plugin(WebThing wt) { LoadThrobber lt = new LoadThrobber(wt); wt.AttachWidget(lt, CompassDirection.Interior); } }