Re: [Banshee-List] a litlle Patch for Wikipedia plugin, v0.0.2



Hello,
i'm sorry i forgot one file, and i found an error i introduced in
wikipediapane.cs 
Am Sonntag, den 30.04.2006, 17:17 +0200 schrieb indecent:
> Hello,
> 
> here comes a little patch for the wikipedia  plugin, i added a parser
> for the wikipedia pages to remove information that is not needed, for
> now the bar left, header and footer. 
> Also I added a class to manage the querys an request the pages using
> httpwebrequest, this could also help tho find pages that didn't match
> match the search. I used the httpwebresponse.Host to detect results not
> from wikipedia.
> Further i started a cache for the downloaded pages, these are stored in
> the plungindir/wikipedia
> 
> David
> 
> Am Sonntag, den 30.04.2006, 02:37 -0400 schrieb Trick van Staveren:
> > Hey folks,
> > 
> > Been working on it a bit and just wanted to publish :)
> > 
> > http://www.trick.vanstaveren.us/banshee/banshee-wikipedia-plugin-0.0.2.tar.bz2
> > 
> > Changelog:
> > 2006-04-30  Patrick van Staveren  <trick vanstaveren us>
> >         * Google search mode - uses the "i'm feeling lucky" feature of Google to direct
> > to the closes match using Google, adding the keyword "band".  I know, this isn't the
> > best way, but it is much much more accurate than just searching for the artist
> > keyword.
> >         * Experimenting with stuff like a status bar and progress bar for loading.
> >                 * Progress bar is way too buggy and causes segfaults - commented out :)
> >         * Opens to about:blank, not google on init.  Faster.
> >         * Made default size a bit bigger.  Maybe this should be a percentage someday. 
> > Someone patch this for me!
> >         * Bunch of attempts to create a HPaned between the track listing and this, but
> > I can't find a widget.  Big chunk of commented code for now.
> >         * Added Wikipedia.dll.config, a DLL mapper copied from gecko-sharp.  Should fix
> > issues with not finding gtkmozembed.so on some platforms. (Send bug reports!)
> >         * Debug info is copied in, so you can easily trace
> > 
> > Enjoy, and send feedback :)
> > 
> > Patrick
> > 
> > --
> > Patrick "Trick" van Staveren
> > Western Michigan University
> > AIM: goofyassmoose
> > Cell: 269.267.6008
> > http://www.trick.vanstaveren.us/
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Banshee-list mailing list
> > Banshee-list gnome org
> > http://mail.gnome.org/mailman/listinfo/banshee-list
> > 
> _______________________________________________
> Banshee-list mailing list
> Banshee-list gnome org
> http://mail.gnome.org/mailman/listinfo/banshee-list
using System;
using System.IO;
using System.Text;

namespace Banshee.Plugins.Wikipedia
{
	
	public class WikipediaPage
	{
		private static string header = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\";> "+
		"<html xmlns=\"http://www.w3.org/1999/xhtml\"; xml:lang=\"de\" ><head>"+
		"<meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\" />"+
		"<style type=\"text/css\" media=\"screen,projection\">"+
					"/*<![CDATA[*/"+
					""+
					"/* Basic Styling */"+
					""+
					"body {"+					
					"	font-family: Lucida Grande,  Trebuchet MS, Arial, sans-serif;"+   
					"  	font-size: x-small;"+
					"  	color: black;"+
					"  	background: white;"+
					"  	letter-spacing: -0.05ex;"+
					"  	margin: 0;"+
					"  	padding: 0px;"+
					"	color: #222;"+
					"	}"+
					"h1 {"+
					"	color: #92278f;"+
					"	margin: 0;"+
					"	}"+
					"h1 a {"+
					"	color: #92278f;"+
					"	font-size: 18px;"+
					"	margin: 0 0 0 10px;"+
					"	text-decoration: none;"+
					"	}"+
		"</style>"+
		"</head><body>";
		private static string footer = "</body></html>";
		//public Stream body;
		private StreamReader body_reader;
		private string base_url;
		public string BaseUri {
			get {
				return base_url;
			} set {
				this.base_url = value;
			}
		}
		
		public string Header {
			get {
				return header;
			}
		}
		
		public string Footer {
			get {
				return footer;
			}
		}
		
			
		
		public WikipediaPage(Stream body)
		{
			body_reader = new StreamReader(body,System.Text.Encoding.UTF8);
		}
		~WikipediaPage() {
			body_reader.Close();
			//body.Close();
		}
		
		public string ReadBodyLine() {			
			return  body_reader.ReadLine();			
		}	
		
	}
	
}
using System;
using System.Text;
using Mono;
using Mono.Posix;
using Gtk;
using Gecko;
using GLib;
using Banshee;
using Banshee.Base;
using Gdk;

namespace Banshee.Plugins.Wikipedia
{
	public class WikipediaPane : Frame
	{
		private WebControl web;
		private Viewport win;
		private Statusbar sb;
		private VBox main;
		private HBox bot;
		private ProgressBar pb;
		private int bot_queue_length;
		public string current_artist;
		
		public WikipediaPane () {
			Visible = false;
			
			// set url
			
			web = new WebControl("about:blank", "Gecko");
			win = new Viewport();
			sb = new Statusbar();
			pb = new ProgressBar();
			main = new VBox();
			bot = new HBox();
			
			bot_queue_length = 0;

			sb.TextPushed += new Gtk.TextPushedHandler (StatusbarDisplay);
			sb.Visible = false;
			sb.HasResizeGrip = false;

			pb.WidthRequest = 300;


			//web.ProgressAll += new Gecko.ProgressAllHandler(updateProgress);
			web.LinkMsg += new EventHandler (LinkMessage);
			
			
			bot.PackStart(sb, true, true, 0);
			//bot.PackEnd(pb, false, false, 0);
			
			main.PackStart(web, true, true, 0);
			main.PackEnd(bot, false, false, 0);
			
			win.Add(main);
			Add(win);

			ShowAll();
		}
		
		public void StatusbarDisplay (object o, TextPushedArgs args) {
			bot.Visible = true;
			bot_queue_length++;
			GLib.Timeout.Add(5000, delegate {
				bot_queue_length--;
				sb.Pop(1);
				if(bot_queue_length < 1) {
					bot.Visible = false;
					pb.Visible = false;
				}
				return false;
			});
		}
		
		/*public void ProgressbarDisplay (object o, ProgressAllArgs args) {
			bot.Visible = true;
			bot.PackEnd(pb);
			pb.Visible = true;
			bot_queue_length++;
			pb.Fraction = (double) args.Curprogress / (double) args.Maxprogress;
			GLib.Timeout.Add(5000, delegate {
				bot_queue_length--;
				if(bot_queue_length < 1) {
					bot.Remove(pb);
					bot.Visible = false;
				}
				return false;
			});
		}*/
		
		public void LinkMessage (object o, EventArgs args) {
			sb.Push(1, web.LinkMessage);
		}
		
		/*public void updateProgress(object o, ProgressAllArgs args) {
			Console.WriteLine("on {0} of {1}", args.Curprogress, args.Maxprogress);
			if(args.Curprogress <= args.Maxprogress && args.Curprogress > 0 && args.Maxprogress > 1)
				ProgressbarDisplay(o, args);
		}*/
		
		private void ShowArtist(object o, EventArgs e){
			/*
				A way to find pages thru google's index of wikipedia.
				PROS:
					possibly more effective.  tests show better results than just querying an artist
					If the page doesn't exist, the nearest one will automatically be returned
					Since it's google, it could return a page that's not the exact title, but is the most popular representation of this.  Might work better.
				CONS:
					slower, as we're going to google and then wikipedia
					Since it's google, it could return a page that's not the exact title, but is the most popular representation of this.  Might work worse.
					(Why this method isn't being used right now): because I want to pass to wikipedia that this is a printable page
			*/			
			
				string temp;		
				WikipediaQuery w_query 	= new WikipediaQuery(current_artist);
				WikipediaPage w_page	= w_query.PerformLookUp();
				if ( w_page != null ) {
					web.OpenStream(w_page.BaseUri,"text/html");
					web.AppendData(w_page.Header);
					web.AppendData("<h1>"+current_artist+"</h1>");
					//Console.WriteLine(w_page.Header);
					while ( (temp = w_page.ReadBodyLine())!= null ) {
						web.AppendData(temp);
						//Console.WriteLine(temp);
					}
					web.AppendData(w_page.Footer);
					web.CloseStream();
					web.Show();
					Console.WriteLine("Wikipedia plugin debug: URL=" +w_page.BaseUri);
				} else {
					Visible = false;
				}
			/*
			The plain 'ol, link to wikipedia.
			tags on printable=yes.  nice, but hides links, and doesn't persist from page-to-page.
			also, no help with searching for music only...
			
			web.LoadUrl(
				"http://en.wikipedia.org/wiki/"; +
				current_artist + " " + 
				"?printable=yes"
			);
			*/
			
			
		}
		
		// --------------------------------------------------------------- //

		public void HideWikipedia ()
		{
			Visible = false;
		}

		public void ShowWikipedia (string artist)
		{
			/*if(web.Allocation.Width > 1) {
				web.WidthRequest = win.Allocation.Width + 200 - 4;
				win.Hadjustment = new Adjustment(200, 0, win.Allocation.Width, 1, 1, 1);
			}else{
				Console.WriteLine("Apparently it hasn't been drawn yet.  crap.");
			}*/
			if (current_artist == artist) {
				ShowArtist(null, null);
				Visible = true;
				return;
			}
			current_artist = artist;
			ShowArtist(null, null);
			Visible = true;
			ShowAll ();
			this.HeightRequest = 450;
		}
	}
}



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