X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=plugins%2FLoadProgress.cs;h=d6355731480aead7ecb51440cd2bc7248a3ca304;hb=2744fefc32dbe9b59a570f6515d51121b8fcfbe3;hp=3d5e59d8c7ab7c4e209de97ee71b366fe5987a65;hpb=126f2111e41f6b2595ffde1de6828ef12246e545;p=WebThing.git diff --git a/plugins/LoadProgress.cs b/plugins/LoadProgress.cs index 3d5e59d..d635573 100644 --- a/plugins/LoadProgress.cs +++ b/plugins/LoadProgress.cs @@ -4,84 +4,92 @@ using WebKit; using bytex64.WebThing; public class LoadThrobber : Gtk.DrawingArea { - public enum Mode { - LoadStarted, - LoadInProgress, - LoadFinished - }; - public Mode LoadState; - int r; - uint idletimer; + public enum Mode { + LoadStarted, + LoadInProgress, + LoadFinished + }; + public Mode LoadState; + int r; + uint idletimer; - public LoadThrobber(WebThing wt) { - LoadState = Mode.LoadStarted; + 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); + } - SetSizeRequest(64, 64); - } + public void AttachSignals(WebView wv) { + wv.LoadStarted += WebView_LoadStarted; + wv.LoadCommitted += WebView_LoadCommitted; + wv.LoadProgressChanged += WebView_LoadProgressChanged; + wv.LoadFinished += WebView_LoadFinished; + } - 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); + 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(); + 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; - } + 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_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_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_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(); - } + 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); - } +public class LoadThrobberPlugin : WebThingPlugin { + LoadThrobber lt; + + public override void Init(WebThing wt) { + lt = new LoadThrobber(wt); + wt.AttachWidget(lt, AttachPoint.Interior); + } + + public override void InitWebView(WebView wv) { + lt.AttachSignals(wv); + } }